Port debug sphere to SP

This commit is contained in:
Benau 2018-01-03 13:29:19 +08:00
parent df6fbc455b
commit 1400257a60
6 changed files with 57 additions and 23 deletions

View File

@ -1108,8 +1108,8 @@ scene::IMeshSceneNode *IrrDriver::addOctTree(scene::IMesh *mesh)
* \param radius The radius of the sphere.
* \param color The color to use (default (0,0,0,0)
*/
scene::IMeshSceneNode *IrrDriver::addSphere(float radius,
const video::SColor &color)
scene::ISceneNode *IrrDriver::addSphere(float radius,
const video::SColor &color)
{
scene::IMesh *mesh = m_scene_manager->getGeometryCreator()
->createSphereMesh(radius);
@ -1122,22 +1122,21 @@ scene::IMeshSceneNode *IrrDriver::addSphere(float radius,
m.BackfaceCulling = false;
m.MaterialType = video::EMT_SOLID;
#ifndef SERVER_ONLY
//m.setTexture(0, STKTexManager::getInstance()->getUnicolorTexture(video::SColor(128, 255, 105, 180)));
m.setTexture(0, STKTexManager::getInstance()->getUnicolorTexture(color));
m.setTexture(1, STKTexManager::getInstance()->getUnicolorTexture(video::SColor(0, 0, 0, 0)));
m.setTexture(2, STKTexManager::getInstance()->getUnicolorTexture(video::SColor(0, 0, 0, 0)));
if (CVS->isGLSL())
{
STKMeshSceneNode *node =
new STKMeshSceneNode(mesh,
m_scene_manager->getRootSceneNode(),
NULL, -1, "sphere");
return node;
SP::SPMesh* spm = SP::convertEVTStandard(mesh, &color);
SP::SPMeshNode* spmn = new SP::SPMeshNode(spm,
m_scene_manager->getRootSceneNode(), m_scene_manager, -1,
"sphere");
spmn->setMesh(spm);
spm->drop();
spmn->drop();
return spmn;
}
#endif
scene::IMeshSceneNode *node = m_scene_manager->addMeshSceneNode(mesh);
mesh->drop();
return node;
} // addSphere

View File

@ -234,7 +234,7 @@ public:
float wave_height,
float wave_speed, float wave_length);
scene::IMeshSceneNode*addOctTree(scene::IMesh *mesh);
scene::IMeshSceneNode*addSphere(float radius,
scene::ISceneNode* addSphere(float radius,
const video::SColor &color=video::SColor(128, 255, 255, 255));
scene::ISceneNode* addMesh(scene::IMesh *mesh,
const std::string& debug_name,

View File

@ -806,7 +806,6 @@ void ShaderBasedRenderer::render(float dt)
if (CVS->isDefferedEnabled())
{
renderSceneDeferred(camnode, dt, track->hasShadows(), false);
}
else
{
@ -820,19 +819,19 @@ void ShaderBasedRenderer::render(float dt)
SP::drawBoundingBoxes();
m_draw_calls.renderBoundingBoxes();
}
debugPhysics();
if (CVS->isDefferedEnabled())
{
renderPostProcessing(camera);
}
// Save projection-view matrix for the next frame
camera->setPreviousPVMatrix(irr_driver->getProjViewMatrix());
PROFILER_POP_CPU_MARKER();
} // for i<world->getNumKarts()
glBindVertexArray(0);
glBindBuffer(GL_ARRAY_BUFFER, 0);

View File

@ -87,7 +87,7 @@ SlipStream::SlipStream(AbstractKart* kart) : MovingTexture(0, 0), m_kart(kart)
m_debug_dc->getVerticesVector().data();
video::SColor red(128, 255, 0, 0);
unsigned idx[] = { 0, 3, 1, 2 };
for (unsigned i; i < 4; i++)
for (unsigned i = 0; i < 4; i++)
{
v[i].m_position = p[idx[i]].toIrrVector();
v[i].m_normal = 0x1FF << 10;

View File

@ -21,7 +21,7 @@
#include "graphics/central_settings.hpp"
#include "graphics/frame_buffer.hpp"
#include "graphics/irr_driver.hpp"
#include "graphics/material.hpp"
#include "graphics/material_manager.hpp"
#include "graphics/shader_based_renderer.hpp"
#include "graphics/shared_gpu_objects.hpp"
#include "graphics/shader_based_renderer.hpp"
@ -1798,7 +1798,6 @@ void drawBoundingBoxes()
unsigned count = std::min((unsigned)g_bounding_boxes.size() - i,
(unsigned)1024 * 6);
glBufferSubData(GL_ARRAY_BUFFER, 0, count * sizeof(float), &tmp[i]);
glDrawArrays(GL_LINES, 0, count / 3);
}
#endif
@ -1809,5 +1808,39 @@ void addDynamicDrawCall(std::shared_ptr<SPDynamicDrawCall> dy_dc)
{
g_dy_dc.push_back(dy_dc);
} // addDynamicDrawCall
// ----------------------------------------------------------------------------
SPMesh* convertEVTStandard(irr::scene::IMesh* mesh,
const irr::video::SColor* color)
{
SPMesh* spm = new SPMesh();
Material* material = material_manager->getSPMaterial("solid");
for (unsigned i = 0; i < mesh->getMeshBufferCount(); i++)
{
std::vector<video::S3DVertexSkinnedMesh> vertices;
scene::IMeshBuffer* mb = mesh->getMeshBuffer(i);
assert(mb->getVertexType() == video::EVT_STANDARD);
video::S3DVertex* v_ptr = (video::S3DVertex*)mb->getVertices();
for (unsigned j = 0; j < mb->getVertexCount(); j++)
{
video::S3DVertexSkinnedMesh sp;
sp.m_position = v_ptr[j].Pos;
sp.m_normal = MiniGLM::compressVector3(v_ptr[j].Normal);
sp.m_color = color ? *color : v_ptr[j].Color;
sp.m_all_uvs[0] = MiniGLM::toFloat16(v_ptr[j].TCoords.X);
sp.m_all_uvs[1] = MiniGLM::toFloat16(v_ptr[j].TCoords.Y);
vertices.push_back(sp);
}
uint16_t* idx_ptr = mb->getIndices();
std::vector<uint16_t> indices(idx_ptr, idx_ptr + mb->getIndexCount());
SPMeshBuffer* buffer = new SPMeshBuffer();
buffer->setSPMVertices(vertices);
buffer->setIndices(indices);
buffer->setSTKMaterial(material);
spm->addSPMeshBuffer(buffer);
}
mesh->drop();
spm->updateBoundingBox();
return spm;
} // convertEVTStandard
}

View File

@ -34,15 +34,15 @@
namespace irr
{
namespace scene { class ICameraSceneNode; }
namespace video { class ITexture; }
namespace scene { class ICameraSceneNode; class IMesh; }
namespace video { class SColor; }
}
class ShaderBasedRenderer;
namespace SP
{
class SPMesh;
enum DrawCallType: unsigned int
{
@ -135,6 +135,9 @@ void resetEmptyFogColor();
// ----------------------------------------------------------------------------
void drawBoundingBoxes();
// ----------------------------------------------------------------------------
SPMesh* convertEVTStandard(irr::scene::IMesh* mesh,
const irr::video::SColor* color = NULL);
// ----------------------------------------------------------------------------
inline uint8_t srgbToLinear(float color_srgb)
{
int ret;