From e0caf654e6c56de827cf6ae98565873909cc2409 Mon Sep 17 00:00:00 2001 From: Joe Groff Date: Sat, 12 Jan 2008 22:58:56 -0800 Subject: [PATCH 01/30] OpenGL 2.1 support --- core/alien/syntax/syntax.factor | 9 + extra/opengl/gl/gl.factor | 858 +++++++++++++++++++------ extra/opengl/gl/unix/unix.factor | 5 + extra/opengl/gl/windows/windows.factor | 18 + extra/opengl/opengl.factor | 101 ++- 5 files changed, 809 insertions(+), 182 deletions(-) create mode 100644 extra/opengl/gl/unix/unix.factor create mode 100644 extra/opengl/gl/windows/windows.factor diff --git a/core/alien/syntax/syntax.factor b/core/alien/syntax/syntax.factor index 99275d02bf..bc3bc911ef 100755 --- a/core/alien/syntax/syntax.factor +++ b/core/alien/syntax/syntax.factor @@ -23,6 +23,15 @@ IN: alien.syntax PRIVATE> +: indirect-quot ( function-ptr-quot return types abi -- quot ) + [ alien-indirect ] 3curry compose ; + +: define-indirect ( abi return function-ptr-quot function-name parameters -- ) + >r pick r> parse-arglist + rot create-in dup reset-generic + >r >r swapd roll indirect-quot r> r> + -rot define-declared ; + : DLL" skip-blank parse-string dlopen parsed ; parsing : ALIEN: scan string>number parsed ; parsing diff --git a/extra/opengl/gl/gl.factor b/extra/opengl/gl/gl.factor index 40ead55ddd..c7ce176aca 100644 --- a/extra/opengl/gl/gl.factor +++ b/extra/opengl/gl/gl.factor @@ -3,7 +3,10 @@ ! This file is based on the gl.h that comes with xorg-x11 6.8.2 -USING: alien alien.syntax kernel sequences words ; +USING: alien alien.syntax kernel sequences system words ; +USE-IF: windows? opengl.gl.windows +USE-IF: unix? opengl.gl.unix + IN: opengl.gl TYPEDEF: uint GLenum @@ -1118,195 +1121,690 @@ FUNCTION: void glPushName ( GLuint name ) ; FUNCTION: void glPopName ( ) ; +! OpenGL extension functions + + + + + ! OpenGL 1.2 -: GL_PACK_SKIP_IMAGES HEX: 806B ; inline -: GL_PACK_IMAGE_HEIGHT HEX: 806C ; inline -: GL_UNPACK_SKIP_IMAGES HEX: 806D ; inline -: GL_UNPACK_IMAGE_HEIGHT HEX: 806E ; inline -: GL_TEXTURE_3D HEX: 806F ; inline -: GL_PROXY_TEXTURE_3D HEX: 8070 ; inline -: GL_TEXTURE_DEPTH HEX: 8071 ; inline -: GL_TEXTURE_WRAP_R HEX: 8072 ; inline -: GL_MAX_3D_TEXTURE_SIZE HEX: 8073 ; inline -: GL_BGR HEX: 80E0 ; inline -: GL_BGRA HEX: 80E1 ; inline -: GL_UNSIGNED_BYTE_3_3_2 HEX: 8032 ; inline -: GL_UNSIGNED_BYTE_2_3_3_REV HEX: 8362 ; inline -: GL_UNSIGNED_SHORT_5_6_5 HEX: 8363 ; inline -: GL_UNSIGNED_SHORT_5_6_5_REV HEX: 8364 ; inline -: GL_UNSIGNED_SHORT_4_4_4_4 HEX: 8033 ; inline -: GL_UNSIGNED_SHORT_4_4_4_4_REV HEX: 8365 ; inline -: GL_UNSIGNED_SHORT_5_5_5_1 HEX: 8034 ; inline -: GL_UNSIGNED_SHORT_1_5_5_5_REV HEX: 8366 ; inline -: GL_UNSIGNED_INT_8_8_8_8 HEX: 8035 ; inline -: GL_UNSIGNED_INT_8_8_8_8_REV HEX: 8367 ; inline -: GL_UNSIGNED_INT_10_10_10_2 HEX: 8036 ; inline -: GL_UNSIGNED_INT_2_10_10_10_REV HEX: 8368 ; inline -: GL_RESCALE_NORMAL HEX: 803A ; inline -: GL_LIGHT_MODEL_COLOR_CONTROL HEX: 81F8 ; inline -: GL_SINGLE_COLOR HEX: 81F9 ; inline -: GL_SEPARATE_SPECULAR_COLOR HEX: 81FA ; inline -: GL_CLAMP_TO_EDGE HEX: 812F ; inline -: GL_TEXTURE_MIN_LOD HEX: 813A ; inline -: GL_TEXTURE_MAX_LOD HEX: 813B ; inline -: GL_TEXTURE_BASE_LEVEL HEX: 813C ; inline -: GL_TEXTURE_MAX_LEVEL HEX: 813D ; inline -: GL_MAX_ELEMENTS_VERTICES HEX: 80E8 ; inline -: GL_MAX_ELEMENTS_INDICES HEX: 80E9 ; inline -: GL_ALIASED_POINT_SIZE_RANGE HEX: 846D ; inline -: GL_ALIASED_LINE_WIDTH_RANGE HEX: 846E ; inline +: GL_SMOOTH_POINT_SIZE_RANGE HEX: 0B12 ; inline +: GL_SMOOTH_POINT_SIZE_GRANULARITY HEX: 0B13 ; inline +: GL_SMOOTH_LINE_WIDTH_RANGE HEX: 0B22 ; inline +: GL_SMOOTH_LINE_WIDTH_GRANULARITY HEX: 0B23 ; inline +: GL_UNSIGNED_BYTE_3_3_2 HEX: 8032 ; inline +: GL_UNSIGNED_SHORT_4_4_4_4 HEX: 8033 ; inline +: GL_UNSIGNED_SHORT_5_5_5_1 HEX: 8034 ; inline +: GL_UNSIGNED_INT_8_8_8_8 HEX: 8035 ; inline +: GL_UNSIGNED_INT_10_10_10_2 HEX: 8036 ; inline +: GL_RESCALE_NORMAL HEX: 803A ; inline +: GL_TEXTURE_BINDING_3D HEX: 806A ; inline +: GL_PACK_SKIP_IMAGES HEX: 806B ; inline +: GL_PACK_IMAGE_HEIGHT HEX: 806C ; inline +: GL_UNPACK_SKIP_IMAGES HEX: 806D ; inline +: GL_UNPACK_IMAGE_HEIGHT HEX: 806E ; inline +: GL_TEXTURE_3D HEX: 806F ; inline +: GL_PROXY_TEXTURE_3D HEX: 8070 ; inline +: GL_TEXTURE_DEPTH HEX: 8071 ; inline +: GL_TEXTURE_WRAP_R HEX: 8072 ; inline +: GL_MAX_3D_TEXTURE_SIZE HEX: 8073 ; inline +: GL_BGR HEX: 80E0 ; inline +: GL_BGRA HEX: 80E1 ; inline +: GL_MAX_ELEMENTS_VERTICES HEX: 80E8 ; inline +: GL_MAX_ELEMENTS_INDICES HEX: 80E9 ; inline +: GL_CLAMP_TO_EDGE HEX: 812F ; inline +: GL_TEXTURE_MIN_LOD HEX: 813A ; inline +: GL_TEXTURE_MAX_LOD HEX: 813B ; inline +: GL_TEXTURE_BASE_LEVEL HEX: 813C ; inline +: GL_TEXTURE_MAX_LEVEL HEX: 813D ; inline +: GL_LIGHT_MODEL_COLOR_CONTROL HEX: 81F8 ; inline +: GL_SINGLE_COLOR HEX: 81F9 ; inline +: GL_SEPARATE_SPECULAR_COLOR HEX: 81FA ; inline +: GL_UNSIGNED_BYTE_2_3_3_REV HEX: 8362 ; inline +: GL_UNSIGNED_SHORT_5_6_5 HEX: 8363 ; inline +: GL_UNSIGNED_SHORT_5_6_5_REV HEX: 8364 ; inline +: GL_UNSIGNED_SHORT_4_4_4_4_REV HEX: 8365 ; inline +: GL_UNSIGNED_SHORT_1_5_5_5_REV HEX: 8366 ; inline +: GL_UNSIGNED_INT_8_8_8_8_REV HEX: 8367 ; inline +: GL_UNSIGNED_INT_2_10_10_10_REV HEX: 8368 ; inline +: GL_ALIASED_POINT_SIZE_RANGE HEX: 846D ; inline +: GL_ALIASED_LINE_WIDTH_RANGE HEX: 846E ; inline -! Not present on Windows -! FUNCTION: void glDrawRangeElements ( GLenum mode, GLuint start, GLuint end, GLsizei count, GLenum type, GLvoid* indices ) ; +GL-FUNCTION: void glCopyTexSubImage3D ( GLenum target, GLint level, GLint xoffset, GLint yoffset, GLint zoffset, GLint x, GLint y, GLsizei width, GLsizei height ) ; +GL-FUNCTION: void glDrawRangeElements ( GLenum mode, GLuint start, GLuint end, GLsizei count, GLenum type, GLvoid* indices ) ; +GL-FUNCTION: void glTexImage3D ( GLenum target, GLint level, GLint internalFormat, GLsizei width, GLsizei height, GLsizei depth, GLint border, GLenum format, GLenum type, GLvoid* pixels ) ; +GL-FUNCTION: void glTexSubImage3D ( GLenum target, GLint level, GLint xoffset, GLint yoffset, GLint zoffset, GLsizei width, GLsizei height, GLsizei depth, GLenum format, GLenum type, GLvoid* pixels ) ; -! FUNCTION: void glTexImage3D ( GLenum target, GLint level, GLint internalFormat, GLsizei width, GLsizei height, GLsizei depth, GLint border, GLenum format, GLenum type, GLvoid* pixels ) ; - -! FUNCTION: void glTexSubImage3D ( GLenum target, GLint level, GLint xoffset, GLint yoffset, GLint zoffset, GLsizei width, GLsizei height, GLsizei depth, GLenum format, GLenum type, GLvoid* pixels ) ; - -! FUNCTION: void glCopyTexSubImage3D ( GLenum target, GLint level, GLint xoffset, GLint yoffset, GLint zoffset, GLint x, GLint y, GLsizei width, GLsizei height ) ; - -! TODO: the rest. looks fiddly ! OpenGL 1.3 -: GL_ACTIVE_TEXTURE HEX: 84E0 ; inline -: GL_CLIENT_ACTIVE_TEXTURE HEX: 84E1 ; inline -: GL_MAX_TEXTURE_UNITS HEX: 84E2 ; inline -: GL_TEXTURE0 HEX: 84C0 ; inline -: GL_TEXTURE1 HEX: 84C1 ; inline -: GL_TEXTURE2 HEX: 84C2 ; inline -: GL_TEXTURE3 HEX: 84C3 ; inline -: GL_TEXTURE4 HEX: 84C4 ; inline -: GL_TEXTURE5 HEX: 84C5 ; inline -: GL_TEXTURE6 HEX: 84C6 ; inline -: GL_TEXTURE7 HEX: 84C7 ; inline -: GL_TEXTURE8 HEX: 84C8 ; inline -: GL_TEXTURE9 HEX: 84C9 ; inline -: GL_TEXTURE10 HEX: 84CA ; inline -: GL_TEXTURE11 HEX: 84CB ; inline -: GL_TEXTURE12 HEX: 84CC ; inline -: GL_TEXTURE13 HEX: 84CD ; inline -: GL_TEXTURE14 HEX: 84CE ; inline -: GL_TEXTURE15 HEX: 84CF ; inline -: GL_TEXTURE16 HEX: 84D0 ; inline -: GL_TEXTURE17 HEX: 84D1 ; inline -: GL_TEXTURE18 HEX: 84D2 ; inline -: GL_TEXTURE19 HEX: 84D3 ; inline -: GL_TEXTURE20 HEX: 84D4 ; inline -: GL_TEXTURE21 HEX: 84D5 ; inline -: GL_TEXTURE22 HEX: 84D6 ; inline -: GL_TEXTURE23 HEX: 84D7 ; inline -: GL_TEXTURE24 HEX: 84D8 ; inline -: GL_TEXTURE25 HEX: 84D9 ; inline -: GL_TEXTURE26 HEX: 84DA ; inline -: GL_TEXTURE27 HEX: 84DB ; inline -: GL_TEXTURE28 HEX: 84DC ; inline -: GL_TEXTURE29 HEX: 84DD ; inline -: GL_TEXTURE30 HEX: 84DE ; inline -: GL_TEXTURE31 HEX: 84DF ; inline -: GL_NORMAL_MAP HEX: 8511 ; inline -: GL_REFLECTION_MAP HEX: 8512 ; inline -: GL_TEXTURE_CUBE_MAP HEX: 8513 ; inline -: GL_TEXTURE_BINDING_CUBE_MAP HEX: 8514 ; inline -: GL_TEXTURE_CUBE_MAP_POSITIVE_X HEX: 8515 ; inline -: GL_TEXTURE_CUBE_MAP_NEGATIVE_X HEX: 8516 ; inline -: GL_TEXTURE_CUBE_MAP_POSITIVE_Y HEX: 8517 ; inline -: GL_TEXTURE_CUBE_MAP_NEGATIVE_Y HEX: 8518 ; inline -: GL_TEXTURE_CUBE_MAP_POSITIVE_Z HEX: 8519 ; inline -: GL_TEXTURE_CUBE_MAP_NEGATIVE_Z HEX: 851A ; inline -: GL_PROXY_TEXTURE_CUBE_MAP HEX: 851B ; inline -: GL_MAX_CUBE_MAP_TEXTURE_SIZE HEX: 851C ; inline -: GL_COMBINE HEX: 8570 ; inline -: GL_COMBINE_RGB HEX: 8571 ; inline -: GL_COMBINE_ALPHA HEX: 8572 ; inline -: GL_RGB_SCALE HEX: 8573 ; inline -: GL_ADD_SIGNED HEX: 8574 ; inline -: GL_INTERPOLATE HEX: 8575 ; inline -: GL_CONSTANT HEX: 8576 ; inline -: GL_PRIMARY_COLOR HEX: 8577 ; inline -: GL_PREVIOUS HEX: 8578 ; inline -: GL_SOURCE0_RGB HEX: 8580 ; inline -: GL_SOURCE1_RGB HEX: 8581 ; inline -: GL_SOURCE2_RGB HEX: 8582 ; inline -: GL_SOURCE0_ALPHA HEX: 8588 ; inline -: GL_SOURCE1_ALPHA HEX: 8589 ; inline -: GL_SOURCE2_ALPHA HEX: 858A ; inline -: GL_OPERAND0_RGB HEX: 8590 ; inline -: GL_OPERAND1_RGB HEX: 8591 ; inline -: GL_OPERAND2_RGB HEX: 8592 ; inline -: GL_OPERAND0_ALPHA HEX: 8598 ; inline -: GL_OPERAND1_ALPHA HEX: 8599 ; inline -: GL_OPERAND2_ALPHA HEX: 859A ; inline -: GL_SUBTRACT HEX: 84E7 ; inline -: GL_TRANSPOSE_MODELVIEW_MATRIX HEX: 84E3 ; inline -: GL_TRANSPOSE_PROJECTION_MATRIX HEX: 84E4 ; inline -: GL_TRANSPOSE_TEXTURE_MATRIX HEX: 84E5 ; inline -: GL_TRANSPOSE_COLOR_MATRIX HEX: 84E6 ; inline -: GL_COMPRESSED_ALPHA HEX: 84E9 ; inline -: GL_COMPRESSED_LUMINANCE HEX: 84EA ; inline -: GL_COMPRESSED_LUMINANCE_ALPHA HEX: 84EB ; inline -: GL_COMPRESSED_INTENSITY HEX: 84EC ; inline -: GL_COMPRESSED_RGB HEX: 84ED ; inline -: GL_COMPRESSED_RGBA HEX: 84EE ; inline -: GL_TEXTURE_COMPRESSION_HINT HEX: 84EF ; inline -: GL_TEXTURE_COMPRESSED_IMAGE_SIZE HEX: 86A0 ; inline -: GL_TEXTURE_COMPRESSED HEX: 86A1 ; inline + +: GL_MULTISAMPLE HEX: 809D ; inline +: GL_SAMPLE_ALPHA_TO_COVERAGE HEX: 809E ; inline +: GL_SAMPLE_ALPHA_TO_ONE HEX: 809F ; inline +: GL_SAMPLE_COVERAGE HEX: 80A0 ; inline +: GL_SAMPLE_BUFFERS HEX: 80A8 ; inline +: GL_SAMPLES HEX: 80A9 ; inline +: GL_SAMPLE_COVERAGE_VALUE HEX: 80AA ; inline +: GL_SAMPLE_COVERAGE_INVERT HEX: 80AB ; inline +: GL_CLAMP_TO_BORDER HEX: 812D ; inline +: GL_TEXTURE0 HEX: 84C0 ; inline +: GL_TEXTURE1 HEX: 84C1 ; inline +: GL_TEXTURE2 HEX: 84C2 ; inline +: GL_TEXTURE3 HEX: 84C3 ; inline +: GL_TEXTURE4 HEX: 84C4 ; inline +: GL_TEXTURE5 HEX: 84C5 ; inline +: GL_TEXTURE6 HEX: 84C6 ; inline +: GL_TEXTURE7 HEX: 84C7 ; inline +: GL_TEXTURE8 HEX: 84C8 ; inline +: GL_TEXTURE9 HEX: 84C9 ; inline +: GL_TEXTURE10 HEX: 84CA ; inline +: GL_TEXTURE11 HEX: 84CB ; inline +: GL_TEXTURE12 HEX: 84CC ; inline +: GL_TEXTURE13 HEX: 84CD ; inline +: GL_TEXTURE14 HEX: 84CE ; inline +: GL_TEXTURE15 HEX: 84CF ; inline +: GL_TEXTURE16 HEX: 84D0 ; inline +: GL_TEXTURE17 HEX: 84D1 ; inline +: GL_TEXTURE18 HEX: 84D2 ; inline +: GL_TEXTURE19 HEX: 84D3 ; inline +: GL_TEXTURE20 HEX: 84D4 ; inline +: GL_TEXTURE21 HEX: 84D5 ; inline +: GL_TEXTURE22 HEX: 84D6 ; inline +: GL_TEXTURE23 HEX: 84D7 ; inline +: GL_TEXTURE24 HEX: 84D8 ; inline +: GL_TEXTURE25 HEX: 84D9 ; inline +: GL_TEXTURE26 HEX: 84DA ; inline +: GL_TEXTURE27 HEX: 84DB ; inline +: GL_TEXTURE28 HEX: 84DC ; inline +: GL_TEXTURE29 HEX: 84DD ; inline +: GL_TEXTURE30 HEX: 84DE ; inline +: GL_TEXTURE31 HEX: 84DF ; inline +: GL_ACTIVE_TEXTURE HEX: 84E0 ; inline +: GL_CLIENT_ACTIVE_TEXTURE HEX: 84E1 ; inline +: GL_MAX_TEXTURE_UNITS HEX: 84E2 ; inline +: GL_TRANSPOSE_MODELVIEW_MATRIX HEX: 84E3 ; inline +: GL_TRANSPOSE_PROJECTION_MATRIX HEX: 84E4 ; inline +: GL_TRANSPOSE_TEXTURE_MATRIX HEX: 84E5 ; inline +: GL_TRANSPOSE_COLOR_MATRIX HEX: 84E6 ; inline +: GL_SUBTRACT HEX: 84E7 ; inline +: GL_COMPRESSED_ALPHA HEX: 84E9 ; inline +: GL_COMPRESSED_LUMINANCE HEX: 84EA ; inline +: GL_COMPRESSED_LUMINANCE_ALPHA HEX: 84EB ; inline +: GL_COMPRESSED_INTENSITY HEX: 84EC ; inline +: GL_COMPRESSED_RGB HEX: 84ED ; inline +: GL_COMPRESSED_RGBA HEX: 84EE ; inline +: GL_TEXTURE_COMPRESSION_HINT HEX: 84EF ; inline +: GL_NORMAL_MAP HEX: 8511 ; inline +: GL_REFLECTION_MAP HEX: 8512 ; inline +: GL_TEXTURE_CUBE_MAP HEX: 8513 ; inline +: GL_TEXTURE_BINDING_CUBE_MAP HEX: 8514 ; inline +: GL_TEXTURE_CUBE_MAP_POSITIVE_X HEX: 8515 ; inline +: GL_TEXTURE_CUBE_MAP_NEGATIVE_X HEX: 8516 ; inline +: GL_TEXTURE_CUBE_MAP_POSITIVE_Y HEX: 8517 ; inline +: GL_TEXTURE_CUBE_MAP_NEGATIVE_Y HEX: 8518 ; inline +: GL_TEXTURE_CUBE_MAP_POSITIVE_Z HEX: 8519 ; inline +: GL_TEXTURE_CUBE_MAP_NEGATIVE_Z HEX: 851A ; inline +: GL_PROXY_TEXTURE_CUBE_MAP HEX: 851B ; inline +: GL_MAX_CUBE_MAP_TEXTURE_SIZE HEX: 851C ; inline +: GL_COMBINE HEX: 8570 ; inline +: GL_COMBINE_RGB HEX: 8571 ; inline +: GL_COMBINE_ALPHA HEX: 8572 ; inline +: GL_RGB_SCALE HEX: 8573 ; inline +: GL_ADD_SIGNED HEX: 8574 ; inline +: GL_INTERPOLATE HEX: 8575 ; inline +: GL_CONSTANT HEX: 8576 ; inline +: GL_PRIMARY_COLOR HEX: 8577 ; inline +: GL_PREVIOUS HEX: 8578 ; inline +: GL_SOURCE0_RGB HEX: 8580 ; inline +: GL_SOURCE1_RGB HEX: 8581 ; inline +: GL_SOURCE2_RGB HEX: 8582 ; inline +: GL_SOURCE0_ALPHA HEX: 8588 ; inline +: GL_SOURCE1_ALPHA HEX: 8589 ; inline +: GL_SOURCE2_ALPHA HEX: 858A ; inline +: GL_OPERAND0_RGB HEX: 8590 ; inline +: GL_OPERAND1_RGB HEX: 8591 ; inline +: GL_OPERAND2_RGB HEX: 8592 ; inline +: GL_OPERAND0_ALPHA HEX: 8598 ; inline +: GL_OPERAND1_ALPHA HEX: 8599 ; inline +: GL_OPERAND2_ALPHA HEX: 859A ; inline +: GL_TEXTURE_COMPRESSED_IMAGE_SIZE HEX: 86A0 ; inline +: GL_TEXTURE_COMPRESSED HEX: 86A1 ; inline : GL_NUM_COMPRESSED_TEXTURE_FORMATS HEX: 86A2 ; inline -: GL_COMPRESSED_TEXTURE_FORMATS HEX: 86A3 ; inline -: GL_DOT3_RGB HEX: 86AE ; inline -: GL_DOT3_RGBA HEX: 86AF ; inline -: GL_CLAMP_TO_BORDER HEX: 812D ; inline -: GL_MULTISAMPLE HEX: 809D ; inline -: GL_SAMPLE_ALPHA_TO_COVERAGE HEX: 809E ; inline -: GL_SAMPLE_ALPHA_TO_ONE HEX: 809F ; inline -: GL_SAMPLE_COVERAGE HEX: 80A0 ; inline -: GL_SAMPLE_BUFFERS HEX: 80A8 ; inline -: GL_SAMPLES HEX: 80A9 ; inline -: GL_SAMPLE_COVERAGE_VALUE HEX: 80AA ; inline -: GL_SAMPLE_COVERAGE_INVERT HEX: 80AB ; inline -: GL_MULTISAMPLE_BIT HEX: 20000000 ; inline +: GL_COMPRESSED_TEXTURE_FORMATS HEX: 86A3 ; inline +: GL_DOT3_RGB HEX: 86AE ; inline +: GL_DOT3_RGBA HEX: 86AF ; inline +: GL_MULTISAMPLE_BIT HEX: 20000000 ; inline + +GL-FUNCTION: void glActiveTexture ( GLenum texture ) ; +GL-FUNCTION: void glClientActiveTexture ( GLenum texture ) ; +GL-FUNCTION: void glCompressedTexImage1D ( GLenum target, GLint level, GLenum internalformat, GLsizei width, GLint border, GLsizei imageSize, GLvoid* data ) ; +GL-FUNCTION: void glCompressedTexImage2D ( GLenum target, GLint level, GLenum internalformat, GLsizei width, GLsizei height, GLint border, GLsizei imageSize, GLvoid* data ) ; +GL-FUNCTION: void glCompressedTexImage3D ( GLenum target, GLint level, GLenum internalformat, GLsizei width, GLsizei height, GLsizei depth, GLint border, GLsizei imageSize, GLvoid* data ) ; +GL-FUNCTION: void glCompressedTexSubImage1D ( GLenum target, GLint level, GLint xoffset, GLsizei width, GLenum format, GLsizei imageSize, GLvoid* data ) ; +GL-FUNCTION: void glCompressedTexSubImage2D ( GLenum target, GLint level, GLint xoffset, GLint yoffset, GLsizei width, GLsizei height, GLenum format, GLsizei imageSize, GLvoid* data ) ; +GL-FUNCTION: void glCompressedTexSubImage3D ( GLenum target, GLint level, GLint xoffset, GLint yoffset, GLint zoffset, GLsizei width, GLsizei height, GLsizei depth, GLenum format, GLsizei imageSize, GLvoid* data ) ; +GL-FUNCTION: void glGetCompressedTexImage ( GLenum target, GLint lod, GLvoid* img ) ; +GL-FUNCTION: void glLoadTransposeMatrixd ( GLdouble m[16] ) ; +GL-FUNCTION: void glLoadTransposeMatrixf ( GLfloat m[16] ) ; +GL-FUNCTION: void glMultTransposeMatrixd ( GLdouble m[16] ) ; +GL-FUNCTION: void glMultTransposeMatrixf ( GLfloat m[16] ) ; +GL-FUNCTION: void glMultiTexCoord1d ( GLenum target, GLdouble s ) ; +GL-FUNCTION: void glMultiTexCoord1dv ( GLenum target, GLdouble* v ) ; +GL-FUNCTION: void glMultiTexCoord1f ( GLenum target, GLfloat s ) ; +GL-FUNCTION: void glMultiTexCoord1fv ( GLenum target, GLfloat* v ) ; +GL-FUNCTION: void glMultiTexCoord1i ( GLenum target, GLint s ) ; +GL-FUNCTION: void glMultiTexCoord1iv ( GLenum target, GLint* v ) ; +GL-FUNCTION: void glMultiTexCoord1s ( GLenum target, GLshort s ) ; +GL-FUNCTION: void glMultiTexCoord1sv ( GLenum target, GLshort* v ) ; +GL-FUNCTION: void glMultiTexCoord2d ( GLenum target, GLdouble s, GLdouble t ) ; +GL-FUNCTION: void glMultiTexCoord2dv ( GLenum target, GLdouble* v ) ; +GL-FUNCTION: void glMultiTexCoord2f ( GLenum target, GLfloat s, GLfloat t ) ; +GL-FUNCTION: void glMultiTexCoord2fv ( GLenum target, GLfloat* v ) ; +GL-FUNCTION: void glMultiTexCoord2i ( GLenum target, GLint s, GLint t ) ; +GL-FUNCTION: void glMultiTexCoord2iv ( GLenum target, GLint* v ) ; +GL-FUNCTION: void glMultiTexCoord2s ( GLenum target, GLshort s, GLshort t ) ; +GL-FUNCTION: void glMultiTexCoord2sv ( GLenum target, GLshort* v ) ; +GL-FUNCTION: void glMultiTexCoord3d ( GLenum target, GLdouble s, GLdouble t, GLdouble r ) ; +GL-FUNCTION: void glMultiTexCoord3dv ( GLenum target, GLdouble* v ) ; +GL-FUNCTION: void glMultiTexCoord3f ( GLenum target, GLfloat s, GLfloat t, GLfloat r ) ; +GL-FUNCTION: void glMultiTexCoord3fv ( GLenum target, GLfloat* v ) ; +GL-FUNCTION: void glMultiTexCoord3i ( GLenum target, GLint s, GLint t, GLint r ) ; +GL-FUNCTION: void glMultiTexCoord3iv ( GLenum target, GLint* v ) ; +GL-FUNCTION: void glMultiTexCoord3s ( GLenum target, GLshort s, GLshort t, GLshort r ) ; +GL-FUNCTION: void glMultiTexCoord3sv ( GLenum target, GLshort* v ) ; +GL-FUNCTION: void glMultiTexCoord4d ( GLenum target, GLdouble s, GLdouble t, GLdouble r, GLdouble q ) ; +GL-FUNCTION: void glMultiTexCoord4dv ( GLenum target, GLdouble* v ) ; +GL-FUNCTION: void glMultiTexCoord4f ( GLenum target, GLfloat s, GLfloat t, GLfloat r, GLfloat q ) ; +GL-FUNCTION: void glMultiTexCoord4fv ( GLenum target, GLfloat* v ) ; +GL-FUNCTION: void glMultiTexCoord4i ( GLenum target, GLint s, GLint t, GLint r, GLint q ) ; +GL-FUNCTION: void glMultiTexCoord4iv ( GLenum target, GLint* v ) ; +GL-FUNCTION: void glMultiTexCoord4s ( GLenum target, GLshort s, GLshort t, GLshort r, GLshort q ) ; +GL-FUNCTION: void glMultiTexCoord4sv ( GLenum target, GLshort* v ) ; +GL-FUNCTION: void glSampleCoverage ( GLclampf value, GLboolean invert ) ; ! OpenGL 1.4 -: GL_POINT_SIZE_MIN HEX: 8126 ; inline -: GL_POINT_SIZE_MAX HEX: 8127 ; inline -: GL_POINT_FADE_THRESHOLD_SIZE HEX: 8128 ; inline -: GL_POINT_DISTANCE_ATTENUATION HEX: 8129 ; inline -: GL_FOG_COORDINATE_SOURCE HEX: 8450 ; inline -: GL_FOG_COORDINATE HEX: 8451 ; inline -: GL_FRAGMENT_DEPTH HEX: 8452 ; inline -: GL_CURRENT_FOG_COORDINATE HEX: 8453 ; inline -: GL_FOG_COORDINATE_ARRAY_TYPE HEX: 8454 ; inline -: GL_FOG_COORDINATE_ARRAY_STRIDE HEX: 8455 ; inline -: GL_FOG_COORDINATE_ARRAY_POINTER HEX: 8456 ; inline -: GL_FOG_COORDINATE_ARRAY HEX: 8457 ; inline -: GL_COLOR_SUM HEX: 8458 ; inline -: GL_CURRENT_SECONDARY_COLOR HEX: 8459 ; inline -: GL_SECONDARY_COLOR_ARRAY_SIZE HEX: 845A ; inline -: GL_SECONDARY_COLOR_ARRAY_TYPE HEX: 845B ; inline -: GL_SECONDARY_COLOR_ARRAY_STRIDE HEX: 845C ; inline -: GL_SECONDARY_COLOR_ARRAY_POINTER HEX: 845D ; inline -: GL_SECONDARY_COLOR_ARRAY HEX: 845E ; inline -: GL_INCR_WRAP HEX: 8507 ; inline -: GL_DECR_WRAP HEX: 8508 ; inline -: GL_MAX_TEXTURE_LOD_BIAS HEX: 84FD ; inline -: GL_TEXTURE_FILTER_CONTROL HEX: 8500 ; inline -: GL_TEXTURE_LOD_BIAS HEX: 8501 ; inline -: GL_GENERATE_MIPMAP HEX: 8191 ; inline -: GL_GENERATE_MIPMAP_HINT HEX: 8192 ; inline -: GL_BLEND_DST_RGB HEX: 80C8 ; inline -: GL_BLEND_SRC_RGB HEX: 80C9 ; inline -: GL_BLEND_DST_ALPHA HEX: 80CA ; inline -: GL_BLEND_SRC_ALPHA HEX: 80CB ; inline -: GL_MIRRORED_REPEAT HEX: 8370 ; inline -: GL_DEPTH_COMPONENT16 HEX: 81A5 ; inline -: GL_DEPTH_COMPONENT24 HEX: 81A6 ; inline -: GL_DEPTH_COMPONENT32 HEX: 81A7 ; inline -: GL_TEXTURE_DEPTH_SIZE HEX: 884A ; inline -: GL_DEPTH_TEXTURE_MODE HEX: 884B ; inline -: GL_TEXTURE_COMPARE_MODE HEX: 884C ; inline -: GL_TEXTURE_COMPARE_FUNC HEX: 884D ; inline -: GL_COMPARE_R_TO_TEXTURE HEX: 884E ; inline + +: GL_BLEND_DST_RGB HEX: 80C8 ; inline +: GL_BLEND_SRC_RGB HEX: 80C9 ; inline +: GL_BLEND_DST_ALPHA HEX: 80CA ; inline +: GL_BLEND_SRC_ALPHA HEX: 80CB ; inline +: GL_POINT_SIZE_MIN HEX: 8126 ; inline +: GL_POINT_SIZE_MAX HEX: 8127 ; inline +: GL_POINT_FADE_THRESHOLD_SIZE HEX: 8128 ; inline +: GL_POINT_DISTANCE_ATTENUATION HEX: 8129 ; inline +: GL_GENERATE_MIPMAP HEX: 8191 ; inline +: GL_GENERATE_MIPMAP_HINT HEX: 8192 ; inline +: GL_DEPTH_COMPONENT16 HEX: 81A5 ; inline +: GL_DEPTH_COMPONENT24 HEX: 81A6 ; inline +: GL_DEPTH_COMPONENT32 HEX: 81A7 ; inline +: GL_MIRRORED_REPEAT HEX: 8370 ; inline +: GL_FOG_COORDINATE_SOURCE HEX: 8450 ; inline +: GL_FOG_COORDINATE HEX: 8451 ; inline +: GL_FRAGMENT_DEPTH HEX: 8452 ; inline +: GL_CURRENT_FOG_COORDINATE HEX: 8453 ; inline +: GL_FOG_COORDINATE_ARRAY_TYPE HEX: 8454 ; inline +: GL_FOG_COORDINATE_ARRAY_STRIDE HEX: 8455 ; inline +: GL_FOG_COORDINATE_ARRAY_POINTER HEX: 8456 ; inline +: GL_FOG_COORDINATE_ARRAY HEX: 8457 ; inline +: GL_COLOR_SUM HEX: 8458 ; inline +: GL_CURRENT_SECONDARY_COLOR HEX: 8459 ; inline +: GL_SECONDARY_COLOR_ARRAY_SIZE HEX: 845A ; inline +: GL_SECONDARY_COLOR_ARRAY_TYPE HEX: 845B ; inline +: GL_SECONDARY_COLOR_ARRAY_STRIDE HEX: 845C ; inline +: GL_SECONDARY_COLOR_ARRAY_POINTER HEX: 845D ; inline +: GL_SECONDARY_COLOR_ARRAY HEX: 845E ; inline +: GL_MAX_TEXTURE_LOD_BIAS HEX: 84FD ; inline +: GL_TEXTURE_FILTER_CONTROL HEX: 8500 ; inline +: GL_TEXTURE_LOD_BIAS HEX: 8501 ; inline +: GL_INCR_WRAP HEX: 8507 ; inline +: GL_DECR_WRAP HEX: 8508 ; inline +: GL_TEXTURE_DEPTH_SIZE HEX: 884A ; inline +: GL_DEPTH_TEXTURE_MODE HEX: 884B ; inline +: GL_TEXTURE_COMPARE_MODE HEX: 884C ; inline +: GL_TEXTURE_COMPARE_FUNC HEX: 884D ; inline +: GL_COMPARE_R_TO_TEXTURE HEX: 884E ; inline + +GL-FUNCTION: void glBlendColor ( GLclampf red, GLclampf green, GLclampf blue, GLclampf alpha ) ; +GL-FUNCTION: void glBlendEquation ( GLenum mode ) ; +GL-FUNCTION: void glBlendFuncSeparate ( GLenum sfactorRGB, GLenum dfactorRGB, GLenum sfactorAlpha, GLenum dfactorAlpha ) ; +GL-FUNCTION: void glFogCoordPointer ( GLenum type, GLsizei stride, GLvoid* pointer ) ; +GL-FUNCTION: void glFogCoordd ( GLdouble coord ) ; +GL-FUNCTION: void glFogCoorddv ( GLdouble* coord ) ; +GL-FUNCTION: void glFogCoordf ( GLfloat coord ) ; +GL-FUNCTION: void glFogCoordfv ( GLfloat* coord ) ; +GL-FUNCTION: void glMultiDrawArrays ( GLenum mode, GLint* first, GLsizei* count, GLsizei primcount ) ; +GL-FUNCTION: void glMultiDrawElements ( GLenum mode, GLsizei* count, GLenum type, GLvoid** indices, GLsizei primcount ) ; +GL-FUNCTION: void glPointParameterf ( GLenum pname, GLfloat param ) ; +GL-FUNCTION: void glPointParameterfv ( GLenum pname, GLfloat* params ) ; +GL-FUNCTION: void glSecondaryColor3b ( GLbyte red, GLbyte green, GLbyte blue ) ; +GL-FUNCTION: void glSecondaryColor3bv ( GLbyte* v ) ; +GL-FUNCTION: void glSecondaryColor3d ( GLdouble red, GLdouble green, GLdouble blue ) ; +GL-FUNCTION: void glSecondaryColor3dv ( GLdouble* v ) ; +GL-FUNCTION: void glSecondaryColor3f ( GLfloat red, GLfloat green, GLfloat blue ) ; +GL-FUNCTION: void glSecondaryColor3fv ( GLfloat* v ) ; +GL-FUNCTION: void glSecondaryColor3i ( GLint red, GLint green, GLint blue ) ; +GL-FUNCTION: void glSecondaryColor3iv ( GLint* v ) ; +GL-FUNCTION: void glSecondaryColor3s ( GLshort red, GLshort green, GLshort blue ) ; +GL-FUNCTION: void glSecondaryColor3sv ( GLshort* v ) ; +GL-FUNCTION: void glSecondaryColor3ub ( GLubyte red, GLubyte green, GLubyte blue ) ; +GL-FUNCTION: void glSecondaryColor3ubv ( GLubyte* v ) ; +GL-FUNCTION: void glSecondaryColor3ui ( GLuint red, GLuint green, GLuint blue ) ; +GL-FUNCTION: void glSecondaryColor3uiv ( GLuint* v ) ; +GL-FUNCTION: void glSecondaryColor3us ( GLushort red, GLushort green, GLushort blue ) ; +GL-FUNCTION: void glSecondaryColor3usv ( GLushort* v ) ; +GL-FUNCTION: void glSecondaryColorPointer ( GLint size, GLenum type, GLsizei stride, GLvoid* pointer ) ; +GL-FUNCTION: void glWindowPos2d ( GLdouble x, GLdouble y ) ; +GL-FUNCTION: void glWindowPos2dv ( GLdouble* p ) ; +GL-FUNCTION: void glWindowPos2f ( GLfloat x, GLfloat y ) ; +GL-FUNCTION: void glWindowPos2fv ( GLfloat* p ) ; +GL-FUNCTION: void glWindowPos2i ( GLint x, GLint y ) ; +GL-FUNCTION: void glWindowPos2iv ( GLint* p ) ; +GL-FUNCTION: void glWindowPos2s ( GLshort x, GLshort y ) ; +GL-FUNCTION: void glWindowPos2sv ( GLshort* p ) ; +GL-FUNCTION: void glWindowPos3d ( GLdouble x, GLdouble y, GLdouble z ) ; +GL-FUNCTION: void glWindowPos3dv ( GLdouble* p ) ; +GL-FUNCTION: void glWindowPos3f ( GLfloat x, GLfloat y, GLfloat z ) ; +GL-FUNCTION: void glWindowPos3fv ( GLfloat* p ) ; +GL-FUNCTION: void glWindowPos3i ( GLint x, GLint y, GLint z ) ; +GL-FUNCTION: void glWindowPos3iv ( GLint* p ) ; +GL-FUNCTION: void glWindowPos3s ( GLshort x, GLshort y, GLshort z ) ; +GL-FUNCTION: void glWindowPos3sv ( GLshort* p ) ; + + +! OpenGL 1.5 + +: GL_BUFFER_SIZE HEX: 8764 ; inline +: GL_BUFFER_USAGE HEX: 8765 ; inline +: GL_QUERY_COUNTER_BITS HEX: 8864 ; inline +: GL_CURRENT_QUERY HEX: 8865 ; inline +: GL_QUERY_RESULT HEX: 8866 ; inline +: GL_QUERY_RESULT_AVAILABLE HEX: 8867 ; inline +: GL_ARRAY_BUFFER HEX: 8892 ; inline +: GL_ELEMENT_ARRAY_BUFFER HEX: 8893 ; inline +: GL_ARRAY_BUFFER_BINDING HEX: 8894 ; inline +: GL_ELEMENT_ARRAY_BUFFER_BINDING HEX: 8895 ; inline +: GL_VERTEX_ARRAY_BUFFER_BINDING HEX: 8896 ; inline +: GL_NORMAL_ARRAY_BUFFER_BINDING HEX: 8897 ; inline +: GL_COLOR_ARRAY_BUFFER_BINDING HEX: 8898 ; inline +: GL_INDEX_ARRAY_BUFFER_BINDING HEX: 8899 ; inline +: GL_TEXTURE_COORD_ARRAY_BUFFER_BINDING HEX: 889A ; inline +: GL_EDGE_FLAG_ARRAY_BUFFER_BINDING HEX: 889B ; inline +: GL_SECONDARY_COLOR_ARRAY_BUFFER_BINDING HEX: 889C ; inline +: GL_FOG_COORDINATE_ARRAY_BUFFER_BINDING HEX: 889D ; inline +: GL_WEIGHT_ARRAY_BUFFER_BINDING HEX: 889E ; inline +: GL_VERTEX_ATTRIB_ARRAY_BUFFER_BINDING HEX: 889F ; inline +: GL_READ_ONLY HEX: 88B8 ; inline +: GL_WRITE_ONLY HEX: 88B9 ; inline +: GL_READ_WRITE HEX: 88BA ; inline +: GL_BUFFER_ACCESS HEX: 88BB ; inline +: GL_BUFFER_MAPPED HEX: 88BC ; inline +: GL_BUFFER_MAP_POINTER HEX: 88BD ; inline +: GL_STREAM_DRAW HEX: 88E0 ; inline +: GL_STREAM_READ HEX: 88E1 ; inline +: GL_STREAM_COPY HEX: 88E2 ; inline +: GL_STATIC_DRAW HEX: 88E4 ; inline +: GL_STATIC_READ HEX: 88E5 ; inline +: GL_STATIC_COPY HEX: 88E6 ; inline +: GL_DYNAMIC_DRAW HEX: 88E8 ; inline +: GL_DYNAMIC_READ HEX: 88E9 ; inline +: GL_DYNAMIC_COPY HEX: 88EA ; inline +: GL_SAMPLES_PASSED HEX: 8914 ; inline +: GL_FOG_COORD_SRC GL_FOG_COORDINATE_SOURCE ; inline +: GL_FOG_COORD GL_FOG_COORDINATE ; inline +: GL_FOG_COORD_ARRAY GL_FOG_COORDINATE_ARRAY ; inline +: GL_SRC0_RGB GL_SOURCE0_RGB ; inline +: GL_FOG_COORD_ARRAY_POINTER GL_FOG_COORDINATE_ARRAY_POINTER ; inline +: GL_FOG_COORD_ARRAY_TYPE GL_FOG_COORDINATE_ARRAY_TYPE ; inline +: GL_SRC1_ALPHA GL_SOURCE1_ALPHA ; inline +: GL_CURRENT_FOG_COORD GL_CURRENT_FOG_COORDINATE ; inline +: GL_FOG_COORD_ARRAY_STRIDE GL_FOG_COORDINATE_ARRAY_STRIDE ; inline +: GL_SRC0_ALPHA GL_SOURCE0_ALPHA ; inline +: GL_SRC1_RGB GL_SOURCE1_RGB ; inline +: GL_FOG_COORD_ARRAY_BUFFER_BINDING GL_FOG_COORDINATE_ARRAY_BUFFER_BINDING ; inline +: GL_SRC2_ALPHA GL_SOURCE2_ALPHA ; inline +: GL_SRC2_RGB GL_SOURCE2_RGB ; inline + +TYPEDEF: long ptrdiff_t + +TYPEDEF: ptrdiff_t GLsizeiptr +TYPEDEF: ptrdiff_t GLintptr + +GL-FUNCTION: void glBeginQuery ( GLenum target, GLuint id ) ; +GL-FUNCTION: void glBindBuffer ( GLenum target, GLuint buffer ) ; +GL-FUNCTION: void glBufferData ( GLenum target, GLsizeiptr size, GLvoid* data, GLenum usage ) ; +GL-FUNCTION: void glBufferSubData ( GLenum target, GLintptr offset, GLsizeiptr size, GLvoid* data ) ; +GL-FUNCTION: void glDeleteBuffers ( GLsizei n, GLuint* buffers ) ; +GL-FUNCTION: void glDeleteQueries ( GLsizei n, GLuint* ids ) ; +GL-FUNCTION: void glEndQuery ( GLenum target ) ; +GL-FUNCTION: void glGenBuffers ( GLsizei n, GLuint* buffers ) ; +GL-FUNCTION: void glGenQueries ( GLsizei n, GLuint* ids ) ; +GL-FUNCTION: void glGetBufferParameteriv ( GLenum target, GLenum pname, GLint* params ) ; +GL-FUNCTION: void glGetBufferPointerv ( GLenum target, GLenum pname, GLvoid** params ) ; +GL-FUNCTION: void glGetBufferSubData ( GLenum target, GLintptr offset, GLsizeiptr size, GLvoid* data ) ; +GL-FUNCTION: void glGetQueryObjectiv ( GLuint id, GLenum pname, GLint* params ) ; +GL-FUNCTION: void glGetQueryObjectuiv ( GLuint id, GLenum pname, GLuint* params ) ; +GL-FUNCTION: void glGetQueryiv ( GLenum target, GLenum pname, GLint* params ) ; +GL-FUNCTION: GLboolean glIsBuffer ( GLuint buffer ) ; +GL-FUNCTION: GLboolean glIsQuery ( GLuint id ) ; +GL-FUNCTION: GLvoid* glMapBuffer ( GLenum target, GLenum access ) ; +GL-FUNCTION: GLboolean glUnmapBuffer ( GLenum target ) ; + + +! OpenGL 2.0 + + +: GL_VERTEX_ATTRIB_ARRAY_ENABLED HEX: 8622 ; inline +: GL_VERTEX_ATTRIB_ARRAY_SIZE HEX: 8623 ; inline +: GL_VERTEX_ATTRIB_ARRAY_STRIDE HEX: 8624 ; inline +: GL_VERTEX_ATTRIB_ARRAY_TYPE HEX: 8625 ; inline +: GL_CURRENT_VERTEX_ATTRIB HEX: 8626 ; inline +: GL_VERTEX_PROGRAM_POINT_SIZE HEX: 8642 ; inline +: GL_VERTEX_PROGRAM_TWO_SIDE HEX: 8643 ; inline +: GL_VERTEX_ATTRIB_ARRAY_POINTER HEX: 8645 ; inline +: GL_STENCIL_BACK_FUNC HEX: 8800 ; inline +: GL_STENCIL_BACK_FAIL HEX: 8801 ; inline +: GL_STENCIL_BACK_PASS_DEPTH_FAIL HEX: 8802 ; inline +: GL_STENCIL_BACK_PASS_DEPTH_PASS HEX: 8803 ; inline +: GL_MAX_DRAW_BUFFERS HEX: 8824 ; inline +: GL_DRAW_BUFFER0 HEX: 8825 ; inline +: GL_DRAW_BUFFER1 HEX: 8826 ; inline +: GL_DRAW_BUFFER2 HEX: 8827 ; inline +: GL_DRAW_BUFFER3 HEX: 8828 ; inline +: GL_DRAW_BUFFER4 HEX: 8829 ; inline +: GL_DRAW_BUFFER5 HEX: 882A ; inline +: GL_DRAW_BUFFER6 HEX: 882B ; inline +: GL_DRAW_BUFFER7 HEX: 882C ; inline +: GL_DRAW_BUFFER8 HEX: 882D ; inline +: GL_DRAW_BUFFER9 HEX: 882E ; inline +: GL_DRAW_BUFFER10 HEX: 882F ; inline +: GL_DRAW_BUFFER11 HEX: 8830 ; inline +: GL_DRAW_BUFFER12 HEX: 8831 ; inline +: GL_DRAW_BUFFER13 HEX: 8832 ; inline +: GL_DRAW_BUFFER14 HEX: 8833 ; inline +: GL_DRAW_BUFFER15 HEX: 8834 ; inline +: GL_BLEND_EQUATION_ALPHA HEX: 883D ; inline +: GL_POINT_SPRITE HEX: 8861 ; inline +: GL_COORD_REPLACE HEX: 8862 ; inline +: GL_MAX_VERTEX_ATTRIBS HEX: 8869 ; inline +: GL_VERTEX_ATTRIB_ARRAY_NORMALIZED HEX: 886A ; inline +: GL_MAX_TEXTURE_COORDS HEX: 8871 ; inline +: GL_MAX_TEXTURE_IMAGE_UNITS HEX: 8872 ; inline +: GL_FRAGMENT_SHADER HEX: 8B30 ; inline +: GL_VERTEX_SHADER HEX: 8B31 ; inline +: GL_MAX_FRAGMENT_UNIFORM_COMPONENTS HEX: 8B49 ; inline +: GL_MAX_VERTEX_UNIFORM_COMPONENTS HEX: 8B4A ; inline +: GL_MAX_VARYING_FLOATS HEX: 8B4B ; inline +: GL_MAX_VERTEX_TEXTURE_IMAGE_UNITS HEX: 8B4C ; inline +: GL_MAX_COMBINED_TEXTURE_IMAGE_UNITS HEX: 8B4D ; inline +: GL_SHADER_TYPE HEX: 8B4F ; inline +: GL_FLOAT_VEC2 HEX: 8B50 ; inline +: GL_FLOAT_VEC3 HEX: 8B51 ; inline +: GL_FLOAT_VEC4 HEX: 8B52 ; inline +: GL_INT_VEC2 HEX: 8B53 ; inline +: GL_INT_VEC3 HEX: 8B54 ; inline +: GL_INT_VEC4 HEX: 8B55 ; inline +: GL_BOOL HEX: 8B56 ; inline +: GL_BOOL_VEC2 HEX: 8B57 ; inline +: GL_BOOL_VEC3 HEX: 8B58 ; inline +: GL_BOOL_VEC4 HEX: 8B59 ; inline +: GL_FLOAT_MAT2 HEX: 8B5A ; inline +: GL_FLOAT_MAT3 HEX: 8B5B ; inline +: GL_FLOAT_MAT4 HEX: 8B5C ; inline +: GL_SAMPLER_1D HEX: 8B5D ; inline +: GL_SAMPLER_2D HEX: 8B5E ; inline +: GL_SAMPLER_3D HEX: 8B5F ; inline +: GL_SAMPLER_CUBE HEX: 8B60 ; inline +: GL_SAMPLER_1D_SHADOW HEX: 8B61 ; inline +: GL_SAMPLER_2D_SHADOW HEX: 8B62 ; inline +: GL_DELETE_STATUS HEX: 8B80 ; inline +: GL_COMPILE_STATUS HEX: 8B81 ; inline +: GL_LINK_STATUS HEX: 8B82 ; inline +: GL_VALIDATE_STATUS HEX: 8B83 ; inline +: GL_INFO_LOG_LENGTH HEX: 8B84 ; inline +: GL_ATTACHED_SHADERS HEX: 8B85 ; inline +: GL_ACTIVE_UNIFORMS HEX: 8B86 ; inline +: GL_ACTIVE_UNIFORM_MAX_LENGTH HEX: 8B87 ; inline +: GL_SHADER_SOURCE_LENGTH HEX: 8B88 ; inline +: GL_ACTIVE_ATTRIBUTES HEX: 8B89 ; inline +: GL_ACTIVE_ATTRIBUTE_MAX_LENGTH HEX: 8B8A ; inline +: GL_FRAGMENT_SHADER_DERIVATIVE_HINT HEX: 8B8B ; inline +: GL_SHADING_LANGUAGE_VERSION HEX: 8B8C ; inline +: GL_CURRENT_PROGRAM HEX: 8B8D ; inline +: GL_POINT_SPRITE_COORD_ORIGIN HEX: 8CA0 ; inline +: GL_LOWER_LEFT HEX: 8CA1 ; inline +: GL_UPPER_LEFT HEX: 8CA2 ; inline +: GL_STENCIL_BACK_REF HEX: 8CA3 ; inline +: GL_STENCIL_BACK_VALUE_MASK HEX: 8CA4 ; inline +: GL_STENCIL_BACK_WRITEMASK HEX: 8CA5 ; inline +: GL_BLEND_EQUATION HEX: 8009 ; inline +: GL_BLEND_EQUATION_RGB GL_BLEND_EQUATION ; inline + +TYPEDEF: char GLchar + +GL-FUNCTION: void glAttachShader ( GLuint program, GLuint shader ) ; +GL-FUNCTION: void glBindAttribLocation ( GLuint program, GLuint index, GLchar* name ) ; +GL-FUNCTION: void glBlendEquationSeparate ( GLenum modeRGB, GLenum modeAlpha ) ; +GL-FUNCTION: void glCompileShader ( GLuint shader ) ; +GL-FUNCTION: GLuint glCreateProgram ( ) ; +GL-FUNCTION: GLuint glCreateShader ( GLenum type ) ; +GL-FUNCTION: void glDeleteProgram ( GLuint program ) ; +GL-FUNCTION: void glDeleteShader ( GLuint shader ) ; +GL-FUNCTION: void glDetachShader ( GLuint program, GLuint shader ) ; +GL-FUNCTION: void glDisableVertexAttribArray ( GLuint index ) ; +GL-FUNCTION: void glDrawBuffers ( GLsizei n, GLenum* bufs ) ; +GL-FUNCTION: void glEnableVertexAttribArray ( GLuint index ) ; +GL-FUNCTION: void glGetActiveAttrib ( GLuint program, GLuint index, GLsizei maxLength, GLsizei* length, GLint* size, GLenum* type, GLchar* name ) ; +GL-FUNCTION: void glGetActiveUniform ( GLuint program, GLuint index, GLsizei maxLength, GLsizei* length, GLint* size, GLenum* type, GLchar* name ) ; +GL-FUNCTION: void glGetAttachedShaders ( GLuint program, GLsizei maxCount, GLsizei* count, GLuint* shaders ) ; +GL-FUNCTION: GLint glGetAttribLocation ( GLuint program, GLchar* name ) ; +GL-FUNCTION: void glGetProgramInfoLog ( GLuint program, GLsizei bufSize, GLsizei* length, GLchar* infoLog ) ; +GL-FUNCTION: void glGetProgramiv ( GLuint program, GLenum pname, GLint* param ) ; +GL-FUNCTION: void glGetShaderInfoLog ( GLuint shader, GLsizei bufSize, GLsizei* length, GLchar* infoLog ) ; +GL-FUNCTION: void glGetShaderSource ( GLint obj, GLsizei maxLength, GLsizei* length, GLchar* source ) ; +GL-FUNCTION: void glGetShaderiv ( GLuint shader, GLenum pname, GLint* param ) ; +GL-FUNCTION: GLint glGetUniformLocation ( GLint programObj, GLchar* name ) ; +GL-FUNCTION: void glGetUniformfv ( GLuint program, GLint location, GLfloat* params ) ; +GL-FUNCTION: void glGetUniformiv ( GLuint program, GLint location, GLint* params ) ; +GL-FUNCTION: void glGetVertexAttribPointerv ( GLuint index, GLenum pname, GLvoid** pointer ) ; +GL-FUNCTION: void glGetVertexAttribdv ( GLuint index, GLenum pname, GLdouble* params ) ; +GL-FUNCTION: void glGetVertexAttribfv ( GLuint index, GLenum pname, GLfloat* params ) ; +GL-FUNCTION: void glGetVertexAttribiv ( GLuint index, GLenum pname, GLint* params ) ; +GL-FUNCTION: GLboolean glIsProgram ( GLuint program ) ; +GL-FUNCTION: GLboolean glIsShader ( GLuint shader ) ; +GL-FUNCTION: void glLinkProgram ( GLuint program ) ; +GL-FUNCTION: void glShaderSource ( GLuint shader, GLsizei count, GLchar** strings, GLint* lengths ) ; +GL-FUNCTION: void glStencilFuncSeparate ( GLenum frontfunc, GLenum backfunc, GLint ref, GLuint mask ) ; +GL-FUNCTION: void glStencilMaskSeparate ( GLenum face, GLuint mask ) ; +GL-FUNCTION: void glStencilOpSeparate ( GLenum face, GLenum sfail, GLenum dpfail, GLenum dppass ) ; +GL-FUNCTION: void glUniform1f ( GLint location, GLfloat v0 ) ; +GL-FUNCTION: void glUniform1fv ( GLint location, GLsizei count, GLfloat* value ) ; +GL-FUNCTION: void glUniform1i ( GLint location, GLint v0 ) ; +GL-FUNCTION: void glUniform1iv ( GLint location, GLsizei count, GLint* value ) ; +GL-FUNCTION: void glUniform2f ( GLint location, GLfloat v0, GLfloat v1 ) ; +GL-FUNCTION: void glUniform2fv ( GLint location, GLsizei count, GLfloat* value ) ; +GL-FUNCTION: void glUniform2i ( GLint location, GLint v0, GLint v1 ) ; +GL-FUNCTION: void glUniform2iv ( GLint location, GLsizei count, GLint* value ) ; +GL-FUNCTION: void glUniform3f ( GLint location, GLfloat v0, GLfloat v1, GLfloat v2 ) ; +GL-FUNCTION: void glUniform3fv ( GLint location, GLsizei count, GLfloat* value ) ; +GL-FUNCTION: void glUniform3i ( GLint location, GLint v0, GLint v1, GLint v2 ) ; +GL-FUNCTION: void glUniform3iv ( GLint location, GLsizei count, GLint* value ) ; +GL-FUNCTION: void glUniform4f ( GLint location, GLfloat v0, GLfloat v1, GLfloat v2, GLfloat v3 ) ; +GL-FUNCTION: void glUniform4fv ( GLint location, GLsizei count, GLfloat* value ) ; +GL-FUNCTION: void glUniform4i ( GLint location, GLint v0, GLint v1, GLint v2, GLint v3 ) ; +GL-FUNCTION: void glUniform4iv ( GLint location, GLsizei count, GLint* value ) ; +GL-FUNCTION: void glUniformMatrix2fv ( GLint location, GLsizei count, GLboolean transpose, GLfloat* value ) ; +GL-FUNCTION: void glUniformMatrix3fv ( GLint location, GLsizei count, GLboolean transpose, GLfloat* value ) ; +GL-FUNCTION: void glUniformMatrix4fv ( GLint location, GLsizei count, GLboolean transpose, GLfloat* value ) ; +GL-FUNCTION: void glUseProgram ( GLuint program ) ; +GL-FUNCTION: void glValidateProgram ( GLuint program ) ; +GL-FUNCTION: void glVertexAttrib1d ( GLuint index, GLdouble x ) ; +GL-FUNCTION: void glVertexAttrib1dv ( GLuint index, GLdouble* v ) ; +GL-FUNCTION: void glVertexAttrib1f ( GLuint index, GLfloat x ) ; +GL-FUNCTION: void glVertexAttrib1fv ( GLuint index, GLfloat* v ) ; +GL-FUNCTION: void glVertexAttrib1s ( GLuint index, GLshort x ) ; +GL-FUNCTION: void glVertexAttrib1sv ( GLuint index, GLshort* v ) ; +GL-FUNCTION: void glVertexAttrib2d ( GLuint index, GLdouble x, GLdouble y ) ; +GL-FUNCTION: void glVertexAttrib2dv ( GLuint index, GLdouble* v ) ; +GL-FUNCTION: void glVertexAttrib2f ( GLuint index, GLfloat x, GLfloat y ) ; +GL-FUNCTION: void glVertexAttrib2fv ( GLuint index, GLfloat* v ) ; +GL-FUNCTION: void glVertexAttrib2s ( GLuint index, GLshort x, GLshort y ) ; +GL-FUNCTION: void glVertexAttrib2sv ( GLuint index, GLshort* v ) ; +GL-FUNCTION: void glVertexAttrib3d ( GLuint index, GLdouble x, GLdouble y, GLdouble z ) ; +GL-FUNCTION: void glVertexAttrib3dv ( GLuint index, GLdouble* v ) ; +GL-FUNCTION: void glVertexAttrib3f ( GLuint index, GLfloat x, GLfloat y, GLfloat z ) ; +GL-FUNCTION: void glVertexAttrib3fv ( GLuint index, GLfloat* v ) ; +GL-FUNCTION: void glVertexAttrib3s ( GLuint index, GLshort x, GLshort y, GLshort z ) ; +GL-FUNCTION: void glVertexAttrib3sv ( GLuint index, GLshort* v ) ; +GL-FUNCTION: void glVertexAttrib4Nbv ( GLuint index, GLbyte* v ) ; +GL-FUNCTION: void glVertexAttrib4Niv ( GLuint index, GLint* v ) ; +GL-FUNCTION: void glVertexAttrib4Nsv ( GLuint index, GLshort* v ) ; +GL-FUNCTION: void glVertexAttrib4Nub ( GLuint index, GLubyte x, GLubyte y, GLubyte z, GLubyte w ) ; +GL-FUNCTION: void glVertexAttrib4Nubv ( GLuint index, GLubyte* v ) ; +GL-FUNCTION: void glVertexAttrib4Nuiv ( GLuint index, GLuint* v ) ; +GL-FUNCTION: void glVertexAttrib4Nusv ( GLuint index, GLushort* v ) ; +GL-FUNCTION: void glVertexAttrib4bv ( GLuint index, GLbyte* v ) ; +GL-FUNCTION: void glVertexAttrib4d ( GLuint index, GLdouble x, GLdouble y, GLdouble z, GLdouble w ) ; +GL-FUNCTION: void glVertexAttrib4dv ( GLuint index, GLdouble* v ) ; +GL-FUNCTION: void glVertexAttrib4f ( GLuint index, GLfloat x, GLfloat y, GLfloat z, GLfloat w ) ; +GL-FUNCTION: void glVertexAttrib4fv ( GLuint index, GLfloat* v ) ; +GL-FUNCTION: void glVertexAttrib4iv ( GLuint index, GLint* v ) ; +GL-FUNCTION: void glVertexAttrib4s ( GLuint index, GLshort x, GLshort y, GLshort z, GLshort w ) ; +GL-FUNCTION: void glVertexAttrib4sv ( GLuint index, GLshort* v ) ; +GL-FUNCTION: void glVertexAttrib4ubv ( GLuint index, GLubyte* v ) ; +GL-FUNCTION: void glVertexAttrib4uiv ( GLuint index, GLuint* v ) ; +GL-FUNCTION: void glVertexAttrib4usv ( GLuint index, GLushort* v ) ; +GL-FUNCTION: void glVertexAttribPointer ( GLuint index, GLint size, GLenum type, GLboolean normalized, GLsizei stride, GLvoid* pointer ) ; + + +! OpenGL 2.1 + + +: GL_CURRENT_RASTER_SECONDARY_COLOR HEX: 845F ; inline +: GL_PIXEL_PACK_BUFFER HEX: 88EB ; inline +: GL_PIXEL_UNPACK_BUFFER HEX: 88EC ; inline +: GL_PIXEL_PACK_BUFFER_BINDING HEX: 88ED ; inline +: GL_PIXEL_UNPACK_BUFFER_BINDING HEX: 88EF ; inline +: GL_SRGB HEX: 8C40 ; inline +: GL_SRGB8 HEX: 8C41 ; inline +: GL_SRGB_ALPHA HEX: 8C42 ; inline +: GL_SRGB8_ALPHA8 HEX: 8C43 ; inline +: GL_SLUMINANCE_ALPHA HEX: 8C44 ; inline +: GL_SLUMINANCE8_ALPHA8 HEX: 8C45 ; inline +: GL_SLUMINANCE HEX: 8C46 ; inline +: GL_SLUMINANCE8 HEX: 8C47 ; inline +: GL_COMPRESSED_SRGB HEX: 8C48 ; inline +: GL_COMPRESSED_SRGB_ALPHA HEX: 8C49 ; inline +: GL_COMPRESSED_SLUMINANCE HEX: 8C4A ; inline +: GL_COMPRESSED_SLUMINANCE_ALPHA HEX: 8C4B ; inline + +GL-FUNCTION: void glUniformMatrix2x3fv ( GLint location, GLsizei count, GLboolean transpose, GLfloat* value ) ; +GL-FUNCTION: void glUniformMatrix2x4fv ( GLint location, GLsizei count, GLboolean transpose, GLfloat* value ) ; +GL-FUNCTION: void glUniformMatrix3x2fv ( GLint location, GLsizei count, GLboolean transpose, GLfloat* value ) ; +GL-FUNCTION: void glUniformMatrix3x4fv ( GLint location, GLsizei count, GLboolean transpose, GLfloat* value ) ; +GL-FUNCTION: void glUniformMatrix4x2fv ( GLint location, GLsizei count, GLboolean transpose, GLfloat* value ) ; +GL-FUNCTION: void glUniformMatrix4x3fv ( GLint location, GLsizei count, GLboolean transpose, GLfloat* value ) ; + + +! GL_EXT_framebuffer_object + + +: GL_INVALID_FRAMEBUFFER_OPERATION_EXT HEX: 0506 ; inline +: GL_MAX_RENDERBUFFER_SIZE_EXT HEX: 84E8 ; inline +: GL_FRAMEBUFFER_BINDING_EXT HEX: 8CA6 ; inline +: GL_RENDERBUFFER_BINDING_EXT HEX: 8CA7 ; inline +: GL_FRAMEBUFFER_ATTACHMENT_OBJECT_TYPE_EXT HEX: 8CD0 ; inline +: GL_FRAMEBUFFER_ATTACHMENT_OBJECT_NAME_EXT HEX: 8CD1 ; inline +: GL_FRAMEBUFFER_ATTACHMENT_TEXTURE_LEVEL_EXT HEX: 8CD2 ; inline +: GL_FRAMEBUFFER_ATTACHMENT_TEXTURE_CUBE_MAP_FACE_EXT HEX: 8CD3 ; inline +: GL_FRAMEBUFFER_ATTACHMENT_TEXTURE_3D_ZOFFSET_EXT HEX: 8CD4 ; inline +: GL_FRAMEBUFFER_COMPLETE_EXT HEX: 8CD5 ; inline +: GL_FRAMEBUFFER_INCOMPLETE_ATTACHMENT_EXT HEX: 8CD6 ; inline +: GL_FRAMEBUFFER_INCOMPLETE_MISSING_ATTACHMENT_EXT HEX: 8CD7 ; inline +: GL_FRAMEBUFFER_INCOMPLETE_DIMENSIONS_EXT HEX: 8CD9 ; inline +: GL_FRAMEBUFFER_INCOMPLETE_FORMATS_EXT HEX: 8CDA ; inline +: GL_FRAMEBUFFER_INCOMPLETE_DRAW_BUFFER_EXT HEX: 8CDB ; inline +: GL_FRAMEBUFFER_INCOMPLETE_READ_BUFFER_EXT HEX: 8CDC ; inline +: GL_FRAMEBUFFER_UNSUPPORTED_EXT HEX: 8CDD ; inline +: GL_MAX_COLOR_ATTACHMENTS_EXT HEX: 8CDF ; inline +: GL_COLOR_ATTACHMENT0_EXT HEX: 8CE0 ; inline +: GL_COLOR_ATTACHMENT1_EXT HEX: 8CE1 ; inline +: GL_COLOR_ATTACHMENT2_EXT HEX: 8CE2 ; inline +: GL_COLOR_ATTACHMENT3_EXT HEX: 8CE3 ; inline +: GL_COLOR_ATTACHMENT4_EXT HEX: 8CE4 ; inline +: GL_COLOR_ATTACHMENT5_EXT HEX: 8CE5 ; inline +: GL_COLOR_ATTACHMENT6_EXT HEX: 8CE6 ; inline +: GL_COLOR_ATTACHMENT7_EXT HEX: 8CE7 ; inline +: GL_COLOR_ATTACHMENT8_EXT HEX: 8CE8 ; inline +: GL_COLOR_ATTACHMENT9_EXT HEX: 8CE9 ; inline +: GL_COLOR_ATTACHMENT10_EXT HEX: 8CEA ; inline +: GL_COLOR_ATTACHMENT11_EXT HEX: 8CEB ; inline +: GL_COLOR_ATTACHMENT12_EXT HEX: 8CEC ; inline +: GL_COLOR_ATTACHMENT13_EXT HEX: 8CED ; inline +: GL_COLOR_ATTACHMENT14_EXT HEX: 8CEE ; inline +: GL_COLOR_ATTACHMENT15_EXT HEX: 8CEF ; inline +: GL_DEPTH_ATTACHMENT_EXT HEX: 8D00 ; inline +: GL_STENCIL_ATTACHMENT_EXT HEX: 8D20 ; inline +: GL_FRAMEBUFFER_EXT HEX: 8D40 ; inline +: GL_RENDERBUFFER_EXT HEX: 8D41 ; inline +: GL_RENDERBUFFER_WIDTH_EXT HEX: 8D42 ; inline +: GL_RENDERBUFFER_HEIGHT_EXT HEX: 8D43 ; inline +: GL_RENDERBUFFER_INTERNAL_FORMAT_EXT HEX: 8D44 ; inline +: GL_STENCIL_INDEX1_EXT HEX: 8D46 ; inline +: GL_STENCIL_INDEX4_EXT HEX: 8D47 ; inline +: GL_STENCIL_INDEX8_EXT HEX: 8D48 ; inline +: GL_STENCIL_INDEX16_EXT HEX: 8D49 ; inline +: GL_RENDERBUFFER_RED_SIZE_EXT HEX: 8D50 ; inline +: GL_RENDERBUFFER_GREEN_SIZE_EXT HEX: 8D51 ; inline +: GL_RENDERBUFFER_BLUE_SIZE_EXT HEX: 8D52 ; inline +: GL_RENDERBUFFER_ALPHA_SIZE_EXT HEX: 8D53 ; inline +: GL_RENDERBUFFER_DEPTH_SIZE_EXT HEX: 8D54 ; inline +: GL_RENDERBUFFER_STENCIL_SIZE_EXT HEX: 8D55 ; inline + +GL-FUNCTION: void glBindFramebufferEXT ( GLenum target, GLuint framebuffer ) ; +GL-FUNCTION: void glBindRenderbufferEXT ( GLenum target, GLuint renderbuffer ) ; +GL-FUNCTION: GLenum glCheckFramebufferStatusEXT ( GLenum target ) ; +GL-FUNCTION: void glDeleteFramebuffersEXT ( GLsizei n, GLuint* framebuffers ) ; +GL-FUNCTION: void glDeleteRenderbuffersEXT ( GLsizei n, GLuint* renderbuffers ) ; +GL-FUNCTION: void glFramebufferRenderbufferEXT ( GLenum target, GLenum attachment, GLenum renderbuffertarget, GLuint renderbuffer ) ; +GL-FUNCTION: void glFramebufferTexture1DEXT ( GLenum target, GLenum attachment, GLenum textarget, GLuint texture, GLint level ) ; +GL-FUNCTION: void glFramebufferTexture2DEXT ( GLenum target, GLenum attachment, GLenum textarget, GLuint texture, GLint level ) ; +GL-FUNCTION: void glFramebufferTexture3DEXT ( GLenum target, GLenum attachment, GLenum textarget, GLuint texture, GLint level, GLint zoffset ) ; +GL-FUNCTION: void glGenFramebuffersEXT ( GLsizei n, GLuint* framebuffers ) ; +GL-FUNCTION: void glGenRenderbuffersEXT ( GLsizei n, GLuint* renderbuffers ) ; +GL-FUNCTION: void glGenerateMipmapEXT ( GLenum target ) ; +GL-FUNCTION: void glGetFramebufferAttachmentParameterivEXT ( GLenum target, GLenum attachment, GLenum pname, GLint* params ) ; +GL-FUNCTION: void glGetRenderbufferParameterivEXT ( GLenum target, GLenum pname, GLint* params ) ; +GL-FUNCTION: GLboolean glIsFramebufferEXT ( GLuint framebuffer ) ; +GL-FUNCTION: GLboolean glIsRenderbufferEXT ( GLuint renderbuffer ) ; +GL-FUNCTION: void glRenderbufferStorageEXT ( GLenum target, GLenum internalformat, GLsizei width, GLsizei height ) ; + + +! GL_ARB_texture_float + + +: GL_RGBA32F_ARB HEX: 8814 ; inline +: GL_RGB32F_ARB HEX: 8815 ; inline +: GL_ALPHA32F_ARB HEX: 8816 ; inline +: GL_INTENSITY32F_ARB HEX: 8817 ; inline +: GL_LUMINANCE32F_ARB HEX: 8818 ; inline +: GL_LUMINANCE_ALPHA32F_ARB HEX: 8819 ; inline +: GL_RGBA16F_ARB HEX: 881A ; inline +: GL_RGB16F_ARB HEX: 881B ; inline +: GL_ALPHA16F_ARB HEX: 881C ; inline +: GL_INTENSITY16F_ARB HEX: 881D ; inline +: GL_LUMINANCE16F_ARB HEX: 881E ; inline +: GL_LUMINANCE_ALPHA16F_ARB HEX: 881F ; inline +: GL_TEXTURE_RED_TYPE_ARB HEX: 8C10 ; inline +: GL_TEXTURE_GREEN_TYPE_ARB HEX: 8C11 ; inline +: GL_TEXTURE_BLUE_TYPE_ARB HEX: 8C12 ; inline +: GL_TEXTURE_ALPHA_TYPE_ARB HEX: 8C13 ; inline +: GL_TEXTURE_LUMINANCE_TYPE_ARB HEX: 8C14 ; inline +: GL_TEXTURE_INTENSITY_TYPE_ARB HEX: 8C15 ; inline +: GL_TEXTURE_DEPTH_TYPE_ARB HEX: 8C16 ; inline +: GL_UNSIGNED_NORMALIZED_ARB HEX: 8C17 ; inline + diff --git a/extra/opengl/gl/unix/unix.factor b/extra/opengl/gl/unix/unix.factor new file mode 100644 index 0000000000..08141ad81d --- /dev/null +++ b/extra/opengl/gl/unix/unix.factor @@ -0,0 +1,5 @@ +USING: alien.syntax kernel syntax words ; + +IN: opengl.gl.unix + +: GL-FUNCTION: \ FUNCTION: word-def call ; parsing diff --git a/extra/opengl/gl/windows/windows.factor b/extra/opengl/gl/windows/windows.factor new file mode 100644 index 0000000000..96fb91793d --- /dev/null +++ b/extra/opengl/gl/windows/windows.factor @@ -0,0 +1,18 @@ +USING: alien alien.syntax kernel libc namespaces parser + sequences syntax system vectors ; + +IN: opengl.gl.windows + +SYMBOL: gl-function-pointers + +LIBRARY: gl +FUNCTION: void* wglGetProcAddress ( char* name ) ; + +: GL-FUNCTION: + "stdcall" + scan + scan + dup [ wglGetProcAddress check-ptr ] curry swap + ";" parse-tokens [ "()" subseq? not ] subset + define-indirect + ; parsing diff --git a/extra/opengl/opengl.factor b/extra/opengl/opengl.factor index aabdccd1fb..dd9d6b8ccd 100644 --- a/extra/opengl/opengl.factor +++ b/extra/opengl/opengl.factor @@ -1,7 +1,7 @@ ! Copyright (C) 2005, 2007 Slava Pestov. ! Portions copyright (C) 2007 Eduardo Cavazos. ! See http://factorcode.org/license.txt for BSD license. -USING: alien alien.c-types kernel math namespaces sequences +USING: alien alien.c-types kernel libc math namespaces sequences math.vectors math.constants math.functions opengl.gl opengl.glu combinators arrays ; IN: opengl @@ -20,7 +20,7 @@ IN: opengl : gl-error ( -- ) glGetError dup zero? [ - "GL error: " dup gluErrorString append throw + "GL error: " over gluErrorString append throw ] unless drop ; : do-state ( what quot -- ) @@ -185,3 +185,100 @@ TUPLE: sprite loc dim dim2 dlist texture ; glLoadIdentity GL_MODELVIEW glMatrixMode glLoadIdentity ; + +! Shaders + +: c-true? ( int -- ? ) zero? not ; inline + +: with-gl-shader-source-ptr ( string quot -- ) + swap dup length 1+ [ tuck string>memory swap call ] with-malloc ; inline + +: ( source kind -- shader ) + glCreateShader dup rot [ 1 swap f glShaderSource ] with-gl-shader-source-ptr + [ glCompileShader ] keep + gl-error ; + +: (gl-shader?) ( object -- ? ) + dup integer? [ glIsShader c-true? ] [ drop f ] if ; + +: gl-shader-get-int ( shader enum -- value ) + 0 [ glGetShaderiv ] keep *int ; + +: gl-shader-ok? ( shader -- ? ) + GL_COMPILE_STATUS gl-shader-get-int c-true? ; + +: ( source -- vertex-shader ) + GL_VERTEX_SHADER ; inline + +: (vertex-shader?) ( object -- ? ) + dup (gl-shader?) [ GL_SHADER_TYPE gl-shader-get-int GL_VERTEX_SHADER = ] [ drop f ] if ; + +: ( source -- fragment-shader ) + GL_FRAGMENT_SHADER ; inline + +: (fragment-shader?) ( object -- ? ) + dup (gl-shader?) [ GL_SHADER_TYPE gl-shader-get-int GL_FRAGMENT_SHADER = ] [ drop f ] if ; + +: gl-shader-info-log-length ( shader -- log-length ) + GL_INFO_LOG_LENGTH gl-shader-get-int ; inline + +: gl-shader-info-log ( shader -- log ) + dup gl-shader-info-log-length dup [ [ 0 swap glGetShaderInfoLog ] keep alien>char-string ] with-malloc ; + +: check-gl-shader ( shader -- shader* ) + dup gl-shader-ok? [ dup gl-shader-info-log throw ] unless ; + +: delete-gl-shader ( shader -- ) glDeleteShader ; inline + +PREDICATE: integer gl-shader (gl-shader?) ; +PREDICATE: gl-shader vertex-shader (vertex-shader?) ; +PREDICATE: gl-shader fragment-shader (fragment-shader?) ; + +! Programs + +: ( shaders -- program ) + glCreateProgram swap + [ dupd glAttachShader ] each + [ glLinkProgram ] keep + gl-error ; + +: (gl-program?) ( object -- ? ) + dup integer? [ glIsProgram c-true? ] [ drop f ] if ; + +: gl-program-get-int ( program enum -- value ) + 0 [ glGetProgramiv ] keep *int ; + +: gl-program-ok? ( program -- ? ) + GL_LINK_STATUS gl-program-get-int c-true? ; + +: gl-program-info-log-length ( program -- log-length ) + GL_INFO_LOG_LENGTH gl-program-get-int ; inline + +: gl-program-info-log ( program -- log ) + dup gl-program-info-log-length + dup [ [ 0 swap glGetProgramInfoLog ] keep + alien>char-string ] with-malloc ; + +: check-gl-program ( program -- program* ) + dup gl-program-ok? [ dup gl-program-info-log throw ] unless ; + +: gl-program-shaders-length ( program -- shaders-length ) + GL_ATTACHED_SHADERS gl-program-get-int ; inline + +: gl-program-shaders ( program -- shaders ) + dup gl-program-shaders-length + [ dup "GLuint" [ 0 swap glGetAttachedShaders ] keep ] keep + c-uint-array> ; + +: delete-gl-program-only ( program -- ) glDeleteProgram ; inline + +: detach-gl-program-shader ( program shader -- ) glDetachShader ; inline + +: delete-gl-program ( program -- ) + dup gl-program-shaders [ 2dup detach-gl-program-shader delete-gl-shader ] each + delete-gl-program-only ; + +: with-gl-program ( program quot -- ) + swap glUseProgram call 0 glUseProgram ; inline + +PREDICATE: integer gl-program (gl-program?) ; From 606b0be95b7d9e3b46ab0430022af48c21efee9b Mon Sep 17 00:00:00 2001 From: Joe Groff Date: Sat, 12 Jan 2008 23:00:52 -0800 Subject: [PATCH 02/30] TextMate bundle commands: Eval, Help, Infer, Run, See --- .../Commands/Eval Selection:Line.tmCommand | 27 +++++++++++++ .../Commands/Help for Word.tmCommand | 30 +++++++++++++++ .../Infer Effect of Selection.tmCommand | 27 +++++++++++++ .../Commands/Run File in Listener.tmCommand | 25 ++++++++++++ .../Run Selection:Line in Listener.tmCommand | 27 +++++++++++++ .../Commands/See Word.tmCommand | 30 +++++++++++++++ misc/Factor.tmbundle/Support/lib/tm_factor.rb | 38 +++++++++++++++++++ .../Syntaxes/Factor.tmLanguage | 6 +-- .../Syntaxes/HTML (Factor).tmLanguage | 2 +- misc/Factor.tmbundle/info.plist | 13 ++++++- 10 files changed, 220 insertions(+), 5 deletions(-) create mode 100644 misc/Factor.tmbundle/Commands/Eval Selection:Line.tmCommand create mode 100644 misc/Factor.tmbundle/Commands/Help for Word.tmCommand create mode 100644 misc/Factor.tmbundle/Commands/Infer Effect of Selection.tmCommand create mode 100644 misc/Factor.tmbundle/Commands/Run File in Listener.tmCommand create mode 100644 misc/Factor.tmbundle/Commands/Run Selection:Line in Listener.tmCommand create mode 100644 misc/Factor.tmbundle/Commands/See Word.tmCommand create mode 100644 misc/Factor.tmbundle/Support/lib/tm_factor.rb diff --git a/misc/Factor.tmbundle/Commands/Eval Selection:Line.tmCommand b/misc/Factor.tmbundle/Commands/Eval Selection:Line.tmCommand new file mode 100644 index 0000000000..37867a2737 --- /dev/null +++ b/misc/Factor.tmbundle/Commands/Eval Selection:Line.tmCommand @@ -0,0 +1,27 @@ + + + + + beforeRunningCommand + nop + command + #!/usr/bin/env ruby + +require "#{ENV["TM_BUNDLE_SUPPORT"]}/lib/tm_factor" +puts factor_eval(STDIN.read) + fallbackInput + line + input + selection + keyEquivalent + ^E + name + Eval Selection/Line + output + replaceSelectedText + scope + source.factor + uuid + 8E01DDAF-959B-4237-ADB9-C133A4ACCE90 + + diff --git a/misc/Factor.tmbundle/Commands/Help for Word.tmCommand b/misc/Factor.tmbundle/Commands/Help for Word.tmCommand new file mode 100644 index 0000000000..a3d77d2f0c --- /dev/null +++ b/misc/Factor.tmbundle/Commands/Help for Word.tmCommand @@ -0,0 +1,30 @@ + + + + + beforeRunningCommand + nop + command + #!/usr/bin/env ruby + +require "#{ENV["TM_BUNDLE_SUPPORT"]}/lib/tm_factor" + +doc = STDIN.read +word = line_current_word(ENV["TM_CURRENT_LINE"], ENV["TM_LINE_INDEX"].to_i) +factor_run(%Q(#{doc_using_statements(doc)} \\ #{word} help)) + fallbackInput + word + input + document + keyEquivalent + ^H + name + Help for Word + output + showAsTooltip + scope + source.factor + uuid + BC5BE120-734B-40DF-8B6B-5D3243614B27 + + diff --git a/misc/Factor.tmbundle/Commands/Infer Effect of Selection.tmCommand b/misc/Factor.tmbundle/Commands/Infer Effect of Selection.tmCommand new file mode 100644 index 0000000000..378294e6c1 --- /dev/null +++ b/misc/Factor.tmbundle/Commands/Infer Effect of Selection.tmCommand @@ -0,0 +1,27 @@ + + + + + beforeRunningCommand + nop + command + #!/usr/bin/env ruby + +require "#{ENV["TM_BUNDLE_SUPPORT"]}/lib/tm_factor" + +doc = STDIN.read +puts factor_eval(%Q(#{doc_using_statements(doc)} USE: inference\n [ #{ENV["TM_SELECTED_TEXT"]} ] infer.)) + fallbackInput + word + input + document + name + Infer Effect of Selection + output + showAsTooltip + scope + source.factor + uuid + B619FCC0-2DF2-4657-82A8-0E5676A10254 + + diff --git a/misc/Factor.tmbundle/Commands/Run File in Listener.tmCommand b/misc/Factor.tmbundle/Commands/Run File in Listener.tmCommand new file mode 100644 index 0000000000..bc8c84ec13 --- /dev/null +++ b/misc/Factor.tmbundle/Commands/Run File in Listener.tmCommand @@ -0,0 +1,25 @@ + + + + + beforeRunningCommand + nop + command + #!/usr/bin/env ruby + +require "#{ENV["TM_BUNDLE_SUPPORT"]}/lib/tm_factor" +factor_run(%Q("#{ENV["TM_FILEPATH"]}" run-file)) + input + none + keyEquivalent + @r + name + Run File in Listener + output + discard + scope + source.factor + uuid + CAD3BB10-C480-4C0E-9518-94D61F7A0C0B + + diff --git a/misc/Factor.tmbundle/Commands/Run Selection:Line in Listener.tmCommand b/misc/Factor.tmbundle/Commands/Run Selection:Line in Listener.tmCommand new file mode 100644 index 0000000000..5028bd8db3 --- /dev/null +++ b/misc/Factor.tmbundle/Commands/Run Selection:Line in Listener.tmCommand @@ -0,0 +1,27 @@ + + + + + beforeRunningCommand + nop + command + #!/usr/bin/env ruby + +require "#{ENV["TM_BUNDLE_SUPPORT"]}/lib/tm_factor" +factor_run(STDIN.read) + fallbackInput + line + input + selection + keyEquivalent + ^~e + name + Run Selection/Line in Listener + output + discard + scope + source.factor + uuid + 15A984BD-BC65-43E8-878A-267788C8DA70 + + diff --git a/misc/Factor.tmbundle/Commands/See Word.tmCommand b/misc/Factor.tmbundle/Commands/See Word.tmCommand new file mode 100644 index 0000000000..b9dd2e5e90 --- /dev/null +++ b/misc/Factor.tmbundle/Commands/See Word.tmCommand @@ -0,0 +1,30 @@ + + + + + beforeRunningCommand + nop + command + #!/usr/bin/env ruby + +require "#{ENV["TM_BUNDLE_SUPPORT"]}/lib/tm_factor" + +doc = STDIN.read +word = line_current_word(ENV["TM_CURRENT_LINE"], ENV["TM_LINE_INDEX"].to_i) +puts factor_eval(%Q(#{doc_using_statements(doc)} \\ #{word} see)) + fallbackInput + word + input + document + keyEquivalent + ^h + name + See Word + output + showAsTooltip + scope + source.factor + uuid + 35484754-DBF9-4381-BB25-00CAB64DF4A1 + + diff --git a/misc/Factor.tmbundle/Support/lib/tm_factor.rb b/misc/Factor.tmbundle/Support/lib/tm_factor.rb new file mode 100644 index 0000000000..54272e5e36 --- /dev/null +++ b/misc/Factor.tmbundle/Support/lib/tm_factor.rb @@ -0,0 +1,38 @@ +require 'osx/cocoa' + +def _wait_for_return_value(pb) + origCount = pb.changeCount + sleep 0.125 while pb.changeCount == origCount +end + +def perform_service(service, in_string, wait_for_return_value=false) + p = OSX::NSPasteboard.pasteboardWithUniqueName + p.declareTypes_owner([OSX::NSStringPboardType], nil) + p.setString_forType(in_string, OSX::NSStringPboardType) + raise "Unable to call service #{service}" unless OSX::NSPerformService(service, p) + _wait_for_return_value(p) if wait_for_return_value + p.stringForType(OSX::NSStringPboardType) +end + +def textmate_front() + system %Q{osascript -e 'tell app "TextMate" to activate'}; +end + +def factor_run(code) + perform_service("Factor/Evaluate in Listener", code) +end + +def factor_eval(code) + r = perform_service("Factor/Evaluate Selection", code, true) + textmate_front + r +end + +def doc_using_statements(document) + document.scan(/\b(USING:\s[^;]*\s;|USE:\s+\S+|IN:\s\S+)/).join("\n") << "\n" +end + +def line_current_word(line, point) + left = line.rindex(/\s|^/, point - 1) + 1; right = line.index(/\s|$/, point) - 1 + line[left..right] +end diff --git a/misc/Factor.tmbundle/Syntaxes/Factor.tmLanguage b/misc/Factor.tmbundle/Syntaxes/Factor.tmLanguage index ec4961f312..304af129ce 100644 --- a/misc/Factor.tmbundle/Syntaxes/Factor.tmLanguage +++ b/misc/Factor.tmbundle/Syntaxes/Factor.tmLanguage @@ -1,5 +1,5 @@ - + fileTypes @@ -254,9 +254,9 @@ begin - \(\s + \((?=\s) end - \s\) + (^|(?<=\s))\) name comment.parens.factor diff --git a/misc/Factor.tmbundle/Syntaxes/HTML (Factor).tmLanguage b/misc/Factor.tmbundle/Syntaxes/HTML (Factor).tmLanguage index 89c0f191b9..03394b933c 100644 --- a/misc/Factor.tmbundle/Syntaxes/HTML (Factor).tmLanguage +++ b/misc/Factor.tmbundle/Syntaxes/HTML (Factor).tmLanguage @@ -1,5 +1,5 @@ - + fileTypes diff --git a/misc/Factor.tmbundle/info.plist b/misc/Factor.tmbundle/info.plist index 8def3807d7..1ea756a1a5 100644 --- a/misc/Factor.tmbundle/info.plist +++ b/misc/Factor.tmbundle/info.plist @@ -1,9 +1,20 @@ - + name Factor + ordering + + 3C9C9C2A-314A-475B-A4E4-A68BAAF3F36E + 141517D7-73E0-4475-A481-71102575A175 + CAD3BB10-C480-4C0E-9518-94D61F7A0C0B + 15A984BD-BC65-43E8-878A-267788C8DA70 + 8E01DDAF-959B-4237-ADB9-C133A4ACCE90 + 35484754-DBF9-4381-BB25-00CAB64DF4A1 + BC5BE120-734B-40DF-8B6B-5D3243614B27 + B619FCC0-2DF2-4657-82A8-0E5676A10254 + uuid 8061D2F3-B603-411D-AFFE-61784A07906D From 4044cd293a66877d3c6c41cf7cf61d2aba60fc87 Mon Sep 17 00:00:00 2001 From: Joe Groff Date: Sun, 13 Jan 2008 00:09:08 -0800 Subject: [PATCH 03/30] TYPEDEF-IF: and USE-IF: words; ptrdiff_t C type moved to alien.c-types and special-cased for win64 --- core/alien/c-types/c-types.factor | 3 +++ core/alien/syntax/syntax-docs.factor | 10 ++++++++-- core/alien/syntax/syntax.factor | 3 +++ core/syntax/syntax-docs.factor | 6 ++++++ core/syntax/syntax.factor | 1 + extra/opengl/gl/gl.factor | 2 -- extra/opengl/gl/unix/unix.factor | 2 +- 7 files changed, 22 insertions(+), 5 deletions(-) diff --git a/core/alien/c-types/c-types.factor b/core/alien/c-types/c-types.factor index b665300bee..6d9c2cec14 100755 --- a/core/alien/c-types/c-types.factor +++ b/core/alien/c-types/c-types.factor @@ -358,4 +358,7 @@ M: long-long-type box-return ( type -- ) "ushort*" define-primitive-type [ string>u16-alien ] "ushort*" c-type set-c-type-prep + + win64? "longlong" "long" ? "ptrdiff_t" typedef + ] with-compilation-unit diff --git a/core/alien/syntax/syntax-docs.factor b/core/alien/syntax/syntax-docs.factor index d87b67eb59..00ee6345dc 100755 --- a/core/alien/syntax/syntax-docs.factor +++ b/core/alien/syntax/syntax-docs.factor @@ -49,8 +49,14 @@ $nl HELP: TYPEDEF: { $syntax "TYPEDEF: old new" } -{ $values { "old" "a C type" } { "new" "a C type" } } -{ $description "Alises the C type " { $snippet "old" } " under the name " { $snippet "new" } "." } +{ $values { "word" "a word with stack effect " { $snippet "( -- ? )" } } { "old" "a C type" } { "new" "a C type" } } +{ $description "Alises the C type " { $snippet "old" } " under the name " { $snippet "new" } " if ." } +{ $notes "This word differs from " { $link typedef } " in that it runs at parse time, to ensure correct ordering of operations when loading source files. Words defined in source files are compiled before top-level forms are run, so if a source file defines C binding words and uses " { $link typedef } ", the type alias won't be available at compile time." } ; + +HELP: TYPEDEF-IF: +{ $syntax "TYPEDEF-IF: word old new" } +{ $values { "word" "a word with stack effect " { $snippet "( -- ? )" } } { "old" "a C type" } { "new" "a C type" } } +{ $description "Alises the C type " { $snippet "old" } " under the name " { $snippet "new" } " if " { $snippet "word" } " evaluates to a true value." } { $notes "This word differs from " { $link typedef } " in that it runs at parse time, to ensure correct ordering of operations when loading source files. Words defined in source files are compiled before top-level forms are run, so if a source file defines C binding words and uses " { $link typedef } ", the type alias won't be available at compile time." } ; HELP: C-STRUCT: diff --git a/core/alien/syntax/syntax.factor b/core/alien/syntax/syntax.factor index bc3bc911ef..b81a91efcb 100755 --- a/core/alien/syntax/syntax.factor +++ b/core/alien/syntax/syntax.factor @@ -46,6 +46,9 @@ PRIVATE> : TYPEDEF: scan scan typedef ; parsing +: TYPEDEF-IF: + scan-word execute scan scan rot [ typedef ] [ 2drop ] if ; parsing + : C-STRUCT: scan in get parse-definition diff --git a/core/syntax/syntax-docs.factor b/core/syntax/syntax-docs.factor index 9cf9647e41..f4efc3b6bb 100755 --- a/core/syntax/syntax-docs.factor +++ b/core/syntax/syntax-docs.factor @@ -363,6 +363,12 @@ HELP: USE: { $description "Adds a new vocabulary at the front of the search path. Subsequent word lookups by the parser will search this vocabulary first." } { $errors "Throws an error if the vocabulary does not exist." } ; +HELP: USE-IF: +{ $syntax "USE-IF: word vocabulary" } +{ $values { "word" "a word with stack effect " { $snippet "( -- ? )" } } { "vocabulary" "a vocabulary name" } } +{ $description "Adds " { $snippet "vocabulary" } " at the front of the search path if " { $snippet "word" } " evaluates to a true value." } +{ $errors "Throws an error if the vocabulary does not exist." } ; + HELP: USING: { $syntax "USING: vocabularies... ;" } { $values { "vocabularies" "a list of vocabulary names" } } diff --git a/core/syntax/syntax.factor b/core/syntax/syntax.factor index b0a7ea19bd..cd97aea9eb 100755 --- a/core/syntax/syntax.factor +++ b/core/syntax/syntax.factor @@ -46,6 +46,7 @@ IN: bootstrap.syntax ] define-syntax "USE:" [ scan use+ ] define-syntax + "USE-IF:" [ scan-word execute scan swap [ use+ ] [ drop ] if ] define-syntax "USING:" [ ";" parse-tokens add-use ] define-syntax diff --git a/extra/opengl/gl/gl.factor b/extra/opengl/gl/gl.factor index c7ce176aca..4a9d9c84d5 100644 --- a/extra/opengl/gl/gl.factor +++ b/extra/opengl/gl/gl.factor @@ -1469,8 +1469,6 @@ GL-FUNCTION: void glWindowPos3sv ( GLshort* p ) ; : GL_SRC2_ALPHA GL_SOURCE2_ALPHA ; inline : GL_SRC2_RGB GL_SOURCE2_RGB ; inline -TYPEDEF: long ptrdiff_t - TYPEDEF: ptrdiff_t GLsizeiptr TYPEDEF: ptrdiff_t GLintptr diff --git a/extra/opengl/gl/unix/unix.factor b/extra/opengl/gl/unix/unix.factor index 08141ad81d..16cd38f92f 100644 --- a/extra/opengl/gl/unix/unix.factor +++ b/extra/opengl/gl/unix/unix.factor @@ -2,4 +2,4 @@ USING: alien.syntax kernel syntax words ; IN: opengl.gl.unix -: GL-FUNCTION: \ FUNCTION: word-def call ; parsing +: GL-FUNCTION: POSTPONE: FUNCTION: ; parsing From 8f69f864382af35dbd410a50f722a04ac76139c7 Mon Sep 17 00:00:00 2001 From: Joe Groff Date: Sun, 13 Jan 2008 17:35:26 -0800 Subject: [PATCH 04/30] Cel shading demo. Caching implementation of GL-FUNCTION: for windows. --- Makefile | 2 +- core/strings/strings-docs.factor | 0 extra/cel-shading/cel-shading.factor | 152 +++++++++++++++++++++++++ extra/opengl/gl/windows/windows.factor | 26 ++++- extra/windows/opengl32/opengl32.factor | 4 +- 5 files changed, 176 insertions(+), 8 deletions(-) mode change 100644 => 100755 core/strings/strings-docs.factor create mode 100644 extra/cel-shading/cel-shading.factor mode change 100644 => 100755 extra/opengl/gl/windows/windows.factor mode change 100644 => 100755 extra/windows/opengl32/opengl32.factor diff --git a/Makefile b/Makefile index 1042731065..e02b6a672b 100755 --- a/Makefile +++ b/Makefile @@ -140,7 +140,7 @@ factor: $(DLL_OBJS) $(EXE_OBJS) clean: rm -f vm/*.o - rm -f libfactor.a + rm -f factor*.dll libfactor*.* vm/resources.o: windres vm/factor.rs vm/resources.o diff --git a/core/strings/strings-docs.factor b/core/strings/strings-docs.factor old mode 100644 new mode 100755 diff --git a/extra/cel-shading/cel-shading.factor b/extra/cel-shading/cel-shading.factor new file mode 100644 index 0000000000..e21638b75b --- /dev/null +++ b/extra/cel-shading/cel-shading.factor @@ -0,0 +1,152 @@ +USING: arrays bunny io io.files kernel + math math.functions math.vectors + namespaces + opengl opengl.gl + prettyprint + sequences ui ui.gadgets ui.gestures ui.render ; +IN: cel-shading + +: NEAR-PLANE 1.0 64.0 / ; inline +: FAR-PLANE 4.0 ; inline +: FOV 2.0 sqrt 1+ ; inline +: MOUSE-MOTION-SCALE 0.5 ; inline +: MOUSE-DISTANCE-SCALE 1.0 64.0 / ; inline +: KEY-ROTATE-STEP 1.0 ; inline +: KEY-DISTANCE-STEP 1.0 64.0 / ; inline +: DIMS { 640 480 } ; inline + +: FOV-RATIO ( -- fov ) DIMS dup first2 min v/n ; + +SYMBOL: last-drag-loc + +TUPLE: cel-shading-gadget yaw pitch distance model program ; + +: ( -- cel-shading-gadget ) + cel-shading-gadget construct-gadget + 0.0 over set-cel-shading-gadget-yaw + 0.0 over set-cel-shading-gadget-pitch + 0.375 over set-cel-shading-gadget-distance + maybe-download read-model over set-cel-shading-gadget-model ; + +: yaw-cel-shading-gadget ( yaw gadget -- ) + [ [ cel-shading-gadget-yaw + ] keep set-cel-shading-gadget-yaw ] keep relayout-1 ; + +: pitch-cel-shading-gadget ( pitch gadget -- ) + [ [ cel-shading-gadget-pitch + ] keep set-cel-shading-gadget-pitch ] keep relayout-1 ; + +: zoom-cel-shading-gadget ( distance gadget -- ) + [ [ cel-shading-gadget-distance + ] keep set-cel-shading-gadget-distance ] keep relayout-1 ; + +M: cel-shading-gadget pref-dim* ( gadget -- dim ) + drop DIMS ; + +: -+ ( x -- -x x ) + dup neg swap ; + +: cel-shading-frustum ( -- -x x -y y near far ) + FOV-RATIO NEAR-PLANE FOV / v*n + first2 [ -+ ] 2apply NEAR-PLANE FAR-PLANE ; + +: cel-shading-vertex-shader-source + { + "varying vec3 position, normal;" + "" + "void" + "main()" + "{" + "gl_Position = ftransform();" + "" + "position = gl_Vertex.xyz;" + "normal = gl_Normal;" + "}" + } "\n" join ; + +: cel-shading-fragment-shader-source + { + "varying vec3 position, normal;" + "uniform vec3 light_direction;" + "uniform vec4 color;" + "uniform vec4 ambient, diffuse;" + "" + "float" + "smooth_modulate(vec3 direction, vec3 normal)" + "{" + "return clamp(dot(direction, normal), 0.0, 1.0);" + "}" + "" + "float" + "modulate(vec3 direction, vec3 normal)" + "{" + "float m = smooth_modulate(direction, normal);" + "return smoothstep(0.0, 0.01, m) * 0.4 + smoothstep(0.49, 0.5, m) * 0.5;" + "}" + "" + "void" + "main()" + "{" + "vec3 direction = normalize(light_direction - position);" + "gl_FragColor = ambient + diffuse * color * vec4(vec3(modulate(direction, normal)), 1); " + "}" + } "\n" join ; + +: cel-shading-program ( -- program ) + cel-shading-vertex-shader-source check-gl-shader + cel-shading-fragment-shader-source check-gl-shader + 2array check-gl-program ; + +M: cel-shading-gadget graft* ( gadget -- ) + 0.0 0.0 0.0 1.0 glClearColor + GL_CULL_FACE glEnable + GL_DEPTH_TEST glEnable + cel-shading-program swap set-cel-shading-gadget-program ; + +M: cel-shading-gadget ungraft* ( gadget -- ) + cel-shading-gadget-program delete-gl-program ; + +: cel-shading-draw-setup ( gadget -- gadget ) + GL_PROJECTION glMatrixMode + glLoadIdentity + cel-shading-frustum glFrustum + GL_COLOR_BUFFER_BIT GL_DEPTH_BUFFER_BIT bitor glClear + GL_MODELVIEW glMatrixMode + glLoadIdentity + [ >r 0.0 0.0 r> cel-shading-gadget-distance neg glTranslatef ] keep + [ cel-shading-gadget-pitch 1.0 0.0 0.0 glRotatef ] keep + [ cel-shading-gadget-yaw 0.0 1.0 0.0 glRotatef ] keep + [ cel-shading-gadget-program [ "light_direction" glGetUniformLocation -25.0 45.0 80.0 glUniform3f ] keep + [ "color" glGetUniformLocation 0.6 0.5 0.5 1.0 glUniform4f ] keep + [ "ambient" glGetUniformLocation 0.2 0.2 0.2 0.2 glUniform4f ] keep + "diffuse" glGetUniformLocation 0.8 0.8 0.8 0.8 glUniform4f ] keep ; + +M: cel-shading-gadget draw-gadget* ( gadget -- ) + dup cel-shading-gadget-program [ + cel-shading-draw-setup + 0.0 -0.12 0.0 glTranslatef + cel-shading-gadget-model first3 draw-bunny + ] with-gl-program ; + +: reset-last-drag-rel ( -- ) + { 0 0 } last-drag-loc set ; +: last-drag-rel ( -- rel ) + drag-loc [ last-drag-loc get v- ] keep last-drag-loc set ; + +: drag-yaw-pitch ( -- yaw pitch ) + last-drag-rel MOUSE-MOTION-SCALE v*n first2 ; + +cel-shading-gadget H{ + { T{ key-down f f "LEFT" } [ KEY-ROTATE-STEP neg swap yaw-cel-shading-gadget ] } + { T{ key-down f f "RIGHT" } [ KEY-ROTATE-STEP swap yaw-cel-shading-gadget ] } + { T{ key-down f f "DOWN" } [ KEY-ROTATE-STEP neg swap pitch-cel-shading-gadget ] } + { T{ key-down f f "UP" } [ KEY-ROTATE-STEP swap pitch-cel-shading-gadget ] } + { T{ key-down f f "=" } [ KEY-DISTANCE-STEP neg swap zoom-cel-shading-gadget ] } + { T{ key-down f f "-" } [ KEY-DISTANCE-STEP swap zoom-cel-shading-gadget ] } + + { T{ button-down f f 1 } [ drop reset-last-drag-rel ] } + { T{ drag f 1 } [ drag-yaw-pitch rot [ pitch-cel-shading-gadget ] keep yaw-cel-shading-gadget ] } + { T{ mouse-scroll } [ scroll-direction get second MOUSE-DISTANCE-SCALE * swap zoom-cel-shading-gadget ] } +} set-gestures + +: cel-shading-window ( -- ) + [ "Cel Shading" open-window ] with-ui ; + +MAIN: cel-shading-window diff --git a/extra/opengl/gl/windows/windows.factor b/extra/opengl/gl/windows/windows.factor old mode 100644 new mode 100755 index 96fb91793d..186f17206c --- a/extra/opengl/gl/windows/windows.factor +++ b/extra/opengl/gl/windows/windows.factor @@ -1,18 +1,34 @@ -USING: alien alien.syntax kernel libc namespaces parser - sequences syntax system vectors ; +USING: alien alien.syntax arrays assocs hashtables init kernel + libc math namespaces parser sequences syntax system vectors + windows.opengl32 ; IN: opengl.gl.windows + gl-function-pointers set ] "opengl.gl.windows init hook" add-init-hook + +: gl-function-number ( -- n ) + gl-function-number-counter get + dup 1+ gl-function-number-counter set ; + +: gl-function-pointer ( name n -- funptr ) + wglGetCurrentContext 2array dup gl-function-pointers get at + [ -rot 2drop ] + [ >r wglGetProcAddress dup r> gl-function-pointers get set-at ] + if* ; + +PRIVATE> : GL-FUNCTION: "stdcall" scan scan - dup [ wglGetProcAddress check-ptr ] curry swap + dup gl-function-number [ gl-function-pointer ] 2curry swap ";" parse-tokens [ "()" subseq? not ] subset define-indirect ; parsing diff --git a/extra/windows/opengl32/opengl32.factor b/extra/windows/opengl32/opengl32.factor old mode 100644 new mode 100755 index 2d58d34083..a8d8ad8153 --- a/extra/windows/opengl32/opengl32.factor +++ b/extra/windows/opengl32/opengl32.factor @@ -1,8 +1,7 @@ ! Copyright (C) 2005, 2006 Doug Coleman. ! See http://factorcode.org/license.txt for BSD license. USING: alien alien.c-types alien.syntax parser namespaces kernel -math windows.types windows.types init assocs sequences opengl.gl -libc ; +math windows.types windows.types init assocs sequences libc ; IN: windows.opengl32 ! PIXELFORMATDESCRIPTOR flags @@ -100,4 +99,5 @@ LIBRARY: gl FUNCTION: HGLRC wglCreateContext ( HDC hDC ) ; FUNCTION: BOOL wglDeleteContext ( HGLRC hRC ) ; FUNCTION: BOOL wglMakeCurrent ( HDC hDC, HGLRC hglrc ) ; +FUNCTION: HGLRC wglGetCurrentContext ( ) ; FUNCTION: void* wglGetProcAddress ( char* name ) ; From b42d144336e1e98daf93d1e94a5cb38b5e829f02 Mon Sep 17 00:00:00 2001 From: Joe Groff Date: Sun, 13 Jan 2008 18:15:37 -0800 Subject: [PATCH 05/30] Documentation for the cel shading demo --- extra/cel-shading/authors.txt | 1 + extra/cel-shading/summary.txt | 1 + extra/cel-shading/tags.txt | 3 +++ 3 files changed, 5 insertions(+) create mode 100644 extra/cel-shading/authors.txt create mode 100644 extra/cel-shading/summary.txt create mode 100644 extra/cel-shading/tags.txt diff --git a/extra/cel-shading/authors.txt b/extra/cel-shading/authors.txt new file mode 100644 index 0000000000..6a0dc7293a --- /dev/null +++ b/extra/cel-shading/authors.txt @@ -0,0 +1 @@ +Joe Groff \ No newline at end of file diff --git a/extra/cel-shading/summary.txt b/extra/cel-shading/summary.txt new file mode 100644 index 0000000000..60da092f6d --- /dev/null +++ b/extra/cel-shading/summary.txt @@ -0,0 +1 @@ +Stanford Bunny rendered with a cel-shading GLSL program \ No newline at end of file diff --git a/extra/cel-shading/tags.txt b/extra/cel-shading/tags.txt new file mode 100644 index 0000000000..0db7e8e629 --- /dev/null +++ b/extra/cel-shading/tags.txt @@ -0,0 +1,3 @@ +demos +opengl +glsl \ No newline at end of file From d73d8820c13c2305dce0d1c8f190e683cdb6ef75 Mon Sep 17 00:00:00 2001 From: Joe Groff Date: Sun, 13 Jan 2008 18:17:28 -0800 Subject: [PATCH 06/30] Ensure that the right vocabs are available for textmate See and Help commands --- misc/Factor.tmbundle/Commands/Help for Word.tmCommand | 2 +- misc/Factor.tmbundle/Commands/See Word.tmCommand | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/misc/Factor.tmbundle/Commands/Help for Word.tmCommand b/misc/Factor.tmbundle/Commands/Help for Word.tmCommand index a3d77d2f0c..350c01d344 100644 --- a/misc/Factor.tmbundle/Commands/Help for Word.tmCommand +++ b/misc/Factor.tmbundle/Commands/Help for Word.tmCommand @@ -11,7 +11,7 @@ require "#{ENV["TM_BUNDLE_SUPPORT"]}/lib/tm_factor" doc = STDIN.read word = line_current_word(ENV["TM_CURRENT_LINE"], ENV["TM_LINE_INDEX"].to_i) -factor_run(%Q(#{doc_using_statements(doc)} \\ #{word} help)) +factor_run(%Q(#{doc_using_statements(doc)} USE: help\n \\ #{word} help)) fallbackInput word input diff --git a/misc/Factor.tmbundle/Commands/See Word.tmCommand b/misc/Factor.tmbundle/Commands/See Word.tmCommand index b9dd2e5e90..4502e235be 100644 --- a/misc/Factor.tmbundle/Commands/See Word.tmCommand +++ b/misc/Factor.tmbundle/Commands/See Word.tmCommand @@ -11,7 +11,7 @@ require "#{ENV["TM_BUNDLE_SUPPORT"]}/lib/tm_factor" doc = STDIN.read word = line_current_word(ENV["TM_CURRENT_LINE"], ENV["TM_LINE_INDEX"].to_i) -puts factor_eval(%Q(#{doc_using_statements(doc)} \\ #{word} see)) +puts factor_eval(%Q(#{doc_using_statements(doc)} USE: prettyprint\n \\ #{word} see)) fallbackInput word input From dc2109e6cbce003b9671b43c465c81fad2d6297f Mon Sep 17 00:00:00 2001 From: Joe Groff Date: Sun, 13 Jan 2008 18:46:51 -0800 Subject: [PATCH 07/30] Ensure that the parser vocab is in use for textmate Run command --- misc/Factor.tmbundle/Commands/Run File in Listener.tmCommand | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/misc/Factor.tmbundle/Commands/Run File in Listener.tmCommand b/misc/Factor.tmbundle/Commands/Run File in Listener.tmCommand index bc8c84ec13..f28e062541 100644 --- a/misc/Factor.tmbundle/Commands/Run File in Listener.tmCommand +++ b/misc/Factor.tmbundle/Commands/Run File in Listener.tmCommand @@ -8,7 +8,7 @@ #!/usr/bin/env ruby require "#{ENV["TM_BUNDLE_SUPPORT"]}/lib/tm_factor" -factor_run(%Q("#{ENV["TM_FILEPATH"]}" run-file)) +factor_run(%Q(USE: parser\n "#{ENV["TM_FILEPATH"]}" run-file)) input none keyEquivalent From 53effc35a68bf304f71f05706bb6484c3c65ced4 Mon Sep 17 00:00:00 2001 From: Joe Groff Date: Sun, 13 Jan 2008 19:06:16 -0800 Subject: [PATCH 08/30] Get multiline working again and use it in cel-shading --- extra/cel-shading/cel-shading.factor | 82 +++++++++++++-------------- extra/multiline/multiline-docs.factor | 3 +- extra/multiline/multiline.factor | 2 +- 3 files changed, 44 insertions(+), 43 deletions(-) diff --git a/extra/cel-shading/cel-shading.factor b/extra/cel-shading/cel-shading.factor index e21638b75b..20b392195a 100644 --- a/extra/cel-shading/cel-shading.factor +++ b/extra/cel-shading/cel-shading.factor @@ -1,5 +1,5 @@ USING: arrays bunny io io.files kernel - math math.functions math.vectors + math math.functions math.vectors multiline namespaces opengl opengl.gl prettyprint @@ -47,47 +47,47 @@ M: cel-shading-gadget pref-dim* ( gadget -- dim ) FOV-RATIO NEAR-PLANE FOV / v*n first2 [ -+ ] 2apply NEAR-PLANE FAR-PLANE ; -: cel-shading-vertex-shader-source - { - "varying vec3 position, normal;" - "" - "void" - "main()" - "{" - "gl_Position = ftransform();" - "" - "position = gl_Vertex.xyz;" - "normal = gl_Normal;" - "}" - } "\n" join ; +STRING: cel-shading-vertex-shader-source +varying vec3 position, normal; -: cel-shading-fragment-shader-source - { - "varying vec3 position, normal;" - "uniform vec3 light_direction;" - "uniform vec4 color;" - "uniform vec4 ambient, diffuse;" - "" - "float" - "smooth_modulate(vec3 direction, vec3 normal)" - "{" - "return clamp(dot(direction, normal), 0.0, 1.0);" - "}" - "" - "float" - "modulate(vec3 direction, vec3 normal)" - "{" - "float m = smooth_modulate(direction, normal);" - "return smoothstep(0.0, 0.01, m) * 0.4 + smoothstep(0.49, 0.5, m) * 0.5;" - "}" - "" - "void" - "main()" - "{" - "vec3 direction = normalize(light_direction - position);" - "gl_FragColor = ambient + diffuse * color * vec4(vec3(modulate(direction, normal)), 1); " - "}" - } "\n" join ; +void +main() +{ + gl_Position = ftransform(); + + position = gl_Vertex.xyz; + normal = gl_Normal; +} + +; + +STRING: cel-shading-fragment-shader-source +varying vec3 position, normal; +uniform vec3 light_direction; +uniform vec4 color; +uniform vec4 ambient, diffuse; + +float +smooth_modulate(vec3 direction, vec3 normal) +{ + return clamp(dot(direction, normal), 0.0, 1.0); +} + +float +modulate(vec3 direction, vec3 normal) +{ + float m = smooth_modulate(direction, normal); + return smoothstep(0.0, 0.01, m) * 0.4 + smoothstep(0.49, 0.5, m) * 0.5; +} + +void +main() +{ + vec3 direction = normalize(light_direction - position); + gl_FragColor = ambient + diffuse * color * vec4(vec3(modulate(direction, normal)), 1); +} + +; : cel-shading-program ( -- program ) cel-shading-vertex-shader-source check-gl-shader diff --git a/extra/multiline/multiline-docs.factor b/extra/multiline/multiline-docs.factor index 7e7375cfad..0c0eb5e9dd 100644 --- a/extra/multiline/multiline-docs.factor +++ b/extra/multiline/multiline-docs.factor @@ -1,4 +1,5 @@ -USING: help.markup help.syntax multiline ; +USING: help.markup help.syntax ; +IN: multiline HELP: STRING: { $syntax "STRING: name\nfoo\n;" } diff --git a/extra/multiline/multiline.factor b/extra/multiline/multiline.factor index 89a6e06053..e8063fc759 100644 --- a/extra/multiline/multiline.factor +++ b/extra/multiline/multiline.factor @@ -16,7 +16,7 @@ IN: multiline : STRING: CREATE dup reset-generic - parse-here 1quotation define-compound ; parsing + [ parse-here 1quotation define ] keep make-inline ; parsing : (parse-multiline-string) ( start-index end-text -- end-index ) lexer get line-text 2dup start From 18451c4675422f7744a88e9ff8daace0564f7a8e Mon Sep 17 00:00:00 2001 From: Joe Groff Date: Sun, 13 Jan 2008 19:09:01 -0800 Subject: [PATCH 09/30] TextMate syntax highlighting for multiline strings --- .../Syntaxes/Factor.tmLanguage | 38 +++++++++++++++++++ 1 file changed, 38 insertions(+) diff --git a/misc/Factor.tmbundle/Syntaxes/Factor.tmLanguage b/misc/Factor.tmbundle/Syntaxes/Factor.tmLanguage index 304af129ce..8df0179fd1 100644 --- a/misc/Factor.tmbundle/Syntaxes/Factor.tmLanguage +++ b/misc/Factor.tmbundle/Syntaxes/Factor.tmLanguage @@ -240,6 +240,44 @@ + + begin + <" + end + "> + name + string.quoted.double.multiline.factor + patterns + + + include + #escaped_characters + + + + + begin + (^|(?<=\s))(STRING:)\s+(\S+) + captures + + 2 + + name + keyword.colon.factor + + 3 + + name + entity.name.heredoc.factor + + + contentName + string.unquoted.heredoc.factor + end + ^;$ + name + definition.word.heredoc.factor + match inline|foldable From ce92275c8e50ea4347a17749b196e15ea9f9dd2a Mon Sep 17 00:00:00 2001 From: Joe Groff Date: Sun, 13 Jan 2008 22:58:11 -0800 Subject: [PATCH 10/30] Documentation for the GLSL-related utility words in opengl --- extra/opengl/opengl-docs.factor | 96 ++++++++++++++++++++++++++++++++- 1 file changed, 95 insertions(+), 1 deletion(-) diff --git a/extra/opengl/opengl-docs.factor b/extra/opengl/opengl-docs.factor index f9a491aba6..58b86f09b3 100644 --- a/extra/opengl/opengl-docs.factor +++ b/extra/opengl/opengl-docs.factor @@ -92,6 +92,96 @@ HELP: with-translation { $values { "loc" "a pair of integers" } { "quot" quotation } } { $description "Calls the quotation with a translation by " { $snippet "loc" } " pixels applied to the current " { $link GL_MODELVIEW } " matrix, restoring the matrix when the quotation is done." } ; +HELP: gl-shader +{ $class-description { $snippet "gl-shader" } " is a predicate class comprising values returned by OpenGL to represent shader objects. The following words are provided for creating and manipulating these objects:" + { $list + { { $link } " - Compile GLSL code into a shader object" } + { { $link gl-shader-ok? } " - Check whether a shader object compiled successfully" } + { { $link check-gl-shader } " - Throw an error unless a shader object compiled successfully" } + { { $link gl-shader-info-log } " - Retrieve the info log of messages generated by the GLSL compiler" } + { { $link delete-gl-shader } " - Invalidate a shader object" } + } + "The derived predicate classes " { $link vertex-shader } " and " { $link fragment-shader } " are also defined for the two standard kinds of shader defined by the OpenGL specification." } ; + +HELP: vertex-shader +{ $class-description { $snippet "vertex-shader" } " is the predicate class of " { $link gl-shader } " objects that refer to shaders of type " { $snippet "GL_VERTEX_SHADER" } ". In addition to the " { $snippet "gl-shader" } " words, the following vertex shader-specific functions are defined:" + { $list + { { $link } " - Compile GLSL code into a vertex shader object "} + } +} ; + +HELP: fragment-shader +{ $class-description { $snippet "fragment-shader" } " is the predicate class of " { $link gl-shader } " objects that refer to shaders of type " { $snippet "GL_FRAGMENT_SHADER" } ". In addition to the " { $snippet "gl-shader" } " words, the following fragment shader-specific functions are defined:" + { $list + { { $link } " - Compile GLSL code into a fragment shader object "} + } +} ; + +HELP: +{ $values { "source" "The GLSL source code to compile" } { "kind" "The kind of shader to compile, such as " { $snippet "GL_VERTEX_SHADER" } " or " { $snippet "GL_FRAGMENT_SHADER" } } } +{ $description "Tries to compile the given GLSL source into a shader object. The returned object can be checked for validity by " { $link check-gl-shader } " or " { $link gl-shader-ok? } ". Errors and warnings generated by the GLSL compiler will be collected in the info log, available from " { $link gl-shader-info-log } ".\n\nWhen the shader object is no longer needed, it should be deleted using " { $link delete-gl-shader } " or else be attached to a " { $link gl-program } " object deleted using " { $link delete-gl-program } "." } ; + +HELP: +{ $values { "source" "The GLSL source code to compile" } } +{ $description "Tries to compile the given GLSL source into a vertex shader object. Equivalent to " { $snippet "GL_VERTEX_SHADER " } "." } ; + +HELP: +{ $values { "source" "The GLSL source code to compile" } } +{ $description "Tries to compile the given GLSL source into a fragment shader object. Equivalent to " { $snippet "GL_FRAGMENT_SHADER " } "." } ; + +HELP: gl-shader-ok? +{ $values { "shader" "A " { $link gl-shader } " object" } } +{ $description "Returns a boolean value indicating whether the given shader object compiled successfully. Compilation errors and warnings are available in the shader's info log, which can be gotten using " { $link gl-shader-info-log } "." } ; + +HELP: check-gl-shader +{ $values { "shader" "A " { $link gl-shader } " object" } } +{ $description "Throws an error containing the " { $link gl-shader-info-log } " for the shader object if it failed to compile. Otherwise, the shader object is left on the stack." } ; + +HELP: delete-gl-shader +{ $values { "shader" "A " { $link gl-shader } " object" } } +{ $description "Deletes the shader object, invalidating it and releasing any resources allocated for it by the OpenGL implementation." } ; + +HELP: gl-shader-info-log +{ $values { "shader" "A " { $link gl-shader } " object" } } +{ $description "Retrieves the info log for " { $snippet "shader" } ", including any errors or warnings generated in compiling the shader object." } ; + +HELP: gl-program +{ $class-description { $snippet "gl-program" } " is a predicate class comprising values returned by OpenGL to represent proram objects. The following words are provided for creating and manipulating these objects:" + { $list + { { $link } " - Link a set of shaders into a GLSL program" } + { { $link gl-program-ok? } " - Check whether a program object linked successfully" } + { { $link check-gl-program } " - Throw an error unless a program object linked successfully" } + { { $link gl-program-info-log } " - Retrieve the info log of messages generated by the GLSL linker" } + { { $link gl-program-shaders } " - Retrieve the set of shader objects composing the GLSL linker" } + { { $link delete-gl-program } " - Invalidate a program object and all its attached shaders" } + { { $link with-gl-program } " - Use a program object" } + } +} ; + +HELP: +{ $values { "shaders" "A sequence of " { $link gl-shader } " objects." } } +{ $description "Creates a new GLSL program object, attaches all the shader objects in the " { $snippet "shaders" } " sequence, and attempts to link them. The returned object can be checked for validity by " { $link check-gl-program } " or " { $link gl-program-ok? } ". Errors and warnings generated by the GLSL linker will be collected in the info log, available from " { $link gl-program-info-log } ".\n\nWhen the program object and its attached shaders are no longer needed, it should be deleted using " { $link delete-gl-program } "." } ; + +HELP: gl-program-ok? +{ $values { "program" "A " { $link gl-program } " object" } } +{ $description "Returns a boolean value indicating whether the given program object linked successfully. Link errors and warnings are available in the program's info log, which can be gotten using " { $link gl-program-info-log } "." } ; + +HELP: check-gl-program +{ $values { "program" "A " { $link gl-program } " object" } } +{ $description "Throws an error containing the " { $link gl-program-info-log } " for the program object if it failed to link. Otherwise, the program object is left on the stack." } ; + +HELP: gl-program-info-log +{ $values { "program" "A " { $link gl-program } " object" } } +{ $description "Retrieves the info log for " { $snippet "program" } ", including any errors or warnings generated in linking the program object." } ; + +HELP: delete-gl-program +{ $values { "program" "A " { $link gl-program } " object" } } +{ $description "Deletes the program object, invalidating it and releasing any resources allocated for it by the OpenGL implementation. Any attached " { $link gl-shader } "s are also deleted.\n\nIf the shader objects should be preserved, they should each be detached using " { $link detach-gl-program-shader } ". The program object can then be destroyed alone using " { $link delete-gl-program-only } "." } ; + +HELP: with-gl-program +{ $values { "program" "A " { $link gl-program } " object" } { "quot" "A quotation" } } +{ $description "Enables " { $snippet "program" } " for all OpenGL calls made in " { $snippet "quot" } ". The fixed-function pipeline is restored at the end of " { $snippet "quot" } "." } ; + ARTICLE: "gl-utilities" "OpenGL utility words" "In addition to the full OpenGL API, the " { $vocab-link "opengl" } " vocabulary includes some utility words to give OpenGL a more Factor-like feel." $nl @@ -112,6 +202,10 @@ $nl { $subsection gl-rect } { $subsection gl-fill-poly } { $subsection gl-poly } -{ $subsection gl-gradient } ; +{ $subsection gl-gradient } +"Compiling, linking, and using GLSL programs:" +{ $subsection gl-shader } +{ $subsection gl-program } +; ABOUT: "gl-utilities" From b10ab726a372b9f147f933e9161d235d2c83b1d2 Mon Sep 17 00:00:00 2001 From: Joe Groff Date: Tue, 15 Jan 2008 18:16:38 -0800 Subject: [PATCH 11/30] Fix typo in TYPEDEF: documentation --- core/alien/syntax/syntax-docs.factor | 10 ++++++---- 1 file changed, 6 insertions(+), 4 deletions(-) diff --git a/core/alien/syntax/syntax-docs.factor b/core/alien/syntax/syntax-docs.factor index 00ee6345dc..858c3f145e 100755 --- a/core/alien/syntax/syntax-docs.factor +++ b/core/alien/syntax/syntax-docs.factor @@ -49,14 +49,14 @@ $nl HELP: TYPEDEF: { $syntax "TYPEDEF: old new" } -{ $values { "word" "a word with stack effect " { $snippet "( -- ? )" } } { "old" "a C type" } { "new" "a C type" } } -{ $description "Alises the C type " { $snippet "old" } " under the name " { $snippet "new" } " if ." } +{ $values { "old" "a C type" } { "new" "a C type" } } +{ $description "Aliases the C type " { $snippet "old" } " under the name " { $snippet "new" } " if ." } { $notes "This word differs from " { $link typedef } " in that it runs at parse time, to ensure correct ordering of operations when loading source files. Words defined in source files are compiled before top-level forms are run, so if a source file defines C binding words and uses " { $link typedef } ", the type alias won't be available at compile time." } ; HELP: TYPEDEF-IF: { $syntax "TYPEDEF-IF: word old new" } { $values { "word" "a word with stack effect " { $snippet "( -- ? )" } } { "old" "a C type" } { "new" "a C type" } } -{ $description "Alises the C type " { $snippet "old" } " under the name " { $snippet "new" } " if " { $snippet "word" } " evaluates to a true value." } +{ $description "Aliases the C type " { $snippet "old" } " under the name " { $snippet "new" } " if " { $snippet "word" } " evaluates to a true value." } { $notes "This word differs from " { $link typedef } " in that it runs at parse time, to ensure correct ordering of operations when loading source files. Words defined in source files are compiled before top-level forms are run, so if a source file defines C binding words and uses " { $link typedef } ", the type alias won't be available at compile time." } ; HELP: C-STRUCT: @@ -87,7 +87,9 @@ HELP: typedef { $description "Alises the C type " { $snippet "old" } " under the name " { $snippet "new" } "." } { $notes "Using this word in the same source file which defines C bindings can cause problems, because words are compiled before top-level forms are run. Use the " { $link POSTPONE: TYPEDEF: } " word instead." } ; -{ typedef POSTPONE: TYPEDEF: } related-words +{ typedef POSTPONE: TYPEDEF: POSTPONE: TYPEDEF-IF: } related-words +{ POSTPONE: TYPEDEF: typedef POSTPONE: TYPEDEF-IF: } related-words +{ POSTPONE: TYPEDEF-IF: POSTPONE: TYPEDEF: typedef } related-words HELP: c-struct? { $values { "type" "a string" } { "?" "a boolean" } } From 9c78c7c05f61958c460f79254609d27f24d65cbd Mon Sep 17 00:00:00 2001 From: Aaron Schaefer Date: Thu, 17 Jan 2008 12:25:43 -0500 Subject: [PATCH 12/30] Solution to Project Euler problem 27 --- extra/project-euler/004/004.factor | 5 +- extra/project-euler/027/027.factor | 67 ++++++++++++++++++++++++ extra/project-euler/common/common.factor | 8 ++- extra/project-euler/project-euler.factor | 4 +- 4 files changed, 76 insertions(+), 8 deletions(-) create mode 100644 extra/project-euler/027/027.factor diff --git a/extra/project-euler/004/004.factor b/extra/project-euler/004/004.factor index 0db0c6f2cb..d7984a4991 100644 --- a/extra/project-euler/004/004.factor +++ b/extra/project-euler/004/004.factor @@ -1,6 +1,6 @@ ! Copyright (c) 2007 Aaron Schaefer, Daniel Ehrenberg. ! See http://factorcode.org/license.txt for BSD license. -USING: arrays combinators.lib hashtables kernel math math.parser math.ranges +USING: hashtables kernel math math.parser math.ranges project-euler.common sequences sorting ; IN: project-euler.004 @@ -21,9 +21,6 @@ IN: project-euler.004 : palindrome? ( n -- ? ) number>string dup reverse = ; -: cartesian-product ( seq1 seq2 -- seq1xseq2 ) - swap [ swap [ 2array ] map-with ] map-with concat ; - + +: euler027 ( -- answer ) + source-027 max-consecutive drop product ; + +! [ euler027 ] 100 ave-time +! 1306 ms run / 58 ms GC ave time - 100 trials + +! TODO: generalize max-consecutive/max-product (from #26) into a new word + +MAIN: euler027 diff --git a/extra/project-euler/common/common.factor b/extra/project-euler/common/common.factor index 2bd2b7ec0b..d21a780773 100644 --- a/extra/project-euler/common/common.factor +++ b/extra/project-euler/common/common.factor @@ -1,5 +1,5 @@ -USING: kernel math math.functions math.miller-rabin math.parser - math.primes.factors math.ranges namespaces sequences ; +USING: arrays combinators.lib kernel math math.functions math.miller-rabin + math.parser math.primes.factors math.ranges namespaces sequences ; IN: project-euler.common ! A collection of words used by more than one Project Euler solution @@ -7,6 +7,7 @@ IN: project-euler.common ! Problems using each public word ! ------------------------------- +! cartesian-product - #4, #27 ! collect-consecutive - #8, #11 ! log10 - #25, #134 ! max-path - #18, #67 @@ -45,6 +46,9 @@ IN: project-euler.common PRIVATE> +: cartesian-product ( seq1 seq2 -- seq1xseq2 ) + swap [ swap [ 2array ] map-with ] map-with concat ; + : collect-consecutive ( seq width -- seq ) [ 2dup count-shifts [ 2dup head shift-3rd , ] times diff --git a/extra/project-euler/project-euler.factor b/extra/project-euler/project-euler.factor index 6abb056d28..8ff3b9da88 100644 --- a/extra/project-euler/project-euler.factor +++ b/extra/project-euler/project-euler.factor @@ -8,8 +8,8 @@ USING: definitions io io.files kernel math.parser sequences vocabs project-euler.013 project-euler.014 project-euler.015 project-euler.016 project-euler.017 project-euler.018 project-euler.019 project-euler.020 project-euler.021 project-euler.022 project-euler.023 project-euler.024 - project-euler.025 project-euler.026 project-euler.067 project-euler.134 - project-euler.169 project-euler.173 project-euler.175 ; + project-euler.025 project-euler.026 project-euler.027 project-euler.067 + project-euler.134 project-euler.169 project-euler.173 project-euler.175 ; IN: project-euler Date: Thu, 17 Jan 2008 12:55:02 -0500 Subject: [PATCH 13/30] Optimize solution to Project Euler problem 27 --- extra/project-euler/027/027.factor | 9 +++++++-- 1 file changed, 7 insertions(+), 2 deletions(-) diff --git a/extra/project-euler/027/027.factor b/extra/project-euler/027/027.factor index abfe4d5704..3ce684549a 100644 --- a/extra/project-euler/027/027.factor +++ b/extra/project-euler/027/027.factor @@ -36,10 +36,15 @@ IN: project-euler.027 ! SOLUTION ! -------- +! b must be prime since n = 0 must return a prime +! a + b + 1 must be prime since n = 1 must return a prime +! a < b + source-027 max-consecutive drop product ; ! [ euler027 ] 100 ave-time -! 1306 ms run / 58 ms GC ave time - 100 trials +! 687 ms run / 23 ms GC ave time - 100 trials ! TODO: generalize max-consecutive/max-product (from #26) into a new word From 4cba26462df7ebeda53926dc31b8ef07af056a51 Mon Sep 17 00:00:00 2001 From: Aaron Schaefer Date: Thu, 17 Jan 2008 23:37:10 -0500 Subject: [PATCH 14/30] Solution to Project Euler problem 28 --- extra/project-euler/027/027.factor | 5 +- extra/project-euler/028/028.factor | 61 ++++++++++++++++++++++++ extra/project-euler/project-euler.factor | 5 +- 3 files changed, 68 insertions(+), 3 deletions(-) create mode 100644 extra/project-euler/028/028.factor diff --git a/extra/project-euler/027/027.factor b/extra/project-euler/027/027.factor index 3ce684549a..c208caaf9e 100644 --- a/extra/project-euler/027/027.factor +++ b/extra/project-euler/027/027.factor @@ -38,7 +38,10 @@ IN: project-euler.027 ! b must be prime since n = 0 must return a prime ! a + b + 1 must be prime since n = 1 must return a prime -! a < b +! 1 - a + b must be prime as well, hence >= 2. Therefore: +! 1 - a + b >= 2 +! b - a >= 1 +! a < b (2n + 1)² from 0 .. n +! se -> (4 * n²) - (10 * n) + 7 from 1 .. n +! sw -> (4 * n²) + 1 from 0 .. n +! nw -> (4 * n²) - (6 * n) + 3 from 1 .. n + + + +: euler028 ( -- answer ) + 1001 spiral-diags ; + +! [ euler027 ] 100 ave-time +! 0 ms run / 0 ms GC ave time - 100 trials + +MAIN: euler028 diff --git a/extra/project-euler/project-euler.factor b/extra/project-euler/project-euler.factor index 8ff3b9da88..812a010042 100644 --- a/extra/project-euler/project-euler.factor +++ b/extra/project-euler/project-euler.factor @@ -8,8 +8,9 @@ USING: definitions io io.files kernel math.parser sequences vocabs project-euler.013 project-euler.014 project-euler.015 project-euler.016 project-euler.017 project-euler.018 project-euler.019 project-euler.020 project-euler.021 project-euler.022 project-euler.023 project-euler.024 - project-euler.025 project-euler.026 project-euler.027 project-euler.067 - project-euler.134 project-euler.169 project-euler.173 project-euler.175 ; + project-euler.025 project-euler.026 project-euler.027 project-euler.028 + project-euler.067 project-euler.134 project-euler.169 project-euler.173 + project-euler.175 ; IN: project-euler Date: Fri, 18 Jan 2008 00:43:15 -0500 Subject: [PATCH 15/30] Optimize solution to Project Euler problem 28 --- extra/project-euler/028/028.factor | 27 ++++++--------------------- 1 file changed, 6 insertions(+), 21 deletions(-) diff --git a/extra/project-euler/028/028.factor b/extra/project-euler/028/028.factor index 33d87ea451..29a864e2a0 100644 --- a/extra/project-euler/028/028.factor +++ b/extra/project-euler/028/028.factor @@ -25,35 +25,20 @@ IN: project-euler.028 ! SOLUTION ! -------- -! Noticed patterns in the diagnoal numbers starting from the origin going to -! the corners and used these instead of generating the entire spiral: -! ne -> (2n + 1)² from 0 .. n -! se -> (4 * n²) - (10 * n) + 7 from 1 .. n -! sw -> (4 * n²) + 1 from 0 .. n -! nw -> (4 * n²) - (6 * n) + 3 from 1 .. n +! For a square sized n by n, the sum of corners is 4n² - 6n + 6 [ sum-corners ] sigma ; PRIVATE> : euler028 ( -- answer ) - 1001 spiral-diags ; + 1001 sum-diags ; ! [ euler027 ] 100 ave-time ! 0 ms run / 0 ms GC ave time - 100 trials From a3dd5cb1e63f8c02068a32a655b9de4e6af1079a Mon Sep 17 00:00:00 2001 From: Aaron Schaefer Date: Fri, 18 Jan 2008 01:24:55 -0500 Subject: [PATCH 16/30] Solution to Project Euler problem 29 --- extra/project-euler/028/028.factor | 2 +- extra/project-euler/029/029.factor | 37 ++++++++++++++++++++++++ extra/project-euler/project-euler.factor | 4 +-- 3 files changed, 40 insertions(+), 3 deletions(-) create mode 100644 extra/project-euler/029/029.factor diff --git a/extra/project-euler/028/028.factor b/extra/project-euler/028/028.factor index 29a864e2a0..5d20032ea9 100644 --- a/extra/project-euler/028/028.factor +++ b/extra/project-euler/028/028.factor @@ -40,7 +40,7 @@ PRIVATE> : euler028 ( -- answer ) 1001 sum-diags ; -! [ euler027 ] 100 ave-time +! [ euler028 ] 100 ave-time ! 0 ms run / 0 ms GC ave time - 100 trials MAIN: euler028 diff --git a/extra/project-euler/029/029.factor b/extra/project-euler/029/029.factor new file mode 100644 index 0000000000..47855c0bf1 --- /dev/null +++ b/extra/project-euler/029/029.factor @@ -0,0 +1,37 @@ +! Copyright (c) 2007 Aaron Schaefer. +! See http://factorcode.org/license.txt for BSD license. +USING: hashtables kernel math.functions math.ranges project-euler.common + sequences ; +IN: project-euler.029 + +! http://projecteuler.net/index.php?section=problems&id=29 + +! DESCRIPTION +! ----------- + +! Consider all integer combinations of a^b for 2 ≤ a ≤ 5 and 2 ≤ b ≤ 5: + +! 2^2 = 4, 2^3 = 8, 2^4 = 16, 2^5 = 32 +! 3^2 = 9, 3^3 = 27, 3^4 = 81, 3^5 = 243 +! 4^2 = 16, 4^3 = 64, 4^4 = 256, 4^5 = 1024 +! 5^2 = 25, 5^3 = 125, 5^4 = 625, 5^5 = 3125 + +! If they are then placed in numerical order, with any repeats removed, we get +! the following sequence of 15 distinct terms: + +! 4, 8, 9, 16, 25, 27, 32, 64, 81, 125, 243, 256, 625, 1024, 3125 + +! How many distinct terms are in the sequence generated by a^b for 2 ≤ a ≤ 100 +! and 2 ≤ b ≤ 100? + + +! SOLUTION +! -------- + +: euler029 ( -- answer ) + 2 100 [a,b] dup cartesian-product [ first2 ^ ] map prune length ; + +! [ euler029 ] 100 ave-time +! 951 ms run / 12 ms GC ave time - 100 trials + +MAIN: euler029 diff --git a/extra/project-euler/project-euler.factor b/extra/project-euler/project-euler.factor index 812a010042..513eeba020 100644 --- a/extra/project-euler/project-euler.factor +++ b/extra/project-euler/project-euler.factor @@ -9,8 +9,8 @@ USING: definitions io io.files kernel math.parser sequences vocabs project-euler.017 project-euler.018 project-euler.019 project-euler.020 project-euler.021 project-euler.022 project-euler.023 project-euler.024 project-euler.025 project-euler.026 project-euler.027 project-euler.028 - project-euler.067 project-euler.134 project-euler.169 project-euler.173 - project-euler.175 ; + project-euler.029 project-euler.067 project-euler.134 project-euler.169 + project-euler.173 project-euler.175 ; IN: project-euler Date: Thu, 17 Jan 2008 23:06:32 -0800 Subject: [PATCH 17/30] Remove USE-IF: again --- core/syntax/syntax-docs.factor | 6 ------ core/syntax/syntax.factor | 1 - extra/opengl/gl/gl.factor | 5 ++--- 3 files changed, 2 insertions(+), 10 deletions(-) diff --git a/core/syntax/syntax-docs.factor b/core/syntax/syntax-docs.factor index f4efc3b6bb..9cf9647e41 100755 --- a/core/syntax/syntax-docs.factor +++ b/core/syntax/syntax-docs.factor @@ -363,12 +363,6 @@ HELP: USE: { $description "Adds a new vocabulary at the front of the search path. Subsequent word lookups by the parser will search this vocabulary first." } { $errors "Throws an error if the vocabulary does not exist." } ; -HELP: USE-IF: -{ $syntax "USE-IF: word vocabulary" } -{ $values { "word" "a word with stack effect " { $snippet "( -- ? )" } } { "vocabulary" "a vocabulary name" } } -{ $description "Adds " { $snippet "vocabulary" } " at the front of the search path if " { $snippet "word" } " evaluates to a true value." } -{ $errors "Throws an error if the vocabulary does not exist." } ; - HELP: USING: { $syntax "USING: vocabularies... ;" } { $values { "vocabularies" "a list of vocabulary names" } } diff --git a/core/syntax/syntax.factor b/core/syntax/syntax.factor index de627358e4..7616f6e64b 100755 --- a/core/syntax/syntax.factor +++ b/core/syntax/syntax.factor @@ -46,7 +46,6 @@ IN: bootstrap.syntax ] define-syntax "USE:" [ scan use+ ] define-syntax - "USE-IF:" [ scan-word execute scan swap [ use+ ] [ drop ] if ] define-syntax "USING:" [ ";" parse-tokens add-use ] define-syntax diff --git a/extra/opengl/gl/gl.factor b/extra/opengl/gl/gl.factor index 4a9d9c84d5..071fbc45e7 100644 --- a/extra/opengl/gl/gl.factor +++ b/extra/opengl/gl/gl.factor @@ -3,9 +3,8 @@ ! This file is based on the gl.h that comes with xorg-x11 6.8.2 -USING: alien alien.syntax kernel sequences system words ; -USE-IF: windows? opengl.gl.windows -USE-IF: unix? opengl.gl.unix +USING: alien alien.syntax kernel parser sequences system words ; +<< windows? "opengl.gl.windows" "opengl.gl.unix" ? use+ >> IN: opengl.gl From 15fa72da9c3c3e1e12f0fa3a2112300c93393c7b Mon Sep 17 00:00:00 2001 From: Slava Pestov Date: Fri, 18 Jan 2008 02:39:24 -0500 Subject: [PATCH 18/30] No point having get/set-global inline --- core/namespaces/namespaces.factor | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/core/namespaces/namespaces.factor b/core/namespaces/namespaces.factor index bac6895b62..3d3d3c554b 100644 --- a/core/namespaces/namespaces.factor +++ b/core/namespaces/namespaces.factor @@ -15,16 +15,16 @@ IN: namespaces PRIVATE> : namespace ( -- namespace ) namestack* peek ; -: namestack ( -- namestack ) namestack* clone ; inline -: set-namestack ( namestack -- ) >vector 0 setenv ; inline +: namestack ( -- namestack ) namestack* clone ; +: set-namestack ( namestack -- ) >vector 0 setenv ; : global ( -- g ) 21 getenv { hashtable } declare ; inline : init-namespaces ( -- ) global 1array set-namestack ; : get ( variable -- value ) namestack* assoc-stack ; flushable : set ( value variable -- ) namespace set-at ; : on ( variable -- ) t swap set ; inline : off ( variable -- ) f swap set ; inline -: get-global ( variable -- value ) global at ; inline -: set-global ( value variable -- ) global set-at ; inline +: get-global ( variable -- value ) global at ; +: set-global ( value variable -- ) global set-at ; : change ( variable quot -- ) >r dup get r> rot slip set ; inline From 423b0c469745f88c6641b75ac995261cc5e11eba Mon Sep 17 00:00:00 2001 From: Slava Pestov Date: Fri, 18 Jan 2008 17:09:30 -0500 Subject: [PATCH 19/30] Remove useless optimization --- core/cpu/architecture/architecture.factor | 10 ++-------- core/cpu/ppc/architecture/architecture.factor | 14 +------------- core/cpu/x86/architecture/architecture.factor | 10 +--------- core/generator/generator.factor | 17 +++-------------- 4 files changed, 7 insertions(+), 44 deletions(-) diff --git a/core/cpu/architecture/architecture.factor b/core/cpu/architecture/architecture.factor index e48ba97f33..4da22ff38a 100755 --- a/core/cpu/architecture/architecture.factor +++ b/core/cpu/architecture/architecture.factor @@ -51,14 +51,8 @@ HOOK: %save-dispatch-xt compiler-backend ( -- ) M: object %save-dispatch-xt %save-word-xt ; -! Call C primitive -HOOK: %call-primitive compiler-backend ( label -- ) - -! Call another label -HOOK: %call-label compiler-backend ( label -- ) - -! Far jump to C primitive -HOOK: %jump-primitive compiler-backend ( label -- ) +! Call another word +HOOK: %call compiler-backend ( word -- ) ! Local jump for branches HOOK: %jump-label compiler-backend ( label -- ) diff --git a/core/cpu/ppc/architecture/architecture.factor b/core/cpu/ppc/architecture/architecture.factor index edbed571e1..7444c21a8c 100755 --- a/core/cpu/ppc/architecture/architecture.factor +++ b/core/cpu/ppc/architecture/architecture.factor @@ -97,26 +97,14 @@ M: ppc-backend %epilogue ( n -- ) 1 1 rot ADDI 0 MTLR ; -: %prepare-primitive ( word -- ) - #! Save stack pointer to stack_chain->callstack_top, load XT - 4 1 MR - 0 11 LOAD32 - rc-absolute-ppc-2/2 rel-primitive ; - : (%call) 11 MTLR BLRL ; -M: ppc-backend %call-primitive ( word -- ) - %prepare-primitive (%call) ; - : (%jump) 11 MTCTR BCTR ; -M: ppc-backend %jump-primitive ( word -- ) - %prepare-primitive (%jump) ; - : %load-dlsym ( symbol dll register -- ) 0 swap LOAD32 rc-absolute-ppc-2/2 rel-dlsym ; -M: ppc-backend %call-label ( label -- ) BL ; +M: ppc-backend %call ( label -- ) BL ; M: ppc-backend %jump-label ( label -- ) B ; diff --git a/core/cpu/x86/architecture/architecture.factor b/core/cpu/x86/architecture/architecture.factor index 876c631b81..8c5d5c1dc0 100755 --- a/core/cpu/x86/architecture/architecture.factor +++ b/core/cpu/x86/architecture/architecture.factor @@ -70,15 +70,7 @@ M: x86-backend %prepare-alien-invoke temp-reg v>operand 2 cells [+] ds-reg MOV temp-reg v>operand 3 cells [+] rs-reg MOV ; -M: x86-backend %call-primitive ( word -- ) - stack-save-reg stack-reg cell neg [+] LEA - address-operand CALL ; - -M: x86-backend %jump-primitive ( word -- ) - stack-save-reg stack-reg MOV - address-operand JMP ; - -M: x86-backend %call-label ( label -- ) CALL ; +M: x86-backend %call ( label -- ) CALL ; M: x86-backend %jump-label ( label -- ) JMP ; diff --git a/core/generator/generator.factor b/core/generator/generator.factor index df01f9e490..0e499cf90f 100755 --- a/core/generator/generator.factor +++ b/core/generator/generator.factor @@ -100,21 +100,10 @@ UNION: #terminal ! node M: node generate-node drop iterate-next ; -: %call ( word -- ) - dup primitive? [ %call-primitive ] [ %call-label ] if ; - : %jump ( word -- ) - { - { [ dup compiling-label get eq? ] [ - drop current-label-start get %jump-label - ] } - { [ dup primitive? ] [ - %epilogue-later %jump-primitive - ] } - { [ t ] [ - %epilogue-later %jump-label - ] } - } cond ; + dup compiling-label get eq? + [ drop current-label-start get ] [ %epilogue-later ] if + %jump-label ; : generate-call ( label -- next ) dup maybe-compile From 011681f07ab08c0425e398bda93000f6fca3aef2 Mon Sep 17 00:00:00 2001 From: Slava Pestov Date: Fri, 18 Jan 2008 17:09:45 -0500 Subject: [PATCH 20/30] Fix construct-empty transform --- .../transforms/transforms-tests.factor | 4 ++- core/inference/transforms/transforms.factor | 26 +++++++++++++------ 2 files changed, 21 insertions(+), 9 deletions(-) diff --git a/core/inference/transforms/transforms-tests.factor b/core/inference/transforms/transforms-tests.factor index 6dc5bcabcd..9a62a1faca 100644 --- a/core/inference/transforms/transforms-tests.factor +++ b/core/inference/transforms/transforms-tests.factor @@ -1,6 +1,6 @@ IN: temporary USING: sequences inference.transforms tools.test math kernel -quotations ; +quotations tools.test.inference ; : compose-n-quot >quotation ; : compose-n compose-n-quot call ; @@ -18,3 +18,5 @@ quotations ; [ 268 ] [ 1 { 8 { 3 2 } } bitfield-quot call ] unit-test [ 512 ] [ 1 { { 1+ 8 } } bitfield-quot call ] unit-test + +\ construct-empty must-infer diff --git a/core/inference/transforms/transforms.factor b/core/inference/transforms/transforms.factor index 62c3129f3a..eabe4b8c2a 100755 --- a/core/inference/transforms/transforms.factor +++ b/core/inference/transforms/transforms.factor @@ -1,8 +1,8 @@ -! Copyright (C) 2007 Slava Pestov. +! Copyright (C) 2007, 2008 Slava Pestov. ! See http://factorcode.org/license.txt for BSD license. USING: arrays kernel words sequences generic math namespaces quotations assocs combinators math.bitfields inference.backend -inference.dataflow inference.state tuples.private ; +inference.dataflow inference.state tuples.private effects ; IN: inference.transforms : pop-literals ( n -- rstate seq ) @@ -61,11 +61,21 @@ M: pair (bitfield-quot) ( spec -- quot ) \ set-slots [ [get-slots] ] 1 define-transform -: [construct] ( word quot -- newquot ) - >r dup +inlined+ depends-on dup tuple-size r> 2curry ; +\ construct-boa [ + dup +inlined+ depends-on + dup tuple-size [ ] 2curry +] 1 define-transform -\ construct-boa -[ [ ] [construct] ] 1 define-transform +\ construct-empty [ + 1 ensure-values + peek-d value? [ + pop-literal + dup +inlined+ depends-on + dup tuple-size [ ] 2curry + swap infer-quot + ] [ + \ construct-empty declared-infer + ] if +] "infer" set-word-prop -\ construct-empty -[ [ ] [construct] ] 1 define-transform +\ construct-empty 1 1 "inferred-effect" set-word-prop From 30dec8b0a886eea7e9f833d3eda019ec3750f3e3 Mon Sep 17 00:00:00 2001 From: Slava Pestov Date: Fri, 18 Jan 2008 17:09:55 -0500 Subject: [PATCH 21/30] Fix documentation typos --- core/kernel/kernel-docs.factor | 2 +- extra/io/launcher/launcher-docs.factor | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/core/kernel/kernel-docs.factor b/core/kernel/kernel-docs.factor index 8f0e4efbd9..2301216394 100755 --- a/core/kernel/kernel-docs.factor +++ b/core/kernel/kernel-docs.factor @@ -557,7 +557,7 @@ HELP: dip HELP: while { $values { "pred" "a quotation with stack effect " { $snippet "( -- ? )" } } { "body" "a quotation" } { "tail" "a quotation" } } -{ $description "Repeatedly calls " { $snippet "pred" } ". If it yields " { $link f } ", iteration stops, otherwise " { $snippet "quot" } " is called. After iteration stops, " { $snippet "tail" } " is called." } +{ $description "Repeatedly calls " { $snippet "pred" } ". If it yields " { $link f } ", iteration stops, otherwise " { $snippet "body" } " is called. After iteration stops, " { $snippet "tail" } " is called." } { $notes "In most cases, tail recursion should be used, because it is simpler both in terms of implementation and conceptually. However in some cases this combinator expresses intent better and should be used." $nl "Strictly speaking, the " { $snippet "tail" } " is not necessary, since the following are equivalent:" diff --git a/extra/io/launcher/launcher-docs.factor b/extra/io/launcher/launcher-docs.factor index 99f318eaf4..7ad5e064bf 100755 --- a/extra/io/launcher/launcher-docs.factor +++ b/extra/io/launcher/launcher-docs.factor @@ -85,7 +85,7 @@ HELP: run-detached HELP: { $values { "obj" object } { "stream" "a bidirectional stream" } } -{ $description "Launches a process and redirects its input and output via a paper of pipes which may be read and written as a stream." } +{ $description "Launches a process and redirects its input and output via a pair of pipes which may be read and written as a stream." } { $notes "Closing the stream will block until the process exits." } ; { run-process run-detached } related-words From 5c388404d6e061a1d6b4894e12560b010fe5b2f1 Mon Sep 17 00:00:00 2001 From: Slava Pestov Date: Fri, 18 Jan 2008 17:10:08 -0500 Subject: [PATCH 22/30] Fix sha1 --- extra/benchmark/sha1/sha1.factor | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/extra/benchmark/sha1/sha1.factor b/extra/benchmark/sha1/sha1.factor index 614077c673..897d83ea0e 100644 --- a/extra/benchmark/sha1/sha1.factor +++ b/extra/benchmark/sha1/sha1.factor @@ -1,7 +1,7 @@ USING: crypto.sha1 io.files kernel ; IN: benchmark.sha1 -: sha1-primes-list ( -- seq ) - "extra/math/primes/list/list.factor" resource-path file>sha1 ; +: sha1-primes-list ( -- ) + "extra/math/primes/list/list.factor" resource-path file>sha1 drop ; MAIN: sha1-primes-list From 588253dfe3f9c042c1522b2b8174236b63f6ad97 Mon Sep 17 00:00:00 2001 From: Slava Pestov Date: Fri, 18 Jan 2008 18:18:54 -0500 Subject: [PATCH 23/30] Cleaning up Unix I/O --- extra/io/unix/backend/backend.factor | 127 +++++++++------------ extra/io/unix/backend/select/select.factor | 53 +++++++++ extra/io/unix/sockets/sockets.factor | 20 ++-- extra/unix/kqueue/kqueue.factor | 73 ++++++++++++ 4 files changed, 188 insertions(+), 85 deletions(-) create mode 100644 extra/io/unix/backend/select/select.factor create mode 100644 extra/unix/kqueue/kqueue.factor diff --git a/extra/io/unix/backend/backend.factor b/extra/io/unix/backend/backend.factor index 3522a2218b..ec73a5395e 100755 --- a/extra/io/unix/backend/backend.factor +++ b/extra/io/unix/backend/backend.factor @@ -1,21 +1,24 @@ -! Copyright (C) 2004, 2007 Slava Pestov. +! Copyright (C) 2004, 2008 Slava Pestov. ! See http://factorcode.org/license.txt for BSD license. -USING: alien bit-arrays generic assocs io kernel -kernel.private math io.nonblocking sequences strings structs -sbufs threads unix vectors io.buffers io.backend -io.streams.duplex math.parser continuations system libc ; +USING: alien generic assocs kernel kernel.private math +io.nonblocking sequences strings structs sbufs threads unix +vectors io.buffers io.backend io.streams.duplex math.parser +continuations system libc qualified namespaces ; +QUALIFIED: io IN: io.unix.backend +! Multiplexer protocol +SYMBOL: unix-io-backend + +HOOK: init-unix-io unix-io-backend ( -- ) +HOOK: register-io-task unix-io-backend ( task -- ) +HOOK: unregister-io-task unix-io-backend ( task -- ) +HOOK: unix-io-multiplex unix-io-backend ( timeval -- ) + TUPLE: unix-io ; -! We want namespaces::bind to shadow the bind system call from -! unix -USING: namespaces ; - ! Global variables -SYMBOL: read-fdset SYMBOL: read-tasks -SYMBOL: write-fdset SYMBOL: write-tasks ! Some general stuff @@ -53,9 +56,9 @@ M: integer close-handle ( fd -- ) ! port to finish I/O TUPLE: io-task port callbacks ; -: ( port class -- task ) - >r V{ } clone io-task construct-boa - { set-delegate } r> construct ; inline +: ( port continuation class -- task ) + >r 1vector io-task construct-boa r> construct-delegate ; + inline ! Multiplexer GENERIC: do-io-task ( task -- ? ) @@ -63,58 +66,30 @@ GENERIC: task-container ( task -- vector ) : io-task-fd io-task-port port-handle ; -: add-io-task ( callback task -- ) - [ io-task-callbacks push ] keep - dup io-task-fd over task-container 2dup at [ +: check-io-task ( task -- ) + dup io-task-fd swap task-container at [ "Cannot perform multiple reads from the same port" throw - ] when set-at ; + ] when ; + +: add-io-task ( task -- ) + dup check-io-task + dup register-io-task + dup io-task-fd over task-container set-at ; : remove-io-task ( task -- ) - dup io-task-fd swap task-container delete-at ; + dup io-task-fd over task-container delete-at + unregister-io-task ; : pop-callbacks ( task -- ) - dup io-task-callbacks swap remove-io-task - [ schedule-thread ] each ; + dup remove-io-task + io-task-callbacks [ schedule-thread ] each ; : handle-fd ( task -- ) dup io-task-port touch-port dup do-io-task [ pop-callbacks ] [ drop ] if ; -: handle-fdset ( fdset tasks -- ) - swap [ - swap dup io-task-port timeout? [ - dup io-task-port "Timeout" swap report-error - nip pop-callbacks - ] [ - tuck io-task-fd swap nth - [ handle-fd ] [ drop ] if - ] if drop - ] curry assoc-each ; - -: init-fdset ( fdset tasks -- ) - swap dup clear-bits - [ >r drop t swap r> set-nth ] curry assoc-each ; - -: read-fdset/tasks - read-fdset get-global read-tasks get-global ; - -: write-fdset/tasks - write-fdset get-global write-tasks get-global ; - -: init-fdsets ( -- read write except ) - read-fdset/tasks dupd init-fdset - write-fdset/tasks dupd init-fdset - f ; - -: (io-multiplex) ( ms -- ) - >r FD_SETSIZE init-fdsets r> make-timeval select 0 < [ - err_no ignorable-error? [ (io-error) ] unless - ] when ; - -M: unix-io io-multiplex ( ms -- ) - (io-multiplex) - read-fdset/tasks handle-fdset - write-fdset/tasks handle-fdset ; +: handle-timeout ( task -- ) + "Timeout" over io-task-port report-error pop-callbacks ; ! Readers : reader-eof ( reader -- ) @@ -137,17 +112,18 @@ M: unix-io io-multiplex ( ms -- ) TUPLE: read-task ; -: ( port -- task ) read-task ; +: ( port continuation -- task ) + read-task ; M: read-task do-io-task io-task-port dup refill [ [ reader-eof ] [ drop ] if ] keep ; -M: read-task task-container drop read-tasks get-global ; +M: read-task task-container + drop read-tasks get-global ; M: input-port (wait-to-read) - [ swap add-io-task stop ] callcc0 - pending-error ; + [ add-io-task stop ] callcc0 pending-error ; ! Writers : write-step ( port -- ? ) @@ -156,35 +132,34 @@ M: input-port (wait-to-read) TUPLE: write-task ; -: ( port -- task ) write-task ; +: ( port continuation -- task ) + write-task ; M: write-task do-io-task io-task-port dup buffer-empty? over port-error or [ 0 swap buffer-reset t ] [ write-step ] if ; -M: write-task task-container drop write-tasks get-global ; +M: write-task task-container + drop write-tasks get-global ; -: add-write-io-task ( callback task -- ) - dup io-task-fd write-tasks get-global at - [ io-task-callbacks push ] [ add-io-task ] ?if ; +: add-write-io-task ( port continuation -- ) + over port-handle write-tasks get-global at + [ io-task-callbacks push drop ] + [ add-io-task ] if* ; : (wait-to-write) ( port -- ) - [ swap add-write-io-task stop ] callcc0 drop ; + [ add-write-io-task stop ] callcc0 drop ; M: port port-flush ( port -- ) dup buffer-empty? [ drop ] [ (wait-to-write) ] if ; -USE: io +M: unix-io io-multiplex ( ms -- ) + make-timeval unix-io-multiplex ; M: unix-io init-io ( -- ) - #! Should only be called on startup. Calling this at any - #! other time can have unintended consequences. - global [ - H{ } clone read-tasks set - FD_SETSIZE 8 * read-fdset set - H{ } clone write-tasks set - FD_SETSIZE 8 * write-fdset set - ] bind ; + H{ } clone read-tasks set-global + H{ } clone write-tasks set-global + init-unix-io ; M: unix-io init-stdio ( -- ) - 0 1 handle>duplex-stream stdio set-global ; + 0 1 handle>duplex-stream io:stdio set-global ; diff --git a/extra/io/unix/backend/select/select.factor b/extra/io/unix/backend/select/select.factor new file mode 100644 index 0000000000..255010bff6 --- /dev/null +++ b/extra/io/unix/backend/select/select.factor @@ -0,0 +1,53 @@ +! Copyright (C) 2004, 2008 Slava Pestov. +! See http://factorcode.org/license.txt for BSD license. +USING: alien.syntax kernel io.nonblocking io.unix.backend +bit-arrays sequences assocs unix math namespaces ; +IN: io.unix.backend.select + +TUPLE: unix-select-io ; + +! Global variables +SYMBOL: read-fdset +SYMBOL: write-fdset + +M: unix-select-io init-unix-io ( -- ) + FD_SETSIZE 8 * read-fdset set-global + FD_SETSIZE 8 * write-fdset set-global ; + +: handle-fdset ( fdset tasks -- ) + swap [ + swap dup io-task-port timeout? [ + nip handle-timeout + ] [ + tuck io-task-fd swap nth + [ handle-fd ] [ drop ] if + ] if drop + ] curry assoc-each ; + +: init-fdset ( fdset tasks -- ) + swap dup clear-bits + [ >r drop t swap r> set-nth ] curry assoc-each ; + +: read-fdset/tasks + read-fdset get-global read-tasks get-global ; + +: write-fdset/tasks + write-fdset get-global write-tasks get-global ; + +: init-fdsets ( -- read write except ) + read-fdset/tasks dupd init-fdset + write-fdset/tasks dupd init-fdset + f ; + +M: unix-select-io register-io-task ( task -- ) drop ; + +M: unix-select-io unregister-io-task ( task -- ) drop ; + +M: unix-select-io unix-io-multiplex ( timeval -- ) + >r FD_SETSIZE init-fdsets r> select 0 < [ + err_no ignorable-error? [ (io-error) ] unless + ] when + read-fdset/tasks handle-fdset + write-fdset/tasks handle-fdset ; + +T{ unix-select-io } unix-io-backend set-global diff --git a/extra/io/unix/sockets/sockets.factor b/extra/io/unix/sockets/sockets.factor index 0787a1afde..30d3bbd94c 100644 --- a/extra/io/unix/sockets/sockets.factor +++ b/extra/io/unix/sockets/sockets.factor @@ -33,7 +33,8 @@ M: unix-io addrinfo-error ( n -- ) TUPLE: connect-task ; -: ( port -- task ) connect-task ; +: ( port continuation -- task ) + connect-task ; M: connect-task do-io-task io-task-port dup port-handle f 0 write @@ -42,7 +43,7 @@ M: connect-task do-io-task M: connect-task task-container drop write-tasks get-global ; : wait-to-connect ( port -- ) - [ swap add-io-task stop ] callcc0 drop ; + [ add-io-task stop ] callcc0 drop ; M: unix-io (client) ( addrspec -- stream ) dup make-sockaddr/size >r >r @@ -66,7 +67,8 @@ USE: unix TUPLE: accept-task ; -: ( port -- task ) accept-task ; +: ( port continuation -- task ) + accept-task ; M: accept-task task-container drop read-tasks get ; @@ -85,7 +87,7 @@ M: accept-task do-io-task over 0 >= [ do-accept t ] [ 2drop defer-error ] if ; : wait-to-accept ( server -- ) - [ swap add-io-task stop ] callcc0 drop ; + [ add-io-task stop ] callcc0 drop ; USE: io.sockets @@ -136,7 +138,8 @@ packet-size receive-buffer set-global TUPLE: receive-task ; -: ( stream -- task ) receive-task ; +: ( stream continuation -- task ) + receive-task ; M: receive-task do-io-task io-task-port @@ -152,7 +155,7 @@ M: receive-task do-io-task M: receive-task task-container drop read-tasks get ; : wait-receive ( stream -- ) - [ swap add-io-task stop ] callcc0 drop ; + [ add-io-task stop ] callcc0 drop ; M: unix-io receive ( datagram -- packet addrspec ) dup check-datagram-port @@ -166,7 +169,7 @@ M: unix-io receive ( datagram -- packet addrspec ) TUPLE: send-task packet sockaddr len ; -: ( packet sockaddr len port -- task ) +: ( packet sockaddr len stream continuation -- task ) send-task [ { set-send-task-packet @@ -185,8 +188,7 @@ M: send-task do-io-task M: send-task task-container drop write-tasks get ; : wait-send ( packet sockaddr len stream -- ) - [ >r r> swap add-io-task stop ] callcc0 - 2drop 2drop ; + [ add-io-task stop ] callcc0 2drop 2drop ; M: unix-io send ( packet addrspec datagram -- ) 3dup check-datagram-send diff --git a/extra/unix/kqueue/kqueue.factor b/extra/unix/kqueue/kqueue.factor new file mode 100644 index 0000000000..4e6504470d --- /dev/null +++ b/extra/unix/kqueue/kqueue.factor @@ -0,0 +1,73 @@ +! Copyright (C) 2008 Slava Pestov. +! See http://factorcode.org/license.txt for BSD license. +USING: alien.syntax ; +IN: unix.kqueue + +FUNCTION: int kqueue ( ) ; + +FUNCTION: int kevent ( int kq, kevent* changelist, int nchanges, kevent* eventlist, int nevents, timespec* timeout ) ; + +C-STRUCT: kevent + { "ulong" "ident" } ! identifier for this event + { "short" "filter" } ! filter for event + { "ushort" "flags" } ! action flags for kqueue + { "uint" "fflags" } ! filter flag value + { "long" "data" } ! filter data value + { "void*" "udata" } ! opaque user data identifier +; + +: EVFILT_READ -1 ; inline +: EVFILT_WRITE -2 ; inline +: EVFILT_AIO -3 ; inline ! attached to aio requests +: EVFILT_VNODE -4 ; inline ! attached to vnodes +: EVFILT_PROC -5 ; inline ! attached to struct proc +: EVFILT_SIGNAL -6 ; inline ! attached to struct proc +: EVFILT_TIMER -7 ; inline ! timers +: EVFILT_MACHPORT -8 ; inline ! Mach ports +: EVFILT_FS -9 ; inline ! Filesystem events + +! actions +: EV_ADD HEX: 1 ; inline ! add event to kq (implies enable) +: EV_DELETE HEX: 2 ; inline ! delete event from kq +: EV_ENABLE HEX: 4 ; inline ! enable event +: EV_DISABLE HEX: 8 ; inline ! disable event (not reported) + +! flags +: EV_ONESHOT HEX: 10 ; inline ! only report one occurrence +: EV_CLEAR HEX: 20 ; inline ! clear event state after reporting + +: EV_SYSFLAGS HEX: f000 ; inline ! reserved by system +: EV_FLAG0 HEX: 1000 ; inline ! filter-specific flag +: EV_FLAG1 HEX: 2000 ; inline ! filter-specific flag + +! returned values +: EV_EOF HEX: 8000 ; inline ! EOF detected +: EV_ERROR HEX: 4000 ; inline ! error, data contains errno + +: EV_POLL EV_FLAG0 ; inline +: EV_OOBAND EV_FLAG1 ; inline + +: NOTE_LOWAT HEX: 00000001 ; inline ! low water mark + +: NOTE_DELETE HEX: 00000001 ; inline ! vnode was removed +: NOTE_WRITE HEX: 00000002 ; inline ! data contents changed +: NOTE_EXTEND HEX: 00000004 ; inline ! size increased +: NOTE_ATTRIB HEX: 00000008 ; inline ! attributes changed +: NOTE_LINK HEX: 00000010 ; inline ! link count changed +: NOTE_RENAME HEX: 00000020 ; inline ! vnode was renamed +: NOTE_REVOKE HEX: 00000040 ; inline ! vnode access was revoked + +: NOTE_EXIT HEX: 80000000 ; inline ! process exited +: NOTE_FORK HEX: 40000000 ; inline ! process forked +: NOTE_EXEC HEX: 20000000 ; inline ! process exec'd +: NOTE_PCTRLMASK HEX: f0000000 ; inline ! mask for hint bits +: NOTE_PDATAMASK HEX: 000fffff ; inline ! mask for pid + +: NOTE_SECONDS HEX: 00000001 ; inline ! data is seconds +: NOTE_USECONDS HEX: 00000002 ; inline ! data is microseconds +: NOTE_NSECONDS HEX: 00000004 ; inline ! data is nanoseconds +: NOTE_ABSOLUTE HEX: 00000008 ; inline ! absolute timeout + +: NOTE_TRACK HEX: 00000001 ; inline ! follow across forks +: NOTE_TRACKERR HEX: 00000002 ; inline ! could not track child +: NOTE_CHILD HEX: 00000004 ; inline ! am a child process From 309a1c179c6fb745210eb7f92dce8c0a872abcf3 Mon Sep 17 00:00:00 2001 From: Slava Pestov Date: Fri, 18 Jan 2008 19:43:14 -0500 Subject: [PATCH 24/30] Add stderr stream; more Unix I/O work --- core/io/io.factor | 3 + core/io/streams/c/c.factor | 5 +- extra/io/unix/backend/backend.factor | 8 ++- extra/io/unix/backend/kqueue/kqueue.factor | 83 ++++++++++++++++++++++ extra/io/unix/backend/select/select.factor | 5 +- extra/io/unix/unix.factor | 16 +++-- extra/structs/structs.factor | 1 - extra/unix/unix.factor | 6 ++ vm/io.c | 5 +- vm/run.h | 7 +- 10 files changed, 120 insertions(+), 19 deletions(-) create mode 100644 extra/io/unix/backend/kqueue/kqueue.factor diff --git a/core/io/io.factor b/core/io/io.factor index 0336ffda78..56b284eaaf 100755 --- a/core/io/io.factor +++ b/core/io/io.factor @@ -35,6 +35,9 @@ GENERIC: stream-write-table ( table-cells style stream -- ) ! Default stream SYMBOL: stdio +! Default error stream +SYMBOL: stderr + : close ( -- ) stdio get stream-close ; : readln ( -- str/f ) stdio get stream-readln ; diff --git a/core/io/streams/c/c.factor b/core/io/streams/c/c.factor index 61eea4ba7b..1dfb89f9c9 100755 --- a/core/io/streams/c/c.factor +++ b/core/io/streams/c/c.factor @@ -57,11 +57,12 @@ M: c-reader stream-close M: object init-io ; : stdin 11 getenv ; - : stdout 12 getenv ; +: stderr 38 getenv ; M: object init-stdio - stdin stdout stdio set-global ; + stdin stdout stdio set-global + stderr stderr set-global ; M: object io-multiplex (sleep) ; diff --git a/extra/io/unix/backend/backend.factor b/extra/io/unix/backend/backend.factor index ec73a5395e..f29d71dd86 100755 --- a/extra/io/unix/backend/backend.factor +++ b/extra/io/unix/backend/backend.factor @@ -154,7 +154,7 @@ M: port port-flush ( port -- ) dup buffer-empty? [ drop ] [ (wait-to-write) ] if ; M: unix-io io-multiplex ( ms -- ) - make-timeval unix-io-multiplex ; + unix-io-multiplex ; M: unix-io init-io ( -- ) H{ } clone read-tasks set-global @@ -162,4 +162,8 @@ M: unix-io init-io ( -- ) init-unix-io ; M: unix-io init-stdio ( -- ) - 0 1 handle>duplex-stream io:stdio set-global ; + 0 1 handle>duplex-stream io:stdio set-global + 2 io:stderr set-global ; + +: multiplexer-error ( n -- ) + 0 < [ err_no ignorable-error? [ (io-error) ] unless ] when ; diff --git a/extra/io/unix/backend/kqueue/kqueue.factor b/extra/io/unix/backend/kqueue/kqueue.factor new file mode 100644 index 0000000000..35f2641e00 --- /dev/null +++ b/extra/io/unix/backend/kqueue/kqueue.factor @@ -0,0 +1,83 @@ +! Copyright (C) 2008 Slava Pestov. +! See http://factorcode.org/license.txt for BSD license. +USING: alien.syntax kernel io.nonblocking io.unix.backend +sequences assocs unix unix.kqueue math namespaces ; +IN: io.unix.backend.kqueue + +TUPLE: unix-kqueue-io ; + +! Global variables +SYMBOL: kqueue-fd +SYMBOL: kqueue-changes +SYMBOL: kqueue-events + +: max-events ( -- n ) + #! We read up to 256 events at a time. This is an arbitrary + #! constant... + 256 ; inline + +M: unix-kqueue-io init-unix-io ( -- ) + V{ } clone kqueue-changes set-global + max-events "kevent" kqueue-events set-global + kqueue kqueue-fd dup io-error set-global ; + +: add-change ( event -- ) kqueue-changes get-global push ; + +: io-task-filter ( task -- n ) + class { + { read-task EVFILT_READ } + { accept-task EVFILT_READ } + { receive-task EVFILT_READ } + { write-task EVFILT_WRITE } + { connect-task EVFILT_WRITE } + { send-task EVFILT_WRITE } + } case ; + +: make-kevent ( task -- event ) + "kevent" + over io-task-fd over set-kevent-ident + over io-task-filter over set-kevent-filter ; + +: make-add-kevent ( task -- event ) + make-kevent + EV_ADD over set-kevent-flags ; + +: make-delete-kevent ( task -- event ) + make-kevent + EV_DELETE over set-kevent-flags ; + +M: unix-select-io register-io-task ( task -- ) + make-add-kevent add-change ; + +M: unix-select-io unregister-io-task ( task -- ) + make-delete-kevent add-change ; + +: kqueue-changelist ( -- byte-array n ) + kqueue-changes get-global + dup concat f like over length rot delete-all ; + +: kqueue-eventlist ( -- byte-array n ) + kqueue-events get-global max-events ; + +: do-kevent ( timespec -- n ) + >r + kqueue-fd get-global + kqueue-changelist + kqueue-eventlist + r> kevent dup multiplexer-error ; + +: kevent-task ( kevent -- task ) + dup kevent-filter { + { [ dup EVFILT_READ = ] [ read-tasks ] } + { [ dup EVFILT_WRITE = ] [ write-tasks ] } + } cond get at ; + +: handle-kevents ( n eventlist -- ) + [ kevent-nth kevent-task handle-fd ] curry each ; + +M: unix-select-io unix-io-multiplex ( ms -- ) + make-timespec + do-kevent + kqueue-events get-global handle-kevents ; + +T{ unix-kqueue-io } unix-io-backend set-global diff --git a/extra/io/unix/backend/select/select.factor b/extra/io/unix/backend/select/select.factor index 255010bff6..b132c8b9e8 100644 --- a/extra/io/unix/backend/select/select.factor +++ b/extra/io/unix/backend/select/select.factor @@ -44,9 +44,8 @@ M: unix-select-io register-io-task ( task -- ) drop ; M: unix-select-io unregister-io-task ( task -- ) drop ; M: unix-select-io unix-io-multiplex ( timeval -- ) - >r FD_SETSIZE init-fdsets r> select 0 < [ - err_no ignorable-error? [ (io-error) ] unless - ] when + make-timeval >r FD_SETSIZE init-fdsets r> + select multiplexer-error read-fdset/tasks handle-fdset write-fdset/tasks handle-fdset ; diff --git a/extra/io/unix/unix.factor b/extra/io/unix/unix.factor index 7114f388e0..1c86224433 100755 --- a/extra/io/unix/unix.factor +++ b/extra/io/unix/unix.factor @@ -1,9 +1,11 @@ -USE: io.unix.backend -USE: io.unix.files -USE: io.unix.sockets -USE: io.unix.launcher -USE: io.unix.mmap -USE: io.backend -USE: namespaces +USING: io.unix.backend io.unix.files io.unix.sockets +io.unix.launcher io.unix.mmap io.backend combinators namespaces +system vocabs.loader ; + +{ + { [ macosx? ] [ "io.unix.backend.kqueue" ] } + { [ bsd? ] [ "io.unix.backend.kqueue" ] } + { [ unix? ] [ "io.unix.backend.select" ] } +} cond require T{ unix-io } io-backend set-global diff --git a/extra/structs/structs.factor b/extra/structs/structs.factor index c0792ed317..f54917dc47 100644 --- a/extra/structs/structs.factor +++ b/extra/structs/structs.factor @@ -10,4 +10,3 @@ C-STRUCT: timeval "timeval" [ set-timeval-usec ] keep [ set-timeval-sec ] keep ; - diff --git a/extra/unix/unix.factor b/extra/unix/unix.factor index 94bb598c25..d87e7f885d 100755 --- a/extra/unix/unix.factor +++ b/extra/unix/unix.factor @@ -41,6 +41,12 @@ C-STRUCT: timespec { "time_t" "sec" } { "long" "nsec" } ; +: make-timespec ( ms -- timespec ) + 1000 /mod 1000000 * + "timespec" + [ set-timespec-nsec ] keep + [ set-timespec-usec ] keep ; + ! ! ! Unix constants ! File type diff --git a/vm/io.c b/vm/io.c index bc7d057abf..d3a29abe72 100755 --- a/vm/io.c +++ b/vm/io.c @@ -13,8 +13,9 @@ normal operation. */ void init_c_io(void) { - userenv[IN_ENV] = allot_alien(F,(CELL)stdin); - userenv[OUT_ENV] = allot_alien(F,(CELL)stdout); + userenv[STDIN_ENV] = allot_alien(F,(CELL)stdin); + userenv[STDOUT_ENV] = allot_alien(F,(CELL)stdout); + userenv[STDERR_ENV] = allot_alien(F,(CELL)stderr); } void io_error(void) diff --git a/vm/run.h b/vm/run.h index 6f2caa0c14..976fa36337 100755 --- a/vm/run.h +++ b/vm/run.h @@ -16,8 +16,8 @@ typedef enum { OS_ENV, /* operating system name */ ARGS_ENV = 10, /* command line arguments */ - IN_ENV, /* stdin FILE* handle */ - OUT_ENV, /* stdout FILE* handle */ + STDIN_ENV, /* stdin FILE* handle */ + STDOUT_ENV, /* stdout FILE* handle */ IMAGE_ENV = 13, /* image path name */ EXECUTABLE_ENV, /* runtime executable path name */ @@ -51,6 +51,9 @@ typedef enum { STACK_TRACES_ENV = 36, UNDEFINED_ENV = 37, /* default quotation for undefined words */ + + STDERR_ENV = 38, /* stderr FILE* handle */ + STAGE2_ENV = 39 /* have we bootstrapped? */ } F_ENVTYPE; From d5257e47b14cb1bd77a8a748ca5ff53a2c7fd4a6 Mon Sep 17 00:00:00 2001 From: Slava Pestov Date: Fri, 18 Jan 2008 19:50:18 -0500 Subject: [PATCH 25/30] Fix circularity --- core/alien/syntax/syntax-docs.factor | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/core/alien/syntax/syntax-docs.factor b/core/alien/syntax/syntax-docs.factor index 858c3f145e..09169e63b4 100755 --- a/core/alien/syntax/syntax-docs.factor +++ b/core/alien/syntax/syntax-docs.factor @@ -1,5 +1,6 @@ -USING: alien alien.c-types alien.structs alien.syntax -alien.syntax.private help.markup help.syntax ; +IN: alien.syntax +USING: alien alien.c-types alien.structs alien.syntax.private +help.markup help.syntax ; HELP: DLL" { $syntax "DLL\" path\"" } From 670a28477286dc633771d1dbcbc6389a942765ad Mon Sep 17 00:00:00 2001 From: Slava Pestov Date: Fri, 18 Jan 2008 19:50:35 -0500 Subject: [PATCH 26/30] Fix stderr --- core/io/streams/c/c-docs.factor | 15 ++++++++++----- core/io/streams/c/c.factor | 10 +++++----- 2 files changed, 15 insertions(+), 10 deletions(-) diff --git a/core/io/streams/c/c-docs.factor b/core/io/streams/c/c-docs.factor index af8136262a..de8a756f92 100644 --- a/core/io/streams/c/c-docs.factor +++ b/core/io/streams/c/c-docs.factor @@ -14,9 +14,10 @@ ARTICLE: "io.streams.c" "ANSI C streams" { $subsection fclose } { $subsection fgetc } { $subsection fread } -"Two standard file handles:" -{ $subsection stdin } -{ $subsection stdout } ; +"The three standard file handles:" +{ $subsection stdin-handle } +{ $subsection stdout-handle } +{ $subsection stderr-handle } ; ABOUT: "io.streams.c" @@ -64,10 +65,14 @@ HELP: fread ( n alien -- str/f ) { $description "Reads a sequence of characters from a C FILE* handle, and outputs " { $link f } " on end of file." } { $errors "Throws an error if the input operation failed." } ; -HELP: stdin +HELP: stdin-handle { $values { "in" "a C FILE* handle" } } { $description "Outputs the console standard input file handle." } ; -HELP: stdout +HELP: stdout-handle { $values { "out" "a C FILE* handle" } } { $description "Outputs the console standard output file handle." } ; + +HELP: stderr-handle +{ $values { "out" "a C FILE* handle" } } +{ $description "Outputs the console standard error file handle." } ; diff --git a/core/io/streams/c/c.factor b/core/io/streams/c/c.factor index 1dfb89f9c9..d816e08443 100755 --- a/core/io/streams/c/c.factor +++ b/core/io/streams/c/c.factor @@ -56,13 +56,13 @@ M: c-reader stream-close M: object init-io ; -: stdin 11 getenv ; -: stdout 12 getenv ; -: stderr 38 getenv ; +: stdin-handle 11 getenv ; +: stdout-handle 12 getenv ; +: stderr-handle 38 getenv ; M: object init-stdio - stdin stdout stdio set-global - stderr stderr set-global ; + stdin-handle stdout-handle stdio set-global + stderr-handle stderr set-global ; M: object io-multiplex (sleep) ; From 3f5342890e92f3b07ff713c1eea02f95e47fe19c Mon Sep 17 00:00:00 2001 From: Slava Pestov Date: Fri, 18 Jan 2008 19:50:48 -0500 Subject: [PATCH 27/30] Fix typo --- extra/unix/unix.factor | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/extra/unix/unix.factor b/extra/unix/unix.factor index d87e7f885d..16b279765f 100755 --- a/extra/unix/unix.factor +++ b/extra/unix/unix.factor @@ -45,7 +45,7 @@ C-STRUCT: timespec 1000 /mod 1000000 * "timespec" [ set-timespec-nsec ] keep - [ set-timespec-usec ] keep ; + [ set-timespec-sec ] keep ; ! ! ! Unix constants From f138c3675eb7794a198c63c8991d15c8afef7027 Mon Sep 17 00:00:00 2001 From: Slava Pestov Date: Fri, 18 Jan 2008 19:51:01 -0500 Subject: [PATCH 28/30] Fix typo --- core/kernel/kernel-docs.factor | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/core/kernel/kernel-docs.factor b/core/kernel/kernel-docs.factor index 2301216394..f832742034 100755 --- a/core/kernel/kernel-docs.factor +++ b/core/kernel/kernel-docs.factor @@ -49,7 +49,7 @@ ARTICLE: "basic-combinators" "Basic combinators" { $subsection execute } "These words are used to implement " { $emphasis "combinators" } ", which are words that take code from the stack. Note that combinator definitions must be followed by the " { $link POSTPONE: inline } " declaration in order to compile in the optimizing compiler; for example:" { $code - ": keep ( x quot -- x | quot: x -- )" + ": keep ( x quot -- x )" " over >r call r> ; inline" } "Word inlining is documented in " { $link "declarations" } "." From 8339cb0b4a01447d095797458a464ad3dee2c248 Mon Sep 17 00:00:00 2001 From: Slava Pestov Date: Fri, 18 Jan 2008 20:28:43 -0500 Subject: [PATCH 29/30] Fix for word renaming --- extra/tools/deploy/shaker/shaker.factor | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/extra/tools/deploy/shaker/shaker.factor b/extra/tools/deploy/shaker/shaker.factor index d157571757..fd6c79e5ba 100755 --- a/extra/tools/deploy/shaker/shaker.factor +++ b/extra/tools/deploy/shaker/shaker.factor @@ -11,7 +11,7 @@ IN: tools.deploy.shaker : show ( msg -- ) #! Use primitives directly so that we can print stuff even #! after most of the image has been stripped away - "\r\n" append stdout fwrite stdout fflush ; + "\r\n" append stdout-handle fwrite stdout-handle fflush ; : strip-init-hooks ( -- ) "Stripping startup hooks" show From 74329237e6d49522ba0c169ca04039e041d02fff Mon Sep 17 00:00:00 2001 From: Slava Pestov Date: Fri, 18 Jan 2008 20:29:43 -0500 Subject: [PATCH 30/30] kqueue work in progress --- extra/io/unix/backend/kqueue/kqueue.factor | 67 +++++++++++++++------- extra/io/unix/unix.factor | 5 +- 2 files changed, 48 insertions(+), 24 deletions(-) diff --git a/extra/io/unix/backend/kqueue/kqueue.factor b/extra/io/unix/backend/kqueue/kqueue.factor index 35f2641e00..287b88c1c3 100644 --- a/extra/io/unix/backend/kqueue/kqueue.factor +++ b/extra/io/unix/backend/kqueue/kqueue.factor @@ -1,14 +1,16 @@ ! Copyright (C) 2008 Slava Pestov. ! See http://factorcode.org/license.txt for BSD license. -USING: alien.syntax kernel io.nonblocking io.unix.backend -sequences assocs unix unix.kqueue math namespaces ; +USING: alien.c-types kernel io.nonblocking io.unix.backend +io.unix.sockets sequences assocs unix unix.kqueue math +namespaces classes combinators ; IN: io.unix.backend.kqueue TUPLE: unix-kqueue-io ; ! Global variables SYMBOL: kqueue-fd -SYMBOL: kqueue-changes +SYMBOL: kqueue-added +SYMBOL: kqueue-deleted SYMBOL: kqueue-events : max-events ( -- n ) @@ -17,26 +19,43 @@ SYMBOL: kqueue-events 256 ; inline M: unix-kqueue-io init-unix-io ( -- ) - V{ } clone kqueue-changes set-global + H{ } clone kqueue-added set-global + H{ } clone kqueue-deleted set-global max-events "kevent" kqueue-events set-global - kqueue kqueue-fd dup io-error set-global ; + kqueue dup io-error kqueue-fd set-global ; -: add-change ( event -- ) kqueue-changes get-global push ; +M: unix-kqueue-io register-io-task ( task -- ) + dup io-task-fd kqueue-added get-global key? [ drop ] [ + dup io-task-fd kqueue-deleted get-global key? [ + io-task-fd kqueue-deleted get-global delete-at + ] [ + dup io-task-fd kqueue-added get-global set-at + ] if + ] if ; + +M: unix-kqueue-io unregister-io-task ( task -- ) + dup io-task-fd kqueue-deleted get-global key? [ drop ] [ + dup io-task-fd kqueue-added get-global key? [ + io-task-fd kqueue-added get-global delete-at + ] [ + dup io-task-fd kqueue-deleted get-global set-at + ] if + ] if ; : io-task-filter ( task -- n ) class { - { read-task EVFILT_READ } - { accept-task EVFILT_READ } - { receive-task EVFILT_READ } - { write-task EVFILT_WRITE } - { connect-task EVFILT_WRITE } - { send-task EVFILT_WRITE } + { read-task [ EVFILT_READ ] } + { accept-task [ EVFILT_READ ] } + { receive-task [ EVFILT_READ ] } + { write-task [ EVFILT_WRITE ] } + { connect-task [ EVFILT_WRITE ] } + { send-task [ EVFILT_WRITE ] } } case ; : make-kevent ( task -- event ) "kevent" over io-task-fd over set-kevent-ident - over io-task-filter over set-kevent-filter ; + swap io-task-filter over set-kevent-filter ; : make-add-kevent ( task -- event ) make-kevent @@ -46,15 +65,19 @@ M: unix-kqueue-io init-unix-io ( -- ) make-kevent EV_DELETE over set-kevent-flags ; -M: unix-select-io register-io-task ( task -- ) - make-add-kevent add-change ; +: kqueue-additions ( -- kevents ) + kqueue-added get-global + dup clear-assoc values + [ make-add-kevent ] map ; -M: unix-select-io unregister-io-task ( task -- ) - make-delete-kevent add-change ; +: kqueue-deletions ( -- kevents ) + kqueue-deleted get-global + dup clear-assoc values + [ make-delete-kevent ] map ; : kqueue-changelist ( -- byte-array n ) - kqueue-changes get-global - dup concat f like over length rot delete-all ; + kqueue-additions kqueue-deletions append + dup concat f like swap length ; : kqueue-eventlist ( -- byte-array n ) kqueue-events get-global max-events ; @@ -67,15 +90,15 @@ M: unix-select-io unregister-io-task ( task -- ) r> kevent dup multiplexer-error ; : kevent-task ( kevent -- task ) - dup kevent-filter { + dup kevent-ident swap kevent-filter { { [ dup EVFILT_READ = ] [ read-tasks ] } { [ dup EVFILT_WRITE = ] [ write-tasks ] } - } cond get at ; + } cond nip get at ; : handle-kevents ( n eventlist -- ) [ kevent-nth kevent-task handle-fd ] curry each ; -M: unix-select-io unix-io-multiplex ( ms -- ) +M: unix-kqueue-io unix-io-multiplex ( ms -- ) make-timespec do-kevent kqueue-events get-global handle-kevents ; diff --git a/extra/io/unix/unix.factor b/extra/io/unix/unix.factor index 1c86224433..3800008864 100755 --- a/extra/io/unix/unix.factor +++ b/extra/io/unix/unix.factor @@ -3,8 +3,9 @@ io.unix.launcher io.unix.mmap io.backend combinators namespaces system vocabs.loader ; { - { [ macosx? ] [ "io.unix.backend.kqueue" ] } - { [ bsd? ] [ "io.unix.backend.kqueue" ] } + ! kqueue is a work in progress + ! { [ macosx? ] [ "io.unix.backend.kqueue" ] } + ! { [ bsd? ] [ "io.unix.backend.kqueue" ] } { [ unix? ] [ "io.unix.backend.select" ] } } cond require