Просмотр исходного кода

Refactors Image::Format enumeration for cleaner separation from the Texture class.

Chris Culy 14 лет назад
Родитель
Сommit
46361f7892
4 измененных файлов с 17 добавлено и 10 удалено
  1. 2 2
      gameplay/src/Image.cpp
  2. 2 3
      gameplay/src/Image.h
  3. 4 4
      gameplay/src/PhysicsRigidBody.cpp
  4. 9 1
      gameplay/src/Texture.cpp

+ 2 - 2
gameplay/src/Image.cpp

@@ -65,11 +65,11 @@ Image* Image::create(const char* path)
     switch (colorType)
     {
     case PNG_COLOR_TYPE_RGBA:
-        image->_format = RGBA8888;
+        image->_format = RGBA;
         break;
 
     case PNG_COLOR_TYPE_RGB:
-        image->_format = RGB888;
+        image->_format = RGB;
         break;
 
     default:

+ 2 - 3
gameplay/src/Image.h

@@ -2,7 +2,6 @@
 #define IMAGE_H__
 
 #include "Ref.h"
-#include "Texture.h"
 
 namespace gameplay
 {
@@ -19,8 +18,8 @@ public:
      */
     enum Format
     {
-        RGB888 = Texture::RGB888,
-        RGBA8888 = Texture::RGBA8888
+        RGB,
+        RGBA
     };
 
     /**

+ 4 - 4
gameplay/src/PhysicsRigidBody.cpp

@@ -80,10 +80,10 @@ PhysicsRigidBody::PhysicsRigidBody(Node* node, Image* image, float mass,
     unsigned int pixelSize = 0;
     switch (image->getFormat())
     {
-        case Image::RGB888:
+        case Image::RGB:
             pixelSize = 3;
             break;
-        case Image::RGBA8888:
+        case Image::RGBA:
             pixelSize = 4;
             break;
     }
@@ -394,8 +394,8 @@ PhysicsRigidBody* PhysicsRigidBody::create(Node* node, Properties* properties)
         // Ensure that the image's pixel format is supported.
         switch (image->getFormat())
         {
-            case Texture::RGB888:
-            case Texture::RGBA8888:
+            case Image::RGB:
+            case Image::RGBA:
                 break;
             default:
                 WARN_VARG("Heightmap: pixel format is not supported: %d", image->getFormat());

+ 9 - 1
gameplay/src/Texture.cpp

@@ -92,7 +92,15 @@ Texture* Texture::create(const char* path, bool generateMipmaps)
 
 Texture* Texture::create(Image* image, bool generateMipmaps)
 {
-    return create((Texture::Format)image->getFormat(), image->getWidth(), image->getHeight(), image->getData(), generateMipmaps);
+    switch (image->getFormat())
+    {
+    case Image::RGB:
+        return create(RGB888, image->getWidth(), image->getHeight(), image->getData(), generateMipmaps);
+    case Image::RGBA:
+        return create(RGBA8888, image->getWidth(), image->getHeight(), image->getData(), generateMipmaps);
+    }
+    
+    return NULL;
 }
 
 Texture* Texture::create(Format format, unsigned int width, unsigned int height, unsigned char* data, bool generateMipmaps)