X-Git-Url: https://git.delphigl.com/?p=LazOpenGLCore.git;a=blobdiff_plain;f=uglcVertexArrayObject.pas;fp=uglcVertexArrayObject.pas;h=89e7ac28cb8f46d5a103b1071127d0d2dff1ee24;hp=0000000000000000000000000000000000000000;hb=f6ca47eeb2c217505d9c1babe79d46b6668d3881;hpb=dfa7064d827360dd9a3ce0467fadb3f1c32a36c1 diff --git a/uglcVertexArrayObject.pas b/uglcVertexArrayObject.pas new file mode 100644 index 0000000..89e7ac2 --- /dev/null +++ b/uglcVertexArrayObject.pas @@ -0,0 +1,84 @@ +unit uglcVertexArrayObject; + +{$mode objfpc}{$H+} + +interface + +uses + Classes, SysUtils, contnrs, dglOpenGL, uglcArrayBuffer; + +type + EglcVertexArrayObject = class(Exception); + TglcVertexArrayObject = class(TObject) + private + fID: GLuint; + fArrayBuffers: TObjectList; + public + property ID: GLuint read fID; + + procedure BindArrayBuffer(const aBuffer: TglcArrayBuffer; const aOwnsObject: Boolean); + procedure VertexAttribPointer(const aIndex: GLuint; const aSize: GLint; const aType: GLenum; + const aNormalized: GLboolean; const aStride: GLsizei; const aOffset: GLint); + + procedure Bind; + procedure Unbind; + + constructor Create; + destructor Destroy; override; + end; + +implementation + +///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// +//TglcVertexArrayObject////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// +///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// +procedure TglcVertexArrayObject.BindArrayBuffer(const aBuffer: TglcArrayBuffer; const aOwnsObject: Boolean); +begin + Bind; + aBuffer.Bind; + if aOwnsObject and (fArrayBuffers.IndexOf(aBuffer) < 0) then + fArrayBuffers.Add(aBuffer); +end; + +///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// +procedure TglcVertexArrayObject.VertexAttribPointer(const aIndex: GLuint; const aSize: GLint; const aType: GLenum; + const aNormalized: GLboolean; const aStride: GLsizei; const aOffset: GLint); +begin + Bind; + glEnableVertexAttribArray(aIndex); + glVertexAttribPointer(aIndex, aSize, aType, aNormalized, aStride, Pointer(aOffset)); +end; + +///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// +procedure TglcVertexArrayObject.Bind; +begin + glBindVertexArray(fID); +end; + +///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// +procedure TglcVertexArrayObject.Unbind; +begin + glBindVertexArray(0); +end; + +///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// +constructor TglcVertexArrayObject.Create; +begin + inherited Create; + if not GL_VERSION_3_0 and + not GL_ARB_vertex_array_object then + raise EglcVertexArrayObject.Create('vertex array objects are not supported by video vard'); + glGenVertexArrays(1, @fID); + fArrayBuffers := TObjectList.Create(true); +end; + +///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// +destructor TglcVertexArrayObject.Destroy; +begin + glDeleteVertexArrays(1, @fID); + FreeAndNil(fArrayBuffers); + inherited Destroy; +end; + +end. +