summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authoralokp@chromium.org <alokp@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2010-01-15 21:32:20 +0000
committeralokp@chromium.org <alokp@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2010-01-15 21:32:20 +0000
commitcb79b334b49795a96034749007d3104e3b7740aa (patch)
tree28ccf42ac462bc22c3ebc494c175e6385d9515fa
parenteb003245da4a579090d1e9bdee891587db451d4c (diff)
downloadchromium_src-cb79b334b49795a96034749007d3104e3b7740aa.zip
chromium_src-cb79b334b49795a96034749007d3104e3b7740aa.tar.gz
chromium_src-cb79b334b49795a96034749007d3104e3b7740aa.tar.bz2
Added stencil-test demo.
PS: I have not moved the repeated code to the base class for this demo because this is the last one I intend to submit before starting to port the demos to pepper. I will refactor all the demos to eliminate repeating code in light of pepper framework. BUG=26099 TEST=Run stencil_test executable. You should see four different-colored quads. Review URL: http://codereview.chromium.org/545092 git-svn-id: svn://svn.chromium.org/chrome/trunk/src@36410 0039d316-1c4b-4281-b951-d872f2087c98
-rw-r--r--gpu/demos/demos.gyp11
-rw-r--r--gpu/demos/stencil_test/main.cc63
-rw-r--r--third_party/gles2_book/Chapter_11/Stencil_Test/Stencil_Test.c54
-rw-r--r--third_party/gles2_book/Chapter_11/Stencil_Test/Stencil_Test.h45
-rw-r--r--third_party/gles2_book/gles2_book.gyp11
5 files changed, 137 insertions, 47 deletions
diff --git a/gpu/demos/demos.gyp b/gpu/demos/demos.gyp
index 5aeaade..99aa697 100644
--- a/gpu/demos/demos.gyp
+++ b/gpu/demos/demos.gyp
@@ -79,6 +79,17 @@
],
},
{
+ 'target_name': 'stencil_test',
+ 'type': 'executable',
+ 'dependencies': [
+ 'app_framework',
+ '../../third_party/gles2_book/gles2_book.gyp:stencil_test',
+ ],
+ 'sources': [
+ 'stencil_test/main.cc',
+ ],
+ },
+ {
'target_name': 'texture_wrap',
'type': 'executable',
'dependencies': [
diff --git a/gpu/demos/stencil_test/main.cc b/gpu/demos/stencil_test/main.cc
new file mode 100644
index 0000000..a0009cc
--- /dev/null
+++ b/gpu/demos/stencil_test/main.cc
@@ -0,0 +1,63 @@
+// Copyright (c) 2010 The Chromium Authors. All rights reserved.
+// Use of this source code is governed by a BSD-style license that can be
+// found in the LICENSE file.
+
+// This example shows various stencil buffer operations.
+
+#include "gpu/demos/app_framework/application.h"
+#include "third_party/gles2_book/Chapter_11/Stencil_Test/Stencil_Test.h"
+
+namespace gpu_demos {
+class StencilTest : public Application {
+ public:
+ StencilTest();
+ ~StencilTest();
+
+ bool Init();
+
+ protected:
+ virtual void Draw(float elapsed_sec);
+
+ private:
+ ESContext context_;
+ STUserData user_data_;
+
+ DISALLOW_COPY_AND_ASSIGN(StencilTest);
+};
+
+StencilTest::StencilTest() {
+ esInitContext(&context_);
+
+ memset(&user_data_, 0, sizeof(STUserData));
+ context_.userData = &user_data_;
+}
+
+StencilTest::~StencilTest() {
+ stShutDown(&context_);
+}
+
+bool StencilTest::Init() {
+ if (!Application::InitRenderContext()) return false;
+
+ context_.width = width();
+ context_.height = height();
+ if (!stInit(&context_)) return false;
+
+ return true;
+}
+
+void StencilTest::Draw(float /*elapsed_sec*/) {
+ stDraw(&context_);
+}
+} // namespace gpu_demos
+
+int main(int argc, char *argv[]) {
+ gpu_demos::StencilTest app;
+ if (!app.Init()) {
+ printf("Could not init.\n");
+ return EXIT_FAILURE;
+ }
+
+ app.MainLoop();
+ return EXIT_SUCCESS;
+}
diff --git a/third_party/gles2_book/Chapter_11/Stencil_Test/Stencil_Test.c b/third_party/gles2_book/Chapter_11/Stencil_Test/Stencil_Test.c
index 28091903..b884e8d 100644
--- a/third_party/gles2_book/Chapter_11/Stencil_Test/Stencil_Test.c
+++ b/third_party/gles2_book/Chapter_11/Stencil_Test/Stencil_Test.c
@@ -14,30 +14,14 @@
// operations.
//
#include <stdlib.h>
-#include "esUtil.h"
-
-typedef struct
-{
- // Handle to a program object
- GLuint programObject;
-
- // Attribute locations
- GLint positionLoc;
-
- // Uniform locations
- GLint colorLoc;
-
- // Vertex buffer object handles
- GLuint vboIds[2];
-
-} UserData;
+#include "Stencil_Test.h"
///
// Initialize the shader and program object
//
-int Init ( ESContext *esContext )
+int stInit ( ESContext *esContext )
{
- UserData *userData = esContext->userData;
+ STUserData *userData = esContext->userData;
GLbyte vShaderStr[] =
"attribute vec4 a_position; \n"
"void main() \n"
@@ -122,12 +106,12 @@ int Init ( ESContext *esContext )
// Initialize the stencil buffer values, and then use those
// values to control rendering
//
-void Draw ( ESContext *esContext )
+void stDraw ( ESContext *esContext )
{
int i;
GLubyte *offset = NULL;
- UserData *userData = esContext->userData;
+ STUserData *userData = esContext->userData;
#define NumTests 4
GLfloat colors[NumTests][4] = {
@@ -251,16 +235,14 @@ void Draw ( ESContext *esContext )
glUniform4fv( userData->colorLoc, 1, colors[i] );
glDrawElements( GL_TRIANGLES, 6, GL_UNSIGNED_BYTE, offset );
}
-
- eglSwapBuffers ( esContext->eglDisplay, esContext->eglSurface );
}
///
// Cleanup
//
-void ShutDown ( ESContext *esContext )
+void stShutDown ( ESContext *esContext )
{
- UserData *userData = esContext->userData;
+ STUserData *userData = esContext->userData;
// Delete program object
glDeleteProgram ( userData->programObject );
@@ -268,25 +250,3 @@ void ShutDown ( ESContext *esContext )
// Delete vertex buffer objects
glDeleteBuffers ( 2, userData->vboIds );
}
-
-
-int main ( int argc, char *argv[] )
-{
- ESContext esContext;
- UserData userData;
-
- esInitContext ( &esContext );
- esContext.userData = &userData;
-
- esCreateWindow ( &esContext, "Stencil Test", 320, 240,
- ES_WINDOW_RGB | ES_WINDOW_DEPTH | ES_WINDOW_STENCIL );
-
- if ( !Init ( &esContext ) )
- return 0;
-
- esRegisterDrawFunc ( &esContext, Draw );
-
- esMainLoop ( &esContext );
-
- ShutDown ( &esContext );
-}
diff --git a/third_party/gles2_book/Chapter_11/Stencil_Test/Stencil_Test.h b/third_party/gles2_book/Chapter_11/Stencil_Test/Stencil_Test.h
new file mode 100644
index 0000000..ff6bff9
--- /dev/null
+++ b/third_party/gles2_book/Chapter_11/Stencil_Test/Stencil_Test.h
@@ -0,0 +1,45 @@
+//
+// Book: OpenGL(R) ES 2.0 Programming Guide
+// Authors: Aaftab Munshi, Dan Ginsburg, Dave Shreiner
+// ISBN-10: 0321502795
+// ISBN-13: 9780321502797
+// Publisher: Addison-Wesley Professional
+// URLs: http://safari.informit.com/9780321563835
+// http://www.opengles-book.com
+//
+
+#ifndef STENCIL_TEST_H
+#define STENCIL_TEST_H
+
+#include "esUtil.h"
+
+#ifdef __cplusplus
+extern "C" {
+#endif // __cplusplus
+
+typedef struct
+{
+ // Handle to a program object
+ GLuint programObject;
+
+ // Attribute locations
+ GLint positionLoc;
+
+ // Uniform locations
+ GLint colorLoc;
+
+ // Vertex buffer object handles
+ GLuint vboIds[2];
+
+} STUserData;
+
+extern int stInit ( ESContext *esContext );
+
+extern void stDraw ( ESContext *esContext );
+
+extern void stShutDown ( ESContext *esContext );
+
+#ifdef __cplusplus
+}
+#endif // __cplusplus
+#endif // STENCIL_TEST_H
diff --git a/third_party/gles2_book/gles2_book.gyp b/third_party/gles2_book/gles2_book.gyp
index e4975dc..97b351f 100644
--- a/third_party/gles2_book/gles2_book.gyp
+++ b/third_party/gles2_book/gles2_book.gyp
@@ -84,6 +84,17 @@
],
},
{
+ 'target_name': 'stencil_test',
+ 'type': 'static_library',
+ 'dependencies': [
+ 'es_util',
+ ],
+ 'sources': [
+ 'Chapter_11/Stencil_Test/Stencil_Test.c',
+ 'Chapter_11/Stencil_Test/Stencil_Test.h',
+ ],
+ },
+ {
'target_name': 'texture_wrap',
'type': 'static_library',
'dependencies': [