Changeset 1921
 Timestamp:
 Sep 16, 2012, 6:48:19 PM (9 years ago)
 File:

 1 edited
Legend:
 Unmodified
 Added
 Removed

trunk/tutorial/11_fractal.cpp
r1893 r1921 81 81 m_oldmouse = ivec2(0, 0); 82 82 83 m_pixels = new u8vec4[m_size.x * m_size.y]; 84 m_tmppixels = new u8vec4[m_size.x / 2 * m_size.y / 2]; 83 m_pixels.Resize(m_size.x * m_size.y); 85 84 m_frame = 1; 86 85 m_slices = 4; … … 105 104 m_drag = false; 106 105 107 m_palette = new u8vec4[(MAX_ITERATIONS + 1) * PALETTE_STEP];108 106 for (int i = 0; i < (MAX_ITERATIONS + 1) * PALETTE_STEP; i++) 109 107 { … … 126 124 uint8_t blue = b * 255.99f; 127 125 #if defined __CELLOS_LV2__  defined _XBOX 128 m_palette [i] = u8vec4(255, red, green, blue);126 m_palette.Push(u8vec4(255, red, green, blue)); 129 127 #elif defined __native_client__ 130 m_palette [i] = u8vec4(red, green, blue, 255);131 #else 132 m_palette [i] = u8vec4(blue, green, red, 255);128 m_palette.Push(u8vec4(red, green, blue, 255)); 129 #else 130 m_palette.Push(u8vec4(blue, green, red, 255)); 133 131 #endif 134 132 } … … 175 173 Ticker::Unref(m_zoomtext); 176 174 #endif 177 delete m_pixels;178 delete m_tmppixels;179 delete m_palette;180 175 } 181 176 … … 362 357 if (jmax > m_size.y) 363 358 jmax = m_size.y; 364 u8vec4 *m_pixelstart = m_pixels359 u8vec4 *m_pixelstart = &m_pixels[0] 365 360 + m_size.x * (m_size.y / 4 * m_frame + line / 4); 366 361 … … 370 365 for (int i = m_frame % 2; i < m_size.x; i += 2) 371 366 { 367 double xr, yr, x0, y0, x1, y1, x2, y2, x3, y3; 372 368 dcmplx z0 = c + TexelToWorldOffset(ivec2(i, j)); 373 dcmplx z1, z2, z3, r0 = z0;374 369 //dcmplx r0(0.28693186889504513, 0.014286693904085048); 375 370 //dcmplx r0(0.001643721971153, 0.822467633298876); … … 377 372 //dcmplx r0(0.79192956889854, 0.14632423080102); 378 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 379 int iter = MAX_ITERATIONS  4; 380 380 for (;;) … … 382 382 /* Unroll the loop: tests are more expensive to do at each 383 383 * iteration than the few extra multiplications. */ 384 z1 = z0 * z0 + r0; 385 z2 = z1 * z1 + r0; 386 z3 = z2 * z2 + r0; 387 z0 = z3 * z3 + r0; 388 if (sqlength(z0) >= maxsqlen) 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) 389 394 break; 390 395 iter = 4; … … 395 400 if (iter) 396 401 { 397 double n = sqlength(z0); 398 399 if (sqlength(z1) >= maxsqlen) { iter += 3; n = sqlength(z1); } 400 else if (sqlength(z2) >= maxsqlen) { iter += 2; n = sqlength(z2); } 401 else if (sqlength(z3) >= maxsqlen) { iter += 1; n = sqlength(z3); } 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 } 402 416 403 417 if (n > maxsqlen * maxsqlen) … … 461 475 glTexImage2D(GL_TEXTURE_2D, 0, INTERNAL_FORMAT, 462 476 m_size.x / 2, m_size.y * 2, 0, 463 TEXTURE_FORMAT, TEXTURE_TYPE, m_pixels);477 TEXTURE_FORMAT, TEXTURE_TYPE, &m_pixels[0]); 464 478 # if defined __CELLOS_LV2__ 465 479 /* We need this hint because by default the storage type is … … 543 557 glTexImage2D(GL_TEXTURE_2D, 0, INTERNAL_FORMAT, 544 558 m_size.x / 2, m_size.y * 2, 0, 545 TEXTURE_FORMAT, TEXTURE_TYPE, m_pixels);559 TEXTURE_FORMAT, TEXTURE_TYPE, &m_pixels[0]); 546 560 #else 547 561 glTexSubImage2D(GL_TEXTURE_2D, 0, 0, m_frame * m_size.y / 2, 548 562 m_size.x / 2, m_size.y / 2, 549 563 TEXTURE_FORMAT, TEXTURE_TYPE, 550 m_pixels + m_size.x * m_size.y / 4 * m_frame);564 &m_pixels[m_size.x * m_size.y / 4 * m_frame]); 551 565 #endif 552 566 } … … 578 592 double m_window2world; 579 593 dvec2 m_texel2world; 580 u8vec4 *m_pixels, *m_tmppixels, *m_palette;594 Array<u8vec4> m_pixels, m_palette; 581 595 582 596 Shader *m_shader; … … 615 629 int main(int argc, char **argv) 616 630 { 617 Application app("Tutorial 3: Fractal", ivec2(640, 480), 60.0f); 631 ivec2 window_size(640, 480); 632 633 Application app("Tutorial 3: Fractal", window_size, 60.0f); 618 634 619 635 #if defined _MSC_VER && !defined _XBOX … … 624 640 625 641 new DebugFps(5, 5); 626 new Fractal( ivec2(640, 480));642 new Fractal(window_size); 627 643 //new DebugRecord("fractalol.ogm", 60.0f); 628 644
Note: See TracChangeset
for help on using the changeset viewer.