made rendering work
This commit is contained in:
@@ -1,65 +0,0 @@
|
||||
#include "helper.h"
|
||||
#include "c.h"
|
||||
#include "ld.h"
|
||||
#include "tier1/utlstring.h"
|
||||
|
||||
CUtlVector<CUtlString> engine_CompiledFiles = {
|
||||
"engine/engine.cpp",
|
||||
"engine/cvar.cpp",
|
||||
"engine/filesystem_pak.cpp",
|
||||
|
||||
"engine/gamewindow_sdl.cpp",
|
||||
|
||||
"engine/sv_dll.cpp",
|
||||
"engine/cl_dll.cpp",
|
||||
};
|
||||
|
||||
CUtlVector<CUtlString> engine_Libraries = {
|
||||
"c",
|
||||
"SDL3",
|
||||
};
|
||||
|
||||
DECLARE_BUILD_STAGE(engine)
|
||||
{
|
||||
CProject_t compileProject = {};
|
||||
LinkProject_t ldProject = {};
|
||||
|
||||
compileProject.m_szName = "engine";
|
||||
compileProject.files = engine_CompiledFiles;
|
||||
compileProject.includeDirectories = {"public"};
|
||||
compileProject.bFPIC = true;
|
||||
ldProject = ccompiler->Compile(&compileProject);
|
||||
|
||||
/*
|
||||
if (bStaticBuild)
|
||||
ldProject.linkType = ELINK_STATIC_LIBRARY;
|
||||
else
|
||||
{
|
||||
ldProject.objects.AppendTail((Object_t){tier1_lib});
|
||||
ldProject.objects.AppendTail((Object_t){tier2_lib});
|
||||
ldProject.objects.AppendTail((Object_t){rapier_lib});
|
||||
ldProject.objects.AppendTail((Object_t){material_lib});
|
||||
if (bSteam)
|
||||
ldProject.objects.AppendTail((Object_t){steam_lib});
|
||||
}
|
||||
*/
|
||||
ldProject.linkType = ELINK_DYNAMIC_LIBRARY;
|
||||
|
||||
|
||||
ldProject.libraries = engine_Libraries;
|
||||
CUtlString szOutputDir = linker->Link(&ldProject);
|
||||
|
||||
/*
|
||||
if (!bStaticBuild)
|
||||
{
|
||||
*/
|
||||
filesystem2->MakeDirectory(CUtlString("%s/bin",szOutputDir.GetString()));
|
||||
filesystem2->CopyFile(CUtlString("%s/bin", szOutputDir.GetString()), szOutputDir);
|
||||
/*
|
||||
} else {
|
||||
engine_lib = outputProject;
|
||||
}
|
||||
*/
|
||||
|
||||
return 0;
|
||||
};
|
||||
@@ -11,11 +11,6 @@ ADD_DEPENDENCY_BUILD_FILE(tier2, FUNNYSTDLIB"tier2/build.cpp");
|
||||
|
||||
DECLARE_BUILD_STAGE(engine)
|
||||
{
|
||||
bool bUsesSDL = true;
|
||||
if (Target_t::DefaultTarget().cpu == TARGET_CPU_WASM32)
|
||||
{
|
||||
bUsesSDL = false;
|
||||
}
|
||||
CProject_t compileProject = {};
|
||||
LinkProject_t ldProject = {};
|
||||
|
||||
@@ -27,8 +22,6 @@ DECLARE_BUILD_STAGE(engine)
|
||||
"sv_dll.cpp",
|
||||
"cl_dll.cpp",
|
||||
};
|
||||
if (bUsesSDL)
|
||||
compileProject.files.AppendTail("gamewindow_sdl.cpp");
|
||||
|
||||
compileProject.includeDirectories = {
|
||||
"../public",
|
||||
@@ -46,8 +39,6 @@ DECLARE_BUILD_STAGE(engine)
|
||||
ldProject.objects.AppendTail({GET_PROJECT_LIBRARY(tier1, "tier1")});
|
||||
ldProject.objects.AppendTail({GET_PROJECT_LIBRARY(tier2, "tier2")});
|
||||
|
||||
if (bUsesSDL)
|
||||
ldProject.libraries.AppendTail("SDL3");
|
||||
if (ldProject.m_target.kernel & TARGET_KERNEL_WINDOWS_DEVICES)
|
||||
{
|
||||
ldProject.libraryDirectories = {"../external/windows"};
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
|
||||
#include "tier2/ifilesystem.h"
|
||||
#include "igamewindow.h"
|
||||
#include "materialsystem/igamewindow.h"
|
||||
#include "materialsystem/imaterialsystem.h"
|
||||
#include "tier1/interface.h"
|
||||
#include "tier0/commandline.h"
|
||||
@@ -9,21 +9,34 @@
|
||||
|
||||
IRenderContext *g_pRenderContext;
|
||||
IFileSystem *filesystem;
|
||||
IGameWindowManager *g_pWindowManager;
|
||||
|
||||
extern "C" void FunnyMain( int argc, char **argv )
|
||||
{
|
||||
CommandLine()->CreateCommandLine(argc, argv);
|
||||
|
||||
CreateInterfaceFn pFilesystemFactory = Sys_GetFactory("filesystem_std");
|
||||
CreateInterfaceFn pMaterialSystemFactory = Sys_GetFactory("MaterialSystem");
|
||||
CreateInterfaceFn pRenderSystemFactory = Sys_GetFactory("RenderSystemVulkan");
|
||||
|
||||
filesystem = (IFileSystem*)pFilesystemFactory(FILESYSTEM_INTERFACE_VERSION, NULL);
|
||||
filesystem->Init();
|
||||
|
||||
CreateInterfaceFn pMaterialSystemFactory = Sys_GetFactory("MaterialSystem");
|
||||
CreateInterfaceFn pRenderSystemFactory = Sys_GetFactory("RenderSystemVulkan");
|
||||
g_pWindowManager = (IGameWindowManager*)pRenderSystemFactory(GAME_WINDOW_MANAGER_INTERFACE_VERSION, NULL);
|
||||
V_printf("%s\n", GAME_WINDOW_MANAGER_INTERFACE_VERSION);
|
||||
g_pWindowManager->Init();
|
||||
|
||||
IGameWindow *pWindow = g_pWindowManager->CreateWindow();
|
||||
pWindow->Init();
|
||||
|
||||
|
||||
g_pRenderContext = (IRenderContext*)pRenderSystemFactory(RENDER_CONTEXT_INTERFACE_VERSION, NULL);
|
||||
g_pRenderContext->SetMainWindowManager(g_pWindowManager);
|
||||
g_pRenderContext->Init();
|
||||
|
||||
g_pRenderContext->RegisterGameWindow(pWindow);
|
||||
|
||||
|
||||
ServerGameDLL()->Init();
|
||||
|
||||
IShader *pShader = NULL;
|
||||
@@ -33,54 +46,68 @@ extern "C" void FunnyMain( int argc, char **argv )
|
||||
IImage *pOutputImage = NULL;
|
||||
IVertexBuffer *pVertices = NULL;
|
||||
|
||||
float vertices[9] = {
|
||||
0,-0.5, 0.5,
|
||||
0.5,0.5, 0.5,
|
||||
-0.5,0.5, 0.5,
|
||||
float vertices[18] = {
|
||||
-0.5, -0.5, 0,
|
||||
0.5, -0.5, 0,
|
||||
-0.5, 0.5, 0,
|
||||
-0.5, 0.5, 0,
|
||||
0.5, -0.5, 0,
|
||||
0.5, 0.5, 0
|
||||
|
||||
};
|
||||
|
||||
pVertices = g_pRenderContext->CreateVertexBuffer(36);
|
||||
pVertices = g_pRenderContext->CreateVertexBuffer(72);
|
||||
|
||||
void *pMapped = pVertices->Map();
|
||||
V_memcpy(pMapped, vertices, 36);
|
||||
V_memcpy(pMapped, vertices, 72);
|
||||
pVertices->Unmap();
|
||||
|
||||
pCameraInfoBuffer = g_pRenderContext->CreateConstantBuffer(64);
|
||||
|
||||
/*
|
||||
pShader = g_pRenderContext->CreateShader("funnygame/core/shaders/flat.shader_c");
|
||||
pShader = g_pRenderContext->CreateShader("game/core/shaders/flat.shader_c");
|
||||
pShader->AddLayout(0, 12);
|
||||
pShader->AddAttribute(0, 0, VERTEX_FORMAT_XYZ32_SFLOAT, 0);
|
||||
pShader->AddOutputImage(0, IMAGE_FORMAT_RGBA8_UNORM);
|
||||
pShader->Build();
|
||||
pMaterial = g_pRenderContext->CreateMaterial(pShader);
|
||||
pMaterial->PSSetConstantsBuffer(0, pCameraInfoBuffer);
|
||||
*/
|
||||
|
||||
|
||||
pOutputImage = g_pRenderContext->CreateRenderTarget(
|
||||
1280,
|
||||
720,
|
||||
100,
|
||||
100,
|
||||
IMAGE_FORMAT_RGBA8_UNORM,
|
||||
MULTISAMPLE_TYPE_NONE);
|
||||
|
||||
IRenderCommandList *pCommandList = g_pRenderContext->CreateCommandList();
|
||||
pCommandList->StartRecording();
|
||||
pCommandList->SetRenderTarget(0, pOutputImage);
|
||||
pCommandList->SetClearColor(0, 1,0,0,0);
|
||||
pCommandList->EndRecording();
|
||||
|
||||
for (;;) {
|
||||
/*
|
||||
if (g_pRenderContext->BIsOutputImageOutdated())
|
||||
g_pWindowManager->Frame(0);
|
||||
if (pWindow->BRenderSizeUpdated())
|
||||
{
|
||||
uint32_t nWidth;
|
||||
uint32_t nHeight;
|
||||
g_pRenderContext->DestroyImage(pOutputImage);
|
||||
pOutputImage = g_pRenderContext->CreateRenderTarget(
|
||||
g_pRenderContext->GetNewOutputImageWidth(),
|
||||
g_pRenderContext->GetNewOutputImageHeight(),
|
||||
pWindow->GetRenderWidth(),
|
||||
pWindow->GetRenderHeight(),
|
||||
IMAGE_FORMAT_RGBA8_UNORM,
|
||||
MULTISAMPLE_TYPE_NONE);
|
||||
}
|
||||
*/
|
||||
|
||||
IRenderCommandList *pCommandList = g_pRenderContext->CreateCommandList();
|
||||
pCommandList->StartRecording();
|
||||
|
||||
pCommandList->SetRenderResolution(pWindow->GetRenderWidth(), pWindow->GetRenderHeight());
|
||||
pCommandList->SetRenderTarget(0, pOutputImage);
|
||||
pCommandList->SetClearColor(0, 0, 0, 0, 0);
|
||||
|
||||
pCommandList->SetMaterial(pMaterial);
|
||||
pCommandList->SetVertexBuffer(0, pVertices);
|
||||
pCommandList->DrawPrimitives(6, 0, 1, 0);
|
||||
|
||||
pCommandList->EndRecording();
|
||||
pWindow->SetOutputImage(pOutputImage);
|
||||
|
||||
g_pRenderContext->SubmitCommandList(pCommandList);
|
||||
g_pRenderContext->Frame(0);
|
||||
g_pRenderContext->DestroyCommandList(pCommandList);
|
||||
};
|
||||
|
||||
};
|
||||
|
||||
@@ -1,155 +0,0 @@
|
||||
#include "SDL3/SDL_error.h"
|
||||
#include "igamewindow.h"
|
||||
#include "tier0/lib.h"
|
||||
#include "tier0/platform.h"
|
||||
#include "tier1/interface.h"
|
||||
#include "tier1/utlvector.h"
|
||||
|
||||
#define SDL_MAIN_HANDLED
|
||||
#include "SDL3/SDL.h"
|
||||
#include "SDL3/SDL_init.h"
|
||||
#include "SDL3/SDL_video.h"
|
||||
#include "SDL3/SDL_vulkan.h"
|
||||
#include "SDL3/SDL_events.h"
|
||||
|
||||
class CSDLGameWindow: public IGameWindow
|
||||
{
|
||||
public:
|
||||
virtual void Init() override;
|
||||
virtual void Shutdown() override;
|
||||
virtual void Tick( float fDelta ) override;
|
||||
virtual void Frame( float fDelta ) override;
|
||||
virtual uint32_t GetRenderWidth() override;
|
||||
virtual uint32_t GetRenderHeight() override;
|
||||
|
||||
virtual void *CreateVulkanSurface( void *pInstance ) override;
|
||||
virtual void DestroyVulkanSurface( void *pInstance ) override;
|
||||
private:
|
||||
|
||||
VkSurfaceKHR m_hSurface;
|
||||
SDL_Window *m_pWindow;
|
||||
};
|
||||
|
||||
|
||||
void CSDLGameWindow::Init()
|
||||
{
|
||||
if (!SDL_Init(SDL_INIT_VIDEO | SDL_INIT_EVENTS | SDL_INIT_GAMEPAD))
|
||||
Plat_FatalErrorFunc("SDL_Init: %s\n", SDL_GetError());
|
||||
|
||||
m_pWindow = SDL_CreateWindow("funnygame", 1280, 720, SDL_WINDOW_VULKAN | SDL_WINDOW_RESIZABLE);
|
||||
if (!m_pWindow)
|
||||
Plat_FatalErrorFunc("SDL_CreateWindow: %s\n", SDL_GetError());
|
||||
}
|
||||
|
||||
void CSDLGameWindow::Shutdown()
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
void CSDLGameWindow::Frame( float fDelta )
|
||||
{
|
||||
SDL_Event event;
|
||||
while (SDL_PollEvent(&event))
|
||||
{
|
||||
switch (event.type)
|
||||
{
|
||||
case SDL_EVENT_WINDOW_PIXEL_SIZE_CHANGED:
|
||||
break;
|
||||
case SDL_EVENT_QUIT:
|
||||
SDL_Quit();
|
||||
Plat_Exit(0);
|
||||
break;
|
||||
default:
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
void CSDLGameWindow::Tick( float fDelta )
|
||||
{
|
||||
|
||||
};
|
||||
|
||||
uint32_t CSDLGameWindow::GetRenderWidth()
|
||||
{
|
||||
return 0;
|
||||
}
|
||||
|
||||
uint32_t CSDLGameWindow::GetRenderHeight()
|
||||
{
|
||||
return 0;
|
||||
}
|
||||
|
||||
|
||||
void *CSDLGameWindow::CreateVulkanSurface( void *pInstance )
|
||||
{
|
||||
SDL_Vulkan_CreateSurface(m_pWindow, (VkInstance)pInstance, NULL, (VkSurfaceKHR*)&m_hSurface);
|
||||
return (void*)m_hSurface;
|
||||
}
|
||||
|
||||
void CSDLGameWindow::DestroyVulkanSurface( void *pInstance )
|
||||
{
|
||||
SDL_Vulkan_DestroySurface((VkInstance)pInstance, (VkSurfaceKHR)m_hSurface, NULL);
|
||||
}
|
||||
|
||||
class CSDLGameWindowManager: public IGameWindowManager
|
||||
{
|
||||
|
||||
virtual void Init() override;
|
||||
virtual void Tick( float fDelta ) override;
|
||||
virtual void Frame( float fDelta ) override;
|
||||
virtual void Shutdown() override;
|
||||
|
||||
virtual IGameWindow *CreateWindow() override;
|
||||
virtual void DestroyWindow( IGameWindow* pWindow ) override;
|
||||
|
||||
virtual int GetVulkanInstanceExtensionCount() override;
|
||||
virtual const char **GetVulkanInstanceExtensions() override;
|
||||
};
|
||||
|
||||
void CSDLGameWindowManager::Init()
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
void CSDLGameWindowManager::Tick( float fDelta )
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
void CSDLGameWindowManager::Frame( float fDelta )
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
void CSDLGameWindowManager::Shutdown()
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
|
||||
IGameWindow *CSDLGameWindowManager::CreateWindow()
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
void CSDLGameWindowManager::DestroyWindow( IGameWindow* pWindow )
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
|
||||
int CSDLGameWindowManager::GetVulkanInstanceExtensionCount()
|
||||
{
|
||||
uint32_t nCount;
|
||||
SDL_Vulkan_GetInstanceExtensions(&nCount);
|
||||
|
||||
return nCount;
|
||||
}
|
||||
|
||||
const char **CSDLGameWindowManager::GetVulkanInstanceExtensions()
|
||||
{
|
||||
|
||||
uint32_t nCount;
|
||||
return (const char **)SDL_Vulkan_GetInstanceExtensions(&nCount);
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user