Commit cefa68f1 authored by Clark Lin's avatar Clark Lin
Browse files

Merge branch 'study' into 'main'

merge up to "add bindables and drawables"

See merge request !1
parents 90937151 42c3decc
#pragma once
// HRESULT hr should exist in the local scope for these macros to work
#define GFX_EXCEPT_NOINFO(hr) Graphics::HrException( __LINE__,__FILE__,(hr) )
#define GFX_THROW_NOINFO(hrcall) if( FAILED( hr = (hrcall) ) ) throw Graphics::HrException( __LINE__,__FILE__,hr )
#ifndef NDEBUG
#define GFX_EXCEPT(hr) Graphics::HrException( __LINE__,__FILE__,(hr),infoManager.GetMessages() )
#define GFX_THROW_INFO(hrcall) infoManager.Set(); if( FAILED( hr = (hrcall) ) ) throw GFX_EXCEPT(hr)
#define GFX_DEVICE_REMOVED_EXCEPT(hr) Graphics::DeviceRemovedException( __LINE__,__FILE__,(hr),infoManager.GetMessages() )
#define GFX_THROW_INFO_ONLY(call) infoManager.Set(); (call); {auto v = infoManager.GetMessages(); if(!v.empty()) {throw Graphics::InfoException( __LINE__,__FILE__,v);}}
#else
#define GFX_EXCEPT(hr) Graphics::HrException( __LINE__,__FILE__,(hr) )
#define GFX_THROW_INFO(hrcall) GFX_THROW_NOINFO(hrcall)
#define GFX_DEVICE_REMOVED_EXCEPT(hr) Graphics::DeviceRemovedException( __LINE__,__FILE__,(hr) )
#define GFX_THROW_INFO_ONLY(call) (call)
#endif
// macro for importing infomanager into local scope
// this.GetInfoManager(Graphics gfx) must exist
#ifdef NDEBUG
#define INFOMAN(gfx) HRESULT hr
#else
#define INFOMAN(gfx) HRESULT hr; DxgiInfoManager& infoManager = GetInfoManager(gfx)
#endif
#include "IndexBuffer.h"
#include "GraphicsThrowMacros.h"
IndexBuffer::IndexBuffer( Graphics& gfx,const std::vector<unsigned short>& indices )
:
count( (UINT)indices.size() )
{
INFOMAN( gfx );
D3D11_BUFFER_DESC ibd = {};
ibd.BindFlags = D3D11_BIND_INDEX_BUFFER;
ibd.Usage = D3D11_USAGE_DEFAULT;
ibd.CPUAccessFlags = 0u;
ibd.MiscFlags = 0u;
ibd.ByteWidth = UINT( count * sizeof( unsigned short ) );
ibd.StructureByteStride = sizeof( unsigned short );
D3D11_SUBRESOURCE_DATA isd = {};
isd.pSysMem = indices.data();
GFX_THROW_INFO( GetDevice( gfx )->CreateBuffer( &ibd,&isd,&pIndexBuffer ) );
}
void IndexBuffer::Bind( Graphics& gfx ) noexcept
{
GetContext( gfx )->IASetIndexBuffer( pIndexBuffer.Get(),DXGI_FORMAT_R16_UINT,0u );
}
UINT IndexBuffer::GetCount() const noexcept
{
return count;
}
#pragma once
#include "Bindable.h"
class IndexBuffer : public Bindable
{
public:
IndexBuffer( Graphics& gfx,const std::vector<unsigned short>& indices );
void Bind( Graphics& gfx ) noexcept override;
UINT GetCount() const noexcept;
protected:
UINT count;
Microsoft::WRL::ComPtr<ID3D11Buffer> pIndexBuffer;
};
\ No newline at end of file
#include "InputLayout.h"
#include "GraphicsThrowMacros.h"
InputLayout::InputLayout( Graphics& gfx,
const std::vector<D3D11_INPUT_ELEMENT_DESC>& layout,
ID3DBlob* pVertexShaderBytecode )
{
INFOMAN( gfx );
GFX_THROW_INFO( GetDevice( gfx )->CreateInputLayout(
layout.data(),(UINT)layout.size(),
pVertexShaderBytecode->GetBufferPointer(),
pVertexShaderBytecode->GetBufferSize(),
&pInputLayout
) );
}
void InputLayout::Bind( Graphics& gfx ) noexcept
{
GetContext( gfx )->IASetInputLayout( pInputLayout.Get() );
}
#pragma once
#include "Bindable.h"
class InputLayout : public Bindable
{
public:
InputLayout( Graphics& gfx,
const std::vector<D3D11_INPUT_ELEMENT_DESC>& layout,
ID3DBlob* pVertexShaderBytecode );
void Bind( Graphics& gfx ) noexcept override;
protected:
Microsoft::WRL::ComPtr<ID3D11InputLayout> pInputLayout;
};
\ No newline at end of file
/******************************************************************************************
* Chili Direct3D Engine *
* Copyright 2018 PlanetChili <http://www.planetchili.net> *
* *
* This file is part of Chili Direct3D Engine. *
* *
* Chili Direct3D Engine is free software: you can redistribute it and/or modify *
* it under the terms of the GNU General Public License as published by *
* the Free Software Foundation, either version 3 of the License, or *
* (at your option) any later version. *
* *
* The Chili Direct3D Engine is distributed in the hope that it will be useful, *
* but WITHOUT ANY WARRANTY; without even the implied warranty of *
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the *
* GNU General Public License for more details. *
* *
* You should have received a copy of the GNU General Public License *
* along with The Chili Direct3D Engine. If not, see <http://www.gnu.org/licenses/>. *
******************************************************************************************/
#include "Keyboard.h"
bool Keyboard::KeyIsPressed( unsigned char keycode ) const noexcept
{
return keystates[keycode];
}
Keyboard::Event Keyboard::ReadKey() noexcept
{
if( keybuffer.size() > 0u )
{
Keyboard::Event e = keybuffer.front();
keybuffer.pop();
return e;
}
else
{
return Keyboard::Event();
}
}
bool Keyboard::KeyIsEmpty() const noexcept
{
return keybuffer.empty();
}
char Keyboard::ReadChar() noexcept
{
if( charbuffer.size() > 0u )
{
unsigned char charcode = charbuffer.front();
charbuffer.pop();
return charcode;
}
else
{
return 0;
}
}
bool Keyboard::CharIsEmpty() const noexcept
{
return charbuffer.empty();
}
void Keyboard::FlushKey() noexcept
{
keybuffer = std::queue<Event>();
}
void Keyboard::FlushChar() noexcept
{
charbuffer = std::queue<char>();
}
void Keyboard::Flush() noexcept
{
FlushKey();
FlushChar();
}
void Keyboard::EnableAutorepeat() noexcept
{
autorepeatEnabled = true;
}
void Keyboard::DisableAutorepeat() noexcept
{
autorepeatEnabled = false;
}
bool Keyboard::AutorepeatIsEnabled() const noexcept
{
return autorepeatEnabled;
}
void Keyboard::OnKeyPressed( unsigned char keycode ) noexcept
{
keystates[keycode] = true;
keybuffer.push( Keyboard::Event( Keyboard::Event::Type::Press,keycode ) );
TrimBuffer( keybuffer );
}
void Keyboard::OnKeyReleased( unsigned char keycode ) noexcept
{
keystates[keycode] = false;
keybuffer.push( Keyboard::Event( Keyboard::Event::Type::Release,keycode ) );
TrimBuffer( keybuffer );
}
void Keyboard::OnChar( char character ) noexcept
{
charbuffer.push( character );
TrimBuffer( charbuffer );
}
void Keyboard::ClearState() noexcept
{
keystates.reset();
}
template<typename T>
void Keyboard::TrimBuffer( std::queue<T>& buffer ) noexcept
{
while( buffer.size() > bufferSize )
{
buffer.pop();
}
}
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
#include "PixelShader.h"
#include "GraphicsThrowMacros.h"
PixelShader::PixelShader( Graphics& gfx,const std::wstring& path )
{
INFOMAN( gfx );
Microsoft::WRL::ComPtr<ID3DBlob> pBlob;
GFX_THROW_INFO( D3DReadFileToBlob( path.c_str(),&pBlob ) );
GFX_THROW_INFO( GetDevice( gfx )->CreatePixelShader( pBlob->GetBufferPointer(),pBlob->GetBufferSize(),nullptr,&pPixelShader ) );
}
void PixelShader::Bind( Graphics& gfx ) noexcept
{
GetContext( gfx )->PSSetShader( pPixelShader.Get(),nullptr,0u );
}
#pragma once
#include "Bindable.h"
class PixelShader : public Bindable
{
public:
PixelShader( Graphics& gfx,const std::wstring& path );
void Bind( Graphics& gfx ) noexcept override;
protected:
Microsoft::WRL::ComPtr<ID3D11PixelShader> pPixelShader;
};
\ No newline at end of file
cbuffer CBuf
{
float4 face_color[6];
};
//float4 main( float3 color : Color) : SV_Target
float4 main(uint tid: SV_PrimitiveID) : SV_Target
{
//return float4(color, 1.0f);
return face_color[tid/2];
}
\ No newline at end of file
B// Microsoft Visual C++ generated resource script.
This diff is collapsed.
This diff is collapsed.
#include "Topology.h"
Topology::Topology( Graphics& gfx,D3D11_PRIMITIVE_TOPOLOGY type )
:
type( type )
{}
void Topology::Bind( Graphics& gfx ) noexcept
{
GetContext( gfx )->IASetPrimitiveTopology( type );
}
#pragma once
#include "Bindable.h"
class Topology : public Bindable
{
public:
Topology( Graphics& gfx,D3D11_PRIMITIVE_TOPOLOGY type );
void Bind( Graphics& gfx ) noexcept override;
protected:
D3D11_PRIMITIVE_TOPOLOGY type;
};
\ No newline at end of file
#include "TransformCbuf.h"
TransformCbuf::TransformCbuf( Graphics& gfx,const Drawable& parent )
:
vcbuf( gfx ),
parent( parent )
{}
void TransformCbuf::Bind( Graphics& gfx ) noexcept
{
vcbuf.Update( gfx,
DirectX::XMMatrixTranspose(
parent.GetTransformXM() * gfx.GetProjection()
)
);
vcbuf.Bind( gfx );
}
#pragma once
#include "ConstantBuffers.h"
#include "Drawable.h"
#include <DirectXMath.h>
class TransformCbuf : public Bindable
{
public:
TransformCbuf( Graphics& gfx,const Drawable& parent );
void Bind( Graphics& gfx ) noexcept override;
private:
VertexConstantBuffer<DirectX::XMMATRIX> vcbuf;
const Drawable& parent;
};
\ 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