Commit 05264599 authored by Martok's avatar Martok

* [glBitmap] Always generate mipmaps using correct method for GL Version

parent dce20821
......@@ -304,7 +304,7 @@ type
{ possible mipmap types }
TglBitmapMipMap = (
mmNone, //< no mipmaps
mmMipmap, //< normal mipmaps
mmMipmap, //< normal mipmaps, glGenerateMipmap for 3.0+ or GL_GENERATE_MIPMAP for legacy
mmMipmapGlu); //< mipmaps generated with glu functions
{ possible normal map functions }
......@@ -1009,7 +1009,7 @@ type
procedure CreateID;
{ setup texture parameters }
procedure SetupParameters({$IFNDEF OPENGL_ES}out aBuildWithGlu: Boolean{$ENDIF});
procedure SetupParameters({$IFNDEF OPENGL_ES}out aRealMipMapMode: TglBitmapMipMap{$ENDIF});
protected
property Width: Integer read GetWidth; //< the actual width of the texture
......@@ -1108,7 +1108,7 @@ type
{ upload the texture data to video card
@param aDataObj texture data object that contains the actual data
@param aBuildWithGlu use glu functions to build mipmaps }
procedure UploadDataIntern(const aDataObj: TglBitmapData; const aBuildWithGlu: Boolean);
procedure UploadDataIntern(const aDataObj: TglBitmapData; const aRealMipMapMode: TglBitmapMipMap);
public
property Width; //< actual with of the texture
......@@ -1134,7 +1134,7 @@ type
@param aTarget target o upload data to (e.g. GL_TEXTURE_2D)
@param aBuildWithGlu use glu functions to build mipmaps }
procedure UploadDataIntern(const aDataObj: TglBitmapData; const aTarget: GLenum
{$IFNDEF OPENGL_ES}; const aBuildWithGlu: Boolean{$ENDIF});
{$IFNDEF OPENGL_ES}; const aRealMipMap: TglBitmapMipMap{$ENDIF});
public
property Width; //< actual width of the texture
......@@ -8188,7 +8188,7 @@ begin
end;
//////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
procedure TglBitmap.SetupParameters({$IFNDEF OPENGL_ES}out aBuildWithGlu: Boolean{$ENDIF});
procedure TglBitmap.SetupParameters({$IFNDEF OPENGL_ES}out aRealMipMapMode: TglBitmapMipMap{$ENDIF});
begin
// Set Up Parameters
SetWrap(fWrapS, fWrapT, fWrapR);
......@@ -8203,17 +8203,26 @@ begin
{$IFNDEF OPENGL_ES}
// Mip Maps Generation Mode
aBuildWithGlu := false;
if (MipMap = mmMipmap) then begin
if (GL_VERSION_1_4 or GL_SGIS_generate_mipmap) then
glTexParameteri(Target, GL_GENERATE_MIPMAP, GLint(GL_TRUE))
else
aBuildWithGlu := true;
end else if (MipMap = mmMipmapGlu) then
aBuildWithGlu := true;
aRealMipMapMode:= mmNone;
case MipMap of
mmNone: begin
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_BASE_LEVEL, 0);
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAX_LEVEL, 0);
end;
mmMipmap: begin
if GL_VERSION_3_0 or GL_ARB_framebuffer_object then
aRealMipMapMode:= mmMipmap
else if GL_VERSION_1_4 or GL_SGIS_generate_mipmap then begin
glTexParameteri(GL_TEXTURE_2D, GL_GENERATE_MIPMAP, GLint(GL_TRUE));
aRealMipMapMode:= mmNone;
end else
aRealMipMapMode:= mmMipmapGlu;
end;
mmMipmapGlu: aRealMipMapMode:= mmMipmapGlu;
end;
{$ELSE}
if (MipMap = mmMipmap) then
glGenerateMipmap(Target);
if MipMap <> mmNone then
aRealMipMapMode:= mmMipmap;
{$ENDIF}
end;
......@@ -8502,7 +8511,7 @@ begin
end;
//////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
procedure TglBitmap1D.UploadDataIntern(const aDataObj: TglBitmapData; const aBuildWithGlu: Boolean);
procedure TglBitmap1D.UploadDataIntern(const aDataObj: TglBitmapData; const aRealMipMapMode: TglBitmapMipMap);
var
fd: TglBitmapFormatDescriptor;
begin
......@@ -8514,18 +8523,24 @@ begin
if fd.IsCompressed then begin
if not Assigned(glCompressedTexImage1D) then
raise EglBitmap.Create('compressed formats not supported by video adapter');
glCompressedTexImage1D(Target, 0, fd.glInternalFormat, aDataObj.Width, 0, fd.GetSize(aDataObj.Width, 1), aDataObj.Data)
end else if aBuildWithGlu then
glCompressedTexImage1D(Target, 0, fd.glInternalFormat, aDataObj.Width, 0, fd.GetSize(aDataObj.Width, 1), aDataObj.Data);
if aRealMipMapMode = mmMipmap then
glGenerateMipmap(Target);
end else if aRealMipMapMode = mmMipmapGlu then
gluBuild1DMipmaps(Target, fd.glInternalFormat, aDataObj.Width, fd.glFormat, fd.glDataFormat, aDataObj.Data)
else
else begin
glTexImage1D(Target, 0, fd.glInternalFormat, aDataObj.Width, 0, fd.glFormat, fd.glDataFormat, aDataObj.Data);
if aRealMipMapMode = mmMipmap then
glGenerateMipmap(Target);
end;
end;
//////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
procedure TglBitmap1D.UploadData(const aDataObj: TglBitmapData; const aCheckSize: Boolean);
var
BuildWithGlu, TexRec: Boolean;
TexRec: Boolean;
TexSize: Integer;
realMM: TglBitmapMipMap;
begin
if not Assigned(aDataObj) then
exit;
......@@ -8547,8 +8562,8 @@ begin
if (fID = 0) then
CreateID;
SetupParameters(BuildWithGlu);
UploadDataIntern(aDataObj, BuildWithGlu);
SetupParameters(realMM);
UploadDataIntern(aDataObj, realMM);
glAreTexturesResident(1, @fID, @fIsResident);
end;
{$ENDIF}
......@@ -8563,7 +8578,7 @@ begin
end;
//////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
procedure TglBitmap2D.UploadDataIntern(const aDataObj: TglBitmapData; const aTarget: GLenum{$IFNDEF OPENGL_ES}; const aBuildWithGlu: Boolean{$ENDIF});
procedure TglBitmap2D.UploadDataIntern(const aDataObj: TglBitmapData; const aTarget: GLenum{$IFNDEF OPENGL_ES}; const aRealMipMap: TglBitmapMipMap{$ENDIF});
var
fd: TglBitmapFormatDescriptor;
begin
......@@ -8576,13 +8591,17 @@ begin
if fd.IsCompressed then begin
if not Assigned(glCompressedTexImage2D) then
raise EglBitmap.Create('compressed formats not supported by video adapter');
glCompressedTexImage2D(aTarget, 0, fd.glInternalFormat, aDataObj.Width, aDataObj.Height, 0, fd.GetSize(fDimension), aDataObj.Data)
glCompressedTexImage2D(aTarget, 0, fd.glInternalFormat, aDataObj.Width, aDataObj.Height, 0, fd.GetSize(fDimension), aDataObj.Data);
if aRealMipMap = mmMipmap then
glGenerateMipmap(aTarget);
{$IFNDEF OPENGL_ES}
end else if aBuildWithGlu then begin
end else if aRealMipMap = mmMipmapGlu then begin
gluBuild2DMipmaps(aTarget, fd.ChannelCount, aDataObj.Width, aDataObj.Height, fd.glFormat, fd.glDataFormat, aDataObj.Data)
{$ENDIF}
end else begin
glTexImage2D(aTarget, 0, fd.glInternalFormat, aDataObj.Width, aDataObj.Height, 0, fd.glFormat, fd.glDataFormat, aDataObj.Data);
if aRealMipMap = mmMipmap then
glGenerateMipmap(aTarget);
end;
end;
......@@ -8590,7 +8609,8 @@ end;
procedure TglBitmap2D.UploadData(const aDataObj: TglBitmapData; const aCheckSize: Boolean);
var
{$IFNDEF OPENGL_ES}
BuildWithGlu, TexRec: Boolean;
TexRec: Boolean;
realMM: TglBitmapMipMap;
{$ENDIF}
PotTex: Boolean;
TexSize: Integer;
......@@ -8623,8 +8643,8 @@ begin
if (fID = 0) then
CreateID;
SetupParameters({$IFNDEF OPENGL_ES}BuildWithGlu{$ENDIF});
UploadDataIntern(aDataObj, Target{$IFNDEF OPENGL_ES}, BuildWithGlu{$ENDIF});
SetupParameters({$IFNDEF OPENGL_ES}realMM{$ENDIF});
UploadDataIntern(aDataObj, Target{$IFNDEF OPENGL_ES}, realMM{$ENDIF});
{$IFNDEF OPENGL_ES}
glAreTexturesResident(1, @fID, @fIsResident);
{$ENDIF}
......@@ -8690,7 +8710,7 @@ end;
procedure TglBitmapCubeMap.UploadCubeMap(const aDataObj: TglBitmapData; const aCubeTarget: Cardinal; const aCheckSize: Boolean);
var
{$IFNDEF OPENGL_ES}
BuildWithGlu: Boolean;
realMM: TglBitmapMipMap;
{$ENDIF}
TexSize: Integer;
begin
......@@ -8716,8 +8736,8 @@ begin
if (fID = 0) then
CreateID;
SetupParameters({$IFNDEF OPENGL_ES}BuildWithGlu{$ENDIF});
UploadDataIntern(aDataObj, aCubeTarget{$IFNDEF OPENGL_ES}, BuildWithGlu{$ENDIF});
SetupParameters({$IFNDEF OPENGL_ES}realMM{$ENDIF});
UploadDataIntern(aDataObj, aCubeTarget{$IFNDEF OPENGL_ES}, realMM{$ENDIF});
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