Too much changes

This commit is contained in:
2025-03-09 04:50:41 +03:00
parent e45d21b621
commit b1fb15fa1f
20 changed files with 255 additions and 44 deletions

View File

@@ -69,8 +69,7 @@ LINK32=link.exe
# PROP Ignore_Export_Lib 0 # PROP Ignore_Export_Lib 0
# PROP Target_Dir "" # PROP Target_Dir ""
# ADD BASE CPP /nologo /W3 /Gm /GX /ZI /Od /D "WIN32" /D "_DEBUG" /D "_WINDOWS" /D "_MBCS" /YX /FD /GZ /c # ADD BASE CPP /nologo /W3 /Gm /GX /ZI /Od /D "WIN32" /D "_DEBUG" /D "_WINDOWS" /D "_MBCS" /YX /FD /GZ /c
# ADD CPP /nologo /W3 /Gm /GX /ZI /Od /I "./" /I "../sdk" /D "WIN32" /D "_DEBUG" /D "_WINDOWS" /D "_MBCS" /FR /YX /FD /GZ /c # ADD CPP /nologo /W3 /Gm /GX /ZI /Od /I "./" /I "../sdk" /D "WIN32" /D "_DEBUG" /D "_WINDOWS" /D "_MBCS" /FR /YX /FD /GZ
# SUBTRACT CPP /X
# ADD BASE MTL /nologo /D "_DEBUG" /mktyplib203 /win32 # ADD BASE MTL /nologo /D "_DEBUG" /mktyplib203 /win32
# ADD MTL /nologo /D "_DEBUG" /mktyplib203 /win32 # ADD MTL /nologo /D "_DEBUG" /mktyplib203 /win32
# ADD BASE RSC /l 0x419 /d "_DEBUG" # ADD BASE RSC /l 0x419 /d "_DEBUG"
@@ -93,6 +92,10 @@ LINK32=link.exe
# PROP Default_Filter "cpp;c;cxx;rc;def;r;odl;idl;hpj;bat" # PROP Default_Filter "cpp;c;cxx;rc;def;r;odl;idl;hpj;bat"
# Begin Source File # Begin Source File
SOURCE=.\server\entity.cpp
# End Source File
# Begin Source File
SOURCE=.\filesystem\file.cpp SOURCE=.\filesystem\file.cpp
# End Source File # End Source File
# Begin Source File # Begin Source File
@@ -141,6 +144,14 @@ SOURCE=.\render\rendertarget.cpp
# End Source File # End Source File
# Begin Source File # Begin Source File
SOURCE=.\render\shader.cpp
# End Source File
# Begin Source File
SOURCE=.\render\shadersystem.cpp
# End Source File
# Begin Source File
SOURCE=.\filesystem\stream.cpp SOURCE=.\filesystem\stream.cpp
# End Source File # End Source File
# Begin Source File # Begin Source File
@@ -153,6 +164,10 @@ SOURCE=.\render\texturesmanager.cpp
# End Source File # End Source File
# Begin Source File # Begin Source File
SOURCE=.\render\ui.cpp
# End Source File
# Begin Source File
SOURCE=.\render\vertexbuffer.cpp SOURCE=.\render\vertexbuffer.cpp
# End Source File # End Source File
# End Group # End Group
@@ -161,6 +176,10 @@ SOURCE=.\render\vertexbuffer.cpp
# PROP Default_Filter "h;hpp;hxx;hm;inl" # PROP Default_Filter "h;hpp;hxx;hm;inl"
# Begin Source File # Begin Source File
SOURCE=.\server\entity.h
# End Source File
# Begin Source File
SOURCE=.\filesystem\file.h SOURCE=.\filesystem\file.h
# End Source File # End Source File
# Begin Source File # Begin Source File
@@ -209,6 +228,22 @@ SOURCE=.\render\rendertarget.h
# End Source File # End Source File
# Begin Source File # Begin Source File
SOURCE=.\utils\rtti.h
# End Source File
# Begin Source File
SOURCE=.\render\shader.h
# End Source File
# Begin Source File
SOURCE=.\render\shadersystem.h
# End Source File
# Begin Source File
SOURCE=.\utils\str.h
# End Source File
# Begin Source File
SOURCE=.\filesystem\stream.h SOURCE=.\filesystem\stream.h
# End Source File # End Source File
# Begin Source File # Begin Source File
@@ -221,6 +256,10 @@ SOURCE=.\render\texturesmanager.h
# End Source File # End Source File
# Begin Source File # Begin Source File
SOURCE=.\render\ui.h
# End Source File
# Begin Source File
SOURCE=.\render\vertexbuffer.h SOURCE=.\render\vertexbuffer.h
# End Source File # End Source File
# End Group # End Group

1
engine/gen_vs2019.bat Normal file
View File

@@ -0,0 +1 @@
..\tools\premake5.exe vs2019

View File

@@ -235,7 +235,11 @@ void GL_Load()
LogMsg("GL_VENDOR: %s", vendor_string); LogMsg("GL_VENDOR: %s", vendor_string);
LogMsg("GL_RENDERER: %s", renderer_string); LogMsg("GL_RENDERER: %s", renderer_string);
LogMsg("GL_VERSION: %s", version_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 // OpenGL 1.3
LOAD_GL_FUNC( PFNGLACTIVETEXTUREPROC, glActiveTexture); LOAD_GL_FUNC( PFNGLACTIVETEXTUREPROC, glActiveTexture);

View File

@@ -1,6 +1,9 @@
#include "render/render.h" #include "render/render.h"
#include "render/renderdevice.h" #include "render/renderdevice.h"
#include "render/shadersystem.h"
#include "render/gl_shared.h" #include "render/gl_shared.h"
#include "render/ui.h"
#include "render/texturesmanager.h"
#include "input/inputsystem.h" #include "input/inputsystem.h"
#include "utils/logger.h" #include "utils/logger.h"
@@ -91,10 +94,29 @@ void R_Init()
// Create render device // Create render device
g_renderDevice = new RenderDevice(); g_renderDevice = new RenderDevice();
g_shaderSystem = new ShaderSystem();
g_texturesManager = new TexturesManager();
// Initialize UI
uiInit();
} }
void R_Shutdown() 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) if (g_renderDevice != NULL)
{ {
delete g_renderDevice; delete g_renderDevice;
@@ -104,6 +126,10 @@ void R_Shutdown()
void R_Present() 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); GL_SwapBuffers(0);
} }

View File

@@ -1,7 +1,8 @@
#ifndef RENDERTARGET_H #ifndef RENDERTARGET_H
#define RENDERTARGET_H #define RENDERTARGET_H
#include <stdint.h> #include <stdlib.h>
#include "utils/maths.h"
class Texture2D; class Texture2D;
class RenderDevice; class RenderDevice;
@@ -17,7 +18,7 @@ public:
RenderTarget(); RenderTarget();
~RenderTarget(); ~RenderTarget();
void Create(const char* name = nullptr); void Create(const char* name = NULL);
void Destroy(); void Destroy();
void Finialize(); void Finialize();
@@ -26,7 +27,7 @@ public:
void AttachDepthTexture(Texture2D* texture); void AttachDepthTexture(Texture2D* texture);
private: private:
uint32_t m_framebuffer; uint m_framebuffer;
}; };

View File

@@ -44,7 +44,7 @@ GLuint CreateShader(GLenum shaderType, const char* filename)
} }
Shader::Shader() : Shader::Shader() :
m_name(nullptr), m_name(NULL),
m_stride(0), m_stride(0),
m_layout_count(0) m_layout_count(0)
{ {

View File

@@ -1,7 +1,6 @@
#ifndef SHADER_H #ifndef SHADER_H
#define SHADER_H #define SHADER_H
#include <stdint.h>
#include "gl_shared.h" #include "gl_shared.h"
const int SHADERUNIFORM_MAX_COUNT = 16; const int SHADERUNIFORM_MAX_COUNT = 16;

View File

@@ -24,7 +24,7 @@ static const char* g_samplersNameTable[SAMPLER_MAX] =
"u_lightmapTexture", "u_lightmapTexture",
}; };
ShaderSystem* g_shaderSystem = nullptr; ShaderSystem* g_shaderSystem = NULL;
ShaderSystem::ShaderSystem() ShaderSystem::ShaderSystem()
{ {
@@ -48,7 +48,7 @@ void ShaderSystem::Shutdown()
if (shaderData.shader) if (shaderData.shader)
{ {
delete 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 ); pShader->Create( name, vsfilepath, psfilepath );
ShaderData shaderData = { name, pShader }; ShaderData shaderData;
shaderData.name = name;
shaderData.shader = pShader;
m_shaders.push_back(shaderData); m_shaders.push_back(shaderData);
return pShader; return pShader;

View File

@@ -38,7 +38,7 @@ public:
void Init(); void Init();
void Shutdown(); 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); void SetShader(const Shader* shader);

View File

@@ -95,7 +95,7 @@ Texture2D* TexturesManager::CreateManual2D(const char* name, int width, int heig
// allocate // allocate
Texture2D* texture = Texture2D::Create(); Texture2D* texture = Texture2D::Create();
texture->CreateRaw(nullptr, width, height, format); texture->CreateRaw(NULL, width, height, format);
texture->m_textureFileName = name; texture->m_textureFileName = name;
if (useAsRenderTarget) if (useAsRenderTarget)
@@ -160,10 +160,10 @@ Texture2D* TexturesManager::LoadTexture2D(const char* texturename, bool useMipma
std::string texnamebuf; std::string texnamebuf;
// find texture from disk // find texture from disk
for (int i = 0; i < kTexFileExtensionsSize; i++) for (int j = 0; j < kTexFileExtensionsSize; j++)
{ {
std::string textureFilename = fs::getFileNameWithoutExtension(texturename); std::string textureFilename = fs::getFileNameWithoutExtension(texturename);
textureFilename += g_texFileExtensions[i]; textureFilename += g_texFileExtensions[j];
if (g_fileManager->FileExist(textureFilename.c_str())) if (g_fileManager->FileExist(textureFilename.c_str()))
{ {

View File

@@ -1,7 +1,7 @@
#include <cstdint>
#include <cmath> #include <cmath>
#include <cassert> #include <cassert>
#include "utils/logger.h" #include "utils/logger.h"
#include "utils/maths.h"
#include "render/ui.h" #include "render/ui.h"
#include "render/vertexbuffer.h" #include "render/vertexbuffer.h"
#include "render/indexbuffer.h" #include "render/indexbuffer.h"
@@ -12,35 +12,37 @@
struct DrawInfo struct DrawInfo
{ {
uint16_t vxcount; uint16 vxcount;
uint16_t idxcount; uint16 idxcount;
}; };
struct UIGlobals { struct UIGlobals {
VertexBuffer* vb; VertexBuffer* vb;
IndexBuffer* ib; IndexBuffer* ib;
Shader* shader; Shader* shader;
Texture2D* activetexture = nullptr; Texture2D* activetexture;
Texture2D* defaultTexture = nullptr; Texture2D* defaultTexture;
UIVertex* vertices = nullptr; UIVertex* vertices;
uint16_t* indices = nullptr; uint16* indices;
DrawInfo drawInfo[MAX_UI_VERTICES]; DrawInfo drawInfo[MAX_UI_VERTICES];
uint16_t count = 0; uint16 count;
uint16_t position = 0; uint16 position;
uint16_t Indexposition = 0; uint16 Indexposition;
uint16_t currentIdx = 0; uint16 currentIdx;
} g_ui; } g_ui;
void uiInit() void uiInit()
{ {
memset( &g_ui, 0, sizeof(g_ui) );
////////////////////////////////////////////////////////////////////////// //////////////////////////////////////////////////////////////////////////
// Buffer and context state // Buffer and context state
// Buffer creation // Buffer creation
g_ui.vb = g_renderDevice->CreateVertexBuffer(nullptr, MAX_UI_VERTICES, true); g_ui.vb = g_renderDevice->CreateVertexBuffer(NULL, MAX_UI_VERTICES, true);
g_ui.ib = g_renderDevice->CreateIndexBuffer(nullptr, MAX_UI_INDICES, true); g_ui.ib = g_renderDevice->CreateIndexBuffer(NULL, MAX_UI_INDICES, true);
// Create shader // Create shader
@@ -51,7 +53,7 @@ void uiInit()
{ VERTEXATTR_VEC4, SHADERSEMANTIC_COLOR }, { 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.shader->m_stride = sizeof( UIVertex );
g_ui.defaultTexture = g_texturesManager->LoadTexture2D("$white$"); g_ui.defaultTexture = g_texturesManager->LoadTexture2D("$white$");
@@ -61,6 +63,7 @@ void uiShutdown()
{ {
delete g_ui.ib; delete g_ui.ib;
delete g_ui.vb; delete g_ui.vb;
memset(&g_ui, 0, sizeof(g_ui));
} }
void uiDumpBuffers() void uiDumpBuffers()
@@ -91,7 +94,7 @@ void uiBeginRender()
g_ui.vertices = (UIVertex*)g_ui.vb->MapBuffer(BA_WRITE_ONLY); g_ui.vertices = (UIVertex*)g_ui.vb->MapBuffer(BA_WRITE_ONLY);
assert(g_ui.vertices); 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); 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; g_ui.vertices[g_ui.position + 3].position = d; g_ui.vertices[g_ui.position + 3].color = color;
// texcoord // texcoord
g_ui.vertices[g_ui.position + 0].uv = Vec2{ 0.0f, 1.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 + 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 + 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 + 3].uv = Vec2( 0.0f, 0.0f );
g_ui.currentIdx += 4; g_ui.currentIdx += 4;
g_ui.Indexposition += 6; 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) void uiDrawRect(const Vec2& position, const Vec2& size, const Vec4& color)
{ {
Vec2 quad[4]; Vec2 quad[4];
quad[0] = { position.x, position.y }; quad[0] = Vec2( position.x, position.y );
quad[1] = { position.x + size.x, position.y }; quad[1] = Vec2( position.x + size.x, position.y );
quad[2] = { position.x + size.x, position.y + size.y }; quad[2] = Vec2( position.x + size.x, position.y + size.y );
quad[3] = { position.x, position.y + size.y }; quad[3] = Vec2( position.x, position.y + size.y );
uiDrawQuad(quad[0], quad[1], quad[2], quad[3], color); uiDrawQuad(quad[0], quad[1], quad[2], quad[3], color);
} }
@@ -191,8 +194,8 @@ void uiSetTextureByName(const char* filename)
void uiEndRender() void uiEndRender()
{ {
g_ui.indices = nullptr; g_ui.indices = NULL;
g_ui.vertices = nullptr; g_ui.vertices = NULL;
g_ui.ib->UnmapBuffer(); g_ui.ib->UnmapBuffer();
g_ui.vb->UnmapBuffer(); g_ui.vb->UnmapBuffer();
@@ -215,7 +218,7 @@ void uiEndRender()
{ (R + L) / (L - R), (T + B) / (B - T), 0.0f, 1.0f }, { (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_ui.activetexture = g_ui.defaultTexture;
g_texturesManager->SetTexture( 0, g_ui.activetexture ); g_texturesManager->SetTexture( 0, g_ui.activetexture );

View File

@@ -6,7 +6,7 @@ IMPLEMENT_RTTI_BASE( Entity );
Entity::Entity() : Entity::Entity() :
m_position(0.0f), m_rotation(0.0f), m_scale(1.0f), m_position(0.0f), m_rotation(0.0f), m_scale(1.0f),
m_model(nullptr) m_model(NULL)
{ {
} }
@@ -46,13 +46,13 @@ void TestRTTI()
LogMsg("light classname: %s", light->GetRuntimeClass()->m_pClassName); LogMsg("light classname: %s", light->GetRuntimeClass()->m_pClassName);
LightEntity* lightCasted = DynamicCast< LightEntity, Entity >( entity ); LightEntity* lightCasted = DynamicCast< LightEntity, Entity >( entity );
LogMsg("light from entity casted: %s", lightCasted ? "successful" : "failed"); LogMsg("light from entity cast: %s", lightCasted ? "successful" : "failed");
delete entity; delete entity;
entity = light; entity = light;
lightCasted = DynamicCast< LightEntity, Entity >( entity ); lightCasted = DynamicCast< LightEntity, Entity >( entity );
LogMsg("light from entity(LightEntity) casted: %s", lightCasted ? "successful" : "failed"); LogMsg("light from entity(LightEntity) cast: %s", lightCasted ? "successful" : "failed");
entity = NULL; entity = NULL;
delete light; delete light;

10
shaders/debug_draw.ps Normal file
View File

@@ -0,0 +1,10 @@
#version 330 core
in vec3 v_color;
out vec4 fragColor;
void main()
{
fragColor = vec4(v_color, 1.0);
}

15
shaders/debug_draw.vs Normal file
View File

@@ -0,0 +1,15 @@
#version 330 core
layout (location = 0) in vec3 position;
layout (location = 1) in vec3 color;
out vec3 v_color;
uniform mat4 u_modelViewProjection;
void main()
{
gl_Position = u_modelViewProjection * vec4(position, 1.0f);
v_color = color;
}

15
shaders/lit_generic.ps Normal file
View File

@@ -0,0 +1,15 @@
#version 120
varying vec3 v_position;
varying vec3 v_normal;
varying vec2 v_texcoord;
varying vec3 v_finalColor;
uniform sampler2D u_albedoTexture;
uniform vec4 u_customColor;
void main() {
//gl_FragColor = vec4(1.0, 0.0, 0.0, 1.0);
gl_FragColor = u_customColor * vec4(v_finalColor, 1.0) * texture2D(u_albedoTexture, v_texcoord);
//gl_FragColor = vec4( v_normal, 1.0 );
}

46
shaders/lit_generic.vs Normal file
View File

@@ -0,0 +1,46 @@
#version 120
attribute vec3 a_position;
attribute vec3 a_normal;
attribute vec2 a_texcoord;
varying vec3 v_position;
varying vec3 v_normal;
varying vec2 v_texcoord;
varying vec3 v_finalColor;
uniform mat4 u_modelMatrix;
uniform mat4 u_viewMatrix;
uniform mat4 u_projectionMatrix;
uniform mat4 u_modelViewProjection;
vec3 CalcOmniLight()
{
vec3 lightPos = vec3(0.1, 2.1, 0.1);
float d = distance(lightPos, v_position);
vec3 L = normalize(lightPos-v_position);
vec3 N = normalize(v_normal);
vec3 col = vec3( max(0, dot(N, L) / d) );
col = col * 0.8 + 0.2;
return col;
}
vec3 CalcDirLight()
{
vec3 lightPos = vec3(5.0, 10.0, 1.0);
//lightPos = -lightPos;
vec3 L = normalize(lightPos);
vec3 N = normalize(v_normal);
vec3 col = vec3( max(0, dot(N, L)) );
col = col * 0.8 + 0.2;
return col;
}
void main() {
v_position = vec3( u_modelMatrix * vec4(a_position, 1.0) );
v_normal = vec3( mat3(u_modelMatrix) * a_normal );
v_texcoord = a_texcoord;
v_finalColor = CalcDirLight();
gl_Position = u_modelViewProjection * vec4(a_position, 1);
}

View File

@@ -0,0 +1,15 @@
#version 120
varying vec3 v_position;
varying vec3 v_normal;
varying vec2 v_texcoord;
varying vec3 v_finalColor;
uniform sampler2D u_albedoTexture;
uniform vec4 u_customColor;
void main() {
//gl_FragColor = vec4(1.0, 0.0, 0.0, 1.0);
gl_FragColor = u_customColor * vec4(v_finalColor, 1.0) * texture2D(u_albedoTexture, v_texcoord);
//gl_FragColor = vec4( v_normal, 1.0 );
}

8
shaders/ui_base.ps Normal file
View File

@@ -0,0 +1,8 @@
#version 120
varying vec2 v_texcoord;
varying vec4 v_color;
void main() {
gl_FragColor = v_color;
}

16
shaders/ui_base.vs Normal file
View File

@@ -0,0 +1,16 @@
#version 120
attribute vec2 a_position;
attribute vec2 a_texcoord;
attribute vec4 a_color;
varying vec2 v_texcoord;
varying vec4 v_color;
uniform mat4 u_projectionMatrix;
void main() {
v_texcoord = a_texcoord;
v_color = a_color;
gl_Position = u_projectionMatrix * vec4(a_position.xy,0,1);
}

11
shaders/ui_tex.ps Normal file
View File

@@ -0,0 +1,11 @@
#version 120
varying vec2 v_texcoord;
varying vec4 v_color;
uniform sampler2D u_texture;
void main() {
vec4 tex = texture2D( u_texture, v_texcoord );
gl_FragColor = v_color * tex;
}