2011-02-03 02:12:24 +01:00
|
|
|
/* Copyright (C) 2011 Wildfire Games.
|
2009-04-18 19:00:33 +02:00
|
|
|
* 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();
|
|
|
|
void RenderOutline();
|
2011-02-03 15:36:54 +01:00
|
|
|
void RenderSides();
|
2011-01-29 17:31:48 +01:00
|
|
|
void RenderPriorities();
|
2004-06-11 00:24:03 +02:00
|
|
|
|
2011-03-13 20:06:33 +01:00
|
|
|
static void RenderBases(const std::vector<CPatchRData*>& patches);
|
|
|
|
static void RenderBlends(const std::vector<CPatchRData*>& patches);
|
|
|
|
static void RenderStreams(const std::vector<CPatchRData*>& patches, int streamflags);
|
|
|
|
|
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];
|
2011-03-13 20:06:33 +01:00
|
|
|
// add some padding since VBOs prefer power-of-two sizes
|
|
|
|
u32 m_Padding[2];
|
2006-02-13 15:18:20 +01:00
|
|
|
};
|
2011-03-13 20:06:33 +01:00
|
|
|
cassert(sizeof(SBaseVertex) == 32);
|
2004-06-11 00:24:03 +02:00
|
|
|
|
2011-02-03 15:36:54 +01:00
|
|
|
struct SSideVertex {
|
|
|
|
// vertex position
|
|
|
|
CVector3D m_Position;
|
2011-03-13 20:06:33 +01:00
|
|
|
// add some padding
|
|
|
|
u32 m_Padding[1];
|
2011-02-03 15:36:54 +01:00
|
|
|
};
|
2011-03-13 20:06:33 +01:00
|
|
|
cassert(sizeof(SSideVertex) == 16);
|
2011-02-03 15:36:54 +01:00
|
|
|
|
2004-06-11 00:24:03 +02:00
|
|
|
struct SBlendVertex {
|
|
|
|
// vertex position
|
|
|
|
CVector3D m_Position;
|
|
|
|
// vertex uvs for base texture
|
|
|
|
float m_UVs[2];
|
|
|
|
// vertex uvs for alpha texture
|
|
|
|
float m_AlphaUVs[2];
|
2011-03-13 20:06:33 +01:00
|
|
|
// add some padding
|
|
|
|
u32 m_Padding[1];
|
2006-02-13 15:18:20 +01:00
|
|
|
};
|
2011-03-13 20:06:33 +01:00
|
|
|
cassert(sizeof(SBlendVertex) == 32);
|
2004-06-11 00:24:03 +02:00
|
|
|
|
2004-05-29 22:53:40 +02:00
|
|
|
// build this renderdata object
|
|
|
|
void Build();
|
|
|
|
|
2011-03-13 20:10:38 +01:00
|
|
|
void AddBlend(std::vector<SBlendVertex>& blendVertices, std::vector<u16>& blendIndices, u16 i, u16 j, u8 shape);
|
2011-01-29 17:31:48 +01:00
|
|
|
|
2004-05-29 22:53:40 +02:00
|
|
|
void BuildBlends();
|
|
|
|
void BuildIndices();
|
|
|
|
void BuildVertices();
|
2011-02-03 15:36:54 +01:00
|
|
|
void BuildSides();
|
|
|
|
|
|
|
|
void BuildSide(std::vector<SSideVertex>& vertices, CPatchSideFlags side);
|
2004-05-29 22:53:40 +02:00
|
|
|
|
|
|
|
// owner patch
|
|
|
|
CPatch* m_Patch;
|
2005-10-09 10:14:42 +02:00
|
|
|
|
2011-03-13 20:10:38 +01:00
|
|
|
// vertex buffer handle for side vertices
|
|
|
|
CVertexBuffer::VBChunk* m_VBSides;
|
|
|
|
|
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
|
|
|
|
2011-03-13 20:06:33 +01:00
|
|
|
// vertex buffer handle for base vertex indices
|
|
|
|
CVertexBuffer::VBChunk* m_VBBaseIndices;
|
|
|
|
|
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
|
|
|
|
2011-03-13 20:10:38 +01:00
|
|
|
// vertex buffer handle for blend vertex indices
|
|
|
|
CVertexBuffer::VBChunk* m_VBBlendIndices;
|
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
|
|
|
// 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
|