Commits

Jason McKesson committed 932dd6b

glimg: Added function to get the texture type
that a texture will be created with.

  • Participants
  • Parent commits 5ea09a4

Comments (0)

Files changed (2)

glimg/include/glimg/TextureGenerator.h

 	OpenGLPixelTransferParams GetUploadFormatType(const ImageFormat &format, unsigned int forceConvertBits);
 
 	/**
+	\brief Retrieves the texture type for the given ImageSet.
+
+	When the CreateTexture functions are called, they will create a texture with a specific
+	texture type. This is the target that the texture is bound to the context with, and this
+	information is baked into the texture object. It is vital to know what this type will actually
+	be, so that the texture object can be properly bound to the context.
+
+	This function will return the texture target that CreateTexture will create, given
+	\em exactly the same parameters as CreateTexture.
+
+	\param pImage The image that would be uploaded in a CreateTexture call.
+	\param forceConvertBits A bitfield containing values from ForcedConvertFlags.
+
+	\return The texture type for a texture that would be created with CreateTexture.
+	**/
+	GLenum GetTextureType(const ImageSet *pImage, unsigned int forceConvertBits);
+
+	/**
 	\brief Creates a texture object from the given ImageSet, with flags.
 
 	If an exception is thrown, no OpenGL state will be changed. If a texture was created with

glimg/source/TextureGenerator.cpp

 		}
 	}
 
+	GLenum GetTextureType( const ImageSet *pImage, unsigned int forceConvertBits )
+	{
+		Dimensions dims = pImage->GetDimensions();
+
+		switch(dims.numDimensions)
+		{
+		case 1:
+			//May be 1D or 1D array.
+			if(IsArrayTexture(pImage, forceConvertBits))
+				return gl::GL_TEXTURE_1D_ARRAY;
+			else
+				return gl::GL_TEXTURE_1D;
+		case 2:
+			//2D, 2D array, 2D cube, or 2D array cube.
+			if(IsArrayTexture(pImage, forceConvertBits))
+			{
+				if(pImage->GetFaceCount() > 1)
+					return gl::GL_TEXTURE_CUBE_MAP_ARRAY;
+				else
+					return gl::GL_TEXTURE_2D_ARRAY;
+			}
+			else
+			{
+				if(pImage->GetFaceCount() > 1)
+					return gl::GL_TEXTURE_CUBE_MAP;
+				else
+					return gl::GL_TEXTURE_2D;
+			}
+			break;
+		case 3:
+			//3D.
+			return gl::GL_TEXTURE_3D;
+		}
+
+		return -1;
+	}
+
 	unsigned int CreateTexture( const ImageSet *pImage, unsigned int forceConvertBits )
 	{
 		GLuint textureName = 0;
 		GLuint internalFormat = GetInternalFormat(format, forceConvertBits);
 		OpenGLPixelTransferParams upload = GetUploadFormatType(format, forceConvertBits);
 
-		Dimensions dims = pImage->GetDimensions();
-
-		switch(dims.numDimensions)
+		switch(GetTextureType(pImage, forceConvertBits))
 		{
-		case 1:
-			//May be 1D or 1D array.
-			if(IsArrayTexture(pImage, forceConvertBits))
-				Build1DArrayTexture(textureName, pImage->m_pImpl, forceConvertBits,
-					internalFormat, upload);
-			else
-				Build1DTexture(textureName, pImage->m_pImpl, forceConvertBits,
-					internalFormat, upload);
+		case gl::GL_TEXTURE_1D:
+			Build1DTexture(textureName, pImage->m_pImpl, forceConvertBits,
+				internalFormat, upload);
 			break;
-		case 2:
-			//2D, 2D array, 2D cube, or 2D array cube.
-			if(IsArrayTexture(pImage, forceConvertBits))
-			{
-				if(pImage->GetFaceCount() > 1)
-					Build2DCubeArrayTexture(textureName, pImage->m_pImpl, forceConvertBits,
-						internalFormat, upload);
-				else
-					Build2DArrayTexture(textureName, pImage->m_pImpl, forceConvertBits,
-						internalFormat, upload);
-			}
-			else
-			{
-				if(pImage->GetFaceCount() > 1)
-					Build2DCubeTexture(textureName, pImage->m_pImpl, forceConvertBits,
-						internalFormat, upload);
-				else
-					Build2DTexture(textureName, pImage->m_pImpl, forceConvertBits,
-						internalFormat, upload);
-			}
+		case gl::GL_TEXTURE_2D:
+			Build2DTexture(textureName, pImage->m_pImpl, forceConvertBits,
+				internalFormat, upload);
 			break;
-		case 3:
-			//3D.
-			Build3DTexture(textureName, pImage->m_pImpl, forceConvertBits, internalFormat, upload);
+		case gl::GL_TEXTURE_3D:
+			Build3DTexture(textureName, pImage->m_pImpl, forceConvertBits,
+				internalFormat, upload);
+			break;
+		case gl::GL_TEXTURE_1D_ARRAY:
+			Build1DArrayTexture(textureName, pImage->m_pImpl, forceConvertBits,
+				internalFormat, upload);
+			break;
+		case gl::GL_TEXTURE_2D_ARRAY:
+			Build2DArrayTexture(textureName, pImage->m_pImpl, forceConvertBits,
+				internalFormat, upload);
+			break;
+		case gl::GL_TEXTURE_CUBE_MAP:
+			Build2DCubeTexture(textureName, pImage->m_pImpl, forceConvertBits,
+				internalFormat, upload);
+			break;
+		case gl::GL_TEXTURE_CUBE_MAP_ARRAY:
+			Build2DCubeArrayTexture(textureName, pImage->m_pImpl, forceConvertBits,
+				internalFormat, upload);
 			break;
 		}
 	}