Permalink
Browse files

organization

  • Loading branch information...
tmpvar committed Aug 20, 2011
1 parent 65aa97e commit 305653d400ccff7ea2f2ad227584a93ca09bc7e0
Showing with 950 additions and 85 deletions.
  1. +1 −1 bin/SConstruct
  2. +1 −1 example/SConstruct
  3. +35 −6 example/js/main.cc
  4. +30 −74 example/triangle.cc
  5. +1 −1 src/SConstruct
  6. +1 −0 src/arch/wrapper.h
  7. +676 −0 src/js/spidermonkey.cc
  8. +203 −0 src/js/spidermonkey.h
  9. +2 −2 test/runner.js
View
@@ -9,7 +9,7 @@ spidermonkey_src = path.abspath(path.join(current_dir, '..', 'deps', 'spidermonk
spidermonkey = File(path.join(spidermonkey_src, 'libjs_static.a'))
spidermonkey_includes = spidermonkey_src
-FRAMEWORKS = ['OpenGL', 'Cocoa']
+FRAMEWORKS = ['OpenGL', 'GLUT']
Program('triangle', 'triangle.cc',
LIBS = [webgl],
View
@@ -9,7 +9,7 @@ spidermonkey_src = path.abspath(path.join(current_dir, '..', 'deps', 'spidermonk
spidermonkey = File(path.join(spidermonkey_src, 'libjs_static.a'))
spidermonkey_includes = spidermonkey_src
-FRAMEWORKS = ['OpenGL', 'Cocoa']
+FRAMEWORKS = ['OpenGL', 'GLUT']
Program('triangle', 'triangle.cc',
LIBS = [webgl],
View
@@ -6,18 +6,17 @@
#endif
/* Include the JSAPI header file to get access to SpiderMonkey. */
-#include "jsapi.h"
-#include "../deps/spidermonkey/js/src/jstypedarray.h"
+#include <../src/js/spidermonkey.h>
#include "WebGL.h"
#include "module.h"
#include <stdlib.h>
/* The class of the global object. */
static JSClass global_class = {
- "global", JSCLASS_GLOBAL_FLAGS,
- JS_PropertyStub, JS_PropertyStub, JS_PropertyStub, JS_StrictPropertyStub,
- JS_EnumerateStub, JS_ResolveStub, JS_ConvertStub, JS_FinalizeStub,
- JSCLASS_NO_OPTIONAL_MEMBERS
+ "global", JSCLASS_GLOBAL_FLAGS,
+ JS_PropertyStub, JS_PropertyStub, JS_PropertyStub, JS_StrictPropertyStub,
+ JS_EnumerateStub, JS_ResolveStub, JS_ConvertStub, JS_FinalizeStub,
+ JSCLASS_NO_OPTIONAL_MEMBERS
};
@@ -124,6 +123,27 @@ void setupGlobals(JSContext *cx, JSObject *global) {
+
+JSBool printer_construct(JSContext *cx, uintN argc, jsval *argv)
+{
+ cout << "constructed!" << endl;
+ return JS_TRUE;
+}
+
+void printer_finalize(JSContext *cx, JSObject *obj)
+{
+}
+
+static JSClass printer_class = {
+ "Printer",
+ JSCLASS_HAS_PRIVATE | JSCLASS_CONSTRUCT_PROTOTYPE,
+ JS_PropertyStub, JS_PropertyStub, JS_PropertyStub, JS_StrictPropertyStub,
+ JS_EnumerateStub, JS_ResolveStub, JS_ConvertStub, printer_finalize,
+ JSCLASS_NO_OPTIONAL_MEMBERS
+};
+
+
+
int main(int argc, const char *argv[])
{
if (argc < 2) {
@@ -144,17 +164,26 @@ int main(int argc, const char *argv[])
if (cx == NULL)
c_exit(EXIT_FAILURE);
+
+
+
+
JS_SetOptions(cx, JSOPTION_VAROBJFIX | JSOPTION_JIT | JSOPTION_METHODJIT);
JS_SetVersion(cx, JSVERSION_LATEST);
JS_SetErrorReporter(cx, reportError);
global = JS_NewCompartmentAndGlobalObject(cx, &global_class, NULL);
+
if (global == NULL)
c_exit(EXIT_FAILURE);
if (!JS_InitStandardClasses(cx, global))
c_exit(EXIT_FAILURE);
+
+ // SET UP CUSTOM CLASS
+ JS_InitClass(cx, global, NULL, &printer_class, printer_construct, 0, NULL, NULL, NULL, NULL);
+
jsval rval;
JSString *str;
JSBool ok;
View
@@ -9,6 +9,10 @@
#include "../src/util.h"
using namespace std;
+WebGLRenderingContext *gl = NULL;
+WebGLBuffer *buffer = NULL;
+GLint attr;
+
void addShader(WebGLRenderingContext *gl, WebGLProgram *program, GLenum type, DOMString *source) {
WebGLShader *shader = gl->createShader(type);
@@ -19,54 +23,8 @@ void addShader(WebGLRenderingContext *gl, WebGLProgram *program, GLenum type, DO
gl->attachShader(program, shader);
}
-CGDirectDisplayID getDisplay(unsigned int index) {
- CGDisplayErr dErr;
- CGDisplayCount displayCount;
- CGDisplayCount maxDisplays = 8;
- CGDirectDisplayID onlineDisplays[8];
-
- dErr = CGGetOnlineDisplayList(maxDisplays, onlineDisplays, &displayCount);
-
- if (dErr != kCGErrorSuccess) {
- displayCount = 0;
- }
-
- if ((index < 0) || (index > (displayCount - 1))) {
- return 0;
- }
-
- return onlineDisplays[index];
-}
-
-
-int main() {
- CGDirectDisplayID targetDisplay = getDisplay(0);
- CGOpenGLDisplayMask displayMask;
- CGLPixelFormatObj pixelFormatObj;
- GLint numPixelFormats;
-
- displayMask = CGDisplayIDToOpenGLDisplayMask(targetDisplay);
-
- CGLPixelFormatAttribute attribs[] = {
- kCGLPFAAccelerated,
- kCGLPFANoRecovery,
- kCGLPFADoubleBuffer,
- kCGLPFAFullScreen,
- kCGLPFAStencilSize, ( CGLPixelFormatAttribute ) 8,
- kCGLPFADisplayMask,
- (CGLPixelFormatAttribute)CGDisplayIDToOpenGLDisplayMask( kCGDirectMainDisplay ),
- (CGLPixelFormatAttribute)NULL
- };
-
- CGLContextObj context = NULL;
-
- CGLChoosePixelFormat(attribs, &pixelFormatObj, &numPixelFormats);
- CGLCreateContext(pixelFormatObj, NULL, &context);
- CGLDestroyPixelFormat(pixelFormatObj);
- CGLSetCurrentContext(context);
- CGLRetainContext(context);
- CGLSetFullScreenOnDisplay(context, displayMask);
+void setup() {
WebGLRenderingContext *gl = new WebGLRenderingContext();
WebGLProgram *program = gl->createProgram();
@@ -95,13 +53,7 @@ int main() {
-1.0, -1.0, 0.0,
1.0, -1.0, 0.0,
};
-
-
-
- // 5 frames for now
- int a = 100;
- int interval = 1;
- WebGLBuffer *buffer = gl->createBuffer();
+ buffer = gl->createBuffer();
const float vertexPositions[] = {
0.75f, 0.75f, 0.0f, 1.0f,
@@ -118,25 +70,29 @@ int main() {
glViewport(0, 0, 1920, 1200);
gl->useProgram(program);
- GLint attr = glGetAttribLocation(program->id, pos->value.c_str());
-
- while(a--) {
- gl->clearColor(0.5, 0.5, 0.5, 1);
- gl->clear(WebGLRenderingContext::COLOR_BUFFER_BIT | WebGLRenderingContext::DEPTH_BUFFER_BIT);
- gl->bindBuffer(WebGLRenderingContext::ARRAY_BUFFER, buffer);
- gl->enableVertexAttribArray(attr);
- gl->vertexAttribPointer(attr, sizeof(GLfloat), GL_FLOAT, GL_FALSE, 0, 0);
- gl->drawArrays(GL_TRIANGLES, 0, 3);
-
- // TODO: implement these
- //glDisableVertexAttribArray(0);
- //glUseProgram(0);
-
- CGLSetParameter( context, kCGLCPSwapInterval, &interval );
- CGLFlushDrawable( context );
- }
-
- CGLReleaseContext(context);
- cout << "Done!" << endl;
+ attr = glGetAttribLocation(program->id, pos->value.c_str());
+}
+
+void render(void) {
+ gl->clearColor(0.5, 0.5, 0.5, 1);
+ gl->clear(WebGLRenderingContext::COLOR_BUFFER_BIT | WebGLRenderingContext::DEPTH_BUFFER_BIT);
+ gl->bindBuffer(WebGLRenderingContext::ARRAY_BUFFER, buffer);
+ gl->enableVertexAttribArray(attr);
+ gl->vertexAttribPointer(attr, sizeof(GLfloat), GL_FLOAT, GL_FALSE, 0, 0);
+ gl->drawArrays(GL_TRIANGLES, 0, 3);
+ // TODO: implement these
+ //glDisableVertexAttribArray(0);
+ //glUseProgram(0);
+ glFlush();
+}
+
+int main(int argc, char **argv) {
+ glutInit(&argc, argv);
+ glutInitDisplayMode (GLUT_SINGLE);
+ glutInitWindowSize (500, 500); // Set the width and height of the window
+ glutInitWindowPosition (100, 100);
+ glutCreateWindow ("You’re first OpenGL Window");
+ glutDisplayFunc(render);
+ glutMainLoop();
return 0;
}
View
@@ -6,7 +6,7 @@ CFLAGS = '-Wall -g'
env = Environment(
CFLAGS=CFLAGS,
- FRAMEWORKS=['OpenGL', 'Cocoa']
+ FRAMEWORKS=['OpenGL', 'GLUT']
)
sources = Glob('*.cc')
View
@@ -5,6 +5,7 @@
using namespace std;
#ifdef __APPLE__
+ #include <GLUT/glut.h>
#include <OpenGL/OpenGL.h>
#include <OpenGL/gl.h>
#include <OpenGL/glu.h>
Oops, something went wrong.

0 comments on commit 305653d

Please sign in to comment.