summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorrsesek@chromium.org <rsesek@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2010-01-05 02:05:33 +0000
committerrsesek@chromium.org <rsesek@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2010-01-05 02:05:33 +0000
commit7de03266c2c54238fe225256c481bcea8ae5347d (patch)
tree2b3ceed2a082f093813f7602e99a5c3cb428c672
parent2095d179cdede5b1d58a506189a9a6c3eb0b8a7b (diff)
downloadchromium_src-7de03266c2c54238fe225256c481bcea8ae5347d.zip
chromium_src-7de03266c2c54238fe225256c481bcea8ae5347d.tar.gz
chromium_src-7de03266c2c54238fe225256c481bcea8ae5347d.tar.bz2
Revert 35500 - Added an application framework for demos. Ported hellotriangle example in OpenGL ES book to use the application framework.
BUG=26099 TEST=Try running hello_triangle executable, you should see a red triangle. Review URL: http://codereview.chromium.org/465051 TBR=alokp@chromium.org Review URL: http://codereview.chromium.org/525019 git-svn-id: svn://svn.chromium.org/chrome/trunk/src@35505 0039d316-1c4b-4281-b951-d872f2087c98
-rw-r--r--build/all.gyp2
-rw-r--r--gpu/demos/app_framework/application.cc161
-rw-r--r--gpu/demos/app_framework/application.h57
-rw-r--r--gpu/demos/app_framework/gles2_utils.cc67
-rw-r--r--gpu/demos/app_framework/gles2_utils.h27
-rw-r--r--gpu/demos/app_framework/platform.h23
-rw-r--r--gpu/demos/demos.gyp46
-rw-r--r--gpu/demos/hello_triangle/main.cc64
-rw-r--r--third_party/gles_book_examples/Chapter_2/Hello_Triangle/Hello_Triangle.c303
-rw-r--r--third_party/gles_book_examples/Chapter_2/Hello_Triangle/Hello_Triangle.h46
-rw-r--r--third_party/gles_book_examples/Common/Include/esUtil.h135
-rw-r--r--third_party/gles_book_examples/Common/Include/esUtil_win.h38
-rw-r--r--third_party/gles_book_examples/Common/Source/Win32/esUtil_TGA.c3
-rw-r--r--third_party/gles_book_examples/Common/Source/Win32/esUtil_win32.c183
-rw-r--r--third_party/gles_book_examples/Common/Source/esShader.c4
-rw-r--r--third_party/gles_book_examples/Common/Source/esShapes.c9
-rw-r--r--third_party/gles_book_examples/Common/Source/esTransform.c26
-rw-r--r--third_party/gles_book_examples/Common/Source/esUtil.c184
-rw-r--r--third_party/gles_book_examples/gles_book_examples.gyp49
19 files changed, 720 insertions, 707 deletions
diff --git a/build/all.gyp b/build/all.gyp
index 6243b55..ee2de12 100644
--- a/build/all.gyp
+++ b/build/all.gyp
@@ -96,13 +96,11 @@
'../courgette/courgette.gyp:*',
'../gears/gears.gyp:*',
'../gpu/gpu.gyp:*',
- '../gpu/demos/demos.gyp:*',
'../rlz/rlz.gyp:*',
'../sandbox/sandbox.gyp:*',
'../third_party/bsdiff/bsdiff.gyp:*',
'../third_party/bspatch/bspatch.gyp:*',
'../third_party/cld/cld.gyp:*',
- '../third_party/gles_book_examples/gles_book_examples.gyp:*',
'../tools/memory_watcher/memory_watcher.gyp:*',
# As of now Skia build has problems with Linux and/or 64 bits.
# TODO(sehr,brettw): Make this unconditional.
diff --git a/gpu/demos/app_framework/application.cc b/gpu/demos/app_framework/application.cc
deleted file mode 100644
index 0ae2cb9..0000000
--- a/gpu/demos/app_framework/application.cc
+++ /dev/null
@@ -1,161 +0,0 @@
-// Copyright (c) 2006-2009 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.
-
-#include "gpu/demos/app_framework/application.h"
-
-#include "gpu/command_buffer/client/gles2_implementation.h"
-#include "gpu/command_buffer/client/gles2_lib.h"
-#include "gpu/command_buffer/service/command_buffer_service.h"
-#include "gpu/command_buffer/service/gpu_processor.h"
-
-using gpu::Buffer;
-using gpu::CommandBufferService;
-using gpu::GPUProcessor;
-using gpu::gles2::GLES2CmdHelper;
-using gpu::gles2::GLES2Implementation;
-
-// TODO(alokp): Implement it on mac and linux when gpu process is functional
-// on these OS'.
-#if defined(OS_WIN)
-namespace {
-static const int32 kCommandBufferSize = 1024 * 1024;
-static const int32 kTransferBufferSize = 512 * 1024;
-
-static LRESULT CALLBACK WindowProc(HWND hwnd, UINT msg,
- WPARAM w_param, LPARAM l_param) {
- LRESULT result = 0;
- switch (msg) {
- case WM_CLOSE:
- ::DestroyWindow(hwnd);
- break;
- case WM_DESTROY:
- ::PostQuitMessage(0);
- break;
- case WM_PAINT: {
- using gpu_demos::Application;
- Application* app = reinterpret_cast<Application*>(
- GetWindowLongPtr(hwnd, GWL_USERDATA));
- if (app != NULL) app->OnPaint();
- ::ValidateRect(hwnd, NULL);
- break;
- }
- default:
- result = ::DefWindowProc(hwnd, msg, w_param, l_param);
- break;
- }
- return result;
-}
-} // namespace.
-
-namespace gpu_demos {
-
-Application::Application()
- : width_(512),
- height_(512),
- window_handle_(NULL) {
-}
-
-Application::~Application() {
-}
-
-void Application::MainLoop() {
- MSG msg;
- bool done = false;
- while (!done) {
- while (PeekMessage(&msg, NULL, 0, 0, PM_REMOVE)) {
- if (msg.message == WM_QUIT) done = true;
- TranslateMessage(&msg);
- DispatchMessage(&msg);
- }
- // Message queue is empty and application has not quit yet - keep painting.
- if (!done) SendMessage(window_handle_, WM_PAINT, 0, 0);
- }
-}
-
-void Application::OnPaint() {
- Draw();
- gles2::GetGLContext()->SwapBuffers();
-}
-
-bool Application::InitRenderContext() {
- window_handle_ = CreateNativeWindow();
- if (window_handle_ == NULL) {
- return false;
- }
-
- scoped_ptr<CommandBufferService> command_buffer(new CommandBufferService);
- if (!command_buffer->Initialize(kCommandBufferSize)) {
- return false;
- }
-
- scoped_refptr<GPUProcessor> gpu_processor(
- new GPUProcessor(command_buffer.get()));
- if (!gpu_processor->Initialize(window_handle_)) {
- return false;
- }
-
- command_buffer->SetPutOffsetChangeCallback(
- NewCallback(gpu_processor.get(), &GPUProcessor::ProcessCommands));
-
- GLES2CmdHelper* helper = new GLES2CmdHelper(command_buffer.get());
- if (!helper->Initialize()) {
- // TODO(alokp): cleanup.
- return false;
- }
-
- int32 transfer_buffer_id =
- command_buffer->CreateTransferBuffer(kTransferBufferSize);
- Buffer transfer_buffer =
- command_buffer->GetTransferBuffer(transfer_buffer_id);
- if (transfer_buffer.ptr == NULL) return false;
-
- gles2::g_gl_impl = new GLES2Implementation(helper,
- transfer_buffer.size,
- transfer_buffer.ptr,
- transfer_buffer_id);
-
- return command_buffer.release() != NULL;
-}
-
-NativeWindowHandle Application::CreateNativeWindow() {
- WNDCLASS wnd_class = {0};
- HINSTANCE instance = GetModuleHandle(NULL);
- wnd_class.style = CS_OWNDC;
- wnd_class.lpfnWndProc = (WNDPROC)WindowProc;
- wnd_class.hInstance = instance;
- wnd_class.hbrBackground = (HBRUSH)GetStockObject(BLACK_BRUSH);
- wnd_class.lpszClassName = L"opengles2.0";
- if (!RegisterClass(&wnd_class)) return NULL;
-
- DWORD wnd_style = WS_VISIBLE | WS_POPUP | WS_BORDER | WS_SYSMENU | WS_CAPTION;
- RECT wnd_rect;
- wnd_rect.left = 0;
- wnd_rect.top = 0;
- wnd_rect.right = width_;
- wnd_rect.bottom = height_;
- AdjustWindowRect(&wnd_rect, wnd_style, FALSE);
-
- HWND hwnd = CreateWindow(
- wnd_class.lpszClassName,
- wnd_class.lpszClassName,
- wnd_style,
- 0,
- 0,
- wnd_rect.right - wnd_rect.left,
- wnd_rect.bottom - wnd_rect.top,
- NULL,
- NULL,
- instance,
- NULL);
- if (hwnd == NULL) return NULL;
-
- ShowWindow(hwnd, SW_SHOWNORMAL);
- // Set this to the GWL_USERDATA so that it is available to WindowProc.
- SetWindowLongPtr(hwnd, GWL_USERDATA, (LONG_PTR)this);
-
- return hwnd;
-}
-
-} // namespace gpu_demos
-#endif // defined(OS_WIN)
diff --git a/gpu/demos/app_framework/application.h b/gpu/demos/app_framework/application.h
deleted file mode 100644
index 9851c49..0000000
--- a/gpu/demos/app_framework/application.h
+++ /dev/null
@@ -1,57 +0,0 @@
-// Copyright (c) 2006-2009 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.
-
-// Base class for gles2 applications using command buffer.
-
-#ifndef GPU_DEMOS_APP_FRAMEWORK_APPLICATION_H_
-#define GPU_DEMOS_APP_FRAMEWORK_APPLICATION_H_
-
-#include "base/at_exit.h"
-#include "base/message_loop.h"
-
-#include "gpu/demos/app_framework/platform.h"
-
-namespace gpu_demos {
-
-// Acts as a base class for GLES2 applications using command buffer.
-// The derived calls needs to call InitRenderContext() to create a render
-// surface and initialize a rendering context. Currently it only creates
-// an on-screen window. It will be extended to support pepper/nacl plugin
-// when pepper 3D api is in place.
-class Application {
- public:
- Application();
- virtual ~Application();
-
- // Enters the event processing loop.
- void MainLoop();
- void OnPaint();
-
- protected:
- // Returns the size of rendering surface.
- inline int width() const { return width_; }
- inline int height() const { return height_; }
-
- bool InitRenderContext();
-
- virtual void Draw() = 0;
-
- private:
- // Creates a native on-screen window.
- NativeWindowHandle CreateNativeWindow();
-
- int width_;
- int height_;
- NativeWindowHandle window_handle_;
-
- // The following two variables are just needed to satisfy
- // the assumption that we are running inside a browser.
- base::AtExitManager at_exit_manager_;
- MessageLoopForUI message_loop_;
-
- DISALLOW_COPY_AND_ASSIGN(Application);
-};
-
-} // namespace gpu_demos
-#endif // GPU_DEMOS_APP_FRAMEWORK_APPLICATION_H_
diff --git a/gpu/demos/app_framework/gles2_utils.cc b/gpu/demos/app_framework/gles2_utils.cc
deleted file mode 100644
index 7e7d0e5..0000000
--- a/gpu/demos/app_framework/gles2_utils.cc
+++ /dev/null
@@ -1,67 +0,0 @@
-// Copyright (c) 2006-2009 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.
-
-#include "gpu/demos/app_framework/gles2_utils.h"
-
-namespace {
-static const int kInfoBufferLength = 1024;
-} // namespace
-
-namespace gpu_demos {
-namespace gles2_utils {
-
-GLuint LoadShader(GLenum type, const char* shader_src) {
- GLuint shader = glCreateShader(type);
- if (shader == 0) return 0;
-
- // Load the shader source
- glShaderSource(shader, 1, &shader_src, NULL);
- // Compile the shader
- glCompileShader(shader);
- // Check the compile status
- GLint value;
- glGetShaderiv(shader, GL_COMPILE_STATUS, &value);
- if (value == 0) {
- char buffer[kInfoBufferLength];
- GLsizei length;
- glGetShaderInfoLog(shader, sizeof(buffer), &length, buffer);
- std::string log(buffer, length);
- DLOG(ERROR) << "Error compiling shader:" << log;
- glDeleteShader(shader);
- shader = 0;
- }
- return shader;
-}
-
-GLuint LoadProgram(const char* v_shader_src, const char* f_shader_src) {
- GLuint v_shader = LoadShader(GL_VERTEX_SHADER, v_shader_src);
- if (v_shader == 0) return 0;
-
- GLuint f_shader = LoadShader(GL_FRAGMENT_SHADER, f_shader_src);
- if (f_shader == 0) return 0;
-
- // Create the program object
- GLuint program_object = glCreateProgram();
- if (program_object == 0) return 0;
-
- // Link the program and check status.
- glAttachShader(program_object, v_shader);
- glAttachShader(program_object, f_shader);
- glLinkProgram(program_object);
- GLint linked = 0;
- glGetProgramiv(program_object, GL_LINK_STATUS, &linked);
- if (linked == 0) {
- char buffer[kInfoBufferLength];
- GLsizei length;
- glGetProgramInfoLog(program_object, sizeof(buffer), &length, buffer);
- std::string log(buffer, length);
- DLOG(ERROR) << "Error linking program:" << log;
- glDeleteProgram(program_object);
- program_object = 0;
- }
- return program_object;
-}
-
-} // namespace gles2_utils
-} // namespace gpu_demos
diff --git a/gpu/demos/app_framework/gles2_utils.h b/gpu/demos/app_framework/gles2_utils.h
deleted file mode 100644
index 147671f..0000000
--- a/gpu/demos/app_framework/gles2_utils.h
+++ /dev/null
@@ -1,27 +0,0 @@
-// Copyright (c) 2006-2009 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.
-
-// Utility OpenGL ES 2.0 functions.
-
-#ifndef GPU_DEMOS_APP_FRAMEWORK_GLES2_UTILS_H_
-#define GPU_DEMOS_APP_FRAMEWORK_GLES2_UTILS_H_
-
-#include <GLES2/gl2.h>
-
-namespace gpu_demos {
-namespace gles2_utils {
-
-// Uploads and compiles shader source. Returns non-zero shader object id.
-// Returns 0 if an error occurs creating or compiling the shader object.
-// All errors are logged.
-extern GLuint LoadShader(GLenum type, const char* shader_src);
-
-// Uploads, compiles, and links shader program. Returns non-zero program id.
-// Returns 0 if an error occurs creating, compiling, or linking the program
-// object. All errors are logged.
-extern GLuint LoadProgram(const char* v_shader_src, const char* f_shader_src);
-
-} // namespace gles2_utils
-} // namespace gpu_demos
-#endif // GPU_DEMOS_APP_FRAMEWORK_GLES2_UTILS_H_
diff --git a/gpu/demos/app_framework/platform.h b/gpu/demos/app_framework/platform.h
deleted file mode 100644
index 602979e..0000000
--- a/gpu/demos/app_framework/platform.h
+++ /dev/null
@@ -1,23 +0,0 @@
-// Copyright (c) 2006-2009 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.
-
-// Platform-specific types and definitions for native widget handles.
-
-#ifndef GPU_DEMOS_APP_FRAMEWORK_PLATFORM_H_
-#define GPU_DEMOS_APP_FRAMEWORK_PLATFORM_H_
-
-#ifdef _WINDOWS
-#include <windows.h>
-#endif // _WINDOWS
-
-#include "build/build_config.h"
-
-namespace gpu_demos {
-
-#if defined(OS_WIN)
-typedef HWND NativeWindowHandle;
-#endif // defined(OS_WIN)
-
-} // namespace gpu_demos
-#endif // GPU_DEMOS_APP_FRAMEWORK_PLATFORM_H_
diff --git a/gpu/demos/demos.gyp b/gpu/demos/demos.gyp
deleted file mode 100644
index 26cedea..0000000
--- a/gpu/demos/demos.gyp
+++ /dev/null
@@ -1,46 +0,0 @@
-# Copyright (c) 2009 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.
-
-{
- 'variables': {
- 'chromium_code': 1,
- },
- 'includes': [
- '../../build/common.gypi',
- ],
- 'targets': [
- {
- 'target_name': 'app_framework',
- 'type': 'static_library',
- 'dependencies': [
- '../gpu.gyp:command_buffer_client',
- '../gpu.gyp:command_buffer_service',
- ],
- 'sources': [
- 'app_framework/application.cc',
- 'app_framework/application.h',
- 'app_framework/gles2_utils.cc',
- 'app_framework/gles2_utils.h',
- 'app_framework/platform.h',
- ],
- },
- {
- 'target_name': 'hello_triangle',
- 'type': 'executable',
- 'dependencies': [
- 'app_framework',
- '../../third_party/gles_book_examples/gles_book_examples.gyp:hello_triangle',
- ],
- 'sources': [
- 'hello_triangle/main.cc',
- ],
- },
- ]
-}
-
-# Local Variables:
-# tab-width:2
-# indent-tabs-mode:nil
-# End:
-# vim: set expandtab tabstop=2 shiftwidth=2:
diff --git a/gpu/demos/hello_triangle/main.cc b/gpu/demos/hello_triangle/main.cc
deleted file mode 100644
index 124e491..0000000
--- a/gpu/demos/hello_triangle/main.cc
+++ /dev/null
@@ -1,64 +0,0 @@
-// Copyright (c) 2009 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 single triangle with
-// a minimal vertex/fragment shader. The purpose of this
-// example is to demonstrate the basic concepts of
-// OpenGL ES 2.0 rendering.
-
-#include "gpu/demos/app_framework/application.h"
-#include "third_party/gles_book_examples/Chapter_2/Hello_Triangle/Hello_Triangle.h"
-
-namespace gpu_demos {
-class HelloTriangle : public Application {
- public:
- HelloTriangle();
- ~HelloTriangle();
-
- bool Init();
-
- protected:
- virtual void Draw();
-
- private:
- ESContext context_;
- HTUserData user_data_;
-};
-
-HelloTriangle::HelloTriangle() {
- esInitContext(&context_);
-
- memset(&user_data_, 0, sizeof(HTUserData));
- context_.userData = &user_data_;
-}
-
-HelloTriangle::~HelloTriangle() {
- htShutDown(&context_);
-}
-
-bool HelloTriangle::Init() {
- if (!Application::InitRenderContext()) return false;
-
- context_.width = width();
- context_.height = height();
- if (!htInit(&context_)) return false;
-
- return true;
-}
-
-void HelloTriangle::Draw() {
- htDraw(&context_);
-}
-} // namespace gpu_demos
-
-int main(int argc, char *argv[]) {
- gpu_demos::HelloTriangle app;
- if (!app.Init()) {
- printf("Could not init.\n");
- return EXIT_FAILURE;
- }
-
- app.MainLoop();
- return EXIT_SUCCESS;
-}
diff --git a/third_party/gles_book_examples/Chapter_2/Hello_Triangle/Hello_Triangle.c b/third_party/gles_book_examples/Chapter_2/Hello_Triangle/Hello_Triangle.c
index d2deeb2..6b12a59 100644
--- a/third_party/gles_book_examples/Chapter_2/Hello_Triangle/Hello_Triangle.c
+++ b/third_party/gles_book_examples/Chapter_2/Hello_Triangle/Hello_Triangle.c
@@ -1,109 +1,194 @@
-//
-// 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
-//
-
-// Hello_Triangle.c
-//
-// This is a simple example that draws a single triangle with
-// a minimal vertex/fragment shader. The purpose of this
-// example is to demonstrate the basic concepts of
-// OpenGL ES 2.0 rendering.
-
-#include "Hello_Triangle.h"
-
-#include <stdlib.h>
-
-///
-// Initialize the shader and program object
-//
-int htInit ( ESContext *esContext )
-{
- HTUserData *userData = esContext->userData;
-
- GLbyte vShaderStr[] =
- "attribute vec4 vPosition; \n"
- "void main() \n"
- "{ \n"
- " gl_Position = vPosition; \n"
- "} \n";
-
- // TODO(alokp): Shaders containing "precision" do not compile.
- GLbyte fShaderStr[] =
- "void main() \n"
- "{ \n"
- " gl_FragColor = vec4 ( 1.0, 0.0, 0.0, 1.0 );\n"
- "} \n";
-
- // TODO(alokp): Client-side vertex arrays do not work.
- GLfloat vVertices[] = { 0.0f, 0.5f, 0.0f,
- -0.5f, -0.5f, 0.0f,
- 0.5f, -0.5f, 0.0f };
-
- userData->programObject = esLoadProgram ( vShaderStr, fShaderStr );
- if ( userData->programObject == 0 ) return FALSE;
-
- // Bind vPosition to attribute 0
- glBindAttribLocation ( userData->programObject, 0, "vPosition" );
-
- glGenBuffers ( 1, &userData->vbo );
- glBindBuffer ( GL_ARRAY_BUFFER, userData->vbo );
- glBufferData ( GL_ARRAY_BUFFER, sizeof(vVertices), NULL, GL_STATIC_DRAW );
- glBufferSubData ( GL_ARRAY_BUFFER, 0, sizeof(vVertices), vVertices );
-
- glClearColor ( 0.0f, 0.0f, 0.0f, 0.0f );
- return TRUE;
-}
-
-///
-// Draw a triangle using the shader pair created in Init()
-//
-void htDraw ( ESContext *esContext )
-{
- HTUserData *userData = esContext->userData;
-
- // Set the viewport
- glViewport ( 0, 0, esContext->width, esContext->height );
-
- // Clear the color buffer
- glClear ( GL_COLOR_BUFFER_BIT );
-
- // Use the program object
- glUseProgram ( userData->programObject );
-
- // Load the vertex data
- glBindBuffer ( GL_ARRAY_BUFFER, userData->vbo );
- glEnableVertexAttribArray ( 0 );
- glVertexAttribPointer ( 0, 3, GL_FLOAT, GL_FALSE, 0, 0 );
-
- glDrawArrays ( GL_TRIANGLES, 0, 3 );
-
- // Nothing is drawn or application crashes without glFlush.
- // TODO(alokp): glFlush should not be necessary with SwapBuffers().
- glFlush();
-}
-
-///
-// Cleanup
-//
-void htShutDown ( ESContext *esContext )
-{
- HTUserData *userData = esContext->userData;
-
- // Delete program object
- if ( userData->programObject != 0 )
- {
- glDeleteProgram ( userData->programObject );
- userData->programObject = 0;
- }
- if ( userData->vbo != 0 )
- {
- glDeleteBuffers ( 1, &userData->vbo );
- userData->vbo = 0;
- }
-}
+//
+// 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
+//
+
+// Hello_Triangle.c
+//
+// This is a simple example that draws a single triangle with
+// a minimal vertex/fragment shader. The purpose of this
+// example is to demonstrate the basic concepts of
+// OpenGL ES 2.0 rendering.
+#include <stdlib.h>
+#include "esUtil.h"
+
+typedef struct
+{
+ // Handle to a program object
+ GLuint programObject;
+
+} UserData;
+
+///
+// Create a shader object, load the shader source, and
+// compile the shader.
+//
+GLuint LoadShader ( GLenum type, const char *shaderSrc )
+{
+ GLuint shader;
+ GLint compiled;
+
+ // Create the shader object
+ shader = glCreateShader ( type );
+
+ if ( shader == 0 )
+ return 0;
+
+ // Load the shader source
+ glShaderSource ( shader, 1, &shaderSrc, NULL );
+
+ // Compile the shader
+ glCompileShader ( shader );
+
+ // Check the compile status
+ glGetShaderiv ( shader, GL_COMPILE_STATUS, &compiled );
+
+ if ( !compiled )
+ {
+ GLint infoLen = 0;
+
+ glGetShaderiv ( shader, GL_INFO_LOG_LENGTH, &infoLen );
+
+ if ( infoLen > 1 )
+ {
+ char* infoLog = malloc (sizeof(char) * infoLen );
+
+ glGetShaderInfoLog ( shader, infoLen, NULL, infoLog );
+ esLogMessage ( "Error compiling shader:\n%s\n", infoLog );
+
+ free ( infoLog );
+ }
+
+ glDeleteShader ( shader );
+ return 0;
+ }
+
+ return shader;
+
+}
+
+///
+// Initialize the shader and program object
+//
+int Init ( ESContext *esContext )
+{
+ UserData *userData = esContext->userData;
+ GLbyte vShaderStr[] =
+ "attribute vec4 vPosition; \n"
+ "void main() \n"
+ "{ \n"
+ " gl_Position = vPosition; \n"
+ "} \n";
+
+ GLbyte fShaderStr[] =
+ "precision mediump float;\n"\
+ "void main() \n"
+ "{ \n"
+ " gl_FragColor = vec4 ( 1.0, 0.0, 0.0, 1.0 );\n"
+ "} \n";
+
+ GLuint vertexShader;
+ GLuint fragmentShader;
+ GLuint programObject;
+ GLint linked;
+
+ // Load the vertex/fragment shaders
+ vertexShader = LoadShader ( GL_VERTEX_SHADER, vShaderStr );
+ fragmentShader = LoadShader ( GL_FRAGMENT_SHADER, fShaderStr );
+
+ // Create the program object
+ programObject = glCreateProgram ( );
+
+ if ( programObject == 0 )
+ return 0;
+
+ glAttachShader ( programObject, vertexShader );
+ glAttachShader ( programObject, fragmentShader );
+
+ // Bind vPosition to attribute 0
+ glBindAttribLocation ( programObject, 0, "vPosition" );
+
+ // Link the program
+ glLinkProgram ( programObject );
+
+ // Check the link status
+ glGetProgramiv ( programObject, GL_LINK_STATUS, &linked );
+
+ if ( !linked )
+ {
+ GLint infoLen = 0;
+
+ glGetProgramiv ( programObject, GL_INFO_LOG_LENGTH, &infoLen );
+
+ if ( infoLen > 1 )
+ {
+ char* infoLog = malloc (sizeof(char) * infoLen );
+
+ glGetProgramInfoLog ( programObject, infoLen, NULL, infoLog );
+ esLogMessage ( "Error linking program:\n%s\n", infoLog );
+
+ free ( infoLog );
+ }
+
+ glDeleteProgram ( programObject );
+ return FALSE;
+ }
+
+ // Store the program object
+ userData->programObject = programObject;
+
+ glClearColor ( 0.0f, 0.0f, 0.0f, 0.0f );
+ return TRUE;
+}
+
+///
+// Draw a triangle using the shader pair created in Init()
+//
+void Draw ( ESContext *esContext )
+{
+ UserData *userData = esContext->userData;
+ GLfloat vVertices[] = { 0.0f, 0.5f, 0.0f,
+ -0.5f, -0.5f, 0.0f,
+ 0.5f, -0.5f, 0.0f };
+
+ // Set the viewport
+ glViewport ( 0, 0, esContext->width, esContext->height );
+
+ // Clear the color buffer
+ glClear ( GL_COLOR_BUFFER_BIT );
+
+ // Use the program object
+ glUseProgram ( userData->programObject );
+
+ // Load the vertex data
+ glVertexAttribPointer ( 0, 3, GL_FLOAT, GL_FALSE, 0, vVertices );
+ glEnableVertexAttribArray ( 0 );
+
+ glDrawArrays ( GL_TRIANGLES, 0, 3 );
+
+ eglSwapBuffers ( esContext->eglDisplay, esContext->eglSurface );
+}
+
+
+int main ( int argc, char *argv[] )
+{
+ ESContext esContext;
+ UserData userData;
+
+ esInitContext ( &esContext );
+ esContext.userData = &userData;
+
+ esCreateWindow ( &esContext, "Hello Triangle", 320, 240, ES_WINDOW_RGB );
+
+ if ( !Init ( &esContext ) )
+ return 0;
+
+ esRegisterDrawFunc ( &esContext, Draw );
+
+ esMainLoop ( &esContext );
+}
diff --git a/third_party/gles_book_examples/Chapter_2/Hello_Triangle/Hello_Triangle.h b/third_party/gles_book_examples/Chapter_2/Hello_Triangle/Hello_Triangle.h
deleted file mode 100644
index 930d486..0000000
--- a/third_party/gles_book_examples/Chapter_2/Hello_Triangle/Hello_Triangle.h
+++ /dev/null
@@ -1,46 +0,0 @@
-//
-// 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
-//
-
-//
-// Hello_Triangle.h
-//
-// This is a simple example that draws a single triangle with
-// a minimal vertex/fragment shader. The purpose of this
-// example is to demonstrate the basic concepts of
-// OpenGL ES 2.0 rendering.
-
-#ifndef HELLO_TRIANGLE_H
-#define HELLO_TRIANGLE_H
-
-#include "esUtil.h"
-
-#ifdef __cplusplus
-extern "C" {
-#endif // __cplusplus
-
-typedef struct
-{
- // Handle to a program object
- GLuint programObject;
- // Handle to vbo object
- GLuint vbo;
-
-} HTUserData;
-
-extern int htInit ( ESContext *esContext );
-
-extern void htDraw ( ESContext *esContext );
-
-extern void htShutDown ( ESContext *esContext );
-
-#ifdef __cplusplus
-}
-#endif // __cplusplus
-#endif // HELLO_TRIANGLE_H
diff --git a/third_party/gles_book_examples/Common/Include/esUtil.h b/third_party/gles_book_examples/Common/Include/esUtil.h
index 105e0b0..f1ab1bf 100644
--- a/third_party/gles_book_examples/Common/Include/esUtil.h
+++ b/third_party/gles_book_examples/Common/Include/esUtil.h
@@ -21,17 +21,36 @@
// Includes
//
#include <GLES2/gl2.h>
+#include <EGL/egl.h>
#ifdef __cplusplus
+
extern "C" {
-#endif // __cplusplus
+#endif
+
+
+///
+// Macros
+//
+#define ESUTIL_API __cdecl
+#define ESCALLBACK __cdecl
+
-#ifndef FALSE
-#define FALSE 0
-#endif // FALSE
-#ifndef TRUE
-#define TRUE 1
-#endif // TRUE
+/// esCreateWindow flag - RGB color buffer
+#define ES_WINDOW_RGB 0
+/// esCreateWindow flag - ALPHA color buffer
+#define ES_WINDOW_ALPHA 1
+/// esCreateWindow flag - depth buffer
+#define ES_WINDOW_DEPTH 2
+/// esCreateWindow flag - stencil buffer
+#define ES_WINDOW_STENCIL 4
+/// esCreateWindow flat - multi-sample buffer
+#define ES_WINDOW_MULTISAMPLE 8
+
+
+///
+// Types
+//
typedef struct
{
@@ -48,20 +67,84 @@ typedef struct
/// Window height
GLint height;
+
+ /// Window handle
+ EGLNativeWindowType hWnd;
+
+ /// EGL display
+ EGLDisplay eglDisplay;
+
+ /// EGL context
+ EGLContext eglContext;
+
+ /// EGL surface
+ EGLSurface eglSurface;
+
+ /// Callbacks
+ void (ESCALLBACK *drawFunc) ( void* );
+ void (ESCALLBACK *keyFunc) ( void*, unsigned char, int, int );
+ void (ESCALLBACK *updateFunc) ( void*, float deltaTime );
} ESContext;
+
+///
+// Public Functions
+//
+
//
///
/// \brief Initialize ES framework context. This must be called before calling any other functions.
/// \param esContext Application context
//
-extern void esInitContext ( ESContext *esContext );
+void ESUTIL_API esInitContext ( ESContext *esContext );
//
+/// \brief Create a window with the specified parameters
+/// \param esContext Application context
+/// \param title Name for title bar of window
+/// \param width Width in pixels of window to create
+/// \param height Height in pixels of window to create
+/// \param flags Bitfield for the window creation flags
+/// ES_WINDOW_RGB - specifies that the color buffer should have R,G,B channels
+/// ES_WINDOW_ALPHA - specifies that the color buffer should have alpha
+/// ES_WINDOW_DEPTH - specifies that a depth buffer should be created
+/// ES_WINDOW_STENCIL - specifies that a stencil buffer should be created
+/// ES_WINDOW_MULTISAMPLE - specifies that a multi-sample buffer should be created
+/// \return GL_TRUE if window creation is succesful, GL_FALSE otherwise
+GLboolean ESUTIL_API esCreateWindow ( ESContext *esContext, const char *title, GLint width, GLint height, GLuint flags );
+
+//
+/// \brief Start the main loop for the OpenGL ES application
+/// \param esContext Application context
+//
+void ESUTIL_API esMainLoop ( ESContext *esContext );
+
+//
+/// \brief Register a draw callback function to be used to render each frame
+/// \param esContext Application context
+/// \param drawFunc Draw callback function that will be used to render the scene
+//
+void ESUTIL_API esRegisterDrawFunc ( ESContext *esContext, void (ESCALLBACK *drawFunc) ( ESContext* ) );
+
+//
+/// \brief Register an update callback function to be used to update on each time step
+/// \param esContext Application context
+/// \param updateFunc Update callback function that will be used to render the scene
+//
+void ESUTIL_API esRegisterUpdateFunc ( ESContext *esContext, void (ESCALLBACK *updateFunc) ( ESContext*, float ) );
+
+//
+/// \brief Register an keyboard input processing callback function
+/// \param esContext Application context
+/// \param keyFunc Key callback function for application processing of keyboard input
+//
+void ESUTIL_API esRegisterKeyFunc ( ESContext *esContext,
+ void (ESCALLBACK *drawFunc) ( ESContext*, unsigned char, int, int ) );
+//
/// \brief Log a message to the debug output for the platform
/// \param formatStr Format string for error log.
//
-extern void esLogMessage ( const char *formatStr, ... );
+void ESUTIL_API esLogMessage ( const char *formatStr, ... );
//
///
@@ -70,7 +153,7 @@ extern void esLogMessage ( const char *formatStr, ... );
/// \param shaderSrc Shader source string
/// \return A new shader object on success, 0 on failure
//
-extern GLuint esLoadShader ( GLenum type, const char *shaderSrc );
+GLuint ESUTIL_API esLoadShader ( GLenum type, const char *shaderSrc );
//
///
@@ -80,7 +163,7 @@ extern GLuint esLoadShader ( GLenum type, const char *shaderSrc );
/// \param fragShaderSrc Fragment shader source code
/// \return A new program object linked with the vertex/fragment shader pair, 0 on failure
//
-extern GLuint esLoadProgram ( const char *vertShaderSrc, const char *fragShaderSrc );
+GLuint ESUTIL_API esLoadProgram ( const char *vertShaderSrc, const char *fragShaderSrc );
//
@@ -94,8 +177,8 @@ extern GLuint esLoadProgram ( const char *vertShaderSrc, const char *fragShaderS
/// \return The number of indices required for rendering the buffers (the number of indices stored in the indices array
/// if it is not NULL ) as a GL_TRIANGLE_STRIP
//
-extern int esGenSphere ( int numSlices, float radius, GLfloat **vertices, GLfloat **normals,
- GLfloat **texCoords, GLuint **indices );
+int ESUTIL_API esGenSphere ( int numSlices, float radius, GLfloat **vertices, GLfloat **normals,
+ GLfloat **texCoords, GLuint **indices );
//
/// \brief Generates geometry for a cube. Allocates memory for the vertex data and stores
@@ -108,8 +191,8 @@ extern int esGenSphere ( int numSlices, float radius, GLfloat **vertices, GLfloa
/// \return The number of indices required for rendering the buffers (the number of indices stored in the indices array
/// if it is not NULL ) as a GL_TRIANGLES
//
-extern int esGenCube ( float scale, GLfloat **vertices, GLfloat **normals,
- GLfloat **texCoords, GLuint **indices );
+int ESUTIL_API esGenCube ( float scale, GLfloat **vertices, GLfloat **normals,
+ GLfloat **texCoords, GLuint **indices );
//
/// \brief Loads a 24-bit TGA image from a file
@@ -118,7 +201,7 @@ extern int esGenCube ( float scale, GLfloat **vertices, GLfloat **normals,
/// \param height Height of loaded image in pixels
/// \return Pointer to loaded image. NULL on failure.
//
-extern char* esLoadTGA ( char *fileName, int *width, int *height );
+char* ESUTIL_API esLoadTGA ( char *fileName, int *width, int *height );
//
@@ -126,14 +209,14 @@ extern char* esLoadTGA ( char *fileName, int *width, int *height );
/// \param result Specifies the input matrix. Scaled matrix is returned in result.
/// \param sx, sy, sz Scale factors along the x, y and z axes respectively
//
-extern void esScale(ESMatrix *result, GLfloat sx, GLfloat sy, GLfloat sz);
+void ESUTIL_API esScale(ESMatrix *result, GLfloat sx, GLfloat sy, GLfloat sz);
//
/// \brief multiply matrix specified by result with a translation matrix and return new matrix in result
/// \param result Specifies the input matrix. Translated matrix is returned in result.
/// \param tx, ty, tz Scale factors along the x, y and z axes respectively
//
-extern void esTranslate(ESMatrix *result, GLfloat tx, GLfloat ty, GLfloat tz);
+void ESUTIL_API esTranslate(ESMatrix *result, GLfloat tx, GLfloat ty, GLfloat tz);
//
/// \brief multiply matrix specified by result with a rotation matrix and return new matrix in result
@@ -141,7 +224,7 @@ extern void esTranslate(ESMatrix *result, GLfloat tx, GLfloat ty, GLfloat tz);
/// \param angle Specifies the angle of rotation, in degrees.
/// \param x, y, z Specify the x, y and z coordinates of a vector, respectively
//
-extern void esRotate(ESMatrix *result, GLfloat angle, GLfloat x, GLfloat y, GLfloat z);
+void ESUTIL_API esRotate(ESMatrix *result, GLfloat angle, GLfloat x, GLfloat y, GLfloat z);
//
// \brief multiply matrix specified by result with a perspective matrix and return new matrix in result
@@ -150,7 +233,7 @@ extern void esRotate(ESMatrix *result, GLfloat angle, GLfloat x, GLfloat y, GLfl
/// \param bottom, top Coordinates for the bottom and top horizontal clipping planes
/// \param nearZ, farZ Distances to the near and far depth clipping planes. Both distances must be positive.
//
-extern void esFrustum(ESMatrix *result, float left, float right, float bottom, float top, float nearZ, float farZ);
+void ESUTIL_API esFrustum(ESMatrix *result, float left, float right, float bottom, float top, float nearZ, float farZ);
//
/// \brief multiply matrix specified by result with a perspective matrix and return new matrix in result
@@ -160,7 +243,7 @@ extern void esFrustum(ESMatrix *result, float left, float right, float bottom, f
/// \param nearZ Near plane distance
/// \param farZ Far plane distance
//
-extern void esPerspective(ESMatrix *result, float fovy, float aspect, float nearZ, float farZ);
+void ESUTIL_API esPerspective(ESMatrix *result, float fovy, float aspect, float nearZ, float farZ);
//
/// \brief multiply matrix specified by result with a perspective matrix and return new matrix in result
@@ -169,23 +252,23 @@ extern void esPerspective(ESMatrix *result, float fovy, float aspect, float near
/// \param bottom, top Coordinates for the bottom and top horizontal clipping planes
/// \param nearZ, farZ Distances to the near and far depth clipping planes. These values are negative if plane is behind the viewer
//
-extern void esOrtho(ESMatrix *result, float left, float right, float bottom, float top, float nearZ, float farZ);
+void ESUTIL_API esOrtho(ESMatrix *result, float left, float right, float bottom, float top, float nearZ, float farZ);
//
/// \brief perform the following operation - result matrix = srcA matrix * srcB matrix
/// \param result Returns multiplied matrix
/// \param srcA, srcB Input matrices to be multiplied
//
-extern void esMatrixMultiply(ESMatrix *result, ESMatrix *srcA, ESMatrix *srcB);
+void ESUTIL_API esMatrixMultiply(ESMatrix *result, ESMatrix *srcA, ESMatrix *srcB);
//
//// \brief return an indentity matrix
//// \param result returns identity matrix
//
-extern void esMatrixLoadIdentity(ESMatrix *result);
+void ESUTIL_API esMatrixLoadIdentity(ESMatrix *result);
#ifdef __cplusplus
}
-#endif // __cplusplus
+#endif
-#endif // ESUTIL_H
+#endif // ESUTIL_H \ No newline at end of file
diff --git a/third_party/gles_book_examples/Common/Include/esUtil_win.h b/third_party/gles_book_examples/Common/Include/esUtil_win.h
index 752535c..4017118 100644
--- a/third_party/gles_book_examples/Common/Include/esUtil_win.h
+++ b/third_party/gles_book_examples/Common/Include/esUtil_win.h
@@ -15,9 +15,41 @@
#ifndef ESUTIL_WIN_H
#define ESUTIL_WIN_H
+///
+// Includes
+//
+
#ifdef __cplusplus
+
extern "C" {
-#endif // __cplusplus
+#endif
+
+
+///
+// Macros
+//
+
+///
+// Types
+//
+
+///
+// Public Functions
+//
+
+///
+// WinCreate()
+//
+// Create Win32 instance and window
+//
+GLboolean WinCreate ( ESContext *esContext, const char *title );
+
+///
+// WinLoop()
+//
+// Start main windows loop
+//
+void WinLoop ( ESContext *esContext );
///
// WinTGALoad()
@@ -28,6 +60,6 @@ int WinTGALoad ( const char *fileName, char **buffer, int *width, int *height );
#ifdef __cplusplus
}
-#endif // __cplusplus
+#endif
-#endif // ESUTIL_WIN_H
+#endif // ESUTIL_WIN_H \ No newline at end of file
diff --git a/third_party/gles_book_examples/Common/Source/Win32/esUtil_TGA.c b/third_party/gles_book_examples/Common/Source/Win32/esUtil_TGA.c
index 9936a4f..4617cdd 100644
--- a/third_party/gles_book_examples/Common/Source/Win32/esUtil_TGA.c
+++ b/third_party/gles_book_examples/Common/Source/Win32/esUtil_TGA.c
@@ -12,10 +12,7 @@
//
// This file contains the Win32 implementation of a TGA image loader
-#ifndef WIN32_LEAN_AND_MEAN
#define WIN32_LEAN_AND_MEAN
-#endif // WIN32_LEAN_AND_MEAN
-
#include <windows.h>
#include <stdio.h>
#include <stdlib.h>
diff --git a/third_party/gles_book_examples/Common/Source/Win32/esUtil_win32.c b/third_party/gles_book_examples/Common/Source/Win32/esUtil_win32.c
new file mode 100644
index 0000000..73dcaad
--- /dev/null
+++ b/third_party/gles_book_examples/Common/Source/Win32/esUtil_win32.c
@@ -0,0 +1,183 @@
+//
+// 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
+//
+
+// esUtil_win32.c
+//
+// This file contains the Win32 implementation of the windowing functions.
+
+
+///
+// Includes
+//
+#define WIN32_LEAN_AND_MEAN
+#include <windows.h>
+#include "esUtil.h"
+
+//////////////////////////////////////////////////////////////////
+//
+// Private Functions
+//
+//
+
+///
+// ESWindowProc()
+//
+// Main window procedure
+//
+LRESULT WINAPI ESWindowProc ( HWND hWnd, UINT uMsg, WPARAM wParam, LPARAM lParam )
+{
+ LRESULT lRet = 1;
+
+ switch (uMsg)
+ {
+ case WM_CREATE:
+ break;
+
+ case WM_PAINT:
+ {
+ ESContext *esContext = (ESContext*)(LONG_PTR) GetWindowLongPtr ( hWnd, GWL_USERDATA );
+
+ if ( esContext && esContext->drawFunc )
+ esContext->drawFunc ( esContext );
+
+ ValidateRect( esContext->hWnd, NULL );
+ }
+ break;
+
+ case WM_DESTROY:
+ PostQuitMessage(0);
+ break;
+
+ case WM_CHAR:
+ {
+ POINT point;
+ ESContext *esContext = (ESContext*)(LONG_PTR) GetWindowLongPtr ( hWnd, GWL_USERDATA );
+
+ GetCursorPos( &point );
+
+ if ( esContext && esContext->keyFunc )
+ esContext->keyFunc ( esContext, (unsigned char) wParam,
+ (int) point.x, (int) point.y );
+}
+ break;
+
+ default:
+ lRet = DefWindowProc (hWnd, uMsg, wParam, lParam);
+ break;
+ }
+
+ return lRet;
+}
+
+//////////////////////////////////////////////////////////////////
+//
+// Public Functions
+//
+//
+
+///
+// WinCreate()
+//
+// Create Win32 instance and window
+//
+GLboolean WinCreate ( ESContext *esContext, const char *title )
+{
+ WNDCLASS wndclass = {0};
+ DWORD wStyle = 0;
+ RECT windowRect;
+ HINSTANCE hInstance = GetModuleHandle(NULL);
+
+
+ wndclass.style = CS_OWNDC;
+ wndclass.lpfnWndProc = (WNDPROC)ESWindowProc;
+ wndclass.hInstance = hInstance;
+ wndclass.hbrBackground = (HBRUSH)GetStockObject(BLACK_BRUSH);
+ wndclass.lpszClassName = "opengles2.0";
+
+ if (!RegisterClass (&wndclass) )
+ return FALSE;
+
+ wStyle = WS_VISIBLE | WS_POPUP | WS_BORDER | WS_SYSMENU | WS_CAPTION;
+
+ // Adjust the window rectangle so that the client area has
+ // the correct number of pixels
+ windowRect.left = 0;
+ windowRect.top = 0;
+ windowRect.right = esContext->width;
+ windowRect.bottom = esContext->height;
+
+ AdjustWindowRect ( &windowRect, wStyle, FALSE );
+
+
+
+ esContext->hWnd = CreateWindow(
+ "opengles2.0",
+ title,
+ wStyle,
+ 0,
+ 0,
+ windowRect.right - windowRect.left,
+ windowRect.bottom - windowRect.top,
+ NULL,
+ NULL,
+ hInstance,
+ NULL);
+
+ // Set the ESContext* to the GWL_USERDATA so that it is available to the
+ // ESWindowProc
+ SetWindowLongPtr ( esContext->hWnd, GWL_USERDATA, (LONG) (LONG_PTR) esContext );
+
+
+ if ( esContext->hWnd == NULL )
+ return GL_FALSE;
+
+ ShowWindow ( esContext->hWnd, TRUE );
+
+ return GL_TRUE;
+}
+
+///
+// winLoop()
+//
+// Start main windows loop
+//
+void WinLoop ( ESContext *esContext )
+{
+ MSG msg = { 0 };
+ int done = 0;
+ DWORD lastTime = GetTickCount();
+
+ while (!done)
+ {
+ int gotMsg = (PeekMessage(&msg, NULL, 0, 0, PM_REMOVE) != 0);
+ DWORD curTime = GetTickCount();
+ float deltaTime = (float)( curTime - lastTime ) / 1000.0f;
+ lastTime = curTime;
+
+ if ( gotMsg )
+ {
+ if (msg.message==WM_QUIT)
+ {
+ done=1;
+ }
+ else
+ {
+ TranslateMessage(&msg);
+ DispatchMessage(&msg);
+ }
+ }
+ else
+ SendMessage( esContext->hWnd, WM_PAINT, 0, 0 );
+
+ // Call update function if registered
+ if ( esContext->updateFunc != NULL )
+ esContext->updateFunc ( esContext, deltaTime );
+ }
+}
diff --git a/third_party/gles_book_examples/Common/Source/esShader.c b/third_party/gles_book_examples/Common/Source/esShader.c
index 47bf6af..4ea2cbc 100644
--- a/third_party/gles_book_examples/Common/Source/esShader.c
+++ b/third_party/gles_book_examples/Common/Source/esShader.c
@@ -40,7 +40,7 @@
/// \param shaderSrc Shader source string
/// \return A new shader object on success, 0 on failure
//
-GLuint esLoadShader ( GLenum type, const char *shaderSrc )
+GLuint ESUTIL_API esLoadShader ( GLenum type, const char *shaderSrc )
{
GLuint shader;
GLint compiled;
@@ -93,7 +93,7 @@ GLuint esLoadShader ( GLenum type, const char *shaderSrc )
/// \param fragShaderSrc Fragment shader source code
/// \return A new program object linked with the vertex/fragment shader pair, 0 on failure
//
-GLuint esLoadProgram ( const char *vertShaderSrc, const char *fragShaderSrc )
+GLuint ESUTIL_API esLoadProgram ( const char *vertShaderSrc, const char *fragShaderSrc )
{
GLuint vertexShader;
GLuint fragmentShader;
diff --git a/third_party/gles_book_examples/Common/Source/esShapes.c b/third_party/gles_book_examples/Common/Source/esShapes.c
index 16e4ef0..b0f061d 100644
--- a/third_party/gles_book_examples/Common/Source/esShapes.c
+++ b/third_party/gles_book_examples/Common/Source/esShapes.c
@@ -19,7 +19,6 @@
#include "esUtil.h"
#include <stdlib.h>
#include <math.h>
-#include <string.h>
///
// Defines
@@ -51,8 +50,8 @@
/// \return The number of indices required for rendering the buffers (the number of indices stored in the indices array
/// if it is not NULL ) as a GL_TRIANGLE_STRIP
//
-int esGenSphere ( int numSlices, float radius, GLfloat **vertices, GLfloat **normals,
- GLfloat **texCoords, GLuint **indices )
+int ESUTIL_API esGenSphere ( int numSlices, float radius, GLfloat **vertices, GLfloat **normals,
+ GLfloat **texCoords, GLuint **indices )
{
int i;
int j;
@@ -138,8 +137,8 @@ int esGenSphere ( int numSlices, float radius, GLfloat **vertices, GLfloat **nor
/// \return The number of indices required for rendering the buffers (the number of indices stored in the indices array
/// if it is not NULL ) as a GL_TRIANGLE_STRIP
//
-int esGenCube ( float scale, GLfloat **vertices, GLfloat **normals,
- GLfloat **texCoords, GLuint **indices )
+int ESUTIL_API esGenCube ( float scale, GLfloat **vertices, GLfloat **normals,
+ GLfloat **texCoords, GLuint **indices )
{
int i;
int numVertices = 24;
diff --git a/third_party/gles_book_examples/Common/Source/esTransform.c b/third_party/gles_book_examples/Common/Source/esTransform.c
index c714327..12182fd 100644
--- a/third_party/gles_book_examples/Common/Source/esTransform.c
+++ b/third_party/gles_book_examples/Common/Source/esTransform.c
@@ -20,11 +20,11 @@
//
#include "esUtil.h"
#include <math.h>
-#include <string.h>
#define PI 3.1415926535897932384626433832795f
-void esScale(ESMatrix *result, GLfloat sx, GLfloat sy, GLfloat sz)
+void ESUTIL_API
+esScale(ESMatrix *result, GLfloat sx, GLfloat sy, GLfloat sz)
{
result->m[0][0] *= sx;
result->m[0][1] *= sx;
@@ -42,7 +42,8 @@ void esScale(ESMatrix *result, GLfloat sx, GLfloat sy, GLfloat sz)
result->m[2][3] *= sz;
}
-void esTranslate(ESMatrix *result, GLfloat tx, GLfloat ty, GLfloat tz)
+void ESUTIL_API
+esTranslate(ESMatrix *result, GLfloat tx, GLfloat ty, GLfloat tz)
{
result->m[3][0] += (result->m[0][0] * tx + result->m[1][0] * ty + result->m[2][0] * tz);
result->m[3][1] += (result->m[0][1] * tx + result->m[1][1] * ty + result->m[2][1] * tz);
@@ -50,7 +51,8 @@ void esTranslate(ESMatrix *result, GLfloat tx, GLfloat ty, GLfloat tz)
result->m[3][3] += (result->m[0][3] * tx + result->m[1][3] * ty + result->m[2][3] * tz);
}
-void esRotate(ESMatrix *result, GLfloat angle, GLfloat x, GLfloat y, GLfloat z)
+void ESUTIL_API
+esRotate(ESMatrix *result, GLfloat angle, GLfloat x, GLfloat y, GLfloat z)
{
GLfloat sinAngle, cosAngle;
GLfloat mag = sqrtf(x * x + y * y + z * z);
@@ -102,7 +104,8 @@ void esRotate(ESMatrix *result, GLfloat angle, GLfloat x, GLfloat y, GLfloat z)
}
}
-void esFrustum(ESMatrix *result, float left, float right, float bottom, float top, float nearZ, float farZ)
+void ESUTIL_API
+esFrustum(ESMatrix *result, float left, float right, float bottom, float top, float nearZ, float farZ)
{
float deltaX = right - left;
float deltaY = top - bottom;
@@ -131,7 +134,8 @@ void esFrustum(ESMatrix *result, float left, float right, float bottom, float to
}
-void esPerspective(ESMatrix *result, float fovy, float aspect, float nearZ, float farZ)
+void ESUTIL_API
+esPerspective(ESMatrix *result, float fovy, float aspect, float nearZ, float farZ)
{
GLfloat frustumW, frustumH;
@@ -141,7 +145,8 @@ void esPerspective(ESMatrix *result, float fovy, float aspect, float nearZ, floa
esFrustum( result, -frustumW, frustumW, -frustumH, frustumH, nearZ, farZ );
}
-void esOrtho(ESMatrix *result, float left, float right, float bottom, float top, float nearZ, float farZ)
+void ESUTIL_API
+esOrtho(ESMatrix *result, float left, float right, float bottom, float top, float nearZ, float farZ)
{
float deltaX = right - left;
float deltaY = top - bottom;
@@ -163,7 +168,8 @@ void esOrtho(ESMatrix *result, float left, float right, float bottom, float top,
}
-void esMatrixMultiply(ESMatrix *result, ESMatrix *srcA, ESMatrix *srcB)
+void ESUTIL_API
+esMatrixMultiply(ESMatrix *result, ESMatrix *srcA, ESMatrix *srcB)
{
ESMatrix tmp;
int i;
@@ -194,7 +200,8 @@ void esMatrixMultiply(ESMatrix *result, ESMatrix *srcA, ESMatrix *srcB)
}
-void esMatrixLoadIdentity(ESMatrix *result)
+void ESUTIL_API
+esMatrixLoadIdentity(ESMatrix *result)
{
memset(result, 0x0, sizeof(ESMatrix));
result->m[0][0] = 1.0f;
@@ -202,3 +209,4 @@ void esMatrixLoadIdentity(ESMatrix *result)
result->m[2][2] = 1.0f;
result->m[3][3] = 1.0f;
}
+
diff --git a/third_party/gles_book_examples/Common/Source/esUtil.c b/third_party/gles_book_examples/Common/Source/esUtil.c
index e0692eb..fe774ae 100644
--- a/third_party/gles_book_examples/Common/Source/esUtil.c
+++ b/third_party/gles_book_examples/Common/Source/esUtil.c
@@ -20,21 +20,96 @@
//
#include <stdio.h>
#include <stdlib.h>
-#include <stdarg.h>
-#include <string.h>
-
#include <GLES2/gl2.h>
-
+#include <EGL/egl.h>
#include "esUtil.h"
#include "esUtil_win.h"
+
+
+
+///
+// CreateEGLContext()
+//
+// Creates an EGL rendering context and all associated elements
+//
+EGLBoolean CreateEGLContext ( EGLNativeWindowType hWnd, EGLDisplay* eglDisplay,
+ EGLContext* eglContext, EGLSurface* eglSurface,
+ EGLint attribList[])
+{
+ EGLint numConfigs;
+ EGLint majorVersion;
+ EGLint minorVersion;
+ EGLDisplay display;
+ EGLContext context;
+ EGLSurface surface;
+ EGLConfig config;
+ EGLint contextAttribs[] = { EGL_CONTEXT_CLIENT_VERSION, 2, EGL_NONE, EGL_NONE };
+
+ // Get Display
+ display = eglGetDisplay(GetDC(hWnd));
+ if ( display == EGL_NO_DISPLAY )
+ {
+ return EGL_FALSE;
+ }
+
+ // Initialize EGL
+ if ( !eglInitialize(display, &majorVersion, &minorVersion) )
+ {
+ return EGL_FALSE;
+ }
+
+ // Get configs
+ if ( !eglGetConfigs(display, NULL, 0, &numConfigs) )
+ {
+ return EGL_FALSE;
+ }
+
+ // Choose config
+ if ( !eglChooseConfig(display, attribList, &config, 1, &numConfigs) )
+ {
+ return EGL_FALSE;
+ }
+
+ // Create a surface
+ surface = eglCreateWindowSurface(display, config, (EGLNativeWindowType)hWnd, NULL);
+ if ( surface == EGL_NO_SURFACE )
+ {
+ return EGL_FALSE;
+ }
+
+ // Create a GL context
+ context = eglCreateContext(display, config, EGL_NO_CONTEXT, contextAttribs );
+ if ( context == EGL_NO_CONTEXT )
+ {
+ return EGL_FALSE;
+ }
+
+ // Make the context current
+ if ( !eglMakeCurrent(display, surface, surface, context) )
+ {
+ return EGL_FALSE;
+ }
+
+ *eglDisplay = display;
+ *eglSurface = surface;
+ *eglContext = context;
+ return EGL_TRUE;
+}
+
+//////////////////////////////////////////////////////////////////
+//
+// Public Functions
+//
+//
+
///
// esInitContext()
//
// Initialize ES utility context. This must be called before calling any other
// functions.
//
-void esInitContext ( ESContext *esContext )
+void ESUTIL_API esInitContext ( ESContext *esContext )
{
if ( esContext != NULL )
{
@@ -43,11 +118,103 @@ void esInitContext ( ESContext *esContext )
}
///
+// esCreateWindow()
+//
+// title - name for title bar of window
+// width - width of window to create
+// height - height of window to create
+// flags - bitwise or of window creation flags
+// ES_WINDOW_ALPHA - specifies that the framebuffer should have alpha
+// ES_WINDOW_DEPTH - specifies that a depth buffer should be created
+// ES_WINDOW_STENCIL - specifies that a stencil buffer should be created
+// ES_WINDOW_MULTISAMPLE - specifies that a multi-sample buffer should be created
+//
+GLboolean ESUTIL_API esCreateWindow ( ESContext *esContext, const char* title, GLint width, GLint height, GLuint flags )
+{
+ EGLint attribList[] =
+ {
+ EGL_RED_SIZE, 5,
+ EGL_GREEN_SIZE, 6,
+ EGL_BLUE_SIZE, 5,
+ EGL_ALPHA_SIZE, (flags & ES_WINDOW_ALPHA) ? 8 : EGL_DONT_CARE,
+ EGL_DEPTH_SIZE, (flags & ES_WINDOW_DEPTH) ? 8 : EGL_DONT_CARE,
+ EGL_STENCIL_SIZE, (flags & ES_WINDOW_STENCIL) ? 8 : EGL_DONT_CARE,
+ EGL_SAMPLE_BUFFERS, (flags & ES_WINDOW_MULTISAMPLE) ? 1 : 0,
+ EGL_NONE
+ };
+
+ if ( esContext == NULL )
+ {
+ return GL_FALSE;
+ }
+
+ esContext->width = width;
+ esContext->height = height;
+
+ if ( !WinCreate ( esContext, title) )
+ {
+ return GL_FALSE;
+ }
+
+
+ if ( !CreateEGLContext ( esContext->hWnd,
+ &esContext->eglDisplay,
+ &esContext->eglContext,
+ &esContext->eglSurface,
+ attribList) )
+ {
+ return GL_FALSE;
+ }
+
+
+ return GL_TRUE;
+}
+
+///
+// esMainLoop()
+//
+// Start the main loop for the OpenGL ES application
+//
+void ESUTIL_API esMainLoop ( ESContext *esContext )
+{
+ WinLoop ( esContext );
+}
+
+
+///
+// esRegisterDrawFunc()
+//
+void ESUTIL_API esRegisterDrawFunc ( ESContext *esContext, void (ESCALLBACK *drawFunc) (ESContext* ) )
+{
+ esContext->drawFunc = drawFunc;
+}
+
+
+///
+// esRegisterUpdateFunc()
+//
+void ESUTIL_API esRegisterUpdateFunc ( ESContext *esContext, void (ESCALLBACK *updateFunc) ( ESContext*, float ) )
+{
+ esContext->updateFunc = updateFunc;
+}
+
+
+///
+// esRegisterKeyFunc()
+//
+void ESUTIL_API esRegisterKeyFunc ( ESContext *esContext,
+ void (ESCALLBACK *keyFunc) (ESContext*, unsigned char, int, int ) )
+{
+ esContext->keyFunc = keyFunc;
+}
+
+
+///
// esLogMessage()
//
// Log an error message to the debug output for the platform
//
-void esLogMessage ( const char *formatStr, ... )
+void ESUTIL_API esLogMessage ( const char *formatStr, ... )
{
va_list params;
char buf[BUFSIZ];
@@ -60,12 +227,13 @@ void esLogMessage ( const char *formatStr, ... )
va_end ( params );
}
+
///
// esLoadTGA()
//
// Loads a 24-bit TGA image from a file
//
-char* esLoadTGA ( char *fileName, int *width, int *height )
+char* ESUTIL_API esLoadTGA ( char *fileName, int *width, int *height )
{
char *buffer;
@@ -75,4 +243,4 @@ char* esLoadTGA ( char *fileName, int *width, int *height )
}
return NULL;
-}
+} \ No newline at end of file
diff --git a/third_party/gles_book_examples/gles_book_examples.gyp b/third_party/gles_book_examples/gles_book_examples.gyp
deleted file mode 100644
index eeaa68d..0000000
--- a/third_party/gles_book_examples/gles_book_examples.gyp
+++ /dev/null
@@ -1,49 +0,0 @@
-# Copyright (c) 2009 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.
-
-{
- 'targets': [
- {
- 'target_name': 'es_util',
- 'type': 'static_library',
- 'dependencies': [
- '../../gpu/gpu.gyp:gles2_c_lib',
- ],
- 'include_dirs': [
- 'Common/Include',
- ],
- 'all_dependent_settings': {
- 'include_dirs': [
- 'Common/Include',
- ],
- },
- 'sources': [
- 'Common/Include/esUtil.h',
- 'Common/Include/esUtil_win.h',
- 'Common/Source/esShader.c',
- 'Common/Source/esShapes.c',
- 'Common/Source/esTransform.c',
- 'Common/Source/esUtil.c',
- 'Common/Source/Win32/esUtil_TGA.c',
- ],
- },
- {
- 'target_name': 'hello_triangle',
- 'type': 'static_library',
- 'dependencies': [
- 'es_util',
- ],
- 'sources': [
- 'Chapter_2/Hello_Triangle/Hello_Triangle.c',
- 'Chapter_2/Hello_Triangle/Hello_Triangle.h',
- ],
- },
- ]
-}
-
-# Local Variables:
-# tab-width:2
-# indent-tabs-mode:nil
-# End:
-# vim: set expandtab tabstop=2 shiftwidth=2: