You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
 
 
 

631 lines
21 KiB

  1. //
  2. // Lol Engine - Fractal tutorial
  3. //
  4. // Copyright: (c) 2011-2012 Sam Hocevar <sam@hocevar.net>
  5. // This program is free software; you can redistribute it and/or
  6. // modify it under the terms of the Do What The Fuck You Want To
  7. // Public License, Version 2, as published by Sam Hocevar. See
  8. // http://sam.zoy.org/projects/COPYING.WTFPL for more details.
  9. //
  10. #if defined HAVE_CONFIG_H
  11. # include "config.h"
  12. #endif
  13. #include <cstring>
  14. #include "core.h"
  15. #include "lolgl.h"
  16. #include "loldebug.h"
  17. using namespace lol;
  18. #if defined _WIN32 && defined USE_D3D9
  19. # define FAR
  20. # define NEAR
  21. # include <d3d9.h>
  22. #endif
  23. #if USE_SDL
  24. # include <SDL_main.h>
  25. #endif
  26. #if defined _WIN32
  27. # include <direct.h>
  28. #endif
  29. extern char const *lolfx_11_fractal;
  30. #if defined USE_D3D9
  31. extern IDirect3DDevice9 *g_d3ddevice;
  32. #elif defined _XBOX
  33. extern D3DDevice *g_d3ddevice;
  34. #elif __CELLOS_LV2__
  35. static GLint const INTERNAL_FORMAT = GL_ARGB_SCE;
  36. static GLenum const TEXTURE_FORMAT = GL_BGRA;
  37. static GLenum const TEXTURE_TYPE = GL_UNSIGNED_INT_8_8_8_8_REV;
  38. #elif defined __native_client__
  39. static GLint const INTERNAL_FORMAT = GL_RGBA;
  40. static GLenum const TEXTURE_FORMAT = GL_RGBA;
  41. static GLenum const TEXTURE_TYPE = GL_UNSIGNED_BYTE;
  42. #else
  43. /* Seems efficient for little endian textures */
  44. static GLint const INTERNAL_FORMAT = GL_RGBA;
  45. static GLenum const TEXTURE_FORMAT = GL_BGRA;
  46. static GLenum const TEXTURE_TYPE = GL_UNSIGNED_INT_8_8_8_8_REV;
  47. #endif
  48. class Fractal : public WorldEntity
  49. {
  50. public:
  51. Fractal(ivec2 const &size)
  52. {
  53. /* Ensure texture size is a multiple of 16 for better aligned
  54. * data access. Store the dimensions of a texel for our shader,
  55. * as well as the half-size of the screen. */
  56. m_size = size;
  57. m_size.x = (m_size.x + 15) & ~15;
  58. m_size.y = (m_size.y + 15) & ~15;
  59. m_texel_settings = vec4(1.0, 1.0, 2.0, 2.0) / m_size.xyxy;
  60. m_screen_settings = vec4(1.0, 1.0, 0.5, 0.5) * m_size.xyxy;
  61. /* Window size decides the world aspect ratio. For instance, 640×480
  62. * will be mapped to (-0.66,-0.5) - (0.66,0.5). */
  63. #if !defined __native_client__
  64. m_window_size = Video::GetSize();
  65. #else
  66. /* FIXME: it's illegal to call this on the game thread! */
  67. m_window_size = ivec2(640, 480);
  68. #endif
  69. if (m_window_size.y < m_window_size.x)
  70. m_window2world = 0.5 / m_window_size.y;
  71. else
  72. m_window2world = 0.5 / m_window_size.x;
  73. m_texel2world = (vec2)m_window_size / m_size * m_window2world;
  74. m_oldmouse = ivec2(0, 0);
  75. m_pixels = new u8vec4[m_size.x * m_size.y];
  76. m_tmppixels = new u8vec4[m_size.x / 2 * m_size.y / 2];
  77. m_frame = -1;
  78. m_slices = 4;
  79. for (int i = 0; i < 4; i++)
  80. {
  81. m_deltashift[i] = 0.0;
  82. m_deltascale[i] = 1.0;
  83. m_dirty[i] = 2;
  84. }
  85. #if defined __CELLOS_LV2__ || defined _XBOX
  86. //m_center = dcmplx(-.22815528839841, -1.11514249704382);
  87. //m_center = dcmplx(0.001643721971153, 0.822467633298876);
  88. m_center = dcmplx(-0.65823419062254, 0.50221777363480);
  89. m_zoom_speed = -0.025;
  90. #else
  91. m_center = -0.75;
  92. m_zoom_speed = 0.0;
  93. #endif
  94. m_translate = 0;
  95. m_radius = 5.0;
  96. m_ready = false;
  97. m_drag = false;
  98. m_palette = new u8vec4[(MAX_ITERATIONS + 1) * PALETTE_STEP];
  99. for (int i = 0; i < (MAX_ITERATIONS + 1) * PALETTE_STEP; i++)
  100. {
  101. double f = (double)i / PALETTE_STEP;
  102. double r = 0.5 * lol::sin(f * 0.27 + 2.0) + 0.5;
  103. double g = 0.5 * lol::sin(f * 0.17 - 1.8) + 0.5;
  104. double b = 0.5 * lol::sin(f * 0.21 - 2.6) + 0.5;
  105. if (f < 7.0)
  106. {
  107. f = f < 1.0 ? 0.0 : (f - 1.0) / 6.0;
  108. r *= f;
  109. g *= f;
  110. b *= f;
  111. }
  112. uint8_t red = r * 255.99f;
  113. uint8_t green = g * 255.99f;
  114. uint8_t blue = b * 255.99f;
  115. #if defined __CELLOS_LV2__ || defined _XBOX
  116. m_palette[i] = u8vec4(255, red, green, blue);
  117. #elif defined __native_client__
  118. m_palette[i] = u8vec4(red, green, blue, 255);
  119. #else
  120. m_palette[i] = u8vec4(blue, green, red, 255);
  121. #endif
  122. }
  123. #if !defined __native_client__
  124. m_centertext = new Text(NULL, "src/data/font/ascii.png");
  125. m_centertext->SetPos(ivec3(5, m_window_size.y - 15, 1));
  126. Ticker::Ref(m_centertext);
  127. m_mousetext = new Text(NULL, "src/data/font/ascii.png");
  128. m_mousetext->SetPos(ivec3(5, m_window_size.y - 29, 1));
  129. Ticker::Ref(m_mousetext);
  130. m_zoomtext = new Text(NULL, "src/data/font/ascii.png");
  131. m_zoomtext->SetPos(ivec3(5, m_window_size.y - 43, 1));
  132. Ticker::Ref(m_zoomtext);
  133. #endif
  134. m_position = ivec3(0, 0, 0);
  135. m_bbox[0] = m_position;
  136. m_bbox[1] = ivec3(m_window_size, 0);
  137. Input::TrackMouse(this);
  138. /* Spawn worker threads and wait for their readiness. */
  139. for (int i = 0; i < MAX_THREADS; i++)
  140. m_threads[i] = new Thread(DoWorkHelper, this);
  141. for (int i = 0; i < MAX_THREADS; i++)
  142. m_spawnqueue.Pop();
  143. }
  144. ~Fractal()
  145. {
  146. /* Signal worker threads for completion and wait for
  147. * them to quit. */
  148. for (int i = 0; i < MAX_THREADS; i++)
  149. m_jobqueue.Push(-1);
  150. for (int i = 0; i < MAX_THREADS; i++)
  151. m_donequeue.Pop();
  152. Input::UntrackMouse(this);
  153. #if !defined __native_client__
  154. Ticker::Unref(m_centertext);
  155. Ticker::Unref(m_mousetext);
  156. Ticker::Unref(m_zoomtext);
  157. #endif
  158. delete m_pixels;
  159. delete m_tmppixels;
  160. delete m_palette;
  161. }
  162. inline dcmplx TexelToWorldOffset(vec2 texel)
  163. {
  164. double dx = (0.5 + texel.x - m_size.x / 2) * m_texel2world.x;
  165. double dy = (0.5 + m_size.y / 2 - texel.y) * m_texel2world.y;
  166. return m_radius * dcmplx(dx, dy);
  167. }
  168. inline dcmplx ScreenToWorldOffset(vec2 pixel)
  169. {
  170. /* No 0.5 offset here, because we want to be able to position the
  171. * mouse at (0,0) exactly. */
  172. double dx = pixel.x - m_window_size.x / 2;
  173. double dy = m_window_size.y / 2 - pixel.y;
  174. return m_radius * m_window2world * dcmplx(dx, dy);
  175. }
  176. virtual void TickGame(float seconds)
  177. {
  178. WorldEntity::TickGame(seconds);
  179. int prev_frame = m_frame;
  180. m_frame = (m_frame + 1) % 4;
  181. dcmplx worldmouse = m_center + ScreenToWorldOffset(m_mousepos);
  182. ivec3 buttons = Input::GetMouseButtons();
  183. #if !defined __CELLOS_LV2__ && !defined _XBOX
  184. if (buttons[1])
  185. {
  186. if (!m_drag)
  187. {
  188. m_oldmouse = m_mousepos;
  189. m_drag = true;
  190. }
  191. m_translate = ScreenToWorldOffset(m_oldmouse)
  192. - ScreenToWorldOffset(m_mousepos);
  193. /* XXX: the purpose of this hack is to avoid translating by
  194. * an exact number of pixels. If this were to happen, the step()
  195. * optimisation for i915 cards in our shader would behave
  196. * incorrectly because a quarter of the pixels in the image
  197. * would have tie rankings in the distance calculation. */
  198. m_translate *= 1023.0 / 1024.0;
  199. m_oldmouse = m_mousepos;
  200. }
  201. else
  202. {
  203. m_drag = false;
  204. if (m_translate != 0.0)
  205. {
  206. m_translate *= std::pow(2.0, -seconds * 5.0);
  207. if (m_translate.norm() / m_radius < 1e-4)
  208. m_translate = 0.0;
  209. }
  210. }
  211. if ((buttons[0] || buttons[2]) && m_mousepos.x != -1)
  212. {
  213. double zoom = buttons[0] ? -0.5 : 0.5;
  214. m_zoom_speed += seconds * zoom;
  215. if (m_zoom_speed / zoom > 5e-3f)
  216. m_zoom_speed = 5e-3f * zoom;
  217. }
  218. else if (m_zoom_speed)
  219. {
  220. m_zoom_speed *= std::pow(2.0, -seconds * 5.0);
  221. if (abs(m_zoom_speed) < 1e-5 || m_drag)
  222. m_zoom_speed = 0.0;
  223. }
  224. #endif
  225. if (m_zoom_speed || m_translate != 0.0)
  226. {
  227. dcmplx oldcenter = m_center;
  228. double oldradius = m_radius;
  229. double zoom = std::pow(2.0, seconds * 1e3f * m_zoom_speed);
  230. if (m_radius * zoom > 8.0)
  231. {
  232. m_zoom_speed *= -1.0;
  233. zoom = 8.0 / m_radius;
  234. }
  235. else if (m_radius * zoom < 1e-14)
  236. {
  237. m_zoom_speed *= -1.0;
  238. zoom = 1e-14 / m_radius;
  239. }
  240. m_radius *= zoom;
  241. #if !defined __CELLOS_LV2__ && !defined _XBOX
  242. m_center += m_translate;
  243. m_center = (m_center - worldmouse) * zoom + worldmouse;
  244. worldmouse = m_center + ScreenToWorldOffset(m_mousepos);
  245. #endif
  246. /* Store the transformation properties to go from m_frame - 1
  247. * to m_frame. */
  248. m_deltashift[prev_frame] = (m_center - oldcenter) / oldradius;
  249. m_deltashift[prev_frame].x /= m_size.x * m_texel2world.x;
  250. m_deltashift[prev_frame].y /= m_size.y * m_texel2world.y;
  251. m_deltascale[prev_frame] = m_radius / oldradius;
  252. m_dirty[0] = m_dirty[1] = m_dirty[2] = m_dirty[3] = 2;
  253. }
  254. else
  255. {
  256. /* If settings didn't change, set transformation from previous
  257. * frame to identity. */
  258. m_deltashift[prev_frame] = 0.0;
  259. m_deltascale[prev_frame] = 1.0;
  260. }
  261. /* Transformation from current frame to current frame is always
  262. * identity. */
  263. m_zoom_settings[m_frame][0] = 0.0f;
  264. m_zoom_settings[m_frame][1] = 0.0f;
  265. m_zoom_settings[m_frame][2] = 1.0f;
  266. /* Compute transformation from other frames to current frame */
  267. for (int i = 0; i < 3; i++)
  268. {
  269. int prev_index = (m_frame + 4 - i) % 4;
  270. int cur_index = (m_frame + 3 - i) % 4;
  271. m_zoom_settings[cur_index][0] = m_zoom_settings[prev_index][0] * m_deltascale[cur_index] + m_deltashift[cur_index].x;
  272. m_zoom_settings[cur_index][1] = m_zoom_settings[prev_index][1] * m_deltascale[cur_index] + m_deltashift[cur_index].y;
  273. m_zoom_settings[cur_index][2] = m_zoom_settings[prev_index][2] * m_deltascale[cur_index];
  274. }
  275. /* Precompute texture offset change instead of doing it in GLSL */
  276. for (int i = 0; i < 4; i++)
  277. {
  278. m_zoom_settings[i][0] += 0.5 * (1.0 - m_zoom_settings[i][2]);
  279. m_zoom_settings[i][1] -= 0.5 * (1.0 - m_zoom_settings[i][2]);
  280. }
  281. #if !defined __native_client__
  282. char buf[128];
  283. sprintf(buf, "center: %+16.14f%+16.14fi", m_center.x, m_center.y);
  284. m_centertext->SetText(buf);
  285. sprintf(buf, " mouse: %+16.14f%+16.14fi", worldmouse.x, worldmouse.y);
  286. m_mousetext->SetText(buf);
  287. sprintf(buf, " zoom: %g", 1.0 / m_radius);
  288. m_zoomtext->SetText(buf);
  289. #endif
  290. if (m_dirty[m_frame])
  291. {
  292. m_dirty[m_frame]--;
  293. for (int i = 0; i < m_size.y; i += MAX_LINES * 2)
  294. m_jobqueue.Push(i);
  295. }
  296. }
  297. static void *DoWorkHelper(void *data)
  298. {
  299. Fractal *that = (Fractal *)data;
  300. that->m_spawnqueue.Push(0);
  301. for ( ; ; )
  302. {
  303. int line = that->m_jobqueue.Pop();
  304. if (line == -1)
  305. break;
  306. that->DoWork(line);
  307. that->m_donequeue.Push(0);
  308. }
  309. that->m_donequeue.Push(0);
  310. return NULL;
  311. };
  312. void DoWork(int line)
  313. {
  314. double const maxsqlen = 1024;
  315. double const k1 = 1.0 / (1 << 10) / (std::log(maxsqlen) / std::log(2.0));
  316. int jmin = ((m_frame + 1) % 4) / 2 + line;
  317. int jmax = jmin + MAX_LINES * 2;
  318. if (jmax > m_size.y)
  319. jmax = m_size.y;
  320. u8vec4 *m_pixelstart = m_pixels
  321. + m_size.x * (m_size.y / 4 * m_frame + line / 4);
  322. for (int j = jmin; j < jmax; j += 2)
  323. for (int i = m_frame % 2; i < m_size.x; i += 2)
  324. {
  325. dcmplx z0 = m_center + TexelToWorldOffset(ivec2(i, j));
  326. dcmplx z1, z2, z3, r0 = z0;
  327. //dcmplx r0(0.28693186889504513, 0.014286693904085048);
  328. //dcmplx r0(0.001643721971153, 0.822467633298876);
  329. //dcmplx r0(-1.207205434596, 0.315432814901);
  330. //dcmplx r0(-0.79192956889854, -0.14632423080102);
  331. //dcmplx r0(0.3245046418497685, 0.04855101129280834);
  332. int iter = MAX_ITERATIONS - 4;
  333. for (;;)
  334. {
  335. /* Unroll the loop: tests are more expensive to do at each
  336. * iteration than the few extra multiplications. */
  337. z1 = z0 * z0 + r0;
  338. z2 = z1 * z1 + r0;
  339. z3 = z2 * z2 + r0;
  340. z0 = z3 * z3 + r0;
  341. if (sqlength(z0) >= maxsqlen)
  342. break;
  343. iter -= 4;
  344. if (iter < 4)
  345. break;
  346. }
  347. if (iter)
  348. {
  349. double n = sqlength(z0);
  350. if (sqlength(z1) >= maxsqlen) { iter += 3; n = sqlength(z1); }
  351. else if (sqlength(z2) >= maxsqlen) { iter += 2; n = sqlength(z2); }
  352. else if (sqlength(z3) >= maxsqlen) { iter += 1; n = sqlength(z3); }
  353. if (n > maxsqlen * maxsqlen)
  354. n = maxsqlen * maxsqlen;
  355. /* Approximate log(sqrt(n))/log(sqrt(maxsqlen)) */
  356. double f = iter;
  357. union { double n; uint64_t x; } u = { n };
  358. double k = (u.x >> 42) - (((1 << 10) - 1) << 10);
  359. k *= k1;
  360. /* Approximate log2(k) in [1,2]. */
  361. f += (- 0.344847817623168308695977510213252644185 * k
  362. + 2.024664188044341212602376988171727038739) * k
  363. - 1.674876738008591047163498125918330313237;
  364. *m_pixelstart++ = m_palette[(int)(f * PALETTE_STEP)];
  365. }
  366. else
  367. {
  368. #if defined __CELLOS_LV2__ || defined _XBOX
  369. *m_pixelstart++ = u8vec4(255, 0, 0, 0);
  370. #else
  371. *m_pixelstart++ = u8vec4(0, 0, 0, 255);
  372. #endif
  373. }
  374. }
  375. }
  376. virtual void TickDraw(float seconds)
  377. {
  378. WorldEntity::TickDraw(seconds);
  379. static float const vertices[] =
  380. {
  381. 1.0f, 1.0f,
  382. -1.0f, 1.0f,
  383. -1.0f, -1.0f,
  384. -1.0f, -1.0f,
  385. 1.0f, -1.0f,
  386. 1.0f, 1.0f,
  387. };
  388. static float const texcoords[] =
  389. {
  390. 1.0f, 1.0f,
  391. 0.0f, 1.0f,
  392. 0.0f, 0.0f,
  393. 0.0f, 0.0f,
  394. 1.0f, 0.0f,
  395. 1.0f, 1.0f,
  396. };
  397. if (!m_ready)
  398. {
  399. #if !defined _XBOX && !defined USE_D3D9
  400. /* Create a texture of half the width and twice the height
  401. * so that we can upload four different subimages each frame. */
  402. glGenTextures(1, &m_texid);
  403. glBindTexture(GL_TEXTURE_2D, m_texid);
  404. glTexImage2D(GL_TEXTURE_2D, 0, INTERNAL_FORMAT,
  405. m_size.x / 2, m_size.y * 2, 0,
  406. TEXTURE_FORMAT, TEXTURE_TYPE, m_pixels);
  407. # if defined __CELLOS_LV2__
  408. /* We need this hint because by default the storage type is
  409. * GL_TEXTURE_SWIZZLED_GPU_SCE. */
  410. glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_ALLOCATION_HINT_SCE,
  411. GL_TEXTURE_TILED_GPU_SCE);
  412. # endif
  413. glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_NEAREST);
  414. glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_NEAREST);
  415. #elif defined _XBOX
  416. /* By default the X360 will swizzle the texture. Ask for linear. */
  417. g_d3ddevice->CreateTexture(m_size.x / 2, m_size.y * 2, 1,
  418. D3DUSAGE_WRITEONLY, D3DFMT_LIN_A8R8G8B8,
  419. D3DPOOL_DEFAULT, &m_tex, NULL);
  420. #else
  421. g_d3ddevice->CreateTexture(m_size.x / 2, m_size.y * 2, 1,
  422. D3DUSAGE_DYNAMIC, D3DFMT_A8R8G8B8,
  423. D3DPOOL_SYSTEMMEM, &m_tex, NULL);
  424. #endif
  425. m_shader = Shader::Create(lolfx_11_fractal);
  426. m_vertexattrib = m_shader->GetAttribLocation("a_Vertex", VertexUsage::Position, 0);
  427. m_texattrib = m_shader->GetAttribLocation("a_TexCoord", VertexUsage::TexCoord, 0);
  428. m_texeluni = m_shader->GetUniformLocation("u_TexelSize");
  429. m_screenuni = m_shader->GetUniformLocation("u_ScreenSize");
  430. m_zoomuni = m_shader->GetUniformLocation("u_ZoomSettings");
  431. m_vdecl =
  432. new VertexDeclaration(VertexStream<vec2>(VertexUsage::Position),
  433. VertexStream<vec2>(VertexUsage::TexCoord));
  434. m_vbo = new VertexBuffer(sizeof(vertices));
  435. m_tbo = new VertexBuffer(sizeof(texcoords));
  436. void *tmp = m_vbo->Lock(0, 0);
  437. memcpy(tmp, vertices, sizeof(vertices));
  438. m_vbo->Unlock();
  439. tmp = m_tbo->Lock(0, 0);
  440. memcpy(tmp, texcoords, sizeof(texcoords));
  441. m_tbo->Unlock();
  442. /* FIXME: this object never cleans up */
  443. m_ready = true;
  444. }
  445. #if defined _XBOX || defined USE_D3D9
  446. #else
  447. # if !defined HAVE_GLES_2X
  448. glEnable(GL_TEXTURE_2D);
  449. # endif
  450. glBindTexture(GL_TEXTURE_2D, m_texid);
  451. #endif
  452. if (m_dirty[m_frame])
  453. {
  454. for (int i = 0; i < m_size.y; i += MAX_LINES * 2)
  455. m_donequeue.Pop();
  456. m_dirty[m_frame]--;
  457. #if defined _XBOX || defined USE_D3D9
  458. D3DLOCKED_RECT rect;
  459. # if defined _XBOX
  460. m_tex->LockRect(0, &rect, NULL, D3DLOCK_NOOVERWRITE);
  461. # else
  462. m_tex->LockRect(0, &rect, NULL,
  463. D3DLOCK_DISCARD | D3DLOCK_NOOVERWRITE);
  464. # endif
  465. for (int j = 0; j < m_size.y * 2; j++)
  466. {
  467. u8vec4 *line = (u8vec4 *)rect.pBits + j * rect.Pitch / 4;
  468. for (int i = 0; i < m_size.x / 2; i++)
  469. line[i] = m_pixels[m_size.x / 2 * j + i];
  470. }
  471. m_tex->UnlockRect(0);
  472. #elif defined __CELLOS_LV2__
  473. /* glTexSubImage2D is extremely slow on the PS3, to the point
  474. * that uploading the whole texture is 40 times faster. */
  475. glTexImage2D(GL_TEXTURE_2D, 0, INTERNAL_FORMAT,
  476. m_size.x / 2, m_size.y * 2, 0,
  477. TEXTURE_FORMAT, TEXTURE_TYPE, m_pixels);
  478. #else
  479. glTexSubImage2D(GL_TEXTURE_2D, 0, 0, m_frame * m_size.y / 2,
  480. m_size.x / 2, m_size.y / 2,
  481. TEXTURE_FORMAT, TEXTURE_TYPE,
  482. m_pixels + m_size.x * m_size.y / 4 * m_frame);
  483. #endif
  484. }
  485. m_shader->Bind();
  486. m_shader->SetUniform(m_texeluni, m_texel_settings);
  487. m_shader->SetUniform(m_screenuni, m_screen_settings);
  488. m_shader->SetUniform(m_zoomuni, m_zoom_settings);
  489. m_vdecl->Bind();
  490. m_vdecl->SetStream(m_vbo, m_vertexattrib);
  491. m_vdecl->SetStream(m_tbo, m_texattrib);
  492. #if defined _XBOX || defined USE_D3D9
  493. g_d3ddevice->SetTexture(0, m_tex);
  494. g_d3ddevice->SetRenderState(D3DRS_CULLMODE, D3DCULL_CW);
  495. #elif !defined __CELLOS_LV2__ && !defined __ANDROID__
  496. #else
  497. #endif
  498. m_vdecl->DrawElements(MeshPrimitive::Triangles, 0, 2);
  499. m_vdecl->Unbind();
  500. }
  501. private:
  502. static int const MAX_ITERATIONS = 340;
  503. static int const PALETTE_STEP = 32;
  504. static int const MAX_THREADS = 8;
  505. static int const MAX_LINES = 8;
  506. ivec2 m_size, m_window_size, m_oldmouse;
  507. double m_window2world;
  508. dvec2 m_texel2world;
  509. u8vec4 *m_pixels, *m_tmppixels, *m_palette;
  510. Shader *m_shader;
  511. ShaderAttrib m_vertexattrib, m_texattrib;
  512. ShaderUniform m_texeluni, m_screenuni, m_zoomuni;
  513. VertexDeclaration *m_vdecl;
  514. VertexBuffer *m_vbo, *m_tbo;
  515. #if defined USE_D3D9
  516. IDirect3DTexture9 *m_tex;
  517. #elif defined _XBOX
  518. D3DTexture *m_tex;
  519. #else
  520. GLuint m_texid;
  521. #endif
  522. int m_frame, m_slices, m_dirty[4];
  523. bool m_ready, m_drag;
  524. dcmplx m_center, m_translate;
  525. double m_zoom_speed, m_radius;
  526. vec4 m_texel_settings, m_screen_settings;
  527. mat4 m_zoom_settings;
  528. dcmplx m_deltashift[4];
  529. double m_deltascale[4];
  530. /* Worker threads */
  531. Thread *m_threads[MAX_THREADS];
  532. Queue<int> m_spawnqueue, m_jobqueue, m_donequeue;
  533. /* Debug information */
  534. #if !defined __native_client__
  535. Text *m_centertext, *m_mousetext, *m_zoomtext;
  536. #endif
  537. };
  538. int main(int argc, char **argv)
  539. {
  540. Application app("Tutorial 3: Fractal", ivec2(640, 480), 60.0f);
  541. #if defined _MSC_VER && !defined _XBOX
  542. _chdir("..");
  543. #elif defined _WIN32 && !defined _XBOX
  544. _chdir("../..");
  545. #endif
  546. new DebugFps(5, 5);
  547. new Fractal(ivec2(640, 480));
  548. //new DebugRecord("fractalol.ogm", 60.0f);
  549. app.Run();
  550. return EXIT_SUCCESS;
  551. }