#else
- #if !defined(__ANDROID__) && !defined(__ODROID__)
+ #if !defined(__ANDROID__) && !defined(__ODROID__) && !defined(__EMSCRIPTEN__)
#define property _property
#define new _new
#undef property
#undef class
+#elif defined(__EMSCRIPTEN__)
+
+ #define property _property
+ #define uint _uint
+
+ #include <GL/gl.h>
+
+ //#include <GLES/gl.h>
+ //#include <EGL/egl.h>
+
+ //#include <GLES2/gl.h>
+ //#include <EGL/egl.h>
+
+ //#include <GLES2/gl2.h>
+ #include <GL/glfw.h>
+ #include <emscripten/emscripten.h>
+
+ #undef property
+ #undef uint
+
#else
#include <GL/gl.h>
#define _GLES
#endif
+#if defined(__EMSCRIPTEN__)
+#define EM_MODE
+#endif
+
#undef pointer
import "Display"
#if defined(__unix__) || defined(__APPLE__)
- #if !defined(__ANDROID__) && !defined(__ODROID__)
+ #if !defined(__ANDROID__) && !defined(__ODROID__) && !defined(__EMSCRIPTEN__)
import "XInterface"
#endif
#if defined(__ANDROID__) || defined(__ODROID__)
#define glBindFramebuffer glBindFramebufferOES
#define glBindRenderbuffer glBindRenderbufferOES
- #define GL_FRAMEBUFFER GL_FRAMEBUFFER_OES
- #define GL_RENDERBUFFER GL_RENDERBUFFER_OES
#define glFramebufferTexture2D glFramebufferTexture2DOES
- #define GL_COLOR_ATTACHMENT0 GL_COLOR_ATTACHMENT0_OES
#define glGenFramebuffers glGenFramebuffersOES
#define glGenRenderbuffers glGenRenderbuffersOES
#define glDeleteFramebuffers glDeleteFramebuffersOES
#define glDeleteRenderbuffers glDeleteRenderbuffersOES
- #define GL_POLYGON_STIPPLE 0xFFFF
- #define GL_LINE_STIPPLE 0xFFFF
- #define GL_LINE 0xFFFF
- #define GL_FILL 0xFFFF
- #define GL_ALL_ATTRIB_BITS 0xFFFF
- #define GL_LIGHT_MODEL_LOCAL_VIEWER 0xFFFF
#define GL_INT 0x1404
#define GL_UNSIGNED_INT 0x1405
#define GL_DOUBLE 0x140A
- #define GL_POLYGON 9
- #define GL_QUADS 7
#define APIENTRY
#endif
#define glVertex3fv glesVertex3fv
#define glLightModeli glesLightModeli
-#if defined(__ANDROID__)
- //#define GL_QUADS 0
- #define GL_QUAD_STRIP 0
- //#define GL_DOUBLE 0
- //#define GL_UNSIGNED_INT 0
- //#define GL_FILL 0
- //#define GL_LINE 0
- //#define GL_LINE_STIPPLE 0
- #define GL_BGRA_EXT 0
- #define GL_UNPACK_ROW_LENGTH 0
- #define GL_UNPACK_SKIP_PIXELS 0
- #define GL_UNPACK_SKIP_ROWS 0
- #define GL_RGBA8 0
- #define GL_PACK_ROW_LENGTH 0
- #define GL_PACK_SKIP_ROWS 0
- #define GL_PACK_SKIP_PIXELS 0
-#endif
-
#else
#define glVertexPointerd(nc, s, p, nv) glVertexPointer(nc, GL_DOUBLE, s, p)
}
}
+#if !defined(ECERE_NO3D) && !defined(ECERE_VANILLA)
public void glesRotated( double a, double b, double c, double d )
{
Quaternion q;
matrixStack[curStack][matrixIndex[curStack]] = r;
LoadCurMatrix();
}
+#endif
public void glesMatrixMode(int mode)
{
}
static GLuint stippleTexture;
-#if defined(_GLES)
+#if defined(_GLES) || defined(EM_MODE)
static bool stippleEnabled;
#endif
public void glesLightModeli( unsigned int pname, int param )
{
+#if !defined(EM_MODE)
if(pname == GL_LIGHT_MODEL_TWO_SIDE)
glLightModelf(GL_LIGHT_MODEL_TWO_SIDE, param);
+#endif
}
#if defined(__ANDROID__) || defined(__ODROID__)
public void GLGenBuffers(int count, GLAB * buffers)
{
-#if defined(__ANDROID__) || defined(__ODROID__)
+#if defined(__ANDROID__) || defined(__ODROID__) || defined(__EMSCRIPTEN__)
glGenBuffers(count, (GLuint *)buffers);
#else
#if defined(__WIN32__)
GLBindBuffer(GL_ELEMENT_ARRAY_BUFFER_ARB, 0);
}
}
-#if defined(__ANDROID__) || defined(__ODROID__)
+#if defined(__ANDROID__) || defined(__ODROID__) || defined(__EMSCRIPTEN__)
if(count && buffers[0].buffer)
glDeleteBuffers(count, (GLuint *)buffers);
#else
void GLBindBuffer(int target, uint buffer)
{
-#if defined(__ANDROID__) || defined(__ODROID__)
+#if defined(__ANDROID__) || defined(__ODROID__) || defined(__EMSCRIPTEN__)
glBindBuffer(target, buffer);
#else
#if defined(__WIN32__)
else
#endif
-#if defined(__ANDROID__) || defined(__ODROID__)
+#if defined(__ANDROID__) || defined(__ODROID__) || defined(__EMSCRIPTEN__)
glBufferData(target, size, data, usage);
#else
int imageBuffers[2];
byte * pboMemory1, * pboMemory2;
*/
-#elif !defined(__ANDROID__) && !defined(__ODROID__)
+#elif !defined(__ANDROID__) && !defined(__ODROID__) && !defined(__EMSCRIPTEN__)
GLXContext glContext;
Pixmap pixmap;
HDC hdc;
HGLRC glrc;
HWND hwnd;
-#elif !defined(__ANDROID__) && !defined(__ODROID__)
+#elif !defined(__ANDROID__) && !defined(__ODROID__) && !defined(__EMSCRIPTEN__)
XVisualInfo * visualInfo;
GLXContext glContext;
GLXDrawable glxDrawable;
bool LockSystem(DisplaySystem displaySystem)
{
-#if !defined(__ANDROID__) && !defined(__ODROID__)
+#if !defined(__ANDROID__) && !defined(__ODROID__) && !defined(__EMSCRIPTEN__)
OGLSystem oglSystem = displaySystem.driverData;
if(useSingleGLContext) return true;
#if defined(__WIN32__)
wglMakeCurrent(null, null);
#elif defined(__unix__) || defined(__APPLE__)
// printf("Making NULL current\n");
- #if defined(__ANDROID__) || defined(__ODROID__)
+ #if defined(__ANDROID__) || defined(__ODROID__) || defined(__EMSCRIPTEN__)
#else
glXMakeCurrent(xGlobalDisplay, None, null);
#endif
bool Lock(Display display)
{
-#if !defined(__ANDROID__) && !defined(__ODROID__)
+#if !defined(__ANDROID__) && !defined(__ODROID__) && !defined(__EMSCRIPTEN__)
OGLDisplay oglDisplay = display.driverData;
if(useSingleGLContext) return true;
#if defined(__WIN32__)
if(oglDisplay.memBitmap) DeleteObject(oglDisplay.memBitmap);
#elif defined(__unix__) || defined(__APPLE__)
- #if defined(__ANDROID__) || defined(__ODROID__)
+ #if defined(__ANDROID__) || defined(__ODROID__) || defined(__EMSCRIPTEN__)
#else
if(oglDisplay.shapePixmap)
XFreePixmap(xGlobalDisplay, oglDisplay.shapePixmap);
egl_init_display((uint)displaySystem.window);
CheckExtensions(oglSystem);
result = true;
+ #elif defined(__EMSCRIPTEN__)
+ if(glfwInit() == GL_TRUE)
+ {
+ const int width = 640, height = 480;
+ if(glfwOpenWindow(width, height, 8, 8, 8, 8, 16, 0, GLFW_WINDOW) == GL_TRUE)
+ {
+ //glfwSwapBuffers();
+ result = true;
+ }
+ else
+ printf("glfwOpenWindow() failed\n"); //glfwTerminate();
+ }
+ else
+ printf("glfwInit() failed\n"); //glfwTerminate();
#else
{
X11Window root = RootWindow( xGlobalDisplay, DefaultScreen( xGlobalDisplay ) );
#elif defined(__unix__) || defined(__APPLE__)
#if defined(__ANDROID__) || defined(__ODROID__)
egl_term_display();
+ #elif defined(__EMSCRIPTEN__)
+ glfwTerminate();
#else
if(oglSystem.visualInfo)
{
{
bool result = false;
OGLDisplay oglDisplay = display.driverData;
-#if !defined(__ANDROID__) && !defined(__ODROID__)
+#if !defined(__ANDROID__) && !defined(__ODROID__) && !defined(__EMSCRIPTEN__)
OGLSystem oglSystem = display.displaySystem.driverData;
#endif
if(!oglDisplay)
else
ReleaseDC(display.window, oglDisplay.hdc);
#elif defined(__unix__) || defined(__APPLE__)
- #if defined(__ANDROID__) || defined(__ODROID__)
+ #if defined(__ANDROID__) || defined(__ODROID__) || defined(__EMSCRIPTEN__)
#else
XVisualInfo * visualInfo = ((XWindowData)display.windowDriverData).visual;
/*
glShadeModel(GL_FLAT);
// glLightModeli(GL_LIGHT_MODEL_LOCAL_VIEWER, true);
+#if !defined(EM_MODE)
glLightModeli(GL_LIGHT_MODEL_COLOR_CONTROL, GL_SEPARATE_SPECULAR_COLOR);
+#endif
glFogi(GL_FOG_MODE, GL_EXP);
glFogf(GL_FOG_DENSITY, 0);
glEnable(GL_NORMALIZE);
#if defined(__WIN32__)
wglMakeCurrent(null, null);
#elif defined(__unix__) || defined(__APPLE__)
- #if defined(__ANDROID__) || defined(__ODROID__)
+ #if defined(__ANDROID__) || defined(__ODROID__) || defined(__EMSCRIPTEN__)
result = true;
#else
glXMakeCurrent(xGlobalDisplay, None, null);
ReleaseDC(display.window, hdc);
}
#elif defined(__unix__) || defined(__APPLE__)
- #if defined(__ANDROID__) || defined(__ODROID__)
+ #if defined(__ANDROID__) || defined(__ODROID__) || defined(__EMSCRIPTEN__)
result = true;
#else
int attrib[] =
#if defined(__WIN32__)
wglMakeCurrent(oglDisplay.hdc, oglDisplay.glrc);
#elif defined(__unix__) || defined(__APPLE__)
- #if defined(__ANDROID__) || defined(__ODROID__)
+ #if defined(__ANDROID__) || defined(__ODROID__) || defined(__EMSCRIPTEN__)
width = eglWidth;
height = eglHeight;
#else
ReleaseDC(0, hdc);
#elif defined(__unix__) || defined(__APPLE__)
- #if defined(__ANDROID__) || defined(__ODROID__)
+ #if defined(__ANDROID__) || defined(__ODROID__) || defined(__EMSCRIPTEN__)
#else
XTransform transform =
{
#elif defined(__unix__) || defined(__APPLE__)
#if defined(__ANDROID__) || defined(__ODROID__)
eglSwapBuffers(eglDisplay, eglSurface);
+ #elif defined(__EMSCRIPTEN__)
+ glfwSwapBuffers();
#else
glXSwapBuffers(xGlobalDisplay, (GLXDrawable)display.window);
#endif
glColor4fv(oglSurface.foreground);
glBegin(GL_LINES);
-#ifdef _GLES
+#if defined(_GLES) || defined(EM_MODE)
if(stippleEnabled)
{
glTexCoord2f(0.5f, 0);
//Logf("Rectangle\n");
glColor4fv(oglSurface.foreground);
-#ifdef _GLES
+#if defined(_GLES) || defined(EM_MODE)
if(stippleEnabled)
{
glBegin(GL_LINES);
//Logf("Area\n");
glColor4fv(oglSurface.background);
+
+#ifdef EM_MODE
+ glBegin(GL_QUADS);
+ glVertex2f(x1+surface.offset.x, y1+surface.offset.y);
+ glVertex2f(x1+surface.offset.x, y2+surface.offset.y+1);
+ glVertex2f(x2+surface.offset.x+1, y2+surface.offset.y+1);
+ glVertex2f(x2+surface.offset.x+1, y1+surface.offset.y);
+ glEnd();
+#else
glRecti(x1+surface.offset.x, y1+surface.offset.y,
x2+surface.offset.x + 1, y2+surface.offset.y + 1);
-
+#endif
/*
glRectf(x1+surface.offset.x, y1+surface.offset.y,
x2+surface.offset.x + 1, y2+surface.offset.y + 1);
void StretchDI(Display display, Surface surface, Bitmap bitmap, int dx, int dy, int sx, int sy, int w, int h, int sw, int sh)
{
+#if !defined(EM_MODE)
float s2dw,s2dh,d2sw,d2sh;
//bool flipX = false, flipY = false;
glPixelStorei(GL_UNPACK_SKIP_PIXELS, 0);
glPixelStorei(GL_UNPACK_SKIP_ROWS, 0);
}
+#endif
}
void BlitDI(Display display, Surface surface, Bitmap bitmap, int dx, int dy, int sx, int sy, int w, int h)
{
+#if !defined(EM_MODE)
//Logf("BlitDI\n");
//Clip against the edges of the source
glPixelStorei(GL_UNPACK_SKIP_PIXELS, 0);
glPixelStorei(GL_UNPACK_SKIP_ROWS, 0);
}
+#endif
}
void FilterDI(Display display, Surface surface, Bitmap bitmap, int dx, int dy, int sx, int sy, int w, int h, int sw, int sh)
if(stipple)
{
-#if defined(_GLES)
+#if defined(_GLES) || defined(EM_MODE)
stippleEnabled = true;
glesLineStipple(1, (uint16)stipple);
#else
}
else
{
-#if defined(_GLES)
+#if defined(_GLES) || defined(EM_MODE)
stippleEnabled = false;
glMatrixMode(GL_TEXTURE);
glLoadIdentity();
break;
case ambient:
{
+#if !defined(EM_MODE)
float ambient[4] = { ((Color)value).r/255.0f, ((Color)value).g/255.0f, ((Color)value).b/255.0f, 1.0f };
glLightModelfv(GL_LIGHT_MODEL_AMBIENT, ambient);
+#endif
break;
}
case alphaWrite:
void SetLight(Display display, int id, Light light)
{
+#if !defined(EM_MODE)
//Logf("SetLight\n");
if(light != null)
}
else
glDisable(GL_LIGHT0 + id);
+#endif
}
void SetCamera(Display display, Surface surface, Camera camera)
// ...
glEnable(GL_DEPTH_TEST);
+#if !defined(EM_MODE)
glEnable(GL_LIGHTING);
glShadeModel(GL_SMOOTH);
+#endif
glDepthMask((byte)bool::true);
oglDisplay.depthWrite = true;
glDisable(GL_LIGHTING);
glDisable(GL_FOG);
glDisable(GL_TEXTURE_2D);
+#if !defined(EM_MODE)
glShadeModel(GL_FLAT);
+#endif
glEnable(GL_BLEND);
glDisable(GL_MULTISAMPLE_ARB);
// Basic Properties
if(material.flags.doubleSided)
{
+#if !defined(EM_MODE)
glLightModeli(GL_LIGHT_MODEL_TWO_SIDE, !material.flags.singleSideLight);
+#endif
glDisable(GL_CULL_FACE);
}
else
{
+#if !defined(EM_MODE)
glLightModeli(GL_LIGHT_MODEL_TWO_SIDE, bool::false);
+#endif
glEnable(GL_CULL_FACE);
}
else
glDisable(GL_TEXTURE_2D);
+#ifdef EM_MODE
+ glColor4f(material.diffuse.r, material.diffuse.g, material.diffuse.b, material.opacity);
+#else
if(mesh.flags.colors)
{
glColorMaterial(GL_FRONT_AND_BACK, GL_AMBIENT_AND_DIFFUSE);
}
glMaterialfv(GL_FRONT_AND_BACK, GL_SHININESS, &material.power);
+#endif
}
void FreeMesh(DisplaySystem displaySystem, Mesh mesh)
{
//Logf("SelectMesh\n");
-#if !defined( __ANDROID__) && !defined(__APPLE__) && !defined(__ODROID__)
+#if !defined( __ANDROID__) && !defined(__APPLE__) && !defined(__ODROID__) && !defined(__EMSCRIPTEN__)
#if defined(__WIN32__)
if(glUnlockArraysEXT)
glDisableClientState(GL_COLOR_ARRAY);
}
-#if !defined(__ANDROID__) && !defined(__APPLE__) && !defined(__ODROID__)
+#if !defined(__ANDROID__) && !defined(__APPLE__) && !defined(__ODROID__) && !defined(__EMSCRIPTEN__)
#if defined(__WIN32__)
if(glLockArraysEXT)
return system.glrc;
#elif defined(__ANDROID__) || defined(__ODROID__)
return eglContext;
+#elif defined(__EMSCRIPTEN__)
#else
OGLSystem system = displaySystem.driverData;
return system.glContext;