Changeset 330 for trunk/thune/gl

Show
Ignore:
Timestamp:
01/02/07 02:19:55 (2 years ago)
Author:
krobillard
Message:

Thune GL - font! & framebuffer! now hold texture from GC. Working on shadowmapping.

Location:
trunk/thune/gl
Files:
9 modified

Legend:

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

    r315 r330  
    487487 
    488488 
    489 #if 0 
     489#if 1 
    490490// Transform from -1..1 to 0..1 
    491491const GLdouble bias[] = 
     
    498498 
    499499 
    500 static void dop_shadowmap( /*UThread* ur_thread,*/ UCell* fbCell ) 
    501 { 
     500GLdouble lightModelMatrix[ 16 ]; 
     501GLdouble lightProjMatrix[ 16 ]; 
     502 
     503//#define SHADOW_BACK_FACES   1 
     504 
     505static void dop_shadow_begin( /*UThread* ur_thread,*/ UCell* fbCell ) 
     506{ 
     507    glGetDoublev( GL_MODELVIEW_MATRIX, lightModelMatrix ); 
     508    glGetDoublev( GL_PROJECTION_MATRIX, lightProjMatrix ); 
     509 
     510 
    502511    glBindFramebufferEXT( GL_FRAMEBUFFER_EXT, ur_fboId(fbCell) ); 
    503     glClear( GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT ); 
    504  
     512    glClear( GL_DEPTH_BUFFER_BIT ); 
     513 
     514#ifdef SHADOW_BACK_FACES 
     515    glEnable( GL_CULL_FACE ); 
     516    glCullFace( GL_FRONT ); 
     517#else 
    505518    //glPolygonOffset( polygon_offset_scale, polygon_offset_bias ); 
    506519    glPolygonOffset( 2.0f, 10.0f ); 
     520    //glPolygonOffset( 2.0f, 2.0f ); 
    507521    glEnable( GL_POLYGON_OFFSET_FILL ); 
     522#endif 
     523 
     524 
     525#if 0 
     526    glMatrixMode( GL_TEXTURE ); 
     527    glLoadIdentity(); 
     528    glMatrixMode( GL_MODELVIEW ); 
     529#endif 
     530 
     531} 
     532 
     533 
     534static void dop_shadow_end() 
     535{ 
     536#ifdef SHADOW_BACK_FACES 
     537    glCullFace( GL_BACK ); 
     538#else 
     539    glDisable( GL_POLYGON_OFFSET_FILL ); 
     540#endif 
     541    glBindFramebufferEXT( GL_FRAMEBUFFER_EXT, 0 ); 
     542 
     543 
     544    //glActiveTextureARB(GL_TEXTURE1_ARB); 
    508545 
    509546    glMatrixMode( GL_TEXTURE ); 
    510547    glLoadMatrixd( bias ); 
    511 #if 1 
     548#if 0 
    512549    gluPerspective( fov, 1, near, far ); 
    513550#else 
    514     glMultMatrixd( l->get_proj_matrix() ); 
    515     glMultMatrixd( l->get_model_matrix() ); 
     551    glMultMatrixd( lightProjMatrix ); 
     552    glMultMatrixd( lightModelMatrix ); 
    516553#endif 
    517554    glMatrixMode( GL_MODELVIEW ); 
    518 } 
    519  
    520  
    521 static void dop_shadowmap_end() 
    522 { 
    523     glDisable( GL_POLYGON_OFFSET_FILL ); 
    524     glBindFramebufferEXT( GL_FRAMEBUFFER_EXT, 0 ); 
     555 
     556    //glActiveTextureARB(GL_TEXTURE0_ARB); 
    525557} 
    526558#endif 
     
    876908                    glBindFramebufferEXT( GL_FRAMEBUFFER_EXT, 0 ); 
    877909                break; 
    878 #if 0 
    879             case DOP_SHADOWMAP: 
     910 
     911            case DOP_SHADOW_BEGIN: 
    880912                ++pc; 
    881913                VAL_WORD_OR_PC 
    882914                if( ur_is(val, UT_FBO) ) 
    883                     dop_shadowmap( /*ur_thread,*/ val ); 
    884                 else 
    885                     dop_shadowmap_end(); 
    886                 break; 
    887 #endif 
     915                    dop_shadow_begin( /*ur_thread,*/ val ); 
     916                break; 
     917 
     918            case DOP_SHADOW_END: 
     919                dop_shadow_end(); 
     920                break; 
     921 
    888922            default: 
    889923                assert( 0 && "Invalid Draw List Opcode" ); 
  • trunk/thune/gl/draw_ops.h

    r312 r330  
    3232#define DOP_SHADER          29 
    3333#define DOP_FRAMEBUFFER     30 
    34 #define DOP_SHADOWMAP       31 
     34#define DOP_SHADOW_BEGIN    31 
     35#define DOP_SHADOW_END      32 
  • trunk/thune/gl/gx.c

    r325 r330  
    12411241    ur_throwErr( UR_ERR_DATATYPE, "perlin expected raster! int! decimal!" ); 
    12421242} 
     1243#endif 
    12431244 
    12441245 
     
    12591260 
    12601261        glGetIntegerv( GL_DEPTH_BITS, &depthBits ); 
    1261         printf( "KR depthBits %d\n", depthBits ); 
    1262  
    1263         // TODO: Hold texture! (return context?) 
     1262        //printf( "KR depthBits %d\n", depthBits ); 
     1263 
    12641264        texName = gltex_alloc( &texPool ); 
    12651265        glBindTexture( GL_TEXTURE_2D, texName ); 
     
    12901290                 GL_DEPTH_ATTACHMENT_EXT, GL_TEXTURE_2D, texName, 0 ); 
    12911291        glDrawBuffer( GL_NONE ); 
    1292         //glReadBuffer( GL_FALSE ); 
     1292        glReadBuffer( GL_NONE ); 
    12931293 
    12941294        if( (err = _framebufferStatus()) ) 
     
    13001300        glBindFramebufferEXT( GL_FRAMEBUFFER_EXT, 0 ); 
    13011301 
    1302         ur_initType( tos, UT_FBO ); 
    1303         ur_fboPool(tos) = fboPool; 
    1304         ur_fboId(tos)   = fboName; 
     1302        ur_initType(tos, UT_FBO); 
     1303        ur_fboPool(tos)    = fboPool; 
     1304        ur_fboId(tos)      = fboName; 
     1305        ur_fboTexPool(tos) = texPool; 
     1306        ur_fboTexId(tos)   = texName; 
    13051307        return; 
    13061308    } 
    13071309    ur_throwErr( UR_ERR_DATATYPE, "shadowmap expected coord!" ); 
    13081310} 
    1309 #endif 
    13101311 
    13111312 
     
    13431344    { uc_gl_max_textures,"gl-max-textures" }, 
    13441345    //{ uc_perlin,         "perlin" }, 
    1345     //{ uc_shadowmap,      "shadowmap" } 
     1346    { uc_shadowmap,      "shadowmap" } 
    13461347}; 
    13471348 
     
    13701371    FIXED_ATOM( "rect",         4, UR_ATOM_RECT ) 
    13711372    FIXED_ATOM( "raster",       6, UR_ATOM_RASTER ) 
     1373    FIXED_ATOM( "texture",      7, UR_ATOM_TEXTURE ) 
    13721374    FIXED_ATOM( "elem",         4, UR_ATOM_ELEM ) 
    13731375    FIXED_ATOM( "close",        5, UR_ATOM_CLOSE ) 
  • trunk/thune/gl/gx.h

    r321 r330  
    6767    uint8_t  type; 
    6868    uint8_t  flags; 
    69     uint16_t glTexIdPool; 
     69    uint16_t glTexPool; 
    7070    UIndex   rasterN;    // Raster binary 
    7171    UIndex   fontN;      // TexFont binary 
     
    7676 
    7777typedef UCellRasterFont     UCellTexture; 
     78 
     79 
     80typedef struct 
     81{ 
     82    uint8_t  type; 
     83    uint8_t  flags; 
     84    uint16_t glTexPool; 
     85    uint16_t glFboPool; 
     86    uint16_t _pad; 
     87    GLuint   glFboId; 
     88    GLuint   glTexId; 
     89} 
     90UCellFramebuffer; 
    7891 
    7992 
     
    173186#define ur_fontTF(c)        ((UCellRasterFont*) (c))->fontN 
    174187#define ur_fontTexId(c)     ((UCellRasterFont*) (c))->glTexId 
     188#define ur_fontTexPool(c)   ((UCellRasterFont*) (c))->glTexPool 
    175189 
    176190#define ur_texRast(c)       ((UCellTexture*) (c))->rasterN 
    177191#define ur_texId(c)         ((UCellTexture*) (c))->glTexId 
    178 #define ur_texPool(c)       ((UCellTexture*) (c))->glTexIdPool 
    179  
    180 #define ur_fboId(c)         ((UCellTexture*) (c))->glTexId 
    181 #define ur_fboPool(c)       ((UCellTexture*) (c))->glTexIdPool 
     192#define ur_texPool(c)       ((UCellTexture*) (c))->glTexPool 
     193 
     194#define ur_fboId(c)         ((UCellFramebuffer*) (c))->glFboId 
     195#define ur_fboPool(c)       ((UCellFramebuffer*) (c))->glFboPool 
     196#define ur_fboTexId(c)      ((UCellFramebuffer*) (c))->glTexId 
     197#define ur_fboTexPool(c)    ((UCellFramebuffer*) (c))->glTexPool 
    182198 
    183199 
  • trunk/thune/gl/gx.t

    r325 r330  
    135135    shader 
    136136    framebuffer 
    137     shadowmap 
     137    shadow-begin 
     138    shadow-end 
    138139] 
    139140make-opcodes :draw-list-opcodes 
  • trunk/thune/gl/gx_atoms.h

    r311 r330  
    66#define UR_ATOM_RECT            306 
    77#define UR_ATOM_RASTER          307 
    8 #define UR_ATOM_ELEM            308 
     8#define UR_ATOM_TEXTURE         308 
     9#define UR_ATOM_ELEM            309 
    910#define UR_ATOM_CLOSE           171 
    10 #define UR_ATOM_FOCUS           309 
    11 #define UR_ATOM_RESIZE          310 
    12 #define UR_ATOM_KEY_DOWN                311 
    13 #define UR_ATOM_KEY_UP          312 
    14 #define UR_ATOM_MOUSE_MOVE              313 
    15 #define UR_ATOM_MOUSE_UP                314 
    16 #define UR_ATOM_MOUSE_DOWN              315 
    17 #define UR_ATOM_MOUSE_WHEEL             316 
    18 #define UR_ATOM_AMBIENT         317 
    19 #define UR_ATOM_DIFFUSE         318 
    20 #define UR_ATOM_SPECULAR                319 
    21 #define UR_ATOM_POS             320 
    22 #define UR_ATOM_SHADER          321 
    23 #define UR_ATOM_VERTEX          322 
    24 #define UR_ATOM_FRAGMENT                323 
    25 #define UR_ATOM_DEFAULT         324 
    26 #define UR_ATOM_RGB             325 
    27 #define UR_ATOM_RGBA            326 
    28 #define UR_ATOM_DEPTH           327 
    29 #define UR_ATOM_CLAMP           328 
    30 #define UR_ATOM_REPEAT          329 
    31 #define UR_ATOM_NEAREST         330 
    32 #define UR_ATOM_LINEAR          331 
    33 #define UR_ATOM_MIN             332 
    34 #define UR_ATOM_MAG             333 
    35 #define UR_ATOM_MIPMAP          334 
     11#define UR_ATOM_FOCUS           310 
     12#define UR_ATOM_RESIZE          311 
     13#define UR_ATOM_KEY_DOWN                312 
     14#define UR_ATOM_KEY_UP          313 
     15#define UR_ATOM_MOUSE_MOVE              314 
     16#define UR_ATOM_MOUSE_UP                315 
     17#define UR_ATOM_MOUSE_DOWN              316 
     18#define UR_ATOM_MOUSE_WHEEL             317 
     19#define UR_ATOM_AMBIENT         318 
     20#define UR_ATOM_DIFFUSE         319 
     21#define UR_ATOM_SPECULAR                320 
     22#define UR_ATOM_POS             321 
     23#define UR_ATOM_SHADER          322 
     24#define UR_ATOM_VERTEX          323 
     25#define UR_ATOM_FRAGMENT                324 
     26#define UR_ATOM_DEFAULT         325 
     27#define UR_ATOM_RGB             326 
     28#define UR_ATOM_RGBA            327 
     29#define UR_ATOM_DEPTH           328 
     30#define UR_ATOM_CLAMP           329 
     31#define UR_ATOM_REPEAT          330 
     32#define UR_ATOM_NEAREST         331 
     33#define UR_ATOM_LINEAR          332 
     34#define UR_ATOM_MIN             333 
     35#define UR_ATOM_MAG             334 
     36#define UR_ATOM_MIPMAP          335 
    3637#define UR_ATOM_ON              247 
    3738#define UR_ATOM_OFF             249 
    3839#define UR_ATOM_ADD             190 
    39 #define UR_ATOM_BURN            335 
    40 #define UR_ATOM_COLOR           336 
    41 #define UR_ATOM_TRANS           337 
     40#define UR_ATOM_BURN            336 
     41#define UR_ATOM_COLOR           337 
     42#define UR_ATOM_TRANS           338 
  • trunk/thune/gl/gx_dt.c

    r321 r330  
    485485static void mark_texture( UCollector* gc, UCell* cell ) 
    486486{ 
    487     UCellTexture* tc = (UCellTexture*) cell; 
    488     ur_gcMarkBin( gc, tc->rasterN ); 
    489     gltex_gcMark( tc->glTexIdPool, tc->glTexId ); 
     487    ur_gcMarkBin( gc, ur_texRast(cell) ); 
     488    gltex_gcMark( ur_texPool(cell), ur_texId(cell) ); 
    490489} 
    491490 
     
    570569    { 
    571570        case UR_ATOM_RASTER: 
    572         { 
    573             UCellRasterFont* fc = (UCellRasterFont*) val; 
    574571            ur_initType(res, UT_RASTER); 
    575             ur_setSeries(res, fc->rasterN, 0); 
    576         } 
     572            ur_setSeries(res, ur_fontRast(val), 0); 
     573            break; 
     574 
     575        case UR_ATOM_TEXTURE: 
     576            ur_initType(res, UT_TEXTURE); 
     577            ur_texPool(res) = ur_fontTexPool(val); 
     578            ur_texId(res)   = ur_fontTexId(val); 
     579            ur_texRast(res) = ur_fontRast(val); 
    577580            break; 
    578581 
     
    588591{ 
    589592    UCellRasterFont* fc = (UCellRasterFont*) cell; 
    590     ur_gcMarkBin( gc, fc->rasterN ); 
    591     ur_gcMarkBin( gc, fc->fontN ); 
    592     //gltexture_gcMark( fc->glTexIdPool, fc->glTexId ); 
     593    if( fc->rasterN ) 
     594        ur_gcMarkBin( gc, fc->rasterN ); 
     595    if( fc->fontN ) 
     596        ur_gcMarkBin( gc, fc->fontN ); 
     597    gltex_gcMark( fc->glTexPool, fc->glTexId ); 
    593598} 
    594599 
     
    775780 
    776781            ur_initType( res, UT_FBO ); 
    777             ur_fboPool(res) = pool; 
    778             ur_fboId(res)   = name; 
     782            ur_fboPool(res)    = pool; 
     783            ur_fboId(res)      = name; 
     784            ur_fboTexPool(res) = ur_texPool(tos); 
     785            ur_fboTexId(res)   = ur_texId(tos); 
    779786 
    780787            UR_S_DROP; 
     
    794801 
    795802 
     803static int select_fbo( UThread* ur_thread, UCell* val, const UCell* sel, 
     804                       UCell* res ) 
     805{ 
     806    switch( ur_sel(sel) ) 
     807    { 
     808        /* 
     809        case UR_ATOM_RASTER: 
     810            ur_initType(res, UT_RASTER); 
     811            ur_setSeries(res, ur_fontRast(val), 0); 
     812            break; 
     813        */ 
     814 
     815        case UR_ATOM_TEXTURE: 
     816            ur_initType(res, UT_TEXTURE); 
     817            ur_texPool(res) = ur_fboTexPool(val); 
     818            ur_texId(res)   = ur_fboTexId(val); 
     819            ur_texRast(res) = 0; 
     820            break; 
     821 
     822        default: 
     823            ur_throwErr( UR_ERR_SCRIPT, "Invalid select!" ); 
     824            return 0; 
     825    } 
     826    return 1; 
     827} 
     828 
     829 
    796830static void mark_fbo( UCollector* gc, UCell* cell ) 
    797831{ 
    798832    (void) gc; 
    799833    glfbo_gcMark( ur_fboPool(cell), ur_fboId(cell) ); 
     834    gltex_gcMark( ur_fboTexPool(cell), ur_fboTexId(cell) ); 
    800835} 
    801836 
     
    857892    {"framebuffer!", 0, 0, 
    858893        make_fbo, to_nop, toStr_fbo, toStr_fbo, 
    859         select_nop, recycle_nop, mark_fbo, rmres_nop }, 
     894        select_fbo, recycle_nop, mark_fbo, rmres_nop }, 
    860895}; 
    861896 
  • trunk/thune/gl/rfont.c

    r321 r330  
    1212#include "gx.h" 
    1313#include "rfont.h" 
    14  
    15  
    16 static GLuint buildFontTexture( RasterHead* img ) 
     14#include "gltex.h" 
     15 
     16 
     17static void buildFontTexture( RasterHead* img, GLuint id ) 
    1718{ 
    18     GLuint id; 
    1919    GLenum format; 
    2020    GLint  comp; 
     
    4040 
    4141        default: 
    42             return 0; 
    43     } 
    44  
    45     glGenTextures( 1, &id ); 
     42            return; 
     43    } 
     44 
    4645    glBindTexture( GL_TEXTURE_2D, id ); 
    4746 
     
    7675 
    7776    glTexEnvi( GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_MODULATE ); 
    78  
    79     return id; 
    8077} 
    8178 
     
    10198{ 
    10299#define ENV     ur_thread->env 
     100    UIndex rastN; 
    103101    UIndex binN; 
    104102    UIndex hold; 
     
    114112        cfg->pointSize = 100; 
    115113 
    116     binN = ur_makeRaster( res, UR_RAST_GRAY, cfg->texW, cfg->texH, &bin ); 
     114    rastN = ur_makeRaster( res, UR_RAST_GRAY, cfg->texW, cfg->texH, &bin ); 
    117115    if( bin->ptr.b ) 
    118116    { 
    119         hold = ur_hold( ENV, UT_BINARY, binN ); 
     117        hold = ur_hold( ENV, UT_BINARY, rastN ); 
    120118 
    121119        fbm.width  = cfg->texW; 
     
    135133            TexGlyphInfo** src; 
    136134            TexGlyphInfo** end; 
    137  
    138             // TODO: Track & delete texture. 
    139             ur_fontTexId(res) = buildFontTexture( (RasterHead*) bin->ptr.v ); 
    140135 
    141136 
     
    178173 
    179174 
     175            { 
     176            int texPool; 
     177            GLuint texId; 
     178 
     179            texId = gltex_alloc( &texPool ); 
     180            bin = ur_binPtr( rastN ); 
     181            buildFontTexture( (RasterHead*) bin->ptr.v, texId ); 
     182 
     183            // Should ditch raster? 
     184 
    180185            ur_initType( res, UT_FONT ); 
    181             ur_fontTF(res) = binN; 
     186            //ur_fontRast(res)  =       // Already set by ur_makeRaster(). 
     187            ur_fontTF(res)      = binN; 
     188            ur_fontTexId(res)   = texId; 
     189            ur_fontTexPool(res) = texPool; 
     190            } 
    182191 
    183192            ok = 1; 
  • trunk/thune/gl/test_fw.t

    r310 r330  
    7676        key-down [ 
    7777            esc [quit] 
     78            f10 [display.snapshot "snapshot.png" save.png] 
    7879        ] 
    7980