diff options
author | Brecht Van Lommel <brechtvanlommel@pandora.be> | 2009-10-29 13:12:07 +0300 |
---|---|---|
committer | Brecht Van Lommel <brechtvanlommel@pandora.be> | 2009-10-29 13:12:07 +0300 |
commit | a365ccd20eac888417b63b173e168d3338a5a45b (patch) | |
tree | ac0006461cfaabe64719cf6e30fc7dc3e6286d1e /source/blender/gpu | |
parent | 7ce5c951c5bb3607cac2bc603ed9a1fbcc5299dd (diff) | |
parent | e14a8635cca97f339d28744624cf1284866bc63d (diff) |
Sculpt: svn merge https://svn.blender.org/svnroot/bf-blender/trunk/blender -r24095:24152
Diffstat (limited to 'source/blender/gpu')
-rw-r--r-- | source/blender/gpu/GPU_extensions.h | 11 | ||||
-rw-r--r-- | source/blender/gpu/intern/gpu_extensions.c | 74 | ||||
-rw-r--r-- | source/blender/gpu/intern/gpu_material.c | 2 |
3 files changed, 86 insertions, 1 deletions
diff --git a/source/blender/gpu/GPU_extensions.h b/source/blender/gpu/GPU_extensions.h index a910ff9c3e7..c2af4e8fcb1 100644 --- a/source/blender/gpu/GPU_extensions.h +++ b/source/blender/gpu/GPU_extensions.h @@ -48,6 +48,9 @@ typedef struct GPUTexture GPUTexture; struct GPUFrameBuffer; typedef struct GPUFrameBuffer GPUFrameBuffer; +struct GPUOffScreen; +typedef struct GPUOffScreen GPUOffScreen; + struct GPUShader; typedef struct GPUShader GPUShader; @@ -107,6 +110,14 @@ void GPU_framebuffer_free(GPUFrameBuffer *fb); void GPU_framebuffer_restore(); +/* GPU OffScreen + - wrapper around framebuffer and texture for simple offscreen drawing */ + +GPUOffScreen *GPU_offscreen_create(int width, int height); +void GPU_offscreen_free(GPUOffScreen *ofs); +void GPU_offscreen_bind(GPUOffScreen *ofs); +void GPU_offscreen_unbind(GPUOffScreen *ofs); + /* GPU Shader - only for fragment shaders now - must call texture bind before setting a texture as uniform! */ diff --git a/source/blender/gpu/intern/gpu_extensions.c b/source/blender/gpu/intern/gpu_extensions.c index 5c8157be789..5deef4a5200 100644 --- a/source/blender/gpu/intern/gpu_extensions.c +++ b/source/blender/gpu/intern/gpu_extensions.c @@ -616,7 +616,7 @@ int GPU_framebuffer_texture_attach(GPUFrameBuffer *fb, GPUTexture *tex) } else { glDrawBuffer(GL_COLOR_ATTACHMENT0_EXT); - glReadBuffer(GL_NONE); + glReadBuffer(GL_COLOR_ATTACHMENT0_EXT); } status = glCheckFramebufferStatusEXT(GL_FRAMEBUFFER_EXT); @@ -727,6 +727,78 @@ void GPU_framebuffer_restore() } } +/* GPUOffScreen */ + +struct GPUOffScreen { + GPUFrameBuffer *fb; + GPUTexture *color; + GPUTexture *depth; +}; + +GPUOffScreen *GPU_offscreen_create(int width, int height) +{ + GPUOffScreen *ofs; + + ofs= MEM_callocN(sizeof(GPUOffScreen), "GPUOffScreen"); + + ofs->fb = GPU_framebuffer_create(); + if(!ofs->fb) { + GPU_offscreen_free(ofs); + return NULL; + } + + ofs->depth = GPU_texture_create_depth(width, height); + if(!ofs->depth) { + GPU_offscreen_free(ofs); + return NULL; + } + + if(!GPU_framebuffer_texture_attach(ofs->fb, ofs->depth)) { + GPU_offscreen_free(ofs); + return NULL; + } + + ofs->color = GPU_texture_create_2D(width, height, NULL); + if(!ofs->color) { + GPU_offscreen_free(ofs); + return NULL; + } + + if(!GPU_framebuffer_texture_attach(ofs->fb, ofs->color)) { + GPU_offscreen_free(ofs); + return NULL; + } + + GPU_framebuffer_restore(); + + return ofs; +} + +void GPU_offscreen_free(GPUOffScreen *ofs) +{ + if(ofs->fb) + GPU_framebuffer_free(ofs->fb); + if(ofs->color) + GPU_texture_free(ofs->color); + if(ofs->depth) + GPU_texture_free(ofs->depth); + + MEM_freeN(ofs); +} + +void GPU_offscreen_bind(GPUOffScreen *ofs) +{ + glDisable(GL_SCISSOR_TEST); + GPU_framebuffer_texture_bind(ofs->fb, ofs->color); +} + +void GPU_offscreen_unbind(GPUOffScreen *ofs) +{ + GPU_framebuffer_texture_unbind(ofs->fb, ofs->color); + GPU_framebuffer_restore(); + glEnable(GL_SCISSOR_TEST); +} + /* GPUShader */ struct GPUShader { diff --git a/source/blender/gpu/intern/gpu_material.c b/source/blender/gpu/intern/gpu_material.c index 0dc17da93a1..0650a0bfa19 100644 --- a/source/blender/gpu/intern/gpu_material.c +++ b/source/blender/gpu/intern/gpu_material.c @@ -1509,6 +1509,7 @@ void GPU_lamp_shadow_buffer_bind(GPULamp *lamp, float viewmat[][4], int *winsize Mat4MulMat4(lamp->persmat, persmat, rangemat); /* opengl */ + glDisable(GL_SCISSOR_TEST); GPU_framebuffer_texture_bind(lamp->fb, lamp->tex); /* set matrices */ @@ -1521,6 +1522,7 @@ void GPU_lamp_shadow_buffer_unbind(GPULamp *lamp) { GPU_framebuffer_texture_unbind(lamp->fb, lamp->tex); GPU_framebuffer_restore(); + glEnable(GL_SCISSOR_TEST); } int GPU_lamp_shadow_layer(GPULamp *lamp) |