1 // Created by: Kirill GAVRILOV
2 // Copyright (c) 2013-2014 OPEN CASCADE SAS
4 // This file is part of Open CASCADE Technology software library.
6 // This library is free software; you can redistribute it and/or modify it under
7 // the terms of the GNU Lesser General Public License version 2.1 as published
8 // by the Free Software Foundation, with special exception defined in the file
9 // OCCT_LGPL_EXCEPTION.txt. Consult the file LICENSE_LGPL_21.txt included in OCCT
10 // distribution for complete text of the license and disclaimer of any warranty.
12 // Alternatively, this file may be used under the terms of Open CASCADE
13 // commercial license or contractual agreement.
15 #include <OpenGl_Texture.hxx>
17 #include <OpenGl_ArbFBO.hxx>
18 #include <OpenGl_Context.hxx>
19 #include <OpenGl_GlCore32.hxx>
20 #include <Graphic3d_TextureParams.hxx>
21 #include <TCollection_ExtendedString.hxx>
22 #include <Standard_Assert.hxx>
23 #include <Image_PixMap.hxx>
26 IMPLEMENT_STANDARD_RTTIEXT(OpenGl_Texture,OpenGl_Resource)
28 //! Simple class to reset unpack alignment settings
29 struct OpenGl_UnpackAlignmentSentry
32 //! Reset unpack alignment settings to safe values
35 glPixelStorei (GL_UNPACK_ALIGNMENT, 1);
36 #if !defined(GL_ES_VERSION_2_0)
37 glPixelStorei (GL_UNPACK_ROW_LENGTH, 0);
41 ~OpenGl_UnpackAlignmentSentry()
48 // =======================================================================
49 // function : OpenGl_Texture
51 // =======================================================================
52 OpenGl_Texture::OpenGl_Texture (const Handle(Graphic3d_TextureParams)& theParams)
54 myTextureId (NO_TEXTURE),
55 myTarget (GL_TEXTURE_2D),
59 myTextFormat (GL_RGBA),
60 myHasMipmaps (Standard_False),
64 if (myParams.IsNull())
66 myParams = new Graphic3d_TextureParams();
70 // =======================================================================
71 // function : ~OpenGl_Texture
73 // =======================================================================
74 OpenGl_Texture::~OpenGl_Texture()
79 // =======================================================================
80 // function : HasMipmaps
82 // =======================================================================
83 Standard_Boolean OpenGl_Texture::HasMipmaps() const
88 // =======================================================================
89 // function : GetParams
91 // =======================================================================
92 const Handle(Graphic3d_TextureParams)& OpenGl_Texture::GetParams() const
97 // =======================================================================
98 // function : SetParams
100 // =======================================================================
101 void OpenGl_Texture::SetParams (const Handle(Graphic3d_TextureParams)& theParams)
103 myParams = theParams;
106 // =======================================================================
109 // =======================================================================
110 bool OpenGl_Texture::Create (const Handle(OpenGl_Context)& )
112 if (myTextureId == NO_TEXTURE)
114 glGenTextures (1, &myTextureId);
116 return myTextureId != NO_TEXTURE;
119 // =======================================================================
120 // function : Release
122 // =======================================================================
123 void OpenGl_Texture::Release (OpenGl_Context* theGlCtx)
125 if (myTextureId == NO_TEXTURE)
130 // application can not handle this case by exception - this is bug in code
131 Standard_ASSERT_RETURN (theGlCtx != NULL,
132 "OpenGl_Texture destroyed without GL context! Possible GPU memory leakage...",);
134 if (theGlCtx->IsValid())
136 glDeleteTextures (1, &myTextureId);
138 myTextureId = NO_TEXTURE;
139 mySizeX = mySizeY = 0;
142 // =======================================================================
145 // =======================================================================
146 void OpenGl_Texture::Bind (const Handle(OpenGl_Context)& theCtx,
147 const GLenum theTextureUnit) const
149 if (theCtx->core15fwd != NULL)
151 theCtx->core15fwd->glActiveTexture (theTextureUnit);
153 glBindTexture (myTarget, myTextureId);
156 // =======================================================================
159 // =======================================================================
160 void OpenGl_Texture::Unbind (const Handle(OpenGl_Context)& theCtx,
161 const GLenum theTextureUnit) const
163 if (theCtx->core15fwd != NULL)
165 theCtx->core15fwd->glActiveTexture (theTextureUnit);
167 glBindTexture (myTarget, NO_TEXTURE);
170 //=======================================================================
171 //function : GetDataFormat
173 //=======================================================================
174 bool OpenGl_Texture::GetDataFormat (const Handle(OpenGl_Context)& theCtx,
175 const Image_PixMap& theData,
176 GLint& theTextFormat,
177 GLenum& thePixelFormat,
180 theTextFormat = GL_RGBA8;
183 switch (theData.Format())
185 case Image_PixMap::ImgGrayF:
187 if (theCtx->core11 == NULL)
189 theTextFormat = GL_R8; // GL_R32F
190 thePixelFormat = GL_RED;
194 theTextFormat = GL_LUMINANCE8;
195 thePixelFormat = GL_LUMINANCE;
197 theDataType = GL_FLOAT;
200 case Image_PixMap::ImgAlphaF:
202 if (theCtx->core11 == NULL)
204 theTextFormat = GL_R8; // GL_R32F
205 thePixelFormat = GL_RED;
209 theTextFormat = GL_ALPHA8;
210 thePixelFormat = GL_ALPHA;
212 theDataType = GL_FLOAT;
215 case Image_PixMap::ImgRGBAF:
217 theTextFormat = GL_RGBA8; // GL_RGBA32F
218 thePixelFormat = GL_RGBA;
219 theDataType = GL_FLOAT;
222 case Image_PixMap::ImgBGRAF:
224 if (!theCtx->IsGlGreaterEqual (1, 2) && !theCtx->extBgra)
228 theTextFormat = GL_RGBA8; // GL_RGBA32F
229 thePixelFormat = GL_BGRA_EXT; // equals to GL_BGRA
230 theDataType = GL_FLOAT;
233 case Image_PixMap::ImgRGBF:
235 theTextFormat = GL_RGB8; // GL_RGB32F
236 thePixelFormat = GL_RGB;
237 theDataType = GL_FLOAT;
240 case Image_PixMap::ImgBGRF:
242 #if !defined(GL_ES_VERSION_2_0)
243 theTextFormat = GL_RGB8; // GL_RGB32F
244 thePixelFormat = GL_BGR; // equals to GL_BGR_EXT
245 theDataType = GL_FLOAT;
251 case Image_PixMap::ImgRGBA:
253 theTextFormat = GL_RGBA8;
254 thePixelFormat = GL_RGBA;
255 theDataType = GL_UNSIGNED_BYTE;
258 case Image_PixMap::ImgBGRA:
260 if (!theCtx->IsGlGreaterEqual (1, 2) && !theCtx->extBgra)
264 theTextFormat = GL_RGBA8;
265 thePixelFormat = GL_BGRA_EXT; // equals to GL_BGRA
266 theDataType = GL_UNSIGNED_BYTE;
269 case Image_PixMap::ImgRGB32:
271 theTextFormat = GL_RGB8;
272 thePixelFormat = GL_RGBA;
273 theDataType = GL_UNSIGNED_BYTE;
276 case Image_PixMap::ImgBGR32:
278 if (!theCtx->IsGlGreaterEqual (1, 2) && !theCtx->extBgra)
282 theTextFormat = GL_RGB8;
283 thePixelFormat = GL_BGRA_EXT; // equals to GL_BGRA
284 theDataType = GL_UNSIGNED_BYTE;
287 case Image_PixMap::ImgRGB:
289 theTextFormat = GL_RGB8;
290 thePixelFormat = GL_RGB;
291 theDataType = GL_UNSIGNED_BYTE;
294 case Image_PixMap::ImgBGR:
296 #if !defined(GL_ES_VERSION_2_0)
297 if (!theCtx->IsGlGreaterEqual (1, 2) && !theCtx->extBgra)
301 theTextFormat = GL_RGB8;
302 thePixelFormat = GL_BGR; // equals to GL_BGR_EXT
303 theDataType = GL_UNSIGNED_BYTE;
309 case Image_PixMap::ImgGray:
311 if (theCtx->core11 == NULL)
313 theTextFormat = GL_R8;
314 thePixelFormat = GL_RED;
318 theTextFormat = GL_LUMINANCE8;
319 thePixelFormat = GL_LUMINANCE;
321 theDataType = GL_UNSIGNED_BYTE;
324 case Image_PixMap::ImgAlpha:
326 if (theCtx->core11 == NULL)
328 theTextFormat = GL_R8;
329 thePixelFormat = GL_RED;
333 theTextFormat = GL_ALPHA8;
334 thePixelFormat = GL_ALPHA;
336 theDataType = GL_UNSIGNED_BYTE;
339 case Image_PixMap::ImgUNKNOWN:
347 // =======================================================================
350 // =======================================================================
351 bool OpenGl_Texture::Init (const Handle(OpenGl_Context)& theCtx,
352 const Standard_Integer theTextFormat,
353 const GLenum thePixelFormat,
354 const GLenum theDataType,
355 const Standard_Integer theSizeX,
356 const Standard_Integer theSizeY,
357 const Graphic3d_TypeOfTexture theType,
358 const Image_PixMap* theImage)
360 if (!Create (theCtx))
362 Release (theCtx.operator->());
366 if (theImage != NULL)
368 myIsAlpha = theImage->Format() == Image_PixMap::ImgAlpha
369 || theImage->Format() == Image_PixMap::ImgAlphaF;
373 myIsAlpha = thePixelFormat == GL_ALPHA;
376 myHasMipmaps = Standard_False;
377 myTextFormat = thePixelFormat;
378 #if !defined(GL_ES_VERSION_2_0)
379 const GLint anIntFormat = theTextFormat;
381 // ES does not support sized formats and format conversions - them detected from data type
382 const GLint anIntFormat = thePixelFormat;
383 (void) theTextFormat;
385 const GLsizei aWidth = theSizeX;
386 const GLsizei aHeight = theSizeY;
387 const GLsizei aMaxSize = theCtx->MaxTextureSize();
389 if (aWidth > aMaxSize || aHeight > aMaxSize)
391 TCollection_ExtendedString aWarnMessage = TCollection_ExtendedString ("Error: Texture dimension - ")
392 + aWidth + "x" + aHeight + " exceeds hardware limits (" + aMaxSize + "x" + aMaxSize + ")";
394 theCtx->PushMessage (GL_DEBUG_SOURCE_APPLICATION, GL_DEBUG_TYPE_ERROR, 0, GL_DEBUG_SEVERITY_HIGH, aWarnMessage);
395 Release (theCtx.operator->());
398 #if !defined(GL_ES_VERSION_2_0)
399 else if (!theCtx->IsGlGreaterEqual (3, 0) && !theCtx->arbNPTW)
401 // Notice that formally general NPOT textures are required by OpenGL 2.0 specifications
402 // however some hardware (NV30 - GeForce FX, RadeOn 9xxx and Xxxx) supports GLSL but not NPOT!
403 // Trying to create NPOT textures on such hardware will not fail
404 // but driver will fall back into software rendering,
405 const GLsizei aWidthP2 = OpenGl_Context::GetPowerOfTwo (aWidth, aMaxSize);
406 const GLsizei aHeightP2 = OpenGl_Context::GetPowerOfTwo (aHeight, aMaxSize);
408 if (aWidth != aWidthP2 || (theType != Graphic3d_TOT_1D && aHeight != aHeightP2))
410 TCollection_ExtendedString aWarnMessage =
411 TCollection_ExtendedString ("Error: NPOT Textures (") + aWidth + "x" + aHeight + ") are not supported by hardware.";
413 theCtx->PushMessage (GL_DEBUG_SOURCE_APPLICATION, GL_DEBUG_TYPE_PORTABILITY, 0, GL_DEBUG_SEVERITY_HIGH, aWarnMessage);
415 Release (theCtx.operator->());
420 else if (!theCtx->IsGlGreaterEqual (3, 0) && theType == Graphic3d_TOT_2D_MIPMAP)
422 // Mipmap NPOT textures are not supported by OpenGL ES 2.0.
423 const GLsizei aWidthP2 = OpenGl_Context::GetPowerOfTwo (aWidth, aMaxSize);
424 const GLsizei aHeightP2 = OpenGl_Context::GetPowerOfTwo (aHeight, aMaxSize);
426 if (aWidth != aWidthP2 || aHeight != aHeightP2)
428 TCollection_ExtendedString aWarnMessage =
429 TCollection_ExtendedString ("Error: Mipmap NPOT Textures (") + aWidth + "x" + aHeight + ") are not supported by OpenGL ES 2.0";
431 theCtx->PushMessage (GL_DEBUG_SOURCE_APPLICATION, GL_DEBUG_TYPE_PORTABILITY, 0, GL_DEBUG_SEVERITY_HIGH, aWarnMessage);
433 Release (theCtx.operator->());
439 const GLenum aFilter = (myParams->Filter() == Graphic3d_TOTF_NEAREST) ? GL_NEAREST : GL_LINEAR;
440 const GLenum aWrapMode = myParams->IsRepeat() ? GL_REPEAT : theCtx->TextureWrapClamp();
442 #if !defined(GL_ES_VERSION_2_0)
443 GLint aTestWidth = 0;
444 GLint aTestHeight = 0;
446 GLvoid* aDataPtr = (theImage != NULL) ? (GLvoid* )theImage->Data() : NULL;
448 // setup the alignment
449 OpenGl_UnpackAlignmentSentry anUnpackSentry;
450 (void)anUnpackSentry; // avoid compiler warning
452 if (aDataPtr != NULL)
454 const GLint anAligment = Min ((GLint )theImage->MaxRowAligmentBytes(), 8); // OpenGL supports alignment upto 8 bytes
455 glPixelStorei (GL_UNPACK_ALIGNMENT, anAligment);
457 #if !defined(GL_ES_VERSION_2_0)
458 // notice that GL_UNPACK_ROW_LENGTH is not available on OpenGL ES 2.0 without GL_EXT_unpack_subimage extension
459 const GLint anExtraBytes = GLint(theImage->RowExtraBytes());
460 const GLint aPixelsWidth = GLint(theImage->SizeRowBytes() / theImage->SizePixelBytes());
461 glPixelStorei (GL_UNPACK_ROW_LENGTH, (anExtraBytes >= anAligment) ? aPixelsWidth : 0);
467 case Graphic3d_TOT_1D:
469 #if !defined(GL_ES_VERSION_2_0)
470 myTarget = GL_TEXTURE_1D;
472 glTexParameteri (GL_TEXTURE_1D, GL_TEXTURE_MAG_FILTER, aFilter);
473 glTexParameteri (GL_TEXTURE_1D, GL_TEXTURE_MIN_FILTER, aFilter);
474 glTexParameteri (GL_TEXTURE_1D, GL_TEXTURE_WRAP_S, aWrapMode);
476 // use proxy to check texture could be created or not
477 glTexImage1D (GL_PROXY_TEXTURE_1D, 0, anIntFormat,
479 thePixelFormat, theDataType, NULL);
480 glGetTexLevelParameteriv (GL_PROXY_TEXTURE_2D, 0, GL_TEXTURE_WIDTH, &aTestWidth);
483 // no memory or broken input parameters
485 Release (theCtx.operator->());
489 glTexImage1D (GL_TEXTURE_1D, 0, anIntFormat,
491 thePixelFormat, theDataType, aDataPtr);
492 if (glGetError() != GL_NO_ERROR)
495 Release (theCtx.operator->());
505 Release (theCtx.operator->());
509 case Graphic3d_TOT_2D:
511 myTarget = GL_TEXTURE_2D;
513 glTexParameteri (GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, aFilter);
514 glTexParameteri (GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, aFilter);
515 glTexParameteri (GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, aWrapMode);
516 glTexParameteri (GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, aWrapMode);
518 #if !defined(GL_ES_VERSION_2_0)
519 // use proxy to check texture could be created or not
520 glTexImage2D (GL_PROXY_TEXTURE_2D, 0, anIntFormat,
522 thePixelFormat, theDataType, NULL);
523 glGetTexLevelParameteriv (GL_PROXY_TEXTURE_2D, 0, GL_TEXTURE_WIDTH, &aTestWidth);
524 glGetTexLevelParameteriv (GL_PROXY_TEXTURE_2D, 0, GL_TEXTURE_HEIGHT, &aTestHeight);
525 if (aTestWidth == 0 || aTestHeight == 0)
527 // no memory or broken input parameters
529 Release (theCtx.operator->());
534 glTexImage2D (GL_TEXTURE_2D, 0, anIntFormat,
536 thePixelFormat, theDataType, aDataPtr);
537 if (glGetError() != GL_NO_ERROR)
540 Release (theCtx.operator->());
550 case Graphic3d_TOT_2D_MIPMAP:
552 myTarget = GL_TEXTURE_2D;
553 myHasMipmaps = Standard_True;
555 GLenum aFilterMin = aFilter;
556 aFilterMin = GL_NEAREST_MIPMAP_NEAREST;
557 if (myParams->Filter() == Graphic3d_TOTF_BILINEAR)
559 aFilterMin = GL_LINEAR_MIPMAP_NEAREST;
561 else if (myParams->Filter() == Graphic3d_TOTF_TRILINEAR)
563 aFilterMin = GL_LINEAR_MIPMAP_LINEAR;
567 glTexParameteri (GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, aFilterMin);
568 glTexParameteri (GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, aFilter);
569 glTexParameteri (GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, aWrapMode);
570 glTexParameteri (GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, aWrapMode);
572 #if !defined(GL_ES_VERSION_2_0)
573 // use proxy to check texture could be created or not
574 glTexImage2D (GL_PROXY_TEXTURE_2D, 0, anIntFormat,
576 thePixelFormat, theDataType, NULL);
577 glGetTexLevelParameteriv (GL_PROXY_TEXTURE_2D, 0, GL_TEXTURE_WIDTH, &aTestWidth);
578 glGetTexLevelParameteriv (GL_PROXY_TEXTURE_2D, 0, GL_TEXTURE_HEIGHT, &aTestHeight);
579 if (aTestWidth == 0 || aTestHeight == 0)
581 // no memory or broken input parameters
583 Release (theCtx.operator->());
588 // upload main picture
589 glTexImage2D (GL_TEXTURE_2D, 0, anIntFormat,
591 thePixelFormat, theDataType, theImage->Data());
592 if (glGetError() != GL_NO_ERROR)
595 Release (theCtx.operator->());
602 if (theCtx->arbFBO != NULL)
605 //glHint (GL_GENERATE_MIPMAP_HINT, GL_NICEST);
606 theCtx->arbFBO->glGenerateMipmap (GL_TEXTURE_2D);
608 if (glGetError() != GL_NO_ERROR)
611 Release (theCtx.operator->());
617 const TCollection_ExtendedString aWarnMessage ("Warning: generating mipmaps requires GL_ARB_framebuffer_object extension which is missing.");
619 theCtx->PushMessage (GL_DEBUG_SOURCE_APPLICATION, GL_DEBUG_TYPE_PORTABILITY, 0, GL_DEBUG_SEVERITY_HIGH, aWarnMessage);
622 Release (theCtx.operator->());
631 Release (theCtx.operator->());
637 // =======================================================================
640 // =======================================================================
641 bool OpenGl_Texture::Init (const Handle(OpenGl_Context)& theCtx,
642 const Image_PixMap& theImage,
643 const Graphic3d_TypeOfTexture theType)
645 if (theImage.IsEmpty())
647 Release (theCtx.operator->());
654 if (!GetDataFormat (theCtx, theImage, aTextFormat, aPixelFormat, aDataType))
656 Release (theCtx.operator->());
661 aTextFormat, aPixelFormat, aDataType,
662 (Standard_Integer)theImage.SizeX(),
663 (Standard_Integer)theImage.SizeY(),
667 // =======================================================================
668 // function : Init2DMultisample
670 // =======================================================================
671 bool OpenGl_Texture::Init2DMultisample (const Handle(OpenGl_Context)& theCtx,
672 const GLsizei theNbSamples,
673 const GLint theTextFormat,
674 const GLsizei theSizeX,
675 const GLsizei theSizeY)
678 || theNbSamples > theCtx->MaxMsaaSamples()
684 const GLsizei aNbSamples = OpenGl_Context::GetPowerOfTwo (theNbSamples, theCtx->MaxMsaaSamples());
685 myTarget = GL_TEXTURE_2D_MULTISAMPLE;
686 if(theSizeX > theCtx->MaxTextureSize()
687 || theSizeY > theCtx->MaxTextureSize())
693 //myTextFormat = theTextFormat;
694 #if !defined(GL_ES_VERSION_2_0)
695 if (theCtx->Functions()->glTexStorage2DMultisample != NULL)
697 theCtx->Functions()->glTexStorage2DMultisample (myTarget, aNbSamples, theTextFormat, theSizeX, theSizeY, GL_FALSE);
701 theCtx->Functions()->glTexImage2DMultisample (myTarget, aNbSamples, theTextFormat, theSizeX, theSizeY, GL_FALSE);
704 theCtx->Functions() ->glTexStorage2DMultisample (myTarget, aNbSamples, theTextFormat, theSizeX, theSizeY, GL_FALSE);
706 if (theCtx->core11fwd->glGetError() != GL_NO_ERROR)
719 // =======================================================================
720 // function : InitRectangle
722 // =======================================================================
723 bool OpenGl_Texture::InitRectangle (const Handle(OpenGl_Context)& theCtx,
724 const Standard_Integer theSizeX,
725 const Standard_Integer theSizeY,
726 const OpenGl_TextureFormat& theFormat)
728 if (!Create (theCtx) || !theCtx->IsGlGreaterEqual (3, 0))
733 #if !defined(GL_ES_VERSION_2_0)
734 myTarget = GL_TEXTURE_RECTANGLE;
736 const GLsizei aSizeX = Min (theCtx->MaxTextureSize(), theSizeX);
737 const GLsizei aSizeY = Min (theCtx->MaxTextureSize(), theSizeY);
738 const GLenum aFilter = (myParams->Filter() == Graphic3d_TOTF_NEAREST) ? GL_NEAREST : GL_LINEAR;
739 const GLenum aWrapMode = myParams->IsRepeat() ? GL_REPEAT : theCtx->TextureWrapClamp();
742 glTexParameteri (myTarget, GL_TEXTURE_MIN_FILTER, aFilter);
743 glTexParameteri (myTarget, GL_TEXTURE_MAG_FILTER, aFilter);
744 glTexParameteri (myTarget, GL_TEXTURE_WRAP_S, aWrapMode);
745 glTexParameteri (myTarget, GL_TEXTURE_WRAP_T, aWrapMode);
747 const GLint anIntFormat = theFormat.Internal();
748 myTextFormat = theFormat.Format();
750 glTexImage2D (GL_PROXY_TEXTURE_RECTANGLE,
760 GLint aTestSizeX = 0;
761 GLint aTestSizeY = 0;
763 glGetTexLevelParameteriv (
764 GL_PROXY_TEXTURE_RECTANGLE, 0, GL_TEXTURE_WIDTH, &aTestSizeX);
765 glGetTexLevelParameteriv (
766 GL_PROXY_TEXTURE_RECTANGLE, 0, GL_TEXTURE_HEIGHT, &aTestSizeY);
768 if (aTestSizeX == 0 || aTestSizeY == 0)
774 glTexImage2D (myTarget,
784 if (glGetError() != GL_NO_ERROR)
803 // =======================================================================
806 // =======================================================================
807 bool OpenGl_Texture::Init3D (const Handle(OpenGl_Context)& theCtx,
808 const GLint theTextFormat,
809 const GLenum thePixelFormat,
810 const GLenum theDataType,
811 const Standard_Integer theSizeX,
812 const Standard_Integer theSizeY,
813 const Standard_Integer theSizeZ,
814 const void* thePixels)
816 if (theCtx->Functions()->glTexImage3D == NULL)
818 TCollection_ExtendedString aMsg ("Error: three-dimensional textures are not supported by hardware.");
820 theCtx->PushMessage (GL_DEBUG_SOURCE_APPLICATION,
823 GL_DEBUG_SEVERITY_HIGH,
834 myTarget = GL_TEXTURE_3D;
836 const GLsizei aSizeX = Min (theCtx->MaxTextureSize(), theSizeX);
837 const GLsizei aSizeY = Min (theCtx->MaxTextureSize(), theSizeY);
838 const GLsizei aSizeZ = Min (theCtx->MaxTextureSize(), theSizeZ);
842 if (theDataType == GL_FLOAT && !theCtx->arbTexFloat)
844 TCollection_ExtendedString aMsg ("Error: floating-point textures are not supported by hardware.");
846 theCtx->PushMessage (GL_DEBUG_SOURCE_APPLICATION,
849 GL_DEBUG_SEVERITY_HIGH,
852 Release (theCtx.operator->());
857 const GLint anIntFormat = theTextFormat;
859 #if !defined (GL_ES_VERSION_2_0)
860 theCtx->core15fwd->glTexImage3D (GL_PROXY_TEXTURE_3D,
871 GLint aTestSizeX = 0;
872 GLint aTestSizeY = 0;
873 GLint aTestSizeZ = 0;
875 glGetTexLevelParameteriv (GL_PROXY_TEXTURE_3D, 0, GL_TEXTURE_WIDTH, &aTestSizeX);
876 glGetTexLevelParameteriv (GL_PROXY_TEXTURE_3D, 0, GL_TEXTURE_HEIGHT, &aTestSizeY);
877 glGetTexLevelParameteriv (GL_PROXY_TEXTURE_3D, 0, GL_TEXTURE_DEPTH, &aTestSizeZ);
879 if (aTestSizeX == 0 || aTestSizeY == 0 || aTestSizeZ == 0)
882 Release (theCtx.operator->());
887 const GLenum aWrapMode = myParams->IsRepeat() ? GL_REPEAT : theCtx->TextureWrapClamp();
888 const GLenum aFilter = (myParams->Filter() == Graphic3d_TOTF_NEAREST) ? GL_NEAREST : GL_LINEAR;
890 glTexParameteri (myTarget, GL_TEXTURE_WRAP_S, aWrapMode);
891 glTexParameteri (myTarget, GL_TEXTURE_WRAP_T, aWrapMode);
892 glTexParameteri (myTarget, GL_TEXTURE_WRAP_R, aWrapMode);
894 glTexParameteri (myTarget, GL_TEXTURE_MIN_FILTER, aFilter);
895 glTexParameteri (myTarget, GL_TEXTURE_MAG_FILTER, aFilter);
897 theCtx->Functions()->glTexImage3D (myTarget,
908 if (glGetError() != GL_NO_ERROR)
911 Release (theCtx.operator->());