Too much changes
This commit is contained in:
@@ -235,7 +235,11 @@ void GL_Load()
|
||||
LogMsg("GL_VENDOR: %s", vendor_string);
|
||||
LogMsg("GL_RENDERER: %s", renderer_string);
|
||||
LogMsg("GL_VERSION: %s", version_string);
|
||||
LogMsg("GL_EXTENSIONS: %s", extensions_string);
|
||||
|
||||
if (strlen(extensions_string) >= 2048)
|
||||
LogMsg("GL_EXTENSIONS: cannot print, too long string");
|
||||
else
|
||||
LogMsg("GL_EXTENSIONS: %s", extensions_string);
|
||||
|
||||
// OpenGL 1.3
|
||||
LOAD_GL_FUNC( PFNGLACTIVETEXTUREPROC, glActiveTexture);
|
||||
|
||||
@@ -1,6 +1,9 @@
|
||||
#include "render/render.h"
|
||||
#include "render/renderdevice.h"
|
||||
#include "render/shadersystem.h"
|
||||
#include "render/gl_shared.h"
|
||||
#include "render/ui.h"
|
||||
#include "render/texturesmanager.h"
|
||||
#include "input/inputsystem.h"
|
||||
#include "utils/logger.h"
|
||||
|
||||
@@ -91,10 +94,29 @@ void R_Init()
|
||||
|
||||
// Create render device
|
||||
g_renderDevice = new RenderDevice();
|
||||
g_shaderSystem = new ShaderSystem();
|
||||
g_texturesManager = new TexturesManager();
|
||||
|
||||
// Initialize UI
|
||||
uiInit();
|
||||
}
|
||||
|
||||
void R_Shutdown()
|
||||
{
|
||||
uiShutdown();
|
||||
|
||||
if (g_texturesManager != NULL)
|
||||
{
|
||||
delete g_texturesManager;
|
||||
g_texturesManager = NULL;
|
||||
}
|
||||
|
||||
if (g_shaderSystem != NULL)
|
||||
{
|
||||
delete g_shaderSystem;
|
||||
g_shaderSystem = NULL;
|
||||
}
|
||||
|
||||
if (g_renderDevice != NULL)
|
||||
{
|
||||
delete g_renderDevice;
|
||||
@@ -104,6 +126,10 @@ void R_Shutdown()
|
||||
|
||||
void R_Present()
|
||||
{
|
||||
uiBeginRender();
|
||||
uiDrawRect( Vec2( 0.0f, 0.0f ), Vec2( 100.0f, 100.0f ), Vec4( 0.0f, 0.5f, 0.5f, 1.0f ) );
|
||||
uiEndRender();
|
||||
|
||||
GL_SwapBuffers(0);
|
||||
}
|
||||
|
||||
|
||||
@@ -1,7 +1,8 @@
|
||||
#ifndef RENDERTARGET_H
|
||||
#define RENDERTARGET_H
|
||||
|
||||
#include <stdint.h>
|
||||
#include <stdlib.h>
|
||||
#include "utils/maths.h"
|
||||
|
||||
class Texture2D;
|
||||
class RenderDevice;
|
||||
@@ -17,7 +18,7 @@ public:
|
||||
RenderTarget();
|
||||
~RenderTarget();
|
||||
|
||||
void Create(const char* name = nullptr);
|
||||
void Create(const char* name = NULL);
|
||||
void Destroy();
|
||||
|
||||
void Finialize();
|
||||
@@ -26,7 +27,7 @@ public:
|
||||
void AttachDepthTexture(Texture2D* texture);
|
||||
|
||||
private:
|
||||
uint32_t m_framebuffer;
|
||||
uint m_framebuffer;
|
||||
|
||||
};
|
||||
|
||||
|
||||
@@ -44,7 +44,7 @@ GLuint CreateShader(GLenum shaderType, const char* filename)
|
||||
}
|
||||
|
||||
Shader::Shader() :
|
||||
m_name(nullptr),
|
||||
m_name(NULL),
|
||||
m_stride(0),
|
||||
m_layout_count(0)
|
||||
{
|
||||
|
||||
@@ -1,7 +1,6 @@
|
||||
#ifndef SHADER_H
|
||||
#define SHADER_H
|
||||
|
||||
#include <stdint.h>
|
||||
#include "gl_shared.h"
|
||||
|
||||
const int SHADERUNIFORM_MAX_COUNT = 16;
|
||||
|
||||
@@ -24,7 +24,7 @@ static const char* g_samplersNameTable[SAMPLER_MAX] =
|
||||
"u_lightmapTexture",
|
||||
};
|
||||
|
||||
ShaderSystem* g_shaderSystem = nullptr;
|
||||
ShaderSystem* g_shaderSystem = NULL;
|
||||
|
||||
ShaderSystem::ShaderSystem()
|
||||
{
|
||||
@@ -48,7 +48,7 @@ void ShaderSystem::Shutdown()
|
||||
if (shaderData.shader)
|
||||
{
|
||||
delete shaderData.shader;
|
||||
shaderData.shader = nullptr;
|
||||
shaderData.shader = NULL;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -73,7 +73,9 @@ Shader* ShaderSystem::CreateShader(const char* name, const char* vsfilepath, con
|
||||
|
||||
pShader->Create( name, vsfilepath, psfilepath );
|
||||
|
||||
ShaderData shaderData = { name, pShader };
|
||||
ShaderData shaderData;
|
||||
shaderData.name = name;
|
||||
shaderData.shader = pShader;
|
||||
m_shaders.push_back(shaderData);
|
||||
|
||||
return pShader;
|
||||
|
||||
@@ -38,7 +38,7 @@ public:
|
||||
void Init();
|
||||
void Shutdown();
|
||||
|
||||
Shader* CreateShader(const char* name, const char* vsfilepath, const char* psfilepath, InputLayoutDesc_t* inputLayout = nullptr, int inputLayoutCount = 0);
|
||||
Shader* CreateShader(const char* name, const char* vsfilepath, const char* psfilepath, InputLayoutDesc_t* inputLayout = NULL, int inputLayoutCount = 0);
|
||||
|
||||
void SetShader(const Shader* shader);
|
||||
|
||||
|
||||
@@ -95,7 +95,7 @@ Texture2D* TexturesManager::CreateManual2D(const char* name, int width, int heig
|
||||
|
||||
// allocate
|
||||
Texture2D* texture = Texture2D::Create();
|
||||
texture->CreateRaw(nullptr, width, height, format);
|
||||
texture->CreateRaw(NULL, width, height, format);
|
||||
texture->m_textureFileName = name;
|
||||
|
||||
if (useAsRenderTarget)
|
||||
@@ -160,10 +160,10 @@ Texture2D* TexturesManager::LoadTexture2D(const char* texturename, bool useMipma
|
||||
std::string texnamebuf;
|
||||
|
||||
// find texture from disk
|
||||
for (int i = 0; i < kTexFileExtensionsSize; i++)
|
||||
for (int j = 0; j < kTexFileExtensionsSize; j++)
|
||||
{
|
||||
std::string textureFilename = fs::getFileNameWithoutExtension(texturename);
|
||||
textureFilename += g_texFileExtensions[i];
|
||||
textureFilename += g_texFileExtensions[j];
|
||||
|
||||
if (g_fileManager->FileExist(textureFilename.c_str()))
|
||||
{
|
||||
|
||||
@@ -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