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.
This commit is contained in:
Родитель
adbd1f8c11
Коммит
1a650f122d
1
AUTHORS
1
AUTHORS
|
@ -297,4 +297,5 @@ a license to everyone to use it as detailed in LICENSE.)
|
|||
* Matjaž Drolc <mdrolc@gmail.com>
|
||||
* James Swift <james@3dengineer.com> (copyright owned by PSPDFKit GmbH)
|
||||
* Ryan Lester <ryan@cyph.com> (copyright owned by Cyph, Inc.)
|
||||
* Nikolay Zapolnov <zapolnov@gmail.com>
|
||||
* Nazar Mokrynskyi <nazar@mokrynskyi.com>
|
||||
|
|
|
@ -3598,6 +3598,10 @@ var LibraryGL = {
|
|||
var log = GLctx.getShaderInfoLog(GL.shaders[shader]);
|
||||
if (log === null) log = '(unknown error)';
|
||||
{{{ makeSetValue('p', '0', 'log.length + 1', 'i32') }}};
|
||||
} else if (pname == 0x8B88) { // GL_SHADER_SOURCE_LENGTH
|
||||
var source = GLctx.getShaderSource(GL.shaders[shader]);
|
||||
var sourceLength = (source === null || source.length == 0) ? 0 : source.length + 1;
|
||||
{{{ makeSetValue('p', '0', 'sourceLength', 'i32') }}};
|
||||
} else {
|
||||
{{{ makeSetValue('p', '0', 'GLctx.getShaderParameter(GL.shaders[shader], pname)', 'i32') }}};
|
||||
}
|
||||
|
|
|
@ -2278,6 +2278,12 @@ Module["preRun"].push(function () {
|
|||
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')
|
||||
self.btest(path_from_root('tests', 'webgl_color_buffer_readpixels.cpp'), args=['-lGL'], expected='0', timeout=20)
|
||||
|
||||
# Test for PR#5373 (https://github.com/kripken/emscripten/pull/5373)
|
||||
def test_webgl_shader_source_length(self):
|
||||
for opts in [[], ['-s', 'FULL_ES2=1']]:
|
||||
print opts
|
||||
self.btest(path_from_root('tests', 'webgl_shader_source_length.cpp'), args=opts + ['-lGL'], expected='0', timeout=20)
|
||||
|
||||
def test_webgl2(self):
|
||||
for opts in [[], ['-O2', '-g1', '--closure', '1'], ['-s', 'FULL_ES2=1']]:
|
||||
print opts
|
||||
|
|
|
@ -0,0 +1,70 @@
|
|||
#define GL_GLEXT_PROTOTYPES
|
||||
#include <GLES/gl.h>
|
||||
#include <GLES/glext.h>
|
||||
#include <GLES2/gl2.h>
|
||||
#include <stdio.h>
|
||||
#include <emscripten.h>
|
||||
#include <emscripten/html5.h>
|
||||
#include <assert.h>
|
||||
#include <string.h>
|
||||
|
||||
int result = 0;
|
||||
|
||||
#define GL_CALL( x ) \
|
||||
{ \
|
||||
x; \
|
||||
GLenum error = glGetError(); \
|
||||
if( error != GL_NO_ERROR ) { \
|
||||
printf( "GL ERROR: %d, %s\n", (int)error, #x ); \
|
||||
result = 1; \
|
||||
} \
|
||||
} \
|
||||
|
||||
|
||||
int main()
|
||||
{
|
||||
emscripten_set_canvas_size( 100, 100 );
|
||||
|
||||
EmscriptenWebGLContextAttributes attrs;
|
||||
emscripten_webgl_init_context_attributes(&attrs);
|
||||
|
||||
EMSCRIPTEN_WEBGL_CONTEXT_HANDLE context = emscripten_webgl_create_context( 0, &attrs );
|
||||
if (!context)
|
||||
{
|
||||
printf("Skipped: WebGL is not supported.\n");
|
||||
#ifdef REPORT_RESULT
|
||||
REPORT_RESULT();
|
||||
#endif
|
||||
return 0;
|
||||
}
|
||||
emscripten_webgl_make_context_current(context);
|
||||
|
||||
GLuint shader;
|
||||
GL_CALL( shader = glCreateShader(GL_VERTEX_SHADER) );
|
||||
|
||||
GLint value = -97631;
|
||||
GL_CALL( glGetShaderiv(shader, GL_SHADER_SOURCE_LENGTH, &value) );
|
||||
assert(value == 0);
|
||||
|
||||
const GLchar* tempSource = (const GLchar*)"";
|
||||
GL_CALL( glShaderSource(shader, 1, &tempSource, NULL) );
|
||||
|
||||
value = -97631;
|
||||
GL_CALL( glGetShaderiv(shader, GL_SHADER_SOURCE_LENGTH, &value) );
|
||||
assert(value == 0);
|
||||
|
||||
tempSource = (const GLchar*)"void main() { gl_Position = vec4(0); }";
|
||||
GL_CALL( glShaderSource(shader, 1, &tempSource, NULL) );
|
||||
|
||||
value = -97631;
|
||||
GL_CALL( glGetShaderiv(shader, GL_SHADER_SOURCE_LENGTH, &value) );
|
||||
assert(value == strlen(tempSource) + 1);
|
||||
|
||||
EMSCRIPTEN_RESULT res = emscripten_webgl_destroy_context(context);
|
||||
assert(res == EMSCRIPTEN_RESULT_SUCCESS);
|
||||
|
||||
#ifdef REPORT_RESULT
|
||||
REPORT_RESULT();
|
||||
#endif
|
||||
return 0;
|
||||
}
|
Загрузка…
Ссылка в новой задаче