port from perforce

This commit is contained in:
2026-04-18 22:31:51 +02:00
commit 8d0ab5b7cc
8409 changed files with 3972376 additions and 0 deletions

View 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;
}

View 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;
};

View File

@@ -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;
}

View File

@@ -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;
};