Skip to content

Commit

Permalink
Merge branch 'master' into Rendering (everything compiles but not work)
Browse files Browse the repository at this point in the history
  • Loading branch information
nieznanysprawiciel committed Oct 11, 2019
1 parent c8dfdf0 commit ef36f28
Show file tree
Hide file tree
Showing 335 changed files with 33,636 additions and 3,136 deletions.
2 changes: 2 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
*.suo
*.user
*.sln.docstates
.vs

# Build results

Expand All @@ -17,6 +18,7 @@ build/
BuildDir/
LibDir/
ProjectDir/Documentation/
ProjectsDir/Output/



Expand Down
76 changes: 76 additions & 0 deletions Assets/MaterialAsset/MaterialAsset.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,76 @@
/**
@file MaterialAsset.cpp
@author nieznanysprawiciel
@copyright File is part of Sleeping Wombat Libraries.
*/

#include "swGraphicAPI/Assets/MaterialAsset/stdafx.h"

#include "MaterialAsset.h"



RTTR_REGISTRATION
{
rttr::registration::class_< std::vector< sw::ParametricBufferInfo > >( "ParametricBuffers" );

rttr::registration::class_< sw::ParametricBufferInfo >( "ParametricBufferInfo" )
.property( "ShaderType", &sw::ParametricBufferInfo::ShaderType )
.property( "BufferSize", &sw::ParametricBufferInfo::BufferSize )
.property( "BufferType", &sw::ParametricBufferInfo::GetBufferType, &sw::ParametricBufferInfo::SetBufferType );

rttr::registration::class_< sw::MaterialInfo >( "MaterialInfo" )
.property( "ParametricBuffers", &sw::MaterialInfo::ParametricBuffers )
.property( "ShadingData", &sw::MaterialInfo::ShadingData );

rttr::registration::class_< sw::MaterialAsset >( "MaterialAsset" )
.property( "VertexShader", &sw::MaterialAsset::m_vertexShader )
.property( "PixelShader", &sw::MaterialAsset::m_pixelShader )
.property( "GeometryShader", &sw::MaterialAsset::m_geometryShader )
.property( "TesselationControlShader", &sw::MaterialAsset::m_controlShader )
.property( "TesselationEvaluationShader", &sw::MaterialAsset::m_evaluationShader )
.property_readonly( "DiffuseTexture", &sw::MaterialAsset::GetTexture1 )
.property_readonly( "SpecularTexture", &sw::MaterialAsset::GetTexture2 )
.property_readonly( "AmbientTexture", &sw::MaterialAsset::GetTexture3 )
.property_readonly( "NormalMap", &sw::MaterialAsset::GetTexture4 )
.property_readonly( "DisplacementMap", &sw::MaterialAsset::GetTexture5 )
.property_readonly( "Texture6", &sw::MaterialAsset::GetTexture6 )
.property_readonly( "Texture7", &sw::MaterialAsset::GetTexture7 )
.property_readonly( "Texture8", &sw::MaterialAsset::GetTexture8 )
//.property( "Textures", &MaterialAsset::m_textures )
.property( "Descriptor", &sw::MaterialAsset::m_descriptor ) BIND_AS_PTR;

}


namespace sw
{


// ================================ //
//
MaterialAsset::MaterialAsset ( AssetPath path, MaterialInitData&& initData )
: Resource( std::move( path ) )
, m_materialBuffer( std::move( initData.MaterialBuffer ) )
, m_vertexShader( std::move( initData.VertexShader ) )
, m_pixelShader( std::move( initData.PixelShader ) )
, m_geometryShader( std::move( initData.GeometryShader ) )
, m_evaluationShader( std::move( initData.TesselationEvaluationShader ) )
, m_controlShader( std::move( initData.TesselationControlShader ) )
, m_descriptor( std::move( initData.AdditionalBuffers ), std::move( initData.ShadingData ) )
{
for( int i = 0; i < MAX_MATERIAL_TEXTURES; ++i )
{
m_textures[ i ] = std::move( initData.Textures[ i ] );
}
}

// ================================ //
//
MaterialAsset::~MaterialAsset ()
{}



} // sw

106 changes: 106 additions & 0 deletions Assets/MaterialAsset/MaterialAsset.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,106 @@
#pragma once
/**
@file MaterialAsset.h
@author nieznanysprawiciel
@copyright File is part of Sleeping Wombat Libraries.
*/



#include "swGraphicAPI/Resources/Textures/Texture.h"
#include "swGraphicAPI/Resources/Buffers/Buffer.h"

#include "ShadingModelData.h"
#include "MaterialAssetInitData.h"
#include "MaterialInfo.h"

#include <vector>


namespace sw
{


/**@defgroup Assets Assets
@brief High level engine resources.
*/


/**@defgroup Materials Materials
@brief Classes describing materials.
Class @ref MaterialAsset is main material class used by engine.
@ingroup Assets
*/




/**@brief Class describes Material.
Material consists of shaders that will be used to render scene element.
Only VertexShader and PixelShader fileds are necessary. GeometryShader will be used
only if it is set. Tesselation will be tuned on if both ControlsShader and EvaluationShader
will be present.
Material has it's own buffer with shading parameters. It will be initialized with ShadingData
from MaterialInfo structure. There's only single Buffer per material instance. We can parametrize
Material by binding to shaders additional buffers with different parameters per scene entity.
To do this we should fill @ref MaterialInfo::ParametricBuffers field.
@ingroup Assets
@ingroup Materials
*/
class MaterialAsset : public Resource
{
RTTR_ENABLE( Resource );
RTTR_REGISTRATION_FRIEND;
private:

BufferPtr m_materialBuffer; ///< GPU buffer containing material data.
VertexShaderPtr m_vertexShader; ///< Vertex shader.
PixelShaderPtr m_pixelShader; ///< Pixel shader.
TexturePtr m_textures[ MAX_MATERIAL_TEXTURES ]; ///< Textures set.

GeometryShaderPtr m_geometryShader; ///< [Optional] Geometry shader.
ControlShaderPtr m_controlShader; ///< [Optional] Shader invoked before tesselation.
EvaluationShaderPtr m_evaluationShader; ///< [Optional] Shader invoked after tesselation.


MaterialInfo m_descriptor; ///< Material descriptor.

public:
explicit MaterialAsset ( AssetPath filePath, MaterialInitData&& initData );

public:

const BufferPtr& GetMaterialBuffer () const { return m_materialBuffer; }
const VertexShaderPtr& GetVertexShader () const { return m_vertexShader; }
const PixelShaderPtr& GetPixelShader () const { return m_pixelShader; }
const GeometryShaderPtr& GetGeometryShader () const { return m_geometryShader; }
const ControlShaderPtr& GetTessControlShader () const { return m_controlShader; }
const EvaluationShaderPtr& GetTessEvaluationShader () const { return m_evaluationShader; }

const TexturePtr& GetTexture ( int index ) const { return m_textures[ index ]; }
const MaterialInfo& GetDescriptor () const { return m_descriptor; }

private:
~MaterialAsset();

// Temporary textures getters for properties.
Texture* GetTexture1() const { return m_textures[ 0 ].Ptr(); }
Texture* GetTexture2() const { return m_textures[ 1 ].Ptr(); }
Texture* GetTexture3() const { return m_textures[ 2 ].Ptr(); }
Texture* GetTexture4() const { return m_textures[ 3 ].Ptr(); }
Texture* GetTexture5() const { return m_textures[ 4 ].Ptr(); }
Texture* GetTexture6() const { return m_textures[ 5 ].Ptr(); }
Texture* GetTexture7() const { return m_textures[ 6 ].Ptr(); }
Texture* GetTexture8() const { return m_textures[ 7 ].Ptr(); }
};

DEFINE_RESOURCE_PTR_TYPE( MaterialAsset );

} // sw
58 changes: 58 additions & 0 deletions Assets/MaterialAsset/MaterialAssetInitData.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,58 @@
/**
@file MaterialAssetInitData.cpp
@author nieznanysprawiciel
@copyright File is part of Sleeping Wombat Libraries.
*/
#include "swGraphicAPI/Assets/MaterialAsset/stdafx.h"


#include "MaterialAssetInitData.h"
#include "swGraphicAPI/Assets/MaterialAsset/MaterialAsset.h"

#include "swGraphicAPI/ResourceManager/ResourceManager.h"
#include "swGraphicAPI/ResourceManager/ResourceManagerAPI.h"



namespace sw
{

// ================================ //
//
ReturnResult MaterialInitData::AutoCreateBuffer ( const AssetPath& materialName, RMLoaderAPI& rmAPI )
{
if( ShadingData.get() != nullptr )
{
BufferRange bufferInfo( ShadingData->GetData(), ShadingData->GetSize() );

auto result = rmAPI.CreateConstantsBuffer( DefaultBufferName( materialName ),
bufferInfo,
(uint32)ShadingData->GetSize(),
ShadingData->GetShadingModelType() );

if( result.IsValid() )
{
this->MaterialBuffer = result.Get();
return Result::Success;
}
else
{
return result.GetError();
}
}
else
{
return "MaterialInitData.ShadingData was nullptr. Set ShadingModel struct before creating buffer.";
}
}

// ================================ //
//
AssetPath MaterialInitData::DefaultBufferName ( const AssetPath& materialName ) const
{
return AssetPath( materialName.GetFile(), materialName.GetInternalPath() / "buffer" );
}


} // sw

66 changes: 66 additions & 0 deletions Assets/MaterialAsset/MaterialAssetInitData.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,66 @@
#pragma once
/**
@file MaterialAssetInitData.h
@author nieznanysprawiciel
@copyright File is part of Sleeping Wombat Libraries.
*/


#include "swCommonLib/Common/TypesDefinitions.h"

#include "swGraphicAPI/Resources/MeshResources.h"
#include "swGraphicAPI/ResourceManager/AssetCreators/IAssetCreateInfo.h"

#include "ShadingModelData.h"
#include "MaterialInfo.h"

#include <vector>


namespace sw
{

class MaterialAsset;
class ResourceManager;


/**@brief Struct contains data needed to initialize material.
@ingroup Materials*/
struct MaterialInitData : public IAssetCreateInfo
{
RTTR_ENABLE( IAssetCreateInfo );
public:
BufferPtr MaterialBuffer;
VertexShaderPtr VertexShader;
PixelShaderPtr PixelShader;
GeometryShaderPtr GeometryShader;
ControlShaderPtr TesselationControlShader;
EvaluationShaderPtr TesselationEvaluationShader;
TexturePtr Textures[ MAX_MATERIAL_TEXTURES ];

std::vector< ParametricBufferInfo > AdditionalBuffers; ///< Additional buffers which should be provided by scene entity.
UPtr< ShadingModelBase > ShadingData; ///< Initializes buffer with shading model data. @see ShadingModelData

public:

// ================================ //
//
MaterialInitData () {}

public:

/**@brief Creates buffer using ShadingData.*/
ReturnResult AutoCreateBuffer ( const AssetPath& materialName, RMLoaderAPI& rm );
AssetPath DefaultBufferName ( const AssetPath& materialName ) const;

public:
// ================================ //
//
virtual TypeID GetAssetType () const override { return TypeID::get< MaterialAsset >(); }
};




} // sw

Loading

0 comments on commit ef36f28

Please sign in to comment.