Too much changes
This commit is contained in:
@@ -1,7 +1,7 @@
|
||||
#include <cstdint>
|
||||
#include <cmath>
|
||||
#include <cassert>
|
||||
#include "utils/logger.h"
|
||||
#include "utils/maths.h"
|
||||
#include "render/ui.h"
|
||||
#include "render/vertexbuffer.h"
|
||||
#include "render/indexbuffer.h"
|
||||
@@ -12,35 +12,37 @@
|
||||
|
||||
struct DrawInfo
|
||||
{
|
||||
uint16_t vxcount;
|
||||
uint16_t idxcount;
|
||||
uint16 vxcount;
|
||||
uint16 idxcount;
|
||||
};
|
||||
|
||||
struct UIGlobals {
|
||||
VertexBuffer* vb;
|
||||
IndexBuffer* ib;
|
||||
Shader* shader;
|
||||
Texture2D* activetexture = nullptr;
|
||||
Texture2D* defaultTexture = nullptr;
|
||||
Texture2D* activetexture;
|
||||
Texture2D* defaultTexture;
|
||||
|
||||
UIVertex* vertices = nullptr;
|
||||
uint16_t* indices = nullptr;
|
||||
UIVertex* vertices;
|
||||
uint16* indices;
|
||||
DrawInfo drawInfo[MAX_UI_VERTICES];
|
||||
uint16_t count = 0;
|
||||
uint16_t position = 0;
|
||||
uint16_t Indexposition = 0;
|
||||
uint16_t currentIdx = 0;
|
||||
uint16 count;
|
||||
uint16 position;
|
||||
uint16 Indexposition;
|
||||
uint16 currentIdx;
|
||||
} g_ui;
|
||||
|
||||
|
||||
void uiInit()
|
||||
{
|
||||
memset( &g_ui, 0, sizeof(g_ui) );
|
||||
|
||||
//////////////////////////////////////////////////////////////////////////
|
||||
// Buffer and context state
|
||||
|
||||
// Buffer creation
|
||||
g_ui.vb = g_renderDevice->CreateVertexBuffer(nullptr, MAX_UI_VERTICES, true);
|
||||
g_ui.ib = g_renderDevice->CreateIndexBuffer(nullptr, MAX_UI_INDICES, true);
|
||||
g_ui.vb = g_renderDevice->CreateVertexBuffer(NULL, MAX_UI_VERTICES, true);
|
||||
g_ui.ib = g_renderDevice->CreateIndexBuffer(NULL, MAX_UI_INDICES, true);
|
||||
|
||||
// Create shader
|
||||
|
||||
@@ -51,7 +53,7 @@ void uiInit()
|
||||
{ VERTEXATTR_VEC4, SHADERSEMANTIC_COLOR },
|
||||
};
|
||||
|
||||
g_ui.shader = g_shaderSystem->CreateShader("ui", "content/shaders/ui_base.vs", "content/shaders/ui_tex.ps", inputLayout, sizeof(inputLayout) / sizeof(inputLayout[0]));
|
||||
g_ui.shader = g_shaderSystem->CreateShader("ui", "shaders/ui_base.vs", "shaders/ui_tex.ps", inputLayout, sizeof(inputLayout) / sizeof(inputLayout[0]));
|
||||
g_ui.shader->m_stride = sizeof( UIVertex );
|
||||
|
||||
g_ui.defaultTexture = g_texturesManager->LoadTexture2D("$white$");
|
||||
@@ -61,6 +63,7 @@ void uiShutdown()
|
||||
{
|
||||
delete g_ui.ib;
|
||||
delete g_ui.vb;
|
||||
memset(&g_ui, 0, sizeof(g_ui));
|
||||
}
|
||||
|
||||
void uiDumpBuffers()
|
||||
@@ -91,7 +94,7 @@ void uiBeginRender()
|
||||
g_ui.vertices = (UIVertex*)g_ui.vb->MapBuffer(BA_WRITE_ONLY);
|
||||
assert(g_ui.vertices);
|
||||
|
||||
g_ui.indices = (uint16_t*)g_ui.ib->MapBuffer(BA_WRITE_ONLY);
|
||||
g_ui.indices = (uint16*)g_ui.ib->MapBuffer(BA_WRITE_ONLY);
|
||||
assert(g_ui.indices);
|
||||
}
|
||||
|
||||
@@ -113,10 +116,10 @@ void uiDrawQuad(const Vec2& a, const Vec2& b, const Vec2& c, const Vec2& d, cons
|
||||
g_ui.vertices[g_ui.position + 3].position = d; g_ui.vertices[g_ui.position + 3].color = color;
|
||||
|
||||
// texcoord
|
||||
g_ui.vertices[g_ui.position + 0].uv = Vec2{ 0.0f, 1.0f };
|
||||
g_ui.vertices[g_ui.position + 1].uv = Vec2{ 1.0f, 1.0f };
|
||||
g_ui.vertices[g_ui.position + 2].uv = Vec2{ 1.0f, 0.0f };
|
||||
g_ui.vertices[g_ui.position + 3].uv = Vec2{ 0.0f, 0.0f };
|
||||
g_ui.vertices[g_ui.position + 0].uv = Vec2( 0.0f, 1.0f );
|
||||
g_ui.vertices[g_ui.position + 1].uv = Vec2( 1.0f, 1.0f );
|
||||
g_ui.vertices[g_ui.position + 2].uv = Vec2( 1.0f, 0.0f );
|
||||
g_ui.vertices[g_ui.position + 3].uv = Vec2( 0.0f, 0.0f );
|
||||
|
||||
g_ui.currentIdx += 4;
|
||||
g_ui.Indexposition += 6;
|
||||
@@ -172,10 +175,10 @@ void uiDrawLines(const Vec2* drawPoints, const size_t pointsCount, bool closed,
|
||||
void uiDrawRect(const Vec2& position, const Vec2& size, const Vec4& color)
|
||||
{
|
||||
Vec2 quad[4];
|
||||
quad[0] = { position.x, position.y };
|
||||
quad[1] = { position.x + size.x, position.y };
|
||||
quad[2] = { position.x + size.x, position.y + size.y };
|
||||
quad[3] = { position.x, position.y + size.y };
|
||||
quad[0] = Vec2( position.x, position.y );
|
||||
quad[1] = Vec2( position.x + size.x, position.y );
|
||||
quad[2] = Vec2( position.x + size.x, position.y + size.y );
|
||||
quad[3] = Vec2( position.x, position.y + size.y );
|
||||
uiDrawQuad(quad[0], quad[1], quad[2], quad[3], color);
|
||||
}
|
||||
|
||||
@@ -191,8 +194,8 @@ void uiSetTextureByName(const char* filename)
|
||||
|
||||
void uiEndRender()
|
||||
{
|
||||
g_ui.indices = nullptr;
|
||||
g_ui.vertices = nullptr;
|
||||
g_ui.indices = NULL;
|
||||
g_ui.vertices = NULL;
|
||||
|
||||
g_ui.ib->UnmapBuffer();
|
||||
g_ui.vb->UnmapBuffer();
|
||||
@@ -215,7 +218,7 @@ void uiEndRender()
|
||||
{ (R + L) / (L - R), (T + B) / (B - T), 0.0f, 1.0f },
|
||||
};
|
||||
|
||||
if ( g_ui.activetexture == nullptr )
|
||||
if ( g_ui.activetexture == NULL )
|
||||
g_ui.activetexture = g_ui.defaultTexture;
|
||||
|
||||
g_texturesManager->SetTexture( 0, g_ui.activetexture );
|
||||
|
||||
Reference in New Issue
Block a user