mirror of
https://github.com/Almamu/linux-wallpaperengine.git
synced 2025-07-13 21:02:34 +08:00
Simplified image rendering code further
Signed-off-by: Alexis Maiquez <almamu@almamu.com>
This commit is contained in:
parent
cb6f05ff27
commit
7e6cb9a458
@ -231,6 +231,40 @@ void CImage::setup ()
|
||||
this->m_effects.emplace_back (new CEffect (this, *cur));
|
||||
}
|
||||
|
||||
// prepare the passes list
|
||||
if (this->getEffects ().empty () == false)
|
||||
{
|
||||
auto effectCur = this->getEffects ().begin ();
|
||||
auto effectEnd = this->getEffects ().end ();
|
||||
|
||||
for (; effectCur != effectEnd; effectCur ++)
|
||||
{
|
||||
auto materialCur = (*effectCur)->getMaterials ().begin ();
|
||||
auto materialEnd = (*effectCur)->getMaterials ().end ();
|
||||
|
||||
for (; materialCur != materialEnd; materialCur ++)
|
||||
{
|
||||
auto passCur = (*materialCur)->getPasses ().begin ();
|
||||
auto passEnd = (*materialCur)->getPasses ().end ();
|
||||
|
||||
for (; passCur != passEnd; passCur ++)
|
||||
{
|
||||
this->m_passes.push_back (*passCur);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// add the final passes too
|
||||
if (this->m_material->getPasses ().empty () == false)
|
||||
{
|
||||
auto passCur = this->m_material->getPasses ().begin ();
|
||||
auto passEnd = this->m_material->getPasses ().end ();
|
||||
|
||||
for (; passCur != passEnd; passCur ++)
|
||||
this->m_passes.push_back (*passCur);
|
||||
}
|
||||
|
||||
// calculate full animation time (if any)
|
||||
this->m_animationTime = 0.0f;
|
||||
|
||||
@ -275,67 +309,6 @@ void CImage::simpleRender ()
|
||||
|
||||
void CImage::complexRender ()
|
||||
{
|
||||
// start drawing to the main framebuffer
|
||||
CFBO* drawTo = this->m_currentMainFBO;
|
||||
ITexture* asInput = this->getTexture ();
|
||||
|
||||
// render all the other materials
|
||||
auto effectCur = this->getEffects ().begin ();
|
||||
auto effectEnd = this->getEffects ().end ();
|
||||
|
||||
for (; effectCur != effectEnd; effectCur ++)
|
||||
{
|
||||
auto materialCur = (*effectCur)->getMaterials ().begin ();
|
||||
auto materialEnd = (*effectCur)->getMaterials ().end ();
|
||||
|
||||
for (; materialCur != materialEnd; materialCur ++)
|
||||
{
|
||||
CFBO* prevDrawTo = drawTo;
|
||||
GLuint spacePosition = *this->getCopySpacePosition ();
|
||||
|
||||
// set viewport and target texture if needed
|
||||
if ((*materialCur)->getMaterial ()->hasTarget () == true)
|
||||
{
|
||||
// setup target texture
|
||||
std::string target = (*materialCur)->getMaterial ()->getTarget ();
|
||||
drawTo = (*effectCur)->findFBO (target);
|
||||
spacePosition = *this->getPassSpacePosition ();
|
||||
|
||||
// not a local fbo, try to find a scene fbo with the same name
|
||||
if (drawTo == nullptr)
|
||||
// this one throws if no fbo was found
|
||||
drawTo = this->getScene ()->findFBO (target);
|
||||
}
|
||||
|
||||
auto passCur = (*materialCur)->getPasses ().begin ();
|
||||
auto passEnd = (*materialCur)->getPasses ().end ();
|
||||
|
||||
for (; passCur != passEnd; passCur ++)
|
||||
{
|
||||
(*passCur)->render (drawTo, asInput, spacePosition, *this->getTexCoordPass (), this->m_modelViewProjectionPass);
|
||||
|
||||
if ((*materialCur)->getMaterial ()->hasTarget () == false)
|
||||
this->pinpongFramebuffer (&drawTo, &asInput);
|
||||
}
|
||||
|
||||
if ((*materialCur)->getMaterial ()->hasTarget () == true)
|
||||
drawTo = prevDrawTo;
|
||||
}
|
||||
}
|
||||
|
||||
// the render has to happen anyway unless it's visible as it might be used by other images
|
||||
if (this->getImage ()->isVisible () == false)
|
||||
return;
|
||||
|
||||
// final step, this one might need more changes, should passes render directly to the output instead of an intermediate framebuffer?
|
||||
// do the first pass render into the main framebuffer
|
||||
auto cur = this->m_material->getPasses ().begin ();
|
||||
auto end = this->m_material->getPasses ().end ();
|
||||
|
||||
glColorMask (true, true, true, false);
|
||||
|
||||
for (; cur != end; cur ++)
|
||||
(*cur)->render (this->getScene ()->getFBO (), asInput, *this->getSceneSpacePosition (), *this->getTexCoordPass (), this->m_modelViewProjectionScreen);
|
||||
}
|
||||
|
||||
void CImage::render ()
|
||||
@ -350,11 +323,57 @@ void CImage::render ()
|
||||
|
||||
glColorMask (true, true, true, true);
|
||||
|
||||
// check if there's more than one pass and do different things based on that
|
||||
if (this->m_effects.empty () == true)
|
||||
this->simpleRender ();
|
||||
else
|
||||
this->complexRender ();
|
||||
// start drawing to the main framebuffer
|
||||
CFBO* drawTo = this->m_currentMainFBO;
|
||||
ITexture* asInput = this->getTexture ();
|
||||
GLuint texcoord = *this->getTexCoordCopy ();
|
||||
|
||||
auto cur = this->m_passes.begin ();
|
||||
auto end = this->m_passes.end ();
|
||||
|
||||
for (; cur != end; cur ++)
|
||||
{
|
||||
Effects::CPass* pass = *cur;
|
||||
CFBO* prevDrawTo = drawTo;
|
||||
GLuint spacePosition = *this->getCopySpacePosition ();
|
||||
glm::mat4 projection = this->m_modelViewProjectionPass;
|
||||
|
||||
// set viewport and target texture if needed
|
||||
if (pass->getMaterial ()->getMaterial ()->hasTarget () == true)
|
||||
{
|
||||
// setup target texture
|
||||
std::string target = pass->getMaterial ()->getMaterial ()->getTarget ();
|
||||
drawTo = pass->getMaterial ()->getEffect ()->findFBO (target);
|
||||
spacePosition = *this->getPassSpacePosition ();
|
||||
|
||||
// not a local fbo, try to find a scene fbo with the same name
|
||||
if (drawTo == nullptr)
|
||||
// this one throws if no fbo was found
|
||||
drawTo = this->getScene ()->findFBO (target);
|
||||
}
|
||||
|
||||
// determine if it's the last element in the list as this is a screen-copy-like process
|
||||
else if (std::next (cur) == end)
|
||||
{
|
||||
// do not draw to screen if the image is not visible
|
||||
if (this->getImage ()->isVisible () == false)
|
||||
return;
|
||||
|
||||
spacePosition = *this->getSceneSpacePosition ();
|
||||
drawTo = this->getScene ()->getFBO ();
|
||||
projection = this->m_modelViewProjectionScreen;
|
||||
|
||||
glColorMask (true, true, true, false);
|
||||
}
|
||||
|
||||
pass->render (drawTo, asInput, spacePosition, texcoord, projection);
|
||||
|
||||
texcoord = *this->getTexCoordPass ();
|
||||
drawTo = prevDrawTo;
|
||||
|
||||
if (pass->getMaterial ()->getMaterial ()->hasTarget () == false)
|
||||
this->pinpongFramebuffer (&drawTo, &asInput);
|
||||
}
|
||||
}
|
||||
|
||||
ITexture* CImage::getTexture () const
|
||||
|
@ -3,6 +3,7 @@
|
||||
#include "WallpaperEngine/Core/Objects/CImage.h"
|
||||
|
||||
#include "WallpaperEngine/Render/Objects/Effects/CMaterial.h"
|
||||
#include "WallpaperEngine/Render/Objects/Effects/CPass.h"
|
||||
#include "WallpaperEngine/Render/Objects/CEffect.h"
|
||||
#include "WallpaperEngine/Render/CObject.h"
|
||||
#include "WallpaperEngine/Render/CScene.h"
|
||||
@ -19,6 +20,7 @@ using namespace WallpaperEngine::Assets;
|
||||
namespace WallpaperEngine::Render::Objects::Effects
|
||||
{
|
||||
class CMaterial;
|
||||
class CPass;
|
||||
}
|
||||
|
||||
namespace WallpaperEngine::Render::Objects
|
||||
@ -80,6 +82,7 @@ namespace WallpaperEngine::Render::Objects
|
||||
|
||||
std::vector<CEffect*> m_effects;
|
||||
Effects::CMaterial* m_material;
|
||||
std::vector <Effects::CPass*> m_passes;
|
||||
|
||||
double m_animationTime;
|
||||
|
||||
|
@ -34,4 +34,9 @@ void CMaterial::generatePasses ()
|
||||
const Core::Objects::Images::CMaterial* CMaterial::getMaterial () const
|
||||
{
|
||||
return this->m_material;
|
||||
}
|
||||
|
||||
const CEffect* CMaterial::getEffect () const
|
||||
{
|
||||
return this->m_effect;
|
||||
}
|
@ -29,6 +29,7 @@ namespace WallpaperEngine::Render::Objects::Effects
|
||||
const std::vector<CPass*>& getPasses () const;
|
||||
CImage* getImage () const;
|
||||
const Core::Objects::Images::CMaterial* getMaterial () const;
|
||||
const CEffect* getEffect () const;
|
||||
|
||||
private:
|
||||
void generatePasses ();
|
||||
|
@ -276,6 +276,11 @@ void CPass::render (CFBO* drawTo, ITexture* input, GLuint position, GLuint texco
|
||||
}
|
||||
}
|
||||
|
||||
const CMaterial* CPass::getMaterial () const
|
||||
{
|
||||
return this->m_material;
|
||||
}
|
||||
|
||||
GLuint CPass::compileShader (Render::Shaders::Compiler* shader, GLuint type)
|
||||
{
|
||||
// reserve shaders in OpenGL
|
||||
|
@ -23,6 +23,8 @@ namespace WallpaperEngine::Render::Objects::Effects
|
||||
|
||||
void render (CFBO* drawTo, ITexture* input, GLuint position, GLuint texcoord, glm::mat4 projection);
|
||||
|
||||
const CMaterial* getMaterial () const;
|
||||
|
||||
private:
|
||||
enum UniformType
|
||||
{
|
||||
|
@ -517,7 +517,7 @@ namespace WallpaperEngine::Render::Shaders
|
||||
"#define float1 float\n"
|
||||
"#define float2 vec2\n"
|
||||
"#define float3 vec3\n"
|
||||
"#define float4 vec4\n";
|
||||
"#define float4 vec4\n\n";
|
||||
|
||||
finalCode += "// ======================================================\n"
|
||||
"// Shader combo parameter definitions\n"
|
||||
@ -689,11 +689,6 @@ namespace WallpaperEngine::Render::Shaders
|
||||
}
|
||||
else if (type == "sampler2D")
|
||||
{
|
||||
if (this->m_file.find ("effects/blur_combine") != std::string::npos)
|
||||
{
|
||||
int i = 0;
|
||||
}
|
||||
|
||||
// samplers can have special requirements, check what sampler we're working with and create definitions
|
||||
// if needed
|
||||
auto combo = data.find ("combo");
|
||||
|
Loading…
Reference in New Issue
Block a user