From f92bed35f5291420ddddb5db382cd848abcc1a86 Mon Sep 17 00:00:00 2001 From: lanariel Date: Wed, 12 Feb 2014 09:24:37 +0100 Subject: [PATCH 1/2] Colored Text and Tinted Gui elements --- Code/OysterGraphics/DllInterfaces/GFXAPI.cpp | 8 ++++---- Code/OysterGraphics/DllInterfaces/GFXAPI.h | 4 ++-- Code/OysterGraphics/Render/GuiRenderer.cpp | 14 ++++++++++++-- Code/OysterGraphics/Render/GuiRenderer.h | 4 ++-- Code/OysterGraphics/Render/Resources.cpp | 8 ++++++++ Code/OysterGraphics/Render/Resources.h | 1 + Code/OysterGraphics/Shader/Passes/2D/2DPixel.hlsl | 2 +- Code/OysterGraphics/Shader/Passes/2D/Header.hlsli | 7 ++++++- .../Shader/Passes/2D/Text/Header.hlsli | 2 +- Code/Tester/MainTest.cpp | 4 ++-- 10 files changed, 39 insertions(+), 15 deletions(-) diff --git a/Code/OysterGraphics/DllInterfaces/GFXAPI.cpp b/Code/OysterGraphics/DllInterfaces/GFXAPI.cpp index 51ea20a2..b8d8bbae 100644 --- a/Code/OysterGraphics/DllInterfaces/GFXAPI.cpp +++ b/Code/OysterGraphics/DllInterfaces/GFXAPI.cpp @@ -158,9 +158,9 @@ namespace Oyster Render::Gui::Begin2DRender(); } - void API::RenderGuiElement(API::Texture tex, Math::Float2 pos, Math::Float2 size) + void API::RenderGuiElement(API::Texture tex, Math::Float2 pos, Math::Float2 size, Math::Float3 color) { - Render::Gui::Render((ID3D11ShaderResourceView*)tex,pos,size); + Render::Gui::Render((ID3D11ShaderResourceView*)tex,pos,size,color); } API::Texture API::CreateTexture(std::wstring filename) @@ -191,9 +191,9 @@ namespace Oyster Render::Gui::Begin2DTextRender(); } - void API::RenderText(std::wstring text, Math::Float2 Pos, Math::Float2 Size) + void API::RenderText(std::wstring text, Math::Float2 Pos, Math::Float2 Size, Math::Float3 color) { - Render::Gui::RenderText(text,Pos,Size); + Render::Gui::RenderText(text,Pos,Size,color); } } } \ No newline at end of file diff --git a/Code/OysterGraphics/DllInterfaces/GFXAPI.h b/Code/OysterGraphics/DllInterfaces/GFXAPI.h index 6511fc4d..bdf70072 100644 --- a/Code/OysterGraphics/DllInterfaces/GFXAPI.h +++ b/Code/OysterGraphics/DllInterfaces/GFXAPI.h @@ -57,13 +57,13 @@ namespace Oyster static void StartGuiRender(); //! @brief Renders a single GUI element using the texture provided and the Pos in the center, %based system - static void RenderGuiElement(Texture, Math::Float2 Pos, Math::Float2 Size); + static void RenderGuiElement(Texture, Math::Float2 Pos, Math::Float2 Size, Math::Float3 Color = Math::Float3(1,1,1)); //! @brief Configures Renderer to process 2D Text, data will be passed in to EndFrame() static void StartTextRender(); //! @brief Renders a single GUI string using the texture provided and the Pos in the center, %based system - static void RenderText(std::wstring, Math::Float2 Pos, Math::Float2 Size); + static void RenderText(std::wstring, Math::Float2 Pos, Math::Float2 Size, Math::Float3 Color = Math::Float3(1,1,1)); //! @brief Performs light calculations, post effects and presents the scene static void EndFrame(); diff --git a/Code/OysterGraphics/Render/GuiRenderer.cpp b/Code/OysterGraphics/Render/GuiRenderer.cpp index ee114898..fbdfa37c 100644 --- a/Code/OysterGraphics/Render/GuiRenderer.cpp +++ b/Code/OysterGraphics/Render/GuiRenderer.cpp @@ -16,7 +16,7 @@ namespace Oyster Core::PipelineManager::SetRenderPass(Render::Resources::Gui::Pass); } - void Gui::Render(ID3D11ShaderResourceView* tex,Math::Float2 pos, Math::Float2 size) + void Gui::Render(ID3D11ShaderResourceView* tex,Math::Float2 pos, Math::Float2 size, Math::Float3 color) { Core::deviceContext->PSSetShaderResources(0,1,&tex); @@ -34,6 +34,12 @@ namespace Oyster void* data = Render::Resources::Gui::Data.Map(); memcpy(data,&gd,sizeof(Definitions::GuiData)); Render::Resources::Gui::Data.Unmap(); + + data = Render::Resources::Gui::Color.Map(); + memcpy(data,&color,sizeof(Math::Float3)); + Render::Resources::Gui::Color.Unmap(); + + Core::deviceContext->Draw(1,0); } @@ -43,7 +49,7 @@ namespace Oyster Core::PipelineManager::SetRenderPass(Resources::Gui::Text::Pass); } - void Gui::RenderText(std::wstring text, Math::Float2 pos, Math::Float2 size) + void Gui::RenderText(std::wstring text, Math::Float2 pos, Math::Float2 size, Math::Float3 color) { size.x = size.x / (text.length() * TEXT_SPACING /2); @@ -70,6 +76,10 @@ namespace Oyster Render::Resources::Gui::Data.Unmap(); Definitions::Text2D tmpInst; + data = Render::Resources::Gui::Color.Map(); + memcpy(data,&color,sizeof(Math::Float3)); + Render::Resources::Gui::Color.Unmap(); + void* dest = Resources::Gui::Text::Vertex.Map(); Definitions::Text2D* dataView = reinterpret_cast(dest); //tmpInst.charOffset=_pos; diff --git a/Code/OysterGraphics/Render/GuiRenderer.h b/Code/OysterGraphics/Render/GuiRenderer.h index 6d865950..f5513d2f 100644 --- a/Code/OysterGraphics/Render/GuiRenderer.h +++ b/Code/OysterGraphics/Render/GuiRenderer.h @@ -12,9 +12,9 @@ namespace Oyster { public: static void Begin2DRender(); - static void Render(ID3D11ShaderResourceView* tex, Math::Float2 pos, Math::Float2 size); + static void Render(ID3D11ShaderResourceView* tex, Math::Float2 pos, Math::Float2 size, Math::Float3 tint = Math::Float3(1,1,1)); static void Begin2DTextRender(); - static void RenderText(std::wstring text, Math::Float2 pos, Math::Float2 size); + static void RenderText(std::wstring text, Math::Float2 pos, Math::Float2 size, Math::Float3 tint = Math::Float3(1,1,1)); }; } } diff --git a/Code/OysterGraphics/Render/Resources.cpp b/Code/OysterGraphics/Render/Resources.cpp index e0a0aa79..73834071 100644 --- a/Code/OysterGraphics/Render/Resources.cpp +++ b/Code/OysterGraphics/Render/Resources.cpp @@ -45,6 +45,7 @@ namespace Oyster Buffer Resources::Gather::AnimationData = Buffer(); Buffer Resources::Light::LightConstantsData = Buffer(); Buffer Resources::Gui::Data = Buffer(); + Buffer Resources::Gui::Color = Buffer(); Buffer Resources::Gui::Text::Vertex = Buffer(); Buffer Resources::Post::Data = Buffer(); @@ -118,6 +119,10 @@ namespace Oyster desc.ElementSize = sizeof(Definitions::AnimationData); Gather::AnimationData.Init(desc); + desc.Type = Buffer::BUFFER_TYPE::CONSTANT_BUFFER_PS; + desc.ElementSize = sizeof(Math::Float3); + Gui::Color.Init(desc); + desc.Type = Buffer::BUFFER_TYPE::CONSTANT_BUFFER_GS; desc.NumElements = 1; desc.ElementSize = sizeof(Definitions::GuiData); @@ -378,6 +383,7 @@ namespace Oyster Gui::Pass.Shaders.Geometry = GetShader::Geometry(L"2D"); Gui::Pass.RTV.push_back(GBufferRTV[2]); Gui::Pass.CBuffers.Geometry.push_back(Gui::Data); + Gui::Pass.CBuffers.Pixel.push_back(Gui::Color); D3D11_INPUT_ELEMENT_DESC indesc2D[] = { @@ -421,6 +427,7 @@ namespace Oyster Shader::CreateInputLayout(Text2Ddesc,3, GetShader::Vertex(L"2DText") ,Gui::Text::Pass.IAStage.Layout); Gui::Text::Pass.CBuffers.Geometry.push_back(Gui::Data); + Gui::Text::Pass.CBuffers.Pixel.push_back(Gui::Color); Gui::Text::Pass.SRV.Pixel.push_back(Gui::Text::Font); Gui::Text::Pass.RTV.push_back(GBufferRTV[2]); Gui::Text::Pass.RenderStates.SampleCount = 1; @@ -448,6 +455,7 @@ namespace Oyster Light::LightConstantsData.~Buffer(); Light::PointLightsData.~Buffer(); Gui::Data.~Buffer(); + Gui::Color.~Buffer(); Gui::Text::Vertex.~Buffer(); Post::Data.~Buffer(); SAFE_RELEASE(Light::PointLightView); diff --git a/Code/OysterGraphics/Render/Resources.h b/Code/OysterGraphics/Render/Resources.h index cdc12efc..d43b5756 100644 --- a/Code/OysterGraphics/Render/Resources.h +++ b/Code/OysterGraphics/Render/Resources.h @@ -61,6 +61,7 @@ namespace Oyster { static Core::PipelineManager::RenderPass Pass; static Core::Buffer Data; + static Core::Buffer Color; struct Text { static Core::PipelineManager::RenderPass Pass; diff --git a/Code/OysterGraphics/Shader/Passes/2D/2DPixel.hlsl b/Code/OysterGraphics/Shader/Passes/2D/2DPixel.hlsl index a09111b9..c28fd642 100644 --- a/Code/OysterGraphics/Shader/Passes/2D/2DPixel.hlsl +++ b/Code/OysterGraphics/Shader/Passes/2D/2DPixel.hlsl @@ -2,5 +2,5 @@ float4 main(Pixel2DIn input) : SV_Target0 { - return Material.Sample(LinearSampler,input.Uv); + return Material.Sample(LinearSampler,input.Uv) * float4(Color,1); } \ No newline at end of file diff --git a/Code/OysterGraphics/Shader/Passes/2D/Header.hlsli b/Code/OysterGraphics/Shader/Passes/2D/Header.hlsli index 5a026d34..4b507644 100644 --- a/Code/OysterGraphics/Shader/Passes/2D/Header.hlsli +++ b/Code/OysterGraphics/Shader/Passes/2D/Header.hlsli @@ -3,11 +3,16 @@ struct Vertex2DIn float2 Pos : Position; }; -cbuffer EveryObject2D : register(c0) +cbuffer EveryObject2D : register(b0) { float4x4 Translation; }; +cbuffer ColorData : register(b0) +{ + float3 Color; +}; + struct Pixel2DIn { float4 Pos : SV_Position; diff --git a/Code/OysterGraphics/Shader/Passes/2D/Text/Header.hlsli b/Code/OysterGraphics/Shader/Passes/2D/Text/Header.hlsli index 7b64fd79..6d7ab899 100644 --- a/Code/OysterGraphics/Shader/Passes/2D/Text/Header.hlsli +++ b/Code/OysterGraphics/Shader/Passes/2D/Text/Header.hlsli @@ -1,5 +1,5 @@ #include "../Header.hlsli" -cbuffer TextPerObject : register(c0) +cbuffer TextPerObject : register(b0) { float4x4 gWorld; }; diff --git a/Code/Tester/MainTest.cpp b/Code/Tester/MainTest.cpp index cd614f42..f545e42d 100644 --- a/Code/Tester/MainTest.cpp +++ b/Code/Tester/MainTest.cpp @@ -233,14 +233,14 @@ HRESULT Render(float deltaTime) Oyster::Graphics::API::RenderModel(m2); Oyster::Graphics::API::StartGuiRender(); Oyster::Graphics::API::RenderGuiElement(t,Oyster::Math::Float2(0.5f,0.5f),Oyster::Math::Float2(1,1)); - Oyster::Graphics::API::RenderGuiElement(t2,Oyster::Math::Float2(0.5f,0.1f),Oyster::Math::Float2(0.5f,0.1f)); + //Oyster::Graphics::API::RenderGuiElement(t2,Oyster::Math::Float2(0.5f,0.1f),Oyster::Math::Float2(0.5f,0.1f),Oyster::Math::Float3(1,0,0)); Oyster::Graphics::API::StartTextRender(); std::wstring fps; float f = 1/deltaTime; fps = std::to_wstring(f); //Oyster::Graphics::API::RenderText(L"Lanariel",Oyster::Math::Float2(0.5f,0.1f),Oyster::Math::Float2(0.5f,0.1f)); //Oyster::Graphics::API::RenderText(L"Lanariel WAS HERE",Oyster::Math::Float2(0.5f,0.1f),Oyster::Math::Float2(0.5f,0.1f)); - //Oyster::Graphics::API::RenderText(fps,Oyster::Math::Float2(0.5f,0.1f),Oyster::Math::Float2(0.5f,0.1f)); + Oyster::Graphics::API::RenderText(fps,Oyster::Math::Float2(0.5f,0.1f),Oyster::Math::Float2(0.5f,0.1f),Oyster::Math::Float3(0,1,0)); Oyster::Graphics::API::EndFrame(); return S_OK; From e6316f323989a66a2e9a91ab9b1ede523be3bba5 Mon Sep 17 00:00:00 2001 From: lanariel Date: Wed, 12 Feb 2014 09:32:15 +0100 Subject: [PATCH 2/2] removed some old stuff, respect animation looping state --- Code/OysterGraphics/ClassDiagram.cd | 2 - .../OysterGraphics.vcxproj.filters.orig | 88 ------- .../OysterGraphics.vcxproj.orig | 214 ------------------ .../OysterGraphics/Render/DefaultRenderer.cpp | 2 +- Code/Tester/MainTest.cpp | 2 +- 5 files changed, 2 insertions(+), 306 deletions(-) delete mode 100644 Code/OysterGraphics/ClassDiagram.cd delete mode 100644 Code/OysterGraphics/OysterGraphics.vcxproj.filters.orig delete mode 100644 Code/OysterGraphics/OysterGraphics.vcxproj.orig diff --git a/Code/OysterGraphics/ClassDiagram.cd b/Code/OysterGraphics/ClassDiagram.cd deleted file mode 100644 index 7b894197..00000000 --- a/Code/OysterGraphics/ClassDiagram.cd +++ /dev/null @@ -1,2 +0,0 @@ - - \ No newline at end of file diff --git a/Code/OysterGraphics/OysterGraphics.vcxproj.filters.orig b/Code/OysterGraphics/OysterGraphics.vcxproj.filters.orig deleted file mode 100644 index 94814340..00000000 --- a/Code/OysterGraphics/OysterGraphics.vcxproj.filters.orig +++ /dev/null @@ -1,88 +0,0 @@ - - - - - {4FC737F1-C7A5-4376-A066-2A32D752A2FF} - cpp;c;cc;cxx;def;odl;idl;hpj;bat;asm;asmx - - - {93995380-89BD-4b04-88EB-625FBE52EBFB} - h;hpp;hxx;hm;inl;inc;xsd - - - {67DA6AB6-F800-4c08-8B7A-83BB121AAD01} - rc;ico;cur;bmp;dlg;rc2;rct;bin;rgs;gif;jpg;jpeg;jpe;resx;tiff;tif;png;wav;mfcribbon-ms - - - - - Source Files - - - Source Files - - - Source Files - - - Source Files - -<<<<<<< HEAD - -======= - ->>>>>>> f08e9491ed00b00aedba0eabf1caed33830fc0e2 - Source Files - - - Source Files - -<<<<<<< HEAD - -======= - - Source Files - - ->>>>>>> f08e9491ed00b00aedba0eabf1caed33830fc0e2 - Source Files - - - - - Header Files - - - Header Files - - - Header Files - - - Header Files - - - Header Files - - - Header Files - - - Header Files - - - Header Files - - - Header Files - - - Header Files - - - - - - - - \ No newline at end of file diff --git a/Code/OysterGraphics/OysterGraphics.vcxproj.orig b/Code/OysterGraphics/OysterGraphics.vcxproj.orig deleted file mode 100644 index 8a0e9221..00000000 --- a/Code/OysterGraphics/OysterGraphics.vcxproj.orig +++ /dev/null @@ -1,214 +0,0 @@ - - - - - Debug - Win32 - - - Debug - x64 - - - Release - Win32 - - - Release - x64 - - - - {0EC83E64-230E-48EF-B08C-6AC9651B4F82} - OysterGraphics - - - - StaticLibrary - true - v110 - MultiByte - - - StaticLibrary - true - v110 - MultiByte - - - StaticLibrary - false - v110 - true - MultiByte - - - StaticLibrary - false - v110 - true - MultiByte - - - - - - - - - - - - - - - - - - - $(SolutionDir)..\External\Lib\$(ProjectName)\ - $(SolutionDir)..\Obj\$(ProjectName)\$(PlatformShortName)\$(Configuration)\ - $(ProjectName)_$(PlatformShortName)D - - - $(SolutionDir)..\External\Lib\$(ProjectName)\ - $(SolutionDir)..\Obj\$(ProjectName)\$(PlatformShortName)\$(Configuration)\ - $(ProjectName)_$(PlatformShortName) - - - $(SolutionDir)..\External\Lib\$(ProjectName)\ - $(SolutionDir)..\Obj\$(ProjectName)\$(PlatformShortName)\$(Configuration)\ - $(ProjectName)_$(PlatformShortName)D - - - $(SolutionDir)..\External\Lib\$(ProjectName)\ - $(SolutionDir)..\Obj\$(ProjectName)\$(PlatformShortName)\$(Configuration)\ - $(ProjectName)_$(PlatformShortName) - - - - Level3 - Disabled - true - $(SolutionDir)OysterMath;$(SolutionDir)Misc;%(AdditionalIncludeDirectories) - - - true - - - true - - - - - Level3 - Disabled - true - ..\OysterPhysic3D\Collision;..\OysterPhysics3D;..\OysterMath;..\Misc;%(AdditionalIncludeDirectories) - - - true - - - - - Level3 - MaxSpeed - true - true - true - ..\OysterPhysics3D;..\OysterMath;..\Misc;%(AdditionalIncludeDirectories) - - - true - true - true - - - - - Level3 - MaxSpeed - true - true - true - ..\OysterPhysics3D;..\OysterMath;..\Misc;%(AdditionalIncludeDirectories) - - - true - true - true - - - - - - - -<<<<<<< HEAD - - - -======= - - - - ->>>>>>> f08e9491ed00b00aedba0eabf1caed33830fc0e2 - - - - - -<<<<<<< HEAD -======= - - ->>>>>>> f08e9491ed00b00aedba0eabf1caed33830fc0e2 - - - - - - - - - - {2ec4dded-8f75-4c86-a10b-e1e8eb29f3ee} - - - {f10cbc03-9809-4cba-95d8-327c287b18ee} - - - - - Vertex - Vertex - Vertex - Vertex - - - Pixel - Pixel - Pixel - Pixel - true - 5.0 - main - - - Vertex - Vertex - Vertex - Vertex - true - 5.0 - main - - - - - - - - \ No newline at end of file diff --git a/Code/OysterGraphics/Render/DefaultRenderer.cpp b/Code/OysterGraphics/Render/DefaultRenderer.cpp index 2ad8646b..a92c54d6 100644 --- a/Code/OysterGraphics/Render/DefaultRenderer.cpp +++ b/Code/OysterGraphics/Render/DefaultRenderer.cpp @@ -82,7 +82,7 @@ namespace Oyster } int b = 0; Model::Animation A = *models[i].Animation.AnimationPlaying; - while(models[i].Animation.AnimationTime>A.duration) + while(models[i].Animation.AnimationTime>A.duration && models[i].Animation.LoopAnimation) models[i].Animation.AnimationTime -= (float)A.duration; float position = models[i].Animation.AnimationTime; diff --git a/Code/Tester/MainTest.cpp b/Code/Tester/MainTest.cpp index f545e42d..4462f060 100644 --- a/Code/Tester/MainTest.cpp +++ b/Code/Tester/MainTest.cpp @@ -176,7 +176,7 @@ HRESULT InitDirect3D() m->WorldMatrix.m[2][2] = 0.00000005f; m2 = Oyster::Graphics::API::CreateModel(L"char_temporary.dan"); m2->WorldMatrix = Oyster::Math3D::OrientationMatrix(Oyster::Math::Float3::null,Oyster::Math::Float3(4,0,0),Oyster::Math::Float3::null); - Oyster::Graphics::API::PlayAnimation(m2, L"movement",true); + Oyster::Graphics::API::PlayAnimation(m2, L"movement",false); t = Oyster::Graphics::API::CreateTexture(L"structure_corp_mdg.png"); t2 = Oyster::Graphics::API::CreateTexture(L"whiteGui.png");