#if defined(__WIN32__)
#define WIN32_LEAN_AND_MEAN
#undef _WIN32_WINNT
-#define _WIN32_WINNT 0x0500
+#define _WIN32_WINNT 0x0502
#define String Sting_
#include <windows.h>
#undef String
typedef int (APIENTRY * PFNWGLRELEASEPBUFFERDCARBPROC) (void * hPbuffer, HDC hDC);
typedef BOOL (APIENTRY * PFNWGLDESTROYPBUFFERARBPROC) (void * hPbuffer);
typedef BOOL (APIENTRY * PFNWGLQUERYPBUFFERARBPROC) (void * hPbuffer, int iAttribute, int *piValue);
+typedef const char * (APIENTRY * PFNWGLGETEXTENSIONSSTRINGARBPROC) (HDC hdc);
+typedef BOOL (APIENTRY * PFNWGLBINDTEXIMAGEARBPROC) (void * hPbuffer, int iBuffer);
+typedef BOOL (APIENTRY * PFNWGLRELEASETEXIMAGEARBPROC) (void * hPbuffer, int iBuffer);
static PFNGLMAPBUFFERARBPROC glMapBufferARB = null;
static PFNGLUNMAPBUFFERARBPROC glUnmapBufferARB = null;
EGL_SAMPLES, 0, //2,*/
EGL_NONE
};
- EGLint w, h, dummy, format;
+ EGLint w, h, format;
EGLint numConfigs;
EGLConfig config;
EGLSurface surface;
{
if(stippleTexture)
{
- glDeleteTextures(1, (int *)&stippleTexture);
+ glDeleteTextures(1, &stippleTexture);
stippleTexture = 0;
}
if(eglDisplay != EGL_NO_DISPLAY)
void glesOrtho( double l, double r, double b, double t, double n, double f )
{
- Matrix m =
+ Matrix m
{ {
(2 / (r - l)), 0, 0, 0,
0, (2 / (t - b)), 0, 0,
0, 0, (-2 / (f - n)), 0,
(-(r + l) / (r - l)), (-(t + b) / (t - b)), (-(f + n) / (f - n)), 1
- } }, res;
+ } };
+ Matrix res;
res.Multiply(m, matrixStack[curStack][matrixIndex[curStack]]);
matrixStack[curStack][matrixIndex[curStack]] = res;
LoadCurMatrix();
double B = ((t + b) / (t - b));
double C = (-(f + n) / (f - n));
double D = (-2*f*n/(f-n));
- Matrix m =
+ Matrix m
{ {
(2.0*n / (r - l)), 0, 0, 0,
0, (2.0*n / (t - b)), 0, 0,
A, B, C,-1,
0, 0, D, 0
- } }, res;
+ } };
+ Matrix res;
res.Multiply(m, matrixStack[curStack][matrixIndex[curStack]]);
matrixStack[curStack][matrixIndex[curStack]] = res;
LoadCurMatrix();
shortBDSize = 0;
}
-static int stippleTexture;
+static GLuint stippleTexture;
static bool stippleEnabled;
void glesLineStipple( int i, unsigned short j )
{
uint texture[1*16];
- int c;
int x;
for(x = 0; x < 16; x++)
{
#ifdef __ANDROID__
glGenBuffers(count, buffer);
#else
+#if defined(__WIN32__)
if(glGenBuffersARB)
+#endif
glGenBuffersARB(count, buffer);
#endif
}
-void GLDeleteBuffers(int count, uint * buffer)
+void GLDeleteBuffers(int count, GLuint * buffer)
{
#ifdef __ANDROID__
glDeleteBuffers(count, buffer);
#else
+#if defined(__WIN32__)
if(glDeleteBuffersARB)
+#endif
glDeleteBuffersARB(count, buffer);
#endif
}
#ifdef __ANDROID__
glBindBuffer(target, buffer);
#else
+#if defined(__WIN32__)
if(glBindBufferARB)
+#endif
glBindBufferARB(target, buffer);
#endif
}
{
#ifdef __ANDROID__
if(type == GL_DOUBLE)
- glesBufferDatad(target, size, data, usage);
+ glesBufferDatad(target, size, (void *)data, usage);
else if(type == GL_UNSIGNED_INT)
- glesBufferDatai(target, size, data, usage);
+ glesBufferDatai(target, size, (void *)data, usage);
else
glBufferData(target, size, data, usage);
#else
+
+#if defined(__WIN32__)
if(glBufferDataARB)
+#endif
glBufferDataARB(target, size, data, usage);
#endif
int imageBuffers[2];
byte * pboMemory1, * pboMemory2;
*/
-#else
+#elif !defined(__ANDROID__)
GLXContext glContext;
Pixmap pixmap;
HDC hdc;
HGLRC glrc;
HWND hwnd;
-#else
+#elif !defined(__ANDROID__)
XVisualInfo * visualInfo;
GLXContext glContext;
GLXDrawable glxDrawable;
class OGLMesh : struct
{
- int vertices;
- int normals;
- int texCoords;
- int texCoords2;
- int colors;
+ uint vertices;
+ uint normals;
+ uint texCoords;
+ uint texCoords2;
+ uint colors;
};
class OGLIndices : struct
{
uint16 * indices;
- int buffer;
- int nIndices;
+ uint buffer;
+ uint nIndices;
};
#if !defined(ECERE_NO3D) && !defined(ECERE_VANILLA)
bool LockSystem(DisplaySystem displaySystem)
{
+#if !defined(__ANDROID__)
OGLSystem oglSystem = displaySystem.driverData;
if(useSingleGLContext) return true;
#if defined(__WIN32__)
#elif defined(__unix__) || defined(__APPLE__)
//if(previous) return true;
// printf("Making SYSTEM current\n");
-#if !defined(__ANDROID__)
glXMakeCurrent(xGlobalDisplay, (GLXDrawable)oglSystem.glxDrawable, oglSystem.glContext);
-#endif
//previous = oglSystem.glContext;
#endif
+#endif
return true;
}
bool Lock(Display display)
{
+#if !defined(__ANDROID__)
OGLDisplay oglDisplay = display.driverData;
- OGLSystem oglSystem = display.displaySystem.driverData;
-
if(useSingleGLContext) return true;
#if defined(__WIN32__)
wglMakeCurrent(oglDisplay.hdc, oglDisplay.glrc);
#elif defined(__unix__) || defined(__APPLE__)
// if(previous) glXMakeCurrent(xGlobalDisplay, None, null);
// printf(" Making DISPLAY current\n");
- #if defined(__ANDROID__)
- #else
- glXMakeCurrent(xGlobalDisplay, (int)display.window, oglDisplay.glContext);
- #endif
+ glXMakeCurrent(xGlobalDisplay, (GLXDrawable)display.window, oglDisplay.glContext);
#endif
+#endif
return true;
}
void ::CheckExtensions(OGLSystem oglSystem)
{
- char * extensions = glGetString(GL_EXTENSIONS);
+ const char * extensions = (const char *)glGetString(GL_EXTENSIONS);
if(extensions)
oglSystem.pow2textures = strstr(extensions, "GL_ARB_texture_non_power_of_two") ? false : true;
glGetIntegerv(GL_MAX_TEXTURE_SIZE, &oglSystem.maxTextureSize);
{
bool result = false;
OGLDisplay oglDisplay = display.driverData;
+#if !defined(__ANDROID__)
OGLSystem oglSystem = display.displaySystem.driverData;
+#endif
if(!oglDisplay)
oglDisplay = display.driverData = OGLDisplay { };
//printf("Inside CreateDisplay\n");
if(oglDisplay.glContext)
{
//printf("CreateDisplay Got a Context\n");
- glXMakeCurrent(xGlobalDisplay, (int)display.window, oglDisplay.glContext);
+ glXMakeCurrent(xGlobalDisplay, (GLXDrawable)display.window, oglDisplay.glContext);
result = true;
}
#endif
#endif
if(result)
{
-#if !defined(__OLDX__)
+#if defined(__WIN32__)
if(glBlendFuncSeparate)
glBlendFuncSeparate(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA, GL_ONE, GL_ONE_MINUS_SRC_ALPHA);
else
-#endif
glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA);
+#else
+#if !defined(__OLDX__)
+ glBlendFuncSeparate(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA, GL_ONE, GL_ONE_MINUS_SRC_ALPHA);
+#else
+ glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA);
+#endif
+#endif
glEnable(GL_BLEND);
glMatrixMode(GL_MODELVIEW);
bool DisplaySize(Display display, int width, int height)
{
OGLDisplay oglDisplay = display.driverData;
- OGLSystem oglSystem = display.displaySystem.driverData;
bool result = false;
//printf("Inside DisplaySize\n");
#if defined(__WIN32__) || defined(USEPBUFFER)
+ OGLSystem oglSystem = display.displaySystem.driverData;
if(display.alphaBlend)
{
#if defined(__WIN32__)
if(oglDisplay.glContext)
{
glXMakeCurrent(xGlobalDisplay, None, null);
- glXMakeCurrent(xGlobalDisplay, (int)display.window, oglDisplay.glContext);
+ glXMakeCurrent(xGlobalDisplay, (GLXDrawable)display.window, oglDisplay.glContext);
// Initialize Shared Memory Pixmap
oglDisplay.image = XShmCreateImage(xGlobalDisplay, DefaultVisual(xGlobalDisplay, DefaultScreen(xGlobalDisplay)), 32,
width = eglWidth;
height = eglHeight;
#else
- glXMakeCurrent(xGlobalDisplay, (int)display.window, oglDisplay.glContext);
+ glXMakeCurrent(xGlobalDisplay, (GLXDrawable)display.window, oglDisplay.glContext);
#endif
#endif
}
void Update(Display display, Box updateBox)
{
+#if defined(__WIN32__) || defined(USEPBUFFER)
OGLDisplay oglDisplay = display.driverData;
+#endif
//Logf("DisplayScreen\n");
glFlush();
#if defined(__ANDROID__)
eglSwapBuffers(eglDisplay, eglSurface);
#else
- glXSwapBuffers(xGlobalDisplay, (int)display.window);
+ glXSwapBuffers(xGlobalDisplay, (GLXDrawable)display.window);
#endif
#endif
}
void FreeBitmap(DisplaySystem displaySystem, Bitmap bitmap)
{
- glDeleteTextures(1, (int *)&bitmap.driverData);
- bitmap.driverData = 0;
-
+ if(bitmap.driverData)
+ {
+ GLuint tex = (GLuint)(uintptr)bitmap.driverData;
+ glDeleteTextures(1, &tex);
+ bitmap.driverData = 0;
+ }
bitmap.driver = ((subclass(DisplayDriver))class(LFBDisplayDriver));
}
OGLSystem oglSystem = displaySystem.driverData;
bool result = false;
Bitmap mipMap { };
- int glBitmap = -1;
+ GLuint glBitmap = 0;
uint w = width, h = height;
if(oglSystem.pow2textures)
delete mipMap;
- bitmap.driverData = (void *)glBitmap;
+ bitmap.driverData = (void *)(uintptr)glBitmap;
bitmap.driver = displaySystem.driver;
bitmap.width = w;
bitmap.height = h;
{
int c, level;
uint w = bitmap.width, h = bitmap.height;
- int glBitmap = -1;
+ GLuint glBitmap = 0;
if(oglSystem.pow2textures)
{
w = pow2i(w);
w = Min(w, oglSystem.maxTextureSize);
h = Min(h, oglSystem.maxTextureSize);
+ if(mipMaps)
+ {
+ while(w * 2 < h) w *= 2;
+ while(h * 2 < w) h *= 2;
+ }
+
// Switch ARGB to RGBA
//if(bitmap.format != pixelFormatRGBA)
{
glGetError();
glGenTextures(1, &glBitmap);
- if(glBitmap == -1)
+ if(glBitmap == 0)
{
- int error = glGetError();
+ //int error = glGetError();
return false;
- //Print("");
}
glBindTexture(GL_TEXTURE_2D, glBitmap);
if(!bitmap.keepData)
bitmap.driver.FreeBitmap(bitmap.displaySystem, bitmap);
- bitmap.driverData = (void *)glBitmap;
+ bitmap.driverData = (void *)(uintptr)glBitmap;
bitmap.driver = displaySystem.driver;
if(!result)
else if(oglSurface.xOffset)
glTranslated(oglSurface.xOffset / 64.0/*-0.375*/, 0.0, 0.0);
- glBindTexture(GL_TEXTURE_2D, (uint)bitmap.driverData);
+ glBindTexture(GL_TEXTURE_2D, (GLuint)(uintptr)bitmap.driverData);
glBegin(GL_QUADS);
if(h < 0)
#endif
glEnable(GL_TEXTURE_2D);
- glBindTexture(GL_TEXTURE_2D, (uint)bitmap.driverData);
+ glBindTexture(GL_TEXTURE_2D, (GLuint)(uintptr)bitmap.driverData);
glColor4fv(oglSurface.bitmapMult);
void StretchDI(Display display, Surface surface, Bitmap bitmap, int dx, int dy, int sx, int sy, int w, int h, int sw, int sh)
{
float s2dw,s2dh,d2sw,d2sh;
- bool flipX = false, flipY = false;
+ //bool flipX = false, flipY = false;
//Logf("StretchDI\n");
{
w = Abs(w);
sw = Abs(sw);
- flipX = true;
+ //flipX = true;
}
if(Sgn(h) != Sgn(sh))
{
h = Abs(h);
sh = Abs(sh);
- flipY = true;
+ //flipY = true;
}
s2dw=(float)w / sw;
((subclass(DisplayDriver))class(LFBDisplayDriver)).UnloadFont(displaySystem, font);
}
- Font LoadFont(DisplaySystem displaySystem, char * faceName, float size, FontFlags flags)
+ Font LoadFont(DisplaySystem displaySystem, const char * faceName, float size, FontFlags flags)
{
Font font;
OGLSystem oglSystem = displaySystem.driverData;
return font;
}
- void FontExtent(DisplaySystem displaySystem, Font font, char * text, int len, int * width, int * height)
+ void FontExtent(DisplaySystem displaySystem, Font font, const char * text, int len, int * width, int * height)
{
((subclass(DisplayDriver))class(LFBDisplayDriver)).FontExtent(displaySystem, font, text, len, width, height);
}
- void WriteText(Display display, Surface surface, int x, int y, char * text, int len)
+ void WriteText(Display display, Surface surface, int x, int y, const char * text, int len)
{
OGLSurface oglSurface = surface.driverData;
OGLSystem oglSystem = display.displaySystem.driverData;
oglSurface.opaqueText = opaque;
}
- void TextExtent(Display display, Surface surface, char * text, int len, int * width, int * height)
+ void TextExtent(Display display, Surface surface, const char * text, int len, int * width, int * height)
{
OGLSurface oglSurface = surface.driverData;
OGLSystem oglSystem = display.displaySystem.driverData;
break;
case depthWrite:
if(value) glDepthMask((byte)bool::true); else glDepthMask((byte)bool::false);
- oglDisplay.depthWrite = value;
+ oglDisplay.depthWrite = (bool)value;
break;
case fogColor:
{
break;
}
case fogDensity:
- value *= nearPlane;
- glFogf(GL_FOG_DENSITY, *(float *)(void *)&value);
+ glFogf(GL_FOG_DENSITY, (float)(RenderStateFloat { ui = value }.f * nearPlane));
break;
case blend:
if(value) glEnable(GL_BLEND); else glDisable(GL_BLEND);
{
float pickX = display.display3D.pickX + surface.offset.x;
float pickY = display.height - (display.display3D.pickY + surface.offset.y) - 1;
- Matrix pickMatrix =
+ Matrix pickMatrix
{
{
w / display.display3D.pickWidth, 0, 0, 0,
{
Bitmap map = material.baseMap;
glEnable(GL_TEXTURE_2D);
- glBindTexture(GL_TEXTURE_2D, (uint)map.driverData);
+ glBindTexture(GL_TEXTURE_2D, (GLuint)(uintptr)map.driverData);
+
+ glMatrixMode(GL_TEXTURE);
+ glLoadIdentity();
+ if(material.uScale && material.vScale)
+ glScalef(material.uScale, material.vScale, 1);
+ glMatrixMode(GL_MODELVIEW);
if(material.flags.tile)
{
}
}
- bool AllocateMesh(DisplaySystem displaySystem, Mesh mesh)
+ bool AllocateMesh(DisplaySystem displaySystem, Mesh mesh, MeshFeatures flags, int nVertices)
{
bool result = false;
if(mesh.data)
{
OGLMesh oglMesh = mesh.data;
-
- if(mesh.flags.vertices && !oglMesh.vertices && !mesh.vertices)
+ if(mesh.nVertices == nVertices)
{
- mesh.vertices = mesh.flags.doubleVertices ? (Vector3Df *)new Vector3D[mesh.nVertices] : new Vector3Df[mesh.nVertices];
- GLGenBuffers(1, &oglMesh.vertices);
- }
- if(mesh.flags.normals && !oglMesh.normals && !mesh.normals)
- {
- GLGenBuffers( 1, &oglMesh.normals);
- mesh.normals = mesh.flags.doubleNormals ? (Vector3Df *)new Vector3D[mesh.nVertices] : new Vector3Df[mesh.nVertices];
- }
- if(mesh.flags.texCoords1 && !oglMesh.texCoords && !mesh.texCoords)
- {
- GLGenBuffers( 1, &oglMesh.texCoords);
- mesh.texCoords = new Pointf[mesh.nVertices];
+ // Same number of vertices, adding features (Leaves the other features pointers alone)
+ if(mesh.flags != flags)
+ {
+ if(!mesh.flags.vertices && flags.vertices)
+ {
+ if(flags.doubleVertices)
+ {
+ mesh.vertices = (Vector3Df *)new Vector3D[nVertices];
+ }
+ else
+ mesh.vertices = new Vector3Df[nVertices];
+ if(!oglMesh.vertices)
+ GLGenBuffers(1, &oglMesh.vertices);
+ }
+ if(!mesh.flags.normals && flags.normals)
+ {
+ if(flags.doubleNormals)
+ {
+ mesh.normals = (Vector3Df *)new Vector3D[nVertices];
+ }
+ else
+ mesh.normals = new Vector3Df[nVertices];
+ if(!oglMesh.normals)
+ GLGenBuffers( 1, &oglMesh.normals);
+ }
+ if(!mesh.flags.texCoords1 && flags.texCoords1)
+ {
+ mesh.texCoords = new Pointf[nVertices];
+ if(!oglMesh.texCoords)
+ GLGenBuffers( 1, &oglMesh.texCoords);
+ }
+ if(!mesh.flags.colors && flags.colors)
+ {
+ mesh.colors = new ColorRGBAf[nVertices];
+ if(!oglMesh.colors)
+ GLGenBuffers( 1, &oglMesh.colors);
+ }
+ }
}
- if(mesh.flags.colors && !oglMesh.colors && !mesh.colors)
+ else
{
- GLGenBuffers( 1, &oglMesh.colors);
- mesh.colors = new ColorRGBAf[mesh.nVertices];
+ // New number of vertices, reallocate all current and new features
+ flags |= mesh.flags;
+ if(flags.vertices)
+ {
+ if(flags.doubleVertices)
+ {
+ mesh.vertices = (Vector3Df *)renew mesh.vertices Vector3D[nVertices];
+ }
+ else
+ mesh.vertices = renew mesh.vertices Vector3Df[nVertices];
+ if(!oglMesh.vertices)
+ GLGenBuffers(1, &oglMesh.vertices);
+ }
+ if(flags.normals)
+ {
+ if(flags.doubleNormals)
+ {
+ mesh.normals = (Vector3Df *)renew mesh.normals Vector3D[nVertices];
+ }
+ else
+ mesh.normals = renew mesh.normals Vector3Df[nVertices];
+ if(!oglMesh.normals)
+ GLGenBuffers( 1, &oglMesh.normals);
+ }
+ if(flags.texCoords1)
+ {
+ mesh.texCoords = renew mesh.texCoords Pointf[nVertices];
+ if(!oglMesh.texCoords)
+ GLGenBuffers( 1, &oglMesh.texCoords);
+ }
+ if(flags.colors)
+ {
+ mesh.colors = renew mesh.colors ColorRGBAf[nVertices];
+ if(!oglMesh.colors)
+ GLGenBuffers( 1, &oglMesh.colors);
+ }
}
result = true;
}
if(vboAvailable)
{
- if(!(flags.vertices) || oglMesh.vertices)
+ if(flags.vertices && oglMesh.vertices)
{
GLBindBuffer(GL_ARRAY_BUFFER_ARB, oglMesh.vertices);
GLBufferData( mesh.flags.doubleVertices ? GL_DOUBLE : GL_FLOAT, GL_ARRAY_BUFFER_ARB, mesh.nVertices * (mesh.flags.doubleVertices ? sizeof(Vector3D) : sizeof(Vector3Df)), mesh.vertices, GL_STATIC_DRAW_ARB );
}
- if(!(flags.normals) || oglMesh.normals)
+ if(flags.normals && oglMesh.normals)
{
GLBindBuffer(GL_ARRAY_BUFFER_ARB, oglMesh.normals);
GLBufferData( mesh.flags.doubleNormals ? GL_DOUBLE : GL_FLOAT, GL_ARRAY_BUFFER_ARB, mesh.nVertices * (mesh.flags.doubleNormals ? sizeof(Vector3D) : sizeof(Vector3Df)), mesh.normals, GL_STATIC_DRAW_ARB );
}
- if(!(flags.texCoords1) || oglMesh.texCoords)
+ if(flags.texCoords1 && oglMesh.texCoords)
{
GLBindBuffer(GL_ARRAY_BUFFER_ARB, oglMesh.texCoords);
GLBufferData( GL_FLOAT, GL_ARRAY_BUFFER_ARB, mesh.nVertices * sizeof(Pointf), mesh.texCoords, GL_STATIC_DRAW_ARB );
}
- if(!(flags.colors) || oglMesh.colors)
+ if(flags.colors && oglMesh.colors)
{
GLBindBuffer( GL_ARRAY_BUFFER_ARB, oglMesh.colors);
GLBufferData( GL_FLOAT, GL_ARRAY_BUFFER_ARB, mesh.nVertices * sizeof(ColorRGBAf), mesh.colors, GL_STATIC_DRAW_ARB );
//Logf("SelectMesh\n");
#if !defined( __ANDROID__) && !defined(__APPLE__)
- if(display.display3D.mesh && glUnlockArraysEXT)
- glUnlockArraysEXT();
+#if defined(__WIN32__)
+ if(glUnlockArraysEXT)
+#endif
+ if(display.display3D.mesh)
+ glUnlockArraysEXT();
#endif
if(mesh)
{
- OGLDisplay oglDisplay = display.driverData;
OGLMesh oglMesh = mesh.data;
// *** Vertex Stream ***
}
#if !defined(__ANDROID__) && !defined(__APPLE__)
- if(glLockArraysEXT) glLockArraysEXT(0, mesh.nVertices);
+
+#if defined(__WIN32__)
+ if(glLockArraysEXT)
+#endif
+ glLockArraysEXT(0, mesh.nVertices);
#endif
}
else
void DrawPrimitives(Display display, PrimitiveSingle * primitive, Mesh mesh)
{
- OGLDisplay oglDisplay = display.driverData;
//Logf("DrawPrimitives\n");
if(primitive->type.vertexRange)
MeshFeatures flags = mesh.flags;
for(c = 0; c<primitive->nIndices; c++)
{
- short index = ((short *) oglIndices.indices)[c];
+ uint16 index = ((uint16 *) oglIndices.indices)[c];
if(flags.normals) glNormal3fv((float *)&mesh.normals[index]);
if(flags.texCoords1) glTexCoord2fv((float *)&mesh.texCoords[index]);
if(flags.colors) glColor4fv((float *)&mesh.colors[index]);
useSingleGLContext = useSingle;
}
-default dllexport void * __attribute__((stdcall)) IS_GLGetContext(DisplaySystem displaySystem)
+default dllexport void *
+#if defined(__WIN32__)
+__attribute__((stdcall))
+#endif
+IS_GLGetContext(DisplaySystem displaySystem)
{
- void * context = null;
if(displaySystem)
{
- OGLSystem system = displaySystem.driverData;
#if defined(__WIN32__)
+ OGLSystem system = displaySystem.driverData;
return system.glrc;
-#else
+#elif !defined(__ANDROID__)
+ OGLSystem system = displaySystem.driverData;
return system.glContext;
+#else
+ return eglContext;
#endif
}
+ return null;
}
#endif