Fix color cache initialization for default and particle materials
authorparasti <parasti@78b8d119-cf0a-0410-b17c-f493084dd1d7>
Mon, 18 Apr 2011 01:50:40 +0000 (01:50 +0000)
committerparasti <parasti@78b8d119-cf0a-0410-b17c-f493084dd1d7>
Mon, 18 Apr 2011 01:50:40 +0000 (01:50 +0000)
git-svn-id: https://s.snth.net/svn/neverball/branches/gles@3575 78b8d119-cf0a-0410-b17c-f493084dd1d7

share/part.c
share/part.h
share/solid_draw.c
share/solid_draw.h

index 141f7cd..86522be 100644 (file)
@@ -53,13 +53,10 @@ static struct b_mtrl coin_base_mtrl =
     { 0.2f, 0.2f, 0.2f, 1.0f },
     { 0.0f, 0.0f, 0.0f, 1.0f },
     { 0.0f, 0.0f, 0.0f, 1.0f },
-    { 0.0f }, 0.0f, M_TRANSPARENT, ""
+    { 0.0f }, 0.0f, M_TRANSPARENT, IMG_PART_STAR
 };
 
-static struct d_mtrl coin_draw_mtrl =
-{
-    &coin_base_mtrl, 0
-};
+static struct d_mtrl coin_draw_mtrl;
 
 /*---------------------------------------------------------------------------*/
 
@@ -139,7 +136,7 @@ void part_reset(void)
 
 void part_init(void)
 {
-    coin_draw_mtrl.o = make_image_from_file(IMG_PART_STAR);
+    sol_load_mtrl(&coin_draw_mtrl, &coin_base_mtrl);
 
     memset(coin_vary, 0, PART_MAX_COIN * sizeof (struct part_vary));
     memset(coin_draw, 0, PART_MAX_COIN * sizeof (struct part_draw));
@@ -160,8 +157,7 @@ void part_free(void)
     if (glIsBuffer_(coin_vbo))
         glDeleteBuffers_(1, &coin_vbo);
 
-    if (glIsTexture(coin_draw_mtrl.o))
-        glDeleteTextures(1, &coin_draw_mtrl.o);
+    sol_free_mtrl(&coin_draw_mtrl);
 }
 
 /*---------------------------------------------------------------------------*/
index 23b7855..41583ac 100644 (file)
@@ -5,8 +5,7 @@
 
 /*---------------------------------------------------------------------------*/
 
-#define IMG_PART_STAR     "png/part.png"
-#define IMG_PART_SQUIGGLE "png/squiggle.png"
+#define IMG_PART_STAR     "png/part"
 
 #define PART_MAX_COIN  64
 #define PART_MAX_GOAL  64
index faa8b56..bfd1ef5 100644 (file)
@@ -207,9 +207,17 @@ static struct b_mtrl default_base_mtrl =
     { 0.0f }, 0.0f, 0, ""
 };
 
+/* Nasty. */
+
 static struct d_mtrl default_draw_mtrl =
 {
-    &default_base_mtrl, 0
+    &default_base_mtrl,
+    0xffcccccc,
+    0xff333333,
+    0xff000000,
+    0xff000000,
+    0x00000000,
+    0
 };
 
 void sol_apply_mtrl(const struct d_mtrl *mp_draw, struct s_rend *rend)
@@ -334,9 +342,7 @@ static GLuint sol_find_texture(const char *name)
     return 0;
 }
 
-static void sol_load_mtrl(struct d_mtrl *mp,
-                          const struct b_mtrl *mq,
-                          struct s_draw *draw)
+void sol_load_mtrl(struct d_mtrl *mp, const struct b_mtrl *mq)
 {
     mp->base = mq;
 
@@ -353,35 +359,30 @@ static void sol_load_mtrl(struct d_mtrl *mp,
             glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_CLAMP_TO_EDGE);
         else
             glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_REPEAT);
-
-        /* If at least one material is reflective, mark it in the SOL. */
-
-        if (mq->fl & M_REFLECTIVE)
-            draw->reflective = 1;
-
-        /* Cache the 32-bit material values for quick comparison. */
-
-        mp->d = (tobyte(mq->d[0]))
-            |   (tobyte(mq->d[1]) <<  8)
-            |   (tobyte(mq->d[2]) << 16)
-            |   (tobyte(mq->d[3]) << 24);
-        mp->a = (tobyte(mq->a[0]))
-            |   (tobyte(mq->a[1]) <<  8)
-            |   (tobyte(mq->a[2]) << 16)
-            |   (tobyte(mq->a[3]) << 24);
-        mp->s = (tobyte(mq->s[0]))
-            |   (tobyte(mq->s[1]) <<  8)
-            |   (tobyte(mq->s[2]) << 16)
-            |   (tobyte(mq->s[3]) << 24);
-        mp->e = (tobyte(mq->e[0]))
-            |   (tobyte(mq->e[1]) <<  8)
-            |   (tobyte(mq->e[2]) << 16)
-            |   (tobyte(mq->e[3]) << 24);
-        mp->h = (tobyte(mq->h[0]));
     }
-}
 
-static void sol_free_mtrl(struct d_mtrl *mp)
+    /* Cache the 32-bit material values for quick comparison. */
+
+    mp->d = (tobyte(mq->d[0]))
+        |   (tobyte(mq->d[1]) <<  8)
+        |   (tobyte(mq->d[2]) << 16)
+        |   (tobyte(mq->d[3]) << 24);
+    mp->a = (tobyte(mq->a[0]))
+        |   (tobyte(mq->a[1]) <<  8)
+        |   (tobyte(mq->a[2]) << 16)
+        |   (tobyte(mq->a[3]) << 24);
+    mp->s = (tobyte(mq->s[0]))
+        |   (tobyte(mq->s[1]) <<  8)
+        |   (tobyte(mq->s[2]) << 16)
+        |   (tobyte(mq->s[3]) << 24);
+    mp->e = (tobyte(mq->e[0]))
+        |   (tobyte(mq->e[1]) <<  8)
+        |   (tobyte(mq->e[2]) << 16)
+        |   (tobyte(mq->e[3]) << 24);
+    mp->h = (tobyte(mq->h[0]));
+}
+
+void sol_free_mtrl(struct d_mtrl *mp)
 {
     if (glIsTexture(mp->o))
         glDeleteTextures(1, &mp->o);
@@ -685,7 +686,14 @@ int sol_load_draw(struct s_draw *draw, const struct s_vary *vary, int s)
             draw->mc = draw->base->mc;
 
             for (i = 0; i < draw->mc; i++)
-                sol_load_mtrl(draw->mv + i, draw->base->mv + i, draw);
+            {
+                sol_load_mtrl(draw->mv + i, draw->base->mv + i);
+
+                /* If at least one material is reflective, mark it. */
+
+                if (draw->base->mv[i].fl & M_REFLECTIVE)
+                    draw->reflective = 1;
+            }
         }
     }
 
index 0cef38c..c7833fa 100644 (file)
@@ -108,6 +108,9 @@ void sol_free_draw(struct s_draw *);
 void sol_draw_enable(struct s_rend *);
 void sol_draw_disable(struct s_rend *);
 
+void sol_load_mtrl(struct d_mtrl *, const struct b_mtrl *);
+void sol_free_mtrl(struct d_mtrl *);
+
 void sol_apply_mtrl(const struct d_mtrl *, struct s_rend *);
 
 void sol_back(const struct s_draw *, struct s_rend *, float, float, float);