Changeset 306 for trunk/thune/gl

Show
Ignore:
Timestamp:
11/05/06 03:27:39 (2 years ago)
Author:
krobillard
Message:

Thune GL - Added texture! datatype.

Location:
trunk/thune/gl
Files:
9 modified

Legend:

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

    r305 r306  
    178178    else 
    179179    { 
    180         ur_throwErr( UR_ERR_DATATYPE, "load-wav expected string!" ); 
     180        ur_throwErr( UR_ERR_DATATYPE, "load.wav expected string!" ); 
    181181    } 
    182182} 
  • trunk/thune/gl/draw_list.c

    r301 r306  
    1818===========================================================================*/ 
    1919 
     20 
     21#define GL_GLEXT_PROTOTYPES 
    2022 
    2123#include <assert.h> 
     
    110112            glDisable( GL_BLEND ); 
    111113 
    112             gr_disableTexture(); 
     114            //gr_disableTexture(); 
     115            gr_enableTexture0(); 
    113116            break; 
    114117 
     
    505508                //glVertex3dv( vec ); 
    506509                glVertex3fv( _state.vertVals + *it * 3 ); 
     510                break; 
     511 
     512            case 't': 
     513            { 
     514                float* uv = _state.uvVals + *it * 2; 
     515                glMultiTexCoord2fv( GL_TEXTURE0_ARB, uv ); 
     516                //glMultiTexCoord2f( GL_TEXTURE0_ARB, uv[0], 1.0f - uv[1] ); 
     517            } 
    507518                break; 
    508519        } 
  • trunk/thune/gl/gx.c

    r304 r306  
    3131#include "audio.h" 
    3232#include "gllist.h" 
     33#include "gltex.h" 
    3334#include "math3d.h" 
    3435//#include <time.h> 
     
    17991800    { uc_play,           "play" }, 
    18001801    { uc_stop,           "stop" }, 
    1801  //   { uc_load_png,      "load-png" }, 
    18021802    { uc_display_events, "display.events" }, 
    18031803    { uc_display_swap,   "display.swap" }, 
     
    18051805    { uc_key_repeat,     "key-repeat" }, 
    18061806    { uc_key_code,       "key-code" }, 
    1807     { uc_load_png,       "load-png" }, 
    1808     { uc_load_wav,       "load-wav" }, 
     1807    { uc_load_png,       "load.png" }, 
     1808    { uc_load_wav,       "load.wav" }, 
    18091809    { uc_display,        "display" }, 
    18101810    { uc_look_at,        "look-at" } 
     
    18531853    FIXED_ATOM( "default",  7, UR_ATOM_DEFAULT ); 
    18541854 
     1855    /* 
     1856    FIXED_ATOM( "clamp",    5, UR_ATOM_CLAMP ); 
     1857    FIXED_ATOM( "repeat",   6, UR_ATOM_REPEAT ); 
     1858    FIXED_ATOM( "nearest",  7, UR_ATOM_NEAREST ); 
     1859    FIXED_ATOM( "linear",   6, UR_ATOM_LINEAR ); 
     1860    FIXED_ATOM( "min",      3, UR_ATOM_MIN ); 
     1861    FIXED_ATOM( "mag",      3, UR_ATOM_MAG ); 
     1862    */ 
     1863 
    18551864#if MAKE_ATOM_HEADER 
    18561865    exit(0); 
     
    19021911 
    19031912    gllist_startup(); 
     1913    gltex_startup(); 
    19041914 
    19051915    return UR_EVAL_OK; 
  • trunk/thune/gl/gx.h

    r301 r306  
    3131 
    3232#define UT_RASTER   UT_BI_COUNT 
    33 #define UT_FONT     UT_BI_COUNT+1 
    34 #define UT_SHADER   UT_BI_COUNT+2 
     33#define UT_TEXTURE  UT_BI_COUNT+1 
     34#define UT_FONT     UT_BI_COUNT+2 
     35#define UT_SHADER   UT_BI_COUNT+3 
    3536 
    3637 
     
    8485 
    8586 
     87typedef UCellRasterFont     UCellTexture; 
     88 
     89 
    8690//---------------------------------------------------------------------------- 
    8791 
     
    187191UIndex ur_makeRaster( UCell*, int format, int w, int h ); 
    188192 
    189 #define ur_rast(c)          ((RasterHead*) ur_bin(c)->ptr.v) 
     193#define ur_rastHead(c)      ((RasterHead*) ur_bin(c)->ptr.v) 
    190194#define ur_rasterElem(bin)  (bin->ptr.b + sizeof(RasterHead)) 
    191195 
     
    194198#define ur_fontTexId(c)     ((UCellRasterFont*) c)->glTexId 
    195199 
     200#define ur_texRast(c)       ((UCellTexture*) c)->rasterN 
     201#define ur_texId(c)         ((UCellTexture*) c)->glTexId 
     202#define ur_texPool(c)       ((UCellTexture*) c)->glTexIdPool 
     203 
    196204 
    197205#endif /*GX_H*/ 
  • trunk/thune/gl/gx_dt.c

    r304 r306  
    2525#include "gx_atoms.h" 
    2626#include "gllist.h" 
     27#include "gltex.h" 
    2728#include "rfont.h" 
    2829#include "shader.h" 
     30 
     31 
     32#ifdef __APPLE__ 
     33#include <OpenGL/glu.h> 
     34#else 
     35#include <GL/glu.h> 
     36#endif 
    2937 
    3038 
     
    97105 
    98106 
    99 UR_CALL( to_raster ) 
    100 { 
    101     UR_CALL_UNUSED_TOS 
    102     ur_throwErr( UR_ERR_DATATYPE, "to cannot be used on raster!" ); 
    103 } 
    104  
    105  
    106 void toStr_raster( const UCell* cell, UString* out, int depth ) 
     107static void toStr_raster( const UCell* cell, UString* out, int depth ) 
    107108{ 
    108109    int uformat; 
     
    111112    (void) depth; 
    112113 
    113     rh = ur_rast(cell); 
     114    rh = ur_rastHead(cell); 
    114115    assert( rh ); 
    115116 
     
    134135 
    135136 
    136 int select_raster( UThread* ur_thread, UCell* val, const UCell* sel, 
    137                    UCell* res ) 
     137static int select_raster( UThread* ur_thread, UCell* val, const UCell* sel, 
     138                          UCell* res ) 
    138139{ 
    139140    RasterHead* rh; 
     
    143144        case UR_ATOM_X: 
    144145        case UR_ATOM_WIDTH: 
    145             rh = ur_rast(val); 
     146            rh = ur_rastHead(val); 
    146147            ur_initType(res, UT_INT); 
    147148            ur_int(res) = rh ? rh->width : 0; 
     
    150151        case UR_ATOM_Y: 
    151152        case UR_ATOM_HEIGHT: 
    152             rh = ur_rast(val); 
     153            rh = ur_rastHead(val); 
    153154            ur_initType(res, UT_INT); 
    154155            ur_int(res) = rh ? rh->height : 0; 
     
    172173    //printf( "KR mark raster\n" ); 
    173174    ur_gcMarkBin( gc, cell->series.n ); 
     175} 
     176 
     177 
     178/*--------------------------------------------------------------------------*/ 
     179 
     180 
     181static void _texFormat( const RasterHead* rh, GLint* comp, GLenum* format ) 
     182{ 
     183    switch( rh->format ) 
     184    { 
     185        case UR_RAST_GRAY: 
     186            *comp   = 1; 
     187            *format = GL_LUMINANCE; 
     188            break; 
     189 
     190        case UR_RAST_RGB: 
     191            *comp   = 3; 
     192            *format = GL_RGB; 
     193            break; 
     194 
     195        case UR_RAST_RGBA: 
     196            *comp   = 4; 
     197            *format = GL_RGBA; 
     198            break; 
     199    } 
     200} 
     201 
     202 
     203// (texture! raster -- texture) 
     204// (texture! [raster 'mipmap] -- texture) 
     205UR_CALL( make_texture ) 
     206{ 
     207    UCell* res = ur_s_prev(tos); 
     208 
     209    if( ur_is(res, UT_DATATYPE) ) 
     210    { 
     211        if( ur_is(tos, UT_RASTER) ) 
     212        { 
     213            RasterHead* rh; 
     214            int pool; 
     215            GLuint name; 
     216            GLenum format; 
     217            GLint comp; 
     218            int mipmap = 0; 
     219 
     220 
     221            name = gltex_alloc( &pool ); 
     222            rh = ur_rastHead(tos); 
     223 
     224            glBindTexture( GL_TEXTURE_2D, name ); 
     225            glTexEnvi( GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_MODULATE ); 
     226 
     227            _texFormat( rh, &comp, &format ); 
     228            if( mipmap ) 
     229            { 
     230                gluBuild2DMipmaps( GL_TEXTURE_2D, comp, rh->width, rh->height, 
     231                                   format, GL_UNSIGNED_BYTE, rh + 1 ); 
     232            } 
     233            else 
     234            { 
     235                glTexImage2D( GL_TEXTURE_2D, 0, comp, rh->width, rh->height, 0, 
     236                              format, GL_UNSIGNED_BYTE, rh + 1 ); 
     237            } 
     238 
     239            // GL_DECAL, GL_MODULATE, GL_REPLACE 
     240            glTexEnvi( GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_MODULATE ); 
     241 
     242            // GL_CLAMP, GL_REPEAT. 
     243            glTexParameteri( GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_REPEAT ); 
     244            glTexParameteri( GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_REPEAT ); 
     245 
     246            // GL_NEAREST, GL_LINEAR, GL_LINEAR_MIPMAP_NEAREST. 
     247            glTexParameteri( GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR ); 
     248            glTexParameteri( GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR ); 
     249 
     250 
     251            ur_initType( res, UT_TEXTURE ); 
     252            ur_texPool(res) = pool; 
     253            ur_texRast(res) = tos->series.n; 
     254            ur_texId(res)   = name; 
     255 
     256            UR_S_DROP; 
     257            return; 
     258        } 
     259    } 
     260    ur_throwErr( UR_ERR_DATATYPE, "texture! make expected raster!" ); 
     261} 
     262 
     263 
     264static void toStr_texture( const UCell* cell, UString* out, int depth ) 
     265{ 
     266    (void) cell; 
     267    (void) depth; 
     268    ur_strCat( out, "<texture>", 9 ); 
     269} 
     270 
     271 
     272static int select_texture( UThread* ur_thread, UCell* val, const UCell* sel, 
     273                           UCell* res ) 
     274{ 
     275    if( ur_sel(sel) == UT_RASTER /*UR_ATOM_RASTER*/ ) 
     276    { 
     277        UIndex ri = ur_texRast(val); 
     278        ur_initType(res, UT_RASTER); 
     279        ur_setSeries(res, ri, 0); 
     280        return 1; 
     281    } 
     282    return select_raster( ur_thread, val, sel, res ); 
     283} 
     284 
     285 
     286static void recycle_texture( UrlanEnv* env, int phase ) 
     287{ 
     288    (void) env; 
     289    if( phase == UR_GC_PHASE_MARK ) 
     290        gltex_gcBegin(); 
     291    else 
     292        gltex_gcSweep(); 
     293} 
     294 
     295 
     296static void mark_texture( UCollector* gc, UCell* cell ) 
     297{ 
     298    UCellTexture* tc = (UCellTexture*) cell; 
     299    ur_gcMarkBin( gc, tc->rasterN ); 
     300    gltex_gcMark( tc->glTexIdPool, tc->glTexId ); 
    174301} 
    175302 
     
    240367 
    241368 
    242 UR_CALL( to_rfont ) 
    243 { 
    244     UR_CALL_UNUSED_TOS 
    245     ur_throwErr( UR_ERR_DATATYPE, "'to cannot be used on font!" ); 
    246 } 
    247  
    248  
    249 void toStr_rfont( const UCell* cell, UString* out, int depth ) 
     369static void toStr_rfont( const UCell* cell, UString* out, int depth ) 
    250370{ 
    251371    (void) cell; 
     
    255375 
    256376 
    257 int select_rfont( UThread* ur_thread, UCell* val, const UCell* sel, 
    258                    UCell* res ) 
     377static int select_rfont( UThread* ur_thread, UCell* val, const UCell* sel, 
     378                         UCell* res ) 
    259379{ 
    260380    switch( ur_sel(sel) ) 
     
    380500 
    381501 
    382 UR_CALL( to_shader ) 
    383 { 
    384     UR_CALL_UNUSED_TOS 
    385     ur_throwErr( UR_ERR_DATATYPE, "'to cannot be used on shader!" ); 
    386 } 
    387  
    388  
    389 void toStr_shader( const UCell* cell, UString* out, int depth ) 
     502static void toStr_shader( const UCell* cell, UString* out, int depth ) 
    390503{ 
    391504    (void) cell; 
     
    395508 
    396509 
    397 int select_shader( UThread* ur_thread, UCell* val, const UCell* sel, 
    398                    UCell* res ) 
     510static void mark_shader( UCollector* gc, UCell* cell ) 
     511{ 
     512    ur_gcMarkBuffer( gc, cell->series.n ); 
     513} 
     514 
     515 
     516static void rmbuf_shader( UBuffer* buf ) 
     517{ 
     518    //printf( "KR rmbuf_shader()\n" ); 
     519    Shader* sh = (Shader*) buf->ptr; 
     520    if( sh ) 
     521    { 
     522        destroyShader( sh ); 
     523        memFree( sh ); 
     524        buf->ptr = 0; 
     525    } 
     526} 
     527 
     528 
     529/*--------------------------------------------------------------------------*/ 
     530 
     531 
     532UR_CALL( to_nop ) 
     533{ 
     534    tos = ur_s_prev(tos); 
     535    ur_throwErr( UR_ERR_DATATYPE, "'to cannot be used on %s!", 
     536                 ur_typeName( ur_type(tos) ) ); 
     537} 
     538 
     539 
     540static int select_nop( UThread* ur_thread, UCell* val, const UCell* sel, 
     541                       UCell* res ) 
    399542{ 
    400543    (void) val; 
     
    406549 
    407550 
    408 static void mark_shader( UCollector* gc, UCell* cell ) 
    409 { 
    410     ur_gcMarkBuffer( gc, cell->series.n ); 
    411 } 
    412  
    413  
    414 static void rmbuf_shader( UBuffer* buf ) 
    415 { 
    416     //printf( "KR rmbuf_shader()\n" ); 
    417     Shader* sh = (Shader*) buf->ptr; 
    418     if( sh ) 
    419     { 
    420         destroyShader( sh ); 
    421         memFree( sh ); 
    422         buf->ptr = 0; 
    423     } 
    424 } 
    425  
    426  
    427 /*--------------------------------------------------------------------------*/ 
    428  
    429  
    430 static void recycle_none( UrlanEnv* env, int phase ) 
     551static void recycle_nop( UrlanEnv* env, int phase ) 
    431552{ 
    432553    (void) env; 
     
    436557 
    437558 
    438 static void rmbuf_none( UBuffer* buf ) 
     559static void rmbuf_nop( UBuffer* buf ) 
    439560{ 
    440561    (void) buf; 
     
    442563 
    443564 
    444 UDatatype ug_datatypes[ 3 ] = 
     565UDatatype ug_datatypes[ 4 ] = 
    445566{ 
    446567    {"raster!", 0, 0, 
    447         make_raster, to_raster, toStr_raster, toStr_raster, 
    448         select_raster, recycle_none, mark_raster, rmbuf_none }, 
     568        make_raster, to_nop, toStr_raster, toStr_raster, 
     569        select_raster, recycle_nop, mark_raster, rmbuf_nop }, 
     570 
     571    {"texture!", 0, 0, 
     572        make_texture, to_nop, toStr_texture, toStr_texture, 
     573        select_texture, recycle_texture, mark_texture, rmbuf_nop }, 
    449574 
    450575    {"font!", 0, 0, 
    451         make_rfont, to_rfont, toStr_rfont, toStr_rfont, 
    452         select_rfont, recycle_rfont, mark_rfont, rmbuf_none }, 
     576        make_rfont, to_nop, toStr_rfont, toStr_rfont, 
     577        select_rfont, recycle_rfont, mark_rfont, rmbuf_nop }, 
    453578 
    454579    {"shader!", 0, 0, 
    455         make_shader, to_shader, toStr_shader, toStr_shader, 
    456         select_shader, recycle_none, mark_shader, rmbuf_shader }, 
     580        make_shader, to_nop, toStr_shader, toStr_shader, 
     581        select_nop, recycle_nop, mark_shader, rmbuf_shader }, 
    457582}; 
    458583 
  • trunk/thune/gl/png_load.c

    r286 r306  
    179179    else 
    180180    { 
    181         ur_throwErr( UR_ERR_DATATYPE, "load-png expected string!" ); 
     181        ur_throwErr( UR_ERR_DATATYPE, "load.png expected string!" ); 
    182182    } 
    183183} 
  • trunk/thune/gl/project.r

    r305 r306  
    8181        %audio.c 
    8282        %gllist.c 
     83        %gltex.c 
    8384        %png_load.c 
    8485        %TexFont.c 
  • trunk/thune/gl/shader.c

    r303 r306  
    215215                        break; 
    216216 
     217                    case GL_SAMPLER_1D_ARB: 
     218                    case GL_SAMPLER_2D_ARB: 
     219                    case GL_SAMPLER_3D_ARB: 
     220                        ur_initType( cval, UT_NONE ); 
     221                        ur_texId(cval) = 0;     // Expecting texture!. 
     222                        break; 
     223 
    217224                    default: 
    218225                        ur_initType( cval, UT_NONE ); 
     
    262269        if( cval && ur_is(cval, UT_SHADER) ) 
    263270        { 
     271            int texUnit = 0; 
    264272            Shader* sh = (Shader*) ur_bufPtr( cval->series.n )->ptr; 
    265273            glUseProgramObjectARB( sh->program ); 
     
    308316 
    309317                    //case GL_INT_VEC4_ARB: 
     318 
     319                    case GL_SAMPLER_1D_ARB: 
     320                    case GL_SAMPLER_2D_ARB: 
     321                    case GL_SAMPLER_3D_ARB: 
     322                        glActiveTexture( GL_TEXTURE0 + texUnit ); 
     323                        glEnable( GL_TEXTURE_2D ); 
     324                        glBindTexture( GL_TEXTURE_2D, ur_texId(cval) ); 
     325                        glUniform1iARB( pi->location, texUnit ); 
     326                        ++texUnit; 
     327                        break; 
    310328                } 
    311329                ++pi; 
    312330            } 
    313             /* 
    314             glUniform1fARB( loc_specularCoeff, specular_coefficient ); 
    315             */ 
    316  
    317331            return; 
    318332        } 
  • trunk/thune/gl/test.t

    r304 r306  
    4545[load shader! swap make] proc :load.shader   ; (file -- shader) 
    4646 
    47 "data/model/d7.gx" load draw-list.compile :d7-list 
    48  
    49 "data/shader/brick.gx" 
     47 
     48;"data/model/d7.gx" 
     49"data/model/cube.gx" 
     50    load draw-list.compile :d7-list 
     51 
     52;"data/shader/brick.gx" 
    5053;"data/shader/testA.gx" 
     54"data/shader/colormap.gx" 
    5155    load.shader :test-shader 
     56 
     57texture! 
     58"data/image/primal64.png" 
     59;"data/image/kr_wood01.png" 
     60    load.png make :test-shader/cmap 
     61 
     62;test-shader . 
    5263 
    53640,0,0 :strobe