#pragma once #pragma push_macro("byte") #pragma push_macro("GetNextSibling") #pragma push_macro("GetFirstChild") #undef byte #undef GetNextSibling #undef GetFirstChild #include #include #include #include // NOTE: pop_macro at end of file struct RmlD3D11Vertex { float position[2]; float texcoord[2]; unsigned char color[4]; }; class RenderInterface_D3D11 : public Rml::RenderInterface { public: RenderInterface_D3D11(ID3D11Device* device, ID3D11DeviceContext* context); virtual ~RenderInterface_D3D11(); bool IsInitialised() const { return m_initialised; } void BeginFrame(); void EndFrame(); void SetViewport(int width, int height); // Rml::RenderInterface Rml::CompiledGeometryHandle CompileGeometry(Rml::Span vertices, Rml::Span indices) override; void RenderGeometry(Rml::CompiledGeometryHandle geometry, Rml::Vector2f translation, Rml::TextureHandle texture) override; void ReleaseGeometry(Rml::CompiledGeometryHandle geometry) override; Rml::TextureHandle LoadTexture(Rml::Vector2i& texture_dimensions, const Rml::String& source) override; Rml::TextureHandle GenerateTexture(Rml::Span source_data, Rml::Vector2i source_dimensions) override; void ReleaseTexture(Rml::TextureHandle texture) override; void EnableScissorRegion(bool enable) override; void SetScissorRegion(Rml::Rectanglei region) override; void SetTransform(const Rml::Matrix4f* transform) override; private: struct CompiledGeometry { ID3D11Buffer* vertex_buffer; ID3D11Buffer* index_buffer; int num_indices; int num_vertices; int vertex_stride; int index_stride; DXGI_FORMAT index_format; }; struct TextureData { ID3D11ShaderResourceView* srv; int width; int height; }; bool CompileShaders(); bool CreateStateObjects(); // Draws geometry with the current shader/projection void DrawCompiledGeometry(CompiledGeometry* geom, const Rml::Vector2f& translation, ID3D11ShaderResourceView* texture_srv); ID3D11Device* m_device; ID3D11DeviceContext* m_context; bool m_initialised; // Shaders ID3D11VertexShader* m_vertex_shader; ID3D11PixelShader* m_pixel_shader_textured; ID3D11PixelShader* m_pixel_shader_color; ID3D11InputLayout* m_input_layout; // State objects ID3D11BlendState* m_blend_state; ID3D11DepthStencilState* m_depth_state; ID3D11RasterizerState* m_raster_state; ID3D11SamplerState* m_sampler_state; // Constant buffer for projection ID3D11Buffer* m_projection_cb; Rml::Matrix4f m_projection; Rml::Matrix4f m_transform; bool m_transform_active; // Scissor state bool m_scissor_enabled; D3D11_RECT m_scissor_rect; // White fallback texture for untextured geometry ID3D11ShaderResourceView* m_white_texture; // Viewport dimensions int m_width; int m_height; // Geometry handle counter Rml::CompiledGeometryHandle m_next_geometry_handle; std::vector m_geometry_lookup; // Texture handle counter Rml::TextureHandle m_next_texture_handle; std::vector m_texture_lookup; }; #pragma pop_macro("GetFirstChild") #pragma pop_macro("GetNextSibling") #pragma pop_macro("byte")