changeset 2042:0fa4c0ca429d deep-learning

added OpenGLTexture::BindAsTextureUnit()
author Sebastien Jodogne <s.jodogne@gmail.com>
date Fri, 03 Feb 2023 21:49:09 +0100
parents 85a20cbfcc04
children f3d756e5503f
files OrthancStone/Sources/OpenGL/OpenGLTexture.cpp OrthancStone/Sources/OpenGL/OpenGLTexture.h
diffstat 2 files changed, 20 insertions(+), 0 deletions(-) [+]
line wrap: on
line diff
--- a/OrthancStone/Sources/OpenGL/OpenGLTexture.cpp	Wed Feb 01 08:23:26 2023 +0100
+++ b/OrthancStone/Sources/OpenGL/OpenGLTexture.cpp	Fri Feb 03 21:49:09 2023 +0100
@@ -156,6 +156,23 @@
     }
 
 
+    void OpenGLTexture::BindAsTextureUnit(GLint location,
+                                          unsigned int unit) const
+    {
+      if (unit >= 32)
+      {
+        throw Orthanc::OrthancException(Orthanc::ErrorCode_ParameterOutOfRange);
+      }
+      
+      assert(GL_TEXTURE0 + 1 == GL_TEXTURE1 &&
+             GL_TEXTURE0 + 31 == GL_TEXTURE31);
+      
+      glActiveTexture(GL_TEXTURE0 + unit);
+      glBindTexture(GL_TEXTURE_2D, texture_);
+      glUniform1i(location, unit /* texture unit */);
+    }
+
+
     Orthanc::ImageAccessor* OpenGLTexture::Download(Orthanc::PixelFormat format) const
     {
       if (context_.IsContextLost())
--- a/OrthancStone/Sources/OpenGL/OpenGLTexture.h	Wed Feb 01 08:23:26 2023 +0100
+++ b/OrthancStone/Sources/OpenGL/OpenGLTexture.h	Fri Feb 03 21:49:09 2023 +0100
@@ -86,6 +86,9 @@
 
       void Bind(GLint location) const;
 
+      void BindAsTextureUnit(GLint location,
+                             unsigned int unit) const;
+
       Orthanc::ImageAccessor* Download(Orthanc::PixelFormat format) const;
 
       /**