changeset 2034:4b24b7533346 deep-learning

cont
author Sebastien Jodogne <s.jodogne@gmail.com>
date Fri, 27 Jan 2023 15:43:24 +0100
parents 23b0a42eea85
children a73a8415780f
files OrthancStone/Sources/OpenGL/OpenGLTexture.cpp OrthancStone/Sources/OpenGL/OpenGLTexture.h
diffstat 2 files changed, 51 insertions(+), 15 deletions(-) [+]
line wrap: on
line diff
--- a/OrthancStone/Sources/OpenGL/OpenGLTexture.cpp	Sun Jan 22 10:48:22 2023 +0100
+++ b/OrthancStone/Sources/OpenGL/OpenGLTexture.cpp	Fri Jan 27 15:43:24 2023 +0100
@@ -82,26 +82,28 @@
       }
     }
 
-    void OpenGLTexture::Load(const Orthanc::ImageAccessor& image,
-                             bool isLinearInterpolation)
+    void OpenGLTexture::Setup(Orthanc::PixelFormat format,
+                              unsigned int width,
+                              unsigned int height,
+                              bool isLinearInterpolation,
+                              const void* data)
     {
-      if (!context_.IsContextLost())
+      if (context_.IsContextLost())
+      {
+        throw Orthanc::OrthancException(Orthanc::ErrorCode_InternalError,
+            "OpenGL context has been lost");
+      }
+      else
       {
         glPixelStorei(GL_UNPACK_ALIGNMENT, 1); // Disable byte-alignment restriction
 
-        if (image.GetPitch() != image.GetBytesPerPixel() * image.GetWidth())
-        {
-          throw Orthanc::OrthancException(Orthanc::ErrorCode_NotImplemented,
-            "Pitch is not the same as the row size");
-        }
-
         // Bind it
         glActiveTexture(GL_TEXTURE0);
         glBindTexture(GL_TEXTURE_2D, texture_);
 
         GLenum sourceFormat, internalFormat, pixelType;
 
-        switch (image.GetFormat())
+        switch (format)
         {
         case Orthanc::PixelFormat_Grayscale8:
           sourceFormat = GL_RED;
@@ -130,17 +132,17 @@
         default:
           throw Orthanc::OrthancException(Orthanc::ErrorCode_NotImplemented,
             "No support for this format in OpenGL textures: " +
-            std::string(EnumerationToString(image.GetFormat())));
+            std::string(EnumerationToString(format)));
         }
 
-        width_ = image.GetWidth();
-        height_ = image.GetHeight();
+        width_ = width;
+        height_ = height;
 
         GLint interpolation = (isLinearInterpolation ? GL_LINEAR : GL_NEAREST);
 
         // Load the texture from the image buffer
-        glTexImage2D(GL_TEXTURE_2D, 0, internalFormat, image.GetWidth(), image.GetHeight(),
-                     0, sourceFormat, pixelType, image.GetConstBuffer());
+        glTexImage2D(GL_TEXTURE_2D, 0, internalFormat, width, height,
+                     0, sourceFormat, pixelType, data);
         glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, interpolation);
         glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, interpolation);
         glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_CLAMP_TO_EDGE);
@@ -148,6 +150,21 @@
       }
     }
 
+    void OpenGLTexture::Load(const Orthanc::ImageAccessor& image,
+                             bool isLinearInterpolation)
+    {
+      if (image.GetPitch() != image.GetBytesPerPixel() * image.GetWidth())
+      {
+        throw Orthanc::OrthancException(Orthanc::ErrorCode_NotImplemented,
+                                        "Pitch is not the same as the row size");
+      }
+      else
+      {
+        Setup(image.GetFormat(), image.GetWidth(), image.GetHeight(),
+              isLinearInterpolation, image.GetConstBuffer());
+      }
+    }
+
 
     void OpenGLTexture::Bind(GLint location)
     {
--- a/OrthancStone/Sources/OpenGL/OpenGLTexture.h	Sun Jan 22 10:48:22 2023 +0100
+++ b/OrthancStone/Sources/OpenGL/OpenGLTexture.h	Fri Jan 27 15:43:24 2023 +0100
@@ -43,11 +43,22 @@
       unsigned int  height_;
       OpenGL::IOpenGLContext& context_;
 
+      void Setup(Orthanc::PixelFormat format,
+                 unsigned int width,
+                 unsigned int height,
+                 bool isLinearInterpolation,
+                 const void* data);
+
     public:
       explicit OpenGLTexture(OpenGL::IOpenGLContext& context);
 
       ~OpenGLTexture();
 
+      GLuint GetId() const
+      {
+        return texture_;
+      }
+
       unsigned int GetWidth() const
       {
         return width_;
@@ -58,6 +69,14 @@
         return height_;
       }
 
+      void Setup(Orthanc::PixelFormat format,
+                 unsigned int width,
+                 unsigned int height,
+                 bool isLinearInterpolation)
+      {
+        Setup(format, width, height, isLinearInterpolation, NULL);
+      }
+
       void Load(const Orthanc::ImageAccessor& image,
                 bool isLinearInterpolation);