zenilib: zenilib/jni/external/zenilib/zeni_graphics/Zeni/Video_DX9.h Source File

zenilib 0.5.3.0

- Main Page
- Modules
- Namespaces
- Classes
- Files

- File List
- File Members

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;
43 typedef struct _D3DPRESENT_PARAMETERS_ D3DPRESENT_PARAMETERS, *LPD3DPRESENT_PARAMETERS;
44 typedef struct ID3DXMatrixStack *LPD3DXMATRIXSTACK;
45 typedef struct ID3DXRenderToSurface *LPD3DXRENDERTOSURFACE;
46 typedef struct IDirect3D9 *LPDIRECT3D9;
47 typedef struct IDirect3DBaseTexture9 *LPDIRECT3DBASETEXTURE9;
48 typedef struct IDirect3DDevice9 *LPDIRECT3DDEVICE9;
49 typedef struct IDirect3DSurface9 *LPDIRECT3DSURFACE9;
50 typedef struct IDirect3DTexture9 *LPDIRECT3DTEXTURE9;
51 typedef struct tagPALETTEENTRY PALETTEENTRY;
52 typedef struct _D3DXMACRO D3DXMACRO, *LPD3DXMACRO;
53 typedef struct ID3DXInclude *LPD3DXINCLUDE;
54 typedef struct ID3DXBuffer *LPD3DXBUFFER;
55 typedef struct ID3DXConstantTable *LPD3DXCONSTANTTABLE;
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*/);
145 void set_clear_Color(const Color &color) {Video::set_clear_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
174 void select_world_matrix() {}
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
IDirect3D9
struct IDirect3D9 IDirect3D9
Definition: SDL_windowsvideo.h:174
_D3DPOOL
_D3DPOOL
Definition: d3d9types.h:1487
Zeni::Light
An Abstraction of a Light.
Definition: Light.h:57
LPD3DXMACRO
struct _D3DXMACRO * LPD3DXMACRO
Zeni::Video_DX9
The Direct3D9 Rendering System.
Definition: Video_DX9.h:62
LPDIRECT3DDEVICE9
struct IDirect3DDevice9 * LPDIRECT3DDEVICE9
Definition: d3d9.h:587
light
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
Zeni::Texture_DX9
Definition: Texture.h:145
color
GLuint color
Definition: glew.h:7185
Zeni::Camera
Camera / Point of View.
Definition: Camera.h:49
Zeni::Video
The Video Rendering Singleton.
Definition: Video.h:71
f
GLclampf f
Definition: glew.h:3390
HRESULT
typedef HRESULT(WINAPI *LPD3DXIMTSIGNALCALLBACK)(CONST D3DXVECTOR2 *uv
Zeni::Video::set_clear_Color
virtual void set_clear_Color(const Color &color)=0
Set the blank background color.
Definition: Video.cpp:214
PALETTEENTRY
struct tagPALETTEENTRY PALETTEENTRY
Definition: Video_DX9.h:51
Zeni::Video_Device_Failure::Video_Device_Failure
Video_Device_Failure()
Definition: Video_DX9.h:252
enabled
GLenum GLsizei const GLuint GLboolean enabled
Definition: glew.h:2538
Zeni::Program
Definition: Shader.h:108
Video.h
init
static void init(struct bs2b *bs2b)
Definition: bs2b.c:46
Zeni::render
static void render(const Vertex_Buffer_Macrorenderer &macrorenderer, std::vector< Vertex_Buffer::Vertex_Buffer_Range * > &descriptors)
Definition: Vertex_Buffer.cpp:581
Zeni::Material
An Abstraction of a Material.
Definition: Material.h:56
Zeni::Video_DX9::D3DXCreateMatrixStack
static D3DXCreateMatrixStack_fcn D3DXCreateMatrixStack()
Definition: Video_DX9.h:117
LPDIRECT3D9
struct IDirect3D9 * LPDIRECT3D9
Definition: d3d9.h:361
_D3DXMACRO
Definition: d3dx9shader.h:134
name
EGLImageKHR EGLint * name
Definition: eglext.h:284
Zeni::Video_DX9::Direct3DCreate9
static Direct3DCreate9_fcn Direct3DCreate9()
Definition: Video_DX9.h:113
LPDIRECT3DTEXTURE9
struct IDirect3DTexture9 * LPDIRECT3DTEXTURE9
Definition: d3d9.h:1216
Zeni::Renderable
A Renderable Interface.
Definition: Renderable.h:47
UINT
typedef UINT(WINAPI *PFNWGLGETCONTEXTGPUIDAMDPROC)(HGLRC hglrc)
Zeni::Image
Image.
Definition: Image.h:52
image
EGLImageKHR image
Definition: eglext.h:88
Zeni::String
Definition: String.h:29
IDirect3DSurface9
interface IDirect3DSurface9 IDirect3DSurface9
Definition: d3d9.h:269
Zeni::Video_DX9::D3DXCompileShader
static D3DXCompileShader_fcn D3DXCompileShader()
Definition: Video_DX9.h:118
ID3DXConstantTable
interface ID3DXConstantTable ID3DXConstantTable
Definition: d3dx9shader.h:268
LPD3DCAPS9
struct _D3DCAPS9 * LPD3DCAPS9
Definition: Video_DX9.h:42
LPD3DXCONSTANTTABLE
interface ID3DXConstantTable * LPD3DXCONSTANTTABLE
Definition: d3dx9shader.h:269
D3DFORMAT
enum _D3DFORMAT D3DFORMAT
Zeni::Video::apply_Texture
void apply_Texture(const String &name)
Apply a texture by name.
Definition: Video.hxx:118
Zeni::Texture
An Abstraction of a Texture.
Definition: Texture.h:61
Zeni::Vector3f
A Featureful 3-Space Vector Class.
Definition: Vector3f.h:58
ID3DXRenderToSurface
interface ID3DXRenderToSurface ID3DXRenderToSurface
Definition: d3dx9core.h:471
Zeni::Video_Device_Failure
Definition: Video_DX9.h:251
Zeni::Fog
An Abstraction of Fog.
Definition: Fog.h:47
LPD3DXRENDERTOSURFACE
interface ID3DXRenderToSurface * LPD3DXRENDERTOSURFACE
Definition: d3dx9core.h:472
sort_controllers.filename
string filename
Definition: sort_controllers.py:8
LPD3DXINCLUDE
interface ID3DXInclude * LPD3DXINCLUDE
Definition: d3dx9shader.h:406
Zeni::Video_DX9::D3DXCreateRenderToSurface
static D3DXCreateRenderToSurface_fcn D3DXCreateRenderToSurface()
Definition: Video_DX9.h:114
LPD3DXMATRIXSTACK
interface ID3DXMatrixStack * LPD3DXMATRIXSTACK
Definition: d3dx9math.h:1304
Zeni::Font
Font Abstraction.
Definition: Font.h:70
D3DPOOL
enum _D3DPOOL D3DPOOL
Zeni::Video_DX9::D3DXCreateTexture
static D3DXCreateTexture_fcn D3DXCreateTexture()
Definition: Video_DX9.h:115
program
GLbitfield GLuint program
Definition: gl2ext.h:1203
Zeni::Video_DX9::D3DXFilterTexture
static D3DXFilterTexture_fcn D3DXFilterTexture()
Definition: Video_DX9.h:116
Zeni::Vertex_Buffer
A Vertex_Buffer that accepts Triangle and Quadrilaterals.
Definition: Vertex_Buffer.h:85
Zeni::Video_DX9::set_clear_Color
void set_clear_Color(const Color &color)
Set the blank background color.
Definition: Video_DX9.h:145
ID3DXInclude
interface ID3DXInclude ID3DXInclude
Definition: d3dx9shader.h:405
Zeni::Video_DX9::select_world_matrix
void select_world_matrix()
Select the world (model view) matrix; Call before [translate/rotate/scale] scene. ...
Definition: Video_DX9.h:174
ID3DXMatrixStack
interface ID3DXMatrixStack ID3DXMatrixStack
Definition: d3dx9math.h:1303
texture
GLenum GLenum GLuint texture
Definition: gl2ext.h:850
value
EGLSurface EGLint void ** value
Definition: eglext.h:301
Zeni::Shader
A base class for Vertex_Shader and Fragment_Shader.
Definition: Shader.h:97
LPDIRECT3DBASETEXTURE9
struct IDirect3DBaseTexture9 * LPDIRECT3DBASETEXTURE9
Definition: d3d9.h:1125
DWORD
typedef DWORD(WINAPI *XInputGetState_t)(DWORD dwUserIndex
_D3DPRESENT_PARAMETERS_
Definition: d3d9types.h:1502
_D3DFORMAT
_D3DFORMAT
Definition: d3d9types.h:1338
IDirect3DDevice9
interface IDirect3DDevice9 IDirect3DDevice9
Definition: d3d9.h:257
IDirect3DTexture9
interface IDirect3DTexture9 IDirect3DTexture9
Definition: d3d9.h:264
LPD3DXBUFFER
interface ID3DXBuffer * LPD3DXBUFFER
Definition: d3dx9core.h:97
Color.h
Zeni::get_Video
Video & get_Video()
Get access to the singleton.
Definition: Video.cpp:149
Zeni::Matrix4f
A Featureful 4-Space Matrix Class.
Definition: Matrix4f.h:47
IDirect3DBaseTexture9
interface IDirect3DBaseTexture9 IDirect3DBaseTexture9
Definition: d3d9.h:263
LPDIRECT3DSURFACE9
struct IDirect3DSurface9 * LPDIRECT3DSURFACE9
Definition: d3d9.h:1658
Zeni::Point2f
A 2D Point represented with floats.
Definition: Coordinate.h:98
LPD3DPRESENT_PARAMETERS
struct _D3DPRESENT_PARAMETERS_ * LPD3DPRESENT_PARAMETERS
Definition: Video_DX9.h:43
Zeni::Vertex_Buffer_Renderer
Definition: Vertex_Buffer.h:71
Zeni::Video_DX9::apply_Texture
void apply_Texture(const String &name)
Apply a texture by name.
Definition: Video_DX9.h:146
Zeni::Color
Color.
Definition: Color.h:41
ID3DXBuffer
interface ID3DXBuffer ID3DXBuffer
Definition: d3dx9core.h:96
BOOL
typedef BOOL(WINAPI *PFNWGLSETSTEREOEMITTERSTATE3DLPROC)(HDC hDC
size
GLsizei size
Definition: gl2ext.h:1467
_D3DCAPS9
Definition: d3d9caps.h:121
Zeni::Point2i
A 2D Point represented with integers.
Definition: Coordinate.h:85