Show
Ignore:
Timestamp:
07/25/07 22:34:48 (16 months ago)
Author:
krobillard
Message:

GL - texture! make can now make GL_TEXTURE_1D from binary!.

Files:
1 modified

Legend:

Unmodified
Added
Removed
  • branches/thune/thread_safe/gl/gx_dt.c

    r403 r438  
    11/*============================================================================ 
    22    Thune OpenGL Module 
    3     Copyright (C) 2005-2006  Karl Robillard 
     3    Copyright (C) 2005-2007  Karl Robillard 
    44 
    55    This library is free software; you can redistribute it and/or 
     
    305305static void _texCoord( TextureDef* tex, const UCell* cell ) 
    306306{ 
    307     tex->width  = cell->coord.elem[0]; 
    308     tex->height = cell->coord.elem[1]; 
     307    if( ur_is(cell, UT_COORD) ) 
     308    { 
     309        tex->width  = cell->coord.elem[0]; 
     310        tex->height = cell->coord.elem[1]; 
     311    } 
     312    else 
     313    { 
     314        tex->width  = ur_int(cell); 
     315        tex->height = 1; 
     316    } 
     317 
    309318    tex->pixels = 0; 
    310319    tex->comp   = 4; 
     
    327336 
    328337 
    329 // (texture! raster -- tex) 
    330 // (texture! coord  -- tex) 
    331 // (texture! [raster!/coord! 'mipmap 'nearest 'linear 'repeat 'clamp] -- tex) 
     338/* 
     339  (texture! raster -- tex) 
     340  (texture! coord  -- tex)    ; 2D Texture 
     341  (texture! int    -- tex)    ; 1D Texture 
     342  (texture! [raster!/coord!/int! 
     343             binary! 
     344             'mipmap 'nearest 'linear 'repeat 'clamp 
     345             'gray 'rgb' 'rgba ] -- tex) 
     346*/ 
    332347UR_CALL( make_texture ) 
    333348{ 
     
    337352    int mipmap = 0; 
    338353    UIndex rastN = 0; 
     354    GLenum target = GL_TEXTURE_2D; 
    339355    UCell* res = ur_s_prev(tos); 
    340356 
     
    353369        else if( ur_is(tos, UT_COORD) ) 
    354370        { 
     371            _texCoord( &def, tos ); 
     372            goto build; 
     373        } 
     374        else if( ur_is(tos, UT_INT) ) 
     375        { 
     376            target = GL_TEXTURE_1D; 
    355377            _texCoord( &def, tos ); 
    356378            goto build; 
     
    380402                            _texRast( &def, ur_rastHead(val) ); 
    381403                        }  
     404                        else if( ur_is(val, UT_BINARY) ) 
     405                        { 
     406                            def.pixels = ur_bin(val)->ptr.b; 
     407                        } 
    382408                        else if( ur_is(val, UT_COORD) ) 
    383409                        { 
     410                            _texCoord( &def, val ); 
     411                        } 
     412                        else if( ur_is(val, UT_INT) ) 
     413                        { 
     414                            target = GL_TEXTURE_1D; 
    384415                            _texCoord( &def, val ); 
    385416                        } 
     
    410441                                mipmap = 1; 
    411442                                break; 
     443 
     444                            case UR_ATOM_GRAY: 
     445                                def.comp   = 1; 
     446                                def.format = GL_LUMINANCE; 
     447                                break; 
     448 
     449                            case UR_ATOM_RGB: 
     450                                def.comp   = 3; 
     451                                def.format = GL_RGB; 
     452                                break; 
     453 
     454                            case UR_ATOM_RGBA: 
     455                                def.comp   = 4; 
     456                                def.format = GL_RGBA; 
     457                                break; 
    412458                        } 
     459                        break; 
     460 
     461                    case UT_INT: 
     462                        target = GL_TEXTURE_1D; 
     463                        _texCoord( &def, it ); 
    413464                        break; 
    414465 
     
    416467                        _texCoord( &def, it ); 
    417468                        break; 
     469 
     470                    case UT_BINARY: 
     471                        def.pixels = ur_bin(it)->ptr.b; 
    418472                } 
    419473                ++it; 
     
    431485 
    432486    name = gltex_alloc( &pool ); 
    433     glBindTexture( GL_TEXTURE_2D, name ); 
     487    glBindTexture( target, name ); 
    434488 
    435489    // TODO: Support texture type of GL_FLOAT. 
    436     if( mipmap ) 
    437     { 
    438         gluBuild2DMipmaps( GL_TEXTURE_2D, def.comp, def.width, def.height, 
    439                            def.format, GL_UNSIGNED_BYTE, def.pixels ); 
     490 
     491    if( target == GL_TEXTURE_2D ) 
     492    { 
     493        if( mipmap ) 
     494        { 
     495            gluBuild2DMipmaps( GL_TEXTURE_2D, def.comp, def.width, def.height, 
     496                               def.format, GL_UNSIGNED_BYTE, def.pixels ); 
     497        } 
     498        else 
     499        { 
     500            // Ensure that a non-mipmap minifying filter is used. 
     501            // Using a mipmap filter can cause FBO format errors and textures 
     502            // to not appear. 
     503            if( def.min_filter != GL_NEAREST ) 
     504                def.min_filter = GL_LINEAR; 
     505 
     506            glTexImage2D( GL_TEXTURE_2D, 0, def.comp, def.width, def.height, 
     507                          0, def.format, GL_UNSIGNED_BYTE, def.pixels ); 
     508        } 
    440509    } 
    441510    else 
    442511    { 
    443         // Ensure that a non-mipmap minifying filter is used. 
    444         // Using a mipmap filter can cause FBO format errors and textures to 
    445         // not appear. 
    446         if( def.min_filter != GL_NEAREST ) 
    447             def.min_filter = GL_LINEAR; 
    448  
    449         glTexImage2D( GL_TEXTURE_2D, 0, def.comp, def.width, def.height, 0, 
    450                       def.format, GL_UNSIGNED_BYTE, def.pixels ); 
     512        if( mipmap ) 
     513        { 
     514            gluBuild1DMipmaps( GL_TEXTURE_1D, def.comp, def.width, 
     515                               def.format, GL_UNSIGNED_BYTE, def.pixels ); 
     516        } 
     517        else 
     518        { 
     519            if( def.min_filter != GL_NEAREST ) 
     520                def.min_filter = GL_LINEAR; 
     521 
     522            glTexImage1D( GL_TEXTURE_1D, 0, def.comp, def.width, 
     523                          0, def.format, GL_UNSIGNED_BYTE, def.pixels ); 
     524        } 
    451525    } 
    452526 
     
    464538 
    465539    // GL_CLAMP, GL_CLAMP_TO_EDGE, GL_REPEAT. 
    466     glTexParameteri( GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, def.wrap ); 
    467     glTexParameteri( GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, def.wrap ); 
     540    glTexParameteri( target, GL_TEXTURE_WRAP_S, def.wrap ); 
     541    glTexParameteri( target, GL_TEXTURE_WRAP_T, def.wrap ); 
    468542 
    469543    // TODO: Support all GL_TEXTURE_MIN_FILTER types. 
    470544    // GL_NEAREST, GL_LINEAR, GL_LINEAR_MIPMAP_NEAREST, etc. 
    471     glTexParameteri( GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, def.min_filter ); 
     545    glTexParameteri( target, GL_TEXTURE_MIN_FILTER, def.min_filter ); 
    472546 
    473547    // GL_NEAREST, GL_LINEAR 
    474     glTexParameteri( GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, def.mag_filter ); 
     548    glTexParameteri( target, GL_TEXTURE_MAG_FILTER, def.mag_filter ); 
    475549 
    476550    ur_initType( res, UT_TEXTURE ); 
     
    522596    if( phase == UR_GC_PHASE_MARK ) 
    523597    { 
     598        // Clear any unchecked GL error. 
     599#ifdef DEBUG 
     600        GLenum err = glGetError(); 
     601        if( err ) 
     602            printf( "recycle_texture - glGetError() returned %d\n", err ); 
     603#else 
     604        glGetError(); 
     605#endif 
     606 
    524607        gllist_gcBegin(); 
    525608        gltex_gcBegin(); 
     
    9411024static int cmp_nop( UThread* ut, const UCell* a, const UCell* b, int mode ) 
    9421025{ 
     1026    (void) ut; 
     1027    (void) a; 
     1028    (void) b; 
     1029    (void) mode; 
    9431030    return 0; 
    9441031}