diff options
author | Alon Zakai <alonzakai@gmail.com> | 2012-04-04 15:04:18 -0700 |
---|---|---|
committer | Alon Zakai <alonzakai@gmail.com> | 2012-04-04 15:04:18 -0700 |
commit | f4be2e8e34cf9394ecd5e7166a584b4224f77d6d (patch) | |
tree | 1dce727d683129c1f12346d0168072e5a0c52f0d | |
parent | b52ad77314eada644113d6c0c0df8c05a1bcc424 (diff) |
add another glbook passing testcase
-rw-r--r-- | src/library_glut.js | 8 | ||||
-rw-r--r-- | tests/glbook/CH09_TextureWrap.png | bin | 0 -> 1812 bytes | |||
-rw-r--r-- | tests/glbook/Chapter_9/TextureWrap/TextureWrap.c | 54 | ||||
-rw-r--r-- | tests/glbook/Makefile | 2 | ||||
-rwxr-xr-x | tests/runner.py | 5 |
5 files changed, 47 insertions, 22 deletions
diff --git a/src/library_glut.js b/src/library_glut.js index 84d800a9..76ff80aa 100644 --- a/src/library_glut.js +++ b/src/library_glut.js @@ -253,6 +253,7 @@ var LibraryGLUT = { var ctx = Module.canvas.getContext('experimental-webgl'); if (!ctx) throw 'Could not create canvas :('; #if GL_DEBUG + // Useful to debug native webgl apps: var Module = { printErr: function(x) { console.log(x) } }; var wrapper = {}; wrapper.objectMap = new WeakMap(); wrapper.objectCounter = 1; @@ -263,7 +264,12 @@ var LibraryGLUT = { wrapper[prop] = function() { var printArgs = Array.prototype.slice.call(arguments).map(function(arg) { if (wrapper.objectMap[arg]) return '<' + arg + '|' + wrapper.objectMap[arg] + '>'; - if (arg.subarray) return '{' + arg + '|' + arg.length /*+ '|' + Array.prototype.slice.call(arg).toString().replace(/,/g, ', ')*/ + '}'; + if (arg.byteLength) { + var ret = '{' + arg.byteLength + ':'; + var arr = Array.prototype.slice.call(new Uint8Array(arg.buffer), 0, 40); + ret += arr.toString().replace(/,/g, ', ') + '}'; + return ret; + } return arg; }); Module.printErr('[gl_f:' + prop + ':' + printArgs + ']'); diff --git a/tests/glbook/CH09_TextureWrap.png b/tests/glbook/CH09_TextureWrap.png Binary files differnew file mode 100644 index 00000000..3367e254 --- /dev/null +++ b/tests/glbook/CH09_TextureWrap.png diff --git a/tests/glbook/Chapter_9/TextureWrap/TextureWrap.c b/tests/glbook/Chapter_9/TextureWrap/TextureWrap.c index fe22282f..30f39444 100644 --- a/tests/glbook/Chapter_9/TextureWrap/TextureWrap.c +++ b/tests/glbook/Chapter_9/TextureWrap/TextureWrap.c @@ -34,6 +34,8 @@ typedef struct // Texture handle GLuint textureId; + GLuint vertexObject, indexObject; + } UserData; /// @@ -88,6 +90,9 @@ GLuint CreateTexture2D( ) if ( pixels == NULL ) return 0; + // Use tightly packed data + glPixelStorei ( GL_UNPACK_ALIGNMENT, 1 ); + // Generate a texture object glGenTextures ( 1, &textureId ); @@ -152,7 +157,28 @@ int Init ( ESContext *esContext ) // Load the texture userData->textureId = CreateTexture2D (); - glClearColor ( 0.0f, 0.0f, 0.0f, 0.0f ); + // Setup the vertex data + GLfloat vVertices[] = { -0.3, 0.3, 0.0, 1.0, // Position 0 + -1.0, -1.0, // TexCoord 0 + -0.3, -0.3, 0.0, 1.0, // Position 1 + -1.0, 2.0, // TexCoord 1 + 0.3, -0.3, 0.0, 1.0, // Position 2 + 2.0, 2.0, // TexCoord 2 + 0.3, 0.3, 0.0, 1.0, // Position 3 + 2.0, -1.0 // TexCoord 3 + }; + GLushort indices[] = { 0, 1, 2, 0, 2, 3 }; + + glGenBuffers(1, &userData->vertexObject); + glBindBuffer ( GL_ARRAY_BUFFER, userData->vertexObject ); + glBufferData ( GL_ARRAY_BUFFER, 6 * 4 * 4, vVertices, GL_STATIC_DRAW ); + + glGenBuffers(1, &userData->indexObject); + glBindBuffer ( GL_ELEMENT_ARRAY_BUFFER, userData->indexObject ); + glBufferData ( GL_ELEMENT_ARRAY_BUFFER, 6 * 2, indices, GL_STATIC_DRAW ); + + glClearColor ( 0.0, 0.0, 0.0, 1.0 ); + return GL_TRUE; } @@ -162,17 +188,7 @@ int Init ( ESContext *esContext ) void Draw ( ESContext *esContext ) { UserData *userData = esContext->userData; - GLfloat vVertices[] = { -0.3f, 0.3f, 0.0f, 1.0f, // Position 0 - -1.0f, -1.0f, // TexCoord 0 - -0.3f, -0.3f, 0.0f, 1.0f, // Position 1 - -1.0f, 2.0f, // TexCoord 1 - 0.3f, -0.3f, 0.0f, 1.0f, // Position 2 - 2.0f, 2.0f, // TexCoord 2 - 0.3f, 0.3f, 0.0f, 1.0f, // Position 3 - 2.0f, -1.0f // TexCoord 3 - }; - GLushort indices[] = { 0, 1, 2, 0, 2, 3 }; - + // Set the viewport glViewport ( 0, 0, esContext->width, esContext->height ); @@ -183,11 +199,12 @@ void Draw ( ESContext *esContext ) glUseProgram ( userData->programObject ); // Load the vertex position + glBindBuffer ( GL_ARRAY_BUFFER, userData->vertexObject ); glVertexAttribPointer ( userData->positionLoc, 4, GL_FLOAT, - GL_FALSE, 6 * sizeof(GLfloat), vVertices ); + GL_FALSE, 6 * sizeof(GLfloat), 0 ); // Load the texture coordinate glVertexAttribPointer ( userData->texCoordLoc, 2, GL_FLOAT, - GL_FALSE, 6 * sizeof(GLfloat), &vVertices[4] ); + GL_FALSE, 6 * sizeof(GLfloat), 4 * sizeof(GLfloat) ); glEnableVertexAttribArray ( userData->positionLoc ); glEnableVertexAttribArray ( userData->texCoordLoc ); @@ -203,19 +220,20 @@ void Draw ( ESContext *esContext ) glTexParameteri ( GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_REPEAT ); glTexParameteri ( GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_REPEAT ); glUniform1f ( userData->offsetLoc, -0.7f ); - glDrawElements ( GL_TRIANGLES, 6, GL_UNSIGNED_SHORT, indices ); + glBindBuffer ( GL_ELEMENT_ARRAY_BUFFER, userData->indexObject ); + glDrawElements ( GL_TRIANGLES, 6, GL_UNSIGNED_SHORT, 0 ); // Draw quad with clamp to edge wrap mode glTexParameteri ( GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_CLAMP_TO_EDGE ); glTexParameteri ( GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_CLAMP_TO_EDGE ); glUniform1f ( userData->offsetLoc, 0.0f ); - glDrawElements ( GL_TRIANGLES, 6, GL_UNSIGNED_SHORT, indices ); + glDrawElements ( GL_TRIANGLES, 6, GL_UNSIGNED_SHORT, 0 ); // Draw quad with mirrored repeat glTexParameteri ( GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_MIRRORED_REPEAT ); glTexParameteri ( GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_MIRRORED_REPEAT ); glUniform1f ( userData->offsetLoc, 0.7f ); - glDrawElements ( GL_TRIANGLES, 6, GL_UNSIGNED_SHORT, indices ); + glDrawElements ( GL_TRIANGLES, 6, GL_UNSIGNED_SHORT, 0 ); } @@ -243,7 +261,7 @@ int main ( int argc, char *argv[] ) esInitContext ( &esContext ); esContext.userData = &userData; - esCreateWindow ( &esContext, "MipMap 2D", 640, 480, ES_WINDOW_RGB ); + esCreateWindow ( &esContext, "MipMap 2D", 320, 240, ES_WINDOW_RGB ); if ( !Init ( &esContext ) ) return 0; diff --git a/tests/glbook/Makefile b/tests/glbook/Makefile index df8b1615..77e83c2d 100644 --- a/tests/glbook/Makefile +++ b/tests/glbook/Makefile @@ -27,7 +27,7 @@ all: ./Chapter_2/Hello_Triangle/CH02_HelloTriangle.bc \ ./Chapter_9/Simple_Texture2D/CH09_SimpleTexture2D.bc \ ./Chapter_9/MipMap2D/CH09_MipMap2D.bc \ ./Chapter_9/Simple_TextureCubemap/CH09_TextureCubemap.bc \ -# ./Chapter_9/TextureWrap/CH09_TextureWrap.bc \ + ./Chapter_9/TextureWrap/CH09_TextureWrap.bc \ # ./Chapter_10/MultiTexture/CH10_MultiTexture.bc \ # ./Chapter_11/Multisample/CH11_Multisample.bc \ # ./Chapter_11/Stencil_Test/CH11_Stencil_Test.bc \ diff --git a/tests/runner.py b/tests/runner.py index 0165dd3d..16ef9b88 100755 --- a/tests/runner.py +++ b/tests/runner.py @@ -6601,8 +6601,8 @@ elif 'browser' in str(sys.argv): doReftest.done = true; var img = new Image(); img.onload = function() { - assert(img.width == Module.canvas.width); - assert(img.height == Module.canvas.height); + assert(img.width == Module.canvas.width, 'Invalid width: ' + Module.canvas.width + ', should be ' + img.width); + assert(img.height == Module.canvas.height, 'Invalid height: ' + Module.canvas.height + ', should be ' + img.height); var canvas = document.createElement('canvas'); canvas.width = img.width; @@ -6915,6 +6915,7 @@ elif 'browser' in str(sys.argv): os.path.join('Chapter_8', 'Simple_VertexShader', 'CH08_SimpleVertexShader.bc'), os.path.join('Chapter_9', 'Simple_Texture2D', 'CH09_SimpleTexture2D.bc'), os.path.join('Chapter_9', 'Simple_TextureCubemap', 'CH09_TextureCubemap.bc'), + os.path.join('Chapter_9', 'TextureWrap', 'CH09_TextureWrap.bc'), ], configure=None) for program in programs: print program |