OpenClonk
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros
C4FoWDrawWireframeStrategy Class Reference

#include <C4FoWDrawStrategy.h>

Inheritance diagram for C4FoWDrawWireframeStrategy:
[legend]
Collaboration diagram for C4FoWDrawWireframeStrategy:
[legend]

Public Types

enum  DrawPhase {
  P_None, P_Fan, P_FanMaxed, P_Fade,
  P_Intermediate
}
 

Public Member Functions

 C4FoWDrawWireframeStrategy (const C4FoWLight *light, const C4TargetFacet *screen)
 
virtual ~C4FoWDrawWireframeStrategy ()
 
virtual void DrawLightVertex (float x, float y)
 
virtual void DrawDarkVertex (float x, float y)
 
virtual void Begin (const C4FoWRegion *region)
 
virtual void End (C4ShaderCall &call)
 
virtual void BeginFan ()
 
virtual void EndFan ()
 
virtual void BeginFanMaxed ()
 
virtual void EndFanMaxed ()
 
virtual void BeginFade ()
 
virtual void EndFade ()
 
virtual void BeginIntermediateFade ()
 
virtual void EndIntermediateFade ()
 

Public Attributes

enum C4FoWDrawStrategy::DrawPhase phase
 

Protected Attributes

C4FoWDrawTriangulator triangulator
 

Detailed Description

This draw strategy is the debug draw strategy (press Ctrl+F7,...) that draws a wireframe of the light triangles (except the inner fan, but you can change that in the code below) directly onto the screen.

Definition at line 154 of file C4FoWDrawStrategy.h.

Member Enumeration Documentation

Enumerator
P_None 
P_Fan 
P_FanMaxed 
P_Fade 
P_Intermediate 

Definition at line 76 of file C4FoWDrawStrategy.h.

Constructor & Destructor Documentation

C4FoWDrawWireframeStrategy::C4FoWDrawWireframeStrategy ( const C4FoWLight light,
const C4TargetFacet screen 
)

Definition at line 345 of file C4FoWDrawStrategy.cpp.

References CStdGL::GenVAOID(), and pGL.

345  :
346  light(light), screen(screen), vbo_size(0), ibo_size(0)
347 {
348  glGenBuffers(2, bo);
349  vaoid = pGL->GenVAOID();
350 }
unsigned int GenVAOID()
Definition: C4DrawGL.cpp:934
CStdGL * pGL
Definition: C4DrawGL.cpp:914

Here is the call graph for this function:

C4FoWDrawWireframeStrategy::~C4FoWDrawWireframeStrategy ( )
virtual

Definition at line 352 of file C4FoWDrawStrategy.cpp.

References CStdGL::FreeVAOID(), and pGL.

353 {
354  glDeleteBuffers(2, bo);
355  pGL->FreeVAOID(vaoid);
356 }
void FreeVAOID(unsigned int vaoid)
Definition: C4DrawGL.cpp:976
CStdGL * pGL
Definition: C4DrawGL.cpp:914

Here is the call graph for this function:

Member Function Documentation

void C4FoWDrawWireframeStrategy::Begin ( const C4FoWRegion region)
virtual

Called before each rendering pass

Implements C4FoWDrawStrategy.

Definition at line 358 of file C4FoWDrawStrategy.cpp.

359 {
360 }
virtual void C4FoWDrawStrategy::BeginFade ( )
inlinevirtualinherited

Called before rendering the quads in which the light fades out

Definition at line 103 of file C4FoWDrawStrategy.h.

References C4FoWDrawStrategy::P_Fade, C4FoWDrawStrategy::phase, C4FoWDrawTriangulator::Quads(), and C4FoWDrawStrategy::triangulator.

103 { triangulator.Quads(); phase = P_Fade; };
enum C4FoWDrawStrategy::DrawPhase phase
C4FoWDrawTriangulator triangulator

Here is the call graph for this function:

virtual void C4FoWDrawStrategy::BeginFan ( )
inlinevirtualinherited

Called before rendering the inner triangle fan (the area with 100% light)

Definition at line 93 of file C4FoWDrawStrategy.h.

References C4FoWDrawTriangulator::Fan(), C4FoWDrawStrategy::P_Fan, C4FoWDrawStrategy::phase, and C4FoWDrawStrategy::triangulator.

93 { triangulator.Fan(); phase = P_Fan; };
enum C4FoWDrawStrategy::DrawPhase phase
C4FoWDrawTriangulator triangulator

Here is the call graph for this function:

virtual void C4FoWDrawStrategy::BeginFanMaxed ( )
inlinevirtualinherited

Called before rendering the triangle fan existnsion (100% light, maxed out normals)

Definition at line 98 of file C4FoWDrawStrategy.h.

References C4FoWDrawStrategy::P_FanMaxed, C4FoWDrawStrategy::phase, C4FoWDrawTriangulator::Quads(), and C4FoWDrawStrategy::triangulator.

enum C4FoWDrawStrategy::DrawPhase phase
C4FoWDrawTriangulator triangulator

Here is the call graph for this function:

virtual void C4FoWDrawStrategy::BeginIntermediateFade ( )
inlinevirtualinherited

Called before rendering the triangles that fill the space between the fadeout quads

Definition at line 108 of file C4FoWDrawStrategy.h.

References C4FoWDrawTriangulator::Fan(), C4FoWDrawStrategy::P_Intermediate, C4FoWDrawStrategy::phase, and C4FoWDrawStrategy::triangulator.

Here is the call graph for this function:

void C4FoWDrawWireframeStrategy::DrawDarkVertex ( float  x,
float  y 
)
virtual

Reimplemented from C4FoWDrawStrategy.

Definition at line 436 of file C4FoWDrawStrategy.cpp.

References C4FoWDrawStrategy::DrawDarkVertex(), C4FoWDrawStrategy::P_Fade, C4FoWDrawStrategy::P_Intermediate, C4FoWDrawStrategy::P_None, and C4FoWDrawStrategy::phase.

437 {
438  vertices.emplace_back();
439  Vertex& vtx = vertices.back();
440  vtx.x = x; vtx.y = y;
441 
442  switch(phase)
443  {
444  case P_None: return;
445  case P_Fade: vtx.r = 0.0f; vtx.g = 0.5f; vtx.b = 0.0f; vtx.a = 1.0f; break;
446  case P_Intermediate: vtx.r = 0.0f; vtx.g = 0.0f; vtx.b = 0.5f; vtx.a = 1.0f; break;
447  default: assert(false); // only fade has dark vertices
448  }
449 
450  DrawVertex(vtx);
452 }
enum C4FoWDrawStrategy::DrawPhase phase
virtual void DrawDarkVertex(float x, float y)

Here is the call graph for this function:

void C4FoWDrawWireframeStrategy::DrawLightVertex ( float  x,
float  y 
)
virtual

Reimplemented from C4FoWDrawStrategy.

Definition at line 454 of file C4FoWDrawStrategy.cpp.

References C4FoWDrawStrategy::DrawLightVertex(), C4FoWDrawStrategy::P_Fade, C4FoWDrawStrategy::P_Fan, C4FoWDrawStrategy::P_FanMaxed, C4FoWDrawStrategy::P_Intermediate, C4FoWDrawStrategy::P_None, and C4FoWDrawStrategy::phase.

455 {
456  vertices.emplace_back();
457  Vertex& vtx = vertices.back();
458  vtx.x = x; vtx.y = y;
459 
460  switch(phase)
461  {
462  case P_None: return;
463  case P_Fan: vtx.r = 1.0f; vtx.g = 0.0f; vtx.b = 0.0f; vtx.a = 1.0f; break;
464  case P_FanMaxed: vtx.r = 1.0f; vtx.g = 1.0f; vtx.b = 0.0f; vtx.a = 1.0f; break;
465  case P_Fade: vtx.r = 0.0f; vtx.g = 1.0f; vtx.b = 0.0f; vtx.a = 1.0f; break;
466  case P_Intermediate: vtx.r = 0.0f; vtx.g = 0.0f; vtx.b = 1.0f; vtx.a = 1.0f; break;
467  default: assert(false);
468  }
469 
470  DrawVertex(vtx);
472 }
enum C4FoWDrawStrategy::DrawPhase phase
virtual void DrawLightVertex(float x, float y)

Here is the call graph for this function:

void C4FoWDrawWireframeStrategy::End ( C4ShaderCall call)
virtual

Called after each rendering pass

Reimplemented from C4FoWDrawStrategy.

Definition at line 362 of file C4FoWDrawStrategy.cpp.

References C4FoWRSA_Color, C4FoWRSA_Position, C4FoWRSU_VertexOffset, C4FoWDrawStrategy::End(), C4ShaderCall::GetAttribute(), C4FoWDrawTriangulator::GetIndices(), C4FoWDrawTriangulator::GetNIndices(), CStdGL::GetVAO(), pGL, C4ShaderCall::SetUniform2fv(), and C4FoWDrawStrategy::triangulator.

363 {
364  // If we have nothing to draw (e.g. directly after initialization), abort early.
365  if (vertices.empty()) return;
366 
367  const GLuint vbo = bo[0];
368  const GLuint ibo = bo[1];
369 
370  glPolygonMode(GL_FRONT_AND_BACK, GL_LINE);
371 
372  // Upload vertices
373  glBindBuffer(GL_ARRAY_BUFFER, vbo);
374  if (vbo_size < vertices.size())
375  {
376  glBufferData(GL_ARRAY_BUFFER, vertices.size() * sizeof(Vertex), &vertices[0], GL_STREAM_DRAW);
377  vbo_size = vertices.size();
378  }
379  else
380  {
381  glBufferSubData(GL_ARRAY_BUFFER, 0, vertices.size() * sizeof(Vertex), &vertices[0]);
382  }
383  glBindBuffer(GL_ARRAY_BUFFER, 0);
384 
385  // Upload indices
386  glBindBuffer(GL_ELEMENT_ARRAY_BUFFER, ibo);
387  if (ibo_size < triangulator.GetNIndices())
388  {
389  glBufferData(GL_ELEMENT_ARRAY_BUFFER, triangulator.GetNIndices() * sizeof(GLuint), triangulator.GetIndices(), GL_STREAM_DRAW);
390  ibo_size = triangulator.GetNIndices();
391  }
392  else
393  {
394  glBufferSubData(GL_ELEMENT_ARRAY_BUFFER, 0, triangulator.GetNIndices() * sizeof(GLuint), triangulator.GetIndices());
395  }
396  glBindBuffer(GL_ELEMENT_ARRAY_BUFFER, 0);
397 
398  GLuint vao;
399  const bool has_vao = pGL->GetVAO(vaoid, vao);
400  glBindVertexArray(vao);
401  if (!has_vao)
402  {
403  glBindBuffer(GL_ARRAY_BUFFER, vbo);
404  glBindBuffer(GL_ELEMENT_ARRAY_BUFFER, ibo);
405  glEnableVertexAttribArray(call.GetAttribute(C4FoWRSA_Position));
406  glEnableVertexAttribArray(call.GetAttribute(C4FoWRSA_Color));
407 
408  glVertexAttribPointer(call.GetAttribute(C4FoWRSA_Position), 2, GL_FLOAT, GL_FALSE, sizeof(Vertex), reinterpret_cast<const uint8_t*>(offsetof(Vertex, x)));
409  glVertexAttribPointer(call.GetAttribute(C4FoWRSA_Color), 4, GL_FLOAT, GL_FALSE, sizeof(Vertex), reinterpret_cast<const uint8_t*>(offsetof(Vertex, r)));
410  }
411 
412  // Set Y offset for vertex
413  const float y_offset[] = { 0.0f, 0.0f };
414  call.SetUniform2fv(C4FoWRSU_VertexOffset, 1, y_offset);
415 
416  glDrawElements(GL_TRIANGLES, triangulator.GetNIndices(), GL_UNSIGNED_INT, 0);
417 
418  // Reset GL state
419  glBindVertexArray(0);
420  glPolygonMode(GL_FRONT_AND_BACK, GL_FILL);
421 
422  // Assume the capacity stays the same:
423  vertices.resize(0);
425 }
GLint GetAttribute(int iAttribute) const
Definition: C4Shader.h:195
unsigned int GetNIndices() const
C4FoWDrawTriangulator triangulator
bool GetVAO(unsigned int vaoid, GLuint &vao)
Definition: C4DrawGL.cpp:1023
const unsigned int * GetIndices() const
virtual void End(C4ShaderCall &call)
CStdGL * pGL
Definition: C4DrawGL.cpp:914
void SetUniform2fv(int iUniform, int iLength, const float *pVals) const
Definition: C4Shader.h:230

Here is the call graph for this function:

virtual void C4FoWDrawStrategy::EndFade ( )
inlinevirtualinherited

Called after rendering the quads in which the light fades out

Definition at line 105 of file C4FoWDrawStrategy.h.

105 { };
virtual void C4FoWDrawStrategy::EndFan ( )
inlinevirtualinherited

Called after rendering the inner triangle fan

Definition at line 95 of file C4FoWDrawStrategy.h.

95 { };
virtual void C4FoWDrawStrategy::EndFanMaxed ( )
inlinevirtualinherited

Called after rendering the inner triangle fan

Definition at line 100 of file C4FoWDrawStrategy.h.

100 { };
virtual void C4FoWDrawStrategy::EndIntermediateFade ( )
inlinevirtualinherited

Called after rendering the triangles that fill the space between the fadeout quads

Definition at line 110 of file C4FoWDrawStrategy.h.

110 { };

Member Data Documentation


The documentation for this class was generated from the following files: