#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
void glesRotated( double a, double b, double c, double d )
{
- Matrix m;
Quaternion q;
- q.RotationAxis({(float)b,(float)-c,(float)d}, a );
+ Matrix m, r;
+
+ q.RotationAxis({(float)b,(float)c,(float)-d}, a );
m.RotationQuaternion(q);
- matrixStack[curStack][matrixIndex[curStack]].Rotate(q);
+ r.Multiply(m, matrixStack[curStack][matrixIndex[curStack]]);
+ matrixStack[curStack][matrixIndex[curStack]] = r;
LoadCurMatrix();
}
void glesScaled( double a, double b, double c )
void glesMatrixMode(int mode)
{
- curStack = mode == GL_MODELVIEW ? 0 : mode == GL_PROJECTION ? 1 : 2;
+ curStack = (mode == GL_MODELVIEW) ? 0 : (mode == GL_PROJECTION) ? 1 : 2;
glMatrixMode(mode);
}
void glesTerminate()
{
delete vertexPointer;
+ delete normalPointer;
beginBufferSize = 0;
delete floatVPBuffer;
#endif
}
-void GLBufferData(int type, GLenum target, int size, const GLvoid *data, GLenum usage)
+public void GLVertexPointer(int numCoords, int glType, int stride, void *pointer, int numVertices)
+{
+#ifdef __ANDROID__
+ if(type == GL_DOUBLE)
+ glesVertexPointerd(numCoords, stride, pointer, numVertices);
+ else if(type == GL_UNSIGNED_INT)
+ glesVertexPointeri(numCoords, stride, pointer, numVertices);
+ else
+#endif
+ glVertexPointer(numCoords, glType, stride, pointer);
+}
+
+public void GLBufferData(int type, GLenum target, int size, const GLvoid *data, GLenum usage)
{
#ifdef __ANDROID__
if(type == GL_DOUBLE)
{
oglDisplay.flipBufW = width;
oglDisplay.flipBufH = height;
+#ifdef _GLES
+ result = true;
+#else
oglDisplay.flippingBuffer = renew oglDisplay.flippingBuffer ColorAlpha [width * height];
+#endif
}
if(oglDisplay.flippingBuffer || !width || !height)
result = true;
glBindTexture(GL_TEXTURE_2D, glBitmap);
glPixelStorei( GL_UNPACK_ALIGNMENT, 1 );
- glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR);
- glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, mipMaps ? GL_LINEAR_MIPMAP_LINEAR : GL_LINEAR);
+ glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, mipMaps ? GL_LINEAR_MIPMAP_LINEAR : GL_LINEAR);
+ glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR);
+
//glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR);
//glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_CLAMP);
result = true;
- for(level = 0; result && (w > 1 || h > 1); level++, w >>= 1, h >>= 1)
+ for(level = 0; result && (w >= 1 || h >= 1); level++, w >>= 1, h >>= 1)
{
Bitmap mipMap;
+ if(!w) w = 1;
+ if(!h) h = 1;
if(bitmap.width != w || bitmap.height != h)
{
mipMap = Bitmap { };
break;
}
case fogDensity:
- glFogf(GL_FOG_DENSITY, (float)(RenderStateFloat { value }.f * nearPlane));
+ glFogf(GL_FOG_DENSITY, (float)(RenderStateFloat { ui = value }.f * nearPlane));
break;
case blend:
if(value) glEnable(GL_BLEND); else glDisable(GL_BLEND);
}
}
- 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)
- {
- 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)
+ if(mesh.nVertices == nVertices)
{
- 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 defined(__WIN32__)
if(glUnlockArraysEXT)
#endif
- if(display.display3D.mesh)
+ if(!vboAvailable && display.display3D.mesh)
glUnlockArraysEXT();
+
#endif
if(mesh)
{
#if defined(__WIN32__)
if(glLockArraysEXT)
#endif
- glLockArraysEXT(0, mesh.nVertices);
+ if(!vboAvailable)
+ glLockArraysEXT(0, mesh.nVertices);
+
#endif
}
else