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

Method DrawCubeMap

Source/Main/engine.cpp:3308–3368  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

3306}
3307
3308void Engine::DrawCubeMap(TextureRef cube_map, const vec3& pos, GLuint cube_map_fbo, SceneGraph::SceneDrawType scene_draw_type) {
3309 GLuint cube_map_tex_id = Textures::Instance()->returnTexture(cube_map);
3310 Graphics* graphics = Graphics::Instance();
3311 CHECK_GL_ERROR();
3312 // TODO: Why do we have to render the first one twice? Some state is messed up
3313 for (int temp_i = -1; temp_i < 6; ++temp_i) {
3314 PROFILER_GPU_ZONE(g_profiler_ctx, "Draw cubemap face")
3315 int i = max(0, temp_i);
3316 graphics->startDraw(vec2(0.0f, 0.0f), vec2(128.0f, 128.0f), Graphics::kTexture);
3317 ActiveCameras::Set(1);
3318 CHECK_GL_ERROR();
3319 ActiveCameras::Get()->SetFlags(Camera::kPreviewCamera);
3320 // Apply camera object settings to camera
3321 Camera* camera = ActiveCameras::Instance()->Get();
3322 CHECK_GL_ERROR();
3323 // Set camera position
3324 camera->SetPos(pos);
3325 // Set camera euler angles from rotation matrix
3326 mat4 rot = GetCubeMapRotation(i);
3327 vec3 front = rot * vec3(0, 0, 1);
3328 vec3 up = rot * vec3(0, 1, 0);
3329 vec3 expected_right = normalize(cross(front, vec3(0, 1, 0)));
3330 vec3 expected_up = normalize(cross(expected_right, front));
3331 float cam[3];
3332 cam[0] = asinf(front[1]) * -180.0f / PI_f;
3333 cam[1] = atan2f(front[0], front[2]) * 180.0f / PI_f;
3334 cam[2] = atan2f(dot(up, expected_right), dot(up, expected_up)) * 180.0f / PI_f;
3335 // Set rotation twice so we don't have to worry about interpolation
3336 camera->SetXRotation(cam[0]);
3337 camera->SetXRotation(cam[0]);
3338 camera->SetYRotation(cam[1]);
3339 camera->SetYRotation(cam[1]);
3340 camera->SetZRotation(cam[2]);
3341 camera->SetZRotation(cam[2]);
3342 // Force true 90 degree fov
3343 camera->flexible_fov = false;
3344 camera->SetFOV(90.0f);
3345 camera->SetDistance(0.0f);
3346 // Draw view
3347 CHECK_GL_ERROR();
3348 DrawScene(kViewport, Engine::kStraight, SceneGraph::kStaticOnly);
3349 CHECK_GL_ERROR();
3350 scenegraph_->level->Draw();
3351
3352 graphics->PushFramebuffer();
3353 glBindFramebuffer(GL_FRAMEBUFFER, cube_map_fbo);
3354 CHECK_GL_ERROR();
3355 glFramebufferTexture2D(GL_FRAMEBUFFER, GL_COLOR_ATTACHMENT0, GL_TEXTURE_CUBE_MAP_POSITIVE_X + i, cube_map_tex_id, 0);
3356 CHECK_GL_ERROR();
3357 glBindFramebuffer(GL_READ_FRAMEBUFFER, graphics->framebuffer);
3358 CHECK_GL_ERROR();
3359 glBindFramebuffer(GL_DRAW_FRAMEBUFFER, cube_map_fbo);
3360 CHECK_GL_ERROR();
3361 glBlitFramebuffer(0, 0, 128, 128, 0, 0, 128, 128, GL_COLOR_BUFFER_BIT, GL_NEAREST);
3362 CHECK_GL_ERROR();
3363 graphics->PopFramebuffer();
3364
3365 camera->flexible_fov = true;

Callers

nothing calls this directly

Calls 15

maxFunction · 0.85
GetCubeMapRotationFunction · 0.85
returnTextureMethod · 0.80
startDrawMethod · 0.80
SetXRotationMethod · 0.80
SetYRotationMethod · 0.80
SetZRotationMethod · 0.80
SetFOVMethod · 0.80
SetDistanceMethod · 0.80
PushFramebufferMethod · 0.80
PopFramebufferMethod · 0.80
vec2Class · 0.50

Tested by

no test coverage detected