mirror of
https://github.com/Almamu/linux-wallpaperengine.git
synced 2025-09-14 13:56:48 +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));
|
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)
|
// calculate full animation time (if any)
|
||||||
this->m_animationTime = 0.0f;
|
this->m_animationTime = 0.0f;
|
||||||
|
|
||||||
@ -275,67 +309,6 @@ void CImage::simpleRender ()
|
|||||||
|
|
||||||
void CImage::complexRender ()
|
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 ()
|
void CImage::render ()
|
||||||
@ -350,11 +323,57 @@ void CImage::render ()
|
|||||||
|
|
||||||
glColorMask (true, true, true, true);
|
glColorMask (true, true, true, true);
|
||||||
|
|
||||||
// check if there's more than one pass and do different things based on that
|
// start drawing to the main framebuffer
|
||||||
if (this->m_effects.empty () == true)
|
CFBO* drawTo = this->m_currentMainFBO;
|
||||||
this->simpleRender ();
|
ITexture* asInput = this->getTexture ();
|
||||||
else
|
GLuint texcoord = *this->getTexCoordCopy ();
|
||||||
this->complexRender ();
|
|
||||||
|
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
|
ITexture* CImage::getTexture () const
|
||||||
|
@ -3,6 +3,7 @@
|
|||||||
#include "WallpaperEngine/Core/Objects/CImage.h"
|
#include "WallpaperEngine/Core/Objects/CImage.h"
|
||||||
|
|
||||||
#include "WallpaperEngine/Render/Objects/Effects/CMaterial.h"
|
#include "WallpaperEngine/Render/Objects/Effects/CMaterial.h"
|
||||||
|
#include "WallpaperEngine/Render/Objects/Effects/CPass.h"
|
||||||
#include "WallpaperEngine/Render/Objects/CEffect.h"
|
#include "WallpaperEngine/Render/Objects/CEffect.h"
|
||||||
#include "WallpaperEngine/Render/CObject.h"
|
#include "WallpaperEngine/Render/CObject.h"
|
||||||
#include "WallpaperEngine/Render/CScene.h"
|
#include "WallpaperEngine/Render/CScene.h"
|
||||||
@ -19,6 +20,7 @@ using namespace WallpaperEngine::Assets;
|
|||||||
namespace WallpaperEngine::Render::Objects::Effects
|
namespace WallpaperEngine::Render::Objects::Effects
|
||||||
{
|
{
|
||||||
class CMaterial;
|
class CMaterial;
|
||||||
|
class CPass;
|
||||||
}
|
}
|
||||||
|
|
||||||
namespace WallpaperEngine::Render::Objects
|
namespace WallpaperEngine::Render::Objects
|
||||||
@ -80,6 +82,7 @@ namespace WallpaperEngine::Render::Objects
|
|||||||
|
|
||||||
std::vector<CEffect*> m_effects;
|
std::vector<CEffect*> m_effects;
|
||||||
Effects::CMaterial* m_material;
|
Effects::CMaterial* m_material;
|
||||||
|
std::vector <Effects::CPass*> m_passes;
|
||||||
|
|
||||||
double m_animationTime;
|
double m_animationTime;
|
||||||
|
|
||||||
|
@ -35,3 +35,8 @@ const Core::Objects::Images::CMaterial* CMaterial::getMaterial () const
|
|||||||
{
|
{
|
||||||
return this->m_material;
|
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;
|
const std::vector<CPass*>& getPasses () const;
|
||||||
CImage* getImage () const;
|
CImage* getImage () const;
|
||||||
const Core::Objects::Images::CMaterial* getMaterial () const;
|
const Core::Objects::Images::CMaterial* getMaterial () const;
|
||||||
|
const CEffect* getEffect () const;
|
||||||
|
|
||||||
private:
|
private:
|
||||||
void generatePasses ();
|
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)
|
GLuint CPass::compileShader (Render::Shaders::Compiler* shader, GLuint type)
|
||||||
{
|
{
|
||||||
// reserve shaders in OpenGL
|
// 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);
|
void render (CFBO* drawTo, ITexture* input, GLuint position, GLuint texcoord, glm::mat4 projection);
|
||||||
|
|
||||||
|
const CMaterial* getMaterial () const;
|
||||||
|
|
||||||
private:
|
private:
|
||||||
enum UniformType
|
enum UniformType
|
||||||
{
|
{
|
||||||
|
@ -517,7 +517,7 @@ namespace WallpaperEngine::Render::Shaders
|
|||||||
"#define float1 float\n"
|
"#define float1 float\n"
|
||||||
"#define float2 vec2\n"
|
"#define float2 vec2\n"
|
||||||
"#define float3 vec3\n"
|
"#define float3 vec3\n"
|
||||||
"#define float4 vec4\n";
|
"#define float4 vec4\n\n";
|
||||||
|
|
||||||
finalCode += "// ======================================================\n"
|
finalCode += "// ======================================================\n"
|
||||||
"// Shader combo parameter definitions\n"
|
"// Shader combo parameter definitions\n"
|
||||||
@ -689,11 +689,6 @@ namespace WallpaperEngine::Render::Shaders
|
|||||||
}
|
}
|
||||||
else if (type == "sampler2D")
|
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
|
// samplers can have special requirements, check what sampler we're working with and create definitions
|
||||||
// if needed
|
// if needed
|
||||||
auto combo = data.find ("combo");
|
auto combo = data.find ("combo");
|
||||||
|
Loading…
Reference in New Issue
Block a user