Blame |
Last modification |
View Log
| RSS feed
unit app_particle_vertexbuffer;
interface
uses sux_constant, sux_object, app_constant;
type
SAPVertexBuffer=class
vertexcount: SXInt;
positions: array of SXVertex3D;
colors: array of SXColorRGBA;
texcoords0: array of SXVertex2D;
texcoords1: array of SXVertex2D;
texcoords2: array of SXVertex3D;
procedure enableTextureCoordSet(const setindex: SXInt; const elementspercoord: SXInt; const arraystart: Pointer);
procedure disableTextureCoordSet(const setindex: SXInt);
procedure onRender; virtual;
procedure setVertexCount(const vertices: SXInt);
procedure setVertex(const vertexindex: SXInt; const position: SXVertex3D; const color: SXColorRGBA; const texcoord0, texcoord1: SXVertex2D; const texcoord2: SXVertex3D);
constructor Create;
destructor Destroy; override;
end;
implementation
uses main, gl_main, OpenGL, gl_vertexbufferengine, glExt;
// --- SAPVertexBuffer
procedure SAPVertexBuffer.enableTextureCoordSet(const setindex: SXInt; const elementspercoord: SXInt; const arraystart: Pointer);
begin
gl.texture.settings.mt.glActiveTextureARB(GL_TEXTURE0_ARB + setindex);
gl.vertexbuffer.settings.vbo.glClientActiveTextureARB(GL_TEXTURE0_ARB + setindex);
glEnableClientState(GL_TEXTURE_COORD_ARRAY);
glTexCoordPointer(elementspercoord, GL_FLOAT, 0, arraystart);
end;
procedure SAPVertexBuffer.disableTextureCoordSet(const setindex: SXInt);
begin
gl.vertexbuffer.settings.vbo.glClientActiveTextureARB(GL_TEXTURE0_ARB + setindex);
glDisableClientState(GL_TEXTURE_COORD_ARRAY);
gl.vertexbuffer.settings.vbo.glClientActiveTextureARB(GL_TEXTURE0_ARB);
end;
procedure SAPVertexBuffer.onRender;
begin
glEnableClientState(GL_VERTEX_ARRAY);
glVertexPointer(3, GL_FLOAT, 0, positions);
glEnableClientState(GL_COLOR_ARRAY);
glColorPointer(4, GL_FLOAT, 0, colors);
enableTextureCoordSet(0, 2, texcoords0);
enableTextureCoordSet(1, 2, texcoords1);
enableTextureCoordSet(2, 3, texcoords2);
glDrawArrays(GL_QUADS, 0, vertexcount);
glDisableClientState(GL_VERTEX_ARRAY);
glDisableClientState(GL_COLOR_ARRAY);
disableTextureCoordSet(0);
disableTextureCoordSet(1);
disableTextureCoordSet(2);
end;
procedure SAPVertexBuffer.setVertexCount(const vertices: SXInt);
begin
vertexcount := vertices;
SetLength(positions, vertices);
SetLength(colors, vertices);
SetLength(texcoords0, vertices);
SetLength(texcoords1, vertices);
SetLength(texcoords2, vertices);
end;
procedure SAPVertexBuffer.setVertex(const vertexindex: SXInt; const position: SXVertex3D; const color: SXColorRGBA; const texcoord0, texcoord1: SXVertex2D; const texcoord2: SXVertex3D);
begin
positions[vertexindex] := position;
colors[vertexindex] := color;
texcoords0[vertexindex] := texcoord0;
texcoords1[vertexindex] := texcoord1;
texcoords2[vertexindex] := texcoord2;
end;
constructor SAPVertexBuffer.Create;
begin
inherited Create;
end;
destructor SAPVertexBuffer.Destroy;
begin
finalize(positions);
finalize(colors);
finalize(texcoords0);
finalize(texcoords1);
finalize(texcoords2);
inherited;
end;
end.