# HG changeset patch # User Sebastien Jodogne # Date 1678032391 -3600 # Node ID e5c812a367467881559ef8d1301ae769a97beb20 # Parent c9dadbe7c7b09f0b0b832118fbaf82729324d754 added support of WebGL2 in WebAssemblyOpenGLContext diff -r c9dadbe7c7b0 -r e5c812a36746 OrthancStone/Sources/OpenGL/OpenGLTexture.cpp --- 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, diff -r c9dadbe7c7b0 -r e5c812a36746 OrthancStone/Sources/Platforms/WebAssembly/WebAssemblyOpenGLContext.cpp --- 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)) { } diff -r c9dadbe7c7b0 -r e5c812a36746 OrthancStone/Sources/Platforms/WebAssembly/WebAssemblyOpenGLContext.h --- 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_; @@ -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;