changeset 2045:e5c812a36746 deep-learning

added support of WebGL2 in WebAssemblyOpenGLContext
author Sebastien Jodogne <s.jodogne@gmail.com>
date Sun, 05 Mar 2023 17:06:31 +0100
parents c9dadbe7c7b0
children 98b44468332e
files OrthancStone/Sources/OpenGL/OpenGLTexture.cpp OrthancStone/Sources/Platforms/WebAssembly/WebAssemblyOpenGLContext.cpp OrthancStone/Sources/Platforms/WebAssembly/WebAssemblyOpenGLContext.h
diffstat 3 files changed, 35 insertions(+), 2 deletions(-) [+]
line wrap: on
line diff
--- a/OrthancStone/Sources/OpenGL/OpenGLTexture.cpp	Sun Mar 05 15:05:58 2023 +0100
+++ b/OrthancStone/Sources/OpenGL/OpenGLTexture.cpp	Sun Mar 05 17:06:31 2023 +0100
@@ -42,6 +42,8 @@
       {
         // Generate a texture object
         glGenTextures(1, &texture_);
+        ORTHANC_OPENGL_CHECK("glGenTextures()");
+
         if (texture_ == 0)
         {
           throw Orthanc::OrthancException(Orthanc::ErrorCode_InternalError,
--- a/OrthancStone/Sources/Platforms/WebAssembly/WebAssemblyOpenGLContext.cpp	Sun Mar 05 15:05:58 2023 +0100
+++ b/OrthancStone/Sources/Platforms/WebAssembly/WebAssemblyOpenGLContext.cpp	Sun Mar 05 17:06:31 2023 +0100
@@ -45,7 +45,8 @@
       bool                            isContextLost_;
 
     public:
-      explicit PImpl(const std::string& canvasSelector) :
+      explicit PImpl(const std::string& canvasSelector,
+                     Version version) :
         canvasSelector_(canvasSelector),
         isContextLost_(false)
       {
@@ -53,6 +54,20 @@
         EmscriptenWebGLContextAttributes attr; 
         emscripten_webgl_init_context_attributes(&attr);
 
+        switch (version)
+        {
+          case Version_WebGL1:
+            break;
+
+          case Version_WebGL2:
+            attr.majorVersion = 2;
+            attr.minorVersion = 0;
+            break;
+
+          default:
+            throw Orthanc::OrthancException(Orthanc::ErrorCode_ParameterOutOfRange);
+        }
+        
         // The next line might be necessary to print using
         // WebGL. Sometimes, if set to "false" (the default value),
         // the canvas was rendered as a fully white or black
@@ -162,7 +177,13 @@
 
 
     WebAssemblyOpenGLContext::WebAssemblyOpenGLContext(const std::string& canvasSelector) :
-      pimpl_(new PImpl(canvasSelector))
+      pimpl_(new PImpl(canvasSelector, Version_WebGL1))
+    {
+    }
+
+    WebAssemblyOpenGLContext::WebAssemblyOpenGLContext(const std::string& canvasSelector,
+                                                       Version version) :
+      pimpl_(new PImpl(canvasSelector, version))
     {
     }
 
--- a/OrthancStone/Sources/Platforms/WebAssembly/WebAssemblyOpenGLContext.h	Sun Mar 05 15:05:58 2023 +0100
+++ b/OrthancStone/Sources/Platforms/WebAssembly/WebAssemblyOpenGLContext.h	Sun Mar 05 17:06:31 2023 +0100
@@ -51,6 +51,13 @@
   {
     class WebAssemblyOpenGLContext : public OpenGL::IOpenGLContext
     {
+    public:
+      enum Version
+      {
+        Version_WebGL1,
+        Version_WebGL2
+      };
+      
     private:
       class PImpl;
       boost::shared_ptr<PImpl>  pimpl_;
@@ -58,6 +65,9 @@
     public:
       explicit WebAssemblyOpenGLContext(const std::string& canvasSelector);
 
+      explicit WebAssemblyOpenGLContext(const std::string& canvasSelector,
+                                        Version version);
+
       virtual bool IsContextLost() ORTHANC_OVERRIDE;
 
       virtual void MakeCurrent() ORTHANC_OVERRIDE;