]> git.tdb.fi Git - libs/gl.git/commitdiff
Use UNSIGNED_SHORT for allocating DEPTH_COMPONENT textures
authorMikko Rasa <tdb@tdb.fi>
Sat, 23 Jan 2016 02:56:04 +0000 (04:56 +0200)
committerMikko Rasa <tdb@tdb.fi>
Sat, 23 Jan 2016 02:56:04 +0000 (04:56 +0200)
OpenGL ES doesn't accept DEPTH_COMPONENT together with BYTE types.

source/texture.cpp
source/texture.h
source/texture1d.cpp
source/texture1d.h
source/texture2d.cpp
source/texture2d.h
source/texture3d.cpp
source/texture3d.h
source/texturecube.cpp
source/texturecube.h

index 6484440e08708075081bab3d9b54c20e2c4e55ec..8d43143c9d734c218211d070890bf4cd080b42ed 100644 (file)
@@ -75,6 +75,11 @@ Texture::~Texture()
                glDeleteTextures(1, &id);
 }
 
+DataType Texture::get_alloc_type(PixelFormat fmt)
+{
+       return (fmt==DEPTH_COMPONENT ? UNSIGNED_SHORT : UNSIGNED_BYTE);
+}
+
 void Texture::update_parameter(int mask) const
 {
        if(TexUnit::current().get_texture()!=this)
index db6165fed82628206f29d69b39036d2160edefca..4cd5481e2e18f570377c3f13d86b8b4dbf984cb8 100644 (file)
@@ -2,7 +2,9 @@
 #define MSP_GL_TEXTURE_H_
 
 #include <msp/datafile/objectloader.h>
+#include "datatype.h"
 #include "gl.h"
+#include "pixelformat.h"
 #include "predicate.h"
 #include "resource.h"
 
@@ -122,6 +124,8 @@ public:
        ~Texture();
 
 protected:
+       static DataType get_alloc_type(PixelFormat);
+
        void update_parameter(int) const;
 public:
        void set_min_filter(TextureFilter);
index accd0e0c06c76a4bfe0b91f828cc840c5becff49..046fca6fa4eccbe49a5a5174ba498adefc1b892c 100644 (file)
@@ -34,7 +34,8 @@ void Texture1D::allocate(unsigned level)
        if(allocated&(1<<level))
                return;
 
-       image(level, get_base_pixelformat(ifmt), UNSIGNED_BYTE, 0);
+       PixelFormat base_fmt = get_base_pixelformat(ifmt);
+       image(level, base_fmt, get_alloc_type(base_fmt), 0);
 }
 
 void Texture1D::image(unsigned level, PixelFormat fmt, DataType type, const void *data)
index 63b25c138756c8c6a44bd635e341cab9810332f9..20b1d35cbf88b8ead6421902493e18d3d97aea19 100644 (file)
@@ -1,8 +1,6 @@
 #ifndef MSP_GL_TEXTURE1D_H_
 #define MSP_GL_TEXTURE1D_H_
 
-#include "datatype.h"
-#include "pixelformat.h"
 #include "texture.h"
 
 namespace Msp {
index de75420973134b3d0aa1d2e2275365778b407915..64ad124f97a1952f19307d429c8f9acd427d76c1 100644 (file)
@@ -63,7 +63,8 @@ void Texture2D::allocate(unsigned level)
        if(allocated&(1<<level))
                return;
 
-       image(level, get_base_pixelformat(ifmt), UNSIGNED_BYTE, 0);
+       PixelFormat base_fmt = get_base_pixelformat(ifmt);
+       image(level, base_fmt, get_alloc_type(base_fmt), 0);
 }
 
 void Texture2D::image(unsigned level, PixelFormat fmt, DataType type, const void *data)
index 71e04b576f2b62aa8a93d4c154a3258a596f2bc1..030fe408ad0a2b08bcdc448fe1f305703c3d8dce 100644 (file)
@@ -3,8 +3,6 @@
 
 #include <string>
 #include <msp/graphics/image.h>
-#include "datatype.h"
-#include "pixelformat.h"
 #include "resource.h"
 #include "texture.h"
 
index 7b9c3590ef6bc7eb8e936e20816c36549bbdec2c..d5badc725435fb3efb37d4c15c52bedafd40ece6 100644 (file)
@@ -41,7 +41,8 @@ void Texture3D::allocate(unsigned level)
        if(allocated&(1<<level))
                return;
 
-       image(level, get_base_pixelformat(ifmt), UNSIGNED_BYTE, 0);
+       PixelFormat base_fmt = get_base_pixelformat(ifmt);
+       image(level, base_fmt, get_alloc_type(base_fmt), 0);
 }
 
 void Texture3D::image(unsigned level, PixelFormat fmt, DataType type, const void *data)
index c55a3c1ae3bffd40be72d97183e0fbbebe86bd7e..93cae7e84e573ff40b0e5685210a9ab6c3ca990c 100644 (file)
@@ -2,8 +2,6 @@
 #define MSP_GL_TEXTURE3D_H_
 
 #include <string>
-#include "datatype.h"
-#include "pixelformat.h"
 #include "texture.h"
 
 namespace Msp {
index 37390a853612523e503889230f030f2a70d2b73d..24d02f4022b2aeac380410ea481a2e392181f8af 100644 (file)
@@ -47,8 +47,10 @@ void TextureCube::allocate(unsigned level)
        if(allocated&(1<<level))
                return;
 
+       PixelFormat base_fmt = get_base_pixelformat(ifmt);
+       DataType type = get_alloc_type(base_fmt);
        for(unsigned i=0; i<6; ++i)
-               image(enumerate_faces(i), level, get_base_pixelformat(ifmt), UNSIGNED_BYTE, 0);
+               image(enumerate_faces(i), level, base_fmt, type, 0);
 }
 
 void TextureCube::image(TextureCubeFace face, unsigned level, PixelFormat fmt, DataType type, const void *data)
index 4530a97ac8525d4719af598c9ed1757edfbbf47b..f65ec0592a4358b1816a59090b68f224f0c7ad78 100644 (file)
@@ -2,8 +2,6 @@
 #define MSP_GL_TEXTURECUBE_H_
 
 #include <msp/graphics/image.h>
-#include "datatype.h"
-#include "pixelformat.h"
 #include "texture.h"
 #include "vector.h"
 #include <msp/gl/extensions/arb_texture_cube_map.h>