[Bf-blender-cvs] SVN commit: /data/svn/bf-blender [16301] branches/apricot/source: Apricot Branch: better support for multiple scenes with glsl,
Brecht Van Lommel
brechtvanlommel at pandora.be
Fri Aug 29 15:23:38 CEST 2008
Revision: 16301
http://projects.blender.org/plugins/scmsvn/viewcvs.php?view=rev&root=bf-blender&revision=16301
Author: blendix
Date: 2008-08-29 15:23:33 +0200 (Fri, 29 Aug 2008)
Log Message:
-----------
Apricot Branch: better support for multiple scenes with glsl,
now it keeps shaders and lamps per scene.
Modified Paths:
--------------
branches/apricot/source/blender/blenkernel/intern/material.c
branches/apricot/source/blender/blenloader/intern/readfile.c
branches/apricot/source/blender/gpu/GPU_material.h
branches/apricot/source/blender/gpu/intern/gpu_codegen.c
branches/apricot/source/blender/gpu/intern/gpu_draw.c
branches/apricot/source/blender/gpu/intern/gpu_material.c
branches/apricot/source/blender/makesdna/DNA_material_types.h
branches/apricot/source/blender/src/drawscene.c
branches/apricot/source/blender/src/drawview.c
branches/apricot/source/blender/src/previewrender.c
branches/apricot/source/gameengine/Ketsji/BL_BlenderShader.cpp
branches/apricot/source/gameengine/Ketsji/KX_Light.cpp
branches/apricot/source/gameengine/Ketsji/KX_Light.h
Modified: branches/apricot/source/blender/blenkernel/intern/material.c
===================================================================
--- branches/apricot/source/blender/blenkernel/intern/material.c 2008-08-29 12:24:07 UTC (rev 16300)
+++ branches/apricot/source/blender/blenkernel/intern/material.c 2008-08-29 13:23:33 UTC (rev 16301)
@@ -99,7 +99,7 @@
MEM_freeN(ma->nodetree);
}
- if(ma->gpumaterial)
+ if(ma->gpumaterial.first)
GPU_material_free(ma);
}
@@ -213,7 +213,7 @@
man->nodetree= ntreeCopyTree(ma->nodetree, 0); /* 0 == full new tree */
}
- man->gpumaterial= NULL;
+ man->gpumaterial.first= man->gpumaterial.last= NULL;
return man;
}
Modified: branches/apricot/source/blender/blenloader/intern/readfile.c
===================================================================
--- branches/apricot/source/blender/blenloader/intern/readfile.c 2008-08-29 12:24:07 UTC (rev 16300)
+++ branches/apricot/source/blender/blenloader/intern/readfile.c 2008-08-29 13:23:33 UTC (rev 16301)
@@ -2562,7 +2562,7 @@
direct_link_nodetree(fd, ma->nodetree);
ma->preview = direct_link_preview_image(fd, ma->preview);
- ma->gpumaterial = NULL;
+ ma->gpumaterial.first = ma->gpumaterial.last = NULL;
}
/* ************ READ PARTICLE SETTINGS ***************** */
Modified: branches/apricot/source/blender/gpu/GPU_material.h
===================================================================
--- branches/apricot/source/blender/gpu/GPU_material.h 2008-08-29 12:24:07 UTC (rev 16300)
+++ branches/apricot/source/blender/gpu/GPU_material.h 2008-08-29 13:23:33 UTC (rev 16301)
@@ -119,7 +119,7 @@
/* High level functions to create and use GPU materials */
-int GPU_material_from_blender(struct Scene *scene, struct Material *ma);
+GPUMaterial *GPU_material_from_blender(struct Scene *scene, struct Material *ma);
void GPU_material_free(struct Material *ma);
void GPU_materials_free();
@@ -151,7 +151,7 @@
/* Lamps */
-GPULamp *GPU_lamp_from_blender(struct Object *ob, struct Object *par);
+GPULamp *GPU_lamp_from_blender(struct Scene *scene, struct Object *ob, struct Object *par);
void GPU_lamp_free(struct Object *ob);
int GPU_lamp_has_shadow_buffer(GPULamp *lamp);
Modified: branches/apricot/source/blender/gpu/intern/gpu_codegen.c
===================================================================
--- branches/apricot/source/blender/gpu/intern/gpu_codegen.c 2008-08-29 12:24:07 UTC (rev 16300)
+++ branches/apricot/source/blender/gpu/intern/gpu_codegen.c 2008-08-29 13:23:33 UTC (rev 16301)
@@ -362,7 +362,7 @@
{
extern Material defmaterial; // render module abuse...
- if(defmaterial.gpumaterial)
+ if(defmaterial.gpumaterial.first)
GPU_material_free(&defmaterial);
if(FUNCTION_HASH) {
Modified: branches/apricot/source/blender/gpu/intern/gpu_draw.c
===================================================================
--- branches/apricot/source/blender/gpu/intern/gpu_draw.c 2008-08-29 12:24:07 UTC (rev 16300)
+++ branches/apricot/source/blender/gpu/intern/gpu_draw.c 2008-08-29 13:23:33 UTC (rev 16301)
@@ -765,6 +765,7 @@
{
extern Material defmaterial; /* from material.c */
Material *ma;
+ GPUMaterial *gpumat;
GPUBlendMode blendmode;
int a;
@@ -818,13 +819,12 @@
continue;
/* create glsl material if requested */
- if(glsl)
- GPU_material_from_blender(GMS.gscene, ma);
+ gpumat = (glsl)? GPU_material_from_blender(GMS.gscene, ma): NULL;
- if(glsl && ma->gpumaterial) {
+ if(gpumat) {
/* do glsl only if creating it succeed, else fallback */
GMS.gmatbuf[a]= ma;
- blendmode = GPU_material_blend_mode(ma->gpumaterial, ob->col);
+ blendmode = GPU_material_blend_mode(gpumat, ob->col);
}
else {
/* fixed function opengl materials */
@@ -866,6 +866,7 @@
int GPU_enable_material(int nr, void *attribs)
{
GPUVertexAttribs *gattribs = attribs;
+ GPUMaterial *gpumat;
GPUBlendMode blendmode;
/* prevent index to use un-initialized array items */
@@ -882,7 +883,7 @@
/* unbind glsl material */
if(GMS.gboundmat) {
if(GMS.alphapass) glDepthMask(0);
- GPU_material_unbind(GMS.gboundmat->gpumaterial);
+ GPU_material_unbind(GPU_material_from_blender(GMS.gscene, GMS.gboundmat));
GMS.gboundmat= NULL;
}
@@ -897,9 +898,10 @@
/* bind glsl material and get attributes */
Material *mat = GMS.gmatbuf[nr];
- GPU_material_vertex_attributes(mat->gpumaterial, gattribs);
- GPU_material_bind(mat->gpumaterial, GMS.gob->lay, 1.0);
- GPU_material_bind_uniforms(mat->gpumaterial, GMS.gob->obmat, G.vd->viewmat, G.vd->viewinv, GMS.gob->col);
+ gpumat = GPU_material_from_blender(GMS.gscene, mat);
+ GPU_material_vertex_attributes(gpumat, gattribs);
+ GPU_material_bind(gpumat, GMS.gob->lay, 1.0);
+ GPU_material_bind_uniforms(gpumat, GMS.gob->obmat, G.vd->viewmat, G.vd->viewinv, GMS.gob->col);
GMS.gboundmat= mat;
if(GMS.alphapass) glDepthMask(1);
@@ -939,7 +941,7 @@
if(GMS.gboundmat) {
if(GMS.alphapass) glDepthMask(0);
- GPU_material_unbind(GMS.gboundmat->gpumaterial);
+ GPU_material_unbind(GPU_material_from_blender(GMS.gscene, GMS.gboundmat));
GMS.gboundmat= NULL;
}
Modified: branches/apricot/source/blender/gpu/intern/gpu_material.c
===================================================================
--- branches/apricot/source/blender/gpu/intern/gpu_material.c 2008-08-29 12:24:07 UTC (rev 16300)
+++ branches/apricot/source/blender/gpu/intern/gpu_material.c 2008-08-29 13:23:33 UTC (rev 16301)
@@ -99,6 +99,7 @@
};
struct GPULamp {
+ Scene *scene;
Object *ob;
Object *par;
Lamp *la;
@@ -219,18 +220,20 @@
void GPU_material_free(Material *ma)
{
- GPUMaterial *material = ma->gpumaterial;
+ LinkData *link;
- if(material) {
+ for(link=ma->gpumaterial.first; link; link=link->next) {
+ GPUMaterial *material = link->data;
+
if(material->pass)
GPU_pass_free(material->pass);
BLI_linklist_free(material->lamps, NULL);
MEM_freeN(material);
+ }
- ma->gpumaterial = NULL;
- }
+ BLI_freelistN(&ma->gpumaterial);
}
void GPU_material_bind(GPUMaterial *material, int lay, double time)
@@ -742,7 +745,7 @@
ob= base->object;
if(ob->type==OB_LAMP) {
- lamp = GPU_lamp_from_blender(ob, NULL);
+ lamp = GPU_lamp_from_blender(shi->gpumat->scene, ob, NULL);
if(lamp)
shade_one_light(shi, shr, lamp);
}
@@ -757,7 +760,7 @@
if(ob->type==OB_LAMP) {
Mat4CpyMat4(ob->obmat, dob->mat);
- lamp = GPU_lamp_from_blender(ob, base->object);
+ lamp = GPU_lamp_from_blender(shi->gpumat->scene, ob, base->object);
if(lamp)
shade_one_light(shi, shr, lamp);
}
@@ -1202,14 +1205,16 @@
return shr.combined;
}
-int GPU_material_from_blender(Scene *scene, Material *ma)
+GPUMaterial *GPU_material_from_blender(Scene *scene, Material *ma)
{
GPUMaterial *mat;
GPUNodeLink *outlink;
+ LinkData *link;
- if(ma->gpumaterial)
- return 1;
-
+ for(link=ma->gpumaterial.first; link; link=link->next)
+ if(((GPUMaterial*)link->data)->scene == scene)
+ return link->data;
+
mat = GPU_material_construct_begin(ma);
mat->scene = scene;
@@ -1229,8 +1234,11 @@
GPU_material_construct_end(mat);
- ma->gpumaterial= mat;
- return 1;
+ link = MEM_callocN(sizeof(LinkData), "GPUMaterialLink");
+ link->data = mat;
+ BLI_addtail(&ma->gpumaterial, link);
+
+ return mat;
}
void GPU_materials_free()
@@ -1263,10 +1271,11 @@
Mat4Invert(lamp->imat, mat);
}
-static void gpu_lamp_from_blender(Object *ob, Object *par, Lamp *la, GPULamp *lamp)
+static void gpu_lamp_from_blender(Scene *scene, Object *ob, Object *par, Lamp *la, GPULamp *lamp)
{
float temp, angle, pixsize, wsize;
+ lamp->scene = scene;
lamp->ob = ob;
lamp->par = par;
lamp->la = la;
@@ -1325,14 +1334,15 @@
GPU_framebuffer_free(lamp->fb);
}
-GPULamp *GPU_lamp_from_blender(Object *ob, Object *par)
+GPULamp *GPU_lamp_from_blender(Scene *scene, Object *ob, Object *par)
{
Lamp *la;
GPULamp *lamp;
LinkData *link;
for(link=ob->gpulamp.first; link; link=link->next)
- if(((GPULamp*)link->data)->par == par)
+ if(((GPULamp*)link->data)->par == par &&
+ ((GPULamp*)link->data)->scene == scene)
return link->data;
lamp = MEM_callocN(sizeof(GPULamp), "GPULamp");
@@ -1342,7 +1352,7 @@
BLI_addtail(&ob->gpulamp, link);
la = ob->data;
- gpu_lamp_from_blender(ob, par, la, lamp);
+ gpu_lamp_from_blender(scene, ob, par, la, lamp);
if(la->type==LA_SPOT && (la->mode & LA_SHAD_BUF)) {
/* opengl */
@@ -1381,10 +1391,8 @@
for(nlink=lamp->materials; nlink; nlink=nlink->next) {
ma= nlink->link;
- if(ma->gpumaterial) {
+ if(ma->gpumaterial.first)
GPU_material_free(ma);
- ma->gpumaterial= NULL;
- }
}
BLI_linklist_free(lamp->materials, NULL);
Modified: branches/apricot/source/blender/makesdna/DNA_material_types.h
===================================================================
--- branches/apricot/source/blender/makesdna/DNA_material_types.h 2008-08-29 12:24:07 UTC (rev 16300)
+++ branches/apricot/source/blender/makesdna/DNA_material_types.h 2008-08-29 13:23:33 UTC (rev 16301)
@@ -135,8 +135,7 @@
ScriptLink scriptlink;
- /* runtime glsl material */
- struct GPUMaterial *gpumaterial;
+ ListBase gpumaterial; /* runtime */
} Material;
/* **************** MATERIAL ********************* */
Modified: branches/apricot/source/blender/src/drawscene.c
===================================================================
--- branches/apricot/source/blender/src/drawscene.c 2008-08-29 12:24:07 UTC (rev 16300)
+++ branches/apricot/source/blender/src/drawscene.c 2008-08-29 13:23:33 UTC (rev 16301)
@@ -55,8 +55,6 @@
#include "BSE_view.h"
-#include "GPU_material.h"
-
#include "radio.h"
#include "blendef.h" /* old */
@@ -77,8 +75,6 @@
exit_paint_modes();
set_last_seq(NULL);
-
- GPU_materials_free();
G.scene= sce;
Modified: branches/apricot/source/blender/src/drawview.c
===================================================================
--- branches/apricot/source/blender/src/drawview.c 2008-08-29 12:24:07 UTC (rev 16300)
+++ branches/apricot/source/blender/src/drawview.c 2008-08-29 13:23:33 UTC (rev 16301)
@@ -2938,7 +2938,7 @@
GPULamp *lamp;
View3DShadow *shadow;
- lamp = GPU_lamp_from_blender(ob, par);
+ lamp = GPU_lamp_from_blender(G.scene, ob, par);
if(lamp) {
GPU_lamp_update(lamp, obmat);
Modified: branches/apricot/source/blender/src/previewrender.c
===================================================================
@@ Diff output truncated at 10240 characters. @@
More information about the Bf-blender-cvs
mailing list