Commit 551cc463 authored by chili's avatar chili
Browse files

refactoring tentative

parent ffdeae8c
#pragma once
#include "TestObject.h"
class SkinnedBox : public TestObject<SkinnedBox>
{
public:
SkinnedBox( Graphics& gfx,std::mt19937& rng,
std::uniform_real_distribution<float>& adist,
std::uniform_real_distribution<float>& ddist,
std::uniform_real_distribution<float>& odist,
std::uniform_real_distribution<float>& rdist );
};
\ No newline at end of file
#include "SolidSphere.h"
#include "BindableBase.h"
#include "BindableCommon.h"
#include "GraphicsThrowMacros.h"
#include "Sphere.h"
SolidSphere::SolidSphere( Graphics& gfx,float radius )
{
using namespace Bind;
namespace dx = DirectX;
if( !IsStaticInitialized() )
......
......@@ -62,7 +62,7 @@ void Surface::Clear( Color fillValue ) noexcept
memset( pBuffer.get(),fillValue.dword,width * height * sizeof( Color ) );
}
void Surface::PutPixel( unsigned int x,unsigned int y,Color c ) noexcept(!IS_DEBUG)
void Surface::PutPixel( unsigned int x,unsigned int y,Color c ) noxnd
{
assert( x >= 0 );
assert( y >= 0 );
......@@ -71,7 +71,7 @@ void Surface::PutPixel( unsigned int x,unsigned int y,Color c ) noexcept(!IS_DEB
pBuffer[y * width + x] = c;
}
Surface::Color Surface::GetPixel( unsigned int x,unsigned int y ) const noexcept(!IS_DEBUG)
Surface::Color Surface::GetPixel( unsigned int x,unsigned int y ) const noxnd
{
assert( x >= 0 );
assert( y >= 0 );
......@@ -203,7 +203,7 @@ void Surface::Save( const std::string& filename ) const
}
}
void Surface::Copy( const Surface& src ) noexcept(!IS_DEBUG)
void Surface::Copy( const Surface& src ) noxnd
{
assert( width == src.width );
assert( height == src.height );
......
......@@ -24,6 +24,7 @@
#include <string>
#include <assert.h>
#include <memory>
#include "ConditionalNoexcept.h"
class Surface
......@@ -121,8 +122,8 @@ public:
Surface& operator=( const Surface& ) = delete;
~Surface();
void Clear( Color fillValue ) noexcept;
void PutPixel( unsigned int x,unsigned int y,Color c ) noexcept(!IS_DEBUG);
Color GetPixel( unsigned int x,unsigned int y ) const noexcept(!IS_DEBUG);
void PutPixel( unsigned int x,unsigned int y,Color c ) noxnd;
Color GetPixel( unsigned int x,unsigned int y ) const noxnd;
unsigned int GetWidth() const noexcept;
unsigned int GetHeight() const noexcept;
Color* GetBufferPtr() noexcept;
......@@ -130,7 +131,7 @@ public:
const Color* GetBufferPtrConst() const noexcept;
static Surface FromFile( const std::string& name );
void Save( const std::string& filename ) const;
void Copy( const Surface& src ) noexcept(!IS_DEBUG);
void Copy( const Surface& src ) noxnd;
private:
Surface( unsigned int width,unsigned int height,std::unique_ptr<Color[]> pBufferParam ) noexcept;
private:
......
......@@ -2,10 +2,12 @@
#include "Surface.h"
#include "GraphicsThrowMacros.h"
namespace wrl = Microsoft::WRL;
Texture::Texture( Graphics& gfx,const Surface& s )
namespace Bind
{
namespace wrl = Microsoft::WRL;
Texture::Texture( Graphics& gfx,const Surface& s )
{
INFOMAN( gfx );
// create texture resource
......@@ -38,9 +40,10 @@ Texture::Texture( Graphics& gfx,const Surface& s )
GFX_THROW_INFO( GetDevice( gfx )->CreateShaderResourceView(
pTexture.Get(),&srvDesc,&pTextureView
) );
}
}
void Texture::Bind( Graphics& gfx ) noexcept
{
void Texture::Bind( Graphics& gfx ) noexcept
{
GetContext( gfx )->PSSetShaderResources( 0u,1u,pTextureView.GetAddressOf() );
}
}
#pragma once
#include "Bindable.h"
class Texture : public Bindable
class Surface;
namespace Bind
{
public:
Texture( Graphics& gfx,const class Surface& s );
class Texture : public Bindable
{
public:
Texture( Graphics& gfx,const Surface& s );
void Bind( Graphics& gfx ) noexcept override;
protected:
protected:
Microsoft::WRL::ComPtr<ID3D11ShaderResourceView> pTextureView;
};
};
}
Texture2D tex;
SamplerState splr;
float4 main( float2 tc : TexCoord ) : SV_Target
{
return tex.Sample( splr,tc );
}
\ No newline at end of file
cbuffer CBuf
{
matrix transform;
};
struct VSOut
{
float2 tex : TexCoord;
float4 pos : SV_Position;
};
VSOut main( float3 pos : Position,float2 tex : TexCoord )
{
VSOut vso;
vso.pos = mul( float4(pos,1.0f),transform );
vso.tex = tex;
return vso;
}
\ No newline at end of file
cbuffer LightCBuf
{
float3 lightPos;
float3 ambient;
float3 diffuseColor;
float diffuseIntensity;
float attConst;
float attLin;
float attQuad;
};
cbuffer ObjectCBuf
{
float specularIntensity;
float specularPower;
float padding[2];
};
Texture2D tex;
SamplerState splr;
float4 main( float3 worldPos : Position,float3 n : Normal,float2 tc : Texcoord ) : SV_Target
{
// fragment to light vector data
const float3 vToL = lightPos - worldPos;
const float distToL = length( vToL );
const float3 dirToL = vToL / distToL;
// attenuation
const float att = 1.0f / (attConst + attLin * distToL + attQuad * (distToL * distToL));
// diffuse intensity
const float3 diffuse = diffuseColor * diffuseIntensity * att * max( 0.0f,dot( dirToL,n ) );
// reflected light vector
const float3 w = n * dot( vToL,n );
const float3 r = w * 2.0f - vToL;
// calculate specular intensity based on angle between viewing vector and reflection vector, narrow with power function
const float3 specular = att * (diffuseColor * diffuseIntensity) * specularIntensity * pow( max( 0.0f,dot( normalize( -r ),normalize( worldPos ) ) ),specularPower );
// final color
return float4(saturate(diffuse + ambient + specular), 1.0f) * tex.Sample(splr, tc);
}
\ No newline at end of file
cbuffer CBuf
{
matrix modelView;
matrix modelViewProj;
};
struct VSOut
{
float3 worldPos : Position;
float3 normal : Normal;
float2 tc : Texcoord;
float4 pos : SV_Position;
};
VSOut main( float3 pos : Position,float3 n : Normal,float2 tc : Texcoord )
{
VSOut vso;
vso.worldPos = (float3)mul( float4(pos,1.0f),modelView );
vso.normal = mul( n,(float3x3)modelView );
vso.pos = mul( float4(pos,1.0f),modelViewProj );
vso.tc = tc;
return vso;
}
\ No newline at end of file
#include "Topology.h"
Topology::Topology( Graphics& gfx,D3D11_PRIMITIVE_TOPOLOGY type )
namespace Bind
{
Topology::Topology( Graphics& gfx,D3D11_PRIMITIVE_TOPOLOGY type )
:
type( type )
{}
{}
void Topology::Bind( Graphics& gfx ) noexcept
{
void Topology::Bind( Graphics& gfx ) noexcept
{
GetContext( gfx )->IASetPrimitiveTopology( type );
}
}
#pragma once
#include "Bindable.h"
class Topology : public Bindable
namespace Bind
{
public:
class Topology : public Bindable
{
public:
Topology( Graphics& gfx,D3D11_PRIMITIVE_TOPOLOGY type );
void Bind( Graphics& gfx ) noexcept override;
protected:
protected:
D3D11_PRIMITIVE_TOPOLOGY type;
};
\ No newline at end of file
};
}
\ No newline at end of file
#include "TransformCbuf.h"
TransformCbuf::TransformCbuf( Graphics& gfx,const Drawable& parent,UINT slot )
namespace Bind
{
TransformCbuf::TransformCbuf( Graphics& gfx,const Drawable& parent,UINT slot )
:
parent( parent )
{
{
if( !pVcbuf )
{
pVcbuf = std::make_unique<VertexConstantBuffer<Transforms>>( gfx,slot );
}
}
}
void TransformCbuf::Bind( Graphics& gfx ) noexcept
{
void TransformCbuf::Bind( Graphics& gfx ) noexcept
{
const auto modelView = parent.GetTransformXM() * gfx.GetCamera();
const Transforms tf =
{
......@@ -23,6 +25,7 @@ void TransformCbuf::Bind( Graphics& gfx ) noexcept
};
pVcbuf->Update( gfx,tf );
pVcbuf->Bind( gfx );
}
}
std::unique_ptr<VertexConstantBuffer<TransformCbuf::Transforms>> TransformCbuf::pVcbuf;
\ No newline at end of file
std::unique_ptr<VertexConstantBuffer<TransformCbuf::Transforms>> TransformCbuf::pVcbuf;
}
\ No newline at end of file
......@@ -3,18 +3,21 @@
#include "Drawable.h"
#include <DirectXMath.h>
class TransformCbuf : public Bindable
namespace Bind
{
private:
class TransformCbuf : public Bindable
{
private:
struct Transforms
{
DirectX::XMMATRIX modelViewProj;
DirectX::XMMATRIX model;
};
public:
public:
TransformCbuf( Graphics& gfx,const Drawable& parent,UINT slot = 0u );
void Bind( Graphics& gfx ) noexcept override;
private:
private:
static std::unique_ptr<VertexConstantBuffer<Transforms>> pVcbuf;
const Drawable& parent;
};
\ No newline at end of file
};
}
\ No newline at end of file
#include "Vertex.h"
namespace Dvtx
{
// VertexLayout
const VertexLayout::Element& VertexLayout::ResolveByIndex( size_t i ) const noxnd
{
return elements[i];
}
VertexLayout& VertexLayout::Append( ElementType type ) noxnd
{
elements.emplace_back( type,Size() );
return *this;
}
size_t VertexLayout::Size() const noxnd
{
return elements.empty() ? 0u : elements.back().GetOffsetAfter();
}
size_t VertexLayout::GetElementCount() const noexcept
{
return elements.size();
}
std::vector<D3D11_INPUT_ELEMENT_DESC> VertexLayout::GetD3DLayout() const noxnd
{
std::vector<D3D11_INPUT_ELEMENT_DESC> desc;
desc.reserve( GetElementCount() );
for( const auto& e : elements )
{
desc.push_back( e.GetDesc() );
}
return desc;
}
// VertexLayout::Element
VertexLayout::Element::Element( ElementType type,size_t offset )
:
type( type ),
offset( offset )
{}
size_t VertexLayout::Element::GetOffsetAfter() const noxnd
{
return offset + Size();
}
size_t VertexLayout::Element::GetOffset() const
{
return offset;
}
size_t VertexLayout::Element::Size() const noxnd
{
return SizeOf( type );
}
constexpr size_t VertexLayout::Element::SizeOf( ElementType type ) noxnd
{
switch( type )
{
case Position2D:
return sizeof( Map<Position2D>::SysType );
case Position3D:
return sizeof( Map<Position3D>::SysType );
case Texture2D:
return sizeof( Map<Texture2D>::SysType );
case Normal:
return sizeof( Map<Normal>::SysType );
case Float3Color:
return sizeof( Map<Float3Color>::SysType );
case Float4Color:
return sizeof( Map<Float4Color>::SysType );
case BGRAColor:
return sizeof( Map<BGRAColor>::SysType );
}
assert( "Invalid element type" && false );
return 0u;
}
VertexLayout::ElementType VertexLayout::Element::GetType() const noexcept
{
return type;
}
D3D11_INPUT_ELEMENT_DESC VertexLayout::Element::GetDesc() const noxnd
{
switch( type )
{
case Position2D:
return GenerateDesc<Position2D>( GetOffset() );
case Position3D:
return GenerateDesc<Position3D>( GetOffset() );
case Texture2D:
return GenerateDesc<Texture2D>( GetOffset() );
case Normal:
return GenerateDesc<Normal>( GetOffset() );
case Float3Color:
return GenerateDesc<Float3Color>( GetOffset() );
case Float4Color:
return GenerateDesc<Float4Color>( GetOffset() );
case BGRAColor:
return GenerateDesc<BGRAColor>( GetOffset() );
}
assert( "Invalid element type" && false );
return { "INVALID",0,DXGI_FORMAT_UNKNOWN,0,0,D3D11_INPUT_PER_VERTEX_DATA,0 };
}
// Vertex
Vertex::Vertex( char* pData,const VertexLayout& layout ) noxnd
:
pData( pData ),
layout( layout )
{
assert( pData != nullptr );
}
ConstVertex::ConstVertex( const Vertex& v ) noxnd
:
vertex( v )
{}
// VertexBuffer
VertexBuffer::VertexBuffer( VertexLayout layout ) noxnd
:
layout( std::move( layout ) )
{}
const char* VertexBuffer::GetData() const noxnd
{
return buffer.data();
}
const VertexLayout& VertexBuffer::GetLayout() const noexcept
{
return layout;
}
size_t VertexBuffer::Size() const noxnd
{
return buffer.size() / layout.Size();
}
size_t VertexBuffer::SizeBytes() const noxnd
{
return buffer.size();
}
Vertex VertexBuffer::Back() noxnd
{
assert( buffer.size() != 0u );
return Vertex{ buffer.data() + buffer.size() - layout.Size(),layout };
}
Vertex VertexBuffer::Front() noxnd
{
assert( buffer.size() != 0u );
return Vertex{ buffer.data(),layout };
}
Vertex VertexBuffer::operator[]( size_t i ) noxnd
{
assert( i < Size() );
return Vertex{ buffer.data() + layout.Size() * i,layout };
}
ConstVertex VertexBuffer::Back() const noxnd
{
return const_cast<VertexBuffer*>(this)->Back();
}
ConstVertex VertexBuffer::Front() const noxnd
{
return const_cast<VertexBuffer*>(this)->Front();
}
ConstVertex VertexBuffer::operator[]( size_t i ) const noxnd
{
return const_cast<VertexBuffer&>(*this)[i];
}
}
\ No newline at end of file
......@@ -2,17 +2,11 @@
#include <vector>
#include <type_traits>
#include "Graphics.h"
#include "Color.h"
#include "ConditionalNoexcept.h"
namespace hw3dexp
namespace Dvtx
{
struct BGRAColor
{
unsigned char a;
unsigned char r;
unsigned char g;
unsigned char b;
};
class VertexLayout
{
public:
......@@ -66,7 +60,7 @@ namespace hw3dexp
};
template<> struct Map<BGRAColor>
{
using SysType = hw3dexp::BGRAColor;
using SysType = ::BGRAColor;
static constexpr DXGI_FORMAT dxgiFormat = DXGI_FORMAT_R8G8B8A8_UNORM;
static constexpr const char* semantic = "Color";
};
......@@ -74,74 +68,16 @@ namespace hw3dexp
class Element
{
public:
Element( ElementType type,size_t offset )
:
type( type ),
offset( offset )
{}
size_t GetOffsetAfter() const noexcept(!IS_DEBUG)
{
return offset + Size();
}
size_t GetOffset() const
{
return offset;
}
size_t Size() const noexcept(!IS_DEBUG)
{
return SizeOf( type );
}
static constexpr size_t SizeOf( ElementType type ) noexcept(!IS_DEBUG)
{
switch( type )
{
case Position2D:
return sizeof( Map<Position2D>::SysType );
case Position3D:
return sizeof( Map<Position3D>::SysType );
case Texture2D:
return sizeof( Map<Texture2D>::SysType );
case Normal:
return sizeof( Map<Normal>::SysType );
case Float3Color:
return sizeof( Map<Float3Color>::SysType );
case Float4Color:
return sizeof( Map<Float4Color>::SysType );
case BGRAColor:
return sizeof( Map<BGRAColor>::SysType );
}
assert( "Invalid element type" && false );
return 0u;
}
ElementType GetType() const noexcept
{
return type;
}
D3D11_INPUT_ELEMENT_DESC GetDesc() const noexcept(!IS_DEBUG)
{
switch( type )
{
case Position2D:
return GenerateDesc<Position2D>( GetOffset() );
case Position3D:
return GenerateDesc<Position3D>( GetOffset() );
case Texture2D:
return GenerateDesc<Texture2D>( GetOffset() );
case Normal:
return GenerateDesc<Normal>( GetOffset() );
case Float3Color:
return GenerateDesc<Float3Color>( GetOffset() );
case Float4Color:
return GenerateDesc<Float4Color>( GetOffset() );
case BGRAColor:
return GenerateDesc<BGRAColor>( GetOffset() );
}
assert( "Invalid element type" && false );
return { "INVALID",0,DXGI_FORMAT_UNKNOWN,0,0,D3D11_INPUT_PER_VERTEX_DATA,0 };
}
Element( ElementType type,size_t offset );
size_t GetOffsetAfter() const noxnd;
size_t GetOffset() const;
size_t Size() const noxnd;
static constexpr size_t SizeOf( ElementType type ) noxnd;
ElementType GetType() const noexcept;
D3D11_INPUT_ELEMENT_DESC GetDesc() const noxnd;
private:
template<ElementType type>
static constexpr D3D11_INPUT_ELEMENT_DESC GenerateDesc( size_t offset ) noexcept(!IS_DEBUG)
static constexpr D3D11_INPUT_ELEMENT_DESC GenerateDesc( size_t offset ) noxnd
{
return { Map<type>::semantic,0,Map<type>::dxgiFormat,0,(UINT)offset,D3D11_INPUT_PER_VERTEX_DATA,0 };
}
......@@ -151,7 +87,7 @@ namespace hw3dexp
};
public:
template<ElementType Type>
const Element& Resolve() const noexcept(!IS_DEBUG)
const Element& Resolve() const noxnd
{
for( auto& e : elements )
{
......@@ -163,33 +99,11 @@ namespace hw3dexp
assert( "Could not resolve element type" && false );
return elements.front();
}
const Element& ResolveByIndex( size_t i ) const noexcept(!IS_DEBUG)
{
return elements[i];
}
VertexLayout& Append( ElementType type ) noexcept(!IS_DEBUG)
{
elements.emplace_back( type,Size() );
return *this;
}
size_t Size() const noexcept(!IS_DEBUG)
{
return elements.empty() ? 0u : elements.back().GetOffsetAfter();
}
size_t GetElementCount() const noexcept
{
return elements.size();
}
std::vector<D3D11_INPUT_ELEMENT_DESC> GetD3DLayout() const noexcept(!IS_DEBUG)
{
std::vector<D3D11_INPUT_ELEMENT_DESC> desc;
desc.reserve( GetElementCount() );
for( const auto& e : elements )
{
desc.push_back( e.GetDesc() );
}
return desc;
}
const Element& ResolveByIndex( size_t i ) const noxnd;
VertexLayout& Append( ElementType type ) noxnd;
size_t Size() const noxnd;
size_t GetElementCount() const noexcept;
std::vector<D3D11_INPUT_ELEMENT_DESC> GetD3DLayout() const noxnd;
private:
std::vector<Element> elements;
};
......@@ -199,13 +113,13 @@ namespace hw3dexp
friend class VertexBuffer;
public:
template<VertexLayout::ElementType Type>
auto& Attr() noexcept(!IS_DEBUG)
auto& Attr() noxnd
{
auto pAttribute = pData + layout.Resolve<Type>().GetOffset();
return *reinterpret_cast<typename VertexLayout::Map<Type>::SysType*>(pAttribute);
}
template<typename T>
void SetAttributeByIndex( size_t i,T&& val ) noexcept(!IS_DEBUG)
void SetAttributeByIndex( size_t i,T&& val ) noxnd
{
const auto& element = layout.ResolveByIndex( i );
auto pAttribute = pData + element.GetOffset();
......@@ -237,24 +151,18 @@ namespace hw3dexp
}
}
protected:
Vertex( char* pData,const VertexLayout& layout ) noexcept(!IS_DEBUG)
:
pData( pData ),
layout( layout )
{
assert( pData != nullptr );
}
Vertex( char* pData,const VertexLayout& layout ) noxnd;
private:
template<typename First,typename ...Rest>
// enables parameter pack setting of multiple parameters by element index
void SetAttributeByIndex( size_t i,First&& first,Rest&&... rest ) noexcept(!IS_DEBUG)
template<typename First,typename ...Rest>
void SetAttributeByIndex( size_t i,First&& first,Rest&&... rest ) noxnd
{
SetAttributeByIndex( i,std::forward<First>( first ) );
SetAttributeByIndex( i + 1,std::forward<Rest>( rest )... );
}
// helper to reduce code duplication in SetAttributeByIndex
template<VertexLayout::ElementType DestLayoutType,typename SrcType>
void SetAttribute( char* pAttribute,SrcType&& val ) noexcept(!IS_DEBUG)
void SetAttribute( char* pAttribute,SrcType&& val ) noxnd
{
using Dest = typename VertexLayout::Map<DestLayoutType>::SysType;
if constexpr( std::is_assignable<Dest,SrcType>::value )
......@@ -274,12 +182,9 @@ namespace hw3dexp
class ConstVertex
{
public:
ConstVertex( const Vertex& v ) noexcept(!IS_DEBUG)
:
vertex( v )
{}
ConstVertex( const Vertex& v ) noxnd;
template<VertexLayout::ElementType Type>
const auto& Attr() const noexcept(!IS_DEBUG)
const auto& Attr() const noxnd
{
return const_cast<Vertex&>(vertex).Attr<Type>();
}
......@@ -290,60 +195,24 @@ namespace hw3dexp
class VertexBuffer
{
public:
VertexBuffer( VertexLayout layout ) noexcept(!IS_DEBUG)
:
layout( std::move( layout ) )
{}
const char* GetData() const noexcept(!IS_DEBUG)
{
return buffer.data();
}
const VertexLayout& GetLayout() const noexcept
{
return layout;
}
size_t Size() const noexcept(!IS_DEBUG)
{
return buffer.size() / layout.Size();
}
size_t SizeBytes() const noexcept(!IS_DEBUG)
{
return buffer.size();
}
VertexBuffer( VertexLayout layout ) noxnd;
const char* GetData() const noxnd;
const VertexLayout& GetLayout() const noexcept;
size_t Size() const noxnd;
size_t SizeBytes() const noxnd;
template<typename ...Params>
void EmplaceBack( Params&&... params ) noexcept(!IS_DEBUG)
void EmplaceBack( Params&&... params ) noxnd
{
assert( sizeof...(params) == layout.GetElementCount() && "Param count doesn't match number of vertex elements" );
buffer.resize( buffer.size() + layout.Size() );
Back().SetAttributeByIndex( 0u,std::forward<Params>( params )... );
}
Vertex Back() noexcept(!IS_DEBUG)
{
assert( buffer.size() != 0u );
return Vertex{ buffer.data() + buffer.size() - layout.Size(),layout };
}
Vertex Front() noexcept(!IS_DEBUG)
{
assert( buffer.size() != 0u );
return Vertex{ buffer.data(),layout };
}
Vertex operator[]( size_t i ) noexcept(!IS_DEBUG)
{
assert( i < Size() );
return Vertex{ buffer.data() + layout.Size() * i,layout };
}
ConstVertex Back() const noexcept(!IS_DEBUG)
{
return const_cast<VertexBuffer*>(this)->Back();
}
ConstVertex Front() const noexcept(!IS_DEBUG)
{
return const_cast<VertexBuffer*>(this)->Front();
}
ConstVertex operator[]( size_t i ) const noexcept(!IS_DEBUG)
{
return const_cast<VertexBuffer&>(*this)[i];
}
Vertex Back() noxnd;
Vertex Front() noxnd;
Vertex operator[]( size_t i ) noxnd;
ConstVertex Back() const noxnd;
ConstVertex Front() const noxnd;
ConstVertex operator[]( size_t i ) const noxnd;
private:
std::vector<char> buffer;
VertexLayout layout;
......
#include "VertexBuffer.h"
void VertexBuffer::Bind( Graphics& gfx ) noexcept
namespace Bind
{
VertexBuffer::VertexBuffer( Graphics& gfx,const Dvtx::VertexBuffer& vbuf )
:
stride( (UINT)vbuf.GetLayout().Size() )
{
INFOMAN( gfx );
D3D11_BUFFER_DESC bd = {};
bd.BindFlags = D3D11_BIND_VERTEX_BUFFER;
bd.Usage = D3D11_USAGE_DEFAULT;
bd.CPUAccessFlags = 0u;
bd.MiscFlags = 0u;
bd.ByteWidth = UINT( vbuf.SizeBytes() );
bd.StructureByteStride = stride;
D3D11_SUBRESOURCE_DATA sd = {};
sd.pSysMem = vbuf.GetData();
GFX_THROW_INFO( GetDevice( gfx )->CreateBuffer( &bd,&sd,&pVertexBuffer ) );
}
void VertexBuffer::Bind( Graphics& gfx ) noexcept
{
const UINT offset = 0u;
GetContext( gfx )->IASetVertexBuffers( 0u,1u,pVertexBuffer.GetAddressOf(),&stride,&offset );
}
}
......@@ -3,9 +3,11 @@
#include "GraphicsThrowMacros.h"
#include "Vertex.h"
class VertexBuffer : public Bindable
namespace Bind
{
public:
class VertexBuffer : public Bindable
{
public:
template<class V>
VertexBuffer( Graphics& gfx,const std::vector<V>& vertices )
:
......@@ -24,25 +26,10 @@ public:
sd.pSysMem = vertices.data();
GFX_THROW_INFO( GetDevice( gfx )->CreateBuffer( &bd,&sd,&pVertexBuffer ) );
}
VertexBuffer( Graphics& gfx,const hw3dexp::VertexBuffer& vbuf )
:
stride( (UINT)vbuf.GetLayout().Size() )
{
INFOMAN( gfx );
D3D11_BUFFER_DESC bd = {};
bd.BindFlags = D3D11_BIND_VERTEX_BUFFER;
bd.Usage = D3D11_USAGE_DEFAULT;
bd.CPUAccessFlags = 0u;
bd.MiscFlags = 0u;
bd.ByteWidth = UINT( vbuf.SizeBytes() );
bd.StructureByteStride = stride;
D3D11_SUBRESOURCE_DATA sd = {};
sd.pSysMem = vbuf.GetData();
GFX_THROW_INFO( GetDevice( gfx )->CreateBuffer( &bd,&sd,&pVertexBuffer ) );
}
VertexBuffer( Graphics& gfx,const Dvtx::VertexBuffer& vbuf );
void Bind( Graphics& gfx ) noexcept override;
protected:
protected:
UINT stride;
Microsoft::WRL::ComPtr<ID3D11Buffer> pVertexBuffer;
};
};
}
#include "VertexShader.h"
#include "GraphicsThrowMacros.h"
VertexShader::VertexShader( Graphics& gfx,const std::wstring& path )
namespace Bind
{
VertexShader::VertexShader( Graphics& gfx,const std::wstring& path )
{
INFOMAN( gfx );
GFX_THROW_INFO( D3DReadFileToBlob( path.c_str(),&pBytecodeBlob ) );
......@@ -13,14 +14,15 @@ VertexShader::VertexShader( Graphics& gfx,const std::wstring& path )
nullptr,
&pVertexShader
) );
}
}
void VertexShader::Bind( Graphics& gfx ) noexcept
{
void VertexShader::Bind( Graphics& gfx ) noexcept
{
GetContext( gfx )->VSSetShader( pVertexShader.Get(),nullptr,0u );
}
}
ID3DBlob* VertexShader::GetBytecode() const noexcept
{
ID3DBlob* VertexShader::GetBytecode() const noexcept
{
return pBytecodeBlob.Get();
}
}
#pragma once
#include "Bindable.h"
class VertexShader : public Bindable
namespace Bind
{
public:
class VertexShader : public Bindable
{
public:
VertexShader( Graphics& gfx,const std::wstring& path );
void Bind( Graphics& gfx ) noexcept override;
ID3DBlob* GetBytecode() const noexcept;
protected:
protected:
Microsoft::WRL::ComPtr<ID3DBlob> pBytecodeBlob;
Microsoft::WRL::ComPtr<ID3D11VertexShader> pVertexShader;
};
\ No newline at end of file
};
}
\ No newline at end of file
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment