1 unit uglcVertexArrayObject;
8 Classes, SysUtils, contnrs, dglOpenGL, uglcArrayBuffer;
11 EglcVertexArrayObject = class(Exception);
12 TglcVertexArrayObject = class(TObject)
15 fArrayBuffers: TObjectList;
17 property ID: GLuint read fID;
19 procedure BindArrayBuffer(const aBuffer: TglcArrayBuffer; const aOwnsObject: Boolean);
20 procedure VertexAttribPointer(const aIndex: GLuint; const aSize: GLint; const aType: GLenum;
21 const aNormalized: GLboolean; const aStride: GLsizei; const aOffset: GLint);
27 destructor Destroy; override;
32 /////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
33 //TglcVertexArrayObject//////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
34 /////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
35 procedure TglcVertexArrayObject.BindArrayBuffer(const aBuffer: TglcArrayBuffer; const aOwnsObject: Boolean);
39 if aOwnsObject and (fArrayBuffers.IndexOf(aBuffer) < 0) then
40 fArrayBuffers.Add(aBuffer);
43 /////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
44 procedure TglcVertexArrayObject.VertexAttribPointer(const aIndex: GLuint; const aSize: GLint; const aType: GLenum;
45 const aNormalized: GLboolean; const aStride: GLsizei; const aOffset: GLint);
48 glEnableVertexAttribArray(aIndex);
49 glVertexAttribPointer(aIndex, aSize, aType, aNormalized, aStride, Pointer(aOffset));
52 /////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
53 procedure TglcVertexArrayObject.Bind;
55 glBindVertexArray(fID);
58 /////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
59 procedure TglcVertexArrayObject.Unbind;
64 /////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
65 constructor TglcVertexArrayObject.Create;
68 if not GL_VERSION_3_0 and
69 not GL_ARB_vertex_array_object then
70 raise EglcVertexArrayObject.Create('vertex array objects are not supported by video vard');
71 glGenVertexArrays(1, @fID);
72 fArrayBuffers := TObjectList.Create(true);
75 /////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
76 destructor TglcVertexArrayObject.Destroy;
78 glDeleteVertexArrays(1, @fID);
79 FreeAndNil(fArrayBuffers);