Changeset 347 for trunk/thune/gl

Show
Ignore:
Timestamp:
01/20/07 05:28:58 (2 years ago)
Author:
krobillard
Message:

Thune GL - Shadowmap working, imported shaders, updated atoms.

Location:
trunk/thune/gl
Files:
20 added
5 modified

Legend:

Unmodified
Added
Removed
  • trunk/thune/gl/draw_list.c

    r331 r347  
    336336} 
    337337#endif 
     338 
     339 
     340static GLfloat* _cameraMatrix = 0; 
    338341 
    339342 
     
    384387        if( ur_is(val, UT_VECTOR) && (ur_vectorDT(val) == UT_DECIMAL) ) 
    385388        { 
     389            // glLoadTransposeMatrixf() could be used in GL 2.0? 
    386390            GLfloat eye[16]; 
    387391            UBinary* arr = ur_bin(val); 
    388392            if( arr->used == 16 ) 
    389393            { 
     394                _cameraMatrix = arr->ptr.f; 
    390395                ur_matrixInverse( eye, arr->ptr.f ); 
    391396                glLoadMatrixf( eye ); 
     
    484489 
    485490#if 1 
     491#define SHADOW_BACK_FACES   1 
     492 
     493static GLdouble lightViewMatrix[ 16 ]; 
     494static GLdouble lightProjMatrix[ 16 ]; 
     495 
     496 
     497/* 
     498   Camera must be set up for light before calling shadow-begin. 
     499*/ 
     500static void dop_shadow_begin( /*UThread* ur_thread,*/ UCell* fbCell ) 
     501{ 
     502    // Save matrices for shadow-end. 
     503    glGetDoublev( GL_MODELVIEW_MATRIX, lightViewMatrix ); 
     504    glGetDoublev( GL_PROJECTION_MATRIX, lightProjMatrix ); 
     505 
     506 
     507    glDepthMask( GL_TRUE ); 
     508    glEnable( GL_DEPTH_TEST ); 
     509    glDisable( GL_LIGHTING ); 
     510    glDisable( GL_BLEND ); 
     511    gr_disableTexture(); 
     512 
     513 
     514    glBindFramebufferEXT( GL_FRAMEBUFFER_EXT, ur_fboId(fbCell) ); 
     515    glClear( GL_DEPTH_BUFFER_BIT ); 
     516 
     517#ifdef SHADOW_BACK_FACES 
     518    glEnable( GL_CULL_FACE ); 
     519    glCullFace( GL_FRONT ); 
     520#else 
     521    glEnable( GL_POLYGON_OFFSET_FILL ); 
     522    //glPolygonOffset( polygon_offset_scale, polygon_offset_bias ); 
     523    //glPolygonOffset( 2.0f, 10.0f ); 
     524    glPolygonOffset( 2.0f, 4.0f ); 
     525#endif 
     526} 
     527 
     528 
    486529// Transform from -1..1 to 0..1 
    487530const GLdouble bias[] = 
     
    492535    0.5, 0.5, 0.5, 1.0 
    493536}; 
    494  
    495  
    496 GLdouble lightModelMatrix[ 16 ]; 
    497 GLdouble lightProjMatrix[ 16 ]; 
    498  
    499 //#define SHADOW_BACK_FACES   1 
    500  
    501 static void dop_shadow_begin( /*UThread* ur_thread,*/ UCell* fbCell ) 
    502 { 
    503     glGetDoublev( GL_MODELVIEW_MATRIX, lightModelMatrix ); 
    504     glGetDoublev( GL_PROJECTION_MATRIX, lightProjMatrix ); 
    505  
    506  
    507     glBindFramebufferEXT( GL_FRAMEBUFFER_EXT, ur_fboId(fbCell) ); 
    508     glClear( GL_DEPTH_BUFFER_BIT ); 
    509  
    510 #ifdef SHADOW_BACK_FACES 
    511     glEnable( GL_CULL_FACE ); 
    512     glCullFace( GL_FRONT ); 
    513 #else 
    514     //glPolygonOffset( polygon_offset_scale, polygon_offset_bias ); 
    515     glPolygonOffset( 2.0f, 10.0f ); 
    516     //glPolygonOffset( 2.0f, 2.0f ); 
    517     glEnable( GL_POLYGON_OFFSET_FILL ); 
    518 #endif 
    519  
    520  
    521 #if 0 
    522     glMatrixMode( GL_TEXTURE ); 
    523     glLoadIdentity(); 
    524     glMatrixMode( GL_MODELVIEW ); 
    525 #endif 
    526  
    527 } 
    528537 
    529538 
     
    538547 
    539548 
    540     //glActiveTextureARB(GL_TEXTURE1_ARB); 
    541  
     549    glActiveTextureARB( GL_TEXTURE1 ); 
    542550    glMatrixMode( GL_TEXTURE ); 
     551 
     552#if 1 
    543553    glLoadMatrixd( bias ); 
    544 #if 0 
    545     gluPerspective( fov, 1, near, far ); 
    546554#else 
     555    glLoadIdentity(); 
     556#endif 
    547557    glMultMatrixd( lightProjMatrix ); 
    548     glMultMatrixd( lightModelMatrix ); 
    549 #endif 
     558    glMultMatrixd( lightViewMatrix ); 
     559    //glMultMatrixf( _cameraMatrix ); 
     560 
    550561    glMatrixMode( GL_MODELVIEW ); 
    551  
    552     //glActiveTextureARB(GL_TEXTURE0_ARB); 
     562    glActiveTextureARB( GL_TEXTURE0 ); 
    553563} 
    554564#endif 
  • trunk/thune/gl/gx.t

    r331 r347  
    5252context :widget-proto 
    5353 
     54 
     55/* 
     56[ 
     57    none  :value 
     58    0.0   :time 
     59    'loop :repeat 
     60    none  :curve 
     61] 
     62context :anim-proto 
     63 
     64[ 
     65    0.0,0,0 :p1 
     66    0.0,0,0 :p2 
     67    1.0  :radius 
     68    none :mesh 
     69    -1   :mask 
     70    []   :hits 
     71] 
     72context :hit-input 
     73*/ 
    5474 
    5575[ 
  • trunk/thune/gl/gx_atoms.h

    r331 r347  
    11// This file is automatically generated - do not edit. 
    22 
    3 #define UR_ATOM_DRAW_LIST_OPCODES               303 
    4 #define UR_ATOM_WIDTH           304 
    5 #define UR_ATOM_HEIGHT          305 
    6 #define UR_ATOM_AREA            306 
    7 #define UR_ATOM_RECT            307 
    8 #define UR_ATOM_RASTER          308 
    9 #define UR_ATOM_TEXTURE         309 
    10 #define UR_ATOM_ELEM            310 
    11 #define UR_ATOM_CLOSE           171 
    12 #define UR_ATOM_FOCUS           311 
    13 #define UR_ATOM_RESIZE          312 
    14 #define UR_ATOM_KEY_DOWN                313 
    15 #define UR_ATOM_KEY_UP          314 
    16 #define UR_ATOM_MOUSE_MOVE              315 
    17 #define UR_ATOM_MOUSE_UP                316 
    18 #define UR_ATOM_MOUSE_DOWN              317 
    19 #define UR_ATOM_MOUSE_WHEEL             318 
    20 #define UR_ATOM_AMBIENT         319 
    21 #define UR_ATOM_DIFFUSE         320 
    22 #define UR_ATOM_SPECULAR                321 
    23 #define UR_ATOM_POS             322 
    24 #define UR_ATOM_SHADER          323 
    25 #define UR_ATOM_VERTEX          324 
    26 #define UR_ATOM_FRAGMENT                325 
    27 #define UR_ATOM_DEFAULT         326 
    28 #define UR_ATOM_RGB             327 
    29 #define UR_ATOM_RGBA            328 
    30 #define UR_ATOM_DEPTH           329 
    31 #define UR_ATOM_CLAMP           330 
    32 #define UR_ATOM_REPEAT          331 
    33 #define UR_ATOM_NEAREST         332 
    34 #define UR_ATOM_LINEAR          333 
    35 #define UR_ATOM_MIN             334 
    36 #define UR_ATOM_MAG             335 
    37 #define UR_ATOM_MIPMAP          336 
    38 #define UR_ATOM_ON              247 
    39 #define UR_ATOM_OFF             249 
    40 #define UR_ATOM_ADD             190 
    41 #define UR_ATOM_BURN            337 
    42 #define UR_ATOM_COLOR           338 
    43 #define UR_ATOM_TRANS           339 
     3#define UR_ATOM_DRAW_LIST_OPCODES               307 
     4#define UR_ATOM_WIDTH           308 
     5#define UR_ATOM_HEIGHT          309 
     6#define UR_ATOM_AREA            310 
     7#define UR_ATOM_RECT            311 
     8#define UR_ATOM_RASTER          312 
     9#define UR_ATOM_TEXTURE         313 
     10#define UR_ATOM_ELEM            314 
     11#define UR_ATOM_CLOSE           172 
     12#define UR_ATOM_FOCUS           315 
     13#define UR_ATOM_RESIZE          316 
     14#define UR_ATOM_KEY_DOWN                317 
     15#define UR_ATOM_KEY_UP          318 
     16#define UR_ATOM_MOUSE_MOVE              319 
     17#define UR_ATOM_MOUSE_UP                320 
     18#define UR_ATOM_MOUSE_DOWN              321 
     19#define UR_ATOM_MOUSE_WHEEL             322 
     20#define UR_ATOM_AMBIENT         323 
     21#define UR_ATOM_DIFFUSE         324 
     22#define UR_ATOM_SPECULAR                325 
     23#define UR_ATOM_POS             326 
     24#define UR_ATOM_SHADER          327 
     25#define UR_ATOM_VERTEX          328 
     26#define UR_ATOM_FRAGMENT                329 
     27#define UR_ATOM_DEFAULT         330 
     28#define UR_ATOM_RGB             331 
     29#define UR_ATOM_RGBA            332 
     30#define UR_ATOM_DEPTH           333 
     31#define UR_ATOM_CLAMP           334 
     32#define UR_ATOM_REPEAT          335 
     33#define UR_ATOM_NEAREST         336 
     34#define UR_ATOM_LINEAR          337 
     35#define UR_ATOM_MIN             338 
     36#define UR_ATOM_MAG             339 
     37#define UR_ATOM_MIPMAP          340 
     38#define UR_ATOM_ON              250 
     39#define UR_ATOM_OFF             252 
     40#define UR_ATOM_ADD             191 
     41#define UR_ATOM_BURN            341 
     42#define UR_ATOM_COLOR           342 
     43#define UR_ATOM_TRANS           343 
  • trunk/thune/gl/gx_dt.c

    r331 r347  
    240240 
    241241 
    242 struct TextureDef 
     242typedef struct 
    243243{ 
    244244    const void* pixels; 
     
    250250    GLint  min_filter; 
    251251    GLint  mag_filter; 
    252 }; 
    253  
    254  
    255 static void _texRast( struct TextureDef* tex, const RasterHead* rh ) 
     252} 
     253TextureDef; 
     254 
     255 
     256static void _texRast( TextureDef* tex, const RasterHead* rh ) 
    256257{ 
    257258    tex->width  = rh->width; 
     
    280281 
    281282 
    282 static void _texCoord( struct TextureDef* tex, const UCell* cell ) 
     283static void _texCoord( TextureDef* tex, const UCell* cell ) 
    283284{ 
    284285    tex->width  = cell->coord.elem[0]; 
     
    309310UR_CALL( make_texture ) 
    310311{ 
    311     struct TextureDef def; 
     312    TextureDef def; 
    312313    GLuint name; 
    313314    int pool; 
     
    778779/* 
    779780  (framebuffer! texture -- fbo) 
     781  (framebuffer! coord -- fbo) 
    780782*/ 
     783//  (framebuffer! size 'shadow -- fbo) 
    781784UR_CALL( make_fbo ) 
    782785{ 
    783     int pool; 
    784     GLuint name; 
     786    int fbPool; 
     787    int texPool; 
     788    GLuint fbName; 
     789    GLuint texName; 
    785790    const char* err; 
    786791    UCell* res = ur_s_prev(tos); 
     
    790795        if( ur_is(tos, UT_TEXTURE) ) 
    791796        { 
    792             name = glfbo_alloc( &pool ); 
    793  
    794             glBindFramebufferEXT( GL_FRAMEBUFFER_EXT, name ); 
    795  
    796             glFramebufferTexture2DEXT( GL_FRAMEBUFFER_EXT, 
    797                                        GL_COLOR_ATTACHMENT0_EXT, GL_TEXTURE_2D, 
    798                                        ur_texId(tos), 0 ); 
    799  
    800             if( (err = _framebufferStatus()) ) 
    801             { 
    802                 ur_throwErr( UR_ERR_INTERNAL, err ); 
    803                 return; 
    804             } 
    805  
    806             glBindFramebufferEXT( GL_FRAMEBUFFER_EXT, 0 ); 
    807  
    808             ur_initType( res, UT_FBO ); 
    809             ur_fboPool(res)    = pool; 
    810             ur_fboId(res)      = name; 
    811             ur_fboTexPool(res) = ur_texPool(tos); 
    812             ur_fboTexId(res)   = ur_texId(tos); 
    813  
    814             UR_S_DROP; 
    815             return; 
    816         } 
    817     } 
    818     ur_throwErr( UR_ERR_DATATYPE, "framebuffer! make expected texture!" ); 
     797            fbName = glfbo_alloc( &fbPool ); 
     798            texName = ur_texId(tos); 
     799            texPool = ur_texPool(tos); 
     800            goto build; 
     801        } 
     802        else if( ur_is(tos, UT_COORD) ) 
     803        { 
     804            TextureDef def; 
     805 
     806            fbName = glfbo_alloc( &fbPool ); 
     807 
     808            _texCoord( &def, tos ); 
     809 
     810            texName = gltex_alloc( &texPool ); 
     811            glBindTexture( GL_TEXTURE_2D, texName ); 
     812 
     813            glTexImage2D( GL_TEXTURE_2D, 0, def.comp, def.width, def.height, 
     814                          0, def.format, GL_UNSIGNED_BYTE, 0 ); 
     815            /* 
     816            glTexParameteri( GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, def.wrap ); 
     817            glTexParameteri( GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, def.wrap ); 
     818            */ 
     819            glTexParameteri( GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR ); 
     820            glTexParameteri( GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR ); 
     821            goto build; 
     822        } 
     823        /* 
     824        else if( ur_isAWord(tos) && (ur_atom(tos) == UR_ATOM_SHADOW) ) 
     825        { 
     826        } 
     827        */ 
     828    } 
     829    ur_throwErr( UR_ERR_DATATYPE, 
     830                 "framebuffer! make expected texture!/coord!" ); 
     831    return; 
     832 
     833build: 
     834 
     835    glBindFramebufferEXT( GL_FRAMEBUFFER_EXT, fbName ); 
     836 
     837    glFramebufferTexture2DEXT( GL_FRAMEBUFFER_EXT, 
     838                               GL_COLOR_ATTACHMENT0_EXT, GL_TEXTURE_2D, 
     839                               texName, 0 ); 
     840 
     841    if( (err = _framebufferStatus()) ) 
     842    { 
     843        ur_throwErr( UR_ERR_INTERNAL, err ); 
     844        return; 
     845    } 
     846 
     847    glBindFramebufferEXT( GL_FRAMEBUFFER_EXT, 0 ); 
     848 
     849    ur_initType( res, UT_FBO ); 
     850    ur_fboPool(res)    = fbPool; 
     851    ur_fboId(res)      = fbName; 
     852    ur_fboTexPool(res) = texPool; 
     853    ur_fboTexId(res)   = texName; 
     854 
     855    UR_S_DROP; 
    819856} 
    820857 
  • trunk/thune/gl/project.r

    r325 r347  
    1010    include_from %. 
    1111    include_from %.. 
     12    ;include_from %hit 
    1213    ;include_from %../util 
    1314    libs_from %.. %thune0 
     
    8990        %shader.c 
    9091        ;%perlin.c 
     92        ;%hit/AABBTree.c 
     93        ;%hit/build_bbt.c 
    9194 
    9295        ;%noise.c