diff OrthancStone/Sources/Platforms/WebAssembly/WebAssemblyOpenGLContext.cpp @ 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 184b0aeae1af
children fdb012c86a75
line wrap: on
line diff
--- 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))
     {
     }