summaryrefslogtreecommitdiffstats
path: root/src/Rml.cpp
diff options
context:
space:
mode:
authorLaG1924 <lag1924@gmail.com>2021-11-14 12:23:15 +0100
committerLaG1924 <lag1924@gmail.com>2021-11-14 12:23:15 +0100
commit5651b71788487e986ea945d76cbaf647d4554813 (patch)
treeefec4c9a455dd4911bbeefd9f8c593e36ee97973 /src/Rml.cpp
parentAdded basic Graphics Abstraction Layer (diff)
downloadAltCraft-5651b71788487e986ea945d76cbaf647d4554813.tar
AltCraft-5651b71788487e986ea945d76cbaf647d4554813.tar.gz
AltCraft-5651b71788487e986ea945d76cbaf647d4554813.tar.bz2
AltCraft-5651b71788487e986ea945d76cbaf647d4554813.tar.lz
AltCraft-5651b71788487e986ea945d76cbaf647d4554813.tar.xz
AltCraft-5651b71788487e986ea945d76cbaf647d4554813.tar.zst
AltCraft-5651b71788487e986ea945d76cbaf647d4554813.zip
Diffstat (limited to 'src/Rml.cpp')
-rw-r--r--src/Rml.cpp32
1 files changed, 14 insertions, 18 deletions
diff --git a/src/Rml.cpp b/src/Rml.cpp
index 4e28529..4f5c0b9 100644
--- a/src/Rml.cpp
+++ b/src/Rml.cpp
@@ -45,7 +45,7 @@ void RmlSystemInterface::GetClipboardText(Rml::String& text) {
text = clipboard;
}
-RmlRenderInterface::RmlRenderInterface(RenderState& renderState) : State(&renderState) {
+RmlRenderInterface::RmlRenderInterface(RenderState& renderState) {
auto gal = Gal::GetImplementation();
auto pipelineConfig = gal->CreatePipelineConfig();
pipelineConfig->AddShaderParameter("viewportSize", Gal::Type::Vec2u32);
@@ -117,15 +117,15 @@ void RmlRenderInterface::RenderGeometry(Rml::Vertex* vertices, int num_vertices,
vertexBuffer->SetData({ reinterpret_cast<std::byte*>(vertices), reinterpret_cast<std::byte*>(vertices + num_vertices) });
glCheckError();
-
- if (texture) {
+ auto tex = textures.find(texture);
+ if (tex != textures.end()) {
texPipeline->Activate();
glCheckError();
texPipeline->SetShaderParameter("translation", glm::vec2(translation.x, translation.y));
glCheckError();
- texPipelineInstance->Activate();
+ texPipeline->SetDynamicTexture("fontTexture", tex->second);
glCheckError();
- glBindTexture(GL_TEXTURE_2D, texture);
+ texPipelineInstance->Activate();
glCheckError();
texPipelineInstance->Render(0, num_indices);
} else {
@@ -157,21 +157,16 @@ bool RmlRenderInterface::LoadTexture(Rml::TextureHandle& texture_handle, Rml::Ve
}
bool RmlRenderInterface::GenerateTexture(Rml::TextureHandle& texture_handle, const Rml::byte* source, const Rml::Vector2i& source_dimensions) {
- int mipLevelCount = 1;
- glActiveTexture(GL_TEXTURE0);
- GLuint texture;
- glGenTextures(1, &texture);
- glBindTexture(GL_TEXTURE_2D, texture);
- 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);
glCheckError();
-
- glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA8, source_dimensions.x, source_dimensions.y, 0, GL_RGBA, GL_UNSIGNED_INT_8_8_8_8_REV, source);
+ size_t textureId = textures.empty() ? 1 : textures.rbegin()->first + 1;
+ auto gal = Gal::GetImplementation();
+ auto textureConfig = gal->CreateTexture2DConfig(source_dimensions.x, source_dimensions.y, Gal::Format::R8G8B8A8);
+ auto texture = gal->BuildTexture(textureConfig);
+ texture->SetData({ reinterpret_cast<const std::byte*>(source),reinterpret_cast<const std::byte*>(source + (source_dimensions.x * source_dimensions.y) * 4) });
+ textures.insert({ textureId,texture });
+ texture_handle = textureId;
glCheckError();
- texture_handle = texture;
return true;
}
@@ -185,11 +180,12 @@ void RmlRenderInterface::Update(unsigned int windowWidth, unsigned int windowHei
glCheckError();
-
pipeline->SetShaderParameter("viewportSize", glm::uvec2(windowWidth, windowHeight));
texPipeline->SetShaderParameter("viewportSize", glm::uvec2(windowWidth, windowHeight));
texPipeline->SetShaderParameter("fontTexture", 0);
+ glCheckError();
+
vpWidth = windowWidth;
vpHeight = windowHeight;
}