Clean up math functions

- Remove checking for standard functions from the build system
- Prefix all invocations with std::
- Replace suffixed functions with unprefixed versions
- Include <cmath> in all files that use it and remove the global include

e.g. floorf(x) -> std::floor(x)
This commit is contained in:
Martin Natano
2023-04-19 19:31:40 +02:00
parent f39ed52dbf
commit b68ca517e6
111 changed files with 1831 additions and 1785 deletions
+73 -72
View File
@@ -19,6 +19,7 @@ using namespace RageDisplay_Legacy_Helpers;
#include "arch/LowLevelWindow/LowLevelWindow.h"
#include <cmath>
#include <set>
#if defined(WINDOWS)
@@ -291,7 +292,7 @@ GLhandleARB CompileShader( GLenum ShaderType, RString sFile, std::vector<RString
LOG->Warn("Fragment shaders not supported by driver. Some effects will not be available.");
return 0;
}
RString sBuffer;
{
RageFile file;
@@ -300,7 +301,7 @@ GLhandleARB CompileShader( GLenum ShaderType, RString sFile, std::vector<RString
LOG->Warn( "Error compiling shader %s: %s", sFile.c_str(), file.GetError().c_str() );
return 0;
}
if (file.Read(sBuffer, file.GetFileSize()) == -1)
{
LOG->Warn( "Error compiling shader %s: %s", sFile.c_str(), file.GetError().c_str() );
@@ -367,14 +368,14 @@ GLhandleARB LoadShader( GLenum ShaderType, RString sFile, std::vector<RString> a
secondaryShader = CompileShader( GL_FRAGMENT_SHADER_ARB, "Data/Shaders/GLSL/Shell.frag", asDefines);
else if (sFile == "Data/Shaders/GLSL/Distance field.vert")
secondaryShader = CompileShader( GL_FRAGMENT_SHADER_ARB, "Data/Shaders/GLSL/Distance field.frag", asDefines);
GLhandleARB hShader = CompileShader( ShaderType, sFile, asDefines );
if (hShader == 0)
return 0;
GLhandleARB hProgram = glCreateProgramObjectARB();
glAttachObjectARB( hProgram, hShader );
if (secondaryShader)
{
glAttachObjectARB( hProgram, secondaryShader );
@@ -416,15 +417,15 @@ void InitShaders()
// the shaders and determines shader type by file extension. -aj
// argh shaders in stepmania are painful -colby
std::vector<RString> asDefines;
// used for scrolling textures (I think)
g_bTextureMatrixShader = LoadShader( GL_VERTEX_SHADER_ARB, "Data/Shaders/GLSL/Texture matrix scaling.vert", asDefines );
// these two are for dancing characters and are both actually shader pairs
g_gShellShader = LoadShader( GL_VERTEX_SHADER_ARB, "Data/Shaders/GLSL/Shell.vert", asDefines );
g_gCelShader = LoadShader( GL_VERTEX_SHADER_ARB, "Data/Shaders/GLSL/Cel.vert", asDefines );
g_gDistanceFieldShader = LoadShader( GL_VERTEX_SHADER_ARB, "Data/Shaders/GLSL/Distance field.vert", asDefines );
// effects
g_bUnpremultiplyShader = LoadShader( GL_FRAGMENT_SHADER_ARB, "Data/Shaders/GLSL/Unpremultiply.frag", asDefines );
g_bColorBurnShader = LoadShader( GL_FRAGMENT_SHADER_ARB, "Data/Shaders/GLSL/Color burn.frag", asDefines );
@@ -434,7 +435,7 @@ void InitShaders()
g_hOverlayShader = LoadShader( GL_FRAGMENT_SHADER_ARB, "Data/Shaders/GLSL/Overlay.frag", asDefines );
g_hScreenShader = LoadShader( GL_FRAGMENT_SHADER_ARB, "Data/Shaders/GLSL/Screen.frag", asDefines );
g_hYUYV422Shader = LoadShader( GL_FRAGMENT_SHADER_ARB, "Data/Shaders/GLSL/YUYV422.frag", asDefines );
// Bind attributes.
if (g_bTextureMatrixShader)
{
@@ -602,7 +603,7 @@ static void CheckPalettedTextures()
}
glTexImage2D( GL_PROXY_TEXTURE_2D,
0, glTexFormat,
0, glTexFormat,
16, 16, 0,
glImageFormat, glImageType, nullptr );
GL_CHECK_ERROR( "glTexImage2D" );
@@ -666,7 +667,7 @@ static void CheckReversePackedPixels()
/* Try to create a texture. */
FlushGLErrors();
glTexImage2D( GL_PROXY_TEXTURE_2D,
0, GL_RGBA,
0, GL_RGBA,
16, 16, 0,
GL_BGRA, GL_UNSIGNED_SHORT_1_5_5_5_REV, nullptr );
@@ -686,15 +687,15 @@ static void CheckReversePackedPixels()
void SetupExtensions()
{
const float fGLVersion = StringToFloat( (const char *) glGetString(GL_VERSION) );
g_glVersion = lrintf( fGLVersion * 10 );
g_glVersion = std::lrint( fGLVersion * 10 );
const float fGLUVersion = StringToFloat( (const char *) gluGetString(GLU_VERSION) );
g_gluVersion = lrintf( fGLUVersion * 10 );
g_gluVersion = std::lrint( fGLUVersion * 10 );
#ifndef HAVE_X11 // LLW_X11 needs to init GLEW early for GLX exts
glewInit();
#endif
g_iMaxTextureUnits = 1;
if (GLEW_ARB_multitexture)
glGetIntegerv( GL_MAX_TEXTURE_UNITS_ARB, (GLint *) &g_iMaxTextureUnits );
@@ -816,7 +817,7 @@ RString RageDisplay_Legacy::TryVideoMode( const VideoModeParams &p, bool &bNewDe
else
return RString("The WGL_EXT_swap_control extension is not supported on your computer.");
#endif
ResolutionChanged();
return RString(); // successfully set mode
@@ -913,7 +914,7 @@ RageSurface* RageDisplay_Legacy::CreateScreenshot()
//TODO: revisit for MacOS, where backbuffer size can be less than window size
glReadBuffer( GL_FRONT );
DebugAssertNoGLError();
glReadPixels( 0, 0, g_pWind->GetActualVideoModeParams().width, g_pWind->GetActualVideoModeParams().height, GL_RGBA,
GL_UNSIGNED_BYTE, image->pixels );
DebugAssertNoGLError();
@@ -955,7 +956,7 @@ ActualVideoModeParams RageDisplay_Legacy::GetActualVideoModeParams() const
static void SetupVertices( const RageSpriteVertex v[], int iNumVerts )
{
static float *Vertex, *Texture, *Normal;
static float *Vertex, *Texture, *Normal;
static GLubyte *Color;
static int Size = 0;
if (iNumVerts > Size)
@@ -997,10 +998,10 @@ static void SetupVertices( const RageSpriteVertex v[], int iNumVerts )
if (GLEW_ARB_multitexture)
{
glClientActiveTextureARB( GL_TEXTURE1_ARB );
glClientActiveTextureARB( GL_TEXTURE1_ARB );
glEnableClientState( GL_TEXTURE_COORD_ARRAY );
glTexCoordPointer( 2, GL_FLOAT, 0, Texture );
glClientActiveTextureARB( GL_TEXTURE0_ARB );
glClientActiveTextureARB( GL_TEXTURE0_ARB );
}
glEnableClientState( GL_NORMAL_ARRAY );
@@ -1034,7 +1035,7 @@ void RageDisplay_Legacy::SendCurrentMatrices()
class RageCompiledGeometrySWOGL : public RageCompiledGeometry
{
public:
void Allocate( const std::vector<msMesh> &vMeshes )
{
/* Always allocate at least 1 entry, so &x[0] is valid. */
@@ -1114,10 +1115,10 @@ public:
glLoadMatrixf( (const float*)mat );
}
glDrawElements(
GL_TRIANGLES,
meshInfo.iTriangleCount*3,
GL_UNSIGNED_SHORT,
glDrawElements(
GL_TRIANGLES,
meshInfo.iTriangleCount*3,
GL_UNSIGNED_SHORT,
&m_vTriangles[0]+meshInfo.iTriangleStart );
}
@@ -1164,7 +1165,7 @@ public:
/* This is called when our OpenGL context is invalidated. */
void Invalidate();
void Allocate( const std::vector<msMesh> &vMeshes );
void Change( const std::vector<msMesh> &vMeshes );
void Draw( int iMeshIndex ) const;
@@ -1305,45 +1306,45 @@ void RageCompiledGeometryHWOGL::Allocate( const std::vector<msMesh> &vMeshes )
RageCompiledGeometrySWOGL::Allocate( vMeshes );
glBindBufferARB( GL_ARRAY_BUFFER_ARB, m_nPositions );
DebugAssertNoGLError();
glBufferDataARB(
GL_ARRAY_BUFFER_ARB,
GetTotalVertices()*sizeof(RageVector3),
nullptr,
glBufferDataARB(
GL_ARRAY_BUFFER_ARB,
GetTotalVertices()*sizeof(RageVector3),
nullptr,
GL_STATIC_DRAW_ARB );
DebugAssertNoGLError();
glBindBufferARB( GL_ARRAY_BUFFER_ARB, m_nTextureCoords );
DebugAssertNoGLError();
glBufferDataARB(
GL_ARRAY_BUFFER_ARB,
GetTotalVertices()*sizeof(RageVector2),
nullptr,
glBufferDataARB(
GL_ARRAY_BUFFER_ARB,
GetTotalVertices()*sizeof(RageVector2),
nullptr,
GL_STATIC_DRAW_ARB );
DebugAssertNoGLError();
glBindBufferARB( GL_ARRAY_BUFFER_ARB, m_nNormals );
DebugAssertNoGLError();
glBufferDataARB(
GL_ARRAY_BUFFER_ARB,
GetTotalVertices()*sizeof(RageVector3),
nullptr,
glBufferDataARB(
GL_ARRAY_BUFFER_ARB,
GetTotalVertices()*sizeof(RageVector3),
nullptr,
GL_STATIC_DRAW_ARB );
DebugAssertNoGLError();
glBindBufferARB( GL_ELEMENT_ARRAY_BUFFER_ARB, m_nTriangles );
DebugAssertNoGLError();
glBufferDataARB(
GL_ELEMENT_ARRAY_BUFFER_ARB,
GetTotalTriangles()*sizeof(msTriangle),
nullptr,
glBufferDataARB(
GL_ELEMENT_ARRAY_BUFFER_ARB,
GetTotalTriangles()*sizeof(msTriangle),
nullptr,
GL_STATIC_DRAW_ARB );
DebugAssertNoGLError();
glBindBufferARB( GL_ARRAY_BUFFER_ARB, m_nTextureMatrixScale );
DebugAssertNoGLError();
glBufferDataARB(
GL_ARRAY_BUFFER_ARB,
GetTotalVertices()*sizeof(RageVector2),
glBufferDataARB(
GL_ARRAY_BUFFER_ARB,
GetTotalVertices()*sizeof(RageVector2),
nullptr,
GL_STATIC_DRAW_ARB );
}
@@ -1380,7 +1381,7 @@ void RageCompiledGeometryHWOGL::Draw( int iMeshIndex ) const
glTexCoordPointer(2, GL_FLOAT, 0, nullptr);
DebugAssertNoGLError();
// TRICKY: Don't bind and send normals if lighting is disabled. This
// TRICKY: Don't bind and send normals if lighting is disabled. This
// will save some effort transforming these values.
// XXX: We should keep track of these ourself and avoid glGet*()
GLboolean bLighting;
@@ -1389,7 +1390,7 @@ void RageCompiledGeometryHWOGL::Draw( int iMeshIndex ) const
glGetBooleanv( GL_TEXTURE_GEN_S, &bTextureGenS );
GLboolean bTextureGenT;
glGetBooleanv( GL_TEXTURE_GEN_T, &bTextureGenT );
if (bLighting || bTextureGenS || bTextureGenT)
{
glEnableClientState(GL_NORMAL_ARRAY);
@@ -1455,8 +1456,8 @@ void RageCompiledGeometryHWOGL::Draw( int iMeshIndex ) const
#define BUFFER_OFFSET(o) ((char*)(o))
ASSERT( glDrawRangeElements != nullptr );
glDrawRangeElements(
GL_TRIANGLES,
glDrawRangeElements(
GL_TRIANGLES,
meshInfo.iVertexStart, // minimum array index contained in indices
meshInfo.iVertexStart+meshInfo.iVertexCount-1,
// maximum array index contained in indices
@@ -1535,10 +1536,10 @@ void RageDisplay_Legacy::DrawSymmetricQuadStripInternal( const RageSpriteVertex
SendCurrentMatrices();
SetupVertices( v, iNumVerts );
glDrawElements(
GL_TRIANGLES,
glDrawElements(
GL_TRIANGLES,
iNumIndices,
GL_UNSIGNED_SHORT,
GL_UNSIGNED_SHORT,
&vIndices[0] );
}
@@ -1744,7 +1745,7 @@ void RageDisplay_Legacy::SetTextureMode( TextureUnit tu, TextureMode tm )
void RageDisplay_Legacy::SetTextureFiltering( TextureUnit tu, bool b )
{
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, b ? GL_LINEAR : GL_NEAREST);
GLint iMinFilter;
if (b)
{
@@ -1984,13 +1985,13 @@ void RageDisplay_Legacy::SetTextureWrapping( TextureUnit tu, bool b )
* so we'll behave incorrectly if the same texture is used in more than one texture
* unit simultaneously with different wrapping. */
SetTextureUnit( tu );
GLenum mode = b ? GL_REPEAT : GL_CLAMP_TO_EDGE;
glTexParameteri( GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, mode );
glTexParameteri( GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, mode );
}
void RageDisplay_Legacy::SetMaterial(
void RageDisplay_Legacy::SetMaterial(
const RageColor &emissive,
const RageColor &ambient,
const RageColor &diffuse,
@@ -1998,7 +1999,7 @@ void RageDisplay_Legacy::SetMaterial(
float shininess
)
{
// TRICKY: If lighting is off, then setting the material
// TRICKY: If lighting is off, then setting the material
// will have no effect. Even if lighting is off, we still
// want Models to have basic color and transparency.
// We can do this fake lighting by setting the vertex color.
@@ -2037,11 +2038,11 @@ void RageDisplay_Legacy::SetLightOff( int index )
glDisable( GL_LIGHT0+index );
}
void RageDisplay_Legacy::SetLightDirectional(
int index,
const RageColor &ambient,
const RageColor &diffuse,
const RageColor &specular,
void RageDisplay_Legacy::SetLightDirectional(
int index,
const RageColor &ambient,
const RageColor &diffuse,
const RageColor &specular,
const RageVector3 &dir )
{
// Light coordinates are transformed by the modelview matrix, but
@@ -2132,7 +2133,7 @@ void RageDisplay_Legacy::DeleteTexture( uintptr_t iTexture )
RagePixelFormat RageDisplay_Legacy::GetImgPixelFormat( RageSurface* &img, bool &bFreeImg, int width, int height, bool bPalettedTexture )
{
RagePixelFormat pixfmt = FindPixelFormat( img->format->BitsPerPixel, img->format->Rmask, img->format->Gmask, img->format->Bmask, img->format->Amask );
/* If img is paletted, we're setting up a non-paletted texture, and color indexes
* are too small, depalettize. */
bool bSupported = true;
@@ -2196,7 +2197,7 @@ void SetPixelMapForSurface( int glImageFormat, int glTexFormat, const RageSurfac
DebugAssertNoGLError();
}
uintptr_t RageDisplay_Legacy::CreateTexture(
uintptr_t RageDisplay_Legacy::CreateTexture(
RagePixelFormat pixfmt,
RageSurface* pImg,
bool bGenerateMipMaps )
@@ -2244,7 +2245,7 @@ uintptr_t RageDisplay_Legacy::CreateTexture(
uintptr_t iTexHandle;
glGenTextures( 1, reinterpret_cast<GLuint*>(&iTexHandle) );
ASSERT( iTexHandle != 0 );
glBindTexture( GL_TEXTURE_2D, static_cast<GLuint>(iTexHandle) );
if (g_pWind->GetActualVideoModeParams().bAnisotropicFiltering &&
@@ -2296,7 +2297,7 @@ uintptr_t RageDisplay_Legacy::CreateTexture(
if (bGenerateMipMaps)
{
GLenum error = gluBuild2DMipmaps(
GL_TEXTURE_2D, glTexFormat,
GL_TEXTURE_2D, glTexFormat,
pImg->w, pImg->h,
glImageFormat, glImageType, pImg->pixels );
ASSERT_M( error == 0, (char *) gluErrorString(error) );
@@ -2304,7 +2305,7 @@ uintptr_t RageDisplay_Legacy::CreateTexture(
else
{
glTexImage2D(
GL_TEXTURE_2D, 0, glTexFormat,
GL_TEXTURE_2D, 0, glTexFormat,
power_of_two(pImg->w), power_of_two(pImg->h), 0,
glImageFormat, glImageType, nullptr );
if (pImg->pixels)
@@ -2312,7 +2313,7 @@ uintptr_t RageDisplay_Legacy::CreateTexture(
0, 0,
pImg->w, pImg->h,
glImageFormat, glImageType, pImg->pixels );
DebugAssertNoGLError();
}
@@ -2414,8 +2415,8 @@ RageTextureLock *RageDisplay_Legacy::CreateTextureLock()
return new RageTextureLock_OGL;
}
void RageDisplay_Legacy::UpdateTexture(
uintptr_t iTexHandle,
void RageDisplay_Legacy::UpdateTexture(
uintptr_t iTexHandle,
RageSurface* pImg,
int iXOffset, int iYOffset, int iWidth, int iHeight )
{
@@ -2460,7 +2461,7 @@ public:
uintptr_t GetTexture() const { return m_iTexHandle; }
void StartRenderingTo();
void FinishRenderingTo();
virtual bool InvertY() const { return true; }
private:
@@ -2491,7 +2492,7 @@ void RenderTarget_FramebufferObject::Create( const RenderTargetParam &param, int
m_Param = param;
DebugFlushGLErrors();
// Allocate OpenGL texture resource
glGenTextures( 1, reinterpret_cast<GLuint*>(&m_iTexHandle) );
ASSERT( m_iTexHandle != 0 );
@@ -2509,7 +2510,7 @@ void RenderTarget_FramebufferObject::Create( const RenderTargetParam &param, int
internalformat = param.bWithAlpha? GL_RGBA16F_ARB:GL_RGB16F_ARB;
else
internalformat = param.bWithAlpha? GL_RGBA8:GL_RGB8;
glTexImage2D( GL_TEXTURE_2D, 0, internalformat,
iTextureWidth, iTextureHeight, 0, type, GL_UNSIGNED_BYTE, nullptr );
DebugAssertNoGLError();
@@ -2620,7 +2621,7 @@ void RageDisplay_Legacy::SetRenderTarget( uintptr_t iTexture, bool bPreserveText
{
g_bInvertY = false;
glFrontFace( GL_CCW );
/* Pop matrixes affected by SetDefaultRenderStates. */
DISPLAY->CameraPopMatrix();
@@ -2753,7 +2754,7 @@ void RageDisplay_Legacy::SetAlphaTest(bool b)
* everything supports packed pixels.
*
* Another case of this is incomplete packed pixels support. Some implementations
* neglect GL_UNSIGNED_SHORT_*_REV.
* neglect GL_UNSIGNED_SHORT_*_REV.
*/
bool RageDisplay_Legacy::SupportsSurfaceFormat(RagePixelFormat pixfmt)
{