Skip to content

Commit

Permalink
Support building with glew.
Browse files Browse the repository at this point in the history
  • Loading branch information
deanm committed Jul 20, 2009
1 parent d36e49e commit b84edd2
Show file tree
Hide file tree
Showing 8 changed files with 135 additions and 50 deletions.
25 changes: 18 additions & 7 deletions glbindings/glbind.cpp
Original file line number Original file line Diff line number Diff line change
@@ -1,7 +1,18 @@

#include "glbind.h" #include "glbind.h"


Persistent<Object> GlFactory::self_; #if defined(V8_GL_USE_GLEW)
#include "GL/glew.h"
#elif defined(__APPLE__)
#include <OpenGL/OpenGL.h>
#else
#define GL_GLEXT_PROTOTYPES
#include <GL/gl.h>
#endif

using namespace v8;


Persistent<Object> GlFactory::self_;




Handle<Value> GLglAccumCallback(const Arguments& args) { Handle<Value> GLglAccumCallback(const Arguments& args) {
Expand Down Expand Up @@ -8988,16 +8999,16 @@ Handle<Value> GLglPointParameterfvCallback(const Arguments& args) {




Handle<Array> arrHandle1 = Handle<Array>::Cast(args[1]); Handle<Array> arrHandle1 = Handle<Array>::Cast(args[1]);
GLfloat* arg1 = new GLfloat[arrHandle1->Length()]; GLfloat* arg1 = new GLfloat[arrHandle1->Length()];
for (unsigned j = 0; j < arrHandle1->Length(); j++) { for (unsigned j = 0; j < arrHandle1->Length(); j++) {
Handle<Value> arg(arrHandle1->Get(Integer::New(j))); Handle<Value> arg(arrHandle1->Get(Integer::New(j)));
GLfloat aux = ( GLfloat)arg->NumberValue(); GLfloat aux = (GLfloat)arg->NumberValue();
arg1[j] = aux; arg1[j] = aux;
} }




//make call //make call
glPointParameterfv((GLenum) arg0, (const GLfloat*) arg1); glPointParameterfv((GLenum) arg0, (GLfloat*) arg1);
Handle<Object> res(GlFactory::self_); Handle<Object> res(GlFactory::self_);
return res; return res;
} }
Expand Down Expand Up @@ -9033,16 +9044,16 @@ Handle<Value> GLglPointParameterivCallback(const Arguments& args) {




Handle<Array> arrHandle1 = Handle<Array>::Cast(args[1]); Handle<Array> arrHandle1 = Handle<Array>::Cast(args[1]);
GLint* arg1 = new GLint[arrHandle1->Length()]; GLint* arg1 = new GLint[arrHandle1->Length()];
for (unsigned j = 0; j < arrHandle1->Length(); j++) { for (unsigned j = 0; j < arrHandle1->Length(); j++) {
Handle<Value> arg(arrHandle1->Get(Integer::New(j))); Handle<Value> arg(arrHandle1->Get(Integer::New(j)));
GLint aux = ( GLint)arg->IntegerValue(); GLint aux = (GLint)arg->IntegerValue();
arg1[j] = aux; arg1[j] = aux;
} }




//make call //make call
glPointParameteriv((GLenum) arg0, (const GLint*) arg1); glPointParameteriv((GLenum) arg0, (GLint*) arg1);
Handle<Object> res(GlFactory::self_); Handle<Object> res(GlFactory::self_);
return res; return res;
} }
Expand Down
18 changes: 4 additions & 14 deletions glbindings/glbind.h
Original file line number Original file line Diff line number Diff line change
Expand Up @@ -8,23 +8,13 @@
#ifndef GLBIND_H_ #ifndef GLBIND_H_
#define GLBIND_H_ #define GLBIND_H_



#include <v8.h>
#include <v8-debug.h>

#ifdef __APPLE__
#include <OpenGL/OpenGL.h>
#else
#define GL_GLEXT_PROTOTYPES
#include <GL/gl.h>
#endif

using namespace std;
using namespace v8;


class GlFactory { class GlFactory {
public: public:
static Handle<ObjectTemplate> createGl(void); static v8::Handle<v8::ObjectTemplate> createGl(void);


static Persistent<Object> self_; static v8::Persistent<v8::Object> self_;
}; };

#endif /* GLBIND_H_ */ #endif /* GLBIND_H_ */
4 changes: 2 additions & 2 deletions glbindings/glbind.json
Original file line number Original file line Diff line number Diff line change
Expand Up @@ -8940,7 +8940,7 @@
"name": "glPointParameterfv", "name": "glPointParameterfv",
"parameters": [ "parameters": [
"GLenum", "GLenum",
"const GLfloat*" "GLfloat*"
] ]
}, },
{ {
Expand All @@ -8958,7 +8958,7 @@
"name": "glPointParameteriv", "name": "glPointParameteriv",
"parameters": [ "parameters": [
"GLenum", "GLenum",
"const GLint*" "GLint*"
] ]
}, },
{ {
Expand Down
18 changes: 16 additions & 2 deletions glbindings/glbind.py
Original file line number Original file line Diff line number Diff line change
Expand Up @@ -38,8 +38,22 @@ def main():
pass pass


with open(OUT_FILE, 'w') as fout: with open(OUT_FILE, 'w') as fout:
fout.write('#include "glbind.h"\n\nPersistent<Object> GlFactory::self_;\n\n' \ fout.write("""
+ '\n'.join(text_out) + '\n' + generate_main_function(constants, functions)) #include "glbind.h"
#if defined(V8_GL_USE_GLEW)
#include "GL/glew.h"
#elif defined(__APPLE__)
#include <OpenGL/OpenGL.h>
#else
#define GL_GLEXT_PROTOTYPES
#include <GL/gl.h>
#endif
using namespace v8;
Persistent<Object> GlFactory::self_;
""" + '\n'.join(text_out) + '\n' + generate_main_function(constants, functions))




def generate_main_function(constants, functions): def generate_main_function(constants, functions):
Expand Down
18 changes: 17 additions & 1 deletion glesbindings/glesbind.cpp
Original file line number Original file line Diff line number Diff line change
@@ -1,8 +1,24 @@

#include "glesbind.h" #include "glesbind.h"


#if defined(V8_GL_USE_GLEW)
#include "GL/glew.h"
#include "glew_desktop_shim.h"
#elif defined(__APPLE__)
#include <OpenGL/OpenGL.h>
#else
#define GL_GLEXT_PROTOTYPES
#include <GL/gl.h>
// If we're running on desktop OpenGL, some ES 2.0 constants don't exist, or
// are under a name with EXT in them, etc.
#include "gles_desktop_shim.h"
#endif

using namespace v8;


Persistent<Object> GlesFactory::self_; Persistent<Object> GlesFactory::self_;
Persistent<Context> GlesFactory::gles_persistent_context; Persistent<Context> GlesFactory::gles_persistent_context;

// glGenBuffers uses an output parameter to return an array of ints. // glGenBuffers uses an output parameter to return an array of ints.
Handle<Value> GLESglGenBuffersCallback(const Arguments& args) { Handle<Value> GLESglGenBuffersCallback(const Arguments& args) {
if (args.Length() != 1) if (args.Length() != 1)
Expand Down
25 changes: 4 additions & 21 deletions glesbindings/glesbind.h
Original file line number Original file line Diff line number Diff line change
Expand Up @@ -6,31 +6,14 @@
#ifndef GLESBIND_H_ #ifndef GLESBIND_H_
#define GLESBIND_H_ #define GLESBIND_H_


#include <v8-debug.h> #include <v8.h>

#ifdef __APPLE__
#include <OpenGL/OpenGL.h>
#else
#define GL_GLEXT_PROTOTYPES
#include <GL/gl.h>
#endif

// If we're running on desktop OpenGL, some ES 2.0 constants don't exist, or
// are under a name with EXT in them, etc.
#ifndef GL_ES_VERSION_2_0
//#include "missing.h"
#include "gles_desktop_shim.h"
#endif

using namespace std;
using namespace v8;


class GlesFactory { class GlesFactory {
public: public:
static Handle<ObjectTemplate> createGles(void); static v8::Handle<v8::ObjectTemplate> createGles(void);


static Persistent<Object> self_; static v8::Persistent<v8::Object> self_;
static Persistent<Context> gles_persistent_context; static v8::Persistent<v8::Context> gles_persistent_context;
}; };


#endif /* GLESBIND_H_ */ #endif /* GLESBIND_H_ */
25 changes: 22 additions & 3 deletions glesbindings/glesbind.py
Original file line number Original file line Diff line number Diff line change
Expand Up @@ -124,9 +124,28 @@ def main():
functions.extend(accessor_extras) functions.extend(accessor_extras)


with open(OUT_FILE, 'w') as fout: with open(OUT_FILE, 'w') as fout:
fout.write('#include "glesbind.h"\n\nPersistent<Object> GlesFactory::self_;\n' \ fout.write("""
+ 'Persistent<Context> GlesFactory::gles_persistent_context;\n\n' \ #include "glesbind.h"
+ custom_code + '\n'.join(text_out) + '\n' + generate_main_function(constants, functions))
#if defined(V8_GL_USE_GLEW)
#include "GL/glew.h"
#include "glew_desktop_shim.h"
#elif defined(__APPLE__)
#include <OpenGL/OpenGL.h>
#else
#define GL_GLEXT_PROTOTYPES
#include <GL/gl.h>
// If we're running on desktop OpenGL, some ES 2.0 constants don't exist, or
// are under a name with EXT in them, etc.
#include "gles_desktop_shim.h"
#endif
using namespace v8;
Persistent<Object> GlesFactory::self_;
Persistent<Context> GlesFactory::gles_persistent_context;
""" + custom_code + '\n'.join(text_out) + '\n' + generate_main_function(constants, functions))




def generate_main_function(constants, functions): def generate_main_function(constants, functions):
Expand Down
52 changes: 52 additions & 0 deletions glesbindings/glew_desktop_shim.h
Original file line number Original file line Diff line number Diff line change
@@ -0,0 +1,52 @@
#define GL_ES_VERSION_2_0 1
#define GL_FIXED 0x140C
#define GL_MAX_VERTEX_UNIFORM_VECTORS 0x8DFB
#define GL_MAX_VARYING_VECTORS 0x8DFC
#define GL_MAX_FRAGMENT_UNIFORM_VECTORS 0x8DFD
#define GL_SHADER_COMPILER 0x8DFA
#define GL_SHADER_BINARY_FORMATS 0x8DF8
#define GL_NUM_SHADER_BINARY_FORMATS 0x8DF9
#define GL_LOW_FLOAT 0x8DF0
#define GL_MEDIUM_FLOAT 0x8DF1
#define GL_HIGH_FLOAT 0x8DF2
#define GL_LOW_INT 0x8DF3
#define GL_MEDIUM_INT 0x8DF4
#define GL_HIGH_INT 0x8DF5
#define GL_FRAMEBUFFER 0x8D40
#define GL_RENDERBUFFER 0x8D41
#define GL_RGB565 0x8D62
#define GL_STENCIL_INDEX8 0x8D48
#define GL_RENDERBUFFER_WIDTH 0x8D42
#define GL_RENDERBUFFER_HEIGHT 0x8D43
#define GL_RENDERBUFFER_INTERNAL_FORMAT 0x8D44
#define GL_RENDERBUFFER_RED_SIZE 0x8D50
#define GL_RENDERBUFFER_GREEN_SIZE 0x8D51
#define GL_RENDERBUFFER_BLUE_SIZE 0x8D52
#define GL_RENDERBUFFER_ALPHA_SIZE 0x8D53
#define GL_RENDERBUFFER_DEPTH_SIZE 0x8D54
#define GL_RENDERBUFFER_STENCIL_SIZE 0x8D55
#define GL_FRAMEBUFFER_ATTACHMENT_OBJECT_TYPE 0x8CD0
#define GL_FRAMEBUFFER_ATTACHMENT_OBJECT_NAME 0x8CD1
#define GL_FRAMEBUFFER_ATTACHMENT_TEXTURE_LEVEL 0x8CD2
#define GL_FRAMEBUFFER_ATTACHMENT_TEXTURE_CUBE_MAP_FACE 0x8CD3
#define GL_COLOR_ATTACHMENT0 0x8CE0
#define GL_DEPTH_ATTACHMENT 0x8D00
#define GL_STENCIL_ATTACHMENT 0x8D20
#define GL_FRAMEBUFFER_COMPLETE 0x8CD5
#define GL_FRAMEBUFFER_INCOMPLETE_ATTACHMENT 0x8CD6
#define GL_FRAMEBUFFER_INCOMPLETE_MISSING_ATTACHMENT 0x8CD7
#define GL_FRAMEBUFFER_INCOMPLETE_DIMENSIONS 0x8CD9
#define GL_FRAMEBUFFER_UNSUPPORTED 0x8CDD
#define GL_FRAMEBUFFER_BINDING 0x8CA6
#define GL_RENDERBUFFER_BINDING 0x8CA7
#define GL_MAX_RENDERBUFFER_SIZE 0x84E8

// Some of the OpenGL 2.0 spec is defined as doubles, so ES 2.0 adds float
// versions. Implement some simple shims here.
#define glClearDepthf(depth) glClearDepth(depth)
#define glDepthRangef(zNear, zFar) glDepthRange((zNear), (zFar))

// These don't exist in desktop OpenGL, just stub them out.
#define glReleaseShaderCompiler ((void) 0)
#define glGetShaderPrecisionFormat(a, b, c, d) ((void) 0)

0 comments on commit b84edd2

Please sign in to comment.