{
namespace graphics
{
- ///////////////////////////////////////////////////////////////////////////
+ ///////////////////////////////////////////////////////////////////////////////////////////////////////////////
- class shader_device
+ class pass
{
public:
enum exception_codes
{
- exception_codes__head = exception_code_root::shader,
-
- buffer__CreateBuffer_Failed,
- get_pass_Failed,
- get_technique_Failed
+ exception_codes__head = exception_code_root::pass,
+ get_desc__GetDesc_Failed
};
protected:
- device& m_dev;
-
+ d3dpass* m_if;
+ mutable D3D10_PASS_DESC m_desc;
+ mutable bool m_desc_got;
public:
- shader_device(device &d) : m_dev(d)
- {
+ pass(d3dpass* pass_in) : m_if(pass_in){
+ //::ZeroMemory(&m_desc,sizeof(m_desc));
+ m_desc_got = false;
}
-
- ///////////////
-
- template <typename VERTEX_TYPE>
- void set_vertex_buffer(const input_vertex_buffer<VERTEX_TYPE> &vb)// const OK...?
- {
- typename const input_vertex_buffer<VERTEX_TYPE>::_IfType *buffer_ptr = vb.get_buffer_ptr();
- UINT stride = sizeof(VERTEX_TYPE);
- UINT offset = 0;
- m_dev.get_d3ddevice_ptr()->IASetVertexBuffers( 0, 1, (ID3D10Buffer *const *)&buffer_ptr, &stride, &offset );
- }
-
- void set_primitive_topology(::D3D10_PRIMITIVE_TOPOLOGY topology)
+
+ // Get Desc
+ const D3D10_PASS_DESC& get_desc() const
{
- m_dev.get_d3ddevice_ptr()->IASetPrimitiveTopology(topology);
- }
-
- void draw(UINT vertex_count, UINT vertex_offset=0)
- {
- m_dev.get_d3ddevice_ptr()->Draw(vertex_count, vertex_offset);
- }
-
- void draw_primitive(::D3D10_PRIMITIVE_TOPOLOGY topology, UINT vertex_count, UINT vertex_offset=0)
- {
- set_primitive_topology(topology);
- draw(vertex_count, vertex_offset);
+ if ( !m_desc_got )
+ {
+ HRESULT hr = m_if->GetDesc(&m_desc);
+ if ( hr != D3D_OK ){
+ throw api_error(get_desc__GetDesc_Failed,
+ "ID3D10EffectPass::GetDesc() Failed.", hr);
+ }
+ m_desc_got = true;
+ }
+ return m_desc;
}
};
- typedef shader_device render_device, renderer;
-
- ///////////////////////////////////////////////////////////////////////////////////////////////////////////////
-
- class pass
- {
- protected:
- d3dpass* m_if;
- public:
- pass(d3dpass* pass_in) : m_if(pass_in){}
- };
///////////////////////////////////////////////////////////////////////////////////////////////////////////////
}
};
+
+ ///////////////////////////////////////////////////////////////////////////////////
+
+ class shader_device
+ {
+ public:
+ enum exception_codes
+ {
+ exception_codes__head = exception_code_root::shader,
+
+ buffer__CreateBuffer_Failed,
+ setup_input_layout__CreateInputLayout_Failed,
+ get_pass_Failed,
+ get_technique_Failed
+ };
+ protected:
+ device& m_dev;
+
+ public:
+ shader_device(device &d) : m_dev(d)
+ {
+ }
+
+ ///////////////////////////////////////////////////////
+
+ template <typename VERTEX_TYPE>
+ void set_vertex_buffer(const input_vertex_buffer<VERTEX_TYPE> &vb)// const OK...?
+ {
+ typename const input_vertex_buffer<VERTEX_TYPE>::_IfType *buffer_ptr = vb.get_buffer_ptr();
+ UINT stride = sizeof(VERTEX_TYPE);
+ UINT offset = 0;
+ m_dev.get_d3ddevice_ptr()->IASetVertexBuffers( 0, 1, (ID3D10Buffer *const *)&buffer_ptr, &stride, &offset );
+ }
+
+ ///////
+
+ template <typename VERTEX_TYPE>
+ void setup_input_layout(const ::D3D10_INPUT_ELEMENT_DESC *input_desc, int num_elements, const pass &pss)
+ {
+ ::ID3D10InputLayout* input_layout;
+
+ // Create Input Layout
+ HRESULT hr = m_dev.get_d3ddevice_ptr()->CreateInputLayout(input_desc, num_elements,
+ pss.get_desc().pIAInputSignature, pss.get_desc().IAInputSignatureSize, &input_layout );
+ if ( hr != D3D_OK ){
+ throw api_error(setup_input_layout__CreateInputLayout_Failed, "ID3D10Device::CreateInputLayout() Failed.", hr);
+ }
+
+ // Bind Input Layout
+ m_dev.get_d3ddevice_ptr()->IASetInputLayout(input_layout);
+ }
+
+ ///////
+
+ void set_primitive_topology(::D3D10_PRIMITIVE_TOPOLOGY topology)
+ {
+ m_dev.get_d3ddevice_ptr()->IASetPrimitiveTopology(topology);
+ }
+
+ void draw(UINT vertex_count, UINT vertex_offset=0)
+ {
+ m_dev.get_d3ddevice_ptr()->Draw(vertex_count, vertex_offset);
+ }
+
+ void draw_primitive(::D3D10_PRIMITIVE_TOPOLOGY topology, UINT vertex_count, UINT vertex_offset=0)
+ {
+ set_primitive_topology(topology);
+ draw(vertex_count, vertex_offset);
+ }
+ };
+ typedef shader_device render_device, renderer;
+
///////////////////////////////////////////////////////////////////////////
}
}