Show
Ignore:
Timestamp:
05/26/08 17:22:18 (6 months ago)
Author:
krobillard
Message:

Added thune-gl widget! datatype.

Files:
1 modified

Legend:

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

    r516 r527  
    7272 
    7373 
    74 struct GrRenderState grState; 
    75  
    76  
    77 #if 0 
     74GrRenderState grState; 
     75 
     76 
     77#if 1 
    7878void gr_disableTexture() 
    7979{ 
     
    132132        case GRS_SOLID: 
    133133            glDepthMask( GL_FALSE ); 
     134#if 0 
    134135            gr_disable( "lbct" ); 
    135             /* 
     136#else 
    136137            glDisable( GL_LIGHTING ); 
    137138            glDisable( GL_BLEND ); 
    138139            glDisable( GL_CULL_FACE ); 
    139140            gr_disableTexture(); 
    140             */ 
     141 
     142            grState.enableMask &= 
     143                ~(EN_LIGHTING | EN_BLEND | EN_CULL_FACE | EN_TEXTURE_2D); 
     144#endif 
    141145            break; 
    142146 
     
    163167 
    164168            // NOTE: Must disable all texture units but GL_TEXTURE0 if not 
    165             // using a shader or text may not render properly. 
     169            //       using a shader or text may not render properly. 
    166170            gr_enableTexture0(); 
    167171 
     
    235239 
    236240 
    237 int gr_textWidth( const TexFont* tf, const char* it, const char* end ) 
    238 { 
    239     TexGlyphInfo* prev = 0; 
    240     TexGlyphInfo* tgi; 
    241     int width = 0; 
    242  
    243     while( it != end ) 
    244     { 
    245         if( *it == '\n' ) 
    246             break; 
    247         if( *it == ' ' ) 
    248         { 
    249             tgi = txf_glyph( tf, ' ' ); 
    250             if( tgi ) 
    251                 width += tgi->advance; 
    252             prev = 0; 
    253         } 
    254         else 
    255         { 
    256             tgi = txf_glyph( tf, *it ); 
    257             if( tgi ) 
    258             { 
    259                 width += tgi->advance; 
    260                 if( prev ) 
    261                     width += txf_kerning( tf, prev, tgi ); 
    262                 prev = tgi; 
    263             } 
    264         } 
    265         ++it; 
    266     } 
    267  
    268     return width; 
    269 } 
    270  
    271  
    272241/* 
    273242  Returns TexGlyphInfo of rendered glyph. 
     
    395364    { 
    396365        int16_t* rect = area->coord.elem; 
    397         int w = gr_textWidth( tf, cpA, cpB ); 
     366        int w = txf_width( tf, cpA, cpB ); 
    398367        int h = tf->max_ascent - (tf->max_ascent >> 1); 
    399368 
     
    646615 
    647616        blk = ur_block(val); 
    648         UR_ITER_BLOCK( it, end, blk, val ); 
     617        UR_ITER_BLOCK( it, end, blk, val ) 
    649618        while( it != end ) 
    650619        { 
     
    826795    COW_VALUE(pc, ts); 
    827796    if( ! ur_is(ts, UT_COORD) ) 
     797    { 
     798bad_dt: 
     799        ur_throwErr( UR_ERR_DATATYPE, "qaud-skin expected coord!" ); 
    828800        return 0; 
     801    } 
    829802    ++pc; 
    830803    COW_VALUE(pc, tc); 
    831804    if( ! ur_is(tc, UT_COORD) ) 
    832         return 0; 
     805        goto bad_dt; 
    833806    ++pc; 
    834807    COW_VALUE(pc, vc); 
    835808    if( ! ur_is(vc, UT_COORD) ) 
    836         return 0; 
     809        goto bad_dt; 
    837810 
    838811    { 
     
    11631136        glEnable( e ); } 
    11641137 
     1138#if 1 
    11651139#define DISABLE(f,e) \ 
    11661140    if( grState.enableMask & f ) { \ 
    11671141        grState.enableMask &= ~f; \ 
    11681142        glDisable( e ); } 
     1143#else 
     1144#define DISABLE(f,e)    glDisable( e ); 
     1145#endif 
     1146 
    11691147 
    11701148static void gr_enable( const char* cp ) 
     
    12881266   Returns zero if an error occurred. 
    12891267*/ 
    1290 static int _runDrawList( UThread* ut, UCell* val ) 
     1268int ug_runDrawList( UThread* ut, UCell* val ) 
    12911269{ 
    12921270    UBlock* blk = ur_blockPtr( val->series.n ); 
     
    13371315                        glCallList( ur_dlGL(val) ); 
    13381316                    } 
    1339                     else if( ! _runDrawList( ut, val ) ) 
     1317                    else if( ! ug_runDrawList( ut, val ) ) 
    13401318                        return 0; 
     1319                } 
     1320                else if( ur_is(val, UT_WIDGET) ) 
     1321                { 
     1322                    // NOTE: Compiliation of widget draw lists will happen 
     1323                    //       inside gui_render(). 
     1324                    gui_render( &gxEnv.gui, ur_int(val) ); 
    13411325                } 
    13421326                break; 
     
    16541638                { 
    16551639                    if( ! ur_is(val, UT_COORD) || (val->coord.len < 4) ) 
     1640                    { 
     1641                        ur_throwErr( UR_ERR_DATATYPE, 
     1642                                     "text expected area coord!" ); 
    16561643                        return 0; 
     1644                    } 
    16571645                    area = val; 
    16581646                    ++pc; 
     
    16891677                loadShader( ut, val ); 
    16901678                break; 
    1691 #if 0 
     1679#if 1 
    16921680            case DOP_UNIFORM: 
    16931681            { 
     
    17371725                if( ur_is(pc, UT_BLOCK) ) 
    17381726                { 
    1739                     if( ! _runDrawList( ut, pc ) ) 
     1727                    if( ! ug_runDrawList( ut, pc ) ) 
    17401728                        return 0; 
    17411729                } 
     
    18051793 
    18061794 
     1795int ug_compileDrawList( UThread* ut, UCell* blkCell, GLuint dl ) 
     1796{ 
     1797    int ok; 
     1798 
     1799    //printf( "KR compile DL %d\n", dl ); 
     1800 
     1801    // Need to keep grState.shaderProg for uniform to work in compiled list. 
     1802    //gr_clearState(); 
     1803 
     1804    glNewList( dl, GL_COMPILE ); 
     1805    ok = ug_runDrawList( ut, blkCell ); 
     1806    glEndList(); 
     1807 
     1808    return ok; 
     1809} 
     1810 
     1811 
    18071812/* 
    18081813   (draw-list! block -- dlist) 
     
    18261831        ur_initType(res, UT_DRAWLIST); 
    18271832        ur_setSeries(res, tos->series.n, tos->series.it ); 
    1828         ur_dlGL(res)   = 0; 
     1833        ur_dlGL(res) = 0; 
    18291834        //ur_dlPool(res) = 0;   // Cleared by ur_initType. 
    18301835    } 
     
    18411846 
    18421847        gr_clearState(); 
    1843  
    1844         //printf( "KR compile %d\n", ur_dlGL(tos) ); 
    1845  
    1846         glNewList( ur_dlGL(res), GL_COMPILE ); 
    1847  
    1848         if( ! _runDrawList( ut, tos ) ) 
    1849         { 
    1850             ur_throwErr( UR_ERR_SCRIPT, "runDrawList failed" ); 
    1851         } 
    1852  
    1853         glEndList(); 
     1848        if( ! ug_compileDrawList( ut, tos, ur_dlGL(res) ) ) 
     1849            return; 
    18541850    } 
    18551851    else 
     
    18711867    if( ur_is(tos, UT_DRAWLIST) ) 
    18721868    { 
     1869        if( ur_dlGL(tos) ) 
     1870        { 
     1871            glCallList( ur_dlGL(tos) ); 
     1872        } 
     1873        else 
     1874        { 
     1875            gr_clearState(); 
     1876            ug_runDrawList( ut, tos ); 
     1877        } 
     1878    } 
     1879    else if( ur_is(tos, UT_WIDGET) ) 
     1880    { 
    18731881        gr_clearState(); 
    1874  
    1875         if( ur_dlGL(tos) ) 
    1876             glCallList( ur_dlGL(tos) ); 
    1877         else 
    1878             _runDrawList( ut, tos ); 
     1882        gui_render( &gxEnv.gui, ur_int(tos) ); 
    18791883    } 
    18801884    UR_S_DROP;