From b6459105b47526cd33851d4e00740fbd9d050ea4 Mon Sep 17 00:00:00 2001 From: Brecht Van Lommel Date: Wed, 28 Oct 2009 18:03:04 +0000 Subject: OpenGL Render restored. I tried to make it integrate more with regular render but couldn't do it well, it still needs a 3D view to take the settings from, and can't run in a separate thread due to OpenGL. However, it is now rendering to an offscreen buffer which then gets displayed in the image window. This requires FBO's to be available, so a fallback creating a new window is still needed. Currently available from the Render menu in the top header. --- source/blender/gpu/GPU_extensions.h | 11 +++++ source/blender/gpu/intern/gpu_extensions.c | 74 +++++++++++++++++++++++++++++- source/blender/gpu/intern/gpu_material.c | 2 + 3 files changed, 86 insertions(+), 1 deletion(-) (limited to 'source/blender/gpu') 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) -- cgit v1.2.3