added rest of basics in TSE_Core
This commit is contained in:
@@ -6,7 +6,7 @@ namespace TSE
|
|||||||
{
|
{
|
||||||
typedef std::string string;
|
typedef std::string string;
|
||||||
|
|
||||||
typedef char byte;
|
typedef unsigned char byte;
|
||||||
typedef signed char sbyte;
|
typedef signed char sbyte;
|
||||||
|
|
||||||
typedef unsigned short ushort;
|
typedef unsigned short ushort;
|
||||||
|
|||||||
1163
TSE_Core/include/FI/FreeImage.h
Normal file
1163
TSE_Core/include/FI/FreeImage.h
Normal file
File diff suppressed because it is too large
Load Diff
203
TSE_Core/src/BehaviourScripts/Camera.cpp
Normal file
203
TSE_Core/src/BehaviourScripts/Camera.cpp
Normal file
@@ -0,0 +1,203 @@
|
|||||||
|
#include "Camera.hpp"
|
||||||
|
#include "elements/Transformable.hpp"
|
||||||
|
#include "interfaces/IRenderer.hpp"
|
||||||
|
|
||||||
|
TSE::Camera* TSE::Camera::mainCamera = nullptr;
|
||||||
|
|
||||||
|
float TSE::Camera::GetRenderScale() const
|
||||||
|
{
|
||||||
|
return RenderScale;
|
||||||
|
}
|
||||||
|
|
||||||
|
TSE::ProjectionType TSE::Camera::GetProjection() const
|
||||||
|
{
|
||||||
|
return projection;
|
||||||
|
}
|
||||||
|
|
||||||
|
float TSE::Camera::GetNearClippingPlane() const
|
||||||
|
{
|
||||||
|
return nearClippingPlane;
|
||||||
|
}
|
||||||
|
|
||||||
|
float TSE::Camera::GetFarClippingPlane() const
|
||||||
|
{
|
||||||
|
return farClippingPlane;
|
||||||
|
}
|
||||||
|
|
||||||
|
float TSE::Camera::GetFov() const
|
||||||
|
{
|
||||||
|
return fov;
|
||||||
|
}
|
||||||
|
|
||||||
|
TSE::Vector3 TSE::Camera::SceenPositionToGamePosition(Vector2 screenPos)
|
||||||
|
{
|
||||||
|
float x = 2.0f * screenPos.x / lastRtSize.x -1.0f;
|
||||||
|
float y = 1.0f - 2.0f * screenPos.y / lastRtSize.y;
|
||||||
|
float z = -1.0f;
|
||||||
|
Vector4 ndc(x,y,x,1);
|
||||||
|
|
||||||
|
Matrix4x4 InversProj = Matrix4x4(*projectionMatrix);
|
||||||
|
InversProj.Invert();
|
||||||
|
Vector4 camSpace = InversProj * ndc;
|
||||||
|
camSpace = camSpace / camSpace.w;
|
||||||
|
Vector3 relativPos(camSpace);
|
||||||
|
relativPos.z = 0;
|
||||||
|
return baseObject->LocalToGlobalPosition(relativPos);
|
||||||
|
}
|
||||||
|
|
||||||
|
void TSE::Camera::SetRenderScale(float v)
|
||||||
|
{
|
||||||
|
RenderScale = v; RecalculateProjMatrix();
|
||||||
|
}
|
||||||
|
|
||||||
|
void TSE::Camera::SetProjection(ProjectionType v)
|
||||||
|
{
|
||||||
|
projection = v; RecalculateProjMatrix();
|
||||||
|
}
|
||||||
|
|
||||||
|
void TSE::Camera::SetNearClippingPlane(float v)
|
||||||
|
{
|
||||||
|
nearClippingPlane = v; RecalculateProjMatrix();
|
||||||
|
}
|
||||||
|
|
||||||
|
void TSE::Camera::SetFarClippingPlane(float v)
|
||||||
|
{
|
||||||
|
farClippingPlane = v; RecalculateProjMatrix();
|
||||||
|
}
|
||||||
|
|
||||||
|
void TSE::Camera::SetFov(float v)
|
||||||
|
{
|
||||||
|
fov = v; RecalculateProjMatrix();
|
||||||
|
}
|
||||||
|
|
||||||
|
TSE::Camera::Camera()
|
||||||
|
{
|
||||||
|
}
|
||||||
|
|
||||||
|
TSE::Camera::~Camera()
|
||||||
|
{
|
||||||
|
delete(projectionMatrix);
|
||||||
|
if(mainCamera == this)
|
||||||
|
mainCamera = nullptr;
|
||||||
|
}
|
||||||
|
|
||||||
|
void TSE::Camera::OnResize(float width, float height, IResizable *wnd)
|
||||||
|
{
|
||||||
|
lastRtSize = {width, height};
|
||||||
|
RecalculateProjMatrix();
|
||||||
|
}
|
||||||
|
|
||||||
|
void TSE::Camera::SetRenderTarget(IRenderTarget *target)
|
||||||
|
{
|
||||||
|
if(rt != nullptr)
|
||||||
|
rt->RemoveResizeNotifiable(this);
|
||||||
|
if(target != nullptr)
|
||||||
|
target->AddResizeNotifiable(this);
|
||||||
|
rt = target;
|
||||||
|
RecalculateProjMatrix();
|
||||||
|
}
|
||||||
|
|
||||||
|
TSE::IRenderTarget *TSE::Camera::GetRenderTarget()
|
||||||
|
{
|
||||||
|
return rt;
|
||||||
|
}
|
||||||
|
|
||||||
|
void TSE::Camera::RecalculateProjMatrix()
|
||||||
|
{
|
||||||
|
if(projectionMatrix)
|
||||||
|
delete(projectionMatrix);
|
||||||
|
|
||||||
|
if(projection == ProjectionType::Orthographic)
|
||||||
|
{
|
||||||
|
float x = lastRtSize.x / RenderScale;
|
||||||
|
float y = lastRtSize.y / RenderScale;
|
||||||
|
float mx = -x;
|
||||||
|
float my = -y;
|
||||||
|
projectionMatrix = new Matrix4x4(Matrix4x4::Orthographic(mx, x, my, y, nearClippingPlane, farClippingPlane));
|
||||||
|
}
|
||||||
|
else if(projection == ProjectionType::Perspective)
|
||||||
|
{
|
||||||
|
float x = lastRtSize.x / RenderScale;
|
||||||
|
float y = lastRtSize.y / RenderScale;
|
||||||
|
|
||||||
|
float aspectRatio = x / y;
|
||||||
|
|
||||||
|
projectionMatrix = new Matrix4x4(Matrix4x4::Perspective(fov, aspectRatio, nearClippingPlane, farClippingPlane));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
void TSE::Camera::OnUpdate()
|
||||||
|
{
|
||||||
|
if(mainCamera == nullptr && baseObject->name != ".EditorCamera")
|
||||||
|
{
|
||||||
|
mainCamera = this;
|
||||||
|
}
|
||||||
|
IRenderer::camerasToRenderWith.push_back(this);
|
||||||
|
}
|
||||||
|
|
||||||
|
void TSE::Camera::Start()
|
||||||
|
{
|
||||||
|
if(mainCamera == nullptr && baseObject->name != ".EditorCamera")
|
||||||
|
{
|
||||||
|
mainCamera = this;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
TSE::Matrix4x4 BuildView_Zplus_RH(const TSE::Matrix4x4& world)
|
||||||
|
{
|
||||||
|
using namespace TSE;
|
||||||
|
// Welt-Position (w=1)
|
||||||
|
Vector3 pos = Vector3(world * Vector4(0,0,0,1));
|
||||||
|
|
||||||
|
// Richtungsachsen in Welt (w=0, KEINE Translation!)
|
||||||
|
Vector3 fwdWS = Vector3(world * Vector4(0,0,1,0)); // +Z vorwärts in Welt
|
||||||
|
Vector3 upWS = Vector3(world * Vector4(0,1,0,0)); // +Y oben in Welt
|
||||||
|
|
||||||
|
// Orthonormale Basis aufbauen (X+ soll "right" sein)
|
||||||
|
Vector3 f = Vector3::Normalize(fwdWS);
|
||||||
|
Vector3 r = Vector3::Normalize(Vector3::Cross(upWS, f)); // right = up × forward => (+1,0,0) im Identity-Fall
|
||||||
|
Vector3 u = Vector3::Cross(f, r); // re-orthonormalisiertes up
|
||||||
|
|
||||||
|
Matrix4x4 view(1.0f); // Identität als Basis
|
||||||
|
|
||||||
|
// Row-major befüllen (Zeilen = r,u,-f), letzte Spalte = -dot(row, pos) bzw. +dot(f,pos)
|
||||||
|
view.m[0][0] = r.x; view.m[0][1] = r.y; view.m[0][2] = r.z; view.m[0][3] = -Vector3::Dot(r, pos);
|
||||||
|
view.m[1][0] = u.x; view.m[1][1] = u.y; view.m[1][2] = u.z; view.m[1][3] = -Vector3::Dot(u, pos);
|
||||||
|
view.m[2][0] = -f.x; view.m[2][1] = -f.y; view.m[2][2] = -f.z; view.m[2][3] = Vector3::Dot(f, pos);
|
||||||
|
view.m[3][0] = 0.0f; view.m[3][1] = 0.0f; view.m[3][2] = 0.0f; view.m[3][3] = 1.0f;
|
||||||
|
|
||||||
|
return view;
|
||||||
|
}
|
||||||
|
|
||||||
|
void TSE::Camera::PreDraw(IShader *shader)
|
||||||
|
{
|
||||||
|
rt->Bind();
|
||||||
|
shader->SetUniform("prMatrix", projectionMatrix);
|
||||||
|
|
||||||
|
auto worlmatrix = baseObject->GetGlobalMatrix();
|
||||||
|
|
||||||
|
viewMatrix = BuildView_Zplus_RH(worlmatrix);
|
||||||
|
|
||||||
|
shader->SetUniform("camMatrix", &viewMatrix);
|
||||||
|
}
|
||||||
|
|
||||||
|
void TSE::Camera::PostDraw()
|
||||||
|
{
|
||||||
|
rt->Unbind();
|
||||||
|
}
|
||||||
|
|
||||||
|
void TSE::Camera::Bind()
|
||||||
|
{
|
||||||
|
rt->Bind();
|
||||||
|
}
|
||||||
|
|
||||||
|
void TSE::Camera::Unbind()
|
||||||
|
{
|
||||||
|
rt->Unbind();
|
||||||
|
}
|
||||||
|
|
||||||
|
void TSE::Camera::UpdateRenderTarget()
|
||||||
|
{
|
||||||
|
rt->Update();
|
||||||
|
}
|
||||||
79
TSE_Core/src/BehaviourScripts/Camera.hpp
Normal file
79
TSE_Core/src/BehaviourScripts/Camera.hpp
Normal file
@@ -0,0 +1,79 @@
|
|||||||
|
#pragma once
|
||||||
|
|
||||||
|
#define CAMERA typeid(Camera).name()
|
||||||
|
|
||||||
|
#include "interfaces/IShader.hpp"
|
||||||
|
#include "Matrix4x4.hpp"
|
||||||
|
#include "Vector2.hpp"
|
||||||
|
#include "Vector3.hpp"
|
||||||
|
#include "interfaces/IRenderTarget.hpp"
|
||||||
|
#include "elements/BehaviourScript.hpp"
|
||||||
|
|
||||||
|
namespace TSE
|
||||||
|
{
|
||||||
|
enum ProjectionType
|
||||||
|
{
|
||||||
|
Orthographic = 1,
|
||||||
|
Perspective = 2,
|
||||||
|
};
|
||||||
|
|
||||||
|
class Camera : public IResizeNotifiable, public BehaviourScript
|
||||||
|
{
|
||||||
|
private:
|
||||||
|
float RenderScale = 32;
|
||||||
|
IRenderTarget* rt = nullptr;
|
||||||
|
ProjectionType projection = ProjectionType::Orthographic;
|
||||||
|
Matrix4x4* projectionMatrix = nullptr;
|
||||||
|
Matrix4x4 viewMatrix;
|
||||||
|
|
||||||
|
float nearClippingPlane = 0;
|
||||||
|
float farClippingPlane = 100;
|
||||||
|
|
||||||
|
//perspective
|
||||||
|
float fov = 60;
|
||||||
|
|
||||||
|
Vector2 lastRtSize = {0, 0};
|
||||||
|
|
||||||
|
public:
|
||||||
|
static Camera* mainCamera;
|
||||||
|
|
||||||
|
// Getter
|
||||||
|
float GetRenderScale() const;
|
||||||
|
ProjectionType GetProjection() const;
|
||||||
|
float GetNearClippingPlane() const;
|
||||||
|
float GetFarClippingPlane() const;
|
||||||
|
float GetFov() const;
|
||||||
|
|
||||||
|
// Setter
|
||||||
|
Vector3 SceenPositionToGamePosition(Vector2 screenPos);
|
||||||
|
void SetRenderScale(float v);
|
||||||
|
void SetProjection(ProjectionType v);
|
||||||
|
void SetNearClippingPlane(float v);
|
||||||
|
void SetFarClippingPlane(float v);
|
||||||
|
void SetFov(float v);
|
||||||
|
|
||||||
|
Camera();
|
||||||
|
~Camera();
|
||||||
|
void OnResize(float width, float height, IResizable* wnd) override;
|
||||||
|
void SetRenderTarget(IRenderTarget* target);
|
||||||
|
IRenderTarget* GetRenderTarget();
|
||||||
|
|
||||||
|
void RecalculateProjMatrix();
|
||||||
|
|
||||||
|
void OnUpdate() override;
|
||||||
|
void Start() override;
|
||||||
|
|
||||||
|
void PreDraw(IShader* shader);
|
||||||
|
|
||||||
|
void PostDraw();
|
||||||
|
|
||||||
|
void Bind();
|
||||||
|
void Unbind();
|
||||||
|
void UpdateRenderTarget();
|
||||||
|
|
||||||
|
inline const char* GetName() override
|
||||||
|
{
|
||||||
|
return "Camera";
|
||||||
|
}
|
||||||
|
};
|
||||||
|
} // namespace TSE
|
||||||
47
TSE_Core/src/BehaviourScripts/Image.cpp
Normal file
47
TSE_Core/src/BehaviourScripts/Image.cpp
Normal file
@@ -0,0 +1,47 @@
|
|||||||
|
#include "Image.hpp"
|
||||||
|
|
||||||
|
#include "Renderable.hpp"
|
||||||
|
#include "MeshContainer.hpp"
|
||||||
|
#include "Debug.hpp"
|
||||||
|
#include "elements/Transformable.hpp"
|
||||||
|
|
||||||
|
TSE::Image::Image()
|
||||||
|
{
|
||||||
|
}
|
||||||
|
|
||||||
|
void TSE::Image::SetSprite(Sprite &s)
|
||||||
|
{
|
||||||
|
if(!baseObject->HasBehaviourScript(RENDERABLE) || !baseObject->HasBehaviourScript(MESH_CONTAINER))
|
||||||
|
{
|
||||||
|
TSE_WARNING("Dependencies not found for Image BehaviourScript.");
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
if(&s == nullptr) return;
|
||||||
|
spr = s;
|
||||||
|
sprPtr = &spr;
|
||||||
|
Renderable* r = (Renderable*)baseObject->GetBehaviourScript(RENDERABLE);
|
||||||
|
r->GetMaterial()->SetValue<ITexture*>("mainTex", s.GetTexture());
|
||||||
|
MeshContainer* mc = (MeshContainer*)baseObject->GetBehaviourScript(MESH_CONTAINER);
|
||||||
|
s.GetUVs(mc->GetMesh()->uvs);
|
||||||
|
lastrect = s.GetUVRect();
|
||||||
|
}
|
||||||
|
|
||||||
|
TSE::Sprite &TSE::Image::GetSprite()
|
||||||
|
{
|
||||||
|
return spr;
|
||||||
|
}
|
||||||
|
|
||||||
|
TSE::Sprite *TSE::Image::GetSpritePtr()
|
||||||
|
{
|
||||||
|
return sprPtr;
|
||||||
|
}
|
||||||
|
|
||||||
|
void TSE::Image::OnUpdate()
|
||||||
|
{
|
||||||
|
if(lastrect.p1 != spr.GetUVRect().p1 || lastrect.p2 != spr.GetUVRect().p2)
|
||||||
|
{
|
||||||
|
lastrect = spr.GetUVRect();
|
||||||
|
MeshContainer* mc = (MeshContainer*)baseObject->GetBehaviourScript(MESH_CONTAINER);
|
||||||
|
spr.GetUVs(mc->GetMesh()->uvs);
|
||||||
|
}
|
||||||
|
}
|
||||||
29
TSE_Core/src/BehaviourScripts/Image.hpp
Normal file
29
TSE_Core/src/BehaviourScripts/Image.hpp
Normal file
@@ -0,0 +1,29 @@
|
|||||||
|
#pragma once
|
||||||
|
|
||||||
|
#define IMAGE typeid(Image).name()
|
||||||
|
|
||||||
|
#include "elements/Texture.hpp"
|
||||||
|
#include "elements/BehaviourScript.hpp"
|
||||||
|
|
||||||
|
namespace TSE
|
||||||
|
{
|
||||||
|
class Image : public BehaviourScript
|
||||||
|
{
|
||||||
|
private:
|
||||||
|
Sprite spr;
|
||||||
|
Sprite* sprPtr = nullptr;
|
||||||
|
Rect lastrect;
|
||||||
|
|
||||||
|
public:
|
||||||
|
Image();
|
||||||
|
void SetSprite(Sprite& s);
|
||||||
|
Sprite& GetSprite();
|
||||||
|
Sprite* GetSpritePtr();
|
||||||
|
void OnUpdate() override;
|
||||||
|
inline const char* GetName() override
|
||||||
|
{
|
||||||
|
return "Image";
|
||||||
|
};
|
||||||
|
};
|
||||||
|
} // namespace TSE
|
||||||
|
|
||||||
88
TSE_Core/src/BehaviourScripts/ImageAnimation.cpp
Normal file
88
TSE_Core/src/BehaviourScripts/ImageAnimation.cpp
Normal file
@@ -0,0 +1,88 @@
|
|||||||
|
#include "ImageAnimation.hpp"
|
||||||
|
#include "Debug.hpp"
|
||||||
|
#include "elements/Transformable.hpp"
|
||||||
|
#include "utils/Time.hpp"
|
||||||
|
|
||||||
|
TSE::ImageAnimation::ImageAnimation()
|
||||||
|
{
|
||||||
|
}
|
||||||
|
|
||||||
|
void TSE::ImageAnimation::SetAnimationSet(ImageAnimationSet *set)
|
||||||
|
{
|
||||||
|
animations[set->Name] = set;
|
||||||
|
}
|
||||||
|
|
||||||
|
void TSE::ImageAnimation::SetAnimationSet(string name, ImageAnimationSet *set)
|
||||||
|
{
|
||||||
|
animations[name] = set;
|
||||||
|
}
|
||||||
|
|
||||||
|
void TSE::ImageAnimation::StartAnimation(const string name)
|
||||||
|
{
|
||||||
|
currentAnimation = name;
|
||||||
|
frame = 0;
|
||||||
|
deltatime = 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
int TSE::ImageAnimation::GetImageAnimationSetCount()
|
||||||
|
{
|
||||||
|
return animations.size();
|
||||||
|
}
|
||||||
|
|
||||||
|
TSE::ImageAnimationSet *TSE::ImageAnimation::GetImageAnimationAt(int &i)
|
||||||
|
{
|
||||||
|
auto it = animations.begin();
|
||||||
|
for (int j = 0; j < i; j++)
|
||||||
|
{
|
||||||
|
it++;
|
||||||
|
}
|
||||||
|
return it->second;
|
||||||
|
}
|
||||||
|
|
||||||
|
TSE::string &TSE::ImageAnimation::GetCurrentAnimation()
|
||||||
|
{
|
||||||
|
return currentAnimation;
|
||||||
|
}
|
||||||
|
|
||||||
|
int &TSE::ImageAnimation::GetCurrentFrame()
|
||||||
|
{
|
||||||
|
return frame;
|
||||||
|
}
|
||||||
|
|
||||||
|
float &TSE::ImageAnimation::GetDeltaTime()
|
||||||
|
{
|
||||||
|
return deltatime;
|
||||||
|
}
|
||||||
|
|
||||||
|
void TSE::ImageAnimation::RemoveAnimationSet(std::string &name)
|
||||||
|
{
|
||||||
|
if(currentAnimation == name)
|
||||||
|
{
|
||||||
|
currentAnimation = "";
|
||||||
|
frame = 0;
|
||||||
|
deltatime = 0;
|
||||||
|
}
|
||||||
|
animations.erase(name);
|
||||||
|
}
|
||||||
|
|
||||||
|
void TSE::ImageAnimation::OnUpdate()
|
||||||
|
{
|
||||||
|
if(currentAnimation == "") return;
|
||||||
|
if(animations.find(currentAnimation) == animations.end())
|
||||||
|
{
|
||||||
|
TSE_ERROR("AnimationSet " + currentAnimation + " not found.");
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
deltatime += Time::deltaTime();
|
||||||
|
if(deltatime >= animations[currentAnimation]->frameTime)
|
||||||
|
{
|
||||||
|
deltatime = 0;
|
||||||
|
frame++;
|
||||||
|
if(frame >= animations[currentAnimation]->Sprites.size())
|
||||||
|
{
|
||||||
|
frame = 0;
|
||||||
|
}
|
||||||
|
Image* img = (Image*)baseObject->GetBehaviourScript(IMAGE);
|
||||||
|
img->SetSprite(*animations[currentAnimation]->Sprites[frame]);
|
||||||
|
}
|
||||||
|
}
|
||||||
38
TSE_Core/src/BehaviourScripts/ImageAnimation.hpp
Normal file
38
TSE_Core/src/BehaviourScripts/ImageAnimation.hpp
Normal file
@@ -0,0 +1,38 @@
|
|||||||
|
#pragma once
|
||||||
|
|
||||||
|
#define IMAGE_ANIMATION typeid(ImageAnimation).name()
|
||||||
|
|
||||||
|
#include "Image.hpp"
|
||||||
|
#include "elements/BehaviourScript.hpp"
|
||||||
|
#include "elements/ImageAnimationSet.hpp"
|
||||||
|
#include <unordered_map>
|
||||||
|
|
||||||
|
|
||||||
|
namespace TSE
|
||||||
|
{
|
||||||
|
class ImageAnimation : public BehaviourScript
|
||||||
|
{
|
||||||
|
private:
|
||||||
|
std::unordered_map<string, ImageAnimationSet*> animations;
|
||||||
|
string currentAnimation = "";
|
||||||
|
int frame = 0;
|
||||||
|
float deltatime = 0;
|
||||||
|
|
||||||
|
public:
|
||||||
|
ImageAnimation();
|
||||||
|
void SetAnimationSet(ImageAnimationSet* set);
|
||||||
|
void SetAnimationSet(string name, ImageAnimationSet* set);
|
||||||
|
void StartAnimation(const string name);
|
||||||
|
int GetImageAnimationSetCount();
|
||||||
|
ImageAnimationSet* GetImageAnimationAt(int& i);
|
||||||
|
string& GetCurrentAnimation();
|
||||||
|
int& GetCurrentFrame();
|
||||||
|
float& GetDeltaTime();
|
||||||
|
void RemoveAnimationSet(std::string& name);
|
||||||
|
void OnUpdate() override;
|
||||||
|
inline const char* GetName() override
|
||||||
|
{
|
||||||
|
return "Image Animation";
|
||||||
|
}
|
||||||
|
};
|
||||||
|
} // namespace TSE
|
||||||
233
TSE_Core/src/BehaviourScripts/ParticleSystem.cpp
Normal file
233
TSE_Core/src/BehaviourScripts/ParticleSystem.cpp
Normal file
@@ -0,0 +1,233 @@
|
|||||||
|
#include "ParticleSystem.hpp"
|
||||||
|
#include <algorithm>
|
||||||
|
#include <cmath>
|
||||||
|
#include <ctime>
|
||||||
|
#include "utils/Time.hpp"
|
||||||
|
#include "elements/Transformable.hpp"
|
||||||
|
|
||||||
|
void TSE::ParticleSystem::OnUpdate()
|
||||||
|
{
|
||||||
|
if(firstFrame)
|
||||||
|
{
|
||||||
|
firstFrame = false;
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
particles.erase(
|
||||||
|
std::remove_if(particles.begin(), particles.end(),
|
||||||
|
[](auto* particle)
|
||||||
|
{
|
||||||
|
particle->lifetime -= Time::deltaTime();
|
||||||
|
if (particle->lifetime <= 0.0f) {
|
||||||
|
delete particle;
|
||||||
|
return true; // aus vector löschen
|
||||||
|
}
|
||||||
|
return false; // behalten
|
||||||
|
}),
|
||||||
|
particles.end()
|
||||||
|
);
|
||||||
|
for(auto particle : particles)
|
||||||
|
{
|
||||||
|
MoveParticle(particle);
|
||||||
|
RotateParticle(particle);
|
||||||
|
ColorParticle(particle);
|
||||||
|
}
|
||||||
|
time += Time::deltaTime();
|
||||||
|
if(particles.size() < particleCount)
|
||||||
|
{
|
||||||
|
const float spawnInterwal = maxLifetime / particleCount;
|
||||||
|
if(spawnInterwal < Time::deltaTime())
|
||||||
|
{
|
||||||
|
time = 0;
|
||||||
|
int count = Time::deltaTime() / spawnInterwal;
|
||||||
|
for (size_t i = 0; i < count; i++)
|
||||||
|
{
|
||||||
|
CreateParticle();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
if(time >= spawnInterwal)
|
||||||
|
{
|
||||||
|
time = 0;
|
||||||
|
CreateParticle();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
void TSE::ParticleSystem::Start()
|
||||||
|
{
|
||||||
|
rng = std::mt19937(std::time(nullptr));
|
||||||
|
}
|
||||||
|
|
||||||
|
const std::vector<TSE::Particle *> &TSE::ParticleSystem::GetParticles()
|
||||||
|
{
|
||||||
|
return particles;
|
||||||
|
}
|
||||||
|
|
||||||
|
float naive_lerp(float a, float b, float t)
|
||||||
|
{
|
||||||
|
return a + t * (b - a);
|
||||||
|
}
|
||||||
|
|
||||||
|
void TSE::ParticleSystem::MoveParticle(Particle *&particle)
|
||||||
|
{
|
||||||
|
float age = particle->lifetime / maxLifetime;
|
||||||
|
float speed = startSpeed;
|
||||||
|
if(changeSpeedOverLifetime)
|
||||||
|
{
|
||||||
|
speed = naive_lerp(startSpeed, endSpeed, age);
|
||||||
|
}
|
||||||
|
if(speed == 0) return;
|
||||||
|
particle->position = Vector3::Lerp(particle->position, particle->position + particle->direction, speed * Time::deltaTime());
|
||||||
|
}
|
||||||
|
|
||||||
|
void TSE::ParticleSystem::RotateParticle(Particle *&particle)
|
||||||
|
{
|
||||||
|
float age = particle->lifetime / maxLifetime;
|
||||||
|
float speed = startRotationSpeed;
|
||||||
|
if(changeRotationspeedOverLifetime)
|
||||||
|
{
|
||||||
|
speed = naive_lerp(startRotationSpeed, endRotationSpeed, age);
|
||||||
|
}
|
||||||
|
if(speed == 0) return;
|
||||||
|
particle->rotationRad = naive_lerp(particle->rotationRad, particle->rotationRad - particle->rotDirection, speed * Time::deltaTime());
|
||||||
|
}
|
||||||
|
|
||||||
|
void TSE::ParticleSystem::ColorParticle(Particle *&particle)
|
||||||
|
{
|
||||||
|
float age = particle->lifetime / maxLifetime;
|
||||||
|
Color c = startColor;
|
||||||
|
if(changeColorOverLifetime)
|
||||||
|
{
|
||||||
|
c = Color::Lerp(endColor, startColor, age);
|
||||||
|
}
|
||||||
|
particle->color = c;
|
||||||
|
}
|
||||||
|
|
||||||
|
void TSE::ParticleSystem::CreateParticle()
|
||||||
|
{
|
||||||
|
std::uniform_real_distribution<float> dist(0.0f, 1.0f);
|
||||||
|
std::uniform_int_distribution<int> distI(0,1);
|
||||||
|
|
||||||
|
Particle* part = new Particle();
|
||||||
|
part->color = startColor;
|
||||||
|
part->lifetime = maxLifetime;
|
||||||
|
if(startWithRandomLifetime)
|
||||||
|
{
|
||||||
|
part->lifetime = naive_lerp(minLifetime, maxLifetime, dist(rng));
|
||||||
|
}
|
||||||
|
part->size = maxSize;
|
||||||
|
if(startWithRandomSize)
|
||||||
|
{
|
||||||
|
part->size = naive_lerp(minSize, maxSize, dist(rng));
|
||||||
|
}
|
||||||
|
part->rotationRad = maxrotationRad;
|
||||||
|
if(startWithRandomRotation)
|
||||||
|
{
|
||||||
|
part->rotationRad = naive_lerp(minRotationRad, maxrotationRad, dist(rng));
|
||||||
|
}
|
||||||
|
part->rotDirection = rotationDirection;
|
||||||
|
if(startWithRandomRotationDirection)
|
||||||
|
{
|
||||||
|
int rnd = distI(rng);
|
||||||
|
if(rnd == 0) rnd--;
|
||||||
|
part->rotDirection = rnd;
|
||||||
|
}
|
||||||
|
Vector3 localPos = SamplePointInVolume(rng);
|
||||||
|
part->position = baseObject->LocalToGlobalPosition(localPos);
|
||||||
|
Vector3 direction = localPos - offset;
|
||||||
|
direction.Normalize();
|
||||||
|
Vector3 globalOBJPos = baseObject->GetGlobalPosition();
|
||||||
|
Vector3 globalOffsetPos = baseObject->LocalToGlobalPosition(direction);
|
||||||
|
|
||||||
|
Vector3 globalDirection = globalOffsetPos - globalOBJPos;
|
||||||
|
globalDirection.Normalize();
|
||||||
|
part->direction = globalDirection;
|
||||||
|
|
||||||
|
particles.push_back(part);
|
||||||
|
}
|
||||||
|
|
||||||
|
float TSE::ParticleSystem::PlaneAsCosAlpha()
|
||||||
|
{
|
||||||
|
return std::clamp(conePlane * 2.0f - 1.0f, -1.0f, 1.0f);
|
||||||
|
}
|
||||||
|
|
||||||
|
bool TSE::ParticleSystem::InVolume(const Vector3 &x)
|
||||||
|
{
|
||||||
|
// no cone set
|
||||||
|
if(conePlane == 0) return false;
|
||||||
|
|
||||||
|
// out of radius
|
||||||
|
const Vector3 v = x - offset;
|
||||||
|
const float r2 = v.LengthSqr();
|
||||||
|
if(r2 > radius * radius ) return false;
|
||||||
|
|
||||||
|
//full circle
|
||||||
|
if(conePlane == 1 || r2 <= TSE_EPSILON) return true;
|
||||||
|
|
||||||
|
const float invr = 1.0f / std::sqrt(r2);
|
||||||
|
const float cosTheta = Vector3::Dot(Vector3(v.x * invr, v.y * invr, v.z * invr), forward);
|
||||||
|
const float cosA = PlaneAsCosAlpha();
|
||||||
|
|
||||||
|
if (conePlane <= 0.5f) return cosTheta >= cosA;
|
||||||
|
else return cosTheta <= cosA; // Inverse
|
||||||
|
}
|
||||||
|
|
||||||
|
void TSE::ParticleSystem::BuildTangent(Vector3 &t, Vector3 &b)
|
||||||
|
{
|
||||||
|
if (std::abs(forward.z) < 0.999f)
|
||||||
|
{
|
||||||
|
t = Vector3::Cross(forward, Vector3::forward);
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
t = Vector3::Cross(forward, Vector3::up);
|
||||||
|
}
|
||||||
|
t.NormalizeSafe(Vector3::right);
|
||||||
|
|
||||||
|
b = Vector3::Cross(forward, t);
|
||||||
|
}
|
||||||
|
|
||||||
|
TSE::Vector3 TSE::ParticleSystem::SampleDirection(float u1, float u2)
|
||||||
|
{
|
||||||
|
const float cosA = PlaneAsCosAlpha();
|
||||||
|
|
||||||
|
float z;
|
||||||
|
if(conePlane == 1)
|
||||||
|
{
|
||||||
|
z = -1.0f + 2.0f * u1;
|
||||||
|
}
|
||||||
|
// else if(conePlane <= 0.5f)
|
||||||
|
// {
|
||||||
|
// z = 1.0f - u1 * (1.0f - cosA);
|
||||||
|
// }
|
||||||
|
else
|
||||||
|
{
|
||||||
|
z = -1.0f + u1 * (1.0f + cosA);
|
||||||
|
}
|
||||||
|
|
||||||
|
const float phi = 2.0f * TSE_PI * u2;
|
||||||
|
const float s = std::sqrt(((0.0f) > (1.0f - z * z)) ? (0.0f) : (1.0f - z * z));
|
||||||
|
|
||||||
|
Vector3 t, b;
|
||||||
|
BuildTangent(t,b);
|
||||||
|
return Vector3(t.x * (s * std::cos(phi)) + b.x * (s * std::sin(phi)) + forward.x * z,
|
||||||
|
t.y * (s * std::cos(phi)) + b.y * (s * std::sin(phi)) + forward.y * z,
|
||||||
|
t.z * (s * std::cos(phi)) + b.z * (s * std::sin(phi)) + forward.z * z);
|
||||||
|
}
|
||||||
|
|
||||||
|
TSE::Vector3 TSE::ParticleSystem::samplePointInVolume(float u1, float u2, float u3)
|
||||||
|
{
|
||||||
|
const Vector3 dir = SampleDirection(u1,u2);
|
||||||
|
const float r = radius * std::cbrt(u3);
|
||||||
|
return offset + dir * r;
|
||||||
|
}
|
||||||
|
|
||||||
|
TSE::Vector3 TSE::ParticleSystem::SamplePointInVolume(std::mt19937 &rng)
|
||||||
|
{
|
||||||
|
if(conePlane == 0) return Vector3::zero;
|
||||||
|
std::uniform_real_distribution<float> U(0.0f, 1.0f);
|
||||||
|
return samplePointInVolume(U(rng), U(rng), U(rng));
|
||||||
|
}
|
||||||
95
TSE_Core/src/BehaviourScripts/ParticleSystem.hpp
Normal file
95
TSE_Core/src/BehaviourScripts/ParticleSystem.hpp
Normal file
@@ -0,0 +1,95 @@
|
|||||||
|
#pragma once
|
||||||
|
|
||||||
|
#define PARTICLESYSTEM typeid(ParticleSystem).name()
|
||||||
|
|
||||||
|
#include <random>
|
||||||
|
#include <vector>
|
||||||
|
#include "Vector3.hpp"
|
||||||
|
#include "Color.hpp"
|
||||||
|
#include "MathF.hpp"
|
||||||
|
#include "elements/BehaviourScript.hpp"
|
||||||
|
|
||||||
|
namespace TSE
|
||||||
|
{
|
||||||
|
struct Particle
|
||||||
|
{
|
||||||
|
public:
|
||||||
|
Vector3 position;
|
||||||
|
float size;
|
||||||
|
float rotationRad;
|
||||||
|
Color color;
|
||||||
|
|
||||||
|
float lifetime;
|
||||||
|
Vector3 direction;
|
||||||
|
float rotDirection;
|
||||||
|
};
|
||||||
|
|
||||||
|
class ParticleSystem : public BehaviourScript
|
||||||
|
{
|
||||||
|
public:
|
||||||
|
//Random Rotation
|
||||||
|
bool startWithRandomRotationDirection = false;
|
||||||
|
float rotationDirection = 1; //1 or -1 //-> used if not random
|
||||||
|
bool startWithRandomRotation = false;
|
||||||
|
float minRotationRad = 0;
|
||||||
|
float maxrotationRad = 2 * TSE_PI; //-> used if not random
|
||||||
|
//Random Size
|
||||||
|
bool startWithRandomSize = false;
|
||||||
|
float minSize = 1;
|
||||||
|
float maxSize = 2; //-> used if not random
|
||||||
|
//Random Lifetime
|
||||||
|
bool startWithRandomLifetime = false;
|
||||||
|
float minLifetime = 1; // -> smallest possible lifetime
|
||||||
|
float maxLifetime = 2; // -> biggest possible lifetime -> also the lifetime if not random
|
||||||
|
//Color over Lifetime
|
||||||
|
bool changeColorOverLifetime = false;
|
||||||
|
Color startColor = Color::white;
|
||||||
|
Color endColor = Color::white;
|
||||||
|
//Speed over Lifetime
|
||||||
|
bool changeSpeedOverLifetime = false;
|
||||||
|
float startSpeed = 1;
|
||||||
|
float endSpeed = 0.5f;
|
||||||
|
//Ratationspeed over Lifetime
|
||||||
|
bool changeRotationspeedOverLifetime = false;
|
||||||
|
float startRotationSpeed = 1;
|
||||||
|
float endRotationSpeed = 0.5f;
|
||||||
|
//Rest
|
||||||
|
uint particleCount = 10;
|
||||||
|
bool startWithSimulatedParicles = false;
|
||||||
|
|
||||||
|
//Spawn Area
|
||||||
|
Vector3 offset;
|
||||||
|
float conePlane = 1;
|
||||||
|
float radius = 1;
|
||||||
|
Vector3 forward = Vector3::forward;
|
||||||
|
|
||||||
|
private:
|
||||||
|
std::vector<Particle*> particles;
|
||||||
|
float time;
|
||||||
|
std::mt19937 rng;
|
||||||
|
bool firstFrame = true;
|
||||||
|
|
||||||
|
public:
|
||||||
|
void OnUpdate() override;
|
||||||
|
void Start() override;
|
||||||
|
inline const char* GetName() override
|
||||||
|
{
|
||||||
|
return "Particle System";
|
||||||
|
}
|
||||||
|
const std::vector<Particle*>& GetParticles();
|
||||||
|
|
||||||
|
private:
|
||||||
|
void MoveParticle(Particle*& particle);
|
||||||
|
void RotateParticle(Particle*& particle);
|
||||||
|
void ColorParticle(Particle*& particle);
|
||||||
|
void CreateParticle();
|
||||||
|
float PlaneAsCosAlpha();
|
||||||
|
bool InVolume(const Vector3& x);
|
||||||
|
void BuildTangent(Vector3& t, Vector3& b);
|
||||||
|
Vector3 SampleDirection(float u1, float u2);
|
||||||
|
Vector3 samplePointInVolume(float u1, float u2, float u3);
|
||||||
|
|
||||||
|
Vector3 SamplePointInVolume(std::mt19937& rng);
|
||||||
|
};
|
||||||
|
|
||||||
|
} // namespace TSE
|
||||||
112
TSE_Core/src/elements/ErrorTextureData.hpp
Normal file
112
TSE_Core/src/elements/ErrorTextureData.hpp
Normal file
@@ -0,0 +1,112 @@
|
|||||||
|
#pragma once
|
||||||
|
|
||||||
|
constexpr int errorTexWidth = 20;
|
||||||
|
|
||||||
|
constexpr int errorTexHeight = 20;
|
||||||
|
|
||||||
|
constexpr int errorTexBpp = 32;
|
||||||
|
|
||||||
|
constexpr int errorTexChannels = 4;
|
||||||
|
|
||||||
|
const unsigned char errorTextureData[errorTexWidth * errorTexHeight * errorTexChannels] = {
|
||||||
|
255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255,
|
||||||
|
255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255,
|
||||||
|
255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255,
|
||||||
|
255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255,
|
||||||
|
255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255,
|
||||||
|
255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255,
|
||||||
|
255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255,
|
||||||
|
255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255,
|
||||||
|
255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255,
|
||||||
|
255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255,
|
||||||
|
255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255,
|
||||||
|
255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 0, 0, 255, 255,
|
||||||
|
0, 0, 255, 255, 0, 0, 255, 255, 0, 0, 255, 255, 0, 0, 255, 255,
|
||||||
|
0, 0, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255,
|
||||||
|
255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255,
|
||||||
|
255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255,
|
||||||
|
255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 0, 0, 255, 255,
|
||||||
|
0, 0, 255, 255, 0, 0, 255, 255, 0, 0, 255, 255, 0, 0, 255, 255,
|
||||||
|
0, 0, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255,
|
||||||
|
255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255,
|
||||||
|
255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255,
|
||||||
|
255, 255, 255, 255, 0, 0, 255, 255, 0, 0, 255, 255, 255, 255, 255, 255,
|
||||||
|
255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255,
|
||||||
|
255, 255, 255, 255, 0, 0, 255, 255, 0, 0, 255, 255, 255, 255, 255, 255,
|
||||||
|
255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255,
|
||||||
|
255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255,
|
||||||
|
255, 255, 255, 255, 0, 0, 255, 255, 0, 0, 255, 255, 255, 255, 255, 255,
|
||||||
|
255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255,
|
||||||
|
255, 255, 255, 255, 0, 0, 255, 255, 0, 0, 255, 255, 255, 255, 255, 255,
|
||||||
|
255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255,
|
||||||
|
255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255,
|
||||||
|
255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255,
|
||||||
|
255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255,
|
||||||
|
255, 255, 255, 255, 0, 0, 255, 255, 0, 0, 255, 255, 255, 255, 255, 255,
|
||||||
|
255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255,
|
||||||
|
255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255,
|
||||||
|
255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255,
|
||||||
|
255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255,
|
||||||
|
255, 255, 255, 255, 0, 0, 255, 255, 0, 0, 255, 255, 255, 255, 255, 255,
|
||||||
|
255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255,
|
||||||
|
255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255,
|
||||||
|
255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255,
|
||||||
|
255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 0, 0, 255, 255,
|
||||||
|
0, 0, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255,
|
||||||
|
255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255,
|
||||||
|
255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255,
|
||||||
|
255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255,
|
||||||
|
255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 0, 0, 255, 255,
|
||||||
|
0, 0, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255,
|
||||||
|
255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255,
|
||||||
|
255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255,
|
||||||
|
255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255,
|
||||||
|
255, 255, 255, 255, 0, 0, 255, 255, 0, 0, 255, 255, 255, 255, 255, 255,
|
||||||
|
255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255,
|
||||||
|
255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255,
|
||||||
|
255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255,
|
||||||
|
255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255,
|
||||||
|
255, 255, 255, 255, 0, 0, 255, 255, 0, 0, 255, 255, 255, 255, 255, 255,
|
||||||
|
255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255,
|
||||||
|
255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255,
|
||||||
|
255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255,
|
||||||
|
255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255,
|
||||||
|
255, 255, 255, 255, 0, 0, 255, 255, 0, 0, 255, 255, 255, 255, 255, 255,
|
||||||
|
255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255,
|
||||||
|
255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255,
|
||||||
|
255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255,
|
||||||
|
255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255,
|
||||||
|
255, 255, 255, 255, 0, 0, 255, 255, 0, 0, 255, 255, 255, 255, 255, 255,
|
||||||
|
255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255,
|
||||||
|
255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255,
|
||||||
|
255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255,
|
||||||
|
255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255,
|
||||||
|
255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255,
|
||||||
|
255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255,
|
||||||
|
255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255,
|
||||||
|
255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255,
|
||||||
|
255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255,
|
||||||
|
255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255,
|
||||||
|
255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255,
|
||||||
|
255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255,
|
||||||
|
255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255,
|
||||||
|
255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255,
|
||||||
|
255, 255, 255, 255, 0, 0, 255, 255, 0, 0, 255, 255, 255, 255, 255, 255,
|
||||||
|
255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255,
|
||||||
|
255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255,
|
||||||
|
255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255,
|
||||||
|
255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255,
|
||||||
|
255, 255, 255, 255, 0, 0, 255, 255, 0, 0, 255, 255, 255, 255, 255, 255,
|
||||||
|
255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255,
|
||||||
|
255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255,
|
||||||
|
255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255,
|
||||||
|
255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255,
|
||||||
|
255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255,
|
||||||
|
255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255,
|
||||||
|
255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255,
|
||||||
|
255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255,
|
||||||
|
255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255,
|
||||||
|
255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255,
|
||||||
|
255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255,
|
||||||
|
255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255
|
||||||
|
};
|
||||||
7
TSE_Core/src/elements/ImageAnimationSet.cpp
Normal file
7
TSE_Core/src/elements/ImageAnimationSet.cpp
Normal file
@@ -0,0 +1,7 @@
|
|||||||
|
#include "ImageAnimationSet.hpp"
|
||||||
|
|
||||||
|
TSE::ImageAnimationSet::ImageAnimationSet(std::vector<Sprite *> *s, std::string &name)
|
||||||
|
{
|
||||||
|
Sprites = *s;
|
||||||
|
Name = std::string(name);
|
||||||
|
}
|
||||||
18
TSE_Core/src/elements/ImageAnimationSet.hpp
Normal file
18
TSE_Core/src/elements/ImageAnimationSet.hpp
Normal file
@@ -0,0 +1,18 @@
|
|||||||
|
#pragma once
|
||||||
|
|
||||||
|
#include <vector>
|
||||||
|
#include "Sprite.hpp"
|
||||||
|
#include "Types.hpp"
|
||||||
|
|
||||||
|
namespace TSE
|
||||||
|
{
|
||||||
|
struct ImageAnimationSet
|
||||||
|
{
|
||||||
|
public:
|
||||||
|
std::string Name = "";
|
||||||
|
std::vector<Sprite*> Sprites;
|
||||||
|
float frameTime = 0;
|
||||||
|
ImageAnimationSet() = default;
|
||||||
|
ImageAnimationSet(std::vector<Sprite*>* s, std::string& name);
|
||||||
|
};
|
||||||
|
} // namespace TSE
|
||||||
124
TSE_Core/src/elements/Scene.cpp
Normal file
124
TSE_Core/src/elements/Scene.cpp
Normal file
@@ -0,0 +1,124 @@
|
|||||||
|
#include "Scene.hpp"
|
||||||
|
|
||||||
|
void TSE::Scene::Render(IRenderer &rnd, const IWindow &wnd)
|
||||||
|
{
|
||||||
|
int counter = 1;
|
||||||
|
for(auto l : layers)
|
||||||
|
{
|
||||||
|
l.second->Render(rnd);
|
||||||
|
if(counter++ != layers.size())
|
||||||
|
{
|
||||||
|
rnd.End(); //OPTIMIZE:
|
||||||
|
//takes up 13,97% of function, but only needed, if there is more then one layer
|
||||||
|
//possible optimizations:
|
||||||
|
// -remove layers
|
||||||
|
// -make layer calculations, in shader
|
||||||
|
// -make an offset, that is calculated on cpu, and then commit everything at once
|
||||||
|
|
||||||
|
// now it is better because it is only done once per frame if only one shader is used, or textures are full, or more then one layers are used
|
||||||
|
rnd.Flush();
|
||||||
|
rnd.Begin();
|
||||||
|
wnd.ClearDepthBuffer();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
void TSE::Scene::DoneRender()
|
||||||
|
{
|
||||||
|
IRenderer::camerasToRenderWith.clear();
|
||||||
|
}
|
||||||
|
|
||||||
|
void TSE::Scene::AddLayer(Layer *l)
|
||||||
|
{
|
||||||
|
layers.push_back(std::pair(l->GetName(), l));
|
||||||
|
}
|
||||||
|
|
||||||
|
void TSE::Scene::RemoveLayer(const string &name)
|
||||||
|
{
|
||||||
|
auto it = layers.begin();
|
||||||
|
for (int j = 0; j < layers.size(); j++)
|
||||||
|
{
|
||||||
|
if(it->first == name)
|
||||||
|
{
|
||||||
|
layers.erase(it);
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
it++;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
int TSE::Scene::GetLayerCount() const
|
||||||
|
{
|
||||||
|
return layers.size();
|
||||||
|
}
|
||||||
|
|
||||||
|
TSE::Layer *TSE::Scene::GetLayerAt(const int &i) const
|
||||||
|
{
|
||||||
|
auto it = layers.begin();
|
||||||
|
for (int j = 0; j < i; j++)
|
||||||
|
{
|
||||||
|
it++;
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
return (*it).second;
|
||||||
|
}
|
||||||
|
|
||||||
|
void TSE::Scene::SetName(const string &nname)
|
||||||
|
{
|
||||||
|
name = nname;
|
||||||
|
}
|
||||||
|
|
||||||
|
TSE::string TSE::Scene::GetName()
|
||||||
|
{
|
||||||
|
return name;
|
||||||
|
}
|
||||||
|
|
||||||
|
void TSE::Scene::Update()
|
||||||
|
{
|
||||||
|
for(auto l : layers)
|
||||||
|
{
|
||||||
|
l.second->Update();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
void TSE::Scene::RenameLayer(const string &oldName, const string &newName)
|
||||||
|
{
|
||||||
|
for (int j = 0; j < layers.size(); j++)
|
||||||
|
{
|
||||||
|
if(layers[j].first == oldName)
|
||||||
|
{
|
||||||
|
layers[j].first = newName;
|
||||||
|
layers[j].second->SetName(newName);
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
void TSE::Scene::MoveLayerUp(Layer *l)
|
||||||
|
{
|
||||||
|
auto it = layers.begin();
|
||||||
|
for (int j = 0; j < layers.size(); j++)
|
||||||
|
{
|
||||||
|
if(it->first == l->GetName())
|
||||||
|
{
|
||||||
|
std::swap(layers[j-1], layers[j]);
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
it++;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
void TSE::Scene::MoveLayerDown(Layer *l)
|
||||||
|
{
|
||||||
|
auto it = layers.begin();
|
||||||
|
for (int j = 0; j < layers.size(); j++)
|
||||||
|
{
|
||||||
|
if(it->first == l->GetName())
|
||||||
|
{
|
||||||
|
std::swap(layers[j+1], layers[j]);
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
it++;
|
||||||
|
}
|
||||||
|
}
|
||||||
30
TSE_Core/src/elements/Scene.hpp
Normal file
30
TSE_Core/src/elements/Scene.hpp
Normal file
@@ -0,0 +1,30 @@
|
|||||||
|
#pragma once
|
||||||
|
|
||||||
|
#include <vector>
|
||||||
|
#include "Layer.hpp"
|
||||||
|
#include "interfaces/IWindow.hpp"
|
||||||
|
#include "Types.hpp"
|
||||||
|
|
||||||
|
namespace TSE
|
||||||
|
{
|
||||||
|
class Scene
|
||||||
|
{
|
||||||
|
private:
|
||||||
|
string name = "Unnamed";
|
||||||
|
std::vector<std::pair<string, Layer*>> layers;
|
||||||
|
|
||||||
|
public:
|
||||||
|
void Render(IRenderer& rnd, const IWindow& wnd);
|
||||||
|
void DoneRender();
|
||||||
|
void AddLayer(Layer* l);
|
||||||
|
void RemoveLayer(const string& name);
|
||||||
|
int GetLayerCount() const;
|
||||||
|
Layer* GetLayerAt(const int& i) const;
|
||||||
|
void SetName(const string& name);
|
||||||
|
string GetName();
|
||||||
|
void Update();
|
||||||
|
void RenameLayer(const string& oldName, const string& newName);
|
||||||
|
void MoveLayerUp(Layer* l);
|
||||||
|
void MoveLayerDown(Layer* l);
|
||||||
|
};
|
||||||
|
} // namespace TSE
|
||||||
26
TSE_Core/src/elements/Sprite.cpp
Normal file
26
TSE_Core/src/elements/Sprite.cpp
Normal file
@@ -0,0 +1,26 @@
|
|||||||
|
#include "Sprite.hpp"
|
||||||
|
|
||||||
|
TSE::Sprite::Sprite(Texture *tex, Rect bounds)
|
||||||
|
{
|
||||||
|
this->tex = tex;
|
||||||
|
uvBounds = bounds;
|
||||||
|
}
|
||||||
|
|
||||||
|
TSE::Texture *TSE::Sprite::GetTexture()
|
||||||
|
{
|
||||||
|
return tex;
|
||||||
|
}
|
||||||
|
|
||||||
|
TSE::Rect &TSE::Sprite::GetUVRect()
|
||||||
|
{
|
||||||
|
return uvBounds;
|
||||||
|
}
|
||||||
|
|
||||||
|
void TSE::Sprite::GetUVs(std::vector<Vector2> &uvs)
|
||||||
|
{
|
||||||
|
uvs.clear();
|
||||||
|
uvs.push_back(Vector2(uvBounds.p1));
|
||||||
|
uvs.push_back(Vector2(uvBounds.p2.x, uvBounds.p1.y));
|
||||||
|
uvs.push_back(Vector2(uvBounds.p2));
|
||||||
|
uvs.push_back(Vector2(uvBounds.p1.x, uvBounds.p2.y));
|
||||||
|
}
|
||||||
23
TSE_Core/src/elements/Sprite.hpp
Normal file
23
TSE_Core/src/elements/Sprite.hpp
Normal file
@@ -0,0 +1,23 @@
|
|||||||
|
#pragma once
|
||||||
|
|
||||||
|
#include "Rect.hpp"
|
||||||
|
|
||||||
|
namespace TSE
|
||||||
|
{
|
||||||
|
class Texture;
|
||||||
|
|
||||||
|
struct Sprite
|
||||||
|
{
|
||||||
|
private:
|
||||||
|
Texture* tex = nullptr;
|
||||||
|
Rect uvBounds = Rect(0,0,0,0);
|
||||||
|
|
||||||
|
public:
|
||||||
|
inline Sprite() {};
|
||||||
|
Sprite(Texture* tex, Rect bounds);
|
||||||
|
~Sprite() = default;
|
||||||
|
Texture* GetTexture();
|
||||||
|
Rect& GetUVRect();
|
||||||
|
void GetUVs(std::vector<Vector2>& uvs);
|
||||||
|
};
|
||||||
|
} // namespace TSE
|
||||||
359
TSE_Core/src/elements/Texture.cpp
Normal file
359
TSE_Core/src/elements/Texture.cpp
Normal file
@@ -0,0 +1,359 @@
|
|||||||
|
#include "Texture.hpp"
|
||||||
|
#include "Debug.hpp"
|
||||||
|
#include "Color.hpp"
|
||||||
|
#include "ErrorTextureData.hpp"
|
||||||
|
|
||||||
|
TSE::Texture::Texture(const string &path)
|
||||||
|
{
|
||||||
|
FREE_IMAGE_FORMAT fif = FREE_IMAGE_FORMAT::FIF_UNKNOWN;
|
||||||
|
bmp = nullptr;
|
||||||
|
imagePtr = nullptr;
|
||||||
|
Size = Vector2(0,0);
|
||||||
|
|
||||||
|
fif = FreeImage_GetFileType(path.c_str(), 0);
|
||||||
|
if(fif == FREE_IMAGE_FORMAT::FIF_UNKNOWN)
|
||||||
|
fif = FreeImage_GetFIFFromFilename(path.c_str());
|
||||||
|
if(fif == FREE_IMAGE_FORMAT::FIF_UNKNOWN)
|
||||||
|
{
|
||||||
|
TSE_ERROR("Failed to load image. Unsupported Format.");
|
||||||
|
Bpp = 24;
|
||||||
|
makeError(*this);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
if(FreeImage_FIFSupportsReading(fif))
|
||||||
|
{
|
||||||
|
bmp = FreeImage_Load(fif, path.c_str());
|
||||||
|
if(FreeImage_GetBPP(bmp) != 32)
|
||||||
|
{
|
||||||
|
auto tmpBmp = FreeImage_ConvertTo32Bits(bmp);
|
||||||
|
FreeImage_Unload(bmp);
|
||||||
|
bmp = tmpBmp;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
if(bmp == nullptr)
|
||||||
|
{
|
||||||
|
TSE_ERROR("Failed to load image. Bitmap was nullptr.");
|
||||||
|
Bpp = 24;
|
||||||
|
makeError(*this);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
Bpp = FreeImage_GetBPP(bmp);
|
||||||
|
imagePtr = FreeImage_GetBits(bmp);
|
||||||
|
|
||||||
|
switch (Bpp)
|
||||||
|
{
|
||||||
|
case 32:
|
||||||
|
chanels = 4;
|
||||||
|
break;
|
||||||
|
case 24:
|
||||||
|
chanels = 3;
|
||||||
|
case 8:
|
||||||
|
chanels = 4;
|
||||||
|
}
|
||||||
|
|
||||||
|
Size = Vector2(FreeImage_GetWidth(bmp), FreeImage_GetHeight(bmp));
|
||||||
|
regist();
|
||||||
|
}
|
||||||
|
|
||||||
|
TSE::Texture::Texture(const int &width, const int &height, int bpp)
|
||||||
|
{
|
||||||
|
switch (bpp)
|
||||||
|
{
|
||||||
|
case 32:
|
||||||
|
chanels = 4;
|
||||||
|
break;
|
||||||
|
case 24:
|
||||||
|
chanels = 3;
|
||||||
|
case 8:
|
||||||
|
chanels = 4;
|
||||||
|
}
|
||||||
|
Bpp = bpp;
|
||||||
|
Size = Vector2(width, height);
|
||||||
|
bmp = FreeImage_Allocate(width, height, bpp);
|
||||||
|
imagePtr = FreeImage_GetBits(bmp);
|
||||||
|
regist();
|
||||||
|
}
|
||||||
|
|
||||||
|
TSE::Texture::Texture(const Vector2 &size, int bpp)
|
||||||
|
{
|
||||||
|
switch (bpp)
|
||||||
|
{
|
||||||
|
case 32:
|
||||||
|
chanels = 4;
|
||||||
|
break;
|
||||||
|
case 24:
|
||||||
|
chanels = 3;
|
||||||
|
case 8:
|
||||||
|
chanels = 4;
|
||||||
|
}
|
||||||
|
Bpp = bpp;
|
||||||
|
Size = size;
|
||||||
|
bmp = FreeImage_Allocate(size.x, size.y, bpp);
|
||||||
|
imagePtr = FreeImage_GetBits(bmp);
|
||||||
|
regist();
|
||||||
|
}
|
||||||
|
|
||||||
|
TSE::Texture::~Texture()
|
||||||
|
{
|
||||||
|
if(bmp != nullptr)
|
||||||
|
{
|
||||||
|
FreeImage_Unload(bmp);
|
||||||
|
bmp = nullptr;
|
||||||
|
}
|
||||||
|
if(TextureID != 0)
|
||||||
|
{
|
||||||
|
//glDeleteTextures(1, &TextureID); --> need to do in platform openGL
|
||||||
|
PlatformDestroy();
|
||||||
|
TextureID = 0;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
TSE::uint TSE::Texture::bpp() const
|
||||||
|
{
|
||||||
|
return Bpp;
|
||||||
|
}
|
||||||
|
|
||||||
|
TSE::Vector2 TSE::Texture::size() const
|
||||||
|
{
|
||||||
|
return Size;
|
||||||
|
}
|
||||||
|
|
||||||
|
float TSE::Texture::width() const
|
||||||
|
{
|
||||||
|
return Size.x;
|
||||||
|
}
|
||||||
|
|
||||||
|
float TSE::Texture::height() const
|
||||||
|
{
|
||||||
|
return Size.y;
|
||||||
|
}
|
||||||
|
|
||||||
|
TSE::byte TSE::Texture::Chanels() const
|
||||||
|
{
|
||||||
|
return chanels;
|
||||||
|
}
|
||||||
|
|
||||||
|
TSE::byte *TSE::Texture::GetImagePtr() const
|
||||||
|
{
|
||||||
|
return imagePtr;
|
||||||
|
}
|
||||||
|
|
||||||
|
void TSE::Texture::SetPixel(const Vector2 &pos, const Color &c)
|
||||||
|
{
|
||||||
|
SetPixel(pos.x, pos.y, c);
|
||||||
|
}
|
||||||
|
|
||||||
|
void TSE::Texture::GetPixel(const Vector2 &pos, Color &c) const
|
||||||
|
{
|
||||||
|
GetPixel(pos.x, pos.y, c);
|
||||||
|
}
|
||||||
|
|
||||||
|
void TSE::Texture::SetPixelNoApply(const Vector2 &pos, const Color &c)
|
||||||
|
{
|
||||||
|
SetPixelNoApply(pos.x, pos.y, c);
|
||||||
|
}
|
||||||
|
|
||||||
|
void TSE::Texture::ToSprite(Sprite &s)
|
||||||
|
{
|
||||||
|
s = Sprite(this, Rect(0,0,1,1));
|
||||||
|
}
|
||||||
|
|
||||||
|
void TSE::Texture::SetChanels(const byte &ch)
|
||||||
|
{
|
||||||
|
chanels = ch;
|
||||||
|
}
|
||||||
|
|
||||||
|
uint TSE::Texture::GetTextureId() const
|
||||||
|
{
|
||||||
|
return TextureID;
|
||||||
|
}
|
||||||
|
|
||||||
|
void TSE::Texture::SetTextureId(uint id)
|
||||||
|
{
|
||||||
|
TextureID = id;
|
||||||
|
}
|
||||||
|
|
||||||
|
void TSE::Texture::SetPixel(const int &x, const int &y, const Color &c)
|
||||||
|
{
|
||||||
|
SetPixelNoApply(x,y,c);
|
||||||
|
Apply();
|
||||||
|
}
|
||||||
|
|
||||||
|
void TSE::Texture::GetPixel(const int &x, const int &y, Color &c) const
|
||||||
|
{
|
||||||
|
if(x >= width() || x < 0 ||y >= height() || y < 0)
|
||||||
|
{
|
||||||
|
TSE_WARNING("trying to access pixel outside of texture.\n pixel: (" + std::to_string(x) + ";" + std::to_string(y) + ")\nTexture size: (" + std::to_string(width()) + ";" + std::to_string(height()) );
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
byte* pixel = getPixelPointer(x,y);
|
||||||
|
byte b = *pixel++;
|
||||||
|
byte g = *pixel++;
|
||||||
|
byte r = *pixel++;
|
||||||
|
byte a = *pixel++;
|
||||||
|
if(bpp() == 8)
|
||||||
|
c = Color(r,r,r);
|
||||||
|
else if(bpp() == 24)
|
||||||
|
c = Color(r,g,b,a);
|
||||||
|
else if(bpp() == 32)
|
||||||
|
c = Color(r,g,b);
|
||||||
|
}
|
||||||
|
|
||||||
|
void TSE::Texture::Fill(const Color &c)
|
||||||
|
{
|
||||||
|
for (int x = 0; x < width(); x++)
|
||||||
|
{
|
||||||
|
for (int y = 0; y < height(); y++)
|
||||||
|
{
|
||||||
|
SetPixelNoApply(x,y,c);
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
Apply();
|
||||||
|
}
|
||||||
|
|
||||||
|
void TSE::Texture::SetPixelNoApply(const int &x, const int &y, const Color &c)
|
||||||
|
{
|
||||||
|
if(x >= width() || x < 0 ||y >= height() || y < 0)
|
||||||
|
{
|
||||||
|
TSE_WARNING("trying to access pixel outside of texture.\n pixel: (" + std::to_string(x) + ";" + std::to_string(y) + ")\nTexture size: (" + std::to_string(width()) + ";" + std::to_string(height()) );
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
byte* pixel = getPixelPointer(x,y);
|
||||||
|
if(chanels == 4 && bpp() == 8)
|
||||||
|
{
|
||||||
|
byte r2bit = static_cast<byte>(c.r * 3.0f);
|
||||||
|
byte g2bit = static_cast<byte>(c.g * 3.0f);
|
||||||
|
byte b2bit = static_cast<byte>(c.b * 3.0f);
|
||||||
|
byte a2bit = static_cast<byte>(c.a * 3.0f);
|
||||||
|
|
||||||
|
byte result = (r2bit << 6) | (g2bit << 4) | (b2bit << 2) | a2bit;
|
||||||
|
*pixel++ = result;
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
*pixel++ = c.B();
|
||||||
|
if(bpp() > 8)
|
||||||
|
{
|
||||||
|
*pixel++ = c.G();
|
||||||
|
*pixel++ = c.R();
|
||||||
|
if(bpp() > 24)
|
||||||
|
*pixel++ = c.A();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
void TSE::Texture::AddPixelNoApply(const int &x, const int &y, const Color &c)
|
||||||
|
{
|
||||||
|
if(x >= width() || x < 0 ||y >= height() || y < 0)
|
||||||
|
{
|
||||||
|
TSE_WARNING("trying to access pixel outside of texture.\n pixel: (" + std::to_string(x) + ";" + std::to_string(y) + ")\nTexture size: (" + std::to_string(width()) + ";" + std::to_string(height()) );
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
byte* pixel = getPixelPointer(x,y);
|
||||||
|
if(chanels == 4 && bpp() == 8) //TODO add propper adding, becouse currently is only setting
|
||||||
|
{
|
||||||
|
byte r2bit = static_cast<byte>(c.r * 3.0f);
|
||||||
|
byte g2bit = static_cast<byte>(c.g * 3.0f);
|
||||||
|
byte b2bit = static_cast<byte>(c.b * 3.0f);
|
||||||
|
byte a2bit = static_cast<byte>(c.a * 3.0f);
|
||||||
|
|
||||||
|
byte result = (r2bit << 6) | (g2bit << 4) | (b2bit << 2) | a2bit;
|
||||||
|
*pixel++ = result;
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
Color bc(pixel[2], pixel[1], pixel[0], pixel[3]);
|
||||||
|
|
||||||
|
bc = c + bc;
|
||||||
|
|
||||||
|
*pixel++ = bc.B();
|
||||||
|
if(bpp() > 8)
|
||||||
|
{
|
||||||
|
*pixel++ = bc.G();
|
||||||
|
*pixel++ = bc.R();
|
||||||
|
if(bpp() > 24)
|
||||||
|
*pixel++ = bc.A();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
void TSE::Texture::Recreate(const int &x, const int &y, const int &bpp, const int &chanels)
|
||||||
|
{
|
||||||
|
if(bmp != nullptr)
|
||||||
|
{
|
||||||
|
FreeImage_Unload(bmp);
|
||||||
|
bmp = nullptr;
|
||||||
|
}
|
||||||
|
if(TextureID != 0)
|
||||||
|
{
|
||||||
|
PlatformDestroy();
|
||||||
|
TextureID = 0;
|
||||||
|
}
|
||||||
|
this->chanels = chanels;
|
||||||
|
Bpp = bpp;
|
||||||
|
Size = Vector2(x, y);
|
||||||
|
bmp = FreeImage_Allocate(x, y, bpp);
|
||||||
|
imagePtr = FreeImage_GetBits(bmp);
|
||||||
|
regist();
|
||||||
|
}
|
||||||
|
|
||||||
|
void TSE::Texture::SavePNG(const std::string &path) const
|
||||||
|
{
|
||||||
|
if(!FreeImage_Save(FREE_IMAGE_FORMAT::FIF_PNG, bmp, path.c_str(), PNG_Z_NO_COMPRESSION))
|
||||||
|
TSE_ERROR("Failed to save Image to \"" + path + "\"");
|
||||||
|
}
|
||||||
|
|
||||||
|
TSE::byte *TSE::Texture::getPixelPointer(const int &x, const int &y) const
|
||||||
|
{
|
||||||
|
int alphaoffset = y * 2;
|
||||||
|
if(bpp() > 24)
|
||||||
|
alphaoffset = 0;
|
||||||
|
int offset = ((y * width() + x) * (bpp() / 8) + alphaoffset);
|
||||||
|
return imagePtr + offset;
|
||||||
|
}
|
||||||
|
|
||||||
|
void TSE::Texture::makeError(Texture &tex)
|
||||||
|
{
|
||||||
|
tex.Bpp = errorTexBpp;
|
||||||
|
tex.chanels = errorTexChannels;
|
||||||
|
tex.Size = Vector2(errorTexWidth, errorTexHeight);
|
||||||
|
|
||||||
|
tex.bmp = FreeImage_ConvertFromRawBits(
|
||||||
|
const_cast<BYTE*>(errorTextureData), // wichtig: cast!
|
||||||
|
errorTexWidth,
|
||||||
|
errorTexHeight,
|
||||||
|
errorTexWidth * errorTexChannels,
|
||||||
|
errorTexBpp,
|
||||||
|
FI_RGBA_RED_MASK,
|
||||||
|
FI_RGBA_GREEN_MASK,
|
||||||
|
FI_RGBA_BLUE_MASK,
|
||||||
|
true // top-down
|
||||||
|
);
|
||||||
|
|
||||||
|
tex.imagePtr = FreeImage_GetBits(tex.bmp);
|
||||||
|
tex.regist();
|
||||||
|
}
|
||||||
|
|
||||||
|
void TSE::Texture::bind() const
|
||||||
|
{
|
||||||
|
helper->Bind(this);
|
||||||
|
}
|
||||||
|
|
||||||
|
void TSE::Texture::unbind() const
|
||||||
|
{
|
||||||
|
helper->UnBind(this);
|
||||||
|
}
|
||||||
|
|
||||||
|
void TSE::Texture::Apply()
|
||||||
|
{
|
||||||
|
helper->Apply(this);
|
||||||
|
}
|
||||||
|
|
||||||
|
void TSE::Texture::regist()
|
||||||
|
{
|
||||||
|
helper->Regist(this);
|
||||||
|
}
|
||||||
|
|
||||||
|
void TSE::Texture::PlatformDestroy()
|
||||||
|
{
|
||||||
|
helper->PlatromDestroy(this);
|
||||||
|
}
|
||||||
62
TSE_Core/src/elements/Texture.hpp
Normal file
62
TSE_Core/src/elements/Texture.hpp
Normal file
@@ -0,0 +1,62 @@
|
|||||||
|
#pragma once
|
||||||
|
|
||||||
|
#include "Sprite.hpp"
|
||||||
|
#include "interfaces/ITexture.hpp"
|
||||||
|
#include "Types.hpp"
|
||||||
|
#include "Vector2.hpp"
|
||||||
|
#include "interfaces/ITextureHelper.hpp"
|
||||||
|
|
||||||
|
#define FREEIMAGE_LIB
|
||||||
|
#include "FI/FreeImage.h"
|
||||||
|
|
||||||
|
namespace TSE
|
||||||
|
{
|
||||||
|
class Texture : public ITexture
|
||||||
|
{
|
||||||
|
protected:
|
||||||
|
uint TextureID = 0;
|
||||||
|
Vector2 Size;
|
||||||
|
uint Bpp;
|
||||||
|
byte chanels = 0;
|
||||||
|
FIBITMAP* bmp = nullptr;
|
||||||
|
byte* imagePtr = nullptr;
|
||||||
|
|
||||||
|
public:
|
||||||
|
string name = "Unnamed";
|
||||||
|
static ITextureHelper* helper;
|
||||||
|
|
||||||
|
Texture(const string& path);
|
||||||
|
Texture(const int& width, const int& height, int bpp = 32);
|
||||||
|
Texture(const Vector2& size, int bpp = 32);
|
||||||
|
~Texture();
|
||||||
|
|
||||||
|
uint bpp() const;
|
||||||
|
Vector2 size() const override;
|
||||||
|
float width() const override;
|
||||||
|
float height() const override;
|
||||||
|
byte Chanels() const;
|
||||||
|
byte* GetImagePtr() const;
|
||||||
|
void SetPixel(const Vector2& pos, const Color& c);
|
||||||
|
void GetPixel(const Vector2& pos, Color& c) const;
|
||||||
|
void SetPixelNoApply(const Vector2& pos, const Color& c);
|
||||||
|
void ToSprite(Sprite& s);
|
||||||
|
void SetChanels(const byte& ch);
|
||||||
|
uint GetTextureId() const override;
|
||||||
|
void SetTextureId(uint id);
|
||||||
|
void SetPixel(const int& x, const int& y, const Color& c);
|
||||||
|
void GetPixel(const int& x, const int& y, Color& c) const;
|
||||||
|
void Fill(const Color& c);
|
||||||
|
void SetPixelNoApply(const int& x, const int& y, const Color& c);
|
||||||
|
void AddPixelNoApply(const int& x, const int& y, const Color& c);
|
||||||
|
void Recreate(const int& x, const int& y, const int& bpp, const int& chanels);
|
||||||
|
void SavePNG(const std::string& path) const;
|
||||||
|
byte* getPixelPointer(const int& x, const int& y) const;
|
||||||
|
static void makeError(Texture& tex);
|
||||||
|
|
||||||
|
void bind() const;
|
||||||
|
void unbind() const;
|
||||||
|
void Apply();
|
||||||
|
void regist();
|
||||||
|
void PlatformDestroy();
|
||||||
|
};
|
||||||
|
} // namespace TSE
|
||||||
35
TSE_Core/src/elements/TileSet.cpp
Normal file
35
TSE_Core/src/elements/TileSet.cpp
Normal file
@@ -0,0 +1,35 @@
|
|||||||
|
#include "TileSet.hpp"
|
||||||
|
#include "Debug.hpp"
|
||||||
|
|
||||||
|
#define PADDING 0.0f
|
||||||
|
|
||||||
|
TSE::TileSet::TileSet(Texture *tex, int x, int y)
|
||||||
|
{
|
||||||
|
SetTexture(tex);
|
||||||
|
SetCount(x,y);
|
||||||
|
}
|
||||||
|
|
||||||
|
void TSE::TileSet::SetCount(int x, int y)
|
||||||
|
{
|
||||||
|
resx = x;
|
||||||
|
resy = y;
|
||||||
|
}
|
||||||
|
|
||||||
|
void TSE::TileSet::SetTexture(Texture *tex)
|
||||||
|
{
|
||||||
|
this->tex = tex;
|
||||||
|
}
|
||||||
|
|
||||||
|
void TSE::TileSet::GetSpriteAt(int x, int y, Sprite &s)
|
||||||
|
{
|
||||||
|
if(x < 0 || x >= resx || y < 0 || y >= resy)
|
||||||
|
{
|
||||||
|
TSE_ERROR("The sprite you are trying to access is out of range");
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
Vector2 startpos = Vector2(((tex->size().x / resx) * (x + PADDING)) / tex->size().x, ((tex->size().y / resy) * (y + PADDING)) / tex->size().y);
|
||||||
|
Vector2 endpos = Vector2(((tex->size().x / resx) * ((x + 1) - PADDING)) / tex->size().x, ((tex->size().y / resy) * ((y + 1) - PADDING)) / tex->size().y);
|
||||||
|
|
||||||
|
s = Sprite(tex, Rect(startpos, endpos));
|
||||||
|
}
|
||||||
31
TSE_Core/src/elements/TileSet.hpp
Normal file
31
TSE_Core/src/elements/TileSet.hpp
Normal file
@@ -0,0 +1,31 @@
|
|||||||
|
#pragma once
|
||||||
|
|
||||||
|
#include "Texture.hpp"
|
||||||
|
#include "Sprite.hpp"
|
||||||
|
|
||||||
|
namespace TSE
|
||||||
|
{
|
||||||
|
class TileSet
|
||||||
|
{
|
||||||
|
private:
|
||||||
|
Texture* tex = nullptr;
|
||||||
|
int resx = 0, resy = 0;
|
||||||
|
|
||||||
|
public:
|
||||||
|
TileSet(Texture* tex, int x, int y);
|
||||||
|
|
||||||
|
void SetCount(int x, int y);
|
||||||
|
void SetTexture(Texture* tex);
|
||||||
|
|
||||||
|
void GetSpriteAt(int x, int y, Sprite& s);
|
||||||
|
|
||||||
|
inline void SetCount(Vector2& v)
|
||||||
|
{
|
||||||
|
SetCount(v.x, v.y);
|
||||||
|
};
|
||||||
|
inline void GetSpriteAt(Vector2& v, Sprite& s)
|
||||||
|
{
|
||||||
|
GetSpriteAt(v.x, v.y, s);
|
||||||
|
};
|
||||||
|
};
|
||||||
|
} // namespace TSE
|
||||||
16
TSE_Core/src/interfaces/ITextureHelper.hpp
Normal file
16
TSE_Core/src/interfaces/ITextureHelper.hpp
Normal file
@@ -0,0 +1,16 @@
|
|||||||
|
#pragma once
|
||||||
|
|
||||||
|
namespace TSE
|
||||||
|
{
|
||||||
|
class Texture;
|
||||||
|
|
||||||
|
class ITextureHelper
|
||||||
|
{
|
||||||
|
public:
|
||||||
|
virtual void Bind(const Texture* tex) = 0;
|
||||||
|
virtual void UnBind(const Texture* tex) = 0;
|
||||||
|
virtual void Apply(Texture* tex) = 0;
|
||||||
|
virtual void Regist(Texture* tex) = 0;
|
||||||
|
virtual void PlatromDestroy(Texture* tex) = 0;
|
||||||
|
};
|
||||||
|
} // namespace TSE
|
||||||
@@ -1,16 +1,16 @@
|
|||||||
#include "InputGlfw.hpp"
|
#include "InputGlfw.hpp"
|
||||||
|
|
||||||
void TSE::InputGlfw::Init()
|
void TSE::GLFW::InputGlfw::Init()
|
||||||
{
|
{
|
||||||
Instance = new InputGlfw();
|
Instance = new InputGlfw();
|
||||||
}
|
}
|
||||||
|
|
||||||
void TSE::InputGlfw::Delete()
|
void TSE::GLFW::InputGlfw::Delete()
|
||||||
{
|
{
|
||||||
delete(Instance);
|
delete(Instance);
|
||||||
}
|
}
|
||||||
|
|
||||||
void TSE::InputGlfw::KeyCallback(GLFWwindow *window, int key, int scancode, int action, int mods)
|
void TSE::GLFW::InputGlfw::KeyCallback(GLFWwindow *window, int key, int scancode, int action, int mods)
|
||||||
{
|
{
|
||||||
switch (action)
|
switch (action)
|
||||||
{
|
{
|
||||||
@@ -35,7 +35,7 @@ void TSE::InputGlfw::KeyCallback(GLFWwindow *window, int key, int scancode, int
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void TSE::InputGlfw::MouseButtonCallback(GLFWwindow *window, int button, int action, int mods)
|
void TSE::GLFW::InputGlfw::MouseButtonCallback(GLFWwindow *window, int button, int action, int mods)
|
||||||
{
|
{
|
||||||
switch (action)
|
switch (action)
|
||||||
{
|
{
|
||||||
@@ -60,7 +60,7 @@ void TSE::InputGlfw::MouseButtonCallback(GLFWwindow *window, int button, int act
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void TSE::InputGlfw::CursorPosCallback(GLFWwindow *window, double xpos, double ypos)
|
void TSE::GLFW::InputGlfw::CursorPosCallback(GLFWwindow *window, double xpos, double ypos)
|
||||||
{
|
{
|
||||||
for(auto handler : ((InputGlfw*)instance())->cursorHandler)
|
for(auto handler : ((InputGlfw*)instance())->cursorHandler)
|
||||||
{
|
{
|
||||||
@@ -68,7 +68,7 @@ void TSE::InputGlfw::CursorPosCallback(GLFWwindow *window, double xpos, double y
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void TSE::InputGlfw::ScrollCallback(GLFWwindow *window, double xoffset, double yoffset)
|
void TSE::GLFW::InputGlfw::ScrollCallback(GLFWwindow *window, double xoffset, double yoffset)
|
||||||
{
|
{
|
||||||
for(auto handler : ((InputGlfw*)instance())->cursorHandler)
|
for(auto handler : ((InputGlfw*)instance())->cursorHandler)
|
||||||
{
|
{
|
||||||
@@ -99,7 +99,7 @@ std::string UTF32ToUTF8(char32_t ch)
|
|||||||
return result;
|
return result;
|
||||||
}
|
}
|
||||||
|
|
||||||
void TSE::InputGlfw::CharCallback(GLFWwindow *window, unsigned int codepoint)
|
void TSE::GLFW::InputGlfw::CharCallback(GLFWwindow *window, unsigned int codepoint)
|
||||||
{
|
{
|
||||||
char32_t c = static_cast<char32_t>(codepoint);
|
char32_t c = static_cast<char32_t>(codepoint);
|
||||||
std::string msg = UTF32ToUTF8(c);
|
std::string msg = UTF32ToUTF8(c);
|
||||||
|
|||||||
@@ -3,7 +3,7 @@
|
|||||||
#include "interfaces/IInputManager.hpp"
|
#include "interfaces/IInputManager.hpp"
|
||||||
#include "GLFW/glfw3.h"
|
#include "GLFW/glfw3.h"
|
||||||
|
|
||||||
namespace TSE
|
namespace TSE::GLFW
|
||||||
{
|
{
|
||||||
class InputGlfw : public IInputManager
|
class InputGlfw : public IInputManager
|
||||||
{
|
{
|
||||||
|
|||||||
@@ -8,6 +8,8 @@
|
|||||||
#include "extern/imgui_impl_glfw.h"
|
#include "extern/imgui_impl_glfw.h"
|
||||||
#include "extern/imgui_impl_opengl3.h"
|
#include "extern/imgui_impl_opengl3.h"
|
||||||
#include "PathHelper.hpp"
|
#include "PathHelper.hpp"
|
||||||
|
#include "elements/Texture.hpp"
|
||||||
|
#include "TextureHelperOpenGL.hpp"
|
||||||
|
|
||||||
TSE::GLFW::OpenGLRenderingBackend::OpenGLRenderingBackend(Color _backgroundColor, bool _vsync)
|
TSE::GLFW::OpenGLRenderingBackend::OpenGLRenderingBackend(Color _backgroundColor, bool _vsync)
|
||||||
: OpenGLRenderingBackend(_backgroundColor, _vsync, 0, false){ }
|
: OpenGLRenderingBackend(_backgroundColor, _vsync, 0, false){ }
|
||||||
@@ -32,6 +34,8 @@ TSE::GLFW::OpenGLRenderingBackend::~OpenGLRenderingBackend()
|
|||||||
|
|
||||||
void TSE::GLFW::OpenGLRenderingBackend::InitPreWindow()
|
void TSE::GLFW::OpenGLRenderingBackend::InitPreWindow()
|
||||||
{
|
{
|
||||||
|
Texture::helper = new TextureHelperOpenGL();
|
||||||
|
|
||||||
glfwWindowHint(GLFW_CONTEXT_VERSION_MAJOR, TSE_OPENGL_VERSION_MAJOR);
|
glfwWindowHint(GLFW_CONTEXT_VERSION_MAJOR, TSE_OPENGL_VERSION_MAJOR);
|
||||||
glfwWindowHint(GLFW_CONTEXT_VERSION_MINOR, TSE_OPENGL_VERSION_MINOR);
|
glfwWindowHint(GLFW_CONTEXT_VERSION_MINOR, TSE_OPENGL_VERSION_MINOR);
|
||||||
glfwWindowHint(GLFW_OPENGL_DEBUG_CONTEXT, 1);
|
glfwWindowHint(GLFW_OPENGL_DEBUG_CONTEXT, 1);
|
||||||
|
|||||||
60
TSE_GlfwOpenGlImpl/src/TextureHelperOpenGL.cpp
Normal file
60
TSE_GlfwOpenGlImpl/src/TextureHelperOpenGL.cpp
Normal file
@@ -0,0 +1,60 @@
|
|||||||
|
#include "TextureHelperOpenGL.hpp"
|
||||||
|
#include <GL/gl3w.h>
|
||||||
|
|
||||||
|
void TSE::GLFW::TextureHelperOpenGL::Bind(const Texture *tex)
|
||||||
|
{
|
||||||
|
glBindTexture(GL_TEXTURE_2D, tex->GetTextureId());
|
||||||
|
}
|
||||||
|
|
||||||
|
void TSE::GLFW::TextureHelperOpenGL::UnBind(const Texture *tex)
|
||||||
|
{
|
||||||
|
glBindTexture(GL_TEXTURE_2D, 0);
|
||||||
|
}
|
||||||
|
|
||||||
|
void TSE::GLFW::TextureHelperOpenGL::Apply(Texture *tex)
|
||||||
|
{
|
||||||
|
glBindTexture(GL_TEXTURE_2D, tex->GetTextureId());
|
||||||
|
if(tex->Chanels() == 1)
|
||||||
|
{
|
||||||
|
if (tex->bpp() == 8)
|
||||||
|
glTexImage2D(GL_TEXTURE_2D, 0,GL_RGBA, tex->width(), tex->height(), 0, GL_RED, GL_UNSIGNED_BYTE, tex->GetImagePtr());
|
||||||
|
}
|
||||||
|
if(tex->Chanels() == 3)
|
||||||
|
{
|
||||||
|
if(tex->bpp() == 24)
|
||||||
|
glTexImage2D(GL_TEXTURE_2D, 0,GL_RGBA, tex->width(), tex->height(), 0, GL_BGR, GL_UNSIGNED_BYTE, tex->GetImagePtr());
|
||||||
|
}
|
||||||
|
else if(tex->Chanels() == 4)
|
||||||
|
{
|
||||||
|
if(tex->bpp() == 32)
|
||||||
|
glTexImage2D(GL_TEXTURE_2D, 0,GL_RGBA, tex->width(), tex->height(), 0, GL_BGRA, GL_UNSIGNED_BYTE, tex->GetImagePtr());
|
||||||
|
if (tex->bpp() == 8) //need to decode it with bitwise operations in shader
|
||||||
|
glTexImage2D(GL_TEXTURE_2D, 0,GL_RGBA, tex->width(), tex->height(), 0, GL_RED, GL_UNSIGNED_BYTE, tex->GetImagePtr());
|
||||||
|
}
|
||||||
|
|
||||||
|
glGenerateMipmap(GL_TEXTURE_2D);
|
||||||
|
|
||||||
|
glBindTexture(GL_TEXTURE_2D, 0);
|
||||||
|
}
|
||||||
|
|
||||||
|
void TSE::GLFW::TextureHelperOpenGL::Regist(Texture *tex)
|
||||||
|
{
|
||||||
|
uint TextureID;
|
||||||
|
|
||||||
|
glGenTextures(1, &TextureID);
|
||||||
|
glBindTexture(GL_TEXTURE_2D, TextureID);
|
||||||
|
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_NEAREST);
|
||||||
|
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_NEAREST);
|
||||||
|
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_CLAMP_TO_EDGE);
|
||||||
|
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_CLAMP_TO_EDGE);
|
||||||
|
|
||||||
|
tex->SetTextureId(TextureID);
|
||||||
|
|
||||||
|
tex->Apply();
|
||||||
|
}
|
||||||
|
|
||||||
|
void TSE::GLFW::TextureHelperOpenGL::PlatromDestroy(Texture *tex)
|
||||||
|
{
|
||||||
|
uint id = tex->GetTextureId();
|
||||||
|
glDeleteTextures(1, &id);
|
||||||
|
}
|
||||||
17
TSE_GlfwOpenGlImpl/src/TextureHelperOpenGL.hpp
Normal file
17
TSE_GlfwOpenGlImpl/src/TextureHelperOpenGL.hpp
Normal file
@@ -0,0 +1,17 @@
|
|||||||
|
#pragma once
|
||||||
|
|
||||||
|
#include "interfaces/ITextureHelper.hpp"
|
||||||
|
#include "elements/Texture.hpp"
|
||||||
|
|
||||||
|
namespace TSE::GLFW
|
||||||
|
{
|
||||||
|
class TextureHelperOpenGL : public ITextureHelper
|
||||||
|
{
|
||||||
|
public:
|
||||||
|
void Bind(const Texture* tex) override;
|
||||||
|
void UnBind(const Texture* tex) override;
|
||||||
|
void Apply(Texture* tex) override;
|
||||||
|
void Regist(Texture* tex) override;
|
||||||
|
void PlatromDestroy(Texture* tex) override;
|
||||||
|
};
|
||||||
|
} // namespace TSE::GLFW
|
||||||
Reference in New Issue
Block a user