Changeset 311 for trunk/thune/gl
- Timestamp:
- 11/22/06 22:12:17 (2 years ago)
- Location:
- trunk/thune/gl
- Files:
-
- 3 modified
Legend:
- Unmodified
- Added
- Removed
-
trunk/thune/gl/gx.c
r310 r311 1103 1103 1104 1104 ur_throwErr( UR_ERR_DATATYPE, "look-at expected array! vec3!" ); 1105 } 1106 1107 1108 // ( -- string) 1109 UR_CALL( uc_gl_extensions ) 1110 { 1111 // Replace with 'gl-info that returns version, extensions, etc.? 1112 const GLubyte* str; 1113 UIndex binN; 1114 1115 UR_CALL_UNUSED_TH 1116 1117 str = glGetString( GL_EXTENSIONS ); 1118 binN = ur_makeString( (const char*) str, -1 ); 1119 1120 1121 UR_S_GROW; 1122 tos = UR_TOS; 1123 ur_initType(tos, UT_STRING); 1124 ur_setSeries(tos, binN, 0 ); 1105 1125 } 1106 1126 … … 1809 1829 { uc_load_wav, "load.wav" }, 1810 1830 { uc_display, "display" }, 1811 { uc_look_at, "look-at" } 1831 { uc_look_at, "look-at" }, 1832 { uc_gl_extensions, "gl-extensions" } 1812 1833 }; 1813 1834 … … 1833 1854 FIXED_ATOM( "width", 5, UR_ATOM_WIDTH ) 1834 1855 FIXED_ATOM( "height", 6, UR_ATOM_HEIGHT ) 1856 FIXED_ATOM( "area", 4, UR_ATOM_AREA ) 1857 FIXED_ATOM( "rect", 4, UR_ATOM_RECT ) 1835 1858 FIXED_ATOM( "raster", 6, UR_ATOM_RASTER ) 1836 1859 FIXED_ATOM( "elem", 4, UR_ATOM_ELEM ) … … 1864 1887 FIXED_ATOM( "min", 3, UR_ATOM_MIN ); 1865 1888 FIXED_ATOM( "mag", 3, UR_ATOM_MAG ); 1889 FIXED_ATOM( "mipmap", 6, UR_ATOM_MIPMAP ); 1866 1890 1867 1891 // Particles -
trunk/thune/gl/gx_atoms.h
r310 r311 1 1 // This file is automatically generated - do not edit. 2 2 3 #define UR_ATOM_WIDTH 302 4 #define UR_ATOM_HEIGHT 303 5 #define UR_ATOM_RASTER 304 6 #define UR_ATOM_ELEM 305 7 #define UR_ATOM_CLOSE 170 8 #define UR_ATOM_FOCUS 306 9 #define UR_ATOM_RESIZE 307 10 #define UR_ATOM_KEY_DOWN 308 11 #define UR_ATOM_KEY_UP 309 12 #define UR_ATOM_MOUSE_MOVE 310 13 #define UR_ATOM_MOUSE_UP 311 14 #define UR_ATOM_MOUSE_DOWN 312 15 #define UR_ATOM_MOUSE_WHEEL 313 16 #define UR_ATOM_AMBIENT 314 17 #define UR_ATOM_DIFFUSE 315 18 #define UR_ATOM_SPECULAR 316 19 #define UR_ATOM_POS 317 20 #define UR_ATOM_SHADER 318 21 #define UR_ATOM_VERTEX 319 22 #define UR_ATOM_FRAGMENT 320 23 #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 3 #define UR_ATOM_WIDTH 303 4 #define UR_ATOM_HEIGHT 304 5 #define UR_ATOM_AREA 305 6 #define UR_ATOM_RECT 306 7 #define UR_ATOM_RASTER 307 8 #define UR_ATOM_ELEM 308 9 #define UR_ATOM_CLOSE 171 10 #define UR_ATOM_FOCUS 309 11 #define UR_ATOM_RESIZE 310 12 #define UR_ATOM_KEY_DOWN 311 13 #define UR_ATOM_KEY_UP 312 14 #define UR_ATOM_MOUSE_MOVE 313 15 #define UR_ATOM_MOUSE_UP 314 16 #define UR_ATOM_MOUSE_DOWN 315 17 #define UR_ATOM_MOUSE_WHEEL 316 18 #define UR_ATOM_AMBIENT 317 19 #define UR_ATOM_DIFFUSE 318 20 #define UR_ATOM_SPECULAR 319 21 #define UR_ATOM_POS 320 22 #define UR_ATOM_SHADER 321 23 #define UR_ATOM_VERTEX 322 24 #define UR_ATOM_FRAGMENT 323 25 #define UR_ATOM_DEFAULT 324 26 #define UR_ATOM_RGB 325 27 #define UR_ATOM_RGBA 326 28 #define UR_ATOM_DEPTH 327 29 #define UR_ATOM_CLAMP 328 30 #define UR_ATOM_REPEAT 329 31 #define UR_ATOM_NEAREST 330 32 #define UR_ATOM_LINEAR 331 33 #define UR_ATOM_MIN 332 34 #define UR_ATOM_MAG 333 35 #define UR_ATOM_MIPMAP 334 36 #define UR_ATOM_ON 247 37 #define UR_ATOM_OFF 249 38 #define UR_ATOM_ADD 190 39 #define UR_ATOM_BURN 335 40 #define UR_ATOM_COLOR 336 41 #define UR_ATOM_TRANS 337 -
trunk/thune/gl/gx_dt.c
r310 r311 157 157 ur_int(res) = rh ? rh->height : 0; 158 158 break; 159 159 #if 0 160 case UR_ATOM_RECT: // Can plug directly into camera/viewport. 161 ur_initType(res, UT_COORD); 162 res->coord.elem[0] = 0; 163 res->coord.elem[1] = 0; 164 165 rh = ur_rastHead(val); 166 if( rh ) 167 { 168 res->coord.elem[2] = rh->width; 169 res->coord.elem[3] = rh->height; 170 res->coord.len = 4; 171 } 172 else 173 { 174 res->coord.len = 2; 175 } 176 break; 177 #endif 160 178 case UR_ATOM_ELEM: 161 179 ur_initType(res, UT_BINARY); … … 181 199 182 200 183 static void _texFormat( const RasterHead* rh, GLint* comp, GLenum* format ) 184 { 201 struct TextureDef 202 { 203 const void* pixels; 204 int width; 205 int height; 206 GLenum format; 207 GLint comp; 208 GLint wrap; 209 GLint min_filter; 210 GLint mag_filter; 211 }; 212 213 214 static void _texRast( struct TextureDef* tex, const RasterHead* rh ) 215 { 216 tex->width = rh->width; 217 tex->height = rh->height; 218 tex->pixels = rh + 1; 219 185 220 switch( rh->format ) 186 221 { 187 222 case UR_RAST_GRAY: 188 *comp = 1;189 *format = GL_LUMINANCE;223 tex->comp = 1; 224 tex->format = GL_LUMINANCE; 190 225 break; 191 226 192 227 case UR_RAST_RGB: 193 *comp = 3;194 *format = GL_RGB;228 tex->comp = 3; 229 tex->format = GL_RGB; 195 230 break; 196 231 197 232 case UR_RAST_RGBA: 198 *comp = 4; 199 *format = GL_RGBA; 233 default: 234 tex->comp = 4; 235 tex->format = GL_RGBA; 200 236 break; 201 237 } … … 203 239 204 240 205 // (texture! raster -- texture) 206 // (texture! coord -- texture) 207 //;(texture! [raster coord 'mipmap 'nearest 'linear 'repeat 'clamp] -- texture) 241 static void _texCoord( struct TextureDef* tex, const UCell* cell ) 242 { 243 tex->width = cell->coord.elem[0]; 244 tex->height = cell->coord.elem[1]; 245 tex->pixels = 0; 246 tex->comp = 4; 247 tex->format = GL_RGBA; 248 249 if( cell->coord.len > 2 ) 250 { 251 if( cell->coord.elem[2] == 3 ) 252 { 253 tex->comp = 3; 254 tex->format = GL_RGB; 255 } 256 else if( cell->coord.elem[2] == 1 ) 257 { 258 tex->comp = 1; 259 tex->format = GL_LUMINANCE; 260 } 261 } 262 } 263 264 265 // (texture! raster -- tex) 266 // (texture! coord -- tex) 267 // (texture! [raster!/coord! 'mipmap 'nearest 'linear 'repeat 'clamp] -- tex) 208 268 UR_CALL( make_texture ) 209 269 { 270 struct TextureDef def; 271 GLuint name; 210 272 int pool; 211 GLuint name;212 GLenum format;213 GLint comp;214 int width, height;215 void* pixels;216 273 int mipmap = 0; 217 int wrap = GL_REPEAT; 218 int filter = GL_LINEAR; 219 RasterHead* rh = 0; 274 UIndex rastN = 0; 220 275 UCell* res = ur_s_prev(tos); 221 276 277 def.wrap = GL_REPEAT; 278 def.min_filter = GL_NEAREST_MIPMAP_LINEAR; 279 def.mag_filter = GL_LINEAR; 280 222 281 if( ur_is(res, UT_DATATYPE) ) 223 282 { 224 283 if( ur_is(tos, UT_RASTER) ) 225 284 { 226 rh = ur_rastHead(tos); 227 width = rh->width; 228 height = rh->height; 229 pixels = rh + 1; 230 _texFormat( rh, &comp, &format ); 285 rastN = tos->series.n; 286 _texRast( &def, ur_rastHead(tos) ); 287 goto build; 288 } 289 else if( ur_is(tos, UT_COORD) ) 290 { 291 _texCoord( &def, tos ); 292 goto build; 293 } 294 else if( ur_is(tos, UT_BLOCK) ) 295 { 296 UCell* it; 297 UCell* end; 298 UCell* val; 299 UBlock* blk; 300 301 def.width = 0; 302 303 blk = ur_block(tos); 304 UR_ITER_BLOCK( it, end, blk, tos ); 305 while( it != end ) 306 { 307 switch( ur_type(it) ) 308 { 309 case UT_WORD: 310 val = ur_wordCell( ur_thread, it ); 311 if( ! val ) 312 return; 313 if( ur_is(val, UT_RASTER) ) 314 { 315 rastN = val->series.n; 316 _texRast( &def, ur_rastHead(val) ); 317 } 318 else if( ur_is(val, UT_COORD) ) 319 { 320 _texCoord( &def, val ); 321 } 322 break; 323 324 case UT_LITWORD: 325 switch( ur_atom( it ) ) 326 { 327 case UR_ATOM_CLAMP: 328 def.wrap = GL_CLAMP; 329 break; 330 331 case UR_ATOM_REPEAT: 332 def.wrap = GL_REPEAT; 333 break; 334 335 case UR_ATOM_NEAREST: 336 def.min_filter = GL_NEAREST; 337 def.mag_filter = GL_NEAREST; 338 break; 339 340 case UR_ATOM_LINEAR: 341 def.min_filter = GL_LINEAR; 342 def.mag_filter = GL_LINEAR; 343 break; 344 345 case UR_ATOM_MIPMAP: 346 mipmap = 1; 347 break; 348 } 349 break; 350 351 case UT_COORD: 352 _texCoord( &def, it ); 353 break; 354 } 355 ++it; 356 } 357 358 if( def.width ) 359 goto build; 360 } 361 } 362 363 ur_throwErr( UR_ERR_DATATYPE, "texture! make expected coord!/raster!" ); 364 return; 231 365 232 366 build: 233 name = gltex_alloc( &pool ); 234 glBindTexture( GL_TEXTURE_2D, name ); 235 236 if( mipmap ) 237 { 238 gluBuild2DMipmaps( GL_TEXTURE_2D, comp, width, height, 239 format, GL_UNSIGNED_BYTE, pixels ); 240 } 241 else 242 { 243 glTexImage2D( GL_TEXTURE_2D, 0, comp, width, height, 0, 244 format, GL_UNSIGNED_BYTE, pixels ); 245 } 246 247 // GL_DECAL, GL_MODULATE, GL_REPLACE 248 //glTexEnvi( GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_MODULATE ); 249 250 // GL_CLAMP, GL_REPEAT. 251 glTexParameteri( GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, wrap ); 252 glTexParameteri( GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, wrap ); 253 254 // GL_NEAREST, GL_LINEAR, GL_LINEAR_MIPMAP_NEAREST. 255 glTexParameteri( GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, filter ); 256 glTexParameteri( GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, filter ); 257 258 259 ur_initType( res, UT_TEXTURE ); 260 ur_texPool(res) = pool; 261 ur_texRast(res) = rh ? tos->series.n : 0; 262 ur_texId(res) = name; 263 264 UR_S_DROP; 367 368 name = gltex_alloc( &pool ); 369 glBindTexture( GL_TEXTURE_2D, name ); 370 371 // TODO: Support texture type of GL_FLOAT. 372 if( mipmap ) 373 { 374 gluBuild2DMipmaps( GL_TEXTURE_2D, def.comp, def.width, def.height, 375 def.format, GL_UNSIGNED_BYTE, def.pixels ); 376 } 377 else 378 { 379 // Ensure that a non-mipmap minifying filter is used. 380 // Using a mipmap filter can cause FBO format errors and textures to 381 // not appear. 382 if( def.min_filter != GL_NEAREST ) 383 def.min_filter = GL_LINEAR; 384 385 glTexImage2D( GL_TEXTURE_2D, 0, def.comp, def.width, def.height, 0, 386 def.format, GL_UNSIGNED_BYTE, def.pixels ); 387 } 388 389 { 390 GLenum err = glGetError(); 391 if( err != GL_NO_ERROR ) 392 { 393 ur_throwErr( UR_ERR_INTERNAL, (const char*) gluErrorString( err ) ); 265 394 return; 266 395 } 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; 290 } 291 } 292 ur_throwErr( UR_ERR_DATATYPE, "texture! make expected raster!" ); 396 } 397 398 // GL_DECAL, GL_MODULATE, GL_REPLACE 399 //glTexEnvi( GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_MODULATE ); 400 401 // GL_CLAMP, GL_CLAMP_TO_EDGE, GL_REPEAT. 402 glTexParameteri( GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, def.wrap ); 403 glTexParameteri( GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, def.wrap ); 404 405 // TODO: Support all GL_TEXTURE_MIN_FILTER types. 406 // GL_NEAREST, GL_LINEAR, GL_LINEAR_MIPMAP_NEAREST, etc. 407 glTexParameteri( GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, def.min_filter ); 408 409 // GL_NEAREST, GL_LINEAR 410 glTexParameteri( GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, def.mag_filter ); 411 412 ur_initType( res, UT_TEXTURE ); 413 ur_texPool(res) = pool; 414 ur_texRast(res) = rastN; 415 ur_texId(res) = name; 416 417 UR_S_DROP; 293 418 } 294 419
