Revision: 49100
          
http://projects.blender.org/scm/viewvc.php?view=rev&root=bf-blender&revision=49100
Author:   kupoman
Date:     2012-07-21 08:17:42 +0000 (Sat, 21 Jul 2012)
Log Message:
-----------
Getting a start on a new UI for Post-process 2D filters.

Modified Paths:
--------------
    branches/ge_harmony/release/scripts/startup/bl_ui/properties_game.py
    branches/ge_harmony/source/blender/blenkernel/intern/scene.c
    branches/ge_harmony/source/blender/editors/render/render_intern.h
    branches/ge_harmony/source/blender/editors/render/render_ops.c
    branches/ge_harmony/source/blender/editors/render/render_shading.c
    branches/ge_harmony/source/blender/makesdna/DNA_scene_types.h
    branches/ge_harmony/source/blender/makesdna/DNA_shader_types.h
    branches/ge_harmony/source/blender/makesrna/intern/rna_scene.c
    branches/ge_harmony/source/blender/makesrna/intern/rna_shader.c

Modified: branches/ge_harmony/release/scripts/startup/bl_ui/properties_game.py
===================================================================
--- branches/ge_harmony/release/scripts/startup/bl_ui/properties_game.py        
2012-07-21 08:15:54 UTC (rev 49099)
+++ branches/ge_harmony/release/scripts/startup/bl_ui/properties_game.py        
2012-07-21 08:17:42 UTC (rev 49100)
@@ -359,7 +359,45 @@
 
             layout.prop(gs, "dome_text")
 
+class RENDER_PT_game_post_filters(RenderButtonsPanel, Panel):
+    bl_label = "Post-Process Filters"
+    COMPAT_ENGINES = {'BLENDER_GAME'}
+    
+    def draw(self, context):
+        layout = self.layout
+        
+        gs = context.scene.game_settings
+        
+        row = layout.row()
+        col = row.column()
+        col.template_list(gs, "post_filters", gs, "active_post_filter_index", 
rows=2)
+        col.template_ID(gs, "active_post_filter", new="shader.new_postfilter")
+            
+        filter = gs.active_post_filter
+        if filter:
+            col.label("Source:")
+            row = col.row()
+            row.prop(filter, "shader_location", expand=True)
+            if filter.shader_location == "INTERNAL":
+                col.prop(filter, "source_text", text="")
+            elif filter.shader_location == "EXTERNAL":
+                col.prop(filter, "source_path", text="")
+                
+            if filter.uniforms:
+                col.label("Uniforms:")
+                
+            for uniform in filter.uniforms:
+                if hasattr(uniform, "value"):
+                    if uniform.type in ("VEC2", "VEC3", "VEC4", "IVEC2", 
"IVEC3", "IVEC4"):
+                        col.label(uniform.name + ":")
+                        row = col.row()
+                        row.prop(uniform, "value", text="")
+                    else:
+                        row = col.row()
+                        row.label(uniform.name + ":")
+                        row.prop(uniform, "value", text="")
 
+
 class RENDER_PT_game_shading(RenderButtonsPanel, Panel):
     bl_label = "Shading"
     COMPAT_ENGINES = {'BLENDER_GAME'}

Modified: branches/ge_harmony/source/blender/blenkernel/intern/scene.c
===================================================================
--- branches/ge_harmony/source/blender/blenkernel/intern/scene.c        
2012-07-21 08:15:54 UTC (rev 49099)
+++ branches/ge_harmony/source/blender/blenkernel/intern/scene.c        
2012-07-21 08:17:42 UTC (rev 49100)
@@ -543,6 +543,9 @@
 
        sce->gm.exitkey = 218; // Blender key code for ESC
 
+       sce->gm.postfilters.first = sce->gm.postfilters.last = NULL;
+       sce->gm.actpostfilter = 0;
+
        sound_create_scene(sce);
 
        return sce;

Modified: branches/ge_harmony/source/blender/editors/render/render_intern.h
===================================================================
--- branches/ge_harmony/source/blender/editors/render/render_intern.h   
2012-07-21 08:15:54 UTC (rev 49099)
+++ branches/ge_harmony/source/blender/editors/render/render_intern.h   
2012-07-21 08:17:42 UTC (rev 49100)
@@ -46,6 +46,7 @@
 
 void MATERIAL_OT_new(struct wmOperatorType *ot);
 void SHADER_OT_new(struct wmOperatorType *ot);
+void SHADER_OT_new_postfilter(struct wmOperatorType *ot);
 void TEXTURE_OT_new(struct wmOperatorType *ot);
 void WORLD_OT_new(struct wmOperatorType *ot);
 

Modified: branches/ge_harmony/source/blender/editors/render/render_ops.c
===================================================================
--- branches/ge_harmony/source/blender/editors/render/render_ops.c      
2012-07-21 08:15:54 UTC (rev 49099)
+++ branches/ge_harmony/source/blender/editors/render/render_ops.c      
2012-07-21 08:17:42 UTC (rev 49100)
@@ -54,6 +54,7 @@
 
        WM_operatortype_append(MATERIAL_OT_new);
        WM_operatortype_append(SHADER_OT_new);
+       WM_operatortype_append(SHADER_OT_new_postfilter);
        WM_operatortype_append(TEXTURE_OT_new);
        WM_operatortype_append(WORLD_OT_new);
        

Modified: branches/ge_harmony/source/blender/editors/render/render_shading.c
===================================================================
--- branches/ge_harmony/source/blender/editors/render/render_shading.c  
2012-07-21 08:15:54 UTC (rev 49099)
+++ branches/ge_harmony/source/blender/editors/render/render_shading.c  
2012-07-21 08:17:42 UTC (rev 49100)
@@ -465,6 +465,55 @@
        ot->flag = OPTYPE_REGISTER | OPTYPE_UNDO;
 }
 
+/********************** new filter operator *********************/
+
+static int new_shader_postfilter_exec(bContext *C, wmOperator *UNUSED(op))
+{
+       Scene *scene = CTX_data_scene(C);
+       Shader *sh = CTX_data_pointer_get_type(C, "shader", &RNA_Shader).data;
+       PointerRNA ptr, idptr;
+       PropertyRNA *prop;
+
+       /* add or copy material */
+       if (sh)
+               sh = BKE_shader_copy(sh);
+       else
+               sh = BKE_shader_add("Post-Process");
+
+       sh->type = SHADER_TYPE_POSTPROCESS;
+
+       /* hook into UI */
+       uiIDContextProperty(C, &ptr, &prop);
+
+       if (prop) {
+               /* when creating new ID blocks, use is already 1, but RNA
+                * pointer set also increases user, so this compensates it */
+               sh->id.us--;
+
+               RNA_id_pointer_create(&sh->id, &idptr);
+               RNA_property_pointer_set(&ptr, prop, idptr);
+               RNA_property_update(C, &ptr, prop);
+       }
+
+       scene->gm.actpostfilter = BLI_countlist(&scene->gm.postfilters) - 1;
+
+       return OPERATOR_FINISHED;
+}
+
+void SHADER_OT_new_postfilter(wmOperatorType *ot)
+{
+       /* identifiers */
+       ot->name = "New Post-Process Filter";
+       ot->idname = "SHADER_OT_new_postfilter";
+       ot->description = "Add a new Post-Process 2D Filter";
+       
+       /* api callbacks */
+       ot->exec = new_shader_postfilter_exec;
+
+       /* flags */
+       ot->flag = OPTYPE_REGISTER | OPTYPE_UNDO;
+}
+
 /********************** new texture operator *********************/
 
 static int new_texture_exec(bContext *C, wmOperator *UNUSED(op))

Modified: branches/ge_harmony/source/blender/makesdna/DNA_scene_types.h
===================================================================
--- branches/ge_harmony/source/blender/makesdna/DNA_scene_types.h       
2012-07-21 08:15:54 UTC (rev 49099)
+++ branches/ge_harmony/source/blender/makesdna/DNA_scene_types.h       
2012-07-21 08:17:42 UTC (rev 49100)
@@ -625,7 +625,10 @@
        short ticrate, maxlogicstep, physubstep, maxphystep;
        short obstacleSimulation, pad1;
        float levelHeight;
-       float deactivationtime, lineardeactthreshold, 
angulardeactthreshold,pad2;
+       float deactivationtime, lineardeactthreshold, angulardeactthreshold;
+
+       int actpostfilter;
+       ListBase postfilters;
 } GameData;
 
 #define STEREO_NOSTEREO                1

Modified: branches/ge_harmony/source/blender/makesdna/DNA_shader_types.h
===================================================================
--- branches/ge_harmony/source/blender/makesdna/DNA_shader_types.h      
2012-07-21 08:15:54 UTC (rev 49099)
+++ branches/ge_harmony/source/blender/makesdna/DNA_shader_types.h      
2012-07-21 08:17:42 UTC (rev 49100)
@@ -61,6 +61,11 @@
        GHash *uniform_cache;
 } Shader;
 
+typedef struct ShaderLink {
+       struct ShaderLink *next, *prev;
+       struct Shader *shader;
+} ShaderLink;
+
 /* type */
 #define SHADER_TYPE_VERTEX             0
 #define SHADER_TYPE_FRAGMENT   1

Modified: branches/ge_harmony/source/blender/makesrna/intern/rna_scene.c
===================================================================
--- branches/ge_harmony/source/blender/makesrna/intern/rna_scene.c      
2012-07-21 08:15:54 UTC (rev 49099)
+++ branches/ge_harmony/source/blender/makesrna/intern/rna_scene.c      
2012-07-21 08:17:42 UTC (rev 49100)
@@ -1321,6 +1321,57 @@
                gm->exitkey = value;
 }
 
+static PointerRNA rna_GameSettings_active_postfilter_get(PointerRNA *ptr)
+{
+       GameData *gm = (GameData *)ptr->data;
+       ShaderLink *link = BLI_findlink(&gm->postfilters, 
(int)gm->actpostfilter);
+       Shader *shader = (link) ? link->shader : NULL;
+       return rna_pointer_inherit_refine(ptr, &RNA_Shader, shader);
+}
+
+static void rna_GameSettings_active_postfilter_set(PointerRNA *ptr, PointerRNA 
value)
+{
+       GameData *gm = (GameData *)ptr->data;
+       Shader *sh = (Shader*)value.data;
+
+       ShaderLink *link = BLI_findlink(&gm->postfilters, 
(int)gm->actpostfilter);
+       if (!link)
+       {
+               link = MEM_callocN(sizeof(ShaderLink), "New Post Process 
Filter");
+               link->shader = sh;
+               BLI_addtail(&gm->postfilters, sh);
+       }
+       else
+       {
+               if (link->shader)
+                       link->shader->id.us--;
+               link->shader = sh;
+       }
+
+       id_us_plus((ID *) sh);
+}
+
+static int rna_GameSettings_active_postfilter_index_get(PointerRNA *ptr)
+{
+       GameData *gm = (GameData*)ptr->data;
+       return MAX2(gm->actpostfilter-1, 0);
+}
+
+static void rna_GameSettings_active_postfilter_index_set(PointerRNA *ptr, int 
value)
+{
+       GameData *gm = (GameData*)ptr->data;
+       gm->actpostfilter = value+1;
+}
+
+static void rna_GameSettings_active_postfilter_index_range(PointerRNA *ptr, 
int *min, int *max)
+{
+       GameData *gm = (GameData*)ptr->data;
+
+       *min = 0;
+       *max = BLI_countlist(&gm->postfilters)-1;
+       *max = MAX2(0, *max);
+}
+
 static TimeMarker *rna_TimeLine_add(Scene *scene, const char name[])
 {
        TimeMarker *marker = MEM_callocN(sizeof(TimeMarker), "TimeMarker");
@@ -2736,7 +2787,25 @@
        prop = RNA_def_property(srna, "show_obstacle_simulation", PROP_BOOLEAN, 
PROP_NONE);
        RNA_def_property_boolean_sdna(prop, NULL, "flag", 
GAME_SHOW_OBSTACLE_SIMULATION);
        RNA_def_property_ui_text(prop, "Visualization", "Enable debug 
visualization for obstacle simulation");
+       
+       /* Filter Settings */
+       prop = RNA_def_property(srna, "post_filters", PROP_COLLECTION, 
PROP_NONE);
+       RNA_def_property_collection_sdna(prop, NULL, "postfilters", NULL);
+       RNA_def_property_collection_funcs(prop, NULL, NULL, NULL, NULL, NULL, 
NULL, NULL, NULL);
+       RNA_def_property_struct_type(prop, "ShaderLink");
+       RNA_def_property_ui_text(prop, "Post Process Filters", "2D filters run 
after the scene is rendered");
 
+       prop = RNA_def_property(srna, "active_post_filter", PROP_POINTER, 
PROP_NONE);
+       RNA_def_property_struct_type(prop, "Shader");
+       RNA_def_property_pointer_funcs(prop, 
"rna_GameSettings_active_postfilter_get", 
"rna_GameSettings_active_postfilter_set", NULL, NULL);
+       RNA_def_property_flag(prop, PROP_EDITABLE);
+       RNA_def_property_ui_text(prop, "Active Shader", "");
+
+       prop = RNA_def_property(srna, "active_post_filter_index", PROP_INT, 
PROP_NONE);
+       RNA_def_property_int_sdna(prop, NULL, "actpostfilter");
+       RNA_def_property_int_funcs(prop, NULL, NULL, 
"rna_GameSettings_active_postfilter_index_range");
+       RNA_def_property_ui_text(prop, "Active Post Filter Index", "");
+
        /* Recast Settings */
        prop = RNA_def_property(srna, "recast_data", PROP_POINTER, PROP_NONE);
        RNA_def_property_flag(prop, PROP_NEVER_NULL);


@@ 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