diff options
author | Alon Zakai <alonzakai@gmail.com> | 2012-04-04 17:11:39 -0700 |
---|---|---|
committer | Alon Zakai <alonzakai@gmail.com> | 2012-04-04 17:11:39 -0700 |
commit | 12e45ea3243b1e734e01785109ec73e76f23965c (patch) | |
tree | 80dd2a9d48f1468b75d3a524c3525becf38d2d2b | |
parent | f4be2e8e34cf9394ecd5e7166a584b4224f77d6d (diff) |
add yet another working glbook testcase
-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/Makefile | 2 | ||||
-rwxr-xr-x | tests/runner.py | 17 |
4 files changed, 43 insertions, 20 deletions
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/Makefile b/tests/glbook/Makefile index 77e83c2d..cd5f8aee 100644 --- a/tests/glbook/Makefile +++ b/tests/glbook/Makefile @@ -28,7 +28,7 @@ all: ./Chapter_2/Hello_Triangle/CH02_HelloTriangle.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_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 16ef9b88..532b6b0d 100755 --- a/tests/runner.py +++ b/tests/runner.py @@ -6639,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): @@ -6916,11 +6918,18 @@ elif 'browser' in str(sys.argv): 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): |