summaryrefslogtreecommitdiffhomepage
diff options
context:
space:
mode:
-rw-r--r--CMakeLists.txt1
-rw-r--r--include/compile_flags.txt5
-rw-r--r--src/.clangd13
-rw-r--r--src/compile_flags.txt2
-rw-r--r--src/rmlui/irodeo_rmlui.h0
-rw-r--r--src/rmlui/irodeo_rmlui.hpp66
-rw-r--r--src/rmlui/irodeo_rmlui_t.h0
-rw-r--r--src/rmlui/rodeo_rmlui.cpp180
8 files changed, 266 insertions, 1 deletions
diff --git a/CMakeLists.txt b/CMakeLists.txt
index 11a5003..3e3b533 100644
--- a/CMakeLists.txt
+++ b/CMakeLists.txt
@@ -19,6 +19,7 @@ add_library(${PROJECT_NAME}
"src/math/rodeo_vec3.c"
"src/math/rodeo_mat4.c"
"src/math/rodeo_rng.c"
+ "src/rmlui/rodeo_rmlui.cpp"
)
set_property(TARGET RodeoKit PROPERTY C_STANDARD 99)
diff --git a/include/compile_flags.txt b/include/compile_flags.txt
index 668f22f..c9801a7 100644
--- a/include/compile_flags.txt
+++ b/include/compile_flags.txt
@@ -1,10 +1,14 @@
-I./
-I../include
-I../external/SDL/include
+-I../external/SDL_image
+-I../external/SDL_mixer/include
-I../external/bgfx/include
-I../external/bx/include
-I../external/cglm/include
-I../external/STC/include
+-I../external/RmlUi/Include
+-DSDL_VIDEO_DRIVER_X11=ON
-Wall
-Wextra
-Wpedantic
@@ -19,3 +23,4 @@
-Wnested-externs
-Wmissing-include-dirs
-std=c99
+
diff --git a/src/.clangd b/src/.clangd
new file mode 100644
index 0000000..5b9dfec
--- /dev/null
+++ b/src/.clangd
@@ -0,0 +1,13 @@
+If:
+ PathMatch: .*\.cpp
+
+CompileFlags:
+ Add: [-std=c++14]
+
+---
+
+If:
+ PathMatch: .*\.c
+
+CompileFlags:
+ Add: [-std=c99]
diff --git a/src/compile_flags.txt b/src/compile_flags.txt
index 7a756f9..7bc47aa 100644
--- a/src/compile_flags.txt
+++ b/src/compile_flags.txt
@@ -7,6 +7,7 @@
-I../external/bx/include
-I../external/cglm/include
-I../external/STC/include
+-I../external/RmlUi/Include
-DSDL_VIDEO_DRIVER_X11=ON
-Wall
-Wextra
@@ -21,5 +22,4 @@
-Wredundant-decls
-Wnested-externs
-Wmissing-include-dirs
--std=c99
diff --git a/src/rmlui/irodeo_rmlui.h b/src/rmlui/irodeo_rmlui.h
new file mode 100644
index 0000000..e69de29
--- /dev/null
+++ b/src/rmlui/irodeo_rmlui.h
diff --git a/src/rmlui/irodeo_rmlui.hpp b/src/rmlui/irodeo_rmlui.hpp
new file mode 100644
index 0000000..66573b0
--- /dev/null
+++ b/src/rmlui/irodeo_rmlui.hpp
@@ -0,0 +1,66 @@
+#pragma once
+
+#define RMLUI_STATIC_LIB
+
+// -- external --
+#include <RmlUi/Core/RenderInterface.h>
+#include <RmlUi/Core/Types.h>
+
+class RenderInterface_Rodeo : public Rml::RenderInterface {
+ public:
+
+ bool is_projecting = false;
+
+ RenderInterface_Rodeo();
+ ~RenderInterface_Rodeo();
+
+ // The viewport should be updated whenever the window size changes.
+ void SetViewport(int viewport_width, int viewport_height);
+
+ // Sets up OpenGL states for taking rendering commands from RmlUi.
+ void BeginFrame();
+ void EndFrame();
+
+ // -- Inherited from Rml::RenderInterface --
+
+ void RenderGeometry(
+ Rml::Vertex* vertices,
+ int num_vertices,
+ int* indices,
+ int num_indices,
+ Rml::TextureHandle texture,
+ const Rml::Vector2f& translation
+ ) override;
+
+ void EnableScissorRegion(bool enable) override;
+ void SetScissorRegion(int x, int y, int width, int height) override;
+
+ bool LoadTexture(
+ Rml::TextureHandle& texture_handle,
+ Rml::Vector2i& texture_dimensions,
+ const Rml::String& source
+ ) override;
+ bool GenerateTexture(
+ Rml::TextureHandle& texture_handle,
+ const Rml::byte* source,
+ const Rml::Vector2i& source_dimensions
+ ) override;
+ void ReleaseTexture(Rml::TextureHandle texture_handle) override;
+
+ void SetTransform(const Rml::Matrix4f* transform) override;
+
+ // Can be passed to RenderGeometry() to enable texture rendering without changing the bound texture.
+ static const Rml::TextureHandle TextureEnableWithoutBinding = Rml::TextureHandle(-1);
+
+ private:
+ //Rml::Matrix4f transform, projection;
+ //ProgramId transform_dirty_state = ProgramId::All;
+ //bool transform_active = false;
+
+ //enum class ScissoringState { Disable, Scissor, Stencil };
+ //ScissoringState scissoring_state = ScissoringState::Disable;
+
+ int viewport_width = 0;
+ int viewport_height = 0;
+
+};
diff --git a/src/rmlui/irodeo_rmlui_t.h b/src/rmlui/irodeo_rmlui_t.h
new file mode 100644
index 0000000..e69de29
--- /dev/null
+++ b/src/rmlui/irodeo_rmlui_t.h
diff --git a/src/rmlui/rodeo_rmlui.cpp b/src/rmlui/rodeo_rmlui.cpp
new file mode 100644
index 0000000..c9f872a
--- /dev/null
+++ b/src/rmlui/rodeo_rmlui.cpp
@@ -0,0 +1,180 @@
+
+#define RMLUI_STATIC_LIB
+
+// -- internal --
+// public
+#include "rodeo/gfx.h"
+// private
+#include "rmlui/irodeo_rmlui.hpp"
+
+// -- external --
+#include "RmlUi/Core/Core.h"
+#include "RmlUi/Core/FileInterface.h"
+#include "RmlUi/Core/Log.h"
+#include "RmlUi/Core/Platform.h"
+
+
+
+RenderInterface_Rodeo::RenderInterface_Rodeo()
+{
+}
+
+RenderInterface_Rodeo::~RenderInterface_Rodeo()
+{
+}
+
+void RenderInterface_Rodeo::SetViewport(int width, int height)
+{
+ viewport_width = width;
+ viewport_height = height;
+}
+
+void RenderInterface_Rodeo::BeginFrame()
+{
+ SetViewport((int)rodeo_gfx_width_get(), (int)rodeo_gfx_height_get());
+ rodeo_gfx_renderer_flush();
+ rodeo_gfx_matrix_push();
+}
+
+void RenderInterface_Rodeo::EndFrame()
+{
+ //if(is_projecting)
+ //{
+ // rlMatrixMode(RL_PROJECTION);
+ // rlPopMatrix();
+ // rlMatrixMode(RL_MODELVIEW);
+ // is_projecting = false;
+ //}
+ rodeo_gfx_renderer_flush();
+ rodeo_gfx_matrix_pop();
+ rodeo_gfx_scissor_end();
+}
+
+void RenderInterface_Rodeo::RenderGeometry(
+ Rml::Vertex* vertices,
+ int num_vertices, // ignore?
+ int* indices,
+ int num_indices,
+ const Rml::TextureHandle texture,
+ const Rml::Vector2f& translation
+ )
+{
+ unsigned int textureId = 0;
+ if(texture != NULL)
+ {
+ textureId = texture;
+ }
+
+ rlBegin(RL_TRIANGLES);
+ rlSetTexture(textureId);
+ rlPushMatrix();
+ rlTranslatef(translation.x, translation.y, 0);
+
+ for (unsigned int i = 0; i <= (num_indices - 3); i += 3)
+ {
+ if(rlCheckRenderBatchLimit(3))
+ {
+ rlBegin(RL_TRIANGLES);
+ rlSetTexture(textureId);
+ }
+
+ int indexA = indices[i];
+ int indexB = indices[i + 1];
+ int indexC = indices[i + 2];
+
+ Rml::Vertex vertexA = vertices[indexA];
+ Rml::Vertex vertexB = vertices[indexB];
+ Rml::Vertex vertexC = vertices[indexC];
+
+ RenderInterface_Rodeo::RodeoTriangleVert(vertexA);
+ RenderInterface_Rodeo::RodeoTriangleVert(vertexB);
+ RenderInterface_Rodeo::RodeoTriangleVert(vertexC);
+ }
+
+
+ rlPopMatrix();
+ rlDrawRenderBatchActive();
+ rlEnd();
+}
+
+
+void RenderInterface_Rodeo::EnableScissorRegion(bool enable)
+{
+ if(enable)
+ {
+ // do nothing
+ }
+ else
+ {
+ rodeo_gfx_scissor_end();
+ }
+}
+
+void RenderInterface_Rodeo::SetScissorRegion(int x, int y, int width, int height)
+{
+ rodeo_gfx_scissor_begin(
+ { (float)x, (float)y, (float)width, (float)height }
+ );
+ //rlScissor(x, viewport_height - (y + height), width, height);
+}
+
+
+bool RenderInterface_Rodeo::LoadTexture(Rml::TextureHandle& texture_handle, Rml::Vector2i& texture_dimensions, const Rml::String& source)
+{
+ rodeo_gfx_texture_2d_t texture = rodeo_gfx_texture_2d_create_from_path(cstr_from(source.c_str()));
+
+ texture_dimensions.x = (int)texture.width;
+ texture_dimensions.y = (int)texture.height;
+ texture_handle = (Rml::TextureHandle) texture.data;
+
+ return true;
+}
+
+bool RenderInterface_Rodeo::GenerateTexture(Rml::TextureHandle& texture_handle, const Rml::byte* source, const Rml::Vector2i& source_dimensions)
+{
+ rodeo_gfx_texture_2d_t texture = rodeo_gfx_texture_2d_create_from_RGBA8(
+ (uint16_t)source_dimensions.x,
+ (uint16_t)source_dimensions.y,
+ source
+ );
+ //Image image = GenImageColor(source_dimensions.x, source_dimensions.y, BLANK);
+ //Texture texture = LoadTextureFromImage(image);
+
+ texture_handle = (Rml::TextureHandle)texture.data;
+
+ return true;
+}
+
+void RenderInterface_Rodeo::ReleaseTexture(Rml::TextureHandle texture_handle)
+{
+ rodeo_gfx_texture_2d_destroy({ (irodeo_gfx_texture_2d_t*)texture_handle, 0, 0 });
+}
+
+void RenderInterface_Rodeo::SetTransform(const Rml::Matrix4f* new_transform)
+{
+ if(new_transform != nullptr)
+ {
+ //if(!is_projecting)
+ //{
+ // rlMatrixMode(RL_PROJECTION);
+ // rlPushMatrix();
+ // rlLoadIdentity();
+ // rlFrustum(0.0, viewport_width, 0.0, viewport_height, -100.0, 100.0);
+ // rlMatrixMode(RL_MODELVIEW);
+ // is_projecting = true;
+ //}
+ //rlLoadIdentity();
+
+ rodeo_math_mat4_t matrix;
+ memcpy(matrix.raw, new_transform->data(), sizeof(matrix));
+ rodeo_gfx_matrix_set(matrix);
+
+ //rlScalef(1.0,1.0,0.001);
+ //rlTranslatef(0.0,0.0,100.0);
+ }
+ else
+ {
+ rodeo_gfx_matrix_pop();
+ rodeo_gfx_matrix_push();
+ }
+}