# HG changeset patch # User Sebastien Jodogne # Date 1674906934 -3600 # Node ID d81a7157a8460eff6d9c566cecba9376fa2263c5 # Parent 444527d34647956844def11a67b9021db21e2eb0 added OpenGLTexture::ConvertToOpenGLFormats() diff -r 444527d34647 -r d81a7157a846 OrthancStone/Sources/OpenGL/OpenGLTexture.cpp --- a/OrthancStone/Sources/OpenGL/OpenGLTexture.cpp Sat Jan 28 12:05:23 2023 +0100 +++ b/OrthancStone/Sources/OpenGL/OpenGLTexture.cpp Sat Jan 28 12:55:34 2023 +0100 @@ -102,38 +102,7 @@ glBindTexture(GL_TEXTURE_2D, texture_); GLenum sourceFormat, internalFormat, pixelType; - - switch (format) - { - case Orthanc::PixelFormat_Grayscale8: - sourceFormat = GL_RED; - internalFormat = GL_RED; - pixelType = GL_UNSIGNED_BYTE; - break; - - case Orthanc::PixelFormat_RGB24: - sourceFormat = GL_RGB; - internalFormat = GL_RGB; - pixelType = GL_UNSIGNED_BYTE; - break; - - case Orthanc::PixelFormat_RGBA32: - sourceFormat = GL_RGBA; - internalFormat = GL_RGBA; - pixelType = GL_UNSIGNED_BYTE; - break; - - case Orthanc::PixelFormat_Float32: - sourceFormat = GL_RED; - internalFormat = GL_R32F; // Don't use "GL_RED" here, as it clamps to [0,1] - pixelType = GL_FLOAT; - break; - - default: - throw Orthanc::OrthancException(Orthanc::ErrorCode_NotImplemented, - "No support for this format in OpenGL textures: " + - std::string(EnumerationToString(format))); - } + ConvertToOpenGLFormats(sourceFormat, internalFormat, pixelType, format); width_ = width; height_ = height; @@ -235,5 +204,44 @@ GLfloat colorfv[4] = { 0, 0, 0, 0 }; glTextureParameterfv(texture_, GL_TEXTURE_BORDER_COLOR, colorfv); } + + + void OpenGLTexture::ConvertToOpenGLFormats(GLenum& sourceFormat, + GLenum& internalFormat, + GLenum& pixelType, + Orthanc::PixelFormat format) + { + switch (format) + { + case Orthanc::PixelFormat_Grayscale8: + sourceFormat = GL_RED; + internalFormat = GL_RED; + pixelType = GL_UNSIGNED_BYTE; + break; + + case Orthanc::PixelFormat_RGB24: + sourceFormat = GL_RGB; + internalFormat = GL_RGB; + pixelType = GL_UNSIGNED_BYTE; + break; + + case Orthanc::PixelFormat_RGBA32: + sourceFormat = GL_RGBA; + internalFormat = GL_RGBA; + pixelType = GL_UNSIGNED_BYTE; + break; + + case Orthanc::PixelFormat_Float32: + sourceFormat = GL_RED; + internalFormat = GL_R32F; // Don't use "GL_RED" here, as it clamps to [0,1] + pixelType = GL_FLOAT; + break; + + default: + throw Orthanc::OrthancException(Orthanc::ErrorCode_NotImplemented, + "No support for this format in OpenGL textures: " + + std::string(EnumerationToString(format))); + } + } } } diff -r 444527d34647 -r d81a7157a846 OrthancStone/Sources/OpenGL/OpenGLTexture.h --- a/OrthancStone/Sources/OpenGL/OpenGLTexture.h Sat Jan 28 12:05:23 2023 +0100 +++ b/OrthancStone/Sources/OpenGL/OpenGLTexture.h Sat Jan 28 12:55:34 2023 +0100 @@ -89,6 +89,11 @@ * function will set out-of-image access to zero. **/ void SetClampingToZero(); + + static void ConvertToOpenGLFormats(GLenum& sourceFormat, + GLenum& internalFormat, + GLenum& pixelType, + Orthanc::PixelFormat format); }; } }