Changeset 383

Show
Ignore:
Timestamp:
04/29/07 06:21:11 (19 months ago)
Author:
krobillard
Message:

Thune GL - Shader attributes can now be used.

Location:
trunk/thune
Files:
6 modified

Legend:

Unmodified
Added
Removed
  • trunk/thune/doc/GLManual

    r364 r383  
    229229normals           vector!                 Set normal array 
    230230uvs               vector!                 Set texture UV array 
     231attrib            select! (int!) vector!  Set user attribute array 
    231232points            attr vector!            Draw points 
    232233lines             attr vector!            Draw line primitives 
     
    256257UV                t                       Index into texture *uvs* vector 
    257258Vertex            v                       Index into *verts* vector 
     259User Attribute    a                       Index into *attrib* vector 
    258260================  ======================  =========================== 
    259261 
     262The UV attribute (t) may appear more than once in the word.  Each occurance 
     263will set the UV of the next texture unit (0, 1, 2, etc.). 
    260264 
    261265Some primitive examples:: 
     
    267271 
    268272    quads tnv #[0 0 0   1 0 1   2 0 2   3 0 3 
    269  
    270273 
    271274 
  • trunk/thune/gl/boot.c

    r360 r383  
    6969  "    normals\n" 
    7070  "    uvs\n" 
     71  "    attrib\n" 
    7172  "    points\n" 
    7273  "    lines\n" 
  • trunk/thune/gl/draw_list.c

    r382 r383  
    7373    _state.uvVals    = 0; 
    7474    _state.colorVals = 0; 
     75    _state.attr[0].vals = 0; 
     76    _state.attr[1].vals = 0; 
    7577} 
    7678 
     
    598600 
    599601/* 
     602  attrib/1 shader/my-attrib float-count #[...] 
     603 
     604  Returns pc at last argument or zero if arguments are bad. 
     605*/ 
     606static UCell* dop_attrib( UThread* ur_thread, UCell* pc ) 
     607{ 
     608    GrVertexAttribute* attr; 
     609    Shader* sh = 0; 
     610 
     611    attr = _state.attr; // + ur_sel(pc); 
     612    ++pc; 
     613 
     614    if( ur_is(pc, UT_SELECT) ) 
     615    { 
     616        UCell* val = ur_wordCell( ur_thread, pc ); 
     617        if( ! val ) 
     618            return 0; 
     619        if( ur_is(val, UT_CONTEXT) ) 
     620        { 
     621            UCell* cval = ur_blockPtr( val->ctx.valBlk )->ptr.cells; 
     622            if( cval && ur_is(cval, UT_SHADER) ) 
     623            { 
     624                sh = (Shader*) ur_resPtr( cval->series.n )->ptr; 
     625            } 
     626        } 
     627        else if( ur_is(val, UT_SHADER) ) 
     628        { 
     629            sh = (Shader*) ur_resPtr( val->series.n )->ptr; 
     630        } 
     631    } 
     632 
     633    if( ! sh ) 
     634    { 
     635        ur_throwErr( UR_ERR_DATATYPE, "attrib expected shader!" ); 
     636        return 0; 
     637    } 
     638 
     639    //glUseProgram( sh->program ); 
     640 
     641    // LIMIT: Shader attribute names must be lower-case. 
     642    attr->loc = glGetAttribLocation( sh->program, ur_atomCStr(ur_sel(pc), 0) ); 
     643    if( attr->loc == -1 ) 
     644    { 
     645        ur_throwErr( UR_ERR_SCRIPT, "attrib '%s not found", 
     646                     ur_atomCStr(ur_sel(pc), 0) ); 
     647        return 0; 
     648    } 
     649 
     650    ++pc; 
     651    if( ur_is(pc, UT_INT) ) 
     652    { 
     653        attr->count = ur_int(pc); 
     654        ++pc; 
     655    } 
     656    else 
     657    { 
     658        attr->count = 3; 
     659    } 
     660 
     661    if( ur_is(pc, UT_VECTOR) ) 
     662    { 
     663        attr->vals = ur_bin(pc)->ptr.f; 
     664        return pc; 
     665    } 
     666 
     667    ur_throwErr( UR_ERR_DATATYPE, "attrib expected vector!" ); 
     668    return 0; 
     669} 
     670 
     671 
     672/* 
    600673   icell is an int array! 
    601674*/ 
     
    604677    //GLdouble vec[3]; 
    605678    const char* ki; 
     679    int ti; 
    606680    UCell* col; 
    607681    int32_t* it; 
     
    613687 
    614688    ki = key; 
     689    ti = 0; 
    615690 
    616691    while( it != end ) 
     
    618693        switch( *ki ) 
    619694        { 
    620             /* 
    621             glUseProgram( program ); 
    622             GLint attrib_loc = glGetAttribLocation( program, “my_attrib” ); 
    623             if( attrib_loc == -1 ) not_found; 
    624695            case 'a': 
    625                 glVertexAttrib3f( attrib_loc, 4.0f, 2.0f, 7.0f ); 
    626                 break; 
    627             */ 
     696            { 
     697                GrVertexAttribute* attr = _state.attr; 
     698                switch( attr->count ) 
     699                { 
     700                case 1: 
     701                    glVertexAttrib1fv( attr->loc, attr->vals + *it ); 
     702                    break; 
     703                case 2: 
     704                    glVertexAttrib2fv( attr->loc, attr->vals + *it * 2 ); 
     705                    break; 
     706                case 3: 
     707                    glVertexAttrib3fv( attr->loc, attr->vals + *it * 3 ); 
     708                    break; 
     709                case 4: 
     710                    glVertexAttrib4fv( attr->loc, attr->vals + *it * 4 ); 
     711                    break; 
     712                } 
     713            } 
     714                break; 
    628715 
    629716            case 'c': 
     
    657744                float* uv = _state.uvVals + *it * 2; 
    658745                //glMultiTexCoord2fv( GL_TEXTURE0, uv ); 
    659                 glMultiTexCoord2f( GL_TEXTURE0, uv[0], 1.0f - uv[1] ); 
     746                glMultiTexCoord2f( GL_TEXTURE0 + ti, uv[0], 1.0f - uv[1] ); 
     747                ++ti; 
    660748            } 
    661749                break; 
     
    664752        ++ki; 
    665753        if( *ki == '\0' ) 
     754        { 
    666755            ki = key; 
     756            ti = 0; 
     757        } 
    667758 
    668759        ++it; 
     
    852943                if( ur_is(pc, UT_VECTOR) ) 
    853944                    _state.uvVals = ur_bin(pc)->ptr.f; 
     945                break; 
     946 
     947            case DOP_ATTRIB: 
     948                pc = dop_attrib( ur_thread, pc ); 
     949                if( ! pc ) 
     950                    return 0; 
    854951                break; 
    855952 
  • trunk/thune/gl/draw_ops.h

    r359 r383  
    1414#define DOP_NORMALS         11 
    1515#define DOP_UVS             12 
    16 #define DOP_POINTS          13 
    17 #define DOP_LINES           14 
    18 #define DOP_LINE_STRIP      15 
    19 #define DOP_TRIS            16 
    20 #define DOP_TRI_STRIP       17 
    21 #define DOP_TRI_FAN         18 
    22 #define DOP_QUADS           19 
    23 #define DOP_QUAD_STRIP      20 
    24 #define DOP_CAMERA          21 
    25 #define DOP_LIGHT           22 
    26 #define DOP_LIGHTING        23 
    27 #define DOP_PUSH            24 
    28 #define DOP_POP             25 
    29 #define DOP_TRANSLATE       26 
    30 #define DOP_ROTATE          27 
    31 #define DOP_SCALE           28 
    32 #define DOP_FONT            29 
    33 #define DOP_TEXT            30 
    34 #define DOP_SHADER          31 
    35 #define DOP_FRAMEBUFFER     32 
    36 #define DOP_SHADOW_BEGIN    33 
    37 #define DOP_SHADOW_END      34 
     16#define DOP_ATTRIB          13 
     17#define DOP_POINTS          14 
     18#define DOP_LINES           15 
     19#define DOP_LINE_STRIP      16 
     20#define DOP_TRIS            17 
     21#define DOP_TRI_STRIP       18 
     22#define DOP_TRI_FAN         19 
     23#define DOP_QUADS           20 
     24#define DOP_QUAD_STRIP      21 
     25#define DOP_CAMERA          22 
     26#define DOP_LIGHT           23 
     27#define DOP_LIGHTING        24 
     28#define DOP_PUSH            25 
     29#define DOP_POP             26 
     30#define DOP_TRANSLATE       27 
     31#define DOP_ROTATE          28 
     32#define DOP_SCALE           29 
     33#define DOP_FONT            30 
     34#define DOP_TEXT            31 
     35#define DOP_SHADER          32 
     36#define DOP_FRAMEBUFFER     33 
     37#define DOP_SHADOW_BEGIN    34 
     38#define DOP_SHADOW_END      35 
  • trunk/thune/gl/gx.h

    r382 r383  
    120120 
    121121 
     122typedef struct 
     123{ 
     124    float* vals; 
     125    int    count; 
     126    GLint  loc; 
     127} 
     128GrVertexAttribute; 
     129 
     130 
    122131struct GrRenderState 
    123132{ 
     
    133142    UCell*  colorVals; 
    134143    float*  uvVals; 
     144 
     145    GrVertexAttribute attr[2]; 
    135146}; 
    136147 
  • trunk/thune/gl/gx.t

    r360 r383  
    128128    normals 
    129129    uvs 
     130    attrib 
    130131 
    131132    points