diff options
author | alokp@chromium.org <alokp@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2010-01-06 20:32:57 +0000 |
---|---|---|
committer | alokp@chromium.org <alokp@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2010-01-06 20:32:57 +0000 |
commit | 1dcd5e8c3061bcd016dd99a04b939ba23e60497f (patch) | |
tree | 03feb6727eb8ff36802c3d4b104b5fac42ef410a | |
parent | 2d4d7d554ca674fe43159ff777d6f8f048cec44a (diff) | |
download | chromium_src-1dcd5e8c3061bcd016dd99a04b939ba23e60497f.zip chromium_src-1dcd5e8c3061bcd016dd99a04b939ba23e60497f.tar.gz chromium_src-1dcd5e8c3061bcd016dd99a04b939ba23e60497f.tar.bz2 |
Resubmit 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/525070
git-svn-id: svn://svn.chromium.org/chrome/trunk/src@35647 0039d316-1c4b-4281-b951-d872f2087c98
20 files changed, 639 insertions, 649 deletions
diff --git a/build/all.gyp b/build/all.gyp index a24ab0f..70d3036 100644 --- a/build/all.gyp +++ b/build/all.gyp @@ -96,11 +96,13 @@ '../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. @@ -4,4 +4,7 @@ include_rules = [ # For gfx::PluginWindowHandle "+app/gfx", + + # For demos + "+third_party/gles_book_examples", ] diff --git a/gpu/demos/app_framework/application.cc b/gpu/demos/app_framework/application.cc new file mode 100644 index 0000000..0ae2cb9 --- /dev/null +++ b/gpu/demos/app_framework/application.cc @@ -0,0 +1,161 @@ +// 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 new file mode 100644 index 0000000..9851c49 --- /dev/null +++ b/gpu/demos/app_framework/application.h @@ -0,0 +1,57 @@ +// 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 new file mode 100644 index 0000000..7e7d0e5 --- /dev/null +++ b/gpu/demos/app_framework/gles2_utils.cc @@ -0,0 +1,67 @@ +// 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 new file mode 100644 index 0000000..147671f --- /dev/null +++ b/gpu/demos/app_framework/gles2_utils.h @@ -0,0 +1,27 @@ +// 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 new file mode 100644 index 0000000..602979e --- /dev/null +++ b/gpu/demos/app_framework/platform.h @@ -0,0 +1,23 @@ +// 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 new file mode 100644 index 0000000..26cedea --- /dev/null +++ b/gpu/demos/demos.gyp @@ -0,0 +1,46 @@ +# 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 new file mode 100644 index 0000000..124e491 --- /dev/null +++ b/gpu/demos/hello_triangle/main.cc @@ -0,0 +1,64 @@ +// 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 6b12a59..740ffe3 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 @@ -14,70 +14,18 @@ // 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 );
+#include "Hello_Triangle.h"
- 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;
-
-}
+#include <stdlib.h>
///
// Initialize the shader and program object
//
-int Init ( ESContext *esContext )
+int htInit ( ESContext *esContext )
{
- UserData *userData = esContext->userData;
+ HTUserData *userData = esContext->userData;
+
GLbyte vShaderStr[] =
"attribute vec4 vPosition; \n"
"void main() \n"
@@ -85,62 +33,28 @@ int Init ( ESContext *esContext ) " gl_Position = vPosition; \n"
"} \n";
+ // TODO(alokp): Shaders containing "precision" do not compile.
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;
+ // 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 };
- glAttachShader ( programObject, vertexShader );
- glAttachShader ( programObject, fragmentShader );
+ userData->programObject = esLoadProgram ( vShaderStr, fShaderStr );
+ if ( userData->programObject == 0 ) return FALSE;
// Bind vPosition to attribute 0
- glBindAttribLocation ( programObject, 0, "vPosition" );
-
- // Link the program
- glLinkProgram ( programObject );
+ glBindAttribLocation ( userData->programObject, 0, "vPosition" );
- // 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;
+ 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;
@@ -149,13 +63,10 @@ int Init ( ESContext *esContext ) ///
// Draw a triangle using the shader pair created in Init()
//
-void Draw ( ESContext *esContext )
+void htDraw ( 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 };
-
+ HTUserData *userData = esContext->userData;
+
// Set the viewport
glViewport ( 0, 0, esContext->width, esContext->height );
@@ -166,29 +77,33 @@ void Draw ( ESContext *esContext ) glUseProgram ( userData->programObject );
// Load the vertex data
- glVertexAttribPointer ( 0, 3, GL_FLOAT, GL_FALSE, 0, vVertices );
+ glBindBuffer ( GL_ARRAY_BUFFER, userData->vbo );
glEnableVertexAttribArray ( 0 );
+ glVertexAttribPointer ( 0, 3, GL_FLOAT, GL_FALSE, 0, 0 );
glDrawArrays ( GL_TRIANGLES, 0, 3 );
- eglSwapBuffers ( esContext->eglDisplay, esContext->eglSurface );
+ // Nothing is drawn or application crashes without glFlush.
+ // TODO(alokp): glFlush should not be necessary with SwapBuffers().
+ glFlush();
}
-
-int main ( int argc, char *argv[] )
+///
+// Cleanup
+//
+void htShutDown ( ESContext *esContext )
{
- ESContext esContext;
- UserData userData;
-
- esInitContext ( &esContext );
- esContext.userData = &userData;
-
- esCreateWindow ( &esContext, "Hello Triangle", 320, 240, ES_WINDOW_RGB );
-
- if ( !Init ( &esContext ) )
- return 0;
+ HTUserData *userData = esContext->userData;
- esRegisterDrawFunc ( &esContext, Draw );
-
- esMainLoop ( &esContext );
+ // Delete program object
+ if ( userData->programObject != 0 )
+ {
+ glDeleteProgram ( userData->programObject );
+ userData->programObject = 0;
+ }
+ if ( userData->vbo != 0 )
+ {
+ glDeleteBuffers ( 1, &userData->vbo );
+ userData->vbo = 0;
+ }
}
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 new file mode 100644 index 0000000..930d486 --- /dev/null +++ b/third_party/gles_book_examples/Chapter_2/Hello_Triangle/Hello_Triangle.h @@ -0,0 +1,46 @@ +// +// 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 f1ab1bf..2a0adfc 100644 --- a/third_party/gles_book_examples/Common/Include/esUtil.h +++ b/third_party/gles_book_examples/Common/Include/esUtil.h @@ -21,36 +21,17 @@ // Includes
//
#include <GLES2/gl2.h>
-#include <EGL/egl.h>
#ifdef __cplusplus
-
extern "C" {
-#endif
-
-
-///
-// Macros
-//
-#define ESUTIL_API __cdecl
-#define ESCALLBACK __cdecl
-
+#endif // __cplusplus
-/// 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
-//
+#ifndef FALSE
+#define FALSE 0
+#endif // FALSE
+#ifndef TRUE
+#define TRUE 1
+#endif // TRUE
typedef struct
{
@@ -67,84 +48,20 @@ 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
//
-void ESUTIL_API esInitContext ( ESContext *esContext );
+extern void 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.
//
-void ESUTIL_API esLogMessage ( const char *formatStr, ... );
+extern void esLogMessage ( const char *formatStr, ... );
//
///
@@ -153,7 +70,7 @@ void ESUTIL_API esLogMessage ( const char *formatStr, ... ); /// \param shaderSrc Shader source string
/// \return A new shader object on success, 0 on failure
//
-GLuint ESUTIL_API esLoadShader ( GLenum type, const char *shaderSrc );
+extern GLuint esLoadShader ( GLenum type, const char *shaderSrc );
//
///
@@ -163,7 +80,7 @@ GLuint ESUTIL_API 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 ESUTIL_API esLoadProgram ( const char *vertShaderSrc, const char *fragShaderSrc );
+extern GLuint esLoadProgram ( const char *vertShaderSrc, const char *fragShaderSrc );
//
@@ -177,8 +94,8 @@ GLuint ESUTIL_API esLoadProgram ( const char *vertShaderSrc, const char *fragSha /// \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 ESUTIL_API esGenSphere ( int numSlices, float radius, GLfloat **vertices, GLfloat **normals,
- GLfloat **texCoords, GLuint **indices );
+extern int 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
@@ -191,8 +108,8 @@ int ESUTIL_API esGenSphere ( int numSlices, float radius, GLfloat **vertices, GL /// \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
//
-int ESUTIL_API esGenCube ( float scale, GLfloat **vertices, GLfloat **normals,
- GLfloat **texCoords, GLuint **indices );
+extern int esGenCube ( float scale, GLfloat **vertices, GLfloat **normals,
+ GLfloat **texCoords, GLuint **indices );
//
/// \brief Loads a 24-bit TGA image from a file
@@ -201,7 +118,7 @@ int ESUTIL_API esGenCube ( float scale, GLfloat **vertices, GLfloat **normals, /// \param height Height of loaded image in pixels
/// \return Pointer to loaded image. NULL on failure.
//
-char* ESUTIL_API esLoadTGA ( char *fileName, int *width, int *height );
+extern char* esLoadTGA ( char *fileName, int *width, int *height );
//
@@ -209,14 +126,14 @@ char* ESUTIL_API 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
//
-void ESUTIL_API esScale(ESMatrix *result, GLfloat sx, GLfloat sy, GLfloat sz);
+extern void 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
//
-void ESUTIL_API esTranslate(ESMatrix *result, GLfloat tx, GLfloat ty, GLfloat tz);
+extern void 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
@@ -224,7 +141,7 @@ void ESUTIL_API 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
//
-void ESUTIL_API esRotate(ESMatrix *result, GLfloat angle, GLfloat x, GLfloat y, GLfloat z);
+extern void 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
@@ -233,7 +150,7 @@ void ESUTIL_API esRotate(ESMatrix *result, GLfloat angle, GLfloat x, GLfloat y, /// \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.
//
-void ESUTIL_API esFrustum(ESMatrix *result, float left, float right, float bottom, float top, float nearZ, float farZ);
+extern void 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
@@ -243,7 +160,7 @@ void ESUTIL_API esFrustum(ESMatrix *result, float left, float right, float botto /// \param nearZ Near plane distance
/// \param farZ Far plane distance
//
-void ESUTIL_API esPerspective(ESMatrix *result, float fovy, float aspect, float nearZ, float farZ);
+extern void 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
@@ -252,23 +169,23 @@ void ESUTIL_API esPerspective(ESMatrix *result, float fovy, float aspect, float /// \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
//
-void ESUTIL_API esOrtho(ESMatrix *result, float left, float right, float bottom, float top, float nearZ, float farZ);
+extern void 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
//
-void ESUTIL_API esMatrixMultiply(ESMatrix *result, ESMatrix *srcA, ESMatrix *srcB);
+extern void esMatrixMultiply(ESMatrix *result, ESMatrix *srcA, ESMatrix *srcB);
//
//// \brief return an indentity matrix
//// \param result returns identity matrix
//
-void ESUTIL_API esMatrixLoadIdentity(ESMatrix *result);
+extern void esMatrixLoadIdentity(ESMatrix *result);
#ifdef __cplusplus
}
-#endif
+#endif // __cplusplus
#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 4017118..cf3acdf 100644 --- a/third_party/gles_book_examples/Common/Include/esUtil_win.h +++ b/third_party/gles_book_examples/Common/Include/esUtil_win.h @@ -15,41 +15,9 @@ #ifndef ESUTIL_WIN_H
#define ESUTIL_WIN_H
-///
-// Includes
-//
-
#ifdef __cplusplus
-
extern "C" {
-#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 );
+#endif // __cplusplus
///
// WinTGALoad()
@@ -60,6 +28,6 @@ int WinTGALoad ( const char *fileName, char **buffer, int *width, int *height ); #ifdef __cplusplus
}
-#endif
+#endif // __cplusplus
#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 4617cdd..9936a4f 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,7 +12,10 @@ //
// 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 deleted file mode 100644 index 73dcaad..0000000 --- a/third_party/gles_book_examples/Common/Source/Win32/esUtil_win32.c +++ /dev/null @@ -1,183 +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
-//
-
-// 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 4ea2cbc..47bf6af 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 ESUTIL_API esLoadShader ( GLenum type, const char *shaderSrc )
+GLuint esLoadShader ( GLenum type, const char *shaderSrc )
{
GLuint shader;
GLint compiled;
@@ -93,7 +93,7 @@ GLuint ESUTIL_API 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 ESUTIL_API esLoadProgram ( const char *vertShaderSrc, const char *fragShaderSrc )
+GLuint 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 b0f061d..16e4ef0 100644 --- a/third_party/gles_book_examples/Common/Source/esShapes.c +++ b/third_party/gles_book_examples/Common/Source/esShapes.c @@ -19,6 +19,7 @@ #include "esUtil.h"
#include <stdlib.h>
#include <math.h>
+#include <string.h>
///
// Defines
@@ -50,8 +51,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 ESUTIL_API esGenSphere ( int numSlices, float radius, GLfloat **vertices, GLfloat **normals,
- GLfloat **texCoords, GLuint **indices )
+int esGenSphere ( int numSlices, float radius, GLfloat **vertices, GLfloat **normals,
+ GLfloat **texCoords, GLuint **indices )
{
int i;
int j;
@@ -137,8 +138,8 @@ int ESUTIL_API esGenSphere ( int numSlices, float radius, GLfloat **vertices, GL /// \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 ESUTIL_API esGenCube ( float scale, GLfloat **vertices, GLfloat **normals,
- GLfloat **texCoords, GLuint **indices )
+int 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 12182fd..c714327 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 ESUTIL_API
-esScale(ESMatrix *result, GLfloat sx, GLfloat sy, GLfloat sz)
+void esScale(ESMatrix *result, GLfloat sx, GLfloat sy, GLfloat sz)
{
result->m[0][0] *= sx;
result->m[0][1] *= sx;
@@ -42,8 +42,7 @@ esScale(ESMatrix *result, GLfloat sx, GLfloat sy, GLfloat sz) result->m[2][3] *= sz;
}
-void ESUTIL_API
-esTranslate(ESMatrix *result, GLfloat tx, GLfloat ty, GLfloat tz)
+void 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);
@@ -51,8 +50,7 @@ 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 ESUTIL_API
-esRotate(ESMatrix *result, GLfloat angle, GLfloat x, GLfloat y, GLfloat z)
+void esRotate(ESMatrix *result, GLfloat angle, GLfloat x, GLfloat y, GLfloat z)
{
GLfloat sinAngle, cosAngle;
GLfloat mag = sqrtf(x * x + y * y + z * z);
@@ -104,8 +102,7 @@ esRotate(ESMatrix *result, GLfloat angle, GLfloat x, GLfloat y, GLfloat z) }
}
-void ESUTIL_API
-esFrustum(ESMatrix *result, float left, float right, float bottom, float top, float nearZ, float farZ)
+void esFrustum(ESMatrix *result, float left, float right, float bottom, float top, float nearZ, float farZ)
{
float deltaX = right - left;
float deltaY = top - bottom;
@@ -134,8 +131,7 @@ esFrustum(ESMatrix *result, float left, float right, float bottom, float top, fl }
-void ESUTIL_API
-esPerspective(ESMatrix *result, float fovy, float aspect, float nearZ, float farZ)
+void esPerspective(ESMatrix *result, float fovy, float aspect, float nearZ, float farZ)
{
GLfloat frustumW, frustumH;
@@ -145,8 +141,7 @@ esPerspective(ESMatrix *result, float fovy, float aspect, float nearZ, float far esFrustum( result, -frustumW, frustumW, -frustumH, frustumH, nearZ, farZ );
}
-void ESUTIL_API
-esOrtho(ESMatrix *result, float left, float right, float bottom, float top, float nearZ, float farZ)
+void esOrtho(ESMatrix *result, float left, float right, float bottom, float top, float nearZ, float farZ)
{
float deltaX = right - left;
float deltaY = top - bottom;
@@ -168,8 +163,7 @@ esOrtho(ESMatrix *result, float left, float right, float bottom, float top, floa }
-void ESUTIL_API
-esMatrixMultiply(ESMatrix *result, ESMatrix *srcA, ESMatrix *srcB)
+void esMatrixMultiply(ESMatrix *result, ESMatrix *srcA, ESMatrix *srcB)
{
ESMatrix tmp;
int i;
@@ -200,8 +194,7 @@ esMatrixMultiply(ESMatrix *result, ESMatrix *srcA, ESMatrix *srcB) }
-void ESUTIL_API
-esMatrixLoadIdentity(ESMatrix *result)
+void esMatrixLoadIdentity(ESMatrix *result)
{
memset(result, 0x0, sizeof(ESMatrix));
result->m[0][0] = 1.0f;
@@ -209,4 +202,3 @@ 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 fe774ae..34a1efe 100644 --- a/third_party/gles_book_examples/Common/Source/esUtil.c +++ b/third_party/gles_book_examples/Common/Source/esUtil.c @@ -20,96 +20,21 @@ //
#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 ESUTIL_API esInitContext ( ESContext *esContext )
+void esInitContext ( ESContext *esContext )
{
if ( esContext != NULL )
{
@@ -118,103 +43,11 @@ void ESUTIL_API 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 ESUTIL_API esLogMessage ( const char *formatStr, ... )
+void esLogMessage ( const char *formatStr, ... )
{
va_list params;
char buf[BUFSIZ];
@@ -227,13 +60,12 @@ void ESUTIL_API esLogMessage ( const char *formatStr, ... ) va_end ( params );
}
-
///
// esLoadTGA()
//
// Loads a 24-bit TGA image from a file
//
-char* ESUTIL_API esLoadTGA ( char *fileName, int *width, int *height )
+char* esLoadTGA ( char *fileName, int *width, int *height )
{
char *buffer;
diff --git a/third_party/gles_book_examples/gles_book_examples.gyp b/third_party/gles_book_examples/gles_book_examples.gyp new file mode 100644 index 0000000..eeaa68d --- /dev/null +++ b/third_party/gles_book_examples/gles_book_examples.gyp @@ -0,0 +1,49 @@ +# 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: |