Welcome to mirror list, hosted at ThFree Co, Russian Federation.

git.blender.org/blender.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorBrecht Van Lommel <brechtvanlommel@pandora.be>2011-10-28 20:57:06 +0400
committerBrecht Van Lommel <brechtvanlommel@pandora.be>2011-10-28 20:57:06 +0400
commited77c356fc1c323cef306fef2e7af03fd67a6871 (patch)
treebf7c31d131d6fc65030c3bcf9940469c8450813e /source/blender/gpu
parent7627a742ab6e630522186b04a71fa40533d87db2 (diff)
Fix: OpenGL renders on graphics cards which do not support non-power-of-two
textures were stretched and the wrong size.
Diffstat (limited to 'source/blender/gpu')
-rw-r--r--source/blender/gpu/GPU_extensions.h5
-rw-r--r--source/blender/gpu/intern/gpu_extensions.c29
-rw-r--r--source/blender/gpu/intern/gpu_material.c3
3 files changed, 22 insertions, 15 deletions
diff --git a/source/blender/gpu/GPU_extensions.h b/source/blender/gpu/GPU_extensions.h
index 965f317aa50..3fff79390e3 100644
--- a/source/blender/gpu/GPU_extensions.h
+++ b/source/blender/gpu/GPU_extensions.h
@@ -136,7 +136,7 @@ int GPU_texture_opengl_bindcode(GPUTexture *tex);
GPUFrameBuffer *GPU_framebuffer_create(void);
int GPU_framebuffer_texture_attach(GPUFrameBuffer *fb, GPUTexture *tex, char err_out[256]);
void GPU_framebuffer_texture_detach(GPUFrameBuffer *fb, GPUTexture *tex);
-void GPU_framebuffer_texture_bind(GPUFrameBuffer *fb, GPUTexture *tex);
+void GPU_framebuffer_texture_bind(GPUFrameBuffer *fb, GPUTexture *tex, int w, int h);
void GPU_framebuffer_texture_unbind(GPUFrameBuffer *fb, GPUTexture *tex);
void GPU_framebuffer_free(GPUFrameBuffer *fb);
@@ -146,10 +146,11 @@ void GPU_framebuffer_restore(void);
- wrapper around framebuffer and texture for simple offscreen drawing
- changes size if graphics card can't support it */
-GPUOffScreen *GPU_offscreen_create(int *width, int *height, char err_out[256]);
+GPUOffScreen *GPU_offscreen_create(int width, int height, char err_out[256]);
void GPU_offscreen_free(GPUOffScreen *ofs);
void GPU_offscreen_bind(GPUOffScreen *ofs);
void GPU_offscreen_unbind(GPUOffScreen *ofs);
+void GPU_offscreen_read_pixels(GPUOffScreen *ofs, int type, void *pixels);
/* GPU Shader
- only for fragment shaders now
diff --git a/source/blender/gpu/intern/gpu_extensions.c b/source/blender/gpu/intern/gpu_extensions.c
index 6189062a855..e1a89daf7e2 100644
--- a/source/blender/gpu/intern/gpu_extensions.c
+++ b/source/blender/gpu/intern/gpu_extensions.c
@@ -790,7 +790,7 @@ void GPU_framebuffer_texture_detach(GPUFrameBuffer *fb, GPUTexture *tex)
tex->fb = NULL;
}
-void GPU_framebuffer_texture_bind(GPUFrameBuffer *UNUSED(fb), GPUTexture *tex)
+void GPU_framebuffer_texture_bind(GPUFrameBuffer *UNUSED(fb), GPUTexture *tex, int w, int h)
{
/* push attributes */
glPushAttrib(GL_ENABLE_BIT);
@@ -801,7 +801,7 @@ void GPU_framebuffer_texture_bind(GPUFrameBuffer *UNUSED(fb), GPUTexture *tex)
glBindFramebufferEXT(GL_FRAMEBUFFER_EXT, tex->fb->object);
/* push matrices and set default viewport and matrix */
- glViewport(0, 0, tex->w, tex->h);
+ glViewport(0, 0, w, h);
GG.currentfb = tex->fb->object;
glMatrixMode(GL_PROJECTION);
@@ -859,13 +859,19 @@ 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])
+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) {
@@ -873,24 +879,18 @@ GPUOffScreen *GPU_offscreen_create(int *width, int *height, char err_out[256])
return NULL;
}
- ofs->depth = GPU_texture_create_depth(*width, *height, err_out);
+ ofs->depth = GPU_texture_create_depth(width, height, err_out);
if(!ofs->depth) {
GPU_offscreen_free(ofs);
return NULL;
}
- if(*width!=ofs->depth->w || *height!=ofs->depth->h) {
- *width= ofs->depth->w;
- *height= ofs->depth->h;
- printf("Offscreen size differs from given size!\n");
- }
-
if(!GPU_framebuffer_texture_attach(ofs->fb, ofs->depth, err_out)) {
GPU_offscreen_free(ofs);
return NULL;
}
- ofs->color = GPU_texture_create_2D(*width, *height, NULL, err_out);
+ ofs->color = GPU_texture_create_2D(width, height, NULL, err_out);
if(!ofs->color) {
GPU_offscreen_free(ofs);
return NULL;
@@ -921,7 +921,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);
+ GPU_framebuffer_texture_bind(ofs->fb, ofs->color, ofs->w, ofs->h);
}
void GPU_offscreen_unbind(GPUOffScreen *ofs)
@@ -931,6 +931,11 @@ void GPU_offscreen_unbind(GPUOffScreen *ofs)
glEnable(GL_SCISSOR_TEST);
}
+void GPU_offscreen_read_pixels(GPUOffScreen *ofs, int type, void *pixels)
+{
+ glReadPixels(0, 0, ofs->w, ofs->h, GL_RGBA, type, pixels);
+}
+
/* GPUShader */
struct GPUShader {
diff --git a/source/blender/gpu/intern/gpu_material.c b/source/blender/gpu/intern/gpu_material.c
index d0f834977c8..26c08f6cae5 100644
--- a/source/blender/gpu/intern/gpu_material.c
+++ b/source/blender/gpu/intern/gpu_material.c
@@ -1661,7 +1661,8 @@ void GPU_lamp_shadow_buffer_bind(GPULamp *lamp, float viewmat[][4], int *winsize
/* opengl */
glDisable(GL_SCISSOR_TEST);
- GPU_framebuffer_texture_bind(lamp->fb, lamp->tex);
+ GPU_framebuffer_texture_bind(lamp->fb, lamp->tex,
+ GPU_texture_opengl_width(lamp->tex), GPU_texture_opengl_height(lamp->tex));
/* set matrices */
copy_m4_m4(viewmat, lamp->viewmat);