[Bf-blender-cvs] [570d6e8] cycles-ptex-12: Simplify some of the Ptex GLSL drawing code

Nicholas Bishop noreply at git.blender.org
Mon Jan 26 02:05:04 CET 2015


Commit: 570d6e8739aa8ee55e5044718b64c4cc06275cc9
Author: Nicholas Bishop
Date:   Thu Jan 22 14:17:22 2015 +0100
Branches: cycles-ptex-12
https://developer.blender.org/rB570d6e8739aa8ee55e5044718b64c4cc06275cc9

Simplify some of the Ptex GLSL drawing code

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

M	source/blender/gpu/GPU_extensions.h
M	source/blender/gpu/intern/gpu_codegen.c
M	source/blender/gpu/intern/gpu_draw.c
M	source/blender/gpu/intern/gpu_extensions.c
M	source/blender/makesdna/DNA_image_types.h

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

diff --git a/source/blender/gpu/GPU_extensions.h b/source/blender/gpu/GPU_extensions.h
index bb0cf2d..262399d 100644
--- a/source/blender/gpu/GPU_extensions.h
+++ b/source/blender/gpu/GPU_extensions.h
@@ -112,6 +112,9 @@ GPUTexture *GPU_texture_create_2D(int w, int h, float *pixels, char err_out[256]
 GPUTexture *GPU_texture_create_3D(int w, int h, int depth, int channels, float *fpixels);
 GPUTexture *GPU_texture_create_depth(int w, int h, char err_out[256]);
 GPUTexture *GPU_texture_create_vsm_shadow_map(int size, char err_out[256]);
+	// TODO
+GPUTexture *GPU_ptex_texture_from_blender(struct Image *ima,
+	struct ImageUser *iuser);
 GPUTexture *GPU_texture_from_blender(struct Image *ima,
 	struct ImageUser *iuser, bool is_data, double time, int mipmap);
 GPUTexture *GPU_texture_from_preview(struct PreviewImage *prv, int mipmap);
diff --git a/source/blender/gpu/intern/gpu_codegen.c b/source/blender/gpu/intern/gpu_codegen.c
index 6d5fe6d..786f710 100644
--- a/source/blender/gpu/intern/gpu_codegen.c
+++ b/source/blender/gpu/intern/gpu_codegen.c
@@ -52,9 +52,7 @@
 
 #include "BKE_customdata.h"
 #include "BKE_DerivedMesh.h"
-#include "BKE_image.h"
-#include "IMB_imbuf_types.h"
-#include "IMB_imbuf.h"
+#include "BKE_ptex.h"
 
 #include "gpu_codegen.h"
 
@@ -827,39 +825,27 @@ void GPU_pass_bind(GPUPass *pass, double time, int mipmap,
 	GPUShader *shader = pass->shader;
 	ListBase *inputs = &pass->inputs;
 
-	DerivedMesh *dm = (ob && ob->derivedFinal) ? ob->derivedFinal : NULL;
-
 	if (!shader)
 		return;
 
 	GPU_shader_bind(shader);
 
-	// TODO
+	// TODO: putting this here for now so that texture creation
+	// doesn't screw up bindings
 	for (input=inputs->first; input; input=input->next) {
 		if (input->ptex != 0) {
-			ImBuf *imbuf = NULL;
-
-			MTessFacePtex *ptex = CustomData_get_layer(&dm->faceData,
-													   CD_TESSFACE_PTEX);
-
-			if (ptex) {
-				imbuf = ptex[0].imbuf;
-			}
-			
-			input->tex = 0;
-			if (input->ptex == 1 && imbuf) {
-				char err[256];
-				IMB_float_from_rect(imbuf);
-				input->tex = GPU_texture_create_2D(imbuf->x,
-												   imbuf->y,
-												   (float*)imbuf->rect_float,
-												   err);
-			}
-			else if (input->ptex == 2 && imbuf) {
-				input->tex =
-					GPU_texture_create_1D_float(imbuf->num_ptex_coords,
-												(float*)imbuf->ptex_coords,
-												NULL);
+			// TODO: will pass a layer index or name here
+			Image *image = BKE_ptex_mesh_image_get(ob);
+			input->tex = NULL;
+			if (image) {
+				if (input->ptex == 1) {
+					input->tex = GPU_texture_from_blender(image,
+														  NULL, false,
+														  time, false);
+				}
+				else if (input->ptex == 2) {
+					input->tex = GPU_ptex_texture_from_blender(image, NULL);
+				}
 			}
 		}
 	}
diff --git a/source/blender/gpu/intern/gpu_draw.c b/source/blender/gpu/intern/gpu_draw.c
index 500b53c..c63d0d0 100644
--- a/source/blender/gpu/intern/gpu_draw.c
+++ b/source/blender/gpu/intern/gpu_draw.c
@@ -1288,6 +1288,11 @@ void GPU_free_image(Image *ima)
 		ima->gputexture= NULL;
 	}
 
+	if (ima->ptex_gputexture) {
+		GPU_texture_free(ima->ptex_gputexture);
+		ima->ptex_gputexture= NULL;
+	}
+
 	/* free repeated image binding */
 	if (ima->repbind) {
 		glDeleteTextures(ima->totbind, (GLuint *)ima->repbind);
diff --git a/source/blender/gpu/intern/gpu_extensions.c b/source/blender/gpu/intern/gpu_extensions.c
index a6b711f..d106edf 100644
--- a/source/blender/gpu/intern/gpu_extensions.c
+++ b/source/blender/gpu/intern/gpu_extensions.c
@@ -49,6 +49,10 @@
 #include "GPU_extensions.h"
 #include "GPU_simple_shader.h"
 
+// TODO
+#include "BKE_image.h"
+#include "IMB_imbuf_types.h"
+
 #include "intern/gpu_extensions_private.h"
 
 #include <stdlib.h>
@@ -698,6 +702,38 @@ GPUTexture *GPU_texture_create_vsm_shadow_map(int size, char err_out[256])
 	return tex;
 }
 
+// Very TODO, the code in this file could use a bit of a scrub
+GPUTexture *GPU_ptex_texture_from_blender(Image *ima, ImageUser *UNUSED(iuser))
+{
+
+	ImBuf *ibuf;
+	GPUTexture *tex;
+	int size;
+	float *data;
+	void *lock;
+
+	ibuf = BKE_image_acquire_ibuf(ima, NULL, &lock);
+	if (!ibuf) return NULL;
+
+	size = ibuf->num_ptex_coords;
+	data = (float*)ibuf->ptex_coords;
+
+	tex = GPU_texture_create_nD(size, 1, 2, NULL, 0, NULL);
+
+	if (tex) {
+		/* Now we tweak some of the settings */
+		/* glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_CLAMP_TO_EDGE); */
+		/* glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_CLAMP_TO_EDGE); */
+		glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA32F, size, 1, 0, GL_RGBA, GL_FLOAT, data);
+
+		GPU_texture_unbind(tex);
+	}
+
+	BKE_image_release_ibuf(ima, ibuf, lock);
+
+	return tex;
+}
+
 void GPU_invalid_tex_init(void)
 {
 	float color[4] = {1.0f, 0.0f, 1.0f, 1.0};
diff --git a/source/blender/makesdna/DNA_image_types.h b/source/blender/makesdna/DNA_image_types.h
index fcb894c..01b5377 100644
--- a/source/blender/makesdna/DNA_image_types.h
+++ b/source/blender/makesdna/DNA_image_types.h
@@ -81,6 +81,7 @@ typedef struct Image {
 	
 	struct MovieCache *cache;	/* not written in file */
 	struct GPUTexture *gputexture;	/* not written in file */
+	struct GPUTexture *ptex_gputexture;	/* not written in file */
 	
 	/* sources from: */
 	struct anim *anim;




More information about the Bf-blender-cvs mailing list