Преглед изворни кода

Merge branch 'neo' into next

mozeal пре 12 година
родитељ
комит
e79f2071b9
2 измењених фајлова са 52 додато и 0 уклоњено
  1. 38 0
      gameplay/src/Texture.cpp
  2. 14 0
      gameplay/src/Texture.h

+ 38 - 0
gameplay/src/Texture.cpp

@@ -155,6 +155,44 @@ Texture* Texture::create(Image* image, bool generateMipmaps)
     }
 }
 
+Texture* Texture::createCubeMap(const char* path[6], bool generateMipmaps)
+{
+    // Create and load the texture.
+    GLuint textureId;
+    GL_ASSERT( glGenTextures(1, &textureId) );
+    GL_ASSERT( glBindTexture(GL_TEXTURE_CUBE_MAP, textureId) );
+    GL_ASSERT( glPixelStorei(GL_UNPACK_ALIGNMENT, 1) );
+    
+    Image* image;
+    Format format;
+    for (int f = 0; f < 6; ++f) {
+        image = Image::create(path[f]);
+        
+        if( image->getFormat() == Image::RGB )
+            format = Texture::RGB;
+        else if( image->getFormat() == Image::RGBA )
+            format = Texture::RGBA;
+        else
+            return NULL;
+        
+        GLenum face = GL_TEXTURE_CUBE_MAP_POSITIVE_X + f;
+        glTexImage2D(face, 0, format, image->getWidth(), image->getHeight(), 0, format, GL_UNSIGNED_BYTE, image->getData());
+    }
+    Filter minFilter = generateMipmaps ? NEAREST_MIPMAP_LINEAR : LINEAR;
+    GL_ASSERT( glTexParameteri(GL_TEXTURE_CUBE_MAP, GL_TEXTURE_MIN_FILTER, minFilter) );
+    glGenerateMipmap(GL_TEXTURE_CUBE_MAP);
+    
+    Texture* texture = new Texture();
+    texture->_handle = textureId;
+    texture->_format = format;
+    texture->_width = image->getWidth();
+    texture->_height = image->getHeight();
+    texture->_minFilter = minFilter;
+    
+    return texture;
+}
+
+
 Texture* Texture::create(Format format, unsigned int width, unsigned int height, unsigned char* data, bool generateMipmaps)
 {
     // Create and load the texture.

+ 14 - 0
gameplay/src/Texture.h

@@ -152,6 +152,20 @@ public:
      */
     static Texture* create(const char* path, bool generateMipmaps = false);
 
+    /**
+     * Creates a texture from the given image resource.
+     *
+     * Note that for textures that include mipmap data in the source data (such as most compressed textures),
+     * the generateMipmaps flags should NOT be set to true.
+     *
+     * @param The array of 6 of path The image resource path.
+     * @param generateMipmaps true to auto-generate a full mipmap chain, false otherwise.
+     *
+     * @return The new texture, or NULL if the texture could not be loaded/created.
+     * @script{create}
+     */
+    static Texture* createCubeMap(const char* path[6], bool generateMipmaps = false);
+
     /**
      * Creates a texture from the given image.
      *