Ignore:
Timestamp:
06/27/08 01:43:45 (16 years ago)
Author:
mattausch
Message:

friendly culling debug version with timers, no materials

File:
1 edited

Legend:

Unmodified
Added
Removed
  • GTP/trunk/App/Demos/Vis/FriendlyCulling/src/SceneQuery.cpp

    r2797 r2800  
    55#include "SceneQuery.h" 
    66#include "RenderTraverser.h" 
     7#include <IL/il.h> 
     8#include <assert.h> 
    79 
    810 
    9 void startil(); 
    10 void stopil(); 
     11void startil() 
     12{ 
     13        ilInit(); 
     14        assert(ilGetError() == IL_NO_ERROR); 
     15} 
     16 
     17 
     18void stopil() 
     19{ 
     20        ilShutDown(); 
     21        assert(ilGetError() == IL_NO_ERROR); 
     22} 
    1123 
    1224 
     
    1729 
    1830 
    19 const static int viewport[4] = {0, 0, 512, 512}; 
    20 //const static int viewport[4] = {0, 0, 1024, 768}; 
     31//const static int viewport[4] = {0, 0, 512, 512}; 
     32const static int viewport[4] = {0, 0, 1024, 768}; 
     33//const static int viewport[4] = {0, 0, 2048, 2048}; 
    2134 
    2235 
     
    3447        int py = (pt.y - mSceneBox.Min(1)) * (viewport[3] - 1) / mSceneBox.Size(1); 
    3548 
    36         const float d = mDepth[px + py * viewport[1]]; 
     49        unsigned char d = mDepth[px + py * viewport[2]]; 
    3750 
    38         if (d > 0.0f) 
     51        const float offs = mSceneBox.Size(2) * 1e-1f; 
     52 
     53        static float depth = (float)d; 
     54 
     55        if (d > 0) 
    3956        { 
    40                 pt.z =  mSceneBox.Max().z - mSceneBox.Size().z * d; 
    41                 cout << "new depth " << pt.z << " (" << d << ")" << endl; 
     57                const float x = 0.1f; 
     58                depth = depth * x + d * (1.0f - x); 
     59                pt.z =  mSceneBox.Max().z - mSceneBox.Size().z * depth / 255.0f + offs; 
     60                //cout << "new depth " << pt.z << " (" << d << ")" << endl; 
    4261 
    4362                return true; 
    4463        } 
     64        //cout << "invalid depth: " << d << endl; 
    4565 
    4666        return false; 
     
    6585 
    6686        //glPixelStorei(GL_PACK_ROW_LENGTH, viewport[2]); 
     87        glPixelStorei(GL_PACK_ALIGNMENT, 1); 
     88        glReadBuffer(GL_BACK); 
    6789 
    6890        // hack: should create offscreen buffer for this 
     
    80102        glClear(GL_DEPTH_BUFFER_BIT); 
    81103 
    82         mDepth = new float[viewport[2] * viewport[3]]; 
     104        mDepth = new unsigned char[viewport[2] * viewport[3]]; 
     105        //mDepth = new float[viewport[2] * viewport[3]]; 
    83106 
    84107        //renderer->SetCamera(orthoCam); 
     
    86109        renderer->RenderScene(); 
    87110 
    88         glReadPixels(0, 0, viewport[2], viewport[3], GL_DEPTH_COMPONENT, GL_FLOAT, mDepth); 
     111        glReadPixels(0, 0, viewport[2], viewport[3], GL_DEPTH_COMPONENT, GL_UNSIGNED_BYTE, mDepth); 
     112        //glReadPixels(0, 0, viewport[2], viewport[3], GL_DEPTH_COMPONENT, GL_FLOAT, mDepth); 
     113/* 
     114        startil(); 
    89115 
     116        if (!ilTexImage(viewport[2], viewport[3], 1, 1, IL_LUMINANCE, IL_UNSIGNED_BYTE, mDepth)) 
     117        { 
     118                cerr << "IL error " << ilGetError() << endl; 
     119                stopil(); 
     120                return; 
     121        } 
     122 
     123        ILstring writename = ILstring("out.tga"); 
     124 
     125        ilSetInteger(IL_TGA_RLE, 1); 
     126        if (!ilSaveImage(writename)) 
     127        { 
     128                cerr << "TGA write error " << ilGetError() << endl; 
     129        } 
     130 
     131        stopil(); 
     132*/ 
    90133        DEL_PTR(orthoCam); 
    91134} 
Note: See TracChangeset for help on using the changeset viewer.