diff options
-rw-r--r-- | source/blender/gpu/GPU_extensions.h | 4 | ||||
-rw-r--r-- | source/blender/gpu/intern/gpu_extensions.c | 67 | ||||
-rw-r--r-- | source/blender/gpu/intern/gpu_material.c | 3 |
3 files changed, 48 insertions, 26 deletions
diff --git a/source/blender/gpu/GPU_extensions.h b/source/blender/gpu/GPU_extensions.h index 8ca7958d493..b2378f0dae6 100644 --- a/source/blender/gpu/GPU_extensions.h +++ b/source/blender/gpu/GPU_extensions.h @@ -140,10 +140,12 @@ int GPU_texture_opengl_bindcode(GPUTexture *tex); * - after any of the GPU_framebuffer_* functions, GPU_framebuffer_restore must * be called before rendering to the window framebuffer again */ +void GPU_texture_bind_as_framebuffer(GPUTexture *tex); + GPUFrameBuffer *GPU_framebuffer_create(void); int GPU_framebuffer_texture_attach(GPUFrameBuffer *fb, GPUTexture *tex, int slot, char err_out[256]); void GPU_framebuffer_texture_detach(GPUTexture *tex); -void GPU_framebuffer_texture_bind(GPUFrameBuffer *fb, GPUTexture *tex, int w, int h); +void GPU_framebuffer_slot_bind(GPUFrameBuffer *fb, int slot); void GPU_framebuffer_texture_unbind(GPUFrameBuffer *fb, GPUTexture *tex); void GPU_framebuffer_free(GPUFrameBuffer *fb); diff --git a/source/blender/gpu/intern/gpu_extensions.c b/source/blender/gpu/intern/gpu_extensions.c index ed1bbefa452..10a8783cf6a 100644 --- a/source/blender/gpu/intern/gpu_extensions.c +++ b/source/blender/gpu/intern/gpu_extensions.c @@ -906,16 +906,6 @@ int GPU_framebuffer_texture_attach(GPUFrameBuffer *fb, GPUTexture *tex, int slot return 0; } - if (tex->depth) { - glDrawBuffer(GL_NONE); - glReadBuffer(GL_NONE); - } - else { - /* last bound prevails here, better allow explicit control here too */ - glDrawBuffer(GL_COLOR_ATTACHMENT0_EXT + slot); - glReadBuffer(GL_COLOR_ATTACHMENT0_EXT + slot); - } - status = glCheckFramebufferStatusEXT(GL_FRAMEBUFFER_EXT); if (status != GL_FRAMEBUFFER_COMPLETE_EXT) { @@ -967,8 +957,13 @@ void GPU_framebuffer_texture_detach(GPUTexture *tex) tex->fb_attachment = -1; } -void GPU_framebuffer_texture_bind(GPUFrameBuffer *UNUSED(fb), GPUTexture *tex, int w, int h) +void GPU_texture_bind_as_framebuffer(GPUTexture *tex) { + if (!tex->fb) { + fprintf(stderr, "Error, texture not bound to framebuffer!"); + return; + } + /* push attributes */ glPushAttrib(GL_ENABLE_BIT | GL_VIEWPORT_BIT); glDisable(GL_SCISSOR_TEST); @@ -976,8 +971,12 @@ void GPU_framebuffer_texture_bind(GPUFrameBuffer *UNUSED(fb), GPUTexture *tex, i /* bind framebuffer */ glBindFramebufferEXT(GL_FRAMEBUFFER_EXT, tex->fb->object); + /* last bound prevails here, better allow explicit control here too */ + glDrawBuffer(GL_COLOR_ATTACHMENT0_EXT + tex->fb_attachment); + glReadBuffer(GL_COLOR_ATTACHMENT0_EXT + tex->fb_attachment); + /* push matrices and set default viewport and matrix */ - glViewport(0, 0, w, h); + glViewport(0, 0, tex->w, tex->h); GG.currentfb = tex->fb->object; glMatrixMode(GL_PROJECTION); @@ -986,6 +985,35 @@ void GPU_framebuffer_texture_bind(GPUFrameBuffer *UNUSED(fb), GPUTexture *tex, i glPushMatrix(); } +void GPU_framebuffer_slot_bind(GPUFrameBuffer *fb, int slot) +{ + if (!fb->colortex[slot]) { + fprintf(stderr, "Error, framebuffer slot empty!"); + return; + } + + /* push attributes */ + glPushAttrib(GL_ENABLE_BIT | GL_VIEWPORT_BIT); + glDisable(GL_SCISSOR_TEST); + + /* bind framebuffer */ + glBindFramebufferEXT(GL_FRAMEBUFFER_EXT, fb->object); + + /* last bound prevails here, better allow explicit control here too */ + glDrawBuffer(GL_COLOR_ATTACHMENT0_EXT + slot); + glReadBuffer(GL_COLOR_ATTACHMENT0_EXT + slot); + + /* push matrices and set default viewport and matrix */ + glViewport(0, 0, fb->colortex[slot]->w, fb->colortex[slot]->h); + GG.currentfb = fb->object; + + glMatrixMode(GL_PROJECTION); + glPushMatrix(); + glMatrixMode(GL_MODELVIEW); + glPushMatrix(); +} + + void GPU_framebuffer_texture_unbind(GPUFrameBuffer *UNUSED(fb), GPUTexture *UNUSED(tex)) { /* restore matrix */ @@ -996,7 +1024,6 @@ void GPU_framebuffer_texture_unbind(GPUFrameBuffer *UNUSED(fb), GPUTexture *UNUS /* restore attributes */ glPopAttrib(); - glEnable(GL_SCISSOR_TEST); } void GPU_framebuffer_free(GPUFrameBuffer *fb) @@ -1100,10 +1127,6 @@ struct GPUOffScreen { GPUFrameBuffer *fb; GPUTexture *color; GPUTexture *depth; - - /* requested width/height, may be smaller than actual texture size due - * to missing non-power of two support, so we compensate for that */ - int w, h; }; GPUOffScreen *GPU_offscreen_create(int width, int height, char err_out[256]) @@ -1111,8 +1134,6 @@ GPUOffScreen *GPU_offscreen_create(int width, int height, char err_out[256]) GPUOffScreen *ofs; ofs= MEM_callocN(sizeof(GPUOffScreen), "GPUOffScreen"); - ofs->w= width; - ofs->h= height; ofs->fb = GPU_framebuffer_create(); if (!ofs->fb) { @@ -1162,7 +1183,7 @@ void GPU_offscreen_free(GPUOffScreen *ofs) void GPU_offscreen_bind(GPUOffScreen *ofs) { glDisable(GL_SCISSOR_TEST); - GPU_framebuffer_texture_bind(ofs->fb, ofs->color, ofs->w, ofs->h); + GPU_texture_bind_as_framebuffer(ofs->color); } void GPU_offscreen_unbind(GPUOffScreen *ofs) @@ -1174,17 +1195,17 @@ void GPU_offscreen_unbind(GPUOffScreen *ofs) void GPU_offscreen_read_pixels(GPUOffScreen *ofs, int type, void *pixels) { - glReadPixels(0, 0, ofs->w, ofs->h, GL_RGBA, type, pixels); + glReadPixels(0, 0, ofs->color->w, ofs->color->h, GL_RGBA, type, pixels); } int GPU_offscreen_width(GPUOffScreen *ofs) { - return ofs->w; + return ofs->color->w; } int GPU_offscreen_height(GPUOffScreen *ofs) { - return ofs->h; + return ofs->color->h; } /* GPUShader */ diff --git a/source/blender/gpu/intern/gpu_material.c b/source/blender/gpu/intern/gpu_material.c index e4fa8a71742..d6244b4255b 100644 --- a/source/blender/gpu/intern/gpu_material.c +++ b/source/blender/gpu/intern/gpu_material.c @@ -1979,8 +1979,7 @@ void GPU_lamp_shadow_buffer_bind(GPULamp *lamp, float viewmat[4][4], int *winsiz /* opengl */ glDisable(GL_SCISSOR_TEST); - GPU_framebuffer_texture_bind(lamp->fb, lamp->tex, - GPU_texture_opengl_width(lamp->tex), GPU_texture_opengl_height(lamp->tex)); + GPU_texture_bind_as_framebuffer(lamp->tex); if (lamp->la->shadowmap_type == LA_SHADMAP_VARIANCE) GPU_shader_bind(GPU_shader_get_builtin_shader(GPU_SHADER_VSM_STORE)); |