source: trunk/tutorial/11_fractal.cpp @ 1963

Last change on this file since 1963 was 1963, checked in by sam, 7 years ago

gpu: add support for triangle strips and fans, and change the DrawElement
calls so that they take a number of vertices or indexes, not elements.

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