[Bf-blender-cvs] SVN commit: /data/svn/bf-blender [11592] branches/soc-2007-maike/source/ blender: glsl basic texture code generation and respective generic functions concatenation
Miguel Torres Lima
torreslima at gmail.com
Tue Aug 14 17:46:27 CEST 2007
Revision: 11592
http://projects.blender.org/plugins/scmsvn/viewcvs.php?view=rev&root=bf-blender&revision=11592
Author: maike
Date: 2007-08-14 17:46:26 +0200 (Tue, 14 Aug 2007)
Log Message:
-----------
glsl basic texture code generation and respective generic functions concatenation
Modified Paths:
--------------
branches/soc-2007-maike/source/blender/include/BIF_glsl_texture_node.h
branches/soc-2007-maike/source/blender/src/glsl_texture.c
branches/soc-2007-maike/source/blender/src/glsl_texture_node.c
Modified: branches/soc-2007-maike/source/blender/include/BIF_glsl_texture_node.h
===================================================================
--- branches/soc-2007-maike/source/blender/include/BIF_glsl_texture_node.h 2007-08-14 15:44:29 UTC (rev 11591)
+++ branches/soc-2007-maike/source/blender/include/BIF_glsl_texture_node.h 2007-08-14 15:46:26 UTC (rev 11592)
@@ -1,3 +1,31 @@
+
+#define GLSL_TEX_CLOUDS 1
+#define GLSL_TEX_WOOD 2
+#define GLSL_TEX_MARBLE 4
+#define GLSL_TEX_MAGIC 8
+#define GLSL_TEX_BLEND 16
+#define GLSL_TEX_STUCCI 32
+#define GLSL_TEX_NOISE 64
+#define GLSL_TEX_IMAGE 128
+#define GLSL_TEX_PLUGIN 256
+#define GLSL_TEX_ENVMAP 512
+#define GLSL_TEX_MUSGRAVE 1024
+#define GLSL_TEX_VORONOI 2048
+#define GLSL_TEX_DISTNOISE 4096
+
+#define GLSL_MTEX_BLEND 1
+#define GLSL_MTEX_MUL 2
+#define GLSL_MTEX_ADD 4
+#define GLSL_MTEX_SUB 8
+#define GLSL_MTEX_DIV 16
+#define GLSL_MTEX_DARK 32
+#define GLSL_MTEX_DIFF 64
+#define GLSL_MTEX_LIGHT 128
+#define GLSL_MTEX_SCREEN 256
+#define GLSL_MTEX_OVERLAY 512
+
+/* ------------------------------------------------------------------------ */
+
struct Material;
struct GLSL_Material_;
struct GLSL_MaterialTree_;
@@ -3,9 +31,21 @@
struct GLSL_Texture_;
struct GLSL_NodeCode_;
+struct MTex;
+struct Tex;
/* ------------------------------------------------------------------------ */
struct GLSL_NodeCode_ *glsl_texture_vertex_code(struct GLSL_MaterialTree_ *tree);
-struct GLSL_NodeCode_ *glsl_texture_node(struct Material *mat, int num);
-char *glsl_texture_struct(struct GLSL_Material_ *material);
-char *glsl_texture_magic(struct GLSL_Texture_ *texture, struct GLSL_Material_ *material, int index);
+struct GLSL_NodeCode_ *glsl_texture_fragment_code(struct Material *mat, int num, int *tex_type, int *blend, int *blendval);
+char *glsl_texture_uniform_code(int num, int i, struct Tex *tex);
+char *glsl_texture_common_uniforms_code(int num, int i);
+char *glsl_texture_specific_uniforms_code(int num, int i, short type);
+char *glsl_texture_function_code(int num, int i, struct MTex *mtex, int *tex_type, int *blend, int *blendval);
+char *glsl_texture_function_defines(int num, int i, struct Tex *tex, int *tex_type);
+char *glsl_texture_mapto_defines(struct MTex *mtex, short *rgb_blend, short *normal_blend, short *val_blend);
+char *glsl_texture_factors_defines(int num, int i, short rgb_blend, short normal_blend, short val_blend);
+char *glsl_texture_blend_defines(struct MTex *mtex, short rgb_blend, short val_blend, int *blend, int *blendval);
+
+char *glsl_texture_funcs(int tex_type);
+char *glsl_texture_blend_funcs(int blend);
+char *glsl_texture_blendval_funcs(int blend);
Modified: branches/soc-2007-maike/source/blender/src/glsl_texture.c
===================================================================
--- branches/soc-2007-maike/source/blender/src/glsl_texture.c 2007-08-14 15:44:29 UTC (rev 11591)
+++ branches/soc-2007-maike/source/blender/src/glsl_texture.c 2007-08-14 15:46:26 UTC (rev 11592)
@@ -36,7 +36,9 @@
#include "butspace.h"
+
struct GHash *texHash = NULL;
+extern struct GHash *matHash;
@@ -97,77 +99,117 @@
void glsl_clear_texture(Material *mat, int index)
{
- printf("\nGLSL Texture cleared.\n");
+ GLSL_Material material = BLI_ghash_lookup(matHash, material);
+
+ if(material){
+ printf("\nGLSL Texture cleared.\n");
+ material->redo_prog(material);
+ }
}
void glsl_paste_texture(Material *mat, int index)
{
- printf("\nGLSL Texture paste.\n");
+ GLSL_Material material = BLI_ghash_lookup(matHash, mat);
+
+ if(material){
+ printf("\nGLSL Texture paste.\n");
+ material->redo_prog(material);
+ }
}
void glsl_set_texture_state(Material *mat, int index)
{
- printf("\nGLSL Texture activated/deactivated.\n");
+ GLSL_Material material = BLI_ghash_lookup(matHash, mat);
+
+ if(material){
+ printf("\nGLSL Texture activated/deactivated.\n");
+ material->redo_prog(material);
+ }
}
void glsl_add_texture(Material *mat, int index)
{
- printf("\nGLSL Texture added\n");
+ GLSL_Material material = BLI_ghash_lookup(matHash, mat);
+
+ if(material){
+ printf("\nGLSL Texture added.\n");
+ material->redo_prog(material);
+ }
}
void glsl_change_texture(Material *mat, int index)
{
- printf("\nGLSL Texture changed.\n");
+ GLSL_Material material = BLI_ghash_lookup(matHash, mat);
+
+ if(material){
+ printf("\nGLSL Texture changed.\n");
+ material->redo_prog(material);
+ }
}
void glsl_texture_mapto(Material *mat, int index, unsigned short event)
{
- switch(event)
- {
- case B_MAT_MAPTO_REWR:
- printf("\nGLSL Texture Mapping changed.\n");
- break;
- case B_MAT_MAPTO_UNIFS:
- printf("\nGLSL Texture Mapping Uniforms changed.\n");
- break;
- case B_MAT_MAPTO_BLEND:
- printf("\nGLSL Texture Blend mode changed.\n");
- break;
- }
+ GLSL_Material material = BLI_ghash_lookup(matHash, mat);
+
+ if(material){
+ switch(event)
+ {
+ case B_MAT_MAPTO_REWR:
+ printf("\nGLSL Texture Mapping changed.\n");
+ material->redo_prog(material);
+ break;
+ case B_MAT_MAPTO_UNIFS:
+ printf("\nGLSL Texture Mapping Uniforms changed.\n");
+ break;
+ case B_MAT_MAPTO_BLEND:
+ printf("\nGLSL Texture Blend mode changed.\n");
+ material->redo_prog(material);
+ break;
+ }
+ }
}
void glsl_texture_mapinput(Material *mat, int index, unsigned short event)
{
- switch(event)
- {
- case B_MAT_MAPIN_COORDS:
- printf("\nGLSL Texture Input Coords changed.\n");
- break;
- case B_MAT_MAPIN_MAP:
- printf("\nGLSL Texture Input Mapping changed.\n");
- break;
- case B_MAT_MAPIN_AXIS:
- printf("\nGLSL Texture Input Axis changed.\n");
- break;
- case B_MAT_MAPIN_OFS:
- printf("\nGLSL Texture Offset changed.\n");
- break;
- case B_MAT_MAPIN_SIZE:
- printf("\nGLSL Texture Size changed.\n");
- break;
+ GLSL_Material material = BLI_ghash_lookup(matHash, mat);
+
+ if(material){
+ switch(event)
+ {
+ case B_MAT_MAPIN_COORDS:
+ printf("\nGLSL Texture Input Coords changed.\n");
+ break;
+ case B_MAT_MAPIN_MAP:
+ printf("\nGLSL Texture Input Mapping changed.\n");
+ break;
+ case B_MAT_MAPIN_AXIS:
+ printf("\nGLSL Texture Input Axis changed.\n");
+ break;
+ case B_MAT_MAPIN_OFS:
+ printf("\nGLSL Texture Offset changed.\n");
+ break;
+ case B_MAT_MAPIN_SIZE:
+ printf("\nGLSL Texture Size changed.\n");
+ break;
}
+ }
}
void glsl_texture_type(Material *mat, int index)
{
- printf("\nGLSL Texture type changed.\n");
+ GLSL_Material material = BLI_ghash_lookup(matHash, mat);
+
+ if(material){
+ printf("\nGLSL Texture type changed.\n");
+ material->redo_prog(material);
+ }
}
@@ -176,13 +218,24 @@
printf("\nGLSL Texture value param changed.\n");
}
+
void glsl_texture_update_sel(Material *mat, int index)
{
- printf("\nGLSL Texture sel param changed.\n");
+ GLSL_Material material = BLI_ghash_lookup(matHash, mat);
+
+ if(material){
+ printf("\nGLSL Texture sel param changed.\n");
+ material->redo_prog(material);
+ }
}
void glsl_texture_update_list(Material *mat, int index)
{
- printf("\nGLSL Texture list param changed.\n");
+ GLSL_Material material = BLI_ghash_lookup(matHash, mat);
+
+ if(material){
+ printf("\nGLSL Texture list param changed.\n");
+ material->redo_prog(material);
+ }
}
Modified: branches/soc-2007-maike/source/blender/src/glsl_texture_node.c
===================================================================
--- branches/soc-2007-maike/source/blender/src/glsl_texture_node.c 2007-08-14 15:44:29 UTC (rev 11591)
+++ branches/soc-2007-maike/source/blender/src/glsl_texture_node.c 2007-08-14 15:46:26 UTC (rev 11592)
@@ -51,33 +51,37 @@
for(j = 0; j < MAX_MTEX; j++){
if(mat->mtex[j]){
- texture_node->uniform_code = glsl_string(6,
- GFREE, texture_node->uniform_code,
- 0, "attribute vec3 mat_",
- GINT, i,
- 0, "_tex_",
- GINT, j,
- 0, ";\n");
+ MTex *mtex = mat->mtex[j];
+
+ if(mtex->tex && mtex->tex->type){
+ texture_node->uniform_code = glsl_string(6,
+ GFREE, texture_node->uniform_code,
+ 0, "attribute vec3 mat_",
+ GINT, i,
+ 0, "_tex_",
+ GINT, j,
+ 0, ";\n");
- texture_node->uniform_code = glsl_string(6,
- GFREE, texture_node->uniform_code,
- 0, "varying vec3 mat_",
- GINT, i,
+ texture_node->uniform_code = glsl_string(6,
+ GFREE, texture_node->uniform_code,
+ 0, "varying vec3 mat_",
+ GINT, i,
0, "_tex_",
- GINT, j,
- 0, "_coords;\n");
-
- texture_node->main_code = glsl_string(10,
- GFREE, texture_node->main_code,
+ GINT, j,
+ 0, "_coords;\n");
+
+ texture_node->main_code = glsl_string(10,
+ GFREE, texture_node->main_code,
0, "mat_",
- GINT, i,
- 0, "_tex_",
- GINT, j,
+ GINT, i,
+ 0, "_tex_",
+ GINT, j,
0, "_coords = mat_",
- GINT, i,
- 0, "_tex_",
- GINT, j,
- 0, ";\n");
+ GINT, i,
+ 0, "_tex_",
+ GINT, j,
+ 0, ";\n");
+ }
}
}
}
@@ -89,19 +93,375 @@
}
-GLSL_NodeCode glsl_texture_node(Material *mat, int num)
+GLSL_NodeCode glsl_texture_fragment_code(Material *mat, int num, int *tex_type, int *blend, int *blendval)
{
+ GLSL_NodeCode texture_node = glsl_init_nodecode();
+ int i;
+ for(i = 0; i < MAX_MTEX; i++){
+ if(mat->mtex[i]){
+ MTex *mtex = mat->mtex[i];
+
+ if(mtex->tex && mtex->tex->type){
+ char *uniform_code = glsl_texture_uniform_code(num, i, mtex->tex);
+ char *func_code = glsl_texture_function_code(num, i, mtex, tex_type, blend, blendval);
+ texture_node->uniform_code = glsl_string(2, GFREE, texture_node->uniform_code, GFREE, uniform_code);
+ texture_node->node_code = glsl_string(2, GFREE, texture_node->node_code, GFREE, func_code);
+ }
+ }
+ }
+
+ return texture_node;
}
-char *glsl_texture_struct(GLSL_Material material)
+char *glsl_texture_uniform_code(int num, int i, Tex *tex)
{
+ char *code = NULL;
@@ Diff output truncated at 10240 characters. @@
More information about the Bf-blender-cvs
mailing list