Changeset 271

Show
Ignore:
Timestamp:
10/10/06 18:01:16 (2 years ago)
Author:
dshipton
Message:

Add in pixel coverage info.

Files:

Legend:

Unmodified
Added
Removed
Modified
Copied
Moved
  • branches/Dirk_RenderTraversalWork/Source/System/Action/RenderTraversal/OSGOcclusionCullingTreeBuilder.cpp

    r268 r271  
    5454#include "OSGRenderPartition.h" 
    5555#include "OSGRenderTraversalAction.h" 
     56#include "OSGVolumeDraw.h" 
    5657 
    5758//#define OSG_DUMP_SORTING 
     
    132133    UInt32 current_node = 1; 
    133134    GLuint queries[uNumNodes]; 
    134     std::cout << "Submitting " << uNumNodes << " queries" << std::endl; 
     135    //std::cout << "Submitting " << uNumNodes << " queries" << std::endl; 
    135136 
    136137    GenQueryT genquer = (GenQueryT)win->getFunction(_funcGenQueriesARB); 
     
    138139     
    139140    //glGenQueriesARB(uNumNodes, queries); 
     141    std::cout << "Calculated Pixels" << std::endl; 
    140142    drawNode(_pRoot, denv, part, screen_covered_percentage, current_node, queries); 
    141     std::cout << "Calc Pixels" << std::endl; 
     143    //std::cout << "Calc Pixels" << std::endl; 
    142144 
    143145    GetQueryObjectuivT getquiv =  
     
    148150    sc->getElem(statNOccInvisible)->set(0); // Just create it 
    149151     
     152    std::cout << std::endl; 
     153    std::cout << "Real pixels " << std::endl; 
    150154    for(UInt32 i = 1; i<uNumNodes; i++) 
    151155    { 
    152156        GLuint available = 0; 
    153157        getquiv(queries[i], GL_QUERY_RESULT_AVAILABLE_ARB, &available); 
     158        /* 
     159        if (!available) 
     160        { 
     161            std::cout << std::endl << "Waiting on " << i << "th query"; 
     162        }  
     163        */ 
    154164        while (!available) 
    155165        { 
    156          std::cout << "Waiting on " << i << "th query" << std::endl; 
    157          getquiv(queries[i], GL_QUERY_RESULT_AVAILABLE_ARB, &available); 
    158          //glGetQueryObjectivARB(queries[i], GL_QUERY_RESULT_AVAILABLE_ARB, &available); 
    159         } 
     166            //std::cout << "."; 
     167            getquiv(queries[i], GL_QUERY_RESULT_AVAILABLE_ARB, &available); 
     168            //glGetQueryObjectivARB(queries[i], GL_QUERY_RESULT_AVAILABLE_ARB, &available); 
     169            /* 
     170            if(available) 
     171            { 
     172                std::cout << std::endl; 
     173            } 
     174            */ 
     175        } 
     176         
    160177        GLuint sampleCount = 0; 
    161178        getquiv(queries[i], GL_QUERY_RESULT_ARB, &sampleCount); 
     
    177194    while (pNode != NULL) 
    178195    { 
    179         Int32 pix_width = denv.getViewport()->getPixelWidth(); 
    180         Int32 pix_height = denv.getViewport()->getPixelHeight(); 
     196        Viewport* vp = denv.getViewport(); 
     197        Int32 pix_width = vp->getPixelWidth(); 
     198        Int32 pix_height = vp->getPixelHeight(); 
     199 
     200        Matrix worldToCam; 
     201        vp->getCamera()->getWorldToScreen(worldToCam, *vp); 
     202 
    181203 
    182204        UInt32 uiNextMatrix = pNode->getMatrixStore().first; 
     
    218240            } 
    219241        } 
    220  
     242        DynamicVolume volume = pNode->getVol(); 
     243        Pnt3r min,max; 
     244        //volume.transform(_accMatrix); 
     245        volume.getBounds(min, max); 
     246        Pnt3r p[8]; 
     247        p[0].setValues(min[0],min[1],min[2]); 
     248        p[1].setValues(max[0],min[1],min[2]); 
     249        p[2].setValues(min[0],max[1],min[2]); 
     250        p[3].setValues(min[0],min[1],max[2]); 
     251        p[4].setValues(max[0],max[1],min[2]); 
     252        p[5].setValues(max[0],min[1],max[2]); 
     253        p[6].setValues(min[0],max[1],max[2]); 
     254        p[7].setValues(max[0],max[1],max[2]); 
     255         
     256        //std::cout << "OtoW:" << std::endl; 
     257        //std::cout << denv.getObjectToWorld() << std::endl; 
     258        //std::cout << "WtoC:" << std::endl; 
     259        //std::cout << worldToCam << std::endl; 
     260        for(UInt32 i = 0; i<8;i++) 
     261        { 
     262           // std::cout << p[i] << "=>"; 
     263            denv.getObjectToWorld().mult(p[i]); 
     264            worldToCam.multFullMatrixPnt(p[i]); 
     265            //std::cout << p[i] << "  "; 
     266        } 
     267        min=p[0]; 
     268        max=p[0]; 
     269        for(UInt32 i = 0; i<8; i++) 
     270        { 
     271           for(UInt32 j=0; j<2; j++) 
     272           { 
     273              if(p[i][j] < min[j]) 
     274              { 
     275                min[j] = p[i][j]; 
     276              } 
     277              if(p[i][j] > max[j]) 
     278              { 
     279                max[j] = p[i][j]; 
     280              } 
     281           } 
     282        } 
     283        max[0] = osgClamp(-1.f, max[0], 1.f); 
     284        max[1] = osgClamp(-1.f, max[1], 1.f); 
     285        min[0] = osgClamp(-1.f, min[0], 1.f); 
     286        min[1] = osgClamp(-1.f, min[1], 1.f); 
     287        //std::cout << min << std::endl; 
     288        //std::cout << max << std::endl; 
     289        //v.transform(worldToCam); 
     290        Real32 pix; 
     291        pix = (max[0] - min[0]) * (max[1] - min[1]) * ((pix_width/2.0f)*(pix_height/2.0f)); 
     292         
     293        std::cout << cur_node << ":" << pix << " "; 
     294 //       std::cout << max - min << std::endl; 
     295 
     296         
    221297        State         *pNewState         = pNode->getState(); 
    222298        StateOverride *pNewStateOverride = pNode->getStateOverride(); 
     
    226302        Window* win = denv.getWindow(); 
    227303         
    228         BeginQueryT beginq = (BeginQueryT) win->getFunction(_funcBeginQueryARB); 
    229         beginq(GL_SAMPLES_PASSED_ARB, queries[cur_node]); 
    230304        //glBeginQueryARB(GL_SAMPLES_PASSED_ARB, queries[cur_node]); 
    231  
    232305        if(pNode->hasFunctor() == true) 
    233             pNode->getFunctor()(&denv); 
    234          
    235         EndQueryT endq = (EndQueryT) win->getFunction(_funcEndQueryARB);                
    236         endq(GL_SAMPLES_PASSED_ARB); 
    237         //glEndQueryARB(GL_SAMPLES_PASSED_ARB); 
    238  
    239         cur_node++; 
     306        { 
     307            std::cout << " D "; 
     308            BeginQueryT beginq = (BeginQueryT) win->getFunction(_funcBeginQueryARB); 
     309            beginq(GL_SAMPLES_PASSED_ARB, queries[cur_node]); 
     310            if(1) 
     311            { 
     312            //glPushMatrix(); 
     313            //glLoadIdentity(); 
     314            //glMatrixMode(GL_PROJECTION); 
     315            //GLfloat m[16]; 
     316            //glGetFloatv(GL_PROJECTION_MATRIX, m); 
     317            //glLoadIdentity(); 
     318            //glOrtho(-1,1,-1,1,-1,1); 
     319             
     320            volume.getBounds(min, max); 
     321            static GLdouble n[6][3] = { 
     322            {-1.0, 0.0, 0.0}, {0.0, 1.0, 0.0}, {1.0, 0.0, 0.0}, 
     323            {0.0, -1.0, 0.0}, {0.0, 0.0, 1.0}, {0.0, 0.0, -1.0} 
     324            }; 
     325            static GLint faces[6][4] = { 
     326            { 0, 1, 2, 3}, { 3, 2, 6, 7}, { 7, 6, 5, 4}, 
     327            { 4, 5, 1, 0}, { 5, 6, 2, 1}, { 7, 4, 0, 3} 
     328            }; 
     329             
     330            GLdouble v[8][3]; 
     331            v[0][0] = v[1][0] = v[2][0] = v[3][0] = min[0]; 
     332            v[4][0] = v[5][0] = v[6][0] = v[7][0] = max[0]; 
     333            v[0][1] = v[1][1] = v[4][1] = v[5][1] = min[1]; 
     334            v[2][1] = v[3][1] = v[6][1] = v[7][1] = max[1]; 
     335            v[0][2] = v[3][2] = v[4][2] = v[7][2] = min[2]; 
     336            v[1][2] = v[2][2] = v[5][2] = v[6][2] = max[2]; 
     337            glColor3f(0.3,0.4,0.6); 
     338            for(UInt32 i = 0; i<6; i++) 
     339            { 
     340                glBegin(GL_QUADS); 
     341                    glNormal3dv(&n[i][0]); 
     342                    glVertex3dv(&v[faces[i][0]][0]); 
     343                    glNormal3dv(&n[i][0]); 
     344                    glVertex3dv(&v[faces[i][1]][0]); 
     345                    glNormal3dv(&n[i][0]); 
     346                    glVertex3dv(&v[faces[i][2]][0]); 
     347                    glNormal3dv(&n[i][0]); 
     348                    glVertex3dv(&v[faces[i][3]][0]); 
     349                glEnd(); 
     350            } 
     351            //glLoadMatrixf(m); 
     352            //glMatrixMode(GL_MODELVIEW); 
     353            //glPopMatrix(); 
     354            } 
     355            else 
     356            { 
     357                drawVolume(volume); 
     358                pNode->getFunctor()(&denv); 
     359            } 
     360 
     361            EndQueryT endq = (EndQueryT) win->getFunction(_funcEndQueryARB);                
     362            endq(GL_SAMPLES_PASSED_ARB); 
     363            //glEndQueryARB(GL_SAMPLES_PASSED_ARB); 
     364            cur_node++; 
     365        } 
     366         
     367 
    240368 
    241369        if(pNode->getFirstChild() != NULL) 
     
    261389    { 
    262390        _pRoot->addChild(pNode); 
     391        uNumNodes++; 
    263392    } 
    264393    else 
     
    294423                _pRoot->insertChildAfter(pLast, pNode); 
    295424            } 
     425            uNumNodes++; 
    296426        } 
    297427        else 
    298428        { 
    299429            _pRoot->addChild(pNode); 
    300         } 
    301     } 
    302     uNumNodes++; 
     430            uNumNodes++; 
     431        } 
     432    } 
     433     
    303434} 
    304435 
  • branches/Dirk_RenderTraversalWork/Source/System/Action/RenderTraversal/OSGRenderPartition.cpp

    r268 r271  
    523523        _currMatrix.second.mult(objPos); 
    524524 
    525         Real32        objVol; 
    526         objVol = _oDrawEnv.getRTAction()->getActNode()->getVolume().getScalarVolume(); 
    527         pNewElem->setBBC        ( objVol ); 
     525        DynamicVolume     objVol; 
     526        objVol = _oDrawEnv.getRTAction()->getActNode()->getVolume(); 
     527        //objVol.transform(_currMatrix.second); 
     528        pNewElem->setVol        ( objVol ); 
    528529 
    529530        pNewElem->setFunctor    ( func      ); 
  • branches/Dirk_RenderTraversalWork/Source/System/Action/RenderTraversal/OSGRenderTreeNode.cpp

    r267 r271  
    6666    _oMatrixStore  (     ), 
    6767    _rScalarVal    (0.f  ), 
    68     _rBBCVal       (0.f  ), 
    6968    _lightsState   (0    ) 
    7069{ 
  • branches/Dirk_RenderTraversalWork/Source/System/Action/RenderTraversal/OSGRenderTreeNode.h

    r267 r271  
    101101    Real32          getScalar       (void                             ); 
    102102 
    103     void            setBBC       (Real32             rBBC       ); 
    104     Real32          getBBC       (void                             ); 
     103    void            setVol       (DynamicVolume             vol       ); 
     104    DynamicVolume   getVol       (void                             ); 
    105105 
    106106    void            setLightsState  (UInt64             state         ); 
     
    133133    Real32          _rScalarVal; 
    134134 
    135     Real32         _rBBCVal; 
     135    DynamicVolume   _dVol; 
    136136 
    137137    UInt64          _lightsState; 
  • branches/Dirk_RenderTraversalWork/Source/System/Action/RenderTraversal/OSGRenderTreeNode.inl

    r267 r271  
    195195 
    196196inline 
    197 void RenderTreeNode::setBBC(Real32 rBBC
    198 { 
    199     _rBBCVal = rBBC
    200 } 
    201  
    202 inline 
    203 Real32 RenderTreeNode::getBBC(void) 
    204 { 
    205     return _rBBCVal; 
     197void RenderTreeNode::setVol(DynamicVolume vol
     198{ 
     199    _dVol = vol
     200} 
     201 
     202inline 
     203DynamicVolume RenderTreeNode::getVol(void) 
     204{ 
     205    return _dVol; 
    206206} 
    207207 
     
    233233    _rScalarVal  = 0.f; 
    234234 
    235     _rBBCVal     = 0.f; 
    236  
    237235    _lightsState = 0; 
    238236}