comparison OrthancStone/Sources/OpenGL/OpenGLTexture.cpp @ 2048:a05b03f45289 deep-learning

added ORTHANC_WEBGL2_HEAP_COMPAT
author Sebastien Jodogne <s.jodogne@gmail.com>
date Wed, 08 Mar 2023 17:46:04 +0100
parents 0b596428e60c
children 66c130af0d3c
comparison
equal deleted inserted replaced
2047:0b596428e60c 2048:a05b03f45289
26 26
27 #include <Images/Image.h> 27 #include <Images/Image.h>
28 #include <Logging.h> 28 #include <Logging.h>
29 #include <OrthancException.h> 29 #include <OrthancException.h>
30 30
31 #if defined(__EMSCRIPTEN__)
32 # if !defined(ORTHANC_WEBGL2_HEAP_COMPAT)
33 # error The macro ORTHANC_WEBGL2_HEAP_COMPAT must be defined
34 # endif
35 #endif
36
31 namespace OrthancStone 37 namespace OrthancStone
32 { 38 {
33 namespace OpenGL 39 namespace OpenGL
34 { 40 {
35 OpenGLTexture::OpenGLTexture(OpenGL::IOpenGLContext& context) : 41 OpenGLTexture::OpenGLTexture(OpenGL::IOpenGLContext& context) :
112 height_ = height; 118 height_ = height;
113 119
114 GLint interpolation = (isLinearInterpolation ? GL_LINEAR : GL_NEAREST); 120 GLint interpolation = (isLinearInterpolation ? GL_LINEAR : GL_NEAREST);
115 121
116 // Load the texture from the image buffer 122 // Load the texture from the image buffer
123
124 #if defined(__EMSCRIPTEN__) && (ORTHANC_WEBGL2_HEAP_COMPAT == 1)
125 /**
126 * This compatibility implementation seems to be necessary
127 * with WebGL2, at least in Web workers. In such a situation,
128 * the calls that are referred to as the "new garbage-free
129 * entry points" in the Emscripten source file
130 * "upstream/emscripten/src/library_webgl.js" seem to fail,
131 * because the "Uint8Array" and "Float32Array" seem to be
132 * incorrectly created. This compatibility reverts to the
133 * WebGL1 behavior of "library_webgl.js", which requires the
134 * function "emscriptenWebGLGetTexPixelData" that is defined
135 * in "upstream/emscripten/src/library_webgl.js" to be
136 * exported in the linker using option
137 * "EXTRA_EXPORTED_RUNTIME_METHODS" or
138 * "EXPORTED_RUNTIME_METHODS".
139 **/
140 EM_ASM({
141 var ptr = $0 ? emscriptenWebGLGetTexPixelData($5, $4, $2, $3, $0, $1) : null;
142 GLctx.texImage2D(GLctx.TEXTURE_2D, 0, $1, $2, $3, 0, $4, $5, ptr);
143 },
144 data, // $0
145 internalFormat, // $1
146 width, // $2
147 height, // $3
148 sourceFormat, // $4
149 pixelType); // $5
150 #else
117 glTexImage2D(GL_TEXTURE_2D, 0, internalFormat, width, height, 151 glTexImage2D(GL_TEXTURE_2D, 0, internalFormat, width, height,
118 0, sourceFormat, pixelType, data); 152 0, sourceFormat, pixelType, data);
153 #endif
154
119 ORTHANC_OPENGL_CHECK("glTexImage2D()"); 155 ORTHANC_OPENGL_CHECK("glTexImage2D()");
120 156
121 #if !defined(__EMSCRIPTEN__) 157 #if !defined(__EMSCRIPTEN__)
122 /** 158 /**
123 * glGetTexLevelParameteriv() was introduced in OpenGL ES 3.1, 159 * glGetTexLevelParameteriv() was introduced in OpenGL ES 3.1,