Skip to content

Commit

Permalink
Allow building only some of the bindings (for example on GLES-only pl…
Browse files Browse the repository at this point in the history
…atforms).
  • Loading branch information
cscott committed Nov 16, 2011
1 parent 1e83b94 commit 263af37
Show file tree
Hide file tree
Showing 3 changed files with 54 additions and 1 deletion.
27 changes: 26 additions & 1 deletion Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,32 @@ CC = g++
CFLAGS := $(CFLAGS) -m32 -Wall -Iv8/include
PROG = v8-gl

SRCS = main.cpp imageloader.cpp utils.cpp v8-gl.cpp glbindings/glbind.cpp glesbindings/glesbind.cpp glubindings/glubind.cpp glutbindings/glutbind.cpp
BUILD_GL_BINDINGS=1
BUILD_GLES_BINDINGS=1
BUILD_GLU_BINDINGS=1
BUILD_GLUT_BINDINGS=1

SRCS = main.cpp imageloader.cpp utils.cpp v8-gl.cpp

ifdef BUILD_GL_BINDINGS
SRCS += glbindings/glbind.cpp
CFLAGS += -DBUILD_GL_BINDINGS
endif

ifdef BUILD_GLES_BINDINGS
SRCS += glesbindings/glesbind.cpp
CFLAGS += -DBUILD_GLES_BINDINGS
endif

ifdef BUILD_GLU_BINDINGS
SRCS += glubindings/glubind.cpp
CFLAGS += -DBUILD_GLU_BINDINGS
endif

ifdef BUILD_GLUT_BINDINGS
SRCS += glutbindings/glutbind.cpp
CFLAGS += -DBUILD_GLUT_BINDINGS
endif

all: $(PROG)

Expand Down
20 changes: 20 additions & 0 deletions v8-gl.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -126,31 +126,51 @@ bool V8GL::initialize(int* pargc, char** argv, string scriptname) {

// Each processor gets its own context so different processors
// don't affect each other.
#ifdef BUILD_GL_BINDINGS
Handle<ObjectTemplate> Gl = GlFactory::createGl();
#endif
#ifdef BUILD_GLES_BINDINGS
Handle<ObjectTemplate> Gles = GlesFactory::createGles();
#endif

//Set global objects and functions.
#ifdef BUILD_GL_BINDINGS
global->Set(String::New("Gl"), Gl);
#endif
#ifdef BUILD_GLES_BINDINGS
global->Set(String::New("Gles"), Gles);
#endif
#ifdef BUILD_GLU_BINDINGS
global->Set(String::New("Glu"), createGlu());
#endif
#ifdef BUILD_GLUT_BINDINGS
global->Set(String::New("Glut"), GlutFactory::createGlut(pargc, argv));
#endif
global->Set(String::New("log"), FunctionTemplate::New(log));
global->Set(String::New("load"), FunctionTemplate::New(load));

Handle<Context> context = Context::New(NULL, global);

//TODO(nico): should find another way to set the right context when calling a func.
V8GL::context = Persistent<Context>::New(context);
#ifdef BUILD_GLUT_BINDINGS
GlutFactory::glut_persistent_context = V8GL::context;
#endif
#ifdef BUILD_GLES_BINDINGS
GlesFactory::gles_persistent_context = V8GL::context;
#endif

// Enter the new context so all the following operations take place
// within it.
Context::Scope context_scope(context);

//Append *this* as Gl static variable so we can do dot-this-dot-that stuff
#ifdef BUILD_GL_BINDINGS
GlFactory::self_ = Persistent<Object>::New(Gl->NewInstance());
#endif
#ifdef BUILD_GLES_BINDINGS
GlesFactory::self_ = Persistent<Object>::New(Gles->NewInstance());
#endif

//Set (only once) the absolute path for the .js file being executed.
V8GLUtils::setRootPath(argv[0], argv[1]);
Expand Down
8 changes: 8 additions & 0 deletions v8-gl.h
Original file line number Diff line number Diff line change
Expand Up @@ -9,10 +9,18 @@
#include <v8-debug.h>

#include "utils.h"
#ifdef BUILD_GL_BINDINGS
#include "glbindings/glbind.h"
#endif
#ifdef BUILD_GLES_BINDINGS
#include "glesbindings/glesbind.h"
#endif
#ifdef BUILD_GLU_BINDINGS
#include "glubindings/glubind.h"
#endif
#ifdef BUILD_GLUT_BINDINGS
#include "glutbindings/glutbind.h"
#endif

using namespace std;
using namespace v8;
Expand Down

0 comments on commit 263af37

Please sign in to comment.