From 52aa5803af3fcb3d717dab34caa432c8084556bf Mon Sep 17 00:00:00 2001 From: kotofyt Date: Tue, 16 Jun 2026 04:21:59 +0300 Subject: [PATCH] work on android port --- .fpccfg | 7 + buildcfg.cpp | 6 + engine/build.cpp | 1 + external/funnystdlib | 2 +- game/client/assetmgr.cpp | 3 - game/client/entitysystem.cpp | 28 +- game/client/entitysystem.h | 6 +- game/client/game.cpp | 22 +- .../client/kbt_vr_psy/experience.cpp | 0 game/client/kbt_vr_psy/experience.h | 16 + game/client/kbt_vr_psy/interactable.cpp | 0 game/client/kbt_vr_psy/materials.cpp | 39 ++ game/client/kbt_vr_psy/observer_http.cpp | 0 game/client/kbt_vr_psy/player.cpp | 25 ++ game/client/kbt_vr_psy/stop_button.cpp | 0 game/client/kbt_vr_psy/ui/settings.cpp | 0 game/client/worldrender.cpp | 406 +++++++++--------- game/client/worldrender.h | 25 +- game/server/build.cpp | 51 ++- game/server/kbt_vr_psy/experience.cpp | 0 game/server/kbt_vr_psy/interactable.cpp | 0 game/server/kbt_vr_psy/observer_ingame.cpp | 0 game/server/kbt_vr_psy/player.cpp | 0 launcher/launcher.cpp | 5 +- materialsystem/gamewindow_sdl.cpp | 6 +- materialsystem/vulkan/rendercontext.cpp | 51 +-- materialsystem/vulkan/shader.cpp | 18 + materialsystem/vulkan/vulkan_state.h | 15 + public/materialsystem/imaterialsystem.h | 39 ++ 29 files changed, 499 insertions(+), 272 deletions(-) rename engine/jsonformat.cpp => game/client/kbt_vr_psy/experience.cpp (100%) create mode 100644 game/client/kbt_vr_psy/experience.h create mode 100644 game/client/kbt_vr_psy/interactable.cpp create mode 100644 game/client/kbt_vr_psy/materials.cpp create mode 100644 game/client/kbt_vr_psy/observer_http.cpp create mode 100644 game/client/kbt_vr_psy/player.cpp create mode 100644 game/client/kbt_vr_psy/stop_button.cpp create mode 100644 game/client/kbt_vr_psy/ui/settings.cpp create mode 100644 game/server/kbt_vr_psy/experience.cpp create mode 100644 game/server/kbt_vr_psy/interactable.cpp create mode 100644 game/server/kbt_vr_psy/observer_ingame.cpp create mode 100644 game/server/kbt_vr_psy/player.cpp diff --git a/.fpccfg b/.fpccfg index 4058cee..aa6a25e 100644 --- a/.fpccfg +++ b/.fpccfg @@ -6,3 +6,10 @@ sysroot = "/home/kotofyt/Downloads/xcode/Xcode_26.1_Apple_silicon/Xcode.app/Cont [x86_64-apple-ios] sysroot = "/Applications/Xcode.app/Contents/Developer/Platforms/iPhoneSimulator.platform/Developer/SDKs/iPhoneSimulator.sdk" + +[x86_64-linux-android] +sysroot = "/home/kotofyt/Android/Sdk/ndk/29.0.13599879/toolchains/llvm/prebuilt/linux-x86_64/sysroot" +"clang++" = "/home/kotofyt/Android/Sdk/ndk/29.0.13599879/toolchains/llvm/prebuilt/linux-x86_64/bin/clang++" + +[Android_Build_Tools] +path = "/home/kotofyt/Android/Sdk/build-tools/36.0.0" diff --git a/buildcfg.cpp b/buildcfg.cpp index 8c30b13..fc34851 100644 --- a/buildcfg.cpp +++ b/buildcfg.cpp @@ -25,5 +25,11 @@ DECLARE_BUILD_STAGE(config) ADD_OUTPUT_VALUE("steam", "true"); ADD_OUTPUT_OBJECT("steam_lib", EXTERNAL"steamworks/redistributable_bin/win64/steam_api64.dll"); } + if (Target_t::DefaultTarget().kernel == TARGET_KERNEL_ANDROID) + { + ADD_OUTPUT_VALUE("static", "true"); + ADD_OUTPUT_VALUE("bundle", "true"); + ADD_OUTPUT_VALUE("steam", "false"); + } return 0; } diff --git a/engine/build.cpp b/engine/build.cpp index 3fbe077..3e2f095 100644 --- a/engine/build.cpp +++ b/engine/build.cpp @@ -47,6 +47,7 @@ DECLARE_BUILD_STAGE(engine) EXTERNAL"steamworks/public", EXTERNAL"Vulkan-Headers/include", EXTERNAL"Vulkan-Utility-Libraries/include", + EXTERNAL"OpenXR-SDK/include", EXTERNAL }; if ( GET_PROJECT_VALUE(config, "steam") == "true" ) diff --git a/external/funnystdlib b/external/funnystdlib index df40d74..ecb21ea 160000 --- a/external/funnystdlib +++ b/external/funnystdlib @@ -1 +1 @@ -Subproject commit df40d74b9b65efaf91ea0b0e150dfaad9e87f6c6 +Subproject commit ecb21ea0c4e1e3541727cc28f6f38bdfebd3cb88 diff --git a/game/client/assetmgr.cpp b/game/client/assetmgr.cpp index c2b3d05..06dc357 100644 --- a/game/client/assetmgr.cpp +++ b/game/client/assetmgr.cpp @@ -137,7 +137,6 @@ FunnyMesh_t *CAssetManager::GetMeshByIndex( uint32_t uIndex ) uint32_t CAssetManager::LoadModel( const char *szName ) { - V_printf("LOADING %s\n", szName); bool bHasBeenCreated = false; HFunnyModel hModel = m_models.GetOrCreateObject(szName, &bHasBeenCreated); if (!bHasBeenCreated) @@ -296,7 +295,6 @@ void CAssetManager::UnrefMaterial( uint32_t uIndex ) HFunnyMesh CAssetManager::LoadMesh( const char *szName ) { - V_printf("LOADING %s\n", szName); bool bHasBeenCreated = false; HFunnyMesh hAsset = m_meshes.GetOrCreateObject(szName, &bHasBeenCreated); if (!bHasBeenCreated) @@ -310,7 +308,6 @@ HFunnyMesh CAssetManager::LoadMesh( const char *szName ) m_meshes.UnrefObject(hAsset); return 0; } - V_printf("V_LOADING %s %llu\n", szName, filesystem->Size(hMesh)); IVertexBuffer *pVertexBuffer = g_pRenderContext->CreateVertexBuffer(filesystem->Size(hMesh)); pVertexBuffer->Lock(); diff --git a/game/client/entitysystem.cpp b/game/client/entitysystem.cpp index 159819e..d13477b 100644 --- a/game/client/entitysystem.cpp +++ b/game/client/entitysystem.cpp @@ -14,9 +14,9 @@ static C_BaseEntity *s_pLocalEntity; -CEntitySystem *EntitySystem() +C_EntitySystem *EntitySystem() { - static CEntitySystem s_entitySystem; + static C_EntitySystem s_entitySystem; return &s_entitySystem; } @@ -27,7 +27,7 @@ static struct EntityRegistry_t struct EntityRegistry_t *m_pNext; } *s_pEntitiesRegistry = NULL; -CEntitySystem::CEntitySystem() +C_EntitySystem::C_EntitySystem() { int i = 0; for ( i = 0; i < MAX_EDICTS; i++ ) @@ -37,7 +37,7 @@ CEntitySystem::CEntitySystem() m_nEntityCount = 0; } -void CEntitySystem::RegisterEntityClass( IEntityFactory *pEntityFactory, const char *szClassName ) +void C_EntitySystem::RegisterEntityClass( IEntityFactory *pEntityFactory, const char *szClassName ) { IEntityFactory *pFactory; EntityRegistry_t *pRegistry; @@ -57,7 +57,7 @@ void CEntitySystem::RegisterEntityClass( IEntityFactory *pEntityFactory, const c s_pEntitiesRegistry = pRegistry; } -C_BaseEntity *CEntitySystem::CreateByClassname( const char *szName ) +C_BaseEntity *C_EntitySystem::CreateByClassname( const char *szName ) { IEntityFactory *pFactory; C_BaseEntity *pEntity; @@ -89,7 +89,7 @@ C_BaseEntity *CEntitySystem::CreateByClassname( const char *szName ) m_nEntityCount++; return pEntity; } -C_BaseEntity *CEntitySystem::CreateByClassnameWithIndex( const char *szName, uint32_t uIndex ) +C_BaseEntity *C_EntitySystem::CreateByClassnameWithIndex( const char *szName, uint32_t uIndex ) { IEntityFactory *pFactory; C_BaseEntity *pEntity; @@ -109,7 +109,7 @@ C_BaseEntity *CEntitySystem::CreateByClassnameWithIndex( const char *szName, uin return pEntity; } -IEntityFactory *CEntitySystem::GetFactoryByClassname( const char *szName ) +IEntityFactory *C_EntitySystem::GetFactoryByClassname( const char *szName ) { EntityRegistry_t *pEntity; @@ -124,7 +124,7 @@ IEntityFactory *CEntitySystem::GetFactoryByClassname( const char *szName ) } -void CEntitySystem::DestroyEntityByIndex( uint32_t uIndex ) +void C_EntitySystem::DestroyEntityByIndex( uint32_t uIndex ) { if ( uIndex >= MAX_EDICTS ) return; @@ -138,12 +138,12 @@ void CEntitySystem::DestroyEntityByIndex( uint32_t uIndex ) } } -void CEntitySystem::DestroyEntityByPtr( C_BaseEntity *pEntity ) +void C_EntitySystem::DestroyEntityByPtr( C_BaseEntity *pEntity ) { } -void CEntitySystem::Think() +void C_EntitySystem::Think() { C_BaseEntity *pEntity; int i; @@ -180,7 +180,7 @@ searchIndex: } -void CEntitySystem::NetRecvPacket( NetPacket_t *pPacket ) +void C_EntitySystem::NetRecvPacket( NetPacket_t *pPacket ) { PlayerPacket_t *pPlayerPacket = (PlayerPacket_t*)pPacket->pData; C_BaseEntity *pEntity; @@ -249,7 +249,7 @@ void CEntitySystem::NetRecvPacket( NetPacket_t *pPacket ) } } -void CEntitySystem::NetSendThink( INetworkBase *pBase ) +void C_EntitySystem::NetSendThink( INetworkBase *pBase ) { C_BaseEntity *pEntity; int i; @@ -320,12 +320,12 @@ void CEntitySystem::NetSendThink( INetworkBase *pBase ) } -C_BaseEntity **CEntitySystem::GetEntities() +C_BaseEntity **C_EntitySystem::GetEntities() { return m_pEntities; }; -C_BaseEntity *CEntitySystem::GetEntityByIndex( int idx ) +C_BaseEntity *C_EntitySystem::GetEntityByIndex( int idx ) { if (idx < 0 || idx >= MAX_EDICTS) return NULL; diff --git a/game/client/entitysystem.h b/game/client/entitysystem.h index ef6a910..d778362 100644 --- a/game/client/entitysystem.h +++ b/game/client/entitysystem.h @@ -16,10 +16,10 @@ class C_BaseEntity; #define MAX_EDICTS 8192 #define EDICT_INDEX_UNDEFINED (-1U) -class CEntitySystem +class C_EntitySystem { public: - CEntitySystem(); + C_EntitySystem(); virtual void RegisterEntityClass( IEntityFactory *pEntityFactory, const char *szClassName ); virtual C_BaseEntity *CreateByClassname( const char *szName ); @@ -43,7 +43,7 @@ private: int m_nEntityCount; }; -CEntitySystem *EntitySystem(); +C_EntitySystem *EntitySystem(); C_BaseEntity *UTIL_GetLocalPlayer(); diff --git a/game/client/game.cpp b/game/client/game.cpp index 3fa23cb..57158a9 100644 --- a/game/client/game.cpp +++ b/game/client/game.cpp @@ -28,6 +28,8 @@ class CFunnyGameBridge: public IEngineBridge bool m_bIsConnectedToServer; float m_fNetUpdateTimer; + + IViewport *m_pMainViewport; }; @@ -47,7 +49,6 @@ void CFunnyGameBridge::Init() Console()->AddCommand("exec game/core/default.cfg\n"); Console()->Execute(); - g_pWorldRenderer->Init(); #ifdef STEAM if (g_pEngineConstants->m_bIsSteam) { @@ -89,6 +90,12 @@ void CFunnyGameBridge::Init() g_pRenderContext->ConnectInterface(g_pXRManager, XR_INTERFACE_VERSION); + g_pWorldRenderer->Init(); + m_pMainViewport = g_pWorldRenderer->CreateViewport(g_pMainWindow->GetRenderWidth(), g_pMainWindow->GetRenderHeight()); + m_pMainViewport->SetFOV(90); + m_pMainViewport->SetPosition({0,0,0}); + m_pMainViewport->SetRotation({0,0,0,1}); + IXRHeadset *pHeadSet = g_pXRManager->GetHeadset(0); if (pHeadSet) { @@ -150,6 +157,11 @@ void CFunnyGameBridge::TryToConnectToServer() void CFunnyGameBridge::Frame( float fDelta ) { + + if (g_pMainWindow->GetRenderWidth() != m_pMainViewport->GetWidth()) + if (g_pMainWindow->GetRenderHeight() != m_pMainViewport->GetHeight()) + m_pMainViewport->UpdateResolution(g_pMainWindow->GetRenderWidth(), g_pMainWindow->GetRenderHeight()); + g_pEngineVars->m_fTime += fDelta; g_pEngineVars->m_fDeltaTime = fDelta; @@ -158,13 +170,6 @@ void CFunnyGameBridge::Frame( float fDelta ) g_pXRManager->Frame(); - IXRHeadset *pHeadSet = g_pXRManager->GetHeadset(0); - if (pHeadSet) { - XRRenderSurface_t s = pHeadSet->GetSurface(0); - g_pWorldRenderer->SetCameraPosition(s.m_vPosition); - g_pWorldRenderer->SetCameraRotation(s.m_vRotation); - } - INetworkBase *pCurrentServer = g_pServerBridge; pCurrentServer = g_pServerBridge; if (m_bIsConnectedToServer) @@ -217,6 +222,7 @@ void CFunnyGameBridge::Frame( float fDelta ) EntitySystem()->NetSendThink(pCurrentServer); } g_pWorldRenderer->Frame(fDelta); + g_pMainWindow->SetOutputImage(m_pMainViewport->GetRenderImage()); } void CFunnyGameBridge::Shutdown() diff --git a/engine/jsonformat.cpp b/game/client/kbt_vr_psy/experience.cpp similarity index 100% rename from engine/jsonformat.cpp rename to game/client/kbt_vr_psy/experience.cpp diff --git a/game/client/kbt_vr_psy/experience.h b/game/client/kbt_vr_psy/experience.h new file mode 100644 index 0000000..b5e8998 --- /dev/null +++ b/game/client/kbt_vr_psy/experience.h @@ -0,0 +1,16 @@ +#include "baseentity.h" + +class C_KBTExperience: public C_BaseEntity +{ +public: + DECLARE_CLASS(C_KBTExperience, C_BaseEntity) + DECLARE_CLIENTCLASS() + + virtual ~C_KBTExperience() override; + virtual void Precache() override; + virtual void Spawn() override; + void Frame( float fDelta ); +}; + +C_KBTExperience *GetExperience(); + diff --git a/game/client/kbt_vr_psy/interactable.cpp b/game/client/kbt_vr_psy/interactable.cpp new file mode 100644 index 0000000..e69de29 diff --git a/game/client/kbt_vr_psy/materials.cpp b/game/client/kbt_vr_psy/materials.cpp new file mode 100644 index 0000000..15731ad --- /dev/null +++ b/game/client/kbt_vr_psy/materials.cpp @@ -0,0 +1,39 @@ +#include "materials.h" +#include "worldrender.h" +#include "tier0/lib.h" + +class CBasicPBR: public CBaseMaterial +{ +public: + DECLARE_CLASS(CBasicPBR, CBaseMaterial) + DECLARE_DATADESC() + DECLARE_SHADER("game/core/shaders/funny_basic_pbr.shader_c") + virtual void SetUpMesh( MaterialData_t *pData ) override { + pData->m_vAlbedoColor = m_vAlbedo; + pData->m_uAlbedo = m_tAlbedo; + }; + + + FMat::XMFLOAT4 m_vAlbedo = { 1, 1, 1, 1 }; + FMat::XMTexture m_tAlbedo = TEXTURE_NO_TEXTURE; +}; + +BEGIN_DATADESC(CBasicPBR) + DEFINE_KEYFIELD(m_vAlbedo, FIELD_SHADER_COLOR_FLOAT4, "AlbedoMultiplier") + DEFINE_KEYFIELD(m_tAlbedo, FIELD_SHADER_TEXTURE, "AlbedoTexture") +END_DATADESC() +DEFINE_MATERIAL(CBasicPBR, "funny_basic_pbr") + + + +class CBasicError: public CBaseMaterial +{ +public: + DECLARE_CLASS(CBasicError, CBaseMaterial) + DECLARE_DATADESC() + DECLARE_SHADER("game/core/shaders/funny_error.shader_c") +}; + +BEGIN_DATADESC(CBasicError) +END_DATADESC() +DEFINE_MATERIAL(CBasicError, "funny_error") diff --git a/game/client/kbt_vr_psy/observer_http.cpp b/game/client/kbt_vr_psy/observer_http.cpp new file mode 100644 index 0000000..e69de29 diff --git a/game/client/kbt_vr_psy/player.cpp b/game/client/kbt_vr_psy/player.cpp new file mode 100644 index 0000000..2fb4564 --- /dev/null +++ b/game/client/kbt_vr_psy/player.cpp @@ -0,0 +1,25 @@ +#include "baseentity.h" + +class C_KBTPlayer: public C_BaseEntity +{ +public: + DECLARE_CLASS(C_KBTPlayer, C_BaseEntity) + DECLARE_CLIENTCLASS() + + virtual ~C_KBTPlayer() override; + virtual void Precache() override; + virtual void Spawn() override; + void Frame( float fDelta ); +}; + +class C_KBRPlayer_Controller: public C_BaseEntity +{ +public: + DECLARE_CLASS(C_KBTPlayer, C_BaseEntity) + DECLARE_CLIENTCLASS() + + virtual ~C_KBRPlayer_Controller() override; + virtual void Precache() override; + virtual void Spawn() override; + void Frame( float fDelta ); +}; diff --git a/game/client/kbt_vr_psy/stop_button.cpp b/game/client/kbt_vr_psy/stop_button.cpp new file mode 100644 index 0000000..e69de29 diff --git a/game/client/kbt_vr_psy/ui/settings.cpp b/game/client/kbt_vr_psy/ui/settings.cpp new file mode 100644 index 0000000..e69de29 diff --git a/game/client/worldrender.cpp b/game/client/worldrender.cpp index 8ecdd37..e8f59d9 100644 --- a/game/client/worldrender.cpp +++ b/game/client/worldrender.cpp @@ -6,6 +6,108 @@ #include "cglm/mat4.h" #include "game.h" +class CFunnyViewport: public IViewport +{ +public: + virtual void UpdateResolution( uint32_t uX, uint32_t uY ) override; + + virtual IImage *GetRenderImage() override; + virtual IImage *GetDepthImage() override; + virtual IImage *GetNormalImage() override; + + virtual void SetFOV( float f ) override; + virtual void SetPosition( Vector v ) override; + virtual void SetRotation( Quat q ) override; + + virtual uint32_t GetWidth() override; + virtual uint32_t GetHeight() override; + + + IImage *m_pColor = 0; + IImage *m_pNormal = 0; + IImage *m_pWorldCoords = 0; + IImage *m_pDepth = 0; + IImage *m_pColorResolved = 0; + IImage *m_pRenderImage = 0; + + uint32_t m_uX; + uint32_t m_uY; + float m_fFov; + vec3 m_vPos; + versor m_qRot; +}; + +void CFunnyViewport::UpdateResolution( uint32_t uX, uint32_t uY ) +{ + if (m_pColor) + { + g_pRenderContext->DestroyImage(m_pColor); + g_pRenderContext->DestroyImage(m_pNormal); + g_pRenderContext->DestroyImage(m_pWorldCoords); + g_pRenderContext->DestroyImage(m_pDepth); + g_pRenderContext->DestroyImage(m_pColorResolved); + g_pRenderContext->DestroyImage(m_pRenderImage); + } + m_pColor = g_pRenderContext->CreateRenderTarget(uX, uY, IMAGE_FORMAT_RGBA8_UNORM, MULTISAMPLE_TYPE_4_SAMPLES); + m_pNormal = g_pRenderContext->CreateRenderTarget(uX, uY, IMAGE_FORMAT_RGBA16_SNORM, MULTISAMPLE_TYPE_4_SAMPLES); + m_pWorldCoords = g_pRenderContext->CreateRenderTarget(uX, uY, IMAGE_FORMAT_RGBA32_SFLOAT, MULTISAMPLE_TYPE_4_SAMPLES); + m_pDepth = g_pRenderContext->CreateRenderTarget(uX, uY, IMAGE_FORMAT_D32_SFLOAT, MULTISAMPLE_TYPE_4_SAMPLES); + m_pColorResolved = g_pRenderContext->CreateRenderTarget(uX, uY, IMAGE_FORMAT_RGBA8_UNORM, MULTISAMPLE_TYPE_1_SAMPLES); + m_pRenderImage = g_pRenderContext->CreateStorageImage(uX, uY, IMAGE_FORMAT_RGBA16_SFLOAT, MULTISAMPLE_TYPE_1_SAMPLES); + m_uX = uX; + m_uY = uY; +} + +IImage *CFunnyViewport::GetRenderImage() +{ + return m_pRenderImage; +} + +IImage *CFunnyViewport::GetDepthImage() +{ + return m_pDepth; +} + +IImage *CFunnyViewport::GetNormalImage() +{ + return m_pNormal; +} + +void CFunnyViewport::SetFOV( float f ) +{ + m_fFov = f; + +} + +void CFunnyViewport::SetPosition( Vector v ) +{ + m_vPos[0] = v.x; + m_vPos[1] = v.y; + m_vPos[2] = v.z; + +} + +void CFunnyViewport::SetRotation( Quat q ) +{ + m_qRot[0] = q.x; + m_qRot[1] = q.y; + m_qRot[2] = q.z; + m_qRot[3] = q.w; + +} + +uint32_t CFunnyViewport::GetWidth() +{ + return m_uX; +} + +uint32_t CFunnyViewport::GetHeight() +{ + return m_uY; +} + + + struct ViewBuffer_t { mat4 m_matCameraProjection; @@ -122,9 +224,6 @@ public: virtual void Frame( float fDelta ) override; virtual void Shutdown() override; - virtual void SetCameraRotation( Quat vRotation ) override; - virtual void SetCameraPosition( Vector vPosition ) override; - virtual IMesh *CreateMesh( const char *szName ) override; virtual IMeshInstance *CreateInstance( IMesh *pMesh ) override; virtual void DestroyMeshInstance( IMesh *pMesh, IMeshInstance *pInstance ) override; @@ -132,15 +231,12 @@ public: virtual void ConfigureShader( IShader *pShader ) override; + virtual IViewport *CreateViewport( uint32_t uX, uint32_t uY ) override; + virtual void DestroyViewport( IViewport *pViewport ) override; + virtual ITextureArray *GetTextures() override; private: CUtlVector m_pMeshes; - IImage *m_pOutputImage = NULL; - IImage *m_pResolvedOutputImage = NULL; - IImage *m_pDepthImage = NULL; - IImage *m_pNormalImage = NULL; - IImage *m_pWorldSpaceImage = NULL; - IImage *m_pStorageOutputImage = NULL; IRenderCommandList *m_pRasterCommandList = NULL; IBuffer *m_pViewBuffer; ViewBuffer_t *m_pViewBufferData; @@ -152,8 +248,7 @@ private: IComputeShader *m_pPostProcessing; IMaterial *m_pPostProcessingMaterial; - vec3 m_vPos; - versor m_vRot; + CUtlVector m_viewports; }; void CFunnyWorldRenderer::ConfigureShader( IShader *pShader ) @@ -164,7 +259,7 @@ void CFunnyWorldRenderer::ConfigureShader( IShader *pShader ) pShader->AddAttribute(0, 2, VERTEX_FORMAT_XYZ32_SFLOAT, 20); // albedo pShader->AddOutputImage(0, IMAGE_FORMAT_RGBA8_UNORM); - pShader->AddOutputImage(1, IMAGE_FORMAT_RGBA16_SFLOAT); + pShader->AddOutputImage(1, IMAGE_FORMAT_RGBA16_SNORM); pShader->AddOutputImage(2, IMAGE_FORMAT_RGBA32_SFLOAT); pShader->SetMultisampling(MULTISAMPLE_TYPE_4_SAMPLES); @@ -178,43 +273,6 @@ IWorldRenderer *g_pWorldRenderer = &s_renderer; void CFunnyWorldRenderer::Init() { - m_pOutputImage = g_pRenderContext->CreateRenderTarget( - 100, - 100, - IMAGE_FORMAT_RGBA8_UNORM, - MULTISAMPLE_TYPE_4_SAMPLES - ); - m_pResolvedOutputImage = g_pRenderContext->CreateRenderTarget( - 100, - 100, - IMAGE_FORMAT_RGBA8_UNORM, - MULTISAMPLE_TYPE_1_SAMPLES - ); - m_pNormalImage = g_pRenderContext->CreateRenderTarget( - 100, - 100, - IMAGE_FORMAT_RGBA16_SFLOAT, - MULTISAMPLE_TYPE_4_SAMPLES - ); - m_pWorldSpaceImage = g_pRenderContext->CreateRenderTarget( - 100, - 100, - IMAGE_FORMAT_RGBA32_SFLOAT, - MULTISAMPLE_TYPE_4_SAMPLES - ); - - m_pDepthImage = g_pRenderContext->CreateRenderTarget( - 100, - 100, - IMAGE_FORMAT_D32_SFLOAT, - MULTISAMPLE_TYPE_4_SAMPLES - ); - m_pStorageOutputImage = g_pRenderContext->CreateStorageImage( - 100, - 100, - IMAGE_FORMAT_RGBA16_SFLOAT, - MULTISAMPLE_TYPE_1_SAMPLES - ); m_pRasterShader = g_pRenderContext->CreateShader("game/core/shaders/mesh_raster.shader_c"); ConfigureShader(m_pRasterShader); m_pRasterShader->Build(); @@ -232,8 +290,6 @@ void CFunnyWorldRenderer::Init() m_pPostProcessing->Build(); m_pPostProcessingMaterial = g_pRenderContext->CreateMaterial(m_pPostProcessing); - - g_pMainWindow->SetOutputImage(m_pResolvedOutputImage); } void CFunnyWorldRenderer::Tick( float fDelta ) @@ -242,136 +298,94 @@ void CFunnyWorldRenderer::Tick( float fDelta ) void CFunnyWorldRenderer::Frame( float fDelta ) { - uint32_t uWidth = g_pMainWindow->GetRenderWidth(); - uint32_t uHeight = g_pMainWindow->GetRenderHeight(); - mat4 matCamera; - mat4 matCamera2; - glm_mat4_identity(matCamera); - glm_mat4_identity(matCamera2); - glm_translate(matCamera2, m_vPos); - glm_quat_rotate(matCamera2, m_vRot, matCamera2); - glm_mat4_inv(matCamera2, matCamera2); - glm_perspective(glm_rad(75), uWidth/(float)uHeight, 0.01, 10000, matCamera); - glm_mul(matCamera, matCamera2, matCamera); - m_pViewBufferData = (ViewBuffer_t*)m_pViewBuffer->Map(); - m_pViewBuffer->Lock(); - V_memcpy(&m_pViewBufferData->m_matCameraProjection, matCamera, sizeof(matCamera)); - V_memcpy(&m_pViewBufferData->m_vCameraPosition, m_vPos, sizeof(vec3)); - m_pViewBuffer->Unlock(); - m_pViewBuffer->Unmap(); - - if (g_pMainWindow->BRenderSizeUpdated()) + for (auto &v: m_viewports) { - g_pRenderContext->DestroyImage(m_pOutputImage); - g_pRenderContext->DestroyImage(m_pResolvedOutputImage); - g_pRenderContext->DestroyImage(m_pNormalImage); - g_pRenderContext->DestroyImage(m_pWorldSpaceImage); - g_pRenderContext->DestroyImage(m_pDepthImage); - g_pRenderContext->DestroyImage(m_pStorageOutputImage); + uint32_t uWidth = v->m_uX; + uint32_t uHeight = v->m_uY; + mat4 matCamera; + mat4 matCamera2; + glm_mat4_identity(matCamera); + glm_mat4_identity(matCamera2); + glm_translate(matCamera2, v->m_vPos); + glm_quat_rotate(matCamera2, v->m_qRot, matCamera2); + glm_mat4_inv(matCamera2, matCamera2); + glm_perspective(glm_rad(v->m_fFov), uWidth/(float)uHeight, 0.01, 10000, matCamera); + glm_mul(matCamera, matCamera2, matCamera); + m_pViewBufferData = (ViewBuffer_t*)m_pViewBuffer->Map(); + m_pViewBuffer->Lock(); + V_memcpy(&m_pViewBufferData->m_matCameraProjection, matCamera, sizeof(matCamera)); + V_memcpy(&m_pViewBufferData->m_vCameraPosition, v->m_vPos, sizeof(vec3)); + m_pViewBuffer->Unlock(); + m_pViewBuffer->Unmap(); - m_pOutputImage = g_pRenderContext->CreateRenderTarget( - g_pMainWindow->GetRenderWidth(), - g_pMainWindow->GetRenderHeight(), - IMAGE_FORMAT_RGBA8_UNORM, - MULTISAMPLE_TYPE_4_SAMPLES); - m_pResolvedOutputImage = g_pRenderContext->CreateRenderTarget( - g_pMainWindow->GetRenderWidth(), - g_pMainWindow->GetRenderHeight(), - IMAGE_FORMAT_RGBA8_UNORM, - MULTISAMPLE_TYPE_1_SAMPLES); - - m_pNormalImage = g_pRenderContext->CreateRenderTarget( - g_pMainWindow->GetRenderWidth(), - g_pMainWindow->GetRenderHeight(), - IMAGE_FORMAT_RGBA16_SFLOAT, - MULTISAMPLE_TYPE_4_SAMPLES - ); - m_pWorldSpaceImage = g_pRenderContext->CreateRenderTarget( - g_pMainWindow->GetRenderWidth(), - g_pMainWindow->GetRenderHeight(), - IMAGE_FORMAT_RGBA32_SFLOAT, - MULTISAMPLE_TYPE_4_SAMPLES - ); - m_pDepthImage = g_pRenderContext->CreateRenderTarget( - g_pMainWindow->GetRenderWidth(), - g_pMainWindow->GetRenderHeight(), - IMAGE_FORMAT_D32_SFLOAT, - MULTISAMPLE_TYPE_4_SAMPLES); - m_pStorageOutputImage = g_pRenderContext->CreateStorageImage( - g_pMainWindow->GetRenderWidth(), - g_pMainWindow->GetRenderHeight(), - IMAGE_FORMAT_RGBA16_SFLOAT, - MULTISAMPLE_TYPE_1_SAMPLES - ); - g_pMainWindow->SetOutputImage(m_pStorageOutputImage); - } - m_pRasterCommandList->StartRecording(); - m_pRasterCommandList->SetRenderResolution(uWidth, uHeight); - m_pRasterCommandList->SetRenderTarget(0, m_pOutputImage); - m_pRasterCommandList->SetRenderTarget(1, m_pNormalImage); - m_pRasterCommandList->SetRenderTarget(2, m_pWorldSpaceImage); - m_pRasterCommandList->SetDepthTarget(m_pDepthImage); - m_pRasterCommandList->SetViewport(0, 0, uWidth, uHeight, 0, 1); - m_pRasterCommandList->SetScissors(0, 0, uWidth, uHeight); - m_pRasterCommandList->SetClearColor(0, 0, 0, 0, 0); - m_pRasterCommandList->SetClearColor(1, 0, 0, 0, 0); - m_pRasterCommandList->SetClearColor(2, 0, 0, 0, 0); - m_pRasterCommandList->SetClearDepth(1); - m_pRasterCommandList->SetLoadStoreModes(0, LOAD_MODE_CLEAR, STORE_MODE_STORE); - m_pRasterCommandList->SetLoadStoreModes(1, LOAD_MODE_CLEAR, STORE_MODE_STORE); - m_pRasterCommandList->SetLoadStoreModes(2, LOAD_MODE_CLEAR, STORE_MODE_STORE); - uint32_t uTotalMeshes = 0; - uint32_t u = 0; - for ( auto mesh: m_pMeshes) - { - uTotalMeshes+=mesh->m_instances.GetSize(); - } - if (!uTotalMeshes) - return; - IBuffer *pDataBuffer = g_pRenderContext->CreateStorageBuffer(uTotalMeshes*sizeof(PerMeshData_t)); - pDataBuffer->Lock(); - void *pData = pDataBuffer->Map(); - for ( auto mesh: m_pMeshes) - { - if (mesh->m_instances.GetSize()==0) - continue; - for ( uint32_t i = 0; i < mesh->m_instances.GetSize(); i++ ) + m_pRasterCommandList->StartRecording(); + m_pRasterCommandList->SetRenderResolution(uWidth, uHeight); + m_pRasterCommandList->SetRenderTarget(0, v->m_pColor); + m_pRasterCommandList->SetRenderTarget(1, v->m_pNormal); + m_pRasterCommandList->SetRenderTarget(2, v->m_pWorldCoords); + m_pRasterCommandList->SetDepthTarget(v->m_pDepth); + m_pRasterCommandList->SetViewport(0, 0, uWidth, uHeight, 0, 1); + m_pRasterCommandList->SetScissors(0, 0, uWidth, uHeight); + m_pRasterCommandList->SetClearColor(0, 0, 0, 0, 0); + m_pRasterCommandList->SetClearColor(1, 0, 0, 0, 0); + m_pRasterCommandList->SetClearColor(2, 0, 0, 0, 0); + m_pRasterCommandList->SetClearDepth(1); + m_pRasterCommandList->SetLoadStoreModes(0, LOAD_MODE_CLEAR, STORE_MODE_STORE); + m_pRasterCommandList->SetLoadStoreModes(1, LOAD_MODE_CLEAR, STORE_MODE_STORE); + m_pRasterCommandList->SetLoadStoreModes(2, LOAD_MODE_CLEAR, STORE_MODE_STORE); + uint32_t uTotalMeshes = 0; + uint32_t u = 0; + for ( auto mesh: m_pMeshes) { - mesh->m_instances[i]->Frame(); - V_memcpy(&((PerMeshData_t*)pData)[i+u], &mesh->m_instances[i]->m_data, sizeof(PerMeshData_t)); + uTotalMeshes+=mesh->m_instances.GetSize(); } - u+=mesh->m_instances.GetSize(); + if (!uTotalMeshes) + return; + IBuffer *pDataBuffer = g_pRenderContext->CreateStorageBuffer(uTotalMeshes*sizeof(PerMeshData_t)); + pDataBuffer->Lock(); + void *pData = pDataBuffer->Map(); + for ( auto mesh: m_pMeshes) + { + if (mesh->m_instances.GetSize()==0) + continue; + for ( uint32_t i = 0; i < mesh->m_instances.GetSize(); i++ ) + { + mesh->m_instances[i]->Frame(); + V_memcpy(&((PerMeshData_t*)pData)[i+u], &mesh->m_instances[i]->m_data, sizeof(PerMeshData_t)); + } + u+=mesh->m_instances.GetSize(); + } + pDataBuffer->Unmap(); + pDataBuffer->Unlock(); + g_pRenderContext->DestroyBuffer(pDataBuffer); + + m_pRasterMaterial->VSSetConstantsBuffer(0, m_pViewBuffer); + m_pRasterMaterial->VSSetConstantsBuffer(1, pDataBuffer); + m_pRasterMaterial->PSSetTextureArray(1, m_pTextures); + + m_pRasterCommandList->SetMaterial(m_pRasterMaterial); + u = 0; + for ( auto mesh: m_pMeshes) + { + if (mesh->m_instances.GetSize()==0) + continue; + m_pRasterCommandList->SetVertexBuffer(0, mesh->m_pVertexBuffer); + m_pRasterCommandList->DrawPrimitives(mesh->m_pVertexBuffer->GetSize()/32, 0, mesh->m_instances.GetSize(), u); + u += mesh->m_instances.GetSize(); + } + + m_pRasterCommandList->ResolveImage(v->m_pColor, v->m_pColorResolved); + + m_pPostProcessingMaterial->CSSetTexture(0, 0, v->m_pColorResolved); + m_pPostProcessingMaterial->CSSetTexture(1, 0, v->m_pRenderImage); + m_pRasterCommandList->SetMaterial(m_pPostProcessingMaterial); + m_pRasterCommandList->Barrier(v->m_pColorResolved, true, false); + m_pRasterCommandList->Barrier(v->m_pRenderImage, false, true); + m_pRasterCommandList->DispatchCompute(uWidth, uHeight, 1); + m_pRasterCommandList->EndRecording(); + + g_pRenderContext->SubmitCommandList(m_pRasterCommandList); } - pDataBuffer->Unmap(); - pDataBuffer->Unlock(); - g_pRenderContext->DestroyBuffer(pDataBuffer); - - m_pRasterMaterial->VSSetConstantsBuffer(0, m_pViewBuffer); - m_pRasterMaterial->VSSetConstantsBuffer(1, pDataBuffer); - m_pRasterMaterial->PSSetTextureArray(1, m_pTextures); - - m_pRasterCommandList->SetMaterial(m_pRasterMaterial); - u = 0; - for ( auto mesh: m_pMeshes) - { - if (mesh->m_instances.GetSize()==0) - continue; - m_pRasterCommandList->SetVertexBuffer(0, mesh->m_pVertexBuffer); - m_pRasterCommandList->DrawPrimitives(mesh->m_pVertexBuffer->GetSize()/32, 0, mesh->m_instances.GetSize(), u); - u += mesh->m_instances.GetSize(); - } - - m_pRasterCommandList->ResolveImage(m_pOutputImage, m_pResolvedOutputImage); - - m_pPostProcessingMaterial->CSSetTexture(0, 0, m_pResolvedOutputImage); - m_pPostProcessingMaterial->CSSetTexture(1, 0, m_pStorageOutputImage); - m_pRasterCommandList->SetMaterial(m_pPostProcessingMaterial); - m_pRasterCommandList->Barrier(m_pResolvedOutputImage, true, false); - m_pRasterCommandList->Barrier(m_pStorageOutputImage, false, true); - m_pRasterCommandList->DispatchCompute(uWidth, uHeight, 1); - m_pRasterCommandList->EndRecording(); - - g_pRenderContext->SubmitCommandList(m_pRasterCommandList); } void CFunnyWorldRenderer::Shutdown() @@ -379,23 +393,6 @@ void CFunnyWorldRenderer::Shutdown() } - -void CFunnyWorldRenderer::SetCameraRotation( Quat vRotation ) -{ - m_vRot[0] = vRotation.x; - m_vRot[1] = vRotation.y; - m_vRot[2] = vRotation.z; - m_vRot[3] = vRotation.w; -} - -void CFunnyWorldRenderer::SetCameraPosition( Vector vPosition ) -{ - m_vPos[0] = vPosition.x; - m_vPos[1] = vPosition.y; - m_vPos[2] = vPosition.z; -} - - IMesh *CFunnyWorldRenderer::CreateMesh( const char *szName ) { CFunnyMesh *pMesh = new CFunnyMesh; @@ -440,3 +437,26 @@ ITextureArray *CFunnyWorldRenderer::GetTextures() return m_pTextures; } + +IViewport *CFunnyWorldRenderer::CreateViewport( uint32_t uX, uint32_t uY ) +{ + CFunnyViewport *pViewport = new CFunnyViewport; + pViewport->UpdateResolution(uX, uY); + m_viewports.AppendTail(pViewport); + return pViewport; +} + +void CFunnyWorldRenderer::DestroyViewport( IViewport *pViewport ) +{ + for ( uint32_t i = 0; i < m_viewports.GetSize(); i++ ) + { + if (m_viewports[i] == pViewport) + { + m_viewports.RemoveAt(i); + delete (CFunnyViewport*)pViewport; + return; + } + } +} + + diff --git a/game/client/worldrender.h b/game/client/worldrender.h index 83eb9be..c93d4a0 100644 --- a/game/client/worldrender.h +++ b/game/client/worldrender.h @@ -9,6 +9,22 @@ #include "cglm/mat4.h" +abstract_class IViewport +{ +public: + virtual void UpdateResolution( uint32_t uX, uint32_t uY ) = 0; + + virtual IImage *GetRenderImage() = 0; + virtual IImage *GetDepthImage() = 0; + virtual IImage *GetNormalImage() = 0; + + virtual void SetFOV( float f ) = 0; + virtual void SetPosition( Vector v ) = 0; + virtual void SetRotation( Quat q ) = 0; + + virtual uint32_t GetWidth() = 0; + virtual uint32_t GetHeight() = 0; +}; abstract_class IMesh @@ -27,8 +43,6 @@ public: virtual void SetColor( Vector vColor ) = 0; virtual void SetRadius( Vector vColor ) = 0; virtual void SetPosition( Vector vPosition ) = 0; - virtual void SetRotation( Quat vRotation ) = 0; - virtual void SetScale( Vector vScale ) = 0; }; abstract_class IMeshInstance @@ -43,19 +57,20 @@ public: abstract_class IWorldRenderer: public IGameSystem { public: - virtual void SetCameraRotation( Quat vRotation ) = 0; - virtual void SetCameraPosition( Vector vPosition ) = 0; - virtual IMesh *CreateMesh( const char *szName ) = 0; virtual IMeshInstance *CreateInstance( IMesh *pMesh ) = 0; virtual void DestroyMeshInstance( IMesh *pMesh, IMeshInstance *pInstance ) = 0; virtual void DestroyMesh( IMesh *pMesh ) = 0; + virtual IViewport *CreateViewport( uint32_t uX, uint32_t uY ) = 0; + virtual void DestroyViewport( IViewport *pViewport ) = 0; + virtual void ConfigureShader( IShader *pShader ) = 0; virtual ITextureArray *GetTextures() = 0; }; + extern IWorldRenderer *g_pWorldRenderer; #endif diff --git a/game/server/build.cpp b/game/server/build.cpp index 1449d93..2884c93 100644 --- a/game/server/build.cpp +++ b/game/server/build.cpp @@ -9,27 +9,48 @@ ADD_DEPENDENCY_BUILD_FILE(cfg, ROOT"buildcfg.cpp"); ADD_DEPENDENCY_BUILD_FILE(tier0, FUNNYSTDLIB"tier0/build.cpp"); ADD_DEPENDENCY_BUILD_FILE(tier1, FUNNYSTDLIB"tier1/build.cpp"); ADD_DEPENDENCY_BUILD_FILE(tier2, FUNNYSTDLIB"tier2/build.cpp"); + +CUtlVector milmoba = { + "../shared/game.cpp", + "../shared/boneanimation.cpp", + + "game.cpp", + "assetmgr.cpp", + "worldsystem.cpp", + + "entitysystem.cpp", + "baseentity.cpp", + "basemodelentity.cpp", + "physicsprop.cpp", + + "milmoba/player.cpp", +}; +CUtlVector kbt_vt_psy = { + "../shared/game.cpp", + "../shared/boneanimation.cpp", + + "game.cpp", + "assetmgr.cpp", + "worldsystem.cpp", + + "entitysystem.cpp", + "baseentity.cpp", + "basemodelentity.cpp", + "physicsprop.cpp", + + "kbt_vr_psy/events.cpp", + "kbt_vr_psy/pickable.cpp", + "kbt_vr_psy/interactable.cpp", + "kbt_vr_psy/player.cpp", +}; + DECLARE_BUILD_STAGE(Server) { CProject_t compileProject = {}; LinkProject_t ldProject = {}; compileProject.m_szName = "server"; - compileProject.files = { - "../shared/game.cpp", - "../shared/boneanimation.cpp", - - "game.cpp", - "assetmgr.cpp", - "worldsystem.cpp", - - "entitysystem.cpp", - "baseentity.cpp", - "basemodelentity.cpp", - "physicsprop.cpp", - - "milmoba/player.cpp", - }; + compileProject.files = milmoba; compileProject.includeDirectories = { "../../public", ".", diff --git a/game/server/kbt_vr_psy/experience.cpp b/game/server/kbt_vr_psy/experience.cpp new file mode 100644 index 0000000..e69de29 diff --git a/game/server/kbt_vr_psy/interactable.cpp b/game/server/kbt_vr_psy/interactable.cpp new file mode 100644 index 0000000..e69de29 diff --git a/game/server/kbt_vr_psy/observer_ingame.cpp b/game/server/kbt_vr_psy/observer_ingame.cpp new file mode 100644 index 0000000..e69de29 diff --git a/game/server/kbt_vr_psy/player.cpp b/game/server/kbt_vr_psy/player.cpp new file mode 100644 index 0000000..e69de29 diff --git a/launcher/launcher.cpp b/launcher/launcher.cpp index 533171c..62a08fd 100644 --- a/launcher/launcher.cpp +++ b/launcher/launcher.cpp @@ -37,6 +37,7 @@ void *pEngineLib = NULL; void *pTier0Lib = NULL; typedef void (*EngineMainFn)(int argc, char** argv); EngineMainFn pEngineMain; +extern void FunnyMain(int argc, char** argv); int main( int argc, char **argv ) { #ifdef __linux__ @@ -99,6 +100,6 @@ int main( int argc, char **argv ) { SetCurrentDirectoryA(szLauncherPath); pEngineMain(argc, argv); #endif - //FunnyMain(argc, argv); - //return 0; + FunnyMain(argc, argv); + return 0; }; diff --git a/materialsystem/gamewindow_sdl.cpp b/materialsystem/gamewindow_sdl.cpp index b6622ef..6aa5e74 100644 --- a/materialsystem/gamewindow_sdl.cpp +++ b/materialsystem/gamewindow_sdl.cpp @@ -46,9 +46,9 @@ public: private: - VkSurfaceKHR m_hSurface; - SDL_Window *m_pWindow; - IImage *m_pOutputImage; + VkSurfaceKHR m_hSurface = NULL; + SDL_Window *m_pWindow = NULL; + IImage *m_pOutputImage = NULL; }; diff --git a/materialsystem/vulkan/rendercontext.cpp b/materialsystem/vulkan/rendercontext.cpp index fcae491..d394f72 100644 --- a/materialsystem/vulkan/rendercontext.cpp +++ b/materialsystem/vulkan/rendercontext.cpp @@ -750,7 +750,6 @@ IImage *CVkRenderContext::CreateImageFromVkImage( void *pVkImage, uint32_t x, ui } VkPipelineLayout g_pLibraryEmptyLayout; -static IVkCommandBuffer *s_pPresentCommandBuffer; void CVkRenderContext::Init() { @@ -984,13 +983,12 @@ void CVkRenderContext::Frame( float fDeltaTime ) if (m_pXRManager) m_pXRManager->PreRender(); + IRenderCommandList *pList = CreateCommandList(); + pList->StartRecording(); - s_pPresentCommandBuffer = m_pCommandBufferManager->CreateCommandBuffer(); - s_pPresentCommandBuffer->Reset(); double a = Plat_GetTime(); i = 0; - CVkEmptyCommand *pEmptyCommand = CREATE_COMMAND(m_pCommandBufferManager, Empty); for ( auto &s: m_renderWindows ) { @@ -998,30 +996,24 @@ void CVkRenderContext::Frame( float fDeltaTime ) CVkBlitCommand *pBlitCommand = NULL; if (s.m_pWindow->GetOutputImage()) { - pBlitCommand = CREATE_COMMAND(m_pCommandBufferManager, Blit); - pBlitCommand->AddDependency(s.m_pWindow->GetOutputImage(), DEPENDENCY_MODE_BLIT_IMAGE_SOURCE); - pBlitCommand->AddDependency((IRenderingObject*)s.m_images[uSwapchainImageIndexes[i]], DEPENDENCY_MODE_BLIT_IMAGE_DESTINATION); - pBlitCommand->stInputImage.m_eObjectType = FRAME_OBJECT_TYPE_SINGLE; - pBlitCommand->stInputImage.m_pSingle = s.m_pWindow->GetOutputImage(); - pBlitCommand->stOutputImage.m_eObjectType = FRAME_OBJECT_TYPE_SINGLE; - pBlitCommand->stOutputImage.m_pSingle = (IRenderingObject*)s.m_images[uSwapchainImageIndexes[i]]; - pBlitCommand->iSrcMax[0] = s.m_pWindow->GetOutputImage()->GetImageWidth(); - pBlitCommand->iSrcMax[1] = s.m_pWindow->GetOutputImage()->GetImageHeight(); - pBlitCommand->iSrcMax[2] = 1; - pBlitCommand->iDstMax[0] = s.m_pWindow->GetRenderWidth(); - pBlitCommand->iDstMax[1] = s.m_pWindow->GetRenderHeight(); - pBlitCommand->iDstMax[2] = 1; - pEmptyCommand->AddDependency((IRenderingObject*)s.m_images[uSwapchainImageIndexes[i]], DEPENDENCY_MODE_IMAGE_PRESENT); + ImageSector_t src = {}; + src.m_iWidth = s.m_pWindow->GetOutputImage()->GetImageWidth(); + src.m_iHeight = s.m_pWindow->GetOutputImage()->GetImageHeight(); + src.m_iX = 0; + src.m_iY = 0; + ImageSector_t dst = {}; + dst.m_iWidth = s.m_pWindow->GetRenderWidth(); + dst.m_iHeight = s.m_pWindow->GetRenderHeight(); + dst.m_iX = 0; + dst.m_iY = 0; + pList->BlitImageToImage(s.m_pWindow->GetOutputImage(), src, s.m_images[uSwapchainImageIndexes[i]], dst); } - if (pBlitCommand != NULL) - s_pPresentCommandBuffer->AddCommand(pBlitCommand); i++; } - s_pPresentCommandBuffer->AddCommand(pEmptyCommand); - - s_pPresentCommandBuffer->Render(); - s_pPresentCommandBuffer->Submit(0); + pList->EndRecording(); + SubmitCommandList(pList); + DestroyCommandList(pList); if (m_pXRManager) m_pXRManager->CopySwapchain(); @@ -1066,13 +1058,22 @@ void CVkRenderContext::Frame( float fDeltaTime ) { delete a; } + for (auto &a: m_scheduledRemovalImages) + { + delete a; + } + for (auto &a: m_scheduledRemovalTextureArrays) + { + delete a; + } for (auto &a: m_scheduledRemovalLists) { delete a; } m_scheduledRemovalLists = {}; + m_scheduledRemovalImages = {}; + m_scheduledRemovalTextureArrays = {}; m_scheduledRemovalBuffers = {}; - m_pCommandBufferManager->FreeCommandBufferWithCommands(s_pPresentCommandBuffer); } diff --git a/materialsystem/vulkan/shader.cpp b/materialsystem/vulkan/shader.cpp index 6f3778a..d83726f 100644 --- a/materialsystem/vulkan/shader.cpp +++ b/materialsystem/vulkan/shader.cpp @@ -44,6 +44,24 @@ void CVkShader::DisablePixelShader( bool bDisable ) { } +void CVkShader::SetBlendingMode( int iImageIndex, + EBlendingFactor eSrcColor, + EBlendingFactor eDstColor, + EBlendingOp eColorOp, + EBlendingFactor eSrcAlpha, + EBlendingFactor eDstAlpha, + EBlendingOp eAlphaOp + ) +{ + m_formats[iImageIndex].eSrcColor = eSrcColor; + m_formats[iImageIndex].eDstColor = eDstColor; + m_formats[iImageIndex].eColorOp = eColorOp; + + m_formats[iImageIndex].eSrcAlpha = eSrcAlpha; + m_formats[iImageIndex].eDstAlpha = eDstAlpha; + m_formats[iImageIndex].eAlphaOp = eAlphaOp; + +} void CVkShader::Build() diff --git a/materialsystem/vulkan/vulkan_state.h b/materialsystem/vulkan/vulkan_state.h index 4a575bd..5ffde23 100644 --- a/materialsystem/vulkan/vulkan_state.h +++ b/materialsystem/vulkan/vulkan_state.h @@ -276,6 +276,12 @@ struct VkOutputImageConfig_t { VkFormat m_eFormat; bool m_bIsBlendingEnabled; + EBlendingFactor eSrcColor; + EBlendingFactor eDstColor; + EBlendingOp eColorOp; + EBlendingFactor eSrcAlpha; + EBlendingFactor eDstAlpha; + EBlendingOp eAlphaOp; }; class CVkShader : public IShader @@ -289,6 +295,15 @@ public: virtual void SetDepthImage( EImageFormat eFormat ) override; virtual void SetMultisampling( EMultisampleType eFormat ) override; virtual void DisablePixelShader( bool bDisable ) override; + virtual void SetBlendingMode( int iImageIndex, + EBlendingFactor eSrcColor, + EBlendingFactor eDstColor, + EBlendingOp eColorOp, + EBlendingFactor eSrcAlpha, + EBlendingFactor eDstAlpha, + EBlendingOp eAlphaOp + ) override; + virtual void Build() override; VkPipeline m_hPipeline = NULL; diff --git a/public/materialsystem/imaterialsystem.h b/public/materialsystem/imaterialsystem.h index c95761b..3ce44c0 100644 --- a/public/materialsystem/imaterialsystem.h +++ b/public/materialsystem/imaterialsystem.h @@ -126,6 +126,37 @@ enum ETopologyMode TOPOLOGY_MODE_TRIANGLE_STRIP, }; +enum EBlendingFactor +{ + BLENDING_FACTOR_ZERO, + BLENDING_FACTOR_ONE, + BLENDING_FACTOR_SRC_COLOR, + BLENDING_FACTOR_ONE_MINUS_SRC_COLOR, + BLENDING_FACTOR_DST_COLOR, + BLENDING_FACTOR_ONE_MINUS_DST_COLOR, + BLENDING_FACTOR_SRC_ALPHA, + BLENDING_FACTOR_ONE_MINUS_SRC_ALPHA , + BLENDING_FACTOR_DST_ALPHA, + BLENDING_FACTOR_ONE_MINUS_DST_ALPHA, + BLENDING_FACTOR_CONSTANT_COLOR, + BLENDING_FACTOR_ONE_MINUS_CONSTANT_COLOR , + BLENDING_FACTOR_CONSTANT_ALPHA, + BLENDING_FACTOR_ONE_MINUS_CONSTANT_ALPHA, + BLENDING_FACTOR_SRC_ALPHA_SATURATE, + BLENDING_FACTOR_SRC1_COLOR, + BLENDING_FACTOR_ONE_MINUS_SRC1_COLOR, + BLENDING_FACTOR_SRC1_ALPHA, + BLENDING_FACTOR_ONE_MINUS_SRC1_ALPHA, +}; + +enum EBlendingOp +{ + BLENDING_OP_ADD, + BLENDING_OP_SUBTRACT, + BLENDING_OP_REVERSE_SUBTRACT, + BLENDING_OP_MIN, + BLENDING_OP_MAX, +}; //----------------------------------------------------------------------------- // Basic rendering object @@ -225,6 +256,14 @@ public: virtual void SetDepthImage( EImageFormat eFormat ) = 0; virtual void SetMultisampling( EMultisampleType eFormat ) = 0; virtual void DisablePixelShader( bool bDisable) = 0; + virtual void SetBlendingMode( int iImageIndex, + EBlendingFactor eSrcColor, + EBlendingFactor eDstColor, + EBlendingOp eColorOp, + EBlendingFactor eSrcAlpha, + EBlendingFactor eDstAlpha, + EBlendingOp eAlphaOp + ) = 0; }; abstract_class IComputeShader: public IBaseShader