OSDN Git Service

directx/dx10/shader.hpp: set_primitive_topology(), draw(), draw_primitive() Add.
[roast/roast_ex_windows.git] / roast_ex / include / roast / graphics / directx / dx10 / buffer.hpp
1 //      Roast+ License
2
3 #ifndef __SFJP_ROAST_EX__graphics__directx__dx10__buffer_HPP__
4 #define __SFJP_ROAST_EX__graphics__directx__dx10__buffer_HPP__
5
6 #include "roast/graphics/directx/dx10/device.hpp"
7 #include "roast/graphics/directx/shader_param.hpp"      //      Hmm...
8
9 namespace roast
10 {
11         namespace directx
12         {
13                 namespace dx10
14                 {
15                         namespace graphics
16                         {
17                                 ///////////////////////////////////////////////////////////////////////////
18
19                                 class buffer : /*public buffer_base,*/ protected iunknown_<::ID3D10Buffer>
20                                 {
21                                 public:
22                                         typedef ::ID3D10Buffer _BufferT, _IfType;
23                                         enum exception_codes
24                                         {
25                                                 exception_codes__head = exception_code_root::buffer,
26
27                                                 buffer__CreateBuffer_Failed
28                                         };
29                                 protected:
30                                         device& m_dev;
31
32                                 public:
33                                         buffer(device &d, D3D10_BIND_FLAG buffer_type, unsigned int size, const void* initial_data=NULL,
34                                                 ::D3D10_USAGE access=D3D10_USAGE_DEFAULT, UINT cpu_access=0,
35                                                 UINT memory_pitch=0, UINT slice_pitch=0, UINT misc_flags=0) : m_dev(d)
36                                         {
37                                                 ::D3D10_BUFFER_DESC bufdesc;
38                                                 //::ZeroMemory( &bufdesc, sizeof(bufdesc) );
39                                                 bufdesc.BindFlags = buffer_type;
40                                                 bufdesc.ByteWidth = size;
41                                                 bufdesc.Usage = access;
42                                                 bufdesc.CPUAccessFlags = (D3D10_CPU_ACCESS_FLAG)cpu_access;
43                                                 bufdesc.MiscFlags = misc_flags;
44
45                                                 ::D3D10_SUBRESOURCE_DATA srdata;
46                                                 srdata.pSysMem = initial_data;
47                                                 srdata.SysMemPitch = memory_pitch;
48                                                 srdata.SysMemSlicePitch = slice_pitch;
49
50                                                 ::HRESULT hr = m_dev.get_id3d_device_ptr()->CreateBuffer( &bufdesc, &srdata, &m_if );
51                                                 if ( hr != D3D_OK ){
52                                                         throw api_error(buffer__CreateBuffer_Failed,
53                                                                 "ID3D10Device::CreateBuffer() Failed.", hr);
54                                                 }
55                                         }
56
57                                         ///////////////
58
59                                         
60                                         //////////////////////////////////////////////////////////////////////////////
61                                         
62                                         _BufferT* get_buffer_ptr(){ return get_internal_ptr(); }
63                                         const _BufferT* get_buffer_ptr() const { return get_internal_ptr(); }
64                                 };
65
66                                 ///////////////////////////////////////////////////////////////////////////
67
68                                 template <typename VERTEX_TYPE>
69                                 class input_vertex_buffer : public buffer
70                                 {
71                                 public:
72                                         input_vertex_buffer(device &d, const VERTEX_TYPE* initial_data, unsigned int size) : buffer(d,D3D10_BIND_VERTEX_BUFFER,size,initial_data){}
73                                 };
74
75                                 ///////////////////////////////////////////////////////////////////////////
76                         }
77                 }
78         }
79 }
80
81 #endif//__SFJP_ROAST_EX__graphics__directx__dx10__buffer_HPP__