Changeset 25269

Timestamp:
Apr 15, 2021, 8:07:01 PM (3 years ago)
Author:
Vladislav Belov
Message:

Removes low-level GL calls from graphics and geometrics primitives and adds DebugRenderer.

Tested By: Freagarach

Differential Revision: https://code.wildfiregames.com/D3857

Location:
ps/trunk/source
Files:
2 added
11 edited

Legend:

Unmodified
Added
Removed
  • ps/trunk/source/graphics/Camera.cpp

    r25266 r25269  
    393393    m_Orientation._41 = 0.0f;   m_Orientation._42 = 0.0f;   m_Orientation._43 = 0.0f;           m_Orientation._44 = 1.0f;
    394394}
    395 
    396 // Render the camera's frustum
    397 void CCamera::Render(int intermediates) const
    398 {
    399 #if CONFIG2_GLES
    400 #warning TODO: implement camera frustum for GLES
    401 #else
    402     Quad nearPoints;
    403     Quad farPoints;
    404 
    405     GetViewQuad(m_NearPlane, nearPoints);
    406     GetViewQuad(m_FarPlane, farPoints);
    407     for(int i = 0; i < 4; i++)
    408     {
    409         nearPoints[i] = m_Orientation.Transform(nearPoints[i]);
    410         farPoints[i] = m_Orientation.Transform(farPoints[i]);
    411     }
    412 
    413     // near plane
    414     glBegin(GL_POLYGON);
    415         glVertex3fv(&nearPoints[0].X);
    416         glVertex3fv(&nearPoints[1].X);
    417         glVertex3fv(&nearPoints[2].X);
    418         glVertex3fv(&nearPoints[3].X);
    419     glEnd();
    420 
    421     // far plane
    422     glBegin(GL_POLYGON);
    423         glVertex3fv(&farPoints[0].X);
    424         glVertex3fv(&farPoints[1].X);
    425         glVertex3fv(&farPoints[2].X);
    426         glVertex3fv(&farPoints[3].X);
    427     glEnd();
    428 
    429     // connection lines
    430     glBegin(GL_QUAD_STRIP);
    431         glVertex3fv(&nearPoints[0].X);
    432         glVertex3fv(&farPoints[0].X);
    433         glVertex3fv(&nearPoints[1].X);
    434         glVertex3fv(&farPoints[1].X);
    435         glVertex3fv(&nearPoints[2].X);
    436         glVertex3fv(&farPoints[2].X);
    437         glVertex3fv(&nearPoints[3].X);
    438         glVertex3fv(&farPoints[3].X);
    439         glVertex3fv(&nearPoints[0].X);
    440         glVertex3fv(&farPoints[0].X);
    441     glEnd();
    442 
    443     // intermediate planes
    444     CVector3D intermediatePoints[4];
    445     for(int i = 0; i < intermediates; ++i)
    446     {
    447         float t = (i+1.0)/(intermediates+1.0);
    448 
    449         for(int j = 0; j < 4; ++j)
    450             intermediatePoints[j] = nearPoints[j]*t + farPoints[j]*(1.0-t);
    451 
    452         glBegin(GL_POLYGON);
    453             glVertex3fv(&intermediatePoints[0].X);
    454             glVertex3fv(&intermediatePoints[1].X);
    455             glVertex3fv(&intermediatePoints[2].X);
    456             glVertex3fv(&intermediatePoints[3].X);
    457         glEnd();
    458     }
    459 #endif
    460 }
  • ps/trunk/source/graphics/Camera.h

    r25159 r25269  
    109109        void LookAlong(const CVector3D& camera, CVector3D orientation, CVector3D up);
    110110
    111         /**
    112          * Render: Renders the camera's frustum in world space.
    113          * The caller should set the color using glColorXy before calling Render.
    114          *
    115          * @param intermediates determines how many intermediate distance planes should
    116          * be hinted at between the near and far planes
    117          */
    118         void Render(int intermediates = 0) const;
    119 
    120111    public:
    121112        // This is the orientation matrix. The inverse of this
  • ps/trunk/source/maths/BoundingBoxAligned.cpp

    r25159 r25269  
    2424#include "BoundingBoxAligned.h"
    2525
    26 #include "graphics/ShaderProgram.h"
    27 #include "lib/ogl.h"
    2826#include "maths/BoundingBoxOriented.h"
    2927#include "maths/Brush.h"
     
    266264    m_Data[1] += CVector3D(amount, amount, amount);
    267265}
    268 
    269 ///////////////////////////////////////////////////////////////////////////////
    270 // Render the bounding box
    271 void CBoundingBoxAligned::Render(CShaderProgramPtr& shader) const
    272 {
    273     std::vector<float> data;
    274 
    275 #define ADD_FACE(x, y, z) \
    276     ADD_PT(0, 0, x, y, z); ADD_PT(1, 0, x, y, z); ADD_PT(1, 1, x, y, z); \
    277     ADD_PT(1, 1, x, y, z); ADD_PT(0, 1, x, y, z); ADD_PT(0, 0, x, y, z);
    278 #define ADD_PT(u_, v_, x, y, z) \
    279     STMT(int u = u_; int v = v_; \
    280         data.push_back(u); \
    281         data.push_back(v); \
    282         data.push_back(m_Data[x].X); \
    283         data.push_back(m_Data[y].Y); \
    284         data.push_back(m_Data[z].Z); \
    285     )
    286 
    287     ADD_FACE(u, v, 0);
    288     ADD_FACE(0, u, v);
    289     ADD_FACE(u, 0, 1-v);
    290     ADD_FACE(u, 1-v, 1);
    291     ADD_FACE(1, u, 1-v);
    292     ADD_FACE(u, 1, v);
    293 
    294 #undef ADD_FACE
    295 
    296     shader->TexCoordPointer(GL_TEXTURE0, 2, GL_FLOAT, 5*sizeof(float), &data[0]);
    297     shader->VertexPointer(3, GL_FLOAT, 5*sizeof(float), &data[2]);
    298 
    299     shader->AssertPointersBound();
    300     glDrawArrays(GL_TRIANGLES, 0, 6*6);
    301 }
    302 
    303 void CBoundingBoxAligned::RenderOutline(CShaderProgramPtr& shader) const
    304 {
    305     std::vector<float> data;
    306 
    307 #define ADD_FACE(x, y, z) \
    308     ADD_PT(0, 0, x, y, z); ADD_PT(1, 0, x, y, z); \
    309     ADD_PT(1, 0, x, y, z); ADD_PT(1, 1, x, y, z); \
    310     ADD_PT(1, 1, x, y, z); ADD_PT(0, 1, x, y, z); \
    311     ADD_PT(0, 1, x, y, z); ADD_PT(0, 0, x, y, z);
    312 #define ADD_PT(u_, v_, x, y, z) \
    313     STMT(int u = u_; int v = v_; \
    314         data.push_back(u); \
    315         data.push_back(v); \
    316         data.push_back(m_Data[x].X); \
    317         data.push_back(m_Data[y].Y); \
    318         data.push_back(m_Data[z].Z); \
    319     )
    320 
    321     ADD_FACE(u, v, 0);
    322     ADD_FACE(0, u, v);
    323     ADD_FACE(u, 0, 1-v);
    324     ADD_FACE(u, 1-v, 1);
    325     ADD_FACE(1, u, 1-v);
    326     ADD_FACE(u, 1, v);
    327 
    328 #undef ADD_FACE
    329 
    330     shader->TexCoordPointer(GL_TEXTURE0, 2, GL_FLOAT, 5*sizeof(float), &data[0]);
    331     shader->VertexPointer(3, GL_FLOAT, 5*sizeof(float), &data[2]);
    332 
    333     shader->AssertPointersBound();
    334     glDrawArrays(GL_LINES, 0, 6*8);
    335 }
  • ps/trunk/source/maths/BoundingBoxAligned.h

    r22372 r25269  
    1 /* Copyright (C) 2019 Wildfire Games.
     1/* Copyright (C) 20 Wildfire Games.
    22 * This file is part of 0 A.D.
    33 *
     
    148148    CFrustum ToFrustum() const;
    149149
    150     /**
    151      * Render the surfaces of the bound object as triangles.
    152      */
    153     void Render(CShaderProgramPtr& shader) const;
    154 
    155     /**
    156      * Render the outline of the bound object as lines.
    157      */
    158     void RenderOutline(CShaderProgramPtr& shader) const;
    159 
    160150private:
    161151    // Holds the minimal and maximal coordinate points in m_Data[0] and m_Data[1], respectively.
  • ps/trunk/source/maths/Brush.cpp

    r25159 r25269  
    1616 */
    1717
    18 /*
    19  * Implementation of CBrush, a class representing a convex object
    20  */
    21 
    2218#include "precompiled.h"
    2319
    2420#include "Brush.h"
    2521
    26 #include "graphics/ShaderProgram.h"
    2722#include "maths/BoundingBoxAligned.h"
    2823#include "maths/Frustum.h"
    29 #include "lib/ogl.h"
    30 
    31 #include <float.h>
    32 
     24
     25CBrush::CBrush() = default;
    3326
    3427///////////////////////////////////////////////////////////////////////////////
     
    381374    ENSURE(prev == &result);
    382375}
    383 std::vector<CVector3D> CBrush::GetVertices() const
     376
     377const std::vector<CVector3D>& CBrush::GetVertices() const
    384378{
    385379    return m_Vertices;
    386380}
    387381
    388 void CBrush::GetFaces(std::vector<std::vector<size_t> >& out) const
     382void CBrush::GetFaces(std::vector<std::vector<size_t>>& out) const
    389383{
    390384    // split the back-to-back faces into separate face vectors, so that they're in a
     
    416410    }
    417411}
    418 
    419 void CBrush::Render(CShaderProgramPtr& shader) const
    420 {
    421     std::vector<float> data;
    422 
    423     std::vector<std::vector<size_t> > faces;
    424     GetFaces(faces);
    425 
    426 #define ADD_VERT(a) \
    427     STMT( \
    428         data.push_back(u); \
    429         data.push_back(v); \
    430         data.push_back(m_Vertices[faces[i][a]].X); \
    431         data.push_back(m_Vertices[faces[i][a]].Y); \
    432         data.push_back(m_Vertices[faces[i][a]].Z); \
    433     )
    434 
    435     for (size_t i = 0; i < faces.size(); ++i)
    436     {
    437         // Triangulate into (0,1,2), (0,2,3), ...
    438         for (size_t j = 1; j < faces[i].size() - 2; ++j)
    439         {
    440             float u = 0;
    441             float v = 0;
    442             ADD_VERT(0);
    443             ADD_VERT(j);
    444             ADD_VERT(j+1);
    445         }
    446     }
    447 
    448 #undef ADD_VERT
    449 
    450     shader->TexCoordPointer(GL_TEXTURE0, 2, GL_FLOAT, 5*sizeof(float), &data[0]);
    451     shader->VertexPointer(3, GL_FLOAT, 5*sizeof(float), &data[2]);
    452 
    453     shader->AssertPointersBound();
    454     glDrawArrays(GL_TRIANGLES, 0, data.size() / 5);
    455 }
    456 
    457 void CBrush::RenderOutline(CShaderProgramPtr& shader) const
    458 {
    459     std::vector<float> data;
    460 
    461     std::vector<std::vector<size_t> > faces;
    462     GetFaces(faces);
    463 
    464 #define ADD_VERT(a) \
    465     STMT( \
    466         data.push_back(u); \
    467         data.push_back(v); \
    468         data.push_back(m_Vertices[faces[i][a]].X); \
    469         data.push_back(m_Vertices[faces[i][a]].Y); \
    470         data.push_back(m_Vertices[faces[i][a]].Z); \
    471     )
    472 
    473     for (size_t i = 0; i < faces.size(); ++i)
    474     {
    475         for (size_t j = 0; j < faces[i].size() - 1; ++j)
    476         {
    477             float u = 0;
    478             float v = 0;
    479             ADD_VERT(j);
    480             ADD_VERT(j+1);
    481         }
    482     }
    483 
    484 #undef ADD_VERT
    485 
    486     shader->TexCoordPointer(GL_TEXTURE0, 2, GL_FLOAT, 5*sizeof(float), &data[0]);
    487     shader->VertexPointer(3, GL_FLOAT, 5*sizeof(float), &data[2]);
    488 
    489     shader->AssertPointersBound();
    490     glDrawArrays(GL_LINES, 0, data.size() / 5);
    491 }
  • ps/trunk/source/maths/Brush.h

    r24352 r25269  
    1 /* Copyright (C) 2020 Wildfire Games.
     1/* Copyright (C) 202 Wildfire Games.
    22 * This file is part of 0 A.D.
    33 *
     
    2020 */
    2121
    22 #ifndef maths_brush_h
    23 #define maths_brush_h
     22#ifndef
     23#define
    2424
    25 #include "Vector3D.h"
    26 
    27 #include "graphics/ShaderProgramPtr.h"
     25#include "maths/Vector3D.h"
    2826
    2927#include <vector>
     
    3937class CBrush
    4038{
    41     friend class TestBrush;
    42 
    4339public:
    44     CBrush() { }
     40    CBrush()
    4541
    4642    /**
     
    8480
    8581    /**
    86      * Render the surfaces of the brush as triangles.
    87      */
    88     void Render(CShaderProgramPtr& shader) const;
    89 
    90     /**
    91      * Render the outline of the brush as lines.
    92      */
    93     void RenderOutline(CShaderProgramPtr& shader) const;
    94 
    95 private:
    96 
    97     /**
    98      * Returns a copy of the vertices in this brush. Intended for testing purposes; you should not need to use
     82     * Returns vertices in the brush. Intended for testing purposes; you should not need to use
    9983     * this method directly.
    10084     */
    101     std::vector<CVector3D> GetVertices() const;
     85    GetVertices() const;
    10286
    10387    /**
     
    10690     * need to use this method directly.
    10791     */
    108     void GetFaces(std::vector<std::vector<size_t> >& out) const;
     92    void GetFaces(std::vector<std::vector<size_t>>& out) const;
    10993
    11094private:
     
    127111};
    128112
    129 #endif // maths_brush_h
     113#endif //
  • ps/trunk/source/renderer/ParticleRenderer.cpp

    r24652 r25269  
    2525#include "graphics/TextureManager.h"
    2626#include "ps/Profile.h"
     27
    2728#include "renderer/Renderer.h"
    2829
     
    159160
    160161        CBoundingBoxAligned bounds = emitter->m_Type->CalculateBounds(emitter->GetPosition(), emitter->GetParticleBounds());
    161         bounds.Render(shader);
     162        shader);
    162163    }
    163164}
  • ps/trunk/source/renderer/Renderer.cpp

    r25261 r25269  
    2222
    2323#include "precompiled.h"
    24 
    25 #include <map>
    26 #include <set>
    27 #include <algorithm>
    28 
    29 #include <boost/algorithm/string.hpp>
    3024
    3125#include "Renderer.h"
     
    5953#include "graphics/Texture.h"
    6054#include "graphics/TextureManager.h"
     55
    6156#include "renderer/HWLightingModelRenderer.h"
    6257#include "renderer/InstancingModelRenderer.h"
     
    7772#include "scriptinterface/ScriptInterface.h"
    7873
     74
     75
     76
     77
     78
    7979struct SScreenRect
    8080{
     
    299299    CPostprocManager postprocManager;
    300300
     301
     302
    301303    CFontManager fontManager;
    302304
     
    14841486    glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA);
    14851487    glColor4ub(255,255,255,64);
    1486     m_CullCamera.Render(2);
     1488    2);
    14871489    glDisable(GL_BLEND);
    14881490
    14891491    glPolygonMode(GL_FRONT_AND_BACK, GL_LINE);
    14901492    glColor3ub(255,255,255);
    1491     m_CullCamera.Render(2);
     1493    2);
    14921494    glPolygonMode(GL_FRONT_AND_BACK, GL_FILL);
    14931495
     
    19531955}
    19541956
     1957
     1958
     1959
     1960
     1961
    19551962CFontManager& CRenderer::GetFontManager()
    19561963{
  • ps/trunk/source/renderer/Renderer.h

    r25261 r25269  
    3434#include "renderer/Scene.h"
    3535
     36
    3637class CFontManager;
    3738class CLightEnv;
     
    277278    CPostprocManager& GetPostprocManager();
    278279
     280
     281
    279282    /**
    280283     * GetCapabilities: Return which OpenGL capabilities are available and enabled.
  • ps/trunk/source/renderer/ShadowMap.cpp

    r25261 r25269  
    3434#include "ps/ConfigDB.h"
    3535#include "ps/Profile.h"
     36
    3637#include "renderer/Renderer.h"
    3738#include "renderer/RenderingOptions.h"
     
    677678
    678679    shader->Uniform(str_color, 1.0f, 1.0f, 0.0f, 1.0f);
    679     m->ShadowReceiverBound.RenderOutline(shader);
     680    shader);
    680681
    681682    shader->Uniform(str_color, 0.0f, 1.0f, 0.0f, 1.0f);
    682     m->ShadowCasterBound.RenderOutline(shader);
     683    shader);
    683684
    684685    glEnable(GL_BLEND);
    685686    glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA);
    686687    shader->Uniform(str_color, 0.0f, 0.0f, 1.0f, 0.25f);
    687     m->ShadowRenderBound.Render(shader);
     688    shader);
    688689    glDisable(GL_BLEND);
    689690
    690691    shader->Uniform(str_color, 0.0f, 0.0f, 1.0f, 1.0f);
    691     m->ShadowRenderBound.RenderOutline(shader);
     692    shader);
    692693
    693694    // Render light frustum
     
    706707    glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA);
    707708    shader->Uniform(str_color, 1.0f, 0.0f, 0.0f, 0.25f);
    708     frustumBrush.Render(shader);
     709    shader);
    709710    glDisable(GL_BLEND);
    710711
    711712    shader->Uniform(str_color, 1.0f, 0.0f, 0.0f, 1.0f);
    712     frustumBrush.RenderOutline(shader);
    713 
     713    g_Renderer.GetDebugRenderer().DrawBrushOutline(frustumBrush, shader);
    714714
    715715    shaderTech->EndPass();
  • ps/trunk/source/renderer/SilhouetteRenderer.cpp

    r25266 r25269  
    2727#include "maths/MathUtil.h"
    2828#include "ps/Profile.h"
     29
    2930#include "renderer/Renderer.h"
    3031#include "renderer/Scene.h"
     
    456457    {
    457458        shader->Uniform(str_color, m_DebugBounds[i].color);
    458         m_DebugBounds[i].bounds.RenderOutline(shader);
     459        shader);
    459460    }
    460461
Note: See TracChangeset for help on using the changeset viewer.