Skip to content

Commit e93ac86

Browse files
committed
Different lists are created for transparent objs
1 parent 2f7a7fc commit e93ac86

File tree

3 files changed

+142
-21
lines changed

3 files changed

+142
-21
lines changed

src/Interface/Modules/Render/ES/SRInterface.cc

Lines changed: 96 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -300,6 +300,11 @@ namespace SCIRun {
300300
}
301301

302302
// Add vertex buffer objects.
303+
//-----------------------------------------------------------------
304+
char* vbo_buffer = 0;
305+
size_t stride_vbo = 0;
306+
//-----------------------------------------------------------------
307+
303308
int nameIndex = 0;
304309
for (auto it = obj->mVBOs.cbegin(); it != obj->mVBOs.cend(); ++it)
305310
{
@@ -317,7 +322,11 @@ namespace SCIRun {
317322
GLuint vboID = vboMan.addInMemoryVBO(vbo.data->getBuffer(), vbo.data->getBufferSize(),
318323
attributeData, vbo.name);
319324
}
320-
325+
//-----------------------------------------------------------------
326+
vbo_buffer = reinterpret_cast<char*>(vbo.data->getBuffer());
327+
for (auto a : vbo.attributes)
328+
stride_vbo += a.sizeInBytes;
329+
//-----------------------------------------------------------------
321330
bbox.extend(vbo.boundingBox);
322331
}
323332

@@ -364,10 +373,74 @@ namespace SCIRun {
364373
break;
365374
}
366375

367-
int numPrimitives = ibo.data->getBufferSize() / ibo.indexSize;
376+
//----------------------------------------------------------------
377+
uint32_t* ibo_buffer = reinterpret_cast<uint32_t*>(ibo.data->getBuffer());
378+
size_t num_triangles = ibo.data->getBufferSize() / (sizeof(uint32_t) * 3);
379+
Core::Geometry::Vector dir(0.0, 0.0, 0.0);
380+
381+
std::vector<DepthIndex> rel_depth(num_triangles);
382+
for (int i = 0; i <= 3; ++i)
383+
{
384+
std::string name = ibo.name;
385+
386+
if (i == 0)
387+
{
388+
dir = Core::Geometry::Vector(1.0, 0.0, 0.0);
389+
name += "X";
390+
}
391+
else if (i == 1)
392+
{
393+
dir = Core::Geometry::Vector(0.0, 1.0, 0.0);
394+
name += "Y";
395+
}
396+
else if (i == 2)
397+
{
398+
dir = Core::Geometry::Vector(0.0, 0.0, 1.0);
399+
name += "Z";
400+
}
401+
else if (i == 3)
402+
{
403+
int numPrimitives = ibo.data->getBufferSize() / ibo.indexSize;
404+
iboMan.addInMemoryIBO(ibo.data->getBuffer(), ibo.data->getBufferSize(), primitive, primType, numPrimitives, name);
405+
break;
406+
}
407+
408+
for (size_t j = 0; j < num_triangles; j++)
409+
{
410+
float* vertex1 = reinterpret_cast<float*>(vbo_buffer + stride_vbo * (ibo_buffer[j * 3]));
411+
Core::Geometry::Point node1(vertex1[0], vertex1[1], vertex1[2]);
412+
413+
float* vertex2 = reinterpret_cast<float*>(vbo_buffer + stride_vbo * (ibo_buffer[j * 3 + 1]));
414+
Core::Geometry::Point node2(vertex2[0], vertex2[1], vertex2[2]);
415+
416+
float* vertex3 = reinterpret_cast<float*>(vbo_buffer + stride_vbo * (ibo_buffer[j * 3 + 2]));
417+
Core::Geometry::Point node3(vertex3[0], vertex3[1], vertex3[2]);
368418

369-
iboMan.addInMemoryIBO(ibo.data->getBuffer(), ibo.data->getBufferSize(), primitive, primType,
370-
numPrimitives, ibo.name);
419+
rel_depth[j].mDepth = Core::Geometry::Dot(dir, node1) + Core::Geometry::Dot(dir, node2) + Core::Geometry::Dot(dir, node3);
420+
rel_depth[j].mIndex = j;
421+
}
422+
423+
std::sort(rel_depth.begin(), rel_depth.end());
424+
425+
int numPrimitives = ibo.data->getBufferSize() / ibo.indexSize;
426+
427+
std::vector<char> sorted_buffer(ibo.data->getBufferSize());
428+
char* ibuffer = reinterpret_cast<char*>(ibo.data->getBuffer());
429+
char* sbuffer = reinterpret_cast<char*>(&sorted_buffer[0]);
430+
size_t tri_size = ibo.data->getBufferSize() / num_triangles;
431+
432+
for (size_t j = 0; j < num_triangles; j++)
433+
{
434+
memcpy(sbuffer + j * tri_size, ibuffer + rel_depth[j].mIndex * tri_size, tri_size);
435+
}
436+
437+
iboMan.addInMemoryIBO(sbuffer, ibo.data->getBufferSize(), primitive, primType, numPrimitives, name);
438+
}
439+
//----------------------------------------------------------------
440+
441+
//int numPrimitives = ibo.data->getBufferSize() / ibo.indexSize;
442+
443+
//iboMan.addInMemoryIBO(ibo.data->getBuffer(), ibo.data->getBufferSize(), primitive, primType, numPrimitives, ibo.name);
371444
}
372445

373446
// Add default identity transform to the object globally (instead of per-pass)
@@ -386,9 +459,20 @@ namespace SCIRun {
386459

387460
if (pass.renderType == Core::Datatypes::GeometryObject::RENDER_VBO_IBO)
388461
{
389-
reorderIBO(pass);
462+
//reorderIBO(pass);
390463
addVBOToEntity(entityID, pass.vboName);
391-
addIBOToEntity(entityID, pass.iboName);
464+
for (int i = 0; i <= 3; ++i)
465+
{
466+
std::string name = pass.iboName;
467+
if (i == 1)
468+
name += "X";
469+
if (i == 2)
470+
name += "Y";
471+
if (i == 3)
472+
name += "Z";
473+
474+
addIBOToEntity(entityID, name);
475+
}
392476
}
393477
else
394478
{
@@ -547,7 +631,7 @@ namespace SCIRun {
547631
ibo.primType = iboData.primType;
548632
ibo.primMode = iboData.primMode;
549633
ibo.numPrims = iboData.numPrims;
550-
634+
551635
mCore.addComponent(entityID, ibo);
552636
}
553637

@@ -563,7 +647,7 @@ namespace SCIRun {
563647

564648
std::vector<DepthIndex> rel_depth(num_triangles);
565649
Core::Geometry::Vector dir(mCamera->getViewToWorld()[0][2], mCamera->getViewToWorld()[1][2], mCamera->getViewToWorld()[2][2]);
566-
650+
567651
for (size_t j = 0; j < num_triangles; j++)
568652
{
569653
float* vertex1 = reinterpret_cast<float*>(vbo_buffer + stride_vbo * (ibo_buffer[j * 3]));
@@ -590,14 +674,14 @@ namespace SCIRun {
590674

591675
for (size_t j = 0; j < num_triangles; j++)
592676
{
593-
memcpy(sbuffer + j * tri_size, ibuffer + rel_depth[j].mIndex * tri_size, tri_size);
677+
memcpy(sbuffer + j * tri_size, pass.ibo.data->getBuffer() + rel_depth[j].mIndex * tri_size, tri_size);
594678
}
595679

596-
ren::IBOMan& iboMan = *mCore.getStaticComponent<ren::StaticIBOMan>()->instance;
680+
//ren::IBOMan& iboMan = *mCore.getStaticComponent<ren::StaticIBOMan>()->instance;
597681

598-
auto iboData = iboMan.getIBOData(pass.iboName);
682+
// auto iboData = iboMan.getIBOData(pass.iboName);
599683

600-
iboMan.addInMemoryIBO(sbuffer, pass.ibo.data->getBufferSize(), iboData.primMode, iboData.primType, iboData.numPrims, pass.iboName);
684+
//iboMan.addInMemoryIBO(sbuffer, pass.ibo.data->getBufferSize(), iboData.primMode, iboData.primType, iboData.numPrims, pass.iboName);
601685
}
602686

603687
//------------------------------------------------------------------------------

src/Interface/Modules/Render/ES/systems/RenderTransBasicSys.cc

Lines changed: 8 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -24,8 +24,6 @@
2424

2525
#include <bserialize/BSerialize.hpp>
2626

27-
#include <Core/Datatypes/Geometry.h>
28-
2927
#include "../comp/RenderBasicGeom.h"
3028
#include "../comp/SRRenderState.h"
3129
#include "../comp/RenderList.h"
@@ -59,7 +57,8 @@ class RenderBasicSysTrans :
5957
StaticWorldLight,
6058
gen::StaticCamera,
6159
ren::StaticGLState,
62-
ren::StaticVBOMan>
60+
ren::StaticVBOMan,
61+
ren::StaticIBOMan>
6362
{
6463
public:
6564

@@ -93,7 +92,8 @@ class RenderBasicSysTrans :
9392
const es::ComponentGroup<StaticWorldLight>& worldLight,
9493
const es::ComponentGroup<gen::StaticCamera>& camera,
9594
const es::ComponentGroup<ren::StaticGLState>& defaultGLState,
96-
const es::ComponentGroup<ren::StaticVBOMan>& vboMan) override
95+
const es::ComponentGroup<ren::StaticVBOMan>& vboMan,
96+
const es::ComponentGroup<ren::StaticIBOMan>& iboMan) override
9797
{
9898
/// \todo This needs to be moved to pre-execute.
9999
if (glCheckFramebufferStatus(GL_FRAMEBUFFER) != GL_FRAMEBUFFER_COMPLETE)
@@ -106,6 +106,10 @@ class RenderBasicSysTrans :
106106
return;
107107
}
108108

109+
Core::Geometry::Vector currentDir(camera.front().data.worldToView[0][2],
110+
camera.front().data.worldToView[1][2],
111+
camera.front().data.worldToView[2][2]);
112+
109113
// Setup *everything*. We don't want to enter multiple conditional
110114
// statements if we can avoid it. So we assume everything has not been
111115
// setup (including uniforms) if the simple geom hasn't been setup.
@@ -185,7 +189,6 @@ class RenderBasicSysTrans :
185189
bool cullFace = glIsEnabled(GL_CULL_FACE);
186190
bool blend = glIsEnabled(GL_BLEND);
187191

188-
GL(glEnable(GL_DEPTH_TEST));
189192
GL(glDepthMask(GL_FALSE));
190193
GL(glDisable(GL_CULL_FACE));
191194
GL(glEnable(GL_BLEND));

src/Interface/Modules/Render/ES/systems/RenderTransColorMapSys.cc

Lines changed: 38 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -56,7 +56,8 @@ class RenderColorMapSysTrans :
5656
StaticWorldLight,
5757
gen::StaticCamera,
5858
ren::StaticGLState,
59-
ren::StaticVBOMan>
59+
ren::StaticVBOMan,
60+
ren::StaticIBOMan>
6061
{
6162
public:
6263

@@ -91,7 +92,8 @@ class RenderColorMapSysTrans :
9192
const es::ComponentGroup<StaticWorldLight>& worldLight,
9293
const es::ComponentGroup<gen::StaticCamera>& camera,
9394
const es::ComponentGroup<ren::StaticGLState>& defaultGLState,
94-
const es::ComponentGroup<ren::StaticVBOMan>& vboMan) override
95+
const es::ComponentGroup<ren::StaticVBOMan>& vboMan,
96+
const es::ComponentGroup<ren::StaticIBOMan>& iboMan) override
9597
{
9698
/// \todo This needs to be moved to pre-execute.
9799
if (glCheckFramebufferStatus(GL_FRAMEBUFFER) != GL_FRAMEBUFFER_COMPLETE)
@@ -104,6 +106,39 @@ class RenderColorMapSysTrans :
104106
return;
105107
}
106108

109+
GLuint iboID = ibo.front().glid;
110+
GLuint iboXID = ibo.front().glid;
111+
GLuint iboYID = ibo.front().glid;
112+
GLuint iboZID = ibo.front().glid;
113+
114+
int index = 0;
115+
for (auto it = ibo.begin(); it != ibo.end(); ++it, ++index)
116+
{
117+
if (index == 1)
118+
iboXID = it->glid;
119+
if (index == 2)
120+
iboYID = it->glid;
121+
if (index == 3)
122+
iboZID = it->glid;
123+
}
124+
125+
Core::Geometry::Vector currentDir(camera.front().data.worldToView[0][2],
126+
camera.front().data.worldToView[1][2],
127+
camera.front().data.worldToView[2][2]);
128+
129+
130+
std::cout << "CurrentDir: " << currentDir << std::endl;
131+
132+
currentDir.normalize();
133+
134+
std::cout << "CurrentDirNormalize: " << currentDir << std::endl;
135+
136+
currentDir.safe_normalize();
137+
138+
std::cout << "CurrentDirSafeNormalize: " << currentDir << std::endl;
139+
140+
iboID = iboXID;
141+
107142
// Setup *everything*. We don't want to enter multiple conditional
108143
// statements if we can avoid it. So we assume everything has not been
109144
// setup (including uniforms) if the simple geom hasn't been setup.
@@ -159,7 +194,7 @@ class RenderColorMapSysTrans :
159194

160195
// Bind VBO and IBO
161196
GL(glBindBuffer(GL_ARRAY_BUFFER, vbo.front().glid));
162-
GL(glBindBuffer(GL_ELEMENT_ARRAY_BUFFER, ibo.front().glid));
197+
GL(glBindBuffer(GL_ELEMENT_ARRAY_BUFFER, iboID));
163198

164199
// Bind any common uniforms.
165200
if (commonUniforms.size() > 0)
@@ -196,7 +231,6 @@ class RenderColorMapSysTrans :
196231
bool cullFace = glIsEnabled(GL_CULL_FACE);
197232
bool blend = glIsEnabled(GL_BLEND);
198233

199-
GL(glEnable(GL_DEPTH_TEST));
200234
GL(glDepthMask(GL_FALSE));
201235
GL(glDisable(GL_CULL_FACE));
202236
GL(glEnable(GL_BLEND));

0 commit comments

Comments
 (0)