Commit ff16b4dd authored by Bergmann89's avatar Bergmann89

* ArrayBuffer: fixed some small bugs for OpenGL ES

* Camera: added projection matrix for frustum
* Shader: added BindAttribLocation and GetAttribLocation
parent 38723f45
......@@ -137,9 +137,10 @@ begin
{$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;
......@@ -152,9 +153,12 @@ begin
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;
......@@ -164,9 +168,12 @@ begin
{$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;
......@@ -192,6 +199,7 @@ begin
if not GL_VERSION_2_0 then
raise EglcArrayBuffer.Create('Create - VertexBuffer: not supported');
{$ENDIF}
glGetError();
inherited Create;
glGenBuffers(1, @fID);
fDataCount := 0;
......
......@@ -33,25 +33,30 @@ type
////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
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);
......@@ -68,8 +73,10 @@ type
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);
......@@ -86,14 +93,69 @@ implementation
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
......@@ -122,6 +184,7 @@ begin
fRight := aTop;
fNear := aNear;
fFar := aFar;
UpdateProjMatrix;
end;
////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
......@@ -134,6 +197,7 @@ begin
fBottom := -fTop;
fRight := aAspectRatio * fTop;
fLeft := -fRight;
UpdateProjMatrix;
end;
////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
......@@ -146,6 +210,7 @@ begin
fBottom := aBottom;
fNear := aNear;
fFar := aFar;
UpdateProjMatrix;
end;
////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
......@@ -208,6 +273,12 @@ end;
////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
//TglcCamera////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
function TglcCamera.GetPositionPtr: Pointer;
begin
result := @fPosition[0, 0];
end;
////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
procedure TglcCamera.Move(const aVec: TgluVector3f);
begin
......
......@@ -145,6 +145,8 @@ type
function GetUniformfv(const aName: String; aP: PGLfloat): Boolean;
function GetUniformfi(const aName: String; aP: PGLint): Boolean;
procedure BindAttribLocation(const aName: String; const aAttribIndex: GLint);
function GetAttribLocation(const aName: String): Integer;
function HasUniform(const aName: String): Boolean;
procedure LoadFromFile(const aFilename: String);
......@@ -193,10 +195,10 @@ end;
//@result: TRUE wenn ohne Fehler kompiliert, sonst FALSE;
function TglcShaderObject.GetCompiled: Boolean;
var
value: glInt;
value: GLint;
begin
glGetShaderiv(fShaderObj, GL_COMPILE_STATUS, @value);
result := (value = GL_TRUE);
result := (value = GLint(GL_TRUE));
end;
////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
......@@ -329,7 +331,7 @@ var
value: glInt;
begin
glGetProgramiv(fProgramObj, GL_LINK_STATUS, @value);
result := (value = GL_TRUE);
result := (value = GLint(GL_TRUE));
end;
////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
......@@ -770,6 +772,19 @@ begin
glGetUniformiv(fProgramObj, pos, aP);
end;
////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
procedure TglcShaderProgram.BindAttribLocation(const aName: String; const aAttribIndex: GLint);
begin
CreateProgramObj;
glBindAttribLocation(fProgramObj, aAttribIndex, PGLchar(aName));
end;
////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
function TglcShaderProgram.GetAttribLocation(const aName: String): Integer;
begin
result := glGetAttribLocation(fProgramObj, PGLchar(aName));
end;
////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
function TglcShaderProgram.HasUniform(const aName: String): Boolean;
var
......@@ -862,30 +877,6 @@ begin
rx.Free;
sl.Free;
end;
{
if Assigned(aStream) then begin
Clear;
fFilename := '';
reader := TutlStreamReader.Create(aStream);
try
if reader.ReadAnsiString <> GLSL_FILE_HEADER then
raise EglcShader.Create('TglShaderProgram.SaveToStream - incompatible file');
v := reader.ReadInteger;
if v >= 100 then begin //version 1.00
c := reader.ReadInteger;
for i := 0 to c-1 do begin
Add(TglcShaderObject.Create(Cardinal(reader.ReadInteger), fOnLog));
Last.fCode := reader.ReadAnsiString;
end;
end;
finally
reader.Free;
end;
end else
}
end;
////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment