Commits

Anonymous committed 0d216e7

new texture for ss, fixed segfault in material

  • Participants
  • Parent commits b6b37cb

Comments (0)

Files changed (6)

 	
 			glR   = new glRenderer();
 			guiR  = new guiRenderer();
-			scene = new Cubes(new sceneProcessor(glR, guiR));
+			scene = new ColladaTest(new sceneProcessor(glR, guiR));
 			
 			glR.window().systemMessenger().add(this);
 			

File demo/collada/Test.d

 
 			foreach(i, m; meshes)
 			{
-				trace(Format("texcoords in ss part: {}", m.texcoords.length));
     			auto ssPart = new Node!(Placed, Geometry)(Format("spaceship_mesh{}", i));
 
     			m.renderType = EMeshRenderType.fill;

File demo/collada/model.dae

       <author>Administrator</author>
       <authoring_tool>Right Hemisphere Collada Interface v1536.36 with FCollada v3.05.</authoring_tool>
     </contributor>
-    <created>2010-04-18T09:49:55Z</created>
-    <modified>2010-04-18T09:49:55Z</modified>
+    <created>2010-05-16T13:07:54Z</created>
+    <modified>2010-05-16T13:07:55Z</modified>
     <up_axis>Z_UP</up_axis>
   </asset>
   <library_animations>

File demo/collada/texture.tga

Old
Old image
New
New image

File res/Material.d

 
 public import mg.res.Texture;
 
+import
+	mg.util.Log;
+
 
 // TODO: think what it should be
+// TODO: think moar
 class Material
 {
 	protected:
 		Texture _tex;
+		int     _useCount;
 
 	public:
 		bool lit         = true;
 		{
 			_tex = t;
 		}
+		
+		~this()
+		{
+			if (_tex !is null)
+				error("Material destructor: still has texture, potential segfault on app exit");
+		}
 
 		static typeof(this) opCall(Texture t)
 		{
 			return new typeof(this)(t);
 		}
+		
+		void use() { _useCount++; }
+
+		void dispose()
+		{
+			--_useCount;
+			
+			if (_useCount <= 0 )
+			{
+				if (_useCount < 0)
+					_useCount = 0;
+				
+				if (_tex !is null)
+				{
+					delete _tex;
+					_tex = null;
+				}
+			}
+		}
 
 		Texture texture()
 		{

File scene/component/Geometry.d

             assert(n !is null, "owner node is null!");
             node = n;
         }
+		
+		~this()
+		{
+			if (_material !is null)
+				_material.dispose();
+		}
         
         
         static char[] guid()
 
 
 		Geometry material(Material m)
-		in
 		{
 			assert(m !is null, "material is null");
-		}
-		body
-		{
-			_material = m;	// TODO: here and in mesh setting - think what to do with old one
+			
+			if (_material !is null)
+				_material.dispose();
+
+			_material = m;
+			_material.use();
 			return this;
 		}