diff options
Diffstat (limited to 'tests')
-rw-r--r-- | tests/glbook/CH08_SimpleVertexShader.png | bin | 0 -> 1600 bytes | |||
-rw-r--r-- | tests/glbook/Chapter_8/Simple_VertexShader/Simple_VertexShader.c | 21 | ||||
-rw-r--r-- | tests/glbook/Common/esShapes.c | 6 | ||||
-rw-r--r-- | tests/glbook/Common/esUtil.h | 2 | ||||
-rw-r--r-- | tests/glbook/Makefile | 2 | ||||
-rwxr-xr-x | tests/runner.py | 45 |
6 files changed, 58 insertions, 18 deletions
diff --git a/tests/glbook/CH08_SimpleVertexShader.png b/tests/glbook/CH08_SimpleVertexShader.png Binary files differnew file mode 100644 index 00000000..84b276fd --- /dev/null +++ b/tests/glbook/CH08_SimpleVertexShader.png diff --git a/tests/glbook/Chapter_8/Simple_VertexShader/Simple_VertexShader.c b/tests/glbook/Chapter_8/Simple_VertexShader/Simple_VertexShader.c index 6036bf0c..44380c18 100644 --- a/tests/glbook/Chapter_8/Simple_VertexShader/Simple_VertexShader.c +++ b/tests/glbook/Chapter_8/Simple_VertexShader/Simple_VertexShader.c @@ -29,7 +29,7 @@ typedef struct // Vertex daata GLfloat *vertices; - GLuint *indices; + GLushort *indices; int numIndices; // Rotation angle @@ -37,6 +37,8 @@ typedef struct // MVP matrix ESMatrix mvpMatrix; + + GLuint vertPosObject, indicesObject; } UserData; /// @@ -78,6 +80,14 @@ int Init ( ESContext *esContext ) // Starting rotation angle for the cube userData->angle = 45.0f; + glGenBuffers(1, &userData->vertPosObject); + glBindBuffer(GL_ARRAY_BUFFER, userData->vertPosObject); + glBufferData(GL_ARRAY_BUFFER, 24 * sizeof(GLfloat) * 3, userData->vertices, GL_STATIC_DRAW); + + glGenBuffers(1, &userData->indicesObject); + glBindBuffer(GL_ELEMENT_ARRAY_BUFFER, userData->indicesObject); + glBufferData(GL_ELEMENT_ARRAY_BUFFER, userData->numIndices * sizeof(GLushort), userData->indices, GL_STATIC_DRAW); + glClearColor ( 0.0f, 0.0f, 0.0f, 0.0f ); return GL_TRUE; } @@ -137,17 +147,20 @@ void Draw ( ESContext *esContext ) glUseProgram ( userData->programObject ); // Load the vertex position + glBindBuffer(GL_ARRAY_BUFFER, userData->vertPosObject); glVertexAttribPointer ( userData->positionLoc, 3, GL_FLOAT, - GL_FALSE, 3 * sizeof(GLfloat), userData->vertices ); - + GL_FALSE, 0, 0 ); glEnableVertexAttribArray ( userData->positionLoc ); + // Load the index buffer + glBindBuffer(GL_ELEMENT_ARRAY_BUFFER, userData->indicesObject); + // Load the MVP matrix glUniformMatrix4fv( userData->mvpLoc, 1, GL_FALSE, (GLfloat*) &userData->mvpMatrix.m[0][0] ); // Draw the cube - glDrawElements ( GL_TRIANGLES, userData->numIndices, GL_UNSIGNED_INT, userData->indices ); + glDrawElements ( GL_TRIANGLES, userData->numIndices, GL_UNSIGNED_SHORT, 0 ); } /// diff --git a/tests/glbook/Common/esShapes.c b/tests/glbook/Common/esShapes.c index 0fa65057..aecd37ce 100644 --- a/tests/glbook/Common/esShapes.c +++ b/tests/glbook/Common/esShapes.c @@ -139,7 +139,7 @@ int ESUTIL_API esGenSphere ( int numSlices, float radius, GLfloat **vertices, GL /// if it is not NULL ) as a GL_TRIANGLE_STRIP // int ESUTIL_API esGenCube ( float scale, GLfloat **vertices, GLfloat **normals, - GLfloat **texCoords, GLuint **indices ) + GLfloat **texCoords, GLushort **indices ) { int i; int numVertices = 24; @@ -256,7 +256,7 @@ int ESUTIL_API esGenCube ( float scale, GLfloat **vertices, GLfloat **normals, // Generate the indices if ( indices != NULL ) { - GLuint cubeIndices[] = + GLushort cubeIndices[] = { 0, 2, 1, 0, 3, 2, @@ -272,7 +272,7 @@ int ESUTIL_API esGenCube ( float scale, GLfloat **vertices, GLfloat **normals, 20, 22, 21 }; - *indices = malloc ( sizeof(GLuint) * numIndices ); + *indices = malloc ( sizeof(GLushort) * numIndices ); memcpy( *indices, cubeIndices, sizeof( cubeIndices ) ); } diff --git a/tests/glbook/Common/esUtil.h b/tests/glbook/Common/esUtil.h index b675e367..1ff236de 100644 --- a/tests/glbook/Common/esUtil.h +++ b/tests/glbook/Common/esUtil.h @@ -199,7 +199,7 @@ int ESUTIL_API esGenSphere ( int numSlices, float radius, GLfloat **vertices, GL /// if it is not NULL ) as a GL_TRIANGLES
//
int ESUTIL_API esGenCube ( float scale, GLfloat **vertices, GLfloat **normals,
- GLfloat **texCoords, GLuint **indices );
+ GLfloat **texCoords, GLushort **indices );
//
/// \brief Loads a 24-bit TGA image from a file
diff --git a/tests/glbook/Makefile b/tests/glbook/Makefile index 299b594f..386d5717 100644 --- a/tests/glbook/Makefile +++ b/tests/glbook/Makefile @@ -23,7 +23,7 @@ CH13SRC2=./Chapter_13/ParticleSystem/ParticleSystem.c default: all all: ./Chapter_2/Hello_Triangle/CH02_HelloTriangle.bc \ -# ./Chapter_8/Simple_VertexShader/CH08_SimpleVertexShader.bc \ + ./Chapter_8/Simple_VertexShader/CH08_SimpleVertexShader.bc \ # ./Chapter_9/Simple_Texture2D/CH09_SimpleTexture2D.bc \ # ./Chapter_9/MipMap2D/CH09_MipMap2D.bc \ # ./Chapter_9/Simple_TextureCubemap/CH09_TextureCubemap.bc \ diff --git a/tests/runner.py b/tests/runner.py index 62d09ee9..431a1c6e 100755 --- a/tests/runner.py +++ b/tests/runner.py @@ -598,13 +598,13 @@ if 'benchmark' not in str(sys.argv) and 'sanity' not in str(sys.argv) and 'brows return 0; } ''' - self.do_run(src, '*1311918518731868200\n' + + self.do_run(src, '*1311918518731868041\n' + '0,0,0,1,1\n' + '1,0,1,0,1*\n' + '*245127260211081*\n' + '*245127260209443*\n' + - '*18446744073709552000*\n' + - '*576460752303423500*\n' + + '*18446744073709551615*\n' + + '*576460752303423487*\n' + 'm1: 127\n' + '*123*\n' + '*127*\n' + @@ -832,7 +832,6 @@ m_divisor is 1091269979 def test_i64_precise(self): if Settings.USE_TYPED_ARRAYS != 2: return self.skip('full i64 stuff only in ta2') - Settings.PRECISE_I64_MATH = 1 src = r''' #include <inttypes.h> @@ -860,14 +859,39 @@ m_divisor is 1091269979 ''' self.do_run(src, open(path_from_root('tests', 'i64_precise.txt')).read()) - print 'TODO: make precise the default, and imprecise in -O3. Remove precise setting in this test and cube2hash' - print 'TODO: only include this code when needed' - #1/0. + # Verify that without precision, we do not include the precision code + Settings.PRECISE_I64_MATH = 0 + self.do_run(src, 'unsigned') + code = open(os.path.join(self.get_dir(), 'src.cpp.o.js')).read() + assert 'goog.math.Long' not in code and 'jsbn' not in code, 'i64 precise math should not have been included if not asked for' + + # Verify that even if we ask for precision, if it is not needed it is not included + Settings.PRECISE_I64_MATH = 1 + src = ''' + #include <inttypes.h> + #include <stdio.h> + + int main(int argc, char **argv) { + uint64_t x = 2125299906845564, y = 1225891506842664; + if (argc == 12) { + x = x >> 1; + y = y >> 1; + } + x = x & 12ULL; + y = y | 12ULL; + x = x ^ y; + x <<= 2; + y >>= 3; + printf("*%llu, %llu*\\n", x, y); + } + ''' + self.do_run(src, '*4903566027370624, 153236438355333*') + code = open(os.path.join(self.get_dir(), 'src.cpp.o.js')).read() + assert 'goog.math.Long' not in code and 'jsbn' not in code, 'i64 precise math should not have been included if not actually used' def test_cube2hash(self): # A good test of i64 math if Settings.USE_TYPED_ARRAYS != 2: return self.skip('requires ta2 C-style memory aliasing') - Settings.PRECISE_I64_MATH = 1 self.do_run('', 'Usage: hashstring <seed>', libraries=self.get_library('cube2hash', ['cube2hash.bc'], configure=None), includes=[path_from_root('tests', 'cube2hash')]) @@ -6854,7 +6878,10 @@ elif 'browser' in str(sys.argv): self.run_browser('something.html', 'You should not see animating gears.', '/report_gl_result?false') def test_glbook(self): - programs = self.get_library('glbook', [os.path.join('Chapter_2/Hello_Triangle/CH02_HelloTriangle.bc')], configure=None) + programs = self.get_library('glbook', [ + os.path.join('Chapter_2/Hello_Triangle/CH02_HelloTriangle.bc'), + os.path.join('Chapter_8/Simple_VertexShader/CH08_SimpleVertexShader.bc') + ], configure=None) for program in programs: print program self.reftest(path_from_root('tests', 'glbook', os.path.basename(program).replace('.bc', '.png'))) |