zenilib  0.5.3.0
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Groups Pages
Video_DX9.h
Go to the documentation of this file.
1 /* This file is part of the Zenipex Library (zenilib).
2  * Copyright (C) 2011 Mitchell Keith Bloch (bazald).
3  *
4  * zenilib is free software: you can redistribute it and/or modify
5  * it under the terms of the GNU Lesser General Public License as published by
6  * the Free Software Foundation, either version 3 of the License, or
7  * (at your option) any later version.
8  *
9  * zenilib is distributed in the hope that it will be useful,
10  * but WITHOUT ANY WARRANTY; without even the implied warranty of
11  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12  * GNU Lesser General Public License for more details.
13  *
14  * You should have received a copy of the GNU Lesser General Public License
15  * along with zenilib. If not, see <http://www.gnu.org/licenses/>.
16  */
17 
32 #ifndef ZENI_VIDEO_DX9_H
33 #define ZENI_VIDEO_DX9_H
34 
35 #include <Zeni/Color.h>
36 #include <Zeni/Video.h>
37 
38 #ifndef DISABLE_DX9
39 
40 typedef enum _D3DFORMAT D3DFORMAT;
41 typedef enum _D3DPOOL D3DPOOL;
42 typedef struct _D3DCAPS9 D3DCAPS9, *LPD3DCAPS9;
46 typedef struct IDirect3D9 *LPDIRECT3D9;
51 typedef struct tagPALETTEENTRY PALETTEENTRY;
52 typedef struct _D3DXMACRO D3DXMACRO, *LPD3DXMACRO;
53 typedef struct ID3DXInclude *LPD3DXINCLUDE;
54 typedef struct ID3DXBuffer *LPD3DXBUFFER;
56 
57 namespace Zeni {
58 
59  struct Color;
60  class Texture_DX9;
61 
62  class ZENI_GRAPHICS_DLL Video_DX9 : public Video {
63  friend class Video;
64  friend ZENI_GRAPHICS_DLL Video & get_Video();
65 
66  Video_DX9();
67  ~Video_DX9();
68 
69  // Undefined
70  Video_DX9(const Video_DX9 &);
71  Video_DX9 & operator=(const Video_DX9 &);
72 
73  public:
74  typedef LPDIRECT3D9 (WINAPI *Direct3DCreate9_fcn)(UINT SDKVersion);
75  typedef HRESULT (WINAPI *D3DXCreateRenderToSurface_fcn)(
76  LPDIRECT3DDEVICE9 pDevice,
77  UINT Width,
78  UINT Height,
79  D3DFORMAT Format,
80  BOOL DepthStencil,
81  D3DFORMAT DepthStencilFormat,
82  LPD3DXRENDERTOSURFACE* ppRenderToSurface);
83  typedef HRESULT (WINAPI *D3DXCreateTexture_fcn)(
84  LPDIRECT3DDEVICE9 pDevice,
85  UINT Width,
86  UINT Height,
87  UINT MipLevels,
88  DWORD Usage,
89  D3DFORMAT Format,
90  D3DPOOL Pool,
91  LPDIRECT3DTEXTURE9* ppTexture);
92  typedef HRESULT (WINAPI *D3DXFilterTexture_fcn)(
93  LPDIRECT3DBASETEXTURE9 pBaseTexture,
94  CONST PALETTEENTRY* pPalette,
95  UINT SrcLevel,
96  DWORD Filter);
97  typedef HRESULT (WINAPI *D3DXCreateMatrixStack_fcn)(
98  DWORD Flags,
99  LPD3DXMATRIXSTACK* ppStack);
100  typedef HRESULT (WINAPI *D3DXCompileShader_fcn)(
101  LPCSTR pSrcData,
102  UINT srcDataLen,
103  const D3DXMACRO *pDefines,
104  LPD3DXINCLUDE pInclude,
105  LPCSTR pFunctionName,
106  LPCSTR pProfile,
107  DWORD Flags,
108  LPD3DXBUFFER *ppShader,
109  LPD3DXBUFFER *ppErrorMsgs,
110  LPD3DXCONSTANTTABLE *ppConstantTable);
111 
112  // DLL Functions
113  static Direct3DCreate9_fcn Direct3DCreate9() {return g_Direct3DCreate9;}
114  static D3DXCreateRenderToSurface_fcn D3DXCreateRenderToSurface() {return g_D3DXCreateRenderToSurface;}
115  static D3DXCreateTexture_fcn D3DXCreateTexture() {return g_D3DXCreateTexture;}
116  static D3DXFilterTexture_fcn D3DXFilterTexture() {return g_D3DXFilterTexture;}
117  static D3DXCreateMatrixStack_fcn D3DXCreateMatrixStack() {return g_D3DXCreateMatrixStack;}
118  static D3DXCompileShader_fcn D3DXCompileShader() {return g_D3DXCompileShader;}
119 
120  // Rendering functions
121  bool begin_prerender();
122  bool begin_render();
123  void end_render();
124  void render(const Renderable &renderable);
125  void clear_depth_buffer();
126 
127  // Accessors
128  int get_maximum_anisotropy() const;
129  bool has_vertex_buffers() const;
130 
131  // Modifiers
132  void set_2d_view(const std::pair<Point2f, Point2f> &camera2d,
133  const std::pair<Point2i, Point2i> &viewport = std::make_pair(Point2i(), get_Video().get_render_target_size()),
134  const bool &fix_aspect_ratio = false);
135  void set_3d_view(const Camera &camera,
136  const std::pair<Point2i, Point2i> &viewport = std::make_pair(Point2i(), get_Video().get_render_target_size()));
137  void set_backface_culling(const bool &on);
138  void set_vertical_sync(const bool &on);
139  void set_zwrite(const bool &enabled);
140  void set_ztest(const bool &enabled);
141  void set_alpha_test(const bool &enabled, const TEST &test, const float &value);
142 
143  // Color and Texturing
144  void set_Color(const Color & /*color*/);
146  inline void apply_Texture(const String &name) {return Video::apply_Texture(name);}
147  void apply_Texture(const unsigned long &id);
148  void apply_Texture(const Texture &texture);
149  void unapply_Texture();
150 
151  // Lighting and Materials
152  void set_lighting(const bool &on = true);
153  void set_ambient_lighting(const Color &color);
154  void set_Light(const int &number, const Light &light);
155  void unset_Light(const int &number);
156  void set_Material(const Material &material);
157  void unset_Material(const Material &material);
158 
159  // Fog
160  void set_Fog(const Fog &fog);
161  void unset_Fog();
162 
163  // Shaders
164  void set_program(Program &program);
165  void unset_program();
166 
167  // Render-to-texture
168  void set_render_target(Texture &texture);
169  void unset_render_target();
170  void clear_render_target(const Color &color = Color(0.0f, 0.0f, 0.0f, 0.0f));
171  const Point2i & get_render_target_size() const;
172 
173  // Model/World Transformation Stack Functions
175  void push_world_stack();
176  void pop_world_stack();
177  void translate_scene(const Vector3f &direction);
178  void rotate_scene(const Vector3f &about, const float &radians);
179  void scale_scene(const Vector3f &factor);
180  void transform_scene(const Matrix4f &transformation);
181 
182  // View+Projection Matrix Functions
183  Point2f get_pixel_offset() const;
184  void set_view_matrix(const Matrix4f &view);
185  void set_projection_matrix(const Matrix4f &projection);
186  void set_viewport(const std::pair<Point2i, Point2i> &viewport =
187  std::make_pair(Point2i(), get_Video().get_render_target_size()));
188 
189  // Creation Functions
190  Texture * load_Texture(const String &filename, const bool &repeat, const bool &lazy_loading = false);
191  Texture * create_Texture(const Image &image);
192  Texture * create_Texture(const Point2i &size, const bool &repeat);
193  Font * create_Font(const String &filename,
194  const float &glyph_height, const float &virtual_screen_height);
195  Vertex_Buffer_Renderer * create_Vertex_Buffer_Renderer(Vertex_Buffer &vertex_buffer);
196  Shader * create_Vertex_Shader(const String &filename);
197  Shader * create_Fragment_Shader(const String &filename);
198  Program * create_Program();
199 
200  // D3D-Related Functions
201  const D3DCAPS9 & get_d3d_capabilities();
202  const D3DPRESENT_PARAMETERS & get_d3d_parameters();
203  inline LPDIRECT3D9 & get_d3d();
204  inline LPDIRECT3DDEVICE9 & get_d3d_device();
205  inline LPD3DXMATRIXSTACK & get_matrix_stack();
206  inline const int & get_dpi();
207  inline float get_dpi_ratio();
208 
209  // Custom D3D-Related Functions
210  bool is_fvf_3d() const;
211  void set_fvf_3d(const bool &on);
212  void set_fvf(const bool &is_3d);
213 
214  protected:
215  void init();
216  bool init_device();
217  void init_context();
218  void destroy_device();
219 
220  private:
221  void zero_handles();
222 
223  HMODULE m_d3d9;
224  static Direct3DCreate9_fcn g_Direct3DCreate9;
225 
226  HMODULE m_d3dx9;
227  static D3DXCreateRenderToSurface_fcn g_D3DXCreateRenderToSurface;
228  static D3DXCreateTexture_fcn g_D3DXCreateTexture;
229  static D3DXFilterTexture_fcn g_D3DXFilterTexture;
230  static D3DXCreateMatrixStack_fcn g_D3DXCreateMatrixStack;
231  static D3DXCompileShader_fcn g_D3DXCompileShader;
232 
233  void set_fvf();
234 
235  LPD3DCAPS9 m_d3d_capabilities;
236  LPD3DPRESENT_PARAMETERS m_d3d_parameters;
237 
238  LPDIRECT3D9 m_d3d;
239  LPDIRECT3DDEVICE9 m_d3d_device;
240  LPD3DXMATRIXSTACK m_matrix_stack;
241  int m_dpi;
242  bool m_begun_render;
243 
244  bool m_textured, m_fvf_3d;
245 
246  Texture_DX9 * m_render_target;
247  ID3DXRenderToSurface * m_render_to_surface;
248  LPDIRECT3DSURFACE9 m_back_buffer;
249  };
250 
251  struct ZENI_GRAPHICS_DLL Video_Device_Failure : public std::exception {
252  Video_Device_Failure() : std::exception("Zeni Video Device Failed") {}
253  };
254 
255 }
256 
257 #endif
258 
259 #endif
struct IDirect3D9 IDirect3D9
_D3DPOOL
Definition: d3d9types.h:1487
An Abstraction of a Light.
Definition: Light.h:57
struct _D3DXMACRO * LPD3DXMACRO
The Direct3D9 Rendering System.
Definition: Video_DX9.h:62
struct IDirect3DDevice9 * LPDIRECT3DDEVICE9
Definition: d3d9.h:587
const GLubyte GLuint GLuint GLuint GLuint alpha GLboolean GLboolean GLboolean GLboolean alpha GLint GLint GLsizei GLsizei GLenum type GLenum GLint GLenum GLint GLint GLsizei GLsizei GLint border GLenum GLint GLint GLint GLint GLint GLsizei GLsizei height GLsizei GLsizei GLenum GLenum const GLvoid *pixels GLenum GLint GLint GLint GLint j2 GLdouble GLdouble GLdouble GLdouble GLdouble GLdouble zFar GLenum light
Definition: SDL_glfuncs.h:144
GLuint color
Definition: glew.h:7185
Camera / Point of View.
Definition: Camera.h:49
The Video Rendering Singleton.
Definition: Video.h:71
GLclampf f
Definition: glew.h:3390
typedef HRESULT(WINAPI *LPD3DXIMTSIGNALCALLBACK)(CONST D3DXVECTOR2 *uv
virtual void set_clear_Color(const Color &color)=0
Set the blank background color.
Definition: Video.cpp:214
struct tagPALETTEENTRY PALETTEENTRY
Definition: Video_DX9.h:51
GLenum GLsizei const GLuint GLboolean enabled
Definition: glew.h:2538
static void init(struct bs2b *bs2b)
Definition: bs2b.c:46
static void render(const Vertex_Buffer_Macrorenderer &macrorenderer, std::vector< Vertex_Buffer::Vertex_Buffer_Range * > &descriptors)
An Abstraction of a Material.
Definition: Material.h:56
static D3DXCreateMatrixStack_fcn D3DXCreateMatrixStack()
Definition: Video_DX9.h:117
struct IDirect3D9 * LPDIRECT3D9
Definition: d3d9.h:361
EGLImageKHR EGLint * name
Definition: eglext.h:284
static Direct3DCreate9_fcn Direct3DCreate9()
Definition: Video_DX9.h:113
struct IDirect3DTexture9 * LPDIRECT3DTEXTURE9
Definition: d3d9.h:1216
A Renderable Interface.
Definition: Renderable.h:47
typedef UINT(WINAPI *PFNWGLGETCONTEXTGPUIDAMDPROC)(HGLRC hglrc)
Image.
Definition: Image.h:52
EGLImageKHR image
Definition: eglext.h:88
interface IDirect3DSurface9 IDirect3DSurface9
Definition: d3d9.h:269
static D3DXCompileShader_fcn D3DXCompileShader()
Definition: Video_DX9.h:118
interface ID3DXConstantTable ID3DXConstantTable
Definition: d3dx9shader.h:268
struct _D3DCAPS9 * LPD3DCAPS9
Definition: Video_DX9.h:42
interface ID3DXConstantTable * LPD3DXCONSTANTTABLE
Definition: d3dx9shader.h:269
enum _D3DFORMAT D3DFORMAT
void apply_Texture(const String &name)
Apply a texture by name.
Definition: Video.hxx:118
An Abstraction of a Texture.
Definition: Texture.h:61
A Featureful 3-Space Vector Class.
Definition: Vector3f.h:58
interface ID3DXRenderToSurface ID3DXRenderToSurface
Definition: d3dx9core.h:471
An Abstraction of Fog.
Definition: Fog.h:47
interface ID3DXRenderToSurface * LPD3DXRENDERTOSURFACE
Definition: d3dx9core.h:472
interface ID3DXInclude * LPD3DXINCLUDE
Definition: d3dx9shader.h:406
static D3DXCreateRenderToSurface_fcn D3DXCreateRenderToSurface()
Definition: Video_DX9.h:114
interface ID3DXMatrixStack * LPD3DXMATRIXSTACK
Definition: d3dx9math.h:1304
Font Abstraction.
Definition: Font.h:70
enum _D3DPOOL D3DPOOL
static D3DXCreateTexture_fcn D3DXCreateTexture()
Definition: Video_DX9.h:115
GLbitfield GLuint program
Definition: gl2ext.h:1203
static D3DXFilterTexture_fcn D3DXFilterTexture()
Definition: Video_DX9.h:116
A Vertex_Buffer that accepts Triangle and Quadrilaterals.
Definition: Vertex_Buffer.h:85
void set_clear_Color(const Color &color)
Set the blank background color.
Definition: Video_DX9.h:145
interface ID3DXInclude ID3DXInclude
Definition: d3dx9shader.h:405
void select_world_matrix()
Select the world (model view) matrix; Call before [translate/rotate/scale] scene. ...
Definition: Video_DX9.h:174
interface ID3DXMatrixStack ID3DXMatrixStack
Definition: d3dx9math.h:1303
GLenum GLenum GLuint texture
Definition: gl2ext.h:850
EGLSurface EGLint void ** value
Definition: eglext.h:301
A base class for Vertex_Shader and Fragment_Shader.
Definition: Shader.h:97
struct IDirect3DBaseTexture9 * LPDIRECT3DBASETEXTURE9
Definition: d3d9.h:1125
typedef DWORD(WINAPI *XInputGetState_t)(DWORD dwUserIndex
_D3DFORMAT
Definition: d3d9types.h:1338
interface IDirect3DDevice9 IDirect3DDevice9
Definition: d3d9.h:257
interface IDirect3DTexture9 IDirect3DTexture9
Definition: d3d9.h:264
interface ID3DXBuffer * LPD3DXBUFFER
Definition: d3dx9core.h:97
Video & get_Video()
Get access to the singleton.
Definition: Video.cpp:149
A Featureful 4-Space Matrix Class.
Definition: Matrix4f.h:47
interface IDirect3DBaseTexture9 IDirect3DBaseTexture9
Definition: d3d9.h:263
struct IDirect3DSurface9 * LPDIRECT3DSURFACE9
Definition: d3d9.h:1658
A 2D Point represented with floats.
Definition: Coordinate.h:98
struct _D3DPRESENT_PARAMETERS_ * LPD3DPRESENT_PARAMETERS
Definition: Video_DX9.h:43
void apply_Texture(const String &name)
Apply a texture by name.
Definition: Video_DX9.h:146
Color.
Definition: Color.h:41
interface ID3DXBuffer ID3DXBuffer
Definition: d3dx9core.h:96
typedef BOOL(WINAPI *PFNWGLSETSTEREOEMITTERSTATE3DLPROC)(HDC hDC
GLsizei size
Definition: gl2ext.h:1467
A 2D Point represented with integers.
Definition: Coordinate.h:85