Changeset 312 for trunk/thune/gl
- Timestamp:
- 12/03/06 04:52:27 (2 years ago)
- Location:
- trunk/thune/gl
- Files:
-
- 1 added
- 7 modified
Legend:
- Unmodified
- Added
- Removed
-
trunk/thune/gl/draw_list.c
r310 r312 19 19 20 20 21 #define GL_GLEXT_PROTOTYPES22 23 21 #include <assert.h> 22 #include "glh.h" 24 23 #include "gx.h" 25 24 #include "gx_atoms.h" … … 32 31 #include FT_FREETYPE_H 33 32 #include "TexFont.h" 34 35 #ifdef __APPLE__36 #include <OpenGL/glu.h>37 #else38 #include <GL/glu.h>39 #endif40 33 41 34 … … 393 386 394 387 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) ) 396 389 { 397 390 GLfloat eye[16]; … … 494 487 495 488 489 #if 0 490 // Transform from -1..1 to 0..1 491 const 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 500 static 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 521 static void dop_shadowmap_end() 522 { 523 glDisable( GL_POLYGON_OFFSET_FILL ); 524 glBindFramebufferEXT( GL_FRAMEBUFFER_EXT, 0 ); 525 } 526 #endif 527 528 496 529 /* 497 530 icell is an int array! … … 598 631 { 599 632 if( ur_gldl(val) ) 633 { 634 //if( ur_gldl(val) != 1 ) 635 // printf( "KR list %d\n", ur_gldl(val) ); 600 636 glCallList( ur_gldl(val) ); 637 } 601 638 else if( ! _runDrawList( ur_thread, val ) ) 602 639 return 0; … … 710 747 case DOP_VERTS: 711 748 ++pc; 712 if( ur_is(pc, UT_ ARRAY) )749 if( ur_is(pc, UT_VECTOR) ) 713 750 _state.vertVals = ur_bin(pc)->ptr.f; 714 751 break; … … 716 753 case DOP_NORMALS: 717 754 ++pc; 718 if( ur_is(pc, UT_ ARRAY) )755 if( ur_is(pc, UT_VECTOR) ) 719 756 _state.normVals = ur_bin(pc)->ptr.f; 720 757 break; … … 722 759 case DOP_UVS: 723 760 ++pc; 724 if( ur_is(pc, UT_ ARRAY) )761 if( ur_is(pc, UT_VECTOR) ) 725 762 _state.uvVals = ur_bin(pc)->ptr.f; 726 763 break; … … 736 773 pc += 2; 737 774 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) && 739 776 _state.vertVals ) 740 777 { … … 839 876 glBindFramebufferEXT( GL_FRAMEBUFFER_EXT, 0 ); 840 877 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 842 888 default: 843 889 assert( 0 && "Invalid Draw List Opcode" ); … … 889 935 gr_clearState(); 890 936 937 //printf( "KR compile %d\n", ur_gldl(tos) ); 938 891 939 glNewList( ur_gldl(tos), GL_COMPILE ); 892 940 -
trunk/thune/gl/draw_ops.h
r310 r312 32 32 #define DOP_SHADER 29 33 33 #define DOP_FRAMEBUFFER 30 34 #define DOP_SHADOWMAP 31 -
trunk/thune/gl/gx.c
r311 r312 27 27 #include <glv_keys.h> 28 28 #include "os.h" 29 #include "glh.h" 29 30 #include "gx.h" 30 31 #include "gx_atoms.h" … … 35 36 #include "math3d.h" 36 37 //#include <time.h> 37 38 #ifdef __APPLE__39 #include <OpenGL/glu.h>40 #else41 #include <GL/glu.h>42 #endif43 38 44 39 … … 1074 1069 prev = ur_s_prev(tos); 1075 1070 1076 if( ur_is(prev, UT_ ARRAY) && ur_is(tos, UT_VEC3) )1071 if( ur_is(prev, UT_VECTOR) && ur_is(tos, UT_VEC3) ) 1077 1072 { 1078 1073 bin = ur_bin( prev ); … … 1106 1101 1107 1102 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 1108 1106 // ( -- string) 1109 1107 UR_CALL( uc_gl_extensions ) 1110 1108 { 1111 // Replace with 'gl-info that returns version, extensions, etc.?1112 1109 const GLubyte* str; 1113 1110 UIndex binN; … … 1124 1121 ur_setSeries(tos, binN, 0 ); 1125 1122 } 1123 1124 1125 // ( -- count) 1126 UR_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 1143 extern float perlinNoise2D( float x, float y, int octaves, float persist ); 1144 #define PReal float 1145 #else 1146 extern 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) 1152 UR_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 1223 extern const char* _framebufferStatus(); 1224 1225 // (size -- framebuffer) 1226 UR_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 1126 1288 1127 1289 … … 1830 1992 { uc_display, "display" }, 1831 1993 { 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" } 1833 1998 }; 1834 1999 -
trunk/thune/gl/gx.t
r310 r312 135 135 shader 136 136 framebuffer 137 shadowmap 137 138 ] 138 139 make-opcodes :draw-list-opcodes … … 193 194 [load.png texture! swap make] proc :load.tex ; (png -- texture) 194 195 196 [file | rast] 197 [ 198 file load.png :rast 199 texture! [rast 'mipmap] make 200 ] func :load.mip ; (png -- texture) 201 195 202 196 203 ;eof -
trunk/thune/gl/gx_dt.c
r311 r312 19 19 20 20 21 #ifdef __APPLE__22 #include <OpenGL/glu.h>23 #else24 #define GL_GLEXT_PROTOTYPES25 #include <GL/glu.h>26 #endif27 28 29 21 #include "os.h" 22 #include "glh.h" 30 23 #include "gx.h" 31 24 #include "internal.h" … … 695 688 696 689 697 staticconst char* _framebufferStatus()690 const char* _framebufferStatus() 698 691 { 699 692 GLenum status; -
trunk/thune/gl/project.r
r310 r312 87 87 %rfont.c 88 88 %shader.c 89 ;%res.c 89 ;%perlin.c 90 ;%noise.c 90 91 ;%../util/cbparse.c 91 92 ;%png_save.c -
trunk/thune/gl/test.t
r310 r312 50 50 51 51 ;"data/shader/brick.gx" 52 ;"data/shader/ testA.gx"52 ;"data/shader/specular.gx" 53 53 "data/shader/colormap.gx" 54 54 load.shader :test-shader
