From 31a6ffdd3ab7f166295ceea37fcb807c2bbc4ee0 Mon Sep 17 00:00:00 2001 From: vladislavbelov Date: Mon, 11 Oct 2021 12:39:01 +0000 Subject: [PATCH] Removes mentions of legacy and unused GL calls, unifies AsFloatArray. This was SVN commit r25961. --- source/graphics/Color.h | 16 ++++++++++++++-- source/graphics/LOSTexture.h | 4 ++-- source/graphics/TerritoryTexture.h | 6 +++--- source/maths/Matrix3D.h | 4 ++-- source/maths/Vector3D.h | 15 +++++++++++++-- source/soundmanager/items/CSoundBase.cpp | 4 ++-- 6 files changed, 36 insertions(+), 13 deletions(-) diff --git a/source/graphics/Color.h b/source/graphics/Color.h index 4bbc34c595..a90c39d6a7 100644 --- a/source/graphics/Color.h +++ b/source/graphics/Color.h @@ -65,8 +65,20 @@ struct CColor return !(*this == color); } - // For passing to glColor[34]fv: - const float* FloatArray() const { return &r; } + // For passing to uniform as vec3/vec4. + const float* AsFloatArray() const + { + // Additional check to prevent a weird compiler has a different + // alignement for an array and a class members. + static_assert( + sizeof(CColor) == sizeof(float) * 4u && + offsetof(CColor, r) == 0 && + offsetof(CColor, g) == sizeof(float) && + offsetof(CColor, b) == sizeof(float) * 2u && + offsetof(CColor, a) == sizeof(float) * 3u, + "CColor should be properly layouted to use AsFloatArray"); + return &r; + } // For passing to CRenderer: SColor4ub AsSColor4ub() const diff --git a/source/graphics/LOSTexture.h b/source/graphics/LOSTexture.h index f6bd11aa07..0d2ebe66bc 100644 --- a/source/graphics/LOSTexture.h +++ b/source/graphics/LOSTexture.h @@ -65,14 +65,14 @@ public: /** * Returns a matrix to map (x,y,z) world coordinates onto (u,v) LOS texture - * coordinates, in the form expected by glLoadMatrixf. + * coordinates, in the form expected by a matrix uniform. * This must only be called after BindTexture. */ const CMatrix3D& GetTextureMatrix(); /** * Returns a matrix to map (0,0)-(1,1) texture coordinates onto LOS texture - * coordinates, in the form expected by glLoadMatrixf. + * coordinates, in the form expected by a matrix uniform. * This must only be called after BindTexture. */ const CMatrix3D* GetMinimapTextureMatrix(); diff --git a/source/graphics/TerritoryTexture.h b/source/graphics/TerritoryTexture.h index f059201baa..a3c4f27128 100644 --- a/source/graphics/TerritoryTexture.h +++ b/source/graphics/TerritoryTexture.h @@ -1,4 +1,4 @@ -/* Copyright (C) 2011 Wildfire Games. +/* Copyright (C) 2021 Wildfire Games. * This file is part of 0 A.D. * * 0 A.D. is free software: you can redistribute it and/or modify @@ -52,14 +52,14 @@ public: /** * Returns a matrix to map (x,y,z) world coordinates onto (u,v) texture - * coordinates, in the form expected by glLoadMatrixf. + * coordinates, in the form expected by a matrix uniform. * This must only be called after BindTexture. */ const float* GetTextureMatrix(); /** * Returns a matrix to map (0,0)-(1,1) texture coordinates onto texture - * coordinates, in the form expected by glLoadMatrixf. + * coordinates, in the form expected by a matrix uniform. * This must only be called after BindTexture. */ const CMatrix3D* GetMinimapTextureMatrix(); diff --git a/source/maths/Matrix3D.h b/source/maths/Matrix3D.h index 6972cc5aac..92b77fd8a3 100644 --- a/source/maths/Matrix3D.h +++ b/source/maths/Matrix3D.h @@ -1,4 +1,4 @@ -/* Copyright (C) 2019 Wildfire Games. +/* Copyright (C) 2021 Wildfire Games. * This file is part of 0 A.D. * * 0 A.D. is free software: you can redistribute it and/or modify @@ -181,7 +181,7 @@ public: void SetIdentity(); // set this matrix to the zero matrix void SetZero(); - // set this matrix to the orthogonal projection matrix (as with glOrtho) + // set this matrix to the orthogonal projection matrix void SetOrtho(float left, float right, float bottom, float top, float near, float far); // set this matrix to the perspective projection matrix void SetPerspective(float fov, float aspect, float near, float far); diff --git a/source/maths/Vector3D.h b/source/maths/Vector3D.h index cc2462a7eb..b552c96c4c 100644 --- a/source/maths/Vector3D.h +++ b/source/maths/Vector3D.h @@ -120,8 +120,19 @@ class CVector3D void Normalize(); CVector3D Normalized() const; - // Returns 3 element array of floats, e.g. for glVertex3fv - const float* GetFloatArray() const { return &X; } + // Returns 3 element array of floats, e.g. for vec3 uniforms. + const float* AsFloatArray() const + { + // Additional check to prevent a weird compiler has a different + // alignement for an array and a class members. + static_assert( + sizeof(CVector3D) == sizeof(float) * 3u && + offsetof(CVector3D, X) == 0 && + offsetof(CVector3D, Y) == sizeof(float) && + offsetof(CVector3D, Z) == sizeof(float) * 2u, + "Vector3D should be properly layouted to use AsFloatArray"); + return &X; + } }; extern float MaxComponent(const CVector3D& v); diff --git a/source/soundmanager/items/CSoundBase.cpp b/source/soundmanager/items/CSoundBase.cpp index 7d59ab505e..70fc94b9ed 100644 --- a/source/soundmanager/items/CSoundBase.cpp +++ b/source/soundmanager/items/CSoundBase.cpp @@ -177,7 +177,7 @@ void CSoundBase::SetDirection(const CVector3D& direction) if ( m_ALSource ) { std::lock_guard lock(m_ItemMutex); - alSourcefv(m_ALSource, AL_DIRECTION, direction.GetFloatArray()); + alSourcefv(m_ALSource, AL_DIRECTION, direction.AsFloatArray()); AL_CHECK; } } @@ -212,7 +212,7 @@ void CSoundBase::SetLocation (const CVector3D& position) if ( m_ALSource != 0 ) { std::lock_guard lock(m_ItemMutex); - alSourcefv(m_ALSource,AL_POSITION, position.GetFloatArray()); + alSourcefv(m_ALSource,AL_POSITION, position.AsFloatArray()); AL_CHECK; } }