diff options
-rw-r--r-- | src/library_glut.js | 8 | ||||
-rw-r--r-- | tests/cube2hash/readme.txt | 27 | ||||
-rw-r--r-- | tests/glbook/CH09_TextureWrap.png | bin | 0 -> 1812 bytes | |||
-rw-r--r-- | tests/glbook/CH10_MultiTexture.png | bin | 0 -> 59495 bytes | |||
-rw-r--r-- | tests/glbook/Chapter_10/MultiTexture/MultiTexture.c | 44 | ||||
-rw-r--r-- | tests/glbook/Chapter_9/TextureWrap/TextureWrap.c | 54 | ||||
-rw-r--r-- | tests/glbook/Makefile | 4 | ||||
-rwxr-xr-x | tests/runner.py | 51 |
8 files changed, 146 insertions, 42 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/cube2hash/readme.txt b/tests/cube2hash/readme.txt new file mode 100644 index 00000000..6eb129c2 --- /dev/null +++ b/tests/cube2hash/readme.txt @@ -0,0 +1,27 @@ +This directory contains zlib code (c) the Cube 2/Sauerbraten project. +http://sauerbraten.org/ + +LICENSE +======= + +Sauerbraten game engine source code, any release. + +Copyright (C) 2001-2009 Wouter van Oortmerssen, Lee Salzman, Mike Dysart, Robert Pointon, and Quinton Reeves + +This software is provided 'as-is', without any express or implied +warranty. In no event will the authors be held liable for any damages +arising from the use of this software. + +Permission is granted to anyone to use this software for any purpose, +including commercial applications, and to alter it and redistribute it +freely, subject to the following restrictions: + +1. The origin of this software must not be misrepresented; you must not + claim that you wrote the original software. If you use this software + in a product, an acknowledgment in the product documentation would be + appreciated but is not required. +2. Altered source versions must be plainly marked as such, and must not be + misrepresented as being the original software. +3. This notice may not be removed or altered from any source distribution. + + 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/CH10_MultiTexture.png b/tests/glbook/CH10_MultiTexture.png Binary files differnew file mode 100644 index 00000000..8e006eb3 --- /dev/null +++ b/tests/glbook/CH10_MultiTexture.png diff --git a/tests/glbook/Chapter_10/MultiTexture/MultiTexture.c b/tests/glbook/Chapter_10/MultiTexture/MultiTexture.c index 5324ad92..61bda608 100644 --- a/tests/glbook/Chapter_10/MultiTexture/MultiTexture.c +++ b/tests/glbook/Chapter_10/MultiTexture/MultiTexture.c @@ -33,6 +33,8 @@ typedef struct GLuint baseMapTexId;
GLuint lightMapTexId;
+ GLuint vertexObject, indexObject;
+
} UserData;
@@ -117,7 +119,27 @@ int Init ( ESContext *esContext ) if ( userData->baseMapTexId == 0 || userData->lightMapTexId == 0 )
return FALSE;
- glClearColor ( 0.0f, 0.0f, 0.0f, 0.0f );
+ GLfloat vVertices[] = { -0.5, 0.5, 0.0, // Position 0
+ 0.0, 0.0, // TexCoord 0
+ -0.5, -0.5, 0.0, // Position 1
+ 0.0, 1.0, // TexCoord 1
+ 0.5, -0.5, 0.0, // Position 2
+ 1.0, 1.0, // TexCoord 2
+ 0.5, 0.5, 0.0, // Position 3
+ 1.0, 0.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, 5 * 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 TRUE;
}
@@ -127,17 +149,7 @@ int Init ( ESContext *esContext ) void Draw ( ESContext *esContext )
{
UserData *userData = esContext->userData;
- GLfloat vVertices[] = { -0.5f, 0.5f, 0.0f, // Position 0
- 0.0f, 0.0f, // TexCoord 0
- -0.5f, -0.5f, 0.0f, // Position 1
- 0.0f, 1.0f, // TexCoord 1
- 0.5f, -0.5f, 0.0f, // Position 2
- 1.0f, 1.0f, // TexCoord 2
- 0.5f, 0.5f, 0.0f, // Position 3
- 1.0f, 0.0f // TexCoord 3
- };
- GLushort indices[] = { 0, 1, 2, 0, 2, 3 };
-
+
// Set the viewport
glViewport ( 0, 0, esContext->width, esContext->height );
@@ -148,11 +160,12 @@ void Draw ( ESContext *esContext ) glUseProgram ( userData->programObject );
// Load the vertex position
+ glBindBuffer ( GL_ARRAY_BUFFER, userData->vertexObject );
glVertexAttribPointer ( userData->positionLoc, 3, GL_FLOAT,
- GL_FALSE, 5 * sizeof(GLfloat), vVertices );
+ GL_FALSE, 5 * sizeof(GLfloat), 0 );
// Load the texture coordinate
glVertexAttribPointer ( userData->texCoordLoc, 2, GL_FLOAT,
- GL_FALSE, 5 * sizeof(GLfloat), &vVertices[3] );
+ GL_FALSE, 5 * sizeof(GLfloat), 3 * sizeof(GLfloat) );
glEnableVertexAttribArray ( userData->positionLoc );
glEnableVertexAttribArray ( userData->texCoordLoc );
@@ -171,7 +184,8 @@ void Draw ( ESContext *esContext ) // Set the light map sampler to texture unit 1
glUniform1i ( userData->lightMapLoc, 1 );
- glDrawElements ( GL_TRIANGLES, 6, GL_UNSIGNED_SHORT, indices );
+ glBindBuffer ( GL_ELEMENT_ARRAY_BUFFER, userData->indexObject );
+ glDrawElements ( GL_TRIANGLES, 6, GL_UNSIGNED_SHORT, 0 );
eglSwapBuffers ( esContext->eglDisplay, esContext->eglSurface );
}
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..cd5f8aee 100644 --- a/tests/glbook/Makefile +++ b/tests/glbook/Makefile @@ -27,8 +27,8 @@ 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_10/MultiTexture/CH10_MultiTexture.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 \ # ./Chapter_13/ParticleSystem/CH13_ParticleSystem.bc diff --git a/tests/runner.py b/tests/runner.py index 4511f80a..f96f2f7c 100755 --- a/tests/runner.py +++ b/tests/runner.py @@ -6337,6 +6337,35 @@ f.close() Popen(['python', EMCC, os.path.join(self.get_dir(), 'main.cpp'), '-L' + os.path.join(self.get_dir(), 'libdir'), '-lfile'], stdout=PIPE, stderr=STDOUT).communicate() self.assertContained('hello from lib', run_js(os.path.join(self.get_dir(), 'a.out.js'))) + def test_local_link(self): + # Linking a local library directly, like /usr/lib/libsomething.so, cannot work of course since it + # doesn't contain bitcode. However, when we see that we should look for a bitcode file for that + # library in the -L paths and system/lib + open(os.path.join(self.get_dir(), 'main.cpp'), 'w').write(''' + extern void printey(); + int main() { + printey(); + return 0; + } + ''') + + try: + os.makedirs(os.path.join(self.get_dir(), 'subdir')); + except: + pass + open(os.path.join(self.get_dir(), 'subdir', 'libfile.so'), 'w').write('this is not llvm bitcode!') + + open(os.path.join(self.get_dir(), 'libfile.cpp'), 'w').write(''' + #include <stdio.h> + void printey() { + printf("hello from lib\\n"); + } + ''') + + Popen(['python', EMCC, os.path.join(self.get_dir(), 'libfile.cpp'), '-o', 'libfile.so']).communicate() + Popen(['python', EMCC, os.path.join(self.get_dir(), 'main.cpp'), os.path.join(self.get_dir(), 'subdir', 'libfile.so'), '-L.']).communicate() + self.assertContained('hello from lib', run_js(os.path.join(self.get_dir(), 'a.out.js'))) + def test_embed_file(self): open(os.path.join(self.get_dir(), 'somefile.txt'), 'w').write('''hello from a file with lots of data and stuff in it thank you very much''') open(os.path.join(self.get_dir(), 'main.cpp'), 'w').write(r''' @@ -6572,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; @@ -6610,8 +6639,10 @@ elif 'browser' in str(sys.argv): } img.src = '%s'; }; - Module.postRun = doReftest(); - setTimeout(doReftest, 0); // if run() throws an exception, this will kick in + Module.postRun = doReftest; + Module.preRun = function() { + setTimeout(doReftest, 0); // if run() throws an exception and postRun is not called, this will kick in + }; ''' % basename) def test_compression(self): @@ -6895,11 +6926,19 @@ 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'), + os.path.join('Chapter_10', 'MultiTexture', 'CH10_MultiTexture.bc'), ], configure=None) for program in programs: print program - self.reftest(path_from_root('tests', 'glbook', os.path.basename(program).replace('.bc', '.png'))) - Popen(['python', EMCC, program, '-o', 'program.html', '--pre-js', 'reftest.js']).communicate() + basename = os.path.basename(program) + args = [] + if basename == 'CH10_MultiTexture.bc': + shutil.copyfile(path_from_root('tests', 'glbook', 'Chapter_10', 'MultiTexture', 'basemap.tga'), os.path.join(self.get_dir(), 'basemap.tga')) + shutil.copyfile(path_from_root('tests', 'glbook', 'Chapter_10', 'MultiTexture', 'lightmap.tga'), os.path.join(self.get_dir(), 'lightmap.tga')) + args = ['--preload-file', 'basemap.tga', '--preload-file', 'lightmap.tga'] + self.reftest(path_from_root('tests', 'glbook', basename.replace('.bc', '.png'))) + Popen(['python', EMCC, program, '-o', 'program.html', '--pre-js', 'reftest.js'] + args).communicate() self.run_browser('program.html', '', '/report_result?0') elif 'benchmark' in str(sys.argv): |