| 4155 | } |
| 4156 | |
| 4157 | void ReadAverageColorsFromCubemap(vec3* avg_color, TextureRef cubemap) { |
| 4158 | Graphics* graphics = Graphics::Instance(); |
| 4159 | for (int i = 0; i < 6; ++i) { |
| 4160 | static GLuint cube_map_read_fbo = UINT_MAX; |
| 4161 | graphics->PushFramebuffer(); |
| 4162 | if (cube_map_read_fbo == UINT_MAX) { |
| 4163 | graphics->genFramebuffers(&cube_map_read_fbo, "cube_map_read_fbo"); |
| 4164 | } |
| 4165 | graphics->bindFramebuffer(cube_map_read_fbo); |
| 4166 | glFramebufferTexture2D(GL_FRAMEBUFFER, GL_COLOR_ATTACHMENT0, GL_TEXTURE_CUBE_MAP_POSITIVE_X + i, Textures::Instance()->returnTexture(cubemap), 5); |
| 4167 | GLfloat pixels[4 * 4 * 3]; |
| 4168 | glReadBuffer(GL_COLOR_ATTACHMENT0); |
| 4169 | { |
| 4170 | PROFILER_ZONE_STALL(g_profiler_ctx, "Read pixels") |
| 4171 | glReadPixels(0, 0, 4, 4, GL_RGB, GL_FLOAT, (GLfloat*)pixels); |
| 4172 | } |
| 4173 | if (ISNAN(pixels[0])) { |
| 4174 | LOGE << "Light probe read fail" << std::endl; |
| 4175 | LOGE << "cube_map_read_fbo: " << cube_map_read_fbo << std::endl; |
| 4176 | LOGE << "scenegraph_->light_probe_collection.cube_map.id: " << cubemap.id << std::endl; |
| 4177 | LOGE << "pixels[0]: " << pixels[0] << std::endl; |
| 4178 | glFramebufferTexture2D(GL_FRAMEBUFFER, GL_COLOR_ATTACHMENT0, GL_TEXTURE_CUBE_MAP_POSITIVE_X + i, Textures::Instance()->returnTexture(cubemap), 5); |
| 4179 | glReadBuffer(GL_COLOR_ATTACHMENT0); |
| 4180 | { |
| 4181 | PROFILER_ZONE_STALL(g_profiler_ctx, "Read pixels") |
| 4182 | glFramebufferTexture2D(GL_FRAMEBUFFER, GL_COLOR_ATTACHMENT0, GL_TEXTURE_CUBE_MAP_POSITIVE_X + i, Textures::Instance()->returnTexture(cubemap), 4); |
| 4183 | glReadPixels(0, 0, 4, 4, GL_RGB, GL_FLOAT, (GLfloat*)pixels); |
| 4184 | } |
| 4185 | LOGE << "pixels[0]: " << pixels[0] << std::endl; |
| 4186 | } |
| 4187 | LOG_ASSERT(!ISNAN(pixels[0])); |
| 4188 | // Get average of centermost pixels |
| 4189 | avg_color[i] = vec3(0.0f); |
| 4190 | for (int j = 0, index = 0; j < 16; ++j, index += 3) { |
| 4191 | if (j / 4 > 0 && j / 4 < 3 && j % 4 > 0 && j % 4 < 3) { |
| 4192 | avg_color[i] += vec3(pixels[index + 0], pixels[index + 1], pixels[index + 2]) / 4.0f; |
| 4193 | } |
| 4194 | } |
| 4195 | graphics->PopFramebuffer(); |
| 4196 | } |
| 4197 | } |
| 4198 | |
| 4199 | extern int num_detail_object_draw_calls; |
| 4200 |
no test coverage detected