Optimized Renderer
This commit is contained in:
@ -39,11 +39,7 @@ namespace ia::iae
|
||||
Renderer::State Renderer::s_state{};
|
||||
SDL_GPUDevice *Renderer::s_gpuDevice{};
|
||||
|
||||
SDL_GPUTexture *Renderer::s_renderTargetSceneColor{};
|
||||
SDL_GPUTexture *Renderer::s_renderTargetDebugDrawColor{};
|
||||
|
||||
Pipeline *Renderer::s_geometryPipeline{};
|
||||
Pipeline *Renderer::s_postprocessPipeline{};
|
||||
|
||||
Renderer::Geometry *Renderer::s_quadGeometry{};
|
||||
Renderer::Geometry *Renderer::s_circleGeometry{};
|
||||
@ -54,10 +50,12 @@ namespace ia::iae
|
||||
SDL_GPUCommandBuffer *Renderer::s_activeCommandBuffer{};
|
||||
SDL_GPUColorTargetInfo Renderer::s_colorTargetInfo{};
|
||||
class CameraComponent *Renderer::s_activeCamera{};
|
||||
BOOL Renderer::s_ySortingEnabled{false};
|
||||
SDL_Rect Renderer::s_defaultScissor{};
|
||||
SDL_GPUViewport Renderer::s_defaultViewport{};
|
||||
|
||||
SDL_Rect Renderer::s_scissor{0, 0, 0, 0};
|
||||
SDL_GPUViewport Renderer::s_activeViewport{};
|
||||
Vec2 Renderer::s_sceneScaleFactor{1.0f, 1.0f};
|
||||
EXTERN Vec2 g_sceneScalingFactor;
|
||||
EXTERN Vec2 g_sceneDesignViewport;
|
||||
|
||||
VOID Renderer::Initialize()
|
||||
{
|
||||
@ -81,7 +79,7 @@ namespace ia::iae
|
||||
SDL_GetWindowSizeInPixels(g_windowHandle, &s_screenWidth, &s_screenHeight);
|
||||
OnScreenResize(s_screenWidth, s_screenHeight);
|
||||
|
||||
// Initialize Pipelines
|
||||
// Initialize Pipeline
|
||||
s_geometryPipeline = new Pipeline(
|
||||
Pipeline::StageDesc{
|
||||
.SourceData = SHADER_SOURCE_GEOMETRY_VERT,
|
||||
@ -96,20 +94,6 @@ namespace ia::iae
|
||||
.UniformBufferCount = 1,
|
||||
},
|
||||
true, true);
|
||||
s_postprocessPipeline = new Pipeline(
|
||||
Pipeline::StageDesc{
|
||||
.SourceData = SHADER_SOURCE_POSTPROCESS_VERT,
|
||||
.SourceLength = sizeof(SHADER_SOURCE_POSTPROCESS_VERT),
|
||||
.SamplerCount = 0,
|
||||
.UniformBufferCount = 0,
|
||||
},
|
||||
Pipeline::StageDesc{
|
||||
.SourceData = SHADER_SOURCE_POSTPROCESS_FRAG,
|
||||
.SourceLength = sizeof(SHADER_SOURCE_POSTPROCESS_FRAG),
|
||||
.SamplerCount = 2,
|
||||
.UniformBufferCount = 0,
|
||||
},
|
||||
false, false);
|
||||
|
||||
DebugDraw::Initialize();
|
||||
|
||||
@ -256,10 +240,6 @@ namespace ia::iae
|
||||
DebugDraw::Terminate();
|
||||
|
||||
delete s_geometryPipeline;
|
||||
delete s_postprocessPipeline;
|
||||
|
||||
GPUResourceManager::DestroyTexture(s_renderTargetSceneColor);
|
||||
GPUResourceManager::DestroyTexture(s_renderTargetDebugDrawColor);
|
||||
|
||||
GPUResourceManager::Terminate();
|
||||
|
||||
@ -267,6 +247,8 @@ namespace ia::iae
|
||||
SDL_DestroyGPUDevice(s_gpuDevice);
|
||||
}
|
||||
|
||||
ImDrawData *g_imDrawData{};
|
||||
|
||||
VOID Renderer::BeginFrame()
|
||||
{
|
||||
s_drawEntries.clear();
|
||||
@ -274,18 +256,50 @@ namespace ia::iae
|
||||
if (!(s_activeCommandBuffer = SDL_AcquireGPUCommandBuffer(s_gpuDevice)))
|
||||
THROW_UNKNOWN("Failed to acquire SDL GPU command buffer: ", SDL_GetError());
|
||||
|
||||
SDL_GPUTexture *swapChainTexture{};
|
||||
if (!SDL_WaitAndAcquireGPUSwapchainTexture(s_activeCommandBuffer, g_windowHandle, &swapChainTexture,
|
||||
(PUINT32) &s_screenWidth, (PUINT32) &s_screenHeight))
|
||||
THROW_UNKNOWN("Failed to acquire SDL GPU Swapchain texture: ", SDL_GetError());
|
||||
|
||||
if (!swapChainTexture)
|
||||
return;
|
||||
|
||||
DebugDraw::Render();
|
||||
g_imDrawData = ImGui::GetDrawData();
|
||||
ImGui_ImplSDLGPU3_PrepareDrawData(g_imDrawData, s_activeCommandBuffer);
|
||||
|
||||
const auto clearColor = WorldManager::GetActiveScene()->BackgroundColor().GetAsFloatVec();
|
||||
s_colorTargetInfo.clear_color = SDL_FColor{clearColor.x, clearColor.y, clearColor.z, 1.0f};
|
||||
s_colorTargetInfo.texture = s_renderTargetSceneColor;
|
||||
s_colorTargetInfo.texture = swapChainTexture;
|
||||
s_activeRenderPass = SDL_BeginGPURenderPass(s_activeCommandBuffer, &s_colorTargetInfo, 1, nullptr);
|
||||
|
||||
SDL_BindGPUGraphicsPipeline(s_activeRenderPass, s_geometryPipeline->GetHandle());
|
||||
SDL_PushGPUVertexUniformData(s_activeCommandBuffer, 0,
|
||||
s_activeCamera ? s_activeCamera->GetProjectionMatrix() : &IdentityMatrix,
|
||||
sizeof(Mat4));
|
||||
|
||||
s_state.Scissor = s_defaultScissor;
|
||||
}
|
||||
|
||||
VOID Renderer::EndFrame()
|
||||
{
|
||||
std::sort(s_drawEntries.begin(), s_drawEntries.end(), [](IN CONST DrawEntry &a, IN CONST DrawEntry &b) {
|
||||
if (a.Layer != b.Layer)
|
||||
return a.Layer < b.Layer;
|
||||
return a.SortIndex < b.SortIndex;
|
||||
});
|
||||
|
||||
for (const auto &t : s_drawEntries)
|
||||
Draw(t);
|
||||
|
||||
ImGui_ImplSDLGPU3_RenderDrawData(g_imDrawData, s_activeCommandBuffer, s_activeRenderPass);
|
||||
|
||||
SDL_EndGPURenderPass(s_activeRenderPass);
|
||||
|
||||
SDL_SubmitGPUCommandBuffer(s_activeCommandBuffer);
|
||||
}
|
||||
|
||||
VOID Renderer::Draw(IN CONST DrawEntry &t)
|
||||
{
|
||||
#pragma pack(push, 1)
|
||||
|
||||
@ -299,78 +313,39 @@ namespace ia::iae
|
||||
|
||||
#pragma pack(pop)
|
||||
|
||||
std::sort(s_drawEntries.begin(), s_drawEntries.end(), [](IN CONST DrawEntry &a, IN CONST DrawEntry &b) {
|
||||
if (a.Layer != b.Layer)
|
||||
return a.Layer < b.Layer;
|
||||
return a.SortIndex < b.SortIndex;
|
||||
});
|
||||
Vec2 position = t.DrawState.Position * g_sceneScalingFactor;
|
||||
Vec2 scale = t.DrawState.Scale * g_sceneScalingFactor;
|
||||
|
||||
for (const auto &t : s_drawEntries)
|
||||
{
|
||||
SDL_PushGPUVertexUniformData(
|
||||
s_activeCommandBuffer, 1,
|
||||
(s_activeCamera && t.DrawState.CameraRelative) ? s_activeCamera->GetViewMatrix() : &IdentityMatrix,
|
||||
sizeof(Mat4));
|
||||
Mat4 modelMatrix = glm::translate(glm::mat4(1.0f), glm::vec3{position.x, position.y, 0});
|
||||
modelMatrix = glm::rotate(modelMatrix, t.DrawState.Rotation, glm::vec3(0.0f, 0.0f, 1.0f));
|
||||
modelMatrix = glm::scale(modelMatrix, glm::vec3{scale.x, scale.y, 1.0f});
|
||||
|
||||
SDL_PushGPUVertexUniformData(Renderer::s_activeCommandBuffer, 2, &t.DrawState.ModelMatrix, sizeof(Mat4));
|
||||
SDL_PushGPUVertexUniformData(s_activeCommandBuffer, 1,
|
||||
(s_activeCamera && t.DrawState.CameraRelative) ? s_activeCamera->GetViewMatrix()
|
||||
: &IdentityMatrix,
|
||||
sizeof(Mat4));
|
||||
|
||||
s_fragmentUniform.ColorOverlay = t.DrawState.ColorOverlay.GetAsFloatVec();
|
||||
s_fragmentUniform.FlippedH = t.DrawState.FlippedH;
|
||||
s_fragmentUniform.FlippedV = t.DrawState.FlippedV;
|
||||
s_fragmentUniform.TextureOffset = t.DrawState.TextureOffset;
|
||||
SDL_GPUTextureSamplerBinding textureBinding{.texture = t.DrawState.ActiveTexture,
|
||||
.sampler = ((t.DrawState.TextureOffset.x <= FLOAT32_EPSILON) &&
|
||||
(t.DrawState.TextureOffset.y <= FLOAT32_EPSILON))
|
||||
? GPUResourceManager::GetSampler_LinearClamp()
|
||||
: GPUResourceManager::GetSampler_LinearRepeat()};
|
||||
SDL_BindGPUFragmentSamplers(s_activeRenderPass, 0, &textureBinding, 1);
|
||||
SDL_PushGPUFragmentUniformData(s_activeCommandBuffer, 0, &s_fragmentUniform, sizeof(s_fragmentUniform));
|
||||
SDL_PushGPUVertexUniformData(Renderer::s_activeCommandBuffer, 2, &modelMatrix, sizeof(Mat4));
|
||||
|
||||
// SDL_SetGPUScissor(s_activeRenderPass, &s_scissor);
|
||||
// SDL_SetGPUViewport(s_activeRenderPass, &s_activeViewport);
|
||||
s_fragmentUniform.ColorOverlay = t.DrawState.ColorOverlay.GetAsFloatVec();
|
||||
s_fragmentUniform.FlippedH = t.DrawState.FlippedH;
|
||||
s_fragmentUniform.FlippedV = t.DrawState.FlippedV;
|
||||
s_fragmentUniform.TextureOffset = t.DrawState.TextureOffset;
|
||||
SDL_GPUTextureSamplerBinding textureBinding{.texture = t.DrawState.ActiveTexture,
|
||||
.sampler = ((t.DrawState.TextureOffset.x <= FLOAT32_EPSILON) &&
|
||||
(t.DrawState.TextureOffset.y <= FLOAT32_EPSILON))
|
||||
? GPUResourceManager::GetSampler_LinearClamp()
|
||||
: GPUResourceManager::GetSampler_LinearRepeat()};
|
||||
SDL_BindGPUFragmentSamplers(s_activeRenderPass, 0, &textureBinding, 1);
|
||||
SDL_PushGPUFragmentUniformData(s_activeCommandBuffer, 0, &s_fragmentUniform, sizeof(s_fragmentUniform));
|
||||
|
||||
SDL_GPUBufferBinding bufferBindings[] = {{.buffer = t.GeometryHandle->VertexBuffer, .offset = 0},
|
||||
{.buffer = t.GeometryHandle->IndexBuffer, .offset = 0}};
|
||||
SDL_BindGPUVertexBuffers(s_activeRenderPass, 0, bufferBindings, 1);
|
||||
SDL_BindGPUIndexBuffer(s_activeRenderPass, &bufferBindings[1], SDL_GPU_INDEXELEMENTSIZE_32BIT);
|
||||
SDL_DrawGPUIndexedPrimitives(s_activeRenderPass, t.GeometryHandle->IndexCount, 1, 0, 0, 0);
|
||||
}
|
||||
SDL_SetGPUScissor(s_activeRenderPass, &t.DrawState.Scissor);
|
||||
|
||||
SDL_EndGPURenderPass(s_activeRenderPass);
|
||||
|
||||
DebugDraw::Render();
|
||||
const auto imDrawData = ImGui::GetDrawData();
|
||||
ImGui_ImplSDLGPU3_PrepareDrawData(imDrawData, s_activeCommandBuffer);
|
||||
s_colorTargetInfo.load_op = SDL_GPU_LOADOP_CLEAR;
|
||||
s_colorTargetInfo.clear_color = SDL_FColor{0.0f, 0.0f, 0.0f, 0.0f};
|
||||
s_colorTargetInfo.texture = s_renderTargetDebugDrawColor;
|
||||
s_activeRenderPass = SDL_BeginGPURenderPass(s_activeCommandBuffer, &s_colorTargetInfo, 1, nullptr);
|
||||
ImGui_ImplSDLGPU3_RenderDrawData(imDrawData, s_activeCommandBuffer, s_activeRenderPass);
|
||||
SDL_EndGPURenderPass(s_activeRenderPass);
|
||||
|
||||
SDL_GPUTexture *swapChainTexture{};
|
||||
if (!SDL_WaitAndAcquireGPUSwapchainTexture(s_activeCommandBuffer, g_windowHandle, &swapChainTexture,
|
||||
(PUINT32) &s_screenWidth, (PUINT32) &s_screenHeight))
|
||||
THROW_UNKNOWN("Failed to acquire SDL GPU Swapchain texture: ", SDL_GetError());
|
||||
|
||||
if (!swapChainTexture)
|
||||
return;
|
||||
|
||||
s_colorTargetInfo.clear_color = SDL_FColor{1.0f, 1.0f, 1.0f, 1.0f};
|
||||
s_colorTargetInfo.load_op = SDL_GPU_LOADOP_CLEAR;
|
||||
s_colorTargetInfo.texture = swapChainTexture;
|
||||
|
||||
s_activeRenderPass = SDL_BeginGPURenderPass(s_activeCommandBuffer, &s_colorTargetInfo, 1, nullptr);
|
||||
SDL_BindGPUGraphicsPipeline(s_activeRenderPass, s_postprocessPipeline->GetHandle());
|
||||
SDL_GPUTextureSamplerBinding textureBindings[2] = {
|
||||
{.texture = s_renderTargetSceneColor, .sampler = GPUResourceManager::GetSampler_LinearClamp()},
|
||||
{.texture = s_renderTargetDebugDrawColor, .sampler = GPUResourceManager::GetSampler_LinearClamp()},
|
||||
};
|
||||
SDL_BindGPUFragmentSamplers(s_activeRenderPass, 0, textureBindings, 2);
|
||||
SDL_DrawGPUPrimitives(s_activeRenderPass, 6, 1, 0, 0);
|
||||
SDL_EndGPURenderPass(s_activeRenderPass);
|
||||
|
||||
SDL_SubmitGPUCommandBuffer(s_activeCommandBuffer);
|
||||
SDL_GPUBufferBinding bufferBindings[] = {{.buffer = t.GeometryHandle->VertexBuffer, .offset = 0},
|
||||
{.buffer = t.GeometryHandle->IndexBuffer, .offset = 0}};
|
||||
SDL_BindGPUVertexBuffers(s_activeRenderPass, 0, bufferBindings, 1);
|
||||
SDL_BindGPUIndexBuffer(s_activeRenderPass, &bufferBindings[1], SDL_GPU_INDEXELEMENTSIZE_32BIT);
|
||||
SDL_DrawGPUIndexedPrimitives(s_activeRenderPass, t.GeometryHandle->IndexCount, 1, 0, 0, 0);
|
||||
}
|
||||
|
||||
VOID Renderer::OnScreenResize(IN INT32 newWidth, IN INT32 newHeight)
|
||||
@ -378,38 +353,21 @@ namespace ia::iae
|
||||
s_screenWidth = newWidth;
|
||||
s_screenHeight = newHeight;
|
||||
|
||||
if (s_renderTargetSceneColor)
|
||||
GPUResourceManager::DestroyTexture(s_renderTargetSceneColor);
|
||||
if (s_renderTargetDebugDrawColor)
|
||||
GPUResourceManager::DestroyTexture(s_renderTargetDebugDrawColor);
|
||||
s_defaultScissor = {0, 0, newWidth, newHeight};
|
||||
|
||||
s_renderTargetSceneColor = GPUResourceManager::CreateTexture(
|
||||
SDL_GPU_TEXTUREUSAGE_COLOR_TARGET | SDL_GPU_TEXTUREUSAGE_SAMPLER, s_screenWidth, s_screenHeight, nullptr,
|
||||
SDL_GetGPUSwapchainTextureFormat(s_gpuDevice, g_windowHandle));
|
||||
s_renderTargetDebugDrawColor = GPUResourceManager::CreateTexture(
|
||||
SDL_GPU_TEXTUREUSAGE_COLOR_TARGET | SDL_GPU_TEXTUREUSAGE_SAMPLER, s_screenWidth, s_screenHeight, nullptr,
|
||||
SDL_GetGPUSwapchainTextureFormat(s_gpuDevice, g_windowHandle));
|
||||
|
||||
s_scissor = {0, 0, newWidth, newHeight};
|
||||
|
||||
s_activeViewport.x = 0;
|
||||
s_activeViewport.y = 0;
|
||||
s_activeViewport.w = newWidth;
|
||||
s_activeViewport.h = newHeight;
|
||||
s_activeViewport.min_depth = 0.0f;
|
||||
s_activeViewport.max_depth = 1.0f;
|
||||
s_defaultViewport.x = 0;
|
||||
s_defaultViewport.y = 0;
|
||||
s_defaultViewport.w = newWidth;
|
||||
s_defaultViewport.h = newHeight;
|
||||
s_defaultViewport.min_depth = 0.0f;
|
||||
s_defaultViewport.max_depth = 1.0f;
|
||||
|
||||
if (s_activeCamera)
|
||||
s_activeCamera->SetViewport(newWidth, newHeight);
|
||||
|
||||
const auto activeScene = WorldManager::GetActiveScene();
|
||||
if (activeScene)
|
||||
{
|
||||
const auto sceneViewport = activeScene->Viewport();
|
||||
s_sceneScaleFactor = {(FLOAT32) newWidth / (FLOAT32) sceneViewport.x,
|
||||
(FLOAT32) newHeight / (FLOAT32) sceneViewport.y};
|
||||
IAE_LOG_INFO("Updated Scene Scale Factor: (", s_sceneScaleFactor.x, ", ", s_sceneScaleFactor.y, ")");
|
||||
}
|
||||
g_sceneScalingFactor = {(FLOAT32) newWidth / g_sceneDesignViewport.x,
|
||||
(FLOAT32) newHeight / g_sceneDesignViewport.y};
|
||||
IAE_LOG_INFO("Updated Scene Scale Factor: (", g_sceneScalingFactor.x, ", ", g_sceneScalingFactor.y, ")");
|
||||
}
|
||||
|
||||
SDL_GPUTextureFormat Renderer::GetRenderTargetFormat()
|
||||
@ -436,36 +394,38 @@ namespace ia::iae
|
||||
delete handle;
|
||||
}
|
||||
|
||||
VOID Renderer::DrawGeometry(IN Geometry *handle, IN UINT8 layer, IN UINT16 sortIndex)
|
||||
VOID Renderer::DrawGeometry(IN Geometry *handle, IN SDL_GPUTexture *texture, IN Vec2 position, IN Vec2 scale,
|
||||
IN FLOAT32 rotation, IN UINT8 layer, IN UINT16 sortIndex)
|
||||
{
|
||||
const auto t = (UINT16) (sortIndex + ((UINT16) s_state.PositionY * s_state.YSortingEnabled));
|
||||
s_state.ActiveTexture = texture;
|
||||
s_state.Position = position;
|
||||
s_state.Rotation = rotation;
|
||||
s_state.Scale = scale;
|
||||
s_drawEntries.pushBack(
|
||||
DrawEntry{.Layer = layer, .SortIndex = t, .DrawState = s_state, .GeometryHandle = handle});
|
||||
DrawEntry{.Layer = layer,
|
||||
.SortIndex = (UINT16) (sortIndex + ((UINT16) s_state.Position.y * s_ySortingEnabled)),
|
||||
.DrawState = s_state,
|
||||
.GeometryHandle = handle});
|
||||
}
|
||||
|
||||
VOID Renderer::DrawText(IN CONST String &text, IN Vec2 position, IN FLOAT32 scale, IN FLOAT32 rotation,
|
||||
IN UINT8 layer, IN UINT16 sortIndex)
|
||||
{
|
||||
const auto t = (UINT16) (sortIndex + ((UINT16) s_state.Position.y * s_ySortingEnabled));
|
||||
const auto &font = FontManager::GetFont("Roboto");
|
||||
const auto t = (UINT16) (sortIndex + ((UINT16) s_state.PositionY * s_state.YSortingEnabled));
|
||||
Vec3 p{};
|
||||
Vec3 s{};
|
||||
for (const auto &c : text)
|
||||
{
|
||||
if (!c)
|
||||
break;
|
||||
|
||||
const auto glyph = font.Chars[(UINT8) c];
|
||||
|
||||
p = Vec3(position.x, position.y, 0.0f) +
|
||||
Vec3(glyph.Bearing.x, glyph.Size.y - glyph.Bearing.y, 0.0f) * scale;
|
||||
p.y += (16 - glyph.Size.y) * scale;
|
||||
s = Vec3(scale * glyph.Size.x, scale * glyph.Size.y, 1.0f);
|
||||
|
||||
s_state.ActiveTexture = glyph.Texture;
|
||||
s_state.PositionY = position.y;
|
||||
s_state.ModelMatrix = glm::translate(glm::mat4(1.0f), p);
|
||||
s_state.ModelMatrix = glm::rotate(s_state.ModelMatrix, rotation, glm::vec3(0.0f, 0.0f, 1.0f));
|
||||
s_state.ModelMatrix = glm::scale(s_state.ModelMatrix, s);
|
||||
s_state.Position = position + Vec2(glyph.Bearing.x, glyph.Size.y - glyph.Bearing.y) * scale;
|
||||
s_state.Position.y += (16 - glyph.Size.y) * scale;
|
||||
s_state.Rotation = rotation;
|
||||
s_state.Scale = Vec2(scale * glyph.Size.x, scale * glyph.Size.y);
|
||||
|
||||
s_drawEntries.pushBack(
|
||||
DrawEntry{.Layer = layer, .SortIndex = t, .DrawState = s_state, .GeometryHandle = s_quadGeometry});
|
||||
|
||||
@ -502,11 +462,6 @@ namespace ia::iae
|
||||
return Renderer::s_activeCamera;
|
||||
}
|
||||
|
||||
Vec2 Engine::GetRendererScalingFactor()
|
||||
{
|
||||
return Renderer::s_sceneScaleFactor;
|
||||
}
|
||||
|
||||
Handle Engine::CreateGeometry(IN CONST Vector<GeometryVertex> &vertices, IN CONST Vector<INT32> &indices)
|
||||
{
|
||||
return (Handle) Renderer::CreateGeometry(vertices, indices);
|
||||
@ -517,9 +472,11 @@ namespace ia::iae
|
||||
Renderer::DestroyGeometry((Renderer::Geometry *) geometry);
|
||||
}
|
||||
|
||||
VOID Engine::DrawGeometry(IN Handle handle, IN UINT8 layer, IN UINT16 sortIndex)
|
||||
VOID Engine::DrawGeometry(IN Handle handle, IN Handle texture, IN Vec2 position, IN Vec2 scale, IN FLOAT32 rotation,
|
||||
IN UINT8 layer, IN UINT16 sortIndex)
|
||||
{
|
||||
Renderer::DrawGeometry((Renderer::Geometry *) handle, layer, sortIndex);
|
||||
Renderer::DrawGeometry((Renderer::Geometry *) handle, ResourceManager::GetTextureFromImage(texture), position,
|
||||
scale, rotation, layer, sortIndex);
|
||||
}
|
||||
|
||||
VOID Engine::DrawText(IN CONST String &text, IN Vec2 position, IN FLOAT32 scale, IN FLOAT32 rotation,
|
||||
@ -528,10 +485,24 @@ namespace ia::iae
|
||||
Renderer::DrawText(text, position, scale, rotation, layer, sortIndex);
|
||||
}
|
||||
|
||||
VOID Engine::DrawQuad(IN Vec2 position, IN Handle texture, IN Vec2 scale, IN FLOAT32 rotation, IN UINT8 layer,
|
||||
IN UINT16 sortIndex)
|
||||
{
|
||||
Renderer::DrawGeometry(Renderer::s_quadGeometry, ResourceManager::GetTextureFromImage(texture), position, scale,
|
||||
rotation, layer, sortIndex);
|
||||
}
|
||||
|
||||
VOID Engine::DrawCircle(IN Vec2 position, IN Handle texture, IN FLOAT32 radius, IN FLOAT32 rotation, IN UINT8 layer,
|
||||
IN UINT16 sortIndex)
|
||||
{
|
||||
Renderer::DrawGeometry(Renderer::s_circleGeometry, ResourceManager::GetTextureFromImage(texture), position,
|
||||
{radius, radius}, rotation, layer, sortIndex);
|
||||
}
|
||||
|
||||
VOID Engine::SetRenderState_Scissor(IN IVec4 rect)
|
||||
{
|
||||
Renderer::s_scissor = rect.z ? SDL_Rect{0, 0, Renderer::s_screenWidth, Renderer::s_screenHeight}
|
||||
: SDL_Rect{rect.x, rect.y, rect.z, rect.w};
|
||||
Renderer::s_state.Scissor = rect.z ? SDL_Rect{0, 0, Renderer::s_screenWidth, Renderer::s_screenHeight}
|
||||
: SDL_Rect{rect.x, rect.y, rect.z, rect.w};
|
||||
}
|
||||
|
||||
VOID Engine::SetRenderState_FlippedH(IN BOOL value)
|
||||
@ -559,35 +530,9 @@ namespace ia::iae
|
||||
Renderer::s_state.CameraRelative = value;
|
||||
}
|
||||
|
||||
VOID Engine::SetRenderState_Texture(IN Handle image)
|
||||
{
|
||||
Renderer::s_state.ActiveTexture = ResourceManager::GetTextureFromImage(image);
|
||||
}
|
||||
|
||||
VOID Engine::SetRenderState_Transform(IN Vec2 position, IN Vec2 scale, IN FLOAT32 rotation)
|
||||
{
|
||||
position *= Renderer::s_sceneScaleFactor;
|
||||
scale *= Renderer::s_sceneScaleFactor;
|
||||
|
||||
Renderer::s_state.PositionY = position.y;
|
||||
|
||||
Renderer::s_state.ModelMatrix = glm::translate(glm::mat4(1.0f), glm::vec3{position.x, position.y, 0});
|
||||
Renderer::s_state.ModelMatrix =
|
||||
glm::rotate(Renderer::s_state.ModelMatrix, rotation, glm::vec3(0.0f, 0.0f, 1.0f));
|
||||
Renderer::s_state.ModelMatrix = glm::scale(Renderer::s_state.ModelMatrix, glm::vec3{scale.x, scale.y, 1.0f});
|
||||
}
|
||||
|
||||
VOID Engine::SetRenderState_TransformUI(IN Vec2 position, IN Vec2 scale, IN FLOAT32 rotation)
|
||||
{
|
||||
Renderer::s_state.ModelMatrix = glm::translate(glm::mat4(1.0f), glm::vec3{position.x, position.y, 0});
|
||||
Renderer::s_state.ModelMatrix =
|
||||
glm::rotate(Renderer::s_state.ModelMatrix, rotation, glm::vec3(0.0f, 0.0f, 1.0f));
|
||||
Renderer::s_state.ModelMatrix = glm::scale(Renderer::s_state.ModelMatrix, glm::vec3{scale.x, scale.y, 1.0f});
|
||||
}
|
||||
|
||||
VOID Engine::SetRenderState_YSortingEnabled(IN BOOL value)
|
||||
{
|
||||
Renderer::s_state.YSortingEnabled = value;
|
||||
Renderer::s_ySortingEnabled = value;
|
||||
}
|
||||
|
||||
Handle Engine::GetGeometry_Quad()
|
||||
|
||||
Reference in New Issue
Block a user