diff options
Diffstat (limited to 'src/rmlui/rodeo_rmlui.cpp')
| -rw-r--r-- | src/rmlui/rodeo_rmlui.cpp | 213 |
1 files changed, 176 insertions, 37 deletions
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) |
