- removed commented code from main.cpp that is not useful anymore

~ changed how g_Time is calculated so any shader that uses it should behave properly
~ changed how the uniforms are set to a reinterpret_cast instead of static_cast to perform a direct pointer conversion (safe as we know the types were actually those types)

Signed-off-by: Alexis Maiquez <almamu@almamu.com>
This commit is contained in:
Alexis Maiquez 2021-09-02 22:30:38 +02:00
parent 59e6800f81
commit 9d7d344b80
3 changed files with 12 additions and 91 deletions

View File

@ -230,8 +230,6 @@ int main (int argc, char* argv[])
auto sceneInformation = project->getWallpaper ()->as <WallpaperEngine::Core::CScene> (); auto sceneInformation = project->getWallpaper ()->as <WallpaperEngine::Core::CScene> ();
FloatColor clearColor = sceneInformation->getClearColor (); FloatColor clearColor = sceneInformation->getClearColor ();
glClearColor (clearColor.r, clearColor.g, clearColor.b, clearColor.a);
// enable depth text // enable depth text
glEnable (GL_DEPTH_TEST); glEnable (GL_DEPTH_TEST);
glDepthFunc (GL_LESS); glDepthFunc (GL_LESS);
@ -246,7 +244,7 @@ int main (int argc, char* argv[])
while (glfwWindowShouldClose (window) == 0) while (glfwWindowShouldClose (window) == 0)
{ {
// calculate the current time value // calculate the current time value
g_Time += static_cast <float> (endTime - startTime) / CLOCKS_PER_SEC; g_Time = (float) glfwGetTime ();
// get the start time of the frame // get the start time of the frame
startTime = clock (); startTime = clock ();
@ -255,6 +253,7 @@ int main (int argc, char* argv[])
// ensure we render over the whole screen // ensure we render over the whole screen
glViewport (0, 0, 1920, 1080); glViewport (0, 0, 1920, 1080);
glClearColor (clearColor.r, clearColor.g, clearColor.b, clearColor.a);
// clear window // clear window
glClear (GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT); glClear (GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
@ -279,79 +278,4 @@ int main (int argc, char* argv[])
SDL_Quit (); SDL_Quit ();
return 0; return 0;
/*
try
{
IrrlichtContext = new WallpaperEngine::Irrlicht::CContext (screens, isRootWindow);
IrrlichtContext->initializeContext ();
}
catch (std::runtime_error& ex)
{
std::cerr << ex.what () << std::endl;
return 1;
}
path = stringPathFixes (path);
irr::io::path wallpaper_path = IrrlichtContext->getDevice ()->getFileSystem ()->getAbsolutePath (path.c_str ());
irr::io::path project_path = wallpaper_path + "project.json";
if (mode == RUN_MODE_PACKAGE)
{
irr::io::path scene_path = wallpaper_path + "scene.pkg";
// add the package file to the lookup list
IrrlichtContext->getDevice ()->getFileSystem ()->addFileArchive (scene_path, true, false);
}
else if (mode == RUN_MODE_DIRECTORY)
{
project_path = wallpaper_path + "project.json";
// set the working directory to the project folder
IrrlichtContext->getDevice ()->getFileSystem ()->changeWorkingDirectoryTo (wallpaper_path);
}
WallpaperEngine::Core::CProject* project = WallpaperEngine::Core::CProject::fromFile (project_path);
WallpaperEngine::Render::CWallpaper* wallpaper;
if (project->getType () == "scene")
{
WallpaperEngine::Core::CScene* scene = project->getWallpaper ()->as <WallpaperEngine::Core::CScene> ();
wallpaper = new WallpaperEngine::Render::CScene (scene, IrrlichtContext);
IrrlichtContext->getDevice ()->getSceneManager ()->setAmbientLight (
scene->getAmbientColor ().toSColor ()
);
}
else if (project->getType () == "video")
{
wallpaper = new WallpaperEngine::Render::CVideo (
project->getWallpaper ()->as <WallpaperEngine::Core::CVideo> (),
IrrlichtContext
);
}
else
{
throw std::runtime_error ("Unsupported wallpaper type");
}
uint32_t minimumTime = 1000 / maximumFPS;
uint32_t startTime = 0;
uint32_t endTime = 0;
while (IrrlichtContext && IrrlichtContext->getDevice () && IrrlichtContext->getDevice ()->run ())
{
if (IrrlichtContext->getDevice ()->getVideoDriver () == nullptr)
continue;
startTime = IrrlichtContext->getDevice ()->getTimer ()->getTime ();
g_Time = startTime / 1000.0f;
IrrlichtContext->renderFrame (wallpaper);
endTime = IrrlichtContext->getDevice ()->getTimer ()->getTime ();
IrrlichtContext->getDevice ()->sleep (minimumTime - (endTime - startTime), false);
}
SDL_Quit ();
return 0;*/
} }

View File

@ -177,9 +177,6 @@ void CImage::render ()
// now render the last pass (to screen) // now render the last pass (to screen)
glBindBuffer (GL_ARRAY_BUFFER, *this->m_material->getImage ()->getVertexBuffer ()); glBindBuffer (GL_ARRAY_BUFFER, *this->m_material->getImage ()->getVertexBuffer ());
glDrawArrays (GL_TRIANGLES, 0, 6);*/ glDrawArrays (GL_TRIANGLES, 0, 6);*/
// flush stdout
std::cout << std::flush;
} }
/* /*

View File

@ -58,17 +58,17 @@ void CPass::render (GLuint drawTo, GLuint input)
if (this->m_pass->getBlendingMode () == "translucent") if (this->m_pass->getBlendingMode () == "translucent")
{ {
glEnable (GL_BLEND); glEnable (GL_BLEND);
glBlendFuncSeparate(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA, GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA); glBlendFuncSeparate (GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA, GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA);
} }
else if (this->m_pass->getBlendingMode () == "additive") else if (this->m_pass->getBlendingMode () == "additive")
{ {
glEnable (GL_BLEND); glEnable (GL_BLEND);
glBlendFuncSeparate(GL_SRC_ALPHA, GL_ONE, GL_SRC_ALPHA, GL_ONE); glBlendFuncSeparate (GL_SRC_ALPHA, GL_ONE, GL_SRC_ALPHA, GL_ONE);
} }
else if (this->m_pass->getBlendingMode () == "normal") else if (this->m_pass->getBlendingMode () == "normal")
{ {
glEnable (GL_BLEND); glEnable (GL_BLEND);
glBlendFuncSeparate(GL_ONE, GL_ZERO, GL_ONE, GL_ZERO); glBlendFuncSeparate (GL_ONE, GL_ZERO, GL_ONE, GL_ZERO);
} }
else else
{ {
@ -128,25 +128,25 @@ void CPass::render (GLuint drawTo, GLuint input)
switch ((*cur)->type) switch ((*cur)->type)
{ {
case Double: case Double:
glUniform1d ((*cur)->id, *static_cast <const double*> ((*cur)->value)); glUniform1d ((*cur)->id, *reinterpret_cast <const double*> ((*cur)->value));
break; break;
case Float: case Float:
glUniform1f ((*cur)->id, *static_cast <const float*> ((*cur)->value)); glUniform1f ((*cur)->id, *reinterpret_cast <const float*> ((*cur)->value));
break; break;
case Integer: case Integer:
glUniform1i ((*cur)->id, *static_cast <const int*> ((*cur)->value)); glUniform1i ((*cur)->id, *reinterpret_cast <const int*> ((*cur)->value));
break; break;
case Vector4: case Vector4:
glUniform4fv ((*cur)->id, 1, glm::value_ptr (*static_cast <const glm::vec4*> ((*cur)->value))); glUniform4fv ((*cur)->id, 1, glm::value_ptr (*reinterpret_cast <const glm::vec4*> ((*cur)->value)));
break; break;
case Vector3: case Vector3:
glUniform3fv ((*cur)->id, 1, glm::value_ptr (*static_cast <const glm::vec3*> ((*cur)->value))); glUniform3fv ((*cur)->id, 1, glm::value_ptr (*reinterpret_cast <const glm::vec3*> ((*cur)->value)));
break; break;
case Vector2: case Vector2:
glUniform2fv ((*cur)->id, 1, glm::value_ptr (*static_cast <const glm::vec2*> ((*cur)->value))); glUniform2fv ((*cur)->id, 1, glm::value_ptr (*reinterpret_cast <const glm::vec2*> ((*cur)->value)));
break; break;
case Matrix4: case Matrix4:
glUniformMatrix4fv ((*cur)->id, 1, GL_FALSE, glm::value_ptr (*static_cast <const glm::mat4*> ((*cur)->value))); glUniformMatrix4fv ((*cur)->id, 1, GL_FALSE, glm::value_ptr (*reinterpret_cast <const glm::mat4*> ((*cur)->value)));
break; break;
} }
} }