Commit: 7bc964b4f994ed7a672dd5fd905b29a587ef9eb0
Author: Nicholas Bishop
Date:   Mon Jan 19 20:03:59 2015 +0100
Branches: cycles-ptex-49
https://developer.blender.org/rB7bc964b4f994ed7a672dd5fd905b29a587ef9eb0

Add Ptex infrastructure to GPU module

- Function to upload the Ptex face mapping data texture

- Add Ptex to GPUNodeLink

- Pass in object when binding material, used to get at Ptex layer data

- Add Ptex utility functions to the GLSL shader

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

M       source/blender/gpu/GPU_extensions.h
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_draw.c
M       source/blender/gpu/intern/gpu_extensions.c
M       source/blender/gpu/intern/gpu_material.c
M       source/blender/gpu/shaders/gpu_shader_material.glsl

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

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/GPU_material.h 
b/source/blender/gpu/GPU_material.h
index 64ce936..42ff566 100644
--- a/source/blender/gpu/GPU_material.h
+++ b/source/blender/gpu/GPU_material.h
@@ -105,6 +105,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,
@@ -155,6 +160,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_node_link_ptex(GPUPtexInputType ptex, const char *layer_name, 
struct Image *image);
 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);
@@ -178,7 +184,7 @@ void GPU_material_free(struct ListBase *gpumaterial);
 void GPU_materials_free(void);
 
 bool GPU_lamp_override_visible(GPULamp *lamp, struct SceneRenderLayer *srl, 
struct Material *ma);
-void GPU_material_bind(GPUMaterial *material, int oblay, int viewlay, double 
time, int mipmap, float viewmat[4][4], float viewinv[4][4], float 
cameraborder[4], bool scenelock);
+void GPU_material_bind(GPUMaterial *material, int oblay, int viewlay, double 
time, int mipmap, float viewmat[4][4], float viewinv[4][4], float 
cameraborder[4], bool scenelock, struct Object *ob);
 void GPU_material_bind_uniforms(GPUMaterial *material, float obmat[4][4], 
float obcol[4], float autobumpscale);
 void GPU_material_unbind(GPUMaterial *material);
 int GPU_material_bound(GPUMaterial *material);
diff --git a/source/blender/gpu/intern/gpu_codegen.c 
b/source/blender/gpu/intern/gpu_codegen.c
index 97064f4..553980d 100644
--- a/source/blender/gpu/intern/gpu_codegen.c
+++ b/source/blender/gpu/intern/gpu_codegen.c
@@ -38,6 +38,7 @@
 #include "DNA_customdata_types.h"
 #include "DNA_image_types.h"
 #include "DNA_material_types.h"
+#include "DNA_object_types.h"
 
 #include "BLI_blenlib.h"
 #include "BLI_utildefines.h"
@@ -49,6 +50,10 @@
 
 #include "BLI_sys_types.h" // for intptr_t support
 
+#include "BKE_customdata.h"
+#include "BKE_DerivedMesh.h"
+#include "BKE_ptex.h"
+
 #include "gpu_codegen.h"
 
 #include <string.h>
@@ -359,7 +364,7 @@ static int codegen_input_has_texture(GPUInput *input)
 {
        if (input->link)
                return 0;
-       else if (input->ima || input->prv)
+       else if (input->ima || input->prv || input->ptex)
                return 1;
        else
                return input->tex != NULL;
@@ -433,6 +438,11 @@ static void codegen_set_unique_ids(ListBase *nodes)
                                        /* input is texture from buffer */
                                        codegen_set_texid(bindhash, input, 
&texid, input->link);
                                }
+                               else if (input->ptex) {
+                                       // TODO
+                                       input->texid = texid++;
+                                       input->bindtex = 1;
+                               }
                                else if (input->ima) {
                                        /* input is texture from image */
                                        codegen_set_texid(bindhash, input, 
&texid, input->ima);
@@ -780,7 +790,7 @@ static void gpu_nodes_extract_dynamic_inputs(GPUPass *pass, 
ListBase *nodes)
                                continue;
                        }
 
-                       if (input->ima || input->tex || input->prv)
+                       if (input->ima || input->tex || input->prv || 
input->ptex)
                                BLI_snprintf(input->shadername, 
sizeof(input->shadername), "samp%d", input->texid);
                        else
                                BLI_snprintf(input->shadername, 
sizeof(input->shadername), "unf%d", input->id);
@@ -788,7 +798,7 @@ static void gpu_nodes_extract_dynamic_inputs(GPUPass *pass, 
ListBase *nodes)
                        /* pass non-dynamic uniforms to opengl */
                        extract = 0;
 
-                       if (input->ima || input->tex || input->prv) {
+                       if (input->ima || input->tex || input->prv || 
input->ptex) {
                                if (input->bindtex)
                                        extract = 1;
                        }
@@ -809,7 +819,9 @@ static void gpu_nodes_extract_dynamic_inputs(GPUPass *pass, 
ListBase *nodes)
        GPU_shader_unbind();
 }
 
-void GPU_pass_bind(GPUPass *pass, double time, int mipmap)
+void GPU_pass_bind(GPUPass *pass, double time, int mipmap,
+                                  // TODO
+                                  Object *ob)
 {
        GPUInput *input;
        GPUShader *shader = pass->shader;
@@ -820,6 +832,28 @@ void GPU_pass_bind(GPUPass *pass, double time, int mipmap)
 
        GPU_shader_bind(shader);
 
+       // 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 != GPU_PTEX_INPUT_NONE) {
+                       // TODO
+                       Image *image = (input->ptex_image ?
+                                                       input->ptex_image :
+                                                       
BKE_ptex_mesh_image_get(ob, input->attribname));
+                       input->tex = NULL;
+                       if (image) {
+                               if (input->ptex == GPU_PTEX_INPUT_IMAGE) {
+                                       input->tex = 
GPU_texture_from_blender(image,
+                                                                               
                                  NULL, false,
+                                                                               
                                  time, false);
+                               }
+                               else if (input->ptex == GPU_PTEX_INPUT_MAP) {
+                                       input->tex = 
GPU_ptex_texture_from_blender(image, NULL);
+                               }
+                       }
+               }
+       }
+
        /* now bind the textures */
        for (input=inputs->first; input; input=input->next) {
                if (input->ima)
@@ -846,7 +880,7 @@ void GPU_pass_update_uniforms(GPUPass *pass)
 
        /* pass dynamic inputs to opengl, others were removed */
        for (input=inputs->first; input; input=input->next)
-               if (!(input->ima || input->tex || input->prv))
+               if (!(input->ima || input->tex || input->prv || input->ptex))
                        GPU_shader_uniform_vector(shader, input->shaderloc, 
input->type, 1,
                                input->dynamicvec);
 }
@@ -864,7 +898,7 @@ void GPU_pass_unbind(GPUPass *pass)
                if (input->tex && input->bindtex)
                        GPU_texture_unbind(input->tex);
 
-               if (input->ima || input->prv)
+               if (input->ima || input->prv || input->ptex)
                        input->tex = NULL;
        }
        
@@ -994,6 +1028,18 @@ static void gpu_node_input_link(GPUNode *node, 
GPUNodeLink *link, const GPUType
                input->textype = GPU_TEX2D;
                MEM_freeN(link);
        }
+       else if (link->ptex) {
+               input->type = GPU_VEC4;
+               input->source = GPU_SOURCE_TEX;
+               input->ptex = link->ptex;
+               input->textarget = GL_TEXTURE_2D;
+               input->textype = GPU_TEX2D;
+               if (link->attribname) {
+                       BLI_strncpy(input->attribname, link->attribname, 
sizeof(input->attribname));
+               }
+               input->ptex_image = link->ptr1;
+               MEM_freeN(link);
+       }
        else if (link->attribtype) {
                /* vertex attribute */
                input->type = type;
@@ -1196,6 +1242,20 @@ GPUNodeLink *GPU_image(Image *ima, ImageUser *iuser, 
bool is_data)
        return link;
 }
 
+// TODO
+GPUNodeLink *GPU_node_link_ptex(const GPUPtexInputType ptex,
+                                                               const char 
*layer_name,
+                                                               Image *image)
+{
+       GPUNodeLink *link = GPU_node_link_create();
+
+       link->ptex = ptex;
+       link->attribname = layer_name;
+       link->ptr1 = image;
+
+       return link;
+}
+
 GPUNodeLink *GPU_image_preview(PreviewImage *prv)
 {
        GPUNodeLink *link = GPU_node_link_create();
diff --git a/source/blender/gpu/intern/gpu_codegen.h 
b/source/blender/gpu/intern/gpu_codegen.h
index a6da5e0..14bc1bd 100644
--- a/source/blender/gpu/intern/gpu_codegen.h
+++ b/source/blender/gpu/intern/gpu_codegen.h
@@ -101,6 +101,8 @@ struct GPUNodeLink {
        /* Refcount */
        int users;
 
+       GPUPtexInputType ptex;
+
        struct GPUTexture *dynamictex;
 
        GPUBuiltin builtin;
@@ -153,6 +155,8 @@ typedef struct GPUInput {
        int attribfirst;                /* this is the first one that is bound 
*/
        GPUBuiltin builtin;             /* builtin uniform */
        GPUOpenGLBuiltin oglbuiltin; /* opengl built in varying */
+       GPUPtexInputType ptex;
+       struct Image *ptex_image;
 } GPUInput;
 
 struct GPUPass {
@@ -175,7 +179,9 @@ GPUPass *GPU_generate_pass(ListBase *nodes, struct 
GPUNodeLink *outlink,
 
 struct GPUShader *GPU_pass_shader(GPUPass *pass);
 
-void GPU_pass_bind(GPUPass *pass, double time, int mipmap);
+void GPU_pass_bind(GPUPass *pass, double time, int mipmap,
+                                  // TODO
+                                  struct Object *ob);
 void GPU_pass_update_uniforms(GPUPass *pass);
 void GPU_pass_unbind(GPUPass *pass);
 
diff --git a/source/blender/gpu/intern/gpu_draw.c 
b/source/blender/gpu/intern/gpu_draw.c
index 4a93fba..b025d35 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);
@@ -1652,7 +1657,7 @@ int GPU_enable_material(int nr, void *attribs)
 
                        gpumat = GPU_material_from_blender(GMS.gscene, mat);
                        GPU_material_vertex_attributes(gpumat, gattribs);
-                       GPU_material_bind(gpumat, GMS.gob->lay, GMS.glay, 1.0, 
!(GMS.gob->mode & OB_MODE_TEXTURE_PAINT), GMS.gviewmat, GMS.gviewinv, 
GMS.gviewcamtexcofac, GMS.gscenelock);
+                       GPU_material_bind(gpumat, GMS.gob->lay, GMS.glay, 1.0, 
!(GMS.gob->mode & OB_MODE_TEXTURE_PAINT), GMS.gviewmat, GMS.gviewinv, 
GMS.gviewcamtexcofac, GMS.gscenelock, GMS.gob);
 
                        auto_bump_scale = GMS.gob->derivedFinal != NULL ? 
GMS.gob->derivedFinal->auto_bump_scale : 1.0f;
                        GPU_material_bind_uniforms(gpumat, GMS.gob->obmat, 
GMS.gob->col, auto_bump_scale);
diff --git a/source/blender/gpu/intern/gpu_extensions.c 
b/source/blender/gpu/intern/gpu_extensions.c
index a6b711f..ba92e40 100644
--- a/source/blender/gpu/intern/gpu_extensions.c
+++ b/source/blender/gpu/intern/gpu_extensions.c
@@ -49,6 +49,10 @@
 

@@ Diff output truncated at 10240 characters. @@

_______________________________________________
Bf-blender-cvs mailing list
[email protected]
http://lists.blender.org/mailman/listinfo/bf-blender-cvs

Reply via email to