diff options
-rw-r--r-- | gpu/demos/demos.gyp | 11 | ||||
-rw-r--r-- | gpu/demos/simple_texture_cubemap/main.cc | 63 | ||||
-rw-r--r-- | third_party/gles2_book/Chapter_9/Simple_TextureCubemap/Simple_TextureCubemap.c | 57 | ||||
-rw-r--r-- | third_party/gles2_book/Chapter_9/Simple_TextureCubemap/Simple_TextureCubemap.h | 49 | ||||
-rw-r--r-- | third_party/gles2_book/gles2_book.gyp | 11 |
5 files changed, 141 insertions, 50 deletions
diff --git a/gpu/demos/demos.gyp b/gpu/demos/demos.gyp index 0f55b0f..14845ad 100644 --- a/gpu/demos/demos.gyp +++ b/gpu/demos/demos.gyp @@ -57,6 +57,17 @@ ], }, { + 'target_name': 'simple_texture_cubemap', + 'type': 'executable', + 'dependencies': [ + 'app_framework', + '../../third_party/gles2_book/gles2_book.gyp:simple_texture_cubemap', + ], + 'sources': [ + 'simple_texture_cubemap/main.cc', + ], + }, + { 'target_name': 'simple_vertex_shader', 'type': 'executable', 'dependencies': [ diff --git a/gpu/demos/simple_texture_cubemap/main.cc b/gpu/demos/simple_texture_cubemap/main.cc new file mode 100644 index 0000000..d42f003 --- /dev/null +++ b/gpu/demos/simple_texture_cubemap/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 is a simple example that draws a sphere with a cubemap image applied. + +#include "gpu/demos/app_framework/application.h" +#include "third_party/gles2_book/Chapter_9/Simple_TextureCubemap/Simple_TextureCubemap.h" + +namespace gpu_demos { +class SimpleTextureCubemap : public Application { + public: + SimpleTextureCubemap(); + ~SimpleTextureCubemap(); + + bool Init(); + + protected: + virtual void Draw(float elapsed_sec); + + private: + ESContext context_; + STCUserData user_data_; + + DISALLOW_COPY_AND_ASSIGN(SimpleTextureCubemap); +}; + +SimpleTextureCubemap::SimpleTextureCubemap() { + esInitContext(&context_); + + memset(&user_data_, 0, sizeof(STCUserData)); + context_.userData = &user_data_; +} + +SimpleTextureCubemap::~SimpleTextureCubemap() { + stcShutDown(&context_); +} + +bool SimpleTextureCubemap::Init() { + if (!Application::InitRenderContext()) return false; + + context_.width = width(); + context_.height = height(); + if (!stcInit(&context_)) return false; + + return true; +} + +void SimpleTextureCubemap::Draw(float /*elapsed_sec*/) { + stcDraw(&context_); +} +} // namespace gpu_demos + +int main(int argc, char *argv[]) { + gpu_demos::SimpleTextureCubemap 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_9/Simple_TextureCubemap/Simple_TextureCubemap.c b/third_party/gles2_book/Chapter_9/Simple_TextureCubemap/Simple_TextureCubemap.c index 5eb13a6..597982a 100644 --- a/third_party/gles2_book/Chapter_9/Simple_TextureCubemap/Simple_TextureCubemap.c +++ b/third_party/gles2_book/Chapter_9/Simple_TextureCubemap/Simple_TextureCubemap.c @@ -13,27 +13,7 @@ // This is a simple example that draws a sphere with a cubemap image applied. // #include <stdlib.h> -#include "esUtil.h" - -typedef struct -{ - // Handle to a program object - GLuint programObject; - - // Attribute locations - GLint positionLoc; - GLint normalLoc; - - // Sampler location - GLint samplerLoc; - - // Texture handle - GLuint textureId; - - // Vertex data - int numIndices; - GLuint vboIds[3]; -} UserData; +#include "Simple_TextureCubemap.h" /// // Create a simple cubemap with a 1x1 face with a different @@ -100,9 +80,9 @@ static GLuint CreateSimpleTextureCubemap( ) /// // Initialize the shader and program object // -int Init ( ESContext *esContext ) +int stcInit ( ESContext *esContext ) { - UserData *userData = esContext->userData; + STCUserData *userData = esContext->userData; int numSlices = 20; int numVertices = ( (numSlices / 2) + 1 ) * ( numSlices + 1 ); GLfloat *vertices = NULL; @@ -167,9 +147,9 @@ int Init ( ESContext *esContext ) /// // Draw a triangle using the shader pair created in Init() // -void Draw ( ESContext *esContext ) +void stcDraw ( ESContext *esContext ) { - UserData *userData = esContext->userData; + STCUserData *userData = esContext->userData; // Set the viewport glViewport ( 0, 0, esContext->width, esContext->height ); @@ -203,16 +183,14 @@ void Draw ( ESContext *esContext ) glDrawElements ( GL_TRIANGLES, userData->numIndices, GL_UNSIGNED_SHORT, 0 ); - - eglSwapBuffers ( esContext->eglDisplay, esContext->eglSurface ); } /// // Cleanup // -void ShutDown ( ESContext *esContext ) +void stcShutDown ( ESContext *esContext ) { - UserData *userData = esContext->userData; + STCUserData *userData = esContext->userData; // Delete texture object glDeleteTextures ( 1, &userData->textureId ); @@ -223,24 +201,3 @@ void ShutDown ( ESContext *esContext ) // Delete vertex buffer objects glDeleteBuffers ( 3, userData->vboIds ); } - - -int main ( int argc, char *argv[] ) -{ - ESContext esContext; - UserData userData; - - esInitContext ( &esContext ); - esContext.userData = &userData; - - esCreateWindow ( &esContext, "Simple Texture Cubemap", 320, 240, ES_WINDOW_RGB ); - - if ( !Init ( &esContext ) ) - return 0; - - esRegisterDrawFunc ( &esContext, Draw ); - - esMainLoop ( &esContext ); - - ShutDown ( &esContext ); -} diff --git a/third_party/gles2_book/Chapter_9/Simple_TextureCubemap/Simple_TextureCubemap.h b/third_party/gles2_book/Chapter_9/Simple_TextureCubemap/Simple_TextureCubemap.h new file mode 100644 index 0000000..3169f97 --- /dev/null +++ b/third_party/gles2_book/Chapter_9/Simple_TextureCubemap/Simple_TextureCubemap.h @@ -0,0 +1,49 @@ +// +// 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 SIMPLE_TEXTURE_CUBEMAP_H +#define SIMPLE_TEXTURE_CUBEMAP_H + +#include "esUtil.h" + +#ifdef __cplusplus +extern "C" { +#endif // __cplusplus + +typedef struct +{ + // Handle to a program object + GLuint programObject; + + // Attribute locations + GLint positionLoc; + GLint normalLoc; + + // Sampler location + GLint samplerLoc; + + // Texture handle + GLuint textureId; + + // Vertex data + int numIndices; + GLuint vboIds[3]; +} STCUserData; + +extern int stcInit ( ESContext *esContext ); + +extern void stcDraw ( ESContext *esContext ); + +extern void stcShutDown ( ESContext *esContext ); + +#ifdef __cplusplus +} +#endif // __cplusplus +#endif // SIMPLE_TEXTURE_CUBEMAP_H diff --git a/third_party/gles2_book/gles2_book.gyp b/third_party/gles2_book/gles2_book.gyp index b71b5e1..667fbb5 100644 --- a/third_party/gles2_book/gles2_book.gyp +++ b/third_party/gles2_book/gles2_book.gyp @@ -62,6 +62,17 @@ ], }, { + 'target_name': 'simple_texture_cubemap', + 'type': 'static_library', + 'dependencies': [ + 'es_util', + ], + 'sources': [ + 'Chapter_9/Simple_TextureCubemap/Simple_TextureCubemap.c', + 'Chapter_9/Simple_TextureCubemap/Simple_TextureCubemap.h', + ], + }, + { 'target_name': 'simple_vertex_shader', 'type': 'static_library', 'dependencies': [ |