MCPcopy Create free account
hub / github.com/WolfireGames/overgrowth / ProcessCubeMap

Function ProcessCubeMap

Source/Graphics/sky.cpp:117–170  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

115}
116
117void ProcessCubeMap(TextureRef src_ref, TextureRef ref, GLuint framebuffer, GLuint framebuffer2) {
118 Graphics* graphics = Graphics::Instance();
119 PROFILER_GPU_ZONE(g_profiler_ctx, "Sky::ProcessCubeMap");
120 // Read source cube map
121 int tex_width = Textures::Instance()->getWidth(src_ref);
122 // Find out how much source has to be scaled down to match target
123 int mip = 0;
124 while (tex_width > kDiffuseBoxRes) {
125 ++mip;
126 tex_width /= 2;
127 }
128 graphics->PushFramebuffer();
129 for (int i = 0; i < 6; ++i) {
130 glBindFramebuffer(GL_FRAMEBUFFER, 0);
131 glBindFramebuffer(GL_READ_FRAMEBUFFER, framebuffer);
132 glFramebufferTexture2D(GL_READ_FRAMEBUFFER, GL_COLOR_ATTACHMENT0,
133 GL_TEXTURE_CUBE_MAP_POSITIVE_X + i, Textures::Instance()->returnTexture(src_ref), mip);
134 glBindFramebuffer(GL_DRAW_FRAMEBUFFER, framebuffer2);
135 glFramebufferTexture2D(GL_DRAW_FRAMEBUFFER, GL_COLOR_ATTACHMENT0,
136 GL_TEXTURE_CUBE_MAP_POSITIVE_X + i, Textures::Instance()->returnTexture(ref), 0);
137
138 // LOG_ASSERT(glCheckFramebufferStatus(GL_READ_FRAMEBUFFER) == GL_FRAMEBUFFER_COMPLETE);
139 // LOG_ASSERT(glCheckFramebufferStatus(GL_DRAW_FRAMEBUFFER) == GL_FRAMEBUFFER_COMPLETE);
140
141 // LOGE << "Process cubemap blit from " << Textures::Instance()->returnTexture(src_ref) << " to " << Textures::Instance()->returnTexture(ref) << std::endl;
142 // GLint viewport[4];
143 // glGetIntegerv(GL_VIEWPORT,viewport);
144 // LOGE << "CUrrent viewport " << viewport[0] << ", " << viewport[1] << ", "<< viewport[2] << ", "<< viewport[3] << std::endl;
145
146 glClearColor(1, 0, 1, 1);
147 glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
148
149 // Intel actually cares about the scissor test flag in the blit, so we have to disable it.
150 glDisable(GL_SCISSOR_TEST);
151 // We set these incase someone in the future decides blit should care about these too.
152 glViewport(0, 0, kDiffuseBoxRes, kDiffuseBoxRes);
153 glDisable(GL_DEPTH_TEST);
154
155 CHECK_FBO_ERROR();
156 CHECK_GL_ERROR();
157 // glReadBuffer(GL_COLOR_ATTACHMENT0);
158 // glDrawBuffer(GL_COLOR_ATTACHMENT0);
159 glBlitFramebuffer(0, 0, kDiffuseBoxRes, kDiffuseBoxRes, 0, 0, kDiffuseBoxRes, kDiffuseBoxRes, GL_COLOR_BUFFER_BIT, GL_NEAREST);
160
161 glBindFramebuffer(GL_FRAMEBUFFER, 0);
162 glBindFramebuffer(GL_READ_FRAMEBUFFER, 0);
163 glBindFramebuffer(GL_DRAW_FRAMEBUFFER, 0);
164 }
165 graphics->PopFramebuffer();
166 CubemapMipChain(ref, Cubemap::SPHERE, NULL);
167 if (Graphics::Instance()->vendor == _intel) {
168 CubemapMipChain(ref, Cubemap::SPHERE, NULL); // This has to be called twice on the brix for some reason
169 }
170}
171} // namespace
172
173static glm::mat4 CubeFaceTransform(int i) {

Callers 2

BakeFirstPassMethod · 0.85
BakeSecondPassMethod · 0.85

Calls 5

CubemapMipChainFunction · 0.85
PushFramebufferMethod · 0.80
returnTextureMethod · 0.80
PopFramebufferMethod · 0.80
getWidthMethod · 0.45

Tested by

no test coverage detected