From 483236801fc140cb4fae290a4c6f3097f7a184a9 Mon Sep 17 00:00:00 2001 From: lanariel Date: Thu, 16 Jan 2014 09:30:01 +0100 Subject: [PATCH] Fixed compile warnings and crash on non existing models --- Code/OysterGraphics/Core/Buffer.cpp | 5 +++ Code/OysterGraphics/Core/Core.h | 2 +- Code/OysterGraphics/Core/Init.cpp | 4 +-- Code/OysterGraphics/Core/PipelineManager.cpp | 36 +++++++++---------- Code/OysterGraphics/DllInterfaces/GFXAPI.cpp | 12 ++++++- Code/OysterGraphics/DllInterfaces/GFXAPI.h | 2 +- Code/OysterGraphics/FileLoader/ObjReader.cpp | 1 - .../Render/Rendering/BasicRender.cpp | 8 +++-- .../Render/Resources/Deffered.cpp | 2 +- .../HLSL/Deffered Shaders/GBufferHeader.hlsli | 1 - .../HLSL/Deffered Shaders/LightCalc.hlsli | 4 +-- .../HLSL/Deffered Shaders/LightPass.hlsl | 6 ++-- .../Shader/HLSL/Deffered Shaders/SSAO.hlsli | 2 +- .../Deffered Shaders/VertexGatherData.hlsl | 2 +- Code/Tester/MainTest.cpp | 20 +++-------- Code/Tester/Tester.vcxproj | 1 + 16 files changed, 57 insertions(+), 51 deletions(-) diff --git a/Code/OysterGraphics/Core/Buffer.cpp b/Code/OysterGraphics/Core/Buffer.cpp index e84d91d3..d6994554 100644 --- a/Code/OysterGraphics/Core/Buffer.cpp +++ b/Code/OysterGraphics/Core/Buffer.cpp @@ -214,4 +214,9 @@ UINT32 Core::Buffer::GetElementCount() UINT32 Core::Buffer::GetVertexSize() { return this->mElementSize; +} + +ID3D11Buffer* Core::Buffer::GetBufferPointer() +{ + return this->mBuffer; } \ No newline at end of file diff --git a/Code/OysterGraphics/Core/Core.h b/Code/OysterGraphics/Core/Core.h index 126323eb..3e8ffdd6 100644 --- a/Code/OysterGraphics/Core/Core.h +++ b/Code/OysterGraphics/Core/Core.h @@ -7,7 +7,7 @@ #include "Dx11Includes.h" #include #include "OysterMath.h" -#include +//#include namespace Oyster { diff --git a/Code/OysterGraphics/Core/Init.cpp b/Code/OysterGraphics/Core/Init.cpp index db63d847..05a91a59 100644 --- a/Code/OysterGraphics/Core/Init.cpp +++ b/Code/OysterGraphics/Core/Init.cpp @@ -356,8 +356,8 @@ namespace Oyster { ID3D11Texture2D* tex; D3D11_TEXTURE2D_DESC texDesc; - texDesc.Width = Core::resolution.x; - texDesc.Height = Core::resolution.y; + texDesc.Width = (UINT)Core::resolution.x; + texDesc.Height = (UINT)Core::resolution.y; texDesc.MipLevels = 1; texDesc.ArraySize = 1; texDesc.Format = DXGI_FORMAT_R32G32B32A32_FLOAT; diff --git a/Code/OysterGraphics/Core/PipelineManager.cpp b/Code/OysterGraphics/Core/PipelineManager.cpp index ae9e4088..c77873b5 100644 --- a/Code/OysterGraphics/Core/PipelineManager.cpp +++ b/Code/OysterGraphics/Core/PipelineManager.cpp @@ -58,7 +58,7 @@ namespace Oyster } else { - VSMap[name] = VS.size(); + VSMap[name] = (int)VS.size(); VS.push_back((ID3D11VertexShader*)data); } } @@ -76,7 +76,7 @@ namespace Oyster } else { - HSMap[name] = HS.size(); + HSMap[name] = (int)HS.size(); HS.push_back((ID3D11HullShader*)data); } @@ -95,7 +95,7 @@ namespace Oyster } else { - DSMap[name] = DS.size(); + DSMap[name] = (int)DS.size(); DS.push_back((ID3D11DomainShader*)data); } } @@ -113,7 +113,7 @@ namespace Oyster } else { - GSMap[name] = GS.size(); + GSMap[name] = (int)GS.size(); GS.push_back((ID3D11GeometryShader*)data); } } @@ -131,7 +131,7 @@ namespace Oyster } else { - PSMap[name] = PS.size(); + PSMap[name] = (int)PS.size(); PS.push_back((ID3D11PixelShader*)data); } } @@ -149,7 +149,7 @@ namespace Oyster } else { - CSMap[name] = CS.size(); + CSMap[name] = (int)CS.size(); CS.push_back((ID3D11ComputeShader*)data); } @@ -347,19 +347,19 @@ namespace Oyster Core::deviceContext->IASetPrimitiveTopology(se.IAStage.Topology); if(se.CBuffers.Vertex.size()) { - deviceContext->VSSetConstantBuffers(0,se.CBuffers.Vertex.size(),&se.CBuffers.Vertex[0]); + deviceContext->VSSetConstantBuffers(0,(int)se.CBuffers.Vertex.size(),&se.CBuffers.Vertex[0]); } if(se.CBuffers.Pixel.size()) { - deviceContext->PSSetConstantBuffers(0,se.CBuffers.Pixel.size(),&se.CBuffers.Pixel[0]); + deviceContext->PSSetConstantBuffers(0,(int)se.CBuffers.Pixel.size(),&se.CBuffers.Pixel[0]); } if(se.CBuffers.Geometry.size()) { - deviceContext->GSSetConstantBuffers(0,se.CBuffers.Geometry.size(),&se.CBuffers.Geometry[0]); + deviceContext->GSSetConstantBuffers(0,(int)se.CBuffers.Geometry.size(),&se.CBuffers.Geometry[0]); } if(se.CBuffers.Compute.size()) { - deviceContext->CSSetConstantBuffers(0,se.CBuffers.Compute.size(),&se.CBuffers.Compute[0]); + deviceContext->CSSetConstantBuffers(0,(int)se.CBuffers.Compute.size(),&se.CBuffers.Compute[0]); } Core::deviceContext->RSSetState(se.RenderStates.Rasterizer); Core::deviceContext->PSSetSamplers(0,se.RenderStates.SampleCount,se.RenderStates.SampleState); @@ -369,43 +369,43 @@ namespace Oyster if(se.SRV.Vertex.size()) { - Core::deviceContext->VSSetShaderResources(0,se.SRV.Vertex.size(),&se.SRV.Vertex[0]); + Core::deviceContext->VSSetShaderResources(0,(int)se.SRV.Vertex.size(),&se.SRV.Vertex[0]); } if(se.SRV.Geometry.size()) { - Core::deviceContext->GSSetShaderResources(0,se.SRV.Geometry.size(),&se.SRV.Geometry[0]); + Core::deviceContext->GSSetShaderResources(0,(int)se.SRV.Geometry.size(),&se.SRV.Geometry[0]); } if(se.SRV.Pixel.size()) { - Core::deviceContext->PSSetShaderResources(0,se.SRV.Pixel.size(),&se.SRV.Pixel[0]); + Core::deviceContext->PSSetShaderResources(0,(int)se.SRV.Pixel.size(),&se.SRV.Pixel[0]); } if(se.SRV.Compute.size()) { - Core::deviceContext->CSSetShaderResources(0,se.SRV.Compute.size(),&se.SRV.Compute[0]); + Core::deviceContext->CSSetShaderResources(0,(int)se.SRV.Compute.size(),&se.SRV.Compute[0]); } if(se.RTV.size()) { if(se.UAV.Pixel.size()) { - deviceContext->OMSetRenderTargetsAndUnorderedAccessViews(se.RTV.size(),&se.RTV[0],se.depth,se.RTV.size(),se.UAV.Pixel.size(),&se.UAV.Pixel[0],0); + deviceContext->OMSetRenderTargetsAndUnorderedAccessViews((int)se.RTV.size(),&se.RTV[0],se.depth,(int)se.RTV.size(),(int)se.UAV.Pixel.size(),&se.UAV.Pixel[0],0); } else { - deviceContext->OMSetRenderTargets(se.RTV.size(),&se.RTV[0],se.depth); + deviceContext->OMSetRenderTargets((int)se.RTV.size(),&se.RTV[0],se.depth); } } else { if(se.UAV.Pixel.size()) { - deviceContext->OMSetRenderTargetsAndUnorderedAccessViews(0,NULL,se.depth,0,se.UAV.Pixel.size(),&se.UAV.Pixel[0],0); + deviceContext->OMSetRenderTargetsAndUnorderedAccessViews(0,NULL,se.depth,0,(int)se.UAV.Pixel.size(),&se.UAV.Pixel[0],0); } } if(se.UAV.Compute.size()) { - deviceContext->CSSetUnorderedAccessViews(0,se.UAV.Compute.size(),&se.UAV.Compute[0],0); + deviceContext->CSSetUnorderedAccessViews(0,(int)se.UAV.Compute.size(),&se.UAV.Compute[0],0); } } diff --git a/Code/OysterGraphics/DllInterfaces/GFXAPI.cpp b/Code/OysterGraphics/DllInterfaces/GFXAPI.cpp index 4d612513..b38984dc 100644 --- a/Code/OysterGraphics/DllInterfaces/GFXAPI.cpp +++ b/Code/OysterGraphics/DllInterfaces/GFXAPI.cpp @@ -6,6 +6,7 @@ #include "../FileLoader/ObjReader.h" #include "../../Misc/Resource/OysterResource.h" #include "../FileLoader/GeneralLoader.h" +#include "../Model/ModelInfo.h" #include namespace Oyster @@ -47,7 +48,7 @@ namespace Oyster { if(Lights.size()) { - Render::Rendering::Basic::NewFrame(View, Projection, &Lights[0], Lights.size()); + Render::Rendering::Basic::NewFrame(View, Projection, &Lights[0], (int)Lights.size()); } else { @@ -75,6 +76,7 @@ namespace Oyster return API::Sucsess; } + //returns null for invalid filenames Model::Model* API::CreateModel(std::wstring filename) { Model::Model* m = new Model::Model(); @@ -83,11 +85,19 @@ namespace Oyster m->info = Oyster::Resource::OysterResource::LoadResource(filename.c_str(),Oyster::Graphics::Loading::LoadOBJ); + Model::ModelInfo* mi = (Model::ModelInfo*)m->info; + if(mi->Vertices->GetBufferPointer() == NULL) + { + return NULL; + } + return m; } void API::DeleteModel(Model::Model* model) { + if(model==NULL) + return; Model::ModelInfo* info = (Model::ModelInfo*)model->info; delete model; Oyster::Resource::OysterResource::ReleaseResource((Oyster::Resource::OHRESOURCE)info); diff --git a/Code/OysterGraphics/DllInterfaces/GFXAPI.h b/Code/OysterGraphics/DllInterfaces/GFXAPI.h index 65bffe5a..950ef19f 100644 --- a/Code/OysterGraphics/DllInterfaces/GFXAPI.h +++ b/Code/OysterGraphics/DllInterfaces/GFXAPI.h @@ -4,7 +4,7 @@ #include "..\Model\Model.h" #include "OysterMath.h" #include -#include +//#include #ifdef GFX_DLL_EXPORT #define GFX_DLL_USAGE __declspec(dllexport) diff --git a/Code/OysterGraphics/FileLoader/ObjReader.cpp b/Code/OysterGraphics/FileLoader/ObjReader.cpp index ccc32fea..60e7824f 100644 --- a/Code/OysterGraphics/FileLoader/ObjReader.cpp +++ b/Code/OysterGraphics/FileLoader/ObjReader.cpp @@ -230,7 +230,6 @@ std::map ObjReader::GetMaterials(std::w input.open(fileName.c_str()); std::map materials; - ID3D11ShaderResourceView *srv; string texture; string s; string path; diff --git a/Code/OysterGraphics/Render/Rendering/BasicRender.cpp b/Code/OysterGraphics/Render/Rendering/BasicRender.cpp index 9950ce76..06e53e69 100644 --- a/Code/OysterGraphics/Render/Rendering/BasicRender.cpp +++ b/Code/OysterGraphics/Render/Rendering/BasicRender.cpp @@ -50,6 +50,8 @@ namespace Oyster { for(int i = 0; i < count; ++i) { + if(&models[i] == NULL) + continue; if(models[i].Visible) { Definitions::PerModel pm; @@ -65,7 +67,7 @@ namespace Oyster if(info->Material.size()) { - Core::deviceContext->PSSetShaderResources(0,info->Material.size(),&(info->Material[0])); + Core::deviceContext->PSSetShaderResources(0,(UINT)info->Material.size(),&(info->Material[0])); } @@ -86,11 +88,11 @@ namespace Oyster { Core::PipelineManager::SetRenderPass(Resources::Deffered::LightPass); - Core::deviceContext->Dispatch((Core::resolution.x + 15U) / 16U,(Core::resolution.y + 15U) / 16U,1); + Core::deviceContext->Dispatch((UINT)((Core::resolution.x + 15U) / 16U), (UINT)((Core::resolution.y + 15U) / 16U), 1); Core::PipelineManager::SetRenderPass(Resources::Deffered::PostPass); - Core::deviceContext->Dispatch((Core::resolution.x + 15U) / 16U,(Core::resolution.y + 15U) / 16U,1); + Core::deviceContext->Dispatch((UINT)((Core::resolution.x + 15U) / 16U), (UINT)((Core::resolution.y + 15U) / 16U), 1); Core::swapChain->Present(0,0); } diff --git a/Code/OysterGraphics/Render/Resources/Deffered.cpp b/Code/OysterGraphics/Render/Resources/Deffered.cpp index 77bcad09..b1189f39 100644 --- a/Code/OysterGraphics/Render/Resources/Deffered.cpp +++ b/Code/OysterGraphics/Render/Resources/Deffered.cpp @@ -155,7 +155,7 @@ namespace Oyster Buffer* b = &PointLightsData; Core::Init::CreateLinkedShaderResourceFromStructuredBuffer(&b,&PointLightView,NULL); - srand(time(0)); + srand((unsigned int)time(0)); //SSAO Math::Vector3 kernel[KernelSize]; Math::Vector3 random[SampleSpread]; diff --git a/Code/OysterGraphics/Shader/HLSL/Deffered Shaders/GBufferHeader.hlsli b/Code/OysterGraphics/Shader/HLSL/Deffered Shaders/GBufferHeader.hlsli index 2f5a4a01..74f8cc33 100644 --- a/Code/OysterGraphics/Shader/HLSL/Deffered Shaders/GBufferHeader.hlsli +++ b/Code/OysterGraphics/Shader/HLSL/Deffered Shaders/GBufferHeader.hlsli @@ -12,7 +12,6 @@ struct VertexIn struct VertexOut { float4 pos : SV_POSITION; - float4 ViewPos : POSITION; float2 UV : TEXCOORD; float3 normal : NORMAL; //float3 tangent : TANGENT; diff --git a/Code/OysterGraphics/Shader/HLSL/Deffered Shaders/LightCalc.hlsli b/Code/OysterGraphics/Shader/HLSL/Deffered Shaders/LightCalc.hlsli index bd449209..8a1ff05a 100644 --- a/Code/OysterGraphics/Shader/HLSL/Deffered Shaders/LightCalc.hlsli +++ b/Code/OysterGraphics/Shader/HLSL/Deffered Shaders/LightCalc.hlsli @@ -21,8 +21,8 @@ DiffSpec LightCalc(PointLight pl, float3 pos, int2 texCoord) output.Specular * 0; if(d > pl.Radius) { - output.Diffuse = float4(0,0,0,1); - output.Specular = float4(0,0,0,1); + output.Diffuse = float3(0,0,0); + output.Specular = float3(0,0,0); } return output; } \ No newline at end of file diff --git a/Code/OysterGraphics/Shader/HLSL/Deffered Shaders/LightPass.hlsl b/Code/OysterGraphics/Shader/HLSL/Deffered Shaders/LightPass.hlsl index 98b2887e..0aec75da 100644 --- a/Code/OysterGraphics/Shader/HLSL/Deffered Shaders/LightPass.hlsl +++ b/Code/OysterGraphics/Shader/HLSL/Deffered Shaders/LightPass.hlsl @@ -12,13 +12,13 @@ [numthreads(16, 16, 1)] void main( uint3 DTid : SV_DispatchThreadID, uint3 GTid : SV_GroupThreadID ) { - float2 UV = DTid / Pixels; + float2 UV = DTid.xy / Pixels; UV.x = UV.x * 2 - 1; UV.y = 1 - 2 * UV.y; float3 ViewPos = ToVpos(DTid.xy, UV); DiffSpec Shaded; - Shaded.Diffuse = float4(0,0,0,0); - Shaded.Specular = float4(0,0,0,0); + Shaded.Diffuse = float3(0,0,0); + Shaded.Specular = float3(0,0,0); for(int i = 0; i < Lights; ++i) { diff --git a/Code/OysterGraphics/Shader/HLSL/Deffered Shaders/SSAO.hlsli b/Code/OysterGraphics/Shader/HLSL/Deffered Shaders/SSAO.hlsli index 32f84f90..b7e2a9f1 100644 --- a/Code/OysterGraphics/Shader/HLSL/Deffered Shaders/SSAO.hlsli +++ b/Code/OysterGraphics/Shader/HLSL/Deffered Shaders/SSAO.hlsli @@ -24,7 +24,7 @@ float GetSSAO(float3 pos, float2 uv, int2 texCoord2, uint2 rndID) float4 ProjOffset = sampled; ProjOffset = mul(Proj, ProjOffset); float4 offset = ProjOffset; - float2 UV = offset; + float2 UV = offset.xy; offset /= offset.w; offset.xyz = offset.xyz * 0.5f + 0.5f; //extra invert y axis, DX11 diff --git a/Code/OysterGraphics/Shader/HLSL/Deffered Shaders/VertexGatherData.hlsl b/Code/OysterGraphics/Shader/HLSL/Deffered Shaders/VertexGatherData.hlsl index e0cf21c3..8a361ccf 100644 --- a/Code/OysterGraphics/Shader/HLSL/Deffered Shaders/VertexGatherData.hlsl +++ b/Code/OysterGraphics/Shader/HLSL/Deffered Shaders/VertexGatherData.hlsl @@ -4,7 +4,7 @@ VertexOut main( VertexIn input ) { VertexOut output; output.pos = mul(WVP, float4(input.pos,1)); - output.normal = mul(WV, float4(input.normal,0)); + output.normal = mul(WV, float4(input.normal,0)).xyz; output.UV = input.UV; return output; } \ No newline at end of file diff --git a/Code/Tester/MainTest.cpp b/Code/Tester/MainTest.cpp index e3284c0b..af6917c8 100644 --- a/Code/Tester/MainTest.cpp +++ b/Code/Tester/MainTest.cpp @@ -44,18 +44,6 @@ int WINAPI wWinMain( HINSTANCE hInstance, HINSTANCE hPrevInstance, LPWSTR lpCmdL { BOOL b = SetDllDirectoryW(L"..\\DLL"); - typedef struct tagLOADPARMS32 - { - LPSTR lpEnvAddress; // address of environment strings - LPSTR lpCmdLine; // address of command line - LPSTR lpCmdShow; // how to show new program - DWORD dwReserved; // must be zero - } LOADPARMS32; - LOADPARMS32 params; - params.dwReserved=NULL; - params.lpCmdLine=""; - params.lpCmdShow=""; - params.lpEnvAddress=""; if( FAILED( InitWindow( hInstance, nCmdShow ) ) ) return 0; @@ -171,10 +159,12 @@ HRESULT InitDirect3D() return E_FAIL; } - m = Oyster::Graphics::API::CreateModel(L"orca_dummy"); - m2 = Oyster::Graphics::API::CreateModel(L"worldDummy"); + m = Oyster::Graphics::API::CreateModel(L"crate2"); + if(m==NULL) + m = Oyster::Graphics::API::CreateModel(L"crate"); + m2 = Oyster::Graphics::API::CreateModel(L"crate"); m2->WorldMatrix = Oyster::Math3D::OrientationMatrix(Oyster::Math::Float3::null,Oyster::Math::Float3(0,5,0),Oyster::Math::Float3::null); - m3 = Oyster::Graphics::API::CreateModel(L"worldDummy"); + m3 = Oyster::Graphics::API::CreateModel(L"crate"); m3->WorldMatrix = Oyster::Math3D::OrientationMatrix(Oyster::Math::Float3::null,Oyster::Math::Float3(0,5,0),Oyster::Math::Float3::null); diff --git a/Code/Tester/Tester.vcxproj b/Code/Tester/Tester.vcxproj index 80853c72..2f10fdc5 100644 --- a/Code/Tester/Tester.vcxproj +++ b/Code/Tester/Tester.vcxproj @@ -136,6 +136,7 @@ OysterGraphics_$(PlatformShortName)D.lib;%(AdditionalDependencies) $(SolutionDir)..\Bin\DLL;%(AdditionalLibraryDirectories) true + OysterGraphics_$(PlatformShortName)D.dll;