Changeset 274 for trunk/gui/vizservers
- Timestamp:
- Mar 3, 2006, 2:03:43 PM (19 years ago)
- Location:
- trunk/gui/vizservers/nanovis
- Files:
-
- 3 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/gui/vizservers/nanovis/ParticleSystem.cpp
r273 r274 16 16 #include <stdio.h> 17 17 #include <assert.h> 18 #include <malloc.h> 19 #include <string.h> 18 20 19 21 #include "ParticleSystem.h" … … 29 31 flip = true; 30 32 max_life = 30; 33 34 data = (Particle*) malloc(w*h*sizeof(Particle)); 35 36 m_vertex_array = new RenderVertexArray(psys_width*psys_height, 3, GL_FLOAT); 37 assert(glGetError()==0); 31 38 32 39 glGenFramebuffersEXT(2, psys_fbo); … … 73 80 74 81 glDeleteFramebuffersEXT(2, psys_fbo); 75 } 76 77 78 void ParticleSystem::initialize(Particle* data){ 82 83 free(data); 84 } 85 86 87 void ParticleSystem::initialize(Particle* p){ 88 //also store the data on main memory for next initialization 89 memcpy(data, p, psys_width*psys_height*sizeof(Particle)); 90 91 glBindTexture(GL_TEXTURE_RECTANGLE_NV, psys_tex[0]); 92 glTexImage2D(GL_TEXTURE_RECTANGLE_NV, 0, GL_FLOAT_RGBA32_NV, psys_width, psys_height, 0, GL_RGBA, GL_FLOAT, (float*)p); 93 94 assert(glGetError()==0); 95 96 flip = true; 97 reborn = false; 98 99 fprintf(stderr, "init particles\n"); 100 } 101 102 void ParticleSystem::reset(){ 79 103 glBindTexture(GL_TEXTURE_RECTANGLE_NV, psys_tex[0]); 80 104 glTexImage2D(GL_TEXTURE_RECTANGLE_NV, 0, GL_FLOAT_RGBA32_NV, psys_width, psys_height, 0, GL_RGBA, GL_FLOAT, (float*)data); … … 84 108 flip = true; 85 109 reborn = false; 86 87 fprintf(stderr, "init particles\n"); 88 } 110 } 111 89 112 90 113 void ParticleSystem::advect(){ 114 if(reborn) reset(); 115 91 116 glDisable(GL_BLEND); 92 117 … … 150 175 151 176 //soft_read_verts(); 152 153 //hard_read_verts(); 177 update_vertex_buffer(); 154 178 155 179 flip = (!flip); … … 163 187 fprintf(stderr, "advect: %d ", psys_frame); 164 188 } 189 190 191 void ParticleSystem::update_vertex_buffer(){ 192 m_vertex_array->Read(psys_width, psys_height); 193 //m_vertex_array->LoadData(vert); //does not work?? 194 assert(glGetError()==0); 195 } 196 197 198 void ParticleSystem::display_vertices(){ 199 glDisable(GL_TEXTURE_2D); 200 glDisable(GL_BLEND); 201 202 glPointSize(0.5); 203 glColor4f(.8,.8,.8,1.); 204 205 m_vertex_array->SetPointer(0); 206 //glEnableVertexAttribArray(0); 207 glEnableClientState(GL_VERTEX_ARRAY); 208 glDrawArrays(GL_POINTS, 0, psys_width*psys_height); 209 //glDisableVertexAttribArray(0); 210 glDisableClientState(GL_VERTEX_ARRAY); 211 212 assert(glGetError()==0); 213 } 214 215 -
trunk/gui/vizservers/nanovis/ParticleSystem.h
r273 r274 25 25 #include "global.h" 26 26 27 #include "RenderVertexArray.h" 28 27 29 typedef struct Particle{ 28 30 float x; … … 42 44 NVISid psys_tex[2]; //color textures attached to frame buffer objects 43 45 44 int psys_width; //the storage of particles is implemented as a 2D array.45 int psys_height;46 46 Particle* data; 47 47 … … 50 50 bool flip; //flip the source and destination render targets 51 51 float max_life; 52 53 RenderVertexArray* m_vertex_array; //vertex array for display particles 52 54 53 55 //Nvidia CG shaders and their parameters … … 58 60 59 61 public: 62 int psys_width; //the storage of particles is implemented as a 2D array. 63 int psys_height; 64 60 65 ParticleSystem(int w, int h, CGcontext context, NVISid vector_field); 61 66 ~ParticleSystem(); 62 67 void initialize(Particle* data); 63 68 void advect(); 69 void update_vertex_buffer(); 70 void display_vertices(); 71 void reset(); 64 72 65 73 }; -
trunk/gui/vizservers/nanovis/nanovis.cpp
r273 r274 17 17 18 18 ParticleSystem* psys; 19 20 21 //particle system related variables 22 NVISid psys_fbo[2]; 23 NVISid psys_tex[2]; 24 int psys_width = NMESH; //particle system size 25 int psys_height = NMESH; 26 int psys_frame = 0; //count the frame number of particle system iteration 27 float psys_x =0.4, psys_y=0, psys_z=0; //particle initialization coordinates 28 int life = 30; //particle lifespan 29 bool reborn = true; //reinitiate particles 30 bool flip = true; //flip the source and destination render targets 31 19 float psys_x=0.4, psys_y=0, psys_z=0; 32 20 33 21 char* screen_buffer = new char[4*NPIX*NPIX+1]; //buffer to store data read from the screen … … 70 58 CGparameter m_mvp_vert_std_param; 71 59 CGparameter m_mvi_vert_std_param; 72 73 74 float m_pointsize = 1.0;75 float m_point_alpha;76 77 //RenderVertexArray78 RenderVertexArray* m_vertex_array;79 60 80 61 … … 125 106 126 107 127 128 //initialize particle system129 void init_psys(){130 131 glGenFramebuffersEXT(2, psys_fbo);132 glGenTextures(2, psys_tex);133 134 glBindFramebufferEXT(GL_FRAMEBUFFER_EXT, psys_fbo[0]);135 136 glBindTexture(GL_TEXTURE_RECTANGLE_NV, psys_tex[0]);137 glTexParameterf(GL_TEXTURE_RECTANGLE_NV, GL_TEXTURE_MIN_FILTER, GL_NEAREST);138 glTexParameterf(GL_TEXTURE_RECTANGLE_NV, GL_TEXTURE_MAG_FILTER, GL_NEAREST);139 glTexImage2D(GL_TEXTURE_RECTANGLE_NV, 0, GL_FLOAT_RGBA32_NV, psys_width, psys_height, 0, GL_RGBA, GL_FLOAT, NULL);140 glFramebufferTexture2DEXT(GL_FRAMEBUFFER_EXT, GL_COLOR_ATTACHMENT0_EXT, GL_TEXTURE_RECTANGLE_NV, psys_tex[0], 0);141 142 glBindFramebufferEXT(GL_FRAMEBUFFER_EXT, psys_fbo[1]);143 144 glBindTexture(GL_TEXTURE_RECTANGLE_NV, psys_tex[1]);145 glTexParameterf(GL_TEXTURE_RECTANGLE_NV, GL_TEXTURE_MIN_FILTER, GL_NEAREST);146 glTexParameterf(GL_TEXTURE_RECTANGLE_NV, GL_TEXTURE_MAG_FILTER, GL_NEAREST);147 glTexImage2D(GL_TEXTURE_RECTANGLE_NV, 0, GL_FLOAT_RGBA32_NV, psys_width, psys_height, 0, GL_RGBA, GL_FLOAT, NULL);148 glFramebufferTexture2DEXT(GL_FRAMEBUFFER_EXT, GL_COLOR_ATTACHMENT0_EXT, GL_TEXTURE_RECTANGLE_NV, psys_tex[1], 0);149 150 CHECK_FRAMEBUFFER_STATUS();151 assert(glGetError()==0);152 fprintf(stderr, "init_psys\n");153 }154 155 156 108 void load_volume(int index, int width, int height, int depth, int n_component, float* data); 157 158 109 159 110 … … 301 252 302 253 303 //initialize the vertex buffer object304 void init_vbo(){305 m_vertex_array = new RenderVertexArray(psys_width*psys_height, 3, GL_FLOAT);306 assert(glGetError()==0);307 }308 309 310 254 void makeMagnitudes(){ 311 255 GLubyte mag[NMESH][NMESH][4]; … … 399 343 void init_particles(){ 400 344 //random placement on a slice 401 float* data = new float[psys_width*psys_height*4]; 402 bzero(data, sizeof(float)*4*psys_width*psys_height); 403 for (int i=0; i<psys_width; i++){ 404 for (int j=0; j<psys_height; j++){ 405 int index = i + psys_height*j; 345 float* data = new float[psys->psys_width * psys->psys_height * 4]; 346 bzero(data, sizeof(float)*4* psys->psys_width * psys->psys_height); 347 348 for (int i=0; i<psys->psys_width; i++){ 349 for (int j=0; j<psys->psys_height; j++){ 350 int index = i + psys->psys_height*j; 406 351 bool particle = rand() % 256 > 100; 407 352 if(particle) 408 353 { 409 354 data[4*index] = psys_x; 410 data[4*index+1]= i/float(psys _width);411 data[4*index+2]= j/float(psys _height);412 data[4*index+3]= life;355 data[4*index+1]= i/float(psys->psys_width); 356 data[4*index+2]= j/float(psys->psys_height); 357 data[4*index+3]= 30; 413 358 } 414 359 else … … 423 368 424 369 psys->initialize((Particle*)data); 425 426 glBindTexture(GL_TEXTURE_RECTANGLE_NV, psys_tex[0]);427 glTexImage2D(GL_TEXTURE_RECTANGLE_NV, 0, GL_FLOAT_RGBA32_NV, psys_width, psys_height, 0, GL_RGBA, GL_FLOAT, data);428 429 flip = true;430 assert(glGetError()==0);431 432 370 delete[] data; 433 reborn = false;434 371 435 372 fprintf(stderr, "init particles\n"); 436 373 } 437 438 374 439 375 … … 482 418 init_vector_field(); //3d vector field 483 419 init_fbo(); //frame buffer objects 484 init_psys(); //particle system 485 init_cg(); //init cg shaders 486 init_vbo(); //init vertex buffer object 420 init_cg(); //init cg shaders 487 421 488 422 psys = new ParticleSystem(NMESH, NMESH, g_context, volume[0]->id); 489 490 423 init_particles(); //fill initial particles 424 491 425 get_slice_vectors(); 492 426 } … … 790 724 791 725 void soft_read_verts(){ 792 glReadPixels(0, 0, psys _width,psys_height, GL_RGB, GL_FLOAT, vert);726 glReadPixels(0, 0, psys->psys_width, psys->psys_height, GL_RGB, GL_FLOAT, vert); 793 727 //fprintf(stderr, "soft_read_vert"); 794 728 795 729 //cpu sort the distance 796 Particle* p = (Particle*) malloc(sizeof(Particle)* psys_width*psys_height);797 for(int i=0; i<psys _width*psys_height; i++){730 Particle* p = (Particle*) malloc(sizeof(Particle)* psys->psys_width * psys->psys_height); 731 for(int i=0; i<psys->psys_width * psys->psys_height; i++){ 798 732 float x = vert[3*i]; 799 733 float y = vert[3*i+1]; … … 807 741 } 808 742 809 qsort(p, psys _width*psys_height, sizeof(Particle), particle_distance_sort);810 811 for(int i=0; i<psys _width*psys_height; i++){743 qsort(p, psys->psys_width * psys->psys_height, sizeof(Particle), particle_distance_sort); 744 745 for(int i=0; i<psys->psys_width * psys->psys_height; i++){ 812 746 vert[3*i] = p[i].x; 813 747 vert[3*i+1] = p[i].y; … … 816 750 817 751 free(p); 818 }819 820 821 void hard_read_verts(){822 m_vertex_array->Read(psys_width, psys_height);823 //m_vertex_array->LoadData(vert); //does not work824 assert(glGetError()==0);825 }826 827 828 void sortstep();829 830 void advect_particles(){831 832 glDisable(GL_BLEND);833 834 if(flip)835 {836 837 glBindFramebufferEXT(GL_FRAMEBUFFER_EXT, psys_fbo[1]);838 glBindTexture(GL_TEXTURE_RECTANGLE_NV, psys_tex[0]);839 840 glClear(GL_COLOR_BUFFER_BIT);841 842 glViewport(0, 0, psys_width, psys_height);843 glMatrixMode(GL_PROJECTION);844 glLoadIdentity();845 gluOrtho2D(0, psys_width, 0, psys_height);846 glMatrixMode(GL_MODELVIEW);847 glLoadIdentity();848 849 cgGLBindProgram(m_pos_fprog);850 cgGLSetParameter1f(m_pos_timestep_param, 0.1);851 cgGLEnableTextureParameter(m_vel_tex_param);852 cgGLSetTextureParameter(m_pos_tex_param, psys_tex[0]);853 cgGLEnableTextureParameter(m_pos_tex_param);854 855 cgGLEnableProfile(CG_PROFILE_FP30);856 draw_quad(psys_width, psys_height, psys_width, psys_height);857 cgGLDisableProfile(CG_PROFILE_FP30);858 859 cgGLDisableTextureParameter(m_vel_tex_param);860 cgGLDisableTextureParameter(m_pos_tex_param);861 862 /*863 cgGLBindProgram(m_passthru_fprog);864 cgGLEnableProfile(CG_PROFILE_FP30);865 866 cgGLSetParameter4f(m_passthru_scale_param, 1.0, 1.0, 1.0, 1.0);867 cgGLSetParameter4f(m_passthru_bias_param, 0.0, 0.0, 0.0, 0.0);868 869 draw_quad(psys_width, psys_height, psys_width, psys_height);870 cgGLDisableProfile(CG_PROFILE_FP30);871 */872 873 }874 else875 {876 877 glBindFramebufferEXT(GL_FRAMEBUFFER_EXT, psys_fbo[0]);878 glBindTexture(GL_TEXTURE_RECTANGLE_NV, psys_tex[1]);879 880 glClear(GL_COLOR_BUFFER_BIT);881 882 glViewport(0, 0, psys_width, psys_height);883 glMatrixMode(GL_PROJECTION);884 glLoadIdentity();885 gluOrtho2D(0, psys_width, 0, psys_height);886 glMatrixMode(GL_MODELVIEW);887 glLoadIdentity();888 889 cgGLBindProgram(m_pos_fprog);890 cgGLSetParameter1f(m_pos_timestep_param, 0.1);891 cgGLEnableTextureParameter(m_vel_tex_param);892 cgGLSetTextureParameter(m_pos_tex_param, psys_tex[1]);893 cgGLEnableTextureParameter(m_pos_tex_param);894 895 cgGLEnableProfile(CG_PROFILE_FP30);896 draw_quad(psys_width, psys_height, psys_width, psys_height);897 cgGLDisableProfile(CG_PROFILE_FP30);898 899 cgGLDisableTextureParameter(m_vel_tex_param);900 cgGLDisableTextureParameter(m_pos_tex_param);901 902 /*903 cgGLBindProgram(m_passthru_fprog);904 cgGLEnableProfile(CG_PROFILE_FP30);905 906 cgGLSetParameter4f(m_passthru_scale_param, 1.0, 1.0, 1.0, 1.0);907 cgGLSetParameter4f(m_passthru_bias_param, 0.0, 0.0, 0.0, 0.0);908 909 draw_quad(psys_width, psys_height, psys_width, psys_height);910 cgGLDisableProfile(CG_PROFILE_FP30);911 */912 913 }914 915 assert(glGetError()==0);916 917 //soft_read_verts();918 919 hard_read_verts();920 921 flip = (!flip);922 923 psys_frame++;924 if(psys_frame==life){925 psys_frame=0;926 reborn = true;927 }928 929 fprintf(stderr, "advect: %d ", psys_frame);930 752 } 931 753 … … 960 782 961 783 962 //draw vertices in the onboard vertex buffer object963 void hard_display_verts(){964 glDisable(GL_TEXTURE_2D);965 glDisable(GL_BLEND);966 967 glPointSize(m_pointsize);968 glColor4f(.8,.8,.8,1.);969 970 m_vertex_array->SetPointer(0);971 //glEnableVertexAttribArray(0);972 glEnableClientState(GL_VERTEX_ARRAY);973 glDrawArrays(GL_POINTS, 0, psys_width*psys_height);974 //glDisableVertexAttribArray(0);975 glDisableClientState(GL_VERTEX_ARRAY);976 977 assert(glGetError()==0);978 }979 980 981 784 //draw vertices in the main memory 982 785 void soft_display_verts(){ … … 984 787 glEnable(GL_BLEND); 985 788 986 glPointSize( m_pointsize);789 glPointSize(0.5); 987 790 glColor4f(0,0.8,0.8,0.6); 988 791 glBegin(GL_POINTS); 989 for(int i=0; i<psys _width*psys_height; i++){792 for(int i=0; i<psys->psys_width * psys->psys_height; i++){ 990 793 glVertex3f(vert[3*i], vert[3*i+1], vert[3*i+2]); 991 794 } … … 1331 1134 glEnd(); 1332 1135 1333 1334 advect_particles();1136 //advect particles 1137 psys->advect(); 1335 1138 1336 1139 final_fbo_capture(); 1337 1140 1338 /*1339 if(flip)1340 display_texture(psys_tex[1], psys_width, psys_height);1341 else1342 display_texture(psys_tex[0], psys_width, psys_height);1343 */1344 1345 1141 //display_texture(slice_vector_tex, NMESH, NMESH); 1346 1142 … … 1395 1191 1396 1192 //soft_display_verts(); 1397 hard_display_verts();1193 psys->display_vertices(); 1398 1194 1399 1195 //render volume … … 1405 1201 display_final_fbo(); 1406 1202 1407 //rebirth1408 if(reborn){1409 init_particles();1410 }1411 1203 glutSwapBuffers(); 1412 1204 }
Note: See TracChangeset
for help on using the changeset viewer.