mirror of
https://github.com/Almamu/linux-wallpaperengine.git
synced 2025-07-14 13:22:23 +08:00
+ added mouse input handling and mouse position variable to shaders
+ added vector2 pointer class for shader parameters Signed-off-by: Alexis Maiquez <almamu@almamu.com>
This commit is contained in:
parent
d7cf8af7ca
commit
dc36adb200
@ -40,6 +40,8 @@ add_executable(
|
||||
|
||||
src/WallpaperEngine/Render/Shaders/Variables/CShaderVariableFloatPointer.h
|
||||
src/WallpaperEngine/Render/Shaders/Variables/CShaderVariableFloatPointer.cpp
|
||||
src/WallpaperEngine/Render/Shaders/Variables/CShaderVariableVector2Pointer.h
|
||||
src/WallpaperEngine/Render/Shaders/Variables/CShaderVariableVector2Pointer.cpp
|
||||
|
||||
src/WallpaperEngine/Render/Shaders/Compiler.h
|
||||
src/WallpaperEngine/Render/Shaders/Compiler.cpp
|
||||
@ -59,6 +61,8 @@ add_executable(
|
||||
src/WallpaperEngine/FileSystem/FileSystem.cpp
|
||||
src/WallpaperEngine/FileSystem/FileSystem.h
|
||||
|
||||
src/WallpaperEngine/Irrlicht/CEventReceiver.h
|
||||
src/WallpaperEngine/Irrlicht/CEventReceiver.cpp
|
||||
src/WallpaperEngine/Irrlicht/CContext.h
|
||||
src/WallpaperEngine/Irrlicht/CContext.cpp
|
||||
src/WallpaperEngine/Irrlicht/CImageLoaderTEX.h
|
||||
|
@ -9,6 +9,7 @@
|
||||
#include "WallpaperEngine/Irrlicht/CPkgReader.h"
|
||||
|
||||
#include "WallpaperEngine/Render/Shaders/Variables/CShaderVariableFloatPointer.h"
|
||||
#include "WallpaperEngine/Render/Shaders/Variables/CShaderVariableVector2Pointer.h"
|
||||
|
||||
#include "CContext.h"
|
||||
|
||||
@ -30,16 +31,19 @@ void CContext::initializeContext ()
|
||||
{
|
||||
irr::SIrrlichtCreationParameters irrlichtCreationParameters;
|
||||
|
||||
// initialize event receiver first
|
||||
this->m_eventReceiver = new CEventReceiver ();
|
||||
|
||||
// prepare basic configuration for irrlicht
|
||||
irrlichtCreationParameters.AntiAlias = 8;
|
||||
irrlichtCreationParameters.Bits = 16;
|
||||
// _irr_params.DeviceType = Irrlicht::EIDT_X11;
|
||||
irrlichtCreationParameters.DriverType = irr::video::EDT_OPENGL;
|
||||
irrlichtCreationParameters.Doublebuffer = false;
|
||||
irrlichtCreationParameters.EventReceiver = nullptr;
|
||||
irrlichtCreationParameters.EventReceiver = this->m_eventReceiver;
|
||||
irrlichtCreationParameters.Fullscreen = false;
|
||||
irrlichtCreationParameters.HandleSRGB = false;
|
||||
irrlichtCreationParameters.IgnoreInput = true;
|
||||
irrlichtCreationParameters.IgnoreInput = false;
|
||||
irrlichtCreationParameters.Stencilbuffer = true;
|
||||
irrlichtCreationParameters.UsePerformanceTimer = false;
|
||||
irrlichtCreationParameters.Vsync = false;
|
||||
@ -90,7 +94,11 @@ void CContext::initializeContext ()
|
||||
);
|
||||
// register time shader variable
|
||||
this->insertShaderVariable (
|
||||
new Render::Shaders::Variables::CShaderVariableFloatPointer (&this->m_time, 1, "g_Time")
|
||||
new Render::Shaders::Variables::CShaderVariableFloatPointer (&this->m_time, "g_Time")
|
||||
);
|
||||
// register normalized uv position for mouse
|
||||
this->insertShaderVariable (
|
||||
new Render::Shaders::Variables::CShaderVariableVector2Pointer (&this->m_pointerPosition, "g_PointerPosition")
|
||||
);
|
||||
}
|
||||
|
||||
@ -157,6 +165,8 @@ void CContext::initializeViewports (irr::SIrrlichtCreationParameters &irrlichtCr
|
||||
void CContext::renderFrame (Render::CScene* scene)
|
||||
{
|
||||
this->m_time = this->getDevice ()->getTimer ()->getTime () / 1000.0f;
|
||||
this->m_pointerPosition.X = this->m_eventReceiver->getPosition ().X / (irr::f32) this->getDevice ()->getVideoDriver ()->getScreenSize ().Width;
|
||||
this->m_pointerPosition.Y = this->m_eventReceiver->getPosition ().Y / (irr::f32) this->getDevice ()->getVideoDriver ()->getScreenSize ().Height;
|
||||
|
||||
if (this->m_viewports.empty () == true)
|
||||
{
|
||||
|
@ -9,6 +9,8 @@
|
||||
|
||||
#include "WallpaperEngine/Render/Shaders/Variables/CShaderVariable.h"
|
||||
|
||||
#include "CEventReceiver.h"
|
||||
|
||||
namespace WallpaperEngine::Render
|
||||
{
|
||||
class CScene;
|
||||
@ -40,10 +42,12 @@ namespace WallpaperEngine::Irrlicht
|
||||
irr::io::path resolveFile (const irr::io::path& file);
|
||||
|
||||
irr::IrrlichtDevice* m_device;
|
||||
CEventReceiver* m_eventReceiver;
|
||||
|
||||
std::vector<Render::Shaders::Variables::CShaderVariable*> m_globalShaderVariables;
|
||||
|
||||
irr::f32 m_time;
|
||||
irr::core::vector2df m_pointerPosition;
|
||||
|
||||
std::vector<std::string> m_screens;
|
||||
std::vector<irr::core::recti> m_viewports;
|
||||
|
20
src/WallpaperEngine/Irrlicht/CEventReceiver.cpp
Normal file
20
src/WallpaperEngine/Irrlicht/CEventReceiver.cpp
Normal file
@ -0,0 +1,20 @@
|
||||
#include "CEventReceiver.h"
|
||||
|
||||
using namespace WallpaperEngine::Irrlicht;
|
||||
|
||||
bool CEventReceiver::OnEvent(const irr::SEvent &event)
|
||||
{
|
||||
if (event.EventType == irr::EET_MOUSE_INPUT_EVENT && event.MouseInput.Event == irr::EMIE_MOUSE_MOVED)
|
||||
{
|
||||
this->m_position.X = event.MouseInput.X;
|
||||
this->m_position.Y = event.MouseInput.Y;
|
||||
return true;
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
const irr::core::position2di& CEventReceiver::getPosition () const
|
||||
{
|
||||
return this->m_position;
|
||||
}
|
18
src/WallpaperEngine/Irrlicht/CEventReceiver.h
Normal file
18
src/WallpaperEngine/Irrlicht/CEventReceiver.h
Normal file
@ -0,0 +1,18 @@
|
||||
#pragma once
|
||||
|
||||
#include <irrlicht/irrlicht.h>
|
||||
|
||||
namespace WallpaperEngine::Irrlicht
|
||||
{
|
||||
class CEventReceiver : public irr::IEventReceiver
|
||||
{
|
||||
public:
|
||||
// This is the one method that we have to implement
|
||||
bool OnEvent(const irr::SEvent& event) override;
|
||||
|
||||
const irr::core::position2di& getPosition () const;
|
||||
|
||||
private:
|
||||
irr::core::position2di m_position;
|
||||
};
|
||||
}
|
@ -236,10 +236,10 @@ void CImage::OnSetConstants (irr::video::IMaterialRendererServices *services, in
|
||||
);
|
||||
}
|
||||
else if (
|
||||
(*cur)->is <CShaderVariableFloat> () == true ||
|
||||
(*cur)->is <CShaderVariableVector2> () == true ||
|
||||
(*cur)->is <CShaderVariableVector3> () == true ||
|
||||
(*cur)->is <CShaderVariableVector4> () == true)
|
||||
(*cur)->is <CShaderVariableFloat> () == true ||
|
||||
(*cur)->is <CShaderVariableVector2> () == true ||
|
||||
(*cur)->is <CShaderVariableVector3> () == true ||
|
||||
(*cur)->is <CShaderVariableVector4> () == true)
|
||||
{
|
||||
services->setVertexShaderConstant (
|
||||
(*cur)->getName ().c_str (),
|
||||
@ -263,10 +263,10 @@ void CImage::OnSetConstants (irr::video::IMaterialRendererServices *services, in
|
||||
);
|
||||
}
|
||||
else if (
|
||||
(*cur)->is <CShaderVariableFloat> () == true ||
|
||||
(*cur)->is <CShaderVariableVector2> () == true ||
|
||||
(*cur)->is <CShaderVariableVector3> () == true ||
|
||||
(*cur)->is <CShaderVariableVector4> () == true)
|
||||
(*cur)->is <CShaderVariableFloat> () == true ||
|
||||
(*cur)->is <CShaderVariableVector2> () == true ||
|
||||
(*cur)->is <CShaderVariableVector3> () == true ||
|
||||
(*cur)->is <CShaderVariableVector4> () == true)
|
||||
{
|
||||
services->setPixelShaderConstant (
|
||||
(*cur)->getName ().c_str (),
|
||||
|
@ -516,7 +516,7 @@ namespace WallpaperEngine::Render::Shaders
|
||||
if (type == "vec4")
|
||||
{
|
||||
parameter = new Variables::CShaderVariableVector4 (
|
||||
WallpaperEngine::Core::ato3vf (*defvalue)
|
||||
WallpaperEngine::Core::ato3vf (*defvalue)
|
||||
);
|
||||
}
|
||||
else if (type == "vec3")
|
||||
|
@ -5,14 +5,12 @@
|
||||
using namespace WallpaperEngine::Render::Shaders::Variables;
|
||||
|
||||
|
||||
CShaderVariableFloatPointer::CShaderVariableFloatPointer(irr::f32* value, int size) :
|
||||
m_size (size),
|
||||
CShaderVariableFloatPointer::CShaderVariableFloatPointer(irr::f32* value) :
|
||||
CShaderVariable (value, nullptr, Type)
|
||||
{
|
||||
}
|
||||
|
||||
CShaderVariableFloatPointer::CShaderVariableFloatPointer(irr::f32* value, int size, std::string name) :
|
||||
m_size (size),
|
||||
CShaderVariableFloatPointer::CShaderVariableFloatPointer(irr::f32* value, std::string name) :
|
||||
CShaderVariable (value, nullptr, Type)
|
||||
{
|
||||
this->setName (std::move(name));
|
||||
@ -20,7 +18,7 @@ CShaderVariableFloatPointer::CShaderVariableFloatPointer(irr::f32* value, int si
|
||||
|
||||
const int CShaderVariableFloatPointer::getSize () const
|
||||
{
|
||||
return this->m_size;
|
||||
return 1;
|
||||
}
|
||||
|
||||
const std::string CShaderVariableFloatPointer::Type = "pointer";
|
||||
const std::string CShaderVariableFloatPointer::Type = "pointer_float";
|
@ -9,13 +9,12 @@ namespace WallpaperEngine::Render::Shaders::Variables
|
||||
class CShaderVariableFloatPointer : public CShaderVariable
|
||||
{
|
||||
public:
|
||||
CShaderVariableFloatPointer (irr::f32* value, int size);
|
||||
CShaderVariableFloatPointer (irr::f32* value, int size, std::string name);
|
||||
explicit CShaderVariableFloatPointer (irr::f32* value);
|
||||
CShaderVariableFloatPointer (irr::f32* value, std::string name);
|
||||
|
||||
const int getSize () const override;
|
||||
|
||||
static const std::string Type;
|
||||
private:
|
||||
int m_size;
|
||||
};
|
||||
}
|
||||
|
@ -0,0 +1,24 @@
|
||||
#include "CShaderVariableVector2Pointer.h"
|
||||
|
||||
#include <utility>
|
||||
|
||||
using namespace WallpaperEngine::Render::Shaders::Variables;
|
||||
|
||||
|
||||
CShaderVariableVector2Pointer::CShaderVariableVector2Pointer(irr::core::vector2df* value) :
|
||||
CShaderVariable (value, nullptr, Type)
|
||||
{
|
||||
}
|
||||
|
||||
CShaderVariableVector2Pointer::CShaderVariableVector2Pointer(irr::core::vector2df* value, std::string name) :
|
||||
CShaderVariable (value, nullptr, Type)
|
||||
{
|
||||
this->setName (std::move(name));
|
||||
}
|
||||
|
||||
const int CShaderVariableVector2Pointer::getSize () const
|
||||
{
|
||||
return 2;
|
||||
}
|
||||
|
||||
const std::string CShaderVariableVector2Pointer::Type = "pointer_vector2";
|
@ -0,0 +1,19 @@
|
||||
#pragma once
|
||||
|
||||
#include "CShaderVariable.h"
|
||||
|
||||
#include <irrlicht/irrlicht.h>
|
||||
|
||||
namespace WallpaperEngine::Render::Shaders::Variables
|
||||
{
|
||||
class CShaderVariableVector2Pointer : public CShaderVariable
|
||||
{
|
||||
public:
|
||||
CShaderVariableVector2Pointer (irr::core::vector2df* value);
|
||||
CShaderVariableVector2Pointer (irr::core::vector2df* value, std::string name);
|
||||
|
||||
const int getSize () const override;
|
||||
|
||||
static const std::string Type;
|
||||
};
|
||||
}
|
Loading…
Reference in New Issue
Block a user