1
0
forked from 0ad/0ad

Removes mentions of legacy and unused GL calls, unifies AsFloatArray.

This was SVN commit r25961.
This commit is contained in:
Vladislav Belov 2021-10-11 12:39:01 +00:00
parent 9ee448b377
commit 31a6ffdd3a
6 changed files with 36 additions and 13 deletions

View File

@ -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

View File

@ -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();

View File

@ -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();

View File

@ -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);

View File

@ -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);

View File

@ -177,7 +177,7 @@ void CSoundBase::SetDirection(const CVector3D& direction)
if ( m_ALSource )
{
std::lock_guard<std::mutex> 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<std::mutex> lock(m_ItemMutex);
alSourcefv(m_ALSource,AL_POSITION, position.GetFloatArray());
alSourcefv(m_ALSource,AL_POSITION, position.AsFloatArray());
AL_CHECK;
}
}