[Bf-blender-cvs] SVN commit: /data/svn/bf-blender [28832] branches/soc-2010-moguri: Adding support for Text datablocks for shaders.
Mitchell Stokes
mogurijin at gmail.com
Tue May 18 17:02:40 CEST 2010
Revision: 28832
http://projects.blender.org/plugins/scmsvn/viewcvs.php?view=rev&root=bf-blender&revision=28832
Author: moguri
Date: 2010-05-18 17:02:39 +0200 (Tue, 18 May 2010)
Log Message:
-----------
Adding support for Text datablocks for shaders. Currently, the use of external files overrides the Text datablocks. I'll be adding a toggle for this.
Modified Paths:
--------------
branches/soc-2010-moguri/release/scripts/ui/properties_material.py
branches/soc-2010-moguri/source/blender/blenkernel/intern/material.c
branches/soc-2010-moguri/source/blender/blenloader/intern/readfile.c
branches/soc-2010-moguri/source/blender/blenloader/intern/writefile.c
branches/soc-2010-moguri/source/blender/gpu/intern/gpu_codegen.c
branches/soc-2010-moguri/source/blender/gpu/intern/gpu_material.c
branches/soc-2010-moguri/source/blender/makesdna/DNA_material_types.h
branches/soc-2010-moguri/source/blender/makesrna/intern/rna_material.c
Modified: branches/soc-2010-moguri/release/scripts/ui/properties_material.py
===================================================================
--- branches/soc-2010-moguri/release/scripts/ui/properties_material.py 2010-05-18 14:57:56 UTC (rev 28831)
+++ branches/soc-2010-moguri/release/scripts/ui/properties_material.py 2010-05-18 15:02:39 UTC (rev 28832)
@@ -788,10 +788,13 @@
col = layout.column()
mat = active_node_mat(context.material)
+
+ col.prop(mat, "vertex_text")
+ col.prop(mat, "fragment_text")
- col.prop(mat, "vertex_shader", text="Vertex Shader")
- col.prop(mat, "geometry_shader", text="Geometry Shader")
- col.prop(mat, "fragment_shader", text="Fragment Shader")
+ col.prop(mat, "vertex_shader")
+ col.prop(mat, "geometry_shader")
+ col.prop(mat, "fragment_shader")
class VolumeButtonsPanel(bpy.types.Panel):
bl_space_type = 'PROPERTIES'
Modified: branches/soc-2010-moguri/source/blender/blenkernel/intern/material.c
===================================================================
--- branches/soc-2010-moguri/source/blender/blenkernel/intern/material.c 2010-05-18 14:57:56 UTC (rev 28831)
+++ branches/soc-2010-moguri/source/blender/blenkernel/intern/material.c 2010-05-18 15:02:39 UTC (rev 28832)
@@ -85,6 +85,10 @@
if(ma->ramp_col) MEM_freeN(ma->ramp_col);
if(ma->ramp_spec) MEM_freeN(ma->ramp_spec);
+
+ if(ma->vert_text) MEM_freeN(ma->vert_text);
+ if(ma->frag_text) MEM_freeN(ma->frag_text);
+ if(ma->geom_text) MEM_freeN(ma->geom_text);
BKE_free_animdata((ID *)ma);
Modified: branches/soc-2010-moguri/source/blender/blenloader/intern/readfile.c
===================================================================
--- branches/soc-2010-moguri/source/blender/blenloader/intern/readfile.c 2010-05-18 14:57:56 UTC (rev 28831)
+++ branches/soc-2010-moguri/source/blender/blenloader/intern/readfile.c 2010-05-18 15:02:39 UTC (rev 28832)
@@ -2895,6 +2895,10 @@
ma->ramp_col= newdataadr(fd, ma->ramp_col);
ma->ramp_spec= newdataadr(fd, ma->ramp_spec);
+
+ ma->vert_text= newlibadr_us(fd, ma->id.lib, ma->vert_text);
+ ma->frag_text= newlibadr_us(fd, ma->id.lib, ma->frag_text);
+ ma->geom_text= newlibadr_us(fd, ma->id.lib, ma->geom_text);
ma->nodetree= newdataadr(fd, ma->nodetree);
if(ma->nodetree)
Modified: branches/soc-2010-moguri/source/blender/blenloader/intern/writefile.c
===================================================================
--- branches/soc-2010-moguri/source/blender/blenloader/intern/writefile.c 2010-05-18 14:57:56 UTC (rev 28831)
+++ branches/soc-2010-moguri/source/blender/blenloader/intern/writefile.c 2010-05-18 15:02:39 UTC (rev 28832)
@@ -1694,6 +1694,10 @@
if(ma->ramp_col) writestruct(wd, DATA, "ColorBand", 1, ma->ramp_col);
if(ma->ramp_spec) writestruct(wd, DATA, "ColorBand", 1, ma->ramp_spec);
+
+ if(ma->vert_text) writestruct(wd, DATA, "Text", 1, ma->vert_text);
+ if(ma->frag_text) writestruct(wd, DATA, "Text", 1, ma->frag_text);
+ if(ma->geom_text) writestruct(wd, DATA, "Text", 1, ma->geom_text);
/* nodetree is integral part of material, no libdata */
if(ma->nodetree) {
Modified: branches/soc-2010-moguri/source/blender/gpu/intern/gpu_codegen.c
===================================================================
--- branches/soc-2010-moguri/source/blender/gpu/intern/gpu_codegen.c 2010-05-18 14:57:56 UTC (rev 28831)
+++ branches/soc-2010-moguri/source/blender/gpu/intern/gpu_codegen.c 2010-05-18 15:02:39 UTC (rev 28832)
@@ -1437,15 +1437,7 @@
/* generate code and compile with opengl */
if (frag)
- {
- fragmentcode = load_shader(frag);
- if (fragmentcode == NULL)
- {
- printf("Error opening fragment shader\n");
- fragmentcode = code_generate_fragment(nodes, outlink->output, name);
- libcode = datatoc_gpu_shader_material_glsl;
- }
- }
+ fragmentcode = frag;
else
{
fragmentcode = code_generate_fragment(nodes, outlink->output, name);
@@ -1453,26 +1445,12 @@
}
if (vert)
- {
- vertexcode = load_shader(vert);
- if (vertexcode == NULL)
- {
- printf("Error opening vertex shader\n");
- vertexcode = code_generate_vertex(nodes);
- }
- }
+ vertexcode = vert;
else
vertexcode = code_generate_vertex(nodes);
if (geom)
- {
- geometrycode = load_shader(geom);
- if (geometrycode == NULL)
- {
- printf("Error opening geometry shader\n");
- geometrycode = NULL;
- }
- }
+ geometrycode = geom;
else
geometrycode = NULL;
Modified: branches/soc-2010-moguri/source/blender/gpu/intern/gpu_material.c
===================================================================
--- branches/soc-2010-moguri/source/blender/gpu/intern/gpu_material.c 2010-05-18 14:57:56 UTC (rev 28831)
+++ branches/soc-2010-moguri/source/blender/gpu/intern/gpu_material.c 2010-05-18 15:02:39 UTC (rev 28832)
@@ -52,6 +52,7 @@
#include "BKE_node.h"
#include "BKE_scene.h"
#include "BKE_texture.h"
+#include "BKE_text.h"
#include "BKE_utildefines.h"
#include "BLI_math.h"
@@ -182,17 +183,83 @@
attribs->totlayer = b;
}
+char *gpu_load_shader(char *filename)
+{
+ FILE *fp;
+ int len;
+ char *shader = NULL;
+ fp = fopen(filename, "r");
+
+ if (fp)
+ {
+ // Find the size
+ fseek(fp, 0, SEEK_END);
+ len = ftell(fp);
+ rewind(fp);
+
+ // Initialize the string and read the files
+ shader = MEM_callocN(len, "shader_text");
+ fread(shader, 1, len, fp);
+
+ // Close the file
+ fclose(fp);
+ }
+
+ return shader;
+}
+
static int GPU_material_construct_end(GPUMaterial *material)
{
if (material->outlink) {
GPUNodeLink *outlink;
GPUShader *shader;
+ char *frag=NULL, *vert=NULL, *geom=NULL;
+ // Gather information on custom shaders
+ if (strcmp(material->ma->vertex_shader, ""))
+ {
+ vert = gpu_load_shader(material->ma->vertex_shader);
+
+ if (!vert)
+ printf("Error opening vertex shader\n");
+ }
+ else if (material->ma->vert_text)
+ {
+ vert = txt_to_buf(material->ma->vert_text);
+
+ if (!vert)
+ printf("Error?\n");
+ }
+
+
+ if (strcmp(material->ma->fragment_shader, ""))
+ {
+ frag = gpu_load_shader(material->ma->fragment_shader);
+
+ if (!frag)
+ printf("Error opening fragment shader\n");
+ }
+ else if (material->ma->frag_text)
+ {
+ frag = txt_to_buf(material->ma->frag_text);
+
+ if (!frag)
+ printf("Error?\n");
+ }
+
+ if (strcmp(material->ma->geometry_shader, ""))
+ {
+ geom = gpu_load_shader(material->ma->geometry_shader);
+
+ if (!geom)
+ printf("Error opening geometry shader\n");
+ }
+
outlink = material->outlink;
material->pass = GPU_generate_pass(&material->nodes, outlink,
&material->attribs, &material->builtins, material->ma->id.name,
- material->ma->vertex_shader, material->ma->fragment_shader, material->ma->geometry_shader);
+ vert, frag, geom);
if(!material->pass)
return 0;
Modified: branches/soc-2010-moguri/source/blender/makesdna/DNA_material_types.h
===================================================================
--- branches/soc-2010-moguri/source/blender/makesdna/DNA_material_types.h 2010-05-18 14:57:56 UTC (rev 28831)
+++ branches/soc-2010-moguri/source/blender/makesdna/DNA_material_types.h 2010-05-18 15:02:39 UTC (rev 28832)
@@ -133,6 +133,10 @@
char vertex_shader[64];
char fragment_shader[64];
char geometry_shader[64];
+
+ struct Text *vert_text;
+ struct Text *frag_text;
+ struct Text *geom_text;
/* ramp colors */
struct ColorBand *ramp_col;
Modified: branches/soc-2010-moguri/source/blender/makesrna/intern/rna_material.c
===================================================================
--- branches/soc-2010-moguri/source/blender/makesrna/intern/rna_material.c 2010-05-18 14:57:56 UTC (rev 28831)
+++ branches/soc-2010-moguri/source/blender/makesrna/intern/rna_material.c 2010-05-18 15:02:39 UTC (rev 28832)
@@ -1508,6 +1508,20 @@
RNA_def_property_enum_funcs(prop, NULL, "rna_Material_type_set", NULL);
RNA_def_property_update(prop, 0, "rna_Material_draw_update");
+ prop= RNA_def_property(srna, "vertex_text", PROP_POINTER, PROP_NONE);
+ RNA_def_property_pointer_sdna(prop, NULL, "vert_text");
+ RNA_def_property_struct_type(prop, "Text");
+ RNA_def_property_flag(prop, PROP_EDITABLE);
+ RNA_def_property_ui_text(prop, "Vertex Shader", "A custom GLSL vertex shader in a text block");
+ RNA_def_property_update(prop, 0, "rna_Material_update");
+
+ prop= RNA_def_property(srna, "fragment_text", PROP_POINTER, PROP_NONE);
+ RNA_def_property_pointer_sdna(prop, NULL, "frag_text");
+ RNA_def_property_struct_type(prop, "Text");
+ RNA_def_property_flag(prop, PROP_EDITABLE);
+ RNA_def_property_ui_text(prop, "Fragment Shader", "A custom GLSL fragment shader in a text block");
+ RNA_def_property_update(prop, 0, "rna_Material_update");
+
prop= RNA_def_property(srna, "fragment_shader", PROP_STRING, PROP_NONE);
RNA_def_property_string_sdna(prop, NULL, "fragment_shader");
RNA_def_property_ui_text(prop, "Fragement Shader", "A custom GLSL fragment shader to use");
More information about the Bf-blender-cvs
mailing list