class OpenGl_Context;
class Image_PixMap;
+//! Selects preferable texture format for specified parameters.
+template<class T>
+struct OpenGl_TextureFormatSelector
+{
+ // Not implemented
+};
+
+template<>
+struct OpenGl_TextureFormatSelector<GLubyte>
+{
+ static GLint Internal (GLuint theChannels)
+ {
+ switch (theChannels)
+ {
+ case 1:
+ return GL_R8;
+ case 2:
+ return GL_RG8;
+ case 3:
+ return GL_RGB8;
+ case 4:
+ return GL_RGBA8;
+ default:
+ return GL_NONE;
+ }
+ }
+};
+
+template<>
+struct OpenGl_TextureFormatSelector<GLushort>
+{
+ static GLint Internal (GLuint theChannels)
+ {
+ switch (theChannels)
+ {
+ case 1:
+ return GL_R16;
+ case 2:
+ return GL_RG16;
+ case 3:
+ return GL_RGB16;
+ case 4:
+ return GL_RGBA16;
+ default:
+ return GL_NONE;
+ }
+ }
+};
+
+template<>
+struct OpenGl_TextureFormatSelector<GLfloat>
+{
+ static GLint Internal (GLuint theChannels)
+ {
+ switch (theChannels)
+ {
+ case 1:
+ return GL_R32F;
+ case 2:
+ return GL_RG32F;
+ case 3:
+ return GL_RGB32F;
+ case 4:
+ return GL_RGBA32F;
+ default:
+ return GL_NONE;
+ }
+ }
+};
+
+//! Stores parameters of OpenGL texture format.
+class OpenGl_TextureFormat
+{
+ friend class OpenGl_Texture;
+
+public:
+
+ //! Returns OpenGL format of the pixel data.
+ inline GLenum Format() const
+ {
+ switch (myChannels)
+ {
+ case 1:
+ return GL_RED;
+ case 2:
+ return GL_RG;
+ case 3:
+ return GL_RGB;
+ case 4:
+ return GL_RGBA;
+ default:
+ return GL_NONE;
+ }
+ }
+
+ //! Returns OpenGL internal format of the pixel data.
+ inline GLint Internal() const
+ {
+ return myInternal;
+ }
+
+ //! Returns texture format for specified type and number of channels.
+ template<class T, int N>
+ static OpenGl_TextureFormat Create()
+ {
+ return OpenGl_TextureFormat (N, OpenGl_TextureFormatSelector<T>::Internal (N));
+ }
+
+private:
+
+ //! Creates new texture format.
+ OpenGl_TextureFormat (const GLint theChannels, const GLint theInternal)
+ : myChannels (theChannels),
+ myInternal (theInternal)
+ {
+ //
+ }
+
+private:
+
+ //! OpenGL internal format of the pixel data.
+ GLint myInternal;
+
+ //! Number of channels for each pixel (from 1 to 4).
+ GLint myChannels;
+};
+
//! Texture resource.
class OpenGl_Texture : public OpenGl_Resource
{
const Image_PixMap& theImage,
const Graphic3d_TypeOfTexture theType);
+ //! Allocates texture rectangle with specified format and size.
+ //! \note Texture data is not initialized (will contain trash).
+ Standard_EXPORT bool InitRectangle (const Handle(OpenGl_Context)& theCtx,
+ const Standard_Integer theSizeX,
+ const Standard_Integer theSizeY,
+ const OpenGl_TextureFormat& theFormat);
+
//! @return true if texture was generated within mipmaps
Standard_EXPORT const Standard_Boolean HasMipmaps() const;