Skip to content

Commit

Permalink
Removed most glHasGeometryShader
Browse files Browse the repository at this point in the history
  • Loading branch information
hudrima1 committed Dec 9, 2023
1 parent 47bfa2c commit 3365c24
Show file tree
Hide file tree
Showing 7 changed files with 153 additions and 161 deletions.
20 changes: 10 additions & 10 deletions apps/app_demo_slproject/source/AppDemoGui.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -3703,6 +3703,16 @@ void AppDemoGui::buildProperties(SLScene* s, SLSceneView* sv)
SLParticleSystem* ps = dynamic_cast<SLParticleSystem*>(singleFullMesh); // Need to check if good practice
ImGui::PushItemWidth(ImGui::GetWindowWidth() * 0.5f);

if (SLGLState::instance()->glHasGeometryShaders())
{
bool drawInstanced = ps->drawInstanced();
if (ImGui::Checkbox("Instanced draw", &drawInstanced))
{
ps->drawInstanced(drawInstanced);
ps->isGenerated(false);
}
}

// Pause and Resume
bool isPaused = ps->isPaused();
if (isPaused)
Expand All @@ -3729,16 +3739,6 @@ void AppDemoGui::buildProperties(SLScene* s, SLSceneView* sv)
ps->isGenerated(false);
}

if (SLGLState::instance()->glHasGeometryShaders())
{
bool drawInstanced = ps->drawInstanced();
if (ImGui::Checkbox("Instanced draw", &drawInstanced))
{
ps->drawInstanced(drawInstanced);
ps->isGenerated(false);
}
}

// TTL (Time to live)
if (ImGui::CollapsingHeader("Time to live"))
{
Expand Down
267 changes: 131 additions & 136 deletions apps/app_demo_slproject/source/AppDemoLoad.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -3584,7 +3584,7 @@ resolution shadows near the camera and lower resolution shadows further away.");
scene->addChild(cam1);

std::uniform_real_distribution<float> dist(0.0f, 1.0f);
std::default_random_engine randEngine;
std::default_random_engine randEngine;

// create astroboys around the center astroboy
SLint size = 4;
Expand Down Expand Up @@ -5628,7 +5628,7 @@ resolution shadows near the camera and lower resolution shadows further away.");
#ifndef SL_GLES
SLuint numSamples = 10;
#else
SLuint numSamples = 4;
SLuint numSamples = 4;
#endif

stringstream ss;
Expand Down Expand Up @@ -5720,7 +5720,7 @@ resolution shadows near the camera and lower resolution shadows further away.");
#ifndef APP_USES_GLES
SLuint numSamples = 10;
#else
SLuint numSamples = 6;
SLuint numSamples = 6;
#endif

// Scene
Expand Down Expand Up @@ -5817,52 +5817,53 @@ resolution shadows near the camera and lower resolution shadows further away.");

sv->camera(cam1);
}
if (sceneID == SID_ParticleSystem_First) //...............................................

else if (sceneID == SID_ParticleSystem_First) //...............................................
{
if (stateGL->glHasGeometryShaders())
{
// Set scene name and info string
s->name("First particle system");
s->info("First scene with a particle system");
// Set scene name and info string
s->name("First particle system");
s->info("First scene with a particle system");

// Create a scene group node
SLNode* scene = new SLNode("scene node");
s->root3D(scene);
// Create a scene group node
SLNode* scene = new SLNode("scene node");
s->root3D(scene);

// Create and add camera
SLCamera* cam1 = new SLCamera("Camera 1");
cam1->translation(0, 1.5f, 4);
cam1->lookAt(0, 1.5f, 0);
scene->addChild(cam1);
// Create and add camera
SLCamera* cam1 = new SLCamera("Camera 1");
cam1->translation(0, 1.5f, 4);
cam1->lookAt(0, 1.5f, 0);
scene->addChild(cam1);

// Create textures and materials
SLGLTexture* texC = new SLGLTexture(am, texPath + "ParticleSmoke_08_C.png");
SLGLTexture* texFlipbook = new SLGLTexture(am, texPath + "ParticleSmoke_03_8x8_C.png");
// Create textures and materials
SLGLTexture* texC = new SLGLTexture(am,
texPath + "ParticleSmoke_08_C.png");
SLGLTexture* texFlipbook = new SLGLTexture(am,
texPath + "ParticleSmoke_03_8x8_C.png");

// Create a light source node
SLLightSpot* light1 = new SLLightSpot(am, s, 0.3f);
light1->translation(5, 5, 5);
light1->name("light node");
scene->addChild(light1);
// Create a light source node
SLLightSpot* light1 = new SLLightSpot(am, s, 0.3f);
light1->translation(5, 5, 5);
light1->name("light node");
scene->addChild(light1);

// Create meshes and nodes
SLParticleSystem* ps = new SLParticleSystem(am,
50,
SLVec3f(0.04f, 0.4f, 0.1f),
SLVec3f(-0.11f, 0.7f, -0.1f),
4.0f,
texC,
"Particle System",
texFlipbook);
SLNode* pSNode = new SLNode(ps, "Particle system node");
scene->addChild(pSNode);

// Set background color and the root scene node
sv->sceneViewCamera()->background().colors(SLCol4f(0.8f, 0.8f, 0.8f),
SLCol4f(0.2f, 0.2f, 0.2f));
sv->camera(cam1);
sv->doWaitOnIdle(false);
}
// Create meshes and nodes
SLParticleSystem* ps = new SLParticleSystem(am,
50,
SLVec3f(0.04f, 0.4f, 0.1f),
SLVec3f(-0.11f, 0.7f, -0.1f),
4.0f,
texC,
"Particle System",
texFlipbook);

SLNode* pSNode = new SLNode(ps, "Particle system node");
scene->addChild(pSNode);

// Set background color and the root scene node
sv->sceneViewCamera()->background().colors(SLCol4f(0.8f, 0.8f, 0.8f),
SLCol4f(0.2f, 0.2f, 0.2f));
sv->camera(cam1);
sv->doWaitOnIdle(false);
}
else if (sceneID == SID_ParticleSystem_Demo) //................................................
{
Expand Down Expand Up @@ -6711,109 +6712,103 @@ resolution shadows near the camera and lower resolution shadows further away.");
}
else if (sceneID == SID_Benchmark8_ParticleSystemFireComplex) //...............................
{
if (stateGL->glHasGeometryShaders())
{
s->name("Fire Complex Test Scene");
s->info(s->name());
s->name("Fire Complex Test Scene");
s->info(s->name());

SLCamera* cam1 = new SLCamera("Camera 1");
cam1->clipNear(0.1f);
cam1->clipFar(1000);
cam1->translation(0, 10, 40);
cam1->focalDist(100);
cam1->lookAt(0, 0, 0);
cam1->background().colors(SLCol4f(0.3f, 0.3f, 0.3f));
cam1->setInitialState();
SLCamera* cam1 = new SLCamera("Camera 1");
cam1->clipNear(0.1f);
cam1->clipFar(1000);
cam1->translation(0, 10, 40);
cam1->focalDist(100);
cam1->lookAt(0, 0, 0);
cam1->background().colors(SLCol4f(0.3f, 0.3f, 0.3f));
cam1->setInitialState();

// Root scene node
SLNode* root = new SLNode;
s->root3D(root);
root->addChild(cam1);
const int NUM_NODES = 250;

// Create textures and materials
SLGLTexture* texFireCld = new SLGLTexture(am, texPath + "ParticleFirecloudTransparent_C.png");
SLGLTexture* texFireFlm = new SLGLTexture(am, texPath + "ParticleFlames_00_8x4_C.png");
SLGLTexture* texCircle = new SLGLTexture(am, texPath + "ParticleCircle_05_C.png");
SLGLTexture* texSmokeB = new SLGLTexture(am, texPath + "ParticleCloudBlack_C.png");
SLGLTexture* texSmokeW = new SLGLTexture(am, texPath + "ParticleCloudWhite_C.png");

SLVNode nodes(NUM_NODES);
for (int i = 0; i < NUM_NODES; ++i)
{
SLNode* fireComplex = createComplexFire(am,
s,
false,
texFireCld,
texFireFlm,
8,
4,
texCircle,
texSmokeB,
texSmokeW);
fireComplex->translate(-20.0f + (float)(i % 20) * 2,
0.0f,
-(float)((i - (i % 20)) / 20) * 4,
TS_object);
root->addChild(fireComplex);
}
// Root scene node
SLNode* root = new SLNode;
s->root3D(root);
root->addChild(cam1);
const int NUM_NODES = 250;

sv->camera(cam1);
sv->doWaitOnIdle(false);
// Create textures and materials
SLGLTexture* texFireCld = new SLGLTexture(am, texPath + "ParticleFirecloudTransparent_C.png");
SLGLTexture* texFireFlm = new SLGLTexture(am, texPath + "ParticleFlames_00_8x4_C.png");
SLGLTexture* texCircle = new SLGLTexture(am, texPath + "ParticleCircle_05_C.png");
SLGLTexture* texSmokeB = new SLGLTexture(am, texPath + "ParticleCloudBlack_C.png");
SLGLTexture* texSmokeW = new SLGLTexture(am, texPath + "ParticleCloudWhite_C.png");

SLVNode nodes(NUM_NODES);
for (int i = 0; i < NUM_NODES; ++i)
{
SLNode* fireComplex = createComplexFire(am,
s,
false,
texFireCld,
texFireFlm,
8,
4,
texCircle,
texSmokeB,
texSmokeW);
fireComplex->translate(-20.0f + (float)(i % 20) * 2,
0.0f,
-(float)((i - (float)(i % 20)) / 20) * 4,
TS_object);
root->addChild(fireComplex);
}

sv->camera(cam1);
sv->doWaitOnIdle(false);
}
else if (sceneID == SID_Benchmark9_ParticleSystemManyParticles) //.............................
{
if (stateGL->glHasGeometryShaders())
{
s->name("Particle System number Scene");
s->info(s->name());
s->name("Particle System number Scene");
s->info(s->name());

SLCamera* cam1 = new SLCamera("Camera 1");
cam1->clipNear(0.1f);
cam1->clipFar(1000);
cam1->translation(0, 0, 400);
cam1->focalDist(400);
cam1->lookAt(0, 0, 0);
cam1->background().colors(SLCol4f(0.3f, 0.3f, 0.3f));
cam1->setInitialState();
SLCamera* cam1 = new SLCamera("Camera 1");
cam1->clipNear(0.1f);
cam1->clipFar(1000);
cam1->translation(0, 0, 400);
cam1->focalDist(400);
cam1->lookAt(0, 0, 0);
cam1->background().colors(SLCol4f(0.3f, 0.3f, 0.3f));
cam1->setInitialState();

// Root scene node
SLNode* root = new SLNode;
root->addChild(cam1);

// Root scene node
SLNode* root = new SLNode;
root->addChild(cam1);

// Create textures and materials
SLGLTexture* texC = new SLGLTexture(am, texPath + "ParticleSmoke_08_C.png");
SLGLTexture* texFlipbook = new SLGLTexture(am, texPath + "ParticleSmoke_03_8x8_C.png");

// Create meshes and nodes
SLParticleSystem* ps = new SLParticleSystem(am,
1000000,
SLVec3f(-10.0f, -10.0f, -10.0f),
SLVec3f(10.0f, 10.0f, 10.0f),
4.0f,
texC,
"Particle System",
texFlipbook);
ps->doAlphaOverLT(false);
ps->doSizeOverLT(false);
ps->doRotation(false);
ps->doShape(true);
ps->shapeType(ST_Box);
ps->shapeScale(100.0f, 100.0f, 100.0f);
ps->doDirectionSpeed(true);
ps->doBlendBrightness(true);
ps->doColor(true);
ps->color(SLCol4f(0.875f, 0.156f, 0.875f, 1.0f));
ps->speed(0.0f);
SLMesh* pSMesh = ps;
SLNode* pSNode = new SLNode(pSMesh, "Particle system node");
root->addChild(pSNode);
// Create textures and materials
SLGLTexture* texC = new SLGLTexture(am, texPath + "ParticleSmoke_08_C.png");
SLGLTexture* texFlipbook = new SLGLTexture(am, texPath + "ParticleSmoke_03_8x8_C.png");

sv->camera(cam1);
sv->doWaitOnIdle(false);
s->root3D(root);
}
// Create meshes and nodes
SLParticleSystem* ps = new SLParticleSystem(am,
1000000,
SLVec3f(-10.0f, -10.0f, -10.0f),
SLVec3f(10.0f, 10.0f, 10.0f),
4.0f,
texC,
"Particle System",
texFlipbook);
ps->doAlphaOverLT(false);
ps->doSizeOverLT(false);
ps->doRotation(false);
ps->doShape(true);
ps->shapeType(ST_Box);
ps->shapeScale(100.0f, 100.0f, 100.0f);
ps->doDirectionSpeed(true);
ps->doBlendBrightness(true);
ps->doColor(true);
ps->color(SLCol4f(0.875f, 0.156f, 0.875f, 1.0f));
ps->speed(0.0f);
SLMesh* pSMesh = ps;
SLNode* pSNode = new SLNode(pSMesh, "Particle system node");
root->addChild(pSNode);

sv->camera(cam1);
sv->doWaitOnIdle(false);
s->root3D(root);
}

////////////////////////////////////////////////////////////////////////////
Expand Down
8 changes: 4 additions & 4 deletions modules/sl/source/SLMaterial.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -388,7 +388,7 @@ void SLMaterial::deleteDataGpu()
If this material has not yet a shader program assigned (SLMaterial::_program)
a suitable program will be generated with an instance of SLGLProgramGenerated.
*/
void SLMaterial::generateProgramPS(bool renderInstanced)
void SLMaterial::generateProgramPS(bool drawInstanced)
{
// If no shader program is attached add a generated shader program
// A 3D object can be stored without material or shader program information.
Expand All @@ -403,14 +403,14 @@ void SLMaterial::generateProgramPS(bool renderInstanced)
SLGLProgramGenerated::buildProgramNamePS(this,
programNameDraw,
true,
renderInstanced);
drawInstanced);
_program = _assetManager->getProgramByName(programNameDraw);

// If the program was not found by name generate a new one
if (!_program)
{
std::string geom = "";
if (!renderInstanced)
if (!drawInstanced)
geom = "Geom";

_program = new SLGLProgramGenerated(_assetManager,
Expand All @@ -429,7 +429,7 @@ void SLMaterial::generateProgramPS(bool renderInstanced)

// Check first the asset manager if the requested programTF type already exists
string programNameUpdate;
SLGLProgramGenerated::buildProgramNamePS(this, programNameUpdate, false, renderInstanced);
SLGLProgramGenerated::buildProgramNamePS(this, programNameUpdate, false, drawInstanced);
_programTF = _assetManager->getProgramByName(programNameUpdate);
if (!_programTF)
{
Expand Down
2 changes: 1 addition & 1 deletion modules/sl/source/SLMaterial.h
Original file line number Diff line number Diff line change
Expand Up @@ -108,7 +108,7 @@ class SLMaterial : public SLObject
SLGLProgram* program);

~SLMaterial() override;
void generateProgramPS(bool renderInstanced = false);
void generateProgramPS(bool drawInstanced = false);
void activate(SLCamera* cam, SLVLight* lights, SLbool supportGPUSkinning);
SLint passToUniforms(SLGLProgram* program, SLint nextTexUnit);

Expand Down
Loading

0 comments on commit 3365c24

Please sign in to comment.