Changeset 1066
- Timestamp:
- Nov 14, 2011, 9:23:19 AM (11 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/test/tutorial/tut03.cpp
r1065 r1066 38 38 m_size = size; 39 39 m_pixels = new u8vec4[size.x * size.y]; 40 m_tmppixels = new u8vec4[size.x / 2 * size.y / 2]; 40 41 m_frame = -1; 41 m_dirty = 8; 42 for (int i = 0; i < 4; i++) 43 { 44 m_deltashift[i] = 0.0; 45 m_deltascale[i] = 1.0; 46 m_dirty[i] = 2; 47 } 42 48 m_center = -0.75; 43 //f64cmplx(0.001643721971153, 0.822467633298876);44 //f64cmplx(-1.207205434596, 0.315432814901);45 //f64cmplx(-0.79192956889854, -0.14632423080102);46 //f64cmplx(0.3245046418497685, 0.04855101129280834);47 //f64cmplx(0.28693186889504513, 0.014286693904085048);48 49 m_radius = 1.5; 49 50 m_screenradius = 0.5 * (m_size.x < m_size.y ? m_size.x : m_size.y); … … 75 76 Ticker::Unref(m_zoomtext); 76 77 delete m_pixels; 78 delete m_tmppixels; 77 79 } 78 80 79 81 inline f64cmplx ScreenToWorldOffset(ivec2 pixel) 80 82 { 81 f64cmplx tmp = f64cmplx( pixel.x - m_size.x / 2,82 m_size.y / 2 - pixel.y);83 f64cmplx tmp = f64cmplx(0.5 + pixel.x - m_size.x / 2, 84 0.5 + m_size.y / 2 - pixel.y); 83 85 return tmp * (m_radius / m_screenradius); 84 86 } … … 95 97 if ((buttons[0] || buttons[2]) && mousepos.x != -1) 96 98 { 99 f64cmplx oldcenter = m_center; 100 double oldradius = m_radius; 97 101 double zoom = pow(2.0, (buttons[0] ? -deltams : deltams) * 0.0015); 98 102 if (m_radius * zoom > 8.0) … … 103 107 m_center = (m_center - worldmouse) * zoom + worldmouse; 104 108 worldmouse = m_center + ScreenToWorldOffset(mousepos); 105 m_dirty = 8; 106 } 109 110 /* Store the transformation properties to go from m_frame-1 111 * to m_frame. */ 112 m_deltashift[m_frame] = (oldcenter - m_center) / m_radius; 113 m_deltascale[m_frame] = oldradius / m_radius; 114 m_dirty[0] = m_dirty[1] = m_dirty[2] = m_dirty[3] = 2; 115 } 116 else 117 { 118 /* If settings didn't change, set transformation from previous 119 * frame to identity. */ 120 m_deltashift[m_frame] = 0.0; 121 m_deltascale[m_frame] = 1.0; 122 } 123 124 if (buttons[1]) 125 m_dirty[0] = m_dirty[1] = m_dirty[2] = m_dirty[3] = 2; 107 126 108 127 char buf[128]; … … 116 135 u8vec4 *m_pixelstart = m_pixels + m_size.x * m_size.y / 4 * m_frame; 117 136 118 if (m_dirty )119 { 120 m_dirty --;137 if (m_dirty[m_frame]) 138 { 139 m_dirty[m_frame]--; 121 140 122 141 for (int j = ((m_frame + 1) % 4) / 2; j < m_size.y; j += 2) … … 130 149 //f64cmplx r0(0.28693186889504513, 0.014286693904085048); 131 150 //f64cmplx r0(0.001643721971153, 0.822467633298876); 151 //f64cmplx r0(-1.207205434596, 0.315432814901); 152 //f64cmplx r0(-0.79192956889854, -0.14632423080102); 153 //f64cmplx r0(0.3245046418497685, 0.04855101129280834); 132 154 f64cmplx z; 133 155 int iter = maxiter; … … 268 290 glBindTexture(GL_TEXTURE_2D, m_texid); 269 291 270 if (m_dirty )271 { 272 m_dirty --;292 if (m_dirty[m_frame]) 293 { 294 m_dirty[m_frame]--; 273 295 274 296 glTexSubImage2D(GL_TEXTURE_2D, 0, 0, m_frame * m_size.y / 2, … … 282 304 m_pixels + m_size.x * m_size.y / 4 * m_frame); 283 305 } 306 307 /* If other frames are dirty, upload fake data for now */ 308 for (int i = 0; i < 4; i++) 309 { 310 if (m_dirty[i]) 311 { 312 glTexSubImage2D(GL_TEXTURE_2D, 0, 0, i * m_size.y / 2, 313 m_size.x / 2, m_size.y / 2, 314 #if !defined __CELLOS_LV2__ 315 GL_RGBA, GL_UNSIGNED_BYTE, 316 #else 317 /* The PS3 is big-endian */ 318 GL_RGBA, GL_UNSIGNED_INT_8_8_8_8, 319 #endif 320 m_pixels + m_size.x * m_size.y / 4 * m_frame); 321 } 322 } 284 323 285 324 m_shader->Bind(); … … 321 360 private: 322 361 ivec2 m_size; 323 u8vec4 *m_pixels ;362 u8vec4 *m_pixels, *m_tmppixels; 324 363 Shader *m_shader; 325 364 GLuint m_texid; … … 329 368 #endif 330 369 int m_vertexattrib, m_texattrib; 331 int m_frame, m_dirty ;370 int m_frame, m_dirty[4]; 332 371 bool m_ready; 333 372 334 373 f64cmplx m_center; 335 374 double m_radius, m_screenradius; 375 f64cmplx m_deltashift[4]; 376 double m_deltascale[4]; 336 377 337 378 /* Debug information */
Note: See TracChangeset
for help on using the changeset viewer.