Changeset 312 for trunk/thune/gl

Show
Ignore:
Timestamp:
12/03/06 04:52:27 (2 years ago)
Author:
krobillard
Message:

Thune - Renamed array! to vector!. Added vector! make.

Location:
trunk/thune/gl
Files:
1 added
7 modified

Legend:

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

    r310 r312  
    1919 
    2020 
    21 #define GL_GLEXT_PROTOTYPES 
    22  
    2321#include <assert.h> 
     22#include "glh.h" 
    2423#include "gx.h" 
    2524#include "gx_atoms.h" 
     
    3231#include FT_FREETYPE_H 
    3332#include "TexFont.h" 
    34  
    35 #ifdef __APPLE__ 
    36 #include <OpenGL/glu.h> 
    37 #else 
    38 #include <GL/glu.h> 
    39 #endif 
    4033 
    4134 
     
    393386 
    394387        val = ctxCells + CAM_CTX_ORIENT; 
    395         if( ur_is(val, UT_ARRAY) && (ur_arrayDT(val) == UT_DECIMAL) ) 
     388        if( ur_is(val, UT_VECTOR) && (ur_arrayDT(val) == UT_DECIMAL) ) 
    396389        { 
    397390            GLfloat eye[16]; 
     
    494487 
    495488 
     489#if 0 
     490// Transform from -1..1 to 0..1 
     491const GLdouble bias[] = 
     492{ 
     493    0.5, 0.0, 0.0, 0.0,  
     494    0.0, 0.5, 0.0, 0.0, 
     495    0.0, 0.0, 0.5, 0.0, 
     496    0.5, 0.5, 0.5, 1.0 
     497}; 
     498 
     499 
     500static void dop_shadowmap( /*UThread* ur_thread,*/ UCell* fbCell ) 
     501{ 
     502    glBindFramebufferEXT( GL_FRAMEBUFFER_EXT, ur_fboId(fbCell) ); 
     503    glClear( GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT ); 
     504 
     505    //glPolygonOffset( polygon_offset_scale, polygon_offset_bias ); 
     506    glPolygonOffset( 2.0f, 10.0f ); 
     507    glEnable( GL_POLYGON_OFFSET_FILL ); 
     508 
     509    glMatrixMode( GL_TEXTURE ); 
     510    glLoadMatrixd( bias ); 
     511#if 1 
     512    gluPerspective( fov, 1, near, far ); 
     513#else 
     514    glMultMatrixd( l->get_proj_matrix() ); 
     515    glMultMatrixd( l->get_model_matrix() ); 
     516#endif 
     517    glMatrixMode( GL_MODELVIEW ); 
     518} 
     519 
     520 
     521static void dop_shadowmap_end() 
     522{ 
     523    glDisable( GL_POLYGON_OFFSET_FILL ); 
     524    glBindFramebufferEXT( GL_FRAMEBUFFER_EXT, 0 ); 
     525} 
     526#endif 
     527 
     528 
    496529/* 
    497530   icell is an int array! 
     
    598631                { 
    599632                    if( ur_gldl(val) ) 
     633                    { 
     634                        //if( ur_gldl(val) != 1 ) 
     635                        //    printf( "KR list %d\n", ur_gldl(val) ); 
    600636                        glCallList( ur_gldl(val) ); 
     637                    } 
    601638                    else if( ! _runDrawList( ur_thread, val ) ) 
    602639                        return 0; 
     
    710747            case DOP_VERTS: 
    711748                ++pc; 
    712                 if( ur_is(pc, UT_ARRAY) ) 
     749                if( ur_is(pc, UT_VECTOR) ) 
    713750                    _state.vertVals = ur_bin(pc)->ptr.f; 
    714751                break; 
     
    716753            case DOP_NORMALS: 
    717754                ++pc; 
    718                 if( ur_is(pc, UT_ARRAY) ) 
     755                if( ur_is(pc, UT_VECTOR) ) 
    719756                    _state.normVals = ur_bin(pc)->ptr.f; 
    720757                break; 
     
    722759            case DOP_UVS: 
    723760                ++pc; 
    724                 if( ur_is(pc, UT_ARRAY) ) 
     761                if( ur_is(pc, UT_VECTOR) ) 
    725762                    _state.uvVals = ur_bin(pc)->ptr.f; 
    726763                break; 
     
    736773                pc += 2; 
    737774                if( ur_is(pc-1, UT_WORD) && 
    738                     ur_is(pc, UT_ARRAY) && (ur_arrayDT(pc) == UT_INT) && 
     775                    ur_is(pc, UT_VECTOR) && (ur_arrayDT(pc) == UT_INT) && 
    739776                    _state.vertVals ) 
    740777                { 
     
    839876                    glBindFramebufferEXT( GL_FRAMEBUFFER_EXT, 0 ); 
    840877                break; 
    841  
     878#if 0 
     879            case DOP_SHADOWMAP: 
     880                ++pc; 
     881                VAL_WORD_OR_PC 
     882                if( ur_is(val, UT_FBO) ) 
     883                    dop_shadowmap( /*ur_thread,*/ val ); 
     884                else 
     885                    dop_shadowmap_end(); 
     886                break; 
     887#endif 
    842888            default: 
    843889                assert( 0 && "Invalid Draw List Opcode" ); 
     
    889935        gr_clearState(); 
    890936 
     937        //printf( "KR compile %d\n", ur_gldl(tos) ); 
     938 
    891939        glNewList( ur_gldl(tos), GL_COMPILE ); 
    892940 
  • trunk/thune/gl/draw_ops.h

    r310 r312  
    3232#define DOP_SHADER          29 
    3333#define DOP_FRAMEBUFFER     30 
     34#define DOP_SHADOWMAP       31 
  • trunk/thune/gl/gx.c

    r311 r312  
    2727#include <glv_keys.h> 
    2828#include "os.h" 
     29#include "glh.h" 
    2930#include "gx.h" 
    3031#include "gx_atoms.h" 
     
    3536#include "math3d.h" 
    3637//#include <time.h> 
    37  
    38 #ifdef __APPLE__ 
    39 #include <OpenGL/glu.h> 
    40 #else 
    41 #include <GL/glu.h> 
    42 #endif 
    4338 
    4439 
     
    10741069    prev = ur_s_prev(tos); 
    10751070 
    1076     if( ur_is(prev, UT_ARRAY) && ur_is(tos, UT_VEC3) ) 
     1071    if( ur_is(prev, UT_VECTOR) && ur_is(tos, UT_VEC3) ) 
    10771072    { 
    10781073        bin = ur_bin( prev ); 
     
    11061101 
    11071102 
     1103// Should 'gl-extensions, etc. be replaced with a single 'gl-info call that 
     1104// returns a context holding version, extensions, max-textures, etc.? 
     1105 
    11081106// ( -- string) 
    11091107UR_CALL( uc_gl_extensions ) 
    11101108{ 
    1111     // Replace with 'gl-info that returns version, extensions, etc.? 
    11121109    const GLubyte* str; 
    11131110    UIndex binN; 
     
    11241121    ur_setSeries(tos, binN, 0 ); 
    11251122} 
     1123 
     1124 
     1125// ( -- count) 
     1126UR_CALL( uc_gl_max_textures ) 
     1127{ 
     1128    GLint count; 
     1129 
     1130    UR_CALL_UNUSED_TH 
     1131    UR_CALL_UNUSED_TOS 
     1132 
     1133    glGetIntegerv( GL_MAX_TEXTURE_UNITS, &count ); 
     1134 
     1135    UR_S_GROW; 
     1136    ur_initType(UR_TOS, UT_INT); 
     1137    ur_int(UR_TOS) = count; 
     1138} 
     1139 
     1140 
     1141#if 0 
     1142#if 0 
     1143extern float perlinNoise2D( float x, float y, int octaves, float persist ); 
     1144#define PReal   float 
     1145#else 
     1146extern double perlinNoise2D( double x, double y, double alpha, double beta, 
     1147                             int n ); 
     1148#define PReal   double 
     1149#endif 
     1150 
     1151// (raster octaves persist -- raster) 
     1152UR_CALL( uc_perlin ) 
     1153{ 
     1154    RasterHead* rh; 
     1155    int octaves; 
     1156    PReal persist; 
     1157    UCell* octc = ur_s_prev(tos); 
     1158    UCell* rasc = ur_s_prev(octc); 
     1159 
     1160    if( ur_is(rasc, UT_RASTER) && 
     1161        ur_is(octc, UT_INT) && 
     1162        ur_is(tos, UT_DECIMAL) ) 
     1163    { 
     1164        PReal x, y, w, h, n; 
     1165        int in; 
     1166        uint8_t* ep; 
     1167 
     1168        octaves = ur_int(octc); 
     1169        if( octaves < 1 ) 
     1170            octaves = 1; 
     1171        else if( octaves > 4 ) 
     1172            octaves = 4; 
     1173 
     1174        persist = ur_decimal(tos); 
     1175        if( persist < 0.05f ) 
     1176            persist = 0.05f; 
     1177        else if( persist > 1.0f ) 
     1178            persist = 1.0f; 
     1179 
     1180        rh = ur_rastHead(rasc); 
     1181        assert( rh ); 
     1182 
     1183        w  = (PReal) rh->width; 
     1184        h  = (PReal) rh->height; 
     1185        ep = (uint8_t*) (rh + 1); 
     1186 
     1187        switch( rh->format ) 
     1188        { 
     1189            case UR_RAST_GRAY: 
     1190                break; 
     1191 
     1192            case UR_RAST_RGB: 
     1193                for( y = 0.0f; y < h; y += 1.0f ) 
     1194                { 
     1195                    for( x = 0.0f; x < w; x += 1.0f ) 
     1196                    { 
     1197                      //n = perlinNoise2D( x * 0.1, y * 0.1, octaves, persist ); 
     1198                        n = perlinNoise2D( x/w, y/h, persist, 2, octaves ); 
     1199 
     1200                        //printf( "%g\n", n ); 
     1201                        in = (int) ((n + 1.0f) * 127.0f); 
     1202                        *ep++ = in; 
     1203                        *ep++ = in; 
     1204                        *ep++ = in; 
     1205                    } 
     1206                    //printf( "\n" ); 
     1207                } 
     1208                break; 
     1209 
     1210            case UR_RAST_RGBA: 
     1211                break; 
     1212        } 
     1213 
     1214         
     1215        UR_S_DROPN(2); 
     1216        return; 
     1217    } 
     1218 
     1219    ur_throwErr( UR_ERR_DATATYPE, "perlin expected raster! int! decimal!" ); 
     1220} 
     1221 
     1222 
     1223extern const char* _framebufferStatus(); 
     1224 
     1225// (size -- framebuffer) 
     1226UR_CALL( uc_shadowmap ) 
     1227{ 
     1228    if( ur_is(tos, UT_COORD) ) 
     1229    { 
     1230        GLuint fboName; 
     1231        GLuint texName; 
     1232        GLint depthBits; 
     1233        int fboPool; 
     1234        int texPool; 
     1235        const char* err; 
     1236 
     1237 
     1238        glGetIntegerv( GL_DEPTH_BITS, &depthBits ); 
     1239        printf( "KR depthBits %d\n", depthBits ); 
     1240 
     1241        // TODO: Hold texture! (return context?) 
     1242        texName = gltex_alloc( &texPool ); 
     1243        glBindTexture( GL_TEXTURE_2D, texName ); 
     1244        glTexImage2D( GL_TEXTURE_2D, 0, 
     1245                      (depthBits == 16) ? GL_DEPTH_COMPONENT16 : 
     1246                                          GL_DEPTH_COMPONENT24, 
     1247                      tos->coord.elem[0], tos->coord.elem[1], 0, 
     1248                      GL_DEPTH_COMPONENT, 
     1249                      //GL_UNSIGNED_INT, 
     1250                      GL_UNSIGNED_BYTE, 
     1251                      NULL ); 
     1252 
     1253        glTexParameteri( GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR ); 
     1254        glTexParameteri( GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR ); 
     1255        glTexParameteri( GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_CLAMP_TO_EDGE ); 
     1256        glTexParameteri( GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_CLAMP_TO_EDGE ); 
     1257        glTexParameteri( GL_TEXTURE_2D, GL_TEXTURE_COMPARE_MODE_ARB, 
     1258                                        GL_COMPARE_R_TO_TEXTURE_ARB ); 
     1259        glTexParameteri( GL_TEXTURE_2D, GL_TEXTURE_COMPARE_FUNC_ARB, 
     1260                                        GL_LEQUAL ); 
     1261        //glTexParameteri( GL_TEXTURE_2D, GL_DEPTH_TEXTURE_MODE_ARB, 
     1262        //                 GL_INTENSITY ); 
     1263 
     1264 
     1265        fboName = glfbo_alloc( &fboPool ); 
     1266        glBindFramebufferEXT( GL_FRAMEBUFFER_EXT, fboName ); 
     1267        glFramebufferTexture2DEXT( GL_FRAMEBUFFER_EXT, 
     1268                 GL_DEPTH_ATTACHMENT_EXT, GL_TEXTURE_2D, texName, 0 ); 
     1269        glDrawBuffer( GL_NONE ); 
     1270        //glReadBuffer( GL_FALSE ); 
     1271 
     1272        if( (err = _framebufferStatus()) ) 
     1273        { 
     1274            ur_throwErr( UR_ERR_INTERNAL, err ); 
     1275            return; 
     1276        } 
     1277 
     1278        glBindFramebufferEXT( GL_FRAMEBUFFER_EXT, 0 ); 
     1279 
     1280        ur_initType( tos, UT_FBO ); 
     1281        ur_fboPool(tos) = fboPool; 
     1282        ur_fboId(tos)   = fboName; 
     1283        return; 
     1284    } 
     1285    ur_throwErr( UR_ERR_DATATYPE, "shadowmap expected coord!" ); 
     1286} 
     1287#endif 
    11261288 
    11271289 
     
    18301992    { uc_display,        "display" }, 
    18311993    { uc_look_at,        "look-at" }, 
    1832     { uc_gl_extensions,  "gl-extensions" } 
     1994    { uc_gl_extensions,  "gl-extensions" }, 
     1995    { uc_gl_max_textures,"gl-max-textures" }, 
     1996    //{ uc_perlin,         "perlin" }, 
     1997    //{ uc_shadowmap,      "shadowmap" } 
    18331998}; 
    18341999 
  • trunk/thune/gl/gx.t

    r310 r312  
    135135    shader 
    136136    framebuffer 
     137    shadowmap 
    137138] 
    138139make-opcodes :draw-list-opcodes 
     
    193194[load.png texture! swap make] proc :load.tex    ; (png -- texture) 
    194195 
     196[file | rast] 
     197[ 
     198    file load.png :rast 
     199    texture! [rast 'mipmap] make 
     200] func :load.mip    ; (png -- texture) 
     201 
    195202 
    196203;eof 
  • trunk/thune/gl/gx_dt.c

    r311 r312  
    1919 
    2020 
    21 #ifdef __APPLE__ 
    22 #include <OpenGL/glu.h> 
    23 #else 
    24 #define GL_GLEXT_PROTOTYPES 
    25 #include <GL/glu.h> 
    26 #endif 
    27  
    28  
    2921#include "os.h" 
     22#include "glh.h" 
    3023#include "gx.h" 
    3124#include "internal.h" 
     
    695688 
    696689 
    697 static const char* _framebufferStatus() 
     690const char* _framebufferStatus() 
    698691{ 
    699692    GLenum status; 
  • trunk/thune/gl/project.r

    r310 r312  
    8787        %rfont.c 
    8888        %shader.c 
    89         ;%res.c 
     89        ;%perlin.c 
     90        ;%noise.c 
    9091        ;%../util/cbparse.c 
    9192        ;%png_save.c 
  • trunk/thune/gl/test.t

    r310 r312  
    5050 
    5151;"data/shader/brick.gx" 
    52 ;"data/shader/testA.gx" 
     52;"data/shader/specular.gx" 
    5353"data/shader/colormap.gx" 
    5454    load.shader :test-shader