aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorToadKing <toadking@toadking.com>2013-07-22 19:15:43 -0400
committerToadKing <toadking@toadking.com>2013-07-22 19:15:43 -0400
commit63dec7db76330cae0208186eae3c8432b649d85f (patch)
tree62c0adc4227fa359922f87723103f19b13846296
parentde54e944d9561dc1e55e6e668990e5076b940178 (diff)
change error message to assert
add testcase for glGetAttachedShaders
-rw-r--r--src/library_gl.js7
-rw-r--r--tests/glgetattachedshaders.c92
2 files changed, 94 insertions, 5 deletions
diff --git a/src/library_gl.js b/src/library_gl.js
index a5cb8dae..ee3f8581 100644
--- a/src/library_gl.js
+++ b/src/library_gl.js
@@ -1077,11 +1077,8 @@ var LibraryGL = {
{{{ makeSetValue('count', '0', 'len', 'i32') }}};
for (var i = 0; i < len; ++i) {
var id = GL.shaders.indexOf(result[i]);
- if (id === -1) {
- Module.printErr("glGetAttachedShaders: local shader id not found");
- } else {
- {{{ makeSetValue('shaders', 'i*4', 'id', 'i32') }}};
- }
+ assert(id !== -1, 'shader not bound to local id');
+ {{{ makeSetValue('shaders', 'i*4', 'id', 'i32') }}};
}
},
diff --git a/tests/glgetattachedshaders.c b/tests/glgetattachedshaders.c
new file mode 100644
index 00000000..b4cf3989
--- /dev/null
+++ b/tests/glgetattachedshaders.c
@@ -0,0 +1,92 @@
+#include <GLES2/gl2.h>
+#include <EGL/egl.h>
+#include <stdio.h>
+#include <stdlib.h>
+
+static void die(const char *msg)
+{
+ printf("%s\n", msg);
+ abort();
+}
+
+static void create_context(void)
+{
+ EGLint num_config;
+ EGLContext g_egl_ctx;
+ EGLDisplay g_egl_dpy;
+ EGLConfig g_config;
+
+ static const EGLint attribute_list[] =
+ {
+ EGL_RED_SIZE, 8,
+ EGL_GREEN_SIZE, 8,
+ EGL_BLUE_SIZE, 8,
+ EGL_ALPHA_SIZE, 8,
+ EGL_SURFACE_TYPE, EGL_WINDOW_BIT,
+ EGL_NONE
+ };
+
+ static const EGLint context_attributes[] =
+ {
+ EGL_CONTEXT_CLIENT_VERSION, 2,
+ EGL_NONE
+ };
+
+ g_egl_dpy = eglGetDisplay(EGL_DEFAULT_DISPLAY);
+ if (!g_egl_dpy)
+ die("failed to create display");
+
+ if (!eglInitialize(g_egl_dpy, NULL, NULL))
+ die("failed to initialize egl");
+
+ if (!eglChooseConfig(g_egl_dpy, attribute_list, &g_config, 1, &num_config))
+ die("failed to choose config");
+
+ g_egl_ctx = eglCreateContext(g_egl_dpy, g_config, EGL_NO_CONTEXT, context_attributes);
+ if (!g_egl_ctx)
+ die("failed to create context");
+}
+
+int main(int argc, char *argv[])
+{
+ unsigned i;
+
+ create_context();
+
+ GLuint prog = glCreateProgram();
+ if (glGetError())
+ die("failed to create program");
+
+ GLuint vertex = glCreateShader(GL_VERTEX_SHADER);
+ if (glGetError())
+ die("failed to create vertex shader");
+ glAttachShader(prog, vertex);
+
+ GLuint fragment = glCreateShader(GL_FRAGMENT_SHADER);
+ if (glGetError())
+ die("failed to create fragment shader");
+ glAttachShader(prog, fragment);
+
+ GLuint shaders[2];
+ GLsizei count;
+
+ glGetAttachedShaders(prog, 2, &count, shaders);
+ if (glGetError())
+ die("failed to get attached shaders");
+ if (count != 2)
+ die("unknown number of shaders returned");
+ if (shaders[0] == shaders[1])
+ die("returned identical shaders");
+
+ for (i = 0; i < count; i++)
+ {
+ if (shaders[i] == 0)
+ die("returned 0");
+ if (shaders[i] != vertex && shaders[i] != fragment)
+ die("unknown shader returned");
+ }
+
+ printf("test passed\n");
+
+ return 0;
+}