aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorAlon Zakai <alonzakai@gmail.com>2012-04-03 16:23:24 -0700
committerAlon Zakai <alonzakai@gmail.com>2012-04-03 16:23:24 -0700
commit80ed60983b3f9b51bf6d6622e44b08b894e7fd9d (patch)
tree0a2a53abf91c4795b7d9b08337979e8a6b6e8f82
parent9cc7f9fa7a110e6c53f7df7583b40087459d5877 (diff)
add another working glbook testcase
-rw-r--r--src/library_gl.js1
-rw-r--r--tests/glbook/CH09_TextureCubemap.pngbin0 -> 3209 bytes
-rw-r--r--tests/glbook/Chapter_9/Simple_TextureCubemap/Simple_TextureCubemap.c31
-rw-r--r--tests/glbook/Common/esShapes.c8
-rw-r--r--tests/glbook/Common/esUtil.h2
-rw-r--r--tests/glbook/Makefile4
-rwxr-xr-xtests/runner.py3
7 files changed, 34 insertions, 15 deletions
diff --git a/src/library_gl.js b/src/library_gl.js
index d893acf0..f64073b6 100644
--- a/src/library_gl.js
+++ b/src/library_gl.js
@@ -1021,6 +1021,7 @@ 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, ', ')*/ + '}';
return arg;
});
Module.printErr('[gl_f:' + prop + ':' + printArgs + ']');
diff --git a/tests/glbook/CH09_TextureCubemap.png b/tests/glbook/CH09_TextureCubemap.png
new file mode 100644
index 00000000..b592b047
--- /dev/null
+++ b/tests/glbook/CH09_TextureCubemap.png
Binary files differ
diff --git a/tests/glbook/Chapter_9/Simple_TextureCubemap/Simple_TextureCubemap.c b/tests/glbook/Chapter_9/Simple_TextureCubemap/Simple_TextureCubemap.c
index b981d943..9f4a9017 100644
--- a/tests/glbook/Chapter_9/Simple_TextureCubemap/Simple_TextureCubemap.c
+++ b/tests/glbook/Chapter_9/Simple_TextureCubemap/Simple_TextureCubemap.c
@@ -34,8 +34,9 @@ typedef struct
int numIndices;
GLfloat *vertices;
GLfloat *normals;
- GLuint *indices;
+ GLushort *indices;
+ GLuint vertPosObject, vertNormalObject, indicesObject;
} UserData;
///
@@ -143,7 +144,20 @@ int Init ( ESContext *esContext )
userData->numIndices = esGenSphere ( 20, 0.75f, &userData->vertices, &userData->normals,
NULL, &userData->indices );
- glClearColor ( 0.0f, 0.0f, 0.0f, 0.0f );
+ // Generate the VBOs
+ glGenBuffers(1, &userData->vertPosObject);
+ glBindBuffer(GL_ARRAY_BUFFER, userData->vertPosObject);
+ glBufferData(GL_ARRAY_BUFFER, 21 * 21 * 4 * 3, userData->vertices, GL_STATIC_DRAW );
+
+ glGenBuffers(1, &userData->vertNormalObject);
+ glBindBuffer(GL_ARRAY_BUFFER, userData->vertNormalObject );
+ glBufferData(GL_ARRAY_BUFFER, 21 * 21 * 4 * 3, userData->normals, GL_STATIC_DRAW );
+
+ glGenBuffers(1, &userData->indicesObject);
+ glBindBuffer(GL_ELEMENT_ARRAY_BUFFER, userData->indicesObject );
+ glBufferData(GL_ELEMENT_ARRAY_BUFFER, 2 * userData->numIndices, userData->indices, GL_STATIC_DRAW );
+
+ glClearColor ( 0.0f, 0.0f, 0.0f, 1.0f );
return GL_TRUE;
}
@@ -167,11 +181,13 @@ void Draw ( ESContext *esContext )
glUseProgram ( userData->programObject );
// Load the vertex position
- glVertexAttribPointer ( userData->positionLoc, 3, GL_FLOAT,
- GL_FALSE, 0, userData->vertices );
+ glBindBuffer ( GL_ARRAY_BUFFER, userData->vertPosObject );
+ glVertexAttribPointer ( userData->positionLoc, 3, GL_FLOAT,
+ GL_FALSE, 0, 0 );
// Load the normal
+ glBindBuffer ( GL_ARRAY_BUFFER, userData->vertNormalObject );
glVertexAttribPointer ( userData->normalLoc, 3, GL_FLOAT,
- GL_FALSE, 0, userData->normals );
+ GL_FALSE, 0, 0 );
glEnableVertexAttribArray ( userData->positionLoc );
glEnableVertexAttribArray ( userData->normalLoc );
@@ -183,8 +199,9 @@ void Draw ( ESContext *esContext )
// Set the sampler texture unit to 0
glUniform1i ( userData->samplerLoc, 0 );
- glDrawElements ( GL_TRIANGLES, userData->numIndices,
- GL_UNSIGNED_INT, userData->indices );
+ glBindBuffer ( GL_ELEMENT_ARRAY_BUFFER, userData->indicesObject );
+ glDrawElements ( GL_TRIANGLES, userData->numIndices,
+ GL_UNSIGNED_SHORT, 0 );
}
///
diff --git a/tests/glbook/Common/esShapes.c b/tests/glbook/Common/esShapes.c
index aecd37ce..6a8ab7ad 100644
--- a/tests/glbook/Common/esShapes.c
+++ b/tests/glbook/Common/esShapes.c
@@ -52,11 +52,11 @@
/// if it is not NULL ) as a GL_TRIANGLE_STRIP
//
int ESUTIL_API esGenSphere ( int numSlices, float radius, GLfloat **vertices, GLfloat **normals,
- GLfloat **texCoords, GLuint **indices )
+ GLfloat **texCoords, GLushort **indices )
{
int i;
int j;
- int numParallels = numSlices / 2;
+ int numParallels = numSlices;
int numVertices = ( numParallels + 1 ) * ( numSlices + 1 );
int numIndices = numParallels * numSlices * 6;
float angleStep = (2.0f * ES_PI) / ((float) numSlices);
@@ -72,7 +72,7 @@ int ESUTIL_API esGenSphere ( int numSlices, float radius, GLfloat **vertices, GL
*texCoords = malloc ( sizeof(GLfloat) * 2 * numVertices );
if ( indices != NULL )
- *indices = malloc ( sizeof(GLuint) * numIndices );
+ *indices = malloc ( sizeof(GLushort) * numIndices );
for ( i = 0; i < numParallels + 1; i++ )
{
@@ -108,7 +108,7 @@ int ESUTIL_API esGenSphere ( int numSlices, float radius, GLfloat **vertices, GL
// Generate the indices
if ( indices != NULL )
{
- GLuint *indexBuf = (*indices);
+ GLushort *indexBuf = (*indices);
for ( i = 0; i < numParallels ; i++ )
{
for ( j = 0; j < numSlices; j++ )
diff --git a/tests/glbook/Common/esUtil.h b/tests/glbook/Common/esUtil.h
index 1ff236de..c468b430 100644
--- a/tests/glbook/Common/esUtil.h
+++ b/tests/glbook/Common/esUtil.h
@@ -185,7 +185,7 @@ GLuint ESUTIL_API esLoadProgram ( const char *vertShaderSrc, const char *fragSha
/// if it is not NULL ) as a GL_TRIANGLE_STRIP
//
int ESUTIL_API esGenSphere ( int numSlices, float radius, GLfloat **vertices, GLfloat **normals,
- GLfloat **texCoords, GLuint **indices );
+ GLfloat **texCoords, GLushort **indices );
//
/// \brief Generates geometry for a cube. Allocates memory for the vertex data and stores
diff --git a/tests/glbook/Makefile b/tests/glbook/Makefile
index 6220fc3c..df8b1615 100644
--- a/tests/glbook/Makefile
+++ b/tests/glbook/Makefile
@@ -25,8 +25,8 @@ default: all
all: ./Chapter_2/Hello_Triangle/CH02_HelloTriangle.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 \
+ ./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_11/Multisample/CH11_Multisample.bc \
diff --git a/tests/runner.py b/tests/runner.py
index 7c988841..03629b12 100755
--- a/tests/runner.py
+++ b/tests/runner.py
@@ -6880,7 +6880,8 @@ elif 'browser' in str(sys.argv):
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'),
- os.path.join('Chapter_9/Simple_Texture2D/CH09_SimpleTexture2D.bc'),
+ os.path.join('Chapter_9', 'Simple_Texture2D', 'CH09_SimpleTexture2D.bc'),
+ os.path.join('Chapter_9', 'Simple_TextureCubemap', 'CH09_TextureCubemap.bc'),
], configure=None)
for program in programs:
print program