Skip to content

Commit 1a650f1

Browse files
zapolnovjuj
authored andcommitted
Support GL_SHADER_SOURCE_LENGTH parameter for glGetShaderiv. (#5373)
* Support GL_SHADER_SOURCE_LENGTH parameter for glGetShaderiv. * Fix behavior of glGetShaderiv after review; Added test code.
1 parent adbd1f8 commit 1a650f1

File tree

4 files changed

+81
-0
lines changed

4 files changed

+81
-0
lines changed

AUTHORS

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -297,4 +297,5 @@ a license to everyone to use it as detailed in LICENSE.)
297297
* Matjaž Drolc <[email protected]>
298298
* James Swift <[email protected]> (copyright owned by PSPDFKit GmbH)
299299
* Ryan Lester <[email protected]> (copyright owned by Cyph, Inc.)
300+
* Nikolay Zapolnov <[email protected]>
300301
* Nazar Mokrynskyi <[email protected]>

src/library_gl.js

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3598,6 +3598,10 @@ var LibraryGL = {
35983598
var log = GLctx.getShaderInfoLog(GL.shaders[shader]);
35993599
if (log === null) log = '(unknown error)';
36003600
{{{ makeSetValue('p', '0', 'log.length + 1', 'i32') }}};
3601+
} else if (pname == 0x8B88) { // GL_SHADER_SOURCE_LENGTH
3602+
var source = GLctx.getShaderSource(GL.shaders[shader]);
3603+
var sourceLength = (source === null || source.length == 0) ? 0 : source.length + 1;
3604+
{{{ makeSetValue('p', '0', 'sourceLength', 'i32') }}};
36013605
} else {
36023606
{{{ makeSetValue('p', '0', 'GLctx.getShaderParameter(GL.shaders[shader], pname)', 'i32') }}};
36033607
}

tests/test_browser.py

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2278,6 +2278,12 @@ def test_webgl_context_params(self):
22782278
if WINDOWS: return self.skip('SKIPPED due to bug https://bugzilla.mozilla.org/show_bug.cgi?id=1310005 - WebGL implementation advertises implementation defined GL_IMPLEMENTATION_COLOR_READ_TYPE/FORMAT pair that it cannot read with')
22792279
self.btest(path_from_root('tests', 'webgl_color_buffer_readpixels.cpp'), args=['-lGL'], expected='0', timeout=20)
22802280

2281+
# Test for PR#5373 (https://github.com/kripken/emscripten/pull/5373)
2282+
def test_webgl_shader_source_length(self):
2283+
for opts in [[], ['-s', 'FULL_ES2=1']]:
2284+
print opts
2285+
self.btest(path_from_root('tests', 'webgl_shader_source_length.cpp'), args=opts + ['-lGL'], expected='0', timeout=20)
2286+
22812287
def test_webgl2(self):
22822288
for opts in [[], ['-O2', '-g1', '--closure', '1'], ['-s', 'FULL_ES2=1']]:
22832289
print opts

tests/webgl_shader_source_length.cpp

Lines changed: 70 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,70 @@
1+
#define GL_GLEXT_PROTOTYPES
2+
#include <GLES/gl.h>
3+
#include <GLES/glext.h>
4+
#include <GLES2/gl2.h>
5+
#include <stdio.h>
6+
#include <emscripten.h>
7+
#include <emscripten/html5.h>
8+
#include <assert.h>
9+
#include <string.h>
10+
11+
int result = 0;
12+
13+
#define GL_CALL( x ) \
14+
{ \
15+
x; \
16+
GLenum error = glGetError(); \
17+
if( error != GL_NO_ERROR ) { \
18+
printf( "GL ERROR: %d, %s\n", (int)error, #x ); \
19+
result = 1; \
20+
} \
21+
} \
22+
23+
24+
int main()
25+
{
26+
emscripten_set_canvas_size( 100, 100 );
27+
28+
EmscriptenWebGLContextAttributes attrs;
29+
emscripten_webgl_init_context_attributes(&attrs);
30+
31+
EMSCRIPTEN_WEBGL_CONTEXT_HANDLE context = emscripten_webgl_create_context( 0, &attrs );
32+
if (!context)
33+
{
34+
printf("Skipped: WebGL is not supported.\n");
35+
#ifdef REPORT_RESULT
36+
REPORT_RESULT();
37+
#endif
38+
return 0;
39+
}
40+
emscripten_webgl_make_context_current(context);
41+
42+
GLuint shader;
43+
GL_CALL( shader = glCreateShader(GL_VERTEX_SHADER) );
44+
45+
GLint value = -97631;
46+
GL_CALL( glGetShaderiv(shader, GL_SHADER_SOURCE_LENGTH, &value) );
47+
assert(value == 0);
48+
49+
const GLchar* tempSource = (const GLchar*)"";
50+
GL_CALL( glShaderSource(shader, 1, &tempSource, NULL) );
51+
52+
value = -97631;
53+
GL_CALL( glGetShaderiv(shader, GL_SHADER_SOURCE_LENGTH, &value) );
54+
assert(value == 0);
55+
56+
tempSource = (const GLchar*)"void main() { gl_Position = vec4(0); }";
57+
GL_CALL( glShaderSource(shader, 1, &tempSource, NULL) );
58+
59+
value = -97631;
60+
GL_CALL( glGetShaderiv(shader, GL_SHADER_SOURCE_LENGTH, &value) );
61+
assert(value == strlen(tempSource) + 1);
62+
63+
EMSCRIPTEN_RESULT res = emscripten_webgl_destroy_context(context);
64+
assert(res == EMSCRIPTEN_RESULT_SUCCESS);
65+
66+
#ifdef REPORT_RESULT
67+
REPORT_RESULT();
68+
#endif
69+
return 0;
70+
}

0 commit comments

Comments
 (0)