[Bf-blender-cvs] [3ae0126] master: GPUFramebuffer API cleanup:

Antony Riakiotakis noreply at git.blender.org
Tue Nov 18 12:38:52 CET 2014


Commit: 3ae0126f86a01803ba5955e5ec6f3ca6d614349a
Author: Antony Riakiotakis
Date:   Tue Nov 18 12:37:55 2014 +0100
Branches: master
https://developer.blender.org/rB3ae0126f86a01803ba5955e5ec6f3ca6d614349a

GPUFramebuffer API cleanup:

* read buffers are set at texture binding time
* change naming when setting a texture as framebuffer
* add function to set slot of framebuffer as current target instead of
texture.
* Binding a buffer reuses the dimensions of the texture at bind time
(can use viewport to set to arbitrary range later)
* Removed offscreen buffer width/height, use the generated texture
dimensions instead. Those were supposed to be checked to see if
generated texture had the requested size but were never actually changed
to the texture dimensions (and it's redundant to store twice).

===================================================================

M	source/blender/gpu/GPU_extensions.h
M	source/blender/gpu/intern/gpu_extensions.c
M	source/blender/gpu/intern/gpu_material.c

===================================================================

diff --git a/source/blender/gpu/GPU_extensions.h b/source/blender/gpu/GPU_extensions.h
index 8ca7958..b2378f0 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 ed1bbef..10a8783 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 e4fa8a7..d6244b4 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));




More information about the Bf-blender-cvs mailing list