From c6fa7a7ed50fe4fcd712d2bebed31817f77b4a80 Mon Sep 17 00:00:00 2001 From: basisbit Date: Mon, 24 Aug 2015 22:09:23 +0000 Subject: * detect if OpenGL has hardware-support for GL_ARB_texture_non_power_of_two. if yes, don't resize textures => lots faster and texture image quality is a lot better. git-svn-id: svn://svn.code.sf.net/p/ultrastardx/svn/trunk@3126 b956fd51-792f-4845-bead-9b4dfca2ff2c --- src/base/UTexture.pas | 19 ++++++++++++++----- 1 file changed, 14 insertions(+), 5 deletions(-) (limited to 'src/base/UTexture.pas') diff --git a/src/base/UTexture.pas b/src/base/UTexture.pas index c0f0f396..d497f9be 100644 --- a/src/base/UTexture.pas +++ b/src/base/UTexture.pas @@ -133,6 +133,7 @@ type var Texture: TTextureUnit; TextureDatabase: TTextureDatabase; + SupportsNPOT: Boolean; implementation uses @@ -217,6 +218,11 @@ constructor TTextureUnit.Create; begin inherited Create; TextureDatabase := TTextureDatabase.Create; + Log.LogInfo('OpenGL vendor ' + glGetString(GL_VENDOR), 'TTextureUnit.Create'); + Log.LogInfo('OpenGL renderer ' + glGetString(GL_RENDERER), 'TTextureUnit.Create'); + Log.LogInfo('OpenGL version ' + glGetString(GL_VERSION), 'TTextureUnit.Create'); + SupportsNPOT := AnsiContainsStr(glGetString(GL_EXTENSIONS),'texture_non_power_of_two'); + Log.LogInfo('OpenGL TextureNPOT-support: ' + BoolToStr(SupportsNPOT), 'TTextureUnit.Create'); end; destructor TTextureUnit.Destroy; @@ -283,11 +289,14 @@ begin oldWidth := newWidth; oldHeight := newHeight; - // make texture dimensions be powers of 2 - newWidth := Round(Power(2, Ceil(Log2(newWidth)))); - newHeight := Round(Power(2, Ceil(Log2(newHeight)))); - if (newHeight <> oldHeight) or (newWidth <> oldWidth) then - FitImage(TexSurface, newWidth, newHeight); + if (SupportsNPOT = false) then + begin + // make texture dimensions be powers of 2 + newWidth := Round(Power(2, Ceil(Log2(newWidth)))); + newHeight := Round(Power(2, Ceil(Log2(newHeight)))); + if (newHeight <> oldHeight) or (newWidth <> oldWidth) then + FitImage(TexSurface, newWidth, newHeight); + end; // at this point we have the image in memory... // scaled so that dimensions are powers of 2 -- cgit v1.2.3