18 #include "precompiled.h"
22 #include <boost/unordered_map.hpp>
82 typedef boost::unordered_map<QuadBatchKey, QuadBatchData>
QuadBatchMap;
87 std::vector<SOverlayLine*>
lines;
90 std::vector<SOverlayQuad*>
quads;
123 : quadVertices(GL_DYNAMIC_DRAW), quadIndices(GL_DYNAMIC_DRAW)
223 m->
quads.push_back(overlay);
252 for (
size_t i = 0; i <
m->
texlines.size(); ++i)
268 for (
size_t i = 0; i <
m->
quads.size(); ++i)
276 batchRenderData.
m_Quads.push_back(quad);
286 size_t indicesIdx = 0;
287 size_t totalNumQuads = 0;
294 if (batchRenderData.
m_Quads.empty())
309 *vertexPos++ = quad->
m_Corners[0] + vOffset;
310 *vertexPos++ = quad->
m_Corners[1] + vOffset;
311 *vertexPos++ = quad->
m_Corners[2] + vOffset;
312 *vertexPos++ = quad->
m_Corners[3] + vOffset;
327 *vertexColor++ = quadColor;
328 *vertexColor++ = quadColor;
329 *vertexColor++ = quadColor;
330 *vertexColor++ = quadColor;
348 #warning TODO: implement OverlayRenderer::RenderOverlaysBeforeWater for GLES
350 pglActiveTextureARB(GL_TEXTURE0);
351 glDisable(GL_TEXTURE_2D);
356 glDepthFunc(GL_ALWAYS);
358 for (
size_t i = 0; i <
m->
lines.size(); ++i)
369 glInterleavedArrays(GL_V3F,
sizeof(
float)*3, &line->
m_Coords[0]);
370 glDrawArrays(GL_LINE_STRIP, 0, (GLsizei)line->
m_Coords.size()/3);
373 glDisableClientState(GL_VERTEX_ARRAY);
376 glDepthFunc(GL_LEQUAL);
392 #warning TODO: implement OverlayRenderer::RenderTexturedOverlayLines for GLES
400 glEnable(GL_TEXTURE_2D);
404 const char* shaderName;
406 shaderName =
"arb/overlayline";
408 shaderName =
"fixed:overlayline";
418 if (shaderTexLineNormal)
420 shaderTexLineNormal->Bind();
421 shaderTexLineNormal->BindTexture(str_losTex, los.
GetTexture());
427 shaderTexLineNormal->Unbind();
432 if (shaderTexLineAlwaysVisible)
434 shaderTexLineAlwaysVisible->Bind();
436 shaderTexLineAlwaysVisible->BindTexture(str_losTex, los.
GetTexture());
442 shaderTexLineAlwaysVisible->Unbind();
459 for (
size_t i = 0; i <
m->
texlines.size(); ++i)
479 glEnable(GL_TEXTURE_2D);
483 const char* shaderName;
485 shaderName =
"arb/overlayline";
487 shaderName =
"fixed:overlayline";
499 shader->BindTexture(str_losTex, los.
GetTexture());
514 if (batchNumQuads == 0)
519 shader->BindTexture(str_baseTex, maskPair.
m_Texture->GetHandle());
520 shader->BindTexture(str_maskTex, maskPair.
m_TextureMask->GetHandle());
522 int streamflags = shader->GetStreamFlags();
536 shader->AssertPointersBound();
537 glDrawElements(GL_TRIANGLES, (GLsizei)(batchNumQuads * 6), GL_UNSIGNED_SHORT, indexBase + indexStride * batchRenderData.
m_IndicesBase);
540 g_Renderer.GetStats().m_OverlayTris += batchNumQuads*2;
563 #warning TODO: implement OverlayRenderer::RenderForegroundOverlays for GLES
565 glEnable(GL_TEXTURE_2D);
567 glDisable(GL_DEPTH_TEST);
572 glColor4f(1.0f, 1.0f, 1.0f, 1.0f);
574 glEnableClientState(GL_VERTEX_ARRAY);
575 glEnableClientState(GL_TEXTURE_COORD_ARRAY);
582 tech =
g_Renderer.GetShaderManager().LoadEffect(str_foreground_overlay);
584 shader = tech->GetShader();
587 float uvs[8] = { 0,0, 1,0, 1,1, 0,1 };
590 shader->TexCoordPointer(GL_TEXTURE0, 2, GL_FLOAT,
sizeof(
float)*2, &uvs[0]);
592 glTexCoordPointer(2, GL_FLOAT,
sizeof(
float)*2, &uvs);
594 for (
size_t i = 0; i <
m->
sprites.size(); ++i)
599 shader->BindTexture(str_baseTex, sprite->
m_Texture);
611 shader->VertexPointer(3, GL_FLOAT,
sizeof(
float)*3, &pos[0].
X);
613 glVertexPointer(3, GL_FLOAT,
sizeof(
float)*3, &pos[0].
X);
615 glDrawArrays(GL_QUADS, 0, (GLsizei)4);
624 glDisableClientState(GL_VERTEX_ARRAY);
625 glDisableClientState(GL_TEXTURE_COORD_ARRAY);
627 glEnable(GL_DEPTH_TEST);
629 glDisable(GL_TEXTURE_2D);
void Add(CStrIntern name, CStrIntern value)
Add a name and associated value to the map of defines.
OverlayRendererInternals()
std::vector< SOverlayQuad * > m_Quads
Holds the quad overlay structures requested to be rendered in this batch.
size_t m_IndicesBase
Start index of this batch into the dedicated quad indices VertexArray (see OverlayInternals).
VertexArray::Attribute quadAttributeColor
Line-based overlay, with world-space coordinates, rendered in the world potentially behind other obje...
CShaderDefines defsQuadOverlay
void Initialize()
Performs one-time setup.
CShaderDefines defsOverlayLineNormal
size_t m_NumRenderQuads
Amount of quads to actually render in this batch.
VertexArrayIterator< u16 > GetIterator() const
Gets the iterator over the (only) attribute in this array, i.e. a u16.
size_t hash_value(const CStrIntern &v)
bool operator==(const QuadBatchKey &other) const
bool m_AlwaysVisible
Should this line be rendered fully visible at all times, even under the SoD?
void AddAttribute(Attribute *attr)
shared_ptr< CShaderTechnique > CShaderTechniquePtr
std::vector< SOverlayLine * > lines
void RenderQuadOverlays()
Helper method; batch-renders all registered quad overlays, batched by their texture for effiency...
Billboard sprite overlay, with world-space coordinates, rendered on top of all other objects...
CTexturePtr m_TextureMask
void Submit(SOverlayLine *overlay)
Add a line overlay for rendering in this frame.
A VertexArray that is specialised to handle 16-bit array indices.
void EndFrame()
Reset the list of submitted overlays.
std::vector< SOverlayQuad * > quads
std::vector< SOverlaySprite * > sprites
std::vector< float > m_Coords
#define ENSURE(expr)
ensure the expression <expr> evaluates to non-zero.
Textured line overlay, with world-space coordinates, rendered in the world onto the terrain...
Holds information about a single quad rendering batch.
void Initialize()
Performs one-time initialization.
std::vector< SOverlayTexturedLine * > texlines
GLuint GetTexture()
Recomputes the LOS texture if necessary, and returns the texture handle.
void SetNumVertices(size_t num)
Rendering data for an STexturedOverlayLine.
CShaderDefines defsOverlayLineAlwaysVisible
VertexArray::Attribute quadAttributePos
std::vector< float > m_Coords
(x, z) vertex coordinate pairs; y is computed automatically.
Key used to group quads into batches for more efficient rendering.
VertexArrayIterator< T > GetIterator() const
Represents a mapping of name strings to value strings, for use with #if and #ifdef and similar condit...
void RenderForegroundOverlays(const CCamera &viewCamera)
Render all the submitted overlays that should appear on top of everything in the world.
QuadBatchKey(const CTexturePtr &texture, const CTexturePtr &textureMask)
Rectangular single-quad terrain overlay, in world space coordinates.
VertexArray::Attribute quadAttributeUV
void RenderOverlaysAfterWater()
Render all the submitted overlays that are embedded in the world (i.e.
const float * FloatArray() const
~OverlayRendererInternals()
CVector3D GetLeft() const
boost::unordered_map< QuadBatchKey, QuadBatchData > QuadBatchMap
Maintains the LOS (fog-of-war / shroud-of-darkness) texture, used for rendering and for the minimap...
OverlayRendererInternals * m
VertexIndexArray quadIndices
void ogl_WarnIfError()
raise a warning (break into the debugger) if an OpenGL error is pending.
#define PROFILE3_GPU(name)
CShaderProgramPtr LoadProgram(const char *name, const CShaderDefines &defines)
Load a shader program.
const CMatrix3D & GetTextureMatrix()
Returns a matrix to map (x,y,z) world coordinates onto (u,v) LOS texture coordinates, in the form expected by glLoadMatrixf.
static void Unbind()
Unbind any currently-bound buffer, so glVertexPointer etc calls will not attempt to use it...
static const float OVERLAY_VOFFSET
Small vertical offset of overlays from terrain to prevent visual glitches.
void RenderOverlaysBeforeWater()
Render all the submitted overlays that are embedded in the world (i.e.
QuadBatchMap quadBatchMap
shared_ptr< CShaderProgram > CShaderProgramPtr
void PrepareForRendering()
Prepare internal data structures for rendering.
shared_ptr< CTexturedLineRData > m_RenderData
Cached renderer data, because expensive to compute.
Shader manager: loads and caches shader programs.
CTexturePtr m_TextureMask
static const size_t MAX_QUAD_OVERLAYS
Maximum amount of quad overlays we support for rendering.
shared_ptr< CTexture > CTexturePtr
void RenderTexturedOverlayLines()
Helper method; renders all overlay lines currently registered in the internals.