{$IFNDEF OPENGL_ES}
result := glMapBuffer(GLenum(fTarget), GLenum(aAccess));
{$ELSE}
- if not GL_OES_mapbuffer then
+ if GL_OES_mapbuffer then
+ result := glMapBufferOES(GLenum(fTarget), GLenum(aAccess))
+ else
raise EglcArrayBuffer.Create('map buffer is not supported by video card');
- result := glMapBufferOES(GLenum(fTarget), GLenum(aAccess));
{$ENDIF}
glcCheckAndRaiseError;
end;
raise EglcArrayBuffer.Create('map buffer range is not supported by video card');
result := glMapBufferRange(GLenum(fTarget), aOffset, aSize, GLenum(aAccess));
{$ELSE}
- if not GL_VERSION_3_0 then
+ if GL_VERSION_3_0 then
+ result := glMapBufferRange(GLenum(fTarget), aOffset, aSize, GLenum(aAccess))
+ else if GL_EXT_map_buffer_range then
+ result := glMapBufferRangeEXT(GLenum(fTarget), aOffset, aSize, GLenum(aAccess))
+ else
raise EglcArrayBuffer.Create('map buffer range is not supported by video card');
- result := glMapBufferRange(GLenum(fTarget), aOffset, aSize, GLenum(aAccess));
{$ENDIF}
end;
{$IFNDEF OPENGL_ES}
glUnmapBuffer(GLenum(fTarget));
{$ELSE}
- if not (GL_OES_mapbuffer or GL_VERSION_3_0) then
+ if GL_VERSION_3_0 then
+ glUnmapBuffer(GLenum(fTarget))
+ else if GL_OES_mapbuffer then
+ glUnmapBufferOES(GLenum(fTarget))
+ else
raise EglcArrayBuffer.Create('unmap buffer is not supported by video card');
- glUnmapBuffer(GLenum(fTarget));
{$ENDIF}
end;
if not GL_VERSION_2_0 then
raise EglcArrayBuffer.Create('Create - VertexBuffer: not supported');
{$ENDIF}
+ glGetError();
inherited Create;
glGenBuffers(1, @fID);
fDataCount := 0;
////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
TglcFrustum = class(TObject)
private
+ fProjMatrix: TgluMatrix4f;
+ function GetProjMatrixPtr: Pointer;
function GetWidth: Single;
function GetHeight: Single;
function GetFOVAngle: Single;
function GetAspectRatio: Single;
+ procedure UpdateProjMatrix;
protected
fIsOrthogonal: Boolean;
fTop, fBottom, fLeft, fRight, fNear, fFar: Single;
public
- property Top : Single read fTop;
- property Bottom : Single read fBottom;
- property Left : Single read fLeft;
- property Right : Single read fRight;
- property Near : Single read fNear;
- property Far : Single read fFar;
- property Width : Single read GetWidth;
- property Height : Single read GetHeight;
- property FOVAngle : Single read GetFOVAngle;
- property AspectRatio : Single read GetAspectRatio;
- property IsOrthogonal: Boolean read fIsOrthogonal;
+ property Top: Single read fTop;
+ property Bottom: Single read fBottom;
+ property Left: Single read fLeft;
+ property Right: Single read fRight;
+ property Near: Single read fNear;
+ property Far: Single read fFar;
+ property Width: Single read GetWidth;
+ property Height: Single read GetHeight;
+ property FOVAngle: Single read GetFOVAngle;
+ property AspectRatio: Single read GetAspectRatio;
+ property IsOrthogonal: Boolean read fIsOrthogonal;
+ property ProjMatrix: TgluMatrix4f read fProjMatrix;
+ property ProjMatrixPtr: Pointer read GetProjMatrixPtr;
procedure Frustum(const aLeft, aRight, aBottom, aTop, aNear, aFar: Single);
procedure Perspective(const aFOVAngle, aAspectRatio, aNear, aFar: Single);
TglcCamera = class(TglcFrustum)
private
fPosition: TgluMatrix4f;
+ function GetPositionPtr: Pointer;
public
- property Position: TgluMatrix4f read fPosition write fPosition;
+ property Position: TgluMatrix4f read fPosition write fPosition;
+ property PositionPtr: Pointer read GetPositionPtr;
procedure Move(const aVec: TgluVector3f);
procedure Tilt(const aAngle: Single);
uses
Math, {$IFNDEF OPENGL_ES}dglOpenGL{$ELSE}dglOpenGLES{$ENDIF};
+
////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
//TglcFrustum///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
+procedure TglcFrustum.UpdateProjMatrix;
+begin
+ if fIsOrthogonal then begin
+ fProjMatrix[maAxisX] := gluVector4f(
+ 2 / (fRight - fLeft),
+ 0,
+ 0,
+ 0);
+ fProjMatrix[maAxisY] := gluVector4f(
+ 0,
+ 2 / (fTop - fBottom),
+ 0,
+ 0);
+ fProjMatrix[maAxisZ] := gluVector4f(
+ 0,
+ 0,
+ -2 / (fFar - fNear),
+ 0);
+ fProjMatrix[maPos] := gluVector4f(
+ -(fRight + fLeft) / (fRight - fLeft),
+ -(fTop + fBottom) / (fTop - fBottom),
+ -(fFar + fNear) / (fFar - fNear),
+ 1);
+ end else begin
+ fProjMatrix[maAxisX] := gluVector4f(
+ 2 * fNear / (fRight - fLeft),
+ 0,
+ 0,
+ 0);
+ fProjMatrix[maAxisY] := gluVector4f(
+ 0,
+ 2 * fNear / (fTop - fBottom),
+ 0,
+ 0);
+ fProjMatrix[maAxisZ] := gluVector4f(
+ (fRight + fLeft) / (fRight - fLeft),
+ (fTop + fBottom) / (fTop - fBottom),
+ -(fFar + fNear) / (fFar - fNear),
+ -1);
+ fProjMatrix[maPos] := gluVector4f(
+ 0,
+ 0,
+ -2 * fFar * fNear / (fFar - fNear),
+ 0);
+ end;
+end;
+
+////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
function TglcFrustum.GetWidth: Single;
begin
result := (fRight - fLeft);
end;
////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
+function TglcFrustum.GetProjMatrixPtr: Pointer;
+begin
+ result := @fProjMatrix[0, 0];
+end;
+
+////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
function TglcFrustum.GetHeight: Single;
begin
result := (fTop - fBottom);
fRight := aTop;
fNear := aNear;
fFar := aFar;
+ UpdateProjMatrix;
end;
////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
fBottom := -fTop;
fRight := aAspectRatio * fTop;
fLeft := -fRight;
+ UpdateProjMatrix;
end;
////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
fBottom := aBottom;
fNear := aNear;
fFar := aFar;
+ UpdateProjMatrix;
end;
////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
//TglcCamera////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
+function TglcCamera.GetPositionPtr: Pointer;
+begin
+ result := @fPosition[0, 0];
+end;
+
+////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
procedure TglcCamera.Move(const aVec: TgluVector3f);
begin
fPosition := gluMatrixMult(gluMatrixTranslate(aVec), fPosition);
\r
function GetUniformfv(const aName: String; aP: PGLfloat): Boolean;\r
function GetUniformfi(const aName: String; aP: PGLint): Boolean;\r
+ procedure BindAttribLocation(const aName: String; const aAttribIndex: GLint);\r
+ function GetAttribLocation(const aName: String): Integer;\r
function HasUniform(const aName: String): Boolean;\r
\r
procedure LoadFromFile(const aFilename: String);\r
//@result: TRUE wenn ohne Fehler kompiliert, sonst FALSE;\r
function TglcShaderObject.GetCompiled: Boolean;\r
var\r
- value: glInt;\r
+ value: GLint;\r
begin\r
glGetShaderiv(fShaderObj, GL_COMPILE_STATUS, @value);\r
- result := (value = GL_TRUE);\r
+ result := (value = GLint(GL_TRUE));\r
end;\r
\r
////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////\r
value: glInt;\r
begin\r
glGetProgramiv(fProgramObj, GL_LINK_STATUS, @value);\r
- result := (value = GL_TRUE);\r
+ result := (value = GLint(GL_TRUE));\r
end;\r
\r
////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////\r
end;\r
\r
////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////\r
+procedure TglcShaderProgram.BindAttribLocation(const aName: String; const aAttribIndex: GLint);\r
+begin\r
+ CreateProgramObj;\r
+ glBindAttribLocation(fProgramObj, aAttribIndex, PGLchar(aName));\r
+end;\r
+\r
+////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////\r
+function TglcShaderProgram.GetAttribLocation(const aName: String): Integer;\r
+begin\r
+ result := glGetAttribLocation(fProgramObj, PGLchar(aName));\r
+end;\r
+\r
+////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////\r
function TglcShaderProgram.HasUniform(const aName: String): Boolean;\r
var\r
pos: GLint;\r
rx.Free;\r
sl.Free;\r
end;\r
-\r
-\r
- {\r
- if Assigned(aStream) then begin\r
- Clear;\r
- fFilename := '';\r
- reader := TutlStreamReader.Create(aStream);\r
- try\r
- if reader.ReadAnsiString <> GLSL_FILE_HEADER then\r
- raise EglcShader.Create('TglShaderProgram.SaveToStream - incompatible file');\r
- v := reader.ReadInteger;\r
-\r
- if v >= 100 then begin //version 1.00\r
- c := reader.ReadInteger;\r
- for i := 0 to c-1 do begin\r
- Add(TglcShaderObject.Create(Cardinal(reader.ReadInteger), fOnLog));\r
- Last.fCode := reader.ReadAnsiString;\r
- end;\r
- end;\r
- finally\r
- reader.Free;\r
- end;\r
- end else\r
- }\r
end;\r
\r
////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////\r