diff --git a/engines/basic/src/delta_engine.cpp b/engines/basic/src/delta_engine.cpp index 8de54a08..40acca74 100644 --- a/engines/basic/src/delta_engine.cpp +++ b/engines/basic/src/delta_engine.cpp @@ -119,7 +119,7 @@ ysError dbasic::DeltaEngine::CreateGameWindow(const char *title, void *instance, // Create the game window YDS_NESTED_ERROR_CALL(m_windowSystem->NewWindow(&m_gameWindow)); - YDS_NESTED_ERROR_CALL(m_gameWindow->InitializeWindow(nullptr, title, ysWindow::WindowStyle::WINDOWED, 0, 0, 1920, 1080, mainMonitor)); + YDS_NESTED_ERROR_CALL(m_gameWindow->InitializeWindow(nullptr, title, ysWindow::WindowStyle::Windowed, 0, 0, 1920, 1080, mainMonitor)); m_gameWindow->AttachEventHandler(&m_windowHandler); // Create the graphics device @@ -140,6 +140,8 @@ ysError dbasic::DeltaEngine::CreateGameWindow(const char *title, void *instance, // Main render target YDS_NESTED_ERROR_CALL(m_device->CreateOnScreenRenderTarget(&m_mainRenderTarget, m_renderingContext, depthBuffer)); + m_mainRenderTarget->SetDebugName("MAIN_RENDER_TARGET"); + // Initialize Geometry YDS_NESTED_ERROR_CALL(InitializeGeometry()); diff --git a/engines/basic/src/window_handler.cpp b/engines/basic/src/window_handler.cpp index 6b8a16fd..e71861c5 100644 --- a/engines/basic/src/window_handler.cpp +++ b/engines/basic/src/window_handler.cpp @@ -13,9 +13,9 @@ dbasic::WindowHandler::~WindowHandler() { } void dbasic::WindowHandler::OnResizeWindow(int width, int height) { - m_engine->SetWindowSize(width, height); - m_device->UpdateRenderingContext(m_context); - m_engine->GetConsole()->ResetScreenPosition(); + //m_engine->SetWindowSize(width, height); + //m_device->UpdateRenderingContext(m_context); + //m_engine->GetConsole()->ResetScreenPosition(); } void dbasic::WindowHandler::Initialize(ysDevice *device, ysRenderingContext *context, DeltaEngine *engine) { diff --git a/include/yds_base.h b/include/yds_base.h index 6741a8fe..53e2528a 100644 --- a/include/yds_base.h +++ b/include/yds_base.h @@ -15,16 +15,12 @@ class ysObject : public ysDynamicArrayElement { //#define RaiseError(condition, format, ...) ((void)0) //#endif - void SetDebugName(const char *debugName); - const char *GetDebugName() const { return m_debugName; } const char *GetTypeID() const { return m_typeID; } protected: - const char *m_debugName; const char *m_typeID; }; - // TEMP #include "yds_error_system.h" diff --git a/include/yds_breakdown_timer.h b/include/yds_breakdown_timer.h new file mode 100644 index 00000000..05b93154 --- /dev/null +++ b/include/yds_breakdown_timer.h @@ -0,0 +1,27 @@ +#ifndef YDS_BREAKDOWN_TIMER_H +#define YDS_BREAKDOWN_TIMER_H + +#include "yds_base.h" + +#include "yds_expanding_array.h" +#include "yds_breakdown_timer_channel.h" + +class ysBreakdownTimer : public ysObject { +public: + ysBreakdownTimer(); + ~ysBreakdownTimer(); + + int GetChannelCount() const { return m_channels.GetNumObjects(); } + + void StartFrame(); + void StartMeasurement(const std::string &timerChannelName); + void EndMasurement(const std::string &timerChannelName); + +protected: + ysBreakdownTimerChannel *FindChannel(const std::string &s); + + ysExpandingArray m_channels; + ysExpandingArray m_executionOrder; +}; + +#endif /* YDS_BREAKDOWN_TIMER_H */ diff --git a/include/yds_breakdown_timer_channel.h b/include/yds_breakdown_timer_channel.h new file mode 100644 index 00000000..8c186aa5 --- /dev/null +++ b/include/yds_breakdown_timer_channel.h @@ -0,0 +1,33 @@ +#ifndef YDS_BREAKDOWN_TIMER_CHANNEL_H +#define YDS_BREAKDOWN_TIMER_CHANNEL_H + +#include "yds_base.h" + +#include + +class ysBreakdownTimerChannel : public ysObject { +public: + ysBreakdownTimerChannel(); + ~ysBreakdownTimerChannel(); + + void Initialize(int bufferSize); + void Reset(); + void Destroy(); + + void SetName(const std::string &name) { m_name = name; } + std::string GetName() const { return m_name; } + + int GetEntryCount() const { return m_entryCount; } + + void RecordSample(float s); + float GetSample(int i) const; + +protected: + std::string m_name; + float *m_sampleBuffer; + int m_bufferSize; + int m_currentBufferOffset; + int m_entryCount; +}; + +#endif /* YDS_BREAKDOWN_TIMER_CHANNEL_H */ diff --git a/include/yds_context_object.h b/include/yds_context_object.h index 4766e318..5df96c08 100644 --- a/include/yds_context_object.h +++ b/include/yds_context_object.h @@ -3,6 +3,8 @@ #include "yds_base.h" +#include + class ysContextObject : public ysObject { public: enum class DeviceAPI { @@ -21,8 +23,12 @@ class ysContextObject : public ysObject { bool CheckCompatibility(ysContextObject *object) const { return (object) ? object->m_api == m_api : true; } + virtual void SetDebugName(const std::string &debugName) { m_debugName = debugName; } + std::string GetDebugName() const { return m_debugName; } + private: DeviceAPI m_api; + std::string m_debugName; }; #endif /* YDS_CONTEXT_OBJECT_H */ diff --git a/include/yds_d3d11_gpu_buffer.h b/include/yds_d3d11_gpu_buffer.h index 1b302c25..567d1690 100644 --- a/include/yds_d3d11_gpu_buffer.h +++ b/include/yds_d3d11_gpu_buffer.h @@ -4,20 +4,17 @@ #include "yds_gpu_buffer.h" #include -class ysD3D11GPUBuffer : public ysGPUBuffer -{ - +class ysD3D11GPUBuffer : public ysGPUBuffer { friend class ysD3D11Device; public: - ysD3D11GPUBuffer(); virtual ~ysD3D11GPUBuffer(); -protected: + virtual void SetDebugName(const std::string &debugName); +protected: ID3D11Buffer *m_buffer; - }; -#endif \ No newline at end of file +#endif /* YDS_D3D11_GPU_BUFFER_H */ diff --git a/include/yds_d3d11_input_layout.h b/include/yds_d3d11_input_layout.h index 1667bd86..ad37750e 100644 --- a/include/yds_d3d11_input_layout.h +++ b/include/yds_d3d11_input_layout.h @@ -5,20 +5,18 @@ #include -class ysD3D11InputLayout : public ysInputLayout -{ - +class ysD3D11InputLayout : public ysInputLayout { friend class ysD3D11Device; public: - ysD3D11InputLayout(); virtual ~ysD3D11InputLayout(); -protected: + virtual void SetDebugName(const std::string &debugName); +protected: ID3D11InputLayout *m_layout; }; -#endif \ No newline at end of file +#endif /* YDS_D3D11_INPUT_LAYOUT_H */ diff --git a/include/yds_d3d11_render_target.h b/include/yds_d3d11_render_target.h index cbbec8bc..968a0676 100644 --- a/include/yds_d3d11_render_target.h +++ b/include/yds_d3d11_render_target.h @@ -13,6 +13,8 @@ class ysD3D11RenderTarget : public ysRenderTarget { ysD3D11RenderTarget(); virtual ~ysD3D11RenderTarget(); + virtual void SetDebugName(const std::string &debugName); + protected: ID3D11ShaderResourceView *m_resourceView; ID3D11RenderTargetView *m_renderTargetView; diff --git a/include/yds_d3d11_shader.h b/include/yds_d3d11_shader.h index 7941de48..147f0cb5 100644 --- a/include/yds_d3d11_shader.h +++ b/include/yds_d3d11_shader.h @@ -5,29 +5,23 @@ #include -class ysD3D11Shader : public ysShader -{ - +class ysD3D11Shader : public ysShader { friend class ysD3D11Device; public: - ysD3D11Shader(); virtual ~ysD3D11Shader(); -protected: + virtual void SetDebugName(const std::string &debugName); +protected: ID3D10Blob *m_shaderBlob; - union - { - + union { ID3D11VertexShader * m_vertexShader; ID3D11PixelShader * m_pixelShader; ID3D11GeometryShader * m_geometryShader; - }; - }; -#endif \ No newline at end of file +#endif /* YDS_D3D11_SHADER_H */ diff --git a/include/yds_d3d11_texture.h b/include/yds_d3d11_texture.h index 4ff0f30d..92366e9e 100644 --- a/include/yds_d3d11_texture.h +++ b/include/yds_d3d11_texture.h @@ -5,21 +5,18 @@ #include -class ysD3D11Texture : public ysTexture -{ - +class ysD3D11Texture : public ysTexture { friend class ysD3D11Device; public: - ysD3D11Texture(); ~ysD3D11Texture(); -protected: + virtual void SetDebugName(const std::string &debugName); +protected: ID3D11ShaderResourceView *m_resourceView; ID3D11RenderTargetView *m_renderTargetView; - }; -#endif \ No newline at end of file +#endif /* YDS_D3D11_TEXTURE_H */ diff --git a/include/yds_d3d11_utilities.h b/include/yds_d3d11_utilities.h new file mode 100644 index 00000000..99e5f36c --- /dev/null +++ b/include/yds_d3d11_utilities.h @@ -0,0 +1,10 @@ +#ifndef YDS_D3D11_UTILITIES_H +#define YDS_D3D11_UTILITIES_H + +#include + +struct ID3D11DeviceChild; + +void D3D11SetDebugName(ID3D11DeviceChild *object, const std::string &name); + +#endif /* YDS_D3D11_UTILITIES_H */ diff --git a/include/yds_device.h b/include/yds_device.h index a3891007..1a7d79ac 100644 --- a/include/yds_device.h +++ b/include/yds_device.h @@ -182,6 +182,8 @@ class ysDevice : public ysContextObject { // Initialize texture slots ysError InitializeTextureSlots(int maxSlots); + /* Debug */ + // TEMP virtual void Draw(int numFaces, int indexOffset, int vertexOffset) { (void)numFaces; (void)indexOffset; (void)vertexOffset; } diff --git a/include/yds_time_tag_data.h b/include/yds_time_tag_data.h index d9f7a351..482d0d58 100644 --- a/include/yds_time_tag_data.h +++ b/include/yds_time_tag_data.h @@ -3,21 +3,14 @@ #include "yds_expanding_array.h" -class ysTimeTagData -{ - +class ysTimeTagData { public: - - struct TimeTag - { - + struct TimeTag { char Name[64]; int Frame; - }; public: - ysTimeTagData(); ~ysTimeTagData(); @@ -25,7 +18,6 @@ class ysTimeTagData int m_timeTagCount; ysExpandingArray m_timeTags; - }; -#endif \ No newline at end of file +#endif /* YDS_TIME_TAG_DATA_H */ diff --git a/include/yds_window.h b/include/yds_window.h index f65d06e9..51db2c1c 100644 --- a/include/yds_window.h +++ b/include/yds_window.h @@ -12,18 +12,18 @@ class ysWindow : public ysWindowSystemObject { static const int MAX_NAME_LENGTH = 256; enum class WindowState { - VISIBLE, - HIDDEN, - MAXIMIZED, - MINIMIZED, - CLOSED, + Visible, + Hidden, + Maximized, + Minimized, + Closed, Unknown }; enum class WindowStyle { - WINDOWED, - FULLSCREEN, - POPUP, + Windowed, + Fullscreen, + Popup, Unknown }; @@ -36,8 +36,8 @@ class ysWindow : public ysWindowSystemObject { virtual ysError InitializeWindow(ysWindow *parent, const char *title, WindowStyle style, int x, int y, int width, int height, ysMonitor *monitor); virtual ysError InitializeWindow(ysWindow *parent, const char *title, WindowStyle style, ysMonitor *monitor); - virtual void Close() { SetState(WindowState::CLOSED); } - virtual void SetState(WindowState state = WindowState::VISIBLE) { m_windowState = state; } + virtual void Close() { SetState(WindowState::Closed); } + virtual void SetState(WindowState state = WindowState::Visible) { m_windowState = state; } void RestoreWindow(); @@ -59,6 +59,10 @@ class ysWindow : public ysWindowSystemObject { virtual void SetLocation(int x, int y); virtual void SetTitle(const char *title); + virtual void StartResizing() { m_resizing = true; } + virtual void EndResizing() { m_resizing = false; } + bool IsResizing() const { return m_resizing; } + virtual bool SetWindowStyle(WindowStyle style); void AttachEventHandler(ysWindowEventHandler *handler); @@ -122,6 +126,9 @@ class ysWindow : public ysWindowSystemObject { // Window Active bool m_active; + // Status flag indicating whether the window is resizing + bool m_resizing; + protected: // Event handler ysWindowEventHandler *m_eventHandler; diff --git a/include/yds_windows_window.h b/include/yds_windows_window.h index 59b4e6ef..8623f7d1 100644 --- a/include/yds_windows_window.h +++ b/include/yds_windows_window.h @@ -43,7 +43,7 @@ class ysWindowsWindow : public ysWindow { virtual void Close(); virtual void SetTitle(const char *title); - virtual void SetState(WindowState state = WindowState::VISIBLE); + virtual void SetState(WindowState state = WindowState::Visible); virtual void AL_SetSize(int width, int height); virtual void AL_SetLocation(int x, int y); diff --git a/project/delta-core/delta-core.vcxproj b/project/delta-core/delta-core.vcxproj index d774765d..0aea1d92 100644 --- a/project/delta-core/delta-core.vcxproj +++ b/project/delta-core/delta-core.vcxproj @@ -56,6 +56,7 @@ + @@ -166,6 +167,7 @@ + diff --git a/project/delta-core/delta-core.vcxproj.filters b/project/delta-core/delta-core.vcxproj.filters index b001b0f6..351db615 100644 --- a/project/delta-core/delta-core.vcxproj.filters +++ b/project/delta-core/delta-core.vcxproj.filters @@ -495,6 +495,9 @@ Header Files\api + + Header Files\api\directx11 + @@ -794,5 +797,8 @@ Source Files\window-system\windows + + Source Files\api\directx11 + \ No newline at end of file diff --git a/src/yds_base.cpp b/src/yds_base.cpp index d4bc3e0c..3ccf69bf 100644 --- a/src/yds_base.cpp +++ b/src/yds_base.cpp @@ -5,12 +5,10 @@ ysObject::ysObject() { m_typeID = "YS_OBJECT"; - m_debugName = "NO_NAME"; } ysObject::ysObject(const char *typeID) { m_typeID = typeID; - m_debugName = "NO_NAME"; } ysObject::~ysObject() { @@ -39,7 +37,3 @@ ysObject::~ysObject() { // //} //#endif - -void ysObject::SetDebugName(const char *debugName) { - m_debugName = debugName; -} diff --git a/src/yds_breakdown_timer.cpp b/src/yds_breakdown_timer.cpp new file mode 100644 index 00000000..bc6b22c8 --- /dev/null +++ b/src/yds_breakdown_timer.cpp @@ -0,0 +1,25 @@ +#include "../include/yds_breakdown_timer.h" + +ysBreakdownTimer::ysBreakdownTimer() { + /* void */ +} + +ysBreakdownTimer::~ysBreakdownTimer() { + /* void */ +} + +void ysBreakdownTimer::StartFrame() { + m_executionOrder.Clear(); +} + +void ysBreakdownTimer::StartMeasurement(const std::string &timerChannelName) { + +} + +void ysBreakdownTimer::EndMasurement(const std::string &timerChannelName) { + +} + +ysBreakdownTimerChannel *ysBreakdownTimer::FindChannel(const std::string &s) { + return nullptr; +} diff --git a/src/yds_breakdown_timer_channel.cpp b/src/yds_breakdown_timer_channel.cpp new file mode 100644 index 00000000..04e9707e --- /dev/null +++ b/src/yds_breakdown_timer_channel.cpp @@ -0,0 +1,43 @@ +#include "../include/yds_breakdown_timer_channel.h" + +#include + +ysBreakdownTimerChannel::ysBreakdownTimerChannel() { + m_name = ""; + m_sampleBuffer = nullptr; + m_currentBufferOffset = 0; + m_bufferSize = 0; + m_entryCount = 0; +} + +ysBreakdownTimerChannel::~ysBreakdownTimerChannel() { + assert(m_sampleBuffer == nullptr); +} + +void ysBreakdownTimerChannel::Initialize(int bufferSize) { + m_sampleBuffer = new float[bufferSize]; +} + +void ysBreakdownTimerChannel::Reset() { + m_currentBufferOffset = 0; + m_entryCount = 0; +} + +void ysBreakdownTimerChannel::Destroy() { + delete[] m_sampleBuffer; + m_sampleBuffer = nullptr; +} + +void ysBreakdownTimerChannel::RecordSample(float s) { + int index = (m_currentBufferOffset + m_entryCount) % m_bufferSize; + + m_sampleBuffer[index] = s; + m_entryCount++; + if (m_entryCount >= m_bufferSize) m_entryCount = m_bufferSize; +} + +float ysBreakdownTimerChannel::GetSample(int i) const { + int index = (m_currentBufferOffset + i) % m_bufferSize; + + return m_sampleBuffer[(m_currentBufferOffset + index) % m_bufferSize]; +} diff --git a/src/yds_d3d10_device.cpp b/src/yds_d3d10_device.cpp index 46ec75a0..dbd839ab 100644 --- a/src/yds_d3d10_device.cpp +++ b/src/yds_d3d10_device.cpp @@ -110,7 +110,7 @@ ysError ysD3D10Device::CreateRenderingContext(ysRenderingContext **context, ysWi swapChainDesc.BufferUsage = DXGI_USAGE_RENDER_TARGET_OUTPUT; swapChainDesc.BufferCount = 2; swapChainDesc.OutputWindow = windowsWindow->GetWindowHandle(); - swapChainDesc.Windowed = window->GetStyle() != ysWindow::WindowStyle::FULLSCREEN; + swapChainDesc.Windowed = window->GetStyle() != ysWindow::WindowStyle::Fullscreen; swapChainDesc.SwapEffect = DXGI_SWAP_EFFECT_FLIP_DISCARD; swapChainDesc.Flags = DXGI_SWAP_CHAIN_FLAG_ALLOW_MODE_SWITCH; @@ -251,7 +251,7 @@ ysError ysD3D10Device::SetContextMode(ysRenderingContext *context, ysRenderingCo HRESULT result; if (mode == ysRenderingContext::ContextMode::Fullscreen) { - window->SetWindowStyle(ysWindow::WindowStyle::FULLSCREEN); + window->SetWindowStyle(ysWindow::WindowStyle::Fullscreen); //d3d10Context->m_swapChain->ResizeBuffers result = d3d10Context->m_swapChain->SetFullscreenState(TRUE, nullptr); @@ -259,7 +259,7 @@ ysError ysD3D10Device::SetContextMode(ysRenderingContext *context, ysRenderingCo return YDS_ERROR_RETURN(ysError::YDS_COULD_NOT_ENTER_FULLSCREEN); } else if (mode == ysRenderingContext::ContextMode::Windowed) { - window->SetWindowStyle(ysWindow::WindowStyle::WINDOWED); + window->SetWindowStyle(ysWindow::WindowStyle::Windowed); result = d3d10Context->m_swapChain->SetFullscreenState(FALSE, nullptr); if (FAILED(result)) diff --git a/src/yds_d3d11_device.cpp b/src/yds_d3d11_device.cpp index 9bd8dcf6..035cae59 100644 --- a/src/yds_d3d11_device.cpp +++ b/src/yds_d3d11_device.cpp @@ -7,6 +7,7 @@ #include "../include/yds_d3d11_shader_program.h" #include "../include/yds_d3d11_input_layout.h" #include "../include/yds_d3d11_texture.h" +#include "../include/yds_d3d11_utilities.h" #include "../include/yds_windows_window.h" @@ -96,9 +97,10 @@ ysError ysD3D11Device::InitializeDevice() { ysError ysD3D11Device::DestroyDevice() { YDS_ERROR_DECLARE("DestroyDevice"); - if (m_deviceContext != nullptr) m_deviceContext->Release(); - if (m_device != nullptr) m_device->Release(); - if (m_DXGIFactory != nullptr) m_DXGIFactory->Release(); + if (m_deviceContext != nullptr) { + m_deviceContext->ClearState(); + m_deviceContext->Flush(); + } if (m_depthStencilDisabledState != nullptr) m_depthStencilDisabledState->Release(); if (m_depthStencilEnabledState != nullptr) m_depthStencilEnabledState->Release(); @@ -108,13 +110,21 @@ ysError ysD3D11Device::DestroyDevice() { if (m_rasterizerState != nullptr) m_rasterizerState->Release(); + if (m_DXGIFactory != nullptr) m_DXGIFactory->Release(); + if (m_deviceContext != nullptr) m_deviceContext->Release(); + if (m_device != nullptr) m_device->Release(); + #ifdef _DEBUG Microsoft::WRL::ComPtr dxgiDebug; - DXGIGetDebugInterface_proc proc = (DXGIGetDebugInterface_proc)GetProcAddress(GetModuleHandle(TEXT("Dxgidebug.dll")), "DXGIGetDebugInterface"); - const IID &pD = DXGI_DEBUG_ALL; - HRESULT r = proc(IID_PPV_ARGS(dxgiDebug.GetAddressOf())); - dxgiDebug.Get()->ReportLiveObjects(pD, DXGI_DEBUG_RLO_ALL); + HMODULE debugModule = GetModuleHandle(TEXT("Dxgidebug.dll")); + + if (debugModule != NULL) { + DXGIGetDebugInterface_proc proc = (DXGIGetDebugInterface_proc)GetProcAddress(debugModule, "DXGIGetDebugInterface"); + const IID &pD = DXGI_DEBUG_ALL; + HRESULT r = proc(IID_PPV_ARGS(dxgiDebug.GetAddressOf())); + dxgiDebug.Get()->ReportLiveObjects(pD, DXGI_DEBUG_RLO_DETAIL); + } #endif /* _DEBUG */ return YDS_ERROR_RETURN(ysError::YDS_NO_ERROR); @@ -166,9 +176,9 @@ ysError ysD3D11Device::CreateRenderingContext(ysRenderingContext **context, ysWi swapChainDesc.SampleDesc.Count = m_multisampleCount; swapChainDesc.SampleDesc.Quality = m_multisampleQuality; swapChainDesc.BufferUsage = DXGI_USAGE_RENDER_TARGET_OUTPUT; - swapChainDesc.BufferCount = 1; + swapChainDesc.BufferCount = 2; swapChainDesc.OutputWindow = windowsWindow->GetWindowHandle(); - swapChainDesc.Windowed = window->GetStyle() != ysWindow::WindowStyle::FULLSCREEN; + swapChainDesc.Windowed = window->GetStyle() != ysWindow::WindowStyle::Fullscreen; swapChainDesc.SwapEffect = DXGI_SWAP_EFFECT_DISCARD; swapChainDesc.Flags = 0; @@ -205,6 +215,8 @@ ysError ysD3D11Device::CreateRenderingContext(ysRenderingContext **context, ysWi m_device->CreateRasterizerState(&rasterizerDescription, &m_rasterizerState); GetImmediateContext()->RSSetState(m_rasterizerState); + D3D11SetDebugName(m_rasterizerState, "RASTERIZER_STATE"); + // TEMPORARY ALPHA ENABLING D3D11_BLEND_DESC BlendState; ZeroMemory(&BlendState, sizeof(D3D11_BLEND_DESC)); @@ -218,6 +230,8 @@ ysError ysD3D11Device::CreateRenderingContext(ysRenderingContext **context, ysWi BlendState.RenderTarget[0].RenderTargetWriteMask = D3D11_COLOR_WRITE_ENABLE_ALL; m_device->CreateBlendState(&BlendState, &m_blendState); + D3D11SetDebugName(m_blendState, "ALPHA_BLEND_STATE"); + float blendFactor[] = { 0.0f, 0.0f, 0.0f, 0.0f }; UINT sampleMask = 0xffffffff; @@ -311,7 +325,7 @@ ysError ysD3D11Device::DestroyRenderingContext(ysRenderingContext *&context) { YDS_NESTED_ERROR_CALL(SetContextMode(context, ysRenderingContext::ContextMode::Windowed)); ysD3D11Context *d3d11Context = static_cast(context); - if (d3d11Context->m_swapChain) d3d11Context->m_swapChain->Release(); + if (d3d11Context->m_swapChain != nullptr) d3d11Context->m_swapChain->Release(); } YDS_NESTED_ERROR_CALL(ysDevice::DestroyRenderingContext(context)); @@ -332,7 +346,7 @@ ysError ysD3D11Device::SetContextMode(ysRenderingContext *context, ysRenderingCo HRESULT result; if (mode == ysRenderingContext::ContextMode::Fullscreen) { - window->SetWindowStyle(ysWindow::WindowStyle::FULLSCREEN); + window->SetWindowStyle(ysWindow::WindowStyle::Fullscreen); result = d3d11Context->m_swapChain->SetFullscreenState(TRUE, nullptr); if (FAILED(result)) { @@ -341,7 +355,7 @@ ysError ysD3D11Device::SetContextMode(ysRenderingContext *context, ysRenderingCo } else if (mode == ysRenderingContext::ContextMode::Windowed) { - window->SetWindowStyle(ysWindow::WindowStyle::WINDOWED); + window->SetWindowStyle(ysWindow::WindowStyle::Windowed); result = d3d11Context->m_swapChain->SetFullscreenState(FALSE, nullptr); if (FAILED(result)) { @@ -586,6 +600,8 @@ ysError ysD3D11Device::CreateVertexBuffer(ysGPUBuffer **newBuffer, int size, cha return YDS_ERROR_RETURN(ysError::YDS_COULD_NOT_CREATE_GPU_BUFFER); } + D3D11SetDebugName(buffer, "VERTEX_BUFFER"); + ysD3D11GPUBuffer *newD3D11Buffer = m_gpuBuffers.NewGeneric(); newD3D11Buffer->m_size = size; @@ -633,6 +649,8 @@ ysError ysD3D11Device::CreateIndexBuffer(ysGPUBuffer **newBuffer, int size, char return YDS_ERROR_RETURN(ysError::YDS_COULD_NOT_CREATE_GPU_BUFFER); } + D3D11SetDebugName(buffer, "INDEX_BUFFER"); + ysD3D11GPUBuffer *newD3D11Buffer = m_gpuBuffers.NewGeneric(); newD3D11Buffer->m_size = size; @@ -642,7 +660,10 @@ ysError ysD3D11Device::CreateIndexBuffer(ysGPUBuffer **newBuffer, int size, char if (mirrorToRam) { newD3D11Buffer->m_RAMMirror = new char[size]; - memcpy(newD3D11Buffer->m_RAMMirror, data, size); + + if (data != nullptr) { + memcpy(newD3D11Buffer->m_RAMMirror, data, size); + } } *newBuffer = static_cast(newD3D11Buffer); @@ -678,6 +699,8 @@ ysError ysD3D11Device::CreateConstantBuffer(ysGPUBuffer **newBuffer, int size, c return YDS_ERROR_RETURN(ysError::YDS_COULD_NOT_CREATE_GPU_BUFFER); } + D3D11SetDebugName(buffer, "CONSTANT_BUFFER"); + ysD3D11GPUBuffer *newD3D11Buffer = m_gpuBuffers.NewGeneric(); newD3D11Buffer->m_size = size; @@ -689,7 +712,10 @@ ysError ysD3D11Device::CreateConstantBuffer(ysGPUBuffer **newBuffer, int size, c if (mirrorToRam) { newD3D11Buffer->m_RAMMirror = new char[size]; - memcpy(newD3D11Buffer->m_RAMMirror, data, size); + + if (data != nullptr) { + memcpy(newD3D11Buffer->m_RAMMirror, data, size); + } } return YDS_ERROR_RETURN(ysError::YDS_NO_ERROR); @@ -700,7 +726,7 @@ ysError ysD3D11Device::UseVertexBuffer(ysGPUBuffer *buffer, int stride, int offs if (!CheckCompatibility(buffer)) return YDS_ERROR_RETURN(ysError::YDS_INCOMPATIBLE_PLATFORMS); - if (buffer) { + if (buffer != nullptr) { UINT uoffset = (UINT)offset; UINT ustride = (UINT)stride; @@ -880,6 +906,8 @@ ysError ysD3D11Device::CreateVertexShader(ysShader **newShader, const char *shad strcpy_s(newD3D11Shader->m_shaderName, 64, shaderName); newD3D11Shader->m_shaderType = ysShader::ShaderType::Vertex; + D3D11SetDebugName(newD3D11Shader->m_vertexShader, newD3D11Shader->m_filename); + *newShader = static_cast(newD3D11Shader); return YDS_ERROR_RETURN(ysError::YDS_NO_ERROR); @@ -921,6 +949,8 @@ ysError ysD3D11Device::CreatePixelShader(ysShader **newShader, const char *shade *newShader = newD3D11Shader; + D3D11SetDebugName(newD3D11Shader->m_pixelShader, newD3D11Shader->m_filename); + // TEMP ---------------------------------------------------- GetImmediateContext()->PSSetShader(pixelShader, 0, 0); diff --git a/src/yds_d3d11_gpu_buffer.cpp b/src/yds_d3d11_gpu_buffer.cpp index 9d5a497d..4a15011e 100644 --- a/src/yds_d3d11_gpu_buffer.cpp +++ b/src/yds_d3d11_gpu_buffer.cpp @@ -1,9 +1,18 @@ #include "../include/yds_d3d11_gpu_buffer.h" ysD3D11GPUBuffer::ysD3D11GPUBuffer() : ysGPUBuffer(DeviceAPI::DirectX11) { - m_buffer = NULL; + m_buffer = nullptr; } ysD3D11GPUBuffer::~ysD3D11GPUBuffer() { /* void */ } + +void ysD3D11GPUBuffer::SetDebugName(const std::string &debugName) { + ysGPUBuffer::SetDebugName(debugName); + + if (m_buffer != nullptr) { + m_buffer->SetPrivateData(WKPDID_D3DDebugObjectName, debugName.size(), debugName.c_str()); + } +} + diff --git a/src/yds_d3d11_input_layout.cpp b/src/yds_d3d11_input_layout.cpp index 2ae72ea1..7b501bdb 100644 --- a/src/yds_d3d11_input_layout.cpp +++ b/src/yds_d3d11_input_layout.cpp @@ -7,3 +7,11 @@ ysD3D11InputLayout::ysD3D11InputLayout() : ysInputLayout(DeviceAPI::DirectX11) { ysD3D11InputLayout::~ysD3D11InputLayout() { /* void */ } + +void ysD3D11InputLayout::SetDebugName(const std::string &debugName) { + ysInputLayout::SetDebugName(debugName); + + if (m_layout != nullptr) { + m_layout->SetPrivateData(WKPDID_D3DDebugObjectName, debugName.size(), debugName.c_str()); + } +} diff --git a/src/yds_d3d11_render_target.cpp b/src/yds_d3d11_render_target.cpp index 162b0bf8..32ae952e 100644 --- a/src/yds_d3d11_render_target.cpp +++ b/src/yds_d3d11_render_target.cpp @@ -1,5 +1,7 @@ #include "../include/yds_d3d11_render_target.h" +#include "../include/yds_d3d11_utilities.h" + #include ysD3D11RenderTarget::ysD3D11RenderTarget() : ysRenderTarget(DeviceAPI::DirectX11) { @@ -21,3 +23,16 @@ ysD3D11RenderTarget::~ysD3D11RenderTarget() { assert(m_depthTestEnabledState == nullptr); assert(m_depthTestDisabledState == nullptr); } + +void ysD3D11RenderTarget::SetDebugName(const std::string &debugName) { + ysRenderTarget::SetDebugName(debugName); + + if (m_depthBuffer != nullptr) m_depthBuffer->SetDebugName(debugName + "_DEPTH_BUFFER"); + + D3D11SetDebugName(m_resourceView, debugName + "_RESOURCE_VIEW"); + D3D11SetDebugName(m_renderTargetView, debugName + "_RENDER_TARGET_VIEW"); + D3D11SetDebugName(m_depthStencilView, debugName + "_DEPTH_STENCIL_VIEW"); + + D3D11SetDebugName(m_depthTestEnabledState, debugName + "_DEPTH_TEST_ENABLED_STATE"); + D3D11SetDebugName(m_depthTestDisabledState, debugName + "_DEPTH_TEST_DISABLED_STATE"); +} diff --git a/src/yds_d3d11_shader.cpp b/src/yds_d3d11_shader.cpp index 0873eb8a..0e017fb4 100644 --- a/src/yds_d3d11_shader.cpp +++ b/src/yds_d3d11_shader.cpp @@ -1,9 +1,27 @@ #include "../include/yds_d3d11_shader.h" +#include "../include/yds_d3d11_utilities.h" + ysD3D11Shader::ysD3D11Shader() : ysShader(DeviceAPI::DirectX11) { - /* void */ + m_geometryShader = nullptr; + m_vertexShader = nullptr; + m_pixelShader = nullptr; + m_shaderBlob = nullptr; } ysD3D11Shader::~ysD3D11Shader() { /* void */ } + +void ysD3D11Shader::SetDebugName(const std::string &debugName) { + ysShader::SetDebugName(debugName); + + switch (GetShaderType()) { + case ysShader::ShaderType::Vertex: + D3D11SetDebugName(m_vertexShader, debugName); + break; + case ysShader::ShaderType::Pixel: + D3D11SetDebugName(m_pixelShader, debugName); + break; + } +} diff --git a/src/yds_d3d11_texture.cpp b/src/yds_d3d11_texture.cpp index cd964202..3af7a97d 100644 --- a/src/yds_d3d11_texture.cpp +++ b/src/yds_d3d11_texture.cpp @@ -1,10 +1,19 @@ #include "../include/yds_d3d11_texture.h" +#include "../include/yds_d3d11_utilities.h" + ysD3D11Texture::ysD3D11Texture() : ysTexture(DeviceAPI::DirectX11) { - m_resourceView = NULL; - m_renderTargetView = NULL; + m_resourceView = nullptr; + m_renderTargetView = nullptr; } ysD3D11Texture::~ysD3D11Texture() { /* void */ } + +void ysD3D11Texture::SetDebugName(const std::string &debugName) { + ysTexture::SetDebugName(debugName); + + D3D11SetDebugName(m_resourceView, debugName + "_RESOURCE_VIEW"); + D3D11SetDebugName(m_renderTargetView, debugName + "_RENDER_TARGET_VIEW"); +} diff --git a/src/yds_d3d11_utilities.cpp b/src/yds_d3d11_utilities.cpp new file mode 100644 index 00000000..c3731b8f --- /dev/null +++ b/src/yds_d3d11_utilities.cpp @@ -0,0 +1,9 @@ +#include "../include/yds_d3d11_utilities.h" + +#include + +void D3D11SetDebugName(ID3D11DeviceChild *object, const std::string &name) { + if (object != nullptr) { + object->SetPrivateData(WKPDID_D3DDebugObjectName, name.size(), name.c_str()); + } +} diff --git a/src/yds_opengl_windows_context.cpp b/src/yds_opengl_windows_context.cpp index 3727c819..7f8563ca 100644 --- a/src/yds_opengl_windows_context.cpp +++ b/src/yds_opengl_windows_context.cpp @@ -169,7 +169,7 @@ ysError ysOpenGLWindowsContext::SetContextMode(ContextMode mode) { int result; if (mode == ysRenderingContext::ContextMode::Fullscreen) { - window->SetWindowStyle(ysWindow::WindowStyle::FULLSCREEN); + window->SetWindowStyle(ysWindow::WindowStyle::Fullscreen); DEVMODE dmScreenSettings; memset(&dmScreenSettings, 0, sizeof(dmScreenSettings)); @@ -185,7 +185,7 @@ ysError ysOpenGLWindowsContext::SetContextMode(ContextMode mode) { } } else if (mode == ysRenderingContext::ContextMode::Windowed) { - window->SetWindowStyle(ysWindow::WindowStyle::WINDOWED); + window->SetWindowStyle(ysWindow::WindowStyle::Windowed); result = ChangeDisplaySettingsEx(NULL, NULL, NULL, 0, NULL); if (result != DISP_CHANGE_SUCCESSFUL) { diff --git a/src/yds_window.cpp b/src/yds_window.cpp index cbaabad6..30e06b96 100644 --- a/src/yds_window.cpp +++ b/src/yds_window.cpp @@ -19,10 +19,11 @@ ysWindow::ysWindow() : ysWindowSystemObject("WINDOW", Platform::Unknown) { m_locationy = 0; m_windowStyle = WindowStyle::Unknown; - m_windowState = WindowState::HIDDEN; + m_windowState = WindowState::Hidden; m_parent = nullptr; m_active = false; + m_resizing = false; m_eventHandler = nullptr; } @@ -43,10 +44,11 @@ ysWindow::ysWindow(Platform platform) : ysWindowSystemObject("WINDOW", platform) m_locationy = 0; m_windowStyle = WindowStyle::Unknown; - m_windowState = WindowState::HIDDEN; + m_windowState = WindowState::Hidden; m_parent = nullptr; m_active = true; + m_resizing = false; m_eventHandler = nullptr; } @@ -66,7 +68,7 @@ ysError ysWindow::InitializeWindow(ysWindow *parent, const char *title, WindowSt m_locationx = x; m_locationy = y; - m_windowState = WindowState::HIDDEN; // DEFAULT + m_windowState = WindowState::Hidden; // DEFAULT m_windowStyle = style; m_monitor = monitor; @@ -94,7 +96,7 @@ void ysWindow::RestoreWindow() { } bool ysWindow::IsOpen() { - return m_windowState != WindowState::CLOSED; + return m_windowState != WindowState::Closed; } bool ysWindow::IsActive() { @@ -122,14 +124,14 @@ void ysWindow::SetTitle(const char *title) { bool ysWindow::SetWindowStyle(WindowStyle style) { if (style == m_windowStyle) return false; - if (style == WindowStyle::FULLSCREEN) { + if (style == WindowStyle::Fullscreen) { //RaiseError(m_monitor != NULL, "Cannot go into fullscreen without an attached monitor."); m_windowStyle = style; } - else if (style == WindowStyle::WINDOWED) { + else if (style == WindowStyle::Windowed) { m_windowStyle = style; } - else if (style == WindowStyle::POPUP) { + else if (style == WindowStyle::Popup) { m_windowStyle = style; } @@ -166,13 +168,9 @@ void ysWindow::OnActivate() { } void ysWindow::OnDeactivate() { - //HWND current_active = GetFocus(); - m_active = false; if (m_eventHandler) m_eventHandler->OnDeactivate(); - - //SetFocus(current_active); } void ysWindow::OnCloseWindow() { diff --git a/src/yds_windows_window.cpp b/src/yds_windows_window.cpp index fc1d0a8f..8e2aef22 100644 --- a/src/yds_windows_window.cpp +++ b/src/yds_windows_window.cpp @@ -89,7 +89,7 @@ ysError ysWindowsWindow::InitializeWindow(ysWindow *parent, const char *title, W bool ysWindowsWindow::SetWindowStyle(WindowStyle style) { if (!ysWindow::SetWindowStyle(style)) return false; - if (style == WindowStyle::WINDOWED) { + if (style == WindowStyle::Windowed) { SetWindowLongPtr(m_hwnd, GWL_STYLE, GetWindowsStyle()); SetWindowPos(m_hwnd, NULL, 0, 0, 0, 0, SWP_FRAMECHANGED); @@ -102,7 +102,7 @@ bool ysWindowsWindow::SetWindowStyle(WindowStyle style) { ShowWindow(m_hwnd, SW_SHOW); SetForegroundWindow(m_hwnd); } - else if (style == WindowStyle::FULLSCREEN) { + else if (style == WindowStyle::Fullscreen) { SetWindowLongPtr(m_hwnd, GWL_STYLE, GetWindowsStyle()); SetWindowPos(m_hwnd, NULL, 0, 0, 0, 0, SWP_FRAMECHANGED); @@ -115,7 +115,7 @@ bool ysWindowsWindow::SetWindowStyle(WindowStyle style) { ShowWindow(m_hwnd, SW_SHOW); SetForegroundWindow(m_hwnd); } - else if (style == WindowStyle::POPUP) { + else if (style == WindowStyle::Popup) { SetWindowLongPtr(m_hwnd, GWL_STYLE, GetWindowsStyle()); SetWindowPos(m_hwnd, NULL, 0, 0, 0, 0, SWP_FRAMECHANGED); @@ -148,11 +148,11 @@ bool ysWindowsWindow::IsVisible() { int ysWindowsWindow::GetWindowsStyle() const { switch (m_windowStyle) { - case WindowStyle::FULLSCREEN: + case WindowStyle::Fullscreen: return WS_POPUP | WS_VISIBLE; - case WindowStyle::WINDOWED: + case WindowStyle::Windowed: return WS_OVERLAPPEDWINDOW | WS_VISIBLE; - case WindowStyle::POPUP: + case WindowStyle::Popup: return WS_POPUP | WS_VISIBLE; } @@ -178,16 +178,16 @@ void ysWindowsWindow::SetState(WindowState state) { ysWindow::SetState(state); switch (state) { - case WindowState::VISIBLE: + case WindowState::Visible: ShowWindow(m_hwnd, SW_SHOW); break; - case WindowState::HIDDEN: + case WindowState::Hidden: ShowWindow(m_hwnd, SW_HIDE); break; - case WindowState::MAXIMIZED: + case WindowState::Maximized: ShowWindow(m_hwnd, SW_SHOWMAXIMIZED); break; - case WindowState::MINIMIZED: + case WindowState::Minimized: ShowWindow(m_hwnd, SW_SHOWMINIMIZED); break; } diff --git a/src/yds_windows_window_system.cpp b/src/yds_windows_window_system.cpp index 84722ed8..7cdc31ee 100644 --- a/src/yds_windows_window_system.cpp +++ b/src/yds_windows_window_system.cpp @@ -104,27 +104,27 @@ LRESULT WINAPI ysWindowsWindowSystem::WinProc(HWND hWnd, UINT msg, WPARAM wParam ysWindowSystem::Get()->CloseWindow(target); return 0; case WM_SIZE: - if (wParam == SIZE_MAXIMIZED || wParam == SIZE_MINIMIZED || wParam == SIZE_RESTORED) { + if (!target->IsResizing()) { target->OnResizeWindow(LOWORD(lParam), HIWORD(lParam)); } return 0; + case WM_ENTERSIZEMOVE: + target->StartResizing(); + return 0; case WM_EXITSIZEMOVE: { RECT rect; if (GetClientRect(hWnd, &rect)) { target->OnResizeWindow(rect.right - rect.left, rect.bottom - rect.top); } + + target->EndResizing(); + return 0; } case WM_MOVE: target->OnMoveWindow(LOWORD(lParam), HIWORD(lParam)); return 0; - - //case WM_ACTIVATE: - // if (wParam == WA_ACTIVE || wParam == WA_CLICKACTIVE) target->OnActivate(); - // else if (wParam == WA_INACTIVE) target->OnDeactivate(); - // return 0; - case WM_SETFOCUS: target->OnActivate(); return 0;