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_PATCHRDATA
|
|
|
|
#define INCLUDED_PATCHRDATA
|
2004-05-29 22:53:40 +02:00
|
|
|
|
|
|
|
#include <vector>
|
2006-09-26 03:44:20 +02:00
|
|
|
#include "graphics/SColor.h"
|
2006-06-02 04:10:27 +02:00
|
|
|
#include "maths/Vector3D.h"
|
|
|
|
#include "graphics/RenderableObject.h"
|
2004-06-11 00:24:03 +02:00
|
|
|
#include "VertexBufferManager.h"
|
2004-05-29 22:53:40 +02:00
|
|
|
|
|
|
|
class CPatch;
|
2010-09-10 23:02:10 +02:00
|
|
|
class CTerrainTextureEntry;
|
2004-06-11 00:24:03 +02:00
|
|
|
|
|
|
|
//////////////////////////////////////////////////////////////////////////////////////////////////
|
|
|
|
// CPatchRData: class encapsulating logic for rendering terrain patches; holds per
|
2004-06-07 21:53:58 +02:00
|
|
|
// patch data, plus some supporting static functions for batching, etc
|
2004-05-29 22:53:40 +02:00
|
|
|
class CPatchRData : public CRenderData
|
|
|
|
{
|
|
|
|
public:
|
2006-01-07 02:04:26 +01:00
|
|
|
CPatchRData(CPatch* patch);
|
|
|
|
~CPatchRData();
|
2004-05-29 22:53:40 +02:00
|
|
|
|
|
|
|
void Update();
|
2006-02-13 15:18:20 +01:00
|
|
|
void RenderBase(bool losColor);
|
2004-05-29 22:53:40 +02:00
|
|
|
void RenderBlends();
|
|
|
|
void RenderOutline();
|
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 RenderStreams(int streamflags, bool losColor);
|
2011-01-29 17:31:48 +01:00
|
|
|
void RenderPriorities();
|
2004-06-11 00:24:03 +02:00
|
|
|
|
2004-05-29 22:53:40 +02:00
|
|
|
private:
|
2004-06-11 00:24:03 +02:00
|
|
|
struct SSplat {
|
2006-02-13 15:18:20 +01:00
|
|
|
SSplat() : m_Texture(0), m_IndexCount(0) {}
|
2004-06-11 00:24:03 +02:00
|
|
|
|
2010-09-10 23:02:10 +02:00
|
|
|
// texture to apply during splat
|
|
|
|
CTerrainTextureEntry* m_Texture;
|
2004-06-11 00:24:03 +02:00
|
|
|
// offset into the index array for this patch where splat starts
|
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
|
|
|
size_t m_IndexStart;
|
2004-06-11 00:24:03 +02:00
|
|
|
// number of indices used by splat
|
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
|
|
|
size_t m_IndexCount;
|
2004-06-11 00:24:03 +02:00
|
|
|
};
|
|
|
|
|
|
|
|
struct SBaseVertex {
|
|
|
|
// vertex position
|
|
|
|
CVector3D m_Position;
|
2006-02-13 15:18:20 +01:00
|
|
|
// diffuse color from sunlight
|
|
|
|
SColor4ub m_DiffuseColor;
|
2004-06-11 00:24:03 +02:00
|
|
|
// vertex uvs for base texture
|
|
|
|
float m_UVs[2];
|
2006-02-13 15:18:20 +01:00
|
|
|
// color modulation from LOS
|
|
|
|
SColor4ub m_LOSColor;
|
|
|
|
};
|
2004-06-11 00:24:03 +02:00
|
|
|
|
|
|
|
struct SBlendVertex {
|
|
|
|
// vertex position
|
|
|
|
CVector3D m_Position;
|
2006-02-13 15:18:20 +01:00
|
|
|
// color modulation from LOS
|
|
|
|
SColor4ub m_LOSColor;
|
2004-06-11 00:24:03 +02:00
|
|
|
// vertex uvs for base texture
|
|
|
|
float m_UVs[2];
|
|
|
|
// vertex uvs for alpha texture
|
|
|
|
float m_AlphaUVs[2];
|
2006-02-13 15:18:20 +01:00
|
|
|
};
|
2004-06-11 00:24:03 +02:00
|
|
|
|
|
|
|
struct STex {
|
2010-09-10 23:02:10 +02:00
|
|
|
bool operator==(const STex& rhs) const { return m_Texture==rhs.m_Texture; }
|
2004-06-11 00:24:03 +02:00
|
|
|
bool operator<(const STex& rhs) const { return m_Priority<rhs.m_Priority; }
|
2010-09-10 23:02:10 +02:00
|
|
|
CTerrainTextureEntry* m_Texture;
|
2004-06-11 00:24:03 +02:00
|
|
|
int m_Priority;
|
|
|
|
};
|
2006-02-13 15:18:20 +01:00
|
|
|
|
2004-05-29 22:53:40 +02:00
|
|
|
// build this renderdata object
|
|
|
|
void Build();
|
|
|
|
|
2011-01-29 17:31:48 +01:00
|
|
|
ssize_t AddBlend(u16 i, u16 j, u8 shape);
|
|
|
|
|
2004-05-29 22:53:40 +02:00
|
|
|
void BuildBlends();
|
|
|
|
void BuildIndices();
|
|
|
|
void BuildVertices();
|
|
|
|
|
|
|
|
// owner patch
|
|
|
|
CPatch* m_Patch;
|
2005-10-09 10:14:42 +02:00
|
|
|
|
2004-05-29 22:53:40 +02:00
|
|
|
// vertex buffer handle for base vertices
|
2004-06-07 21:53:58 +02:00
|
|
|
CVertexBuffer::VBChunk* m_VBBase;
|
2005-10-09 10:14:42 +02:00
|
|
|
|
2004-05-29 22:53:40 +02:00
|
|
|
// vertex buffer handle for blend vertices
|
2004-06-07 21:53:58 +02:00
|
|
|
CVertexBuffer::VBChunk* m_VBBlends;
|
2005-10-09 10:14:42 +02:00
|
|
|
|
2004-05-29 22:53:40 +02:00
|
|
|
// patch render vertices
|
|
|
|
SBaseVertex* m_Vertices;
|
2005-10-09 10:14:42 +02:00
|
|
|
|
2004-06-07 21:53:58 +02:00
|
|
|
// indices into base vertices for the base splats
|
2004-05-29 22:53:40 +02:00
|
|
|
std::vector<unsigned short> m_Indices;
|
2005-10-09 10:14:42 +02:00
|
|
|
|
2004-06-11 00:24:03 +02:00
|
|
|
// indices into base vertices for the shadow map pass
|
|
|
|
std::vector<unsigned short> m_ShadowMapIndices;
|
2005-10-09 10:14:42 +02:00
|
|
|
|
2004-05-29 22:53:40 +02:00
|
|
|
// list of base splats to apply to this patch
|
|
|
|
std::vector<SSplat> m_Splats;
|
2005-10-09 10:14:42 +02:00
|
|
|
|
2004-05-29 22:53:40 +02:00
|
|
|
// vertices to use for blending transition texture passes
|
|
|
|
std::vector<SBlendVertex> m_BlendVertices;
|
2005-10-09 10:14:42 +02:00
|
|
|
|
|
|
|
// remembers the index in the m_Vertices array of each blend vertex, so that we can
|
|
|
|
// properly update its color for fog of war and shroud of darkness
|
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
|
|
|
std::vector<size_t> m_BlendVertexIndices;
|
2005-10-09 10:14:42 +02:00
|
|
|
|
2004-05-29 22:53:40 +02:00
|
|
|
// indices into blend vertices for the blend splats
|
|
|
|
std::vector<unsigned short> m_BlendIndices;
|
2005-10-09 10:14:42 +02:00
|
|
|
|
2004-05-29 22:53:40 +02:00
|
|
|
// splats used in blend pass
|
2004-06-11 00:24:03 +02:00
|
|
|
std::vector<SSplat> m_BlendSplats;
|
2004-05-29 22:53:40 +02:00
|
|
|
};
|
|
|
|
|
|
|
|
|
|
|
|
#endif
|