[Bf-blender-cvs] [af2e898] cycles-ptex-24: Code cleanup: GPU ptex node

Nicholas Bishop noreply at git.blender.org
Fri Jan 30 18:00:54 CET 2015


Commit: af2e8980cc8da5b2713d514ec2201c196d9af1af
Author: Nicholas Bishop
Date:   Wed Jan 28 20:53:58 2015 +0100
Branches: cycles-ptex-24
https://developer.blender.org/rBaf2e8980cc8da5b2713d514ec2201c196d9af1af

Code cleanup: GPU ptex node

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

M	source/blender/gpu/GPU_material.h
M	source/blender/gpu/intern/gpu_codegen.c
M	source/blender/gpu/intern/gpu_codegen.h
M	source/blender/gpu/intern/gpu_extensions.c
M	source/blender/nodes/shader/nodes/node_shader_tex_ptex.c

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

diff --git a/source/blender/gpu/GPU_material.h b/source/blender/gpu/GPU_material.h
index bc71964..049041e 100644
--- a/source/blender/gpu/GPU_material.h
+++ b/source/blender/gpu/GPU_material.h
@@ -104,6 +104,11 @@ typedef enum GPUMatType {
 	GPU_MATERIAL_TYPE_WORLD = 2,	
 } GPUMatType;
 
+typedef enum {
+	GPU_PTEX_INPUT_NONE = 0,
+	GPU_PTEX_INPUT_IMAGE,
+	GPU_PTEX_INPUT_MAP
+} GPUPtexInputType;
 
 typedef enum GPUBlendMode {
 	GPU_BLEND_SOLID = 0,
@@ -154,7 +159,7 @@ GPUNodeLink *GPU_attribute(CustomDataType type, const char *name);
 GPUNodeLink *GPU_uniform(float *num);
 GPUNodeLink *GPU_dynamic_uniform(float *num, GPUDynamicType dynamictype, void *data);
 GPUNodeLink *GPU_image(struct Image *ima, struct ImageUser *iuser, bool is_data);
-GPUNodeLink *GPU_ptex(int ptex);
+GPUNodeLink *GPU_node_link_ptex(GPUPtexInputType ptex, const char *layer_name);
 GPUNodeLink *GPU_image_preview(struct PreviewImage *prv);
 GPUNodeLink *GPU_texture(int size, float *pixels);
 GPUNodeLink *GPU_dynamic_texture(struct GPUTexture *tex, GPUDynamicType dynamictype, void *data);
diff --git a/source/blender/gpu/intern/gpu_codegen.c b/source/blender/gpu/intern/gpu_codegen.c
index e35ed15..2bc449b 100644
--- a/source/blender/gpu/intern/gpu_codegen.c
+++ b/source/blender/gpu/intern/gpu_codegen.c
@@ -833,17 +833,17 @@ void GPU_pass_bind(GPUPass *pass, double time, int mipmap,
 	// 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) {
-			// TODO: will pass a layer index or name here
-			Image *image = BKE_ptex_mesh_image_get(ob);
+		if (input->ptex != GPU_PTEX_INPUT_NONE) {
+			// TODO
+			Image *image = BKE_ptex_mesh_image_get(ob, input->attribname);
 			input->tex = NULL;
 			if (image) {
-				if (input->ptex == 1) {
+				if (input->ptex == GPU_PTEX_INPUT_IMAGE) {
 					input->tex = GPU_texture_from_blender(image,
 														  NULL, false,
 														  time, false);
 				}
-				else if (input->ptex == 2) {
+				else if (input->ptex == GPU_PTEX_INPUT_MAP) {
 					input->tex = GPU_ptex_texture_from_blender(image, NULL);
 				}
 			}
@@ -1030,6 +1030,7 @@ static void gpu_node_input_link(GPUNode *node, GPUNodeLink *link, const GPUType
 		input->ptex = link->ptex;
 		input->textarget = GL_TEXTURE_2D;
 		input->textype = GPU_TEX2D;
+		BLI_strncpy(input->attribname, link->attribname, sizeof(input->attribname));
 		MEM_freeN(link);
 	}
 	else if (link->attribtype) {
@@ -1235,11 +1236,13 @@ GPUNodeLink *GPU_image(Image *ima, ImageUser *iuser, bool is_data)
 }
 
 // TODO
-GPUNodeLink *GPU_ptex(int ptex)
+GPUNodeLink *GPU_node_link_ptex(const GPUPtexInputType ptex,
+								const char *layer_name)
 {
 	GPUNodeLink *link = GPU_node_link_create();
 
 	link->ptex = ptex;
+	link->attribname = layer_name;
 
 	return link;
 }
diff --git a/source/blender/gpu/intern/gpu_codegen.h b/source/blender/gpu/intern/gpu_codegen.h
index a668962..683be77 100644
--- a/source/blender/gpu/intern/gpu_codegen.h
+++ b/source/blender/gpu/intern/gpu_codegen.h
@@ -101,8 +101,7 @@ struct GPUNodeLink {
 	/* Refcount */
 	int users;
 
-	// TODO
-	int ptex;
+	GPUPtexInputType ptex;
 
 	struct GPUTexture *dynamictex;
 
@@ -156,9 +155,7 @@ typedef struct GPUInput {
 	int attribfirst;		/* this is the first one that is bound */
 	GPUBuiltin builtin;		/* builtin uniform */
 	GPUOpenGLBuiltin oglbuiltin; /* opengl built in varying */
-
-	// TODO
-	int ptex;
+	GPUPtexInputType ptex;
 } GPUInput;
 
 struct GPUPass {
diff --git a/source/blender/gpu/intern/gpu_extensions.c b/source/blender/gpu/intern/gpu_extensions.c
index cbd17f4..ba92e40 100644
--- a/source/blender/gpu/intern/gpu_extensions.c
+++ b/source/blender/gpu/intern/gpu_extensions.c
@@ -709,7 +709,7 @@ GPUTexture *GPU_ptex_texture_from_blender(Image *ima, ImageUser *UNUSED(iuser))
 	ImBuf *ibuf;
 	GPUTexture *tex;
 	int size;
-	float *data;
+	ImPtexRegion *data;
 	void *lock;
 
 	if (ima->ptex_gputexture) {
@@ -719,8 +719,8 @@ GPUTexture *GPU_ptex_texture_from_blender(Image *ima, ImageUser *UNUSED(iuser))
 	ibuf = BKE_image_acquire_ibuf(ima, NULL, &lock);
 	if (!ibuf) return NULL;
 
-	size = ibuf->num_ptex_coords;
-	data = (float*)ibuf->ptex_coords;
+	size = ibuf->num_ptex_regions;
+	data = ibuf->ptex_regions;
 
 	tex = GPU_texture_create_nD(size, 1, 2, NULL, 0, NULL);
 	ima->ptex_gputexture = tex;
@@ -729,7 +729,17 @@ GPUTexture *GPU_ptex_texture_from_blender(Image *ima, ImageUser *UNUSED(iuser))
 		/* 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);
+		// TODO
+		float (*tmp)[4] = MEM_mallocN(sizeof(*tmp) * size, "tmp");
+		int i;
+		for (i = 0; i < size; i++) {
+			tmp[i][0] = data[i].x;
+			tmp[i][1] = data[i].y;
+			tmp[i][2] = data[i].width;
+			tmp[i][3] = data[i].height;
+		}
+		glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA32F, size, 1, 0, GL_RGBA, GL_FLOAT, tmp);
+		MEM_freeN(tmp);
 
 		GPU_texture_unbind(tex);
 	}
diff --git a/source/blender/nodes/shader/nodes/node_shader_tex_ptex.c b/source/blender/nodes/shader/nodes/node_shader_tex_ptex.c
index fe755cb..35039d1 100644
--- a/source/blender/nodes/shader/nodes/node_shader_tex_ptex.c
+++ b/source/blender/nodes/shader/nodes/node_shader_tex_ptex.c
@@ -33,16 +33,20 @@ static bNodeSocketTemplate sh_node_tex_ptex_out[] = {
 	{	-1, 0, ""	}
 };
 
-static int node_shader_gpu_tex_ptex(GPUMaterial *mat, bNode *UNUSED(node),
+static int node_shader_gpu_tex_ptex(GPUMaterial *mat, bNode *node,
 									bNodeExecData *UNUSED(execdata),
 									GPUNodeStack *in, GPUNodeStack *out)
 {
+	const NodeTexPtex *storage = node->storage;
+
 	if (!in[0].link)
 		in[0].link = GPU_attribute(CD_TESSFACE_PTEX, "");
 
 	return GPU_stack_link(mat, "node_tex_ptex", in, out,
-						  GPU_ptex(1),
-						  GPU_ptex(2));
+						  GPU_node_link_ptex(GPU_PTEX_INPUT_IMAGE,
+											 storage->layer_name),
+						  GPU_node_link_ptex(GPU_PTEX_INPUT_MAP,
+											 storage->layer_name));
 }
 
 static void node_shader_init_tex_ptex(bNodeTree *UNUSED(ntree), bNode *node)




More information about the Bf-blender-cvs mailing list