changeset 2037:d81a7157a846 deep-learning

added OpenGLTexture::ConvertToOpenGLFormats()
author Sebastien Jodogne <s.jodogne@gmail.com>
date Sat, 28 Jan 2023 12:55:34 +0100
parents 444527d34647
children a72ca4959aa6
files OrthancStone/Sources/OpenGL/OpenGLTexture.cpp OrthancStone/Sources/OpenGL/OpenGLTexture.h
diffstat 2 files changed, 45 insertions(+), 32 deletions(-) [+]
line wrap: on
line diff
--- 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)));
+      }
+    }
   }
 }
--- 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);
     };
   }
 }