mipmaps
This commit is contained in:
@ -74,6 +74,8 @@ namespace ia::iae
|
||||
Physics::Initialize();
|
||||
|
||||
Game_OnInitialize();
|
||||
|
||||
Engine::ResizeDisplay(config->ScreenWidth, config->ScreenHeight);
|
||||
}
|
||||
|
||||
VOID __Internal_Engine::Terminate()
|
||||
|
||||
@ -36,6 +36,9 @@ namespace ia::iae
|
||||
|
||||
g_linearClampSampler = SDL_CreateGPUSampler(Renderer::GetDevice(), &createInfo);
|
||||
|
||||
createInfo.min_filter = SDL_GPU_FILTER_NEAREST;
|
||||
createInfo.mag_filter = SDL_GPU_FILTER_NEAREST;
|
||||
createInfo.mipmap_mode = SDL_GPU_SAMPLERMIPMAPMODE_LINEAR;
|
||||
createInfo.address_mode_u = SDL_GPU_SAMPLERADDRESSMODE_REPEAT,
|
||||
createInfo.address_mode_v = SDL_GPU_SAMPLERADDRESSMODE_REPEAT,
|
||||
createInfo.address_mode_w = SDL_GPU_SAMPLERADDRESSMODE_REPEAT,
|
||||
@ -62,15 +65,19 @@ namespace ia::iae
|
||||
|
||||
SDL_GPUTexture *GPUResourceManager::CreateTexture(IN SDL_GPUTextureUsageFlags usage, IN INT32 width,
|
||||
IN INT32 height, IN PCUINT8 rgbaData,
|
||||
IN SDL_GPUTextureFormat format)
|
||||
IN SDL_GPUTextureFormat format, IN BOOL generateMipmaps)
|
||||
{
|
||||
const auto mipLevels = generateMipmaps ? floor(log2(ia_max(width, height))) + 1 : 1;
|
||||
|
||||
STATIC Vector<UINT8> TMP_COLOR_BUFFER;
|
||||
|
||||
SDL_GPUTextureCreateInfo createInfo{.type = SDL_GPU_TEXTURETYPE_2D,
|
||||
.format = format,
|
||||
.usage = usage,
|
||||
.width = (UINT32) width,
|
||||
.height = (UINT32) height,
|
||||
.layer_count_or_depth = 1,
|
||||
.num_levels = 1,
|
||||
.num_levels = (UINT32) mipLevels,
|
||||
.sample_count = SDL_GPU_SAMPLECOUNT_1};
|
||||
const auto result = SDL_CreateGPUTexture(Renderer::GetDevice(), &createInfo);
|
||||
if (!result)
|
||||
@ -80,14 +87,25 @@ namespace ia::iae
|
||||
}
|
||||
if (rgbaData)
|
||||
{
|
||||
TMP_COLOR_BUFFER.reset();
|
||||
TMP_COLOR_BUFFER.resize(width * height * 4);
|
||||
for (SIZE_T i = 0; i < TMP_COLOR_BUFFER.size() >> 2; i++)
|
||||
{
|
||||
const auto a = static_cast<FLOAT32>(rgbaData[i * 4 + 3]) / 255.0f;
|
||||
TMP_COLOR_BUFFER[i * 4 + 0] = static_cast<UINT8>(rgbaData[i * 4 + 0] * a);
|
||||
TMP_COLOR_BUFFER[i * 4 + 1] = static_cast<UINT8>(rgbaData[i * 4 + 1] * a);
|
||||
TMP_COLOR_BUFFER[i * 4 + 2] = static_cast<UINT8>(rgbaData[i * 4 + 2] * a);
|
||||
TMP_COLOR_BUFFER[i * 4 + 3] = rgbaData[i * 4 + 3];
|
||||
}
|
||||
|
||||
SDL_GPUTransferBufferCreateInfo stagingBufferCreateInfo{.usage = SDL_GPU_TRANSFERBUFFERUSAGE_UPLOAD,
|
||||
.size = (UINT32) width * (UINT32) height * 4};
|
||||
const auto stagingBuffer = SDL_CreateGPUTransferBuffer(Renderer::GetDevice(), &stagingBufferCreateInfo);
|
||||
const auto mappedPtr = SDL_MapGPUTransferBuffer(Renderer::GetDevice(), stagingBuffer, false);
|
||||
SDL_memcpy(mappedPtr, rgbaData, width * height * 4);
|
||||
SDL_memcpy(mappedPtr, TMP_COLOR_BUFFER.data(), width * height * 4);
|
||||
SDL_UnmapGPUTransferBuffer(Renderer::GetDevice(), stagingBuffer);
|
||||
|
||||
const auto cmdBuffer = SDL_AcquireGPUCommandBuffer(Renderer::GetDevice());
|
||||
auto cmdBuffer = SDL_AcquireGPUCommandBuffer(Renderer::GetDevice());
|
||||
const auto copyPass = SDL_BeginGPUCopyPass(cmdBuffer);
|
||||
|
||||
SDL_GPUTextureTransferInfo transferInfo{.transfer_buffer = stagingBuffer, .offset = 0};
|
||||
@ -98,6 +116,14 @@ namespace ia::iae
|
||||
SDL_SubmitGPUCommandBuffer(cmdBuffer);
|
||||
SDL_WaitForGPUIdle(Renderer::GetDevice());
|
||||
SDL_ReleaseGPUTransferBuffer(Renderer::GetDevice(), stagingBuffer);
|
||||
|
||||
if (mipLevels > 1)
|
||||
{
|
||||
cmdBuffer = SDL_AcquireGPUCommandBuffer(Renderer::GetDevice());
|
||||
SDL_GenerateMipmapsForGPUTexture(cmdBuffer, result);
|
||||
SDL_SubmitGPUCommandBuffer(cmdBuffer);
|
||||
SDL_WaitForGPUIdle(Renderer::GetDevice());
|
||||
}
|
||||
}
|
||||
return result;
|
||||
}
|
||||
@ -138,7 +164,8 @@ namespace ia::iae
|
||||
|
||||
VOID GPUResourceManager::DestroyTexture(IN SDL_GPUTexture *handle)
|
||||
{
|
||||
if(!handle) return;
|
||||
if (!handle)
|
||||
return;
|
||||
SDL_ReleaseGPUTexture(Renderer::GetDevice(), handle);
|
||||
}
|
||||
|
||||
@ -175,8 +202,8 @@ namespace ia::iae
|
||||
return result;
|
||||
}
|
||||
|
||||
SDL_GPUTexture* GPUResourceManager::CombineTextures(IN SDL_GPUTexture** textures, IN INT32 unitWidth, IN INT32 unitHeight,
|
||||
IN INT32 unitCountX, IN INT32 unitCountY)
|
||||
SDL_GPUTexture *GPUResourceManager::CombineTextures(IN SDL_GPUTexture **textures, IN INT32 unitWidth,
|
||||
IN INT32 unitHeight, IN INT32 unitCountX, IN INT32 unitCountY)
|
||||
{
|
||||
SDL_GPUTextureCreateInfo createInfo{.type = SDL_GPU_TEXTURETYPE_2D,
|
||||
.format = SDL_GPU_TEXTUREFORMAT_R8G8B8A8_UNORM,
|
||||
@ -198,7 +225,8 @@ namespace ia::iae
|
||||
for (INT32 x = 0; x < unitCountX; x++)
|
||||
{
|
||||
SDL_GPUTextureLocation src{.texture = textures[x + (y * unitCountX)], .x = 0, .y = 0};
|
||||
SDL_GPUTextureLocation dst{.texture = result, .x = (UINT32)(x * unitWidth), .y = (UINT32)(y * unitHeight)};
|
||||
SDL_GPUTextureLocation dst{
|
||||
.texture = result, .x = (UINT32) (x * unitWidth), .y = (UINT32) (y * unitHeight)};
|
||||
SDL_CopyGPUTextureToTexture(copyPass, &src, &dst, unitWidth, unitHeight, 1, false);
|
||||
}
|
||||
}
|
||||
|
||||
@ -51,7 +51,14 @@ namespace ia::iae
|
||||
|
||||
SDL_GPUColorTargetDescription colorTargetDesc = {
|
||||
.format = Renderer::GetRenderTargetFormat(),
|
||||
};
|
||||
.blend_state = {.src_color_blendfactor = SDL_GPU_BLENDFACTOR_ONE,
|
||||
.dst_color_blendfactor = SDL_GPU_BLENDFACTOR_ONE_MINUS_SRC_ALPHA,
|
||||
.color_blend_op = SDL_GPU_BLENDOP_ADD,
|
||||
.src_alpha_blendfactor = SDL_GPU_BLENDFACTOR_ONE,
|
||||
.dst_alpha_blendfactor = SDL_GPU_BLENDFACTOR_ONE_MINUS_SRC_ALPHA,
|
||||
.alpha_blend_op = SDL_GPU_BLENDOP_ADD,
|
||||
.enable_blend = true,
|
||||
.enable_color_write_mask = false}};
|
||||
|
||||
SDL_GPUVertexBufferDescription vertexBufferDesc = {
|
||||
.slot = 0,
|
||||
@ -85,16 +92,15 @@ namespace ia::iae
|
||||
.front_face = SDL_GPU_FRONTFACE_COUNTER_CLOCKWISE},
|
||||
.depth_stencil_state = SDL_GPUDepthStencilState{.compare_op = SDL_GPU_COMPAREOP_GREATER_OR_EQUAL,
|
||||
.write_mask = 0xFF,
|
||||
.enable_depth_test = enableDepthTest,
|
||||
.enable_depth_write = enableDepthTest,
|
||||
.enable_depth_test = false,
|
||||
.enable_depth_write = false,
|
||||
.enable_stencil_test = false},
|
||||
.target_info = {.color_target_descriptions = &colorTargetDesc,
|
||||
.num_color_targets = 1,
|
||||
.depth_stencil_format = SDL_GPU_TEXTUREFORMAT_D16_UNORM,
|
||||
.has_depth_stencil_target = enableDepthTest},
|
||||
.has_depth_stencil_target = false},
|
||||
};
|
||||
|
||||
if(!(m_handle = SDL_CreateGPUGraphicsPipeline(Renderer::GetDevice(), &createInfo)))
|
||||
if (!(m_handle = SDL_CreateGPUGraphicsPipeline(Renderer::GetDevice(), &createInfo)))
|
||||
THROW_UNKNOWN("Failed to create a SDL graphics pipeline: ", SDL_GetError());
|
||||
|
||||
SDL_ReleaseGPUShader(Renderer::GetDevice(), pixelShader);
|
||||
|
||||
@ -145,8 +145,8 @@ namespace ia::iae
|
||||
s_state.ColorTargetInfo.clear_color = SDL_FColor{clearColor.x, clearColor.y, clearColor.z, 1.0f};
|
||||
s_state.ColorTargetInfo.texture = s_renderTargetSceneColor;
|
||||
s_state.DepthStencilTargetInfo.texture = s_renderTargetSceneDepth;
|
||||
s_state.ActiveRenderPass = SDL_BeginGPURenderPass(s_state.ActiveCommandBuffer, &s_state.ColorTargetInfo, 1,
|
||||
&s_state.DepthStencilTargetInfo);
|
||||
s_state.ActiveRenderPass =
|
||||
SDL_BeginGPURenderPass(s_state.ActiveCommandBuffer, &s_state.ColorTargetInfo, 1, nullptr);
|
||||
|
||||
SDL_BindGPUGraphicsPipeline(s_state.ActiveRenderPass, s_geometryPipeline->GetHandle());
|
||||
SDL_PushGPUVertexUniformData(
|
||||
@ -185,8 +185,8 @@ namespace ia::iae
|
||||
SDL_BeginGPURenderPass(s_state.ActiveCommandBuffer, &s_state.ColorTargetInfo, 1, nullptr);
|
||||
SDL_BindGPUGraphicsPipeline(s_state.ActiveRenderPass, s_postprocessPipeline->GetHandle());
|
||||
SDL_GPUTextureSamplerBinding textureBindings[2] = {
|
||||
{.texture = s_renderTargetSceneColor, .sampler = GPUResourceManager::GetSampler_LinearRepeat()},
|
||||
{.texture = s_renderTargetDebugDrawColor, .sampler = GPUResourceManager::GetSampler_LinearRepeat()},
|
||||
{.texture = s_renderTargetSceneColor, .sampler = GPUResourceManager::GetSampler_LinearClamp()},
|
||||
{.texture = s_renderTargetDebugDrawColor, .sampler = GPUResourceManager::GetSampler_LinearClamp()},
|
||||
};
|
||||
SDL_BindGPUFragmentSamplers(s_state.ActiveRenderPass, 0, textureBindings, 2);
|
||||
SDL_DrawGPUPrimitives(s_state.ActiveRenderPass, 6, 1, 0, 0);
|
||||
@ -287,8 +287,11 @@ namespace ia::iae
|
||||
s_fragmentUniform.FlippedH = s_state.FlippedH;
|
||||
s_fragmentUniform.FlippedV = s_state.FlippedV;
|
||||
s_fragmentUniform.TextureOffset = s_state.TextureOffset;
|
||||
SDL_GPUTextureSamplerBinding textureBinding{.texture = s_state.ActiveTexture,
|
||||
.sampler = ((s_state.TextureOffset.x <= FLOAT32_EPSILON) && (s_state.TextureOffset.y <= FLOAT32_EPSILON)) ? GPUResourceManager::GetSampler_LinearClamp() : GPUResourceManager::GetSampler_LinearRepeat()};
|
||||
SDL_GPUTextureSamplerBinding textureBinding{
|
||||
.texture = s_state.ActiveTexture,
|
||||
.sampler = ((s_state.TextureOffset.x <= FLOAT32_EPSILON) && (s_state.TextureOffset.y <= FLOAT32_EPSILON))
|
||||
? GPUResourceManager::GetSampler_LinearClamp()
|
||||
: GPUResourceManager::GetSampler_LinearRepeat()};
|
||||
SDL_BindGPUFragmentSamplers(s_state.ActiveRenderPass, 0, &textureBinding, 1);
|
||||
SDL_PushGPUFragmentUniformData(s_state.ActiveCommandBuffer, 0, &s_fragmentUniform, sizeof(s_fragmentUniform));
|
||||
|
||||
@ -404,6 +407,19 @@ namespace ia::iae
|
||||
sizeof(Mat4));
|
||||
}
|
||||
|
||||
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,
|
||||
static_cast<FLOAT32>(0xFF << 13)});
|
||||
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});
|
||||
|
||||
SDL_PushGPUVertexUniformData(Renderer::s_state.ActiveCommandBuffer, 2, &Renderer::s_state.ModelMatrix,
|
||||
sizeof(Mat4));
|
||||
}
|
||||
|
||||
VOID Engine::SetRenderState_YSortingEnabled(IN BOOL value)
|
||||
{
|
||||
Renderer::s_state.YSortingEnabled = value;
|
||||
|
||||
@ -61,8 +61,8 @@ namespace ia::iae
|
||||
|
||||
Handle ResourceManager::CreateImage(IN CONST String &name, IN PCUINT8 rgbaData, IN INT32 width, IN INT32 height)
|
||||
{
|
||||
const auto texture = GPUResourceManager::CreateTexture(SDL_GPU_TEXTUREUSAGE_SAMPLER, width, height, rgbaData,
|
||||
SDL_GPU_TEXTUREFORMAT_R8G8B8A8_UNORM);
|
||||
const auto texture = GPUResourceManager::CreateTexture(SDL_GPU_TEXTUREUSAGE_SAMPLER | SDL_GPU_TEXTUREUSAGE_COLOR_TARGET, width, height, rgbaData,
|
||||
SDL_GPU_TEXTUREFORMAT_R8G8B8A8_UNORM, true);
|
||||
s_imageHandles.pushBack(ImageResource{.OriginalWidth = width,
|
||||
.OriginalHeight = height,
|
||||
.OriginalPixelData = new UINT8[width * height * 4],
|
||||
@ -153,8 +153,8 @@ namespace ia::iae
|
||||
stbir_resize_uint8_linear(s_imageHandles[image].OriginalPixelData, s_imageHandles[image].OriginalWidth,
|
||||
s_imageHandles[image].OriginalHeight, s_imageHandles[image].OriginalWidth * 4,
|
||||
nullptr, newWidth, newHeight, newWidth * 4, stbir_pixel_layout::STBIR_RGBA);
|
||||
const auto texture = GPUResourceManager::CreateTexture(SDL_GPU_TEXTUREUSAGE_SAMPLER, newWidth, newHeight,
|
||||
newPixelData, SDL_GPU_TEXTUREFORMAT_R8G8B8A8_UNORM);
|
||||
const auto texture = GPUResourceManager::CreateTexture(SDL_GPU_TEXTUREUSAGE_SAMPLER | SDL_GPU_TEXTUREUSAGE_COLOR_TARGET, newWidth, newHeight,
|
||||
newPixelData, SDL_GPU_TEXTUREFORMAT_R8G8B8A8_UNORM, true);
|
||||
GPUResourceManager::DestroyTexture(s_imageHandles[image].Handle);
|
||||
s_imageHandles[image].Handle = texture;
|
||||
s_imageHandles[image].Width = newWidth;
|
||||
|
||||
@ -30,6 +30,9 @@ namespace ia::iae
|
||||
BOOL g_debuggerEnabled{false};
|
||||
Rml::ElementDocument *g_document{};
|
||||
|
||||
String g_markup;
|
||||
Rml::SharedPtr<Rml::StyleSheetContainer> g_styleSheetContainer;
|
||||
|
||||
class RmlUIRenderInterface : public Rml::RenderInterface
|
||||
{
|
||||
public:
|
||||
@ -445,6 +448,7 @@ namespace ia::iae
|
||||
|
||||
VOID UI::OnScreenResize(IN INT32 newWidth, IN INT32 newHeight)
|
||||
{
|
||||
//g_context->SetDimensions(Rml::Vector2i{newWidth, newHeight});
|
||||
}
|
||||
|
||||
VOID UI::AddFontFromFile(IN CONST String &path)
|
||||
@ -454,9 +458,10 @@ namespace ia::iae
|
||||
|
||||
VOID UI::SetMarkup(IN CONST String &markup, IN CONST String &styles)
|
||||
{
|
||||
g_document->SetStyleSheetContainer(Rml::Factory::InstanceStyleSheetString(styles.c_str()));
|
||||
g_document->SetInnerRML(
|
||||
BuildString("<body style=\"display: block; width: 100%; height: 100%;\">", markup, "</body>").c_str());
|
||||
g_styleSheetContainer = Rml::Factory::InstanceStyleSheetString(styles.c_str());
|
||||
g_markup = BuildString("<body style=\"display: block; width: 100vw; height: 100vh;\">", markup, "</body>");
|
||||
//g_document->SetStyleSheetContainer(g_styleSheetContainer);
|
||||
//g_document->SetInnerRML(g_markup.c_str());
|
||||
}
|
||||
|
||||
VOID UI::AddClickEvent(IN PCCHAR elementId, IN std::function<VOID()> callback)
|
||||
@ -491,7 +496,7 @@ namespace ia::iae
|
||||
Engine::SetRenderState_ColorOverlay({255, 255, 255, 255});
|
||||
Engine::SetRenderState_TextureOffset({0, 0});
|
||||
Engine::SetRenderState_CameraRelative(false);
|
||||
Engine::SetRenderState_Transform({translation.x, translation.y}, {1.0f, 1.0f}, 0, 0xFF, 0);
|
||||
Engine::SetRenderState_TransformUI({translation.x, translation.y}, {1.0f, 1.0f}, 0);
|
||||
|
||||
Engine::DrawGeometry((Handle) geometry);
|
||||
}
|
||||
|
||||
File diff suppressed because one or more lines are too long
@ -30,7 +30,7 @@ namespace ia::iae
|
||||
STATIC SDL_GPUSampler *GetSampler_LinearClamp();
|
||||
STATIC SDL_GPUSampler *GetSampler_LinearRepeat();
|
||||
|
||||
STATIC SDL_GPUTexture *CreateTexture(IN SDL_GPUTextureUsageFlags usage, IN INT32 width, IN INT32 height, IN PCUINT8 rgbaData = nullptr, IN SDL_GPUTextureFormat format = SDL_GPU_TEXTUREFORMAT_R8G8B8A8_UNORM);
|
||||
STATIC SDL_GPUTexture *CreateTexture(IN SDL_GPUTextureUsageFlags usage, IN INT32 width, IN INT32 height, IN PCUINT8 rgbaData = nullptr, IN SDL_GPUTextureFormat format = SDL_GPU_TEXTUREFORMAT_R8G8B8A8_UNORM, IN BOOL generateMipmaps = false);
|
||||
STATIC SDL_GPUBuffer *CreateDeviceLocalBuffer(IN SDL_GPUBufferUsageFlags usage, IN PCVOID data, IN UINT32 dataSize);
|
||||
STATIC VOID DestroyTexture(IN SDL_GPUTexture *handle);
|
||||
STATIC VOID DestroyBuffer(IN SDL_GPUBuffer *handle);
|
||||
|
||||
@ -61,6 +61,7 @@ namespace ia::iae
|
||||
STATIC VOID SetRenderState_Texture(IN Handle image);
|
||||
STATIC VOID SetRenderState_Transform(IN Vec2 position, IN Vec2 scale, IN FLOAT32 rotation, IN UINT8 layer,
|
||||
IN INT16 sortIndex);
|
||||
STATIC VOID SetRenderState_TransformUI(IN Vec2 position, IN Vec2 scale, IN FLOAT32 rotation);
|
||||
STATIC Vec2 GetRendererScalingFactor();
|
||||
|
||||
// Debug Draw Functions
|
||||
|
||||
Reference in New Issue
Block a user