Changeset 5481


Ignore:
Timestamp:
May 9, 2015, 1:37:21 PM (9 years ago)
Author:
ldelgass
Message:

Merge (manual) ParticleRenderer? changes from trunk

Location:
nanovis/branches/1.2
Files:
2 edited

Legend:

Unmodified
Added
Removed
  • nanovis/branches/1.2/ParticleRenderer.cpp

    r5397 r5481  
    1313#include <GL/glew.h>
    1414
     15#include <vrmath/Vector3f.h>
    1516#include <vrmath/Color4f.h>
    1617
    1718#include "ParticleRenderer.h"
     19#include "Volume.h"
    1820#include "define.h"
    1921#include "Trace.h"
    2022
     23using namespace vrmath;
    2124using namespace nv;
    22 
    23 ParticleAdvectionShader *ParticleRenderer::_advectionShader = NULL;
    24 ParticleAdvectionShaderInstance shaderInstance;
    2525
    2626ParticleRenderer::ParticleRenderer(int w, int h) :
    2727    _initPosTex(0),
    2828    _data(NULL),
    29     _psysFrame(0U),
     29    _psysFrame(0),
    3030    _reborn(true),
    3131    _flip(true),
    32     _maxLife(500U),
     32    _maxLife(500),
    3333    _particleSize(1.2),
    3434    _vertexArray(NULL),
     
    4343{
    4444    _data = new Particle[w * h];
    45     memset(_data, 0, sizeof(Particle) * w * h);
    4645
    4746    _vertexArray = new RenderVertexArray(_psysWidth * _psysHeight, 3, GL_FLOAT);
     
    104103#endif
    105104
    106     if (_advectionShader == NULL) {
    107         _advectionShader = new ParticleAdvectionShader();
    108     }
     105    _advectionShader = new ParticleAdvectionShader();
    109106}
    110107
     
    121118    glDeleteFramebuffersEXT(2, _psysFbo);
    122119
     120    delete _advectionShader;
    123121    delete _vertexArray;
    124122    delete [] _data;
     
    128126ParticleRenderer::initializeDataArray()
    129127{
    130     size_t n = _psysWidth * _psysHeight * 4;
    131     memset(_data, 0, sizeof(float)* n);
    132 
    133     int index;
    134     bool particle;
    135     float *p = (float *)_data;
     128    TRACE("Enter axis: %d pos: %g", _sliceAxis, _slicePos);
     129
     130    memset(_data, 0, sizeof(Particle) * _psysWidth * _psysHeight);
     131
     132    bool hasParticle;
    136133    for (int i = 0; i < _psysWidth; i++) {
    137134        for (int j = 0; j < _psysHeight; j++) {
    138             index = i + _psysHeight*j;
    139             particle = (rand() % 256) > 150;
    140             if (particle) {
     135            Particle *p = &_data[i + _psysHeight*j];
     136            hasParticle = (rand() % 256) > 150;
     137            if (hasParticle) {
    141138                //assign any location (x,y,z) in range [0,1]
    142139                switch (_sliceAxis) {
    143140                case AXIS_X:
    144                     p[4*index]   = _slicePos;
    145                     p[4*index+1] = j/float(_psysHeight);
    146                     p[4*index+2] = i/float(_psysWidth);
     141                    p->x   = _slicePos;
     142                    p->y = j/float(_psysHeight);
     143                    p->z = i/float(_psysWidth);
    147144                    break;
    148145                case AXIS_Y:
    149                     p[4*index]  = j/float(_psysHeight);
    150                     p[4*index+1] = _slicePos;
    151                     p[4*index+2] = i/float(_psysWidth);
     146                    p->x = j/float(_psysHeight);
     147                    p->y = _slicePos;
     148                    p->z = i/float(_psysWidth);
    152149                    break;
    153150                case AXIS_Z:
    154                     p[4*index]  = j/float(_psysHeight);
    155                     p[4*index+1] = i/float(_psysWidth);
    156                     p[4*index+2] = _slicePos;
     151                    p->x = j/float(_psysHeight);
     152                    p->y = i/float(_psysWidth);
     153                    p->z = _slicePos;
    157154                    break;
    158155                default:
    159                     p[4*index]   = 0;
    160                     p[4*index+1] = 0;
    161                     p[4*index+2] = 0;
    162                     p[4*index+3] = 0;
     156                    ERROR("Unknown axis");
    163157                }
    164 
    165158                //shorter life span, quicker iterations
    166                 p[4*index+3] = rand() / ((float) RAND_MAX) * 0.5  + 0.5f;
    167             } else {
    168                 p[4*index]   = 0;
    169                 p[4*index+1] = 0;
    170                 p[4*index+2] = 0;
    171                 p[4*index+3] = 0;
     159                p->life = rand() / ((float) RAND_MAX) * 0.5  + 0.5f;
    172160            }
    173161        }
     
    178166ParticleRenderer::initialize()
    179167{
     168    TRACE("Enter");
     169
    180170    initializeDataArray();
    181171
     
    192182    _flip = true;
    193183    _reborn = false;
     184    _psysFrame = 0;
    194185
    195186    glBindTexture(GL_TEXTURE_RECTANGLE_ARB, _initPosTex);
     
    220211    _flip = true;
    221212    _reborn = false;
    222     _psysFrame = 0U;
     213    _psysFrame = 0;
    223214}
    224215
     
    226217ParticleRenderer::advect()
    227218{
     219    TRACE("Enter");
     220
    228221    if (_reborn)
    229222        reset();
     
    281274    _psysFrame++;
    282275    if (_psysFrame == _maxLife) {
    283         _psysFrame = 0U;
    284         // _reborn = true;
     276        //_psysFrame = 0;
     277        //_reborn = true;
    285278    }
    286279    glBindFramebufferEXT(GL_FRAMEBUFFER_EXT, fboOrig);
     
    293286{
    294287    _vertexArray->read(_psysWidth, _psysHeight);
    295 
    296     //_vertexArray->loadData(vert);     //does not work??
    297     //assert(glGetError()==0);
    298288}
    299289
     
    301291ParticleRenderer::render()
    302292{
     293    if (_psysFrame == 0) {
     294        TRACE("Initializing vertex array");
     295        advect();
     296    }
     297
    303298    glPushAttrib(GL_ENABLE_BIT);
    304299    glDisable(GL_TEXTURE_2D);
     
    340335ParticleRenderer::setSliceAxis(FlowSliceAxis axis)
    341336{
    342     _sliceAxis = axis;
    343     initializeDataArray();
     337    if (axis != _sliceAxis) {
     338        _sliceAxis = axis;
     339        initialize();
     340    }
    344341}
    345342
     
    347344ParticleRenderer::setSlicePosition(float pos)
    348345{
    349     _slicePos = pos;
    350     initializeDataArray();
    351 }
     346    if (pos != _slicePos) {
     347        _slicePos = pos;
     348        initialize();
     349    }
     350}
  • nanovis/branches/1.2/ParticleRenderer.h

    r4904 r5481  
    1515
    1616#include "FlowTypes.h"
     17#include "Volume.h"
    1718#include "ParticleAdvectionShader.h"
    1819#include "RenderVertexArray.h"
     
    9495    }
    9596
    96    static ParticleAdvectionShader *_advectionShader;
    97 
    9897private:
    9998    void initializeDataArray();
    10099
    101100    void updateVertexBuffer();
     101
     102    ParticleAdvectionShader *_advectionShader;
    102103
    103104    /// frame buffer objects: two are defined, flip them as input output every step
     
    143144};
    144145
    145 class ParticleAdvectionShaderInstance
    146 {
    147 public :
    148     ParticleAdvectionShaderInstance()
    149     {}
    150 
    151     ~ParticleAdvectionShaderInstance()
    152     {
    153         if (ParticleRenderer::_advectionShader) {
    154             delete ParticleRenderer::_advectionShader;
    155         }
    156     }
    157 };
    158 
    159146}
    160147
Note: See TracChangeset for help on using the changeset viewer.