Changeset 306 for trunk/thune/gl
- Timestamp:
- 11/05/06 03:27:39 (2 years ago)
- Location:
- trunk/thune/gl
- Files:
-
- 9 modified
Legend:
- Unmodified
- Added
- Removed
-
trunk/thune/gl/audio.c
r305 r306 178 178 else 179 179 { 180 ur_throwErr( UR_ERR_DATATYPE, "load -wav expected string!" );180 ur_throwErr( UR_ERR_DATATYPE, "load.wav expected string!" ); 181 181 } 182 182 } -
trunk/thune/gl/draw_list.c
r301 r306 18 18 ===========================================================================*/ 19 19 20 21 #define GL_GLEXT_PROTOTYPES 20 22 21 23 #include <assert.h> … … 110 112 glDisable( GL_BLEND ); 111 113 112 gr_disableTexture(); 114 //gr_disableTexture(); 115 gr_enableTexture0(); 113 116 break; 114 117 … … 505 508 //glVertex3dv( vec ); 506 509 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 } 507 518 break; 508 519 } -
trunk/thune/gl/gx.c
r304 r306 31 31 #include "audio.h" 32 32 #include "gllist.h" 33 #include "gltex.h" 33 34 #include "math3d.h" 34 35 //#include <time.h> … … 1799 1800 { uc_play, "play" }, 1800 1801 { uc_stop, "stop" }, 1801 // { uc_load_png, "load-png" },1802 1802 { uc_display_events, "display.events" }, 1803 1803 { uc_display_swap, "display.swap" }, … … 1805 1805 { uc_key_repeat, "key-repeat" }, 1806 1806 { 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" }, 1809 1809 { uc_display, "display" }, 1810 1810 { uc_look_at, "look-at" } … … 1853 1853 FIXED_ATOM( "default", 7, UR_ATOM_DEFAULT ); 1854 1854 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 1855 1864 #if MAKE_ATOM_HEADER 1856 1865 exit(0); … … 1902 1911 1903 1912 gllist_startup(); 1913 gltex_startup(); 1904 1914 1905 1915 return UR_EVAL_OK; -
trunk/thune/gl/gx.h
r301 r306 31 31 32 32 #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 35 36 36 37 … … 84 85 85 86 87 typedef UCellRasterFont UCellTexture; 88 89 86 90 //---------------------------------------------------------------------------- 87 91 … … 187 191 UIndex ur_makeRaster( UCell*, int format, int w, int h ); 188 192 189 #define ur_rast (c)((RasterHead*) ur_bin(c)->ptr.v)193 #define ur_rastHead(c) ((RasterHead*) ur_bin(c)->ptr.v) 190 194 #define ur_rasterElem(bin) (bin->ptr.b + sizeof(RasterHead)) 191 195 … … 194 198 #define ur_fontTexId(c) ((UCellRasterFont*) c)->glTexId 195 199 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 196 204 197 205 #endif /*GX_H*/ -
trunk/thune/gl/gx_dt.c
r304 r306 25 25 #include "gx_atoms.h" 26 26 #include "gllist.h" 27 #include "gltex.h" 27 28 #include "rfont.h" 28 29 #include "shader.h" 30 31 32 #ifdef __APPLE__ 33 #include <OpenGL/glu.h> 34 #else 35 #include <GL/glu.h> 36 #endif 29 37 30 38 … … 97 105 98 106 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 ) 107 static void toStr_raster( const UCell* cell, UString* out, int depth ) 107 108 { 108 109 int uformat; … … 111 112 (void) depth; 112 113 113 rh = ur_rast (cell);114 rh = ur_rastHead(cell); 114 115 assert( rh ); 115 116 … … 134 135 135 136 136 int select_raster( UThread* ur_thread, UCell* val, const UCell* sel,137 UCell* res )137 static int select_raster( UThread* ur_thread, UCell* val, const UCell* sel, 138 UCell* res ) 138 139 { 139 140 RasterHead* rh; … … 143 144 case UR_ATOM_X: 144 145 case UR_ATOM_WIDTH: 145 rh = ur_rast (val);146 rh = ur_rastHead(val); 146 147 ur_initType(res, UT_INT); 147 148 ur_int(res) = rh ? rh->width : 0; … … 150 151 case UR_ATOM_Y: 151 152 case UR_ATOM_HEIGHT: 152 rh = ur_rast (val);153 rh = ur_rastHead(val); 153 154 ur_initType(res, UT_INT); 154 155 ur_int(res) = rh ? rh->height : 0; … … 172 173 //printf( "KR mark raster\n" ); 173 174 ur_gcMarkBin( gc, cell->series.n ); 175 } 176 177 178 /*--------------------------------------------------------------------------*/ 179 180 181 static 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) 205 UR_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 264 static 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 272 static 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 286 static 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 296 static 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 ); 174 301 } 175 302 … … 240 367 241 368 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 ) 369 static void toStr_rfont( const UCell* cell, UString* out, int depth ) 250 370 { 251 371 (void) cell; … … 255 375 256 376 257 int select_rfont( UThread* ur_thread, UCell* val, const UCell* sel,258 UCell* res )377 static int select_rfont( UThread* ur_thread, UCell* val, const UCell* sel, 378 UCell* res ) 259 379 { 260 380 switch( ur_sel(sel) ) … … 380 500 381 501 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 ) 502 static void toStr_shader( const UCell* cell, UString* out, int depth ) 390 503 { 391 504 (void) cell; … … 395 508 396 509 397 int select_shader( UThread* ur_thread, UCell* val, const UCell* sel, 398 UCell* res ) 510 static void mark_shader( UCollector* gc, UCell* cell ) 511 { 512 ur_gcMarkBuffer( gc, cell->series.n ); 513 } 514 515 516 static 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 532 UR_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 540 static int select_nop( UThread* ur_thread, UCell* val, const UCell* sel, 541 UCell* res ) 399 542 { 400 543 (void) val; … … 406 549 407 550 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 ) 551 static void recycle_nop( UrlanEnv* env, int phase ) 431 552 { 432 553 (void) env; … … 436 557 437 558 438 static void rmbuf_no ne( UBuffer* buf )559 static void rmbuf_nop( UBuffer* buf ) 439 560 { 440 561 (void) buf; … … 442 563 443 564 444 UDatatype ug_datatypes[ 3] =565 UDatatype ug_datatypes[ 4 ] = 445 566 { 446 567 {"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 }, 449 574 450 575 {"font!", 0, 0, 451 make_rfont, to_ rfont, toStr_rfont, toStr_rfont,452 select_rfont, recycle_rfont, mark_rfont, rmbuf_no ne},576 make_rfont, to_nop, toStr_rfont, toStr_rfont, 577 select_rfont, recycle_rfont, mark_rfont, rmbuf_nop }, 453 578 454 579 {"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 }, 457 582 }; 458 583 -
trunk/thune/gl/png_load.c
r286 r306 179 179 else 180 180 { 181 ur_throwErr( UR_ERR_DATATYPE, "load -png expected string!" );181 ur_throwErr( UR_ERR_DATATYPE, "load.png expected string!" ); 182 182 } 183 183 } -
trunk/thune/gl/project.r
r305 r306 81 81 %audio.c 82 82 %gllist.c 83 %gltex.c 83 84 %png_load.c 84 85 %TexFont.c -
trunk/thune/gl/shader.c
r303 r306 215 215 break; 216 216 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 217 224 default: 218 225 ur_initType( cval, UT_NONE ); … … 262 269 if( cval && ur_is(cval, UT_SHADER) ) 263 270 { 271 int texUnit = 0; 264 272 Shader* sh = (Shader*) ur_bufPtr( cval->series.n )->ptr; 265 273 glUseProgramObjectARB( sh->program ); … … 308 316 309 317 //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; 310 328 } 311 329 ++pi; 312 330 } 313 /*314 glUniform1fARB( loc_specularCoeff, specular_coefficient );315 */316 317 331 return; 318 332 } -
trunk/thune/gl/test.t
r304 r306 45 45 [load shader! swap make] proc :load.shader ; (file -- shader) 46 46 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" 50 53 ;"data/shader/testA.gx" 54 "data/shader/colormap.gx" 51 55 load.shader :test-shader 56 57 texture! 58 "data/image/primal64.png" 59 ;"data/image/kr_wood01.png" 60 load.png make :test-shader/cmap 61 62 ;test-shader . 52 63 53 64 0,0,0 :strobe
