From: Bergmann89 Date: Wed, 24 Dec 2014 04:20:44 +0000 (+0100) Subject: * added HasOpenGLSupport to FormatDescriptor to check if the given format is supporte... X-Git-Url: https://git.delphigl.com/?a=commitdiff_plain;h=e991f684566fa8872e7807a9eac99844ac60c058;p=LazOpenGLCore.git * added HasOpenGLSupport to FormatDescriptor to check if the given format is supported by OpenGL --- diff --git a/examples/SimpleLoadFromFile/SimpleLoadFromFile.lpr b/examples/SimpleLoadFromFile/SimpleLoadFromFile.lpr index bdb9c69..64d2db7 100644 --- a/examples/SimpleLoadFromFile/SimpleLoadFromFile.lpr +++ b/examples/SimpleLoadFromFile/SimpleLoadFromFile.lpr @@ -40,15 +40,17 @@ end; begin oglWindow := CreateOpenGLWindow('SimpleLoadFromFile', 800, 600, @WindowProc); try - tex := TglBitmap2D.Create; // create texture object - data := TglBitmapData.Create; // create texture data object + tex := TglBitmap2D.Create; // create texture object + data := TglBitmapData.Create; // create texture data object try - data.LoadFromFile( // load texture data from file + data.LoadFromFile( // load texture data from file ExtractFilePath(ApplicationName) + '../textures/BMP_24_RGB8.bmp'); - tex.UploadData(data); // upload data to video card + if not data.FormatDescriptor.HasOpenGLSupport then // check if format is supported by OpenGL + data.ConvertTo(data.FormatDescriptor.OpenGLFormat); // if not then convert + tex.UploadData(data); // upload data to video card finally - FreeAndNil(data); // after upload is done, the data object could be freed to save memory + FreeAndNil(data); // after upload is done, the data object could be freed to save memory end; while running and ProgressMesages do begin diff --git a/examples/SimpleLoadFromFile/SimpleLoadFromFile.lps b/examples/SimpleLoadFromFile/SimpleLoadFromFile.lps index 41e7f95..5c03634 100644 --- a/examples/SimpleLoadFromFile/SimpleLoadFromFile.lps +++ b/examples/SimpleLoadFromFile/SimpleLoadFromFile.lps @@ -8,9 +8,8 @@ - - + @@ -23,9 +22,10 @@ + - - + + @@ -36,7 +36,6 @@ - @@ -44,7 +43,7 @@ - + @@ -129,6 +128,18 @@ + + + + + + + + + + + + diff --git a/glBitmap.pas b/glBitmap.pas index 1e804e0..574bab5 100644 --- a/glBitmap.pas +++ b/glBitmap.pas @@ -390,6 +390,10 @@ type { @return @true if the format is a grayscale format, @false otherwise } function GetIsGrayscale: Boolean; + + { @return @true if the format is supported by OpenGL, @false otherwise } + function GetHasOpenGLSupport: Boolean; + protected fFormat: TglBitmapFormat; //< format this descriptor belongs to fWithAlpha: TglBitmapFormat; //< suitable format with alpha channel @@ -442,6 +446,8 @@ type property HasColor: Boolean read GetHasColor; //< @true if the format has any color color channel, @false otherwise property IsGrayscale: Boolean read GetIsGrayscale; //< @true if the format is a grayscale format, @false otherwise + property HasOpenGLSupport: Boolean read GetHasOpenGLSupport; //< @true if the format is supported by OpenGL, @false otherwise + function GetSize(const aSize: TglBitmapSize): Integer; overload; virtual; function GetSize(const aWidth, aHeight: Integer): Integer; overload; virtual; @@ -3837,6 +3843,11 @@ begin result := (Mask.r = Mask.g) and (Mask.g = Mask.b) and (Mask.r > 0); end; +function TglBitmapFormatDescriptor.GetHasOpenGLSupport: Boolean; +begin + result := (OpenGLFormat = Format); +end; + procedure TglBitmapFormatDescriptor.SetValues; begin fFormat := tfEmpty;