struct { int first, nVertices; };
};
Material material;
+
private:
void * data;
};
bool Allocate(MeshFeatures what, int nVertices, DisplaySystem displaySystem)
{
bool result = false;
- if((!this.nVertices || this.nVertices == nVertices) && (!this.displaySystem || this.displaySystem == displaySystem))
+ if(!this.displaySystem || this.displaySystem == displaySystem)
{
- flags |= what;
- this.nVertices = nVertices;
driver = displaySystem ? displaySystem.driver : (subclass(DisplayDriver))class(LFBDisplayDriver);
if(driver.AllocateMesh == DisplayDriver::AllocateMesh) driver = (subclass(DisplayDriver))class(LFBDisplayDriver);
- if(driver.AllocateMesh(displaySystem, this))
+ if(driver.AllocateMesh(displaySystem, this, what, nVertices))
{
+ flags |= what;
+ this.nVertices = nVertices;
if(Lock(what))
result = true;
}
virtual void ::SetRenderState(Display, RenderState, uint);
virtual void ::SetLight(Display, int, Light);
virtual void ::SetCamera(Display, Surface, Camera);
- virtual bool ::AllocateMesh(DisplaySystem, Mesh);
+ virtual bool ::AllocateMesh(DisplaySystem, Mesh, MeshFeatures, int nVertices);
virtual void ::FreeMesh(DisplaySystem, Mesh);
virtual bool ::LockMesh(DisplaySystem, Mesh, MeshFeatures flags);
virtual void ::UnlockMesh(DisplaySystem, Mesh, MeshFeatures flags);
}
}
- bool AllocateMesh(DisplaySystem displaySystem, Mesh mesh)
+ bool AllocateMesh(DisplaySystem displaySystem, Mesh mesh, MeshFeatures flags, int nVertices)
{
D3D8System d3dSystem = displaySystem.driverData;
bool result = false;
{
D3D8Mesh d3dMesh = mesh.data;
result = true;
- if((mesh.flags .vertices) && !d3dMesh.vertices)
+ if(mesh.nVertices == nVertices)
{
- mesh.vertices = new Vector3Df[mesh.nVertices];
- if(IDirect3DDevice8_CreateVertexBuffer(d3dDevice, sizeof(Vector3Df) * mesh.nVertices,
- d3dSystem.usage, 0, D3DPOOL_MANAGED, &d3dMesh.vertices))
- result = false;
- }
- if((mesh.flags.normals) && !d3dMesh.normals)
- {
- mesh.normals = new Vector3Df[mesh.nVertices];
- if(IDirect3DDevice8_CreateVertexBuffer(d3dDevice, sizeof(Vector3Df) * mesh.nVertices,
- d3dSystem.usage, 0, D3DPOOL_MANAGED, &d3dMesh.normals))
- result = false;
+ if(mesh.flags != flags)
+ {
+ // Same number of vertices, adding features (Leaves the other features pointers alone)
+ if(flags.vertices && !d3dMesh.vertices)
+ {
+ mesh.vertices = new Vector3Df[nVertices];
+ if(IDirect3DDevice8_CreateVertexBuffer(d3dDevice, sizeof(Vector3Df) * nVertices,
+ d3dSystem.usage, 0, D3DPOOL_MANAGED, &d3dMesh.vertices))
+ result = false;
+ }
+ if(flags.normals && !d3dMesh.normals)
+ {
+ mesh.normals = new Vector3Df[nVertices];
+ if(IDirect3DDevice8_CreateVertexBuffer(d3dDevice, sizeof(Vector3Df) * nVertices,
+ d3dSystem.usage, 0, D3DPOOL_MANAGED, &d3dMesh.normals))
+ result = false;
+ }
+ if(flags.texCoords1 && !d3dMesh.texCoords)
+ {
+ mesh.texCoords = new Pointf[nVertices];
+ if(IDirect3DDevice8_CreateVertexBuffer(d3dDevice, sizeof(Pointf) * nVertices,
+ d3dSystem.usage, 0, D3DPOOL_MANAGED, &d3dMesh.texCoords))
+ result = false;
+ }
+ }
}
- if((mesh.flags.texCoords1) && !d3dMesh.texCoords)
+ else
{
- mesh.texCoords = new Pointf[mesh.nVertices];
- if(IDirect3DDevice8_CreateVertexBuffer(d3dDevice, sizeof(Pointf) * mesh.nVertices,
- d3dSystem.usage, 0, D3DPOOL_MANAGED, &d3dMesh.texCoords))
- result = false;
+ // New number of vertices, reallocate all current and new features
+ flags |= mesh.flags;
+
+ // Same number of vertices, adding features (Leaves the other features pointers alone)
+ if(flags.vertices)
+ {
+ if(d3dMesh.vertices)
+ {
+ IDirect3DVertexBuffer8_Release(d3dMesh.vertices);
+ d3dMesh.vertices = null;
+ }
+ mesh.vertices = renew mesh.vertices Vector3Df[nVertices];
+ if(IDirect3DDevice8_CreateVertexBuffer(d3dDevice, sizeof(Vector3Df) * nVertices,
+ d3dSystem.usage, 0, D3DPOOL_MANAGED, &d3dMesh.vertices))
+ result = false;
+ }
+ if(flags.normals)
+ {
+ if(d3dMesh.normals)
+ {
+ IDirect3DVertexBuffer8_Release(d3dMesh.normals);
+ d3dMesh.normals = null;
+ }
+ mesh.normals = renew mesh.normals Vector3Df[nVertices];
+ if(IDirect3DDevice8_CreateVertexBuffer(d3dDevice, sizeof(Vector3Df) * nVertices,
+ d3dSystem.usage, 0, D3DPOOL_MANAGED, &d3dMesh.normals))
+ result = false;
+ }
+ if(flags.texCoords1)
+ {
+ if(d3dMesh.texCoords)
+ {
+ IDirect3DVertexBuffer8_Release(d3dMesh.texCoords);
+ d3dMesh.texCoords = null;
+ }
+ mesh.texCoords = renew mesh.texCoords Pointf[nVertices];
+ if(IDirect3DDevice8_CreateVertexBuffer(d3dDevice, sizeof(Pointf) * nVertices,
+ d3dSystem.usage, 0, D3DPOOL_MANAGED, &d3dMesh.texCoords))
+ result = false;
+ }
}
}
return result;
}
}
- bool AllocateMesh(DisplaySystem displaySystem, Mesh mesh)
+ bool AllocateMesh(DisplaySystem displaySystem, Mesh mesh, MeshFeatures flags, int nVertices)
{
D3DSystem d3dSystem = displaySystem.driverData;
bool result = false;
{
D3DMesh d3dMesh = mesh.data;
result = true;
- if((mesh.flags.vertices) && !d3dMesh.vertices)
+ if(mesh.nVertices == nVertices)
{
- mesh.vertices = new Vector3Df[mesh.nVertices];
- if(IDirect3DDevice9_CreateVertexBuffer(d3dDevice, sizeof(Vector3Df) * mesh.nVertices,
- d3dSystem.usage, 0, D3DPOOL_MANAGED, &d3dMesh.vertices, null))
- result = false;
- }
- if((mesh.flags.normals) && !d3dMesh.normals)
- {
- mesh.normals = new Vector3Df[mesh.nVertices];
- if(IDirect3DDevice9_CreateVertexBuffer(d3dDevice, sizeof(Vector3Df) * mesh.nVertices,
- d3dSystem.usage, 0, D3DPOOL_MANAGED, &d3dMesh.normals, null))
- result = false;
+ if(mesh.flags != flags)
+ {
+ // Same number of vertices, adding features (Leaves the other features pointers alone)
+ if(flags.vertices && !d3dMesh.vertices)
+ {
+ mesh.vertices = new Vector3Df[nVertices];
+ if(IDirect3DDevice9_CreateVertexBuffer(d3dDevice, sizeof(Vector3Df) * nVertices,
+ d3dSystem.usage, 0, D3DPOOL_MANAGED, &d3dMesh.vertices, null))
+ result = false;
+ }
+ if(flags.normals && !d3dMesh.normals)
+ {
+ mesh.normals = new Vector3Df[nVertices];
+ if(IDirect3DDevice9_CreateVertexBuffer(d3dDevice, sizeof(Vector3Df) * nVertices,
+ d3dSystem.usage, 0, D3DPOOL_MANAGED, &d3dMesh.normals, null))
+ result = false;
+ }
+ if(flags.texCoords1 && !d3dMesh.texCoords)
+ {
+ mesh.texCoords = new Pointf[nVertices];
+ if(IDirect3DDevice9_CreateVertexBuffer(d3dDevice, sizeof(Pointf) * nVertices,
+ d3dSystem.usage, 0, D3DPOOL_MANAGED, &d3dMesh.texCoords, null))
+ result = false;
+ }
+ }
}
- if((mesh.flags.texCoords1) && !d3dMesh.texCoords)
+ else
{
- mesh.texCoords = new Pointf[mesh.nVertices];
- if(IDirect3DDevice9_CreateVertexBuffer(d3dDevice, sizeof(Pointf) * mesh.nVertices,
- d3dSystem.usage, 0, D3DPOOL_MANAGED, &d3dMesh.texCoords, null))
- result = false;
+ // New number of vertices, reallocate all current and new features
+ flags |= mesh.flags;
+
+ // Same number of vertices, adding features (Leaves the other features pointers alone)
+ if(flags.vertices)
+ {
+ if(d3dMesh.vertices)
+ {
+ IDirect3DVertexBuffer9_Release(d3dMesh.vertices);
+ d3dMesh.vertices = null;
+ }
+ mesh.vertices = renew mesh.vertices Vector3Df[nVertices];
+ if(IDirect3DDevice9_CreateVertexBuffer(d3dDevice, sizeof(Vector3Df) * nVertices,
+ d3dSystem.usage, 0, D3DPOOL_MANAGED, &d3dMesh.vertices, null))
+ result = false;
+ }
+ if(flags.normals)
+ {
+ if(d3dMesh.normals)
+ {
+ IDirect3DVertexBuffer9_Release(d3dMesh.normals);
+ d3dMesh.normals = null;
+ }
+ mesh.normals = renew mesh.normals Vector3Df[nVertices];
+ if(IDirect3DDevice9_CreateVertexBuffer(d3dDevice, sizeof(Vector3Df) * nVertices,
+ d3dSystem.usage, 0, D3DPOOL_MANAGED, &d3dMesh.normals, null))
+ result = false;
+ }
+ if(flags.texCoords1)
+ {
+ if(d3dMesh.texCoords)
+ {
+ IDirect3DVertexBuffer9_Release(d3dMesh.texCoords);
+ d3dMesh.texCoords = null;
+ }
+ mesh.texCoords = renew mesh.texCoords Pointf[nVertices];
+ if(IDirect3DDevice9_CreateVertexBuffer(d3dDevice, sizeof(Pointf) * nVertices,
+ d3dSystem.usage, 0, D3DPOOL_MANAGED, &d3dMesh.texCoords, null))
+ result = false;
+ }
}
}
return result;
delete mesh.texCoords;
}
- bool AllocateMesh(DisplaySystem displaySystem, Mesh mesh)
+ bool AllocateMesh(DisplaySystem displaySystem, Mesh mesh, MeshFeatures flags, int nVertices)
{
bool result = false;
-
- if((!mesh.flags.vertices || mesh.vertices || (mesh.vertices = new Vector3Df[mesh.nVertices])) &&
- (!mesh.flags.normals || mesh.normals || (mesh.normals = new Vector3Df[mesh.nVertices])) &&
- (!mesh.flags.texCoords1 || mesh.texCoords || (mesh.texCoords = new Pointf [mesh.nVertices])))
- result = true;
+ if(mesh.nVertices == 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(!mesh.flags.normals && flags.normals)
+ {
+ if(flags.doubleNormals)
+ {
+ mesh.normals = (Vector3Df *)new Vector3D[nVertices];
+ }
+ else
+ mesh.normals = new Vector3Df[nVertices];
+ }
+ if(!mesh.flags.texCoords1 && flags.texCoords1)
+ mesh.texCoords = new Pointf[nVertices];
+ if(!mesh.flags.colors && flags.colors)
+ mesh.colors = new ColorRGBAf[nVertices];
+ }
+ }
+ else
+ {
+ // 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(flags.normals)
+ {
+ if(flags.doubleNormals)
+ {
+ mesh.normals = (Vector3Df *)renew mesh.normals Vector3D[nVertices];
+ }
+ else
+ mesh.normals = renew mesh.normals Vector3Df[nVertices];
+ }
+ if(flags.texCoords1)
+ mesh.texCoords = renew mesh.texCoords Pointf[nVertices];
+ if(flags.colors)
+ mesh.colors = renew mesh.colors ColorRGBAf[nVertices];
+ }
return result;
}
}
}
- 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 );