zenilib  0.5.3.0
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Groups Pages
Video_DX9.cpp
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 
18 #include <zeni_graphics.h>
19 
20 #ifndef DISABLE_DX9
21 
22 #include <GLSLANG/ShaderLang.h>
23 #include <SDL/SDL_syswm.h>
24 
25 #include <cassert>
26 #include <iostream>
27 
28 #include <d3d9.h>
29 #include <d3dx9.h>
30 
31 #if defined(_DEBUG) && defined(_WINDOWS)
32 #define DEBUG_NEW new(_NORMAL_BLOCK, __FILE__, __LINE__)
33 #define new DEBUG_NEW
34 #endif
35 
36 namespace Zeni {
37 
38  Video_DX9::Video_DX9()
39  : m_d3d_capabilities(0),
40  m_d3d_parameters(0),
41  m_d3d(0),
42  m_d3d_device(0),
43  m_matrix_stack(0),
44  m_begun_render(false),
45  m_textured(false),
46  m_fvf_3d(false),
47  m_render_target(0),
48  m_render_to_surface(0),
49  m_back_buffer(0)
50  {
51  m_d3d9 = LoadLibrary("d3d9.dll");
52  if(!m_d3d9) {
53  std::cerr << "Loading d3d9.dll failed." << std::endl;
54 
55  throw Video_Init_Failure();
56  }
57 
58  g_Direct3DCreate9 = (Direct3DCreate9_fcn)GetProcAddress(m_d3d9, "Direct3DCreate9");
59  if(!g_Direct3DCreate9) {
60  std::cerr << "Loading d3d9.dll failed." << std::endl;
61 
62  FreeLibrary(m_d3d9);
63 
64  zero_handles();
65 
66  throw Video_Init_Failure();
67  }
68 
69  m_d3dx9 = LoadLibrary("D3DX9_43.dll");
70  if(!m_d3dx9) m_d3dx9 = LoadLibrary("D3DX9_42.dll");
71  if(!m_d3dx9) m_d3dx9 = LoadLibrary("D3DX9_41.dll");
72  if(!m_d3dx9) m_d3dx9 = LoadLibrary("D3DX9_40.dll");
73  if(!m_d3dx9) m_d3dx9 = LoadLibrary("D3DX9_39.dll");
74  if(!m_d3dx9) m_d3dx9 = LoadLibrary("D3DX9_38.dll");
75  if(!m_d3dx9) m_d3dx9 = LoadLibrary("D3DX9_37.dll");
76  if(!m_d3dx9) m_d3dx9 = LoadLibrary("d3dx9_36.dll");
77  if(!m_d3dx9) m_d3dx9 = LoadLibrary("d3dx9_35.dll");
78  if(!m_d3dx9) m_d3dx9 = LoadLibrary("d3dx9_34.dll");
79  if(!m_d3dx9) m_d3dx9 = LoadLibrary("d3dx9_33.dll");
80  if(!m_d3dx9) m_d3dx9 = LoadLibrary("d3dx9_32.dll");
81  if(!m_d3dx9) m_d3dx9 = LoadLibrary("d3dx9_31.dll");
82  if(!m_d3dx9) m_d3dx9 = LoadLibrary("d3dx9_30.dll");
83  if(!m_d3dx9) m_d3dx9 = LoadLibrary("d3dx9_29.dll");
84  if(!m_d3dx9) m_d3dx9 = LoadLibrary("d3dx9_28.dll");
85  if(!m_d3dx9) m_d3dx9 = LoadLibrary("d3dx9_27.dll");
86  if(!m_d3dx9) m_d3dx9 = LoadLibrary("d3dx9_26.dll");
87  if(!m_d3dx9) m_d3dx9 = LoadLibrary("d3dx9_25.dll");
88  if(!m_d3dx9) m_d3dx9 = LoadLibrary("d3dx9_24.dll");
89  if(!m_d3dx9) {
90  std::cerr << "Loading d3dx9.dll failed." << std::endl;
91 
92  FreeLibrary(m_d3d9);
93 
94  zero_handles();
95 
96  throw Video_Init_Failure();
97  }
98 
99  g_D3DXCreateRenderToSurface = (D3DXCreateRenderToSurface_fcn)GetProcAddress(m_d3dx9, "D3DXCreateRenderToSurface");
100  g_D3DXCreateTexture = (D3DXCreateTexture_fcn)GetProcAddress(m_d3dx9, "D3DXCreateTexture");
101  g_D3DXFilterTexture = (D3DXFilterTexture_fcn)GetProcAddress(m_d3dx9, "D3DXFilterTexture");
102  g_D3DXCreateMatrixStack = (D3DXCreateMatrixStack_fcn)GetProcAddress(m_d3dx9, "D3DXCreateMatrixStack");
103  g_D3DXCompileShader = (D3DXCompileShader_fcn)GetProcAddress(m_d3dx9, "D3DXCompileShader");
104  if(!g_D3DXCreateRenderToSurface || !g_D3DXCreateTexture ||
105  !g_D3DXFilterTexture || !g_D3DXCreateMatrixStack ||
106  !g_D3DXCompileShader)
107  {
108  std::cerr << "Loading d3dx9.dll failed." << std::endl;
109 
110  FreeLibrary(m_d3dx9);
111  FreeLibrary(m_d3d9);
112 
113  zero_handles();
114 
115  throw Video_Init_Failure();
116  }
117 
118  m_d3d = Direct3DCreate9()(D3D_SDK_VERSION);
119  if(!m_d3d) {
120  FreeLibrary(m_d3dx9);
121  FreeLibrary(m_d3d9);
122 
123  zero_handles();
124 
125  throw Video_Init_Failure();
126  }
127 
128  try {
129  init();
130  }
131  catch(...) {
132  delete m_d3d_parameters;
133  delete m_d3d_capabilities;
134 
135  FreeLibrary(m_d3dx9);
136  FreeLibrary(m_d3d9);
137 
138  zero_handles();
139 
140  throw Video_Init_Failure();
141  }
142  }
143 
144  Video_DX9::~Video_DX9() {
145  destroy_device();
146 
147  if(m_d3d) {
148  m_d3d->Release();
149  m_d3d = 0;
150  }
151 
152  delete m_d3d_parameters;
153  delete m_d3d_capabilities;
154 
155  FreeLibrary(m_d3dx9);
156  FreeLibrary(m_d3d9);
157 
158  zero_handles();
159  }
160 
161  static bool g_video_dx9_reset = false;
162 
164  assert(!m_render_target && !m_render_to_surface);
165 
166  if(g_video_dx9_reset) {
167  const HRESULT result = m_d3d_device->TestCooperativeLevel();
168 
169  if(result == D3DERR_DEVICELOST)
170  return false;
171  else if(result == D3DERR_DRIVERINTERNALERROR)
172  throw Video_Device_Failure();
173 
174  if(result == D3DERR_DEVICENOTRESET) {
175  if(m_back_buffer) {
176  m_back_buffer->Release();
177  m_back_buffer = 0;
178  }
179 
180  if(FAILED(m_d3d_device->Reset(m_d3d_parameters)))
181  throw Video_Device_Failure();
182 
183  g_video_dx9_reset = false;
184 
185  m_d3d_device->GetRenderTarget(0, &m_back_buffer);
186 
187  init_context();
188  }
189  }
190 
193 
194  return true;
195  }
196 
198  assert(!m_render_target && !m_render_to_surface);
199 
200  HRESULT result = m_begun_render ? m_d3d_device->Present(0, 0, 0, 0) : S_OK;
201 
202  if(result == S_OK) {
203  m_begun_render = true;
204 
205  D3DVIEWPORT9 vp = {0, 0, DWORD(get_Window().get_width()), DWORD(get_Window().get_height()), 0, 1};
206  m_d3d_device->SetViewport(&vp);
207  m_d3d_device->Clear(0, 0, D3DCLEAR_TARGET | D3DCLEAR_ZBUFFER, D3DCOLOR_XRGB(get_clear_Color().r_ub(), get_clear_Color().g_ub(), get_clear_Color().b_ub()), 1.0f, 0);
208  m_d3d_device->BeginScene();
209 
210  return true;
211  }
212  else if(result == D3DERR_DEVICELOST) {
213  g_video_dx9_reset = true;
214  return false;
215  }
216  else if(result == D3DERR_DEVICEREMOVED) {
217  throw Video_Device_Failure();
218  }
219 
220  return false;
221  }
222 
224  m_d3d_device->EndScene();
225  }
226 
227  void Video_DX9::render(const Renderable &renderable) {
228  class PrePostRenderActor {
229  PrePostRenderActor & operator=(const PrePostRenderActor &) {return *this;}
230 
231  public:
232  PrePostRenderActor(const Renderable &renderable_)
233  : renderable(renderable_)
234  {
235  renderable.pre_render();
236  }
237 
238  ~PrePostRenderActor() {
239  renderable.post_render();
240  }
241  private:
242  const Renderable &renderable;
243  } ppra(renderable);
244 
245  set_fvf(renderable.is_3d());
246 
247  renderable.render_to(*this);
248  }
249 
251  m_d3d_device->Clear(0, 0, D3DCLEAR_ZBUFFER, D3DCOLOR(), 1.0f, 0);
252  }
253 
255  return int(m_d3d_capabilities->MaxAnisotropy);
256  }
257 
259  return true;
260  }
261 
262  void Video_DX9::set_2d_view(const std::pair<Point2f, Point2f> &camera2d, const std::pair<Point2i, Point2i> &viewport, const bool &fix_aspect_ratio) {
263  Video::set_2d_view(camera2d, viewport, fix_aspect_ratio);
264 
265  Matrix4f world = Matrix4f::Scale(Vector3f(1.0f, 1.0f, 0.5f)) *
266  Matrix4f::Translate(Vector3f(0.0f, 0.0f, 1.0f));
267  D3DXMATRIX * const world_ptr = reinterpret_cast<D3DXMATRIX *>(&world);
268 
269  m_d3d_device->SetTransform(D3DTS_WORLD, world_ptr);
270  m_matrix_stack->LoadMatrix(world_ptr);
271  }
272 
273  void Video_DX9::set_3d_view(const Camera &camera, const std::pair<Point2i, Point2i> &viewport) {
274  Video::set_3d_view(camera, viewport);
275 
276  Matrix4f world = Matrix4f::Identity();
277  D3DXMATRIX * const world_ptr = reinterpret_cast<D3DXMATRIX *>(&world);
278 
279  m_d3d_device->SetTransform(D3DTS_WORLD, world_ptr);
280  m_matrix_stack->LoadMatrix(world_ptr);
281  }
282 
283  void Video_DX9::set_backface_culling(const bool &on) {
285 
286  if(on)
287  m_d3d_device->SetRenderState(D3DRS_CULLMODE, D3DCULL_CW);
288  else
289  m_d3d_device->SetRenderState(D3DRS_CULLMODE, D3DCULL_NONE);
290  }
291 
292  void Video_DX9::set_vertical_sync(const bool &on) {
294 
295  destroy_device();
296  init();
297  }
298 
299  void Video_DX9::set_zwrite(const bool &enabled) {
300  Video::set_zwrite(enabled);
301 
302  m_d3d_device->SetRenderState(D3DRS_ZWRITEENABLE, DWORD(enabled));
303  }
304 
305  void Video_DX9::set_ztest(const bool &enabled) {
306  Video::set_ztest(enabled);
307 
308  if(enabled) {
309  m_d3d_device->SetRenderState(D3DRS_ZFUNC, D3DCMP_LESSEQUAL);
310  m_d3d_device->SetRenderState(D3DRS_ZENABLE, D3DZB_TRUE);
311  }
312  else
313  m_d3d_device->SetRenderState(D3DRS_ZENABLE, D3DZB_FALSE);
314  }
315 
317  const TEST &test,
318  const float &value)
319  {
320  Video::set_alpha_test(enabled, test, value);
321 
323 
324  switch(test) {
325  case ZENI_NEVER: func = D3DCMP_NEVER; break;
326  case ZENI_LESS: func = D3DCMP_LESS; break;
327  case ZENI_EQUAL: func = D3DCMP_EQUAL; break;
328  case ZENI_GREATER: func = D3DCMP_GREATER; break;
329  case ZENI_NOT_EQUAL: func = D3DCMP_NOTEQUAL; break;
330  case ZENI_LESS_OR_EQUAL: func = D3DCMP_LESSEQUAL; break;
331  case ZENI_GREATER_OR_EQUAL: func = D3DCMP_GREATEREQUAL; break;
332  case ZENI_ALWAYS: func = D3DCMP_ALWAYS; break;
333  default:
334  assert(false);
335  return;
336  }
337 
338  int ref = static_cast<int>(255.0f * value + 0.5f);
339  if(ref < 0)
340  ref = 0;
341  else if(ref > 0xFF)
342  ref = 0xFF;
343 
344  m_d3d_device->SetRenderState(D3DRS_ALPHATESTENABLE, DWORD(enabled));
345  m_d3d_device->SetRenderState(D3DRS_ALPHAREF, DWORD(ref));
346  m_d3d_device->SetRenderState(D3DRS_ALPHAFUNC, func);
347  }
348 
350  Video::set_Color(color);
351 
352  m_d3d_device->SetRenderState(D3DRS_TEXTUREFACTOR, color.get_argb());
353  }
354 
355  void Video_DX9::apply_Texture(const unsigned long &id) {
357 
358  m_textured = true;
359 
360  set_fvf();
361  }
362 
364  texture.apply_Texture();
365 
366  m_textured = true;
367 
368  set_fvf();
369  }
370 
372  m_textured = false;
373 
374  m_d3d_device->SetTexture(0, 0);
375 
376  m_d3d_device->SetTextureStageState(0, D3DTSS_COLORARG1, D3DTA_DIFFUSE);
377  m_d3d_device->SetTextureStageState(0, D3DTSS_ALPHAARG1, D3DTA_DIFFUSE);
378  m_d3d_device->SetTextureStageState(0, D3DTSS_COLOROP, D3DTOP_SELECTARG1);
379  m_d3d_device->SetTextureStageState(0, D3DTSS_ALPHAOP, D3DTOP_SELECTARG1);
380 
381  set_fvf();
382  }
383 
384  void Video_DX9::set_lighting(const bool &on) {
386 
387  m_d3d_device->SetRenderState(D3DRS_LIGHTING, DWORD(on));
388  m_d3d_device->SetRenderState(D3DRS_SPECULARENABLE, DWORD(on));
389  }
390 
393 
394  m_d3d_device->SetRenderState(D3DRS_AMBIENT, color.get_argb());
395  }
396 
397  void Video_DX9::set_Light(const int &number, const Light &light) {
398  if(number < 0 || 7 < number)
399  throw Light_Out_of_Range(); // Match OpenGL - Limit for both may actually be higher
400 
401  Video::set_Light(number, light);
402 
403  light.set(DWORD(number), *this);
404  }
405 
406  void Video_DX9::unset_Light(const int &number) {
407  if(number < 0 || 7 < number)
408  throw Light_Out_of_Range(); // Match OpenGL - Limit for both may actually be higher
409 
410  Video::unset_Light(number);
411 
412  m_d3d_device->LightEnable(DWORD(number), FALSE);
413  }
414 
415  void Video_DX9::set_Material(const Material &material) {
416  material.set(*this);
417  }
418 
419  void Video_DX9::unset_Material(const Material &material) {
420  material.unset(*this);
421  }
422 
423  void Video_DX9::set_Fog(const Fog &fog) {
424  Video::set_Fog(fog);
425 
426  m_d3d_device->SetRenderState(D3DRS_FOGENABLE, true);
427  fog.set(*this);
428  }
429 
432 
433  m_d3d_device->SetRenderState(D3DRS_FOGENABLE, false);
434  m_d3d_device->SetRenderState(D3DRS_FOGTABLEMODE, D3DFOG_NONE);
435  }
436 
438  Program_DX9 &pdx = dynamic_cast<Program_DX9 &>(program);
439 
440  if(pdx.get_vertex_shader())
441  m_d3d_device->SetVertexShader(pdx.get_vertex_shader()->get_vertex_shader());
442  if(pdx.get_fragment_shader())
443  m_d3d_device->SetPixelShader(pdx.get_fragment_shader()->get_pixel_shader());
444  }
445 
447  m_d3d_device->SetVertexShader(0);
448  m_d3d_device->SetPixelShader(0);
449  }
450 
452  if(m_render_target)
454 
455  Texture_DX9 &tdx = dynamic_cast<Texture_DX9 &>(texture);
456 
457  LPDIRECT3DSURFACE9 render_surface = 0;
458 
459  if(FAILED(tdx.m_texture->GetSurfaceLevel(0, &render_surface)))
461 
462  m_render_to_surface = tdx.render_to_surface();
463 
464  if(!m_render_to_surface || FAILED(m_d3d_device->SetRenderTarget(0, render_surface)))
466 
467  if(FAILED(m_d3d_device->BeginScene())) {
468  m_d3d_device->SetRenderTarget(0, m_back_buffer);
470  }
471 
472  m_render_target = &tdx;
473  }
474 
476  if(!m_render_target || !m_render_to_surface)
478 
479  m_render_target = 0;
480 
481  m_d3d_device->EndScene();
482  m_render_to_surface = 0;
483 
484  if(FAILED(m_d3d_device->SetRenderTarget(0, m_back_buffer)))
486  }
487 
489  const Point2i &render_target_size = get_render_target_size();
490  set_viewport(std::make_pair(Point2i(0, 0), Point2i(render_target_size.x, render_target_size.y)));
491  m_d3d_device->Clear(0, 0, D3DCLEAR_TARGET | D3DCLEAR_ZBUFFER, D3DCOLOR_ARGB(color.a_ub(), color.r_ub(), color.g_ub(), color.b_ub()), 1.0f, 0);
492  }
493 
495  if(m_render_target)
496  return m_render_target->get_size();
497  else
498  return get_Window().get_size();
499  }
500 
502  get_matrix_stack()->Push();
503  }
504 
506  get_matrix_stack()->Pop();
507  m_d3d_device->SetTransform(D3DTS_WORLD, m_matrix_stack->GetTop());
508  }
509 
510  void Video_DX9::translate_scene(const Vector3f &direction) {
511  m_matrix_stack->TranslateLocal(direction.i, direction.j, direction.k);
512  m_d3d_device->SetTransform(D3DTS_WORLD, m_matrix_stack->GetTop());
513  }
514 
515  void Video_DX9::rotate_scene(const Vector3f &about, const float &radians) {
516  m_matrix_stack->RotateAxisLocal(reinterpret_cast<const D3DXVECTOR3 *>(&about), radians);
517  m_d3d_device->SetTransform(D3DTS_WORLD, m_matrix_stack->GetTop());
518  }
519 
520  void Video_DX9::scale_scene(const Vector3f &factor) {
521  m_matrix_stack->ScaleLocal(factor.i, factor.j, factor.k);
522  m_d3d_device->SetTransform(D3DTS_WORLD, m_matrix_stack->GetTop());
523  }
524 
525  void Video_DX9::transform_scene(const Matrix4f &transformation) {
526  m_matrix_stack->MultMatrixLocal(reinterpret_cast<const D3DXMATRIX * const>(&transformation));
527  m_d3d_device->SetTransform(D3DTS_WORLD, m_matrix_stack->GetTop());
528  }
529 
531  return Point2f(0.5f, 0.5f);
532  }
533 
536 
537  m_d3d_device->SetTransform(D3DTS_VIEW, reinterpret_cast<D3DXMATRIX *>(const_cast<Matrix4f *>(&view)));
538  }
539 
540  void Video_DX9::set_projection_matrix(const Matrix4f &projection) {
541  Video::set_projection_matrix(projection);
542 
543  m_d3d_device->SetTransform(D3DTS_PROJECTION, reinterpret_cast<D3DXMATRIX *>(const_cast<Matrix4f *>(&projection)));
544  }
545 
546  void Video_DX9::set_viewport(const std::pair<Point2i, Point2i> &viewport) {
547  Video::set_viewport(viewport);
548 
549  D3DVIEWPORT9 vp = {DWORD(viewport.first.x), DWORD(viewport.first.y), DWORD(viewport.second.x - viewport.first.x), DWORD(viewport.second.y - viewport.first.y), 0u, 1u};
550  m_d3d_device->SetViewport(&vp);
551  }
552 
553  Texture * Video_DX9::load_Texture(const String &filename, const bool &repeat, const bool & /*lazy_loading*/ ) {
554  return new Texture_DX9(filename, repeat);
555  }
556 
558  return new Texture_DX9(image);
559  }
560 
561  Texture * Video_DX9::create_Texture(const Point2i &size, const bool &repeat) {
562  const Point2i &max = get_Window().get_size();
563 
564  Point2i corrected(size);
565  while(corrected.x > max.x)
566  corrected.x /= 2;
567  while(corrected.y > max.y)
568  corrected.y /= 2;
569 
570  return new Texture_DX9(corrected, repeat);
571  }
572 
573  Font * Video_DX9::create_Font(const String &filename, const float &glyph_height, const float &virtual_screen_height) {
574  return new Font_FT(filename, glyph_height, virtual_screen_height);
575  }
576 
578  return new Vertex_Buffer_Renderer_DX9(vertex_buffer);
579  }
580 
582  return new Shader_DX9(compile_glsles_shader(filename, m_vertex_compiler), Shader::VERTEX, *this);
583  }
584 
587  }
588 
590  return new Program_DX9();
591  }
592 
594  return *m_d3d_capabilities;
595  }
596 
598  return *m_d3d_parameters;
599  }
600 
602  SDL_SysWMinfo wmInfo;
603  SDL_VERSION(&wmInfo.version);
604 #if SDL_VERSION_ATLEAST(2,0,0)
605  SDL_GetWindowWMInfo(get_Window().get_window(), &wmInfo);
606  HWND hWnd = wmInfo.info.win.window;
607 #else
608  SDL_GetWMInfo(&wmInfo);
609  HWND hWnd = wmInfo.window;
610 #endif
611 
612  std::cerr << "Initializing DirectX 9" << std::endl;
613 
614  try {
615  m_d3d_capabilities = new D3DCAPS9;
616  m_d3d_parameters = new D3DPRESENT_PARAMETERS;
617  }
618  catch (...) {
619  throw Video_Init_Failure();
620  }
621 
622  m_d3d->GetDeviceCaps(D3DADAPTER_DEFAULT, D3DDEVTYPE_HAL, m_d3d_capabilities);
623 
624  m_dpi = GetDeviceCaps(GetDC(hWnd), LOGPIXELSY);
625 
626  ZeroMemory(m_d3d_parameters, sizeof(m_d3d_parameters));
627 
628  m_d3d_parameters->hDeviceWindow = hWnd;
629 
630  m_d3d_parameters->Windowed = true;
632 
633  m_d3d_parameters->BackBufferCount = 1;
634  m_d3d_parameters->BackBufferWidth = UINT(get_Window().get_width());
635  m_d3d_parameters->BackBufferHeight = UINT(get_Window().get_height());
636  m_d3d_parameters->BackBufferFormat = D3DFMT_A8R8G8B8;
637  m_d3d_parameters->SwapEffect = D3DSWAPEFFECT_DISCARD;
639  m_d3d_parameters->Flags = 0; //D3DPRESENTFLAG_LOCKABLE_BACKBUFFER;
640 
641  m_d3d_parameters->EnableAutoDepthStencil = true;
642  m_d3d_parameters->AutoDepthStencilFormat = D3DFMT_D16;
643 
644  if(get_multisampling() > 1)
645  switch(get_multisampling()) {
646  case 2: m_d3d_parameters->MultiSampleType = D3DMULTISAMPLE_2_SAMPLES; break;
647  case 3: m_d3d_parameters->MultiSampleType = D3DMULTISAMPLE_3_SAMPLES; break;
648  case 4: m_d3d_parameters->MultiSampleType = D3DMULTISAMPLE_4_SAMPLES; break;
649  case 5: m_d3d_parameters->MultiSampleType = D3DMULTISAMPLE_5_SAMPLES; break;
650  case 6: m_d3d_parameters->MultiSampleType = D3DMULTISAMPLE_6_SAMPLES; break;
651  case 7: m_d3d_parameters->MultiSampleType = D3DMULTISAMPLE_7_SAMPLES; break;
652  case 8: m_d3d_parameters->MultiSampleType = D3DMULTISAMPLE_8_SAMPLES; break;
653  case 9: m_d3d_parameters->MultiSampleType = D3DMULTISAMPLE_9_SAMPLES; break;
654  case 10: m_d3d_parameters->MultiSampleType = D3DMULTISAMPLE_10_SAMPLES; break;
655  case 11: m_d3d_parameters->MultiSampleType = D3DMULTISAMPLE_11_SAMPLES; break;
656  case 12: m_d3d_parameters->MultiSampleType = D3DMULTISAMPLE_12_SAMPLES; break;
657  case 13: m_d3d_parameters->MultiSampleType = D3DMULTISAMPLE_13_SAMPLES; break;
658  case 14: m_d3d_parameters->MultiSampleType = D3DMULTISAMPLE_14_SAMPLES; break;
659  case 15: m_d3d_parameters->MultiSampleType = D3DMULTISAMPLE_15_SAMPLES; break;
660  case 16:
661  default: m_d3d_parameters->MultiSampleType = D3DMULTISAMPLE_16_SAMPLES; break;
662  }
663  else if(get_multisampling() < 0)
664  m_d3d_parameters->MultiSampleType = D3DMULTISAMPLE_16_SAMPLES;
665  else
666  m_d3d_parameters->MultiSampleType = D3DMULTISAMPLE_NONE;
667  m_d3d_parameters->MultiSampleQuality = 0;
668 
669  // Initialize the D3D device
670  if(!init_device())
671  throw Video_Init_Failure();
672 
673  // Initialize the rendering context
674  init_context();
675 
676  m_d3d_device->GetRenderTarget(0, &m_back_buffer);
677  }
678 
680  DWORD num_quality_levels;
681  while(FAILED(m_d3d->CheckDeviceMultiSampleType(D3DADAPTER_DEFAULT, D3DDEVTYPE_HAL, D3DFMT_A8R8G8B8, m_d3d_parameters->Windowed, m_d3d_parameters->MultiSampleType, &num_quality_levels))) {
682  switch(m_d3d_parameters->MultiSampleType) {
698 
699  case D3DMULTISAMPLE_NONE:
700  default:
701  return false;
702  }
703  }
704 
705  const bool try_hardware = (m_d3d_capabilities->VertexProcessingCaps & D3DDEVCAPS_HWTRANSFORMANDLIGHT) != 0;
706 
707  if((!try_hardware || FAILED(m_d3d->CreateDevice(D3DADAPTER_DEFAULT, D3DDEVTYPE_HAL, m_d3d_parameters->hDeviceWindow, D3DCREATE_HARDWARE_VERTEXPROCESSING, m_d3d_parameters, &m_d3d_device))) &&
708  (!try_hardware || FAILED(m_d3d->CreateDevice(D3DADAPTER_DEFAULT, D3DDEVTYPE_HAL, m_d3d_parameters->hDeviceWindow, D3DCREATE_MIXED_VERTEXPROCESSING, m_d3d_parameters, &m_d3d_device))) &&
709  FAILED(m_d3d->CreateDevice(D3DADAPTER_DEFAULT, D3DDEVTYPE_HAL, m_d3d_parameters->hDeviceWindow, D3DCREATE_SOFTWARE_VERTEXPROCESSING, m_d3d_parameters, &m_d3d_device)))
710  {
711  // HARDWARE, MIXED, and SOFTWARE all failed
712  return false;
713  }
714 
715  // Set Up Matrix Stack
716  D3DXCreateMatrixStack()(0, &m_matrix_stack);
717  m_matrix_stack->LoadIdentity();
718 
720 
721  ShBuiltInResources resources;
722  ShInitBuiltInResources(&resources);
723 
724  resources.MaxVertexAttribs = 8;
725  resources.MaxVertexUniformVectors = 128;
726  resources.MaxVaryingVectors = 8;
727  resources.MaxVertexTextureImageUnits = 0;
728  resources.MaxCombinedTextureImageUnits = 8;
729  resources.MaxTextureImageUnits = 8;
730  resources.MaxFragmentUniformVectors = 16;
731  resources.MaxDrawBuffers = 1;
732 
733  resources.OES_standard_derivatives = 0;
734  resources.OES_EGL_image_external = 0;
735 
738 
739  return true;
740  }
741 
743  // Enable Alpha Blitting
744  m_d3d_device->SetRenderState(D3DRS_ALPHABLENDENABLE, true);
745  m_d3d_device->SetRenderState(D3DRS_SRCBLEND, D3DBLEND_SRCALPHA);
746  m_d3d_device->SetRenderState(D3DRS_DESTBLEND, D3DBLEND_INVSRCALPHA);
747  m_d3d_device->SetRenderState(D3DRS_BLENDOP, D3DBLENDOP_ADD);
748 
749  // Configure Texture Stages
750  m_d3d_device->SetTextureStageState(0, D3DTSS_COLORARG1, D3DTA_DIFFUSE);
751  m_d3d_device->SetTextureStageState(0, D3DTSS_COLORARG2, D3DTA_TEXTURE);
752  m_d3d_device->SetTextureStageState(0, D3DTSS_ALPHAARG1, D3DTA_DIFFUSE);
753  m_d3d_device->SetTextureStageState(0, D3DTSS_ALPHAARG2, D3DTA_TEXTURE);
754 
755  // Set Lighting Variables
756  m_d3d_device->SetRenderState(D3DRS_NORMALIZENORMALS, true);
757 
758  // Multisampling
759  m_d3d_device->SetRenderState(D3DRS_MULTISAMPLEANTIALIAS, DWORD(get_multisampling() > 1));
760 
761  // More basic stuff
762  set_2d();
763  set_Color(get_Color());
768  for(int i = 0; i != 8; ++i)
769  if(const Light * const lp = get_Light(i))
770  set_Light(i, *lp);
771  if(const Fog * const fp = get_Fog())
772  set_Fog(*fp);
776  }
777 
781 
782  if(m_matrix_stack) {
783  m_matrix_stack->Release();
784  m_matrix_stack = 0;
785  }
786 
787  if(m_back_buffer) {
788  m_back_buffer->Release();
789  m_back_buffer = 0;
790  }
791 
792  if(m_d3d_device) {
793  m_d3d_device->Release();
794  m_d3d_device = 0;
795  }
796  }
797 
798  void Video_DX9::zero_handles() {
799  g_Direct3DCreate9 = 0;
800 
801  g_D3DXCreateRenderToSurface = 0;
802  g_D3DXCreateTexture = 0;
803  g_D3DXFilterTexture = 0;
804  g_D3DXCreateMatrixStack = 0;
805  g_D3DXCompileShader = 0;
806  }
807 
808  void Video_DX9::set_fvf(const bool &is_3d) {
809  m_fvf_3d = is_3d;
810 
811  set_fvf();
812  }
813 
814  void Video_DX9::set_fvf() {
815  DWORD fvf = D3DFVF_XYZ;
816 
817  if(m_fvf_3d)
818  fvf |= D3DFVF_NORMAL;
819 
820  if(m_textured)
821  fvf |= D3DFVF_TEX1;
822  else
823  fvf |= D3DFVF_DIFFUSE;
824 
825  m_d3d_device->SetFVF(fvf);
826  }
827 
828  bool Video_DX9::is_fvf_3d() const {
829  return m_fvf_3d;
830  }
831 
832  void Video_DX9::set_fvf_3d(const bool &on) {
833  m_fvf_3d = on;
834 
835  set_fvf();
836  }
837 
838  Video_DX9::Direct3DCreate9_fcn Video_DX9::g_Direct3DCreate9 = 0;
839 
840  Video_DX9::D3DXCreateRenderToSurface_fcn Video_DX9::g_D3DXCreateRenderToSurface = 0;
841  Video_DX9::D3DXCreateTexture_fcn Video_DX9::g_D3DXCreateTexture = 0;
842  Video_DX9::D3DXFilterTexture_fcn Video_DX9::g_D3DXFilterTexture = 0;
843  Video_DX9::D3DXCreateMatrixStack_fcn Video_DX9::g_D3DXCreateMatrixStack = 0;
844  Video_DX9::D3DXCompileShader_fcn Video_DX9::g_D3DXCompileShader = 0;
845 
846 }
847 
848 #else
849 
850 namespace Zeni {
851  void * this_pointer_is_dead_beef = (void *)0xDEADBEEF;
852 }
853 
854 #endif
D3DFORMAT AutoDepthStencilFormat
Definition: d3d9types.h:1516
Vertex_Buffer_Renderer * create_Vertex_Buffer_Renderer(Vertex_Buffer &vertex_buffer)
Function for creating a Vertex_Buffer_Renderer.
Definition: Video_DX9.cpp:577
void set_projection_matrix(const Matrix4f &projection)
Set the projection Matrix4f.
Definition: Video_DX9.cpp:540
DECLSPEC SDL_bool SDLCALL SDL_GetWindowWMInfo(SDL_Window *window, SDL_SysWMinfo *info)
This function allows access to driver-dependent window information.
Definition: SDL_video.c:3002
An Abstraction of a Light.
Definition: Light.h:57
virtual void set_lighting(const bool &on=true)=0
Set lighting on/off.
Definition: Video.cpp:218
#define D3DERR_DEVICELOST
Definition: d3d9.h:1997
const Color & get_clear_Color() const
Get the blank background color.
Definition: Video.hxx:114
HRESULT(WINAPI * D3DXCompileShader_fcn)(LPCSTR pSrcData, UINT srcDataLen, const D3DXMACRO *pDefines, LPD3DXINCLUDE pInclude, LPCSTR pFunctionName, LPCSTR pProfile, DWORD Flags, LPD3DXBUFFER *ppShader, LPD3DXBUFFER *ppErrorMsgs, LPD3DXCONSTANTTABLE *ppConstantTable)
Definition: Video_DX9.h:100
Texture * load_Texture(const String &filename, const bool &repeat, const bool &lazy_loading=false)
Function for loading a Texture; used internally by Textures.
Definition: Video_DX9.cpp:553
D3DSWAPEFFECT SwapEffect
Definition: d3d9types.h:1512
unsigned char a_ub() const
Get the alpha channel [0x00, 0xFF].
Definition: Color.hxx:39
virtual void set_vertical_sync(const bool &on)=0
Set vertical_sync on/off.
Definition: Video.cpp:190
D3DFORMAT BackBufferFormat
Definition: d3d9types.h:1506
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
static bool g_video_dx9_reset
Definition: Video_DX9.cpp:161
Camera / Point of View.
Definition: Camera.h:49
virtual void post_render() const
Definition: Renderable.cpp:61
virtual void render_to(Video_GL_Fixed &screen) const =0
Overridden for OpenGL rendering.
enum _D3DCMPFUNC D3DCMPFUNC
Font * create_Font(const String &filename, const float &glyph_height, const float &virtual_screen_height)
Function for creating a Font; used internally by Fonts.
Definition: Video_DX9.cpp:573
IDirect3D9 *WINAPI Direct3DCreate9(UINT SDKVersion)
GLclampf f
Definition: glew.h:3390
typedef HRESULT(WINAPI *LPD3DXIMTSIGNALCALLBACK)(CONST D3DXVECTOR2 *uv
LPDIRECT3DVERTEXSHADER9 get_vertex_shader() const
Definition: Shader.hxx:57
virtual void set_view_matrix(const Matrix4f &view)=0
Set the view Matrix4f.
Definition: Video.cpp:226
LPDIRECT3D9(WINAPI * Direct3DCreate9_fcn)(UINT SDKVersion)
Definition: Video_DX9.h:74
virtual void unset_Fog()=0
Unset Fog.
Definition: Video.cpp:300
void unset_program()
Disable a program.
Definition: Video_DX9.cpp:446
#define D3DCOLOR_ARGB(a, r, g, b)
Definition: d3d9types.h:37
GLenum GLsizei const GLuint GLboolean enabled
Definition: glew.h:2538
#define D3D_SDK_VERSION
Definition: d3d9.h:32
void set_2d_view(const std::pair< Point2f, Point2f > &camera2d, const std::pair< Point2i, Point2i > &viewport=std::make_pair(Point2i(), get_Video().get_render_target_size()), const bool &fix_aspect_ratio=false)
Set a 2D view for a viewport.
Definition: Video_DX9.cpp:262
static bool get_backface_culling()
Determine whether backface culling is enabled.
Definition: Video.hxx:37
const Light * get_Light(const int &number) const
Get pointer to Light, or 0 if no such Light.
Definition: Video.cpp:274
static bool get_lighting()
Determine whether dynamic lighting is enabled.
Definition: Video.hxx:41
COMPILER_EXPORT ShHandle ShConstructCompiler(ShShaderType type, ShShaderSpec spec, ShShaderOutput output, const ShBuiltInResources *resources)
Definition: ShaderLang.cpp:140
virtual void set_Light(const int &number, const Light &light)=0
Set a particular Light.
Definition: Video.cpp:283
int MaxFragmentUniformVectors
Definition: ShaderLang.h:212
LPDIRECT3DPIXELSHADER9 get_pixel_shader() const
Definition: Shader.hxx:61
static void init(struct bs2b *bs2b)
Definition: bs2b.c:46
#define D3DCREATE_MIXED_VERTEXPROCESSING
Definition: d3d9.h:1836
bool init_device()
Definition: Video_DX9.cpp:679
int MaxVertexTextureImageUnits
Definition: ShaderLang.h:209
An Abstraction of a Material.
Definition: Material.h:56
void set_ambient_lighting(const Color &color)
Set ambient lighting on/off.
Definition: Video_DX9.cpp:391
SDL_version version
Definition: SDL_syswm.h:161
void set_Fog(const Fog &fog)
Set Fog.
Definition: Video_DX9.cpp:423
static D3DXCreateMatrixStack_fcn D3DXCreateMatrixStack()
Definition: Video_DX9.h:117
void set_ztest(const bool &enabled)
Enable or disable testing of the Z-Buffer.
Definition: Video_DX9.cpp:305
const Shader_DX9 * get_fragment_shader() const
Definition: Shader.hxx:69
bool begin_render()
Must be called before all rendering functions; Returns true if rendering can proceed.
Definition: Video_DX9.cpp:197
void init_context()
Definition: Video_DX9.cpp:742
Shader * create_Fragment_Shader(const String &filename)
Create a Fragment_Shader from a file.
Definition: Video_DX9.cpp:585
#define D3DFVF_TEX1
Definition: d3d9types.h:673
bool is_alpha_test_enabled() const
Determine whether alpha testing is enabled.
Definition: Video.hxx:69
void set(const GLenum &number, Video_GL_Fixed &screen) const
Definition: Light.cpp:52
TEST get_alpha_test_function() const
Determine which alpha test is in use.
Definition: Video.hxx:73
#define assert(x)
Definition: SDL_malloc.c:1234
virtual void set_zwrite(const bool &enabled)=0
Enable or disable writing to the Z-Buffer.
Definition: Video.cpp:194
String compile_glsles_shader(const String &filename, const ShHandle &compiler)
Compile an OpenGL ES shader to GLSL/HLSL.
Definition: Video.cpp:304
A Renderable Interface.
Definition: Renderable.h:47
typedef UINT(WINAPI *PFNWGLGETCONTEXTGPUIDAMDPROC)(HGLRC hglrc)
GLenum func
Definition: SDL_opengl.h:5654
bool begin_prerender()
Must be called before begin_render.
Definition: Video_DX9.cpp:163
void set_program(Program &program)
Enable a program.
Definition: Video_DX9.cpp:437
#define D3DFVF_DIFFUSE
Definition: d3d9types.h:667
#define D3DCREATE_SOFTWARE_VERTEXPROCESSING
Definition: d3d9.h:1834
ShHandle m_vertex_compiler
Definition: Video.h:243
#define D3DCLEAR_ZBUFFER
Definition: d3d9types.h:190
bool is_3d() const
Determine whether currently rendering in 3D.
Definition: Video.hxx:81
Image.
Definition: Image.h:52
EGLImageKHR image
Definition: eglext.h:88
virtual bool is_3d() const =0
Tell the rendering system if we&#39;re using 3D coordinates.
void set(Video_GL_Fixed &screen) const
Definition: Fog.cpp:48
Point2f get_pixel_offset() const
Get the pixel offset in the 2d view.
Definition: Video_DX9.cpp:530
void set_zwrite(const bool &enabled)
Enable or disable writing to the Z-Buffer.
Definition: Video_DX9.cpp:299
void clear_render_target(const Color &color=Color(0.0f, 0.0f, 0.0f, 0.0f))
Clear the viewport.
Definition: Video_DX9.cpp:488
#define D3DADAPTER_DEFAULT
Definition: d3d9.h:1873
const Point2i & get_render_target_size() const
Get the dimensions of the render target.
Definition: Video_DX9.cpp:494
void set_3d_view(const Camera &camera, const std::pair< Point2i, Point2i > &viewport=std::make_pair(Point2i(), get_Video().get_render_target_size()))
Set a 3D view for a viewport.
Definition: Video_DX9.cpp:273
unsigned char r_ub() const
Get the red channel [0x00, 0xFF].
Definition: Color.hxx:27
#define SDL_VERSION(x)
Macro to determine SDL version program was compiled against.
Definition: SDL_version.h:79
bool is_fvf_3d() const
Definition: Video_DX9.cpp:828
bool is_zwrite_enabled() const
Determine whether writing to Z-Buffer is enabled.
Definition: Video.hxx:61
void set_Material(const Material &material)
Set a Material.
Definition: Video_DX9.cpp:415
void transform_scene(const Matrix4f &transformation)
Transform the scene.
Definition: Video_DX9.cpp:525
void scale_scene(const Vector3f &factor)
Scale the scene.
Definition: Video_DX9.cpp:520
#define D3DFVF_NORMAL
Definition: d3d9types.h:665
An Abstraction of a Texture.
Definition: Texture.h:61
A Featureful 3-Space Vector Class.
Definition: Vector3f.h:58
void end_render()
Must be called after all rendering functions.
Definition: Video_DX9.cpp:223
ALuint u
Definition: alMain.h:58
static void preinit_multisampling(const int &multisampling=0)
Set a multisampling value.
Definition: Video.cpp:328
void push_world_stack()
Push a model view matrix onto the stack.
Definition: Video_DX9.cpp:501
virtual void set_ztest(const bool &enabled)=0
Enable or disable testing of the Z-Buffer.
Definition: Video.cpp:198
GLuint64EXT * result
Definition: glew.h:12708
void rotate_scene(const Vector3f &about, const float &radians)
Rotate the scene.
Definition: Video_DX9.cpp:515
void set_alpha_test(const bool &enabled, const TEST &test, const float &value)
Set the alpha test.
Definition: Video_DX9.cpp:316
unsigned char b_ub() const
Get the blue channel [0x00, 0xFF].
Definition: Color.hxx:35
virtual void set_ambient_lighting(const Color &color)=0
Set ambient lighting on/off.
Definition: Video.cpp:222
void set_render_target(Texture &texture)
Set a render target.
Definition: Video_DX9.cpp:451
void unset(Video_GL_Fixed &screen) const
Definition: Material.cpp:115
int
Definition: SDL_systhread.c:37
An Abstraction of Fog.
Definition: Fog.h:47
void unapply_Texture()
Unapply a texture.
Definition: Video_DX9.cpp:371
int get_maximum_anisotropy() const
Get the current level of anisotrophy.
Definition: Video_DX9.cpp:254
#define D3DERR_DRIVERINTERNALERROR
Definition: d3d9.h:1993
void unset_render_target()
Unset a render target.
Definition: Video_DX9.cpp:475
static const Color & get_ambient_lighting()
Get the current ambient lighting Color.
Definition: Video.hxx:45
virtual void set_3d_view(const Camera &camera, const std::pair< Point2i, Point2i > &viewport=std::make_pair(Point2i(), get().get_render_target_size()))=0
Set a 3D view for a viewport.
Definition: Video.cpp:174
COMPILER_EXPORT void ShDestruct(ShHandle handle)
Definition: ShaderLang.cpp:158
COMPILER_EXPORT void ShInitBuiltInResources(ShBuiltInResources *resources)
Definition: ShaderLang.cpp:109
#define D3DCOLOR_XRGB(r, g, b)
Definition: d3d9types.h:40
void set_2d()
Set the default 2D view filling the entire display area.
Definition: Video.hxx:93
void set_fvf_3d(const bool &on)
Definition: Video_DX9.cpp:832
DWORD D3DCOLOR
Definition: d3d9types.h:32
static int get_multisampling()
Get the current level of multisampling.
Definition: Video.hxx:57
Font Abstraction.
Definition: Font.h:70
Shader * create_Vertex_Shader(const String &filename)
Create a Vertex_Shader from a file.
Definition: Video_DX9.cpp:581
virtual void set_Color(const Color &color)=0
Set the current color.
Definition: Video.cpp:210
void set_backface_culling(const bool &on)
Set backface culling on/off.
Definition: Video_DX9.cpp:283
#define D3DPRESENT_INTERVAL_ONE
Definition: d3d9caps.h:267
void set_lighting(const bool &on=true)
Set lighting on/off.
Definition: Video_DX9.cpp:384
virtual void set_2d_view(const std::pair< Point2f, Point2f > &camera2d, const std::pair< Point2i, Point2i > &viewport=std::make_pair(Point2i(), get().get_render_target_size()), const bool &fix_aspect_ratio=false)=0
Set a 2D view for a viewport.
Definition: Video.cpp:153
void unset_Material(const Material &material)
Unset a Material.
Definition: Video_DX9.cpp:419
GLbitfield GLuint program
Definition: gl2ext.h:1203
#define FALSE
Definition: ftobjs.h:57
union SDL_SysWMinfo::@78 info
A Vertex_Buffer that accepts Triangle and Quadrilaterals.
Definition: Vertex_Buffer.h:85
const Shader_DX9 * get_vertex_shader() const
Definition: Shader.hxx:65
void set_Color(const Color &)
Set the current color.
Definition: Video_DX9.cpp:349
void set_clear_Color(const Color &color)
Set the blank background color.
Definition: Video_DX9.h:145
static Matrix4f Translate(const Vector3f &translation_factor)
Definition: Matrix4f.hxx:70
void set(Video_GL_Fixed &screen) const
Definition: Material.cpp:83
virtual void set_Fog(const Fog &fog)=0
Set Fog.
Definition: Video.cpp:295
Textures & get_Textures()
Get access to the singleton.
Definition: Textures.cpp:64
Window & get_Window()
Get access to the singleton.
Definition: Window.cpp:392
virtual void apply_Texture() const =0
Apply a Texture to upcoming polygons.
void clear_depth_buffer()
Can reset the depth buffer at any time if necessary.
Definition: Video_DX9.cpp:250
const D3DPRESENT_PARAMETERS & get_d3d_parameters()
See DirectX Documentation for details.
Definition: Video_DX9.cpp:597
void apply_Texture(const String &name)
Apply a texture for upcoming polygons (Called by Video::apply_Texture)
Definition: Textures.cpp:68
virtual void set_projection_matrix(const Matrix4f &projection)=0
Set the projection Matrix4f.
Definition: Video.cpp:230
int MaxCombinedTextureImageUnits
Definition: ShaderLang.h:210
void set_Light(const int &number, const Light &light)
Set a particular Light.
Definition: Video_DX9.cpp:397
virtual void set_viewport(const std::pair< Point2i, Point2i > &viewport=std::make_pair(Point2i(), get().get_render_target_size()))=0
Set the viewport.
Definition: Video.cpp:234
GLenum GLenum GLuint texture
Definition: gl2ext.h:850
void pop_world_stack()
Pop a model view matrix off the stack.
Definition: Video_DX9.cpp:505
#define D3DTS_WORLD
Definition: d3d9types.h:328
#define D3DDEVCAPS_HWTRANSFORMANDLIGHT
Definition: d3d9caps.h:296
void unlose_resources()
If resources have been lost, then reload them.
Definition: Database.hxx:415
EGLSurface EGLint void ** value
Definition: eglext.h:301
A base class for Vertex_Shader and Fragment_Shader.
Definition: Shader.h:97
DWORD VertexProcessingCaps
Definition: d3d9caps.h:176
#define D3DCLEAR_TARGET
Definition: d3d9types.h:189
#define D3DCREATE_HARDWARE_VERTEXPROCESSING
Definition: d3d9.h:1835
LPD3DXMATRIXSTACK & get_matrix_stack()
Get access to a matrix stack stored by this class.
Definition: Video_DX9.hxx:52
Texture * create_Texture(const Image &image)
Function for creating a Texture from an Image.
Definition: Video_DX9.cpp:557
#define D3DPRESENT_RATE_DEFAULT
Definition: d3d9types.h:1498
HRESULT(WINAPI * D3DXCreateTexture_fcn)(LPDIRECT3DDEVICE9 pDevice, UINT Width, UINT Height, UINT MipLevels, DWORD Usage, D3DFORMAT Format, D3DPOOL Pool, LPDIRECT3DTEXTURE9 *ppTexture)
Definition: Video_DX9.h:83
D3DMULTISAMPLE_TYPE MultiSampleType
Definition: d3d9types.h:1509
void destroy_device()
Definition: Video_DX9.cpp:778
bool has_vertex_buffers() const
Determine whether Vertex_Buffers are supported.
Definition: Video_DX9.cpp:258
typedef DWORD(WINAPI *XInputGetState_t)(DWORD dwUserIndex
const D3DCAPS9 & get_d3d_capabilities()
See DirectX Documentation for details.
Definition: Video_DX9.cpp:593
void * this_pointer_is_dead_beef
Definition: Video_DX9.cpp:851
unsigned char g_ub() const
Get the green channel [0x00, 0xFF].
Definition: Color.hxx:31
ID3DXRenderToSurface * render_to_surface() const
Definition: Texture.hxx:58
static Matrix4f Identity()
Definition: Matrix4f.hxx:52
#define D3DFVF_XYZ
Definition: d3d9types.h:656
void set_viewport(const std::pair< Point2i, Point2i > &viewport=std::make_pair(Point2i(), get_Video().get_render_target_size()))
Set the viewport.
Definition: Video_DX9.cpp:546
HRESULT(WINAPI * D3DXCreateMatrixStack_fcn)(DWORD Flags, LPD3DXMATRIXSTACK *ppStack)
Definition: Video_DX9.h:97
static bool get_vertical_sync()
Determine whether vertical sync is enabled.
Definition: Video.hxx:53
virtual void set_backface_culling(const bool &on)=0
Set backface culling on/off.
Definition: Video.cpp:186
bool is_ztest_enabled() const
Determine whether testing the Z-Buffer is enabled.
Definition: Video.hxx:65
void unset_Light(const int &number)
Unset a particular Light.
Definition: Video_DX9.cpp:406
#define D3DERR_DEVICENOTRESET
Definition: d3d9.h:1998
Program * create_Program()
Create a Program from a file.
Definition: Video_DX9.cpp:589
static const Point2i & get_size()
Definition: Window.hxx:29
GLclampf ref
Definition: gl2ext.h:1455
struct _D3DPRESENT_PARAMETERS_ D3DPRESENT_PARAMETERS
Fonts & get_Fonts()
Get access to the singleton.
Definition: Fonts.cpp:60
void unset_Fog()
Unset Fog.
Definition: Video_DX9.cpp:430
const Color & get_Color() const
Get the current color.
Definition: Video.hxx:110
HRESULT(WINAPI * D3DXCreateRenderToSurface_fcn)(LPDIRECT3DDEVICE9 pDevice, UINT Width, UINT Height, D3DFORMAT Format, BOOL DepthStencil, D3DFORMAT DepthStencilFormat, LPD3DXRENDERTOSURFACE *ppRenderToSurface)
Definition: Video_DX9.h:75
virtual void pre_render() const
Definition: Renderable.cpp:56
const Point2i & get_size() const
Get the resolution of the Texture on the GPU.
Definition: Texture.hxx:54
A Featureful 4-Space Matrix Class.
Definition: Matrix4f.h:47
void set_vertical_sync(const bool &on)
Set vertical_sync on/off.
Definition: Video_DX9.cpp:292
HRESULT(WINAPI * D3DXFilterTexture_fcn)(LPDIRECT3DBASETEXTURE9 pBaseTexture, CONST PALETTEENTRY *pPalette, UINT SrcLevel, DWORD Filter)
Definition: Video_DX9.h:92
#define D3DPRESENT_INTERVAL_IMMEDIATE
Definition: d3d9caps.h:271
int i
Definition: pngrutil.c:1377
void set_fvf(const bool &is_3d)
Definition: Video_DX9.cpp:808
struct _D3DCAPS9 D3DCAPS9
virtual void set_alpha_test(const bool &enabled, const TEST &test=ZENI_ALWAYS, const float &value=0.0f)=0
Set the alpha test.
Definition: Video.cpp:202
virtual void unset_Light(const int &number)=0
Unset a particular Light.
Definition: Video.cpp:287
#define D3DTA_DIFFUSE
Definition: d3d9types.h:615
DWORD MaxAnisotropy
Definition: d3d9caps.h:160
#define max(x, y)
Definition: os.h:79
void render(const Renderable &renderable)
Render a Renderable.
Definition: Video_DX9.cpp:227
Uint32 get_argb() const
Get a Uint32 representation of 0xAARRGGBB.
Definition: Color.hxx:47
#define D3DERR_DEVICEREMOVED
Definition: d3d9.h:2011
void translate_scene(const Vector3f &direction)
Translate the scene.
Definition: Video_DX9.cpp:510
struct IDirect3DSurface9 * LPDIRECT3DSURFACE9
Definition: d3d9.h:1658
ShHandle m_fragment_compiler
Definition: Video.h:244
A 2D Point represented with floats.
Definition: Coordinate.h:98
const Fog * get_Fog() const
Get pointer to current Fog, or 0 if no Fog.
Definition: Video.cpp:291
#define D3DTA_TEXTURE
Definition: d3d9types.h:617
void apply_Texture(const String &name)
Apply a texture by name.
Definition: Video_DX9.h:146
static Matrix4f Scale(const Vector3f &scaling_factor)
Definition: Matrix4f.hxx:59
#define false
Definition: ftrandom.c:50
Color.
Definition: Color.h:41
int OES_standard_derivatives
Definition: ShaderLang.h:217
float get_alpha_test_value() const
Determine what value the alpha test is comparing against.
Definition: Video.hxx:77
GLsizei size
Definition: gl2ext.h:1467
void set_view_matrix(const Matrix4f &view)
Set the view Matrix4f.
Definition: Video_DX9.cpp:534
A 2D Point represented with integers.
Definition: Coordinate.h:85