mouse controls, fixed texture loading

This commit is contained in:
2026-04-27 22:33:40 +03:00
parent cbcfdce047
commit 9569555347
31 changed files with 112 additions and 40 deletions

View File

@@ -33,8 +33,8 @@ public:
SDL_WindowID WindowID();
KeyCallbackFn m_fnKeyCallback;
AxisCallbackFn m_fnAxisCallback;
KeyCallbackFn m_fnKeyCallback = NULL;
AxisCallbackFn m_fnAxisCallback = NULL;
bool m_bWindowSizeUpdated;
uint32_t m_uRenderWidth;
@@ -55,6 +55,7 @@ void CSDLGameWindow::Init()
Plat_FatalErrorFunc("SDL_CreateWindow: %s\n", SDL_GetError());
m_uRenderWidth = 1280;
m_uRenderHeight = 720;
SDL_SetWindowRelativeMouseMode(m_pWindow, true);
}
void CSDLGameWindow::Shutdown()
@@ -231,43 +232,40 @@ void CSDLGameWindowManager::Frame( float fDelta )
}
while (SDL_PollEvent(&event))
{
for (auto a: m_pWindows)
{
if (a->WindowID() != event.window.windowID)
break;
pWindow = a;
break;
}
switch (event.type)
{
case SDL_EVENT_WINDOW_PIXEL_SIZE_CHANGED:
for (auto a: m_pWindows)
{
if (a->WindowID() != event.window.windowID)
break;
pWindow = a;
break;
}
pWindow->m_bWindowSizeUpdated = true;
pWindow->m_uRenderWidth = event.window.data1;
pWindow->m_uRenderHeight = event.window.data2;
break;
case SDL_EVENT_KEY_UP:
for (auto a: m_pWindows)
{
if (a->WindowID() != event.window.windowID)
break;
pWindow = a;
break;
}
if (pWindow->m_fnKeyCallback)
pWindow->m_fnKeyCallback(k_EInputDevice_Keyboard, GetKeyButton(event.key.key), false);
break;
case SDL_EVENT_KEY_DOWN:
for (auto a: m_pWindows)
{
if (a->WindowID() != event.window.windowID)
break;
pWindow = a;
break;
}
if (pWindow->m_fnKeyCallback)
pWindow->m_fnKeyCallback(k_EInputDevice_Keyboard, GetKeyButton(event.key.key), true);
break;
case SDL_EVENT_MOUSE_MOTION:
if (pWindow->m_fnAxisCallback)
{
pWindow->m_fnAxisCallback(k_EInputDevice_Mouse, k_EInputAxis_MouseX, event.motion.xrel);
pWindow->m_fnAxisCallback(k_EInputDevice_Mouse, k_EInputAxis_MouseY, event.motion.yrel);
}
break;
case SDL_EVENT_QUIT:
Plat_Exit(0);
break;

View File

@@ -142,6 +142,7 @@ void CVkMaterial::SetShaderResource( uint32_t uRegister, uint32_t uSet, IRenderi
writes[1].descriptorCount = 128;
writes[1].pImageInfo = stWrites;
vkUpdateDescriptorSets(m_pVkShader->m_hDevice, 2, writes, 0, 0);
m_pTextureArray = pArray;
}
}

View File

@@ -109,6 +109,10 @@ void CVkRenderCommandList::SetMaterial( IMaterial *pMaterial )
CVkSetShaderDataCommand *pSetShaderData = CREATE_COMMAND(m_pCommandBufferManager, SetShaderData);
pSetShaderData->pShaderData = pMaterial;
{
CVkTextureArray *pArray = (CVkTextureArray*)((CVkMaterial*)pMaterial)->m_pTextureArray;
}
m_pCurrentMaterialBuffer->AddCommand(pSetShaderData);
CVkSetScissorsCommand *pScissorsCommand = CREATE_COMMAND(m_pCommandBufferManager, SetScissors);

View File

@@ -397,11 +397,11 @@ uint32_t CVkTextureArray::CreateTexture( uint32_t i, const char *szPath )
IBuffer *pBuffer = m_pRenderContext->CreateStorageBuffer(uWidth*uHeight*4);
pBuffer->Lock();
void *pData = pBuffer->Map();
V_memcpy(pData, pImg, uWidth*uHeight*uChannels);
V_memcpy(pData, pImg, uWidth*uHeight*4);
pBuffer->Unmap();
pBuffer->Unlock();
vkDeviceWaitIdle(s_vkDevice);
IImage *pImage = m_pRenderContext->CreateTexture(uWidth, uHeight, IMAGE_FORMAT_RGBA8_UNORM, MULTISAMPLE_TYPE_NONE);
IImage *pCompressedImage = m_pRenderContext->CreateTexture(uWidth, uHeight, IMAGE_FORMAT_BC1, MULTISAMPLE_TYPE_NONE);
m_pImages[i] = (CVkImage*)pImage;
stbi_image_free(pImg);

View File

@@ -338,6 +338,7 @@ private:
};
CUtlVector<ShaderBinding_t> m_callableShaders = {};
};
#define MAX_TEXTURES 4096
class CVkTextureArray: public ITextureArray
{
@@ -357,7 +358,7 @@ public:
IRenderContext *m_pRenderContext;
IVkCommandBufferManager *m_pCommandBufferManager;
VkSampler m_hSampler;
CVkImage *m_pImages[128];
CVkImage *m_pImages[MAX_TEXTURES];
};
class CVkMaterial: public IMaterial
@@ -377,6 +378,7 @@ public:
CVkShader *m_pVkShader;
CUtlVector<VkDescriptorSet> m_hSets;
ITextureArray *m_pTextureArray;
private:
VkDescriptorPool m_hPool;
CUtlVector<VkWriteDescriptorSet> m_writes = {};