else
{
#if !defined(GL_ES_VERSION_2_0)
- glGetIntegerv (GL_READ_BUFFER, &aReadBufferPrev);
+ theGlCtx->core11fwd->glGetIntegerv (GL_READ_BUFFER, &aReadBufferPrev);
GLint aDrawBufferPrev = GL_BACK;
- glGetIntegerv (GL_DRAW_BUFFER, &aDrawBufferPrev);
+ theGlCtx->core11fwd->glGetIntegerv (GL_DRAW_BUFFER, &aDrawBufferPrev);
glReadBuffer (aDrawBufferPrev);
#endif
}
// setup alignment
- const GLint anAligment = Min (GLint(theImage.MaxRowAligmentBytes()), 8); // limit to 8 bytes for OpenGL
- glPixelStorei (GL_PACK_ALIGNMENT, anAligment);
+ const GLint anAligment = Min (GLint(theImage.MaxRowAligmentBytes()), 8); // limit to 8 bytes for OpenGL
+ theGlCtx->core11fwd->glPixelStorei (GL_PACK_ALIGNMENT, anAligment);
bool isBatchCopy = !theImage.IsTopDown();
const GLint anExtraBytes = GLint(theImage.RowExtraBytes());
aPixelsWidth = 0;
isBatchCopy = false;
}
-#if !defined(GL_ES_VERSION_2_0)
- glPixelStorei (GL_PACK_ROW_LENGTH, aPixelsWidth);
-#else
- if (aPixelsWidth != 0)
+ if (theGlCtx->hasPackRowLength)
+ {
+ theGlCtx->core11fwd->glPixelStorei (GL_PACK_ROW_LENGTH, aPixelsWidth);
+ }
+ else if (aPixelsWidth != 0)
{
isBatchCopy = false;
}
-#endif
+
if (toConvRgba2Rgb)
{
Handle(NCollection_BaseAllocator) anAlloc = new NCollection_AlignedAllocator (16);
{
// Image_PixMap rows indexation always starts from the upper corner
// while order in memory depends on the flag and processed by ChangeRow() method
- glReadPixels (0, GLint(theImage.SizeY() - aRow - 1), GLsizei (theImage.SizeX()), 1, aFormat, aType, aRowBuffer.ChangeData());
+ theGlCtx->core11fwd->glReadPixels (0, GLint(theImage.SizeY() - aRow - 1), GLsizei (theImage.SizeX()), 1, aFormat, aType, aRowBuffer.ChangeData());
const Image_ColorRGBA* aRowDataRgba = (const Image_ColorRGBA* )aRowBuffer.Data();
if (theImage.Format() == Image_Format_BGR)
{
{
// Image_PixMap rows indexation always starts from the upper corner
// while order in memory depends on the flag and processed by ChangeRow() method
- glReadPixels (0, GLint(theImage.SizeY() - aRow - 1), GLsizei (theImage.SizeX()), 1, aFormat, aType, theImage.ChangeRow (aRow));
+ theGlCtx->core11fwd->glReadPixels (0, GLint(theImage.SizeY() - aRow - 1), GLsizei (theImage.SizeX()), 1, aFormat, aType, theImage.ChangeRow (aRow));
}
}
else
{
- glReadPixels (0, 0, GLsizei (theImage.SizeX()), GLsizei (theImage.SizeY()), aFormat, aType, theImage.ChangeData());
+ theGlCtx->core11fwd->glReadPixels (0, 0, GLsizei (theImage.SizeX()), GLsizei (theImage.SizeY()), aFormat, aType, theImage.ChangeData());
}
const bool hasErrors = theGlCtx->ResetErrors (true);
- glPixelStorei (GL_PACK_ALIGNMENT, 1);
-#if !defined(GL_ES_VERSION_2_0)
- glPixelStorei (GL_PACK_ROW_LENGTH, 0);
-#endif
+ theGlCtx->core11fwd->glPixelStorei (GL_PACK_ALIGNMENT, 1);
+ if (theGlCtx->hasPackRowLength)
+ {
+ theGlCtx->core11fwd->glPixelStorei (GL_PACK_ROW_LENGTH, 0);
+ }
if (!theFbo.IsNull() && theFbo->IsValid())
{
#include <Image_PixMap.hxx>
#include <Image_SupportedFormats.hxx>
+#include <algorithm>
+
IMPLEMENT_STANDARD_RTTIEXT(OpenGl_Texture, OpenGl_NamedResource)
namespace
//! Simple class to reset unpack alignment settings
struct OpenGl_UnpackAlignmentSentry
{
-
//! Reset unpack alignment settings to safe values
- static void Reset()
+ static void Reset (const OpenGl_Context& theCtx)
{
- glPixelStorei (GL_UNPACK_ALIGNMENT, 1);
- #if !defined(GL_ES_VERSION_2_0)
- glPixelStorei (GL_UNPACK_ROW_LENGTH, 0);
- #endif
+ theCtx.core11fwd->glPixelStorei (GL_UNPACK_ALIGNMENT, 1);
+ if (theCtx.hasUnpackRowLength)
+ {
+ theCtx.core11fwd->glPixelStorei (GL_UNPACK_ROW_LENGTH, 0);
+ }
}
- OpenGl_UnpackAlignmentSentry() {}
+ OpenGl_UnpackAlignmentSentry (const Handle(OpenGl_Context)& theCtx)
+ : myCtx (theCtx.get()) {}
~OpenGl_UnpackAlignmentSentry()
{
- Reset();
+ Reset (*myCtx);
}
+private:
+ OpenGl_Context* myCtx;
};
//! Compute the upper mipmap level for complete mipmap set (e.g. till the 1x1 level).
if (theGlCtx->IsValid())
{
- glDeleteTextures (1, &myTextureId);
+ theGlCtx->core11fwd->glDeleteTextures (1, &myTextureId);
}
myTextureId = NO_TEXTURE;
mySizeX = mySizeY = mySizeZ = 0;
theCtx->core15fwd->glActiveTexture (GL_TEXTURE0 + theTextureUnit);
}
mySampler->Bind (theCtx, theTextureUnit);
- glBindTexture (myTarget, myTextureId);
+ theCtx->core11fwd->glBindTexture (myTarget, myTextureId);
}
// =======================================================================
theCtx->core15fwd->glActiveTexture (GL_TEXTURE0 + theTextureUnit);
}
mySampler->Unbind (theCtx, theTextureUnit);
- glBindTexture (myTarget, NO_TEXTURE);
+ theCtx->core11fwd->glBindTexture (myTarget, NO_TEXTURE);
}
//=======================================================================
#endif
#if !defined(GL_ES_VERSION_2_0)
- GLint aTestWidth = 0, aTestHeight = 0;
+ GLint aTestWidth = 0, aTestHeight = 0;
#endif
GLvoid* aDataPtr = (theImage != NULL) ? (GLvoid* )theImage->Data() : NULL;
// setup the alignment
- OpenGl_UnpackAlignmentSentry anUnpackSentry;
+ OpenGl_UnpackAlignmentSentry anUnpackSentry (theCtx);
(void)anUnpackSentry; // avoid compiler warning
if (aDataPtr != NULL)
{
const GLint anAligment = Min ((GLint )theImage->MaxRowAligmentBytes(), 8); // OpenGL supports alignment upto 8 bytes
theCtx->core11fwd->glPixelStorei (GL_UNPACK_ALIGNMENT, anAligment);
-
- #if !defined(GL_ES_VERSION_2_0)
- // notice that GL_UNPACK_ROW_LENGTH is not available on OpenGL ES 2.0 without GL_EXT_unpack_subimage extension
const GLint anExtraBytes = GLint(theImage->RowExtraBytes());
const GLint aPixelsWidth = GLint(theImage->SizeRowBytes() / theImage->SizePixelBytes());
- theCtx->core11fwd->glPixelStorei (GL_UNPACK_ROW_LENGTH, (anExtraBytes >= anAligment) ? aPixelsWidth : 0);
- #endif
+ if (theCtx->hasUnpackRowLength)
+ {
+ theCtx->core11fwd->glPixelStorei (GL_UNPACK_ROW_LENGTH, (anExtraBytes >= anAligment) ? aPixelsWidth : 0);
+ }
+ else if (anExtraBytes >= anAligment)
+ {
+ theCtx->PushMessage (GL_DEBUG_SOURCE_APPLICATION, GL_DEBUG_TYPE_PORTABILITY, 0, GL_DEBUG_SEVERITY_HIGH,
+ TCollection_AsciiString ("Error: unsupported image stride within OpenGL ES 2.0 [") + myResourceId +"]");
+ Release (theCtx.get());
+ return false;
+ }
}
myTarget = aTarget;
applyDefaultSamplerParams (theCtx);
// setup the alignment
- OpenGl_UnpackAlignmentSentry::Reset();
+ OpenGl_UnpackAlignmentSentry::Reset (*theCtx);
Graphic3d_Vec2i aMipSizeXY (theImage.SizeX(), theImage.SizeY());
const Standard_Byte* aData = theImage.FaceData()->Data();
{
const Standard_Integer aMipLength = theImage.MipMaps().Value (aMipIter);
theCtx->Functions()->glCompressedTexImage2D (GL_TEXTURE_2D, aMipIter, mySizedFormat, aMipSizeXY.x(), aMipSizeXY.y(), 0, aMipLength, aData);
- const GLenum aTexImgErr = glGetError();
+ const GLenum aTexImgErr = theCtx->core11fwd->glGetError();
if (aTexImgErr != GL_NO_ERROR)
{
theCtx->PushMessage (GL_DEBUG_SOURCE_APPLICATION, GL_DEBUG_TYPE_ERROR, 0, GL_DEBUG_SEVERITY_HIGH,
myNbSamples = 1;
myMaxMipLevel = 0;
- const GLsizei aSizeX = Min (theCtx->MaxTextureSize(), theSizeX);
- const GLsizei aSizeY = Min (theCtx->MaxTextureSize(), theSizeY);
+ const GLsizei aSizeX = Min (theCtx->MaxTextureSize(), theSizeX);
+ const GLsizei aSizeY = Min (theCtx->MaxTextureSize(), theSizeY);
Bind (theCtx);
applyDefaultSamplerParams (theCtx);
mySizedFormat = theFormat.Internal();
// setup the alignment
- OpenGl_UnpackAlignmentSentry::Reset();
+ OpenGl_UnpackAlignmentSentry::Reset (*theCtx);
theCtx->core11fwd->glTexImage2D (GL_PROXY_TEXTURE_RECTANGLE, 0, mySizedFormat,
aSizeX, aSizeY, 0,
myTextFormat, GL_FLOAT, NULL);
- GLint aTestSizeX = 0;
- GLint aTestSizeY = 0;
-
+ GLint aTestSizeX = 0, aTestSizeY = 0;
glGetTexLevelParameteriv (GL_PROXY_TEXTURE_RECTANGLE, 0, GL_TEXTURE_WIDTH, &aTestSizeX);
glGetTexLevelParameteriv (GL_PROXY_TEXTURE_RECTANGLE, 0, GL_TEXTURE_HEIGHT, &aTestSizeY);
glGetTexLevelParameteriv (GL_PROXY_TEXTURE_RECTANGLE, 0, GL_TEXTURE_INTERNAL_FORMAT, &mySizedFormat);
-
if (aTestSizeX == 0 || aTestSizeY == 0)
{
Unbind (theCtx);
theCtx->core11fwd->glTexImage2D (myTarget, 0, mySizedFormat,
aSizeX, aSizeY, 0,
myTextFormat, GL_FLOAT, NULL);
-
if (theCtx->core11fwd->glGetError() != GL_NO_ERROR)
{
Unbind (theCtx);
mySizeX = aSizeX;
mySizeY = aSizeY;
-
Unbind (theCtx);
return true;
#else
mySizedFormat = theFormat.InternalFormat();
// setup the alignment
- OpenGl_UnpackAlignmentSentry::Reset();
+ OpenGl_UnpackAlignmentSentry::Reset (*theCtx);
#if !defined (GL_ES_VERSION_2_0)
theCtx->core15fwd->glTexImage3D (GL_PROXY_TEXTURE_3D, 0, mySizedFormat,
}
}
- OpenGl_UnpackAlignmentSentry::Reset();
+ OpenGl_UnpackAlignmentSentry::Reset (*theCtx);
}
else
{
{
const Standard_Integer aMipLength = aCompImage->MipMaps().Value (aMipIter);
theCtx->Functions()->glCompressedTexImage2D (GL_TEXTURE_CUBE_MAP_POSITIVE_X + i, aMipIter, mySizedFormat, aMipSizeXY.x(), aMipSizeXY.y(), 0, aMipLength, aData);
- const GLenum aTexImgErr = glGetError();
+ const GLenum aTexImgErr = theCtx->core11fwd->glGetError();
if (aTexImgErr != GL_NO_ERROR)
{
theCtx->PushMessage (GL_DEBUG_SOURCE_APPLICATION, GL_DEBUG_TYPE_ERROR, 0, GL_DEBUG_SEVERITY_HIGH,
if (!anImage.IsNull())
{
-#if !defined(GL_ES_VERSION_2_0)
const GLint anAligment = Min ((GLint)anImage->MaxRowAligmentBytes(), 8); // OpenGL supports alignment upto 8 bytes
- theCtx->core11fwd->glPixelStorei (GL_UNPACK_ALIGNMENT, anAligment);
-
- // notice that GL_UNPACK_ROW_LENGTH is not available on OpenGL ES 2.0 without GL_EXT_unpack_subimage extension
const GLint anExtraBytes = GLint(anImage->RowExtraBytes());
const GLint aPixelsWidth = GLint(anImage->SizeRowBytes() / anImage->SizePixelBytes());
const GLint aRowLength = (anExtraBytes >= anAligment) ? aPixelsWidth : 0;
- theCtx->core11fwd->glPixelStorei (GL_UNPACK_ROW_LENGTH, aRowLength);
-#else
- Handle(Image_PixMap) aCopyImage = new Image_PixMap();
- aCopyImage->InitTrash (theFormat, theSize, theSize);
- for (unsigned int y = 0; y < theSize; ++y)
+ if (theCtx->hasUnpackRowLength)
+ {
+ theCtx->core11fwd->glPixelStorei (GL_UNPACK_ROW_LENGTH, aRowLength);
+ }
+
+ if (aRowLength > 0
+ && !theCtx->hasUnpackRowLength)
{
- for (unsigned int x = 0; x < theSize; ++x)
+ Handle(Image_PixMap) aCopyImage = new Image_PixMap();
+ aCopyImage->InitTrash (theFormat, theSize, theSize);
+ const Standard_Size aRowBytesPacked = std::min (aCopyImage->SizeRowBytes(), anImage->SizeRowBytes());
+ for (unsigned int y = 0; y < theSize; ++y)
{
- for (unsigned int aByte = 0; aByte < anImage->SizePixelBytes(); ++aByte)
- {
- aCopyImage->ChangeRawValue (y, x)[aByte] = anImage->RawValue (y, x)[aByte];
- }
+ memcpy (aCopyImage->ChangeRow (y), anImage->ChangeRow (y), aRowBytesPacked);
}
+ anImage = aCopyImage;
+ const GLint anAligment2 = Min((GLint)anImage->MaxRowAligmentBytes(), 8); // OpenGL supports alignment upto 8 bytes
+ theCtx->core11fwd->glPixelStorei (GL_UNPACK_ALIGNMENT, anAligment2);
}
- anImage = aCopyImage;
- const GLint anAligment = Min((GLint)anImage->MaxRowAligmentBytes(), 8); // OpenGL supports alignment upto 8 bytes
- theCtx->core11fwd->glPixelStorei (GL_UNPACK_ALIGNMENT, anAligment);
-#endif
+ else
+ {
+ theCtx->core11fwd->glPixelStorei (GL_UNPACK_ALIGNMENT, anAligment);
+ }
+
aData = anImage->Data();
}
else
0, aFormat.PixelFormat(), aFormat.DataType(),
aData);
- OpenGl_UnpackAlignmentSentry::Reset();
+ OpenGl_UnpackAlignmentSentry::Reset (*theCtx);
const GLenum anErr = theCtx->core11fwd->glGetError();
if (anErr != GL_NO_ERROR)
const GLint anAligment = Min (GLint(theImage.MaxRowAligmentBytes()), 8); // limit to 8 bytes for OpenGL
theCtx->core11fwd->glPixelStorei (GL_PACK_ALIGNMENT, anAligment);
- theCtx->core11fwd->glPixelStorei (GL_PACK_ROW_LENGTH, 0);
+ if (theCtx->hasPackRowLength)
+ {
+ theCtx->core11fwd->glPixelStorei (GL_PACK_ROW_LENGTH, 0);
+ }
// glGetTextureImage() allows avoiding to binding texture id, but apparently requires clean FBO binding state...
//if (theCtx->core45 != NULL) { theCtx->core45->glGetTextureImage (myTextureId, theLevel, aFormat.PixelFormat(), aFormat.DataType(), (GLsizei )theImage.SizeBytes(), theImage.ChangeData()); } else
{