diff options
| -rw-r--r-- | include/rodeo/gfx.h | 6 | ||||
| -rw-r--r-- | include/rodeo/rmlui.h | 37 | ||||
| -rw-r--r-- | include/rodeo/rmlui_t.h | 9 | ||||
| -rw-r--r-- | include/rodeo/window.h | 3 | ||||
| -rw-r--r-- | src/gfx/rodeo_gfx.c | 6 | ||||
| -rw-r--r-- | src/rmlui/irodeo_rmlui.hpp | 66 | ||||
| -rw-r--r-- | src/rmlui/irodeo_rmlui_t.h | 11 | ||||
| -rw-r--r-- | src/rmlui/irodeo_rmlui_t.hpp | 86 | ||||
| -rw-r--r-- | src/rmlui/rodeo_rmlui.cpp | 213 | ||||
| -rw-r--r-- | src/window/rodeo_window.c | 6 |
10 files changed, 344 insertions, 99 deletions
diff --git a/include/rodeo/gfx.h b/include/rodeo/gfx.h index 07d8430..34f8d94 100644 --- a/include/rodeo/gfx.h +++ b/include/rodeo/gfx.h @@ -74,6 +74,9 @@ rodeo_gfx_vertex_maxSize(void); void rodeo_gfx_index_add(rodeo_gfx_index_t index); +uint16_t +rodeo_gfx_index_size(void); + rodeo_gfx_index_t rodeo_gfx_index_count_get(void); @@ -84,6 +87,9 @@ uint16_t rodeo_gfx_index_maxSize(void); void +rodeo_gfx_texture_set(rodeo_gfx_texture_2d_t texture); + +void rodeo_gfx_texture_2d_draw( const rodeo_rectangle_t destination, const rodeo_rectangle_t source, diff --git a/include/rodeo/rmlui.h b/include/rodeo/rmlui.h new file mode 100644 index 0000000..665fcea --- /dev/null +++ b/include/rodeo/rmlui.h @@ -0,0 +1,37 @@ +#pragma once + +// -- internal -- +// public +#include "rodeo/rmlui_t.h" + +// external +#include "stc/cstr.h" + + +void +rodeo_rmlui_init(void); + +void +rodeo_rmlui_deinit(void); + +void +rodeo_rmlui_font_load(cstr path); + +rodeo_rmlui_document_t +rodeo_rmlui_document_load(cstr path); + +void +rodeo_rmlui_document_show(rodeo_rmlui_document_t document); + +void +rodeo_rmlui_update(void); + +void +rodeo_rmlui_render(void); + +#define \ +mrodeo_rmlui_do() \ + mrodeo_defer_do( \ + rodeo_rmlui_init(), \ + rodeo_rmlui_deinit() \ + ) diff --git a/include/rodeo/rmlui_t.h b/include/rodeo/rmlui_t.h new file mode 100644 index 0000000..007e0ff --- /dev/null +++ b/include/rodeo/rmlui_t.h @@ -0,0 +1,9 @@ +#pragma once + +typedef struct irodeo_rmlui_document_data rodeo_rmlui_document_data_t; +typedef +struct +{ + rodeo_rmlui_document_data_t *data; +} +rodeo_rmlui_document_t; diff --git a/include/rodeo/window.h b/include/rodeo/window.h index df73b4f..37c39b5 100644 --- a/include/rodeo/window.h +++ b/include/rodeo/window.h @@ -33,6 +33,9 @@ rodeo_window_shouldQuit(void); void rodeo_window_quit(void); +uint64_t +rodeo_window_elapsedTime_ms(void); + #define \ mrodeo_window_do( \ screen_width, \ diff --git a/src/gfx/rodeo_gfx.c b/src/gfx/rodeo_gfx.c index f922675..3da9a7e 100644 --- a/src/gfx/rodeo_gfx.c +++ b/src/gfx/rodeo_gfx.c @@ -591,6 +591,12 @@ rodeo_gfx_index_add(rodeo_gfx_index_t index) } } +uint16_t +rodeo_gfx_index_size(void) +{ + return irodeo_gfx_state.index_size; +} + rodeo_gfx_index_t rodeo_gfx_index_count_get(void) { diff --git a/src/rmlui/irodeo_rmlui.hpp b/src/rmlui/irodeo_rmlui.hpp index 66573b0..dee6786 100644 --- a/src/rmlui/irodeo_rmlui.hpp +++ b/src/rmlui/irodeo_rmlui.hpp @@ -1,66 +1,8 @@ #pragma once -#define RMLUI_STATIC_LIB +#include "rmlui/irodeo_rmlui_t.hpp" -// -- external -- -#include <RmlUi/Core/RenderInterface.h> -#include <RmlUi/Core/Types.h> +//// -- 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 index e69de29..d318b0e 100644 --- a/src/rmlui/irodeo_rmlui_t.h +++ b/src/rmlui/irodeo_rmlui_t.h @@ -0,0 +1,11 @@ +#pragma once + +typedef struct icpprodeo_rmlui_state icpprodeo_rmlui_state_t; + +typedef +struct +{ + icpprodeo_rmlui_state_t *cpp; +} +irodeo_rmlui_state_t; + diff --git a/src/rmlui/irodeo_rmlui_t.hpp b/src/rmlui/irodeo_rmlui_t.hpp new file mode 100644 index 0000000..43bdebe --- /dev/null +++ b/src/rmlui/irodeo_rmlui_t.hpp @@ -0,0 +1,86 @@ +#pragma once + +// internal + +// external +#include "RmlUi/Core.h" +#include "RmlUi/Core/Platform.h" +#include "RmlUi/Core/RenderInterface.h" +#include "RmlUi/Core/SystemInterface.h" + +class SystemInterface_Rodeo : public Rml::SystemInterface { +public: + double GetElapsedTime() override; +}; + +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; + +}; + +struct +icpprodeo_rmlui_state +{ + RenderInterface_Rodeo render_interface; + SystemInterface_Rodeo system_interface; + Rml::Context *default_context; +}; + +struct irodeo_rmlui_document_data +{ + Rml::ElementDocument *document; +}; diff --git a/src/rmlui/rodeo_rmlui.cpp b/src/rmlui/rodeo_rmlui.cpp index c9f872a..704fb25 100644 --- a/src/rmlui/rodeo_rmlui.cpp +++ b/src/rmlui/rodeo_rmlui.cpp @@ -1,19 +1,113 @@ - -#define RMLUI_STATIC_LIB - +// // -- internal -- +// private +#include "rmlui/irodeo_rmlui.hpp" // must be first to prevent issues // public -#include "rodeo/gfx.h" +extern "C" { + #include "rodeo/rmlui.h" + #include "rodeo/gfx.h" + #include "rodeo/window.h" + #include "rodeo.h" +} // private -#include "rmlui/irodeo_rmlui.hpp" +extern "C" { + #include "gfx/irodeo_gfx.h" + #include "rmlui/irodeo_rmlui_t.h" +} + // -- external -- +extern "C" { + #include "stc/cstr.h" +} #include "RmlUi/Core/Core.h" #include "RmlUi/Core/FileInterface.h" #include "RmlUi/Core/Log.h" #include "RmlUi/Core/Platform.h" +static irodeo_rmlui_state_t irodeo_rmlui_state = {}; + +extern "C" { + + void + rodeo_rmlui_init(void) + { + irodeo_rmlui_state.cpp = (icpprodeo_rmlui_state_t*)malloc(sizeof(*irodeo_rmlui_state.cpp)); + Rml::SetRenderInterface(&irodeo_rmlui_state.cpp->render_interface); + Rml::SetSystemInterface(&irodeo_rmlui_state.cpp->system_interface); + + Rml::Initialise(); + + irodeo_rmlui_state.cpp->default_context = Rml::CreateContext( + "default", + Rml::Vector2i((int32_t)rodeo_gfx_width_get(), (int32_t)rodeo_gfx_height_get()) + ); + if(!irodeo_rmlui_state.cpp->default_context) + { + rodeo_log( + rodeo_logLevel_error, + "Failed to initialise RmlUi" + ); + return; + } + } + + void + rodeo_rmlui_deinit(void) + { + Rml::Shutdown(); + free(irodeo_rmlui_state.cpp); + } + + void + rodeo_rmlui_font_load(cstr path) + { + Rml::LoadFontFace(cstr_str(&path)); + } + + rodeo_rmlui_document_t + rodeo_rmlui_document_load(cstr path) + { + rodeo_rmlui_document_t doc; + doc.data = (irodeo_rmlui_document_data*)malloc(sizeof(*doc.data)); + doc.data->document = irodeo_rmlui_state.cpp->default_context->LoadDocument(Rml::String("assets/demo.html")); + if(!doc.data->document) + { + rodeo_log( + rodeo_logLevel_error, + "Failed to load RmlUi Document" + ); + return {}; + } + return doc; + } + + void + rodeo_rmlui_document_show(rodeo_rmlui_document_t document) + { + document.data->document->Show(); + } + + void + rodeo_rmlui_update(void) + { + irodeo_rmlui_state.cpp->default_context->Update(); + } + + void + rodeo_rmlui_render(void) + { + irodeo_rmlui_state.cpp->default_context->Render(); + } + +} +// interface implementation + +double SystemInterface_Rodeo::GetElapsedTime() +{ + return (double)rodeo_window_elapsedTime_ms() / 1000.0; +} RenderInterface_Rodeo::RenderInterface_Rodeo() { @@ -59,42 +153,85 @@ void RenderInterface_Rodeo::RenderGeometry( const Rml::Vector2f& translation ) { - unsigned int textureId = 0; - if(texture != NULL) + if( + rodeo_gfx_vertex_maxSize() > rodeo_gfx_vertex_size() + num_vertices + || + rodeo_gfx_index_maxSize() > rodeo_gfx_index_size() + num_indices + ) { - textureId = texture; + rodeo_gfx_renderer_flush(); } + for(int32_t i = 0; i < num_vertices; ++i) + { + rodeo_gfx_vertex_t vert = {}; + rodeo_color_RGBA8_t color = {}; - rlBegin(RL_TRIANGLES); - rlSetTexture(textureId); - rlPushMatrix(); - rlTranslatef(translation.x, translation.y, 0); + vert.x = vertices[i].position.x; + vert.y = vertices[i].position.y; - for (unsigned int i = 0; i <= (num_indices - 3); i += 3) - { - if(rlCheckRenderBatchLimit(3)) + color.colors.alpha = vertices[i].colour.alpha; + color.colors.red = vertices[i].colour.red; + color.colors.green = vertices[i].colour.green; + color.colors.blue = vertices[i].colour.blue; + vert.color = rodeo_color_RGBA8_to_RGBAFloat(color); + + vert.texture_x = vertices[i].tex_coord.x; + vert.texture_y = vertices[i].tex_coord.y; + + if(NULL == (rodeo_gfx_texture_2d_t*)texture) { - rlBegin(RL_TRIANGLES); - rlSetTexture(textureId); + vert.texture_id = 0; + } + else + { + rodeo_gfx_texture_set(*(rodeo_gfx_texture_2d_t*)texture); + vert.texture_id = 1; } - 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]; + rodeo_gfx_vertex_add(vert); + } - RenderInterface_Rodeo::RodeoTriangleVert(vertexA); - RenderInterface_Rodeo::RodeoTriangleVert(vertexB); - RenderInterface_Rodeo::RodeoTriangleVert(vertexC); + for(int32_t i = 0; i < num_indices; ++i) + { + rodeo_gfx_index_add(rodeo_gfx_index_count_get() + (uint16_t)indices[i]); } + rodeo_gfx_index_count_increment((uint16_t)num_indices); + + //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(); + //rlPopMatrix(); + //rlDrawRenderBatchActive(); + //rlEnd(); } @@ -121,18 +258,20 @@ void RenderInterface_Rodeo::SetScissorRegion(int x, int y, int width, int 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())); + rodeo_gfx_texture_2d_t *texture = (rodeo_gfx_texture_2d_t*)malloc(sizeof(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; + texture_dimensions.x = (int)texture->width; + texture_dimensions.y = (int)texture->height; + texture_handle = (Rml::TextureHandle)texture; 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( + rodeo_gfx_texture_2d_t *texture = (rodeo_gfx_texture_2d_t*)malloc(sizeof(rodeo_gfx_texture_2d_t)); + *texture = rodeo_gfx_texture_2d_create_from_RGBA8( (uint16_t)source_dimensions.x, (uint16_t)source_dimensions.y, source @@ -140,14 +279,14 @@ bool RenderInterface_Rodeo::GenerateTexture(Rml::TextureHandle& texture_handle, //Image image = GenImageColor(source_dimensions.x, source_dimensions.y, BLANK); //Texture texture = LoadTextureFromImage(image); - texture_handle = (Rml::TextureHandle)texture.data; + texture_handle = (Rml::TextureHandle)texture; return true; } void RenderInterface_Rodeo::ReleaseTexture(Rml::TextureHandle texture_handle) { - rodeo_gfx_texture_2d_destroy({ (irodeo_gfx_texture_2d_t*)texture_handle, 0, 0 }); + rodeo_gfx_texture_2d_destroy(*(rodeo_gfx_texture_2d_t*)texture_handle); } void RenderInterface_Rodeo::SetTransform(const Rml::Matrix4f* new_transform) diff --git a/src/window/rodeo_window.c b/src/window/rodeo_window.c index 0c7899e..83dcbc6 100644 --- a/src/window/rodeo_window.c +++ b/src/window/rodeo_window.c @@ -142,6 +142,12 @@ rodeo_window_quit(void) irodeo_window_state.quit = true; } +uint64_t +rodeo_window_elapsedTime_ms(void) +{ + return SDL_GetTicks64(); +} + SDL_Window * irodeo_window_get(void) { |
