RenderCore
This commit is contained in:
64
Src/RenderCore/inc/RenderCore/Base.hpp
Normal file
64
Src/RenderCore/inc/RenderCore/Base.hpp
Normal file
@ -0,0 +1,64 @@
|
||||
// IAEngine: 2D Game Engine by IA
|
||||
// Copyright (C) 2025 IASoft (PVT) LTD (oss@iasoft.dev)
|
||||
//
|
||||
// This program is free software: you can redistribute it and/or modify
|
||||
// it under the terms of the GNU General Public License as published by
|
||||
// the Free Software Foundation, either version 3 of the License, or
|
||||
// (at your option) any later version.
|
||||
//
|
||||
// This program is distributed in the hope that it will be useful,
|
||||
// but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
// GNU General Public License for more details.
|
||||
//
|
||||
// You should have received a copy of the GNU General Public License
|
||||
// along with this program. If not, see <https://www.gnu.org/licenses/>.
|
||||
|
||||
#pragma once
|
||||
|
||||
#include <IACore/Exception.hpp>
|
||||
#include <IACore/Logger.hpp>
|
||||
#include <IACore/Map.hpp>
|
||||
#include <IACore/Memory.hpp>
|
||||
#include <IACore/String.hpp>
|
||||
#include <IACore/Vector.hpp>
|
||||
|
||||
#include <glm/ext/matrix_clip_space.hpp>
|
||||
#include <glm/ext/matrix_transform.hpp>
|
||||
#include <glm/ext/scalar_constants.hpp>
|
||||
#include <glm/mat4x4.hpp>
|
||||
#include <glm/vec2.hpp>
|
||||
#include <glm/vec3.hpp>
|
||||
#include <glm/vec4.hpp>
|
||||
|
||||
#define RDC_LOG_TAG "RDC"
|
||||
|
||||
#define RDC_LOG_INFO(...) ia::Logger::Info(RDC_LOG_TAG, __VA_ARGS__)
|
||||
#define RDC_LOG_WARN(...) ia::Logger::Warn(RDC_LOG_TAG, __VA_ARGS__)
|
||||
#define RDC_LOG_ERROR(...) ia::Logger::Error(RDC_LOG_TAG, __VA_ARGS__)
|
||||
#define RDC_LOG_SUCCESS(...) ia::Logger::Success(RDC_LOG_TAG, __VA_ARGS__)
|
||||
|
||||
namespace ia::iae
|
||||
{
|
||||
using Handle = INT64;
|
||||
STATIC CONSTEXPR Handle INVALID_HANDLE = -1;
|
||||
|
||||
using Vec2 = glm::vec2;
|
||||
using Vec3 = glm::vec3;
|
||||
using Vec4 = glm::vec4;
|
||||
using IVec2 = glm::ivec2;
|
||||
using IVec3 = glm::ivec3;
|
||||
using IVec4 = glm::ivec4;
|
||||
using Mat4 = glm::mat4;
|
||||
|
||||
struct ImageData
|
||||
{
|
||||
PUINT8 Pixels{};
|
||||
INT32 Width{};
|
||||
INT32 Height{};
|
||||
INT32 TileWidth{};
|
||||
INT32 TileHeight{};
|
||||
INT32 TileCountX{};
|
||||
INT32 TileCountY{};
|
||||
};
|
||||
} // namespace ia::iae
|
||||
90
Src/RenderCore/inc/RenderCore/Buffer.hpp
Normal file
90
Src/RenderCore/inc/RenderCore/Buffer.hpp
Normal file
@ -0,0 +1,90 @@
|
||||
// IAEngine: 2D Game Engine by IA
|
||||
// Copyright (C) 2025 IASoft (PVT) LTD (oss@iasoft.dev)
|
||||
//
|
||||
// This program is free software: you can redistribute it and/or modify
|
||||
// it under the terms of the GNU General Public License as published by
|
||||
// the Free Software Foundation, either version 3 of the License, or
|
||||
// (at your option) any later version.
|
||||
//
|
||||
// This program is distributed in the hope that it will be useful,
|
||||
// but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
// GNU General Public License for more details.
|
||||
//
|
||||
// You should have received a copy of the GNU General Public License
|
||||
// along with this program. If not, see <https://www.gnu.org/licenses/>.
|
||||
|
||||
#pragma once
|
||||
|
||||
#include <RenderCore/Device.hpp>
|
||||
|
||||
namespace ia::iae
|
||||
{
|
||||
class RDC_StagingBuffer;
|
||||
|
||||
class RDC_Buffer
|
||||
{
|
||||
public:
|
||||
enum class EType
|
||||
{
|
||||
NONE,
|
||||
|
||||
VERTEX,
|
||||
INDEX,
|
||||
STORAGE
|
||||
};
|
||||
|
||||
public:
|
||||
RDC_Buffer();
|
||||
RDC_Buffer(IN EType type, IN UINT32 size);
|
||||
|
||||
protected:
|
||||
CONST EType m_type;
|
||||
CONST UINT32 m_size;
|
||||
};
|
||||
|
||||
class RDC_DeviceLocalBuffer : public RDC_Buffer
|
||||
{
|
||||
public:
|
||||
RDC_DeviceLocalBuffer();
|
||||
RDC_DeviceLocalBuffer(IN RDC_Buffer::EType type, IN UINT32 size);
|
||||
~RDC_DeviceLocalBuffer();
|
||||
|
||||
VOID CopyFrom(IN RDC_StagingBuffer *stagingBuffer, IN UINT32 size);
|
||||
VOID CopyFrom(IN SDL_GPUTransferBuffer *stagingBuffer, IN UINT32 size);
|
||||
|
||||
SDL_GPUBuffer *GetHandle()
|
||||
{
|
||||
return m_buffer;
|
||||
}
|
||||
|
||||
protected:
|
||||
SDL_GPUBuffer *m_buffer{};
|
||||
};
|
||||
|
||||
class RDC_HostVisibleBuffer : public RDC_DeviceLocalBuffer
|
||||
{
|
||||
public:
|
||||
RDC_HostVisibleBuffer(IN RDC_Buffer::EType type, IN UINT32 size);
|
||||
~RDC_HostVisibleBuffer();
|
||||
|
||||
VOID CopyFrom(IN PCVOID data, IN UINT32 size);
|
||||
|
||||
private:
|
||||
SDL_GPUTransferBuffer *m_stagingBuffer{};
|
||||
};
|
||||
|
||||
class RDC_StagingBuffer : public RDC_Buffer
|
||||
{
|
||||
public:
|
||||
RDC_StagingBuffer(IN UINT32 size);
|
||||
~RDC_StagingBuffer();
|
||||
|
||||
VOID CopyFrom(IN PCVOID data, IN UINT32 size);
|
||||
|
||||
private:
|
||||
SDL_GPUTransferBuffer *m_buffer{};
|
||||
|
||||
friend class RDC_DeviceLocalBuffer;
|
||||
};
|
||||
} // namespace ia::iae
|
||||
56
Src/RenderCore/inc/RenderCore/Device.hpp
Normal file
56
Src/RenderCore/inc/RenderCore/Device.hpp
Normal file
@ -0,0 +1,56 @@
|
||||
// IAEngine: 2D Game Engine by IA
|
||||
// Copyright (C) 2025 IASoft (PVT) LTD (oss@iasoft.dev)
|
||||
//
|
||||
// This program is free software: you can redistribute it and/or modify
|
||||
// it under the terms of the GNU General Public License as published by
|
||||
// the Free Software Foundation, either version 3 of the License, or
|
||||
// (at your option) any later version.
|
||||
//
|
||||
// This program is distributed in the hope that it will be useful,
|
||||
// but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
// GNU General Public License for more details.
|
||||
//
|
||||
// You should have received a copy of the GNU General Public License
|
||||
// along with this program. If not, see <https://www.gnu.org/licenses/>.
|
||||
|
||||
#pragma once
|
||||
|
||||
#include <RenderCore/Base.hpp>
|
||||
#include <SDL3/SDL.h>
|
||||
|
||||
namespace ia::iae
|
||||
{
|
||||
struct GeometryVertex
|
||||
{
|
||||
Vec2 Position;
|
||||
Vec2 TexCoords;
|
||||
};
|
||||
|
||||
class RDC_Device
|
||||
{
|
||||
public:
|
||||
STATIC VOID Initialize(IN SDL_Window *windowHandle, IN BOOL isDebugMode);
|
||||
STATIC VOID Terminate();
|
||||
|
||||
public:
|
||||
STATIC VOID WaitForIdle();
|
||||
|
||||
STATIC Handle CreateGeometry(IN CONST Vector<GeometryVertex> &vertices, IN CONST Vector<INT32> &indices);
|
||||
STATIC VOID DestroyGeometry(IN Handle geometry);
|
||||
STATIC VOID BindGeometry(IN SDL_GPURenderPass* renderPass, IN Handle geometry);
|
||||
|
||||
public:
|
||||
STATIC SDL_GPUTextureFormat GetSwapchainTextureFormat();
|
||||
|
||||
public:
|
||||
STATIC SDL_GPUDevice *GetHandle()
|
||||
{
|
||||
return s_handle;
|
||||
}
|
||||
|
||||
private:
|
||||
STATIC SDL_GPUDevice *s_handle;
|
||||
STATIC SDL_Window *s_windowHandle;
|
||||
};
|
||||
} // namespace ia::iae
|
||||
50
Src/RenderCore/inc/RenderCore/Pipeline.hpp
Normal file
50
Src/RenderCore/inc/RenderCore/Pipeline.hpp
Normal file
@ -0,0 +1,50 @@
|
||||
// IAEngine: 2D Game Engine by IA
|
||||
// Copyright (C) 2025 IASoft (PVT) LTD (oss@iasoft.dev)
|
||||
//
|
||||
// This program is free software: you can redistribute it and/or modify
|
||||
// it under the terms of the GNU General Public License as published by
|
||||
// the Free Software Foundation, either version 3 of the License, or
|
||||
// (at your option) any later version.
|
||||
//
|
||||
// This program is distributed in the hope that it will be useful,
|
||||
// but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
// GNU General Public License for more details.
|
||||
//
|
||||
// You should have received a copy of the GNU General Public License
|
||||
// along with this program. If not, see <https://www.gnu.org/licenses/>.
|
||||
|
||||
#pragma once
|
||||
|
||||
#include <RenderCore/Device.hpp>
|
||||
|
||||
namespace ia::iae
|
||||
{
|
||||
class RDC_Pipeline
|
||||
{
|
||||
public:
|
||||
struct StageDesc
|
||||
{
|
||||
Vector<UINT8> SourceData{};
|
||||
UINT32 SamplerCount{};
|
||||
UINT32 UniformBufferCount{};
|
||||
UINT32 StorageBufferCount{};
|
||||
};
|
||||
|
||||
public:
|
||||
RDC_Pipeline(IN SDL_GPUTextureFormat renderTargetFormat, IN CONST StageDesc &vertexStageDesc, IN CONST StageDesc &pixelStageDesc,
|
||||
IN BOOL enableVertexBuffer);
|
||||
~RDC_Pipeline();
|
||||
|
||||
VOID Bind(IN SDL_GPURenderPass* renderPass);
|
||||
|
||||
public:
|
||||
SDL_GPUGraphicsPipeline *GetHandle() CONST
|
||||
{
|
||||
return m_handle;
|
||||
}
|
||||
|
||||
private:
|
||||
SDL_GPUGraphicsPipeline *m_handle{};
|
||||
};
|
||||
} // namespace ia::iae
|
||||
90
Src/RenderCore/inc/RenderCore/RenderCore.hpp
Normal file
90
Src/RenderCore/inc/RenderCore/RenderCore.hpp
Normal file
@ -0,0 +1,90 @@
|
||||
// IAEngine: 2D Game Engine by IA
|
||||
// Copyright (C) 2025 IASoft (PVT) LTD (oss@iasoft.dev)
|
||||
//
|
||||
// This program is free software: you can redistribute it and/or modify
|
||||
// it under the terms of the GNU General Public License as published by
|
||||
// the Free Software Foundation, either version 3 of the License, or
|
||||
// (at your option) any later version.
|
||||
//
|
||||
// This program is distributed in the hope that it will be useful,
|
||||
// but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
// GNU General Public License for more details.
|
||||
//
|
||||
// You should have received a copy of the GNU General Public License
|
||||
// along with this program. If not, see <https://www.gnu.org/licenses/>.
|
||||
|
||||
#pragma once
|
||||
|
||||
#include <RenderCore/Buffer.hpp>
|
||||
#include <RenderCore/Texture.hpp>
|
||||
#include <RenderCore/Pipeline.hpp>
|
||||
#include <RenderCore/TextureAtlas.hpp>
|
||||
|
||||
namespace ia::iae
|
||||
{
|
||||
#pragma pack(push, 1)
|
||||
|
||||
struct RDC_SpriteInstanceData
|
||||
{
|
||||
Mat4 Transform{1.0f};
|
||||
Vec4 TexCoords{};
|
||||
Vec4 Color{1.0f, 1.0f, 1.0f, 1.0f};
|
||||
};
|
||||
|
||||
#pragma pack(pop)
|
||||
|
||||
class RDC
|
||||
{
|
||||
public:
|
||||
STATIC CONSTEXPR INT32 MAX_SPRITE_COUNT = 100000;
|
||||
|
||||
public:
|
||||
STATIC VOID Initialize(IN IVec2 viewportExtent, IN SDL_Window *windowHandle, IN BOOL isDebugMode);
|
||||
STATIC VOID Terminate();
|
||||
|
||||
STATIC VOID ResizeScreen(IN IVec2 newExtent);
|
||||
|
||||
STATIC VOID RenderToWindow();
|
||||
|
||||
public:
|
||||
STATIC Vec2 GetCameraPosition();
|
||||
STATIC VOID SetCameraPosition(IN Vec2 position);
|
||||
|
||||
STATIC Vec2 DrawSpriteTopLeft(IN Handle image, IN INT32 tileIndexX, IN INT32 tileIndexY,
|
||||
IN Vec2 position, IN Vec2 scale, IN FLOAT32 rotation, IN BOOL flipH = false, IN BOOL flipV = false, IN Vec2 uvOffset = {});
|
||||
STATIC Vec2 DrawSpriteCentered(IN Handle image, IN INT32 tileIndexX, IN INT32 tileIndexY,
|
||||
IN Vec2 position, IN Vec2 scale, IN FLOAT32 rotation, IN BOOL flipH = false, IN BOOL flipV = false, IN Vec2 uvOffset = {});
|
||||
|
||||
STATIC Handle CreateImage(IN PCUINT8 rgbaData, IN INT32 width, IN INT32 height, IN INT32 tileCountX = 1,
|
||||
IN INT32 tileCountY = 1);
|
||||
STATIC VOID DestroyImage(IN Handle image);
|
||||
|
||||
STATIC VOID CompileTextures(IN CONST Vector<Handle>& images);
|
||||
|
||||
private:
|
||||
STATIC VOID InitializeSamplers();
|
||||
STATIC VOID InitializeDrawData();
|
||||
STATIC VOID InitializeTextures();
|
||||
STATIC VOID InitializePipelines();
|
||||
STATIC VOID InitializeGeometries();
|
||||
|
||||
private:
|
||||
STATIC Mat4 s_viewMatrix;
|
||||
STATIC IVec2 s_viewportExtent;
|
||||
STATIC Mat4 s_projectionMatrix;
|
||||
STATIC Vec2 s_cameraPosition;
|
||||
STATIC Handle s_quadGeometry;
|
||||
STATIC SDL_Window *s_windowHandle;
|
||||
STATIC RDC_Pipeline *s_dynamicSpritePipeline;
|
||||
STATIC SDL_GPUSampler *s_linearClampSampler;
|
||||
STATIC SDL_GPUSampler *s_linearRepeatSampler;
|
||||
STATIC RDC_TextureAtlas *s_staticSpriteAtlas;
|
||||
STATIC RDC_TextureAtlas *s_dynamicSpriteAtlas;
|
||||
STATIC RDC_HostVisibleBuffer* s_staticSpriteInstanceBuffer;
|
||||
STATIC RDC_HostVisibleBuffer* s_dynamicSpriteInstanceBuffer;
|
||||
STATIC INT32 s_spriteInstanceCount;
|
||||
STATIC RDC_Texture* s_defaultTexture;
|
||||
STATIC RDC_SpriteInstanceData s_spriteInstances[MAX_SPRITE_COUNT];
|
||||
};
|
||||
} // namespace ia::iae
|
||||
63
Src/RenderCore/inc/RenderCore/Texture.hpp
Normal file
63
Src/RenderCore/inc/RenderCore/Texture.hpp
Normal file
@ -0,0 +1,63 @@
|
||||
// IAEngine: 2D Game Engine by IA
|
||||
// Copyright (C) 2025 IASoft (PVT) LTD (oss@iasoft.dev)
|
||||
//
|
||||
// This program is free software: you can redistribute it and/or modify
|
||||
// it under the terms of the GNU General Public License as published by
|
||||
// the Free Software Foundation, either version 3 of the License, or
|
||||
// (at your option) any later version.
|
||||
//
|
||||
// This program is distributed in the hope that it will be useful,
|
||||
// but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
// GNU General Public License for more details.
|
||||
//
|
||||
// You should have received a copy of the GNU General Public License
|
||||
// along with this program. If not, see <https://www.gnu.org/licenses/>.
|
||||
|
||||
#pragma once
|
||||
|
||||
#include <RenderCore/Device.hpp>
|
||||
|
||||
namespace ia::iae
|
||||
{
|
||||
class RDC_Texture
|
||||
{
|
||||
public:
|
||||
enum class EType
|
||||
{
|
||||
SAMPLED,
|
||||
RENDER_TARGET
|
||||
};
|
||||
|
||||
public:
|
||||
RDC_Texture(IN EType type, IN INT32 width, IN INT32 height, IN BOOL generateMipMaps = false);
|
||||
~RDC_Texture();
|
||||
|
||||
VOID SetImageData(IN PCUINT8 rgbaData, IN INT32 stride = -1);
|
||||
|
||||
VOID BindAsSampler(IN SDL_GPURenderPass* renderPass, IN INT32 index, IN SDL_GPUSampler* sampler);
|
||||
|
||||
public:
|
||||
SDL_GPUTexture *GetHandle() CONST
|
||||
{
|
||||
return m_handle;
|
||||
}
|
||||
|
||||
INT32 Width() CONST
|
||||
{
|
||||
return m_width;
|
||||
}
|
||||
|
||||
INT32 Height() CONST
|
||||
{
|
||||
return m_height;
|
||||
}
|
||||
|
||||
private:
|
||||
CONST EType m_type;
|
||||
CONST INT32 m_width;
|
||||
CONST INT32 m_height;
|
||||
CONST UINT32 m_mipLevels;
|
||||
SDL_GPUTexture *m_handle;
|
||||
};
|
||||
} // namespace ia::iae
|
||||
44
Src/RenderCore/inc/RenderCore/TextureAtlas.hpp
Normal file
44
Src/RenderCore/inc/RenderCore/TextureAtlas.hpp
Normal file
@ -0,0 +1,44 @@
|
||||
// IAEngine: 2D Game Engine by IA
|
||||
// Copyright (C) 2025 IASoft (PVT) LTD (oss@iasoft.dev)
|
||||
//
|
||||
// This program is free software: you can redistribute it and/or modify
|
||||
// it under the terms of the GNU General Public License as published by
|
||||
// the Free Software Foundation, either version 3 of the License, or
|
||||
// (at your option) any later version.
|
||||
//
|
||||
// This program is distributed in the hope that it will be useful,
|
||||
// but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
// GNU General Public License for more details.
|
||||
//
|
||||
// You should have received a copy of the GNU General Public License
|
||||
// along with this program. If not, see <https://www.gnu.org/licenses/>.
|
||||
|
||||
#pragma once
|
||||
|
||||
#include <RenderCore/Texture.hpp>
|
||||
|
||||
namespace ia::iae
|
||||
{
|
||||
class RDC_TextureAtlas
|
||||
{
|
||||
public:
|
||||
RDC_TextureAtlas(IN CONST Vector<Handle> &images);
|
||||
~RDC_TextureAtlas();
|
||||
|
||||
Vec4 GetTextureCoordinates(IN Handle image, IN INT32 tileIndexX, IN INT32 tileIndexY, IN BOOL flipH,
|
||||
IN BOOL flipV, IN Vec2 uvOffset);
|
||||
|
||||
public:
|
||||
CONST RDC_Texture *GetTexture() CONST
|
||||
{
|
||||
return m_texture;
|
||||
}
|
||||
|
||||
private:
|
||||
IVec2 m_atlasSize;
|
||||
RDC_Texture *m_texture;
|
||||
Vec2 m_inverseAtlasSize;
|
||||
Map<Handle, Vec2> m_texCoordMap;
|
||||
};
|
||||
} // namespace ia::iae
|
||||
Reference in New Issue
Block a user