Modified camera fbos to not create renderbuffers for color instead they always create texture

dev
Shariq Shah 9 years ago
parent 6909a1cda6
commit 8210ba663c
  1. 64
      src/camera.c
  2. 2
      src/game.c

@ -140,41 +140,47 @@ void camera_attach_fbo(struct Camera* camera,
log_error("camera:attach_fbo", "Camera already has fbo attached!"); log_error("camera:attach_fbo", "Camera already has fbo attached!");
return; return;
} }
camera->fbo = framebuffer_create(width, height, has_depth, has_color, resizeable); camera->fbo = framebuffer_create(width, height, has_depth, 0, resizeable);
if(camera->fbo > -1) if(camera->fbo > -1)
{ {
char tex_name[128]; char tex_name[128];
snprintf(tex_name, 128, "cam_render_tex_%d", camera->node); if(has_color)
camera->render_tex = texture_create(tex_name, {
TU_DIFFUSE, snprintf(tex_name, 128, "cam_render_tex_%d", camera->node);
width, height, camera->render_tex = texture_create(tex_name,
GL_RGBA, TU_DIFFUSE,
GL_RGBA8, width, height,
GL_UNSIGNED_BYTE, GL_RGBA,
NULL); GL_RGBA8,
texture_set_param(camera->render_tex, GL_TEXTURE_WRAP_S, GL_CLAMP_TO_EDGE); GL_UNSIGNED_BYTE,
texture_set_param(camera->render_tex, GL_TEXTURE_WRAP_T, GL_CLAMP_TO_EDGE); NULL);
texture_set_param(camera->render_tex, GL_TEXTURE_MIN_FILTER, GL_LINEAR); texture_set_param(camera->render_tex, GL_TEXTURE_WRAP_S, GL_CLAMP_TO_EDGE);
texture_set_param(camera->render_tex, GL_TEXTURE_MAG_FILTER, GL_LINEAR); texture_set_param(camera->render_tex, GL_TEXTURE_WRAP_T, GL_CLAMP_TO_EDGE);
texture_set_param(camera->render_tex, GL_TEXTURE_MIN_FILTER, GL_LINEAR);
texture_set_param(camera->render_tex, GL_TEXTURE_MAG_FILTER, GL_LINEAR);
framebuffer_set_texture(camera->fbo, camera->render_tex, FA_COLOR_ATTACHMENT0);
}
memset(tex_name, '\0', 128); memset(tex_name, '\0', 128);
snprintf(tex_name, 128, "cam_depth_tex_%d", camera->node);
camera->depth_tex = texture_create(tex_name,
TU_SHADOWMAP1,
width, height,
GL_DEPTH_COMPONENT,
GL_DEPTH_COMPONENT,
GL_UNSIGNED_BYTE,
NULL);
texture_set_param(camera->depth_tex, GL_TEXTURE_WRAP_S, GL_CLAMP_TO_EDGE);
texture_set_param(camera->depth_tex, GL_TEXTURE_WRAP_T, GL_CLAMP_TO_EDGE);
texture_set_param(camera->depth_tex, GL_TEXTURE_MIN_FILTER, GL_LINEAR);
texture_set_param(camera->depth_tex, GL_TEXTURE_MAG_FILTER, GL_LINEAR);
texture_set_param(camera->depth_tex, GL_TEXTURE_COMPARE_MODE, GL_COMPARE_REF_TO_TEXTURE);
texture_set_param(camera->depth_tex, GL_TEXTURE_COMPARE_FUNC, GL_LEQUAL);
framebuffer_set_texture(camera->fbo, camera->render_tex, FA_COLOR_ATTACHMENT0); if(has_depth)
framebuffer_set_texture(camera->fbo, camera->depth_tex, FA_DEPTH_ATTACHMENT); {
snprintf(tex_name, 128, "cam_depth_tex_%d", camera->node);
camera->depth_tex = texture_create(tex_name,
TU_SHADOWMAP1,
width, height,
GL_DEPTH_COMPONENT,
GL_DEPTH_COMPONENT,
GL_UNSIGNED_BYTE,
NULL);
texture_set_param(camera->depth_tex, GL_TEXTURE_WRAP_S, GL_CLAMP_TO_EDGE);
texture_set_param(camera->depth_tex, GL_TEXTURE_WRAP_T, GL_CLAMP_TO_EDGE);
texture_set_param(camera->depth_tex, GL_TEXTURE_MIN_FILTER, GL_LINEAR);
texture_set_param(camera->depth_tex, GL_TEXTURE_MAG_FILTER, GL_LINEAR);
texture_set_param(camera->depth_tex, GL_TEXTURE_COMPARE_MODE, GL_COMPARE_REF_TO_TEXTURE);
texture_set_param(camera->depth_tex, GL_TEXTURE_COMPARE_FUNC, GL_LEQUAL);
framebuffer_set_texture(camera->fbo, camera->depth_tex, FA_DEPTH_ATTACHMENT);
}
} }
else else
{ {

@ -102,7 +102,7 @@ void scene_setup(void)
render_width = 1024; render_width = 1024;
render_height = 768; render_height = 768;
struct Camera* camera = entity_component_add(player, C_CAMERA, render_width, render_height); struct Camera* camera = entity_component_add(player, C_CAMERA, render_width, render_height);
camera_attach_fbo(camera, render_width, render_height, 1, 0, 1); camera_attach_fbo(camera, render_width, render_height, 1, 1, 1);
vec4_fill(&camera->clear_color, 0.3f, 0.6f, 0.9f, 1.0f); vec4_fill(&camera->clear_color, 0.3f, 0.6f, 0.9f, 1.0f);
camera_set_primary_viewer(camera); camera_set_primary_viewer(camera);

Loading…
Cancel
Save