2009-04-18 19:00:33 +02:00
|
|
|
/* Copyright (C) 2009 Wildfire Games.
|
|
|
|
* This file is part of 0 A.D.
|
|
|
|
*
|
|
|
|
* 0 A.D. is free software: you can redistribute it and/or modify
|
|
|
|
* it under the terms of the GNU General Public License as published by
|
|
|
|
* the Free Software Foundation, either version 2 of the License, or
|
|
|
|
* (at your option) any later version.
|
|
|
|
*
|
|
|
|
* 0 A.D. is distributed in the hope that it will be useful,
|
|
|
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
|
|
* GNU General Public License for more details.
|
|
|
|
*
|
|
|
|
* You should have received a copy of the GNU General Public License
|
|
|
|
* along with 0 A.D. If not, see <http://www.gnu.org/licenses/>.
|
|
|
|
*/
|
|
|
|
|
2007-05-07 18:33:24 +02:00
|
|
|
#ifndef INCLUDED_MATERIAL
|
|
|
|
#define INCLUDED_MATERIAL
|
2004-09-23 06:00:56 +02:00
|
|
|
|
2006-06-02 04:10:27 +02:00
|
|
|
#include "ps/CStr.h"
|
2004-09-23 06:00:56 +02:00
|
|
|
|
2005-04-07 06:29:07 +02:00
|
|
|
struct CColor;
|
|
|
|
|
2004-09-23 06:00:56 +02:00
|
|
|
struct SMaterialColor
|
|
|
|
{
|
|
|
|
public:
|
2005-04-07 06:29:07 +02:00
|
|
|
float r;
|
|
|
|
float g;
|
|
|
|
float b;
|
|
|
|
float a;
|
|
|
|
|
|
|
|
SMaterialColor() : r(0.0f), g(0.0f), b(0.0f), a(1.0f) {}
|
|
|
|
SMaterialColor(float _r, float _g, float _b, float _a)
|
|
|
|
{
|
|
|
|
r = _r;
|
|
|
|
g = _g;
|
|
|
|
b = _b;
|
|
|
|
a = _a;
|
|
|
|
}
|
2008-07-12 12:45:11 +02:00
|
|
|
SMaterialColor(const SMaterialColor& color)
|
2005-04-07 06:29:07 +02:00
|
|
|
{
|
|
|
|
r = color.r;
|
|
|
|
g = color.g;
|
|
|
|
b = color.b;
|
|
|
|
a = color.a;
|
|
|
|
}
|
|
|
|
|
2008-07-12 12:45:11 +02:00
|
|
|
void operator=(const SMaterialColor& color)
|
2005-04-07 06:29:07 +02:00
|
|
|
{
|
|
|
|
r = color.r;
|
|
|
|
g = color.g;
|
|
|
|
b = color.b;
|
|
|
|
a = color.a;
|
|
|
|
}
|
2008-07-12 12:45:11 +02:00
|
|
|
bool operator==(const SMaterialColor& color);
|
2005-04-07 06:29:07 +02:00
|
|
|
|
|
|
|
float Sum()
|
|
|
|
{
|
|
|
|
return (r + g + b + a);
|
|
|
|
}
|
2004-09-23 06:00:56 +02:00
|
|
|
};
|
|
|
|
|
|
|
|
class CMaterial
|
|
|
|
{
|
|
|
|
public:
|
|
|
|
CMaterial();
|
2008-07-12 12:45:11 +02:00
|
|
|
CMaterial(const CMaterial& material);
|
2004-09-23 06:00:56 +02:00
|
|
|
virtual ~CMaterial();
|
|
|
|
|
2004-09-24 05:52:03 +02:00
|
|
|
void Bind();
|
2005-04-07 06:29:07 +02:00
|
|
|
void Unbind();
|
|
|
|
float GetHash() { return m_Hash; }
|
2004-09-23 06:00:56 +02:00
|
|
|
|
2006-07-20 16:37:58 +02:00
|
|
|
const CStr& GetTexture() { return m_Texture; }
|
|
|
|
const CStr& GetVertexProgram() { return m_VertexProgram; }
|
|
|
|
const CStr& GetFragmentProgram() { return m_FragmentProgram; }
|
2004-09-23 06:00:56 +02:00
|
|
|
SMaterialColor GetDiffuse();
|
|
|
|
SMaterialColor GetAmbient();
|
|
|
|
SMaterialColor GetSpecular();
|
|
|
|
SMaterialColor GetEmissive();
|
|
|
|
float GetSpecularPower() { return m_SpecularPower; }
|
2005-01-27 03:52:26 +01:00
|
|
|
|
2004-09-23 06:00:56 +02:00
|
|
|
bool UsesAlpha() { return m_Alpha; }
|
|
|
|
|
2005-04-07 06:29:07 +02:00
|
|
|
// Determines whether or not the model goes into the PlayerRenderer
|
had to remove uint and ulong from lib/types.h due to conflict with other library.
this snowballed into a massive search+destroy of the hodgepodge of
mostly equivalent types we had in use (int, uint, unsigned, unsigned
int, i32, u32, ulong, uintN).
it is more efficient to use 64-bit types in 64-bit mode, so the
preferred default is size_t (for anything remotely resembling a size or
index). tile coordinates are ssize_t to allow more efficient conversion
to/from floating point. flags are int because we almost never need more
than 15 distinct bits, bit test/set is not slower and int is fastest to
type. finally, some data that is pretty much directly passed to OpenGL
is now typed accordingly.
after several hours, the code now requires fewer casts and less
guesswork.
other changes:
- unit and player IDs now have an "invalid id" constant in the
respective class to avoid casting and -1
- fix some endian/64-bit bugs in the map (un)packing. added a
convenience function to write/read a size_t.
- ia32: change CPUID interface to allow passing in ecx (required for
cache topology detection, which I need at work). remove some unneeded
functions from asm, replace with intrinsics where possible.
This was SVN commit r5942.
2008-05-11 20:48:32 +02:00
|
|
|
bool IsPlayer() { return (m_PlayerID != PLAYER_ID_NONE); }
|
2005-04-07 06:29:07 +02:00
|
|
|
// Get the player colour (in a non-zero amount of time, so don't call it
|
|
|
|
// an unreasonable number of times. But it's fairly close to zero, so
|
|
|
|
// don't worry too much about it.)
|
|
|
|
SMaterialColor GetPlayerColor();
|
|
|
|
|
had to remove uint and ulong from lib/types.h due to conflict with other library.
this snowballed into a massive search+destroy of the hodgepodge of
mostly equivalent types we had in use (int, uint, unsigned, unsigned
int, i32, u32, ulong, uintN).
it is more efficient to use 64-bit types in 64-bit mode, so the
preferred default is size_t (for anything remotely resembling a size or
index). tile coordinates are ssize_t to allow more efficient conversion
to/from floating point. flags are int because we almost never need more
than 15 distinct bits, bit test/set is not slower and int is fastest to
type. finally, some data that is pretty much directly passed to OpenGL
is now typed accordingly.
after several hours, the code now requires fewer casts and less
guesswork.
other changes:
- unit and player IDs now have an "invalid id" constant in the
respective class to avoid casting and -1
- fix some endian/64-bit bugs in the map (un)packing. added a
convenience function to write/read a size_t.
- ia32: change CPUID interface to allow passing in ecx (required for
cache topology detection, which I need at work). remove some unneeded
functions from asm, replace with intrinsics where possible.
This was SVN commit r5942.
2008-05-11 20:48:32 +02:00
|
|
|
void SetPlayerColor_PerPlayer() { m_PlayerID = PLAYER_ID_COMING_SOON; }
|
|
|
|
void SetPlayerColor_PerObject() { m_PlayerID = PLAYER_ID_OTHER; }
|
|
|
|
void SetPlayerColor(size_t id);
|
2005-04-07 06:29:07 +02:00
|
|
|
void SetPlayerColor(CColor &colour);
|
|
|
|
|
2006-07-20 16:37:58 +02:00
|
|
|
void SetTexture(const CStr& texture);
|
|
|
|
void SetVertexProgram(const CStr& prog);
|
|
|
|
void SetFragmentProgram(const CStr& prog);
|
2008-07-12 12:45:11 +02:00
|
|
|
void SetDiffuse(const SMaterialColor& color);
|
|
|
|
void SetAmbient(const SMaterialColor& color);
|
|
|
|
void SetSpecular(const SMaterialColor& color);
|
|
|
|
void SetEmissive(const SMaterialColor& color);
|
2005-04-07 06:29:07 +02:00
|
|
|
void SetSpecularPower(float power);
|
|
|
|
void SetUsesAlpha(bool flag);
|
|
|
|
|
2008-07-12 12:45:11 +02:00
|
|
|
void operator=(const CMaterial& material);
|
|
|
|
bool operator==(const CMaterial& material);
|
2004-09-23 06:00:56 +02:00
|
|
|
protected:
|
2005-04-07 06:29:07 +02:00
|
|
|
void ComputeHash();
|
2004-09-24 05:52:03 +02:00
|
|
|
|
2005-04-07 06:29:07 +02:00
|
|
|
float m_Hash;
|
2004-09-24 05:52:03 +02:00
|
|
|
|
2004-09-23 06:00:56 +02:00
|
|
|
// Various reflective color properties
|
2004-09-24 05:52:03 +02:00
|
|
|
SMaterialColor m_Diffuse;
|
|
|
|
SMaterialColor m_Ambient;
|
|
|
|
SMaterialColor m_Specular;
|
|
|
|
SMaterialColor m_Emissive;
|
2004-09-23 06:00:56 +02:00
|
|
|
float m_SpecularPower;
|
|
|
|
|
|
|
|
// Path to the materials texture
|
|
|
|
CStr m_Texture;
|
|
|
|
|
2005-04-07 06:29:07 +02:00
|
|
|
// Paths to vertex/fragment programs
|
|
|
|
CStr m_VertexProgram;
|
|
|
|
CStr m_FragmentProgram;
|
2004-10-30 23:57:46 +02:00
|
|
|
|
2004-09-23 06:00:56 +02:00
|
|
|
// Alpha required flag
|
|
|
|
bool m_Alpha;
|
2005-01-27 03:52:26 +01:00
|
|
|
|
2005-04-07 06:29:07 +02:00
|
|
|
// Player-colour settings.
|
had to remove uint and ulong from lib/types.h due to conflict with other library.
this snowballed into a massive search+destroy of the hodgepodge of
mostly equivalent types we had in use (int, uint, unsigned, unsigned
int, i32, u32, ulong, uintN).
it is more efficient to use 64-bit types in 64-bit mode, so the
preferred default is size_t (for anything remotely resembling a size or
index). tile coordinates are ssize_t to allow more efficient conversion
to/from floating point. flags are int because we almost never need more
than 15 distinct bits, bit test/set is not slower and int is fastest to
type. finally, some data that is pretty much directly passed to OpenGL
is now typed accordingly.
after several hours, the code now requires fewer casts and less
guesswork.
other changes:
- unit and player IDs now have an "invalid id" constant in the
respective class to avoid casting and -1
- fix some endian/64-bit bugs in the map (un)packing. added a
convenience function to write/read a size_t.
- ia32: change CPUID interface to allow passing in ecx (required for
cache topology detection, which I need at work). remove some unneeded
functions from asm, replace with intrinsics where possible.
This was SVN commit r5942.
2008-05-11 20:48:32 +02:00
|
|
|
// If m_PlayerID <= PLAYER_ID_LAST_VALID, the colour is retrieved from
|
|
|
|
// g_Game whenever it's needed.
|
2005-04-07 06:29:07 +02:00
|
|
|
// (It's not cached, because the player might change colour.)
|
had to remove uint and ulong from lib/types.h due to conflict with other library.
this snowballed into a massive search+destroy of the hodgepodge of
mostly equivalent types we had in use (int, uint, unsigned, unsigned
int, i32, u32, ulong, uintN).
it is more efficient to use 64-bit types in 64-bit mode, so the
preferred default is size_t (for anything remotely resembling a size or
index). tile coordinates are ssize_t to allow more efficient conversion
to/from floating point. flags are int because we almost never need more
than 15 distinct bits, bit test/set is not slower and int is fastest to
type. finally, some data that is pretty much directly passed to OpenGL
is now typed accordingly.
after several hours, the code now requires fewer casts and less
guesswork.
other changes:
- unit and player IDs now have an "invalid id" constant in the
respective class to avoid casting and -1
- fix some endian/64-bit bugs in the map (un)packing. added a
convenience function to write/read a size_t.
- ia32: change CPUID interface to allow passing in ecx (required for
cache topology detection, which I need at work). remove some unneeded
functions from asm, replace with intrinsics where possible.
This was SVN commit r5942.
2008-05-11 20:48:32 +02:00
|
|
|
// If m_PlayerID == PLAYER_ID_OTHER, or if player-colouring has been globally
|
2005-04-07 06:29:07 +02:00
|
|
|
// disabled, m_TextureColor is used instead. This allows per-model colours to
|
|
|
|
// be specified, instead of only a single colour per player.
|
had to remove uint and ulong from lib/types.h due to conflict with other library.
this snowballed into a massive search+destroy of the hodgepodge of
mostly equivalent types we had in use (int, uint, unsigned, unsigned
int, i32, u32, ulong, uintN).
it is more efficient to use 64-bit types in 64-bit mode, so the
preferred default is size_t (for anything remotely resembling a size or
index). tile coordinates are ssize_t to allow more efficient conversion
to/from floating point. flags are int because we almost never need more
than 15 distinct bits, bit test/set is not slower and int is fastest to
type. finally, some data that is pretty much directly passed to OpenGL
is now typed accordingly.
after several hours, the code now requires fewer casts and less
guesswork.
other changes:
- unit and player IDs now have an "invalid id" constant in the
respective class to avoid casting and -1
- fix some endian/64-bit bugs in the map (un)packing. added a
convenience function to write/read a size_t.
- ia32: change CPUID interface to allow passing in ecx (required for
cache topology detection, which I need at work). remove some unneeded
functions from asm, replace with intrinsics where possible.
This was SVN commit r5942.
2008-05-11 20:48:32 +02:00
|
|
|
// If m_PlayerID == PLAYER_ID_NONE, there's no player colour at all.
|
|
|
|
// If m_PlayerID == PLAYER_ID_COMING_SOON, it's going to be linked to a player,
|
2005-04-07 06:29:07 +02:00
|
|
|
// but hasn't yet.
|
had to remove uint and ulong from lib/types.h due to conflict with other library.
this snowballed into a massive search+destroy of the hodgepodge of
mostly equivalent types we had in use (int, uint, unsigned, unsigned
int, i32, u32, ulong, uintN).
it is more efficient to use 64-bit types in 64-bit mode, so the
preferred default is size_t (for anything remotely resembling a size or
index). tile coordinates are ssize_t to allow more efficient conversion
to/from floating point. flags are int because we almost never need more
than 15 distinct bits, bit test/set is not slower and int is fastest to
type. finally, some data that is pretty much directly passed to OpenGL
is now typed accordingly.
after several hours, the code now requires fewer casts and less
guesswork.
other changes:
- unit and player IDs now have an "invalid id" constant in the
respective class to avoid casting and -1
- fix some endian/64-bit bugs in the map (un)packing. added a
convenience function to write/read a size_t.
- ia32: change CPUID interface to allow passing in ecx (required for
cache topology detection, which I need at work). remove some unneeded
functions from asm, replace with intrinsics where possible.
This was SVN commit r5942.
2008-05-11 20:48:32 +02:00
|
|
|
static const size_t PLAYER_ID_NONE = SIZE_MAX-1;
|
|
|
|
static const size_t PLAYER_ID_OTHER = SIZE_MAX-2;
|
|
|
|
static const size_t PLAYER_ID_COMING_SOON = SIZE_MAX-3;
|
|
|
|
static const size_t PLAYER_ID_LAST_VALID = SIZE_MAX-4;
|
|
|
|
size_t m_PlayerID;
|
2005-04-07 06:29:07 +02:00
|
|
|
SMaterialColor m_TextureColor; // used as an alternative to the per-player colour
|
2004-09-23 06:00:56 +02:00
|
|
|
};
|
|
|
|
|
2004-09-23 07:10:03 +02:00
|
|
|
extern CMaterial NullMaterial;
|
|
|
|
extern CMaterial IdentityMaterial;
|
|
|
|
|
2004-09-26 23:21:34 +02:00
|
|
|
#endif
|