Use shared_ptr for dynamic draw call
This commit is contained in:
parent
c8aea0bf9e
commit
2bde6d1325
@ -30,8 +30,8 @@
|
|||||||
Shadow::Shadow(Material* shadow_mat, const AbstractKart& kart)
|
Shadow::Shadow(Material* shadow_mat, const AbstractKart& kart)
|
||||||
: m_dy_dc(NULL), m_shadow_enabled(false), m_kart(kart)
|
: m_dy_dc(NULL), m_shadow_enabled(false), m_kart(kart)
|
||||||
{
|
{
|
||||||
m_dy_dc = new SP::SPDynamicDrawCall(scene::EPT_TRIANGLE_STRIP,
|
m_dy_dc = std::make_shared<SP::SPDynamicDrawCall>
|
||||||
SP::getSPShader("alphablend"), shadow_mat);
|
(scene::EPT_TRIANGLE_STRIP, SP::getSPShader("alphablend"), shadow_mat);
|
||||||
|
|
||||||
m_dy_dc->getVerticesVector().resize(4);
|
m_dy_dc->getVerticesVector().resize(4);
|
||||||
video::S3DVertexSkinnedMesh* v = m_dy_dc->getVerticesVector().data();
|
video::S3DVertexSkinnedMesh* v = m_dy_dc->getVerticesVector().data();
|
||||||
@ -43,16 +43,15 @@ Shadow::Shadow(Material* shadow_mat, const AbstractKart& kart)
|
|||||||
v[3].m_all_uvs[1] = 15360;
|
v[3].m_all_uvs[1] = 15360;
|
||||||
v[2].m_all_uvs[0] = 0;
|
v[2].m_all_uvs[0] = 0;
|
||||||
v[2].m_all_uvs[1] = 15360;
|
v[2].m_all_uvs[1] = 15360;
|
||||||
|
|
||||||
|
m_dy_dc->setVisible(false);
|
||||||
|
SP::addDynamicDrawCall(m_dy_dc);
|
||||||
} // Shadow
|
} // Shadow
|
||||||
|
|
||||||
// ----------------------------------------------------------------------------
|
// ----------------------------------------------------------------------------
|
||||||
Shadow::~Shadow()
|
Shadow::~Shadow()
|
||||||
{
|
{
|
||||||
if (m_shadow_enabled)
|
m_dy_dc->removeFromSP();
|
||||||
{
|
|
||||||
SP::removeDynamicDrawCall(m_dy_dc);
|
|
||||||
}
|
|
||||||
delete m_dy_dc;
|
|
||||||
} // ~Shadow
|
} // ~Shadow
|
||||||
|
|
||||||
// ----------------------------------------------------------------------------
|
// ----------------------------------------------------------------------------
|
||||||
@ -68,11 +67,11 @@ void Shadow::update(bool enabled)
|
|||||||
m_shadow_enabled = enabled;
|
m_shadow_enabled = enabled;
|
||||||
if (m_shadow_enabled)
|
if (m_shadow_enabled)
|
||||||
{
|
{
|
||||||
SP::addDynamicDrawCall(m_dy_dc);
|
m_dy_dc->setVisible(true);
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
SP::removeDynamicDrawCall(m_dy_dc);
|
m_dy_dc->setVisible(false);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
if (m_shadow_enabled)
|
if (m_shadow_enabled)
|
||||||
|
@ -20,6 +20,7 @@
|
|||||||
#define HEADER_SHADOW_HPP
|
#define HEADER_SHADOW_HPP
|
||||||
|
|
||||||
#include "utils/no_copy.hpp"
|
#include "utils/no_copy.hpp"
|
||||||
|
#include <memory>
|
||||||
|
|
||||||
class AbstractKart;
|
class AbstractKart;
|
||||||
class Material;
|
class Material;
|
||||||
@ -39,7 +40,7 @@ class Shadow : public NoCopy
|
|||||||
{
|
{
|
||||||
private:
|
private:
|
||||||
/** The dynamic draw call of the shadow. */
|
/** The dynamic draw call of the shadow. */
|
||||||
SP::SPDynamicDrawCall* m_dy_dc;
|
std::shared_ptr<SP::SPDynamicDrawCall> m_dy_dc;
|
||||||
|
|
||||||
/** If a kart is flying, the shadow is disabled (since it is
|
/** If a kart is flying, the shadow is disabled (since it is
|
||||||
* stuck to the kart, i.e. the shadow would be flying, too). */
|
* stuck to the kart, i.e. the shadow would be flying, too). */
|
||||||
|
@ -208,9 +208,9 @@ SkidMarks::SkidMarkQuads::SkidMarkQuads(const Vec3 &left,
|
|||||||
m_center_start = (left + right)/2;
|
m_center_start = (left + right)/2;
|
||||||
m_z_offset = z_offset;
|
m_z_offset = z_offset;
|
||||||
m_fade_out = 0.0f;
|
m_fade_out = 0.0f;
|
||||||
m_dy_dc = new SP::SPDynamicDrawCall(scene::EPT_TRIANGLE_STRIP,
|
m_dy_dc = std::make_shared<SP::SPDynamicDrawCall>
|
||||||
shader, material);
|
(scene::EPT_TRIANGLE_STRIP, shader, material);
|
||||||
static_cast<SP::SPPerObjectUniform*>(m_dy_dc)->addAssignerFunction
|
static_cast<SP::SPPerObjectUniform*>(m_dy_dc.get())->addAssignerFunction
|
||||||
("custom_alpha", [this](SP::SPUniformAssigner* ua)->void
|
("custom_alpha", [this](SP::SPUniformAssigner* ua)->void
|
||||||
{
|
{
|
||||||
// SP custom_alpha is assigned 1 - x, so this is correct
|
// SP custom_alpha is assigned 1 - x, so this is correct
|
||||||
@ -235,8 +235,7 @@ SkidMarks::SkidMarkQuads::SkidMarkQuads(const Vec3 &left,
|
|||||||
//-----------------------------------------------------------------------------
|
//-----------------------------------------------------------------------------
|
||||||
SkidMarks::SkidMarkQuads::~SkidMarkQuads()
|
SkidMarks::SkidMarkQuads::~SkidMarkQuads()
|
||||||
{
|
{
|
||||||
SP::removeDynamicDrawCall(m_dy_dc);
|
m_dy_dc->removeFromSP();
|
||||||
delete m_dy_dc;
|
|
||||||
} // ~SkidMarkQuads
|
} // ~SkidMarkQuads
|
||||||
|
|
||||||
//-----------------------------------------------------------------------------
|
//-----------------------------------------------------------------------------
|
||||||
|
@ -83,7 +83,7 @@ private:
|
|||||||
/** Vector marking the start of the skidmarks (located between left and right wheel) */
|
/** Vector marking the start of the skidmarks (located between left and right wheel) */
|
||||||
Vec3 m_center_start;
|
Vec3 m_center_start;
|
||||||
|
|
||||||
SP::SPDynamicDrawCall* m_dy_dc;
|
std::shared_ptr<SP::SPDynamicDrawCall> m_dy_dc;
|
||||||
|
|
||||||
public:
|
public:
|
||||||
SkidMarkQuads (const Vec3 &left, const Vec3 &right,
|
SkidMarkQuads (const Vec3 &left, const Vec3 &right,
|
||||||
|
@ -49,7 +49,6 @@
|
|||||||
#include <algorithm>
|
#include <algorithm>
|
||||||
#include <array>
|
#include <array>
|
||||||
#include <cassert>
|
#include <cassert>
|
||||||
#include <numeric>
|
|
||||||
#include <string>
|
#include <string>
|
||||||
#include <unordered_map>
|
#include <unordered_map>
|
||||||
#include <unordered_set>
|
#include <unordered_set>
|
||||||
@ -94,7 +93,7 @@ std::vector<float> g_bounding_boxes;
|
|||||||
// ----------------------------------------------------------------------------
|
// ----------------------------------------------------------------------------
|
||||||
core::vector3df g_wind_dir;
|
core::vector3df g_wind_dir;
|
||||||
// ----------------------------------------------------------------------------
|
// ----------------------------------------------------------------------------
|
||||||
std::unordered_set<SPDynamicDrawCall*> g_dy_dc;
|
std::vector<std::shared_ptr<SPDynamicDrawCall> > g_dy_dc;
|
||||||
// ----------------------------------------------------------------------------
|
// ----------------------------------------------------------------------------
|
||||||
float g_frustums[5][24] = { { } };
|
float g_frustums[5][24] = { { } };
|
||||||
// ----------------------------------------------------------------------------
|
// ----------------------------------------------------------------------------
|
||||||
@ -1373,9 +1372,11 @@ void handleDynamicDrawCall()
|
|||||||
{
|
{
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
for (SPDynamicDrawCall* dydc : g_dy_dc)
|
for (unsigned dc_num = 0; dc_num < g_dy_dc.size(); dc_num++)
|
||||||
{
|
{
|
||||||
if (!dydc->isVisible() || dydc->getVertexCount() < 3)
|
SPDynamicDrawCall* dydc = g_dy_dc[dc_num].get();
|
||||||
|
if (!dydc->isVisible() || dydc->notReadyFromDrawing() ||
|
||||||
|
dydc->isRemoving())
|
||||||
{
|
{
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
@ -1640,6 +1641,12 @@ void uploadAll()
|
|||||||
g_stk_sbr->getShadowMatrices()->getMatricesData());
|
g_stk_sbr->getShadowMatrices()->getMatricesData());
|
||||||
glBindBuffer(GL_UNIFORM_BUFFER, 0);
|
glBindBuffer(GL_UNIFORM_BUFFER, 0);
|
||||||
|
|
||||||
|
g_dy_dc.erase(std::remove_if(g_dy_dc.begin(), g_dy_dc.end(),
|
||||||
|
[] (std::shared_ptr<SPDynamicDrawCall> dc)
|
||||||
|
{
|
||||||
|
return dc->isRemoving();
|
||||||
|
}), g_dy_dc.end());
|
||||||
|
|
||||||
if (!sp_culling)
|
if (!sp_culling)
|
||||||
{
|
{
|
||||||
return;
|
return;
|
||||||
@ -1784,15 +1791,9 @@ void drawBoundingBoxes()
|
|||||||
} // drawBoundingBoxes
|
} // drawBoundingBoxes
|
||||||
|
|
||||||
// ----------------------------------------------------------------------------
|
// ----------------------------------------------------------------------------
|
||||||
void addDynamicDrawCall(SPDynamicDrawCall* dy_dc)
|
void addDynamicDrawCall(std::shared_ptr<SPDynamicDrawCall> dy_dc)
|
||||||
{
|
{
|
||||||
g_dy_dc.insert(dy_dc);
|
g_dy_dc.push_back(dy_dc);
|
||||||
} // addDynamicDrawCall
|
} // addDynamicDrawCall
|
||||||
|
|
||||||
// ----------------------------------------------------------------------------
|
|
||||||
void removeDynamicDrawCall(SPDynamicDrawCall* dy_dc)
|
|
||||||
{
|
|
||||||
g_dy_dc.erase(dy_dc);
|
|
||||||
} // removeDynamicDrawCall
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
@ -125,9 +125,7 @@ void prepareScene();
|
|||||||
// ----------------------------------------------------------------------------
|
// ----------------------------------------------------------------------------
|
||||||
void handleDynamicDrawCall();
|
void handleDynamicDrawCall();
|
||||||
// ----------------------------------------------------------------------------
|
// ----------------------------------------------------------------------------
|
||||||
void addDynamicDrawCall(SPDynamicDrawCall*);
|
void addDynamicDrawCall(std::shared_ptr<SPDynamicDrawCall>);
|
||||||
// ----------------------------------------------------------------------------
|
|
||||||
void removeDynamicDrawCall(SPDynamicDrawCall*);
|
|
||||||
// ----------------------------------------------------------------------------
|
// ----------------------------------------------------------------------------
|
||||||
void updateModelMatrix();
|
void updateModelMatrix();
|
||||||
// ----------------------------------------------------------------------------
|
// ----------------------------------------------------------------------------
|
||||||
|
@ -59,6 +59,8 @@ private:
|
|||||||
|
|
||||||
bool m_update_trans = false;
|
bool m_update_trans = false;
|
||||||
|
|
||||||
|
bool m_removing = false;
|
||||||
|
|
||||||
// ------------------------------------------------------------------------
|
// ------------------------------------------------------------------------
|
||||||
bool initTextureDyDc();
|
bool initTextureDyDc();
|
||||||
|
|
||||||
@ -136,6 +138,12 @@ public:
|
|||||||
// ------------------------------------------------------------------------
|
// ------------------------------------------------------------------------
|
||||||
const core::matrix4& getAbsoluteTransformation() const { return m_trans; }
|
const core::matrix4& getAbsoluteTransformation() const { return m_trans; }
|
||||||
// ------------------------------------------------------------------------
|
// ------------------------------------------------------------------------
|
||||||
|
void removeFromSP() { m_removing = true; }
|
||||||
|
// ------------------------------------------------------------------------
|
||||||
|
bool isRemoving() const { return m_removing; }
|
||||||
|
// ------------------------------------------------------------------------
|
||||||
|
bool notReadyFromDrawing() const { return m_vertices.size() < 3; }
|
||||||
|
// ------------------------------------------------------------------------
|
||||||
void setAbsoluteTransformation(core::matrix4& mat)
|
void setAbsoluteTransformation(core::matrix4& mat)
|
||||||
{
|
{
|
||||||
m_trans = mat;
|
m_trans = mat;
|
||||||
|
@ -54,8 +54,9 @@ RubberBand::RubberBand(Plunger *plunger, AbstractKart *kart)
|
|||||||
color.setGreen(SP::srgbToLinear(tmp.g));
|
color.setGreen(SP::srgbToLinear(tmp.g));
|
||||||
color.setBlue(SP::srgbToLinear(tmp.b));
|
color.setBlue(SP::srgbToLinear(tmp.b));
|
||||||
}
|
}
|
||||||
m_dy_dc = new SP::SPDynamicDrawCall(scene::EPT_TRIANGLE_STRIP,
|
m_dy_dc = std::make_shared<SP::SPDynamicDrawCall>
|
||||||
SP::getSPShader("unlit"), material_manager->getSPMaterial("unlit"));
|
(scene::EPT_TRIANGLE_STRIP, SP::getSPShader("unlit"),
|
||||||
|
material_manager->getSPMaterial("unlit"));
|
||||||
m_dy_dc->getVerticesVector().resize(4);
|
m_dy_dc->getVerticesVector().resize(4);
|
||||||
// Set the vertex colors properly, as the new pipeline doesn't use the old
|
// Set the vertex colors properly, as the new pipeline doesn't use the old
|
||||||
// light values
|
// light values
|
||||||
@ -72,8 +73,7 @@ RubberBand::RubberBand(Plunger *plunger, AbstractKart *kart)
|
|||||||
RubberBand::~RubberBand()
|
RubberBand::~RubberBand()
|
||||||
{
|
{
|
||||||
#ifndef SERVER_ONLY
|
#ifndef SERVER_ONLY
|
||||||
SP::removeDynamicDrawCall(m_dy_dc);
|
m_dy_dc->removeFromSP();
|
||||||
delete m_dy_dc;
|
|
||||||
#endif
|
#endif
|
||||||
} // RubberBand
|
} // RubberBand
|
||||||
|
|
||||||
|
@ -22,6 +22,8 @@
|
|||||||
#include "utils/no_copy.hpp"
|
#include "utils/no_copy.hpp"
|
||||||
#include "utils/vec3.hpp"
|
#include "utils/vec3.hpp"
|
||||||
|
|
||||||
|
#include <memory>
|
||||||
|
|
||||||
namespace SP
|
namespace SP
|
||||||
{
|
{
|
||||||
class SPDynamicDrawCall;
|
class SPDynamicDrawCall;
|
||||||
@ -50,7 +52,7 @@ private:
|
|||||||
AbstractKart *m_owner;
|
AbstractKart *m_owner;
|
||||||
|
|
||||||
/** The dynamic draw call of the rubber band. */
|
/** The dynamic draw call of the rubber band. */
|
||||||
SP::SPDynamicDrawCall *m_dy_dc;
|
std::shared_ptr<SP::SPDynamicDrawCall> m_dy_dc;
|
||||||
|
|
||||||
/** The kart a plunger might have hit. */
|
/** The kart a plunger might have hit. */
|
||||||
AbstractKart *m_hit_kart;
|
AbstractKart *m_hit_kart;
|
||||||
|
Loading…
x
Reference in New Issue
Block a user