Changeset 310 for trunk/thune/gl

Show
Ignore:
Timestamp:
11/20/06 03:13:29 (2 years ago)
Author:
krobillard
Message:

Thune -

Renamed UBuffer to UResource.
coord! 'make now resolves words.

Thune GL -

Added framebuffer! datatype.
Added 'framebuffer, 'particle, and 'rotate draw list opcodes.
Can now load grayscale PNG with alpha (alpha is ignored).

Location:
trunk/thune/gl
Files:
3 added
14 modified

Legend:

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

    r309 r310  
    6666void gr_enableTexture0() 
    6767{ 
     68#if 1 
    6869    glEnable( GL_TEXTURE_2D ); 
     70#else 
     71    glActiveTextureARB( GL_TEXTURE0_ARB + 0 ); 
     72    glEnable( GL_TEXTURE_2D ); 
     73    glActiveTextureARB( GL_TEXTURE0_ARB + 1 ); 
     74    glEnable( GL_TEXTURE_2D ); 
     75#endif 
    6976} 
    7077 
     
    131138 
    132139            //glTexEnvi( GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_MODULATE ); 
     140            break; 
     141 
     142        case GRS_PARTICLE: 
     143            if( _state.stateId != GRS_TEXT ) 
     144            { 
     145                glDepthMask( GL_FALSE ); 
     146 
     147                glDisable( GL_ALPHA_TEST ); 
     148                glDisable( GL_DEPTH_TEST ); 
     149                glDisable( GL_FOG ); 
     150                glDisable( GL_LIGHTING ); 
     151                glDisable( GL_COLOR_MATERIAL ); 
     152 
     153                glEnable( GL_BLEND ); 
     154            } 
     155            glEnable( GL_VERTEX_PROGRAM_POINT_SIZE_ARB ); 
     156            gr_disableTexture(); 
     157 
     158            /* 
     159            glBlendFunc( GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA );  // trans 
     160            glBlendFunc( GL_SRC_ALPHA, GL_ONE );            // additive 
     161            glBlendFunc( GL_ONE, GL_ONE_MINUS_SRC_ALPHA );  // color glow 
     162            glBlendFunc( GL_ONE_MINUS_SRC_ALPHA, GL_ONE );  // rings 
     163            glBlendFunc( GL_SRC_ALPHA, GL_DST_COLOR ); 
     164            glBlendFunc( GL_SRC_COLOR, GL_ONE_MINUS_SRC_ALPHA ); // low energy 
     165            */ 
    133166            break; 
    134167    } 
     
    511544            { 
    512545                float* uv = _state.uvVals + *it * 2; 
    513                 glMultiTexCoord2fv( GL_TEXTURE0_ARB, uv ); 
    514                 //glMultiTexCoord2f( GL_TEXTURE0_ARB, uv[0], 1.0f - uv[1] ); 
     546                //glMultiTexCoord2fv( GL_TEXTURE0_ARB, uv ); 
     547                glMultiTexCoord2f( GL_TEXTURE0_ARB, uv[0], 1.0f - uv[1] ); 
    515548            } 
    516549                break; 
     
    577610            case DOP_MODEL: 
    578611                gr_setState( GRS_MODEL ); 
     612                break; 
     613 
     614            case DOP_PARTICLE: 
     615                switch( ur_sel(pc) ) 
     616                { 
     617                    case UR_ATOM_OFF: 
     618                        glDisable( GL_VERTEX_PROGRAM_POINT_SIZE_ARB ); 
     619                        break; 
     620 
     621                    case UR_ATOM_ADD:       // Additive. 
     622                        gr_setState( GRS_PARTICLE ); 
     623                        glBlendFunc( GL_SRC_ALPHA, GL_ONE ); 
     624                        break; 
     625 
     626                    case UR_ATOM_BURN:      // Controlled additivity. 
     627                        gr_setState( GRS_PARTICLE ); 
     628                        glBlendFunc( GL_ONE, GL_ONE_MINUS_SRC_ALPHA ); 
     629                        break; 
     630 
     631                    case UR_ATOM_COLOR:     // ? 
     632                        gr_setState( GRS_PARTICLE ); 
     633                        glBlendFunc( GL_SRC_COLOR, GL_ONE_MINUS_SRC_ALPHA ); 
     634                        break; 
     635 
     636                    case UR_ATOM_TRANS:     // Standard Transparency. 
     637                    default: 
     638                        gr_setState( GRS_PARTICLE ); 
     639                        glBlendFunc( GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA ); 
     640                        break; 
     641                } 
    579642                break; 
    580643 
     
    701764                break; 
    702765 
    703             case DOP_ROTATE: 
     766            case DOP_ROTATE:    // angle decimal!/int!  axis vec3! 
     767            { 
     768                GLfloat angle; 
     769 
     770                ++pc; 
     771                VAL_WORD_OR_PC 
     772                angle = (GLfloat) number_d( val ); 
     773 
     774                ++pc; 
     775                VAL_WORD_OR_PC 
     776                if( ur_is(val, UT_VEC3) ) 
     777                { 
     778                    glRotatef( angle, val->vec3.xyz[0], 
     779                                      val->vec3.xyz[1], 
     780                                      val->vec3.xyz[2] ); 
     781                } 
     782            } 
    704783                break; 
    705784 
    706785            case DOP_SCALE: 
    707786            { 
    708                 GLdouble n; 
    709  
    710                 ++pc; 
    711                 VAL_WORD_OR_PC 
    712                 n = number_d( val ); 
    713                 glScalef( n, n, n ); 
     787                ++pc; 
     788                VAL_WORD_OR_PC 
     789                if( ur_is(val, UT_VEC3) ) 
     790                { 
     791                    glScalef( val->vec3.xyz[0], 
     792                              val->vec3.xyz[1], 
     793                              val->vec3.xyz[2] ); 
     794                } 
     795                else 
     796                { 
     797                    GLdouble n = number_d( val ); 
     798                    glScaled( n, n, n ); 
     799                } 
    714800            } 
    715801                break; 
     
    743829                VAL_WORD_OR_PC 
    744830                loadShader( val ); 
     831                break; 
     832 
     833            case DOP_FRAMEBUFFER: 
     834                ++pc; 
     835                VAL_WORD_OR_PC 
     836                if( ur_is(val, UT_FBO) ) 
     837                    glBindFramebufferEXT( GL_FRAMEBUFFER_EXT, ur_fboId(val) ); 
     838                else 
     839                    glBindFramebufferEXT( GL_FRAMEBUFFER_EXT, 0 ); 
    745840                break; 
    746841 
  • trunk/thune/gl/draw_ops.h

    r301 r310  
    66#define DOP_SOLID           3 
    77#define DOP_MODEL           4 
    8 #define DOP_COLOR           5 
    9 #define DOP_COLORS          6 
    10 #define DOP_VERTS           7 
    11 #define DOP_NORMALS         8 
    12 #define DOP_UVS             9 
    13 #define DOP_POINTS          10 
    14 #define DOP_LINES           11 
    15 #define DOP_LINE_STRIP      12 
    16 #define DOP_TRIS            13 
    17 #define DOP_TRI_STRIP       14 
    18 #define DOP_TRI_FAN         15 
    19 #define DOP_QUADS           16 
    20 #define DOP_QUAD_STRIP      17 
    21 #define DOP_CAMERA          18 
    22 #define DOP_LIGHT           19 
    23 #define DOP_LIGHTING        20 
    24 #define DOP_PUSH            21 
    25 #define DOP_POP             22 
    26 #define DOP_TRANSLATE       23 
    27 #define DOP_ROTATE          24 
    28 #define DOP_SCALE           25 
    29 #define DOP_FONT            26 
    30 #define DOP_TEXT            27 
    31 #define DOP_SHADER          28 
     8#define DOP_PARTICLE        5 
     9#define DOP_COLOR           6 
     10#define DOP_COLORS          7 
     11#define DOP_VERTS           8 
     12#define DOP_NORMALS         9 
     13#define DOP_UVS             10 
     14#define DOP_POINTS          11 
     15#define DOP_LINES           12 
     16#define DOP_LINE_STRIP      13 
     17#define DOP_TRIS            14 
     18#define DOP_TRI_STRIP       15 
     19#define DOP_TRI_FAN         16 
     20#define DOP_QUADS           17 
     21#define DOP_QUAD_STRIP      18 
     22#define DOP_CAMERA          19 
     23#define DOP_LIGHT           20 
     24#define DOP_LIGHTING        21 
     25#define DOP_PUSH            22 
     26#define DOP_POP             23 
     27#define DOP_TRANSLATE       24 
     28#define DOP_ROTATE          25 
     29#define DOP_SCALE           26 
     30#define DOP_FONT            27 
     31#define DOP_TEXT            28 
     32#define DOP_SHADER          29 
     33#define DOP_FRAMEBUFFER     30 
  • trunk/thune/gl/gllist.c

    r283 r310  
    114114 
    115115 
    116 static void _emptyLists( int i, int end, uint32_t removed, GLuint listBase ) 
     116static void _destroy( int i, int end, uint32_t removed, GLuint listBase ) 
    117117{ 
    118118    for( ; i < end; ++i ) 
     
    148148 
    149149            if( removed & 0xff ) 
    150                 _emptyLists( 0, 8, removed, base ); 
     150                _destroy( 0, 8, removed, base ); 
    151151            if( removed & 0xff00 ) 
    152                 _emptyLists( 8, 16, removed, base ); 
     152                _destroy( 8, 16, removed, base ); 
    153153            if( removed & 0xff0000 ) 
    154                 _emptyLists( 16, 24, removed, base ); 
     154                _destroy( 16, 24, removed, base ); 
    155155            if( removed & 0xff000000 ) 
    156                 _emptyLists( 24, 32, removed, base ); 
     156                _destroy( 24, 32, removed, base ); 
    157157        } 
    158158    } 
  • trunk/thune/gl/gltex.c

    r307 r310  
    117117 
    118118 
    119 static void _delTextures( int i, int end, uint32_t removed, GLuint listBase ) 
     119static void _destroy( int i, int end, uint32_t removed, GLuint listBase ) 
    120120{ 
    121121    for( ; i < end; ++i ) 
     
    150150 
    151151            if( removed & 0xff ) 
    152                 _delTextures( 0, 8, removed, base ); 
     152                _destroy( 0, 8, removed, base ); 
    153153            if( removed & 0xff00 ) 
    154                 _delTextures( 8, 16, removed, base ); 
     154                _destroy( 8, 16, removed, base ); 
    155155            if( removed & 0xff0000 ) 
    156                 _delTextures( 16, 24, removed, base ); 
     156                _destroy( 16, 24, removed, base ); 
    157157            if( removed & 0xff000000 ) 
    158                 _delTextures( 24, 32, removed, base ); 
     158                _destroy( 24, 32, removed, base ); 
    159159        } 
    160160    } 
  • trunk/thune/gl/gx.c

    r306 r310  
    3232#include "gllist.h" 
    3333#include "gltex.h" 
     34#include "glfbo.h" 
    3435#include "math3d.h" 
    3536//#include <time.h> 
     
    18531854    FIXED_ATOM( "default",  7, UR_ATOM_DEFAULT ); 
    18541855 
    1855     /* 
     1856    // Textures 
     1857    FIXED_ATOM( "rgb",      3, UR_ATOM_RGB ); 
     1858    FIXED_ATOM( "rgba",     4, UR_ATOM_RGBA ); 
     1859    FIXED_ATOM( "depth",    5, UR_ATOM_DEPTH ); 
    18561860    FIXED_ATOM( "clamp",    5, UR_ATOM_CLAMP ); 
    18571861    FIXED_ATOM( "repeat",   6, UR_ATOM_REPEAT ); 
     
    18601864    FIXED_ATOM( "min",      3, UR_ATOM_MIN ); 
    18611865    FIXED_ATOM( "mag",      3, UR_ATOM_MAG ); 
    1862     */ 
     1866 
     1867    // Particles 
     1868    FIXED_ATOM( "on",       2, UR_ATOM_ON ); 
     1869    FIXED_ATOM( "off",      3, UR_ATOM_OFF ); 
     1870    FIXED_ATOM( "add",      3, UR_ATOM_ADD ); 
     1871    FIXED_ATOM( "burn",     4, UR_ATOM_BURN ); 
     1872    FIXED_ATOM( "color",    5, UR_ATOM_COLOR ); 
     1873    FIXED_ATOM( "trans",    5, UR_ATOM_TRANS ); 
    18631874 
    18641875#if MAKE_ATOM_HEADER 
     
    18721883int gx_startup( UrlanEnv* env ) 
    18731884{ 
    1874     (void) env; 
     1885    const GLubyte* gstr; 
     1886 
     1887#if 0 
     1888    printf( "sizeof(UCellRasterFont) %ld\n", sizeof(UCellRasterFont) ); 
     1889    printf( "sizeof(GLuint) %ld\n", sizeof(GLuint) ); 
     1890#endif 
    18751891 
    18761892    gxEnv.view = 0; 
     
    19021918    { 
    19031919        ur_throwErr( env->threads, UR_EX_INTERNAL, "glv_create() failed" ); 
     1920        return UR_EVAL_ERROR; 
     1921    } 
     1922 
     1923    gstr = glGetString( GL_VERSION ); 
     1924    if( gstr[0] != '2' ) 
     1925    { 
     1926        glv_destroy( gView ); 
     1927        gView = 0; 
     1928        ur_throwErr( env->threads, UR_EX_INTERNAL, "OpenGL 2.0 required" ); 
    19041929        return UR_EVAL_ERROR; 
    19051930    } 
     
    19121937    gllist_startup(); 
    19131938    gltex_startup(); 
     1939    glfbo_startup(); 
    19141940 
    19151941    return UR_EVAL_OK; 
  • trunk/thune/gl/gx.h

    r306 r310  
    3131 
    3232#define UT_RASTER   UT_BI_COUNT 
    33 #define UT_TEXTURE  UT_BI_COUNT+1 
    34 #define UT_FONT     UT_BI_COUNT+2 
    35 #define UT_SHADER   UT_BI_COUNT+3 
    36  
    37  
    38 /* 
    39 enum ResourceTypes 
    40 { 
    41     RES_TYPE_TEXTURE = 0, 
    42     RES_TYPE_DRAWLIST, 
    43     RES_TYPE_FONT, 
    44     RES_TYPE_COUNT 
    45 }; 
    46 */ 
     33#define UT_TEXTURE  (UT_BI_COUNT+1) 
     34#define UT_FONT     (UT_BI_COUNT+2) 
     35#define UT_SHADER   (UT_BI_COUNT+3) 
     36#define UT_FBO      (UT_BI_COUNT+4) 
    4737 
    4838 
     
    9181 
    9282 
    93 typedef struct 
    94 { 
    95 #if 0 
    96     Resource res; 
    97     //char*    name; 
    98 #endif 
    99     UIndex   imgHold; 
    100     GLuint   glTexId; 
    101 } 
    102 TextureResource; 
    103  
    104  
    105 //---------------------------------------------------------------------------- 
    106  
    107  
    10883enum GrRenderStateId 
    10984{ 
     
    11186    GRS_TEXT, 
    11287    GRS_SOLID, 
    113     GRS_MODEL 
     88    GRS_MODEL, 
     89    GRS_PARTICLE 
    11490}; 
    11591 
     
    202178#define ur_texPool(c)       ((UCellTexture*) c)->glTexIdPool 
    203179 
     180#define ur_fboId(c)         ((UCellTexture*) c)->glTexId 
     181#define ur_fboPool(c)       ((UCellTexture*) c)->glTexIdPool 
     182 
    204183 
    205184#endif /*GX_H*/ 
  • trunk/thune/gl/gx.t

    r301 r310  
    1414 
    1515 
     16/* 
     171.0, 0.0, 0.0 :axis.x 
     180.0, 1.0, 0.0 :axis.y 
     190.0, 0.0, 1.0 :axis.z 
     20*/ 
     21 
     22 
    1623[ 
    17     none :orient 
     24    none :orient    ; matrix 
    1825    none :position 
    19     none :viewport 
     26    none :viewport  ; coord 
    2027    65.0 :fov 
    2128    0.1  :near 
     
    96103    solid 
    97104    model 
     105    particle 
    98106 
    99107    color 
     
    126134 
    127135    shader 
     136    framebuffer 
    128137] 
    129138make-opcodes :draw-list-opcodes 
     
    180189 
    181190 
     191[load shader! swap make] proc :load.shader      ; (file -- shader) 
     192 
     193[load.png texture! swap make] proc :load.tex    ; (png -- texture) 
     194 
     195 
    182196;eof 
  • trunk/thune/gl/gx_atoms.h

    r304 r310  
    2222#define UR_ATOM_FRAGMENT                320 
    2323#define UR_ATOM_DEFAULT         321 
     24#define UR_ATOM_RGB             322 
     25#define UR_ATOM_RGBA            323 
     26#define UR_ATOM_DEPTH           324 
     27#define UR_ATOM_CLAMP           325 
     28#define UR_ATOM_REPEAT          326 
     29#define UR_ATOM_NEAREST         327 
     30#define UR_ATOM_LINEAR          328 
     31#define UR_ATOM_MIN             329 
     32#define UR_ATOM_MAG             330 
     33#define UR_ATOM_ON              246 
     34#define UR_ATOM_OFF             248 
     35#define UR_ATOM_ADD             189 
     36#define UR_ATOM_BURN            331 
     37#define UR_ATOM_COLOR           332 
     38#define UR_ATOM_TRANS           333 
  • trunk/thune/gl/gx_dt.c

    r306 r310  
    1717    Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA 
    1818===========================================================================*/ 
     19 
     20 
     21#ifdef __APPLE__ 
     22#include <OpenGL/glu.h> 
     23#else 
     24#define GL_GLEXT_PROTOTYPES 
     25#include <GL/glu.h> 
     26#endif 
    1927 
    2028 
     
    2634#include "gllist.h" 
    2735#include "gltex.h" 
     36#include "glfbo.h" 
    2837#include "rfont.h" 
    2938#include "shader.h" 
    30  
    31  
    32 #ifdef __APPLE__ 
    33 #include <OpenGL/glu.h> 
    34 #else 
    35 #include <GL/glu.h> 
    36 #endif 
    3739 
    3840 
     
    202204 
    203205// (texture! raster -- texture) 
    204 // (texture! [raster 'mipmap] -- texture) 
     206// (texture! coord  -- texture) 
     207//;(texture! [raster coord 'mipmap 'nearest 'linear 'repeat 'clamp] -- texture) 
    205208UR_CALL( make_texture ) 
    206209{ 
     210    int pool; 
     211    GLuint name; 
     212    GLenum format; 
     213    GLint comp; 
     214    int width, height; 
     215    void* pixels; 
     216    int mipmap = 0; 
     217    int wrap   = GL_REPEAT; 
     218    int filter = GL_LINEAR; 
     219    RasterHead* rh = 0; 
    207220    UCell* res = ur_s_prev(tos); 
    208221 
     
    211224        if( ur_is(tos, UT_RASTER) ) 
    212225        { 
    213             RasterHead* rh; 
    214             int pool; 
    215             GLuint name; 
    216             GLenum format; 
    217             GLint comp; 
    218             int mipmap = 0; 
    219  
    220  
     226            rh = ur_rastHead(tos); 
     227            width  = rh->width; 
     228            height = rh->height; 
     229            pixels = rh + 1; 
     230            _texFormat( rh, &comp, &format ); 
     231 
     232build: 
    221233            name = gltex_alloc( &pool ); 
    222             rh = ur_rastHead(tos); 
    223  
    224234            glBindTexture( GL_TEXTURE_2D, name ); 
    225             glTexEnvi( GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_MODULATE ); 
    226  
    227             _texFormat( rh, &comp, &format ); 
     235 
    228236            if( mipmap ) 
    229237            { 
    230                 gluBuild2DMipmaps( GL_TEXTURE_2D, comp, rh->width, rh->height, 
    231                                    format, GL_UNSIGNED_BYTE, rh + 1 ); 
     238                gluBuild2DMipmaps( GL_TEXTURE_2D, comp, width, height, 
     239                                   format, GL_UNSIGNED_BYTE, pixels ); 
    232240            } 
    233241            else 
    234242            { 
    235                 glTexImage2D( GL_TEXTURE_2D, 0, comp, rh->width, rh->height, 0, 
    236                               format, GL_UNSIGNED_BYTE, rh + 1 ); 
     243                glTexImage2D( GL_TEXTURE_2D, 0, comp, width, height, 0, 
     244                              format, GL_UNSIGNED_BYTE, pixels ); 
    237245            } 
    238246 
    239247            // GL_DECAL, GL_MODULATE, GL_REPLACE 
    240             glTexEnvi( GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_MODULATE ); 
     248            //glTexEnvi( GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_MODULATE ); 
    241249 
    242250            // 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 ); 
     251            glTexParameteri( GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, wrap ); 
     252            glTexParameteri( GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, wrap ); 
    245253 
    246254            // 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 ); 
     255            glTexParameteri( GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, filter ); 
     256            glTexParameteri( GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, filter ); 
    249257 
    250258 
    251259            ur_initType( res, UT_TEXTURE ); 
    252260            ur_texPool(res) = pool; 
    253             ur_texRast(res) = tos->series.n; 
     261            ur_texRast(res) = rh ? tos->series.n : 0; 
    254262            ur_texId(res)   = name; 
    255263 
    256264            UR_S_DROP; 
    257265            return; 
     266        } 
     267        else if( ur_is(tos, UT_COORD) ) 
     268        { 
     269            width  = tos->coord.elem[0]; 
     270            height = tos->coord.elem[1]; 
     271            pixels = 0; 
     272            comp   = 4; 
     273            format = GL_RGBA; 
     274 
     275            if( tos->coord.len > 2 ) 
     276            { 
     277                if( tos->coord.elem[2] == 3 ) 
     278                { 
     279                    comp   = 3; 
     280                    format = GL_RGB; 
     281                } 
     282                else if( tos->coord.elem[2] == 1 ) 
     283                { 
     284                    comp   = 1; 
     285                    format = GL_LUMINANCE; 
     286                } 
     287            } 
     288 
     289            goto build; 
    258290        } 
    259291    } 
     
    273305                           UCell* res ) 
    274306{ 
     307    UIndex ri = ur_texRast(val); 
     308 
    275309    if( ur_sel(sel) == UT_RASTER /*UR_ATOM_RASTER*/ ) 
    276310    { 
    277         UIndex ri = ur_texRast(val); 
    278         ur_initType(res, UT_RASTER); 
    279         ur_setSeries(res, ri, 0); 
     311        if( ri ) 
     312        { 
     313            ur_initType(res, UT_RASTER); 
     314            ur_setSeries(res, ri, 0); 
     315        } 
     316        else 
     317        { 
     318            ur_setNone(res); 
     319        } 
    280320        return 1; 
    281321    } 
    282     return select_raster( ur_thread, val, sel, res ); 
     322    if( ri ) 
     323        return select_raster( ur_thread, val, sel, res ); 
     324    return 0; 
    283325} 
    284326