port from perforce
This commit is contained in:
16
aiwaz/Aiwaz/Aiwaz.cpp
Normal file
16
aiwaz/Aiwaz/Aiwaz.cpp
Normal file
@@ -0,0 +1,16 @@
|
||||
#include "stdafx.h"
|
||||
#include "Aiwaz.h"
|
||||
|
||||
#include "Engine/Engine.h"
|
||||
#include "Window/Window.h"
|
||||
|
||||
namespace Aiwaz
|
||||
{
|
||||
extern "C"
|
||||
{
|
||||
IEngine* CreateEngine()
|
||||
{
|
||||
return new Engine();
|
||||
}
|
||||
}
|
||||
}
|
||||
21
aiwaz/Aiwaz/Aiwaz.h
Normal file
21
aiwaz/Aiwaz/Aiwaz.h
Normal file
@@ -0,0 +1,21 @@
|
||||
#pragma once
|
||||
|
||||
#include "IEngine.h"
|
||||
#include "IRenderTargetBase.h"
|
||||
#include "IResourceFactory.h"
|
||||
#include "ICommonObjectFactory.h"
|
||||
#include "IDeviceEnumerator.h"
|
||||
#include "IWindow.h"
|
||||
#include "IUpdatable.h"
|
||||
#include "IFileSystem.h"
|
||||
|
||||
#ifndef _WINDLL
|
||||
#define DLL extern "C" __declspec(dllimport)
|
||||
#else
|
||||
#define DLL extern "C" __declspec(dllexport)
|
||||
#endif
|
||||
|
||||
namespace Aiwaz
|
||||
{
|
||||
DLL IEngine* CreateEngine();
|
||||
}
|
||||
687
aiwaz/Aiwaz/Aiwaz.vcproj
Normal file
687
aiwaz/Aiwaz/Aiwaz.vcproj
Normal file
@@ -0,0 +1,687 @@
|
||||
<?xml version="1.0" encoding="Windows-1252"?>
|
||||
<VisualStudioProject
|
||||
ProjectType="Visual C++"
|
||||
Version="9,00"
|
||||
Name="Aiwaz"
|
||||
ProjectGUID="{19BD7EE4-4F92-4695-A59F-8A96618FD709}"
|
||||
RootNamespace="Aiwaz"
|
||||
TargetFrameworkVersion="196613"
|
||||
>
|
||||
<Platforms>
|
||||
<Platform
|
||||
Name="Win32"
|
||||
/>
|
||||
</Platforms>
|
||||
<ToolFiles>
|
||||
</ToolFiles>
|
||||
<Configurations>
|
||||
<Configuration
|
||||
Name="Debug|Win32"
|
||||
OutputDirectory="$(SolutionDir)$(ConfigurationName)"
|
||||
IntermediateDirectory="$(SolutionDir)obj\$(ConfigurationName)\$(ProjectName)"
|
||||
ConfigurationType="2"
|
||||
CharacterSet="2"
|
||||
>
|
||||
<Tool
|
||||
Name="VCPreBuildEventTool"
|
||||
/>
|
||||
<Tool
|
||||
Name="VCCustomBuildTool"
|
||||
/>
|
||||
<Tool
|
||||
Name="VCXMLDataGeneratorTool"
|
||||
/>
|
||||
<Tool
|
||||
Name="VCWebServiceProxyGeneratorTool"
|
||||
/>
|
||||
<Tool
|
||||
Name="VCMIDLTool"
|
||||
/>
|
||||
<Tool
|
||||
Name="VCCLCompilerTool"
|
||||
Optimization="0"
|
||||
AdditionalIncludeDirectories="Interfaces"
|
||||
PreprocessorDefinitions="WIN32;_DEBUG;_WINDOWS"
|
||||
MinimalRebuild="true"
|
||||
BasicRuntimeChecks="3"
|
||||
RuntimeLibrary="3"
|
||||
StructMemberAlignment="1"
|
||||
EnableEnhancedInstructionSet="2"
|
||||
UsePrecompiledHeader="2"
|
||||
WarningLevel="3"
|
||||
DebugInformationFormat="4"
|
||||
/>
|
||||
<Tool
|
||||
Name="VCManagedResourceCompilerTool"
|
||||
/>
|
||||
<Tool
|
||||
Name="VCResourceCompilerTool"
|
||||
/>
|
||||
<Tool
|
||||
Name="VCPreLinkEventTool"
|
||||
/>
|
||||
<Tool
|
||||
Name="VCLinkerTool"
|
||||
AdditionalDependencies="dxgi.lib d3d10.lib d3dx10d.lib shlwapi.lib"
|
||||
OutputFile="$(OutDir)\$(ProjectName).dll"
|
||||
LinkIncremental="2"
|
||||
AdditionalLibraryDirectories=""$(SolutionDir)lib\$(ConfigurationName)";"$(ProjectDir)""
|
||||
GenerateDebugInformation="true"
|
||||
SubSystem="1"
|
||||
RandomizedBaseAddress="1"
|
||||
DataExecutionPrevention="0"
|
||||
TargetMachine="1"
|
||||
/>
|
||||
<Tool
|
||||
Name="VCALinkTool"
|
||||
/>
|
||||
<Tool
|
||||
Name="VCManifestTool"
|
||||
UseFAT32Workaround="true"
|
||||
/>
|
||||
<Tool
|
||||
Name="VCXDCMakeTool"
|
||||
/>
|
||||
<Tool
|
||||
Name="VCBscMakeTool"
|
||||
/>
|
||||
<Tool
|
||||
Name="VCFxCopTool"
|
||||
/>
|
||||
<Tool
|
||||
Name="VCAppVerifierTool"
|
||||
/>
|
||||
<Tool
|
||||
Name="VCPostBuildEventTool"
|
||||
/>
|
||||
</Configuration>
|
||||
<Configuration
|
||||
Name="Release|Win32"
|
||||
OutputDirectory="$(SolutionDir)$(ConfigurationName)"
|
||||
IntermediateDirectory="$(SolutionDir)obj\$(ConfigurationName)\$(ProjectName)"
|
||||
ConfigurationType="2"
|
||||
CharacterSet="2"
|
||||
WholeProgramOptimization="1"
|
||||
>
|
||||
<Tool
|
||||
Name="VCPreBuildEventTool"
|
||||
/>
|
||||
<Tool
|
||||
Name="VCCustomBuildTool"
|
||||
/>
|
||||
<Tool
|
||||
Name="VCXMLDataGeneratorTool"
|
||||
/>
|
||||
<Tool
|
||||
Name="VCWebServiceProxyGeneratorTool"
|
||||
/>
|
||||
<Tool
|
||||
Name="VCMIDLTool"
|
||||
/>
|
||||
<Tool
|
||||
Name="VCCLCompilerTool"
|
||||
Optimization="2"
|
||||
EnableIntrinsicFunctions="true"
|
||||
AdditionalIncludeDirectories="Interfaces"
|
||||
PreprocessorDefinitions="WIN32;NDEBUG;_WINDOWS"
|
||||
RuntimeLibrary="0"
|
||||
StructMemberAlignment="1"
|
||||
EnableFunctionLevelLinking="true"
|
||||
EnableEnhancedInstructionSet="2"
|
||||
UsePrecompiledHeader="2"
|
||||
WarningLevel="3"
|
||||
DebugInformationFormat="3"
|
||||
/>
|
||||
<Tool
|
||||
Name="VCManagedResourceCompilerTool"
|
||||
/>
|
||||
<Tool
|
||||
Name="VCResourceCompilerTool"
|
||||
/>
|
||||
<Tool
|
||||
Name="VCPreLinkEventTool"
|
||||
/>
|
||||
<Tool
|
||||
Name="VCLinkerTool"
|
||||
AdditionalDependencies="dxgi.lib d3d10.lib d3dx10.lib shlwapi.lib"
|
||||
LinkIncremental="2"
|
||||
AdditionalLibraryDirectories=""$(SolutionDir)lib\$(ConfigurationName)";"$(ProjectDir)""
|
||||
GenerateDebugInformation="true"
|
||||
OptimizeReferences="2"
|
||||
EnableCOMDATFolding="2"
|
||||
RandomizedBaseAddress="1"
|
||||
DataExecutionPrevention="0"
|
||||
TargetMachine="1"
|
||||
/>
|
||||
<Tool
|
||||
Name="VCALinkTool"
|
||||
/>
|
||||
<Tool
|
||||
Name="VCManifestTool"
|
||||
/>
|
||||
<Tool
|
||||
Name="VCXDCMakeTool"
|
||||
/>
|
||||
<Tool
|
||||
Name="VCBscMakeTool"
|
||||
/>
|
||||
<Tool
|
||||
Name="VCFxCopTool"
|
||||
/>
|
||||
<Tool
|
||||
Name="VCAppVerifierTool"
|
||||
/>
|
||||
<Tool
|
||||
Name="VCPostBuildEventTool"
|
||||
/>
|
||||
</Configuration>
|
||||
</Configurations>
|
||||
<References>
|
||||
</References>
|
||||
<Files>
|
||||
<Filter
|
||||
Name="Source Files"
|
||||
Filter="cpp;c;cc;cxx;def;odl;idl;hpj;bat;asm;asmx"
|
||||
UniqueIdentifier="{4FC737F1-C7A5-4376-A066-2A32D752A2FF}"
|
||||
>
|
||||
<File
|
||||
RelativePath=".\Aiwaz.cpp"
|
||||
>
|
||||
</File>
|
||||
<File
|
||||
RelativePath=".\AnimationManager\AnimationManager.cpp"
|
||||
>
|
||||
</File>
|
||||
<File
|
||||
RelativePath=".\Resources\Camera\BaseCamera.cpp"
|
||||
>
|
||||
</File>
|
||||
<File
|
||||
RelativePath=".\Resources\ShaderParameterCollection\BasisParameterCollection.cpp"
|
||||
>
|
||||
</File>
|
||||
<File
|
||||
RelativePath=".\Resources\Bone\Bone.cpp"
|
||||
>
|
||||
</File>
|
||||
<File
|
||||
RelativePath=".\Resources\Bone\BoneController.cpp"
|
||||
>
|
||||
</File>
|
||||
<File
|
||||
RelativePath=".\FileSystem\CFileLoader\CFileLoader.cpp"
|
||||
>
|
||||
</File>
|
||||
<File
|
||||
RelativePath=".\Commands\CommandBuffer.cpp"
|
||||
>
|
||||
</File>
|
||||
<File
|
||||
RelativePath=".\Commands\CommandUserBase.cpp"
|
||||
>
|
||||
</File>
|
||||
<File
|
||||
RelativePath=".\CommonObjectFactory\CommonObjectFactory.cpp"
|
||||
>
|
||||
</File>
|
||||
<File
|
||||
RelativePath=".\DeviceEnumerator\DeviceEnumerator.cpp"
|
||||
>
|
||||
</File>
|
||||
<File
|
||||
RelativePath=".\DeviceEnumerator\DeviceVisitor\DeviceVisitorBase.cpp"
|
||||
>
|
||||
</File>
|
||||
<File
|
||||
RelativePath=".\DeviceEnumerator\DisplayAdapter.cpp"
|
||||
>
|
||||
</File>
|
||||
<File
|
||||
RelativePath=".\DeviceEnumerator\DisplayMode.cpp"
|
||||
>
|
||||
</File>
|
||||
<File
|
||||
RelativePath=".\Engine\Engine.cpp"
|
||||
>
|
||||
</File>
|
||||
<File
|
||||
RelativePath=".\FileSystem\File.cpp"
|
||||
>
|
||||
</File>
|
||||
<File
|
||||
RelativePath=".\FileSystem\FileSystem.cpp"
|
||||
>
|
||||
</File>
|
||||
<File
|
||||
RelativePath=".\Resources\GeometryBuffer\GeometryBuffer.cpp"
|
||||
>
|
||||
</File>
|
||||
<File
|
||||
RelativePath=".\Resources\Shader\InternalShader.cpp"
|
||||
>
|
||||
</File>
|
||||
<File
|
||||
RelativePath=".\Resources\Camera\OrthographicCamera.cpp"
|
||||
>
|
||||
</File>
|
||||
<File
|
||||
RelativePath=".\DeviceEnumerator\OutputDevice.cpp"
|
||||
>
|
||||
</File>
|
||||
<File
|
||||
RelativePath=".\Resources\Camera\PerspectiveCamera.cpp"
|
||||
>
|
||||
</File>
|
||||
<File
|
||||
RelativePath=".\CommonObjectFactory\PingPongBuffer\PingPongBuffer.cpp"
|
||||
>
|
||||
</File>
|
||||
<File
|
||||
RelativePath=".\Resources\RenderCommandNode\RenderCommandNode.cpp"
|
||||
>
|
||||
</File>
|
||||
<File
|
||||
RelativePath=".\Resources\RenderTarget\RenderTargetBase.cpp"
|
||||
>
|
||||
</File>
|
||||
<File
|
||||
RelativePath=".\Resources\RenderTarget\RenderTargetTexture\RenderTargetTexture.cpp"
|
||||
>
|
||||
</File>
|
||||
<File
|
||||
RelativePath=".\ResourceFactory\ResourceFactory.cpp"
|
||||
>
|
||||
</File>
|
||||
<File
|
||||
RelativePath=".\Resources\Shader\Shader.cpp"
|
||||
>
|
||||
</File>
|
||||
<File
|
||||
RelativePath=".\Resources\ShaderParameterCollection\ShaderParameterCollection.cpp"
|
||||
>
|
||||
</File>
|
||||
<File
|
||||
RelativePath=".\stdafx.cpp"
|
||||
>
|
||||
<FileConfiguration
|
||||
Name="Debug|Win32"
|
||||
>
|
||||
<Tool
|
||||
Name="VCCLCompilerTool"
|
||||
UsePrecompiledHeader="1"
|
||||
/>
|
||||
</FileConfiguration>
|
||||
<FileConfiguration
|
||||
Name="Release|Win32"
|
||||
>
|
||||
<Tool
|
||||
Name="VCCLCompilerTool"
|
||||
UsePrecompiledHeader="1"
|
||||
/>
|
||||
</FileConfiguration>
|
||||
</File>
|
||||
<File
|
||||
RelativePath=".\Resources\RenderTarget\SwapChain\SwapChain.cpp"
|
||||
>
|
||||
</File>
|
||||
<File
|
||||
RelativePath=".\Resources\Texture\Texture.cpp"
|
||||
>
|
||||
</File>
|
||||
<File
|
||||
RelativePath=".\Timeline\Timeline.cpp"
|
||||
>
|
||||
</File>
|
||||
<File
|
||||
RelativePath=".\Resources\Transformation\Transformation.cpp"
|
||||
>
|
||||
</File>
|
||||
<File
|
||||
RelativePath=".\Resources\TransformationAnimation\TransformationAnimation.cpp"
|
||||
>
|
||||
</File>
|
||||
<File
|
||||
RelativePath=".\FileSystem\unzip.cpp"
|
||||
>
|
||||
<FileConfiguration
|
||||
Name="Debug|Win32"
|
||||
>
|
||||
<Tool
|
||||
Name="VCCLCompilerTool"
|
||||
UsePrecompiledHeader="0"
|
||||
/>
|
||||
</FileConfiguration>
|
||||
<FileConfiguration
|
||||
Name="Release|Win32"
|
||||
>
|
||||
<Tool
|
||||
Name="VCCLCompilerTool"
|
||||
UsePrecompiledHeader="0"
|
||||
/>
|
||||
</FileConfiguration>
|
||||
</File>
|
||||
<File
|
||||
RelativePath=".\Window\Window.cpp"
|
||||
>
|
||||
</File>
|
||||
<File
|
||||
RelativePath=".\DeviceEnumerator\DeviceVisitor\XmlDeviceVisitor.cpp"
|
||||
>
|
||||
</File>
|
||||
</Filter>
|
||||
<Filter
|
||||
Name="Header Files"
|
||||
Filter="h;hpp;hxx;hm;inl;inc;xsd"
|
||||
UniqueIdentifier="{93995380-89BD-4b04-88EB-625FBE52EBFB}"
|
||||
>
|
||||
<File
|
||||
RelativePath=".\Aiwaz.h"
|
||||
>
|
||||
</File>
|
||||
<File
|
||||
RelativePath=".\AnimationManager\AnimationManager.h"
|
||||
>
|
||||
</File>
|
||||
<File
|
||||
RelativePath=".\Resources\Camera\BaseCamera.h"
|
||||
>
|
||||
</File>
|
||||
<File
|
||||
RelativePath=".\Resources\ShaderParameterCollection\Types\BaseType.h"
|
||||
>
|
||||
</File>
|
||||
<File
|
||||
RelativePath=".\Common\BaseTypes.h"
|
||||
>
|
||||
</File>
|
||||
<File
|
||||
RelativePath=".\Resources\ShaderParameterCollection\BasisParameterCollection.h"
|
||||
>
|
||||
</File>
|
||||
<File
|
||||
RelativePath=".\Resources\Bone\Bone.h"
|
||||
>
|
||||
</File>
|
||||
<File
|
||||
RelativePath=".\Resources\Bone\BoneController.h"
|
||||
>
|
||||
</File>
|
||||
<File
|
||||
RelativePath=".\Resources\ShaderParameterCollection\Types\Boolean.h"
|
||||
>
|
||||
</File>
|
||||
<File
|
||||
RelativePath=".\FileSystem\CFileLoader\CFileLoader.h"
|
||||
>
|
||||
</File>
|
||||
<File
|
||||
RelativePath=".\Commands\CommandBuffer.h"
|
||||
>
|
||||
</File>
|
||||
<File
|
||||
RelativePath=".\Commands\CommandUserBase.h"
|
||||
>
|
||||
</File>
|
||||
<File
|
||||
RelativePath=".\CommonObjectFactory\CommonObjectFactory.h"
|
||||
>
|
||||
</File>
|
||||
<File
|
||||
RelativePath=".\Common\ConsoleColor.h"
|
||||
>
|
||||
</File>
|
||||
<File
|
||||
RelativePath=".\DeviceEnumerator\DeviceEnumerator.h"
|
||||
>
|
||||
</File>
|
||||
<File
|
||||
RelativePath=".\DeviceEnumerator\DeviceVisitor\DeviceVisitorBase.h"
|
||||
>
|
||||
</File>
|
||||
<File
|
||||
RelativePath=".\DeviceEnumerator\DisplayAdapter.h"
|
||||
>
|
||||
</File>
|
||||
<File
|
||||
RelativePath=".\DeviceEnumerator\DisplayMode.h"
|
||||
>
|
||||
</File>
|
||||
<File
|
||||
RelativePath=".\Engine\Engine.h"
|
||||
>
|
||||
</File>
|
||||
<File
|
||||
RelativePath=".\FileSystem\File.h"
|
||||
>
|
||||
</File>
|
||||
<File
|
||||
RelativePath=".\FileSystem\FileSystem.h"
|
||||
>
|
||||
</File>
|
||||
<File
|
||||
RelativePath=".\Resources\ShaderParameterCollection\Types\Float.h"
|
||||
>
|
||||
</File>
|
||||
<File
|
||||
RelativePath=".\Resources\GeometryBuffer\GeometryBuffer.h"
|
||||
>
|
||||
</File>
|
||||
<File
|
||||
RelativePath=".\Interfaces\IAnimationManager.h"
|
||||
>
|
||||
</File>
|
||||
<File
|
||||
RelativePath=".\Interfaces\IBone.h"
|
||||
>
|
||||
</File>
|
||||
<File
|
||||
RelativePath=".\Interfaces\ICamera.h"
|
||||
>
|
||||
</File>
|
||||
<File
|
||||
RelativePath=".\Interfaces\ICommandUser.h"
|
||||
>
|
||||
</File>
|
||||
<File
|
||||
RelativePath=".\Interfaces\ICommonObjectFactory.h"
|
||||
>
|
||||
</File>
|
||||
<File
|
||||
RelativePath=".\Interfaces\IDeviceEnumerator.h"
|
||||
>
|
||||
</File>
|
||||
<File
|
||||
RelativePath=".\Interfaces\IEngine.h"
|
||||
>
|
||||
</File>
|
||||
<File
|
||||
RelativePath=".\Interfaces\IFileSystem.h"
|
||||
>
|
||||
</File>
|
||||
<File
|
||||
RelativePath=".\Interfaces\IGeometryBuffer.h"
|
||||
>
|
||||
</File>
|
||||
<File
|
||||
RelativePath=".\Resources\ShaderParameterCollection\Types\Integer.h"
|
||||
>
|
||||
</File>
|
||||
<File
|
||||
RelativePath=".\Resources\Shader\InternalShader.h"
|
||||
>
|
||||
</File>
|
||||
<File
|
||||
RelativePath=".\Interfaces\IPingPongBuffer.h"
|
||||
>
|
||||
</File>
|
||||
<File
|
||||
RelativePath=".\Interfaces\IRenderCommandNode.h"
|
||||
>
|
||||
</File>
|
||||
<File
|
||||
RelativePath=".\Interfaces\IRenderTargetBase.h"
|
||||
>
|
||||
</File>
|
||||
<File
|
||||
RelativePath=".\Interfaces\IRenderTargetTexture.h"
|
||||
>
|
||||
</File>
|
||||
<File
|
||||
RelativePath=".\Interfaces\IResourceFactory.h"
|
||||
>
|
||||
</File>
|
||||
<File
|
||||
RelativePath=".\Interfaces\IShader.h"
|
||||
>
|
||||
</File>
|
||||
<File
|
||||
RelativePath=".\Interfaces\IShaderParameterCollection.h"
|
||||
>
|
||||
</File>
|
||||
<File
|
||||
RelativePath=".\Interfaces\ISwapChain.h"
|
||||
>
|
||||
</File>
|
||||
<File
|
||||
RelativePath=".\Interfaces\ISwapChainResource.h"
|
||||
>
|
||||
</File>
|
||||
<File
|
||||
RelativePath=".\Interfaces\ITexture.h"
|
||||
>
|
||||
</File>
|
||||
<File
|
||||
RelativePath=".\Interfaces\ITimeLine.h"
|
||||
>
|
||||
</File>
|
||||
<File
|
||||
RelativePath=".\Interfaces\ITransformation.h"
|
||||
>
|
||||
</File>
|
||||
<File
|
||||
RelativePath=".\Interfaces\ITransformationAnimation.h"
|
||||
>
|
||||
</File>
|
||||
<File
|
||||
RelativePath=".\Interfaces\IUpdatable.h"
|
||||
>
|
||||
</File>
|
||||
<File
|
||||
RelativePath=".\Interfaces\IWindow.h"
|
||||
>
|
||||
</File>
|
||||
<File
|
||||
RelativePath=".\Resources\ShaderParameterCollection\Types\Matrix.h"
|
||||
>
|
||||
</File>
|
||||
<File
|
||||
RelativePath=".\Resources\Camera\OrthographicCamera.h"
|
||||
>
|
||||
</File>
|
||||
<File
|
||||
RelativePath=".\DeviceEnumerator\OutputDevice.h"
|
||||
>
|
||||
</File>
|
||||
<File
|
||||
RelativePath=".\Resources\Camera\PerspectiveCamera.h"
|
||||
>
|
||||
</File>
|
||||
<File
|
||||
RelativePath=".\Resources\RenderCommandNode\RenderCommandNode.h"
|
||||
>
|
||||
</File>
|
||||
<File
|
||||
RelativePath=".\Resources\RenderTarget\RenderTargetBase.h"
|
||||
>
|
||||
</File>
|
||||
<File
|
||||
RelativePath=".\Resources\RenderTarget\RenderTargetTexture\RenderTargetTexture.h"
|
||||
>
|
||||
</File>
|
||||
<File
|
||||
RelativePath=".\Interfaces\Resource.h"
|
||||
>
|
||||
</File>
|
||||
<File
|
||||
RelativePath=".\ResourceFactory\ResourceFactory.h"
|
||||
>
|
||||
</File>
|
||||
<File
|
||||
RelativePath=".\Resources\Shader\Shader.h"
|
||||
>
|
||||
</File>
|
||||
<File
|
||||
RelativePath=".\Resources\ShaderParameterCollection\ShaderParameterCollection.h"
|
||||
>
|
||||
</File>
|
||||
<File
|
||||
RelativePath=".\stdafx.h"
|
||||
>
|
||||
</File>
|
||||
<File
|
||||
RelativePath=".\Common\StringHelper.h"
|
||||
>
|
||||
</File>
|
||||
<File
|
||||
RelativePath=".\Resources\RenderTarget\SwapChain\SwapChain.h"
|
||||
>
|
||||
</File>
|
||||
<File
|
||||
RelativePath=".\targetver.h"
|
||||
>
|
||||
</File>
|
||||
<File
|
||||
RelativePath=".\Resources\Texture\Texture.h"
|
||||
>
|
||||
</File>
|
||||
<File
|
||||
RelativePath=".\Resources\ShaderParameterCollection\Types\Texture.h"
|
||||
>
|
||||
</File>
|
||||
<File
|
||||
RelativePath=".\Timeline\Timeline.h"
|
||||
>
|
||||
</File>
|
||||
<File
|
||||
RelativePath=".\Resources\Transformation\Transformation.h"
|
||||
>
|
||||
</File>
|
||||
<File
|
||||
RelativePath=".\Resources\TransformationAnimation\TransformationAnimation.h"
|
||||
>
|
||||
</File>
|
||||
<File
|
||||
RelativePath=".\Resources\ShaderParameterCollection\Types\Types.h"
|
||||
>
|
||||
</File>
|
||||
<File
|
||||
RelativePath=".\FileSystem\unzip.h"
|
||||
>
|
||||
</File>
|
||||
<File
|
||||
RelativePath=".\Window\Window.h"
|
||||
>
|
||||
</File>
|
||||
<File
|
||||
RelativePath=".\DeviceEnumerator\DeviceVisitor\XmlDeviceVisitor.h"
|
||||
>
|
||||
</File>
|
||||
</Filter>
|
||||
<Filter
|
||||
Name="Resource Files"
|
||||
Filter="rc;ico;cur;bmp;dlg;rc2;rct;bin;rgs;gif;jpg;jpeg;jpe;resx;tiff;tif;png;wav"
|
||||
UniqueIdentifier="{67DA6AB6-F800-4c08-8B7A-83BB121AAD01}"
|
||||
>
|
||||
</Filter>
|
||||
<File
|
||||
RelativePath=".\FileSystem\7za.exe"
|
||||
>
|
||||
</File>
|
||||
<File
|
||||
RelativePath=".\CommonObjectFactory\PingPongBuffer\PingPongBuffer.h"
|
||||
>
|
||||
</File>
|
||||
</Files>
|
||||
<Globals>
|
||||
</Globals>
|
||||
</VisualStudioProject>
|
||||
65
aiwaz/Aiwaz/Aiwaz.vcproj.Shaikur.Frank.user
Normal file
65
aiwaz/Aiwaz/Aiwaz.vcproj.Shaikur.Frank.user
Normal file
@@ -0,0 +1,65 @@
|
||||
<?xml version="1.0" encoding="Windows-1252"?>
|
||||
<VisualStudioUserFile
|
||||
ProjectType="Visual C++"
|
||||
Version="9,00"
|
||||
ShowAllFiles="true"
|
||||
>
|
||||
<Configurations>
|
||||
<Configuration
|
||||
Name="Debug|Win32"
|
||||
>
|
||||
<DebugSettings
|
||||
Command="$(TargetPath)"
|
||||
WorkingDirectory=""
|
||||
CommandArguments=""
|
||||
Attach="false"
|
||||
DebuggerType="3"
|
||||
Remote="1"
|
||||
RemoteMachine="SHAIKUR"
|
||||
RemoteCommand=""
|
||||
HttpUrl=""
|
||||
PDBPath=""
|
||||
SQLDebugging=""
|
||||
Environment=""
|
||||
EnvironmentMerge="true"
|
||||
DebuggerFlavor=""
|
||||
MPIRunCommand=""
|
||||
MPIRunArguments=""
|
||||
MPIRunWorkingDirectory=""
|
||||
ApplicationCommand=""
|
||||
ApplicationArguments=""
|
||||
ShimCommand=""
|
||||
MPIAcceptMode=""
|
||||
MPIAcceptFilter=""
|
||||
/>
|
||||
</Configuration>
|
||||
<Configuration
|
||||
Name="Release|Win32"
|
||||
>
|
||||
<DebugSettings
|
||||
Command="$(TargetPath)"
|
||||
WorkingDirectory=""
|
||||
CommandArguments=""
|
||||
Attach="false"
|
||||
DebuggerType="3"
|
||||
Remote="1"
|
||||
RemoteMachine="SHAIKUR"
|
||||
RemoteCommand=""
|
||||
HttpUrl=""
|
||||
PDBPath=""
|
||||
SQLDebugging=""
|
||||
Environment=""
|
||||
EnvironmentMerge="true"
|
||||
DebuggerFlavor=""
|
||||
MPIRunCommand=""
|
||||
MPIRunArguments=""
|
||||
MPIRunWorkingDirectory=""
|
||||
ApplicationCommand=""
|
||||
ApplicationArguments=""
|
||||
ShimCommand=""
|
||||
MPIAcceptMode=""
|
||||
MPIAcceptFilter=""
|
||||
/>
|
||||
</Configuration>
|
||||
</Configurations>
|
||||
</VisualStudioUserFile>
|
||||
162
aiwaz/Aiwaz/AnimationManager/AnimationManager.cpp
Normal file
162
aiwaz/Aiwaz/AnimationManager/AnimationManager.cpp
Normal file
@@ -0,0 +1,162 @@
|
||||
#include "stdafx.h"
|
||||
#include "ITimeline.h"
|
||||
#include "AnimationManager.h"
|
||||
|
||||
|
||||
AnimationManager::AnimationManager(IEngine& argEngine)
|
||||
: m_Engine(argEngine)
|
||||
, m_PreviousDemoTime(0.0)
|
||||
, m_PreviousRealTime(0.0)
|
||||
{
|
||||
}
|
||||
|
||||
|
||||
AnimationManager::~AnimationManager()
|
||||
{
|
||||
}
|
||||
|
||||
|
||||
void AnimationManager::AddDemoTimeAnimation(double argBeginTime, double argEndTime, IAnimateable* argValue, unsigned int argUserData)
|
||||
{
|
||||
m_ForwardSortedAnimations[r_AnimationInterval(argBeginTime, argEndTime)].push_back(std::make_pair(argValue, argUserData));
|
||||
m_BackwardSortedAnimations[r_AnimationInterval(argBeginTime, argEndTime)].push_back(std::make_pair(argValue, argUserData));
|
||||
}
|
||||
|
||||
|
||||
void AnimationManager::AddRealTimeAnimation(double argBeginTime, double argEndTime, IAnimateable* argValue, unsigned int argUserData)
|
||||
{
|
||||
m_RealTimeAnimations[r_AnimationInterval(argBeginTime, argEndTime)].push_back(std::make_pair(argValue, argUserData));
|
||||
}
|
||||
|
||||
|
||||
void AnimationManager::AddDemoTimeEvent(double argTime, IEvent* argValue, unsigned int argUserData)
|
||||
{
|
||||
m_DemoTimeEvents[argTime].push_back(std::make_pair(argValue, argUserData));
|
||||
}
|
||||
|
||||
|
||||
void AnimationManager::AddRealTimeEvent(double argTime, IEvent* argValue, unsigned int argUserData)
|
||||
{
|
||||
m_RealTimeEvents[argTime].push_back(std::make_pair(argValue, argUserData));
|
||||
}
|
||||
|
||||
|
||||
void AnimationManager::Animate()
|
||||
{
|
||||
ITimeline& timeline = m_Engine.get_Timeline();
|
||||
double ld_DemoTime = timeline.get_DemoTime();
|
||||
double ld_RealTime = timeline.get_RealTime();
|
||||
|
||||
// Gather all active animations, they are the ones that started before now and end after now.
|
||||
// Do this for both the demo time and real time.
|
||||
std::vector<std::pair<IAnimateable*, unsigned int> > lk_ActiveAnimations;
|
||||
std::vector<double> lk_AnimationTimes;
|
||||
|
||||
// Demo time animations: Demo time can go backwards, so search from both directions
|
||||
if (timeline.get_SpeedAndDirection() > 0)
|
||||
{
|
||||
tk_ForwardAnims::iterator lk_Iter = m_ForwardSortedAnimations.begin();
|
||||
for (; lk_Iter != m_ForwardSortedAnimations.end(); ++lk_Iter)
|
||||
{
|
||||
if (lk_Iter->first.m_Begin <= ld_DemoTime && lk_Iter->first.m_End >= ld_DemoTime)
|
||||
{
|
||||
std::vector<std::pair<IAnimateable*, unsigned int> >::iterator lk_AnimIter = lk_Iter->second.begin();
|
||||
for (; lk_AnimIter != lk_Iter->second.end(); ++lk_AnimIter)
|
||||
{
|
||||
lk_ActiveAnimations.push_back(*lk_AnimIter);
|
||||
lk_AnimationTimes.push_back((ld_DemoTime - lk_Iter->first.m_Begin) / (lk_Iter->first.m_End - lk_Iter->first.m_Begin));
|
||||
}
|
||||
}
|
||||
|
||||
if (lk_Iter->first.m_Begin > ld_DemoTime)
|
||||
break;
|
||||
}
|
||||
}
|
||||
else if (timeline.get_SpeedAndDirection() < 0)
|
||||
{
|
||||
tk_BackwardAnims::iterator lk_Iter = m_BackwardSortedAnimations.begin();
|
||||
for (; lk_Iter != m_BackwardSortedAnimations.end(); ++lk_Iter)
|
||||
{
|
||||
if (lk_Iter->first.m_End >= ld_DemoTime && lk_Iter->first.m_Begin <= ld_DemoTime)
|
||||
{
|
||||
std::vector<std::pair<IAnimateable*, unsigned int> >::iterator lk_AnimIter = lk_Iter->second.begin();
|
||||
for (; lk_AnimIter != lk_Iter->second.end(); ++lk_AnimIter)
|
||||
{
|
||||
lk_ActiveAnimations.push_back(*lk_AnimIter);
|
||||
lk_AnimationTimes.push_back((ld_DemoTime - lk_Iter->first.m_Begin) / (lk_Iter->first.m_End - lk_Iter->first.m_Begin));
|
||||
}
|
||||
}
|
||||
|
||||
if (lk_Iter->first.m_End < ld_DemoTime)
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
// Real time animations: The time that we know doesn't allow us to travel to the past, so just check into the future:
|
||||
{
|
||||
tk_ForwardAnims::iterator lk_Iter = m_RealTimeAnimations.begin();
|
||||
for (; lk_Iter != m_RealTimeAnimations.end(); ++lk_Iter)
|
||||
{
|
||||
if (lk_Iter->first.m_Begin <= ld_RealTime && lk_Iter->first.m_End >= ld_RealTime)
|
||||
{
|
||||
std::vector<std::pair<IAnimateable*, unsigned int> >::iterator lk_AnimIter = lk_Iter->second.begin();
|
||||
for (; lk_AnimIter != lk_Iter->second.end(); ++lk_AnimIter)
|
||||
{
|
||||
lk_ActiveAnimations.push_back(*lk_AnimIter);
|
||||
lk_AnimationTimes.push_back((ld_RealTime - lk_Iter->first.m_End) / (lk_Iter->first.m_Begin - lk_Iter->first.m_End));
|
||||
}
|
||||
}
|
||||
|
||||
if (lk_Iter->first.m_Begin > ld_RealTime)
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
// Now that we know what animations correspond to this time, animate them!
|
||||
std::vector<std::pair<IAnimateable*, unsigned int> >::iterator lk_AnimIter = lk_ActiveAnimations.begin();
|
||||
std::vector<double>::iterator lk_TimeIter = lk_AnimationTimes.begin();
|
||||
for (; lk_AnimIter != lk_ActiveAnimations.end(); ++lk_AnimIter, ++lk_TimeIter)
|
||||
{
|
||||
IAnimateable* lr_Animateable_ = lk_AnimIter->first;
|
||||
lr_Animateable_->OnAnimate(*lk_TimeIter, lk_AnimIter->second);
|
||||
}
|
||||
|
||||
// Fire all events that happened since last time:
|
||||
tk_Events::iterator lk_EventIter = m_DemoTimeEvents.begin();
|
||||
for (; lk_EventIter != m_DemoTimeEvents.end(); ++lk_EventIter)
|
||||
{
|
||||
double ld_Time = lk_EventIter->first;
|
||||
|
||||
std::vector<std::pair<IEvent*, unsigned int> >::iterator lk_EventVecIter = lk_EventIter->second.begin();
|
||||
for (; lk_EventVecIter != lk_EventIter->second.end(); ++lk_EventVecIter)
|
||||
{
|
||||
IEvent* lr_Event_ = lk_EventVecIter->first;
|
||||
unsigned int lui_UserData = lk_EventVecIter->second;
|
||||
if (((timeline.get_SpeedAndDirection() > 0) && (ld_Time >= m_PreviousDemoTime && ld_Time <= ld_DemoTime)) ||
|
||||
((timeline.get_SpeedAndDirection() < 0) && (ld_Time <= m_PreviousDemoTime && ld_Time >= ld_DemoTime)))
|
||||
{
|
||||
lr_Event_->OnEvent(lui_UserData);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
lk_EventIter = m_RealTimeEvents.begin();
|
||||
for (; lk_EventIter != m_RealTimeEvents.end(); ++lk_EventIter)
|
||||
{
|
||||
double ld_Time = lk_EventIter->first;
|
||||
|
||||
std::vector<std::pair<IEvent*, unsigned int> >::iterator lk_EventVecIter = lk_EventIter->second.begin();
|
||||
for (; lk_EventVecIter != lk_EventIter->second.end(); ++lk_EventVecIter)
|
||||
{
|
||||
IEvent* lr_Event_ = lk_EventVecIter->first;
|
||||
unsigned int lui_UserData = lk_EventVecIter->second;
|
||||
if (ld_Time >= m_PreviousRealTime && ld_Time <= ld_RealTime)
|
||||
{
|
||||
lr_Event_->OnEvent(lui_UserData);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
m_PreviousDemoTime = ld_DemoTime;
|
||||
m_PreviousRealTime = ld_RealTime;
|
||||
}
|
||||
64
aiwaz/Aiwaz/AnimationManager/AnimationManager.h
Normal file
64
aiwaz/Aiwaz/AnimationManager/AnimationManager.h
Normal file
@@ -0,0 +1,64 @@
|
||||
#pragma once
|
||||
|
||||
#include "IAnimationManager.h"
|
||||
#include "IEngine.h"
|
||||
|
||||
|
||||
class AnimationManager
|
||||
: public IAnimationManager
|
||||
{
|
||||
public:
|
||||
AnimationManager(IEngine& argEngine);
|
||||
virtual ~AnimationManager();
|
||||
|
||||
virtual void AddDemoTimeAnimation(double argBeginTime, double argEndTime, IAnimateable* argValue, unsigned int argUserData = 0);
|
||||
virtual void AddRealTimeAnimation(double argBeginTime, double argEndTime, IAnimateable* argValue, unsigned int argUserData = 0);
|
||||
|
||||
virtual void AddDemoTimeEvent(double argTime, IEvent* argValue, unsigned int argUserData = 0);
|
||||
virtual void AddRealTimeEvent(double argTime, IEvent* argValue, unsigned int argUserData = 0);
|
||||
|
||||
virtual void Animate();
|
||||
|
||||
private:
|
||||
struct r_AnimationInterval
|
||||
{
|
||||
r_AnimationInterval(double argBegin, double argEnd)
|
||||
: m_Begin(argBegin)
|
||||
, m_End(argEnd)
|
||||
{
|
||||
};
|
||||
|
||||
double m_Begin;
|
||||
double m_End;
|
||||
};
|
||||
|
||||
struct r_ForwardSort
|
||||
{
|
||||
bool operator ()(const r_AnimationInterval& a, const r_AnimationInterval& b) const
|
||||
{
|
||||
return a.m_Begin < b.m_Begin;
|
||||
}
|
||||
};
|
||||
|
||||
struct r_BackwardSort
|
||||
{
|
||||
bool operator ()(const r_AnimationInterval& a, const r_AnimationInterval& b) const
|
||||
{
|
||||
return a.m_End > b.m_End;
|
||||
}
|
||||
};
|
||||
|
||||
typedef std::map<r_AnimationInterval, std::vector<std::pair<IAnimateable*, unsigned int> >, r_ForwardSort> tk_ForwardAnims;
|
||||
typedef std::map<r_AnimationInterval, std::vector<std::pair<IAnimateable*, unsigned int> >, r_BackwardSort> tk_BackwardAnims;
|
||||
typedef std::map<double, std::vector<std::pair<IEvent*, unsigned int> > > tk_Events;
|
||||
|
||||
IEngine& m_Engine;
|
||||
tk_ForwardAnims m_ForwardSortedAnimations;
|
||||
tk_BackwardAnims m_BackwardSortedAnimations;
|
||||
tk_ForwardAnims m_RealTimeAnimations;
|
||||
tk_Events m_DemoTimeEvents;
|
||||
tk_Events m_RealTimeEvents;
|
||||
|
||||
double m_PreviousDemoTime;
|
||||
double m_PreviousRealTime;
|
||||
};
|
||||
382
aiwaz/Aiwaz/BLUImporter/BLUImporter.cpp
Normal file
382
aiwaz/Aiwaz/BLUImporter/BLUImporter.cpp
Normal file
@@ -0,0 +1,382 @@
|
||||
#include "stdafx.h"
|
||||
|
||||
#include "BLUImporter.h"
|
||||
|
||||
#include "IFileSystem.h"
|
||||
#include "IResourceFactory.h"
|
||||
#include "IGeometryBuffer.h"
|
||||
#include "IMaterial.h"
|
||||
#include "IBone.h"
|
||||
#include "ITransformationAnimation.h"
|
||||
|
||||
|
||||
BluImporter::BluImporter(IEngine& argEngine)
|
||||
: m_Engine(argEngine)
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
|
||||
BluImportResult BluImporter::Load(const string16& argFileName)
|
||||
{
|
||||
BluImportResult lr_Result;
|
||||
m_CurrentPath = lr_Result.m_FileName = argFileName;
|
||||
int li_Pos = m_CurrentPath.rfind(_T("/"));
|
||||
if (li_Pos >= 0)
|
||||
m_CurrentPath = m_CurrentPath.substr(0, li_Pos + 1);
|
||||
else
|
||||
m_CurrentPath = _T("");
|
||||
|
||||
IFile* lr_File_ = m_Engine.get_FileSystem()->Open(argFileName);
|
||||
if (lr_File_ == NULL)
|
||||
return lr_Result;
|
||||
|
||||
char* lc_CurrentPos_ = lr_File_->get_Buffer();
|
||||
|
||||
try
|
||||
{
|
||||
// header
|
||||
std::string ls_FileTag = lr_File_->ReadString();
|
||||
if (ls_FileTag != "BLUF")
|
||||
throw;
|
||||
int li_FileVersion = lr_File_->ReadInt();
|
||||
|
||||
// sections
|
||||
while (!lr_File_->IsEof())
|
||||
{
|
||||
BluSectionType::Enumeration le_ObjectType = (BluSectionType::Enumeration)lr_File_->ReadInt();
|
||||
if (le_ObjectType > BluSectionType::LastKnownType)
|
||||
throw _T("BLUImporter: Unknown object section detected.");
|
||||
|
||||
std::string ls_ObjectName = lr_File_->ReadString();
|
||||
if (ls_ObjectName.empty())
|
||||
throw _T("BLUImporter: Objectname not set.");
|
||||
|
||||
// content
|
||||
switch (le_ObjectType)
|
||||
{
|
||||
case BluSectionType::Mesh:
|
||||
this->ImportMesh(lr_File_, ls_ObjectName, lr_Result);
|
||||
break;
|
||||
case BluSectionType::Material:
|
||||
this->ImportMaterial(lr_File_, ls_ObjectName, lr_Result);
|
||||
break;
|
||||
case BluSectionType::Bone:
|
||||
this->ImportBone(lr_File_, ls_ObjectName, lr_Result);
|
||||
break;
|
||||
case BluSectionType::Animation:
|
||||
this->ImportAnimation(lr_File_, ls_ObjectName, lr_Result);
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
// put materials to GeometryBuffers
|
||||
std::map<string16, BluImportedGeometryBuffer>::iterator lk_Iter = lr_Result.m_GeometryBuffers.begin();
|
||||
for (; lk_Iter != lr_Result.m_GeometryBuffers.end(); ++lk_Iter)
|
||||
{
|
||||
BluImportedGeometryBuffer lr_Mesh = lk_Iter->second;
|
||||
|
||||
std::map<string16, IMaterial*>::iterator lk_Found = lr_Result.m_Materials.find(lr_Mesh.m_MaterialName);
|
||||
if (lk_Found != lr_Result.m_Materials.end())
|
||||
lr_Mesh.m_GeometryBuffer->set_Material(lk_Found->second);
|
||||
}
|
||||
|
||||
// build bone hierarchy
|
||||
std::map<string16, BluImportedBone>::iterator lk_BonesIter = lr_Result.m_Bones.begin();
|
||||
for (; lk_BonesIter != lr_Result.m_Bones.end(); ++lk_BonesIter)
|
||||
{
|
||||
BluImportedBone lr_Bone = lk_BonesIter->second;
|
||||
|
||||
std::map<string16, BluImportedBone>::iterator lk_Found = lr_Result.m_Bones.find(lr_Bone.m_ParentName);
|
||||
if (lk_Found != lr_Result.m_Bones.end())
|
||||
lr_Bone.m_Bone->set_Parent(lk_Found->second.m_Bone);
|
||||
}
|
||||
|
||||
// add bone animations to bones
|
||||
std::map<string16, ITransformationAnimation*>::iterator lk_AnimIter = lr_Result.m_Animations.begin();
|
||||
for (; lk_AnimIter != lr_Result.m_Animations.end(); ++lk_AnimIter)
|
||||
{
|
||||
std::map<string16, BluImportedBone>::iterator lk_Found = lr_Result.m_Bones.find(lk_AnimIter->first);
|
||||
if (lk_Found != lr_Result.m_Bones.end())
|
||||
{
|
||||
lk_Found->second.m_Bone->set_TransformationAnimation(lk_AnimIter->second);
|
||||
}
|
||||
}
|
||||
|
||||
// collapse bone map to super parent bones only
|
||||
lk_BonesIter = lr_Result.m_Bones.begin();
|
||||
for (; lk_BonesIter != lr_Result.m_Bones.end();)
|
||||
if (!lk_BonesIter->second.m_ParentName.empty())
|
||||
lk_BonesIter = lr_Result.m_Bones.erase(lk_BonesIter);
|
||||
else
|
||||
{
|
||||
// create the boneindexlist structure while we are here
|
||||
lk_BonesIter->second.m_Bone->get_BoneIndexList();
|
||||
++lk_BonesIter;
|
||||
}
|
||||
|
||||
if (lr_Result.m_Bones.size() > 1)
|
||||
throw _T("BLUImporter: Only one bone root allowed!");
|
||||
|
||||
// when we have bones, try to register the bones shadercallback to all materials
|
||||
// also create a default BoneController
|
||||
if (!lr_Result.m_Bones.empty())
|
||||
{
|
||||
std::map<string16, IMaterial*>::iterator lk_MatIter = lr_Result.m_Materials.begin();
|
||||
for (; lk_MatIter != lr_Result.m_Materials.end(); ++lk_MatIter)
|
||||
{
|
||||
const std::D3DXVECTOR4<SubMaterial*>& lk_SubMaterials = lk_MatIter->second->get_SubMaterials();
|
||||
for (unsigned int i = 0; i < lk_SubMaterials.size(); ++i)
|
||||
lk_SubMaterials[i]->ShaderProgram->SetShaderCallbackUsage(_T("bones"), lr_Result.m_Bones.begin()->second.m_Bone);
|
||||
}
|
||||
|
||||
lr_Result.m_BoneController = new BoneController(m_Engine, lr_Result.m_Bones.begin()->second.m_Bone);
|
||||
float lf_MaxDuration = 0.0f;
|
||||
for (lk_AnimIter = lr_Result.m_Animations.begin(); lk_AnimIter != lr_Result.m_Animations.end(); ++lk_AnimIter)
|
||||
{
|
||||
lf_MaxDuration = lf_MaxDuration < lk_AnimIter->second->get_Duration() ? lk_AnimIter->second->get_Duration() : lf_MaxDuration;
|
||||
}
|
||||
lr_Result.m_BoneController->RegisterSequence(L"all", 0.0f, lf_MaxDuration, true);
|
||||
}
|
||||
|
||||
delete lr_File_;
|
||||
}
|
||||
catch (...)
|
||||
{
|
||||
delete lr_File_;
|
||||
throw;
|
||||
}
|
||||
|
||||
lr_Result.m_SuccessfullyLoaded = true;
|
||||
return lr_Result;
|
||||
}
|
||||
|
||||
|
||||
IRenderable* BluImporter::Load(IEngine* argEngine, const string16& argFileName, IMaterial* argOverrideMaterial)
|
||||
{
|
||||
BluImporter lk_Importer(argEngine);
|
||||
BluImportResult lk_Result = lk_Importer.Load(argFileName);
|
||||
if (lk_Result.m_SuccessfullyLoaded)
|
||||
return lk_Result.GenerateRootRenderable(argEngine, argOverrideMaterial);
|
||||
return NULL;
|
||||
}
|
||||
|
||||
|
||||
void BluImporter::ImportMesh(IFile* argFile, std::string argObjectName, BluImportResult& argResult)
|
||||
{
|
||||
std::string ls_MaterialName = argFile->ReadString();
|
||||
unsigned int li_VertexCount = argFile->ReadInt();
|
||||
int li_VertexElementCount = argFile->ReadInt();
|
||||
|
||||
unsigned int lui_VertexStride = 0;
|
||||
std::D3DXVECTOR4<VertexElement::Enumeration> lk_VertexElements;
|
||||
for (int i = 0; i < li_VertexElementCount; ++i)
|
||||
{
|
||||
VertexElement::Enumeration le_VertexElement = (VertexElement::Enumeration)argFile->ReadInt();
|
||||
lui_VertexStride += VertexElement::get_Size(le_VertexElement);
|
||||
lk_VertexElements.push_back(le_VertexElement);
|
||||
}
|
||||
|
||||
ScopedBuffer<char> lr_VertexData((char*)argFile->ReadDataArray(li_VertexCount * lui_VertexStride));
|
||||
|
||||
unsigned int li_IndexCount = argFile->ReadInt();
|
||||
ScopedBuffer<unsigned int> lr_IndexData((unsigned int*)argFile->ReadDataArray(li_IndexCount * sizeof(unsigned int)));
|
||||
|
||||
string16 ls_UniqueName = argResult.m_FileName + _T(".") + std::to_string16(argObjectName);
|
||||
|
||||
IGeometryBuffer* lr_GeometryBuffer_ = m_Engine.get_ResourceFactory()->CreateGeometryBuffer();
|
||||
lr_GeometryBuffer_->set_PrimitiveTopology(PrimitiveTopology::TriangleList);
|
||||
lr_GeometryBuffer_->SetVertexData((void*)lr_VertexData.Detach(), li_VertexCount, lk_VertexElements, GeometryBufferUsage::Static, true);
|
||||
lr_GeometryBuffer_->SetIndexData((unsigned int*)lr_IndexData.Detach(), li_IndexCount, GeometryBufferUsage::Static, true);
|
||||
|
||||
BluImportedGeometryBuffer lr_Mesh;
|
||||
lr_Mesh.m_GeometryBuffer = lr_GeometryBuffer_;
|
||||
lr_Mesh.m_MaterialName = argResult.m_FileName + _T(".") + std::to_string16(ls_MaterialName);
|
||||
argResult.m_GeometryBuffers[ls_UniqueName] = lr_Mesh;
|
||||
}
|
||||
|
||||
|
||||
void BluImporter::ImportMaterial(IFile* argFile, std::string argObjectName, BluImportResult& argResult)
|
||||
{
|
||||
string16 ls_DiffuseTexture = this->ConvertPath(argFile->ReadString());
|
||||
string16 ls_SpecularTexture = this->ConvertPath(argFile->ReadString());
|
||||
string16 ls_NormalTexture = this->ConvertPath(argFile->ReadString());
|
||||
string16 ls_GlowTexture = this->ConvertPath(argFile->ReadString());
|
||||
string16 ls_ReflectionTexture = this->ConvertPath(argFile->ReadString()); // not used yet
|
||||
|
||||
D3DXVECTOR4 lk_AmbientColor;
|
||||
lk_AmbientColor.x = argFile->ReadFloat() / 255.0f;
|
||||
lk_AmbientColor.y = argFile->ReadFloat() / 255.0f;
|
||||
lk_AmbientColor.z = argFile->ReadFloat() / 255.0f;
|
||||
lk_AmbientColor.w = argFile->ReadFloat() / 255.0f;
|
||||
|
||||
D3DXVECTOR4 lk_DiffuseColor;
|
||||
lk_DiffuseColor.x = argFile->ReadFloat() / 255.0f;
|
||||
lk_DiffuseColor.y = argFile->ReadFloat() / 255.0f;
|
||||
lk_DiffuseColor.z = argFile->ReadFloat() / 255.0f;
|
||||
lk_DiffuseColor.w = argFile->ReadFloat() / 255.0f;
|
||||
|
||||
D3DXVECTOR4 lk_SpecularColor;
|
||||
lk_SpecularColor.x = argFile->ReadFloat() / 255.0f;
|
||||
lk_SpecularColor.y = argFile->ReadFloat() / 255.0f;
|
||||
lk_SpecularColor.z = argFile->ReadFloat() / 255.0f;
|
||||
lk_SpecularColor.w = argFile->ReadFloat() / 255.0f;
|
||||
|
||||
D3DXVECTOR4 lk_EmissiveColor;
|
||||
lk_EmissiveColor.x = argFile->ReadFloat() / 255.0f;
|
||||
lk_EmissiveColor.y = argFile->ReadFloat() / 255.0f;
|
||||
lk_EmissiveColor.z = argFile->ReadFloat() / 255.0f;
|
||||
lk_EmissiveColor.w = argFile->ReadFloat() / 255.0f;
|
||||
|
||||
float lf_SpecularLevel = argFile->ReadFloat();
|
||||
float lf_Glossiness = argFile->ReadFloat();
|
||||
|
||||
string16 ls_UniqueName = argResult.m_FileName + _T(".") + std::to_string16(argObjectName);
|
||||
|
||||
IMaterial* lr_Material_ = m_Engine.get_ResourceFactory()->TryGetOrCreateMaterial(ls_UniqueName.c_str());
|
||||
SubMaterial* lr_SubMaterial_ = new SubMaterial();
|
||||
lr_Material_->AddSubMaterial(lr_SubMaterial_);
|
||||
|
||||
lr_SubMaterial_->Ambient = lk_AmbientColor;
|
||||
lr_SubMaterial_->Diffuse = lk_DiffuseColor;
|
||||
lr_SubMaterial_->Specular = lk_SpecularColor * lf_Glossiness;
|
||||
lr_SubMaterial_->Emissive = lk_EmissiveColor;
|
||||
lr_SubMaterial_->Shininess = lf_SpecularLevel;
|
||||
|
||||
IShader* lr_VertexShader_ = NULL;
|
||||
if (ls_NormalTexture.empty())
|
||||
lr_VertexShader_ = m_Engine.get_ResourceFactory()->TryGetOrCreateShader(_T("Common/Phong_simple.vs"), ShaderType::Vertex, _T("Common/Phong_simple.vs"));
|
||||
else if (argResult.m_Bones.empty())
|
||||
lr_VertexShader_ = m_Engine.get_ResourceFactory()->TryGetOrCreateShader(_T("Common/Phong.vs"), ShaderType::Vertex, _T("Common/Phong.vs"));
|
||||
else
|
||||
lr_VertexShader_ = m_Engine.get_ResourceFactory()->TryGetOrCreateShader(_T("Common/PhongBones.vs"), ShaderType::Vertex, _T("Common/PhongBones.vs"));
|
||||
|
||||
IShader* lr_PixelShader_ = NULL;
|
||||
if (ls_NormalTexture.empty())
|
||||
lr_PixelShader_ = m_Engine.get_ResourceFactory()->TryGetOrCreateShader(_T("Common/Phong_simple.ps"), ShaderType::Pixel, _T("Common/Phong_simple.ps"));
|
||||
else
|
||||
lr_PixelShader_ = m_Engine.get_ResourceFactory()->TryGetOrCreateShader(_T("Common/Phon.ps"), ShaderType::Pixel, _T("Common/Phong.ps"));
|
||||
|
||||
std::D3DXVECTOR4<IShader*> lk_Shaders;
|
||||
lk_Shaders.push_back(lr_VertexShader_);
|
||||
lk_Shaders.push_back(lr_PixelShader_);
|
||||
|
||||
lr_SubMaterial_->ShaderProgram = m_Engine.get_ResourceFactory()->CreateShaderProgram(lk_Shaders);
|
||||
if (!ls_DiffuseTexture.empty())
|
||||
lr_SubMaterial_->Textures[0].Texture = m_Engine.get_ResourceFactory()->TryGetOrCreateTexture(ls_DiffuseTexture.c_str(), ls_DiffuseTexture.c_str());
|
||||
if (!ls_SpecularTexture.empty())
|
||||
lr_SubMaterial_->Textures[1].Texture = m_Engine.get_ResourceFactory()->TryGetOrCreateTexture(ls_SpecularTexture.c_str(), ls_SpecularTexture.c_str());
|
||||
if (!ls_NormalTexture.empty())
|
||||
lr_SubMaterial_->Textures[2].Texture = m_Engine.get_ResourceFactory()->TryGetOrCreateTexture(ls_NormalTexture.c_str(), ls_NormalTexture.c_str());
|
||||
if (!ls_GlowTexture.empty())
|
||||
lr_SubMaterial_->Textures[3].Texture = m_Engine.get_ResourceFactory()->TryGetOrCreateTexture(ls_GlowTexture.c_str(), ls_GlowTexture.c_str());
|
||||
|
||||
argResult.m_Materials[ls_UniqueName] = lr_Material_;
|
||||
}
|
||||
|
||||
|
||||
void BluImporter::ImportBone(IFile* argFile, std::string argObjectName, BluImportResult& argResult)
|
||||
{
|
||||
std::string ls_ParentBoneName = argFile->ReadString();
|
||||
|
||||
// translation
|
||||
float lf_TransX = argFile->ReadFloat();
|
||||
float lf_TransY = argFile->ReadFloat();
|
||||
float lf_TransZ = argFile->ReadFloat();
|
||||
|
||||
// rotation
|
||||
float lf_RotX = argFile->ReadFloat();
|
||||
float lf_RotY = argFile->ReadFloat();
|
||||
float lf_RotZ = argFile->ReadFloat();
|
||||
float lf_RotW = argFile->ReadFloat();
|
||||
|
||||
// scale
|
||||
float lf_ScaleX = argFile->ReadFloat();
|
||||
float lf_ScaleY = argFile->ReadFloat();
|
||||
float lf_ScaleZ = argFile->ReadFloat();
|
||||
|
||||
string16 ls_UniqueName = argResult.m_FileName + _T(".") + std::to_string16(argObjectName);
|
||||
string16 ls_UniqueParentName;
|
||||
if (!ls_ParentBoneName.empty())
|
||||
ls_UniqueParentName = argResult.m_FileName + _T(".") + std::to_string16(ls_ParentBoneName);
|
||||
|
||||
IBone* lr_Bone_ = m_Engine.get_ResourceFactory()->CreateBone(ls_UniqueName.c_str(), argResult.m_Bones.size(),
|
||||
D3DXVECTOR4(lf_TransX, lf_TransY, lf_TransZ, 1.0f),
|
||||
D3DXVECTOR4(lf_ScaleX, lf_ScaleY, lf_ScaleZ, 1.0f),
|
||||
D3DXQUATERNION(lf_RotX, lf_RotY, lf_RotZ, lf_RotW, 1.0f));
|
||||
|
||||
BluImportedBone lr_Bone;
|
||||
lr_Bone.m_Bone = lr_Bone_;
|
||||
lr_Bone.m_ParentName = ls_UniqueParentName;
|
||||
argResult.m_Bones[ls_UniqueName] = lr_Bone;
|
||||
}
|
||||
|
||||
|
||||
void BluImporter::ImportAnimation(IFile* argFile, std::string argObjectName, BluImportResult& argResult)
|
||||
{
|
||||
string16 ls_UniqueName = argResult.m_FileName + _T(".") + std::to_string16(argObjectName);
|
||||
|
||||
ITransformationAnimation* lr_Ta_ = m_Engine.get_ResourceFactory()->TryGetOrCreateTransformationAnimation(ls_UniqueName.c_str());
|
||||
|
||||
unsigned int lui_PositionElementCount = argFile->ReadInt();
|
||||
for (unsigned int i = 0; i < lui_PositionElementCount; ++i)
|
||||
{
|
||||
float lf_Time = argFile->ReadFloat();
|
||||
float lf_X = argFile->ReadFloat();
|
||||
float lf_Y = argFile->ReadFloat();
|
||||
float lf_Z = argFile->ReadFloat();
|
||||
|
||||
lr_Ta_->AddKeyFrame(KeyFrame(KeyFrameTarget::Position, D3DXVECTOR4(lf_X, lf_Y, lf_Z, 1.0f), lf_Time));
|
||||
}
|
||||
|
||||
unsigned int lui_ScaleElementCount = argFile->ReadInt();
|
||||
for (unsigned int i = 0; i < lui_ScaleElementCount; ++i)
|
||||
{
|
||||
float lf_Time = argFile->ReadFloat();
|
||||
float lf_X = argFile->ReadFloat();
|
||||
float lf_Y = argFile->ReadFloat();
|
||||
float lf_Z = argFile->ReadFloat();
|
||||
|
||||
lr_Ta_->AddKeyFrame(KeyFrame(KeyFrameTarget::Scale, D3DXVECTOR4(lf_X, lf_Y, lf_Z, 1.0f), lf_Time));
|
||||
}
|
||||
|
||||
unsigned int lui_RotationElementCount = argFile->ReadInt();
|
||||
for (unsigned int i = 0; i < lui_RotationElementCount; ++i)
|
||||
{
|
||||
float lf_Time = argFile->ReadFloat();
|
||||
float lf_X = argFile->ReadFloat();
|
||||
float lf_Y = argFile->ReadFloat();
|
||||
float lf_Z = argFile->ReadFloat();
|
||||
|
||||
lr_Ta_->AddKeyFrame(KeyFrame(KeyFrameTarget::Rotation, D3DXVECTOR4(lf_X, lf_Y, lf_Z, 1.0f), lf_Time));
|
||||
}
|
||||
argResult.m_Animations[ls_UniqueName] = lr_Ta_;
|
||||
}
|
||||
|
||||
|
||||
//////////////////////////////////////////////////////////////////////////
|
||||
IRenderable* BluImportResult::GenerateRootRenderable(IEngine* argEngine, IMaterial* argOverrideMaterial)
|
||||
{
|
||||
IResourceFactory* lr_Factory_ = argEngine->get_ResourceFactory();
|
||||
IRenderable* lr_ResultRenderable_ = lr_Factory_->CreateRenderable();
|
||||
|
||||
std::map<string16, BluImportedGeometryBuffer>::iterator lk_Iter = m_GeometryBuffers.begin();
|
||||
for (; lk_Iter != m_GeometryBuffers.end(); ++lk_Iter)
|
||||
{
|
||||
BluImportedGeometryBuffer lr_Mesh = lk_Iter->second;
|
||||
if (argOverrideMaterial != NULL)
|
||||
lr_Mesh.m_GeometryBuffer->set_Material(argOverrideMaterial);
|
||||
lr_ResultRenderable_->AddRenderable(dynamic_cast<IRenderable*>(lr_Mesh.m_GeometryBuffer));
|
||||
}
|
||||
|
||||
if (!m_Bones.empty())
|
||||
m_Bones.begin()->second.m_Bone->GetTransformationAtTime(0.0f, Matrix());
|
||||
|
||||
if (m_BoneController != NULL)
|
||||
{
|
||||
lr_ResultRenderable_->AddController(m_BoneController); // you can also clone it for instancing reasons :)
|
||||
m_BoneController->PlaySequence(L"all");
|
||||
}
|
||||
|
||||
return lr_ResultRenderable_;
|
||||
}
|
||||
119
aiwaz/Aiwaz/BLUImporter/BLUImporter.h
Normal file
119
aiwaz/Aiwaz/BLUImporter/BLUImporter.h
Normal file
@@ -0,0 +1,119 @@
|
||||
#pragma once
|
||||
#include "../Bone/BoneController.h"
|
||||
|
||||
|
||||
struct BluSectionType
|
||||
{
|
||||
enum Enumeration
|
||||
{
|
||||
Mesh = 0,
|
||||
Material = 1,
|
||||
Bone = 2,
|
||||
Animation = 3,
|
||||
LastKnownType = 3
|
||||
};
|
||||
};
|
||||
|
||||
|
||||
template < typename T >
|
||||
struct ScopedBuffer
|
||||
{
|
||||
ScopedBuffer(T* argData)
|
||||
{
|
||||
m_Data = argData;
|
||||
}
|
||||
|
||||
ScopedBuffer(unsigned int argCount)
|
||||
{
|
||||
m_Data = new T[argCount];
|
||||
}
|
||||
|
||||
~ScopedBuffer()
|
||||
{
|
||||
if (m_Data != NULL)
|
||||
delete [] m_Data;
|
||||
}
|
||||
|
||||
T* Detach()
|
||||
{
|
||||
T* l_Tmp_ = m_Data;
|
||||
m_Data = NULL;
|
||||
return l_Tmp_;
|
||||
}
|
||||
|
||||
T* get_Data() const
|
||||
{
|
||||
return m_Data;
|
||||
}
|
||||
|
||||
operator const T* () { return m_Data; }
|
||||
|
||||
T* m_Data;
|
||||
};
|
||||
|
||||
|
||||
struct BluImportedGeometryBuffer
|
||||
{
|
||||
IGeometryBuffer* m_GeometryBuffer;
|
||||
string16 m_MaterialName;
|
||||
};
|
||||
|
||||
|
||||
struct BluImportedBone
|
||||
{
|
||||
IBone* m_Bone;
|
||||
string16 m_ParentName;
|
||||
};
|
||||
|
||||
|
||||
class BluImportResult
|
||||
{
|
||||
public:
|
||||
BluImportResult()
|
||||
: m_SuccessfullyLoaded(false)
|
||||
, m_BoneController(NULL)
|
||||
{}
|
||||
|
||||
bool m_SuccessfullyLoaded;
|
||||
string16 m_FileName;
|
||||
std::map<string16, BluImportedGeometryBuffer> m_GeometryBuffers;
|
||||
std::map<string16, IMaterial*> m_Materials;
|
||||
std::map<string16, BluImportedBone> m_Bones;
|
||||
std::map<string16, ITransformationAnimation*> m_Animations;
|
||||
|
||||
BoneController* m_BoneController;
|
||||
|
||||
IRenderable* GenerateRootRenderable(IEngine* argEngine, IMaterial* argOverrideMaterial);
|
||||
};
|
||||
|
||||
|
||||
class BluImporter
|
||||
{
|
||||
public:
|
||||
BluImporter(IEngine& argEngine);
|
||||
BluImportResult Load(const string16& argFileName);
|
||||
|
||||
static IRenderable* Load(IEngine* argEngine, const string16& argFileName, IMaterial* argOverrideMaterial = NULL);
|
||||
|
||||
protected:
|
||||
void ImportMesh(IFile* argFile, string8 argObjectName, BluImportResult& argResult);
|
||||
void ImportMaterial(IFile* argFile, string8 argObjectName, BluImportResult& argResult);
|
||||
void ImportBone(IFile* argFile, string8 argObjectName, BluImportResult& argResult);
|
||||
void ImportAnimation(IFile* argFile, string8 argObjectName, BluImportResult& argResult);
|
||||
|
||||
string16 ConvertPath(const string8& argOrignal)
|
||||
{
|
||||
if (argOrignal.empty())
|
||||
return std::to_string16(argOrignal);
|
||||
|
||||
int li_Pos = argOrignal.rfind("\\");
|
||||
if (li_Pos >= 0)
|
||||
return m_CurrentPath + std::to_string16(argOrignal.substr(li_Pos + 1, argOrignal.size() - li_Pos));
|
||||
|
||||
return m_CurrentPath + std::to_string16(argOrignal);
|
||||
}
|
||||
|
||||
private:
|
||||
IEngine& m_Engine;
|
||||
string16 m_CurrentPath;
|
||||
};
|
||||
367
aiwaz/Aiwaz/Commands/CommandBuffer.cpp
Normal file
367
aiwaz/Aiwaz/Commands/CommandBuffer.cpp
Normal file
@@ -0,0 +1,367 @@
|
||||
#include "stdafx.h"
|
||||
#include <algorithm>
|
||||
#include "CommandBuffer.h"
|
||||
|
||||
|
||||
CommandBuffer::CommandBuffer(bool argCommandOwer, bool argChildBufferOwner)
|
||||
: m_CommandOwer(argCommandOwer)
|
||||
, m_ChildBufferOwner(argChildBufferOwner)
|
||||
, m_OptimizedCommandBuffer(NULL)
|
||||
, m_ParentCommandBuffer(NULL)
|
||||
{
|
||||
}
|
||||
|
||||
|
||||
CommandBuffer::~CommandBuffer()
|
||||
{
|
||||
delete m_OptimizedCommandBuffer;
|
||||
}
|
||||
|
||||
|
||||
void CommandBuffer::Clear()
|
||||
{
|
||||
if (!m_CommandOwer)
|
||||
m_CommandList.clear();
|
||||
else
|
||||
{
|
||||
while (!m_CommandList.empty())
|
||||
{
|
||||
delete m_CommandList[0];
|
||||
m_CommandList.erase(m_CommandList.begin());
|
||||
}
|
||||
}
|
||||
|
||||
if (!m_ChildBufferOwner)
|
||||
{
|
||||
while (!m_ChildCommandBuffers.empty())
|
||||
this->RemoveChildCommandBuffer(*m_ChildCommandBuffers.back());
|
||||
}
|
||||
else
|
||||
{
|
||||
while (!m_ChildCommandBuffers.empty())
|
||||
{
|
||||
delete m_ChildCommandBuffers[0];
|
||||
m_ChildCommandBuffers.erase(m_ChildCommandBuffers.begin());
|
||||
}
|
||||
}
|
||||
|
||||
while (!m_GatheredCommandChains.empty())
|
||||
{
|
||||
delete m_GatheredCommandChains[0];
|
||||
m_GatheredCommandChains.erase(m_GatheredCommandChains.begin());
|
||||
}
|
||||
|
||||
if (m_OptimizedCommandBuffer != NULL)
|
||||
m_OptimizedCommandBuffer->Clear();
|
||||
}
|
||||
|
||||
|
||||
void CommandBuffer::AddCommand( Command& argCommand )
|
||||
{
|
||||
m_CommandList.push_back(&argCommand);
|
||||
}
|
||||
|
||||
|
||||
void CommandBuffer::Perform( bool argUseOptimizedList )
|
||||
{
|
||||
if (argUseOptimizedList)
|
||||
{
|
||||
if (m_OptimizedCommandBuffer != NULL)
|
||||
m_OptimizedCommandBuffer->Perform(false);
|
||||
}
|
||||
else
|
||||
{
|
||||
int subChainStartCommandIndex = -1;
|
||||
for (uint32 i = 0; i < m_CommandList.size();)
|
||||
{
|
||||
if (m_CommandList[i]->Flags & CommandFlags::SubChainStart)
|
||||
subChainStartCommandIndex = i;
|
||||
|
||||
switch (m_CommandList[i]->Owner->ExecuteCommand(m_CommandList[i]->Type, *const_cast<CommandBuffer*>(this), i))
|
||||
{
|
||||
case CommandExecuteResult::None:
|
||||
if (m_CommandList[i]->Flags & CommandFlags::SubChainEnd)
|
||||
subChainStartCommandIndex = -1;
|
||||
i++;
|
||||
break;
|
||||
case CommandExecuteResult::RetrySubChain:
|
||||
if (subChainStartCommandIndex == -1)
|
||||
std::wcout << std::red << "Failed to restart sub command chain." << std::white << std::endl;
|
||||
else
|
||||
i = subChainStartCommandIndex;
|
||||
break;
|
||||
case CommandExecuteResult::RetrySubChainSkipHead:
|
||||
if (subChainStartCommandIndex == -1)
|
||||
std::wcout << std::red << "Failed to restart headless sub command chain." << std::white << std::endl;
|
||||
else
|
||||
i = subChainStartCommandIndex + 1;
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
void CommandBuffer::Optimize()
|
||||
{
|
||||
m_HashToCommandChain.clear();
|
||||
if (m_OptimizedCommandBuffer == NULL)
|
||||
m_OptimizedCommandBuffer = new CommandBuffer(false, true);
|
||||
else
|
||||
m_OptimizedCommandBuffer->Clear();
|
||||
|
||||
std::vector<Command*> tempChain;
|
||||
this->SearchDrawableCommandChain(this, tempChain);
|
||||
this->FlushGatheredCommandChains();
|
||||
}
|
||||
|
||||
|
||||
void CommandBuffer::AddChildCommandBuffer( ICommandBuffer& argCommandBuffer )
|
||||
{
|
||||
m_ChildCommandBuffers.push_back(&argCommandBuffer);
|
||||
argCommandBuffer.set_ParentBuffer(this);
|
||||
}
|
||||
|
||||
|
||||
void CommandBuffer::RemoveChildCommandBuffer( ICommandBuffer& argCommandBuffer )
|
||||
{
|
||||
std::vector<ICommandBuffer*>::iterator iter = std::find(m_ChildCommandBuffers.begin(), m_ChildCommandBuffers.end(), &argCommandBuffer);
|
||||
if (iter != m_ChildCommandBuffers.end())
|
||||
{
|
||||
argCommandBuffer.set_ParentBuffer(NULL);
|
||||
m_ChildCommandBuffers.erase(iter);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
std::vector<Command*>& CommandBuffer::get_BufferedCommands()
|
||||
{
|
||||
return m_CommandList;
|
||||
}
|
||||
|
||||
|
||||
const std::vector<ICommandBuffer*>& CommandBuffer::get_ChildCommandBuffers() const
|
||||
{
|
||||
return m_ChildCommandBuffers;
|
||||
}
|
||||
|
||||
|
||||
ICommandBuffer* CommandBuffer::get_ParentBuffer() const
|
||||
{
|
||||
return m_ParentCommandBuffer;
|
||||
}
|
||||
|
||||
|
||||
void CommandBuffer::set_ParentBuffer( ICommandBuffer* ar_CommandBuffer_ )
|
||||
{
|
||||
m_ParentCommandBuffer = ar_CommandBuffer_;
|
||||
}
|
||||
|
||||
|
||||
void CommandBuffer::SearchDrawableCommandChain(ICommandBuffer* ar_Buffer_, std::vector<Command*>& argCurrentChain)
|
||||
{
|
||||
for (uint32 i = 0; i < ar_Buffer_->get_BufferedCommands().size();)
|
||||
{
|
||||
Command& currentCommand = *ar_Buffer_->get_BufferedCommands()[i];
|
||||
UINT32 commandFlags = currentCommand.Flags;
|
||||
// A command is start AND end of a command chain, this indicates that a serious state change will come,
|
||||
// so we will need to flush the current command chains.
|
||||
if ((commandFlags & CommandFlags::FlushChain) != 0)
|
||||
{
|
||||
this->FlushGatheredCommandChains();
|
||||
argCurrentChain.clear();
|
||||
}
|
||||
// Old way commented out due problems with transformations before shaders
|
||||
// A command was found which does not belong to a build up current chain (due no chain is building herself up..)
|
||||
// so we drop it, we simply do not care about some run away
|
||||
/*if (argCurrentChain.empty()
|
||||
&& (commandFlags & CommandFlags::StartChain) == 0
|
||||
&& (commandFlags & CommandFlags::EndChain) == 0)
|
||||
{
|
||||
++i;
|
||||
continue;
|
||||
}*/
|
||||
// New way is to search the list for a start chain command, then we put this command after the start chain command
|
||||
if (argCurrentChain.empty()
|
||||
&& (commandFlags & CommandFlags::StartChain) == 0
|
||||
&& (commandFlags & CommandFlags::EndChain) == 0)
|
||||
{
|
||||
bool foundPlace = false;
|
||||
std::vector<Command*>& commands = ar_Buffer_->get_BufferedCommands();
|
||||
for (uint32 k = i + 1; k < commands.size(); ++k)
|
||||
if (commands[k]->Flags & CommandFlags::StartChain)
|
||||
{
|
||||
commands.insert(commands.begin() + k + 1, ¤tCommand);
|
||||
commands.erase(commands.begin() + i);
|
||||
foundPlace = true;
|
||||
break;
|
||||
}
|
||||
|
||||
if (!foundPlace)
|
||||
++i;
|
||||
continue;
|
||||
}
|
||||
// A new command chain should be initialized, clear our current temp chain and add this command into it.
|
||||
// All old commands remaining in the chain are already used or where completely useless (SetShader -> SetParameter -> NextPass).
|
||||
else if ((commandFlags & CommandFlags::StartChain) != 0
|
||||
&& !argCurrentChain.empty())
|
||||
{
|
||||
argCurrentChain.clear();
|
||||
argCurrentChain.push_back(¤tCommand);
|
||||
++i;
|
||||
}
|
||||
// We should end our chain, now we need to optimize this chain and add this into the gathered chain list,
|
||||
// at the next flush command we will put this list into our optimized list, with some more optimizations.
|
||||
else if ((commandFlags & CommandFlags::EndChain) != 0)
|
||||
{
|
||||
// We have a filled chain (at least 1 operation following by this operation)
|
||||
if (!argCurrentChain.empty())
|
||||
{
|
||||
CommandChainInternal* chain = new CommandChainInternal();
|
||||
chain->m_Chain = argCurrentChain;
|
||||
|
||||
chain->m_Chain.push_back(¤tCommand);
|
||||
std::sort(chain->m_Chain.begin(), chain->m_Chain.end(), CommandChainInternal::CommandSort());
|
||||
|
||||
//m_OptimizedCommandBuffer->get_BufferedCommands().insert(m_OptimizedCommandBuffer->get_BufferedCommands().end(), chain.begin(), chain.end());
|
||||
m_GatheredCommandChains.push_back(chain);
|
||||
|
||||
// Search for the SubChainEnd flagged command , this should be found right after the SubChainStart flagged commands
|
||||
// both commands will mark the beginning of our chain -> delete everything behind this command will ensure
|
||||
// that we will use a fresh new command chain, only filled with what we need (StartSubChain -> EndSubChain)
|
||||
for (uint32 k = 0; k < argCurrentChain.size(); ++k)
|
||||
{
|
||||
if (argCurrentChain[k]->Flags & CommandFlags::SubChainEnd)
|
||||
{
|
||||
argCurrentChain.erase(argCurrentChain.begin() + k + 1, argCurrentChain.end());
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
// Our chain was empty, this means a solo command was found, put it into our optimized list and continue,
|
||||
// there is not much to do here.
|
||||
else
|
||||
{
|
||||
m_OptimizedCommandBuffer->get_BufferedCommands().push_back(¤tCommand);
|
||||
}
|
||||
++i;
|
||||
}
|
||||
// No start and no end of the command chain, just put this command into our chain,
|
||||
// commands of this type are for example, SetVertexBuffer, SetIndexBuffer, SetTransformation,...
|
||||
else
|
||||
{
|
||||
argCurrentChain.push_back(¤tCommand);
|
||||
++i;
|
||||
}
|
||||
}
|
||||
|
||||
// We may have child buffers, continue our search there.
|
||||
for (uint32 i = 0; i < ar_Buffer_->get_ChildCommandBuffers().size(); ++i)
|
||||
{
|
||||
std::vector<Command*> currentChain = argCurrentChain;
|
||||
this->SearchDrawableCommandChain(ar_Buffer_->get_ChildCommandBuffers()[i], argCurrentChain);
|
||||
argCurrentChain = currentChain;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
void CommandBuffer::FlushGatheredCommandChains()
|
||||
{
|
||||
std::vector<Command*> flushedCommands;
|
||||
for (uint32 i = 0; i < m_GatheredCommandChains.size(); ++i)
|
||||
m_GatheredCommandChains[i]->UpdatePriority();
|
||||
|
||||
while (!m_GatheredCommandChains.empty())
|
||||
{
|
||||
std::sort(m_GatheredCommandChains.begin(), m_GatheredCommandChains.end(), CommandChainInternal::CommandChainSort());
|
||||
|
||||
uint32 currentPriority = 0;
|
||||
std::vector<uint32> checkables;
|
||||
for (uint32 i = 0; i < m_GatheredCommandChains.size();)
|
||||
{
|
||||
if (m_GatheredCommandChains[i]->m_Chain.empty())
|
||||
m_GatheredCommandChains.erase(m_GatheredCommandChains.begin() + i);
|
||||
else if (checkables.empty() || currentPriority == m_GatheredCommandChains[i]->m_Priority)
|
||||
{
|
||||
currentPriority = m_GatheredCommandChains[i]->m_Priority;
|
||||
checkables.push_back(i);
|
||||
++i;
|
||||
}
|
||||
else
|
||||
break;
|
||||
}
|
||||
if (checkables.size() == 1)
|
||||
{
|
||||
uint32 thisIndex = checkables.front();
|
||||
flushedCommands.insert( flushedCommands.end(),
|
||||
m_GatheredCommandChains[thisIndex]->m_Chain.begin(),
|
||||
m_GatheredCommandChains[thisIndex]->m_Chain.end());
|
||||
m_GatheredCommandChains.erase(m_GatheredCommandChains.begin() + thisIndex);
|
||||
if (m_GatheredCommandChains.empty())
|
||||
break;
|
||||
}
|
||||
|
||||
std::vector<Command*> optimizedCommandChain;
|
||||
|
||||
Command* lastCommand = NULL;
|
||||
while (checkables.size() > 1)
|
||||
{
|
||||
if (!checkables.empty() && checkables.front() != 0)
|
||||
break;
|
||||
for (uint32 i = 0; i < checkables.size();)
|
||||
{
|
||||
uint32 thisIndex = checkables[i];
|
||||
CommandChainInternal* currentCommandChainInternal = m_GatheredCommandChains[thisIndex];
|
||||
Command* thisCommand = *currentCommandChainInternal->m_Chain.begin();
|
||||
if (i == 0 || (thisCommand->CommandInfo == lastCommand->CommandInfo && thisCommand->Owner == lastCommand->Owner))
|
||||
{
|
||||
// we found a similarity (or the first element), put this into our optimized temp list
|
||||
lastCommand = thisCommand;
|
||||
if (i == 0 || (thisCommand->Flags & CommandFlags::Unique) != 0)
|
||||
optimizedCommandChain.push_back(thisCommand);
|
||||
currentCommandChainInternal->m_Chain.erase(currentCommandChainInternal->m_Chain.begin());
|
||||
if (currentCommandChainInternal->m_Chain.empty())
|
||||
{
|
||||
checkables.erase(checkables.begin() + i);
|
||||
break;
|
||||
}
|
||||
else
|
||||
++i;
|
||||
}
|
||||
else
|
||||
{
|
||||
// do not check this list further, a difference was detected
|
||||
checkables.erase(checkables.begin() + i);
|
||||
}
|
||||
}
|
||||
|
||||
// resort our m_GatheredCommandChains so that we could use the remaining content of a list properly, only do that if the checkable list has no direct preceeding elements ({0,2,3} instead {0,1,2})
|
||||
if (!checkables.empty())
|
||||
for (uint32 i = checkables.front() + 1; i < checkables.size(); ++i)
|
||||
if (checkables[i] != i)
|
||||
{
|
||||
std::swap(m_GatheredCommandChains[i], m_GatheredCommandChains[checkables[i]]);
|
||||
checkables[i] = i;
|
||||
}
|
||||
}
|
||||
|
||||
flushedCommands.insert(flushedCommands.end(), optimizedCommandChain.begin(), optimizedCommandChain.end());
|
||||
}
|
||||
|
||||
// remove unnecessary SubChainEnd commands
|
||||
bool openPass = false;
|
||||
for (int i = flushedCommands.size() - 1; i >= 0; --i)
|
||||
{
|
||||
if (flushedCommands[i]->Flags == CommandFlags::SubChainEnd)
|
||||
{
|
||||
if (!openPass)
|
||||
openPass = true;
|
||||
else
|
||||
flushedCommands.erase(flushedCommands.begin() + i);
|
||||
}
|
||||
else if (flushedCommands[i]->Flags == CommandFlags::SubChainStart)
|
||||
openPass = false;
|
||||
|
||||
}
|
||||
m_OptimizedCommandBuffer->get_BufferedCommands().insert(m_OptimizedCommandBuffer->get_BufferedCommands().end(), flushedCommands.begin(), flushedCommands.end());
|
||||
}
|
||||
96
aiwaz/Aiwaz/Commands/CommandBuffer.h
Normal file
96
aiwaz/Aiwaz/Commands/CommandBuffer.h
Normal file
@@ -0,0 +1,96 @@
|
||||
#pragma once
|
||||
|
||||
#include "ICommandUser.h"
|
||||
|
||||
|
||||
class CommandBuffer
|
||||
: public ICommandBuffer
|
||||
{
|
||||
public:
|
||||
CommandBuffer(bool argCommandOwer, bool argChildBufferOwner);
|
||||
virtual ~CommandBuffer();
|
||||
virtual void Clear();
|
||||
virtual void AddCommand(Command& argCommand);
|
||||
virtual void Perform(bool argUseOptimizedList);
|
||||
virtual void Optimize();
|
||||
virtual void AddChildCommandBuffer(ICommandBuffer& argCommandBuffer);
|
||||
virtual void RemoveChildCommandBuffer(ICommandBuffer& argCommandBuffer);
|
||||
virtual std::vector<Command*>& get_BufferedCommands();
|
||||
virtual const std::vector<ICommandBuffer*>& get_ChildCommandBuffers() const;
|
||||
virtual ICommandBuffer* get_ParentBuffer() const;
|
||||
virtual void set_ParentBuffer(ICommandBuffer* ar_CommandBuffer_);
|
||||
|
||||
protected:
|
||||
void SearchDrawableCommandChain(ICommandBuffer* ar_Buffer_, std::vector<Command*>& argCurrentChain);
|
||||
void FlushGatheredCommandChains();
|
||||
|
||||
private:
|
||||
|
||||
struct CommandChainInternal
|
||||
{
|
||||
CommandChainInternal() : m_Priority(0) {}
|
||||
|
||||
void UpdatePriority()
|
||||
{
|
||||
m_Priority = -1;
|
||||
for (uint32 i = 0; i < m_Chain.size(); ++i)
|
||||
{
|
||||
if (m_Chain[i]->Flags & CommandFlags::SubChainStart)
|
||||
{
|
||||
m_Priority = m_Chain[i]->SubPriority;
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
UINT8 m_Priority;
|
||||
std::vector<Command*> m_Chain;
|
||||
|
||||
struct CommandChainSort
|
||||
{
|
||||
bool operator()(CommandChainInternal* ar_Left_, CommandChainInternal* ar_Right_) const
|
||||
{
|
||||
if (ar_Left_->m_Priority == ar_Right_->m_Priority)
|
||||
return ar_Left_->m_Chain.size() < ar_Right_->m_Chain.size();
|
||||
return ar_Left_->m_Priority < ar_Right_->m_Priority;
|
||||
}
|
||||
};
|
||||
|
||||
struct CommandSort
|
||||
{
|
||||
bool operator()(Command* ar_Left_, Command* ar_Right_) const
|
||||
{
|
||||
return ar_Left_->Priority < ar_Right_->Priority;
|
||||
}
|
||||
};
|
||||
};
|
||||
|
||||
private:
|
||||
ICommandBuffer* m_ParentCommandBuffer;
|
||||
ICommandBuffer* m_OptimizedCommandBuffer;
|
||||
std::vector<Command*> m_CommandList;
|
||||
std::vector<ICommandBuffer*> m_ChildCommandBuffers;
|
||||
|
||||
bool m_CommandOwer;
|
||||
bool m_ChildBufferOwner;
|
||||
|
||||
std::map<uint32, std::vector<Command*> > m_HashToCommandChain;
|
||||
|
||||
intptr_t GenerateHashValue(const std::vector<Command*>& argCommands) const
|
||||
{
|
||||
intptr_t hash = 0;
|
||||
for (uint32 i = 0; i < argCommands.size(); ++i)
|
||||
{
|
||||
hash += (intptr_t)argCommands[i];
|
||||
hash += (hash << 10);
|
||||
hash ^= (hash >> 6);
|
||||
|
||||
hash += (hash << 3);
|
||||
hash ^= (hash >> 11);
|
||||
hash += (hash << 15);
|
||||
}
|
||||
return hash;
|
||||
}
|
||||
|
||||
std::vector<CommandChainInternal*> m_GatheredCommandChains;
|
||||
};
|
||||
57
aiwaz/Aiwaz/Commands/CommandUserBase.cpp
Normal file
57
aiwaz/Aiwaz/Commands/CommandUserBase.cpp
Normal file
@@ -0,0 +1,57 @@
|
||||
#include "stdafx.h"
|
||||
#include <algorithm>
|
||||
#include "CommandUserBase.h"
|
||||
|
||||
|
||||
CommandUserBase::CommandUserBase()
|
||||
{
|
||||
}
|
||||
|
||||
|
||||
CommandUserBase::~CommandUserBase()
|
||||
{
|
||||
this->UnassignFromSceneNodes();
|
||||
while (!m_Commands.empty())
|
||||
{
|
||||
delete m_Commands[0];
|
||||
m_Commands.erase(m_Commands.begin());
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
const std::vector<Command*>& CommandUserBase::GetCommands() const
|
||||
{
|
||||
return m_Commands;
|
||||
}
|
||||
|
||||
|
||||
void CommandUserBase::AssignToRenderCommandNode(IRenderCommandNode& argNode)
|
||||
{
|
||||
m_RenderCommandNodesIamAssignedTo.push_back(&argNode);
|
||||
argNode.MarkDirty();
|
||||
}
|
||||
|
||||
|
||||
void CommandUserBase::UnassignFromRenderCommandNode(IRenderCommandNode& argNode)
|
||||
{
|
||||
std::vector<IRenderCommandNode*>::iterator found = std::find(m_RenderCommandNodesIamAssignedTo.begin(), m_RenderCommandNodesIamAssignedTo.end(), &argNode);
|
||||
if (found != m_RenderCommandNodesIamAssignedTo.end())
|
||||
{
|
||||
m_RenderCommandNodesIamAssignedTo.erase(found);
|
||||
argNode.MarkDirty();
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
void CommandUserBase::UnassignFromSceneNodes()
|
||||
{
|
||||
while (!m_RenderCommandNodesIamAssignedTo.empty())
|
||||
m_RenderCommandNodesIamAssignedTo.back()->RemoveCommandUser(*const_cast<CommandUserBase*>(this));
|
||||
}
|
||||
|
||||
|
||||
void CommandUserBase::MarkCommandsAsDirty()
|
||||
{
|
||||
for (uint32 i = 0; i < m_RenderCommandNodesIamAssignedTo.size(); ++i)
|
||||
m_RenderCommandNodesIamAssignedTo[i]->MarkDirty();
|
||||
}
|
||||
32
aiwaz/Aiwaz/Commands/CommandUserBase.h
Normal file
32
aiwaz/Aiwaz/Commands/CommandUserBase.h
Normal file
@@ -0,0 +1,32 @@
|
||||
#pragma once
|
||||
|
||||
#include "ICommandUser.h"
|
||||
#include "IRenderCommandNode.h"
|
||||
|
||||
|
||||
class CommandUserBase
|
||||
: public ICommandUser
|
||||
{
|
||||
public:
|
||||
CommandUserBase();
|
||||
virtual ~CommandUserBase();
|
||||
|
||||
virtual const std::vector<Command*>& GetCommands() const;
|
||||
virtual CommandExecuteResult::Enumeration ExecuteCommand(unsigned char argCommandType, ICommandBuffer& argCurrentBuffer, uint32 argCurrentPositon) = 0;
|
||||
|
||||
virtual void AssignToRenderCommandNode(IRenderCommandNode& argNode);
|
||||
virtual void UnassignFromRenderCommandNode(IRenderCommandNode& argNode);
|
||||
|
||||
virtual bool get_IsPreconditionForNextCommands() const { return false; }
|
||||
|
||||
virtual string8 get_UserName() const = 0;
|
||||
|
||||
protected:
|
||||
void UnassignFromSceneNodes();
|
||||
void MarkCommandsAsDirty();
|
||||
|
||||
std::vector<Command*> m_Commands;
|
||||
|
||||
private:
|
||||
std::vector<IRenderCommandNode*> m_RenderCommandNodesIamAssignedTo;
|
||||
};
|
||||
6
aiwaz/Aiwaz/Common/BaseTypes.h
Normal file
6
aiwaz/Aiwaz/Common/BaseTypes.h
Normal file
@@ -0,0 +1,6 @@
|
||||
#pragma once
|
||||
#include <string>
|
||||
|
||||
typedef unsigned int uint32;
|
||||
typedef std::wstring string16;
|
||||
typedef std::string string8;
|
||||
101
aiwaz/Aiwaz/Common/ConsoleColor.h
Normal file
101
aiwaz/Aiwaz/Common/ConsoleColor.h
Normal file
@@ -0,0 +1,101 @@
|
||||
#pragma once
|
||||
#include <iostream>
|
||||
#include <windows.h>
|
||||
|
||||
namespace std
|
||||
{
|
||||
inline std::ostream& blue(std::ostream &s)
|
||||
{
|
||||
HANDLE hStdout = GetStdHandle(STD_OUTPUT_HANDLE);
|
||||
SetConsoleTextAttribute(hStdout, FOREGROUND_BLUE
|
||||
|FOREGROUND_GREEN|FOREGROUND_INTENSITY);
|
||||
return s;
|
||||
}
|
||||
|
||||
inline std::ostream& red(std::ostream &s)
|
||||
{
|
||||
HANDLE hStdout = GetStdHandle(STD_OUTPUT_HANDLE);
|
||||
SetConsoleTextAttribute(hStdout,
|
||||
FOREGROUND_RED|FOREGROUND_INTENSITY);
|
||||
return s;
|
||||
}
|
||||
|
||||
inline std::ostream& green(std::ostream &s)
|
||||
{
|
||||
HANDLE hStdout = GetStdHandle(STD_OUTPUT_HANDLE);
|
||||
SetConsoleTextAttribute(hStdout,
|
||||
FOREGROUND_GREEN|FOREGROUND_INTENSITY);
|
||||
return s;
|
||||
}
|
||||
|
||||
inline std::ostream& yellow(std::ostream &s)
|
||||
{
|
||||
HANDLE hStdout = GetStdHandle(STD_OUTPUT_HANDLE);
|
||||
SetConsoleTextAttribute(hStdout,
|
||||
FOREGROUND_GREEN|FOREGROUND_RED|FOREGROUND_INTENSITY);
|
||||
return s;
|
||||
}
|
||||
|
||||
inline std::ostream& white(std::ostream &s)
|
||||
{
|
||||
HANDLE hStdout = GetStdHandle(STD_OUTPUT_HANDLE);
|
||||
SetConsoleTextAttribute(hStdout,
|
||||
FOREGROUND_RED|FOREGROUND_GREEN|FOREGROUND_BLUE);
|
||||
return s;
|
||||
}
|
||||
|
||||
struct color {
|
||||
color(WORD attribute):m_color(attribute){};
|
||||
WORD m_color;
|
||||
};
|
||||
|
||||
template <class _Elem, class _Traits>
|
||||
std::basic_ostream<_Elem,_Traits>&
|
||||
operator<<(std::basic_ostream<_Elem,_Traits>& i, color& c)
|
||||
{
|
||||
HANDLE hStdout=GetStdHandle(STD_OUTPUT_HANDLE);
|
||||
SetConsoleTextAttribute(hStdout,c.m_color);
|
||||
return i;
|
||||
}
|
||||
|
||||
//////////////////////////////////////////////////////////////////////////
|
||||
inline std::wostream& blue(std::wostream &s)
|
||||
{
|
||||
HANDLE hStdout = GetStdHandle(STD_OUTPUT_HANDLE);
|
||||
SetConsoleTextAttribute(hStdout, FOREGROUND_BLUE
|
||||
|FOREGROUND_GREEN|FOREGROUND_INTENSITY);
|
||||
return s;
|
||||
}
|
||||
|
||||
inline std::wostream& red(std::wostream &s)
|
||||
{
|
||||
HANDLE hStdout = GetStdHandle(STD_OUTPUT_HANDLE);
|
||||
SetConsoleTextAttribute(hStdout,
|
||||
FOREGROUND_RED|FOREGROUND_INTENSITY);
|
||||
return s;
|
||||
}
|
||||
|
||||
inline std::wostream& green(std::wostream &s)
|
||||
{
|
||||
HANDLE hStdout = GetStdHandle(STD_OUTPUT_HANDLE);
|
||||
SetConsoleTextAttribute(hStdout,
|
||||
FOREGROUND_GREEN|FOREGROUND_INTENSITY);
|
||||
return s;
|
||||
}
|
||||
|
||||
inline std::wostream& yellow(std::wostream &s)
|
||||
{
|
||||
HANDLE hStdout = GetStdHandle(STD_OUTPUT_HANDLE);
|
||||
SetConsoleTextAttribute(hStdout,
|
||||
FOREGROUND_GREEN|FOREGROUND_RED|FOREGROUND_INTENSITY);
|
||||
return s;
|
||||
}
|
||||
|
||||
inline std::wostream& white(std::wostream &s)
|
||||
{
|
||||
HANDLE hStdout = GetStdHandle(STD_OUTPUT_HANDLE);
|
||||
SetConsoleTextAttribute(hStdout,
|
||||
FOREGROUND_RED|FOREGROUND_GREEN|FOREGROUND_BLUE);
|
||||
return s;
|
||||
}
|
||||
}
|
||||
57
aiwaz/Aiwaz/Common/StringHelper.h
Normal file
57
aiwaz/Aiwaz/Common/StringHelper.h
Normal file
@@ -0,0 +1,57 @@
|
||||
#pragma once
|
||||
|
||||
#include <cstring>
|
||||
#include <string>
|
||||
|
||||
#include <string>
|
||||
#include <vector>
|
||||
#include <locale>
|
||||
#include <functional>
|
||||
#include <iostream>
|
||||
|
||||
#pragma warning(disable:4996)
|
||||
|
||||
namespace std
|
||||
{
|
||||
inline bool equal_nocase(const std::string &argStringA, const std::string &argStringB)
|
||||
{
|
||||
return 0 == stricmp (argStringA.c_str(), argStringB.c_str());
|
||||
}
|
||||
|
||||
inline bool equal_nocase(const std::wstring &argStringA, const std::wstring &argStringB)
|
||||
{
|
||||
return 0 == wcsicmp(argStringA.c_str(), argStringB.c_str());
|
||||
}
|
||||
|
||||
inline std::string to_string8(const std::wstring& argString)
|
||||
{
|
||||
if (argString.empty())
|
||||
return std::string();
|
||||
|
||||
const std::ctype<wchar_t>* cType = &std::use_facet<std::ctype<wchar_t> >(std::locale());
|
||||
|
||||
std::wstring::size_type srcLen = argString.length();
|
||||
const wchar_t* srcBegin = argString.c_str();
|
||||
std::vector<char> tmp(srcLen);
|
||||
|
||||
cType->narrow(srcBegin, srcBegin + srcLen, '\0', &tmp[0]);
|
||||
return std::string(&tmp[0], srcLen);
|
||||
}
|
||||
|
||||
inline std::wstring to_string16(const std::string& argString)
|
||||
{
|
||||
if (argString.empty())
|
||||
return std::wstring();
|
||||
|
||||
const std::ctype<wchar_t>* cType = &std::use_facet<std::ctype<wchar_t> >(std::locale());
|
||||
|
||||
std::wstring::size_type srcLen = argString.length();
|
||||
const char* srcBegin = argString.c_str();
|
||||
std::vector<wchar_t> tmp(srcLen);
|
||||
|
||||
cType->widen(srcBegin, srcBegin + srcLen, &tmp[0]);
|
||||
return std::wstring(&tmp[0], srcLen);
|
||||
}
|
||||
}
|
||||
|
||||
#pragma warning(default:4996)
|
||||
143
aiwaz/Aiwaz/CommonObjectFactory/CommonObjectFactory.cpp
Normal file
143
aiwaz/Aiwaz/CommonObjectFactory/CommonObjectFactory.cpp
Normal file
@@ -0,0 +1,143 @@
|
||||
#include "stdafx.h"
|
||||
#include "IResourceFactory.h"
|
||||
#include "CommonObjectFactory.h"
|
||||
#include "PingPongBuffer/PingPongBuffer.h"
|
||||
|
||||
|
||||
CommonObjectFactory::CommonObjectFactory(IEngine& argEngine)
|
||||
: m_Engine(argEngine)
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
|
||||
CommonObjectFactory::~CommonObjectFactory()
|
||||
{
|
||||
}
|
||||
|
||||
|
||||
IPingPongBuffer* CommonObjectFactory::CreatePingPongBuffer(ITexture& argInputTexture, const PingPongBufferDescription& argDescriptor)
|
||||
{
|
||||
IPingPongBuffer* pingPongBuffer = new PingPongBuffer(m_Engine);
|
||||
pingPongBuffer->set_InputTexture(argInputTexture);
|
||||
pingPongBuffer->set_Descriptor(argDescriptor);
|
||||
return pingPongBuffer;
|
||||
}
|
||||
|
||||
|
||||
IGeometryBuffer* CommonObjectFactory::CreateCube(float argWidth, float argHeight, float argDepth, bool argInverted, const string8& argName)
|
||||
{
|
||||
argWidth *= 0.5f;
|
||||
argHeight *= 0.5f;
|
||||
argDepth *= 0.5f;
|
||||
|
||||
float normal = argInverted ? -1.0f : 1.0f;
|
||||
float tangent = 1.0;//argInverted ? -1.0f : 1.0f;
|
||||
CommonCubeVertex vertices[] =
|
||||
{
|
||||
{ D3DXVECTOR3( -argWidth, argHeight, -argDepth ), D3DXVECTOR3(0.0f, normal, 0.0f), D3DXVECTOR3(-tangent, 0.0f, 0.0f), D3DXVECTOR2( 0.0f, 0.0f ) },
|
||||
{ D3DXVECTOR3( argWidth, argHeight, -argDepth ), D3DXVECTOR3(0.0f, normal, 0.0f), D3DXVECTOR3(-tangent, 0.0f, 0.0f), D3DXVECTOR2( 1.0f, 0.0f ) },
|
||||
{ D3DXVECTOR3( argWidth, argHeight, argDepth ), D3DXVECTOR3(0.0f, normal, 0.0f), D3DXVECTOR3(-tangent, 0.0f, 0.0f), D3DXVECTOR2( 1.0f, 1.0f ) },
|
||||
{ D3DXVECTOR3( -argWidth, argHeight, argDepth ), D3DXVECTOR3(0.0f, normal, 0.0f), D3DXVECTOR3(-tangent, 0.0f, 0.0f), D3DXVECTOR2( 0.0f, 1.0f ) },
|
||||
|
||||
{ D3DXVECTOR3( -argWidth, -argHeight, -argDepth ), D3DXVECTOR3(0.0f, -normal, 0.0f), D3DXVECTOR3(-tangent, 0.0f, 0.0f), D3DXVECTOR2( 0.0f, 0.0f ) },
|
||||
{ D3DXVECTOR3( argWidth, -argHeight, -argDepth ), D3DXVECTOR3(0.0f, -normal, 0.0f), D3DXVECTOR3(-tangent, 0.0f, 0.0f), D3DXVECTOR2( 1.0f, 0.0f ) },
|
||||
{ D3DXVECTOR3( argWidth, -argHeight, argDepth ), D3DXVECTOR3(0.0f, -normal, 0.0f), D3DXVECTOR3(-tangent, 0.0f, 0.0f), D3DXVECTOR2( 1.0f, 1.0f ) },
|
||||
{ D3DXVECTOR3( -argWidth, -argHeight, argDepth ), D3DXVECTOR3(0.0f, -normal, 0.0f), D3DXVECTOR3(-tangent, 0.0f, 0.0f), D3DXVECTOR2( 0.0f, 1.0f ) },
|
||||
|
||||
{ D3DXVECTOR3( -argWidth, -argHeight, argDepth ), D3DXVECTOR3(-normal, 0.0f, 0.0f), D3DXVECTOR3(0.0f, tangent, 0.0f), D3DXVECTOR2( 0.0f, 1.0f ) },
|
||||
{ D3DXVECTOR3( -argWidth, -argHeight, -argDepth ), D3DXVECTOR3(-normal, 0.0f, 0.0f), D3DXVECTOR3(0.0f, tangent, 0.0f), D3DXVECTOR2( 1.0f, 1.0f ) },
|
||||
{ D3DXVECTOR3( -argWidth, argHeight, -argDepth ), D3DXVECTOR3(-normal, 0.0f, 0.0f), D3DXVECTOR3(0.0f, tangent, 0.0f), D3DXVECTOR2( 1.0f, 0.0f ) },
|
||||
{ D3DXVECTOR3( -argWidth, argHeight, argDepth ), D3DXVECTOR3(-normal, 0.0f, 0.0f), D3DXVECTOR3(0.0f, tangent, 0.0f), D3DXVECTOR2( 0.0f, 0.0f ) },
|
||||
|
||||
{ D3DXVECTOR3( argWidth, -argHeight, argDepth ), D3DXVECTOR3(normal, 0.0f, 0.0f), D3DXVECTOR3(0.0f, -tangent, 0.0f), D3DXVECTOR2( 1.0f, 1.0f ) },
|
||||
{ D3DXVECTOR3( argWidth, -argHeight, -argDepth ), D3DXVECTOR3(normal, 0.0f, 0.0f), D3DXVECTOR3(0.0f, -tangent, 0.0f), D3DXVECTOR2( 0.0f, 1.0f ) },
|
||||
{ D3DXVECTOR3( argWidth, argHeight, -argDepth ), D3DXVECTOR3(normal, 0.0f, 0.0f), D3DXVECTOR3(0.0f, -tangent, 0.0f), D3DXVECTOR2( 0.0f, 0.0f ) },
|
||||
{ D3DXVECTOR3( argWidth, argHeight, argDepth ), D3DXVECTOR3(normal, 0.0f, 0.0f), D3DXVECTOR3(0.0f, -tangent, 0.0f), D3DXVECTOR2( 1.0f, 0.0f ) },
|
||||
|
||||
{ D3DXVECTOR3( -argWidth, -argHeight, -argDepth ), D3DXVECTOR3(0.0f, 0.0f, -normal), D3DXVECTOR3(-tangent, 0.0f, 0.0f), D3DXVECTOR2( 0.0f, 1.0f ) },
|
||||
{ D3DXVECTOR3( argWidth, -argHeight, -argDepth ), D3DXVECTOR3(0.0f, 0.0f, -normal), D3DXVECTOR3(-tangent, 0.0f, 0.0f), D3DXVECTOR2( 1.0f, 1.0f ) },
|
||||
{ D3DXVECTOR3( argWidth, argHeight, -argDepth ), D3DXVECTOR3(0.0f, 0.0f, -normal), D3DXVECTOR3(-tangent, 0.0f, 0.0f), D3DXVECTOR2( 1.0f, 0.0f ) },
|
||||
{ D3DXVECTOR3( -argWidth, argHeight, -argDepth ), D3DXVECTOR3(0.0f, 0.0f, -normal), D3DXVECTOR3(-tangent, 0.0f, 0.0f), D3DXVECTOR2( 0.0f, 0.0f ) },
|
||||
|
||||
{ D3DXVECTOR3( -argWidth, -argHeight, argDepth ), D3DXVECTOR3(0.0f, 0.0f, normal), D3DXVECTOR3(-tangent, 0.0f, 0.0f), D3DXVECTOR2( 1.0f, 1.0f ) },
|
||||
{ D3DXVECTOR3( argWidth, -argHeight, argDepth ), D3DXVECTOR3(0.0f, 0.0f, normal), D3DXVECTOR3(-tangent, 0.0f, 0.0f), D3DXVECTOR2( 0.0f, 1.0f ) },
|
||||
{ D3DXVECTOR3( argWidth, argHeight, argDepth ), D3DXVECTOR3(0.0f, 0.0f, normal), D3DXVECTOR3(-tangent, 0.0f, 0.0f), D3DXVECTOR2( 0.0f, 0.0f ) },
|
||||
{ D3DXVECTOR3( -argWidth, argHeight, argDepth ), D3DXVECTOR3(0.0f, 0.0f, normal), D3DXVECTOR3(-tangent, 0.0f, 0.0f), D3DXVECTOR2( 1.0f, 0.0f ) },
|
||||
};
|
||||
|
||||
std::vector<VertexElement> vertexElements;
|
||||
vertexElements.push_back(VertexElement(VertexElement::Position));
|
||||
vertexElements.push_back(VertexElement(VertexElement::Normal));
|
||||
vertexElements.push_back(VertexElement(VertexElement::Tangent));
|
||||
vertexElements.push_back(VertexElement(VertexElement::Texture2D));
|
||||
|
||||
IGeometryBuffer* cubeBuffer = &m_Engine.get_ResourceFactory().CreateOrFindGeometryBuffer(argName);
|
||||
cubeBuffer->SetVertexData(sizeof(vertices) / sizeof(CommonCubeVertex), sizeof(CommonCubeVertex), vertices, vertexElements, false);
|
||||
|
||||
uint32 invertedIndices[] = { 0,1,3, 3,1,2, 5,4,6, 6,4,7, 8,9,11, 11,9,10, 13,12,14, 14,12,15, 16,17,19, 19,17,18, 21,20,22, 22,20,23 };
|
||||
uint32 normalIndices[] = { 3,1,0, 2,1,3, 6,4,5, 7,4,6, 11,9,8, 10,9,11, 14,12,13, 15,12,14, 19,17,16, 18,17,19, 22,20,21, 23,20,22 };
|
||||
if (argInverted)
|
||||
cubeBuffer->SetIndexData(sizeof(invertedIndices) / sizeof(uint32), invertedIndices, false);
|
||||
else
|
||||
cubeBuffer->SetIndexData(sizeof(normalIndices) / sizeof(uint32), normalIndices, false);
|
||||
|
||||
return cubeBuffer;
|
||||
}
|
||||
|
||||
|
||||
IGeometryBuffer* CommonObjectFactory::CreateQuad(float argWidth, float argHeight, bool argTwoSided, const string8& argName)
|
||||
{
|
||||
argWidth *= 0.5f;
|
||||
argHeight *= 0.5f;
|
||||
|
||||
CommonQuadVertex quadOneSidedVertices[] =
|
||||
{
|
||||
{ D3DXVECTOR3( -argWidth, argHeight, 0.0f ), D3DXVECTOR3(0.0f, 0.0f, -1.0f), D3DXVECTOR2( 0.0f, 0.0f ) },
|
||||
{ D3DXVECTOR3( argWidth, -argHeight, 0.0f ), D3DXVECTOR3(0.0f, 0.0f, -1.0f), D3DXVECTOR2( 1.0f, 1.0f ) },
|
||||
{ D3DXVECTOR3( -argWidth, -argHeight, 0.0f ), D3DXVECTOR3(0.0f, 0.0f, -1.0f), D3DXVECTOR2( 0.0f, 1.0f ) },
|
||||
|
||||
{ D3DXVECTOR3( -argWidth, argHeight, 0.0f ), D3DXVECTOR3(0.0f, 0.0f, -1.0f), D3DXVECTOR2( 0.0f, 0.0f ) },
|
||||
{ D3DXVECTOR3( argWidth, argHeight, 0.0f ), D3DXVECTOR3(0.0f, 0.0f, -1.0f), D3DXVECTOR2( 1.0f, 0.0f ) },
|
||||
{ D3DXVECTOR3( argWidth, -argHeight, 0.0f ), D3DXVECTOR3(0.0f, 0.0f, -1.0f), D3DXVECTOR2( 1.0f, 1.0f ) },
|
||||
};
|
||||
|
||||
CommonQuadVertex quadTwoSidedVertices[] =
|
||||
{
|
||||
{ D3DXVECTOR3( -argWidth, argHeight, 0.0f ), D3DXVECTOR3(0.0f, 0.0f, -1.0f), D3DXVECTOR2( 0.0f, 0.0f ) },
|
||||
{ D3DXVECTOR3( argWidth, -argHeight, 0.0f ), D3DXVECTOR3(0.0f, 0.0f, -1.0f), D3DXVECTOR2( 1.0f, 1.0f ) },
|
||||
{ D3DXVECTOR3( -argWidth, -argHeight, 0.0f ), D3DXVECTOR3(0.0f, 0.0f, -1.0f), D3DXVECTOR2( 0.0f, 1.0f ) },
|
||||
{ D3DXVECTOR3( -argWidth, argHeight, 0.0f ), D3DXVECTOR3(0.0f, 0.0f, -1.0f), D3DXVECTOR2( 0.0f, 0.0f ) },
|
||||
{ D3DXVECTOR3( argWidth, argHeight, 0.0f ), D3DXVECTOR3(0.0f, 0.0f, -1.0f), D3DXVECTOR2( 1.0f, 0.0f ) },
|
||||
{ D3DXVECTOR3( argWidth, -argHeight, 0.0f ), D3DXVECTOR3(0.0f, 0.0f, -1.0f), D3DXVECTOR2( 1.0f, 1.0f ) },
|
||||
|
||||
{ D3DXVECTOR3( -argWidth, argHeight, 0.0f ), D3DXVECTOR3(0.0f, 0.0f, 1.0f), D3DXVECTOR2( 1.0f, 0.0f ) },
|
||||
{ D3DXVECTOR3( argWidth, -argHeight, 0.0f ), D3DXVECTOR3(0.0f, 0.0f, 1.0f), D3DXVECTOR2( 0.0f, 1.0f ) },
|
||||
{ D3DXVECTOR3( -argWidth, -argHeight, 0.0f ), D3DXVECTOR3(0.0f, 0.0f, 1.0f), D3DXVECTOR2( 1.0f, 1.0f ) },
|
||||
{ D3DXVECTOR3( -argWidth, argHeight, 0.0f ), D3DXVECTOR3(0.0f, 0.0f, 1.0f), D3DXVECTOR2( 1.0f, 0.0f ) },
|
||||
{ D3DXVECTOR3( argWidth, argHeight, 0.0f ), D3DXVECTOR3(0.0f, 0.0f, 1.0f), D3DXVECTOR2( 0.0f, 0.0f ) },
|
||||
{ D3DXVECTOR3( argWidth, -argHeight, 0.0f ), D3DXVECTOR3(0.0f, 0.0f, 1.0f), D3DXVECTOR2( 0.0f, 1.0f ) },
|
||||
};
|
||||
|
||||
std::vector<VertexElement> vertexElements;
|
||||
vertexElements.push_back(VertexElement(VertexElement::Position));
|
||||
vertexElements.push_back(VertexElement(VertexElement::Normal));
|
||||
vertexElements.push_back(VertexElement(VertexElement::Texture2D));
|
||||
|
||||
uint32 oneSidedIndices[] = { 0,1,2, 3,4,5 };
|
||||
uint32 twoSidedIndices[] = { 0,1,2,3,4,5, 11,10,9,8,7,6 };
|
||||
|
||||
IGeometryBuffer* quadBuffer = &m_Engine.get_ResourceFactory().CreateOrFindGeometryBuffer(argName);
|
||||
if (!argTwoSided)
|
||||
{
|
||||
quadBuffer->SetVertexData(sizeof(quadOneSidedVertices) / sizeof(CommonQuadVertex), sizeof(CommonQuadVertex), quadOneSidedVertices, vertexElements, false);
|
||||
quadBuffer->SetIndexData(sizeof(oneSidedIndices) / sizeof(uint32), oneSidedIndices, false);
|
||||
}
|
||||
else
|
||||
{
|
||||
quadBuffer->SetVertexData(sizeof(quadTwoSidedVertices) / sizeof(CommonQuadVertex), sizeof(CommonQuadVertex), quadTwoSidedVertices, vertexElements, false);
|
||||
quadBuffer->SetIndexData(sizeof(twoSidedIndices) / sizeof(uint32), twoSidedIndices, false);
|
||||
}
|
||||
|
||||
return quadBuffer;
|
||||
}
|
||||
21
aiwaz/Aiwaz/CommonObjectFactory/CommonObjectFactory.h
Normal file
21
aiwaz/Aiwaz/CommonObjectFactory/CommonObjectFactory.h
Normal file
@@ -0,0 +1,21 @@
|
||||
#pragma once
|
||||
|
||||
#include "IEngine.h"
|
||||
#include "IGeometryBuffer.h"
|
||||
#include "ICommonObjectFactory.h"
|
||||
|
||||
|
||||
class CommonObjectFactory
|
||||
: public ICommonObjectFactory
|
||||
{
|
||||
public:
|
||||
CommonObjectFactory(IEngine& argEngine);
|
||||
virtual ~CommonObjectFactory();
|
||||
|
||||
virtual IPingPongBuffer* CreatePingPongBuffer(ITexture& argInputTexture, const PingPongBufferDescription& argDescriptor);
|
||||
virtual IGeometryBuffer* CreateCube(float argWidth, float argHeight, float argDepth, bool argInverted, const string8& argName = "");
|
||||
virtual IGeometryBuffer* CreateQuad(float argWidth, float argHeight, bool argTwoSided, const string8& argName = "");
|
||||
|
||||
private:
|
||||
IEngine& m_Engine;
|
||||
};
|
||||
@@ -0,0 +1,179 @@
|
||||
#include "stdafx.h"
|
||||
|
||||
#include "ICommonObjectFactory.h"
|
||||
#include "PingPongBuffer.h"
|
||||
#include "../Resources/ShaderParameterCollection/Types/Texture.h"
|
||||
|
||||
|
||||
PingPongBuffer::PingPongBuffer(IEngine& argEngine)
|
||||
: m_Engine(argEngine)
|
||||
, m_RenderTargetNodeA(NULL)
|
||||
, m_RenderTargetNodeB(NULL)
|
||||
, m_ShaderA(NULL)
|
||||
, m_ShaderB(NULL)
|
||||
, m_ShaderPreProcess(NULL)
|
||||
, m_TextureA(NULL)
|
||||
, m_TextureB(NULL)
|
||||
, m_ScreenQuad(NULL)
|
||||
, m_ShaderParameterA(NULL)
|
||||
, m_ShaderParameterB(NULL)
|
||||
, m_ShaderParameterPreProcess(NULL)
|
||||
, m_InputTexture(NULL)
|
||||
{
|
||||
m_RootNode = &m_Engine.get_ResourceFactory().CreateRenderCommandNode();
|
||||
m_PreProcessNode = &m_Engine.get_ResourceFactory().CreateRenderCommandNode();
|
||||
}
|
||||
|
||||
|
||||
PingPongBuffer::~PingPongBuffer()
|
||||
{
|
||||
IResourceFactory& resourceFac = m_Engine.get_ResourceFactory();
|
||||
|
||||
resourceFac.DeleteTexture(*m_InputTexture);
|
||||
|
||||
resourceFac.DeleteShader(*m_ShaderA);
|
||||
resourceFac.DeleteShader(*m_ShaderB);
|
||||
resourceFac.DeleteShader(*m_ShaderPreProcess);
|
||||
resourceFac.DeleteRenderTargetTexture(*m_TextureA);
|
||||
resourceFac.DeleteRenderTargetTexture(*m_TextureB);
|
||||
resourceFac.DeleteGeometryBuffer(*m_ScreenQuad);
|
||||
resourceFac.DeleteShaderParameterCollection(*m_ShaderParameterA);
|
||||
resourceFac.DeleteShaderParameterCollection(*m_ShaderParameterB);
|
||||
resourceFac.DeleteShaderParameterCollection(*m_ShaderParameterPreProcess);
|
||||
|
||||
resourceFac.DeleteRenderCommandNode(*m_RootNode);
|
||||
resourceFac.DeleteRenderCommandNode(*m_PreProcessNode);
|
||||
resourceFac.DeleteRenderCommandNode(*m_RenderTargetNodeA);
|
||||
resourceFac.DeleteRenderCommandNode(*m_RenderTargetNodeB);
|
||||
}
|
||||
|
||||
ITexture& PingPongBuffer::get_InputTexture() const
|
||||
{
|
||||
return *m_InputTexture;
|
||||
}
|
||||
|
||||
|
||||
void PingPongBuffer::set_InputTexture(ITexture& argTexture)
|
||||
{
|
||||
m_InputTexture = &argTexture;
|
||||
this->Rebuild(m_Descriptor);
|
||||
}
|
||||
|
||||
|
||||
ITexture& PingPongBuffer::get_OutputTexture() const
|
||||
{
|
||||
return m_TextureB->get_TextureResource();
|
||||
}
|
||||
|
||||
|
||||
const PingPongBufferDescription& PingPongBuffer::get_Descriptor() const
|
||||
{
|
||||
return m_Descriptor;
|
||||
}
|
||||
|
||||
|
||||
void PingPongBuffer::set_Descriptor(const PingPongBufferDescription& argValue)
|
||||
{
|
||||
this->Rebuild(argValue);
|
||||
}
|
||||
|
||||
|
||||
IRenderCommandNode& PingPongBuffer::get_RootNode() const
|
||||
{
|
||||
return *m_RootNode;
|
||||
}
|
||||
|
||||
|
||||
IRenderCommandNode& PingPongBuffer::get_PreProcessNode() const
|
||||
{
|
||||
return *m_PreProcessNode;
|
||||
}
|
||||
|
||||
|
||||
void PingPongBuffer::Rebuild(const PingPongBufferDescription& argValue)
|
||||
{
|
||||
// Shader A
|
||||
if (argValue.ShaderFileName.empty())
|
||||
return;
|
||||
|
||||
if (m_ShaderA == NULL || argValue.ShaderFileName != m_Descriptor.ShaderFileName)
|
||||
{
|
||||
m_ShaderA = &m_Engine.get_ResourceFactory().CreateOrFindShader();
|
||||
m_ShaderA->LoadFromFile(argValue.ShaderFileName);
|
||||
}
|
||||
if (argValue.ShaderTechniqueA != m_Descriptor.ShaderTechniqueA)
|
||||
m_ShaderA->set_TechniqueName(argValue.ShaderTechniqueA);
|
||||
|
||||
// ShaderB
|
||||
if (m_ShaderB == NULL || argValue.ShaderFileName != m_Descriptor.ShaderFileName)
|
||||
{
|
||||
m_ShaderB = &m_Engine.get_ResourceFactory().CreateOrFindShader();
|
||||
m_ShaderB->LoadFromFile(argValue.ShaderFileName);
|
||||
}
|
||||
if (argValue.ShaderTechniqueB != m_Descriptor.ShaderTechniqueB)
|
||||
m_ShaderB->set_TechniqueName(argValue.ShaderTechniqueB);
|
||||
|
||||
// PreProcessShader (downscale, input to buffer)
|
||||
if (m_ShaderPreProcess == NULL || argValue.ShaderFileName != m_Descriptor.ShaderFileName)
|
||||
{
|
||||
m_ShaderPreProcess = &m_Engine.get_ResourceFactory().CreateOrFindShader();
|
||||
m_ShaderPreProcess->LoadFromFile(argValue.ShaderFileName);
|
||||
}
|
||||
if (argValue.PreProcessShaderTechnique != m_Descriptor.PreProcessShaderTechnique)
|
||||
m_ShaderPreProcess->set_TechniqueName(argValue.PreProcessShaderTechnique);
|
||||
|
||||
if (m_TextureA == NULL || m_TextureB == NULL || argValue.TextureWidth != m_Descriptor.TextureWidth || argValue.TextureHeight != m_Descriptor.TextureHeight || argValue.TextureFormat != m_Descriptor.TextureFormat)
|
||||
{
|
||||
if (m_TextureA == NULL)
|
||||
m_TextureA = &m_Engine.get_ResourceFactory().CreateOrFindRenderTargetTexture();
|
||||
if (m_TextureB == NULL)
|
||||
m_TextureB = &m_Engine.get_ResourceFactory().CreateOrFindRenderTargetTexture();
|
||||
m_TextureA->SetTextureParameters(argValue.TextureWidth, argValue.TextureHeight, argValue.TextureFormat);
|
||||
m_TextureB->SetTextureParameters(argValue.TextureWidth, argValue.TextureHeight, argValue.TextureFormat);
|
||||
}
|
||||
|
||||
m_ShaderParameterA = &m_Engine.get_ResourceFactory().CreateOrFindShaderParameterCollection();
|
||||
m_ShaderParameterA->SetParameter("InputTexture", m_TextureB->get_TextureResource());
|
||||
|
||||
m_ShaderParameterB = &m_Engine.get_ResourceFactory().CreateOrFindShaderParameterCollection();
|
||||
m_ShaderParameterB->SetParameter("InputTexture", m_TextureA->get_TextureResource());
|
||||
|
||||
m_ShaderParameterPreProcess = &m_Engine.get_ResourceFactory().CreateOrFindShaderParameterCollection();
|
||||
m_ShaderParameterPreProcess->SetParameter("InputTexture", new TextureShaderParameter(*m_InputTexture, ParameterBindType::BindBySemantic));
|
||||
|
||||
if (m_ScreenQuad == NULL)
|
||||
m_ScreenQuad = m_Engine.get_CommonObjectFactory().CreateQuad(2.0f, 2.0f, false);
|
||||
|
||||
m_RenderTargetNodeA = &m_Engine.get_ResourceFactory().CreateRenderCommandNode();
|
||||
AddToNode(*m_RenderTargetNodeA, m_TextureA);
|
||||
AddToNode(*m_RenderTargetNodeA ,m_ShaderA);
|
||||
AddToNode(*m_RenderTargetNodeA, m_ShaderParameterA);
|
||||
AddToNode(*m_RenderTargetNodeA, m_ScreenQuad);
|
||||
|
||||
m_RenderTargetNodeB = &m_Engine.get_ResourceFactory().CreateRenderCommandNode();
|
||||
AddToNode(*m_RenderTargetNodeB, m_TextureB);
|
||||
AddToNode(*m_RenderTargetNodeB, m_ShaderB);
|
||||
AddToNode(*m_RenderTargetNodeB, m_ShaderParameterB);
|
||||
AddToNode(*m_RenderTargetNodeB, m_ScreenQuad);
|
||||
|
||||
|
||||
const std::vector<ICommandUser*>& lk_CommandUsers = m_RootNode->get_CommandUsers();
|
||||
while (!lk_CommandUsers.empty())
|
||||
m_RootNode->RemoveCommandUser(*lk_CommandUsers[0]);
|
||||
|
||||
// preprocessing
|
||||
AddToNode(*m_RootNode, m_TextureB);
|
||||
AddToNode(*m_RootNode, m_ShaderPreProcess);
|
||||
AddToNode(*m_RootNode, m_ShaderParameterPreProcess);
|
||||
AddToNode(*m_RootNode, m_ScreenQuad);
|
||||
AddToNode(*m_RootNode, m_PreProcessNode);
|
||||
|
||||
// real pingpongs
|
||||
for (uint32 i = 0; i < argValue.LoopCount; ++i)
|
||||
{
|
||||
AddToNode(*m_RootNode, m_RenderTargetNodeA);
|
||||
AddToNode(*m_RootNode, m_RenderTargetNodeB);
|
||||
}
|
||||
|
||||
m_Descriptor = argValue;
|
||||
}
|
||||
@@ -0,0 +1,51 @@
|
||||
#pragma once
|
||||
|
||||
#include "IEngine.h"
|
||||
#include "IShader.h"
|
||||
#include "ITexture.h"
|
||||
#include "IRenderCommandNode.h"
|
||||
#include "IResourceFactory.h"
|
||||
#include "IPingPongBuffer.h"
|
||||
|
||||
|
||||
class PingPongBuffer
|
||||
: public IPingPongBuffer
|
||||
{
|
||||
public:
|
||||
PingPongBuffer(IEngine& argEngine);
|
||||
virtual ~PingPongBuffer();
|
||||
|
||||
virtual ITexture& get_InputTexture() const;
|
||||
virtual void set_InputTexture(ITexture& argTexture);
|
||||
|
||||
virtual ITexture& get_OutputTexture() const;
|
||||
|
||||
virtual const PingPongBufferDescription& get_Descriptor() const;
|
||||
virtual void set_Descriptor(const PingPongBufferDescription& argValue);
|
||||
virtual IRenderCommandNode& get_RootNode() const;
|
||||
virtual IRenderCommandNode& get_PreProcessNode() const;
|
||||
|
||||
protected:
|
||||
void Rebuild(const PingPongBufferDescription& argValue);
|
||||
|
||||
private:
|
||||
IEngine& m_Engine;
|
||||
|
||||
PingPongBufferDescription m_Descriptor;
|
||||
|
||||
ITexture* m_InputTexture;
|
||||
|
||||
IRenderCommandNode* m_RootNode;
|
||||
IRenderCommandNode* m_PreProcessNode;
|
||||
IRenderCommandNode* m_RenderTargetNodeA;
|
||||
IRenderCommandNode* m_RenderTargetNodeB;
|
||||
IShader* m_ShaderA;
|
||||
IShader* m_ShaderB;
|
||||
IShader* m_ShaderPreProcess;
|
||||
IRenderTargetTexture* m_TextureA;
|
||||
IRenderTargetTexture* m_TextureB;
|
||||
IGeometryBuffer* m_ScreenQuad;
|
||||
IShaderParameterCollection* m_ShaderParameterA;
|
||||
IShaderParameterCollection* m_ShaderParameterB;
|
||||
IShaderParameterCollection* m_ShaderParameterPreProcess;
|
||||
};
|
||||
141
aiwaz/Aiwaz/DeviceEnumerator/DeviceEnumerator.cpp
Normal file
141
aiwaz/Aiwaz/DeviceEnumerator/DeviceEnumerator.cpp
Normal file
@@ -0,0 +1,141 @@
|
||||
#include "stdafx.h"
|
||||
#include "DeviceEnumerator.h"
|
||||
#include "DisplayAdapter.h"
|
||||
|
||||
|
||||
DeviceEnumerator::DeviceEnumerator(ID3D10Device* ar_Device_)
|
||||
: m_DXGIFactory(NULL)
|
||||
, m_Device(ar_Device_)
|
||||
, m_HasEnumerated(false)
|
||||
, m_DesiredWidth(0)
|
||||
, m_DesiredHeight(0)
|
||||
, m_DesiredRefreshRate(0)
|
||||
, m_DesiredFormat(DataFormat::Unknown)
|
||||
{
|
||||
HRESULT result = ::CreateDXGIFactory (__uuidof(IDXGIFactory), (void**)&m_DXGIFactory);
|
||||
if (result != S_OK)
|
||||
return;
|
||||
}
|
||||
|
||||
|
||||
DeviceEnumerator::~DeviceEnumerator()
|
||||
{
|
||||
for (uint32 i = 0; i < m_EnumeratedAdapters.size(); ++i)
|
||||
delete m_EnumeratedAdapters[i];
|
||||
|
||||
if (m_DXGIFactory != NULL)
|
||||
m_DXGIFactory->Release();
|
||||
m_DXGIFactory = NULL;
|
||||
}
|
||||
|
||||
|
||||
bool DeviceEnumerator::TryEnumerate(uint32 argDesiredWidth, uint32 argDesiredHeight, uint32 argDesiredRefreshRate, DataFormat::Enumeration argDesiredFormat)
|
||||
{
|
||||
if (m_HasEnumerated)
|
||||
{
|
||||
if (m_DesiredWidth == argDesiredWidth ||
|
||||
m_DesiredHeight == argDesiredHeight ||
|
||||
m_DesiredRefreshRate == argDesiredRefreshRate ||
|
||||
m_DesiredFormat == argDesiredFormat)
|
||||
{
|
||||
return true;
|
||||
}
|
||||
else
|
||||
m_HasEnumerated = false;
|
||||
}
|
||||
if (m_DXGIFactory == NULL)
|
||||
return false;
|
||||
|
||||
int adapterIndex = 0;
|
||||
IDXGIAdapter* adapter = NULL;
|
||||
while (m_DXGIFactory->EnumAdapters(adapterIndex, &adapter) == S_OK)
|
||||
{
|
||||
LARGE_INTEGER version;
|
||||
if (adapter->CheckInterfaceSupport (__uuidof (ID3D10Device), &version) == S_OK)
|
||||
{
|
||||
IDisplayAdapter* deviceAdapter = new DisplayAdapter(adapter, m_Device);
|
||||
if (deviceAdapter->TryEnumerate(argDesiredWidth, argDesiredHeight, argDesiredRefreshRate, argDesiredFormat))
|
||||
m_EnumeratedAdapters.push_back(deviceAdapter);
|
||||
else
|
||||
delete deviceAdapter;
|
||||
}
|
||||
|
||||
adapter->Release();
|
||||
adapterIndex++;
|
||||
}
|
||||
|
||||
m_DesiredWidth = argDesiredWidth;
|
||||
m_DesiredHeight = argDesiredHeight;
|
||||
m_DesiredRefreshRate = argDesiredRefreshRate;
|
||||
m_DesiredFormat = argDesiredFormat;
|
||||
|
||||
m_HasEnumerated = !m_EnumeratedAdapters.empty();
|
||||
return m_HasEnumerated;
|
||||
}
|
||||
|
||||
|
||||
IDisplayAdapter* DeviceEnumerator::FindBestAdapter(bool argAllowToEnumerate, uint32 argDesiredWidth, uint32 argDesiredHeight, uint32 argDesiredRefreshRate, DataFormat::Enumeration argDesiredFormat)
|
||||
{
|
||||
if (argAllowToEnumerate && !this->TryEnumerate(argDesiredWidth, argDesiredHeight, argDesiredRefreshRate, argDesiredFormat))
|
||||
return NULL;
|
||||
|
||||
if (!m_HasEnumerated)
|
||||
return NULL;
|
||||
|
||||
return m_EnumeratedAdapters.front();
|
||||
}
|
||||
|
||||
|
||||
IOutputDevice* DeviceEnumerator::FindBestOutput(bool argAllowToEnumerate, uint32 argDesiredWidth, uint32 argDesiredHeight, uint32 argDesiredRefreshRate, DataFormat::Enumeration argDesiredFormat)
|
||||
{
|
||||
if (argAllowToEnumerate && !this->TryEnumerate(argDesiredWidth, argDesiredHeight, argDesiredRefreshRate, argDesiredFormat))
|
||||
return NULL;
|
||||
|
||||
if (!m_HasEnumerated)
|
||||
return NULL;
|
||||
|
||||
return m_EnumeratedAdapters.front()->FindBestOutput(argAllowToEnumerate, argDesiredWidth, argDesiredHeight, argDesiredRefreshRate, argDesiredFormat);
|
||||
}
|
||||
|
||||
|
||||
IDisplayMode* DeviceEnumerator::FindBestDisplayMode(bool argAllowToEnumerate, uint32 argDesiredWidth, uint32 argDesiredHeight, uint32 argDesiredRefreshRate, DataFormat::Enumeration argDesiredFormat)
|
||||
{
|
||||
if (argAllowToEnumerate && !this->TryEnumerate(argDesiredWidth, argDesiredHeight, argDesiredRefreshRate, argDesiredFormat))
|
||||
return NULL;
|
||||
|
||||
if (!m_HasEnumerated)
|
||||
return NULL;
|
||||
|
||||
return m_EnumeratedAdapters.front()->FindBestDisplayMode(argAllowToEnumerate, argDesiredWidth, argDesiredHeight, argDesiredRefreshRate, argDesiredFormat);
|
||||
}
|
||||
|
||||
|
||||
void DeviceEnumerator::Verbose()
|
||||
{
|
||||
if (!this->get_HasEnumerated())
|
||||
{
|
||||
std::wcout << std::red << L"Enumeration was not executed or no results available." << std::white << std::endl;
|
||||
return;
|
||||
}
|
||||
|
||||
IDisplayAdapter* displayAdapter = this->FindBestAdapter();
|
||||
std::wcout << L"Adapter: " << displayAdapter->get_Name() << std::endl;
|
||||
std::wcout << L"Dedicated System Memory: " << displayAdapter->get_DedicatedSystemMemory()/1024/1024 << L"MB" << std::endl;
|
||||
std::wcout << L"Dedicated Video Memory: " << displayAdapter->get_DedicatedVideoMemory()/1024/1024 << L"MB" << std::endl;
|
||||
std::wcout << L"Shared System Memory: " << displayAdapter->get_SharedSystemMemory()/1024/1024 << L"MB" << std::endl << std::endl;
|
||||
|
||||
for (uint32 i = 0; i < displayAdapter->get_DeviceOutputs().size(); ++i)
|
||||
{
|
||||
IOutputDevice* outputDevice = displayAdapter->get_DeviceOutputs()[i];
|
||||
if (i == 0)
|
||||
std::wcout << L"Primary Output: ";
|
||||
else
|
||||
std::wcout << L"Output: ";
|
||||
|
||||
std::wcout << outputDevice->get_Name() << std::endl;
|
||||
|
||||
IDisplayMode* displayMode = outputDevice->FindBestDisplayMode();
|
||||
int bpp = DataFormat::GetDataFormatByteSize(displayMode->get_Format()) * 8;
|
||||
std::wcout << L"Display: " << displayMode->get_Width() << L"x" << displayMode->get_Height() << L"x" << bpp << L" @" << displayMode->get_RefreshRate() << L"Hz" << std::endl << std::endl;
|
||||
}
|
||||
}
|
||||
33
aiwaz/Aiwaz/DeviceEnumerator/DeviceEnumerator.h
Normal file
33
aiwaz/Aiwaz/DeviceEnumerator/DeviceEnumerator.h
Normal file
@@ -0,0 +1,33 @@
|
||||
#pragma once
|
||||
|
||||
#include "IDeviceEnumerator.h"
|
||||
|
||||
|
||||
class DeviceEnumerator
|
||||
: public IDeviceEnumerator
|
||||
{
|
||||
public:
|
||||
DeviceEnumerator(ID3D10Device* ar_Device_ = NULL);
|
||||
virtual ~DeviceEnumerator();
|
||||
|
||||
virtual bool get_HasEnumerated() const { return m_HasEnumerated; }
|
||||
virtual const std::vector<IDisplayAdapter*>& get_DeviceAdapters() const { return m_EnumeratedAdapters; }
|
||||
|
||||
virtual bool TryEnumerate(uint32 argDesiredWidth = 0, uint32 argDesiredHeight = 0, uint32 argDesiredRefreshRate = 0, DataFormat::Enumeration argDesiredFormat = DataFormat::Unknown);
|
||||
virtual IDisplayAdapter* FindBestAdapter(bool argAllowToEnumerate = false, uint32 argDesiredWidth = 0, uint32 argDesiredHeight = 0, uint32 argDesiredRefreshRate = 0, DataFormat::Enumeration argDesiredFormat = DataFormat::Unknown);
|
||||
virtual IOutputDevice* FindBestOutput(bool argAllowToEnumerate = false, uint32 argDesiredWidth = 0, uint32 argDesiredHeight = 0, uint32 argDesiredRefreshRate = 0, DataFormat::Enumeration argDesiredFormat = DataFormat::Unknown);
|
||||
virtual IDisplayMode* FindBestDisplayMode(bool argAllowToEnumerate = false, uint32 argDesiredWidth = 0, uint32 argDesiredHeight = 0, uint32 argDesiredRefreshRate = 0, DataFormat::Enumeration argDesiredFormat = DataFormat::Unknown);
|
||||
|
||||
virtual void Verbose();
|
||||
|
||||
private:
|
||||
IDXGIFactory* m_DXGIFactory;
|
||||
ID3D10Device* m_Device;
|
||||
bool m_HasEnumerated;
|
||||
|
||||
std::vector<IDisplayAdapter*> m_EnumeratedAdapters;
|
||||
uint32 m_DesiredWidth;
|
||||
uint32 m_DesiredHeight;
|
||||
uint32 m_DesiredRefreshRate;
|
||||
DataFormat::Enumeration m_DesiredFormat;
|
||||
};
|
||||
@@ -0,0 +1,49 @@
|
||||
#include "stdafx.h"
|
||||
#include "DeviceVisitorBase.h"
|
||||
#include "IDeviceEnumerator.h"
|
||||
|
||||
|
||||
DeviceVisitorBase::DeviceVisitorBase()
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
|
||||
DeviceVisitorBase::~DeviceVisitorBase()
|
||||
{
|
||||
}
|
||||
|
||||
|
||||
void DeviceVisitorBase::Visit(IDeviceEnumerator& argEnumerator)
|
||||
{
|
||||
this->VisitEnumerator(argEnumerator);
|
||||
}
|
||||
|
||||
|
||||
void DeviceVisitorBase::VisitEnumerator(IDeviceEnumerator& argEnumerator)
|
||||
{
|
||||
const std::vector<IDisplayAdapter*>& adapters = argEnumerator.get_DeviceAdapters();
|
||||
for (uint32 i = 0; i < adapters.size(); ++i)
|
||||
this->VisitAdapter(*adapters[i]);
|
||||
}
|
||||
|
||||
|
||||
void DeviceVisitorBase::VisitAdapter(IDisplayAdapter& argAdapter)
|
||||
{
|
||||
const std::vector<IOutputDevice*>& outputs = argAdapter.get_DeviceOutputs();
|
||||
for (uint32 i = 0; i < outputs.size(); ++i)
|
||||
this->VisitOutput(*outputs[i]);
|
||||
}
|
||||
|
||||
|
||||
void DeviceVisitorBase::VisitOutput(IOutputDevice& argOutput)
|
||||
{
|
||||
const std::vector<IDisplayMode*>& displayModes = argOutput.get_DisplayModes();
|
||||
for (uint32 i = 0; i < displayModes.size(); ++i)
|
||||
this->VisitDisplayMode(*displayModes[i]);
|
||||
}
|
||||
|
||||
|
||||
void DeviceVisitorBase::VisitDisplayMode(IDisplayMode& argMode)
|
||||
{
|
||||
}
|
||||
@@ -0,0 +1,18 @@
|
||||
#pragma once
|
||||
|
||||
#include "IDeviceEnumerator.h"
|
||||
|
||||
class DeviceVisitorBase
|
||||
{
|
||||
public:
|
||||
DeviceVisitorBase();
|
||||
virtual ~DeviceVisitorBase();
|
||||
|
||||
virtual void Visit(IDeviceEnumerator& argEnumerator);
|
||||
|
||||
protected:
|
||||
virtual void VisitEnumerator(IDeviceEnumerator& argEnumerator);
|
||||
virtual void VisitAdapter(IDisplayAdapter& argAdapter);
|
||||
virtual void VisitOutput(IOutputDevice& argOutput);
|
||||
virtual void VisitDisplayMode(IDisplayMode& argMode);
|
||||
};
|
||||
@@ -0,0 +1,99 @@
|
||||
#include "stdafx.h"
|
||||
#include "XmlDeviceVisitor.h"
|
||||
#include "IDeviceEnumerator.h"
|
||||
|
||||
|
||||
XmlDeviceVisitor::XmlDeviceVisitor(const string16& argOutputFile)
|
||||
: DeviceVisitorBase()
|
||||
, m_OutputFile(argOutputFile)
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
|
||||
XmlDeviceVisitor::~XmlDeviceVisitor()
|
||||
{
|
||||
}
|
||||
|
||||
|
||||
void XmlDeviceVisitor::Visit(IDeviceEnumerator& argEnumerator)
|
||||
{
|
||||
m_FileStream.open(m_OutputFile.c_str());
|
||||
|
||||
DeviceVisitorBase::Visit(argEnumerator);
|
||||
|
||||
m_FileStream.close();
|
||||
}
|
||||
|
||||
|
||||
void XmlDeviceVisitor::VisitEnumerator(IDeviceEnumerator& argEnumerator)
|
||||
{
|
||||
m_FileStream << L"<?xml version=\"1.0\" encoding=\"utf-8\"?>" << std::endl;
|
||||
m_FileStream << L"<DeviceEnumeration>" << std::endl;
|
||||
|
||||
IDisplayAdapter* bestAdapter = argEnumerator.FindBestAdapter();
|
||||
if (bestAdapter != NULL)
|
||||
m_FileStream << L"\t<BestAdapter>" << bestAdapter->get_Name() << L"</BestAdapter>" << std::endl;
|
||||
|
||||
IOutputDevice* bestOutput = argEnumerator.FindBestOutput();
|
||||
if (bestOutput != NULL)
|
||||
m_FileStream << L"\t<BestOutput>" << bestOutput->get_Name() << L"</BestOutput>" << std::endl;
|
||||
|
||||
IDisplayMode* bestDisplayMode = argEnumerator.FindBestDisplayMode();
|
||||
if (bestDisplayMode != NULL)
|
||||
{
|
||||
m_FileStream << L"\t<BestDisplayMode>" << std::endl;
|
||||
m_FileStream << L"\t\t<Resolution>" << bestDisplayMode->get_Width() << L"," << bestDisplayMode->get_Height() << L"</Resolution>" << std::endl;
|
||||
m_FileStream << L"\t\t<RefreshRate>" << bestDisplayMode->get_RefreshRate() << L"</RefreshRate>" << std::endl;
|
||||
m_FileStream << L"\t\t<Format>" << std::to_string16(DataFormat::ToString(bestDisplayMode->get_Format())) << L"</Format>" << std::endl;
|
||||
m_FileStream << L"\t</BestDisplayMode>" << std::endl;
|
||||
}
|
||||
|
||||
DeviceVisitorBase::VisitEnumerator(argEnumerator);
|
||||
|
||||
m_FileStream << L"</DeviceEnumeration>" << std::endl;
|
||||
}
|
||||
|
||||
|
||||
void XmlDeviceVisitor::VisitAdapter(IDisplayAdapter& argAdapter)
|
||||
{
|
||||
m_FileStream << L"\t<Adapter Name=\"" << argAdapter.get_Name() << L"\">"<< std::endl;
|
||||
m_FileStream << L"\t\t<DedicatedSystemMemory>" << argAdapter.get_DedicatedSystemMemory() << L"</DedicatedSystemMemory>" << std::endl;
|
||||
m_FileStream << L"\t\t<DedicatedVideoMemory>" << argAdapter.get_DedicatedVideoMemory() << L"</DedicatedVideoMemory>" << std::endl;
|
||||
m_FileStream << L"\t\t<SharedSystemMemory>" << argAdapter.get_SharedSystemMemory() << L"</SharedSystemMemory>" << std::endl;
|
||||
|
||||
DeviceVisitorBase::VisitAdapter(argAdapter);
|
||||
|
||||
m_FileStream << L"\t</Adapter>"<< std::endl;
|
||||
}
|
||||
|
||||
|
||||
void XmlDeviceVisitor::VisitOutput(IOutputDevice& argOutput)
|
||||
{
|
||||
m_FileStream << L"\t\t<Output Name=\"" << argOutput.get_Name() << L"\">" << std::endl;
|
||||
m_FileStream << L"\t\t\t<AttachedToDesktop>" << argOutput.get_IsAttachedToDesktop() << L"</AttachedToDesktop>" << std::endl;
|
||||
m_FileStream << L"\t\t\t<DesktopCoordinates>" << argOutput.get_DesktopCoordinates().left << L"," << argOutput.get_DesktopCoordinates().top << L"," << argOutput.get_DesktopCoordinates().right << L"," << argOutput.get_DesktopCoordinates().bottom << L"</DesktopCoordinates>" << std::endl;
|
||||
|
||||
const std::vector<IDisplayMode*>& displayModes = argOutput.get_DisplayModes();
|
||||
if (!displayModes.empty())
|
||||
m_FileStream << L"\t\t\t<DisplayModes Count=\"" << displayModes.size() << L"\">" << std::endl;
|
||||
|
||||
DeviceVisitorBase::VisitOutput(argOutput);
|
||||
|
||||
if (!displayModes.empty())
|
||||
m_FileStream << L"\t\t\t</DisplayModes>" << std::endl;
|
||||
|
||||
m_FileStream << L"\t\t</Output>"<< std::endl;
|
||||
}
|
||||
|
||||
|
||||
void XmlDeviceVisitor::VisitDisplayMode(IDisplayMode& argMode)
|
||||
{
|
||||
m_FileStream << L"\t\t\t\t<Mode>" << std::endl;
|
||||
m_FileStream << L"\t\t\t\t\t<Resolution>" << argMode.get_Width() << L"," << argMode.get_Height() << L"</Resolution>" << std::endl;
|
||||
m_FileStream << L"\t\t\t\t\t<RefreshRate>" << argMode.get_RefreshRate() << L"</RefreshRate>" << std::endl;
|
||||
m_FileStream << L"\t\t\t\t\t<Format>" << std::to_string16(DataFormat::ToString(argMode.get_Format())) << L"</Format>" << std::endl;
|
||||
m_FileStream << L"\t\t\t\t</Mode>" << std::endl;
|
||||
|
||||
DeviceVisitorBase::VisitDisplayMode(argMode);
|
||||
}
|
||||
@@ -0,0 +1,24 @@
|
||||
#pragma once
|
||||
|
||||
#include <fstream>
|
||||
#include "DeviceVisitorBase.h"
|
||||
|
||||
class XmlDeviceVisitor
|
||||
: public DeviceVisitorBase
|
||||
{
|
||||
public:
|
||||
XmlDeviceVisitor(const string16& argOutputFile);
|
||||
virtual ~XmlDeviceVisitor();
|
||||
|
||||
virtual void Visit(IDeviceEnumerator& argEnumerator);
|
||||
|
||||
protected:
|
||||
virtual void VisitEnumerator(IDeviceEnumerator& argEnumerator);
|
||||
virtual void VisitAdapter(IDisplayAdapter& argAdapter);
|
||||
virtual void VisitOutput(IOutputDevice& argOutput);
|
||||
virtual void VisitDisplayMode(IDisplayMode& argMode);
|
||||
|
||||
private:
|
||||
std::wofstream m_FileStream;
|
||||
string16 m_OutputFile;
|
||||
};
|
||||
96
aiwaz/Aiwaz/DeviceEnumerator/DisplayAdapter.cpp
Normal file
96
aiwaz/Aiwaz/DeviceEnumerator/DisplayAdapter.cpp
Normal file
@@ -0,0 +1,96 @@
|
||||
#include "stdafx.h"
|
||||
#include "DisplayAdapter.h"
|
||||
#include "outputDevice.h"
|
||||
|
||||
|
||||
DisplayAdapter::DisplayAdapter(IDXGIAdapter* ar_Adapter_, ID3D10Device* ar_Device_)
|
||||
: m_Adapter(ar_Adapter_)
|
||||
, m_Device(ar_Device_)
|
||||
, m_HasEnumerated(false)
|
||||
, m_DesiredWidth(0)
|
||||
, m_DesiredHeight(0)
|
||||
, m_DesiredRefreshRate(0)
|
||||
, m_DesiredFormat(DataFormat::Unknown)
|
||||
{
|
||||
if (m_Adapter != NULL)
|
||||
{
|
||||
m_Adapter->AddRef();
|
||||
m_Adapter->GetDesc(&m_AdapterDesc);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
DisplayAdapter::~DisplayAdapter()
|
||||
{
|
||||
for (uint32 i = 0; i < m_EnumeratedOutputs.size(); ++i)
|
||||
delete m_EnumeratedOutputs[i];
|
||||
|
||||
if (m_Adapter != NULL)
|
||||
m_Adapter->Release();
|
||||
m_Adapter = NULL;
|
||||
}
|
||||
|
||||
|
||||
bool DisplayAdapter::TryEnumerate(uint32 argDesiredWidth, uint32 argDesiredHeight, uint32 argDesiredRefreshRate, DataFormat::Enumeration argDesiredFormat)
|
||||
{
|
||||
if (m_HasEnumerated)
|
||||
{
|
||||
if (m_DesiredWidth == argDesiredWidth ||
|
||||
m_DesiredHeight == argDesiredHeight ||
|
||||
m_DesiredRefreshRate == argDesiredRefreshRate ||
|
||||
m_DesiredFormat == argDesiredFormat)
|
||||
{
|
||||
return true;
|
||||
}
|
||||
else
|
||||
m_HasEnumerated = false;
|
||||
}
|
||||
if (m_Adapter == NULL)
|
||||
return false;
|
||||
|
||||
int outputIndex = 0;
|
||||
IDXGIOutput* output = NULL;
|
||||
while (m_Adapter->EnumOutputs(outputIndex, &output) == S_OK)
|
||||
{
|
||||
IOutputDevice* deviceOutput = new OutputDevice(output, m_Device);
|
||||
if (deviceOutput->TryEnumerate(argDesiredWidth, argDesiredHeight, argDesiredRefreshRate, argDesiredFormat))
|
||||
m_EnumeratedOutputs.push_back(deviceOutput);
|
||||
else
|
||||
delete deviceOutput;
|
||||
|
||||
output->Release();
|
||||
outputIndex++;
|
||||
}
|
||||
|
||||
m_DesiredWidth = argDesiredWidth;
|
||||
m_DesiredHeight = argDesiredHeight;
|
||||
m_DesiredRefreshRate = argDesiredRefreshRate;
|
||||
m_DesiredFormat = argDesiredFormat;
|
||||
|
||||
m_HasEnumerated = !m_EnumeratedOutputs.empty();
|
||||
return m_HasEnumerated;
|
||||
}
|
||||
|
||||
|
||||
IOutputDevice* DisplayAdapter::FindBestOutput(bool argAllowToEnumerate, uint32 argDesiredWidth, uint32 argDesiredHeight, uint32 argDesiredRefreshRate, DataFormat::Enumeration argDesiredFormat)
|
||||
{
|
||||
if (argAllowToEnumerate && !this->TryEnumerate(argDesiredWidth, argDesiredHeight, argDesiredRefreshRate, argDesiredFormat))
|
||||
return NULL;
|
||||
|
||||
if (!m_HasEnumerated)
|
||||
return NULL;
|
||||
|
||||
return m_EnumeratedOutputs.front();
|
||||
}
|
||||
|
||||
|
||||
IDisplayMode* DisplayAdapter::FindBestDisplayMode(bool argAllowToEnumerate, uint32 argDesiredWidth, uint32 argDesiredHeight, uint32 argDesiredRefreshRate, DataFormat::Enumeration argDesiredFormat)
|
||||
{
|
||||
if (argAllowToEnumerate && !this->TryEnumerate(argDesiredWidth, argDesiredHeight, argDesiredRefreshRate, argDesiredFormat))
|
||||
return NULL;
|
||||
|
||||
if (!m_HasEnumerated)
|
||||
return NULL;
|
||||
|
||||
return m_EnumeratedOutputs.front()->FindBestDisplayMode(argAllowToEnumerate, argDesiredWidth, argDesiredHeight, argDesiredRefreshRate, argDesiredFormat);
|
||||
}
|
||||
34
aiwaz/Aiwaz/DeviceEnumerator/DisplayAdapter.h
Normal file
34
aiwaz/Aiwaz/DeviceEnumerator/DisplayAdapter.h
Normal file
@@ -0,0 +1,34 @@
|
||||
#include "IDeviceEnumerator.h"
|
||||
|
||||
|
||||
class DisplayAdapter
|
||||
: public IDisplayAdapter
|
||||
{
|
||||
public:
|
||||
DisplayAdapter(IDXGIAdapter* ar_Adapter_, ID3D10Device* ar_Device_ = NULL);
|
||||
virtual ~DisplayAdapter();
|
||||
|
||||
virtual size_t get_DedicatedSystemMemory() const { return m_AdapterDesc.DedicatedSystemMemory; }
|
||||
virtual size_t get_DedicatedVideoMemory() const { return m_AdapterDesc.DedicatedVideoMemory; }
|
||||
virtual size_t get_SharedSystemMemory() const { return m_AdapterDesc.SharedSystemMemory; }
|
||||
virtual const std::vector<IOutputDevice*>& get_DeviceOutputs() const { return m_EnumeratedOutputs; }
|
||||
virtual bool get_HasEnumerated() const { return m_HasEnumerated; }
|
||||
virtual IDXGIAdapter* get_Adapter() const { return m_Adapter; }
|
||||
|
||||
virtual string16 get_Name() const { return m_AdapterDesc.Description; }
|
||||
virtual bool TryEnumerate(uint32 argDesiredWidth = 0, uint32 argDesiredHeight = 0, uint32 argDesiredRefreshRate = 0, DataFormat::Enumeration argDesiredFormat = DataFormat::Unknown);
|
||||
virtual IOutputDevice* FindBestOutput(bool argAllowToEnumerate = false, uint32 argDesiredWidth = 0, uint32 argDesiredHeight = 0, uint32 argDesiredRefreshRate = 0, DataFormat::Enumeration argDesiredFormat = DataFormat::Unknown);
|
||||
virtual IDisplayMode* FindBestDisplayMode(bool argAllowToEnumerate = false, uint32 argDesiredWidth = 0, uint32 argDesiredHeight = 0, uint32 argDesiredRefreshRate = 0, DataFormat::Enumeration argDesiredFormat = DataFormat::Unknown);
|
||||
|
||||
private:
|
||||
IDXGIAdapter* m_Adapter;
|
||||
ID3D10Device* m_Device;
|
||||
DXGI_ADAPTER_DESC m_AdapterDesc;
|
||||
bool m_HasEnumerated;
|
||||
|
||||
std::vector<IOutputDevice*> m_EnumeratedOutputs;
|
||||
uint32 m_DesiredWidth;
|
||||
uint32 m_DesiredHeight;
|
||||
uint32 m_DesiredRefreshRate;
|
||||
DataFormat::Enumeration m_DesiredFormat;
|
||||
};
|
||||
2
aiwaz/Aiwaz/DeviceEnumerator/DisplayMode.cpp
Normal file
2
aiwaz/Aiwaz/DeviceEnumerator/DisplayMode.cpp
Normal file
@@ -0,0 +1,2 @@
|
||||
#include "stdafx.h"
|
||||
#include "DisplayMode.h"
|
||||
21
aiwaz/Aiwaz/DeviceEnumerator/DisplayMode.h
Normal file
21
aiwaz/Aiwaz/DeviceEnumerator/DisplayMode.h
Normal file
@@ -0,0 +1,21 @@
|
||||
#include <DXGI.h>
|
||||
#include "IDeviceEnumerator.h"
|
||||
|
||||
|
||||
class DisplayMode
|
||||
: public IDisplayMode
|
||||
{
|
||||
public:
|
||||
DisplayMode(DXGI_MODE_DESC& argDescriptor)
|
||||
: m_Descriptor(argDescriptor)
|
||||
{}
|
||||
virtual ~DisplayMode() {}
|
||||
|
||||
virtual uint32 get_Width() const { return m_Descriptor.Width; }
|
||||
virtual uint32 get_Height() const { return m_Descriptor.Height; }
|
||||
virtual uint32 get_RefreshRate() const { return m_Descriptor.RefreshRate.Numerator == 0 ? 0 : static_cast<int>(m_Descriptor.RefreshRate.Numerator / m_Descriptor.RefreshRate.Denominator); }
|
||||
virtual DataFormat::Enumeration get_Format() const { return (DataFormat::Enumeration)m_Descriptor.Format; }
|
||||
|
||||
private:
|
||||
DXGI_MODE_DESC m_Descriptor;
|
||||
};
|
||||
110
aiwaz/Aiwaz/DeviceEnumerator/OutputDevice.cpp
Normal file
110
aiwaz/Aiwaz/DeviceEnumerator/OutputDevice.cpp
Normal file
@@ -0,0 +1,110 @@
|
||||
#include "stdafx.h"
|
||||
#include "OutputDevice.h"
|
||||
#include "DisplayMode.h"
|
||||
|
||||
|
||||
OutputDevice::OutputDevice(IDXGIOutput* ar_Output_, ID3D10Device* ar_Device_)
|
||||
: m_Output(ar_Output_)
|
||||
, m_Device(ar_Device_)
|
||||
, m_HasEnumerated(false)
|
||||
, m_DesiredWidth(0)
|
||||
, m_DesiredHeight(0)
|
||||
, m_DesiredRefreshRate(0)
|
||||
, m_DesiredFormat(DataFormat::Unknown)
|
||||
{
|
||||
if (m_Output != NULL)
|
||||
{
|
||||
m_Output->AddRef();
|
||||
m_Output->GetDesc(&m_OutputDesc);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
OutputDevice::~OutputDevice()
|
||||
{
|
||||
for (uint32 i = 0; i < m_DisplayModes.size(); ++i)
|
||||
delete m_DisplayModes[i];
|
||||
|
||||
if (m_Output != NULL)
|
||||
m_Output->Release();
|
||||
m_Output = NULL;
|
||||
}
|
||||
|
||||
|
||||
bool OutputDevice::TryEnumerate(uint32 argDesiredWidth, uint32 argDesiredHeight, uint32 argDesiredRefreshRate, DataFormat::Enumeration argDesiredFormat)
|
||||
{
|
||||
if (m_HasEnumerated)
|
||||
{
|
||||
if (m_DesiredWidth == argDesiredWidth ||
|
||||
m_DesiredHeight == argDesiredHeight ||
|
||||
m_DesiredRefreshRate == argDesiredRefreshRate ||
|
||||
m_DesiredFormat == argDesiredFormat)
|
||||
{
|
||||
return true;
|
||||
}
|
||||
else
|
||||
m_HasEnumerated = false;
|
||||
}
|
||||
|
||||
for (int formatIndex = (int)argDesiredFormat; formatIndex <= (argDesiredFormat == DataFormat::Unknown ? DXGI_FORMAT_B8G8R8X8_UNORM : (int)argDesiredFormat); ++formatIndex)
|
||||
{
|
||||
DXGI_FORMAT format = (DXGI_FORMAT)formatIndex;
|
||||
uint32 flags = DXGI_ENUM_MODES_SCALING;
|
||||
uint32 displayModeCount = 0;
|
||||
if (m_Output->GetDisplayModeList(format, flags, &displayModeCount, 0) == S_OK && displayModeCount > 0)
|
||||
{
|
||||
DXGI_MODE_DESC* descs = new DXGI_MODE_DESC[displayModeCount];
|
||||
if (m_Output->GetDisplayModeList(format, flags, &displayModeCount, descs) == S_OK)
|
||||
{
|
||||
for (uint32 i = 0; i < displayModeCount; ++i)
|
||||
{
|
||||
IDisplayMode* displayMode = new DisplayMode(descs[i]);
|
||||
bool keepDisplayMode = false;
|
||||
|
||||
if ((argDesiredWidth == 0 || argDesiredWidth <= displayMode->get_Width()) &&
|
||||
(argDesiredHeight == 0 || argDesiredHeight <= displayMode->get_Height()) &&
|
||||
(argDesiredRefreshRate == 0 || argDesiredRefreshRate <= displayMode->get_RefreshRate()) &&
|
||||
(argDesiredFormat == DataFormat::Unknown || argDesiredFormat == displayMode->get_Format()))
|
||||
{
|
||||
if (m_Device != NULL)
|
||||
{
|
||||
uint32 supportBits = 0;
|
||||
m_Device->CheckFormatSupport((DXGI_FORMAT)format, &supportBits);
|
||||
if ((supportBits & D3D10_FORMAT_SUPPORT_DISPLAY) != 0)
|
||||
keepDisplayMode = true;
|
||||
}
|
||||
else
|
||||
keepDisplayMode = true;
|
||||
}
|
||||
|
||||
if (keepDisplayMode)
|
||||
m_DisplayModes.push_back(displayMode);
|
||||
else
|
||||
delete displayMode;
|
||||
|
||||
}
|
||||
delete [] descs;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
m_DesiredWidth = argDesiredWidth;
|
||||
m_DesiredHeight = argDesiredHeight;
|
||||
m_DesiredRefreshRate = argDesiredRefreshRate;
|
||||
m_DesiredFormat = argDesiredFormat;
|
||||
|
||||
m_HasEnumerated = !m_DisplayModes.empty();
|
||||
return m_HasEnumerated;
|
||||
}
|
||||
|
||||
|
||||
IDisplayMode* OutputDevice::FindBestDisplayMode(bool argAllowToEnumerate, uint32 argDesiredWidth, uint32 argDesiredHeight, uint32 argDesiredRefreshRate, DataFormat::Enumeration argDesiredFormat)
|
||||
{
|
||||
if (argAllowToEnumerate && !this->TryEnumerate(argDesiredWidth, argDesiredHeight, argDesiredRefreshRate, argDesiredFormat))
|
||||
return NULL;
|
||||
|
||||
if (!m_HasEnumerated)
|
||||
return NULL;
|
||||
|
||||
return m_DisplayModes.back();
|
||||
}
|
||||
35
aiwaz/Aiwaz/DeviceEnumerator/OutputDevice.h
Normal file
35
aiwaz/Aiwaz/DeviceEnumerator/OutputDevice.h
Normal file
@@ -0,0 +1,35 @@
|
||||
#include "IDeviceEnumerator.h"
|
||||
|
||||
|
||||
class OutputDevice
|
||||
: public IOutputDevice
|
||||
{
|
||||
public:
|
||||
OutputDevice(IDXGIOutput* ar_Output_, ID3D10Device* ar_Device_ = NULL);
|
||||
virtual ~OutputDevice();
|
||||
|
||||
virtual bool get_IsAttachedToDesktop() const { return m_OutputDesc.AttachedToDesktop == TRUE; }
|
||||
virtual HMONITOR get_MonitorHandle() const { return m_OutputDesc.Monitor; }
|
||||
virtual RECT get_DesktopCoordinates() const { return m_OutputDesc.DesktopCoordinates; }
|
||||
virtual const std::vector<IDisplayMode*>& get_DisplayModes() const { return m_DisplayModes; }
|
||||
virtual bool get_HasEnumerated() const { return m_HasEnumerated; }
|
||||
|
||||
virtual bool TryEnumerate(uint32 argDesiredWidth = 0, uint32 argDesiredHeight = 0, uint32 argDesiredRefreshRate = 0, DataFormat::Enumeration argDesiredFormat = DataFormat::Unknown);
|
||||
virtual IDisplayMode* FindBestDisplayMode(bool argAllowToEnumerate = false, uint32 argDesiredWidth = 0, uint32 argDesiredHeight = 0, uint32 argDesiredRefreshRate = 0, DataFormat::Enumeration argDesiredFormat = DataFormat::Unknown);
|
||||
virtual string16 get_Name() const { return m_OutputDesc.DeviceName; }
|
||||
|
||||
private:
|
||||
void GatherDisplayModes();
|
||||
|
||||
private:
|
||||
IDXGIOutput* m_Output;
|
||||
ID3D10Device* m_Device;
|
||||
DXGI_OUTPUT_DESC m_OutputDesc;
|
||||
bool m_HasEnumerated;
|
||||
|
||||
std::vector<IDisplayMode*> m_DisplayModes;
|
||||
uint32 m_DesiredWidth;
|
||||
uint32 m_DesiredHeight;
|
||||
uint32 m_DesiredRefreshRate;
|
||||
DataFormat::Enumeration m_DesiredFormat;
|
||||
};
|
||||
145
aiwaz/Aiwaz/Engine/Engine.cpp
Normal file
145
aiwaz/Aiwaz/Engine/Engine.cpp
Normal file
@@ -0,0 +1,145 @@
|
||||
#include "stdafx.h"
|
||||
|
||||
#include "Engine.h"
|
||||
#include "../ResourceFactory/ResourceFactory.h"
|
||||
#include "../CommonObjectFactory/CommonObjectFactory.h"
|
||||
#include "../FileSystem/FileSystem.h"
|
||||
#include "../Timeline/Timeline.h"
|
||||
#include "../AnimationManager/AnimationManager.h"
|
||||
|
||||
|
||||
Engine::Engine()
|
||||
: m_DX10Device(NULL)
|
||||
, m_DXGIFactory(NULL)
|
||||
, m_ResourceFactory(NULL)
|
||||
, m_CommonObjectFactory(NULL)
|
||||
, m_DeviceEnumeration(NULL)
|
||||
, m_FileSystem(NULL)
|
||||
, m_DriverType(D3D10_DRIVER_TYPE_NULL)
|
||||
, m_Timeline(NULL)
|
||||
, m_AnimationManager(NULL)
|
||||
{
|
||||
ZeroMemory(&m_EngineStates, sizeof(EngineStates));
|
||||
}
|
||||
|
||||
|
||||
Engine::~Engine()
|
||||
{
|
||||
this->Uninitialize();
|
||||
}
|
||||
|
||||
|
||||
void Engine::Initialize(IDisplayAdapter* ar_Adapter_)
|
||||
{
|
||||
std::wcout << std::green << "Initializing engine." << std::white << std::endl;
|
||||
|
||||
HRESULT result = S_OK;
|
||||
if (m_DeviceEnumeration == NULL)
|
||||
m_DeviceEnumeration = new DeviceEnumerator();
|
||||
|
||||
if (m_DX10Device != NULL)
|
||||
this->Uninitialize();
|
||||
|
||||
if (ar_Adapter_ == NULL)
|
||||
{
|
||||
if (!m_DeviceEnumeration->get_HasEnumerated())
|
||||
m_DeviceEnumeration->TryEnumerate(0, 0, 0, DataFormat::R8G8B8A8_UnsignedNormalized);
|
||||
ar_Adapter_ = m_DeviceEnumeration->FindBestAdapter();
|
||||
|
||||
m_DeviceEnumeration->Verbose();
|
||||
}
|
||||
|
||||
if (ar_Adapter_ == NULL)
|
||||
{
|
||||
std::wcout << std::red << "No capable adapter found, ensure DX10 compatible system." << std::white << std::endl;
|
||||
this->Uninitialize();
|
||||
return;
|
||||
}
|
||||
|
||||
// create a functional device, first try a hardware accelerated one, then fallback to software
|
||||
D3D10_DRIVER_TYPE driverTypes[] =
|
||||
{
|
||||
D3D10_DRIVER_TYPE_HARDWARE,
|
||||
D3D10_DRIVER_TYPE_REFERENCE,
|
||||
};
|
||||
|
||||
uint32 deviceFlags = 0;
|
||||
#ifdef _DEBUG
|
||||
// we want debug informations when we run a debug build
|
||||
deviceFlags |= D3D10_CREATE_DEVICE_DEBUG;
|
||||
std::wcout << std::yellow << "Using debug device." << std::white << std::endl;
|
||||
|
||||
#endif
|
||||
|
||||
// lets create the device now
|
||||
uint32 driverTypesCount = sizeof(driverTypes) / sizeof(driverTypes[0]);
|
||||
for(uint32 driverTypeIndex = 0; driverTypeIndex < driverTypesCount; ++driverTypeIndex)
|
||||
{
|
||||
// store the driver type, we will need this for later statistics, eg.
|
||||
m_DriverType = driverTypes[driverTypeIndex];
|
||||
result = ::D3D10CreateDevice(ar_Adapter_->get_Adapter(), m_DriverType, NULL, deviceFlags, D3D10_SDK_VERSION, &m_DX10Device);
|
||||
if( SUCCEEDED( result ) )
|
||||
break;
|
||||
}
|
||||
|
||||
if (result != S_OK)
|
||||
{
|
||||
std::wcout << std::red << "Failed to create device." << std::white << std::endl;
|
||||
this->Uninitialize();
|
||||
return;
|
||||
}
|
||||
|
||||
result = ::CreateDXGIFactory(__uuidof(IDXGIFactory), (void**)&m_DXGIFactory);
|
||||
if (result != S_OK)
|
||||
{
|
||||
std::wcout << std::red << "Failed to create GI factory." << std::white << std::endl;
|
||||
this->Uninitialize();
|
||||
return;
|
||||
}
|
||||
|
||||
m_ResourceFactory = new ResourceFactory(*this);
|
||||
m_CommonObjectFactory = new CommonObjectFactory(*this);
|
||||
m_FileSystem = new FileSystem(this);
|
||||
|
||||
m_Timeline = new Timeline(*this);
|
||||
m_AnimationManager = new AnimationManager(*this);
|
||||
|
||||
std::wcout << std::green << "Finished initializing engine." << std::white << std::endl << std::endl;
|
||||
}
|
||||
|
||||
|
||||
void Engine::Uninitialize()
|
||||
{
|
||||
std::wcout << std::endl << std::green << "Uninitializing engine." << std::white << std::endl;
|
||||
|
||||
delete m_ResourceFactory;
|
||||
m_ResourceFactory = NULL;
|
||||
|
||||
delete m_CommonObjectFactory;
|
||||
m_CommonObjectFactory = NULL;
|
||||
|
||||
delete m_DeviceEnumeration;
|
||||
m_DeviceEnumeration = NULL;
|
||||
|
||||
delete m_FileSystem;
|
||||
m_FileSystem = NULL;
|
||||
|
||||
delete m_Timeline;
|
||||
m_Timeline = NULL;
|
||||
|
||||
delete m_AnimationManager;
|
||||
m_AnimationManager = NULL;
|
||||
|
||||
if (m_DX10Device != NULL)
|
||||
{
|
||||
m_DX10Device->ClearState();
|
||||
m_DX10Device->Release();
|
||||
m_DX10Device = NULL;
|
||||
}
|
||||
|
||||
if (m_DXGIFactory != NULL)
|
||||
m_DXGIFactory->Release();
|
||||
m_DXGIFactory = NULL;
|
||||
|
||||
ZeroMemory(&m_EngineStates, sizeof(EngineStates));
|
||||
}
|
||||
42
aiwaz/Aiwaz/Engine/Engine.h
Normal file
42
aiwaz/Aiwaz/Engine/Engine.h
Normal file
@@ -0,0 +1,42 @@
|
||||
#include "../DeviceEnumerator/DeviceEnumerator.h"
|
||||
#include "IEngine.h"
|
||||
|
||||
|
||||
class Engine
|
||||
: public IEngine
|
||||
{
|
||||
public:
|
||||
Engine();
|
||||
virtual ~Engine();
|
||||
|
||||
virtual void Initialize(IDisplayAdapter* ar_Adapter_ = NULL);
|
||||
virtual void Uninitialize();
|
||||
|
||||
virtual bool get_IsInitialized() const { return m_DX10Device != NULL; }
|
||||
virtual bool get_IsUsingReferenceDriver() const { return m_DriverType == D3D10_DRIVER_TYPE_REFERENCE; }
|
||||
|
||||
virtual IResourceFactory& get_ResourceFactory() const { return *m_ResourceFactory; }
|
||||
virtual ICommonObjectFactory& get_CommonObjectFactory() const { return *m_CommonObjectFactory; }
|
||||
virtual IFileSystem& get_FileSystem() const { return *m_FileSystem; }
|
||||
virtual ITimeline& get_Timeline() const { return *m_Timeline; }
|
||||
virtual IAnimationManager& get_AnimationManager() const { return *m_AnimationManager; }
|
||||
|
||||
virtual ID3D10Device& get_DX10Device() const { return *m_DX10Device; }
|
||||
virtual IDXGIFactory& get_DXGIFactory() const { return *m_DXGIFactory; }
|
||||
|
||||
virtual EngineStates& get_EngineStates() { return m_EngineStates; }
|
||||
|
||||
private:
|
||||
IDXGIFactory* m_DXGIFactory;
|
||||
ID3D10Device* m_DX10Device;
|
||||
D3D10_DRIVER_TYPE m_DriverType;
|
||||
|
||||
IDeviceEnumerator* m_DeviceEnumeration;
|
||||
IResourceFactory* m_ResourceFactory;
|
||||
ICommonObjectFactory* m_CommonObjectFactory;
|
||||
IFileSystem* m_FileSystem;
|
||||
ITimeline* m_Timeline;
|
||||
IAnimationManager* m_AnimationManager;
|
||||
|
||||
EngineStates m_EngineStates;
|
||||
};
|
||||
BIN
aiwaz/Aiwaz/FileSystem/7za.exe
Normal file
BIN
aiwaz/Aiwaz/FileSystem/7za.exe
Normal file
Binary file not shown.
89
aiwaz/Aiwaz/FileSystem/CFileLoader/CFileLoader.cpp
Normal file
89
aiwaz/Aiwaz/FileSystem/CFileLoader/CFileLoader.cpp
Normal file
@@ -0,0 +1,89 @@
|
||||
#include "stdafx.h"
|
||||
#include "CFileLoader.h"
|
||||
|
||||
#include "IFileSystem.h"
|
||||
|
||||
|
||||
CFileLoader::~CFileLoader()
|
||||
{
|
||||
this->FreeFile();
|
||||
}
|
||||
|
||||
|
||||
bool CFileLoader::LoadFile(string16 argFilename)
|
||||
{
|
||||
m_File = m_Engine->get_FileSystem().Open(argFilename);
|
||||
if (m_File != NULL)
|
||||
{
|
||||
std::stringstream dataStream;
|
||||
dataStream.write(m_File->get_Buffer(), m_File->get_BufferLength());
|
||||
|
||||
while (!dataStream.eof())
|
||||
{
|
||||
m_CurrentLineOfCode++;
|
||||
|
||||
std::string currentReadLine;
|
||||
std::getline(dataStream, currentReadLine);
|
||||
if (currentReadLine.empty())
|
||||
continue;
|
||||
|
||||
std::vector<std::string> token = this->SplitString(currentReadLine);
|
||||
if (token.empty())
|
||||
continue;
|
||||
|
||||
m_CurrentSection = token[0];
|
||||
if (!this->OnSectionBegin(m_CurrentSection, token))
|
||||
{
|
||||
this->FreeFile();
|
||||
return false;
|
||||
}
|
||||
|
||||
if (token[token.size() - 1] == "{{")
|
||||
m_EndSectionMarker = "}}";
|
||||
else
|
||||
m_EndSectionMarker = "}";
|
||||
|
||||
while (!dataStream.eof())
|
||||
{
|
||||
m_CurrentLineOfCode++;
|
||||
std::getline(dataStream, currentReadLine);
|
||||
if (currentReadLine.empty())
|
||||
continue;
|
||||
|
||||
std::vector<std::string> token = this->SplitString(currentReadLine, ", \t()\r");
|
||||
if (token.empty())
|
||||
continue;
|
||||
|
||||
if (token[0] == m_EndSectionMarker)
|
||||
{
|
||||
if (!this->OnSectionEnd(m_CurrentSection))
|
||||
{
|
||||
this->FreeFile();
|
||||
return false;
|
||||
}
|
||||
m_CurrentSection = "";
|
||||
break;
|
||||
}
|
||||
|
||||
if (!this->OnContentReceived(token, currentReadLine))
|
||||
{
|
||||
this->FreeFile();
|
||||
return false;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
this->FreeFile();
|
||||
return true;
|
||||
}
|
||||
this->FreeFile();
|
||||
return false;
|
||||
}
|
||||
|
||||
|
||||
void CFileLoader::FreeFile()
|
||||
{
|
||||
if (m_File != NULL)
|
||||
delete m_File;
|
||||
m_File = NULL;
|
||||
}
|
||||
73
aiwaz/Aiwaz/FileSystem/CFileLoader/CFileLoader.h
Normal file
73
aiwaz/Aiwaz/FileSystem/CFileLoader/CFileLoader.h
Normal file
@@ -0,0 +1,73 @@
|
||||
#pragma once
|
||||
|
||||
#include "IEngine.h"
|
||||
#include "IFileSystem.h"
|
||||
#include <iostream>
|
||||
#include <sstream>
|
||||
#include <vector>
|
||||
#include <string>
|
||||
|
||||
class CFileLoader
|
||||
{
|
||||
public:
|
||||
CFileLoader(IEngine* ar_Engine_) : m_Engine(ar_Engine_),m_CurrentLineOfCode(0), m_File(NULL),m_EndSectionMarker("}") {}
|
||||
virtual ~CFileLoader();
|
||||
|
||||
bool LoadFile(string16 argFilename);
|
||||
const std::string& get_CurrentSection() const { return m_CurrentSection; }
|
||||
|
||||
virtual bool OnSectionBegin(const std::string& argContentName, const std::vector<std::string>& argContentToken) { return true; }
|
||||
virtual bool OnContentReceived(const std::vector<std::string>& argContentToken, const std::string& argContentData) { return true; }
|
||||
virtual bool OnSectionEnd(const std::string& argContentName) { return true; }
|
||||
|
||||
unsigned int get_CurrentLineNumber() const { return m_CurrentLineOfCode; }
|
||||
|
||||
protected:
|
||||
std::vector<std::string> SplitString(const std::string & argString, const std::string & argDelimiters=", \t\r")
|
||||
{
|
||||
// Skip delims at beginning, find start of first token
|
||||
std::string::size_type lastPos = argString.find_first_not_of(argDelimiters, 0);
|
||||
// Find next delimiter @ end of token
|
||||
std::string::size_type pos = argString.find_first_of(argDelimiters, lastPos);
|
||||
|
||||
// output vector
|
||||
std::vector<std::string> tokens;
|
||||
while (std::string::npos != pos || std::string::npos != lastPos)
|
||||
{
|
||||
// Found a token, add it to the vector.
|
||||
tokens.push_back(argString.substr(lastPos, pos - lastPos));
|
||||
// Skip delims. Note the "not_of". this is beginning of token
|
||||
lastPos = argString.find_first_not_of(argDelimiters, pos);
|
||||
// Find next delimiter at end of token.
|
||||
pos = argString.find_first_of(argDelimiters, lastPos);
|
||||
}
|
||||
|
||||
return tokens;
|
||||
}
|
||||
|
||||
std::wstring ConvertToString16(const std::string& argString) const
|
||||
{
|
||||
int codePage = 0;
|
||||
if (argString.size() == 0)
|
||||
return std::wstring();
|
||||
|
||||
int length = ::MultiByteToWideChar(codePage, 0, argString.c_str(), argString.size() + 1, NULL, 0);
|
||||
if (length == 0)
|
||||
return std::wstring();
|
||||
|
||||
wchar_t* newString = new wchar_t[length];
|
||||
::MultiByteToWideChar(codePage, 0, argString.c_str(), argString.size() + 1, newString, length);
|
||||
return std::wstring(newString);
|
||||
}
|
||||
|
||||
IEngine* m_Engine;
|
||||
|
||||
void FreeFile();
|
||||
|
||||
private:
|
||||
std::string m_CurrentSection;
|
||||
IFile* m_File;
|
||||
|
||||
std::string m_EndSectionMarker;
|
||||
unsigned int m_CurrentLineOfCode;
|
||||
};
|
||||
123
aiwaz/Aiwaz/FileSystem/File.cpp
Normal file
123
aiwaz/Aiwaz/FileSystem/File.cpp
Normal file
@@ -0,0 +1,123 @@
|
||||
#include "stdafx.h"
|
||||
#include "File.h"
|
||||
|
||||
|
||||
File::File(IEngine* ar_Engine_, char* ac_Buffer_, unsigned int argBufferLength, const string16 argFileName)
|
||||
: m_Engine(ar_Engine_)
|
||||
, m_Buffer(ac_Buffer_)
|
||||
, m_BufferPosition(m_Buffer)
|
||||
, m_BufferLength(argBufferLength)
|
||||
, m_FileName(argFileName)
|
||||
{
|
||||
}
|
||||
|
||||
|
||||
File::~File()
|
||||
{
|
||||
delete [] m_Buffer;
|
||||
}
|
||||
|
||||
|
||||
char* File::get_Buffer()
|
||||
{
|
||||
return m_Buffer;
|
||||
}
|
||||
|
||||
|
||||
unsigned int File::get_BufferLength()
|
||||
{
|
||||
return m_BufferLength;
|
||||
}
|
||||
|
||||
|
||||
void File::SaveAs(string16 argFileName)
|
||||
{
|
||||
FILE* file;
|
||||
fopen_s(&file, std::to_string8(argFileName).c_str(), "wb");
|
||||
fwrite(m_Buffer, 1, m_BufferLength, file);
|
||||
fclose(file);
|
||||
}
|
||||
|
||||
|
||||
std::string File::ReadString()
|
||||
{
|
||||
std::string result;
|
||||
char readChar = 0;
|
||||
do
|
||||
{
|
||||
this->CheckIntegrity(sizeof(char));
|
||||
|
||||
readChar = *m_BufferPosition;
|
||||
if (readChar != '\0')
|
||||
result += readChar;
|
||||
m_BufferPosition++;
|
||||
}
|
||||
while (readChar != '\0');
|
||||
|
||||
return result;
|
||||
}
|
||||
|
||||
|
||||
float File::ReadFloat()
|
||||
{
|
||||
this->CheckIntegrity(sizeof(float));
|
||||
|
||||
float result = *(float*)m_BufferPosition;
|
||||
m_BufferPosition += sizeof(float);
|
||||
return result;
|
||||
}
|
||||
|
||||
|
||||
int File::ReadInt()
|
||||
{
|
||||
this->CheckIntegrity(sizeof(int));
|
||||
|
||||
int result = *(int*)m_BufferPosition;
|
||||
m_BufferPosition += sizeof(int);
|
||||
return result;
|
||||
}
|
||||
|
||||
|
||||
void* File::ReadDataArray(unsigned int argBytes)
|
||||
{
|
||||
this->CheckIntegrity(argBytes);
|
||||
|
||||
char* data = new char[argBytes];
|
||||
|
||||
memcpy(data, m_BufferPosition, argBytes);
|
||||
|
||||
m_BufferPosition += sizeof(char) * argBytes;
|
||||
return data;
|
||||
}
|
||||
|
||||
|
||||
void File::RewindFilePointer()
|
||||
{
|
||||
m_BufferPosition = m_Buffer;
|
||||
}
|
||||
|
||||
|
||||
char* File::get_FilePointer() const
|
||||
{
|
||||
return m_BufferPosition;
|
||||
}
|
||||
|
||||
|
||||
void File::set_FilePointer(char* ac_Position_)
|
||||
{
|
||||
m_BufferPosition = ac_Position_;
|
||||
this->CheckIntegrity(0);
|
||||
}
|
||||
|
||||
|
||||
bool File::IsEof() const
|
||||
{
|
||||
return m_BufferPosition == (m_Buffer + m_BufferLength);
|
||||
}
|
||||
|
||||
|
||||
void File::CheckIntegrity(unsigned int argBytes)
|
||||
{
|
||||
if (m_BufferPosition + argBytes > m_Buffer + m_BufferLength || m_BufferPosition < m_Buffer)
|
||||
throw _T("File integrity is broken.");
|
||||
}
|
||||
39
aiwaz/Aiwaz/FileSystem/File.h
Normal file
39
aiwaz/Aiwaz/FileSystem/File.h
Normal file
@@ -0,0 +1,39 @@
|
||||
#pragma once
|
||||
|
||||
#include "IEngine.h"
|
||||
#include "IFileSystem.h"
|
||||
|
||||
|
||||
class File
|
||||
: public IFile
|
||||
{
|
||||
public:
|
||||
File(IEngine* ar_Engine_, char* ac_Buffer_, unsigned int argBufferLength, const string16 argFileName);
|
||||
virtual ~File();
|
||||
|
||||
virtual char* get_Buffer();
|
||||
virtual unsigned int get_BufferLength();
|
||||
virtual void SaveAs(string16 argFileName);
|
||||
|
||||
virtual std::string ReadString();
|
||||
virtual float ReadFloat();
|
||||
virtual int ReadInt();
|
||||
virtual void* ReadDataArray(unsigned int argBytes);
|
||||
|
||||
virtual void RewindFilePointer();
|
||||
virtual char* get_FilePointer() const;
|
||||
virtual void set_FilePointer(char* ac_Position_);
|
||||
virtual bool IsEof() const;
|
||||
|
||||
virtual string16 get_FileName() const { return m_FileName; }
|
||||
|
||||
protected:
|
||||
void CheckIntegrity(unsigned int argBytes);
|
||||
|
||||
private:
|
||||
IEngine* m_Engine;
|
||||
char* m_Buffer;
|
||||
char* m_BufferPosition;
|
||||
unsigned int m_BufferLength;
|
||||
string16 m_FileName;
|
||||
};
|
||||
81
aiwaz/Aiwaz/FileSystem/FileSystem.cpp
Normal file
81
aiwaz/Aiwaz/FileSystem/FileSystem.cpp
Normal file
@@ -0,0 +1,81 @@
|
||||
#include "stdafx.h"
|
||||
#include "FileSystem.h"
|
||||
#include "File.h"
|
||||
|
||||
|
||||
FileSystem::FileSystem(IEngine* ar_Engine_)
|
||||
: m_Engine(ar_Engine_)
|
||||
, m_Zip(false)
|
||||
{
|
||||
::GetModuleFileName(NULL, m_AppDirectory, MAX_PATH);
|
||||
::PathRemoveFileSpec(m_AppDirectory);
|
||||
}
|
||||
|
||||
|
||||
FileSystem::~FileSystem()
|
||||
{
|
||||
if (m_Zip)
|
||||
{
|
||||
::CloseZip(m_ZipHandle);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
void FileSystem::InitializeFromDirectory(string16 argDirectory)
|
||||
{
|
||||
m_Zip = false;
|
||||
::PathCombine(m_Directory, m_AppDirectory, std::to_string8(argDirectory).c_str());
|
||||
}
|
||||
|
||||
|
||||
void FileSystem::InitializeFromZipFile(string16 argZipFile)
|
||||
{
|
||||
std::cout << "Initializing file system with data file: ";
|
||||
std::wcout << argZipFile << std::white << std::endl;
|
||||
m_Zip = true;
|
||||
char fullPath[MAX_PATH];
|
||||
::PathCombine(fullPath, m_AppDirectory, std::to_string8(argZipFile).c_str());
|
||||
m_ZipHandle = ::OpenZip(fullPath, 0);
|
||||
if (m_ZipHandle == NULL)
|
||||
{
|
||||
std::cout << std::red << "FAILED!" << std::white << std::endl;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
IFile* FileSystem::Open(string16 argFileName)
|
||||
{
|
||||
if (m_Zip)
|
||||
{
|
||||
ZIPENTRY zipEntry;
|
||||
int index;
|
||||
::FindZipItem(m_ZipHandle, std::to_string8(argFileName).c_str(), true, &index, &zipEntry);
|
||||
if (index == -1)
|
||||
return NULL;
|
||||
|
||||
unsigned int bufferSize = zipEntry.unc_size;
|
||||
char* buffer = new char[bufferSize];
|
||||
::UnzipItem(m_ZipHandle, index, buffer, bufferSize);
|
||||
|
||||
return new File(m_Engine, buffer, bufferSize, argFileName);
|
||||
}
|
||||
else
|
||||
{
|
||||
char fullPath[MAX_PATH];
|
||||
::PathCombine(fullPath, m_Directory, std::to_string8(argFileName).c_str());
|
||||
|
||||
FILE* file = NULL;
|
||||
_tfopen_s(&file, fullPath, _T("rb"));
|
||||
if (file == NULL)
|
||||
return NULL;
|
||||
|
||||
fseek(file, 0, SEEK_END);
|
||||
unsigned int bufferSize = ftell(file);
|
||||
rewind(file);
|
||||
char* buffer = new char[bufferSize];
|
||||
fread_s(buffer, bufferSize, 1, bufferSize, file);
|
||||
fclose(file);
|
||||
|
||||
return new File(m_Engine, buffer, bufferSize, argFileName);
|
||||
}
|
||||
}
|
||||
25
aiwaz/Aiwaz/FileSystem/FileSystem.h
Normal file
25
aiwaz/Aiwaz/FileSystem/FileSystem.h
Normal file
@@ -0,0 +1,25 @@
|
||||
#pragma once
|
||||
|
||||
#include "IEngine.h"
|
||||
#include "IFileSystem.h"
|
||||
#include "unzip.h"
|
||||
|
||||
|
||||
class FileSystem
|
||||
: public IFileSystem
|
||||
{
|
||||
public:
|
||||
FileSystem(IEngine* ar_Engine_);
|
||||
virtual ~FileSystem();
|
||||
|
||||
virtual void InitializeFromDirectory(string16 argDirectory = L"data");
|
||||
virtual void InitializeFromZipFile(string16 argZipFile = L"data.pak");
|
||||
virtual IFile* Open(string16 argFileName);
|
||||
|
||||
private:
|
||||
IEngine* m_Engine;
|
||||
bool m_Zip;
|
||||
HZIP m_ZipHandle;
|
||||
char m_Directory[MAX_PATH];
|
||||
char m_AppDirectory[MAX_PATH];
|
||||
};
|
||||
4165
aiwaz/Aiwaz/FileSystem/unzip.cpp
Normal file
4165
aiwaz/Aiwaz/FileSystem/unzip.cpp
Normal file
File diff suppressed because it is too large
Load Diff
214
aiwaz/Aiwaz/FileSystem/unzip.h
Normal file
214
aiwaz/Aiwaz/FileSystem/unzip.h
Normal file
@@ -0,0 +1,214 @@
|
||||
#ifndef _unzip_H
|
||||
#define _unzip_H
|
||||
|
||||
// UNZIPPING functions -- for unzipping.
|
||||
// This file is a repackaged form of extracts from the zlib code available
|
||||
// at www.gzip.org/zlib, by Jean-Loup Gailly and Mark Adler. The original
|
||||
// copyright notice may be found in unzip.cpp. The repackaging was done
|
||||
// by Lucian Wischik to simplify and extend its use in Windows/C++. Also
|
||||
// encryption and unicode filenames have been added.
|
||||
|
||||
|
||||
#ifndef _zip_H
|
||||
DECLARE_HANDLE(HZIP);
|
||||
#endif
|
||||
// An HZIP identifies a zip file that has been opened
|
||||
|
||||
typedef DWORD ZRESULT;
|
||||
// return codes from any of the zip functions. Listed later.
|
||||
|
||||
typedef struct
|
||||
{ int index; // index of this file within the zip
|
||||
TCHAR name[MAX_PATH]; // filename within the zip
|
||||
DWORD attr; // attributes, as in GetFileAttributes.
|
||||
FILETIME atime,ctime,mtime;// access, create, modify filetimes
|
||||
long comp_size; // sizes of item, compressed and uncompressed. These
|
||||
long unc_size; // may be -1 if not yet known (e.g. being streamed in)
|
||||
} ZIPENTRY;
|
||||
|
||||
|
||||
HZIP OpenZip(const TCHAR *fn, const char *password);
|
||||
HZIP OpenZip(void *z,unsigned int len, const char *password);
|
||||
HZIP OpenZipHandle(HANDLE h, const char *password);
|
||||
// OpenZip - opens a zip file and returns a handle with which you can
|
||||
// subsequently examine its contents. You can open a zip file from:
|
||||
// from a pipe: OpenZipHandle(hpipe_read,0);
|
||||
// from a file (by handle): OpenZipHandle(hfile,0);
|
||||
// from a file (by name): OpenZip("c:\\test.zip","password");
|
||||
// from a memory block: OpenZip(bufstart, buflen,0);
|
||||
// If the file is opened through a pipe, then items may only be
|
||||
// accessed in increasing order, and an item may only be unzipped once,
|
||||
// although GetZipItem can be called immediately before and after unzipping
|
||||
// it. If it's opened in any other way, then full random access is possible.
|
||||
// Note: pipe input is not yet implemented.
|
||||
// Note: zip passwords are ascii, not unicode.
|
||||
// Note: for windows-ce, you cannot close the handle until after CloseZip.
|
||||
// but for real windows, the zip makes its own copy of your handle, so you
|
||||
// can close yours anytime.
|
||||
|
||||
ZRESULT GetZipItem(HZIP hz, int index, ZIPENTRY *ze);
|
||||
// GetZipItem - call this to get information about an item in the zip.
|
||||
// If index is -1 and the file wasn't opened through a pipe,
|
||||
// then it returns information about the whole zipfile
|
||||
// (and in particular ze.index returns the number of index items).
|
||||
// Note: the item might be a directory (ze.attr & FILE_ATTRIBUTE_DIRECTORY)
|
||||
// See below for notes on what happens when you unzip such an item.
|
||||
// Note: if you are opening the zip through a pipe, then random access
|
||||
// is not possible and GetZipItem(-1) fails and you can't discover the number
|
||||
// of items except by calling GetZipItem on each one of them in turn,
|
||||
// starting at 0, until eventually the call fails. Also, in the event that
|
||||
// you are opening through a pipe and the zip was itself created into a pipe,
|
||||
// then then comp_size and sometimes unc_size as well may not be known until
|
||||
// after the item has been unzipped.
|
||||
|
||||
ZRESULT FindZipItem(HZIP hz, const TCHAR *name, bool ic, int *index, ZIPENTRY *ze);
|
||||
// FindZipItem - finds an item by name. ic means 'insensitive to case'.
|
||||
// It returns the index of the item, and returns information about it.
|
||||
// If nothing was found, then index is set to -1 and the function returns
|
||||
// an error code.
|
||||
|
||||
ZRESULT UnzipItem(HZIP hz, int index, const TCHAR *fn);
|
||||
ZRESULT UnzipItem(HZIP hz, int index, void *z,unsigned int len);
|
||||
ZRESULT UnzipItemHandle(HZIP hz, int index, HANDLE h);
|
||||
// UnzipItem - given an index to an item, unzips it. You can unzip to:
|
||||
// to a pipe: UnzipItemHandle(hz,i, hpipe_write);
|
||||
// to a file (by handle): UnzipItemHandle(hz,i, hfile);
|
||||
// to a file (by name): UnzipItem(hz,i, ze.name);
|
||||
// to a memory block: UnzipItem(hz,i, buf,buflen);
|
||||
// In the final case, if the buffer isn't large enough to hold it all,
|
||||
// then the return code indicates that more is yet to come. If it was
|
||||
// large enough, and you want to know precisely how big, GetZipItem.
|
||||
// Note: zip files are normally stored with relative pathnames. If you
|
||||
// unzip with ZIP_FILENAME a relative pathname then the item gets created
|
||||
// relative to the current directory - it first ensures that all necessary
|
||||
// subdirectories have been created. Also, the item may itself be a directory.
|
||||
// If you unzip a directory with ZIP_FILENAME, then the directory gets created.
|
||||
// If you unzip it to a handle or a memory block, then nothing gets created
|
||||
// and it emits 0 bytes.
|
||||
ZRESULT SetUnzipBaseDir(HZIP hz, const TCHAR *dir);
|
||||
// if unzipping to a filename, and it's a relative filename, then it will be relative to here.
|
||||
// (defaults to current-directory).
|
||||
|
||||
|
||||
ZRESULT CloseZip(HZIP hz);
|
||||
// CloseZip - the zip handle must be closed with this function.
|
||||
|
||||
unsigned int FormatZipMessage(ZRESULT code, TCHAR *buf,unsigned int len);
|
||||
// FormatZipMessage - given an error code, formats it as a string.
|
||||
// It returns the length of the error message. If buf/len points
|
||||
// to a real buffer, then it also writes as much as possible into there.
|
||||
|
||||
|
||||
// These are the result codes:
|
||||
#define ZR_OK 0x00000000 // nb. the pseudo-code zr-recent is never returned,
|
||||
#define ZR_RECENT 0x00000001 // but can be passed to FormatZipMessage.
|
||||
// The following come from general system stuff (e.g. files not openable)
|
||||
#define ZR_GENMASK 0x0000FF00
|
||||
#define ZR_NODUPH 0x00000100 // couldn't duplicate the handle
|
||||
#define ZR_NOFILE 0x00000200 // couldn't create/open the file
|
||||
#define ZR_NOALLOC 0x00000300 // failed to allocate some resource
|
||||
#define ZR_WRITE 0x00000400 // a general error writing to the file
|
||||
#define ZR_NOTFOUND 0x00000500 // couldn't find that file in the zip
|
||||
#define ZR_MORE 0x00000600 // there's still more data to be unzipped
|
||||
#define ZR_CORRUPT 0x00000700 // the zipfile is corrupt or not a zipfile
|
||||
#define ZR_READ 0x00000800 // a general error reading the file
|
||||
#define ZR_PASSWORD 0x00001000 // we didn't get the right password to unzip the file
|
||||
// The following come from mistakes on the part of the caller
|
||||
#define ZR_CALLERMASK 0x00FF0000
|
||||
#define ZR_ARGS 0x00010000 // general mistake with the arguments
|
||||
#define ZR_NOTMMAP 0x00020000 // tried to ZipGetMemory, but that only works on mmap zipfiles, which yours wasn't
|
||||
#define ZR_MEMSIZE 0x00030000 // the memory size is too small
|
||||
#define ZR_FAILED 0x00040000 // the thing was already failed when you called this function
|
||||
#define ZR_ENDED 0x00050000 // the zip creation has already been closed
|
||||
#define ZR_MISSIZE 0x00060000 // the indicated input file size turned out mistaken
|
||||
#define ZR_PARTIALUNZ 0x00070000 // the file had already been partially unzipped
|
||||
#define ZR_ZMODE 0x00080000 // tried to mix creating/opening a zip
|
||||
// The following come from bugs within the zip library itself
|
||||
#define ZR_BUGMASK 0xFF000000
|
||||
#define ZR_NOTINITED 0x01000000 // initialisation didn't work
|
||||
#define ZR_SEEK 0x02000000 // trying to seek in an unseekable file
|
||||
#define ZR_NOCHANGE 0x04000000 // changed its mind on storage, but not allowed
|
||||
#define ZR_FLATE 0x05000000 // an internal error in the de/inflation code
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
// e.g.
|
||||
//
|
||||
// SetCurrentDirectory("c:\\docs\\stuff");
|
||||
// HZIP hz = OpenZip("c:\\stuff.zip",0);
|
||||
// ZIPENTRY ze; GetZipItem(hz,-1,&ze); int numitems=ze.index;
|
||||
// for (int i=0; i<numitems; i++)
|
||||
// { GetZipItem(hz,i,&ze);
|
||||
// UnzipItem(hz,i,ze.name);
|
||||
// }
|
||||
// CloseZip(hz);
|
||||
//
|
||||
//
|
||||
// HRSRC hrsrc = FindResource(hInstance,MAKEINTRESOURCE(1),RT_RCDATA);
|
||||
// HANDLE hglob = LoadResource(hInstance,hrsrc);
|
||||
// void *zipbuf=LockResource(hglob);
|
||||
// unsigned int ziplen=SizeofResource(hInstance,hrsrc);
|
||||
// HZIP hz = OpenZip(zipbuf, ziplen, 0);
|
||||
// - unzip to a membuffer -
|
||||
// ZIPENTRY ze; int i; FindZipItem(hz,"file.dat",true,&i,&ze);
|
||||
// char *ibuf = new char[ze.unc_size];
|
||||
// UnzipItem(hz,i, ibuf, ze.unc_size);
|
||||
// delete[] ibuf;
|
||||
// - unzip to a fixed membuff -
|
||||
// ZIPENTRY ze; int i; FindZipItem(hz,"file.dat",true,&i,&ze);
|
||||
// char ibuf[1024]; ZRESULT zr=ZR_MORE; unsigned long totsize=0;
|
||||
// while (zr==ZR_MORE)
|
||||
// { zr = UnzipItem(hz,i, ibuf,1024);
|
||||
// unsigned long bufsize=1024; if (zr==ZR_OK) bufsize=ze.unc_size-totsize;
|
||||
// totsize+=bufsize;
|
||||
// }
|
||||
// - unzip to a pipe -
|
||||
// HANDLE hwrite; HANDLE hthread=CreateWavReaderThread(&hwrite);
|
||||
// int i; ZIPENTRY ze; FindZipItem(hz,"sound.wav",true,&i,&ze);
|
||||
// UnzipItemHandle(hz,i, hwrite);
|
||||
// CloseHandle(hwrite);
|
||||
// WaitForSingleObject(hthread,INFINITE);
|
||||
// CloseHandle(hwrite); CloseHandle(hthread);
|
||||
// - finished -
|
||||
// CloseZip(hz);
|
||||
// // note: no need to free resources obtained through Find/Load/LockResource
|
||||
//
|
||||
//
|
||||
// SetCurrentDirectory("c:\\docs\\pipedzipstuff");
|
||||
// HANDLE hread,hwrite; CreatePipe(&hread,&hwrite,0,0);
|
||||
// CreateZipWriterThread(hwrite);
|
||||
// HZIP hz = OpenZipHandle(hread,0);
|
||||
// for (int i=0; ; i++)
|
||||
// { ZIPENTRY ze;
|
||||
// ZRESULT zr=GetZipItem(hz,i,&ze); if (zr!=ZR_OK) break; // no more
|
||||
// UnzipItem(hz,i, ze.name);
|
||||
// }
|
||||
// CloseZip(hz);
|
||||
//
|
||||
//
|
||||
|
||||
|
||||
|
||||
|
||||
// Now we indulge in a little skullduggery so that the code works whether
|
||||
// the user has included just zip or both zip and unzip.
|
||||
// Idea: if header files for both zip and unzip are present, then presumably
|
||||
// the cpp files for zip and unzip are both present, so we will call
|
||||
// one or the other of them based on a dynamic choice. If the header file
|
||||
// for only one is present, then we will bind to that particular one.
|
||||
ZRESULT CloseZipU(HZIP hz);
|
||||
unsigned int FormatZipMessageU(ZRESULT code, TCHAR *buf,unsigned int len);
|
||||
bool IsZipHandleU(HZIP hz);
|
||||
#ifdef _zip_H
|
||||
#undef CloseZip
|
||||
#define CloseZip(hz) (IsZipHandleU(hz)?CloseZipU(hz):CloseZipZ(hz))
|
||||
#else
|
||||
#define CloseZip CloseZipU
|
||||
#define FormatZipMessage FormatZipMessageU
|
||||
#endif
|
||||
|
||||
|
||||
|
||||
#endif // _unzip_H
|
||||
31
aiwaz/Aiwaz/Interfaces/IAnimationManager.h
Normal file
31
aiwaz/Aiwaz/Interfaces/IAnimationManager.h
Normal file
@@ -0,0 +1,31 @@
|
||||
#pragma once
|
||||
|
||||
|
||||
struct __declspec(novtable) IAnimateable
|
||||
{
|
||||
virtual ~IAnimateable() {};
|
||||
|
||||
virtual void OnAnimate(double argPosition, unsigned int argUserData) = 0;
|
||||
};
|
||||
|
||||
|
||||
struct __declspec(novtable) IEvent
|
||||
{
|
||||
virtual ~IEvent() {};
|
||||
|
||||
virtual void OnEvent(unsigned int argUserData) = 0;
|
||||
};
|
||||
|
||||
|
||||
struct __declspec(novtable) IAnimationManager
|
||||
{
|
||||
virtual ~IAnimationManager() {};
|
||||
|
||||
virtual void AddDemoTimeAnimation(double argBeginTime, double argEndTime, IAnimateable* argValue, unsigned int argUserData = 0) = 0;
|
||||
virtual void AddRealTimeAnimation(double argBeginTime, double argEndTime, IAnimateable* argValue, unsigned int argUserData = 0) = 0;
|
||||
|
||||
virtual void AddDemoTimeEvent(double argTime, IEvent* argValue, unsigned int argUserData = 0) = 0;
|
||||
virtual void AddRealTimeEvent(double argTime, IEvent* argValue, unsigned int argUserData = 0) = 0;
|
||||
|
||||
virtual void Animate() = 0;
|
||||
};
|
||||
59
aiwaz/Aiwaz/Interfaces/IBone.h
Normal file
59
aiwaz/Aiwaz/Interfaces/IBone.h
Normal file
@@ -0,0 +1,59 @@
|
||||
#pragma once
|
||||
|
||||
struct ITransformationAnimation;
|
||||
struct __declspec(novtable) IBone
|
||||
{
|
||||
virtual ~IBone() {};
|
||||
|
||||
virtual void Initialize(const string16& argName, int argIndex, const D3DXVECTOR3& argPoseTranslation, const D3DXVECTOR3& argPoseScale, const D3DXQUATERNION& argPoseRotation) = 0;
|
||||
|
||||
virtual const D3DXMATRIX& GetTransformationAtTime(float argTime, const D3DXMATRIX& argRootTransformationMatrix) = 0;
|
||||
virtual const D3DXMATRIX& get_PoseTransformation() const = 0;
|
||||
|
||||
virtual void set_Parent(IBone* argParent_) = 0;
|
||||
virtual IBone* get_Parent() const = 0;
|
||||
virtual std::vector<IBone*>& get_ChildBones() = 0;
|
||||
|
||||
virtual string16 get_Name() const = 0;
|
||||
virtual int get_Index() const = 0;
|
||||
|
||||
virtual void set_TransformationAnimation(ITransformationAnimation* argTransformationAnimation) = 0;
|
||||
virtual ITransformationAnimation* get_TransformationAnimation() const = 0;
|
||||
|
||||
virtual std::map<int, IBone*>& get_BoneIndexList() = 0;
|
||||
|
||||
virtual D3DXMATRIX* get_MatrixArray() = 0;
|
||||
virtual unsigned int get_MatrixArraySize() = 0;
|
||||
};
|
||||
|
||||
|
||||
struct Sequence
|
||||
{
|
||||
Sequence()
|
||||
: m_Start(0.0f)
|
||||
, m_End(0.0f)
|
||||
, m_Loop(false)
|
||||
{
|
||||
}
|
||||
float m_Start;
|
||||
float m_End;
|
||||
bool m_Loop;
|
||||
};
|
||||
|
||||
|
||||
struct __declspec(novtable) IBoneController
|
||||
{
|
||||
virtual ~IBoneController() {}
|
||||
|
||||
virtual void Initialize(IBone& argRootBone) = 0;
|
||||
virtual void Initialize(const IBoneController& argOther) = 0;
|
||||
virtual void Apply() = 0;
|
||||
|
||||
virtual void RegisterSequence(const string16& argName, float argStart, float argEnd, bool argLoop) = 0;
|
||||
virtual void PlaySequence(const string16& argName) = 0;
|
||||
|
||||
virtual const string16& get_CurrentSequence() const = 0;
|
||||
virtual const std::map<string16, Sequence >& get_Sequences() const = 0;
|
||||
|
||||
virtual IBone& get_RootBone() const = 0;
|
||||
};
|
||||
46
aiwaz/Aiwaz/Interfaces/ICamera.h
Normal file
46
aiwaz/Aiwaz/Interfaces/ICamera.h
Normal file
@@ -0,0 +1,46 @@
|
||||
#pragma once
|
||||
|
||||
|
||||
struct ViewFrustum
|
||||
{
|
||||
D3DXPLANE Plane[6];
|
||||
};
|
||||
|
||||
|
||||
struct __declspec(novtable) ICamera
|
||||
{
|
||||
virtual const D3DXMATRIX& get_ProjectionMatrix() const = 0;
|
||||
virtual const D3DXMATRIX& get_ViewMatrix() const = 0;
|
||||
|
||||
virtual void set_AspectRatio(float argValue) = 0;
|
||||
virtual float get_AspectRatio() const = 0;
|
||||
|
||||
virtual void set_FarClip(float argValue) = 0;
|
||||
virtual float get_FarClip() const = 0;
|
||||
|
||||
virtual void set_NearClip(float argValue) = 0;
|
||||
virtual float get_NearClip() const = 0;
|
||||
|
||||
virtual const ViewFrustum& get_ViewFrustum() const = 0;
|
||||
};
|
||||
|
||||
|
||||
struct __declspec(novtable) IPerspectiveCamera
|
||||
{
|
||||
virtual void set_Fov(float argValue) = 0;
|
||||
virtual float get_Fov() const = 0;
|
||||
|
||||
virtual ICamera& get_Base() = 0;
|
||||
};
|
||||
|
||||
|
||||
struct __declspec(novtable) IOrthographicCamera
|
||||
{
|
||||
virtual void set_Width(float argValue) = 0;
|
||||
virtual float get_Width() const = 0;
|
||||
|
||||
virtual void set_Height(float argValue) = 0;
|
||||
virtual float get_Height() const = 0;
|
||||
|
||||
virtual ICamera& get_Base() = 0;
|
||||
};
|
||||
96
aiwaz/Aiwaz/Interfaces/ICommandUser.h
Normal file
96
aiwaz/Aiwaz/Interfaces/ICommandUser.h
Normal file
@@ -0,0 +1,96 @@
|
||||
#pragma once
|
||||
|
||||
|
||||
struct CommandFlags
|
||||
{
|
||||
enum Enumeration
|
||||
{
|
||||
None = 0x00,
|
||||
SubChainStart = 0x01, // Command will start a new command chain (UseShader for example)
|
||||
SubChainEnd = 0x02, // Command will end a command chain (Render)
|
||||
Unique = 0x04, // Similar commands should not be reduced to one Command
|
||||
StartChain = 0x08, // Command will generate a new command chain
|
||||
EndChain = 0x10, // Command will end the command chain (RenderGeometry for example)
|
||||
FlushChain = 0x20, // Command will end the command chain (RenderGeometry for example)
|
||||
};
|
||||
};
|
||||
|
||||
struct ICommandUser;
|
||||
struct Command
|
||||
{
|
||||
|
||||
Command(ICommandUser* inOwner, unsigned char inFlags, unsigned char inType, unsigned char inPriority, unsigned char inSubPriority = 0)
|
||||
: Owner(inOwner)
|
||||
, Flags(inFlags)
|
||||
, Priority(inPriority)
|
||||
, SubPriority(inSubPriority)
|
||||
, Type(inType)
|
||||
{
|
||||
}
|
||||
|
||||
ICommandUser* Owner;
|
||||
union
|
||||
{
|
||||
struct
|
||||
{
|
||||
UINT8 Priority;
|
||||
UINT8 SubPriority;
|
||||
UINT8 Flags;
|
||||
UINT8 Type;
|
||||
};
|
||||
UINT32 CommandInfo;
|
||||
};
|
||||
};
|
||||
|
||||
struct CommandExecuteResult
|
||||
{
|
||||
enum Enumeration
|
||||
{
|
||||
None, // Execution done, proceed to the next Command
|
||||
RetrySubChain, // Execution should start from a previous "SubChainStart"-flagged Command
|
||||
RetrySubChainSkipHead // Equal to the above result but skips the as "SubChainStart"-flagged Command
|
||||
};
|
||||
};
|
||||
|
||||
|
||||
struct IRenderCommandNode;
|
||||
struct ICommandBuffer;
|
||||
struct __declspec(novtable) ICommandUser
|
||||
{
|
||||
virtual ~ICommandUser() {}
|
||||
|
||||
virtual const std::vector<Command*>& GetCommands() const = 0;
|
||||
virtual CommandExecuteResult::Enumeration ExecuteCommand(unsigned char argCommandType, ICommandBuffer& argCurrentBuffer, uint32 argCurrentPositon) = 0;
|
||||
|
||||
virtual void AssignToRenderCommandNode(IRenderCommandNode& argNode) = 0;
|
||||
virtual void UnassignFromRenderCommandNode(IRenderCommandNode& argNode) = 0;
|
||||
|
||||
// Commands should be applied before all following commands
|
||||
virtual bool get_IsPreconditionForNextCommands() const = 0;
|
||||
|
||||
virtual string8 get_UserName() const;
|
||||
};
|
||||
|
||||
|
||||
struct __declspec(novtable) ICommandBuffer
|
||||
{
|
||||
virtual ~ICommandBuffer() {}
|
||||
|
||||
virtual void Clear() = 0;
|
||||
|
||||
virtual void AddCommand(Command& argCommand) = 0;
|
||||
|
||||
virtual void Perform(bool argUseOptimizedList) = 0;
|
||||
|
||||
virtual void Optimize() = 0;
|
||||
|
||||
virtual void AddChildCommandBuffer(ICommandBuffer& argCommandBuffer) = 0;
|
||||
virtual void RemoveChildCommandBuffer(ICommandBuffer& argCommandBuffer) = 0;
|
||||
|
||||
virtual std::vector<Command*>& get_BufferedCommands() = 0;
|
||||
|
||||
virtual const std::vector<ICommandBuffer*>& get_ChildCommandBuffers() const = 0;
|
||||
|
||||
virtual ICommandBuffer* get_ParentBuffer() const = 0;
|
||||
virtual void set_ParentBuffer(ICommandBuffer* ar_CommandBuffer_) = 0;
|
||||
};
|
||||
30
aiwaz/Aiwaz/Interfaces/ICommonObjectFactory.h
Normal file
30
aiwaz/Aiwaz/Interfaces/ICommonObjectFactory.h
Normal file
@@ -0,0 +1,30 @@
|
||||
#pragma once
|
||||
|
||||
#include "IPingPongBuffer.h"
|
||||
|
||||
struct CommonCubeVertex
|
||||
{
|
||||
D3DXVECTOR3 Pos;
|
||||
D3DXVECTOR3 Normal;
|
||||
D3DXVECTOR3 Tangent;
|
||||
D3DXVECTOR2 Tex;
|
||||
};
|
||||
|
||||
|
||||
struct CommonQuadVertex
|
||||
{
|
||||
D3DXVECTOR3 Pos;
|
||||
D3DXVECTOR3 Normal;
|
||||
D3DXVECTOR2 Tex;
|
||||
};
|
||||
|
||||
|
||||
struct IGeometryBuffer;
|
||||
struct __declspec(novtable) ICommonObjectFactory
|
||||
{
|
||||
virtual ~ICommonObjectFactory() {}
|
||||
|
||||
virtual IPingPongBuffer* CreatePingPongBuffer(ITexture& argInputTexture, const PingPongBufferDescription& argDescriptor) = 0;
|
||||
virtual IGeometryBuffer* CreateCube(float argWidth, float argHeight, float argDepth, bool argInverted, const string8& argName = "") = 0;
|
||||
virtual IGeometryBuffer* CreateQuad(float argWidth, float argHeight, bool argTwoSided, const string8& argName = "") = 0;
|
||||
};
|
||||
70
aiwaz/Aiwaz/Interfaces/IDeviceEnumerator.h
Normal file
70
aiwaz/Aiwaz/Interfaces/IDeviceEnumerator.h
Normal file
@@ -0,0 +1,70 @@
|
||||
#pragma once
|
||||
|
||||
#include "Resource.h"
|
||||
#include <vector>
|
||||
|
||||
|
||||
struct IOutputDevice;
|
||||
struct IDisplayAdapter;
|
||||
struct IDisplayMode;
|
||||
|
||||
|
||||
struct __declspec(novtable) IDeviceEnumerator
|
||||
{
|
||||
virtual ~IDeviceEnumerator() {}
|
||||
virtual bool get_HasEnumerated() const = 0;
|
||||
virtual const std::vector<IDisplayAdapter*>& get_DeviceAdapters() const = 0;
|
||||
|
||||
virtual bool TryEnumerate(uint32 argDesiredWidth = 0, uint32 argDesiredHeight = 0, uint32 argDesiredRefreshRate = 0, DataFormat::Enumeration argDesiredFormat = DataFormat::Unknown) = 0;
|
||||
virtual IDisplayAdapter* FindBestAdapter(bool argAllowToEnumerate = false, uint32 argDesiredWidth = 0, uint32 argDesiredHeight = 0, uint32 argDesiredRefreshRate = 0, DataFormat::Enumeration argDesiredFormat = DataFormat::Unknown) = 0;
|
||||
virtual IOutputDevice* FindBestOutput(bool argAllowToEnumerate = false, uint32 argDesiredWidth = 0, uint32 argDesiredHeight = 0, uint32 argDesiredRefreshRate = 0, DataFormat::Enumeration argDesiredFormat = DataFormat::Unknown) = 0;
|
||||
virtual IDisplayMode* FindBestDisplayMode(bool argAllowToEnumerate = false, uint32 argDesiredWidth = 0, uint32 argDesiredHeight = 0, uint32 argDesiredRefreshRate = 0, DataFormat::Enumeration argDesiredFormat = DataFormat::Unknown) = 0;
|
||||
|
||||
virtual void Verbose() = 0;
|
||||
};
|
||||
|
||||
|
||||
struct IDXGIAdapter;
|
||||
struct __declspec(novtable) IDisplayAdapter
|
||||
{
|
||||
virtual ~IDisplayAdapter() {}
|
||||
|
||||
virtual size_t get_DedicatedSystemMemory() const = 0;
|
||||
virtual size_t get_DedicatedVideoMemory() const = 0;
|
||||
virtual size_t get_SharedSystemMemory() const = 0;
|
||||
virtual const std::vector<IOutputDevice*>& get_DeviceOutputs() const = 0;
|
||||
virtual bool get_HasEnumerated() const = 0;
|
||||
virtual IDXGIAdapter* get_Adapter() const = 0;
|
||||
|
||||
virtual string16 get_Name() const = 0;
|
||||
virtual bool TryEnumerate(uint32 argDesiredWidth = 0, uint32 argDesiredHeight = 0, uint32 argDesiredRefreshRate = 0, DataFormat::Enumeration argDesiredFormat = DataFormat::Unknown) = 0;
|
||||
virtual IOutputDevice* FindBestOutput(bool argAllowToEnumerate = false, uint32 argDesiredWidth = 0, uint32 argDesiredHeight = 0, uint32 argDesiredRefreshRate = 0, DataFormat::Enumeration argDesiredFormat = DataFormat::Unknown) = 0;
|
||||
virtual IDisplayMode* FindBestDisplayMode(bool argAllowToEnumerate = false, uint32 argDesiredWidth = 0, uint32 argDesiredHeight = 0, uint32 argDesiredRefreshRate = 0, DataFormat::Enumeration argDesiredFormat = DataFormat::Unknown) = 0;
|
||||
};
|
||||
|
||||
|
||||
struct __declspec(novtable) IOutputDevice
|
||||
{
|
||||
virtual ~IOutputDevice() {}
|
||||
|
||||
virtual bool get_IsAttachedToDesktop() const = 0;
|
||||
virtual HMONITOR get_MonitorHandle() const = 0;
|
||||
virtual RECT get_DesktopCoordinates() const = 0;
|
||||
virtual const std::vector<IDisplayMode*>& get_DisplayModes() const = 0;
|
||||
virtual bool get_HasEnumerated() const = 0;
|
||||
|
||||
virtual bool TryEnumerate(uint32 argDesiredWidth = 0, uint32 argDesiredHeight = 0, uint32 argDesiredRefreshRate = 0, DataFormat::Enumeration argDesiredFormat = DataFormat::Unknown) = 0;
|
||||
virtual IDisplayMode* FindBestDisplayMode(bool argAllowToEnumerate = false, uint32 argDesiredWidth = 0, uint32 argDesiredHeight = 0, uint32 argDesiredRefreshRate = 0, DataFormat::Enumeration argDesiredFormat = DataFormat::Unknown) = 0;
|
||||
virtual string16 get_Name() const = 0;
|
||||
};
|
||||
|
||||
|
||||
struct __declspec(novtable) IDisplayMode
|
||||
{
|
||||
virtual ~IDisplayMode() {}
|
||||
|
||||
virtual uint32 get_Width() const = 0;
|
||||
virtual uint32 get_Height() const = 0;
|
||||
virtual uint32 get_RefreshRate() const = 0;
|
||||
virtual DataFormat::Enumeration get_Format() const = 0;
|
||||
};
|
||||
41
aiwaz/Aiwaz/Interfaces/IEngine.h
Normal file
41
aiwaz/Aiwaz/Interfaces/IEngine.h
Normal file
@@ -0,0 +1,41 @@
|
||||
#pragma once
|
||||
|
||||
struct IDisplayAdapter;
|
||||
struct IResourceFactory;
|
||||
struct ICommonObjectFactory;
|
||||
struct IFileSystem;
|
||||
struct IShader;
|
||||
struct IRenderTargetBase;
|
||||
struct IGeometryBuffer;
|
||||
struct ITimeline;
|
||||
struct IAnimationManager;
|
||||
|
||||
struct EngineStates
|
||||
{
|
||||
IShader* LastShader;
|
||||
IRenderTargetBase* LastRenderTarget;
|
||||
IGeometryBuffer* LastVertexBufferProvider;
|
||||
IGeometryBuffer* LastIndexBufferProvider;
|
||||
};
|
||||
|
||||
struct __declspec(novtable) IEngine
|
||||
{
|
||||
virtual ~IEngine() {}
|
||||
|
||||
virtual void Initialize(IDisplayAdapter* ar_Adapter_ = NULL) = 0;
|
||||
virtual void Uninitialize() = 0;
|
||||
|
||||
virtual bool get_IsInitialized() const = 0;
|
||||
virtual bool get_IsUsingReferenceDriver() const = 0;
|
||||
|
||||
virtual IResourceFactory& get_ResourceFactory() const = 0;
|
||||
virtual ICommonObjectFactory& get_CommonObjectFactory() const = 0;
|
||||
virtual IFileSystem& get_FileSystem() const = 0;
|
||||
virtual ITimeline& get_Timeline() const = 0;
|
||||
virtual IAnimationManager& get_AnimationManager() const = 0;
|
||||
|
||||
virtual ID3D10Device& get_DX10Device() const = 0;
|
||||
virtual IDXGIFactory& get_DXGIFactory() const = 0;
|
||||
|
||||
virtual EngineStates& get_EngineStates() = 0;
|
||||
};
|
||||
34
aiwaz/Aiwaz/Interfaces/IFileSystem.h
Normal file
34
aiwaz/Aiwaz/Interfaces/IFileSystem.h
Normal file
@@ -0,0 +1,34 @@
|
||||
#pragma once
|
||||
|
||||
|
||||
struct __declspec(novtable) IFile
|
||||
{
|
||||
virtual ~IFile() {};
|
||||
|
||||
virtual char* get_Buffer() = 0;
|
||||
virtual unsigned int get_BufferLength() = 0;
|
||||
virtual void SaveAs(string16 argFileName) = 0;
|
||||
|
||||
virtual std::string ReadString() = 0;
|
||||
virtual float ReadFloat() = 0;
|
||||
virtual int ReadInt() = 0;
|
||||
virtual void* ReadDataArray(unsigned int argBytes) = 0;
|
||||
|
||||
virtual void RewindFilePointer() = 0;
|
||||
virtual char* get_FilePointer() const = 0;
|
||||
virtual void set_FilePointer(char* ac_Position_) = 0;
|
||||
virtual bool IsEof() const = 0;
|
||||
|
||||
virtual string16 get_FileName() const = 0;
|
||||
};
|
||||
|
||||
|
||||
struct __declspec(novtable) IFileSystem
|
||||
{
|
||||
virtual ~IFileSystem() {};
|
||||
|
||||
virtual void InitializeFromDirectory(string16 argDirectory = L"data") = 0;
|
||||
virtual void InitializeFromZipFile(string16 argZipFile = L"data.pak") = 0;
|
||||
|
||||
virtual IFile* Open(string16 argFileName) = 0;
|
||||
};
|
||||
170
aiwaz/Aiwaz/Interfaces/IGeometryBuffer.h
Normal file
170
aiwaz/Aiwaz/Interfaces/IGeometryBuffer.h
Normal file
@@ -0,0 +1,170 @@
|
||||
#pragma once
|
||||
#include "Resource.h"
|
||||
|
||||
struct PrimitiveTopology
|
||||
{
|
||||
enum Enumeration
|
||||
{
|
||||
Undefined = 0,
|
||||
PointList = 1,
|
||||
LineList = 2,
|
||||
LineStrip = 3,
|
||||
TriangleList = 4,
|
||||
TriangleStrip = 5,
|
||||
|
||||
LineListAdjacency = 10,
|
||||
LineStripAdjacency = 11,
|
||||
TriangleListAdjacency = 12,
|
||||
TriangleStripAdjacency = 13
|
||||
};
|
||||
};
|
||||
|
||||
|
||||
struct VertexElement
|
||||
{
|
||||
enum Enumeration
|
||||
{
|
||||
Position,
|
||||
PositionT,
|
||||
Normal,
|
||||
Binormal,
|
||||
Tangent,
|
||||
Color,
|
||||
BlendWeight,
|
||||
BlendIndices,
|
||||
Texture2D,
|
||||
Texture3D,
|
||||
Texture4D,
|
||||
PointSize
|
||||
};
|
||||
|
||||
VertexElement(Enumeration argElement, uint32 argNameIndex = 0)
|
||||
: m_NameIndex(argNameIndex)
|
||||
, m_WellKnownFormat(argElement)
|
||||
{
|
||||
switch (argElement)
|
||||
{
|
||||
case PositionT:
|
||||
{
|
||||
m_SemanticName = "POSITIONT";
|
||||
m_ElementFormat = DataFormat::R32G32B32A32_Float;
|
||||
m_Size = 4 * sizeof(float);
|
||||
break;
|
||||
}
|
||||
case Normal:
|
||||
{
|
||||
m_SemanticName = "NORMAL";
|
||||
m_ElementFormat = DataFormat::R32G32B32_Float;
|
||||
m_Size = 3 * sizeof(float);
|
||||
break;
|
||||
}
|
||||
case Binormal:
|
||||
{
|
||||
m_SemanticName = "BINORMAL";
|
||||
m_ElementFormat = DataFormat::R32G32B32_Float;
|
||||
m_Size = 3 * sizeof(float);
|
||||
break;
|
||||
}
|
||||
case Tangent:
|
||||
{
|
||||
m_SemanticName = "TANGENT";
|
||||
m_ElementFormat = DataFormat::R32G32B32_Float;
|
||||
m_Size = 3 * sizeof(float);
|
||||
break;
|
||||
}
|
||||
case Color:
|
||||
{
|
||||
m_SemanticName = "COLOR";
|
||||
m_ElementFormat = DataFormat::R8G8B8A8_UnsignedNormalized;
|
||||
m_Size = 4 * sizeof(unsigned char);
|
||||
break;
|
||||
}
|
||||
case BlendWeight:
|
||||
{
|
||||
m_SemanticName = "BLENDWEIGHT";
|
||||
m_ElementFormat = DataFormat::R32G32B32A32_Float;
|
||||
m_Size = 4 * sizeof(float);
|
||||
break;
|
||||
}
|
||||
case BlendIndices:
|
||||
{
|
||||
m_SemanticName = "BLENDINDICES";
|
||||
m_ElementFormat = DataFormat::R32G32B32A32_SignedInteger;
|
||||
m_Size = 4 * sizeof(int);
|
||||
break;
|
||||
}
|
||||
case Texture2D:
|
||||
{
|
||||
m_SemanticName = "TEXCOORD";
|
||||
m_ElementFormat = DataFormat::R32G32_Float;
|
||||
m_Size = 2 * sizeof(float);
|
||||
break;
|
||||
}
|
||||
case Texture3D:
|
||||
{
|
||||
m_SemanticName = "TEXCOORD";
|
||||
m_ElementFormat = DataFormat::R32G32B32_Float;
|
||||
m_Size = 3 * sizeof(float);
|
||||
break;
|
||||
}
|
||||
case Texture4D:
|
||||
{
|
||||
m_SemanticName = "TEXCOORD";
|
||||
m_ElementFormat = DataFormat::R32G32B32A32_Float;
|
||||
m_Size = 4 * sizeof(float);
|
||||
break;
|
||||
}
|
||||
case PointSize:
|
||||
{
|
||||
m_SemanticName = "PSIZE";
|
||||
m_ElementFormat = DataFormat::R32_Float;
|
||||
m_Size = 1 * sizeof(float);
|
||||
break;
|
||||
}
|
||||
case Position:
|
||||
default:
|
||||
{
|
||||
m_SemanticName = "POSITION";
|
||||
m_ElementFormat = DataFormat::R32G32B32_Float;
|
||||
m_Size = 3 * sizeof(float);
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
string8 m_SemanticName;
|
||||
DataFormat::Enumeration m_ElementFormat;
|
||||
Enumeration m_WellKnownFormat;
|
||||
uint32 m_NameIndex;
|
||||
uint32 m_Size;
|
||||
};
|
||||
|
||||
|
||||
struct __declspec(novtable) IGeometryBuffer
|
||||
{
|
||||
virtual ~IGeometryBuffer() {}
|
||||
virtual void SetVertexData(uint32 argVertexCount, uint32 argVertexElementSize, void* a_VertexData_, const std::vector<VertexElement>& argVertexElements, bool argNeedsDynamicAccess) = 0;
|
||||
virtual void DeleteVertexData() = 0;
|
||||
virtual void SetIndexData(uint32 argIndexCount, uint32* aui_IndexData_, bool argNeedsDynamicAccess) = 0;
|
||||
virtual void DeleteIndexData() = 0;
|
||||
|
||||
virtual void* MapVertexBuffer(DataAccessMode::Enumeration argAccessMode) = 0;
|
||||
virtual void UnmapVertexBuffer() = 0;
|
||||
|
||||
virtual uint32* MapIndexBuffer(DataAccessMode::Enumeration argAccessMode) = 0;
|
||||
virtual void UnmapIndexBuffer() = 0;
|
||||
|
||||
virtual uint32 get_IndexBufferOffset() const = 0;
|
||||
virtual void set_IndexBufferOffset(uint32 argValue) = 0;
|
||||
virtual uint32 get_IndexBufferUsableLength() const = 0;
|
||||
virtual void set_IndexBufferUsableLength(uint32 argValue) = 0;
|
||||
|
||||
virtual uint32 get_IndexBufferLength() const = 0;
|
||||
virtual uint32 get_VertexBufferLength() const = 0;
|
||||
|
||||
//virtual ICollisionHull get_CollisionHull() const = 0;
|
||||
virtual PrimitiveTopology::Enumeration get_PrimitiveTopology() const = 0;
|
||||
virtual void set_PrimitiveTopology(PrimitiveTopology::Enumeration argValue) = 0;
|
||||
|
||||
virtual void ConvertToAdjacency() = 0;
|
||||
};
|
||||
40
aiwaz/Aiwaz/Interfaces/IPingPongBuffer.h
Normal file
40
aiwaz/Aiwaz/Interfaces/IPingPongBuffer.h
Normal file
@@ -0,0 +1,40 @@
|
||||
#pragma once
|
||||
#include "Resource.h"
|
||||
|
||||
struct PingPongBufferDescription
|
||||
{
|
||||
PingPongBufferDescription()
|
||||
{
|
||||
LoopCount = 0;
|
||||
TextureWidth = 0;
|
||||
TextureHeight = 0;
|
||||
TextureFormat = DataFormat::Unknown;
|
||||
}
|
||||
|
||||
uint32 LoopCount;
|
||||
string16 ShaderFileName;
|
||||
string8 ShaderTechniqueA;
|
||||
string8 ShaderTechniqueB;
|
||||
string8 PreProcessShaderTechnique;
|
||||
|
||||
uint32 TextureWidth;
|
||||
uint32 TextureHeight;
|
||||
DataFormat::Enumeration TextureFormat;
|
||||
};
|
||||
|
||||
struct ITexture;
|
||||
struct IRenderCommandNode;
|
||||
|
||||
interface IPingPongBuffer
|
||||
{
|
||||
virtual ~IPingPongBuffer() {}
|
||||
virtual ITexture& get_InputTexture() const = 0;
|
||||
virtual void set_InputTexture(ITexture& argTexture) = 0;
|
||||
|
||||
virtual ITexture& get_OutputTexture() const = 0;
|
||||
|
||||
virtual const PingPongBufferDescription& get_Descriptor() const = 0;
|
||||
virtual void set_Descriptor(const PingPongBufferDescription& argValue) = 0;
|
||||
virtual IRenderCommandNode& get_RootNode() const = 0;
|
||||
virtual IRenderCommandNode& get_PreProcessNode() const = 0;
|
||||
};
|
||||
53
aiwaz/Aiwaz/Interfaces/IRenderCommandNode.h
Normal file
53
aiwaz/Aiwaz/Interfaces/IRenderCommandNode.h
Normal file
@@ -0,0 +1,53 @@
|
||||
#pragma once
|
||||
|
||||
#include "ICommandUser.h"
|
||||
|
||||
struct __declspec(novtable) IRenderCommandNode
|
||||
{
|
||||
virtual ~IRenderCommandNode() {}
|
||||
|
||||
virtual const std::vector<ICommandUser*> get_CommandUsers() const = 0;
|
||||
|
||||
virtual void set_Parent(IRenderCommandNode* ar_Node_) = 0;
|
||||
virtual IRenderCommandNode* get_Parent() const = 0;
|
||||
|
||||
virtual bool IsDirty() const = 0;
|
||||
virtual void MarkDirty() = 0;
|
||||
|
||||
virtual void AddCommandUser(ICommandUser& argCommandUser) = 0;
|
||||
virtual void RemoveCommandUser(ICommandUser& argCommandUser) = 0;
|
||||
virtual void ReplaceCommandUser(ICommandUser& argWhatCommandUser, ICommandUser& argWhithCommandUser) = 0;
|
||||
|
||||
virtual void ProcessCommands() = 0;
|
||||
};
|
||||
|
||||
struct ICommandBuffer;
|
||||
struct __declspec(novtable) IRenderCommandNodeInternal
|
||||
{
|
||||
virtual ~IRenderCommandNodeInternal() {}
|
||||
|
||||
virtual void GenerateDeviceCommands() = 0;
|
||||
virtual ICommandBuffer* get_CommandBuffer() const = 0;
|
||||
};
|
||||
|
||||
|
||||
// Helper functions
|
||||
template<typename T> void AddToNode(IRenderCommandNode& commandNode, T& commandUser)
|
||||
{
|
||||
commandNode.AddCommandUser(dynamic_cast<ICommandUser&>(commandUser));
|
||||
}
|
||||
|
||||
template<typename T> void AddToNode(IRenderCommandNode& commandNode, T* commandUser)
|
||||
{
|
||||
commandNode.AddCommandUser(dynamic_cast<ICommandUser&>(*commandUser));
|
||||
}
|
||||
|
||||
template<typename T> void RemoveFromNode(IRenderCommandNode& commandNode, T& commandUser)
|
||||
{
|
||||
commandNode.RemoveCommandUser(dynamic_cast<ICommandUser&>(commandUser));
|
||||
}
|
||||
|
||||
template<typename T> void RemoveFromNode(IRenderCommandNode& commandNode, T* commandUser)
|
||||
{
|
||||
commandNode.RemoveCommandUser(dynamic_cast<ICommandUser&>(*commandUser));
|
||||
}
|
||||
74
aiwaz/Aiwaz/Interfaces/IRenderTargetBase.h
Normal file
74
aiwaz/Aiwaz/Interfaces/IRenderTargetBase.h
Normal file
@@ -0,0 +1,74 @@
|
||||
#pragma once
|
||||
|
||||
#include "Resource.h"
|
||||
|
||||
|
||||
struct ViewPort
|
||||
{
|
||||
ViewPort()
|
||||
: m_TopLeftX(0)
|
||||
, m_TopLeftY(0)
|
||||
, m_Width(0)
|
||||
, m_Height(0)
|
||||
, m_MinDepth(0.0f)
|
||||
, m_MaxDepth(1.0f)
|
||||
{
|
||||
}
|
||||
|
||||
int m_TopLeftX;
|
||||
int m_TopLeftY;
|
||||
uint32 m_Width;
|
||||
uint32 m_Height;
|
||||
float m_MinDepth;
|
||||
float m_MaxDepth;
|
||||
};
|
||||
|
||||
struct BindFlags
|
||||
{
|
||||
enum Enumeration
|
||||
{
|
||||
ClearDepthStencil = 0x001,
|
||||
ClearColor = 0x002,
|
||||
ClearAll = 0x00F,
|
||||
BindAdditionalTexture0 = 0x010,
|
||||
BindAdditionalTexture1 = 0x020,
|
||||
BindAdditionalTexture2 = 0x040,
|
||||
BindAdditionalTexture3 = 0x080,
|
||||
BindBaseTexture = 0x100,
|
||||
BindAllTextures = 0xFF0,
|
||||
Default = ClearAll | BindAllTextures
|
||||
};
|
||||
};
|
||||
|
||||
struct __declspec(novtable) IRenderTargetBase
|
||||
{
|
||||
virtual ~IRenderTargetBase() {}
|
||||
|
||||
virtual void set_ClearDepth(float argValue) = 0;
|
||||
virtual float get_ClearDepth() const = 0;
|
||||
|
||||
virtual void set_ClearStencil(unsigned char argValue) = 0;
|
||||
virtual unsigned char get_ClearStencil() const = 0;
|
||||
|
||||
virtual void set_ClearColor(const D3DXCOLOR& argValue) = 0;
|
||||
virtual D3DXCOLOR get_ClearColor() const = 0;
|
||||
|
||||
virtual void set_ViewPort(const ViewPort& argValue) = 0;
|
||||
virtual ViewPort get_ViewPort() const = 0;
|
||||
|
||||
virtual uint32 get_RenderTargetWidth() const = 0;
|
||||
virtual uint32 get_RenderTargetHeight() const = 0;
|
||||
virtual DataFormat::Enumeration get_RenderTargetFormat() const = 0;
|
||||
|
||||
virtual void set_HasDepthStencilBuffer(bool argState) = 0;
|
||||
virtual bool get_HasDepthStencilBuffer() const = 0;
|
||||
|
||||
virtual void AddAdditionalRenderTarget(IRenderTargetBase& argTarget) = 0;
|
||||
virtual void RemoveAdditionalRenderTarget(IRenderTargetBase& argTarget) = 0;
|
||||
|
||||
virtual ID3D10RenderTargetView* get_DX10RenderTargetView() const = 0;
|
||||
virtual ID3D10DepthStencilView* get_DX10DepthStencilView() const = 0;
|
||||
|
||||
virtual void Bind(DWORD argBindFlags = BindFlags::Default) = 0;
|
||||
virtual void UnbindAllRenderTargets() = 0;
|
||||
};
|
||||
13
aiwaz/Aiwaz/Interfaces/IRenderTargetTexture.h
Normal file
13
aiwaz/Aiwaz/Interfaces/IRenderTargetTexture.h
Normal file
@@ -0,0 +1,13 @@
|
||||
#pragma once
|
||||
#include "Resource.h"
|
||||
|
||||
struct ITexture;
|
||||
struct IRenderTargetBase;
|
||||
struct __declspec(novtable) IRenderTargetTexture
|
||||
{
|
||||
virtual void SetTextureParameters(uint32 argWidth, uint32 argHeight, DataFormat::Enumeration argFormat, uint32 argMultiSampleCount = 1, uint32 argMultiSampleQuality = 0) = 0;
|
||||
virtual void Resize(int argWidth, int argHeight) = 0;
|
||||
virtual ITexture& get_TextureResource() const = 0;
|
||||
|
||||
virtual IRenderTargetBase& get_Base() = 0;
|
||||
};
|
||||
79
aiwaz/Aiwaz/Interfaces/IResourceFactory.h
Normal file
79
aiwaz/Aiwaz/Interfaces/IResourceFactory.h
Normal file
@@ -0,0 +1,79 @@
|
||||
#pragma once
|
||||
|
||||
#include "ISwapChain.h"
|
||||
#include "IGeometryBuffer.h"
|
||||
#include "IShader.h"
|
||||
#include "IRenderCommandNode.h"
|
||||
#include "IShaderParameterCollection.h"
|
||||
#include "ITexture.h"
|
||||
#include "ITransformation.h"
|
||||
#include "ITransformationAnimation.h"
|
||||
#include "IRenderTargetTexture.h"
|
||||
#include "ICamera.h"
|
||||
#include "IBone.h"
|
||||
#include "IWindow.h"
|
||||
|
||||
|
||||
struct __declspec(novtable) IResourceFactory
|
||||
{
|
||||
virtual ~IResourceFactory() {}
|
||||
|
||||
virtual ITransformationAnimation& CreateTransformationAnimation() = 0;
|
||||
virtual void DeleteTransformationAnimation(ITransformationAnimation& argValue, bool argRemoveOnly = false) = 0;
|
||||
|
||||
virtual IWindow& CreateSwapChainWindow() = 0;
|
||||
virtual void DeleteSwapChainWindow(IWindow& argValue, bool argRemoveOnly = false) = 0;
|
||||
|
||||
virtual IRenderCommandNode& CreateRenderCommandNode() = 0;
|
||||
virtual void DeleteRenderCommandNode(IRenderCommandNode& argValue, bool argRemoveOnly = false) = 0;
|
||||
|
||||
virtual IShader* FindShader(const string8& argId) = 0;
|
||||
virtual IShader& CreateOrFindShader(const string8& argId = "") = 0;
|
||||
virtual void DeleteShader(IShader& argValue, bool argRemoveOnly = false) = 0;
|
||||
|
||||
virtual IInternalShader* FindInternalShader(const string8& argId) = 0;
|
||||
virtual IInternalShader& CreateOrFindInternalShader(const string8& argId = "") = 0;
|
||||
virtual void DeleteInternalShader(IInternalShader& argValue, bool argRemoveOnly = false) = 0;
|
||||
|
||||
virtual ISwapChain* FindSwapChain(const string8& argId) = 0;
|
||||
virtual ISwapChain& CreateOrFindSwapChain(const string8& argId = "") = 0;
|
||||
virtual void DeleteSwapChain(ISwapChain& argValue, bool argRemoveOnly = false) = 0;
|
||||
|
||||
virtual IRenderTargetTexture* FindRenderTargetTexture(const string8& argId) = 0;
|
||||
virtual IRenderTargetTexture& CreateOrFindRenderTargetTexture(const string8& argId = "") = 0;
|
||||
virtual void DeleteRenderTargetTexture(IRenderTargetTexture& argValue, bool argRemoveOnly = false) = 0;
|
||||
|
||||
virtual IGeometryBuffer* FindGeometryBuffer(const string8& argId) = 0;
|
||||
virtual IGeometryBuffer& CreateOrFindGeometryBuffer(const string8& argId = "") = 0;
|
||||
virtual void DeleteGeometryBuffer(IGeometryBuffer& argValue, bool argRemoveOnly = false) = 0;
|
||||
|
||||
virtual IShaderParameterCollection* FindShaderParameterCollection(const string8& argId) = 0;
|
||||
virtual IShaderParameterCollection& CreateOrFindShaderParameterCollection(const string8& argId = "") = 0;
|
||||
virtual void DeleteShaderParameterCollection(IShaderParameterCollection& argValue, bool argRemoveOnly = false) = 0;
|
||||
|
||||
virtual ITexture* FindTexture(const string8& argId) = 0;
|
||||
virtual ITexture& CreateOrFindTexture(const string8& argId = "") = 0;
|
||||
virtual void DeleteTexture(ITexture& argValue, bool argRemoveOnly = false) = 0;
|
||||
|
||||
virtual ITransformation* FindTransformation(const string8& argId) = 0;
|
||||
virtual ITransformation& CreateOrFindTransformation(const string8& argId = "") = 0;
|
||||
virtual void DeleteTransformation(ITransformation& argValue, bool argRemoveOnly = false) = 0;
|
||||
|
||||
virtual IPerspectiveCamera* FindPerspectiveCamera(const string8& argId) = 0;
|
||||
virtual IPerspectiveCamera& CreateOrFindPerspectiveCamera(const string8& argId = "") = 0;
|
||||
virtual void DeletePerspectiveCamera(IPerspectiveCamera& argValue, bool argRemoveOnly = false) = 0;
|
||||
|
||||
virtual IOrthographicCamera* FindOrthographicCamera(const string8& argId) = 0;
|
||||
virtual IOrthographicCamera& CreateOrFindOrthographicCamera(const string8& argId = "") = 0;
|
||||
virtual void DeleteOrthographicCamera(IOrthographicCamera& argValue, bool argRemoveOnly = false) = 0;
|
||||
|
||||
virtual IBone* FindBone(const string8& argId) = 0;
|
||||
virtual IBone& CreateOrFindBone(const string8& argId = "") = 0;
|
||||
virtual void DeleteBone(IBone& argValue, bool argRemoveOnly = false) = 0;
|
||||
|
||||
virtual IBoneController* FindBoneController(const string8& argId) = 0;
|
||||
virtual IBoneController& CreateOrFindBoneController(const string8& argId = "") = 0;
|
||||
virtual void DeleteBoneController(IBoneController& argValue, bool argRemoveOnly = false) = 0;
|
||||
|
||||
virtual bool HasCreatedResource() = 0;
|
||||
};
|
||||
33
aiwaz/Aiwaz/Interfaces/IShader.h
Normal file
33
aiwaz/Aiwaz/Interfaces/IShader.h
Normal file
@@ -0,0 +1,33 @@
|
||||
#pragma once
|
||||
|
||||
|
||||
struct IFile;
|
||||
struct __declspec(novtable) IInternalShader
|
||||
{
|
||||
virtual ~IInternalShader() {}
|
||||
virtual void LoadFromFile(const string16& argValue) = 0;
|
||||
|
||||
virtual ID3D10Effect* get_DX10Effect() const = 0;
|
||||
};
|
||||
|
||||
|
||||
struct __declspec(novtable) IShader
|
||||
{
|
||||
virtual ~IShader() {}
|
||||
|
||||
virtual void LoadFromFile(const string16& argValue) = 0;
|
||||
|
||||
virtual string8 get_TechniqueName() const = 0;
|
||||
virtual void set_TechniqueName(const string8& argValue) = 0;
|
||||
|
||||
virtual ID3D10EffectTechnique* get_DX10Technique() const = 0;
|
||||
|
||||
virtual IInternalShader* get_InternalShader() const = 0;
|
||||
|
||||
virtual bool TryApplyNextPass() = 0;
|
||||
virtual void ApplyFirstPass() = 0;
|
||||
virtual uint32 get_CurrentRenderPass() const = 0;
|
||||
|
||||
virtual void set_Priority(unsigned char argValue) = 0;
|
||||
virtual unsigned char get_Priority() const = 0;
|
||||
};
|
||||
42
aiwaz/Aiwaz/Interfaces/IShaderParameterCollection.h
Normal file
42
aiwaz/Aiwaz/Interfaces/IShaderParameterCollection.h
Normal file
@@ -0,0 +1,42 @@
|
||||
#pragma once
|
||||
|
||||
struct ParameterBindType
|
||||
{
|
||||
enum Enumeration
|
||||
{
|
||||
BindBySemantic,
|
||||
BindByVariable
|
||||
};
|
||||
};
|
||||
|
||||
struct __declspec(novtable) IShaderParameter
|
||||
{
|
||||
virtual ParameterBindType::Enumeration get_ParameterNameType() const = 0;
|
||||
virtual void set_ParameterNameType(ParameterBindType::Enumeration argBindType) = 0;
|
||||
virtual void ApplyValue(ID3D10EffectVariable& argVariable) = 0;
|
||||
};
|
||||
|
||||
|
||||
struct ITexture;
|
||||
struct __declspec(novtable) IShaderParameterCollection
|
||||
{
|
||||
virtual ~IShaderParameterCollection() {}
|
||||
|
||||
virtual bool get_IsPreconditionForFollowingShaders() const = 0;
|
||||
virtual void set_IsPreconditionForFollowingShaders(bool argValue) = 0;
|
||||
|
||||
virtual void SetParameter(const string8& argParameterName,IShaderParameter* ar_Parameter_) = 0;
|
||||
virtual void SetParameter(const string8& argParameterName, ITexture& argParameter, ParameterBindType::Enumeration argParamNameType = ParameterBindType::BindBySemantic) = 0;
|
||||
virtual void SetParameter(const string8& argParameterName, float* af_Parameter_, ParameterBindType::Enumeration argParamNameType = ParameterBindType::BindBySemantic) = 0;
|
||||
virtual void SetParameter(const string8& argParameterName, float argParameter, ParameterBindType::Enumeration argParamNameType = ParameterBindType::BindBySemantic) = 0;
|
||||
virtual void SetParameter(const string8& argParameterName, D3DXVECTOR3* ar_Parameter_, ParameterBindType::Enumeration argParamNameType = ParameterBindType::BindBySemantic) = 0;
|
||||
virtual void SetParameter(const string8& argParameterName, const D3DXVECTOR3& argParameter, ParameterBindType::Enumeration argParamNameType = ParameterBindType::BindBySemantic) = 0;
|
||||
virtual void SetParameter(const string8& argParameterName, D3DXVECTOR4* ar_Parameter_, ParameterBindType::Enumeration argParamNameType = ParameterBindType::BindBySemantic) = 0;
|
||||
virtual void SetParameter(const string8& argParameterName, const D3DXVECTOR4& argParameter, ParameterBindType::Enumeration argParamNameType = ParameterBindType::BindBySemantic) = 0;
|
||||
virtual void SetParameter(const string8& argParameterName, D3DXMATRIX* argParameter, ParameterBindType::Enumeration argParamNameType = ParameterBindType::BindBySemantic) = 0;
|
||||
virtual void SetParameter(const string8& argParameterName, const D3DXMATRIX& argParameter, ParameterBindType::Enumeration argParamNameType = ParameterBindType::BindBySemantic) = 0;
|
||||
virtual void SetParameter(const string8& argParameterName, bool* ab_Parameter_, ParameterBindType::Enumeration argParamNameType = ParameterBindType::BindBySemantic) = 0;
|
||||
virtual void SetParameter(const string8& argParameterName, bool argParameter, ParameterBindType::Enumeration argParamNameType = ParameterBindType::BindBySemantic) = 0;
|
||||
virtual void RemoveParameter(const string8& argParameterName) = 0;
|
||||
|
||||
};
|
||||
20
aiwaz/Aiwaz/Interfaces/ISwapChain.h
Normal file
20
aiwaz/Aiwaz/Interfaces/ISwapChain.h
Normal file
@@ -0,0 +1,20 @@
|
||||
#pragma once
|
||||
|
||||
#include "Resource.h"
|
||||
|
||||
struct IRenderTargetBase;
|
||||
struct __declspec(novtable) ISwapChain
|
||||
{
|
||||
virtual ~ISwapChain() {}
|
||||
|
||||
virtual void SetWindowParameters(HWND argWindowHandle, uint32 argWidth = 0, uint32 argHeight = 0, uint32 argRefreshRate = 0, DataFormat::Enumeration argFormat = DataFormat::Unknown, uint32 argMultiSampleCount = 1, uint32 argMultiSampleQuality = 0) = 0;
|
||||
virtual void Resize(int argWidth, int argHeight) = 0;
|
||||
virtual void Present() = 0;
|
||||
|
||||
virtual bool get_Fullscreen() const = 0;
|
||||
virtual void set_Fullscreen(bool argState) = 0;
|
||||
virtual bool get_VSync() const = 0;
|
||||
virtual void set_VSync(bool argState) = 0;
|
||||
|
||||
virtual IRenderTargetBase& get_Base() = 0;
|
||||
};
|
||||
102
aiwaz/Aiwaz/Interfaces/ITexture.h
Normal file
102
aiwaz/Aiwaz/Interfaces/ITexture.h
Normal file
@@ -0,0 +1,102 @@
|
||||
#pragma once
|
||||
#include "Resource.h"
|
||||
|
||||
|
||||
struct LockedTextureData
|
||||
{
|
||||
void* Data;
|
||||
uint32 RowPitch;
|
||||
};
|
||||
|
||||
|
||||
struct TextureInitialData
|
||||
{
|
||||
TextureInitialData()
|
||||
: Data(NULL)
|
||||
, Pitch(0)
|
||||
, Owner(true)
|
||||
{}
|
||||
|
||||
TextureInitialData(void* Data, uint32 Pitch)
|
||||
: Data(Data)
|
||||
, Pitch(Pitch)
|
||||
, Owner(true)
|
||||
{}
|
||||
|
||||
~TextureInitialData()
|
||||
{
|
||||
if (Owner && Data != NULL)
|
||||
delete [] Data;
|
||||
}
|
||||
|
||||
void* Data;
|
||||
uint32 Pitch;
|
||||
bool Owner;
|
||||
};
|
||||
|
||||
|
||||
struct CreateTextureDescriptor
|
||||
{
|
||||
uint32 Width;
|
||||
uint32 Height;
|
||||
uint32 Elements;
|
||||
uint32 MipLevels;
|
||||
DataFormat::Enumeration Format;
|
||||
DataAccessType::Enumeration AccessType;
|
||||
TextureInitialData* InitialData_;
|
||||
|
||||
static CreateTextureDescriptor AsSingleTexture(uint32 Width, uint32 Height, uint32 MipLevels = 1, DataFormat::Enumeration Format = DataFormat::R8G8B8A8_SignedNormalized, TextureInitialData* InitialData_ = NULL, DataAccessType::Enumeration AccessType = DataAccessType::Dynamic)
|
||||
{
|
||||
CreateTextureDescriptor Desc;
|
||||
|
||||
Desc.Width = Width;
|
||||
Desc.Height = Height;
|
||||
Desc.Elements = 0;
|
||||
Desc.Format = Format;
|
||||
Desc.AccessType = AccessType;
|
||||
Desc.InitialData_ = InitialData_;
|
||||
Desc.MipLevels = MipLevels;
|
||||
|
||||
return Desc;
|
||||
}
|
||||
|
||||
static CreateTextureDescriptor AsArrayTexture(uint32 Width, uint32 Height, uint32 MipLevels = 1, uint32 Elements = 1, DataFormat::Enumeration Format = DataFormat::R8G8B8A8_SignedNormalized, TextureInitialData* InitialData_ = NULL)
|
||||
{
|
||||
CreateTextureDescriptor Desc;
|
||||
|
||||
Desc.Width = Width;
|
||||
Desc.Height = Height;
|
||||
Desc.Elements = Elements;
|
||||
Desc.Format = Format;
|
||||
Desc.AccessType = DataAccessType::Static;
|
||||
Desc.InitialData_ = InitialData_;
|
||||
Desc.MipLevels = MipLevels;
|
||||
|
||||
return Desc;
|
||||
}
|
||||
};
|
||||
|
||||
|
||||
struct IFile;
|
||||
struct __declspec(novtable) ITexture
|
||||
{
|
||||
virtual string8 get_BindingName() const = 0;
|
||||
virtual void set_BindingName(const string8& argName) = 0;
|
||||
|
||||
virtual string16 get_FileName() const = 0;
|
||||
|
||||
virtual uint32 get_TextureWidth() const = 0;
|
||||
virtual uint32 get_TextureHeight() const = 0;
|
||||
virtual uint32 get_TextureArraySize() const = 0;
|
||||
virtual DataFormat::Enumeration get_TextureFormat() const = 0;
|
||||
|
||||
virtual void LoadFromFile(const string16& argFileName, DataAccessType::Enumeration argAccessType = DataAccessType::Static) = 0;
|
||||
virtual void CreateTexture(const CreateTextureDescriptor& argDesc) = 0;
|
||||
virtual LockedTextureData LockTextureBuffer(DataAccessMode::Enumeration argAccessMode, uint32 argArrayElement = 0) = 0;
|
||||
virtual void UnlockTextureBuffer() = 0;
|
||||
|
||||
virtual void CreateRenderTargetTexture(uint32 argWidth, uint32 argHeight, DataFormat::Enumeration argFormat, uint32 argMultiSampleCount, uint32 argMultiSampleQuality) = 0;
|
||||
|
||||
virtual ID3D10ShaderResourceView* get_ResourceViewFromTexture() const = 0;
|
||||
virtual ID3D10Texture2D* get_Texture2D() const = 0;
|
||||
};
|
||||
15
aiwaz/Aiwaz/Interfaces/ITimeLine.h
Normal file
15
aiwaz/Aiwaz/Interfaces/ITimeLine.h
Normal file
@@ -0,0 +1,15 @@
|
||||
#pragma once
|
||||
|
||||
struct __declspec(novtable) ITimeline
|
||||
{
|
||||
virtual ~ITimeline() {};
|
||||
|
||||
virtual double get_DeltaTime() = 0;
|
||||
virtual double get_RealTime() = 0;
|
||||
virtual double get_DemoTime() = 0;
|
||||
|
||||
virtual void set_SpeedAndDirection(double argValue = 1.0) = 0;
|
||||
virtual double get_SpeedAndDirection() = 0;
|
||||
|
||||
virtual void Advance(double argSeconds) = 0;
|
||||
};
|
||||
75
aiwaz/Aiwaz/Interfaces/ITransformation.h
Normal file
75
aiwaz/Aiwaz/Interfaces/ITransformation.h
Normal file
@@ -0,0 +1,75 @@
|
||||
#pragma once
|
||||
|
||||
struct TransformationBindings
|
||||
{
|
||||
static TransformationBindings CreateDefault()
|
||||
{
|
||||
TransformationBindings bindings;
|
||||
bindings.WorldMatrixSemanticName = "WorldMatrix";
|
||||
bindings.LocalMatrixSemanticName = "LocalMatrix";
|
||||
bindings.WorldPositionSemanticName = "WorldPosition";
|
||||
bindings.LocalPositionSemanticName = "LocalPosition";
|
||||
bindings.WorldDirectionSemanticName = "WorldDirection";
|
||||
bindings.LocalDirectionSemanticName = "LocalDirection";
|
||||
bindings.WorldUpDirectionSemanticName = "WorldUpDirection";
|
||||
bindings.LocalUpDirectionSemanticName = "LocalUpDirection";
|
||||
bindings.WorldRightDirectionSemanticName = "WorldUpDirection";
|
||||
bindings.LocalRightDirectionSemanticName = "LocalUpDirection";
|
||||
return bindings;
|
||||
}
|
||||
|
||||
string8 WorldMatrixSemanticName;
|
||||
string8 LocalMatrixSemanticName;
|
||||
|
||||
string8 WorldPositionSemanticName;
|
||||
string8 LocalPositionSemanticName;
|
||||
|
||||
string8 WorldDirectionSemanticName;
|
||||
string8 LocalDirectionSemanticName;
|
||||
|
||||
string8 WorldUpDirectionSemanticName;
|
||||
string8 LocalUpDirectionSemanticName;
|
||||
|
||||
string8 WorldRightDirectionSemanticName;
|
||||
string8 LocalRightDirectionSemanticName;
|
||||
};
|
||||
|
||||
|
||||
struct __declspec(novtable) ITransformation
|
||||
{
|
||||
virtual void set_TransformationBindings(const TransformationBindings& argData) = 0;
|
||||
virtual TransformationBindings get_TransformationBindings() const = 0;
|
||||
|
||||
virtual void set_LocalPosition(const D3DXVECTOR3& argValue) = 0;
|
||||
virtual const D3DXVECTOR3& get_LocalPosition() const = 0;
|
||||
virtual const D3DXVECTOR3& get_WorldPosition() const = 0;
|
||||
|
||||
virtual void set_LocalRotationYPR(const D3DXVECTOR3& argValue) = 0;
|
||||
virtual const D3DXVECTOR3& get_LocalRotationYPR() const = 0;
|
||||
|
||||
virtual void set_LocalRotation(const D3DXQUATERNION& argValue) = 0;
|
||||
virtual const D3DXQUATERNION& get_LocalRotation() const = 0;
|
||||
virtual const D3DXQUATERNION& get_WorldRotation() const = 0;
|
||||
|
||||
virtual const D3DXVECTOR3& get_LocalDirection() const = 0;
|
||||
virtual const D3DXVECTOR3& get_WorldDirection() const = 0;
|
||||
|
||||
virtual const D3DXVECTOR3& get_LocalUpDirection() const = 0;
|
||||
virtual const D3DXVECTOR3& get_WorldUpDirection() const = 0;
|
||||
|
||||
virtual D3DXVECTOR3 get_LocalRightDirection() const = 0;
|
||||
virtual D3DXVECTOR3 get_WorldRightDirection() const = 0;
|
||||
|
||||
virtual void set_LocalScale(const D3DXVECTOR3& argValue) = 0;
|
||||
virtual const D3DXVECTOR3& get_LocalScale() const = 0;
|
||||
virtual const D3DXVECTOR3& get_WorldScale() const = 0;
|
||||
|
||||
virtual const D3DXMATRIX& get_WorldMatrix() const = 0;
|
||||
virtual const D3DXMATRIX& get_LocalMatrix() const = 0;
|
||||
|
||||
virtual void set_TransformationParent(ITransformation* argValue) = 0;
|
||||
virtual ITransformation* get_TransformationParent() const = 0;
|
||||
virtual void AddTransformation(ITransformation& argTransformation) = 0;
|
||||
virtual void RemoveTransformation(ITransformation& argTransformation) = 0;
|
||||
virtual const std::vector<ITransformation*>& get_Transformations() const = 0;
|
||||
};
|
||||
7
aiwaz/Aiwaz/Interfaces/IUpdatable.h
Normal file
7
aiwaz/Aiwaz/Interfaces/IUpdatable.h
Normal file
@@ -0,0 +1,7 @@
|
||||
#pragma once
|
||||
|
||||
struct __declspec(novtable) IUpdatable
|
||||
{
|
||||
virtual void Update(bool argForceUpdate) = 0;
|
||||
virtual bool get_WantsUpdate() const = 0;
|
||||
};
|
||||
30
aiwaz/Aiwaz/Interfaces/IWindow.h
Normal file
30
aiwaz/Aiwaz/Interfaces/IWindow.h
Normal file
@@ -0,0 +1,30 @@
|
||||
#pragma once
|
||||
|
||||
struct ISwapChain;
|
||||
struct __declspec(novtable) __declspec(uuid("{3ABA91B1-9B3E-4ae6-B5EA-EB24E77B6097}")) IWindow
|
||||
{
|
||||
virtual ~IWindow() {};
|
||||
virtual void Initialize(const string16& argTitle, int argWidth, int argHeight, bool argFullscreen) = 0;
|
||||
|
||||
virtual LRESULT ProcessMessage(UINT argMessage, WPARAM argWParam, LPARAM argLParam) = 0;
|
||||
virtual void SwapBuffers() = 0;
|
||||
|
||||
virtual void set_Active(bool argActive) = 0;
|
||||
virtual bool get_Active() = 0;
|
||||
|
||||
virtual void set_Fullscreen(bool argFullscreen) = 0;
|
||||
virtual bool get_Fullscreen() = 0;
|
||||
|
||||
virtual void set_VSync(bool argUseVSync) = 0;
|
||||
virtual bool get_VSync() = 0;
|
||||
|
||||
virtual void set_DeviceContext(HDC argDeviceContext) = 0;
|
||||
virtual HDC get_DeviceContext() = 0;
|
||||
|
||||
virtual void set_Title(const string16& argTitle) = 0;
|
||||
virtual string16 get_Title() = 0;
|
||||
|
||||
virtual HWND get_Handle() = 0;
|
||||
|
||||
virtual ISwapChain& get_SwapChain() const = 0;
|
||||
};
|
||||
506
aiwaz/Aiwaz/Interfaces/Resource.h
Normal file
506
aiwaz/Aiwaz/Interfaces/Resource.h
Normal file
@@ -0,0 +1,506 @@
|
||||
#pragma once
|
||||
|
||||
|
||||
struct DataFormatByteSize
|
||||
{
|
||||
enum Enumeration
|
||||
{
|
||||
Unknown = 0,
|
||||
R32G32B32A32_Typeless = 16,
|
||||
R32G32B32A32_Float = 16,
|
||||
R32G32B32A32_UnsignedInteger = 16,
|
||||
R32G32B32A32_SignedInteger = 16,
|
||||
R32G32B32_Typeless = 12,
|
||||
R32G32B32_Float = 12,
|
||||
R32G32B32_UnsignedInteger = 12,
|
||||
R32G32B32_SignedInteger = 12,
|
||||
R16G16B16A16_Typeless = 8,
|
||||
R16G16B16A16_Float = 8,
|
||||
R16G16B16A16_UnsignedNormalized = 8,
|
||||
R16G16B16A16_UnsignedInteger = 8,
|
||||
R16G16B16A16_SignedNormalized = 8,
|
||||
R16G16B16A16_SignedInteger = 8,
|
||||
R32G32_Typeless = 8,
|
||||
R32G32_Float = 8,
|
||||
R32G32_UnsignedInteger = 8,
|
||||
R32G32_SignedInteger = 8,
|
||||
R32G8X24_Typeless = 8,
|
||||
D32_Float_S8X24_UnsignedInteger = 8,
|
||||
R32_Float_X8X24_Typeless = 8,
|
||||
X32_Typeless_G8X24_UnsignedInteger = 8,
|
||||
R10G10B10A2_Typeless = 4,
|
||||
R10G10B10A2_UnsignedNormalized = 4,
|
||||
R10G10B10A2_UnsignedInteger = 4,
|
||||
R11G11B10_Float = 4,
|
||||
R8G8B8A8_Typeless = 4,
|
||||
R8G8B8A8_UnsignedNormalized = 4,
|
||||
R8G8B8A8_UnsignedNormalized_SRGB = 4,
|
||||
R8G8B8A8_UnsignedInteger = 4,
|
||||
R8G8B8A8_SignedNormalized = 4,
|
||||
R8G8B8A8_SignedInteger = 4,
|
||||
R16G16_Typeless = 4,
|
||||
R16G16_Float = 4,
|
||||
R16G16_UnsignedNormalized = 4,
|
||||
R16G16_UnsignedInteger = 4,
|
||||
R16G16_SignedNormalized = 4,
|
||||
R16G16_SignedInteger = 4,
|
||||
R32_Typeless = 4,
|
||||
D32_Float = 4,
|
||||
R32_Float = 4,
|
||||
R32_UnsignedInteger = 4,
|
||||
R32_SignedInteger = 4,
|
||||
R24G8_Typeless = 4,
|
||||
D24_UnsignedNormalized_S8_UnsignedInteger = 4,
|
||||
R24_UnsignedNormalized_X8_Typeless = 4,
|
||||
X24_Typeless_G8_UnsignedInteger = 4,
|
||||
R8G8_Typeless = 2,
|
||||
R8G8_UnsignedNormalized = 2,
|
||||
R8G8_UnsignedInteger = 2,
|
||||
R8G8_SignedNormalized = 2,
|
||||
R8G8_SignedInteger = 2,
|
||||
R16_Typeless = 2,
|
||||
R16_Float = 2,
|
||||
D16_UnsignedNormalized = 2,
|
||||
R16_UnsignedNormalized = 2,
|
||||
R16_UnsignedInteger = 2,
|
||||
R16_SignedNormalized = 2,
|
||||
R16_SignedInteger = 2,
|
||||
R8_Typeless = 1,
|
||||
R8_UnsignedNormalized = 1,
|
||||
R8_UnsignedInteger = 1,
|
||||
R8_SignedNormalized = 1,
|
||||
R8_SignedInteger = 1,
|
||||
A8_UnsignedNormalized = 1,
|
||||
R1_UnsignedNormalized = 1,
|
||||
R9G9B9E5_SHAREDEXP = 4,
|
||||
R8G8_B8G8_UnsignedNormalized = 4,
|
||||
G8R8_G8B8_UnsignedNormalized = 4,
|
||||
BC1_Typeless = 2,
|
||||
BC1_UnsignedNormalized = 2,
|
||||
BC1_UnsignedNormalized_SRGB = 2,
|
||||
BC2_Typeless = 3,
|
||||
BC2_UnsignedNormalized = 3,
|
||||
BC2_UnsignedNormalized_SRGB = 3,
|
||||
BC3_Typeless = 4,
|
||||
BC3_UnsignedNormalized = 4,
|
||||
BC3_UnsignedNormalized_SRGB = 4,
|
||||
BC4_Typeless = 1,
|
||||
BC4_UnsignedNormalized = 1,
|
||||
BC4_SignedNormalized = 1,
|
||||
BC5_Typeless = 2,
|
||||
BC5_UnsignedNormalized = 2,
|
||||
BC5_SignedNormalized = 2,
|
||||
B5G6R5_UnsignedNormalized = 2,
|
||||
B5G5R5A1_UnsignedNormalized = 2,
|
||||
B8G8R8A8_UnsignedNormalized = 4,
|
||||
B8G8R8X8_UnsignedNormalized = 4
|
||||
};
|
||||
};
|
||||
|
||||
|
||||
struct DataFormat
|
||||
{
|
||||
enum Enumeration
|
||||
{
|
||||
Unknown = 0,
|
||||
R32G32B32A32_Typeless = 1,
|
||||
R32G32B32A32_Float = 2,
|
||||
R32G32B32A32_UnsignedInteger = 3,
|
||||
R32G32B32A32_SignedInteger = 4,
|
||||
R32G32B32_Typeless = 5,
|
||||
R32G32B32_Float = 6,
|
||||
R32G32B32_UnsignedInteger = 7,
|
||||
R32G32B32_SignedInteger = 8,
|
||||
R16G16B16A16_Typeless = 9,
|
||||
R16G16B16A16_Float = 10,
|
||||
R16G16B16A16_UnsignedNormalized = 11,
|
||||
R16G16B16A16_UnsignedInteger = 12,
|
||||
R16G16B16A16_SignedNormalized = 13,
|
||||
R16G16B16A16_SignedInteger = 14,
|
||||
R32G32_Typeless = 15,
|
||||
R32G32_Float = 16,
|
||||
R32G32_UnsignedInteger = 17,
|
||||
R32G32_SignedInteger = 18,
|
||||
R32G8X24_Typeless = 19,
|
||||
D32_Float_S8X24_UnsignedInteger = 20,
|
||||
R32_Float_X8X24_Typeless = 21,
|
||||
X32_Typeless_G8X24_UnsignedInteger = 22,
|
||||
R10G10B10A2_Typeless = 23,
|
||||
R10G10B10A2_UnsignedNormalized = 24,
|
||||
R10G10B10A2_UnsignedInteger = 25,
|
||||
R11G11B10_Float = 26,
|
||||
R8G8B8A8_Typeless = 27,
|
||||
R8G8B8A8_UnsignedNormalized = 28,
|
||||
R8G8B8A8_UnsignedNormalized_SRGB = 29,
|
||||
R8G8B8A8_UnsignedInteger = 30,
|
||||
R8G8B8A8_SignedNormalized = 31,
|
||||
R8G8B8A8_SignedInteger = 32,
|
||||
R16G16_Typeless = 33,
|
||||
R16G16_Float = 34,
|
||||
R16G16_UnsignedNormalized = 35,
|
||||
R16G16_UnsignedInteger = 36,
|
||||
R16G16_SignedNormalized = 37,
|
||||
R16G16_SignedInteger = 38,
|
||||
R32_Typeless = 39,
|
||||
D32_Float = 40,
|
||||
R32_Float = 41,
|
||||
R32_UnsignedInteger = 42,
|
||||
R32_SignedInteger = 43,
|
||||
R24G8_Typeless = 44,
|
||||
D24_UnsignedNormalized_S8_UnsignedInteger = 45,
|
||||
R24_UnsignedNormalized_X8_Typeless = 46,
|
||||
X24_Typeless_G8_UnsignedInteger = 47,
|
||||
R8G8_Typeless = 48,
|
||||
R8G8_UnsignedNormalized = 49,
|
||||
R8G8_UnsignedInteger = 50,
|
||||
R8G8_SignedNormalized = 51,
|
||||
R8G8_SignedInteger = 52,
|
||||
R16_Typeless = 53,
|
||||
R16_Float = 54,
|
||||
D16_UnsignedNormalized = 55,
|
||||
R16_UnsignedNormalized = 56,
|
||||
R16_UnsignedInteger = 57,
|
||||
R16_SignedNormalized = 58,
|
||||
R16_SignedInteger = 59,
|
||||
R8_Typeless = 60,
|
||||
R8_UnsignedNormalized = 61,
|
||||
R8_UnsignedInteger = 62,
|
||||
R8_SignedNormalized = 63,
|
||||
R8_SignedInteger = 64,
|
||||
A8_UnsignedNormalized = 65,
|
||||
R1_UnsignedNormalized = 66,
|
||||
R9G9B9E5_SHAREDEXP = 67,
|
||||
R8G8_B8G8_UnsignedNormalized = 68,
|
||||
G8R8_G8B8_UnsignedNormalized = 69,
|
||||
BC1_Typeless = 70,
|
||||
BC1_UnsignedNormalized = 71,
|
||||
BC1_UnsignedNormalized_SRGB = 72,
|
||||
BC2_Typeless = 73,
|
||||
BC2_UnsignedNormalized = 74,
|
||||
BC2_UnsignedNormalized_SRGB = 75,
|
||||
BC3_Typeless = 76,
|
||||
BC3_UnsignedNormalized = 77,
|
||||
BC3_UnsignedNormalized_SRGB = 78,
|
||||
BC4_Typeless = 79,
|
||||
BC4_UnsignedNormalized = 80,
|
||||
BC4_SignedNormalized = 81,
|
||||
BC5_Typeless = 82,
|
||||
BC5_UnsignedNormalized = 83,
|
||||
BC5_SignedNormalized = 84,
|
||||
B5G6R5_UnsignedNormalized = 85,
|
||||
B5G5R5A1_UnsignedNormalized = 86,
|
||||
B8G8R8A8_UnsignedNormalized = 87,
|
||||
B8G8R8X8_UnsignedNormalized = 88
|
||||
};
|
||||
|
||||
static DataFormatByteSize::Enumeration GetDataFormatByteSize(Enumeration argValue)
|
||||
{
|
||||
switch (argValue)
|
||||
{
|
||||
case Unknown: return DataFormatByteSize::Unknown;
|
||||
case R32G32B32A32_Typeless: return DataFormatByteSize::R32G32B32A32_Typeless;
|
||||
case R32G32B32A32_Float: return DataFormatByteSize::R32G32B32A32_Float;
|
||||
case R32G32B32A32_UnsignedInteger: return DataFormatByteSize::R32G32B32A32_UnsignedInteger;
|
||||
case R32G32B32A32_SignedInteger: return DataFormatByteSize::R32G32B32A32_SignedInteger;
|
||||
case R32G32B32_Typeless: return DataFormatByteSize::R32G32B32_Typeless;
|
||||
case R32G32B32_Float: return DataFormatByteSize::R32G32B32_Float;
|
||||
case R32G32B32_UnsignedInteger: return DataFormatByteSize::R32G32B32_UnsignedInteger;
|
||||
case R32G32B32_SignedInteger: return DataFormatByteSize::R32G32B32_SignedInteger;
|
||||
case R16G16B16A16_Typeless: return DataFormatByteSize::R16G16B16A16_Typeless;
|
||||
case R16G16B16A16_Float: return DataFormatByteSize::R16G16B16A16_Float;
|
||||
case R16G16B16A16_UnsignedNormalized: return DataFormatByteSize::R16G16B16A16_UnsignedNormalized;
|
||||
case R16G16B16A16_UnsignedInteger: return DataFormatByteSize::R16G16B16A16_UnsignedInteger;
|
||||
case R16G16B16A16_SignedNormalized: return DataFormatByteSize::R16G16B16A16_SignedNormalized;
|
||||
case R16G16B16A16_SignedInteger: return DataFormatByteSize::R16G16B16A16_SignedInteger;
|
||||
case R32G32_Typeless: return DataFormatByteSize::R32G32_Typeless;
|
||||
case R32G32_Float: return DataFormatByteSize::R32G32_Float;
|
||||
case R32G32_UnsignedInteger: return DataFormatByteSize::R32G32_UnsignedInteger;
|
||||
case R32G32_SignedInteger: return DataFormatByteSize::R32G32_SignedInteger;
|
||||
case R32G8X24_Typeless: return DataFormatByteSize::R32G8X24_Typeless;
|
||||
case D32_Float_S8X24_UnsignedInteger: return DataFormatByteSize::D32_Float_S8X24_UnsignedInteger;
|
||||
case R32_Float_X8X24_Typeless: return DataFormatByteSize::R32_Float_X8X24_Typeless;
|
||||
case X32_Typeless_G8X24_UnsignedInteger: return DataFormatByteSize::X32_Typeless_G8X24_UnsignedInteger;
|
||||
case R10G10B10A2_Typeless: return DataFormatByteSize::R10G10B10A2_Typeless;
|
||||
case R10G10B10A2_UnsignedNormalized: return DataFormatByteSize::R10G10B10A2_UnsignedNormalized;
|
||||
case R10G10B10A2_UnsignedInteger: return DataFormatByteSize::R10G10B10A2_UnsignedInteger;
|
||||
case R11G11B10_Float: return DataFormatByteSize::R11G11B10_Float;
|
||||
case R8G8B8A8_Typeless: return DataFormatByteSize::R8G8B8A8_Typeless;
|
||||
case R8G8B8A8_UnsignedNormalized: return DataFormatByteSize::R8G8B8A8_UnsignedNormalized;
|
||||
case R8G8B8A8_UnsignedNormalized_SRGB: return DataFormatByteSize::R8G8B8A8_UnsignedNormalized_SRGB;
|
||||
case R8G8B8A8_UnsignedInteger: return DataFormatByteSize::R8G8B8A8_UnsignedInteger;
|
||||
case R8G8B8A8_SignedNormalized: return DataFormatByteSize::R8G8B8A8_SignedNormalized;
|
||||
case R8G8B8A8_SignedInteger: return DataFormatByteSize::R8G8B8A8_SignedInteger;
|
||||
case R16G16_Typeless: return DataFormatByteSize::R16G16_Typeless;
|
||||
case R16G16_Float: return DataFormatByteSize::R16G16_Float;
|
||||
case R16G16_UnsignedNormalized: return DataFormatByteSize::R16G16_UnsignedNormalized;
|
||||
case R16G16_UnsignedInteger: return DataFormatByteSize::R16G16_UnsignedInteger;
|
||||
case R16G16_SignedNormalized: return DataFormatByteSize::R16G16_SignedNormalized;
|
||||
case R16G16_SignedInteger: return DataFormatByteSize::R16G16_SignedInteger;
|
||||
case R32_Typeless: return DataFormatByteSize::R32_Typeless;
|
||||
case D32_Float: return DataFormatByteSize::D32_Float;
|
||||
case R32_Float: return DataFormatByteSize::R32_Float;
|
||||
case R32_UnsignedInteger: return DataFormatByteSize::R32_UnsignedInteger;
|
||||
case R32_SignedInteger: return DataFormatByteSize::R32_SignedInteger;
|
||||
case R24G8_Typeless: return DataFormatByteSize::R24G8_Typeless;
|
||||
case D24_UnsignedNormalized_S8_UnsignedInteger: return DataFormatByteSize::D24_UnsignedNormalized_S8_UnsignedInteger;
|
||||
case R24_UnsignedNormalized_X8_Typeless: return DataFormatByteSize::R24_UnsignedNormalized_X8_Typeless;
|
||||
case X24_Typeless_G8_UnsignedInteger: return DataFormatByteSize::X24_Typeless_G8_UnsignedInteger;
|
||||
case R8G8_Typeless: return DataFormatByteSize::R8G8_Typeless;
|
||||
case R8G8_UnsignedNormalized: return DataFormatByteSize::R8G8_UnsignedNormalized;
|
||||
case R8G8_UnsignedInteger: return DataFormatByteSize::R8G8_UnsignedInteger;
|
||||
case R8G8_SignedNormalized: return DataFormatByteSize::R8G8_SignedNormalized;
|
||||
case R8G8_SignedInteger: return DataFormatByteSize::R8G8_SignedInteger;
|
||||
case R16_Typeless: return DataFormatByteSize::R16_Typeless;
|
||||
case R16_Float: return DataFormatByteSize::R16_Float;
|
||||
case D16_UnsignedNormalized: return DataFormatByteSize::D16_UnsignedNormalized;
|
||||
case R16_UnsignedNormalized: return DataFormatByteSize::R16_UnsignedNormalized;
|
||||
case R16_UnsignedInteger: return DataFormatByteSize::R16_UnsignedInteger;
|
||||
case R16_SignedNormalized: return DataFormatByteSize::R16_SignedNormalized;
|
||||
case R16_SignedInteger: return DataFormatByteSize::R16_SignedInteger;
|
||||
case R8_Typeless: return DataFormatByteSize::R8_Typeless;
|
||||
case R8_UnsignedNormalized: return DataFormatByteSize::R8_UnsignedNormalized;
|
||||
case R8_UnsignedInteger: return DataFormatByteSize::R8_UnsignedInteger;
|
||||
case R8_SignedNormalized: return DataFormatByteSize::R8_SignedNormalized;
|
||||
case R8_SignedInteger: return DataFormatByteSize::R8_SignedInteger;
|
||||
case A8_UnsignedNormalized: return DataFormatByteSize::A8_UnsignedNormalized;
|
||||
case R1_UnsignedNormalized: return DataFormatByteSize::R1_UnsignedNormalized;
|
||||
case R9G9B9E5_SHAREDEXP: return DataFormatByteSize::R9G9B9E5_SHAREDEXP;
|
||||
case R8G8_B8G8_UnsignedNormalized: return DataFormatByteSize::R8G8_B8G8_UnsignedNormalized;
|
||||
case G8R8_G8B8_UnsignedNormalized: return DataFormatByteSize::G8R8_G8B8_UnsignedNormalized;
|
||||
case BC1_Typeless: return DataFormatByteSize::BC1_Typeless;
|
||||
case BC1_UnsignedNormalized: return DataFormatByteSize::BC1_UnsignedNormalized;
|
||||
case BC1_UnsignedNormalized_SRGB: return DataFormatByteSize::BC1_UnsignedNormalized_SRGB;
|
||||
case BC2_Typeless: return DataFormatByteSize::BC2_Typeless;
|
||||
case BC2_UnsignedNormalized: return DataFormatByteSize::BC2_UnsignedNormalized;
|
||||
case BC2_UnsignedNormalized_SRGB: return DataFormatByteSize::BC2_UnsignedNormalized_SRGB;
|
||||
case BC3_Typeless: return DataFormatByteSize::BC3_Typeless;
|
||||
case BC3_UnsignedNormalized: return DataFormatByteSize::BC3_UnsignedNormalized;
|
||||
case BC3_UnsignedNormalized_SRGB: return DataFormatByteSize::BC3_UnsignedNormalized_SRGB;
|
||||
case BC4_Typeless: return DataFormatByteSize::BC4_Typeless;
|
||||
case BC4_UnsignedNormalized: return DataFormatByteSize::BC4_UnsignedNormalized;
|
||||
case BC4_SignedNormalized: return DataFormatByteSize::BC4_SignedNormalized;
|
||||
case BC5_Typeless: return DataFormatByteSize::BC5_Typeless;
|
||||
case BC5_UnsignedNormalized: return DataFormatByteSize::BC5_UnsignedNormalized;
|
||||
case BC5_SignedNormalized: return DataFormatByteSize::BC5_SignedNormalized;
|
||||
case B5G6R5_UnsignedNormalized: return DataFormatByteSize::B5G6R5_UnsignedNormalized;
|
||||
case B5G5R5A1_UnsignedNormalized: return DataFormatByteSize::B5G5R5A1_UnsignedNormalized;
|
||||
case B8G8R8A8_UnsignedNormalized: return DataFormatByteSize::B8G8R8A8_UnsignedNormalized;
|
||||
case B8G8R8X8_UnsignedNormalized: return DataFormatByteSize::B8G8R8X8_UnsignedNormalized;
|
||||
default: return DataFormatByteSize::Unknown;
|
||||
}
|
||||
}
|
||||
|
||||
static Enumeration Parse(string8 argValue)
|
||||
{
|
||||
if (argValue == "R32G32B32A32_Typeless") return R32G32B32A32_Typeless;
|
||||
else if (argValue == "R32G32B32A32_Float") return R32G32B32A32_Float;
|
||||
else if (argValue == "R32G32B32A32_UnsignedInteger") return R32G32B32A32_UnsignedInteger;
|
||||
else if (argValue == "R32G32B32A32_SignedInteger") return R32G32B32A32_SignedInteger;
|
||||
else if (argValue == "R32G32B32_Typeless") return R32G32B32_Typeless;
|
||||
else if (argValue == "R32G32B32_Float") return R32G32B32_Float;
|
||||
else if (argValue == "R32G32B32_UnsignedInteger") return R32G32B32_UnsignedInteger;
|
||||
else if (argValue == "R32G32B32_SignedInteger") return R32G32B32_SignedInteger;
|
||||
else if (argValue == "R16G16B16A16_Typeless") return R16G16B16A16_Typeless;
|
||||
else if (argValue == "R16G16B16A16_Float") return R16G16B16A16_Float;
|
||||
else if (argValue == "R16G16B16A16_UnsignedNormalized") return R16G16B16A16_UnsignedNormalized;
|
||||
else if (argValue == "R16G16B16A16_UnsignedInteger") return R16G16B16A16_UnsignedInteger;
|
||||
else if (argValue == "R16G16B16A16_SignedNormalized") return R16G16B16A16_SignedNormalized;
|
||||
else if (argValue == "R16G16B16A16_SignedInteger") return R16G16B16A16_SignedInteger;
|
||||
else if (argValue == "R32G32_Typeless") return R32G32_Typeless;
|
||||
else if (argValue == "R32G32_Float") return R32G32_Float;
|
||||
else if (argValue == "R32G32_UnsignedInteger") return R32G32_UnsignedInteger;
|
||||
else if (argValue == "R32G32_SignedInteger") return R32G32_SignedInteger;
|
||||
else if (argValue == "R32G8X24_Typeless") return R32G8X24_Typeless;
|
||||
else if (argValue == "D32_Float_S8X24_UnsignedInteger") return D32_Float_S8X24_UnsignedInteger;
|
||||
else if (argValue == "R32_Float_X8X24_Typeless") return R32_Float_X8X24_Typeless;
|
||||
else if (argValue == "X32_Typeless_G8X24_UnsignedInteger") return X32_Typeless_G8X24_UnsignedInteger;
|
||||
else if (argValue == "R10G10B10A2_Typeless") return R10G10B10A2_Typeless;
|
||||
else if (argValue == "R10G10B10A2_UnsignedNormalized") return R10G10B10A2_UnsignedNormalized;
|
||||
else if (argValue == "R10G10B10A2_UnsignedInteger") return R10G10B10A2_UnsignedInteger;
|
||||
else if (argValue == "R11G11B10_Float") return R11G11B10_Float;
|
||||
else if (argValue == "R8G8B8A8_Typeless") return R8G8B8A8_Typeless;
|
||||
else if (argValue == "R8G8B8A8_UnsignedNormalized") return R8G8B8A8_UnsignedNormalized;
|
||||
else if (argValue == "R8G8B8A8_UnsignedNormalized_SRGB") return R8G8B8A8_UnsignedNormalized_SRGB;
|
||||
else if (argValue == "R8G8B8A8_UnsignedInteger") return R8G8B8A8_UnsignedInteger;
|
||||
else if (argValue == "R8G8B8A8_SignedNormalized") return R8G8B8A8_SignedNormalized;
|
||||
else if (argValue == "R8G8B8A8_SignedInteger") return R8G8B8A8_SignedInteger;
|
||||
else if (argValue == "R16G16_Typeless") return R16G16_Typeless;
|
||||
else if (argValue == "R16G16_Float") return R16G16_Float;
|
||||
else if (argValue == "R16G16_UnsignedNormalized") return R16G16_UnsignedNormalized;
|
||||
else if (argValue == "R16G16_UnsignedInteger") return R16G16_UnsignedInteger;
|
||||
else if (argValue == "R16G16_SignedNormalized") return R16G16_SignedNormalized;
|
||||
else if (argValue == "R16G16_SignedInteger") return R16G16_SignedInteger;
|
||||
else if (argValue == "R32_Typeless") return R32_Typeless;
|
||||
else if (argValue == "D32_Float") return D32_Float;
|
||||
else if (argValue == "R32_Float") return R32_Float;
|
||||
else if (argValue == "R32_UnsignedInteger") return R32_UnsignedInteger;
|
||||
else if (argValue == "R32_SignedInteger") return R32_SignedInteger;
|
||||
else if (argValue == "R24G8_Typeless") return R24G8_Typeless;
|
||||
else if (argValue == "D24_UnsignedNormalized_S8_UnsignedInteger") return D24_UnsignedNormalized_S8_UnsignedInteger;
|
||||
else if (argValue == "R24_UnsignedNormalized_X8_Typeless") return R24_UnsignedNormalized_X8_Typeless;
|
||||
else if (argValue == "X24_Typeless_G8_UnsignedInteger") return X24_Typeless_G8_UnsignedInteger;
|
||||
else if (argValue == "R8G8_Typeless") return R8G8_Typeless;
|
||||
else if (argValue == "R8G8_UnsignedNormalized") return R8G8_UnsignedNormalized;
|
||||
else if (argValue == "R8G8_UnsignedInteger") return R8G8_UnsignedInteger;
|
||||
else if (argValue == "R8G8_SignedNormalized") return R8G8_SignedNormalized;
|
||||
else if (argValue == "R8G8_SignedInteger") return R8G8_SignedInteger;
|
||||
else if (argValue == "R16_Typeless") return R16_Typeless;
|
||||
else if (argValue == "R16_Float") return R16_Float;
|
||||
else if (argValue == "D16_UnsignedNormalized") return D16_UnsignedNormalized;
|
||||
else if (argValue == "R16_UnsignedNormalized") return R16_UnsignedNormalized;
|
||||
else if (argValue == "R16_UnsignedInteger") return R16_UnsignedInteger;
|
||||
else if (argValue == "R16_SignedNormalized") return R16_SignedNormalized;
|
||||
else if (argValue == "R16_SignedInteger") return R16_SignedInteger;
|
||||
else if (argValue == "R8_Typeless") return R8_Typeless;
|
||||
else if (argValue == "R8_UnsignedNormalized") return R8_UnsignedNormalized;
|
||||
else if (argValue == "R8_UnsignedInteger") return R8_UnsignedInteger;
|
||||
else if (argValue == "R8_SignedNormalized") return R8_SignedNormalized;
|
||||
else if (argValue == "R8_SignedInteger") return R8_SignedInteger;
|
||||
else if (argValue == "A8_UnsignedNormalized") return A8_UnsignedNormalized;
|
||||
else if (argValue == "R1_UnsignedNormalized") return R1_UnsignedNormalized;
|
||||
else if (argValue == "R9G9B9E5_SHAREDEXP") return R9G9B9E5_SHAREDEXP;
|
||||
else if (argValue == "R8G8_B8G8_UnsignedNormalized") return R8G8_B8G8_UnsignedNormalized;
|
||||
else if (argValue == "G8R8_G8B8_UnsignedNormalized") return G8R8_G8B8_UnsignedNormalized;
|
||||
else if (argValue == "BC1_Typeless") return BC1_Typeless;
|
||||
else if (argValue == "BC1_UnsignedNormalized") return BC1_UnsignedNormalized;
|
||||
else if (argValue == "BC1_UnsignedNormalized_SRGB") return BC1_UnsignedNormalized_SRGB;
|
||||
else if (argValue == "BC2_Typeless") return BC2_Typeless;
|
||||
else if (argValue == "BC2_UnsignedNormalized") return BC2_UnsignedNormalized;
|
||||
else if (argValue == "BC2_UnsignedNormalized_SRGB") return BC2_UnsignedNormalized_SRGB;
|
||||
else if (argValue == "BC3_Typeless") return BC3_Typeless;
|
||||
else if (argValue == "BC3_UnsignedNormalized") return BC3_UnsignedNormalized;
|
||||
else if (argValue == "BC3_UnsignedNormalized_SRGB") return BC3_UnsignedNormalized_SRGB;
|
||||
else if (argValue == "BC4_Typeless") return BC4_Typeless;
|
||||
else if (argValue == "BC4_UnsignedNormalized") return BC4_UnsignedNormalized;
|
||||
else if (argValue == "BC4_SignedNormalized") return BC4_SignedNormalized;
|
||||
else if (argValue == "BC5_Typeless") return BC5_Typeless;
|
||||
else if (argValue == "BC5_UnsignedNormalized") return BC5_UnsignedNormalized;
|
||||
else if (argValue == "BC5_SignedNormalized") return BC5_SignedNormalized;
|
||||
else if (argValue == "B5G6R5_UnsignedNormalized") return B5G6R5_UnsignedNormalized;
|
||||
else if (argValue == "B5G5R5A1_UnsignedNormalized") return B5G5R5A1_UnsignedNormalized;
|
||||
else if (argValue == "B8G8R8A8_UnsignedNormalized") return B8G8R8A8_UnsignedNormalized;
|
||||
else if (argValue == "B8G8R8X8_UnsignedNormalized") return B8G8R8X8_UnsignedNormalized;
|
||||
else return Unknown;
|
||||
}
|
||||
// {^.*case}:b{<.*}:b[=].*
|
||||
// \1 \2: return "\2";
|
||||
static string8 ToString(Enumeration argValue)
|
||||
{
|
||||
switch (argValue)
|
||||
{
|
||||
case Unknown: return "Unknown";
|
||||
case R32G32B32A32_Typeless: return "R32G32B32A32_Typeless";
|
||||
case R32G32B32A32_Float: return "R32G32B32A32_Float";
|
||||
case R32G32B32A32_UnsignedInteger: return "R32G32B32A32_UnsignedInteger";
|
||||
case R32G32B32A32_SignedInteger: return "R32G32B32A32_SignedInteger";
|
||||
case R32G32B32_Typeless: return "R32G32B32_Typeless";
|
||||
case R32G32B32_Float: return "R32G32B32_Float";
|
||||
case R32G32B32_UnsignedInteger: return "R32G32B32_UnsignedInteger";
|
||||
case R32G32B32_SignedInteger: return "R32G32B32_SignedInteger";
|
||||
case R16G16B16A16_Typeless: return "R16G16B16A16_Typeless";
|
||||
case R16G16B16A16_Float: return "R16G16B16A16_Float";
|
||||
case R16G16B16A16_UnsignedNormalized: return "R16G16B16A16_UnsignedNormalized";
|
||||
case R16G16B16A16_UnsignedInteger: return "R16G16B16A16_UnsignedInteger";
|
||||
case R16G16B16A16_SignedNormalized: return "R16G16B16A16_SignedNormalized";
|
||||
case R16G16B16A16_SignedInteger: return "R16G16B16A16_SignedInteger";
|
||||
case R32G32_Typeless: return "R32G32_Typeless";
|
||||
case R32G32_Float: return "R32G32_Float";
|
||||
case R32G32_UnsignedInteger: return "R32G32_UnsignedInteger";
|
||||
case R32G32_SignedInteger: return "R32G32_SignedInteger";
|
||||
case R32G8X24_Typeless: return "R32G8X24_Typeless";
|
||||
case D32_Float_S8X24_UnsignedInteger: return "D32_Float_S8X24_UnsignedInteger";
|
||||
case R32_Float_X8X24_Typeless: return "R32_Float_X8X24_Typeless";
|
||||
case X32_Typeless_G8X24_UnsignedInteger: return "X32_Typeless_G8X24_UnsignedInteger";
|
||||
case R10G10B10A2_Typeless: return "R10G10B10A2_Typeless";
|
||||
case R10G10B10A2_UnsignedNormalized: return "R10G10B10A2_UnsignedNormalized";
|
||||
case R10G10B10A2_UnsignedInteger: return "R10G10B10A2_UnsignedInteger";
|
||||
case R11G11B10_Float: return "R11G11B10_Float";
|
||||
case R8G8B8A8_Typeless: return "R8G8B8A8_Typeless";
|
||||
case R8G8B8A8_UnsignedNormalized: return "R8G8B8A8_UnsignedNormalized";
|
||||
case R8G8B8A8_UnsignedNormalized_SRGB: return "R8G8B8A8_UnsignedNormalized_SRGB";
|
||||
case R8G8B8A8_UnsignedInteger: return "R8G8B8A8_UnsignedInteger";
|
||||
case R8G8B8A8_SignedNormalized: return "R8G8B8A8_SignedNormalized";
|
||||
case R8G8B8A8_SignedInteger: return "R8G8B8A8_SignedInteger";
|
||||
case R16G16_Typeless: return "R16G16_Typeless";
|
||||
case R16G16_Float: return "R16G16_Float";
|
||||
case R16G16_UnsignedNormalized: return "R16G16_UnsignedNormalized";
|
||||
case R16G16_UnsignedInteger: return "R16G16_UnsignedInteger";
|
||||
case R16G16_SignedNormalized: return "R16G16_SignedNormalized";
|
||||
case R16G16_SignedInteger: return "R16G16_SignedInteger";
|
||||
case R32_Typeless: return "R32_Typeless";
|
||||
case D32_Float: return "D32_Float";
|
||||
case R32_Float: return "R32_Float";
|
||||
case R32_UnsignedInteger: return "R32_UnsignedInteger";
|
||||
case R32_SignedInteger: return "R32_SignedInteger";
|
||||
case R24G8_Typeless: return "R24G8_Typeless";
|
||||
case D24_UnsignedNormalized_S8_UnsignedInteger: return "D24_UnsignedNormalized_S8_UnsignedInteger";
|
||||
case R24_UnsignedNormalized_X8_Typeless: return "R24_UnsignedNormalized_X8_Typeless";
|
||||
case X24_Typeless_G8_UnsignedInteger: return "X24_Typeless_G8_UnsignedInteger";
|
||||
case R8G8_Typeless: return "R8G8_Typeless";
|
||||
case R8G8_UnsignedNormalized: return "R8G8_UnsignedNormalized";
|
||||
case R8G8_UnsignedInteger: return "R8G8_UnsignedInteger";
|
||||
case R8G8_SignedNormalized: return "R8G8_SignedNormalized";
|
||||
case R8G8_SignedInteger: return "R8G8_SignedInteger";
|
||||
case R16_Typeless: return "R16_Typeless";
|
||||
case R16_Float: return "R16_Float";
|
||||
case D16_UnsignedNormalized: return "D16_UnsignedNormalized";
|
||||
case R16_UnsignedNormalized: return "R16_UnsignedNormalized";
|
||||
case R16_UnsignedInteger: return "R16_UnsignedInteger";
|
||||
case R16_SignedNormalized: return "R16_SignedNormalized";
|
||||
case R16_SignedInteger: return "R16_SignedInteger";
|
||||
case R8_Typeless: return "R8_Typeless";
|
||||
case R8_UnsignedNormalized: return "R8_UnsignedNormalized";
|
||||
case R8_UnsignedInteger: return "R8_UnsignedInteger";
|
||||
case R8_SignedNormalized: return "R8_SignedNormalized";
|
||||
case R8_SignedInteger: return "R8_SignedInteger";
|
||||
case A8_UnsignedNormalized: return "A8_UnsignedNormalized";
|
||||
case R1_UnsignedNormalized: return "R1_UnsignedNormalized";
|
||||
case R9G9B9E5_SHAREDEXP: return "R9G9B9E5_SHAREDEXP";
|
||||
case R8G8_B8G8_UnsignedNormalized: return "R8G8_B8G8_UnsignedNormalized";
|
||||
case G8R8_G8B8_UnsignedNormalized: return "G8R8_G8B8_UnsignedNormalized";
|
||||
case BC1_Typeless: return "BC1_Typeless";
|
||||
case BC1_UnsignedNormalized: return "BC1_UnsignedNormalized";
|
||||
case BC1_UnsignedNormalized_SRGB: return "BC1_UnsignedNormalized_SRGB";
|
||||
case BC2_Typeless: return "BC2_Typeless";
|
||||
case BC2_UnsignedNormalized: return "BC2_UnsignedNormalized";
|
||||
case BC2_UnsignedNormalized_SRGB: return "BC2_UnsignedNormalized_SRGB";
|
||||
case BC3_Typeless: return "BC3_Typeless";
|
||||
case BC3_UnsignedNormalized: return "BC3_UnsignedNormalized";
|
||||
case BC3_UnsignedNormalized_SRGB: return "BC3_UnsignedNormalized_SRGB";
|
||||
case BC4_Typeless: return "BC4_Typeless";
|
||||
case BC4_UnsignedNormalized: return "BC4_UnsignedNormalized";
|
||||
case BC4_SignedNormalized: return "BC4_SignedNormalized";
|
||||
case BC5_Typeless: return "BC5_Typeless";
|
||||
case BC5_UnsignedNormalized: return "BC5_UnsignedNormalized";
|
||||
case BC5_SignedNormalized: return "BC5_SignedNormalized";
|
||||
case B5G6R5_UnsignedNormalized: return "B5G6R5_UnsignedNormalized";
|
||||
case B5G5R5A1_UnsignedNormalized: return "B5G5R5A1_UnsignedNormalized";
|
||||
case B8G8R8A8_UnsignedNormalized: return "B8G8R8A8_UnsignedNormalized";
|
||||
case B8G8R8X8_UnsignedNormalized: return "B8G8R8X8_UnsignedNormalized";
|
||||
default: return "Unknown";
|
||||
}
|
||||
}
|
||||
};
|
||||
|
||||
|
||||
struct DataAccessMode
|
||||
{
|
||||
enum Enumeration
|
||||
{
|
||||
Read = 1,
|
||||
Write = 2,
|
||||
ReadAndWrite = 3,
|
||||
WriteAndDiscard = 4
|
||||
};
|
||||
};
|
||||
|
||||
|
||||
struct DataAccessType
|
||||
{
|
||||
enum Enumeration
|
||||
{
|
||||
Static, // no CPU access
|
||||
CpuReadOnly, // Resource is only readable and cannot be used by the GPU for rendering purposes
|
||||
Dynamic // Resource may change every frame
|
||||
};
|
||||
};
|
||||
45
aiwaz/Aiwaz/Interfaces/itransformationanimation.h
Normal file
45
aiwaz/Aiwaz/Interfaces/itransformationanimation.h
Normal file
@@ -0,0 +1,45 @@
|
||||
#pragma once
|
||||
|
||||
|
||||
struct KeyFrameTarget
|
||||
{
|
||||
enum Enumeration
|
||||
{
|
||||
Position,
|
||||
Rotation,
|
||||
Scale
|
||||
};
|
||||
};
|
||||
|
||||
|
||||
struct KeyFrame
|
||||
{
|
||||
KeyFrame()
|
||||
: m_Target(KeyFrameTarget::Position)
|
||||
, m_Time(0.0f)
|
||||
{}
|
||||
|
||||
KeyFrame(KeyFrameTarget::Enumeration argTarget, const D3DXVECTOR3& argValue, float argTime)
|
||||
: m_Target(argTarget)
|
||||
, m_Value(argValue)
|
||||
, m_Time(argTime)
|
||||
{}
|
||||
|
||||
KeyFrameTarget::Enumeration m_Target;
|
||||
D3DXVECTOR3 m_Value;
|
||||
float m_Time;
|
||||
};
|
||||
|
||||
|
||||
struct __declspec(novtable) ITransformationAnimation
|
||||
{
|
||||
virtual ~ITransformationAnimation() {};
|
||||
|
||||
//virtual std::wstring get_Name() const = 0;
|
||||
|
||||
virtual void AddKeyFrame(const KeyFrame& argKeyFrame) = 0;
|
||||
virtual float get_Duration() const = 0;
|
||||
|
||||
virtual D3DXMATRIX GetTransformationAtTime(float argT) = 0; // [0.0] - [1.0]
|
||||
};
|
||||
|
||||
302
aiwaz/Aiwaz/ResourceFactory/ResourceFactory.cpp
Normal file
302
aiwaz/Aiwaz/ResourceFactory/ResourceFactory.cpp
Normal file
@@ -0,0 +1,302 @@
|
||||
#include "stdafx.h"
|
||||
#include "ResourceFactory.h"
|
||||
#include <algorithm>
|
||||
|
||||
ResourceFactory::ResourceFactory(IEngine& argEngine)
|
||||
: m_Engine(argEngine)
|
||||
, m_LastCallCreatedResource(false)
|
||||
{
|
||||
}
|
||||
|
||||
|
||||
ResourceFactory::~ResourceFactory()
|
||||
{
|
||||
this->ClearInternal(m_Windows);
|
||||
this->ClearInternal(m_RenderCommandNodes);
|
||||
this->ClearInternal(m_ShaderPool);
|
||||
this->ClearInternal(m_InternalShaderPool);
|
||||
this->ClearInternal(m_GeometryBufferPool);
|
||||
this->ClearInternal(m_SwapChainPool);
|
||||
this->ClearInternal(m_RenderTargetTexturePool);
|
||||
this->ClearInternal(m_TransformationPool);
|
||||
this->ClearInternal(m_PerspectiveCameraPool);
|
||||
this->ClearInternal(m_OrthographicCameraPool);
|
||||
this->ClearInternal(m_BonePool);
|
||||
this->ClearInternal(m_BoneControllerPool);
|
||||
this->ClearInternal(m_ShaderParameterCollectionPool);
|
||||
}
|
||||
|
||||
|
||||
ITransformationAnimation& ResourceFactory::CreateTransformationAnimation()
|
||||
{
|
||||
ITransformationAnimation* var = new TransformationAnimation(m_Engine);
|
||||
m_TransformationAnimations.push_back(var);
|
||||
return *var;
|
||||
}
|
||||
|
||||
|
||||
void ResourceFactory::DeleteTransformationAnimation(ITransformationAnimation& argValue, bool argRemoveOnly)
|
||||
{
|
||||
std::vector<ITransformationAnimation*>::iterator iter = std::find(m_TransformationAnimations.begin(), m_TransformationAnimations.end(), &argValue);
|
||||
if (iter != m_TransformationAnimations.end())
|
||||
{
|
||||
m_TransformationAnimations.erase(iter);
|
||||
if (!argRemoveOnly)
|
||||
delete &argValue;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
IWindow& ResourceFactory::CreateSwapChainWindow()
|
||||
{
|
||||
IWindow* window = new Window(m_Engine);
|
||||
m_Windows.push_back(window);
|
||||
return *window;
|
||||
}
|
||||
|
||||
|
||||
void ResourceFactory::DeleteSwapChainWindow(IWindow& argValue, bool argRemoveOnly)
|
||||
{
|
||||
std::vector<IWindow*>::iterator iter = std::find(m_Windows.begin(), m_Windows.end(), &argValue);
|
||||
if (iter != m_Windows.end())
|
||||
{
|
||||
m_Windows.erase(iter);
|
||||
if (!argRemoveOnly)
|
||||
delete &argValue;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
IRenderCommandNode& ResourceFactory::CreateRenderCommandNode()
|
||||
{
|
||||
IRenderCommandNode* node = new RenderCommandNode(m_Engine);
|
||||
m_RenderCommandNodes.push_back(node);
|
||||
return *node;
|
||||
}
|
||||
|
||||
|
||||
void ResourceFactory::DeleteRenderCommandNode(IRenderCommandNode& argValue, bool argRemoveOnly)
|
||||
{
|
||||
std::vector<IRenderCommandNode*>::iterator iter = std::find(m_RenderCommandNodes.begin(), m_RenderCommandNodes.end(), &argValue);
|
||||
if (iter != m_RenderCommandNodes.end())
|
||||
{
|
||||
m_RenderCommandNodes.erase(iter);
|
||||
if (!argRemoveOnly)
|
||||
delete &argValue;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
IShader* ResourceFactory::FindShader(const string8& argId)
|
||||
{
|
||||
return this->FindInternal(m_ShaderPool, argId);
|
||||
}
|
||||
|
||||
|
||||
IShader& ResourceFactory::CreateOrFindShader(const string8& argId)
|
||||
{
|
||||
return *this->CreateOrFindInternal(m_ShaderPool, argId);
|
||||
}
|
||||
|
||||
|
||||
void ResourceFactory::DeleteShader(IShader& argValue, bool argRemoveOnly)
|
||||
{
|
||||
this->DeleteInternal(m_ShaderPool, argValue, argRemoveOnly);
|
||||
}
|
||||
|
||||
|
||||
IInternalShader* ResourceFactory::FindInternalShader(const string8& argId)
|
||||
{
|
||||
return this->FindInternal(m_InternalShaderPool, argId);
|
||||
}
|
||||
|
||||
|
||||
IInternalShader& ResourceFactory::CreateOrFindInternalShader(const string8& argId)
|
||||
{
|
||||
return *this->CreateOrFindInternal(m_InternalShaderPool, argId);
|
||||
}
|
||||
|
||||
|
||||
void ResourceFactory::DeleteInternalShader(IInternalShader& argValue, bool argRemoveOnly)
|
||||
{
|
||||
this->DeleteInternal(m_InternalShaderPool, argValue, argRemoveOnly);
|
||||
}
|
||||
|
||||
|
||||
ISwapChain* ResourceFactory::FindSwapChain(const string8& argId)
|
||||
{
|
||||
return this->FindInternal(m_SwapChainPool, argId);
|
||||
}
|
||||
|
||||
|
||||
ISwapChain& ResourceFactory::CreateOrFindSwapChain(const string8& argId)
|
||||
{
|
||||
return *this->CreateOrFindInternal(m_SwapChainPool, argId);
|
||||
}
|
||||
|
||||
|
||||
void ResourceFactory::DeleteSwapChain(ISwapChain& argValue, bool argRemoveOnly)
|
||||
{
|
||||
this->DeleteInternal(m_SwapChainPool, argValue, argRemoveOnly);
|
||||
}
|
||||
|
||||
|
||||
IRenderTargetTexture* ResourceFactory::FindRenderTargetTexture(const string8& argId)
|
||||
{
|
||||
return this->FindInternal(m_RenderTargetTexturePool, argId);
|
||||
}
|
||||
|
||||
|
||||
IRenderTargetTexture& ResourceFactory::CreateOrFindRenderTargetTexture(const string8& argId)
|
||||
{
|
||||
return *this->CreateOrFindInternal(m_RenderTargetTexturePool, argId);
|
||||
}
|
||||
|
||||
|
||||
void ResourceFactory::DeleteRenderTargetTexture(IRenderTargetTexture& argValue, bool argRemoveOnly)
|
||||
{
|
||||
this->DeleteInternal(m_RenderTargetTexturePool, argValue, argRemoveOnly);
|
||||
}
|
||||
|
||||
|
||||
IGeometryBuffer* ResourceFactory::FindGeometryBuffer(const string8& argId)
|
||||
{
|
||||
return this->FindInternal(m_GeometryBufferPool, argId);
|
||||
}
|
||||
|
||||
|
||||
IGeometryBuffer& ResourceFactory::CreateOrFindGeometryBuffer(const string8& argId)
|
||||
{
|
||||
return *this->CreateOrFindInternal(m_GeometryBufferPool, argId);
|
||||
}
|
||||
|
||||
|
||||
void ResourceFactory::DeleteGeometryBuffer(IGeometryBuffer& argValue, bool argRemoveOnly)
|
||||
{
|
||||
this->DeleteInternal(m_GeometryBufferPool, argValue, argRemoveOnly);
|
||||
}
|
||||
|
||||
|
||||
IShaderParameterCollection* ResourceFactory::FindShaderParameterCollection(const string8& argId)
|
||||
{
|
||||
return this->FindInternal(m_ShaderParameterCollectionPool, argId);
|
||||
}
|
||||
|
||||
|
||||
IShaderParameterCollection& ResourceFactory::CreateOrFindShaderParameterCollection(const string8& argId)
|
||||
{
|
||||
return *this->CreateOrFindInternal(m_ShaderParameterCollectionPool, argId);
|
||||
}
|
||||
|
||||
|
||||
void ResourceFactory::DeleteShaderParameterCollection(IShaderParameterCollection& argValue, bool argRemoveOnly)
|
||||
{
|
||||
this->DeleteInternal(m_ShaderParameterCollectionPool, argValue, argRemoveOnly);
|
||||
}
|
||||
|
||||
|
||||
ITexture* ResourceFactory::FindTexture(const string8& argId)
|
||||
{
|
||||
return this->FindInternal(m_TexturePool, argId);
|
||||
}
|
||||
|
||||
|
||||
ITexture& ResourceFactory::CreateOrFindTexture(const string8& argId)
|
||||
{
|
||||
return *this->CreateOrFindInternal(m_TexturePool, argId);
|
||||
}
|
||||
|
||||
|
||||
void ResourceFactory::DeleteTexture(ITexture& argValue, bool argRemoveOnly)
|
||||
{
|
||||
this->DeleteInternal(m_TexturePool, argValue, argRemoveOnly);
|
||||
}
|
||||
|
||||
|
||||
ITransformation* ResourceFactory::FindTransformation(const string8& argId)
|
||||
{
|
||||
return this->FindInternal(m_TransformationPool, argId);
|
||||
}
|
||||
|
||||
|
||||
ITransformation& ResourceFactory::CreateOrFindTransformation(const string8& argId)
|
||||
{
|
||||
return *this->CreateOrFindInternal(m_TransformationPool, argId);
|
||||
}
|
||||
|
||||
|
||||
void ResourceFactory::DeleteTransformation(ITransformation& argValue, bool argRemoveOnly)
|
||||
{
|
||||
this->DeleteInternal(m_TransformationPool, argValue, argRemoveOnly);
|
||||
}
|
||||
|
||||
|
||||
IPerspectiveCamera* ResourceFactory::FindPerspectiveCamera(const string8& argId)
|
||||
{
|
||||
return this->FindInternal(m_PerspectiveCameraPool, argId);
|
||||
}
|
||||
|
||||
|
||||
IPerspectiveCamera& ResourceFactory::CreateOrFindPerspectiveCamera(const string8& argId)
|
||||
{
|
||||
return *this->CreateOrFindInternal(m_PerspectiveCameraPool, argId);
|
||||
}
|
||||
|
||||
|
||||
void ResourceFactory::DeletePerspectiveCamera(IPerspectiveCamera& argValue, bool argRemoveOnly)
|
||||
{
|
||||
this->DeleteInternal(m_PerspectiveCameraPool, argValue, argRemoveOnly);
|
||||
}
|
||||
|
||||
|
||||
IOrthographicCamera* ResourceFactory::FindOrthographicCamera(const string8& argId)
|
||||
{
|
||||
return this->FindInternal(m_OrthographicCameraPool, argId);
|
||||
}
|
||||
|
||||
|
||||
IOrthographicCamera& ResourceFactory::CreateOrFindOrthographicCamera(const string8& argId)
|
||||
{
|
||||
return *this->CreateOrFindInternal(m_OrthographicCameraPool, argId);
|
||||
}
|
||||
|
||||
|
||||
void ResourceFactory::DeleteOrthographicCamera(IOrthographicCamera& argValue, bool argRemoveOnly)
|
||||
{
|
||||
this->DeleteInternal(m_OrthographicCameraPool, argValue, argRemoveOnly);
|
||||
}
|
||||
|
||||
|
||||
IBone* ResourceFactory::FindBone(const string8& argId)
|
||||
{
|
||||
return this->FindInternal(m_BonePool, argId);
|
||||
}
|
||||
|
||||
|
||||
IBone& ResourceFactory::CreateOrFindBone(const string8& argId)
|
||||
{
|
||||
return *this->CreateOrFindInternal(m_BonePool, argId);
|
||||
}
|
||||
|
||||
|
||||
void ResourceFactory::DeleteBone(IBone& argValue, bool argRemoveOnly)
|
||||
{
|
||||
this->DeleteInternal(m_BonePool, argValue, argRemoveOnly);
|
||||
}
|
||||
|
||||
IBoneController* ResourceFactory::FindBoneController(const string8& argId)
|
||||
{
|
||||
return this->FindInternal(m_BoneControllerPool, argId);
|
||||
}
|
||||
|
||||
|
||||
IBoneController& ResourceFactory::CreateOrFindBoneController(const string8& argId)
|
||||
{
|
||||
return *this->CreateOrFindInternal(m_BoneControllerPool, argId);
|
||||
}
|
||||
|
||||
|
||||
void ResourceFactory::DeleteBoneController(IBoneController& argValue, bool argRemoveOnly)
|
||||
{
|
||||
this->DeleteInternal(m_BoneControllerPool, argValue, argRemoveOnly);
|
||||
}
|
||||
200
aiwaz/Aiwaz/ResourceFactory/ResourceFactory.h
Normal file
200
aiwaz/Aiwaz/ResourceFactory/ResourceFactory.h
Normal file
@@ -0,0 +1,200 @@
|
||||
#pragma once
|
||||
|
||||
#include <sstream>
|
||||
|
||||
#include "IEngine.h"
|
||||
#include "IResourceFactory.h"
|
||||
|
||||
#include "../Resources/RenderTarget/SwapChain/SwapChain.h"
|
||||
#include "../Resources/RenderTarget/RenderTargetTexture/RenderTargetTexture.h"
|
||||
#include "../Resources/GeometryBuffer/GeometryBuffer.h"
|
||||
#include "../Resources/Shader/Shader.h"
|
||||
#include "../Resources/Shader/InternalShader.h"
|
||||
#include "../Resources/RenderCommandNode/RenderCommandNode.h"
|
||||
#include "../Resources/ShaderParameterCollection/ShaderParameterCollection.h"
|
||||
#include "../Resources/Texture/Texture.h"
|
||||
#include "../Resources/Transformation/Transformation.h"
|
||||
#include "../Resources/TransformationAnimation/TransformationAnimation.h"
|
||||
#include "../Resources/Camera/OrthographicCamera.h"
|
||||
#include "../Resources/Camera/PerspectiveCamera.h"
|
||||
#include "../Resources/Bone/Bone.h"
|
||||
#include "../Resources/Bone/BoneController.h"
|
||||
#include "../Window/Window.h"
|
||||
|
||||
|
||||
class ResourceFactory
|
||||
: public IResourceFactory
|
||||
{
|
||||
public:
|
||||
ResourceFactory(IEngine& argEngine);
|
||||
virtual ~ResourceFactory();
|
||||
|
||||
virtual ITransformationAnimation& CreateTransformationAnimation();
|
||||
virtual void DeleteTransformationAnimation(ITransformationAnimation& argValue, bool argRemoveOnly = false);
|
||||
|
||||
virtual IWindow& CreateSwapChainWindow();
|
||||
virtual void DeleteSwapChainWindow(IWindow& argValue, bool argRemoveOnly = false);
|
||||
|
||||
virtual IRenderCommandNode& CreateRenderCommandNode();
|
||||
virtual void DeleteRenderCommandNode(IRenderCommandNode& argValue, bool argRemoveOnly = false);
|
||||
|
||||
virtual IShader* FindShader(const string8& argId);
|
||||
virtual IShader& CreateOrFindShader(const string8& argId = "");
|
||||
virtual void DeleteShader(IShader& argValue, bool argRemoveOnly = false);
|
||||
|
||||
virtual IInternalShader* FindInternalShader(const string8& argId);
|
||||
virtual IInternalShader& CreateOrFindInternalShader(const string8& argId = "");
|
||||
virtual void DeleteInternalShader(IInternalShader& argValue, bool argRemoveOnly = false);
|
||||
|
||||
virtual ISwapChain* FindSwapChain(const string8& argId);
|
||||
virtual ISwapChain& CreateOrFindSwapChain(const string8& argId = "");
|
||||
virtual void DeleteSwapChain(ISwapChain& argValue, bool argRemoveOnly = false);
|
||||
|
||||
virtual IRenderTargetTexture* FindRenderTargetTexture(const string8& argId);
|
||||
virtual IRenderTargetTexture& CreateOrFindRenderTargetTexture(const string8& argId = "");
|
||||
virtual void DeleteRenderTargetTexture(IRenderTargetTexture& argValue, bool argRemoveOnly = false);
|
||||
|
||||
virtual IGeometryBuffer* FindGeometryBuffer(const string8& argId);
|
||||
virtual IGeometryBuffer& CreateOrFindGeometryBuffer(const string8& argId = "");
|
||||
virtual void DeleteGeometryBuffer(IGeometryBuffer& argValue, bool argRemoveOnly = false);
|
||||
|
||||
virtual IShaderParameterCollection* FindShaderParameterCollection(const string8& argId);
|
||||
virtual IShaderParameterCollection& CreateOrFindShaderParameterCollection(const string8& argId = "");
|
||||
virtual void DeleteShaderParameterCollection(IShaderParameterCollection& argValue, bool argRemoveOnly = false);
|
||||
|
||||
virtual ITexture* FindTexture(const string8& argId);
|
||||
virtual ITexture& CreateOrFindTexture(const string8& argId = "");
|
||||
virtual void DeleteTexture(ITexture& argValue, bool argRemoveOnly = false);
|
||||
|
||||
virtual ITransformation* FindTransformation(const string8& argId);
|
||||
virtual ITransformation& CreateOrFindTransformation(const string8& argId = "");
|
||||
virtual void DeleteTransformation(ITransformation& argValue, bool argRemoveOnly = false);
|
||||
|
||||
virtual IPerspectiveCamera* FindPerspectiveCamera(const string8& argId);
|
||||
virtual IPerspectiveCamera& CreateOrFindPerspectiveCamera(const string8& argId = "");
|
||||
virtual void DeletePerspectiveCamera(IPerspectiveCamera& argValue, bool argRemoveOnly = false);
|
||||
|
||||
virtual IOrthographicCamera* FindOrthographicCamera(const string8& argId);
|
||||
virtual IOrthographicCamera& CreateOrFindOrthographicCamera(const string8& argId = "");
|
||||
virtual void DeleteOrthographicCamera(IOrthographicCamera& argValue, bool argRemoveOnly = false);
|
||||
|
||||
virtual IBone* FindBone(const string8& argId);
|
||||
virtual IBone& CreateOrFindBone(const string8& argId = "");
|
||||
virtual void DeleteBone(IBone& argValue, bool argRemoveOnly = false);
|
||||
|
||||
virtual IBoneController* FindBoneController(const string8& argId);
|
||||
virtual IBoneController& CreateOrFindBoneController(const string8& argId = "");
|
||||
virtual void DeleteBoneController(IBoneController& argValue, bool argRemoveOnly = false);
|
||||
|
||||
virtual bool HasCreatedResource() { return m_LastCallCreatedResource; }
|
||||
|
||||
|
||||
protected:
|
||||
|
||||
template<typename A, typename B> void DeleteInternal(std::map<string8, A*>& argPool, B& argWhich, bool argRemoveOnly)
|
||||
{
|
||||
A* valueA = dynamic_cast<A*>(&argWhich);
|
||||
|
||||
for (std::map<string8, A*>::iterator iter = argPool.begin(); iter != argPool.end(); ++iter)
|
||||
if (iter->second == valueA)
|
||||
{
|
||||
ICommandUser* commandUser = dynamic_cast<ICommandUser*>(iter->second);
|
||||
if (commandUser != NULL)
|
||||
std::cout << "Deleting \"" << std::green << iter->first << std::white << "\" [" << commandUser->get_UserName() << "]" << std::endl;
|
||||
|
||||
argPool.erase(iter);
|
||||
if (!argRemoveOnly)
|
||||
delete valueA;
|
||||
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
template<typename T> void ClearInternal(std::map<string8, T*>& argPool)
|
||||
{
|
||||
while (!argPool.empty())
|
||||
{
|
||||
ICommandUser* commandUser = dynamic_cast<ICommandUser*>(argPool.begin()->second);
|
||||
if (commandUser != NULL)
|
||||
std::cout << "Deleting \"" << std::green << argPool.begin()->first << std::white << "\" [" << commandUser->get_UserName() << "]" << std::endl;
|
||||
|
||||
T* valueA = argPool.begin()->second;
|
||||
argPool.erase(argPool.begin());
|
||||
delete valueA;
|
||||
}
|
||||
}
|
||||
|
||||
template<typename T> void ClearInternal(std::vector<T*>& argPool)
|
||||
{
|
||||
while (!argPool.empty())
|
||||
{
|
||||
delete *argPool.begin();
|
||||
argPool.erase(argPool.begin());
|
||||
}
|
||||
}
|
||||
|
||||
template<typename T> T* FindInternal(std::map<string8, T*>& argPool, const string8& argId)
|
||||
{
|
||||
m_LastCallCreatedResource = false;
|
||||
if (argPool.find(argId) == argPool.end())
|
||||
return NULL;
|
||||
return argPool[argId];
|
||||
}
|
||||
|
||||
template<typename T> string8 CreateUniqueName(std::map<string8, T*>& argPool, const string8& argPrefix = "")
|
||||
{
|
||||
int NameIndex = argPool.size();
|
||||
std::stringstream CurrentName;
|
||||
do
|
||||
{
|
||||
CurrentName.flush();
|
||||
CurrentName << argPrefix << NameIndex++;
|
||||
}
|
||||
while (FindInternal(argPool, CurrentName.str()) != NULL);
|
||||
|
||||
return CurrentName.str();
|
||||
}
|
||||
|
||||
template<typename T> T* CreateOrFindInternal(std::map<string8, T*>& argPool, const string8& argId)
|
||||
{
|
||||
std::string currentId = argId;
|
||||
if (currentId.empty())
|
||||
currentId = CreateUniqueName(argPool);
|
||||
|
||||
T* instance = this->FindInternal(argPool, currentId);
|
||||
if (instance != NULL)
|
||||
return instance;
|
||||
m_LastCallCreatedResource = true;
|
||||
|
||||
instance = new T(m_Engine);
|
||||
|
||||
ICommandUser* commandUser = dynamic_cast<ICommandUser*>(instance);
|
||||
if (commandUser != NULL)
|
||||
std::cout << "Creating \"" << std::green << currentId << std::white << "\" [" << commandUser->get_UserName() << "]" << std::endl;
|
||||
|
||||
argPool[currentId] = instance;
|
||||
return instance;
|
||||
}
|
||||
|
||||
private:
|
||||
IEngine& m_Engine;
|
||||
|
||||
std::map<string8, InternalShader*> m_InternalShaderPool;
|
||||
std::map<string8, Shader*> m_ShaderPool;
|
||||
std::map<string8, GeometryBuffer*> m_GeometryBufferPool;
|
||||
std::map<string8, SwapChain*> m_SwapChainPool;
|
||||
std::map<string8, RenderTargetTexture*> m_RenderTargetTexturePool;
|
||||
std::map<string8, ShaderParameterCollection*> m_ShaderParameterCollectionPool;
|
||||
std::map<string8, Texture*> m_TexturePool;
|
||||
std::map<string8, Transformation*> m_TransformationPool;
|
||||
std::map<string8, OrthographicCamera*> m_OrthographicCameraPool;
|
||||
std::map<string8, PerspectiveCamera*> m_PerspectiveCameraPool;
|
||||
std::map<string8, Bone*> m_BonePool;
|
||||
std::map<string8, BoneController*> m_BoneControllerPool;
|
||||
|
||||
std::vector<IRenderCommandNode*> m_RenderCommandNodes;
|
||||
std::vector<IWindow*> m_Windows;
|
||||
std::vector<ITransformationAnimation*> m_TransformationAnimations;
|
||||
|
||||
bool m_LastCallCreatedResource;
|
||||
};
|
||||
150
aiwaz/Aiwaz/Resources/Bone/Bone.cpp
Normal file
150
aiwaz/Aiwaz/Resources/Bone/Bone.cpp
Normal file
@@ -0,0 +1,150 @@
|
||||
#include "stdafx.h"
|
||||
#include "Bone.h"
|
||||
#include "IResourceFactory.h"
|
||||
#include "ITransformationAnimation.h"
|
||||
|
||||
|
||||
Bone::Bone(IEngine& argEngine)
|
||||
: m_Engine(argEngine)
|
||||
, m_Parent(NULL)
|
||||
, m_TransformationAnimation(NULL)
|
||||
, m_BoneIndex(-1)
|
||||
, m_LastAnimationTime(-1.0f)
|
||||
, m_MatrixArray(NULL)
|
||||
{
|
||||
}
|
||||
|
||||
|
||||
Bone::~Bone()
|
||||
{
|
||||
delete m_MatrixArray;
|
||||
m_Engine.get_ResourceFactory().DeleteBone(*const_cast<Bone*>(this), true);
|
||||
}
|
||||
|
||||
|
||||
void Bone::Initialize(const std::wstring& argName, int argIndex, const D3DXVECTOR3& argPoseTranslation, const D3DXVECTOR3& argPoseScale, const D3DXQUATERNION& argPoseRotation)
|
||||
{
|
||||
D3DXMatrixTransformation(&m_PoseTransformation, NULL, NULL, &argPoseScale, NULL, &argPoseRotation, &argPoseTranslation);
|
||||
D3DXMatrixInverse(&m_InvPoseTransformation, NULL, &m_PoseTransformation);
|
||||
}
|
||||
|
||||
|
||||
const D3DXMATRIX& Bone::GetTransformationAtTime(float argT, const D3DXMATRIX& argRootTransformationMatrix)
|
||||
{
|
||||
if (m_TransformationAnimation != NULL)
|
||||
{
|
||||
if (argT != m_LastAnimationTime)
|
||||
{
|
||||
if (m_Parent != NULL)
|
||||
{
|
||||
m_Transformation = (m_TransformationAnimation->GetTransformationAtTime(argT) * m_InvPoseTransformation) * m_Parent->GetTransformationAtTime(argT, argRootTransformationMatrix);
|
||||
m_Transformation = m_InvPoseTransformation * m_TransformationAnimation->GetTransformationAtTime(argT);
|
||||
//m_Transformation = m_Transformation * ( * m_InvPoseTransformation);
|
||||
}
|
||||
else
|
||||
m_Transformation = m_TransformationAnimation->GetTransformationAtTime(argT) * m_InvPoseTransformation;
|
||||
}
|
||||
}
|
||||
return m_Transformation;
|
||||
}
|
||||
|
||||
|
||||
const D3DXMATRIX& Bone::get_PoseTransformation() const
|
||||
{
|
||||
return m_PoseTransformation;
|
||||
}
|
||||
|
||||
|
||||
void Bone::set_Parent(IBone* argParent)
|
||||
{
|
||||
if (m_Parent != NULL)
|
||||
{
|
||||
std::vector<IBone*>& children = m_Parent->get_ChildBones();
|
||||
for (unsigned int i = 0; i < children.size(); ++i)
|
||||
if (children[i] == this)
|
||||
{
|
||||
children.erase(children.begin() + i);
|
||||
break;
|
||||
}
|
||||
}
|
||||
m_Parent = argParent;
|
||||
if (m_Parent != NULL)
|
||||
m_Parent->get_ChildBones().push_back(this);
|
||||
}
|
||||
|
||||
|
||||
IBone* Bone::get_Parent() const
|
||||
{
|
||||
return m_Parent;
|
||||
}
|
||||
|
||||
|
||||
std::vector<IBone*>& Bone::get_ChildBones()
|
||||
{
|
||||
return m_Children;
|
||||
}
|
||||
|
||||
|
||||
std::wstring Bone::get_Name() const
|
||||
{
|
||||
return m_Name;
|
||||
}
|
||||
|
||||
|
||||
int Bone::get_Index() const
|
||||
{
|
||||
return m_BoneIndex;
|
||||
}
|
||||
|
||||
|
||||
void Bone::set_TransformationAnimation(ITransformationAnimation* argTa)
|
||||
{
|
||||
m_TransformationAnimation = argTa;
|
||||
m_LastAnimationTime = -1.0f;
|
||||
m_Transformation = D3DXMATRIX();
|
||||
}
|
||||
|
||||
|
||||
ITransformationAnimation* Bone::get_TransformationAnimation() const
|
||||
{
|
||||
return m_TransformationAnimation;
|
||||
}
|
||||
|
||||
|
||||
std::map<int, IBone*>& Bone::get_BoneIndexList()
|
||||
{
|
||||
if (m_Parent != NULL)
|
||||
return m_Parent->get_BoneIndexList();
|
||||
|
||||
if (m_BoneIndexList.empty())
|
||||
this->FillBoneIndexList(this, m_BoneIndexList);
|
||||
|
||||
return m_BoneIndexList;
|
||||
}
|
||||
|
||||
|
||||
D3DXMATRIX* Bone::get_MatrixArray()
|
||||
{
|
||||
if (m_MatrixArray == NULL)
|
||||
{
|
||||
m_MatrixArraySize = this->get_BoneIndexList().size();
|
||||
m_MatrixArray = new D3DXMATRIX[m_MatrixArraySize];
|
||||
}
|
||||
return m_MatrixArray;
|
||||
}
|
||||
|
||||
|
||||
unsigned int Bone::get_MatrixArraySize()
|
||||
{
|
||||
if (m_MatrixArray == NULL)
|
||||
this->get_MatrixArray();
|
||||
return m_MatrixArraySize;
|
||||
}
|
||||
|
||||
|
||||
void Bone::FillBoneIndexList(IBone* argCurrentBone, std::map<int, IBone*>& argList)
|
||||
{
|
||||
argList[argCurrentBone->get_Index()] = argCurrentBone;
|
||||
for (unsigned int i = 0; i < argCurrentBone->get_ChildBones().size(); ++i)
|
||||
this->FillBoneIndexList(argCurrentBone->get_ChildBones()[i], argList);
|
||||
}
|
||||
57
aiwaz/Aiwaz/Resources/Bone/Bone.h
Normal file
57
aiwaz/Aiwaz/Resources/Bone/Bone.h
Normal file
@@ -0,0 +1,57 @@
|
||||
#pragma once
|
||||
|
||||
#include "IBone.h"
|
||||
#include "IEngine.h"
|
||||
|
||||
class Bone
|
||||
: public IBone
|
||||
{
|
||||
public:
|
||||
Bone(IEngine& argEngine);
|
||||
virtual ~Bone();
|
||||
|
||||
virtual void Initialize(const string16& argName, int argIndex, const D3DXVECTOR3& argPoseTranslation, const D3DXVECTOR3& argPoseScale, const D3DXQUATERNION& argPoseRotation);
|
||||
|
||||
virtual const D3DXMATRIX& GetTransformationAtTime(float argTime, const D3DXMATRIX& argRootTransformationMatrix);
|
||||
virtual const D3DXMATRIX& get_PoseTransformation() const;
|
||||
|
||||
virtual void set_Parent(IBone* argParent_);
|
||||
virtual IBone* get_Parent() const;
|
||||
virtual std::vector<IBone*>& get_ChildBones();
|
||||
|
||||
virtual string16 get_Name() const;
|
||||
virtual int get_Index() const;
|
||||
|
||||
virtual void set_TransformationAnimation(ITransformationAnimation* argTransformationAnimation);
|
||||
virtual ITransformationAnimation* get_TransformationAnimation() const;
|
||||
|
||||
virtual std::map<int, IBone*>& get_BoneIndexList();
|
||||
|
||||
virtual D3DXMATRIX* get_MatrixArray();
|
||||
virtual unsigned int get_MatrixArraySize();
|
||||
|
||||
private:
|
||||
void FillBoneIndexList(IBone* argCurrentBone, std::map<int, IBone*>& argList);
|
||||
|
||||
private:
|
||||
IEngine& m_Engine;
|
||||
|
||||
string16 m_Name;
|
||||
int m_BoneIndex;
|
||||
|
||||
D3DXMATRIX m_PoseTransformation;
|
||||
D3DXMATRIX m_InvPoseTransformation;
|
||||
|
||||
float m_LastAnimationTime;
|
||||
D3DXMATRIX m_Transformation;
|
||||
|
||||
std::vector<IBone*> m_Children;
|
||||
IBone* m_Parent;
|
||||
|
||||
ITransformationAnimation* m_TransformationAnimation;
|
||||
|
||||
std::map<int, IBone*> m_BoneIndexList;
|
||||
|
||||
D3DXMATRIX* m_MatrixArray;
|
||||
unsigned int m_MatrixArraySize;
|
||||
};
|
||||
118
aiwaz/Aiwaz/Resources/Bone/BoneController.cpp
Normal file
118
aiwaz/Aiwaz/Resources/Bone/BoneController.cpp
Normal file
@@ -0,0 +1,118 @@
|
||||
#include "stdafx.h"
|
||||
#include "IResourceFactory.h"
|
||||
#include "BoneController.h"
|
||||
#include "../ShaderParameterCollection/Types/Types.h"
|
||||
|
||||
|
||||
BoneController::BoneController(IEngine& argEngine)
|
||||
: ShaderParameterCollection(argEngine)
|
||||
, m_StartTime(0.0)
|
||||
, m_LastMatrixArray(NULL)
|
||||
{
|
||||
}
|
||||
|
||||
|
||||
BoneController::~BoneController()
|
||||
{
|
||||
m_Engine.get_ResourceFactory().DeleteBoneController(*const_cast<BoneController*>(this), true);
|
||||
}
|
||||
|
||||
|
||||
void BoneController::Initialize(IBone& argRootBone)
|
||||
{
|
||||
m_RootBone = &argRootBone;
|
||||
m_Bones = m_RootBone->get_BoneIndexList();
|
||||
}
|
||||
|
||||
|
||||
void BoneController::Initialize(const IBoneController& argOther)
|
||||
{
|
||||
m_RootBone = &argOther.get_RootBone();
|
||||
m_Bones = m_RootBone->get_BoneIndexList();
|
||||
|
||||
m_CurrentSequence = argOther.get_CurrentSequence();
|
||||
m_Sequences = argOther.get_Sequences();
|
||||
|
||||
this->PlaySequence(m_CurrentSequence);
|
||||
}
|
||||
|
||||
|
||||
void BoneController::Apply()
|
||||
{
|
||||
float lf_Time = 0.0f;
|
||||
if (!m_CurrentSequence.empty())
|
||||
lf_Time = get_CurrentTime();
|
||||
|
||||
int i = 0;
|
||||
D3DXMATRIX* lr_MatrixArray_ = m_RootBone->get_MatrixArray();
|
||||
for (std::map<int, IBone*>::const_iterator lk_Iter = m_Bones.begin(); lk_Iter != m_Bones.end(); ++lk_Iter, ++i)
|
||||
lr_MatrixArray_[i] = lk_Iter->second->GetTransformationAtTime(lf_Time, D3DXMATRIX());
|
||||
|
||||
if (m_LastMatrixArray != lr_MatrixArray_)
|
||||
{
|
||||
m_LastMatrixArray = lr_MatrixArray_;
|
||||
this->SetParameter("BoneMatrix", new Matrix4x4ShaderParameter(m_LastMatrixArray, m_RootBone->get_MatrixArraySize(), ParameterBindType::BindBySemantic));
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
void BoneController::RegisterSequence(const string16& argName, float argStart, float argEnd, bool argLoop)
|
||||
{
|
||||
Sequence lr_NewSequence;
|
||||
lr_NewSequence.m_Start = argStart;
|
||||
lr_NewSequence.m_End = argEnd;
|
||||
lr_NewSequence.m_Loop = argLoop;
|
||||
m_Sequences[argName] = lr_NewSequence;
|
||||
}
|
||||
|
||||
|
||||
void BoneController::PlaySequence(const string16& argName)
|
||||
{
|
||||
m_StartTime = m_Engine.get_Timeline().get_DemoTime();
|
||||
|
||||
std::map<string16, Sequence >::iterator lk_Iter = m_Sequences.find(argName);
|
||||
if (lk_Iter != m_Sequences.end())
|
||||
{
|
||||
m_CurrentSequenceInfo = lk_Iter->second;
|
||||
m_CurrentSequence = argName;
|
||||
}
|
||||
else
|
||||
m_CurrentSequence = string16();
|
||||
}
|
||||
|
||||
|
||||
const string16& BoneController::get_CurrentSequence() const
|
||||
{
|
||||
return m_CurrentSequence;
|
||||
}
|
||||
|
||||
|
||||
float BoneController::get_CurrentTime()
|
||||
{
|
||||
float lf_CurrentTime = static_cast<float>(m_Engine.get_Timeline().get_DemoTime() - m_StartTime);
|
||||
lf_CurrentTime = lf_CurrentTime / (m_CurrentSequenceInfo.m_End - m_CurrentSequenceInfo.m_Start);
|
||||
lf_CurrentTime = (m_CurrentSequenceInfo.m_End - m_CurrentSequenceInfo.m_Start) * lf_CurrentTime + m_CurrentSequenceInfo.m_Start;
|
||||
|
||||
if (lf_CurrentTime >= m_CurrentSequenceInfo.m_End)
|
||||
{
|
||||
while (m_CurrentSequenceInfo.m_Loop && lf_CurrentTime >= m_CurrentSequenceInfo.m_End)
|
||||
{
|
||||
lf_CurrentTime -= m_CurrentSequenceInfo.m_End;
|
||||
m_StartTime += m_CurrentSequenceInfo.m_End;
|
||||
}
|
||||
if (!m_CurrentSequenceInfo.m_Loop)
|
||||
lf_CurrentTime = m_CurrentSequenceInfo.m_End;
|
||||
}
|
||||
else if (lf_CurrentTime < m_CurrentSequenceInfo.m_Start)
|
||||
{
|
||||
while (m_CurrentSequenceInfo.m_Loop && lf_CurrentTime < m_CurrentSequenceInfo.m_Start)
|
||||
{
|
||||
lf_CurrentTime += m_CurrentSequenceInfo.m_Start;
|
||||
m_StartTime -= m_CurrentSequenceInfo.m_Start;
|
||||
}
|
||||
if (!m_CurrentSequenceInfo.m_Loop)
|
||||
lf_CurrentTime = m_CurrentSequenceInfo.m_Start;
|
||||
}
|
||||
|
||||
return lf_CurrentTime;
|
||||
}
|
||||
51
aiwaz/Aiwaz/Resources/Bone/BoneController.h
Normal file
51
aiwaz/Aiwaz/Resources/Bone/BoneController.h
Normal file
@@ -0,0 +1,51 @@
|
||||
#pragma once
|
||||
|
||||
#include "IBone.h"
|
||||
#include "IEngine.h"
|
||||
#include "ITimeLine.h"
|
||||
#include "IUpdatable.h"
|
||||
#include "../ShaderParameterCollection/ShaderParameterCollection.h"
|
||||
|
||||
|
||||
class BoneController
|
||||
: public IBoneController
|
||||
, public ShaderParameterCollection
|
||||
, public IUpdatable
|
||||
|
||||
{
|
||||
public:
|
||||
BoneController(IEngine& argEngine);
|
||||
virtual ~BoneController();
|
||||
|
||||
virtual void Initialize(IBone& argRootBone);
|
||||
virtual void Initialize(const IBoneController& argOther);
|
||||
virtual void Apply();
|
||||
|
||||
virtual void RegisterSequence(const string16& argName, float argStart, float argEnd, bool argLoop);
|
||||
virtual void PlaySequence(const string16& argName);
|
||||
|
||||
virtual const string16& get_CurrentSequence() const;
|
||||
virtual const std::map<string16, Sequence >& get_Sequences() const { return m_Sequences; }
|
||||
|
||||
virtual IBone& get_RootBone() const { return *m_RootBone; }
|
||||
|
||||
// IUpdatable
|
||||
virtual void Update(bool argForceUpdate) { this->Apply(); }
|
||||
virtual bool get_WantsUpdate() const { return true; }
|
||||
|
||||
protected:
|
||||
// ICommandUser
|
||||
virtual string8 get_UserName() const { return "BoneController"; }
|
||||
|
||||
private:
|
||||
|
||||
float get_CurrentTime();
|
||||
|
||||
IBone* m_RootBone;
|
||||
double m_StartTime;
|
||||
string16 m_CurrentSequence;
|
||||
Sequence m_CurrentSequenceInfo;
|
||||
std::map<string16, Sequence > m_Sequences;
|
||||
std::map<int, IBone*> m_Bones;
|
||||
D3DXMATRIX* m_LastMatrixArray;
|
||||
};
|
||||
43
aiwaz/Aiwaz/Resources/Camera/BaseCamera.cpp
Normal file
43
aiwaz/Aiwaz/Resources/Camera/BaseCamera.cpp
Normal file
@@ -0,0 +1,43 @@
|
||||
#include "stdafx.h"
|
||||
#include "BaseCamera.h"
|
||||
|
||||
|
||||
BaseCamera::BaseCamera(IEngine& argEngine)
|
||||
: Transformation(argEngine)
|
||||
, m_NearClip(1.0f)
|
||||
, m_FarClip(100.0f)
|
||||
, m_AspectRatio(1.0f)
|
||||
{
|
||||
this->set_IsPreconditionForFollowingShaders(true);
|
||||
this->RecreateAllShaderParameters();
|
||||
}
|
||||
|
||||
|
||||
void BaseCamera::set_AspectRatio(float argValue)
|
||||
{
|
||||
m_AspectRatio = argValue;
|
||||
m_IsDirty = true;
|
||||
}
|
||||
|
||||
|
||||
void BaseCamera::set_FarClip(float argValue)
|
||||
{
|
||||
m_FarClip = argValue;
|
||||
m_IsDirty = true;
|
||||
}
|
||||
|
||||
|
||||
void BaseCamera::set_NearClip(float argValue)
|
||||
{
|
||||
m_NearClip = argValue;
|
||||
m_IsDirty = true;
|
||||
}
|
||||
|
||||
|
||||
void BaseCamera::RecreateAllShaderParameters()
|
||||
{
|
||||
this->SetParameter("ViewMatrix", &m_ViewMatrix, ParameterBindType::BindBySemantic);
|
||||
this->SetParameter("ProjectionMatrix", &m_ProjectionMatrix, ParameterBindType::BindBySemantic);
|
||||
|
||||
Transformation::RecreateAllShaderParameters();
|
||||
}
|
||||
40
aiwaz/Aiwaz/Resources/Camera/BaseCamera.h
Normal file
40
aiwaz/Aiwaz/Resources/Camera/BaseCamera.h
Normal file
@@ -0,0 +1,40 @@
|
||||
#pragma once
|
||||
|
||||
#include "ICamera.h"
|
||||
#include "IEngine.h"
|
||||
#include "../Transformation/Transformation.h"
|
||||
|
||||
|
||||
class BaseCamera
|
||||
: public Transformation
|
||||
, public ICamera
|
||||
{
|
||||
public:
|
||||
BaseCamera(IEngine& argEngine);
|
||||
|
||||
virtual const D3DXMATRIX& get_ProjectionMatrix() const { return m_ProjectionMatrix; }
|
||||
virtual const D3DXMATRIX& get_ViewMatrix() const { return m_ViewMatrix; }
|
||||
|
||||
virtual void set_AspectRatio(float argValue);
|
||||
virtual float get_AspectRatio() const { return m_AspectRatio; }
|
||||
|
||||
virtual void set_FarClip(float argValue);
|
||||
virtual float get_FarClip() const { return m_FarClip; }
|
||||
|
||||
virtual void set_NearClip(float argValue);
|
||||
virtual float get_NearClip() const { return m_NearClip; }
|
||||
|
||||
virtual const ViewFrustum& get_ViewFrustum() const { return m_Frustum; }
|
||||
|
||||
protected:
|
||||
virtual void RecreateAllShaderParameters();
|
||||
|
||||
protected:
|
||||
float m_NearClip;
|
||||
float m_FarClip;
|
||||
float m_AspectRatio;
|
||||
|
||||
D3DXMATRIX m_ProjectionMatrix;
|
||||
D3DXMATRIX m_ViewMatrix;
|
||||
ViewFrustum m_Frustum;
|
||||
};
|
||||
89
aiwaz/Aiwaz/Resources/Camera/OrthographicCamera.cpp
Normal file
89
aiwaz/Aiwaz/Resources/Camera/OrthographicCamera.cpp
Normal file
@@ -0,0 +1,89 @@
|
||||
#include "stdafx.h"
|
||||
#include "IResourceFactory.h"
|
||||
#include "OrthographicCamera.h"
|
||||
|
||||
|
||||
OrthographicCamera::OrthographicCamera(IEngine& argEngine)
|
||||
: BaseCamera(argEngine)
|
||||
, m_Width(1.0f)
|
||||
, m_Height(1.0f)
|
||||
{
|
||||
}
|
||||
|
||||
|
||||
OrthographicCamera::~OrthographicCamera()
|
||||
{
|
||||
m_Engine.get_ResourceFactory().DeleteOrthographicCamera(*const_cast<OrthographicCamera*>(this), true);
|
||||
}
|
||||
|
||||
|
||||
void OrthographicCamera::set_Width(float argValue)
|
||||
{
|
||||
m_Width = argValue;
|
||||
m_IsDirty = true;
|
||||
}
|
||||
|
||||
|
||||
void OrthographicCamera::set_Height(float argValue)
|
||||
{
|
||||
m_Height = argValue;
|
||||
m_IsDirty = true;
|
||||
}
|
||||
|
||||
|
||||
void OrthographicCamera::Update(bool argForceUpdate)
|
||||
{
|
||||
BaseCamera::Update(argForceUpdate);
|
||||
|
||||
D3DXMATRIXA16 projectionMatrix;
|
||||
D3DXMATRIXA16 viewMatrix;
|
||||
|
||||
D3DXVECTOR3 worldPos = this->get_WorldPosition();
|
||||
D3DXVECTOR3 worldDirection = this->get_WorldDirection();
|
||||
D3DXVECTOR3 worldUpDirection = this->get_WorldUpDirection();
|
||||
|
||||
::D3DXMatrixOrthoLH(&projectionMatrix, m_Width, m_Height, m_NearClip, m_FarClip);
|
||||
::D3DXMatrixLookAtLH(&viewMatrix, &worldPos, &(worldPos + worldDirection), &worldUpDirection);
|
||||
|
||||
m_ProjectionMatrix = projectionMatrix;
|
||||
m_ViewMatrix = viewMatrix;
|
||||
|
||||
// generate view frustum
|
||||
D3DXMATRIXA16 viewProjection = viewMatrix * projectionMatrix;
|
||||
|
||||
// Left plane
|
||||
m_Frustum.Plane[0].a = viewProjection._14 + viewProjection._11;
|
||||
m_Frustum.Plane[0].b = viewProjection._24 + viewProjection._21;
|
||||
m_Frustum.Plane[0].c = viewProjection._34 + viewProjection._31;
|
||||
m_Frustum.Plane[0].d = viewProjection._44 + viewProjection._41;
|
||||
|
||||
// Right plane
|
||||
m_Frustum.Plane[1].a = viewProjection._14 - viewProjection._11;
|
||||
m_Frustum.Plane[1].b = viewProjection._24 - viewProjection._21;
|
||||
m_Frustum.Plane[1].c = viewProjection._34 - viewProjection._31;
|
||||
m_Frustum.Plane[1].d = viewProjection._44 - viewProjection._41;
|
||||
|
||||
// Top plane
|
||||
m_Frustum.Plane[2].a = viewProjection._14 - viewProjection._12;
|
||||
m_Frustum.Plane[2].b = viewProjection._24 - viewProjection._22;
|
||||
m_Frustum.Plane[2].c = viewProjection._34 - viewProjection._32;
|
||||
m_Frustum.Plane[2].d = viewProjection._44 - viewProjection._42;
|
||||
|
||||
// Bottom plane
|
||||
m_Frustum.Plane[3].a = viewProjection._14 + viewProjection._12;
|
||||
m_Frustum.Plane[3].b = viewProjection._24 + viewProjection._22;
|
||||
m_Frustum.Plane[3].c = viewProjection._34 + viewProjection._32;
|
||||
m_Frustum.Plane[3].d = viewProjection._44 + viewProjection._42;
|
||||
|
||||
// Near plane
|
||||
m_Frustum.Plane[4].a = viewProjection._13;
|
||||
m_Frustum.Plane[4].b = viewProjection._23;
|
||||
m_Frustum.Plane[4].c = viewProjection._33;
|
||||
m_Frustum.Plane[4].d = viewProjection._43;
|
||||
|
||||
// Far plane
|
||||
m_Frustum.Plane[5].a = viewProjection._14 - viewProjection._13;
|
||||
m_Frustum.Plane[5].b = viewProjection._24 - viewProjection._23;
|
||||
m_Frustum.Plane[5].c = viewProjection._34 - viewProjection._33;
|
||||
m_Frustum.Plane[5].d = viewProjection._44 - viewProjection._43;
|
||||
}
|
||||
31
aiwaz/Aiwaz/Resources/Camera/OrthographicCamera.h
Normal file
31
aiwaz/Aiwaz/Resources/Camera/OrthographicCamera.h
Normal file
@@ -0,0 +1,31 @@
|
||||
#pragma once
|
||||
|
||||
#include "BaseCamera.h"
|
||||
|
||||
|
||||
class OrthographicCamera
|
||||
: public BaseCamera
|
||||
, public IOrthographicCamera
|
||||
{
|
||||
public:
|
||||
OrthographicCamera(IEngine& argEngine);
|
||||
virtual ~OrthographicCamera();
|
||||
|
||||
virtual void set_Width(float argValue);
|
||||
virtual float get_Width() const { return m_Width; }
|
||||
|
||||
virtual void set_Height(float argValue);
|
||||
virtual float get_Height() const { return m_Height; }
|
||||
|
||||
virtual void Update(bool argForceUpdate);
|
||||
|
||||
virtual ICamera& get_Base() { return *dynamic_cast<ICamera*>(this); }
|
||||
|
||||
protected:
|
||||
// ICommandUser
|
||||
virtual string8 get_UserName() const { return "OrthographicCamera"; }
|
||||
|
||||
private:
|
||||
float m_Width;
|
||||
float m_Height;
|
||||
};
|
||||
80
aiwaz/Aiwaz/Resources/Camera/PerspectiveCamera.cpp
Normal file
80
aiwaz/Aiwaz/Resources/Camera/PerspectiveCamera.cpp
Normal file
@@ -0,0 +1,80 @@
|
||||
#include "stdafx.h"
|
||||
#include "IResourceFactory.h"
|
||||
#include "PerspectiveCamera.h"
|
||||
|
||||
|
||||
PerspectiveCamera::PerspectiveCamera(IEngine& argEngine)
|
||||
: BaseCamera(argEngine)
|
||||
, m_Fov(90.0f)
|
||||
{
|
||||
}
|
||||
|
||||
PerspectiveCamera::~PerspectiveCamera()
|
||||
{
|
||||
m_Engine.get_ResourceFactory().DeletePerspectiveCamera(*const_cast<PerspectiveCamera*>(this), true);
|
||||
}
|
||||
|
||||
|
||||
void PerspectiveCamera::set_Fov(float argFov)
|
||||
{
|
||||
m_Fov = argFov;
|
||||
m_IsDirty = true;
|
||||
}
|
||||
|
||||
|
||||
void PerspectiveCamera::Update(bool argForceUpdate)
|
||||
{
|
||||
BaseCamera::Update(argForceUpdate);
|
||||
|
||||
D3DXMATRIXA16 projectionMatrix;
|
||||
D3DXMATRIXA16 viewMatrix;
|
||||
|
||||
D3DXVECTOR3 worldPos = this->get_WorldPosition();
|
||||
D3DXVECTOR3 worldDirection = this->get_WorldDirection();
|
||||
D3DXVECTOR3 worldUpDirection = this->get_WorldUpDirection();
|
||||
|
||||
::D3DXMatrixPerspectiveFovLH(&projectionMatrix, static_cast<float>(D3DXToRadian(m_Fov)), m_AspectRatio, m_NearClip, m_FarClip);
|
||||
::D3DXMatrixLookAtLH(&viewMatrix, &worldPos, &(worldPos + worldDirection), &worldUpDirection);
|
||||
|
||||
m_ProjectionMatrix = projectionMatrix;
|
||||
m_ViewMatrix = viewMatrix;
|
||||
|
||||
// generate view frustum
|
||||
D3DXMATRIXA16 viewProjection = viewMatrix * projectionMatrix;
|
||||
|
||||
// Left plane
|
||||
m_Frustum.Plane[0].a = viewProjection._14 + viewProjection._11;
|
||||
m_Frustum.Plane[0].b = viewProjection._24 + viewProjection._21;
|
||||
m_Frustum.Plane[0].c = viewProjection._34 + viewProjection._31;
|
||||
m_Frustum.Plane[0].d = viewProjection._44 + viewProjection._41;
|
||||
|
||||
// Right plane
|
||||
m_Frustum.Plane[1].a = viewProjection._14 - viewProjection._11;
|
||||
m_Frustum.Plane[1].b = viewProjection._24 - viewProjection._21;
|
||||
m_Frustum.Plane[1].c = viewProjection._34 - viewProjection._31;
|
||||
m_Frustum.Plane[1].d = viewProjection._44 - viewProjection._41;
|
||||
|
||||
// Top plane
|
||||
m_Frustum.Plane[2].a = viewProjection._14 - viewProjection._12;
|
||||
m_Frustum.Plane[2].b = viewProjection._24 - viewProjection._22;
|
||||
m_Frustum.Plane[2].c = viewProjection._34 - viewProjection._32;
|
||||
m_Frustum.Plane[2].d = viewProjection._44 - viewProjection._42;
|
||||
|
||||
// Bottom plane
|
||||
m_Frustum.Plane[3].a = viewProjection._14 + viewProjection._12;
|
||||
m_Frustum.Plane[3].b = viewProjection._24 + viewProjection._22;
|
||||
m_Frustum.Plane[3].c = viewProjection._34 + viewProjection._32;
|
||||
m_Frustum.Plane[3].d = viewProjection._44 + viewProjection._42;
|
||||
|
||||
// Near plane
|
||||
m_Frustum.Plane[4].a = viewProjection._13;
|
||||
m_Frustum.Plane[4].b = viewProjection._23;
|
||||
m_Frustum.Plane[4].c = viewProjection._33;
|
||||
m_Frustum.Plane[4].d = viewProjection._43;
|
||||
|
||||
// Far plane
|
||||
m_Frustum.Plane[5].a = viewProjection._14 - viewProjection._13;
|
||||
m_Frustum.Plane[5].b = viewProjection._24 - viewProjection._23;
|
||||
m_Frustum.Plane[5].c = viewProjection._34 - viewProjection._33;
|
||||
m_Frustum.Plane[5].d = viewProjection._44 - viewProjection._43;
|
||||
}
|
||||
27
aiwaz/Aiwaz/Resources/Camera/PerspectiveCamera.h
Normal file
27
aiwaz/Aiwaz/Resources/Camera/PerspectiveCamera.h
Normal file
@@ -0,0 +1,27 @@
|
||||
#pragma once
|
||||
|
||||
#include "BaseCamera.h"
|
||||
|
||||
|
||||
class PerspectiveCamera
|
||||
: public BaseCamera
|
||||
, public IPerspectiveCamera
|
||||
{
|
||||
public:
|
||||
PerspectiveCamera(IEngine& argEngine);
|
||||
virtual ~PerspectiveCamera();
|
||||
|
||||
virtual void set_Fov(float argValue);
|
||||
virtual float get_Fov() const { return m_Fov; }
|
||||
|
||||
virtual void Update(bool argForceUpdate);
|
||||
|
||||
virtual ICamera& get_Base() { return *dynamic_cast<ICamera*>(this); }
|
||||
|
||||
protected:
|
||||
// ICommandUser
|
||||
virtual string8 get_UserName() const { return "PerspectiveCamera"; }
|
||||
|
||||
private:
|
||||
float m_Fov;
|
||||
};
|
||||
431
aiwaz/Aiwaz/Resources/GeometryBuffer/GeometryBuffer.cpp
Normal file
431
aiwaz/Aiwaz/Resources/GeometryBuffer/GeometryBuffer.cpp
Normal file
@@ -0,0 +1,431 @@
|
||||
#include "stdafx.h"
|
||||
#include "IResourceFactory.h"
|
||||
#include "GeometryBuffer.h"
|
||||
|
||||
|
||||
GeometryBuffer::GeometryBuffer(IEngine& argEngine)
|
||||
: m_Engine(argEngine)
|
||||
, m_VertexBuffer(NULL)
|
||||
, m_IndexBuffer(NULL)
|
||||
, m_InputElementDesc(NULL)
|
||||
, m_VertexCount(0)
|
||||
, m_VertexElementSize(0)
|
||||
, m_IndexCount(0)
|
||||
, m_VertexOffset(0)
|
||||
, m_VertexDataMapped(false)
|
||||
, m_IndexDataMapped(false)
|
||||
, m_RawVertexData_(NULL)
|
||||
, m_RawIndexData(NULL)
|
||||
, m_PrimitiveTopology(PrimitiveTopology::TriangleList)
|
||||
, m_IndexOffset(0)
|
||||
, m_UsableIndexCount(0)
|
||||
{
|
||||
m_Commands.push_back(new Command(this, CommandFlags::None, SetIndexBufferCommandType, 1));
|
||||
m_Commands.push_back(new Command(this, CommandFlags::None, SetVertexBufferCommandType, 0));
|
||||
m_Commands.push_back(new Command(this, CommandFlags::EndChain | CommandFlags::Unique, DrawGeometryCommandType, 6));
|
||||
}
|
||||
|
||||
|
||||
GeometryBuffer::~GeometryBuffer()
|
||||
{
|
||||
this->Uninitialize();
|
||||
m_Engine.get_ResourceFactory().DeleteGeometryBuffer(*const_cast<GeometryBuffer*>(this), true);
|
||||
}
|
||||
|
||||
|
||||
void GeometryBuffer::Uninitialize()
|
||||
{
|
||||
if (m_Engine.get_EngineStates().LastIndexBufferProvider == this)
|
||||
m_Engine.get_EngineStates().LastIndexBufferProvider = NULL;
|
||||
if (m_Engine.get_EngineStates().LastVertexBufferProvider == this)
|
||||
m_Engine.get_EngineStates().LastVertexBufferProvider = NULL;
|
||||
|
||||
this->DeleteVertexData();
|
||||
this->DeleteIndexData();
|
||||
}
|
||||
|
||||
|
||||
void GeometryBuffer::SetVertexData(uint32 argVertexCount, uint32 argVertexElementSize, void* a_VertexData_, const std::vector<VertexElement>& argVertexElements, bool argNeedsDynamicAccess)
|
||||
{
|
||||
this->DeleteVertexData();
|
||||
|
||||
D3D10_BUFFER_DESC desc;
|
||||
desc.Usage = argNeedsDynamicAccess ? D3D10_USAGE_DYNAMIC : D3D10_USAGE_DEFAULT;
|
||||
desc.ByteWidth = argVertexElementSize * argVertexCount;
|
||||
desc.BindFlags = D3D10_BIND_VERTEX_BUFFER;
|
||||
desc.CPUAccessFlags = argNeedsDynamicAccess ? D3D10_CPU_ACCESS_WRITE : 0;
|
||||
desc.MiscFlags = 0;
|
||||
|
||||
D3D10_SUBRESOURCE_DATA initData;
|
||||
initData.pSysMem = a_VertexData_;
|
||||
if (S_OK != m_Engine.get_DX10Device().CreateBuffer(&desc, &initData, &m_VertexBuffer))
|
||||
{
|
||||
throw L"GeometryBuffer: Unable to create vertex buffer.";
|
||||
}
|
||||
|
||||
m_VertexCount = argVertexCount;
|
||||
m_VertexElementSize = argVertexElementSize;
|
||||
m_VertexElements = argVertexElements;
|
||||
|
||||
m_RawVertexData_ = new char[argVertexElementSize * argVertexCount];
|
||||
::memcpy(m_RawVertexData_, a_VertexData_, argVertexElementSize * argVertexCount);
|
||||
|
||||
if (m_InputElementDesc == NULL)
|
||||
{
|
||||
if (!m_VertexElements.empty())
|
||||
{
|
||||
m_InputElementDesc = new D3D10_INPUT_ELEMENT_DESC[m_VertexElements.size()];
|
||||
|
||||
for (uint32 i = 0; i < m_VertexElements.size(); ++i)
|
||||
{
|
||||
D3D10_INPUT_ELEMENT_DESC desc;
|
||||
VertexElement& element = m_VertexElements[i];
|
||||
|
||||
desc.AlignedByteOffset = D3D10_APPEND_ALIGNED_ELEMENT;
|
||||
desc.Format = (DXGI_FORMAT)element.m_ElementFormat;
|
||||
desc.InputSlot = 0; // should this be a parameter too?
|
||||
desc.InputSlotClass = D3D10_INPUT_PER_VERTEX_DATA;
|
||||
desc.InstanceDataStepRate = 0;
|
||||
desc.SemanticIndex = element.m_NameIndex;
|
||||
desc.SemanticName = element.m_SemanticName.c_str();
|
||||
m_InputElementDesc[i] = desc;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
void GeometryBuffer::DeleteVertexData()
|
||||
{
|
||||
if (m_VertexBuffer != NULL)
|
||||
m_Engine.get_DX10Device().ClearState();
|
||||
|
||||
m_VertexElements.clear();
|
||||
|
||||
if (m_VertexBuffer != NULL)
|
||||
m_VertexBuffer->Release();
|
||||
m_VertexBuffer = NULL;
|
||||
|
||||
m_VertexCount = 0;
|
||||
m_VertexElementSize = 0;
|
||||
m_VertexDataMapped = false;
|
||||
|
||||
if (m_RawVertexData_ != NULL)
|
||||
delete [] m_RawVertexData_;
|
||||
m_RawVertexData_ = NULL;
|
||||
|
||||
if (m_InputElementDesc != NULL)
|
||||
delete [] m_InputElementDesc;
|
||||
m_InputElementDesc = NULL;
|
||||
}
|
||||
|
||||
|
||||
void GeometryBuffer::SetIndexData(uint32 argIndexCount, uint32* aui_IndexData_, bool argNeedsDynamicAccess)
|
||||
{
|
||||
this->DeleteIndexData();
|
||||
|
||||
D3D10_BUFFER_DESC desc;
|
||||
desc.Usage = D3D10_USAGE_DEFAULT;
|
||||
desc.ByteWidth = sizeof(uint32) * argIndexCount;
|
||||
desc.BindFlags = D3D10_BIND_INDEX_BUFFER;
|
||||
desc.CPUAccessFlags = argNeedsDynamicAccess ? D3D10_CPU_ACCESS_WRITE : 0;
|
||||
desc.MiscFlags = 0;
|
||||
|
||||
D3D10_SUBRESOURCE_DATA initData;
|
||||
initData.pSysMem = aui_IndexData_;
|
||||
initData.SysMemPitch = 0;
|
||||
initData.SysMemSlicePitch = 0;
|
||||
if (S_OK != m_Engine.get_DX10Device().CreateBuffer(&desc, &initData, &m_IndexBuffer))
|
||||
{
|
||||
throw L"GeometryBuffer: Unable to create index buffer.";
|
||||
}
|
||||
|
||||
m_IndexCount = argIndexCount;
|
||||
m_UsableIndexCount = argIndexCount;
|
||||
m_IndexOffset = 0;
|
||||
|
||||
m_RawIndexData = new uint32[m_IndexCount];
|
||||
::memcpy(m_RawIndexData, aui_IndexData_, sizeof(uint32) * m_IndexCount);
|
||||
}
|
||||
|
||||
|
||||
void GeometryBuffer::DeleteIndexData()
|
||||
{
|
||||
if (m_IndexBuffer != NULL)
|
||||
m_Engine.get_DX10Device().ClearState();
|
||||
|
||||
if (m_IndexBuffer != NULL)
|
||||
m_IndexBuffer->Release();
|
||||
m_IndexBuffer = NULL;
|
||||
|
||||
if (m_RawIndexData != NULL)
|
||||
delete [] m_RawIndexData;
|
||||
m_RawIndexData = NULL;
|
||||
|
||||
m_IndexCount = 0;
|
||||
|
||||
while (!m_VertexLayoutsPerShaderAndPass.empty())
|
||||
{
|
||||
while (!m_VertexLayoutsPerShaderAndPass.begin()->second.empty())
|
||||
{
|
||||
m_VertexLayoutsPerShaderAndPass.begin()->second.back()->Release();
|
||||
m_VertexLayoutsPerShaderAndPass.begin()->second.pop_back();
|
||||
}
|
||||
m_VertexLayoutsPerShaderAndPass.erase(m_VertexLayoutsPerShaderAndPass.begin());
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
void* GeometryBuffer::MapVertexBuffer(DataAccessMode::Enumeration argAccessMode)
|
||||
{
|
||||
if (m_VertexBuffer == NULL)
|
||||
{
|
||||
throw L"GeometryBuffer: Access forbidden until resource has been initialized.";
|
||||
}
|
||||
|
||||
if (m_VertexDataMapped)
|
||||
{
|
||||
throw L"GeometryBuffer: Only one access to the vertex buffer at one time possible.";
|
||||
}
|
||||
|
||||
void* dataPointer = NULL;
|
||||
if (S_OK != m_VertexBuffer->Map((D3D10_MAP)argAccessMode, 0, &dataPointer))
|
||||
{
|
||||
throw L"GeometryBuffer: Access to the vertex buffer was not successfull.";
|
||||
}
|
||||
|
||||
m_VertexDataMapped = true;
|
||||
|
||||
return dataPointer;
|
||||
}
|
||||
|
||||
|
||||
void GeometryBuffer::UnmapVertexBuffer()
|
||||
{
|
||||
if (m_VertexBuffer == NULL)
|
||||
{
|
||||
throw L"GeometryBuffer: Access forbidden until resource has been initialized.";
|
||||
}
|
||||
|
||||
if (!m_VertexDataMapped)
|
||||
{
|
||||
throw L"GeometryBuffer: No access was done ending the access to the vertex buffer is not possible.";
|
||||
}
|
||||
|
||||
m_VertexBuffer->Unmap();
|
||||
|
||||
m_VertexDataMapped = false;
|
||||
}
|
||||
|
||||
|
||||
uint32* GeometryBuffer::MapIndexBuffer(DataAccessMode::Enumeration argAccessMode)
|
||||
{
|
||||
if (m_IndexBuffer == NULL)
|
||||
{
|
||||
throw L"GeometryBuffer: Access forbidden until resource has been initialized.";
|
||||
}
|
||||
|
||||
if (m_IndexDataMapped)
|
||||
{
|
||||
throw L"GeometryBuffer: Only one access to the index buffer at one time possible.";
|
||||
}
|
||||
|
||||
void* dataPointer = NULL;
|
||||
if (S_OK != m_IndexBuffer->Map((D3D10_MAP)argAccessMode, 0, &dataPointer))
|
||||
{
|
||||
throw L"GeometryBuffer: Access to the index buffer was not successfull.";
|
||||
}
|
||||
|
||||
m_IndexDataMapped = true;
|
||||
|
||||
return (uint32*)dataPointer;
|
||||
}
|
||||
|
||||
|
||||
void GeometryBuffer::UnmapIndexBuffer()
|
||||
{
|
||||
if (m_IndexBuffer == NULL)
|
||||
{
|
||||
throw L"GeometryBuffer: Access forbidden until resource has been initialized.";
|
||||
}
|
||||
|
||||
if (!m_IndexDataMapped)
|
||||
{
|
||||
throw L"GeometryBuffer: No access was done ending the access to the index buffer is not possible.";
|
||||
}
|
||||
|
||||
m_IndexBuffer->Unmap();
|
||||
|
||||
m_IndexDataMapped = false;
|
||||
}
|
||||
|
||||
|
||||
void GeometryBuffer::ConvertToAdjacency()
|
||||
{
|
||||
switch (m_PrimitiveTopology)
|
||||
{
|
||||
case PrimitiveTopology::LineList:
|
||||
case PrimitiveTopology::LineStrip:
|
||||
case PrimitiveTopology::TriangleList:
|
||||
case PrimitiveTopology::TriangleStrip:
|
||||
break;
|
||||
default:
|
||||
return;
|
||||
}
|
||||
|
||||
D3D10_INPUT_ELEMENT_DESC inputLayout[2] =
|
||||
{
|
||||
{ "POSITION", 0, DXGI_FORMAT_R32G32B32_FLOAT, 0, 0, D3D10_INPUT_PER_VERTEX_DATA, 0 },
|
||||
{ "END", 0, DXGI_FORMAT_R8_UINT, 0, 0, D3D10_INPUT_PER_VERTEX_DATA, 0 },
|
||||
};
|
||||
|
||||
inputLayout[1].AlignedByteOffset = m_VertexElementSize - 1;
|
||||
|
||||
// create the mesh
|
||||
uint32 numVertices = m_VertexCount;
|
||||
uint32 numIndices = m_IndexCount;
|
||||
uint32 Options = D3DX10_MESH_32_BIT;
|
||||
ID3DX10Mesh* mesh = NULL;
|
||||
|
||||
if (S_OK != D3DX10CreateMesh(&m_Engine.get_DX10Device(),
|
||||
inputLayout,
|
||||
2,
|
||||
inputLayout[0].SemanticName,
|
||||
numVertices,
|
||||
numIndices / 3,
|
||||
Options,
|
||||
&mesh ) )
|
||||
{
|
||||
throw L"GeometryBuffer: Unable to create temp. mesh for adjacency data generation.";
|
||||
}
|
||||
|
||||
//set the VB
|
||||
mesh->SetVertexData(0, (void*)m_RawVertexData_);
|
||||
|
||||
//set the IB
|
||||
mesh->SetIndexData((void*)m_RawIndexData, numIndices);
|
||||
|
||||
//generate adjacency
|
||||
const float epsilon = 0.0f;
|
||||
mesh->GenerateAdjacencyAndPointReps(epsilon);
|
||||
|
||||
//generate adjacency indices
|
||||
mesh->GenerateGSAdjacency();
|
||||
|
||||
//get the adjacency data out of the mesh
|
||||
ID3DX10MeshBuffer* indexBufferMesh = NULL;
|
||||
unsigned char* adjIndices = NULL;
|
||||
SIZE_T Size = 0;
|
||||
|
||||
if(S_OK != mesh->GetIndexBuffer(&indexBufferMesh))
|
||||
{
|
||||
throw L"GeometryBuffer: Unable to retrive indexdata for adjacency data generation.";
|
||||
}
|
||||
|
||||
if(S_OK != indexBufferMesh->Map((void**)&adjIndices, &Size))
|
||||
{
|
||||
throw L"GeometryBuffer: Unable to map indexdata for adjacency data generation.";
|
||||
}
|
||||
|
||||
this->SetIndexData((uint32)Size/sizeof(uint32), (uint32*)adjIndices, false);
|
||||
|
||||
//cleanup
|
||||
indexBufferMesh->Unmap();
|
||||
indexBufferMesh->Release();
|
||||
mesh->Release();
|
||||
|
||||
switch (m_PrimitiveTopology)
|
||||
{
|
||||
case PrimitiveTopology::LineList:
|
||||
this->set_PrimitiveTopology(PrimitiveTopology::LineListAdjacency);
|
||||
break;
|
||||
case PrimitiveTopology::LineStrip:
|
||||
this->set_PrimitiveTopology(PrimitiveTopology::LineStripAdjacency);
|
||||
break;
|
||||
case PrimitiveTopology::TriangleList:
|
||||
this->set_PrimitiveTopology(PrimitiveTopology::TriangleListAdjacency);
|
||||
break;
|
||||
case PrimitiveTopology::TriangleStrip:
|
||||
this->set_PrimitiveTopology(PrimitiveTopology::TriangleStripAdjacency);
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
CommandExecuteResult::Enumeration GeometryBuffer::ExecuteCommand(unsigned char argCommandType, ICommandBuffer& argCurrentBuffer, uint32 argCurrentPositon)
|
||||
{
|
||||
ID3D10Device& device = m_Engine.get_DX10Device();
|
||||
|
||||
if (argCommandType == GeometryBuffer::SetIndexBufferCommandType)
|
||||
{
|
||||
if (m_Engine.get_EngineStates().LastIndexBufferProvider != this)
|
||||
{
|
||||
device.IASetIndexBuffer(m_IndexBuffer, DXGI_FORMAT_R32_UINT, m_IndexOffset);
|
||||
m_Engine.get_EngineStates().LastIndexBufferProvider = this;
|
||||
}
|
||||
}
|
||||
else if (argCommandType == GeometryBuffer::SetVertexBufferCommandType)
|
||||
{
|
||||
if (m_Engine.get_EngineStates().LastVertexBufferProvider != this)
|
||||
{
|
||||
device.IASetVertexBuffers(0, 1, &m_VertexBuffer, &m_VertexElementSize, &m_VertexOffset);
|
||||
device.IASetPrimitiveTopology((D3D10_PRIMITIVE_TOPOLOGY)m_PrimitiveTopology);
|
||||
|
||||
m_Engine.get_EngineStates().LastVertexBufferProvider = this;
|
||||
}
|
||||
}
|
||||
else if (argCommandType == GeometryBuffer::DrawGeometryCommandType)
|
||||
{
|
||||
if (m_Engine.get_EngineStates().LastShader == NULL)
|
||||
std::wcout << std::red << "GeometryBuffer could not render without a valid shader." << std::white << std::endl;
|
||||
else if (m_Engine.get_EngineStates().LastVertexBufferProvider == NULL)
|
||||
std::wcout << std::red << "GeometryBuffer could not render without a valid vertex buffer." << std::white << std::endl;
|
||||
else
|
||||
this->Render(*m_Engine.get_EngineStates().LastShader);
|
||||
}
|
||||
return CommandExecuteResult::None;
|
||||
}
|
||||
|
||||
|
||||
void GeometryBuffer::Render(IShader& argShader)
|
||||
{
|
||||
if (m_VertexElements.empty())
|
||||
return;
|
||||
|
||||
uint32 currentPass = argShader.get_CurrentRenderPass();
|
||||
ID3D10EffectPass* currentEffectPass = argShader.get_DX10Technique()->GetPassByIndex(currentPass);
|
||||
|
||||
ID3D10InputLayout* vertexLayout = NULL;
|
||||
tk_VertexLayoutsPerShaderAndPass::iterator found = m_VertexLayoutsPerShaderAndPass.find(&argShader);
|
||||
if (found != m_VertexLayoutsPerShaderAndPass.end() && found->second.size() > currentPass)
|
||||
{
|
||||
vertexLayout = found->second[currentPass];
|
||||
}
|
||||
else
|
||||
{
|
||||
D3D10_PASS_DESC passDesc;
|
||||
currentEffectPass->GetDesc(&passDesc);
|
||||
if (S_OK == m_Engine.get_DX10Device().CreateInputLayout(m_InputElementDesc, m_VertexElements.size(), passDesc.pIAInputSignature,
|
||||
passDesc.IAInputSignatureSize, &vertexLayout ))
|
||||
{
|
||||
if (found == m_VertexLayoutsPerShaderAndPass.end())
|
||||
{
|
||||
std::vector<ID3D10InputLayout*> val;
|
||||
val.push_back(vertexLayout);
|
||||
m_VertexLayoutsPerShaderAndPass[&argShader] = val;
|
||||
}
|
||||
else
|
||||
found->second.push_back(vertexLayout);
|
||||
}
|
||||
}
|
||||
|
||||
if (vertexLayout != NULL)
|
||||
{
|
||||
currentEffectPass->Apply(0);
|
||||
m_Engine.get_DX10Device().IASetInputLayout(vertexLayout);
|
||||
if (m_IndexBuffer == NULL)
|
||||
m_Engine.get_DX10Device().Draw(m_VertexCount, 0);
|
||||
else
|
||||
m_Engine.get_DX10Device().DrawIndexed(m_UsableIndexCount, m_IndexOffset, 0);
|
||||
}
|
||||
}
|
||||
79
aiwaz/Aiwaz/Resources/GeometryBuffer/GeometryBuffer.h
Normal file
79
aiwaz/Aiwaz/Resources/GeometryBuffer/GeometryBuffer.h
Normal file
@@ -0,0 +1,79 @@
|
||||
#pragma once
|
||||
|
||||
#include "IEngine.h"
|
||||
#include "IGeometryBuffer.h"
|
||||
#include "IShader.h"
|
||||
#include "../Commands/CommandUserBase.h"
|
||||
|
||||
|
||||
class GeometryBuffer
|
||||
: public IGeometryBuffer
|
||||
, public CommandUserBase
|
||||
{
|
||||
protected:
|
||||
static const unsigned char SetIndexBufferCommandType = 0;
|
||||
static const unsigned char SetVertexBufferCommandType = 1;
|
||||
static const unsigned char DrawGeometryCommandType = 2;
|
||||
|
||||
public:
|
||||
GeometryBuffer(IEngine& argEngine);
|
||||
virtual ~GeometryBuffer();
|
||||
|
||||
virtual void Uninitialize();
|
||||
|
||||
virtual void SetVertexData(uint32 argVertexCount, uint32 argVertexElementSize, void* a_VertexData_, const std::vector<VertexElement>& argVertexElements, bool argNeedsDynamicAccess);
|
||||
virtual void DeleteVertexData();
|
||||
virtual void SetIndexData(uint32 argIndexCount, uint32* aui_IndexData_, bool argNeedsDynamicAccess);
|
||||
virtual void DeleteIndexData();
|
||||
|
||||
virtual void* MapVertexBuffer(DataAccessMode::Enumeration argAccessMode);
|
||||
virtual void UnmapVertexBuffer();
|
||||
|
||||
virtual uint32* MapIndexBuffer(DataAccessMode::Enumeration argAccessMode);
|
||||
virtual void UnmapIndexBuffer();
|
||||
|
||||
virtual uint32 get_IndexBufferOffset() const { return m_IndexOffset; }
|
||||
virtual void set_IndexBufferOffset(uint32 argValue) { m_IndexOffset = argValue; }
|
||||
virtual uint32 get_IndexBufferUsableLength() const { return m_UsableIndexCount; }
|
||||
virtual void set_IndexBufferUsableLength(uint32 argValue) { m_UsableIndexCount = argValue; }
|
||||
|
||||
virtual uint32 get_IndexBufferLength() const { return m_IndexCount; }
|
||||
virtual uint32 get_VertexBufferLength() const { return m_VertexCount; }
|
||||
|
||||
virtual PrimitiveTopology::Enumeration get_PrimitiveTopology() const { return m_PrimitiveTopology; }
|
||||
virtual void set_PrimitiveTopology(PrimitiveTopology::Enumeration argValue) { m_PrimitiveTopology = argValue; }
|
||||
|
||||
virtual void ConvertToAdjacency();
|
||||
|
||||
// ICommandUser
|
||||
virtual CommandExecuteResult::Enumeration ExecuteCommand(unsigned char argCommandType, ICommandBuffer& argCurrentBuffer, uint32 argCurrentPositon);
|
||||
virtual string8 get_UserName() const { return "GeometryBuffer"; }
|
||||
|
||||
protected:
|
||||
void Render(IShader& argShader);
|
||||
|
||||
protected:
|
||||
IEngine& m_Engine;
|
||||
|
||||
uint32 m_IndexCount;
|
||||
uint32 m_IndexOffset;
|
||||
uint32 m_UsableIndexCount;
|
||||
ID3D10Buffer* m_IndexBuffer;
|
||||
uint32* m_RawIndexData;
|
||||
|
||||
uint32 m_VertexOffset;
|
||||
uint32 m_VertexCount;
|
||||
uint32 m_VertexElementSize;
|
||||
ID3D10Buffer* m_VertexBuffer;
|
||||
void* m_RawVertexData_;
|
||||
|
||||
bool m_VertexDataMapped;
|
||||
bool m_IndexDataMapped;
|
||||
|
||||
PrimitiveTopology::Enumeration m_PrimitiveTopology;
|
||||
std::vector<VertexElement> m_VertexElements;
|
||||
D3D10_INPUT_ELEMENT_DESC* m_InputElementDesc;
|
||||
|
||||
typedef std::map<IShader*, std::vector<ID3D10InputLayout*> > tk_VertexLayoutsPerShaderAndPass;
|
||||
tk_VertexLayoutsPerShaderAndPass m_VertexLayoutsPerShaderAndPass;
|
||||
};
|
||||
186
aiwaz/Aiwaz/Resources/RenderCommandNode/RenderCommandNode.cpp
Normal file
186
aiwaz/Aiwaz/Resources/RenderCommandNode/RenderCommandNode.cpp
Normal file
@@ -0,0 +1,186 @@
|
||||
#include "stdafx.h"
|
||||
#include <algorithm>
|
||||
#include "../Commands/CommandBuffer.h"
|
||||
#include "IResourceFactory.h"
|
||||
#include "RenderCommandNode.h"
|
||||
|
||||
|
||||
RenderCommandNode::RenderCommandNode(IEngine& argEngine)
|
||||
: m_Engine(argEngine)
|
||||
, m_Dirty(true)
|
||||
, m_ParentNode(NULL)
|
||||
, m_CommandBuffer(NULL)
|
||||
{
|
||||
}
|
||||
|
||||
|
||||
RenderCommandNode::~RenderCommandNode()
|
||||
{
|
||||
if (m_ParentNode != NULL)
|
||||
m_ParentNode->RemoveCommandUser(*this);
|
||||
|
||||
while (!m_CommandUsers.empty())
|
||||
RemoveCommandUser(**m_CommandUsers.begin());
|
||||
|
||||
delete m_CommandBuffer;
|
||||
|
||||
m_Engine.get_ResourceFactory().DeleteRenderCommandNode(*const_cast<RenderCommandNode*>(this), true);
|
||||
}
|
||||
|
||||
|
||||
const std::vector<ICommandUser*> RenderCommandNode::get_CommandUsers() const
|
||||
{
|
||||
return m_CommandUsers;
|
||||
}
|
||||
|
||||
|
||||
void RenderCommandNode::set_Parent(IRenderCommandNode* ar_Node_)
|
||||
{
|
||||
m_ParentNode = ar_Node_;
|
||||
}
|
||||
|
||||
|
||||
IRenderCommandNode* RenderCommandNode::get_Parent() const
|
||||
{
|
||||
return m_ParentNode;
|
||||
}
|
||||
|
||||
|
||||
bool RenderCommandNode::IsDirty() const
|
||||
{
|
||||
return m_Dirty;
|
||||
}
|
||||
|
||||
|
||||
void RenderCommandNode::MarkDirty()
|
||||
{
|
||||
m_Dirty = true;
|
||||
if (m_ParentNode != NULL)
|
||||
m_ParentNode->MarkDirty();
|
||||
}
|
||||
|
||||
|
||||
void RenderCommandNode::AddCommandUser(ICommandUser& argCommandUser)
|
||||
{
|
||||
argCommandUser.AssignToRenderCommandNode(*const_cast<RenderCommandNode*>(this));
|
||||
m_CommandUsers.push_back(&argCommandUser);
|
||||
IRenderCommandNode* node = dynamic_cast<IRenderCommandNode*>(&argCommandUser);
|
||||
if (node != NULL)
|
||||
node->set_Parent(this);
|
||||
this->MarkDirty();
|
||||
}
|
||||
|
||||
|
||||
void RenderCommandNode::RemoveCommandUser(ICommandUser& argCommandUser)
|
||||
{
|
||||
std::vector<ICommandUser*>::iterator found = std::find(m_CommandUsers.begin(), m_CommandUsers.end(), &argCommandUser);
|
||||
if (found != m_CommandUsers.end())
|
||||
{
|
||||
IRenderCommandNode* node = dynamic_cast<IRenderCommandNode*>(&argCommandUser);
|
||||
if (node != NULL)
|
||||
node->set_Parent(NULL);
|
||||
|
||||
m_CommandUsers.erase(found);
|
||||
argCommandUser.UnassignFromRenderCommandNode(*const_cast<RenderCommandNode*>(this));
|
||||
|
||||
this->MarkDirty();
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
void RenderCommandNode::ReplaceCommandUser(ICommandUser& argWhatCommandUser, ICommandUser& argWhithCommandUser)
|
||||
{
|
||||
std::vector<ICommandUser*>::iterator found = std::find(m_CommandUsers.begin(), m_CommandUsers.end(), &argWhatCommandUser);
|
||||
if (found != m_CommandUsers.end())
|
||||
{
|
||||
IRenderCommandNode* node = dynamic_cast<IRenderCommandNode*>(&argWhatCommandUser);
|
||||
if (node != NULL)
|
||||
node->set_Parent(NULL);
|
||||
|
||||
m_CommandUsers.insert(found, &argWhithCommandUser);
|
||||
m_CommandUsers.erase(found);
|
||||
|
||||
argWhatCommandUser.UnassignFromRenderCommandNode(*const_cast<RenderCommandNode*>(this));
|
||||
argWhithCommandUser.AssignToRenderCommandNode(*const_cast<RenderCommandNode*>(this));
|
||||
|
||||
node = dynamic_cast<IRenderCommandNode*>(&argWhithCommandUser);
|
||||
if (node != NULL)
|
||||
node->set_Parent(this);
|
||||
|
||||
this->MarkDirty();
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
void RenderCommandNode::ProcessCommands()
|
||||
{
|
||||
if (m_Dirty)
|
||||
{
|
||||
this->GenerateDeviceCommands();
|
||||
m_CommandBuffer->Optimize();
|
||||
}
|
||||
m_CommandBuffer->Perform(true);
|
||||
}
|
||||
|
||||
|
||||
void RenderCommandNode::Update(bool argForceUpdate)
|
||||
{
|
||||
// Walk through all updatables and update them.
|
||||
for (uint32 i = 0; i < m_CommandUsers.size(); ++i)
|
||||
{
|
||||
IUpdatable* updatable = dynamic_cast<IUpdatable*>(m_CommandUsers[i]);
|
||||
if (updatable != NULL && (updatable->get_WantsUpdate() || argForceUpdate))
|
||||
updatable->Update(argForceUpdate);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
bool RenderCommandNode::get_WantsUpdate() const
|
||||
{
|
||||
return true;
|
||||
}
|
||||
|
||||
|
||||
CommandExecuteResult::Enumeration RenderCommandNode::ExecuteCommand(unsigned char argCommandType, ICommandBuffer& argCurrentBuffer, uint32 argCurrentPositon)
|
||||
{
|
||||
return CommandExecuteResult::None;
|
||||
}
|
||||
|
||||
|
||||
void RenderCommandNode::GenerateDeviceCommands()
|
||||
{
|
||||
if (!m_Dirty)
|
||||
return;
|
||||
|
||||
m_Dirty = false;
|
||||
if (m_CommandBuffer == NULL)
|
||||
m_CommandBuffer = new CommandBuffer(false, false);
|
||||
else
|
||||
m_CommandBuffer->Clear();
|
||||
|
||||
for (uint32 i = 0; i < m_CommandUsers.size(); ++i)
|
||||
{
|
||||
// Add the commands all commands
|
||||
const std::vector<Command*>& commands = m_CommandUsers[i]->GetCommands();
|
||||
for (uint32 k = 0; k < commands.size(); ++k)
|
||||
m_CommandBuffer->AddCommand(*commands[k]);
|
||||
|
||||
// Walk further if we found another RenderCommandNode
|
||||
IRenderCommandNodeInternal* nodeInternal = dynamic_cast<IRenderCommandNodeInternal*>(m_CommandUsers[i]);
|
||||
if (nodeInternal != NULL)
|
||||
{
|
||||
nodeInternal->GenerateDeviceCommands();
|
||||
|
||||
// Merge the buffers
|
||||
ICommandBuffer* otherBuffer = nodeInternal->get_CommandBuffer();
|
||||
if (otherBuffer != NULL)
|
||||
m_CommandBuffer->AddChildCommandBuffer(*otherBuffer);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
ICommandBuffer* RenderCommandNode::get_CommandBuffer() const
|
||||
{
|
||||
return m_CommandBuffer;
|
||||
}
|
||||
50
aiwaz/Aiwaz/Resources/RenderCommandNode/RenderCommandNode.h
Normal file
50
aiwaz/Aiwaz/Resources/RenderCommandNode/RenderCommandNode.h
Normal file
@@ -0,0 +1,50 @@
|
||||
#pragma once
|
||||
|
||||
#include "IRenderCommandNode.h"
|
||||
#include "IUpdatable.h"
|
||||
#include "IEngine.h"
|
||||
#include "../Commands/CommandUserBase.h"
|
||||
|
||||
|
||||
class RenderCommandNode
|
||||
: public IRenderCommandNode
|
||||
, public IRenderCommandNodeInternal
|
||||
, public CommandUserBase
|
||||
, public IUpdatable
|
||||
{
|
||||
public:
|
||||
RenderCommandNode(IEngine& argEngine);
|
||||
virtual ~RenderCommandNode();
|
||||
|
||||
// IRenderCommandNode
|
||||
virtual const std::vector<ICommandUser*> get_CommandUsers() const;
|
||||
virtual void set_Parent(IRenderCommandNode* ar_Node_);
|
||||
virtual IRenderCommandNode* get_Parent() const;
|
||||
virtual bool IsDirty() const;
|
||||
virtual void MarkDirty();
|
||||
virtual void AddCommandUser(ICommandUser& argCommandUser);
|
||||
virtual void RemoveCommandUser(ICommandUser& argCommandUser);
|
||||
virtual void ReplaceCommandUser(ICommandUser& argWhatCommandUser, ICommandUser& argWhithCommandUser);
|
||||
|
||||
virtual void ProcessCommands();
|
||||
|
||||
// IUpdatable
|
||||
virtual void Update(bool argForceUpdate);
|
||||
virtual bool get_WantsUpdate() const;
|
||||
|
||||
// ICommandUser
|
||||
virtual CommandExecuteResult::Enumeration ExecuteCommand(unsigned char argCommandType, ICommandBuffer& argCurrentBuffer, uint32 argCurrentPositon);
|
||||
virtual string8 get_UserName() const { return "RenderCommandNode"; }
|
||||
|
||||
protected:
|
||||
// IRenderCommandNodeInternal
|
||||
virtual void GenerateDeviceCommands();
|
||||
virtual ICommandBuffer* get_CommandBuffer() const;
|
||||
|
||||
private:
|
||||
IEngine& m_Engine;
|
||||
bool m_Dirty;
|
||||
IRenderCommandNode* m_ParentNode;
|
||||
std::vector<ICommandUser*> m_CommandUsers;
|
||||
ICommandBuffer* m_CommandBuffer;
|
||||
};
|
||||
308
aiwaz/Aiwaz/Resources/RenderTarget/RenderTargetBase.cpp
Normal file
308
aiwaz/Aiwaz/Resources/RenderTarget/RenderTargetBase.cpp
Normal file
@@ -0,0 +1,308 @@
|
||||
#include "stdafx.h"
|
||||
#include <algorithm>
|
||||
#include "RenderTargetBase.h"
|
||||
|
||||
|
||||
RenderTargetBase::RenderTargetBase(IEngine& argEngine)
|
||||
: m_Engine(argEngine)
|
||||
, m_ClearDepthStencilBufferDepth(1.0f) // 1.0f is the maximum depth
|
||||
, m_ClearDepthStencilBufferStencil(0) // clear the full stencil buffer
|
||||
, m_ClearColorBufferColor(D3DXCOLOR(0.0f, 0.0f, 0.0f, 1.0f)) // good old black opaque
|
||||
, m_RenderTargetView(NULL)
|
||||
, m_DepthStencilView(NULL)
|
||||
, m_DepthStencilTexture(NULL)
|
||||
, m_RenderingTargets(NULL)
|
||||
, m_D3D10Viewports(NULL)
|
||||
, m_MultiSampleCount(1)
|
||||
, m_MultiSampleQuality(0)
|
||||
, m_LastBindFlags(BindFlags::Default)
|
||||
, m_ActiveRenderTargetCount(0)
|
||||
{
|
||||
this->set_ViewPort(this->get_ViewPort()); // force d3d10 viewport generation
|
||||
|
||||
m_Commands.push_back(new Command(this, CommandFlags::EndChain | CommandFlags::FlushChain, SetRenderTargetCommandType, 0));
|
||||
|
||||
memset(m_EmptyShaderResView, 0, sizeof(m_EmptyShaderResView));
|
||||
}
|
||||
|
||||
|
||||
RenderTargetBase::~RenderTargetBase()
|
||||
{
|
||||
this->Uninitialize();
|
||||
}
|
||||
|
||||
|
||||
void RenderTargetBase::Uninitialize()
|
||||
{
|
||||
if (m_Engine.get_EngineStates().LastRenderTarget == this)
|
||||
m_Engine.get_EngineStates().LastRenderTarget = NULL;
|
||||
|
||||
// clear used states
|
||||
ID3D10Device& device = m_Engine.get_DX10Device();
|
||||
|
||||
ID3D10RenderTargetView* activeRenderTargetViews[D3D10_SIMULTANEOUS_RENDER_TARGET_COUNT];
|
||||
ID3D10DepthStencilView* activeDepthStencilView;
|
||||
device.OMGetRenderTargets(D3D10_SIMULTANEOUS_RENDER_TARGET_COUNT, activeRenderTargetViews, &activeDepthStencilView);
|
||||
bool clearRenderTargets = false;
|
||||
if (activeDepthStencilView == m_DepthStencilView && m_DepthStencilView != NULL)
|
||||
clearRenderTargets = true;
|
||||
|
||||
for (uint32 i = 0; i < D3D10_SIMULTANEOUS_RENDER_TARGET_COUNT; ++i)
|
||||
{
|
||||
if (activeRenderTargetViews[i] != NULL)
|
||||
{
|
||||
for (uint32 k = 0; k < m_AdditionalRenderingTargets.size() + 1; ++k)
|
||||
{
|
||||
if (m_RenderingTargets != NULL && m_RenderingTargets[k] == activeRenderTargetViews[i])
|
||||
clearRenderTargets = true;
|
||||
}
|
||||
activeRenderTargetViews[i]->Release();
|
||||
}
|
||||
else
|
||||
break;
|
||||
}
|
||||
|
||||
if (clearRenderTargets)
|
||||
device.OMSetRenderTargets(0, NULL, NULL);
|
||||
|
||||
if (m_RenderTargetView != NULL)
|
||||
m_RenderTargetView->Release();
|
||||
m_RenderTargetView = NULL;
|
||||
|
||||
if (m_DepthStencilView != NULL)
|
||||
m_DepthStencilView->Release();
|
||||
m_DepthStencilView = NULL;
|
||||
|
||||
if (m_DepthStencilTexture != NULL)
|
||||
m_DepthStencilTexture->Release();
|
||||
m_DepthStencilTexture = NULL;
|
||||
|
||||
this->KillViewPortAndRenderTargetData();
|
||||
}
|
||||
|
||||
|
||||
void RenderTargetBase::set_ViewPort(const ViewPort& argViewPort)
|
||||
{
|
||||
m_ViewPort = argViewPort;
|
||||
this->KillViewPortAndRenderTargetData();
|
||||
this->BuildViewPortAndRenderTargetData();
|
||||
}
|
||||
|
||||
|
||||
void RenderTargetBase::set_HasDepthStencilBuffer(bool argState)
|
||||
{
|
||||
if (m_RenderTargetView == NULL)
|
||||
{
|
||||
throw L"RenderTarget: Access forbidden until resource has been initialized.";
|
||||
}
|
||||
|
||||
m_Engine.get_DX10Device().ClearState();
|
||||
|
||||
if (m_DepthStencilView != NULL)
|
||||
m_DepthStencilView->Release();
|
||||
m_DepthStencilView = NULL;
|
||||
|
||||
if (m_DepthStencilTexture != NULL)
|
||||
m_DepthStencilTexture->Release();
|
||||
m_DepthStencilTexture = NULL;
|
||||
|
||||
if (!argState)
|
||||
return; // no further effort needed here
|
||||
|
||||
ID3D10Device& device = m_Engine.get_DX10Device();
|
||||
|
||||
D3D10_TEXTURE2D_DESC depthTextureDesc;
|
||||
D3D10_DEPTH_STENCIL_VIEW_DESC depthStencilViewDesc;
|
||||
|
||||
ZeroMemory(&depthTextureDesc,sizeof(depthTextureDesc));
|
||||
depthTextureDesc.Width = this->get_RenderTargetWidth();
|
||||
depthTextureDesc.Height = this->get_RenderTargetHeight();
|
||||
depthTextureDesc.MipLevels = 1;
|
||||
depthTextureDesc.ArraySize = 1;
|
||||
depthTextureDesc.Format = DXGI_FORMAT_D24_UNORM_S8_UINT;
|
||||
depthTextureDesc.SampleDesc.Count = m_MultiSampleCount == 0 ? 1 : m_MultiSampleCount;
|
||||
depthTextureDesc.SampleDesc.Quality = m_MultiSampleQuality;
|
||||
depthTextureDesc.Usage = D3D10_USAGE_DEFAULT;
|
||||
depthTextureDesc.BindFlags = D3D10_BIND_DEPTH_STENCIL;
|
||||
depthTextureDesc.CPUAccessFlags = 0;
|
||||
depthTextureDesc.MiscFlags = 0;
|
||||
|
||||
if(device.CreateTexture2D(&depthTextureDesc, 0, &m_DepthStencilTexture) != S_OK)
|
||||
{
|
||||
throw L"RenderTarget: Unable to create depthstencil texture.";
|
||||
}
|
||||
|
||||
ZeroMemory(&depthStencilViewDesc, sizeof(depthStencilViewDesc));
|
||||
depthStencilViewDesc.Format = depthTextureDesc.Format;
|
||||
depthStencilViewDesc.ViewDimension = m_MultiSampleCount >= 1 ? D3D10_DSV_DIMENSION_TEXTURE2DMS : D3D10_DSV_DIMENSION_TEXTURE2D;
|
||||
depthStencilViewDesc.Texture2D.MipSlice = 0;
|
||||
|
||||
if(device.CreateDepthStencilView(m_DepthStencilTexture, &depthStencilViewDesc, &m_DepthStencilView) != S_OK)
|
||||
{
|
||||
if (m_DepthStencilTexture != NULL)
|
||||
m_DepthStencilTexture->Release();
|
||||
m_DepthStencilTexture = NULL;
|
||||
throw L"RenderTarget: Unable to create depth stencil view.";
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
void RenderTargetBase::AddAdditionalRenderTarget(IRenderTargetBase& argTarget)
|
||||
{
|
||||
this->RemoveAdditionalRenderTarget(argTarget);
|
||||
if (m_AdditionalRenderingTargets.size() + 1 == D3D10_SIMULTANEOUS_RENDER_TARGET_COUNT)
|
||||
{
|
||||
throw L"RenderTarget: Unable to add an additional rendering target, list is full.";
|
||||
}
|
||||
|
||||
if (argTarget.get_DX10RenderTargetView() == NULL)
|
||||
{
|
||||
throw L"RenderingResource: Unable to add an additional rendering target, new target is not initialized.";
|
||||
}
|
||||
|
||||
m_AdditionalRenderingTargets.push_back(&argTarget);
|
||||
|
||||
this->KillViewPortAndRenderTargetData();
|
||||
this->BuildViewPortAndRenderTargetData();
|
||||
}
|
||||
|
||||
|
||||
void RenderTargetBase::RemoveAdditionalRenderTarget(IRenderTargetBase& argTarget)
|
||||
{
|
||||
std::vector<IRenderTargetBase*>::iterator found = std::find(m_AdditionalRenderingTargets.begin(), m_AdditionalRenderingTargets.end(), &argTarget);
|
||||
if (found != m_AdditionalRenderingTargets.end())
|
||||
m_AdditionalRenderingTargets.erase(found);
|
||||
|
||||
this->KillViewPortAndRenderTargetData();
|
||||
this->BuildViewPortAndRenderTargetData();
|
||||
}
|
||||
|
||||
|
||||
void RenderTargetBase::BuildViewPortAndRenderTargetData()
|
||||
{
|
||||
// Rebuild rendertargets
|
||||
if (m_RenderingTargets == NULL)
|
||||
{
|
||||
if ((m_LastBindFlags & BindFlags::BindAllTextures) == BindFlags::BindAllTextures)
|
||||
{
|
||||
m_ActiveRenderTargetCount = 1 + m_AdditionalRenderingTargets.size();
|
||||
m_RenderingTargets = new ID3D10RenderTargetView*[m_ActiveRenderTargetCount];
|
||||
m_RenderingTargets[0] = m_RenderTargetView;
|
||||
for (uint32 i = 0; i < m_AdditionalRenderingTargets.size(); ++i)
|
||||
m_RenderingTargets[i + 1] = m_AdditionalRenderingTargets[i]->get_DX10RenderTargetView();
|
||||
}
|
||||
else if (m_LastBindFlags & BindFlags::BindAllTextures)
|
||||
{
|
||||
m_ActiveRenderTargetCount = 0;
|
||||
if (m_LastBindFlags & BindFlags::BindBaseTexture) ++m_ActiveRenderTargetCount;
|
||||
if (m_LastBindFlags & BindFlags::BindAdditionalTexture0) ++m_ActiveRenderTargetCount;
|
||||
if (m_LastBindFlags & BindFlags::BindAdditionalTexture1) ++m_ActiveRenderTargetCount;
|
||||
if (m_LastBindFlags & BindFlags::BindAdditionalTexture2) ++m_ActiveRenderTargetCount;
|
||||
if (m_LastBindFlags & BindFlags::BindAdditionalTexture3) ++m_ActiveRenderTargetCount;
|
||||
|
||||
m_RenderingTargets = new ID3D10RenderTargetView*[m_ActiveRenderTargetCount];
|
||||
|
||||
int bufferIndex = 0;
|
||||
if (m_LastBindFlags & BindFlags::BindBaseTexture) m_RenderingTargets[bufferIndex++] = m_RenderTargetView;
|
||||
if (m_LastBindFlags & BindFlags::BindAdditionalTexture0) m_RenderingTargets[bufferIndex++] = m_AdditionalRenderingTargets[0]->get_DX10RenderTargetView();
|
||||
if (m_LastBindFlags & BindFlags::BindAdditionalTexture1) m_RenderingTargets[bufferIndex++] = m_AdditionalRenderingTargets[1]->get_DX10RenderTargetView();
|
||||
if (m_LastBindFlags & BindFlags::BindAdditionalTexture2) m_RenderingTargets[bufferIndex++] = m_AdditionalRenderingTargets[2]->get_DX10RenderTargetView();
|
||||
if (m_LastBindFlags & BindFlags::BindAdditionalTexture3) m_RenderingTargets[bufferIndex++] = m_AdditionalRenderingTargets[3]->get_DX10RenderTargetView();
|
||||
}
|
||||
else
|
||||
throw L"No render target bindable.";
|
||||
}
|
||||
|
||||
// Rebuild viewports
|
||||
if (m_D3D10Viewports == NULL)
|
||||
{
|
||||
m_D3D10Viewports = new D3D10_VIEWPORT[m_ActiveRenderTargetCount];
|
||||
m_D3D10Viewports[0].Height = m_ViewPort.m_Height;
|
||||
m_D3D10Viewports[0].Width = m_ViewPort.m_Width;
|
||||
m_D3D10Viewports[0].MinDepth = m_ViewPort.m_MinDepth;
|
||||
m_D3D10Viewports[0].MaxDepth = m_ViewPort.m_MaxDepth;
|
||||
m_D3D10Viewports[0].TopLeftX = m_ViewPort.m_TopLeftX;
|
||||
m_D3D10Viewports[0].TopLeftY = m_ViewPort.m_TopLeftY;
|
||||
|
||||
for (uint32 i = 0; i < m_ActiveRenderTargetCount - 1; ++i)
|
||||
{
|
||||
ViewPort viewPort = m_AdditionalRenderingTargets[i]->get_ViewPort();
|
||||
m_D3D10Viewports[i + 1].Height = viewPort.m_Height;
|
||||
m_D3D10Viewports[i + 1].Width = viewPort.m_Width;
|
||||
m_D3D10Viewports[i + 1].MinDepth = viewPort.m_MinDepth;
|
||||
m_D3D10Viewports[i + 1].MaxDepth = viewPort.m_MaxDepth;
|
||||
m_D3D10Viewports[i + 1].TopLeftX = viewPort.m_TopLeftX;
|
||||
m_D3D10Viewports[i + 1].TopLeftY = viewPort.m_TopLeftY;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
void RenderTargetBase::KillViewPortAndRenderTargetData()
|
||||
{
|
||||
if (m_RenderingTargets != NULL)
|
||||
delete [] m_RenderingTargets;
|
||||
m_RenderingTargets = NULL;
|
||||
|
||||
if (m_D3D10Viewports != NULL)
|
||||
delete [] m_D3D10Viewports;
|
||||
m_D3D10Viewports = NULL;
|
||||
|
||||
m_ActiveRenderTargetCount = 0;
|
||||
}
|
||||
|
||||
|
||||
void RenderTargetBase::Bind(DWORD argBindFlags)
|
||||
{
|
||||
if ((argBindFlags & ~ BindFlags::ClearAll) != (m_LastBindFlags & ~ BindFlags::ClearAll))
|
||||
{
|
||||
m_LastBindFlags = argBindFlags;
|
||||
this->KillViewPortAndRenderTargetData();
|
||||
this->BuildViewPortAndRenderTargetData();
|
||||
}
|
||||
m_LastBindFlags = argBindFlags;
|
||||
|
||||
ID3D10Device& device = m_Engine.get_DX10Device();
|
||||
|
||||
this->Clear(argBindFlags);
|
||||
|
||||
device.PSSetShaderResources(0, 128, m_EmptyShaderResView);
|
||||
device.OMSetRenderTargets(m_ActiveRenderTargetCount, m_RenderingTargets, m_DepthStencilView);
|
||||
device.RSSetViewports(m_ActiveRenderTargetCount, m_D3D10Viewports);
|
||||
|
||||
m_Engine.get_EngineStates().LastRenderTarget = this;
|
||||
}
|
||||
|
||||
|
||||
void RenderTargetBase::UnbindAllRenderTargets()
|
||||
{
|
||||
m_Engine.get_DX10Device().OMSetRenderTargets(0, NULL, NULL);
|
||||
m_Engine.get_DX10Device().RSSetViewports(0, NULL);
|
||||
m_Engine.get_EngineStates().LastRenderTarget = NULL;
|
||||
}
|
||||
|
||||
|
||||
CommandExecuteResult::Enumeration RenderTargetBase::ExecuteCommand(unsigned char argCommandType, ICommandBuffer& argCurrentBuffer, uint32 argCurrentPositon)
|
||||
{
|
||||
if (argCommandType == RenderTargetBase::SetRenderTargetCommandType)
|
||||
{
|
||||
if (m_Engine.get_EngineStates().LastRenderTarget != this)
|
||||
{
|
||||
this->UnbindAllRenderTargets();
|
||||
this->Bind();
|
||||
}
|
||||
else
|
||||
this->Clear();
|
||||
}
|
||||
return CommandExecuteResult::None;
|
||||
}
|
||||
|
||||
|
||||
void RenderTargetBase::Clear(DWORD argBindFlags)
|
||||
{
|
||||
ID3D10Device& device = m_Engine.get_DX10Device();
|
||||
if (argBindFlags & BindFlags::ClearColor)
|
||||
device.ClearRenderTargetView(m_RenderTargetView, (FLOAT*)m_ClearColorBufferColor);
|
||||
if ((argBindFlags & BindFlags::ClearDepthStencil) && m_DepthStencilView != NULL)
|
||||
device.ClearDepthStencilView(m_DepthStencilView, 0x01L | 0x02L, m_ClearDepthStencilBufferDepth, m_ClearDepthStencilBufferStencil);
|
||||
}
|
||||
81
aiwaz/Aiwaz/Resources/RenderTarget/RenderTargetBase.h
Normal file
81
aiwaz/Aiwaz/Resources/RenderTarget/RenderTargetBase.h
Normal file
@@ -0,0 +1,81 @@
|
||||
#pragma once
|
||||
|
||||
#include "IEngine.h"
|
||||
#include "IRenderTargetBase.h"
|
||||
#include "../Commands/CommandUserBase.h"
|
||||
|
||||
|
||||
class RenderTargetBase
|
||||
: public IRenderTargetBase
|
||||
, public CommandUserBase
|
||||
{
|
||||
protected:
|
||||
static const unsigned char SetRenderTargetCommandType = 0;
|
||||
|
||||
public:
|
||||
RenderTargetBase(IEngine& argEngine);
|
||||
virtual ~RenderTargetBase();
|
||||
|
||||
virtual void set_ClearDepth(float argValue) { m_ClearDepthStencilBufferDepth = argValue; }
|
||||
virtual float get_ClearDepth() const { return m_ClearDepthStencilBufferDepth; }
|
||||
|
||||
virtual void set_ClearStencil(unsigned char argValue) { m_ClearDepthStencilBufferStencil = argValue; }
|
||||
virtual unsigned char get_ClearStencil() const { return m_ClearDepthStencilBufferStencil; }
|
||||
|
||||
virtual void set_ClearColor(const D3DXCOLOR& argValue) { m_ClearColorBufferColor = argValue; }
|
||||
virtual D3DXCOLOR get_ClearColor() const { return m_ClearColorBufferColor; }
|
||||
|
||||
virtual void set_ViewPort(const ViewPort& argValue);
|
||||
virtual ViewPort get_ViewPort() const { return m_ViewPort; }
|
||||
|
||||
virtual uint32 get_RenderTargetWidth() const = 0;
|
||||
virtual uint32 get_RenderTargetHeight() const = 0;
|
||||
virtual DataFormat::Enumeration get_RenderTargetFormat() const = 0;
|
||||
|
||||
virtual void set_HasDepthStencilBuffer(bool argState);
|
||||
virtual bool get_HasDepthStencilBuffer() const { return m_DepthStencilView != NULL; }
|
||||
|
||||
virtual void AddAdditionalRenderTarget(IRenderTargetBase& argTarget);
|
||||
virtual void RemoveAdditionalRenderTarget(IRenderTargetBase& argTarget);
|
||||
|
||||
virtual ID3D10RenderTargetView* get_DX10RenderTargetView() const { return m_RenderTargetView; }
|
||||
virtual ID3D10DepthStencilView* get_DX10DepthStencilView() const { return m_DepthStencilView; }
|
||||
|
||||
virtual void Bind(DWORD argBindFlags = BindFlags::Default);
|
||||
virtual void UnbindAllRenderTargets();
|
||||
|
||||
// ICommandUser
|
||||
virtual CommandExecuteResult::Enumeration ExecuteCommand(unsigned char argCommandType, ICommandBuffer& argCurrentBuffer, uint32 argCurrentPositon);
|
||||
|
||||
protected:
|
||||
void Clear(DWORD argBindFlags = BindFlags::Default);
|
||||
|
||||
virtual void Uninitialize();
|
||||
void BuildViewPortAndRenderTargetData();
|
||||
void KillViewPortAndRenderTargetData();
|
||||
|
||||
protected:
|
||||
IEngine& m_Engine;
|
||||
|
||||
float m_ClearDepthStencilBufferDepth;
|
||||
unsigned char m_ClearDepthStencilBufferStencil;
|
||||
D3DXCOLOR m_ClearColorBufferColor;
|
||||
|
||||
ViewPort m_ViewPort;
|
||||
|
||||
ID3D10RenderTargetView* m_RenderTargetView;
|
||||
ID3D10DepthStencilView* m_DepthStencilView;
|
||||
ID3D10Texture2D* m_DepthStencilTexture;
|
||||
|
||||
uint32 m_MultiSampleCount;
|
||||
uint32 m_MultiSampleQuality;
|
||||
|
||||
std::vector<IRenderTargetBase*> m_AdditionalRenderingTargets;
|
||||
ID3D10RenderTargetView** m_RenderingTargets;
|
||||
D3D10_VIEWPORT* m_D3D10Viewports;
|
||||
uint32 m_ActiveRenderTargetCount;
|
||||
|
||||
DWORD m_LastBindFlags;
|
||||
|
||||
ID3D10ShaderResourceView* m_EmptyShaderResView[128];
|
||||
};
|
||||
@@ -0,0 +1,105 @@
|
||||
#include "stdafx.h"
|
||||
#include "ITexture.h"
|
||||
#include "IEngine.h"
|
||||
#include "IResourcefactory.h"
|
||||
#include "RenderTargetTexture.h"
|
||||
|
||||
|
||||
RenderTargetTexture::RenderTargetTexture(IEngine& argEngine)
|
||||
: RenderTargetBase(argEngine)
|
||||
, m_Texture(NULL)
|
||||
{
|
||||
}
|
||||
|
||||
|
||||
RenderTargetTexture::~RenderTargetTexture()
|
||||
{
|
||||
delete m_Texture;
|
||||
m_Engine.get_ResourceFactory().DeleteRenderTargetTexture(*const_cast<RenderTargetTexture*>(this), true);
|
||||
}
|
||||
|
||||
|
||||
void RenderTargetTexture::SetTextureParameters(uint32 argWidth, uint32 argHeight, DataFormat::Enumeration argFormat, uint32 argMultiSampleCount, uint32 argMultiSampleQuality)
|
||||
{
|
||||
if (argWidth == this->get_RenderTargetWidth() &&
|
||||
argHeight == this->get_RenderTargetHeight() &&
|
||||
argFormat == this->get_RenderTargetFormat() &&
|
||||
m_MultiSampleCount == argMultiSampleCount &&
|
||||
m_MultiSampleQuality == argMultiSampleQuality)
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
RenderTargetBase::Uninitialize();
|
||||
|
||||
// get missing information
|
||||
if (argMultiSampleCount == 0)
|
||||
argMultiSampleCount = 1;
|
||||
if (argWidth == 0)
|
||||
argWidth = 1;
|
||||
if (argHeight == 0)
|
||||
argHeight = 1;
|
||||
if (argFormat == DataFormat::Unknown)
|
||||
argFormat = DataFormat::R8G8B8A8_UnsignedNormalized;
|
||||
|
||||
if (m_Texture == NULL)
|
||||
m_Texture = &m_Engine.get_ResourceFactory().CreateOrFindTexture();
|
||||
|
||||
m_MultiSampleCount = argMultiSampleCount;
|
||||
m_MultiSampleQuality = argMultiSampleQuality;
|
||||
m_Texture->CreateRenderTargetTexture(argWidth, argHeight, argFormat, argMultiSampleCount, argMultiSampleQuality);
|
||||
|
||||
HRESULT lh_Result = m_Engine.get_DX10Device().CreateRenderTargetView(m_Texture->get_Texture2D(), NULL, &m_RenderTargetView);
|
||||
if(FAILED(lh_Result))
|
||||
throw L"RenderTargetTexture: Unable to retrieve rendertarget view.";
|
||||
|
||||
ViewPort viewPort;
|
||||
viewPort.m_Width = argWidth;
|
||||
viewPort.m_Height = argHeight;
|
||||
this->set_ViewPort(viewPort);
|
||||
}
|
||||
|
||||
|
||||
|
||||
void RenderTargetTexture::Resize(int argWidth, int argHeight)
|
||||
{
|
||||
if (m_Texture == NULL)
|
||||
throw L"SwapChainResource: Access forbidden until resource has been initialized.";
|
||||
|
||||
if (this->get_RenderTargetWidth() == argWidth
|
||||
|| this->get_RenderTargetHeight() == argHeight)
|
||||
return;
|
||||
|
||||
bool lb_DepthStencilBuffer = this->get_HasDepthStencilBuffer();
|
||||
|
||||
this->SetTextureParameters(argWidth, argHeight, this->get_RenderTargetFormat(), m_MultiSampleCount, m_MultiSampleQuality);
|
||||
|
||||
this->set_HasDepthStencilBuffer(lb_DepthStencilBuffer);
|
||||
}
|
||||
|
||||
|
||||
void RenderTargetTexture::Uninitialize()
|
||||
{
|
||||
if (m_Texture != NULL)
|
||||
m_Engine.get_ResourceFactory().DeleteTexture(*m_Texture);
|
||||
|
||||
RenderTargetBase::Uninitialize();
|
||||
}
|
||||
|
||||
|
||||
uint32 RenderTargetTexture::get_RenderTargetWidth() const
|
||||
{
|
||||
return m_Texture == NULL ? 0 : m_Texture->get_TextureWidth();
|
||||
}
|
||||
|
||||
|
||||
uint32 RenderTargetTexture::get_RenderTargetHeight() const
|
||||
{
|
||||
return m_Texture == NULL ? 0 : m_Texture->get_TextureHeight();
|
||||
}
|
||||
|
||||
|
||||
DataFormat::Enumeration RenderTargetTexture::get_RenderTargetFormat() const
|
||||
{
|
||||
return m_Texture == NULL ? DataFormat::Unknown : m_Texture->get_TextureFormat();
|
||||
}
|
||||
@@ -0,0 +1,34 @@
|
||||
#pragma once
|
||||
|
||||
#include "IRenderTargetTexture.h"
|
||||
#include "../RenderTargetBase.h"
|
||||
|
||||
struct ITexture;
|
||||
class RenderTargetTexture
|
||||
: public RenderTargetBase
|
||||
, public IRenderTargetTexture
|
||||
{
|
||||
public:
|
||||
RenderTargetTexture(IEngine& argEngine);
|
||||
virtual ~RenderTargetTexture();
|
||||
|
||||
virtual void SetTextureParameters(uint32 argWidth, uint32 argHeight, DataFormat::Enumeration argFormat, uint32 argMultiSampleCount = 1, uint32 argMultiSampleQuality = 0);
|
||||
virtual void Resize(int argWidth, int argHeight);
|
||||
virtual ITexture& get_TextureResource() const { return *m_Texture; }
|
||||
|
||||
virtual IRenderTargetBase& get_Base() { return *dynamic_cast<IRenderTargetBase*>(this); }
|
||||
|
||||
virtual void Uninitialize();
|
||||
|
||||
// IRenderTargetBase
|
||||
virtual uint32 get_RenderTargetWidth() const;
|
||||
virtual uint32 get_RenderTargetHeight() const;
|
||||
virtual DataFormat::Enumeration get_RenderTargetFormat() const;
|
||||
|
||||
protected:
|
||||
//ICommandUser
|
||||
virtual string8 get_UserName() const { return "RenderTargetTexture"; }
|
||||
|
||||
private:
|
||||
ITexture* m_Texture;
|
||||
};
|
||||
187
aiwaz/Aiwaz/Resources/RenderTarget/SwapChain/SwapChain.cpp
Normal file
187
aiwaz/Aiwaz/Resources/RenderTarget/SwapChain/SwapChain.cpp
Normal file
@@ -0,0 +1,187 @@
|
||||
#include "stdafx.h"
|
||||
#include "SwapChain.h"
|
||||
#include "IResourceFactory.h"
|
||||
#include <exception>
|
||||
|
||||
|
||||
SwapChain::SwapChain(IEngine& argEngine)
|
||||
: RenderTargetBase(argEngine)
|
||||
, m_SwapChain(NULL)
|
||||
, m_VSync(true)
|
||||
{
|
||||
}
|
||||
|
||||
|
||||
SwapChain::~SwapChain()
|
||||
{
|
||||
this->Uninitialize();
|
||||
m_Engine.get_ResourceFactory().DeleteSwapChain(*const_cast<SwapChain*>(this), true);
|
||||
|
||||
}
|
||||
|
||||
void SwapChain::SetWindowParameters(HWND argWindowHandle, uint32 argWidth, uint32 argHeight, uint32 argRefreshRate, DataFormat::Enumeration argFormat, uint32 argMultiSampleCount, uint32 argMultiSampleQuality)
|
||||
{
|
||||
if (m_SwapChain != NULL)
|
||||
this->Uninitialize();
|
||||
|
||||
// get missing information
|
||||
if (argMultiSampleCount == 0)
|
||||
argMultiSampleCount = 1;
|
||||
if (argWidth == 0 || argHeight == 0)
|
||||
{
|
||||
RECT windowRect;
|
||||
::GetClientRect(argWindowHandle, &windowRect);
|
||||
if (argWidth == 0)
|
||||
argWidth = windowRect.right - windowRect.left;
|
||||
if (argHeight == 0)
|
||||
argHeight = windowRect.bottom - windowRect.top;
|
||||
}
|
||||
if (argRefreshRate == 0)
|
||||
argRefreshRate = 60; // 60Hz
|
||||
if (argFormat == DataFormat::Unknown)
|
||||
argFormat = DataFormat::R8G8B8A8_UnsignedNormalized; // RGBA(X) 8Bit per channel -> 32Bit
|
||||
|
||||
// build the description
|
||||
ZeroMemory(&m_SwapChainDescription, sizeof(m_SwapChainDescription));
|
||||
m_SwapChainDescription.BufferCount = 1;
|
||||
m_SwapChainDescription.BufferDesc.Width = argWidth;
|
||||
m_SwapChainDescription.BufferDesc.Height = argHeight;
|
||||
m_SwapChainDescription.BufferDesc.Format = (DXGI_FORMAT)argFormat;
|
||||
m_SwapChainDescription.BufferDesc.RefreshRate.Numerator = argRefreshRate;
|
||||
m_SwapChainDescription.BufferDesc.RefreshRate.Denominator = 1;
|
||||
m_SwapChainDescription.BufferUsage = DXGI_USAGE_RENDER_TARGET_OUTPUT;
|
||||
m_SwapChainDescription.OutputWindow = argWindowHandle;
|
||||
m_MultiSampleCount = m_SwapChainDescription.SampleDesc.Count = argMultiSampleCount;
|
||||
m_MultiSampleQuality = m_SwapChainDescription.SampleDesc.Quality = argMultiSampleQuality;
|
||||
m_SwapChainDescription.Windowed = TRUE;
|
||||
|
||||
if (S_OK != m_Engine.get_DXGIFactory().CreateSwapChain(&m_Engine.get_DX10Device(), &m_SwapChainDescription, &m_SwapChain))
|
||||
{
|
||||
throw L"SwapChain: Unable to create swapchain.";
|
||||
}
|
||||
|
||||
this->RetriveData();
|
||||
|
||||
ViewPort vp;
|
||||
vp.m_Width = argWidth;
|
||||
vp.m_Height = argHeight;
|
||||
this->set_ViewPort(vp);
|
||||
}
|
||||
|
||||
|
||||
void SwapChain::Uninitialize()
|
||||
{
|
||||
RenderTargetBase::Uninitialize();
|
||||
|
||||
/*if (m_SwapChain != NULL)
|
||||
m_SwapChain->Release();*/
|
||||
m_SwapChain = NULL;
|
||||
}
|
||||
|
||||
|
||||
void SwapChain::Resize(int argWidth, int argHeight)
|
||||
{
|
||||
if (m_SwapChain == NULL || m_RenderTargetView == NULL)
|
||||
{
|
||||
throw L"SwapChain: Access forbidden until resource has been initialized.";
|
||||
}
|
||||
|
||||
if (argWidth == 0 || argHeight == 0)
|
||||
{
|
||||
RECT windowRect;
|
||||
::GetClientRect(m_SwapChainDescription.OutputWindow, &windowRect);
|
||||
if (argWidth == 0)
|
||||
argWidth = windowRect.right - windowRect.left;
|
||||
if (argHeight == 0)
|
||||
argHeight = windowRect.bottom - windowRect.top;
|
||||
}
|
||||
|
||||
if (m_SwapChainDescription.BufferDesc.Width == argWidth ||
|
||||
m_SwapChainDescription.BufferDesc.Height == argHeight)
|
||||
return;
|
||||
|
||||
bool depthStencilBuffer = this->get_HasDepthStencilBuffer();
|
||||
|
||||
m_Engine.get_DX10Device().ClearState();
|
||||
|
||||
this->set_HasDepthStencilBuffer(false);
|
||||
|
||||
if (m_RenderTargetView != NULL)
|
||||
m_RenderTargetView->Release();
|
||||
m_RenderTargetView = NULL;
|
||||
|
||||
m_SwapChain->ResizeBuffers(m_SwapChainDescription.BufferCount, argWidth, argHeight, m_SwapChainDescription.BufferDesc.Format, DXGI_SWAP_CHAIN_FLAG_ALLOW_MODE_SWITCH);
|
||||
m_SwapChainDescription.BufferDesc.Width = argWidth;
|
||||
m_SwapChainDescription.BufferDesc.Height = argHeight;
|
||||
this->RetriveData();
|
||||
this->set_HasDepthStencilBuffer(depthStencilBuffer);
|
||||
|
||||
ViewPort vp = this->get_ViewPort();
|
||||
vp.m_Width = argWidth;
|
||||
vp.m_Height = argHeight;
|
||||
this->set_ViewPort(vp);
|
||||
}
|
||||
|
||||
|
||||
void SwapChain::set_Fullscreen(bool argState)
|
||||
{
|
||||
if (m_SwapChainDescription.Windowed == FALSE && argState)
|
||||
{
|
||||
throw L"SwapChain: Fullscreen mode already set.";
|
||||
}
|
||||
if (m_SwapChainDescription.Windowed == TRUE && !argState)
|
||||
{
|
||||
throw L"SwapChain: Windowed mode already set.";
|
||||
}
|
||||
|
||||
m_SwapChainDescription.Windowed = argState ? FALSE : TRUE;
|
||||
|
||||
bool depthStencilBuffer = this->get_HasDepthStencilBuffer();
|
||||
|
||||
m_Engine.get_DX10Device().ClearState();
|
||||
|
||||
this->set_HasDepthStencilBuffer(false);
|
||||
|
||||
if (m_RenderTargetView != NULL)
|
||||
m_RenderTargetView->Release();
|
||||
m_RenderTargetView = NULL;
|
||||
|
||||
m_SwapChain->SetFullscreenState(m_SwapChainDescription.Windowed == FALSE, NULL);
|
||||
this->RetriveData();
|
||||
this->set_HasDepthStencilBuffer(depthStencilBuffer);
|
||||
}
|
||||
|
||||
|
||||
|
||||
void SwapChain::Present()
|
||||
{
|
||||
if (m_SwapChain == NULL || m_RenderTargetView == NULL)
|
||||
{
|
||||
throw L"SwapChain: Access forbidden until resource has been initialized.";
|
||||
}
|
||||
|
||||
m_SwapChain->Present(m_VSync ? 1 : 0, 0); // VSync, Flags
|
||||
}
|
||||
|
||||
|
||||
void SwapChain::RetriveData()
|
||||
{
|
||||
if (m_SwapChain == NULL || m_RenderTargetView != NULL)
|
||||
{
|
||||
throw L"SwapChain: Access forbidden until resource has been initialized.";
|
||||
}
|
||||
|
||||
ID3D10Texture2D* backBuffer;
|
||||
HRESULT result = m_SwapChain->GetBuffer(0, __uuidof(ID3D10Texture2D), (void**)&backBuffer);
|
||||
if(FAILED(result))
|
||||
{
|
||||
throw L"SwapChain: Unable to retrive backbuffer.";
|
||||
}
|
||||
|
||||
result = m_Engine.get_DX10Device().CreateRenderTargetView(backBuffer, NULL, &m_RenderTargetView);
|
||||
backBuffer->Release();
|
||||
if(FAILED(result))
|
||||
{
|
||||
throw L"SwapChain: Unable to retrive rendertarget view.";
|
||||
}
|
||||
}
|
||||
44
aiwaz/Aiwaz/Resources/RenderTarget/SwapChain/SwapChain.h
Normal file
44
aiwaz/Aiwaz/Resources/RenderTarget/SwapChain/SwapChain.h
Normal file
@@ -0,0 +1,44 @@
|
||||
#pragma once
|
||||
|
||||
#include "IEngine.h"
|
||||
#include "ISwapChain.h"
|
||||
#include "../RenderTargetBase.h"
|
||||
|
||||
|
||||
class SwapChain
|
||||
: public RenderTargetBase
|
||||
, public ISwapChain
|
||||
{
|
||||
public:
|
||||
SwapChain(IEngine& argEngine);
|
||||
virtual ~SwapChain();
|
||||
|
||||
virtual void SetWindowParameters(HWND argWindowHandle, uint32 argWidth = 0, uint32 argHeight = 0, uint32 argRefreshRate = 0, DataFormat::Enumeration argFormat = DataFormat::Unknown, uint32 argMultiSampleCount = 0, uint32 argMultiSampleQuality = 0);
|
||||
virtual void Resize(int argWidth, int argHeight);
|
||||
virtual void Present();
|
||||
|
||||
virtual bool get_Fullscreen() const { return !m_SwapChainDescription.Windowed; }
|
||||
virtual void set_Fullscreen(bool argState);
|
||||
virtual bool get_VSync() const { return m_VSync; }
|
||||
virtual void set_VSync(bool argState) {m_VSync = argState; }
|
||||
|
||||
virtual IRenderTargetBase& get_Base() { return *dynamic_cast<IRenderTargetBase*>(this); }
|
||||
|
||||
// IRenderTargetBase
|
||||
virtual uint32 get_RenderTargetWidth() const { return m_SwapChainDescription.BufferDesc.Width; }
|
||||
virtual uint32 get_RenderTargetHeight() const { return m_SwapChainDescription.BufferDesc.Height; }
|
||||
virtual DataFormat::Enumeration get_RenderTargetFormat() const { return (DataFormat::Enumeration)m_SwapChainDescription.BufferDesc.Format; }
|
||||
|
||||
protected:
|
||||
//ICommandUser
|
||||
virtual string8 get_UserName() const { return "SwapChain"; }
|
||||
|
||||
protected:
|
||||
void RetriveData();
|
||||
virtual void Uninitialize();
|
||||
|
||||
private:
|
||||
DXGI_SWAP_CHAIN_DESC m_SwapChainDescription;
|
||||
IDXGISwapChain* m_SwapChain;
|
||||
bool m_VSync;
|
||||
};
|
||||
61
aiwaz/Aiwaz/Resources/Shader/InternalShader.cpp
Normal file
61
aiwaz/Aiwaz/Resources/Shader/InternalShader.cpp
Normal file
@@ -0,0 +1,61 @@
|
||||
#include "stdafx.h"
|
||||
#include "InternalShader.h"
|
||||
#include "IResourceFactory.h"
|
||||
|
||||
|
||||
InternalShader::InternalShader(const IEngine& argEngine)
|
||||
: m_Engine(argEngine)
|
||||
, m_Effect(NULL)
|
||||
{
|
||||
}
|
||||
|
||||
|
||||
InternalShader::~InternalShader()
|
||||
{
|
||||
m_Engine.get_ResourceFactory().DeleteInternalShader(*const_cast<InternalShader*>(this), true);
|
||||
}
|
||||
|
||||
|
||||
void InternalShader::LoadFromFile(const string16& argFileName)
|
||||
{
|
||||
if (m_Effect != NULL)
|
||||
this->Uninitialize();
|
||||
|
||||
HRESULT result = E_FAIL;
|
||||
|
||||
IFile* shaderFile = m_Engine.get_FileSystem().Open(argFileName);
|
||||
if (shaderFile == NULL)
|
||||
throw L"Unable to open shader file.";
|
||||
|
||||
ID3D10Blob* error = NULL;
|
||||
result = ::D3DX10CreateEffectFromMemory(shaderFile->get_Buffer(), shaderFile->get_BufferLength(), std::to_string8(argFileName).c_str(), NULL, NULL, "fx_4_0",
|
||||
#ifdef _DEBUG
|
||||
D3D10_SHADER_ENABLE_STRICTNESS | D3D10_SHADER_DEBUG,
|
||||
#else
|
||||
D3D10_SHADER_ENABLE_STRICTNESS,
|
||||
#endif
|
||||
0, &m_Engine.get_DX10Device(), NULL, NULL, &m_Effect, &error, NULL);
|
||||
|
||||
if (result != S_OK)
|
||||
std::cout << std::red << "Unable to load shader file from memory. " << std::white << std::endl;
|
||||
|
||||
if (error != NULL)
|
||||
{
|
||||
string8 errorText = static_cast<char*>(error->GetBufferPointer());
|
||||
std::cout << std::red << errorText << std::white << std::endl;
|
||||
::OutputDebugString(errorText.c_str());
|
||||
throw errorText;
|
||||
}
|
||||
if (error != NULL)
|
||||
error->Release();
|
||||
|
||||
delete shaderFile;
|
||||
}
|
||||
|
||||
|
||||
void InternalShader::Uninitialize()
|
||||
{
|
||||
if (m_Effect != NULL)
|
||||
m_Effect->Release();
|
||||
m_Effect = NULL;
|
||||
}
|
||||
24
aiwaz/Aiwaz/Resources/Shader/InternalShader.h
Normal file
24
aiwaz/Aiwaz/Resources/Shader/InternalShader.h
Normal file
@@ -0,0 +1,24 @@
|
||||
#pragma once
|
||||
|
||||
#include "IEngine.h"
|
||||
#include "IShader.h"
|
||||
#include "IFileSystem.h"
|
||||
|
||||
|
||||
class InternalShader
|
||||
: public IInternalShader
|
||||
{
|
||||
public:
|
||||
InternalShader(const IEngine& argEngine);
|
||||
virtual ~InternalShader();
|
||||
|
||||
virtual void Uninitialize();
|
||||
|
||||
virtual void LoadFromFile(const string16& argValue);
|
||||
|
||||
virtual ID3D10Effect* get_DX10Effect() const { return m_Effect; }
|
||||
|
||||
protected:
|
||||
const IEngine& m_Engine;
|
||||
ID3D10Effect* m_Effect;
|
||||
};
|
||||
140
aiwaz/Aiwaz/Resources/Shader/Shader.cpp
Normal file
140
aiwaz/Aiwaz/Resources/Shader/Shader.cpp
Normal file
@@ -0,0 +1,140 @@
|
||||
#include "stdafx.h"
|
||||
#include "IResourceFactory.h"
|
||||
#include "Shader.h"
|
||||
|
||||
|
||||
Shader::Shader(IEngine& argEngine)
|
||||
: m_Engine(argEngine)
|
||||
, m_Technique(NULL)
|
||||
, m_InternalShader(NULL)
|
||||
, m_CurrentPass(-1)
|
||||
, m_Priority(0)
|
||||
{
|
||||
m_Commands.push_back(new Command(this, CommandFlags::StartChain | CommandFlags::SubChainStart, ApplyFirstPassCommandType, 2, m_Priority));
|
||||
m_Commands.push_back(new Command(this, CommandFlags::SubChainEnd, NextPassCommandType, -1, m_Priority));
|
||||
}
|
||||
|
||||
|
||||
Shader::~Shader()
|
||||
{
|
||||
this->Uninitialize();
|
||||
m_Engine.get_ResourceFactory().DeleteShader(*const_cast<Shader*>(this), true);
|
||||
}
|
||||
|
||||
|
||||
void Shader::set_TechniqueName(const string8& argValue)
|
||||
{
|
||||
m_TechniqueName = argValue;
|
||||
|
||||
if (this->get_InternalShader() == NULL)
|
||||
return;
|
||||
|
||||
if (m_TechniqueName.empty())
|
||||
{
|
||||
m_Technique = this->get_InternalShader()->get_DX10Effect()->GetTechniqueByIndex(0);
|
||||
|
||||
if (m_Technique != NULL)
|
||||
{
|
||||
D3D10_TECHNIQUE_DESC desc;
|
||||
m_Technique->GetDesc(&desc);
|
||||
m_TechniqueName = desc.Name;
|
||||
}
|
||||
}
|
||||
|
||||
m_Technique = this->get_InternalShader()->get_DX10Effect()->GetTechniqueByName(m_TechniqueName.c_str());
|
||||
if (m_Technique == NULL)
|
||||
{
|
||||
throw L"Shader: Technique not found.";
|
||||
}
|
||||
|
||||
m_Technique->GetDesc(&m_TechDesc);
|
||||
}
|
||||
|
||||
|
||||
void Shader::LoadFromFile(const string16& argValue)
|
||||
{
|
||||
this->CreateOrFindShader(argValue);
|
||||
this->set_TechniqueName(m_TechniqueName);
|
||||
}
|
||||
|
||||
|
||||
void Shader::Uninitialize()
|
||||
{
|
||||
if (m_Engine.get_EngineStates().LastShader == this)
|
||||
m_Engine.get_EngineStates().LastShader = NULL;
|
||||
|
||||
m_Technique = NULL;
|
||||
m_CurrentPass = -1;
|
||||
m_TechniqueName = "";
|
||||
}
|
||||
|
||||
|
||||
bool Shader::TryApplyNextPass()
|
||||
{
|
||||
if (m_InternalShader == NULL || m_Technique == NULL)
|
||||
throw L"Shader: Access forbidden until resource has been initialized.";
|
||||
|
||||
if (m_CurrentPass >= m_TechDesc.Passes)
|
||||
m_CurrentPass = m_TechDesc.Passes;
|
||||
else
|
||||
m_CurrentPass++;
|
||||
|
||||
if (m_CurrentPass >= m_TechDesc.Passes)
|
||||
return false;
|
||||
return true;
|
||||
}
|
||||
|
||||
|
||||
void Shader::ApplyFirstPass()
|
||||
{
|
||||
if (m_InternalShader == NULL || m_Technique == NULL)
|
||||
throw L"Shader: Access forbidden until resource has been initialized.";
|
||||
m_CurrentPass = 0;
|
||||
|
||||
m_Engine.get_EngineStates().LastShader = this;
|
||||
}
|
||||
|
||||
|
||||
void Shader::set_Priority(unsigned char argValue)
|
||||
{
|
||||
m_Priority = argValue;
|
||||
for (uint32 i = 0; i < m_Commands.size(); ++i)
|
||||
if (m_Commands[i]->Type == ApplyFirstPassCommandType)
|
||||
m_Commands[i]->SubPriority = m_Priority;
|
||||
}
|
||||
|
||||
|
||||
unsigned char Shader::get_Priority() const
|
||||
{
|
||||
return m_Priority;
|
||||
}
|
||||
|
||||
|
||||
IInternalShader* Shader::CreateOrFindShader(const string16& argFileName)
|
||||
{
|
||||
IResourceFactory& resFac = m_Engine.get_ResourceFactory();
|
||||
m_InternalShader = &resFac.CreateOrFindInternalShader(std::to_string8(argFileName));
|
||||
if (m_InternalShader != NULL)
|
||||
{
|
||||
if (resFac.HasCreatedResource())
|
||||
m_InternalShader->LoadFromFile(argFileName);
|
||||
return m_InternalShader;
|
||||
}
|
||||
|
||||
throw L"Shader: Unable to create ShaderInternal for specified Shader.";
|
||||
}
|
||||
|
||||
|
||||
CommandExecuteResult::Enumeration Shader::ExecuteCommand(unsigned char argCommandType, ICommandBuffer& argCurrentBuffer, uint32 argCurrentPositon)
|
||||
{
|
||||
if (argCommandType == Shader::ApplyFirstPassCommandType)
|
||||
{
|
||||
this->ApplyFirstPass();
|
||||
}
|
||||
else if (argCommandType == Shader::NextPassCommandType)
|
||||
{
|
||||
if (this->TryApplyNextPass())
|
||||
return CommandExecuteResult::RetrySubChainSkipHead;
|
||||
}
|
||||
return CommandExecuteResult::None;
|
||||
}
|
||||
53
aiwaz/Aiwaz/Resources/Shader/Shader.h
Normal file
53
aiwaz/Aiwaz/Resources/Shader/Shader.h
Normal file
@@ -0,0 +1,53 @@
|
||||
#pragma once
|
||||
|
||||
#include "IFileSystem.h"
|
||||
#include "IEngine.h"
|
||||
#include "IShader.h"
|
||||
#include "../Commands/CommandUserBase.h"
|
||||
|
||||
|
||||
class Shader
|
||||
: public IShader
|
||||
, public CommandUserBase
|
||||
{
|
||||
protected:
|
||||
static const unsigned char ApplyFirstPassCommandType = 0;
|
||||
static const unsigned char NextPassCommandType = 1;
|
||||
|
||||
public:
|
||||
Shader(IEngine& argEngine);
|
||||
virtual ~Shader();
|
||||
|
||||
virtual void LoadFromFile(const string16& argValue);
|
||||
|
||||
virtual string8 get_TechniqueName() const { return m_TechniqueName; }
|
||||
virtual void set_TechniqueName(const string8& argValue);
|
||||
|
||||
virtual ID3D10EffectTechnique* get_DX10Technique() const { return m_Technique; }
|
||||
virtual IInternalShader* get_InternalShader() const { return m_InternalShader; }
|
||||
|
||||
virtual bool TryApplyNextPass();
|
||||
virtual void ApplyFirstPass();
|
||||
virtual uint32 get_CurrentRenderPass() const { return m_CurrentPass; }
|
||||
|
||||
virtual void set_Priority(unsigned char argValue);
|
||||
virtual unsigned char get_Priority() const;
|
||||
|
||||
protected:
|
||||
virtual void Uninitialize();
|
||||
IInternalShader* CreateOrFindShader(const string16& argFileName);
|
||||
|
||||
// ICommandUser
|
||||
virtual CommandExecuteResult::Enumeration ExecuteCommand(unsigned char argCommandType, ICommandBuffer& argCurrentBuffer, uint32 argCurrentPositon);
|
||||
virtual string8 get_UserName() const { return "Shader"; }
|
||||
|
||||
private:
|
||||
IEngine& m_Engine;
|
||||
|
||||
string8 m_TechniqueName;
|
||||
uint32 m_CurrentPass;
|
||||
ID3D10EffectTechnique* m_Technique;
|
||||
IInternalShader* m_InternalShader;
|
||||
D3D10_TECHNIQUE_DESC m_TechDesc;
|
||||
unsigned char m_Priority;
|
||||
};
|
||||
@@ -0,0 +1,79 @@
|
||||
#include "stdafx.h"
|
||||
#include "IShader.h"
|
||||
#include "BasisParameterCollection.h"
|
||||
|
||||
|
||||
BasisShaderParameterCollection::BasisShaderParameterCollection()
|
||||
{
|
||||
}
|
||||
|
||||
|
||||
BasisShaderParameterCollection::~BasisShaderParameterCollection()
|
||||
{
|
||||
this->RemoveAllShaderParameters();
|
||||
}
|
||||
|
||||
|
||||
void BasisShaderParameterCollection::UseParametersOnShader(IShader& argShader)
|
||||
{
|
||||
if (m_ParameterMap.empty())
|
||||
return;
|
||||
|
||||
tk_ShaderToShaderParameter::iterator shaderPos = m_ShaderToParameterMap.find(argShader.get_InternalShader());
|
||||
if (shaderPos == m_ShaderToParameterMap.end())
|
||||
{
|
||||
tk_ShaderParameterPairs newSet;
|
||||
|
||||
// (re)create shader entries
|
||||
tk_StringToShaderParameter::iterator iter = m_ParameterMap.begin();
|
||||
for (; iter != m_ParameterMap.end(); ++iter)
|
||||
{
|
||||
if (iter->second != NULL)
|
||||
{
|
||||
ID3D10EffectVariable* var = NULL;
|
||||
if (iter->second->get_ParameterNameType() == ParameterBindType::BindByVariable)
|
||||
var = argShader.get_InternalShader()->get_DX10Effect()->GetVariableByName(iter->first.c_str());
|
||||
else if (iter->second->get_ParameterNameType() == ParameterBindType::BindBySemantic)
|
||||
var = argShader.get_InternalShader()->get_DX10Effect()->GetVariableBySemantic(iter->first.c_str());
|
||||
|
||||
if (var != NULL)
|
||||
newSet.push_back(ShaderParameterPair(*iter->second, var));
|
||||
}
|
||||
}
|
||||
|
||||
if (newSet.empty())
|
||||
return;
|
||||
|
||||
m_ShaderToParameterMap[argShader.get_InternalShader()] = newSet;
|
||||
}
|
||||
|
||||
tk_ShaderParameterPairs& set = m_ShaderToParameterMap[argShader.get_InternalShader()];
|
||||
for (uint32 i = 0; i < set.size(); ++i)
|
||||
set[i].Parameter->ApplyValue(*set[i].TargetVariable);
|
||||
}
|
||||
|
||||
|
||||
void BasisShaderParameterCollection::SetShaderParameter(const string8& argParameterName, IShaderParameter& argParameter)
|
||||
{
|
||||
this->RemoveShaderParameter(argParameterName);
|
||||
m_ParameterMap[argParameterName] = &argParameter;
|
||||
}
|
||||
|
||||
|
||||
void BasisShaderParameterCollection::RemoveShaderParameter(const string8& argParameterName)
|
||||
{
|
||||
m_ShaderToParameterMap.clear();
|
||||
tk_StringToShaderParameter::iterator found = m_ParameterMap.find(argParameterName);
|
||||
if (found != m_ParameterMap.end())
|
||||
m_ParameterMap.erase(found);
|
||||
}
|
||||
|
||||
|
||||
void BasisShaderParameterCollection::RemoveAllShaderParameters()
|
||||
{
|
||||
while (!m_ParameterMap.empty())
|
||||
{
|
||||
delete m_ParameterMap.begin()->second;
|
||||
m_ParameterMap.erase(m_ParameterMap.begin());
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,38 @@
|
||||
#include "IShaderParameterCollection.h"
|
||||
|
||||
|
||||
struct ID3D10EffectVariable;
|
||||
struct IShader;
|
||||
struct IInternalShader;
|
||||
struct IShaderParameter;
|
||||
class BasisShaderParameterCollection
|
||||
{
|
||||
public:
|
||||
BasisShaderParameterCollection();
|
||||
~BasisShaderParameterCollection();
|
||||
|
||||
void UseParametersOnShader(IShader& argShader);
|
||||
void SetShaderParameter(const string8& argParameterName, IShaderParameter& argParameter);
|
||||
void RemoveShaderParameter(const string8& argParameterName);
|
||||
void RemoveAllShaderParameters();
|
||||
|
||||
protected:
|
||||
|
||||
struct ShaderParameterPair
|
||||
{
|
||||
ShaderParameterPair(IShaderParameter& argShaderParameter, ID3D10EffectVariable* ar_EffectVariable_)
|
||||
: Parameter(&argShaderParameter)
|
||||
, TargetVariable(ar_EffectVariable_)
|
||||
{}
|
||||
|
||||
IShaderParameter* Parameter;
|
||||
ID3D10EffectVariable* TargetVariable;
|
||||
};
|
||||
|
||||
typedef std::map<string8, IShaderParameter*> tk_StringToShaderParameter;
|
||||
typedef std::vector<ShaderParameterPair> tk_ShaderParameterPairs;
|
||||
typedef std::map<IInternalShader*, tk_ShaderParameterPairs> tk_ShaderToShaderParameter;
|
||||
|
||||
tk_ShaderToShaderParameter m_ShaderToParameterMap;
|
||||
tk_StringToShaderParameter m_ParameterMap;
|
||||
};
|
||||
@@ -0,0 +1,162 @@
|
||||
#include "stdafx.h"
|
||||
#include "ShaderParameterCollection.h"
|
||||
#include "IEngine.h"
|
||||
#include "IResourceFactory.h"
|
||||
|
||||
#include "Types/Types.h"
|
||||
|
||||
|
||||
ShaderParameterCollection::ShaderParameterCollection(IEngine& argEngine, unsigned char argBasePriority)
|
||||
: m_Engine(argEngine)
|
||||
, m_BasePriority(argBasePriority)
|
||||
{
|
||||
this->set_IsPreconditionForFollowingShaders(false);
|
||||
}
|
||||
|
||||
|
||||
ShaderParameterCollection::~ShaderParameterCollection()
|
||||
{
|
||||
this->Uninitialize();
|
||||
m_Engine.get_ResourceFactory().DeleteShaderParameterCollection(*const_cast<ShaderParameterCollection*>(this), true);
|
||||
}
|
||||
|
||||
|
||||
void ShaderParameterCollection::Uninitialize()
|
||||
{
|
||||
m_BasisShaderParameterCollection.RemoveAllShaderParameters();
|
||||
}
|
||||
|
||||
|
||||
bool ShaderParameterCollection::get_IsPreconditionForFollowingShaders() const
|
||||
{
|
||||
return m_IsPreconditionForFollowingShaders;
|
||||
}
|
||||
|
||||
|
||||
void ShaderParameterCollection::set_IsPreconditionForFollowingShaders(bool argValue)
|
||||
{
|
||||
if (!m_Commands.empty() && argValue == m_IsPreconditionForFollowingShaders)
|
||||
return;
|
||||
|
||||
m_IsPreconditionForFollowingShaders = argValue;
|
||||
|
||||
while (!m_Commands.empty())
|
||||
{
|
||||
delete m_Commands[0];
|
||||
m_Commands.erase(m_Commands.begin());
|
||||
}
|
||||
|
||||
if (m_IsPreconditionForFollowingShaders)
|
||||
m_Commands.push_back(new Command(this, CommandFlags::EndChain | CommandFlags::FlushChain, SetFollowingShaderParameterCollectionCommandType, 0));
|
||||
else
|
||||
m_Commands.push_back(new Command(this, CommandFlags::None, SetShaderParameterCollectionCommandType, m_BasePriority));
|
||||
|
||||
this->MarkCommandsAsDirty();
|
||||
}
|
||||
|
||||
|
||||
void ShaderParameterCollection::SetParameter(const string8& argParameterName, IShaderParameter* ar_Parameter_)
|
||||
{
|
||||
m_BasisShaderParameterCollection.SetShaderParameter(argParameterName, *ar_Parameter_);
|
||||
//this->MarkCommandsAsDirty();
|
||||
}
|
||||
|
||||
|
||||
void ShaderParameterCollection::SetParameter(const string8& argParameterName, ITexture& argParameter, ParameterBindType::Enumeration argParamNameType)
|
||||
{
|
||||
this->SetParameter(argParameterName, new TextureShaderParameter(argParameter, argParamNameType));
|
||||
}
|
||||
|
||||
|
||||
void ShaderParameterCollection::SetParameter(const string8& argParameterName, float* af_Parameter_, ParameterBindType::Enumeration argParamNameType)
|
||||
{
|
||||
this->SetParameter(argParameterName, new FloatShaderParameter(af_Parameter_, argParamNameType));
|
||||
}
|
||||
|
||||
|
||||
void ShaderParameterCollection::SetParameter(const string8& argParameterName, float argParameter, ParameterBindType::Enumeration argParamNameType)
|
||||
{
|
||||
this->SetParameter(argParameterName, new FloatShaderParameter(argParameter, argParamNameType));
|
||||
}
|
||||
|
||||
|
||||
void ShaderParameterCollection::SetParameter(const string8& argParameterName, D3DXVECTOR4* ar_Parameter_, ParameterBindType::Enumeration argParamNameType)
|
||||
{
|
||||
this->SetParameter(argParameterName, new Float4ShaderParameter(ar_Parameter_, argParamNameType));
|
||||
}
|
||||
|
||||
|
||||
void ShaderParameterCollection::SetParameter(const string8& argParameterName, const D3DXVECTOR4& argParameter, ParameterBindType::Enumeration argParamNameType)
|
||||
{
|
||||
this->SetParameter(argParameterName, new Float4ShaderParameter(argParameter, argParamNameType));
|
||||
}
|
||||
|
||||
|
||||
void ShaderParameterCollection::SetParameter(const string8& argParameterName, D3DXVECTOR3* ar_Parameter_, ParameterBindType::Enumeration argParamNameType)
|
||||
{
|
||||
this->SetParameter(argParameterName, new Float3ShaderParameter(ar_Parameter_, argParamNameType));
|
||||
}
|
||||
|
||||
|
||||
void ShaderParameterCollection::SetParameter(const string8& argParameterName, const D3DXVECTOR3& argParameter, ParameterBindType::Enumeration argParamNameType)
|
||||
{
|
||||
this->SetParameter(argParameterName, new Float3ShaderParameter(argParameter, argParamNameType));
|
||||
}
|
||||
|
||||
|
||||
void ShaderParameterCollection::SetParameter(const string8& argParameterName, D3DXMATRIX* argParameter, ParameterBindType::Enumeration argParamNameType)
|
||||
{
|
||||
this->SetParameter(argParameterName, new Matrix4x4ShaderParameter(argParameter, argParamNameType));
|
||||
}
|
||||
|
||||
|
||||
void ShaderParameterCollection::SetParameter(const string8& argParameterName, const D3DXMATRIX& argParameter, ParameterBindType::Enumeration argParamNameType)
|
||||
{
|
||||
this->SetParameter(argParameterName, new Matrix4x4ShaderParameter(argParameter, argParamNameType));
|
||||
}
|
||||
|
||||
|
||||
void ShaderParameterCollection::SetParameter(const string8& argParameterName, bool* ab_Parameter_, ParameterBindType::Enumeration argParamNameType)
|
||||
{
|
||||
this->SetParameter(argParameterName, new BoolShaderParameter(ab_Parameter_, argParamNameType));
|
||||
}
|
||||
|
||||
|
||||
void ShaderParameterCollection::SetParameter(const string8& argParameterName, bool argParameter, ParameterBindType::Enumeration argParamNameType)
|
||||
{
|
||||
this->SetParameter(argParameterName, new BoolShaderParameter(argParameter, argParamNameType));
|
||||
}
|
||||
|
||||
|
||||
void ShaderParameterCollection::RemoveParameter(const string8& argParameterName)
|
||||
{
|
||||
m_BasisShaderParameterCollection.RemoveShaderParameter(argParameterName);
|
||||
}
|
||||
|
||||
|
||||
CommandExecuteResult::Enumeration ShaderParameterCollection::ExecuteCommand(unsigned char argCommandType, ICommandBuffer& argCurrentBuffer, uint32 argCurrentPositon)
|
||||
{
|
||||
if (argCommandType == SetShaderParameterCollectionCommandType)
|
||||
{
|
||||
if (m_Engine.get_EngineStates().LastShader == NULL)
|
||||
std::wcout << std::red << "ShaderParameterCollection could not been used without a valid shader." << std::white << std::endl;
|
||||
this->UseOnShader(*m_Engine.get_EngineStates().LastShader);
|
||||
}
|
||||
else if (argCommandType == SetFollowingShaderParameterCollectionCommandType)
|
||||
{
|
||||
const std::vector<Command*>& commands = argCurrentBuffer.get_BufferedCommands();
|
||||
for (uint32 i = argCurrentPositon + 1; i < commands.size(); ++i)
|
||||
{
|
||||
IShader* shader = dynamic_cast<IShader*>(commands[i]->Owner);
|
||||
if (shader != NULL && commands[i]->Type == 0)
|
||||
this->UseOnShader(*shader);
|
||||
}
|
||||
}
|
||||
return CommandExecuteResult::None;
|
||||
}
|
||||
|
||||
|
||||
void ShaderParameterCollection::UseOnShader(IShader& argShader)
|
||||
{
|
||||
m_BasisShaderParameterCollection.UseParametersOnShader(argShader);
|
||||
}
|
||||
@@ -0,0 +1,53 @@
|
||||
#pragma once
|
||||
|
||||
#include "BasisParameterCollection.h"
|
||||
#include "IShaderParameterCollection.h"
|
||||
#include "../Commands/CommandUserBase.h"
|
||||
|
||||
|
||||
struct IEngine;
|
||||
class ShaderParameterCollection
|
||||
: public IShaderParameterCollection
|
||||
, public CommandUserBase
|
||||
{
|
||||
static const unsigned char SetShaderParameterCollectionCommandType = 0;
|
||||
static const unsigned char SetFollowingShaderParameterCollectionCommandType = 1;
|
||||
public:
|
||||
ShaderParameterCollection(IEngine& argEngine, unsigned char argBasePriority = 4);
|
||||
virtual ~ShaderParameterCollection();
|
||||
|
||||
virtual void Uninitialize();
|
||||
|
||||
// IShaderParameterCollection
|
||||
virtual bool get_IsPreconditionForFollowingShaders() const;
|
||||
virtual void set_IsPreconditionForFollowingShaders(bool argValue);
|
||||
|
||||
virtual void SetParameter(const string8& argParameterName,IShaderParameter* ar_Parameter_);
|
||||
virtual void SetParameter(const string8& argParameterName, ITexture& argParameter, ParameterBindType::Enumeration argParamNameType = ParameterBindType::BindBySemantic);
|
||||
virtual void SetParameter(const string8& argParameterName, float* af_Parameter_, ParameterBindType::Enumeration argParamNameType = ParameterBindType::BindBySemantic);
|
||||
virtual void SetParameter(const string8& argParameterName, float argParameter, ParameterBindType::Enumeration argParamNameType = ParameterBindType::BindBySemantic);
|
||||
virtual void SetParameter(const string8& argParameterName, D3DXVECTOR4* ar_Parameter_, ParameterBindType::Enumeration argParamNameType = ParameterBindType::BindBySemantic);
|
||||
virtual void SetParameter(const string8& argParameterName, const D3DXVECTOR4& argParameter, ParameterBindType::Enumeration argParamNameType = ParameterBindType::BindBySemantic);
|
||||
virtual void SetParameter(const string8& argParameterName, D3DXVECTOR3* ar_Parameter_, ParameterBindType::Enumeration argParamNameType = ParameterBindType::BindBySemantic);
|
||||
virtual void SetParameter(const string8& argParameterName, const D3DXVECTOR3& argParameter, ParameterBindType::Enumeration argParamNameType = ParameterBindType::BindBySemantic);
|
||||
virtual void SetParameter(const string8& argParameterName, D3DXMATRIX* argParameter, ParameterBindType::Enumeration argParamNameType = ParameterBindType::BindBySemantic);
|
||||
virtual void SetParameter(const string8& argParameterName, const D3DXMATRIX& argParameter, ParameterBindType::Enumeration argParamNameType = ParameterBindType::BindBySemantic);
|
||||
virtual void SetParameter(const string8& argParameterName, bool* ab_Parameter_, ParameterBindType::Enumeration argParamNameType = ParameterBindType::BindBySemantic);
|
||||
virtual void SetParameter(const string8& argParameterName, bool argParameter, ParameterBindType::Enumeration argParamNameType = ParameterBindType::BindBySemantic);
|
||||
virtual void RemoveParameter(const string8& argParameterName);
|
||||
|
||||
protected:
|
||||
// ICommandUser
|
||||
virtual CommandExecuteResult::Enumeration ExecuteCommand(unsigned char argCommandType, ICommandBuffer& argCurrentBuffer, uint32 argCurrentPositon);
|
||||
virtual bool get_IsPreconditionForNextCommands() const { return m_IsPreconditionForFollowingShaders; }
|
||||
virtual string8 get_UserName() const { return "ShaderParameterCollection"; }
|
||||
|
||||
void UseOnShader(IShader& argShader);
|
||||
|
||||
protected:
|
||||
IEngine& m_Engine;
|
||||
|
||||
BasisShaderParameterCollection m_BasisShaderParameterCollection;
|
||||
bool m_IsPreconditionForFollowingShaders;
|
||||
unsigned char m_BasePriority;
|
||||
};
|
||||
@@ -0,0 +1,35 @@
|
||||
#pragma once
|
||||
#include "IShader.h"
|
||||
#include "IShaderParameterCollection.h"
|
||||
|
||||
|
||||
//////////////////////////////////////////////////////////////////////////
|
||||
struct ParameterMetaType
|
||||
{
|
||||
enum Enumeration
|
||||
{
|
||||
Fixed,
|
||||
FixedArray,
|
||||
Dynamic,
|
||||
DynamicArray
|
||||
};
|
||||
};
|
||||
|
||||
|
||||
class BaseShaderParameter
|
||||
: public IShaderParameter
|
||||
{
|
||||
public:
|
||||
BaseShaderParameter(ParameterBindType::Enumeration argType, ParameterMetaType::Enumeration argMetaType = ParameterMetaType::Fixed)
|
||||
: m_NameType(argType)
|
||||
, m_Type(argMetaType)
|
||||
{
|
||||
}
|
||||
|
||||
virtual ParameterBindType::Enumeration get_ParameterNameType() const { return m_NameType; }
|
||||
virtual void set_ParameterNameType(ParameterBindType::Enumeration argBindType) { m_NameType = argBindType; }
|
||||
|
||||
protected:
|
||||
ParameterBindType::Enumeration m_NameType;
|
||||
ParameterMetaType::Enumeration m_Type;
|
||||
};
|
||||
@@ -0,0 +1,60 @@
|
||||
#pragma once
|
||||
#include "BaseType.h"
|
||||
|
||||
class BoolShaderParameter
|
||||
: public BaseShaderParameter
|
||||
{
|
||||
public:
|
||||
BoolShaderParameter(bool argValue, ParameterBindType::Enumeration argType = ParameterBindType::BindByVariable)
|
||||
: BaseShaderParameter(argType, ParameterMetaType::Fixed)
|
||||
{
|
||||
m_Value = new bool(argValue);
|
||||
}
|
||||
|
||||
BoolShaderParameter(const bool* af_Value_, uint32 argCount, ParameterBindType::Enumeration argType = ParameterBindType::BindByVariable)
|
||||
: BaseShaderParameter(argType, ParameterMetaType::FixedArray)
|
||||
, m_Count(argCount)
|
||||
{
|
||||
m_Value = new bool[m_Count];
|
||||
::CopyMemory(m_Value, af_Value_, sizeof(bool) * m_Count);
|
||||
}
|
||||
BoolShaderParameter(bool* af_Value_, ParameterBindType::Enumeration argType = ParameterBindType::BindByVariable)
|
||||
: BaseShaderParameter(argType, ParameterMetaType::Dynamic)
|
||||
, m_Value(af_Value_)
|
||||
{
|
||||
}
|
||||
BoolShaderParameter(bool** af_Value__, uint32 argCount, ParameterBindType::Enumeration argType = ParameterBindType::BindByVariable)
|
||||
: BaseShaderParameter(argType, ParameterMetaType::DynamicArray)
|
||||
, m_Value(*af_Value__)
|
||||
, m_Count(argCount)
|
||||
{}
|
||||
|
||||
virtual ~BoolShaderParameter()
|
||||
{
|
||||
if (m_Type == ParameterMetaType::FixedArray)
|
||||
delete [] m_Value;
|
||||
if (m_Type == ParameterMetaType::Fixed)
|
||||
delete m_Value;
|
||||
}
|
||||
|
||||
virtual void ApplyValue(ID3D10EffectVariable& argTargetVariable)
|
||||
{
|
||||
ID3D10EffectScalarVariable* scalar = argTargetVariable.AsScalar();
|
||||
if (scalar != NULL)
|
||||
{
|
||||
switch (m_Type)
|
||||
{
|
||||
case ParameterMetaType::Fixed:
|
||||
case ParameterMetaType::Dynamic:
|
||||
scalar->SetBool((BOOL)*m_Value);
|
||||
break;
|
||||
default:
|
||||
scalar->SetBoolArray((BOOL*)m_Value, 0, m_Count);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private:
|
||||
bool* m_Value;
|
||||
uint32 m_Count;
|
||||
};
|
||||
178
aiwaz/Aiwaz/Resources/ShaderParameterCollection/Types/Float.h
Normal file
178
aiwaz/Aiwaz/Resources/ShaderParameterCollection/Types/Float.h
Normal file
@@ -0,0 +1,178 @@
|
||||
#pragma once
|
||||
#include "baseType.h"
|
||||
|
||||
class FloatShaderParameter
|
||||
: public BaseShaderParameter
|
||||
{
|
||||
public:
|
||||
FloatShaderParameter(float argValue, ParameterBindType::Enumeration argType = ParameterBindType::BindByVariable)
|
||||
: BaseShaderParameter(argType, ParameterMetaType::Fixed)
|
||||
{
|
||||
m_Value = new float(argValue);
|
||||
}
|
||||
|
||||
FloatShaderParameter(const float* af_Value_, uint32 argCount, ParameterBindType::Enumeration argType = ParameterBindType::BindByVariable)
|
||||
: BaseShaderParameter(argType, ParameterMetaType::FixedArray)
|
||||
, m_Count(argCount)
|
||||
{
|
||||
m_Value = new float[m_Count];
|
||||
::CopyMemory(m_Value, af_Value_, sizeof(float) * m_Count);
|
||||
}
|
||||
FloatShaderParameter(float* af_Value_, ParameterBindType::Enumeration argType = ParameterBindType::BindByVariable)
|
||||
: BaseShaderParameter(argType, ParameterMetaType::Dynamic)
|
||||
, m_Value(af_Value_)
|
||||
{
|
||||
}
|
||||
FloatShaderParameter(float** af_Value__, uint32 argCount, ParameterBindType::Enumeration argType = ParameterBindType::BindByVariable)
|
||||
: BaseShaderParameter(argType, ParameterMetaType::DynamicArray)
|
||||
, m_Value(*af_Value__)
|
||||
, m_Count(argCount)
|
||||
{}
|
||||
|
||||
virtual ~FloatShaderParameter()
|
||||
{
|
||||
if (m_Type == ParameterMetaType::FixedArray)
|
||||
delete [] m_Value;
|
||||
if (m_Type == ParameterMetaType::Fixed)
|
||||
delete m_Value;
|
||||
}
|
||||
|
||||
virtual void ApplyValue(ID3D10EffectVariable& argTargetVariable)
|
||||
{
|
||||
ID3D10EffectScalarVariable* scalar = argTargetVariable.AsScalar();
|
||||
if (scalar != NULL)
|
||||
{
|
||||
switch (m_Type)
|
||||
{
|
||||
case ParameterMetaType::Fixed:
|
||||
case ParameterMetaType::Dynamic:
|
||||
scalar->SetFloat(*m_Value);
|
||||
break;
|
||||
default:
|
||||
scalar->SetFloatArray(m_Value, 0, m_Count);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private:
|
||||
float* m_Value;
|
||||
uint32 m_Count;
|
||||
};
|
||||
|
||||
|
||||
class Float3ShaderParameter
|
||||
: public BaseShaderParameter
|
||||
{
|
||||
public:
|
||||
Float3ShaderParameter(const D3DXVECTOR3& argValue, ParameterBindType::Enumeration argType = ParameterBindType::BindByVariable)
|
||||
: BaseShaderParameter(argType, ParameterMetaType::Fixed)
|
||||
{
|
||||
m_Value = new D3DXVECTOR3(argValue);
|
||||
}
|
||||
|
||||
Float3ShaderParameter(const D3DXVECTOR3* ar_Value_, uint32 argCount, ParameterBindType::Enumeration argType = ParameterBindType::BindByVariable)
|
||||
: BaseShaderParameter(argType, ParameterMetaType::FixedArray)
|
||||
, m_Count(argCount)
|
||||
{
|
||||
m_Value = new D3DXVECTOR3[m_Count];
|
||||
::CopyMemory(m_Value, ar_Value_, sizeof(D3DXVECTOR3) * m_Count);
|
||||
}
|
||||
Float3ShaderParameter(D3DXVECTOR3* ar_Value_, ParameterBindType::Enumeration argType = ParameterBindType::BindByVariable)
|
||||
: BaseShaderParameter(argType, ParameterMetaType::Dynamic)
|
||||
, m_Value(ar_Value_)
|
||||
{
|
||||
}
|
||||
Float3ShaderParameter(D3DXVECTOR3** ar_Value__, uint32 argCount, ParameterBindType::Enumeration argType = ParameterBindType::BindByVariable)
|
||||
: BaseShaderParameter(argType, ParameterMetaType::DynamicArray)
|
||||
, m_Value(*ar_Value__)
|
||||
, m_Count(argCount)
|
||||
{}
|
||||
|
||||
virtual ~Float3ShaderParameter()
|
||||
{
|
||||
if (m_Type == ParameterMetaType::FixedArray)
|
||||
delete [] m_Value;
|
||||
if (m_Type == ParameterMetaType::Fixed)
|
||||
delete m_Value;
|
||||
}
|
||||
|
||||
virtual void ApplyValue(ID3D10EffectVariable& argTargetVariable)
|
||||
{
|
||||
ID3D10EffectVectorVariable* vector = argTargetVariable.AsVector();
|
||||
if (vector != NULL)
|
||||
{
|
||||
switch (m_Type)
|
||||
{
|
||||
case ParameterMetaType::Fixed:
|
||||
case ParameterMetaType::Dynamic:
|
||||
vector->SetRawValue((void*)m_Value, 0, sizeof(D3DXVECTOR3));
|
||||
break;
|
||||
default:
|
||||
vector->SetRawValue((void*)m_Value, 0, sizeof(D3DXVECTOR3) * m_Count);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private:
|
||||
D3DXVECTOR3* m_Value;
|
||||
uint32 m_Count;
|
||||
};
|
||||
|
||||
|
||||
class Float4ShaderParameter
|
||||
: public BaseShaderParameter
|
||||
{
|
||||
public:
|
||||
Float4ShaderParameter(const D3DXVECTOR4& argValue, ParameterBindType::Enumeration argType = ParameterBindType::BindByVariable)
|
||||
: BaseShaderParameter(argType, ParameterMetaType::Fixed)
|
||||
{
|
||||
m_Value = new D3DXVECTOR4(argValue);
|
||||
}
|
||||
|
||||
Float4ShaderParameter(const D3DXVECTOR4* ar_Value_, uint32 argCount, ParameterBindType::Enumeration argType = ParameterBindType::BindByVariable)
|
||||
: BaseShaderParameter(argType, ParameterMetaType::FixedArray)
|
||||
, m_Count(argCount)
|
||||
{
|
||||
m_Value = new D3DXVECTOR4[m_Count];
|
||||
::CopyMemory(m_Value, ar_Value_, sizeof(D3DXVECTOR4) * m_Count);
|
||||
}
|
||||
Float4ShaderParameter(D3DXVECTOR4* ar_Value_, ParameterBindType::Enumeration argType = ParameterBindType::BindByVariable)
|
||||
: BaseShaderParameter(argType, ParameterMetaType::Dynamic)
|
||||
, m_Value(ar_Value_)
|
||||
{
|
||||
}
|
||||
Float4ShaderParameter(D3DXVECTOR4** ar_Value__, uint32 argCount, ParameterBindType::Enumeration argType = ParameterBindType::BindByVariable)
|
||||
: BaseShaderParameter(argType, ParameterMetaType::DynamicArray)
|
||||
, m_Value(*ar_Value__)
|
||||
, m_Count(argCount)
|
||||
{}
|
||||
|
||||
virtual ~Float4ShaderParameter()
|
||||
{
|
||||
if (m_Type == ParameterMetaType::FixedArray)
|
||||
delete [] m_Value;
|
||||
if (m_Type == ParameterMetaType::Fixed)
|
||||
delete m_Value;
|
||||
}
|
||||
|
||||
virtual void ApplyValue(ID3D10EffectVariable& argTargetVariable)
|
||||
{
|
||||
ID3D10EffectVectorVariable* vector = argTargetVariable.AsVector();
|
||||
if (vector != NULL)
|
||||
{
|
||||
switch (m_Type)
|
||||
{
|
||||
case ParameterMetaType::Fixed:
|
||||
case ParameterMetaType::Dynamic:
|
||||
vector->SetFloatVector((float*)m_Value);
|
||||
break;
|
||||
default:
|
||||
vector->SetFloatVectorArray((float*)m_Value, 0, m_Count);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private:
|
||||
D3DXVECTOR4* m_Value;
|
||||
uint32 m_Count;
|
||||
};
|
||||
@@ -0,0 +1,61 @@
|
||||
#pragma once
|
||||
#include "BaseType.h"
|
||||
|
||||
|
||||
class IntShaderParameter
|
||||
: public BaseShaderParameter
|
||||
{
|
||||
public:
|
||||
IntShaderParameter(int argValue, ParameterBindType::Enumeration argType = ParameterBindType::BindByVariable)
|
||||
: BaseShaderParameter(argType, ParameterMetaType::Fixed)
|
||||
{
|
||||
m_Value = new int(argValue);
|
||||
}
|
||||
|
||||
IntShaderParameter(const int* af_Value_, uint32 argCount, ParameterBindType::Enumeration argType = ParameterBindType::BindByVariable)
|
||||
: BaseShaderParameter(argType, ParameterMetaType::FixedArray)
|
||||
, m_Count(argCount)
|
||||
{
|
||||
m_Value = new int[m_Count];
|
||||
::CopyMemory(m_Value, af_Value_, sizeof(int) * m_Count);
|
||||
}
|
||||
IntShaderParameter(int* af_Value_, ParameterBindType::Enumeration argType = ParameterBindType::BindByVariable)
|
||||
: BaseShaderParameter(argType, ParameterMetaType::Dynamic)
|
||||
, m_Value(af_Value_)
|
||||
{
|
||||
}
|
||||
IntShaderParameter(int** af_Value__, uint32 argCount, ParameterBindType::Enumeration argType = ParameterBindType::BindByVariable)
|
||||
: BaseShaderParameter(argType, ParameterMetaType::DynamicArray)
|
||||
, m_Value(*af_Value__)
|
||||
, m_Count(argCount)
|
||||
{}
|
||||
|
||||
virtual ~IntShaderParameter()
|
||||
{
|
||||
if (m_Type == ParameterMetaType::FixedArray)
|
||||
delete [] m_Value;
|
||||
if (m_Type == ParameterMetaType::Fixed)
|
||||
delete m_Value;
|
||||
}
|
||||
|
||||
virtual void ApplyValue(ID3D10EffectVariable& argTargetVariable)
|
||||
{
|
||||
ID3D10EffectScalarVariable* scalar = argTargetVariable.AsScalar();
|
||||
if (scalar != NULL)
|
||||
{
|
||||
switch (m_Type)
|
||||
{
|
||||
case ParameterMetaType::Fixed:
|
||||
case ParameterMetaType::Dynamic:
|
||||
scalar->SetInt(*m_Value);
|
||||
break;
|
||||
default:
|
||||
scalar->SetIntArray(m_Value, 0, m_Count);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private:
|
||||
int* m_Value;
|
||||
uint32 m_Count;
|
||||
};
|
||||
Some files were not shown because too many files have changed in this diff Show More
Reference in New Issue
Block a user