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)
 
 ~C4FoWDrawWireframeStrategy () override
 
void DrawLightVertex (float x, float y) override
 
void DrawDarkVertex (float x, float y) override
 
void Begin (const C4FoWRegion *region) override
 
void End (C4ShaderCall &call) override
 
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 P_None
 

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 153 of file C4FoWDrawStrategy.h.

Member Enumeration Documentation

Enumerator
P_None 
P_Fan 
P_FanMaxed 
P_Fade 
P_Intermediate 

Definition at line 75 of file C4FoWDrawStrategy.h.

Constructor & Destructor Documentation

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

Definition at line 342 of file C4FoWDrawStrategy.cpp.

References CStdGL::GenVAOID(), and pGL.

342  :
343  light(light), screen(screen), vbo_size(0), ibo_size(0)
344 {
345  glGenBuffers(2, bo);
346  vaoid = pGL->GenVAOID();
347 }
unsigned int GenVAOID()
Definition: C4DrawGL.cpp:925
CStdGL * pGL
Definition: C4DrawGL.cpp:905

Here is the call graph for this function:

C4FoWDrawWireframeStrategy::~C4FoWDrawWireframeStrategy ( )
override

Definition at line 349 of file C4FoWDrawStrategy.cpp.

References CStdGL::FreeVAOID(), and pGL.

350 {
351  glDeleteBuffers(2, bo);
352  pGL->FreeVAOID(vaoid);
353 }
void FreeVAOID(unsigned int vaoid)
Definition: C4DrawGL.cpp:967
CStdGL * pGL
Definition: C4DrawGL.cpp:905

Here is the call graph for this function:

Member Function Documentation

void C4FoWDrawWireframeStrategy::Begin ( const C4FoWRegion region)
overridevirtual

Called before each rendering pass

Implements C4FoWDrawStrategy.

Definition at line 355 of file C4FoWDrawStrategy.cpp.

356 {
357 }
virtual void C4FoWDrawStrategy::BeginFade ( )
inlinevirtualinherited

Called before rendering the quads in which the light fades out

Definition at line 102 of file C4FoWDrawStrategy.h.

References C4FoWDrawStrategy::P_Fade, C4FoWDrawTriangulator::Quads(), and C4FoWDrawStrategy::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 92 of file C4FoWDrawStrategy.h.

References C4FoWDrawTriangulator::Fan(), C4FoWDrawStrategy::P_Fan, and C4FoWDrawStrategy::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 97 of file C4FoWDrawStrategy.h.

References C4FoWDrawStrategy::P_FanMaxed, C4FoWDrawTriangulator::Quads(), and C4FoWDrawStrategy::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 107 of file C4FoWDrawStrategy.h.

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

Here is the call graph for this function:

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

Reimplemented from C4FoWDrawStrategy.

Definition at line 433 of file C4FoWDrawStrategy.cpp.

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

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

Here is the call graph for this function:

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

Reimplemented from C4FoWDrawStrategy.

Definition at line 451 of file C4FoWDrawStrategy.cpp.

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

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

Here is the call graph for this function:

void C4FoWDrawWireframeStrategy::End ( C4ShaderCall call)
overridevirtual

Called after each rendering pass

Reimplemented from C4FoWDrawStrategy.

Definition at line 359 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.

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

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 104 of file C4FoWDrawStrategy.h.

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

Called after rendering the inner triangle fan

Definition at line 94 of file C4FoWDrawStrategy.h.

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

Called after rendering the inner triangle fan

Definition at line 99 of file C4FoWDrawStrategy.h.

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

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

Definition at line 109 of file C4FoWDrawStrategy.h.

109 { };

Member Data Documentation

enum C4FoWDrawStrategy::DrawPhase C4FoWDrawStrategy::P_None
inherited

Referenced by DrawDarkVertex(), and DrawLightVertex().


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