[Bf-blender-cvs] SVN commit: /data/svn/bf-blender [49013] branches/ge_harmony/source/blender : Shader datablocks are now saving and loading smoother.
Daniel Stokes
kupomail at gmail.com
Wed Jul 18 07:40:25 CEST 2012
Revision: 49013
http://projects.blender.org/scm/viewvc.php?view=rev&root=bf-blender&revision=49013
Author: kupoman
Date: 2012-07-18 05:40:24 +0000 (Wed, 18 Jul 2012)
Log Message:
-----------
Shader datablocks are now saving and loading smoother. Loading and saving Uniforms still needs some work, but the uniforms in general need work.
Modified Paths:
--------------
branches/ge_harmony/source/blender/blenkernel/intern/shader.c
branches/ge_harmony/source/blender/blenloader/intern/readfile.c
branches/ge_harmony/source/blender/blenloader/intern/writefile.c
Modified: branches/ge_harmony/source/blender/blenkernel/intern/shader.c
===================================================================
--- branches/ge_harmony/source/blender/blenkernel/intern/shader.c 2012-07-18 03:56:42 UTC (rev 49012)
+++ branches/ge_harmony/source/blender/blenkernel/intern/shader.c 2012-07-18 05:40:24 UTC (rev 49013)
@@ -59,6 +59,8 @@
{
if (sh->source)
MEM_freeN(sh->source);
+
+ BLI_freelistN(&sh->uniforms);
}
struct Shader *BKE_shader_add(const char *name)
Modified: branches/ge_harmony/source/blender/blenloader/intern/readfile.c
===================================================================
--- branches/ge_harmony/source/blender/blenloader/intern/readfile.c 2012-07-18 03:56:42 UTC (rev 49012)
+++ branches/ge_harmony/source/blender/blenloader/intern/readfile.c 2012-07-18 05:40:24 UTC (rev 49013)
@@ -138,6 +138,7 @@
#include "BKE_scene.h"
#include "BKE_screen.h"
#include "BKE_sequencer.h"
+#include "BKE_shader.h"
#include "BKE_text.h" // for txt_extended_ascii_as_utf8
#include "BKE_tracking.h"
#include "BKE_utildefines.h" // SWITCH_INT DATA ENDB DNA1 O_BINARY GLOB USER TEST REND
@@ -3211,7 +3212,6 @@
Material *ma;
MTex *mtex;
CustomShader *cs;
- CustomUniform *cu;
int a;
for (ma = main->mat.first; ma; ma = ma->id.next) {
@@ -3236,22 +3236,9 @@
if (ma->nodetree)
lib_link_ntree(fd, &ma->id, ma->nodetree);
- cs = (CustomShader *)ma->custom_shaders.first;
- while (cs) {
- cs->shader->sourcetext = newlibadr(fd, ma->id.lib, cs->shader->sourcetext);
+ for (cs = ma->custom_shaders.first; cs; cs = cs->next)
+ cs->shader = newlibadr_us(fd, ma->id.lib, cs->shader);
- cu = cs->shader->uniforms.first;
-
- while(cu) {
- if(cu->type==MA_UNF_SAMPLER2D)
- cu->data= newlibadr(fd, ma->id.lib, cu->data);
-
- cu = cu->next;
- }
-
- cs = cs->next;
- }
-
ma->id.flag -= LIB_NEEDLINK;
}
}
@@ -3260,9 +3247,6 @@
static void direct_link_material(FileData *fd, Material *ma)
{
int a;
- CustomShader *cs;
- CustomUniform *cu;
-
ma->adt = newdataadr(fd, ma->adt);
direct_link_animdata(fd, ma->adt);
@@ -3270,25 +3254,9 @@
for (a = 0; a < MAX_MTEX; a++) {
ma->mtex[a] = newdataadr(fd, ma->mtex[a]);
}
- link_list(fd, &ma->csi.uniforms);
-
- cs = (CustomShader *)ma->custom_shaders.first;
- while (cs) {
- cu = (CustomUniform *)cs->shader->uniforms.first;
+ link_list(fd, &ma->custom_shaders);
- while(cu) {
- // Sampler2D is handled in lib_link, so only vec* and ivec* need special attention here
- if (cu->type != MA_UNF_FLOAT &&
- cu->type != MA_UNF_INT &&
- cu->type != MA_UNF_SAMPLER2D)
- cu->data= newdataadr(fd, cu->data);
-
- cu = cu->next;
- }
- cs = cs->next;
- }
-
ma->ramp_col = newdataadr(fd, ma->ramp_col);
ma->ramp_spec = newdataadr(fd, ma->ramp_spec);
@@ -3300,6 +3268,44 @@
ma->gpumaterial.first = ma->gpumaterial.last = NULL;
}
+/* ************ READ SHADER ***************** */
+static void lib_link_shader(FileData *fd, Main *main)
+{
+ Shader *sh;
+ Uniform *uni;
+ for (sh = main->shader.first; sh; sh = sh->id.next) {
+ if (sh->id.flag & LIB_NEEDLINK) {
+ /* Link ID Properties -- and copy this comment EXACTLY for easy finding
+ * of library blocks that implement this.*/
+ if (sh->id.properties) IDP_LibLinkProperty(sh->id.properties, (fd->flags & FD_FLAGS_SWITCH_ENDIAN), fd);
+
+ sh->sourcetext = newlibadr_us(fd, sh->id.lib, sh->sourcetext);
+ for (uni = sh->uniforms.first; uni; uni = uni->next) {
+ if(uni->type==MA_UNF_SAMPLER2D)
+ uni->data= newlibadr(fd, sh->id.lib, uni->data);
+ }
+
+ BKE_shader_read_source(sh);
+
+ sh->id.flag -= LIB_NEEDLINK;
+ }
+ }
+}
+
+static void direct_link_shader(FileData *fd, Shader *sh)
+{
+ Uniform *uni;
+
+ link_list(fd, &sh->uniforms);
+
+ for (uni = sh->uniforms.first; uni; uni = uni->next) {
+ if (uni->type != MA_UNF_FLOAT &&
+ uni->type != MA_UNF_INT &&
+ uni->type != MA_UNF_SAMPLER2D)
+ uni->data= newdataadr(fd, uni->data);
+ }
+}
+
/* ************ READ PARTICLE SETTINGS ***************** */
/* update this also to writefile.c */
static const char *ptcache_data_struct[] = {
@@ -6561,6 +6567,9 @@
case ID_MSK:
direct_link_mask(fd, (Mask *)id);
break;
+ case ID_SH:
+ direct_link_shader(fd, (Mask *)id);
+ break;
}
/*link direct data of ID properties*/
@@ -7846,6 +7855,7 @@
lib_link_curve(fd, main);
lib_link_mball(fd, main);
lib_link_material(fd, main);
+ lib_link_shader(fd, main);
lib_link_texture(fd, main);
lib_link_image(fd, main);
lib_link_ipo(fd, main); // XXX depreceated... still needs to be maintained for version patches still
@@ -8384,6 +8394,7 @@
static void expand_material(FileData *fd, Main *mainvar, Material *ma)
{
int a;
+ CustomShader *cs;
for (a = 0; a < MAX_MTEX; a++) {
if (ma->mtex[a]) {
@@ -8397,6 +8408,8 @@
/*expand_doit(fd, mainvar, ma->vert_text);
expand_doit(fd, mainvar, ma->frag_text);
expand_doit(fd, mainvar, ma->geom_text);*/
+ for (cs = ma->custom_shaders.first; cs; cs = cs->next)
+ expand_doit(fd, mainvar, cs->shader);
if (ma->adt)
expand_animdata(fd, mainvar, ma->adt);
Modified: branches/ge_harmony/source/blender/blenloader/intern/writefile.c
===================================================================
--- branches/ge_harmony/source/blender/blenloader/intern/writefile.c 2012-07-18 03:56:42 UTC (rev 49012)
+++ branches/ge_harmony/source/blender/blenloader/intern/writefile.c 2012-07-18 05:40:24 UTC (rev 49013)
@@ -1986,6 +1986,7 @@
static void write_materials(WriteData *wd, ListBase *idbase)
{
Material *ma;
+ CustomShader *cs;
int a;
ma= idbase->first;
@@ -2015,12 +2016,49 @@
write_nodetree(wd, ma->nodetree);
}
- write_previews(wd, ma->preview);
+ write_previews(wd, ma->preview);
+
+ for (cs = ma->custom_shaders.first; cs; cs = cs->next) {
+ writestruct(wd, DATA, "CustomShader", 1, cs);
+ writestruct(wd, DATA, "Shader", 1, cs->shader);
+ }
}
ma= ma->id.next;
}
}
+static void write_shaders(WriteData *wd, ListBase *idbase)
+{
+ Shader *sh;
+ Uniform *uni;
+
+ for (sh = idbase->first; sh; sh = sh->id.next) {
+ if (sh->id.us>0 || wd->current) {
+ /* write LibData */
+ writestruct(wd, ID_SH, "Shader", 1, sh);
+ writestruct(wd, ID_TXT, "Text", 1, sh->sourcetext);
+
+ for (uni = sh->uniforms.first; uni; uni = uni->next) {
+ writestruct(wd, DATA, "Uniform", 1, uni);
+ switch (uni->type)
+ {
+ case SHADER_UNF_VEC2:
+ case SHADER_UNF_VEC3:
+ case SHADER_UNF_VEC4:
+ writedata(wd, DATA, sizeof(float) * uni->size, uni->data);
+ break;
+ case SHADER_UNF_IVEC2:
+ case SHADER_UNF_IVEC3:
+ case SHADER_UNF_IVEC4:
+ writedata(wd, DATA, sizeof(int) * uni->size, uni->data);
+ break;
+ }
+ }
+ }
+ }
+
+}
+
static void write_worlds(WriteData *wd, ListBase *idbase)
{
World *wrld;
@@ -2916,6 +2954,7 @@
write_brushes (wd, &mainvar->brush);
write_scripts (wd, &mainvar->script);
write_gpencils (wd, &mainvar->gpencil);
+ write_shaders (wd, &mainvar->shader);
write_libraries(wd, mainvar->next);
if (write_user_block) {
More information about the Bf-blender-cvs
mailing list