diff --git a/lime/graphics/opengl/GL.hx b/lime/graphics/opengl/GL.hx new file mode 100644 index 000000000..62e4bd49b --- /dev/null +++ b/lime/graphics/opengl/GL.hx @@ -0,0 +1,1457 @@ +package lime.graphics.opengl; + +//import lime.utils.compat.Matrix3D; +import lime.utils.ArrayBuffer; +import lime.utils.ArrayBufferView; +import lime.utils.Float32Array; +import lime.utils.IMemoryRange; +import lime.utils.Int32Array; +import lime.system.System; + + + +typedef GLActiveInfo = { + + size : Int, + type : Int, + name : String + +} //GLActiveInfo + + +class GLBuffer extends GLObject { + + override function getType ():String { + return "Buffer"; + } + +} //GLBuffer + + +typedef GLContextAttributes = { + + alpha:Bool, + depth:Bool, + stencil:Bool, + antialias:Bool, + premultipliedAlpha:Bool, + preserveDrawingBuffer:Bool + +} //GLContextAttributes + + +class GLFramebuffer extends GLObject { + + override function getType () : String { + return "Framebuffer"; + } + +} //GLFramebuffer + + +typedef GLUniformLocation = Int; + + +class GLProgram extends GLObject { + + public var shaders:Array; + + public function new( version:Int, id:Dynamic ) { + + super (version, id); + shaders = new Array (); + + } //new + + public function attach( shader:GLShader ) : Void { + shaders.push(shader); + } //attach + + public function getShaders() : Array { + return shaders.copy(); + } //getShaders + + override function getType ():String { + return "Program"; + } //getType + +} //GLProgram + + +class GLRenderbuffer extends GLObject { + + override function getType ():String { + return "Renderbuffer"; + } + +} //GLRenderbuffer + + +class GLShader extends GLObject { + + override function getType ():String { + return "Shader"; + } + +} //GLShader + + +class GLTexture extends GLObject { + + override function getType ():String { + return "Texture"; + } + +} //GLTexture + + + + + + +class GL { + + /* ClearBufferMask */ + public static inline var DEPTH_BUFFER_BIT = 0x00000100; + public static inline var STENCIL_BUFFER_BIT = 0x00000400; + public static inline var COLOR_BUFFER_BIT = 0x00004000; + + /* BeginMode */ + public static inline var POINTS = 0x0000; + public static inline var LINES = 0x0001; + public static inline var LINE_LOOP = 0x0002; + public static inline var LINE_STRIP = 0x0003; + public static inline var TRIANGLES = 0x0004; + public static inline var TRIANGLE_STRIP = 0x0005; + public static inline var TRIANGLE_FAN = 0x0006; + + /* AlphaFunction(not supported in ES20) */ + /* NEVER */ + /* LESS */ + /* EQUAL */ + /* LEQUAL */ + /* GREATER */ + /* NOTEQUAL */ + /* GEQUAL */ + /* ALWAYS */ + /* BlendingFactorDest */ + public static inline var ZERO = 0; + public static inline var ONE = 1; + public static inline var SRC_COLOR = 0x0300; + public static inline var ONE_MINUS_SRC_COLOR = 0x0301; + public static inline var SRC_ALPHA = 0x0302; + public static inline var ONE_MINUS_SRC_ALPHA = 0x0303; + public static inline var DST_ALPHA = 0x0304; + public static inline var ONE_MINUS_DST_ALPHA = 0x0305; + + /* BlendingFactorSrc */ + /* ZERO */ + /* ONE */ + public static inline var DST_COLOR = 0x0306; + public static inline var ONE_MINUS_DST_COLOR = 0x0307; + public static inline var SRC_ALPHA_SATURATE = 0x0308; + /* SRC_ALPHA */ + /* ONE_MINUS_SRC_ALPHA */ + /* DST_ALPHA */ + /* ONE_MINUS_DST_ALPHA */ + /* BlendEquationSeparate */ + public static inline var FUNC_ADD = 0x8006; + public static inline var BLEND_EQUATION = 0x8009; + public static inline var BLEND_EQUATION_RGB = 0x8009; /* same as BLEND_EQUATION */ + public static inline var BLEND_EQUATION_ALPHA = 0x883D; + + /* BlendSubtract */ + public static inline var FUNC_SUBTRACT = 0x800A; + public static inline var FUNC_REVERSE_SUBTRACT = 0x800B; + + /* Separate Blend Functions */ + public static inline var BLEND_DST_RGB = 0x80C8; + public static inline var BLEND_SRC_RGB = 0x80C9; + public static inline var BLEND_DST_ALPHA = 0x80CA; + public static inline var BLEND_SRC_ALPHA = 0x80CB; + public static inline var CONSTANT_COLOR = 0x8001; + public static inline var ONE_MINUS_CONSTANT_COLOR = 0x8002; + public static inline var CONSTANT_ALPHA = 0x8003; + public static inline var ONE_MINUS_CONSTANT_ALPHA = 0x8004; + public static inline var BLEND_COLOR = 0x8005; + + /* GLBuffer Objects */ + public static inline var ARRAY_BUFFER = 0x8892; + public static inline var ELEMENT_ARRAY_BUFFER = 0x8893; + public static inline var ARRAY_BUFFER_BINDING = 0x8894; + public static inline var ELEMENT_ARRAY_BUFFER_BINDING = 0x8895; + + public static inline var STREAM_DRAW = 0x88E0; + public static inline var STATIC_DRAW = 0x88E4; + public static inline var DYNAMIC_DRAW = 0x88E8; + + public static inline var BUFFER_SIZE = 0x8764; + public static inline var BUFFER_USAGE = 0x8765; + + public static inline var CURRENT_VERTEX_ATTRIB = 0x8626; + + /* CullFaceMode */ + public static inline var FRONT = 0x0404; + public static inline var BACK = 0x0405; + public static inline var FRONT_AND_BACK = 0x0408; + + /* DepthFunction */ + /* NEVER */ + /* LESS */ + /* EQUAL */ + /* LEQUAL */ + /* GREATER */ + /* NOTEQUAL */ + /* GEQUAL */ + /* ALWAYS */ + /* EnableCap */ + /* TEXTURE_2D */ + public static inline var CULL_FACE = 0x0B44; + public static inline var BLEND = 0x0BE2; + public static inline var DITHER = 0x0BD0; + public static inline var STENCIL_TEST = 0x0B90; + public static inline var DEPTH_TEST = 0x0B71; + public static inline var SCISSOR_TEST = 0x0C11; + public static inline var POLYGON_OFFSET_FILL = 0x8037; + public static inline var SAMPLE_ALPHA_TO_COVERAGE = 0x809E; + public static inline var SAMPLE_COVERAGE = 0x80A0; + + /* ErrorCode */ + public static inline var NO_ERROR = 0; + public static inline var INVALID_ENUM = 0x0500; + public static inline var INVALID_VALUE = 0x0501; + public static inline var INVALID_OPERATION = 0x0502; + public static inline var OUT_OF_MEMORY = 0x0505; + + /* FrontFaceDirection */ + public static inline var CW = 0x0900; + public static inline var CCW = 0x0901; + + /* GetPName */ + public static inline var LINE_WIDTH = 0x0B21; + public static inline var ALIASED_POINT_SIZE_RANGE = 0x846D; + public static inline var ALIASED_LINE_WIDTH_RANGE = 0x846E; + public static inline var CULL_FACE_MODE = 0x0B45; + public static inline var FRONT_FACE = 0x0B46; + public static inline var DEPTH_RANGE = 0x0B70; + public static inline var DEPTH_WRITEMASK = 0x0B72; + public static inline var DEPTH_CLEAR_VALUE = 0x0B73; + public static inline var DEPTH_FUNC = 0x0B74; + public static inline var STENCIL_CLEAR_VALUE = 0x0B91; + public static inline var STENCIL_FUNC = 0x0B92; + public static inline var STENCIL_FAIL = 0x0B94; + public static inline var STENCIL_PASS_DEPTH_FAIL = 0x0B95; + public static inline var STENCIL_PASS_DEPTH_PASS = 0x0B96; + public static inline var STENCIL_REF = 0x0B97; + public static inline var STENCIL_VALUE_MASK = 0x0B93; + public static inline var STENCIL_WRITEMASK = 0x0B98; + public static inline var STENCIL_BACK_FUNC = 0x8800; + public static inline var STENCIL_BACK_FAIL = 0x8801; + public static inline var STENCIL_BACK_PASS_DEPTH_FAIL = 0x8802; + public static inline var STENCIL_BACK_PASS_DEPTH_PASS = 0x8803; + public static inline var STENCIL_BACK_REF = 0x8CA3; + public static inline var STENCIL_BACK_VALUE_MASK = 0x8CA4; + public static inline var STENCIL_BACK_WRITEMASK = 0x8CA5; + public static inline var VIEWPORT = 0x0BA2; + public static inline var SCISSOR_BOX = 0x0C10; + /* SCISSOR_TEST */ + public static inline var COLOR_CLEAR_VALUE = 0x0C22; + public static inline var COLOR_WRITEMASK = 0x0C23; + public static inline var UNPACK_ALIGNMENT = 0x0CF5; + public static inline var PACK_ALIGNMENT = 0x0D05; + public static inline var MAX_TEXTURE_SIZE = 0x0D33; + public static inline var MAX_VIEWPORT_DIMS = 0x0D3A; + public static inline var SUBPIXEL_BITS = 0x0D50; + public static inline var RED_BITS = 0x0D52; + public static inline var GREEN_BITS = 0x0D53; + public static inline var BLUE_BITS = 0x0D54; + public static inline var ALPHA_BITS = 0x0D55; + public static inline var DEPTH_BITS = 0x0D56; + public static inline var STENCIL_BITS = 0x0D57; + public static inline var POLYGON_OFFSET_UNITS = 0x2A00; + /* POLYGON_OFFSET_FILL */ + public static inline var POLYGON_OFFSET_FACTOR = 0x8038; + public static inline var TEXTURE_BINDING_2D = 0x8069; + public static inline var SAMPLE_BUFFERS = 0x80A8; + public static inline var SAMPLES = 0x80A9; + public static inline var SAMPLE_COVERAGE_VALUE = 0x80AA; + public static inline var SAMPLE_COVERAGE_INVERT = 0x80AB; + + /* GetTextureParameter */ + /* TEXTURE_MAG_FILTER */ + /* TEXTURE_MIN_FILTER */ + /* TEXTURE_WRAP_S */ + /* TEXTURE_WRAP_T */ + public static inline var COMPRESSED_TEXTURE_FORMATS = 0x86A3; + + /* HintMode */ + public static inline var DONT_CARE = 0x1100; + public static inline var FASTEST = 0x1101; + public static inline var NICEST = 0x1102; + + /* HintTarget */ + public static inline var GENERATE_MIPMAP_HINT = 0x8192; + + /* DataType */ + public static inline var BYTE = 0x1400; + public static inline var UNSIGNED_BYTE = 0x1401; + public static inline var SHORT = 0x1402; + public static inline var UNSIGNED_SHORT = 0x1403; + public static inline var INT = 0x1404; + public static inline var UNSIGNED_INT = 0x1405; + public static inline var FLOAT = 0x1406; + + /* PixelFormat */ + public static inline var DEPTH_COMPONENT = 0x1902; + public static inline var ALPHA = 0x1906; + public static inline var RGB = 0x1907; + public static inline var RGBA = 0x1908; + public static inline var LUMINANCE = 0x1909; + public static inline var LUMINANCE_ALPHA = 0x190A; + + /* PixelType */ + /* UNSIGNED_BYTE */ + public static inline var UNSIGNED_SHORT_4_4_4_4 = 0x8033; + public static inline var UNSIGNED_SHORT_5_5_5_1 = 0x8034; + public static inline var UNSIGNED_SHORT_5_6_5 = 0x8363; + + /* Shaders */ + public static inline var FRAGMENT_SHADER = 0x8B30; + public static inline var VERTEX_SHADER = 0x8B31; + public static inline var MAX_VERTEX_ATTRIBS = 0x8869; + public static inline var MAX_VERTEX_UNIFORM_VECTORS = 0x8DFB; + public static inline var MAX_VARYING_VECTORS = 0x8DFC; + public static inline var MAX_COMBINED_TEXTURE_IMAGE_UNITS = 0x8B4D; + public static inline var MAX_VERTEX_TEXTURE_IMAGE_UNITS = 0x8B4C; + public static inline var MAX_TEXTURE_IMAGE_UNITS = 0x8872; + public static inline var MAX_FRAGMENT_UNIFORM_VECTORS = 0x8DFD; + public static inline var SHADER_TYPE = 0x8B4F; + public static inline var DELETE_STATUS = 0x8B80; + public static inline var LINK_STATUS = 0x8B82; + public static inline var VALIDATE_STATUS = 0x8B83; + public static inline var ATTACHED_SHADERS = 0x8B85; + public static inline var ACTIVE_UNIFORMS = 0x8B86; + public static inline var ACTIVE_ATTRIBUTES = 0x8B89; + public static inline var SHADING_LANGUAGE_VERSION = 0x8B8C; + public static inline var CURRENT_PROGRAM = 0x8B8D; + + /* StencilFunction */ + public static inline var NEVER = 0x0200; + public static inline var LESS = 0x0201; + public static inline var EQUAL = 0x0202; + public static inline var LEQUAL = 0x0203; + public static inline var GREATER = 0x0204; + public static inline var NOTEQUAL = 0x0205; + public static inline var GEQUAL = 0x0206; + public static inline var ALWAYS = 0x0207; + + /* StencilOp */ + /* ZERO */ + public static inline var KEEP = 0x1E00; + public static inline var REPLACE = 0x1E01; + public static inline var INCR = 0x1E02; + public static inline var DECR = 0x1E03; + public static inline var INVERT = 0x150A; + public static inline var INCR_WRAP = 0x8507; + public static inline var DECR_WRAP = 0x8508; + + /* StringName */ + public static inline var VENDOR = 0x1F00; + public static inline var RENDERER = 0x1F01; + public static inline var VERSION = 0x1F02; + + /* TextureMagFilter */ + public static inline var NEAREST = 0x2600; + public static inline var LINEAR = 0x2601; + + /* TextureMinFilter */ + /* NEAREST */ + /* LINEAR */ + public static inline var NEAREST_MIPMAP_NEAREST = 0x2700; + public static inline var LINEAR_MIPMAP_NEAREST = 0x2701; + public static inline var NEAREST_MIPMAP_LINEAR = 0x2702; + public static inline var LINEAR_MIPMAP_LINEAR = 0x2703; + + /* TextureParameterName */ + public static inline var TEXTURE_MAG_FILTER = 0x2800; + public static inline var TEXTURE_MIN_FILTER = 0x2801; + public static inline var TEXTURE_WRAP_S = 0x2802; + public static inline var TEXTURE_WRAP_T = 0x2803; + + /* TextureTarget */ + public static inline var TEXTURE_2D = 0x0DE1; + public static inline var TEXTURE = 0x1702; + + public static inline var TEXTURE_CUBE_MAP = 0x8513; + public static inline var TEXTURE_BINDING_CUBE_MAP = 0x8514; + public static inline var TEXTURE_CUBE_MAP_POSITIVE_X = 0x8515; + public static inline var TEXTURE_CUBE_MAP_NEGATIVE_X = 0x8516; + public static inline var TEXTURE_CUBE_MAP_POSITIVE_Y = 0x8517; + public static inline var TEXTURE_CUBE_MAP_NEGATIVE_Y = 0x8518; + public static inline var TEXTURE_CUBE_MAP_POSITIVE_Z = 0x8519; + public static inline var TEXTURE_CUBE_MAP_NEGATIVE_Z = 0x851A; + public static inline var MAX_CUBE_MAP_TEXTURE_SIZE = 0x851C; + + /* TextureUnit */ + public static inline var TEXTURE0 = 0x84C0; + public static inline var TEXTURE1 = 0x84C1; + public static inline var TEXTURE2 = 0x84C2; + public static inline var TEXTURE3 = 0x84C3; + public static inline var TEXTURE4 = 0x84C4; + public static inline var TEXTURE5 = 0x84C5; + public static inline var TEXTURE6 = 0x84C6; + public static inline var TEXTURE7 = 0x84C7; + public static inline var TEXTURE8 = 0x84C8; + public static inline var TEXTURE9 = 0x84C9; + public static inline var TEXTURE10 = 0x84CA; + public static inline var TEXTURE11 = 0x84CB; + public static inline var TEXTURE12 = 0x84CC; + public static inline var TEXTURE13 = 0x84CD; + public static inline var TEXTURE14 = 0x84CE; + public static inline var TEXTURE15 = 0x84CF; + public static inline var TEXTURE16 = 0x84D0; + public static inline var TEXTURE17 = 0x84D1; + public static inline var TEXTURE18 = 0x84D2; + public static inline var TEXTURE19 = 0x84D3; + public static inline var TEXTURE20 = 0x84D4; + public static inline var TEXTURE21 = 0x84D5; + public static inline var TEXTURE22 = 0x84D6; + public static inline var TEXTURE23 = 0x84D7; + public static inline var TEXTURE24 = 0x84D8; + public static inline var TEXTURE25 = 0x84D9; + public static inline var TEXTURE26 = 0x84DA; + public static inline var TEXTURE27 = 0x84DB; + public static inline var TEXTURE28 = 0x84DC; + public static inline var TEXTURE29 = 0x84DD; + public static inline var TEXTURE30 = 0x84DE; + public static inline var TEXTURE31 = 0x84DF; + public static inline var ACTIVE_TEXTURE = 0x84E0; + + /* TextureWrapMode */ + public static inline var REPEAT = 0x2901; + public static inline var CLAMP_TO_EDGE = 0x812F; + public static inline var MIRRORED_REPEAT = 0x8370; + + /* Uniform Types */ + public static inline var FLOAT_VEC2 = 0x8B50; + public static inline var FLOAT_VEC3 = 0x8B51; + public static inline var FLOAT_VEC4 = 0x8B52; + public static inline var INT_VEC2 = 0x8B53; + public static inline var INT_VEC3 = 0x8B54; + public static inline var INT_VEC4 = 0x8B55; + public static inline var BOOL = 0x8B56; + public static inline var BOOL_VEC2 = 0x8B57; + public static inline var BOOL_VEC3 = 0x8B58; + public static inline var BOOL_VEC4 = 0x8B59; + public static inline var FLOAT_MAT2 = 0x8B5A; + public static inline var FLOAT_MAT3 = 0x8B5B; + public static inline var FLOAT_MAT4 = 0x8B5C; + public static inline var SAMPLER_2D = 0x8B5E; + public static inline var SAMPLER_CUBE = 0x8B60; + + /* Vertex Arrays */ + public static inline var VERTEX_ATTRIB_ARRAY_ENABLED = 0x8622; + public static inline var VERTEX_ATTRIB_ARRAY_SIZE = 0x8623; + public static inline var VERTEX_ATTRIB_ARRAY_STRIDE = 0x8624; + public static inline var VERTEX_ATTRIB_ARRAY_TYPE = 0x8625; + public static inline var VERTEX_ATTRIB_ARRAY_NORMALIZED = 0x886A; + public static inline var VERTEX_ATTRIB_ARRAY_POINTER = 0x8645; + public static inline var VERTEX_ATTRIB_ARRAY_BUFFER_BINDING = 0x889F; + + /* Point Size */ + public static inline var VERTEX_PROGRAM_POINT_SIZE = 0x8642; + public static inline var POINT_SPRITE = 0x8861; + + /* GLShader Source */ + public static inline var COMPILE_STATUS = 0x8B81; + + /* GLShader Precision-Specified Types */ + public static inline var LOW_FLOAT = 0x8DF0; + public static inline var MEDIUM_FLOAT = 0x8DF1; + public static inline var HIGH_FLOAT = 0x8DF2; + public static inline var LOW_INT = 0x8DF3; + public static inline var MEDIUM_INT = 0x8DF4; + public static inline var HIGH_INT = 0x8DF5; + + /* GLFramebuffer Object. */ + public static inline var FRAMEBUFFER = 0x8D40; + public static inline var RENDERBUFFER = 0x8D41; + + public static inline var RGBA4 = 0x8056; + public static inline var RGB5_A1 = 0x8057; + public static inline var RGB565 = 0x8D62; + public static inline var DEPTH_COMPONENT16 = 0x81A5; + public static inline var STENCIL_INDEX = 0x1901; + public static inline var STENCIL_INDEX8 = 0x8D48; + public static inline var DEPTH_STENCIL = 0x84F9; + + public static inline var RENDERBUFFER_WIDTH = 0x8D42; + public static inline var RENDERBUFFER_HEIGHT = 0x8D43; + public static inline var RENDERBUFFER_INTERNAL_FORMAT = 0x8D44; + public static inline var RENDERBUFFER_RED_SIZE = 0x8D50; + public static inline var RENDERBUFFER_GREEN_SIZE = 0x8D51; + public static inline var RENDERBUFFER_BLUE_SIZE = 0x8D52; + public static inline var RENDERBUFFER_ALPHA_SIZE = 0x8D53; + public static inline var RENDERBUFFER_DEPTH_SIZE = 0x8D54; + public static inline var RENDERBUFFER_STENCIL_SIZE = 0x8D55; + + public static inline var FRAMEBUFFER_ATTACHMENT_OBJECT_TYPE = 0x8CD0; + public static inline var FRAMEBUFFER_ATTACHMENT_OBJECT_NAME = 0x8CD1; + public static inline var FRAMEBUFFER_ATTACHMENT_TEXTURE_LEVEL = 0x8CD2; + public static inline var FRAMEBUFFER_ATTACHMENT_TEXTURE_CUBE_MAP_FACE = 0x8CD3; + + public static inline var COLOR_ATTACHMENT0 = 0x8CE0; + public static inline var DEPTH_ATTACHMENT = 0x8D00; + public static inline var STENCIL_ATTACHMENT = 0x8D20; + public static inline var DEPTH_STENCIL_ATTACHMENT = 0x821A; + + public static inline var NONE = 0; + + public static inline var FRAMEBUFFER_COMPLETE = 0x8CD5; + public static inline var FRAMEBUFFER_INCOMPLETE_ATTACHMENT = 0x8CD6; + public static inline var FRAMEBUFFER_INCOMPLETE_MISSING_ATTACHMENT = 0x8CD7; + public static inline var FRAMEBUFFER_INCOMPLETE_DIMENSIONS = 0x8CD9; + public static inline var FRAMEBUFFER_UNSUPPORTED = 0x8CDD; + + public static inline var FRAMEBUFFER_BINDING = 0x8CA6; + public static inline var RENDERBUFFER_BINDING = 0x8CA7; + public static inline var MAX_RENDERBUFFER_SIZE = 0x84E8; + + public static inline var INVALID_FRAMEBUFFER_OPERATION = 0x0506; + + /* WebGL-specific enums */ + public static inline var UNPACK_FLIP_Y_WEBGL = 0x9240; + public static inline var UNPACK_PREMULTIPLY_ALPHA_WEBGL = 0x9241; + public static inline var CONTEXT_LOST_WEBGL = 0x9242; + public static inline var UNPACK_COLORSPACE_CONVERSION_WEBGL = 0x9243; + public static inline var BROWSER_DEFAULT_WEBGL = 0x9244; + + public static var version(get_version, null):Int; + + public static function versionString():String { + return lime_gl_version(); + } + + public static function activeTexture(texture:Int):Void + { + lime_gl_active_texture(texture); + } + + public static function attachShader(program:GLProgram, shader:GLShader):Void + { + program.attach(shader); + lime_gl_attach_shader(program.id, shader.id); + } + + public static function bindAttribLocation(program:GLProgram, index:Int, name:String):Void + { + lime_gl_bind_attrib_location(program.id, index, name); + } + + public static function bindBuffer(target:Int, buffer:GLBuffer):Void + { + lime_gl_bind_buffer(target, buffer == null ? 0 : buffer.id); + } + + public static function bindFramebuffer(target:Int, framebuffer:GLFramebuffer):Void + { + lime_gl_bind_framebuffer(target, framebuffer == null ? 0 : framebuffer.id); + } + + public static function bindRenderbuffer(target:Int, renderbuffer:GLRenderbuffer):Void + { + lime_gl_bind_renderbuffer(target, renderbuffer == null ? 0 : renderbuffer.id); + } + + public static function bindTexture(target:Int, texture:GLTexture):Void + { + lime_gl_bind_texture(target, texture == null ? 0 : texture.id); + } + + public static function blendColor(red:Float, green:Float, blue:Float, alpha:Float):Void + { + lime_gl_blend_color(red, green, blue, alpha); + } + + public static function blendEquation(mode:Int):Void + { + lime_gl_blend_equation(mode); + } + + public static function blendEquationSeparate(modeRGB:Int, modeAlpha:Int):Void + { + lime_gl_blend_equation_separate(modeRGB, modeAlpha); + } + + public static function blendFunc(sfactor:Int, dfactor:Int):Void + { + lime_gl_blend_func(sfactor, dfactor); + } + + public static function blendFuncSeparate(srcRGB:Int, dstRGB:Int, srcAlpha:Int, dstAlpha:Int):Void + { + lime_gl_blend_func_separate(srcRGB, dstRGB, srcAlpha, dstAlpha); + } + + public static function bufferData(target:Int, data:IMemoryRange, usage:Int):Void + { + lime_gl_buffer_data(target, data.getByteBuffer(), data.getStart(), data.getLength(), usage); + } + + public static function bufferSubData(target:Int, offset:Int, data:IMemoryRange ):Void + { + lime_gl_buffer_sub_data( target, offset, data.getByteBuffer(), data.getStart(), data.getLength() ); + } + + public static function checkFramebufferStatus(target:Int):Int + { + return lime_gl_check_framebuffer_status(target); + } + + public static function clear(mask:Int):Void + { + lime_gl_clear(mask); + } + + public static function clearColor(red:Float, green:Float, blue:Float, alpha:Float):Void + { + lime_gl_clear_color(red, green, blue, alpha); + } + + public static function clearDepth(depth:Float):Void + { + lime_gl_clear_depth(depth); + } + + public static function clearStencil(s:Int):Void + { + lime_gl_clear_stencil(s); + } + + public static function colorMask(red:Bool, green:Bool, blue:Bool, alpha:Bool):Void + { + lime_gl_color_mask(red, green, blue, alpha); + } + + public static function compileShader(shader:GLShader):Void + { + lime_gl_compile_shader(shader.id); + } + + public static function compressedTexImage2D(target:Int, level:Int, internalformat:Int, width:Int, height:Int, border:Int, data:IMemoryRange):Void + { + lime_gl_compressed_tex_image_2d(target, level, internalformat, width, height, border, data == null ? null : data.getByteBuffer(), data == null ? null : data.getStart()); + } + + public static function compressedTexSubImage2D(target:Int, level:Int, xoffset:Int, yoffset:Int, width:Int, height:Int, format:Int, data:IMemoryRange):Void + { + lime_gl_compressed_tex_sub_image_2d(target, level, xoffset, yoffset, width, height, format, data == null ? null : data.getByteBuffer(), data == null ? null : data.getStart()); + } + + public static function copyTexImage2D(target:Int, level:Int, internalformat:Int, x:Int, y:Int, width:Int, height:Int, border:Int):Void + { + lime_gl_copy_tex_image_2d(target, level, internalformat, x, y, width, height, border); + } + + public static function copyTexSubImage2D(target:Int, level:Int, xoffset:Int, yoffset:Int, x:Int, y:Int, width:Int, height:Int):Void + { + lime_gl_copy_tex_sub_image_2d(target, level, xoffset, yoffset, x, y, width, height); + } + + public static function createBuffer():GLBuffer + { + return new GLBuffer(version, lime_gl_create_buffer()); + } + + public static function createFramebuffer():GLFramebuffer + { + return new GLFramebuffer(version, lime_gl_create_framebuffer()); + } + + public static function createProgram():GLProgram + { + return new GLProgram(version, lime_gl_create_program()); + } + + public static function createRenderbuffer():GLRenderbuffer + { + return new GLRenderbuffer(version, lime_gl_create_render_buffer()); + } + + public static function createShader(type:Int):GLShader + { + return new GLShader(version, lime_gl_create_shader(type)); + } + + public static function createTexture():GLTexture + { + return new GLTexture(version, lime_gl_create_texture()); + } + + public static function cullFace(mode:Int):Void + { + lime_gl_cull_face(mode); + } + + public static function deleteBuffer(buffer:GLBuffer):Void + { + lime_gl_delete_buffer(buffer.id); + buffer.invalidate(); + } + + public static function deleteFramebuffer(framebuffer:GLFramebuffer):Void + { + lime_gl_delete_framebuffer(framebuffer.id); + framebuffer.invalidate(); + } + + public static function deleteProgram(program:GLProgram):Void + { + lime_gl_delete_program(program.id); + program.invalidate(); + } + + public static function deleteRenderbuffer(renderbuffer:GLRenderbuffer):Void + { + lime_gl_delete_render_buffer(renderbuffer.id); + renderbuffer.invalidate(); + } + + public static function deleteShader(shader:GLShader):Void + { + lime_gl_delete_shader(shader.id); + shader.invalidate(); + } + + public static function deleteTexture(texture:GLTexture):Void + { + lime_gl_delete_texture(texture.id); + texture.invalidate(); + } + + public static function depthFunc(func:Int):Void + { + lime_gl_depth_func(func); + } + + public static function depthMask(flag:Bool):Void + { + lime_gl_depth_mask(flag); + } + + public static function depthRange(zNear:Float, zFar:Float):Void + { + lime_gl_depth_range(zNear, zFar); + } + + public static function detachShader(program:GLProgram, shader:GLShader):Void + { + lime_gl_detach_shader(program.id, shader.id); + } + + public static function disable(cap:Int):Void + { + lime_gl_disable(cap); + } + + public static function disableVertexAttribArray(index:Int):Void + { + lime_gl_disable_vertex_attrib_array(index); + } + + public static function drawArrays(mode:Int, first:Int, count:Int):Void + { + lime_gl_draw_arrays(mode, first, count); + } + + public static function drawElements(mode:Int, count:Int, type:Int, offset:Int):Void + { + lime_gl_draw_elements(mode, count, type, offset); + } + + public static function enable(cap:Int):Void + { + lime_gl_enable(cap); + } + + public static function enableVertexAttribArray(index:Int):Void + { + lime_gl_enable_vertex_attrib_array(index); + } + + public static function finish():Void + { + lime_gl_finish(); + } + + public static function flush():Void + { + lime_gl_flush(); + } + + public static function framebufferRenderbuffer(target:Int, attachment:Int, renderbuffertarget:Int, renderbuffer:GLRenderbuffer):Void + { + lime_gl_framebuffer_renderbuffer(target, attachment, renderbuffertarget, renderbuffer.id); + } + + public static function framebufferTexture2D(target:Int, attachment:Int, textarget:Int, texture:GLTexture, level:Int):Void + { + lime_gl_framebuffer_texture2D(target, attachment, textarget, texture.id, level); + } + + public static function frontFace(mode:Int):Void + { + lime_gl_front_face(mode); + } + + public static function generateMipmap(target:Int):Void + { + lime_gl_generate_mipmap(target); + } + + public static function getActiveAttrib(program:GLProgram, index:Int):GLActiveInfo + { + return lime_gl_get_active_attrib(program.id, index); + } + + public static function getActiveUniform(program:GLProgram, index:Int):GLActiveInfo + { + return lime_gl_get_active_uniform(program.id, index); + } + + public static function getAttachedShaders(program:GLProgram):Array + { + return program.getShaders(); + } + + public static function getAttribLocation(program:GLProgram, name:String):Int + { + return lime_gl_get_attrib_location(program.id, name); + } + + public static function getBufferParameter(target:Int, pname:Int):Dynamic + { + return lime_gl_get_buffer_paramerter(target, pname); + } + + public static function getContextAttributes():GLContextAttributes + { + var base = lime_gl_get_context_attributes(); + base.premultipliedAlpha = false; + base.preserveDrawingBuffer = false; + return base; + } + + public static function getError():Int + { + return lime_gl_get_error(); + } + + public static function getExtension(name:String):Dynamic + { + //todo?! + return null; + // return lime_gl_get_extension(name); + } + + public static function getFramebufferAttachmentParameter(target:Int, attachment:Int, pname:Int):Dynamic + { + return lime_gl_get_framebuffer_attachment_parameter(target, attachment, pname); + } + + public static function getParameter(pname:Int):Dynamic + { + return lime_gl_get_parameter(pname); + } + + public static function getProgramInfoLog(program:GLProgram):String + { + return lime_gl_get_program_info_log(program.id); + } + + public static function getProgramParameter(program:GLProgram, pname:Int):Int + { + return lime_gl_get_program_parameter(program.id, pname); + } + + public static function getRenderbufferParameter(target:Int, pname:Int):Dynamic + { + return lime_gl_get_render_buffer_parameter(target, pname); + } + + public static function getShaderInfoLog(shader:GLShader):String + { + return lime_gl_get_shader_info_log(shader.id); + } + + public static function getShaderParameter(shader:GLShader, pname:Int):Int + { + return lime_gl_get_shader_parameter(shader.id, pname); + } + + public static function getShaderPrecisionFormat(shadertype:Int, precisiontype:Int):ShaderPrecisionFormat + { + return lime_gl_get_shader_precision_format(shadertype, precisiontype); + } + + public static function getShaderSource(shader:GLShader):String + { + return lime_gl_get_shader_source(shader.id); + } + + public static function getSupportedExtensions():Array + { + var result = new Array(); + lime_gl_get_supported_extensions(result); + return result; + } + + public static function getTexParameter(target:Int, pname:Int):Dynamic + { + return lime_gl_get_tex_parameter(target, pname); + } + + public static function getUniform(program:GLProgram, location:GLUniformLocation):Dynamic + { + return lime_gl_get_uniform(program.id, location); + } + + public static function getUniformLocation(program:GLProgram, name:String):Dynamic + { + return lime_gl_get_uniform_location(program.id, name); + } + + public static function getVertexAttrib(index:Int, pname:Int):Dynamic + { + return lime_gl_get_vertex_attrib(index, pname); + } + + public static function getVertexAttribOffset(index:Int, pname:Int):Int + { + return lime_gl_get_vertex_attrib_offset(index, pname); + } + + public static function hint(target:Int, mode:Int):Void + { + lime_gl_hint(target, mode); + } + + public static function isBuffer(buffer:GLBuffer):Bool + { + return buffer != null && buffer.id > 0 && lime_gl_is_buffer(buffer.id); + } + + // This is non-static + // public function isContextLost():Bool { return false; } + public static function isEnabled(cap:Int):Bool + { + return lime_gl_is_enabled(cap); + } + + public static function isFramebuffer(framebuffer:GLFramebuffer):Bool + { + return framebuffer != null && framebuffer.id > 0 && lime_gl_is_framebuffer(framebuffer.id); + } + + public static function isProgram(program:GLProgram):Bool + { + return program != null && program.id > 0 && lime_gl_is_program(program.id); + } + + public static function isRenderbuffer(renderbuffer:GLRenderbuffer):Bool + { + return renderbuffer != null && renderbuffer.id > 0 && lime_gl_is_renderbuffer(renderbuffer.id); + } + + public static function isShader(shader:GLShader):Bool + { + return shader != null && shader.id > 0 && lime_gl_is_shader(shader.id); + } + + public static function isTexture(texture:GLTexture):Bool + { + return texture != null && texture.id > 0 && lime_gl_is_texture(texture.id); + } + + public static function lineWidth(width:Float):Void + { + lime_gl_line_width(width); + } + + public static function linkProgram(program:GLProgram):Void + { + lime_gl_link_program(program.id); + } + + static function load(inName:String, inArgCount:Int):Dynamic + { + try + { + return System.load("lime", inName, inArgCount); + + } catch(e:Dynamic) + { + trace(e); + return null; + } + } + + public static function pixelStorei(pname:Int, param:Int):Void + { + lime_gl_pixel_storei(pname, param); + } + + public static function polygonOffset(factor:Float, units:Float):Void + { + lime_gl_polygon_offset(factor, units); + } + + public static function readPixels(x:Int, y:Int, width:Int, height:Int, format:Int, type:Int, pixels:ArrayBufferView):Void + { + lime_gl_read_pixels(x, y, width, height, format, type, pixels == null ? null : pixels.getByteBuffer(), pixels == null ? null : pixels.getStart()); + } + + public static function renderbufferStorage(target:Int, internalformat:Int, width:Int, height:Int):Void + { + lime_gl_renderbuffer_storage(target, internalformat, width, height); + } + + public static function sampleCoverage(value:Float, invert:Bool):Void + { + lime_gl_sample_coverage(value, invert); + } + + public static function scissor(x:Int, y:Int, width:Int, height:Int):Void + { + lime_gl_scissor(x, y, width, height); + } + + public static function shaderSource(shader:GLShader, source:String):Void + { + lime_gl_shader_source(shader.id, source); + } + + public static function stencilFunc(func:Int, ref:Int, mask:Int):Void + { + lime_gl_stencil_func(func, ref, mask); + } + + public static function stencilFuncSeparate(face:Int, func:Int, ref:Int, mask:Int):Void + { + lime_gl_stencil_func_separate(face, func, ref, mask); + } + + public static function stencilMask(mask:Int):Void + { + lime_gl_stencil_mask(mask); + } + + public static function stencilMaskSeparate(face:Int, mask:Int):Void + { + lime_gl_stencil_mask_separate(face, mask); + } + + public static function stencilOp(fail:Int, zfail:Int, zpass:Int):Void + { + lime_gl_stencil_op(fail, zfail, zpass); + } + + public static function stencilOpSeparate(face:Int, fail:Int, zfail:Int, zpass:Int):Void + { + lime_gl_stencil_op_separate(face, fail, zfail, zpass); + } + + public static function texImage2D(target:Int, level:Int, internalformat:Int, width:Int, height:Int, border:Int, format:Int, type:Int, pixels:ArrayBufferView):Void + { + lime_gl_tex_image_2d(target, level, internalformat, width, height, border, format, type, pixels == null ? null : pixels.getByteBuffer(), pixels == null ? null : pixels.getStart()); + } + + public static function texParameterf(target:Int, pname:Int, param:Float):Void + { + lime_gl_tex_parameterf(target, pname, param); + } + + public static function texParameteri(target:Int, pname:Int, param:Int):Void + { + lime_gl_tex_parameteri(target, pname, param); + } + + public static function texSubImage2D(target:Int, level:Int, xoffset:Int, yoffset:Int, width:Int, height:Int, format:Int, type:Int, pixels:ArrayBufferView):Void + { + lime_gl_tex_sub_image_2d(target, level, xoffset, yoffset, width, height, format, type, pixels == null ? null : pixels.getByteBuffer(), pixels == null ? null : pixels.getStart()); + } + + public static function uniform1f(location:GLUniformLocation, x:Float):Void + { + lime_gl_uniform1f(location, x); + } + + public static function uniform1fv(location:GLUniformLocation, x:Float32Array):Void + { + lime_gl_uniform1fv(location, x.getByteBuffer()); + } + + public static function uniform1i(location:GLUniformLocation, x:Int):Void + { + lime_gl_uniform1i(location, x); + } + + public static function uniform1iv(location:GLUniformLocation, v:Int32Array):Void + { + lime_gl_uniform1iv(location, v.getByteBuffer()); + } + + public static function uniform2f(location:GLUniformLocation, x:Float, y:Float):Void + { + lime_gl_uniform2f(location, x, y); + } + + public static function uniform2fv(location:GLUniformLocation, v:Float32Array):Void + { + lime_gl_uniform2fv(location, v.getByteBuffer()); + } + + public static function uniform2i(location:GLUniformLocation, x:Int, y:Int):Void + { + lime_gl_uniform2i(location, x, y); + } + + public static function uniform2iv(location:GLUniformLocation, v:Int32Array):Void + { + lime_gl_uniform2iv(location, v.getByteBuffer()); + } + + public static function uniform3f(location:GLUniformLocation, x:Float, y:Float, z:Float):Void + { + lime_gl_uniform3f(location, x, y, z); + } + + public static function uniform3fv(location:GLUniformLocation, v:Float32Array):Void + { + lime_gl_uniform3fv(location, v.getByteBuffer()); + } + + public static function uniform3i(location:GLUniformLocation, x:Int, y:Int, z:Int):Void + { + lime_gl_uniform3i(location, x, y, z); + } + + public static function uniform3iv(location:GLUniformLocation, v:Int32Array):Void + { + lime_gl_uniform3iv(location, v.getByteBuffer()); + } + + public static function uniform4f(location:GLUniformLocation, x:Float, y:Float, z:Float, w:Float):Void + { + lime_gl_uniform4f(location, x, y, z, w); + } + + public static function uniform4fv(location:GLUniformLocation, v:Float32Array):Void + { + lime_gl_uniform4fv(location, v.getByteBuffer()); + } + + public static function uniform4i(location:GLUniformLocation, x:Int, y:Int, z:Int, w:Int):Void + { + lime_gl_uniform4i(location, x, y, z, w); + } + + public static function uniform4iv(location:GLUniformLocation, v:Int32Array):Void + { + lime_gl_uniform4iv(location, v.getByteBuffer()); + } + + public static function uniformMatrix2fv(location:GLUniformLocation, transpose:Bool, v:Float32Array):Void + { + lime_gl_uniform_matrix(location, transpose, v.getByteBuffer(), 2); + } + + public static function uniformMatrix3fv(location:GLUniformLocation, transpose:Bool, v:Float32Array):Void + { + lime_gl_uniform_matrix(location, transpose, v.getByteBuffer(), 3); + } + + public static function uniformMatrix4fv(location:GLUniformLocation, transpose:Bool, v:Float32Array):Void + { + lime_gl_uniform_matrix(location, transpose, v.getByteBuffer(), 4); + } + + /*public static function uniformMatrix3D(location:GLUniformLocation, transpose:Bool, matrix:Matrix3D):Void + { + lime_gl_uniform_matrix(location, transpose, Float32Array.fromMatrix(matrix).getByteBuffer() , 4); + }*/ + + public static function useProgram(program:GLProgram):Void + { + lime_gl_use_program(program == null ? 0 : program.id); + } + + public static function validateProgram(program:GLProgram):Void + { + lime_gl_validate_program(program.id); + } + + public static function vertexAttrib1f(indx:Int, x:Float):Void + { + lime_gl_vertex_attrib1f(indx, x); + } + + public static function vertexAttrib1fv(indx:Int, values:Float32Array):Void + { + lime_gl_vertex_attrib1fv(indx, values.getByteBuffer()); + } + + public static function vertexAttrib2f(indx:Int, x:Float, y:Float):Void + { + lime_gl_vertex_attrib2f(indx, x, y); + } + + public static function vertexAttrib2fv(indx:Int, values:Float32Array):Void + { + lime_gl_vertex_attrib2fv(indx, values.getByteBuffer()); + } + + public static function vertexAttrib3f(indx:Int, x:Float, y:Float, z:Float):Void + { + lime_gl_vertex_attrib3f(indx, x, y, z); + } + + public static function vertexAttrib3fv(indx:Int, values:Float32Array):Void + { + lime_gl_vertex_attrib3fv(indx, values.getByteBuffer()); + } + + public static function vertexAttrib4f(indx:Int, x:Float, y:Float, z:Float, w:Float):Void + { + lime_gl_vertex_attrib4f(indx, x, y, z, w); + } + + public static function vertexAttrib4fv(indx:Int, values:Float32Array):Void + { + lime_gl_vertex_attrib4fv(indx, values.getByteBuffer()); + } + + public static function vertexAttribPointer(indx:Int, size:Int, type:Int, normalized:Bool, stride:Int, offset:Int):Void + { + lime_gl_vertex_attrib_pointer(indx, size, type, normalized, stride, offset); + } + + public static function viewport(x:Int, y:Int, width:Int, height:Int):Void + { + lime_gl_viewport(x, y, width, height); + } + + + + + // Getters & Setters + + + + + static function get_version():Int { return 2; } + + + + + // Native Methods + + + + + static var lime_gl_active_texture = load("lime_gl_active_texture", 1); + static var lime_gl_attach_shader = load("lime_gl_attach_shader", 2); + static var lime_gl_bind_attrib_location = load("lime_gl_bind_attrib_location", 3); + static var lime_gl_bind_buffer = load("lime_gl_bind_buffer", 2); + static var lime_gl_bind_framebuffer = load("lime_gl_bind_framebuffer", 2); + static var lime_gl_bind_renderbuffer = load("lime_gl_bind_renderbuffer", 2); + static var lime_gl_bind_texture = load("lime_gl_bind_texture", 2); + static var lime_gl_blend_color = load("lime_gl_blend_color", 4); + static var lime_gl_blend_equation = load("lime_gl_blend_equation", 1); + static var lime_gl_blend_equation_separate = load("lime_gl_blend_equation_separate", 2); + static var lime_gl_blend_func = load("lime_gl_blend_func", 2); + static var lime_gl_blend_func_separate = load("lime_gl_blend_func_separate", 4); + static var lime_gl_buffer_data = load("lime_gl_buffer_data", 5); + static var lime_gl_buffer_sub_data = load("lime_gl_buffer_sub_data", 5); + static var lime_gl_check_framebuffer_status = load("lime_gl_check_framebuffer_status", 1); + static var lime_gl_clear = load("lime_gl_clear", 1); + static var lime_gl_clear_color = load("lime_gl_clear_color", 4); + static var lime_gl_clear_depth = load("lime_gl_clear_depth", 1); + static var lime_gl_clear_stencil = load("lime_gl_clear_stencil", 1); + static var lime_gl_color_mask = load("lime_gl_color_mask", 4); + static var lime_gl_compile_shader = load("lime_gl_compile_shader", 1); + static var lime_gl_compressed_tex_image_2d = load("lime_gl_compressed_tex_image_2d", -1); + static var lime_gl_compressed_tex_sub_image_2d = load("lime_gl_compressed_tex_sub_image_2d", -1); + static var lime_gl_copy_tex_image_2d = load("lime_gl_copy_tex_image_2d", -1); + static var lime_gl_copy_tex_sub_image_2d = load("lime_gl_copy_tex_sub_image_2d", -1); + static var lime_gl_create_buffer = load("lime_gl_create_buffer", 0); + static var lime_gl_create_framebuffer = load("lime_gl_create_framebuffer", 0); + static var lime_gl_create_program = load("lime_gl_create_program", 0); + static var lime_gl_create_render_buffer = load("lime_gl_create_render_buffer", 0); + static var lime_gl_create_shader = load("lime_gl_create_shader", 1); + static var lime_gl_create_texture = load("lime_gl_create_texture", 0); + static var lime_gl_cull_face = load("lime_gl_cull_face", 1); + static var lime_gl_delete_buffer = load("lime_gl_delete_buffer", 1); + static var lime_gl_delete_framebuffer = load("lime_gl_delete_framebuffer", 1); + static var lime_gl_delete_program = load("lime_gl_delete_program", 1); + static var lime_gl_delete_render_buffer = load("lime_gl_delete_render_buffer", 1); + static var lime_gl_delete_shader = load("lime_gl_delete_shader", 1); + static var lime_gl_delete_texture = load("lime_gl_delete_texture", 1); + static var lime_gl_depth_func = load("lime_gl_depth_func", 1); + static var lime_gl_depth_mask = load("lime_gl_depth_mask", 1); + static var lime_gl_depth_range = load("lime_gl_depth_range", 2); + static var lime_gl_detach_shader = load("lime_gl_detach_shader", 2); + static var lime_gl_disable = load("lime_gl_disable", 1); + static var lime_gl_disable_vertex_attrib_array = load("lime_gl_disable_vertex_attrib_array", 1); + static var lime_gl_draw_arrays = load("lime_gl_draw_arrays", 3); + static var lime_gl_draw_elements = load("lime_gl_draw_elements", 4); + static var lime_gl_enable = load("lime_gl_enable", 1); + static var lime_gl_enable_vertex_attrib_array = load("lime_gl_enable_vertex_attrib_array", 1); + static var lime_gl_finish = load("lime_gl_finish", 0); + static var lime_gl_flush = load("lime_gl_flush", 0); + static var lime_gl_framebuffer_renderbuffer = load("lime_gl_framebuffer_renderbuffer", 4); + static var lime_gl_framebuffer_texture2D = load("lime_gl_framebuffer_texture2D", 5); + static var lime_gl_front_face = load("lime_gl_front_face", 1); + static var lime_gl_generate_mipmap = load("lime_gl_generate_mipmap", 1); + static var lime_gl_get_active_attrib = load("lime_gl_get_active_attrib", 2); + static var lime_gl_get_active_uniform = load("lime_gl_get_active_uniform", 2); + static var lime_gl_get_attrib_location = load("lime_gl_get_attrib_location", 2); + static var lime_gl_get_buffer_paramerter = load("lime_gl_get_buffer_paramerter", 2); + static var lime_gl_get_context_attributes = load("lime_gl_get_context_attributes", 0); + static var lime_gl_get_error = load("lime_gl_get_error", 0); + static var lime_gl_get_framebuffer_attachment_parameter = load("lime_gl_get_framebuffer_attachment_parameter", 3); + static var lime_gl_get_parameter = load("lime_gl_get_parameter", 1); + // static var lime_gl_get_extension = load("lime_gl_get_extension", 1); + static var lime_gl_get_program_info_log = load("lime_gl_get_program_info_log", 1); + static var lime_gl_get_program_parameter = load("lime_gl_get_program_parameter", 2); + static var lime_gl_get_render_buffer_parameter = load("lime_gl_get_render_buffer_parameter", 2); + static var lime_gl_get_shader_info_log = load("lime_gl_get_shader_info_log", 1); + static var lime_gl_get_shader_parameter = load("lime_gl_get_shader_parameter", 2); + static var lime_gl_get_shader_precision_format = load("lime_gl_get_shader_precision_format", 2); + static var lime_gl_get_shader_source = load("lime_gl_get_shader_source", 1); + static var lime_gl_get_supported_extensions = load("lime_gl_get_supported_extensions", 1); + static var lime_gl_get_tex_parameter = load("lime_gl_get_tex_parameter", 2); + static var lime_gl_get_uniform = load("lime_gl_get_uniform", 2); + static var lime_gl_get_uniform_location = load("lime_gl_get_uniform_location", 2); + static var lime_gl_get_vertex_attrib = load("lime_gl_get_vertex_attrib", 2); + static var lime_gl_get_vertex_attrib_offset = load("lime_gl_get_vertex_attrib_offset", 2); + static var lime_gl_hint = load("lime_gl_hint", 2); + static var lime_gl_is_buffer = load("lime_gl_is_buffer", 1); + static var lime_gl_is_enabled = load("lime_gl_is_enabled", 1); + static var lime_gl_is_framebuffer = load("lime_gl_is_framebuffer", 1); + static var lime_gl_is_program = load("lime_gl_is_program", 1); + static var lime_gl_is_renderbuffer = load("lime_gl_is_renderbuffer", 1); + static var lime_gl_is_shader = load("lime_gl_is_shader", 1); + static var lime_gl_is_texture = load("lime_gl_is_texture", 1); + static var lime_gl_line_width = load("lime_gl_line_width", 1); + static var lime_gl_link_program = load("lime_gl_link_program", 1); + static var lime_gl_pixel_storei = load("lime_gl_pixel_storei", 2); + static var lime_gl_polygon_offset = load("lime_gl_polygon_offset", 2); + static var lime_gl_read_pixels = load("lime_gl_read_pixels", -1); + static var lime_gl_renderbuffer_storage = load("lime_gl_renderbuffer_storage", 4); + static var lime_gl_sample_coverage = load("lime_gl_sample_coverage", 2); + static var lime_gl_scissor = load("lime_gl_scissor", 4); + static var lime_gl_shader_source = load("lime_gl_shader_source", 2); + static var lime_gl_stencil_func = load("lime_gl_stencil_func", 3); + static var lime_gl_stencil_func_separate = load("lime_gl_stencil_func_separate", 4); + static var lime_gl_stencil_mask = load("lime_gl_stencil_mask", 1); + static var lime_gl_stencil_mask_separate = load("lime_gl_stencil_mask_separate", 2); + static var lime_gl_stencil_op = load("lime_gl_stencil_op", 3); + static var lime_gl_stencil_op_separate = load("lime_gl_stencil_op_separate", 4); + static var lime_gl_tex_image_2d = load("lime_gl_tex_image_2d", -1); + static var lime_gl_tex_parameterf = load("lime_gl_tex_parameterf", 3); + static var lime_gl_tex_parameteri = load("lime_gl_tex_parameteri", 3); + static var lime_gl_tex_sub_image_2d = load("lime_gl_tex_sub_image_2d", -1); + static var lime_gl_uniform1f = load("lime_gl_uniform1f", 2); + static var lime_gl_uniform1fv = load("lime_gl_uniform1fv", 2); + static var lime_gl_uniform1i = load("lime_gl_uniform1i", 2); + static var lime_gl_uniform1iv = load("lime_gl_uniform1iv", 2); + static var lime_gl_uniform2f = load("lime_gl_uniform2f", 3); + static var lime_gl_uniform2fv = load("lime_gl_uniform2fv", 2); + static var lime_gl_uniform2i = load("lime_gl_uniform2i", 3); + static var lime_gl_uniform2iv = load("lime_gl_uniform2iv", 2); + static var lime_gl_uniform3f = load("lime_gl_uniform3f", 4); + static var lime_gl_uniform3fv = load("lime_gl_uniform3fv", 2); + static var lime_gl_uniform3i = load("lime_gl_uniform3i", 4); + static var lime_gl_uniform3iv = load("lime_gl_uniform3iv", 2); + static var lime_gl_uniform4f = load("lime_gl_uniform4f", 5); + static var lime_gl_uniform4fv = load("lime_gl_uniform4fv", 2); + static var lime_gl_uniform4i = load("lime_gl_uniform4i", 5); + static var lime_gl_uniform4iv = load("lime_gl_uniform4iv", 2); + static var lime_gl_uniform_matrix = load("lime_gl_uniform_matrix", 4); + static var lime_gl_use_program = load("lime_gl_use_program", 1); + static var lime_gl_validate_program = load("lime_gl_validate_program", 1); + static var lime_gl_version = load("lime_gl_version", 0); + static var lime_gl_vertex_attrib1f = load("lime_gl_vertex_attrib1f", 2); + static var lime_gl_vertex_attrib1fv = load("lime_gl_vertex_attrib1fv", 2); + static var lime_gl_vertex_attrib2f = load("lime_gl_vertex_attrib2f", 3); + static var lime_gl_vertex_attrib2fv = load("lime_gl_vertex_attrib2fv", 2); + static var lime_gl_vertex_attrib3f = load("lime_gl_vertex_attrib3f", 4); + static var lime_gl_vertex_attrib3fv = load("lime_gl_vertex_attrib3fv", 2); + static var lime_gl_vertex_attrib4f = load("lime_gl_vertex_attrib4f", 5); + static var lime_gl_vertex_attrib4fv = load("lime_gl_vertex_attrib4fv", 2); + static var lime_gl_vertex_attrib_pointer = load("lime_gl_vertex_attrib_pointer", -1); + static var lime_gl_viewport = load("lime_gl_viewport", 4); + + +} + + +typedef ShaderPrecisionFormat = +{ + rangeMin : Int, + rangeMax : Int, + precision : Int, + +}; + + +class GLObject { + + /** The native GL handle/id. read only */ + public var id (default, null) : Dynamic; + /** The invalidated state. read only */ + public var invalidated (get, null) : Bool; + /** The valid state. read only */ + public var valid (get, null) : Bool; + + var version:Int; + + public function new (version:Int, id:Dynamic) { + + this.version = version; + this.id = id; + + } //new + + function getType() : String { + return "GLObject"; + } //getType + + public function invalidate() : Void { + id = null; + } //invalidate + + public function isValid() : Bool { + return id != null && version == GL.version; + } //isValid + + public function isInvalid() : Bool { + return !isValid (); + } //isInvalid + + public function toString() : String { + return getType() + "(" + id + ")"; + } //toString + +// Getters & Setters + + function get_invalidated() : Bool { + return isInvalid (); + } //get_invalidated + + function get_valid() : Bool { + return isValid (); + } //get_valid + +} \ No newline at end of file diff --git a/lime/utils/ArrayBuffer.hx b/lime/utils/ArrayBuffer.hx new file mode 100644 index 000000000..1b752d893 --- /dev/null +++ b/lime/utils/ArrayBuffer.hx @@ -0,0 +1,3 @@ +package lime.utils; + +typedef ArrayBuffer = lime.utils.ByteArray; \ No newline at end of file diff --git a/lime/utils/ArrayBufferView.hx b/lime/utils/ArrayBufferView.hx new file mode 100644 index 000000000..1310ed0b2 --- /dev/null +++ b/lime/utils/ArrayBufferView.hx @@ -0,0 +1,238 @@ +package lime.utils; + +#if lime_native + + import lime.utils.ByteArray; + import lime.utils.IMemoryRange; + + #if cpp + import haxe.io.BytesData; + #end + + class ArrayBufferView implements IMemoryRange { + + public var buffer (default, null) : ByteArray; + public var byteOffset (default, null) : Int; + public var byteLength (default, null) : Int; + + #if cpp + var bytes : BytesData; + #end + + function new( lengthOrBuffer:Dynamic, byteOffset:Int = 0, length:Null = null ) { + + if (Std.is(lengthOrBuffer, Int)) { + + byteLength = Std.int(lengthOrBuffer); + this.byteOffset = 0; + buffer = new ArrayBuffer(Std.int(lengthOrBuffer)); + + } else { + + buffer = lengthOrBuffer; + + if (buffer == null) { + throw "Invalid input buffer"; + } + + this.byteOffset = byteOffset; + + if (byteOffset > buffer.length) { + throw "Invalid starting position"; + } + + if (length == null) { + byteLength = buffer.length - byteOffset; + } else { + byteLength = length; + + if (byteLength + byteOffset > buffer.length) { + throw "Invalid buffer length"; + } + } + + } + + buffer.bigEndian = false; + + #if cpp + bytes = buffer.getData(); + #end + + } + + public function getByteBuffer() : ByteArray { + + return buffer; + + } + + public function getLength() : Int { + + return byteLength; + + } + + public function getStart() : Int { + + return byteOffset; + + } + + inline public function getInt8( position:Int ) : Int { + + #if cpp + return untyped __global__.__hxcpp_memory_get_byte(bytes, position + byteOffset); + #else + buffer.position = position + byteOffset; + return buffer.readByte(); + #end + + } + + inline public function setInt8( position:Int, value:Int ) { + + #if cpp + untyped __global__.__hxcpp_memory_set_byte(bytes, position + byteOffset, value); + #else + buffer.position = position + byteOffset; + buffer.writeByte(value); + #end + + } + + inline public function getUInt8( position:Int ) : Int { + + #if cpp + return untyped __global__.__hxcpp_memory_get_byte(bytes, position + byteOffset) & 0xff; + #else + buffer.position = position + byteOffset; + return buffer.readUnsignedByte(); + #end + + } + + inline public function setUInt8( position:Int, value:Int ) { + + #if cpp + untyped __global__.__hxcpp_memory_set_byte(bytes, position + byteOffset, value); + #else + buffer.position = position + byteOffset; + buffer.writeByte(value); + #end + + } + + inline public function getInt16( position:Int ) : Int { + + #if cpp + untyped return __global__.__hxcpp_memory_get_i16(bytes, position + byteOffset); + #else + buffer.position = position + byteOffset; + return buffer.readShort(); + #end + + } + + inline public function setInt16( position:Int, value:Int ) { + + #if cpp + untyped __global__.__hxcpp_memory_set_i16(bytes, position + byteOffset, value); + #else + buffer.position = position + byteOffset; + buffer.writeShort(Std.int(value)); + #end + + } + + inline public function getUInt16( position:Int ) : Int { + + #if cpp + untyped return __global__.__hxcpp_memory_get_ui16(bytes, position + byteOffset) & 0xffff; + #else + buffer.position = position + byteOffset; + return buffer.readUnsignedShort(); + #end + + } + + inline public function setUInt16( position:Int, value:Int ) { + + #if cpp + untyped __global__.__hxcpp_memory_set_ui16(bytes, position + byteOffset, value); + #else + buffer.position = position + byteOffset; + buffer.writeShort(Std.int(value)); + #end + + } + + inline public function getInt32( position:Int ) : Int { + + #if cpp + untyped return __global__.__hxcpp_memory_get_i32(bytes, position + byteOffset); + #else + buffer.position = position + byteOffset; + return buffer.readInt(); + #end + + } + + inline public function setInt32( position:Int, value:Int ) { + + #if cpp + untyped __global__.__hxcpp_memory_set_i32(bytes, position + byteOffset, value); + #else + buffer.position = position + byteOffset; + buffer.writeInt(Std.int(value)); + #end + + } + + inline public function getUInt32( position:Int ) : Int { + + #if cpp + untyped return __global__.__hxcpp_memory_get_ui32(bytes, position + byteOffset); + #else + buffer.position = position + byteOffset; + return buffer.readUnsignedInt(); + #end + + } + + inline public function setUInt32( position:Int, value:Int ) { + + #if cpp + untyped __global__.__hxcpp_memory_set_ui32(bytes, position + byteOffset, value); + #else + buffer.position = position + byteOffset; + buffer.writeUnsignedInt(Std.int(value)); + #end + + } + + inline public function getFloat32( position:Int ) : Float { + + #if cpp + untyped return __global__.__hxcpp_memory_get_float(bytes, position + byteOffset); + #else + buffer.position = position + byteOffset; + return buffer.readFloat(); + #end + + } + + inline public function setFloat32( position:Int, value:Float ) { + + #if cpp + untyped __global__.__hxcpp_memory_set_float(bytes, position + byteOffset, value); + #else + buffer.position = position + byteOffset; + buffer.writeFloat(value); + #end + + } + + } //ArrayBufferView + +#end //lime_native diff --git a/lime/utils/ByteArray.hx b/lime/utils/ByteArray.hx new file mode 100644 index 000000000..8750e2aab --- /dev/null +++ b/lime/utils/ByteArray.hx @@ -0,0 +1,626 @@ +package lime.utils; + +import lime.utils.IMemoryRange; +import haxe.io.Bytes; +import haxe.io.BytesData; +// import lime.errors.EOFError; // Ensure that the neko->haxe callbacks are initialized +//import lime.utils.compat.CompressionAlgorithm; +import lime.utils.IDataInput; +import lime.system.System; + +#if !lime_html5 + + #if neko + import neko.Lib; + import neko.zip.Compress; + import neko.zip.Uncompress; + import neko.zip.Flush; + #else + import cpp.Lib; + import cpp.zip.Compress; + import cpp.zip.Uncompress; + import cpp.zip.Flush; + #end + +#end + +class ByteArray extends Bytes implements ArrayAccess implements IDataInput implements IMemoryRange { + + public var bigEndian:Bool; + public var bytesAvailable(get_bytesAvailable, null):Int; + public var endian(get_endian, set_endian):String; + public var position:Int; + public var byteLength(get_byteLength,null):Int; + + #if neko + /** @private */ private var alloced:Int; + #end + + public function new(inSize = 0) + { + bigEndian = true; + position = 0; + + if (inSize >= 0) + { + #if neko + alloced = inSize < 16 ? 16 : inSize; + var bytes = untyped __dollar__smake(alloced); + super(inSize, bytes); + #else + var data = new BytesData(); + if (inSize > 0) + untyped data[inSize - 1] = 0; + super(inSize, data); + #end + } + } + + @:keep + inline public function __get(pos:Int):Int + { + // Neko/cpp pseudo array accessors... + // No bounds checking is done in the cpp case + #if cpp + return untyped b[pos]; + #else + return get(pos); + #end + } + + #if !no_lime_io + /** @private */ static function __init__() { + var factory = function(inLen:Int) { return new ByteArray(inLen); }; + var resize = function(inArray:ByteArray, inLen:Int) + { + if (inLen > 0) + inArray.ensureElem(inLen - 1, true); + inArray.length = inLen; + + }; + + var bytes = function(inArray:ByteArray) { return inArray==null ? null : inArray.b; } + var slen = function(inArray:ByteArray) { return inArray == null ? 0 : inArray.length; } + + #if !lime_html5 + var init = System.load("lime", "lime_byte_array_init", 4); + init(factory, slen, resize, bytes); + #end //lime_html5 + } + #end + + @:keep + inline public function __set(pos:Int, v:Int):Void + { + // No bounds checking is done in the cpp case + #if cpp + untyped b[pos] = v; + #else + set(pos, v); + #end + } + + public function asString():String + { + return readUTFBytes(length); + } + + public function checkData(inLength:Int) + { + if (inLength + position > length) + ThrowEOFi(); + } + + public function clear() + { + position = 0; + length = 0; + } + +#if !lime_html5 + //todo- sven + + /*public function compress(algorithm:CompressionAlgorithm = null) + { + #if neko + var src = alloced == length ? this : sub(0, length); + #else + var src = this; + #end + + var result:Bytes; + + if (algorithm == CompressionAlgorithm.LZMA) + { + result = Bytes.ofData(lime_lzma_encode( cast src.getData()) ); + + } else + { + var windowBits = switch(algorithm) + { + case DEFLATE: -15; + case GZIP: 31; + default: 15; + } + + #if enable_deflate + result = Compress.run(src, 8, windowBits); + #else + result = Compress.run(src, 8); + #end + } + + b = result.b; + length = result.length; + position = length; + #if neko + alloced = length; + #end + } + + public function deflate() + { + compress(CompressionAlgorithm.DEFLATE); + }*/ + +#end //!lime_html5 + + /** @private */ private function ensureElem(inSize:Int, inUpdateLenght:Bool) { + var len = inSize + 1; + + #if neko + if (alloced < len) + { + alloced =((len+1) * 3) >> 1; + var new_b = untyped __dollar__smake(alloced); + untyped __dollar__sblit(new_b, 0, b, 0, length); + b = new_b; + } + #else + if (b.length < len) + untyped b.__SetSize(len); + #end + + if (inUpdateLenght && length < len) + length = len; + } + + static public function fromBytes(inBytes:Bytes) + { + var result = new ByteArray( -1); + result.limeFromBytes(inBytes); + return result; + } + + public function getLength():Int { return length; } + + // IMemoryRange + public function getByteBuffer():ByteArray { return this; } + public function getStart():Int { return 0; } + +#if !lime_html5 + + public function inflate() { + + //uncompress(CompressionAlgorithm.DEFLATE); + + } + +#end //!lime_html5 + + private inline function limeFromBytes(inBytes:Bytes):Void + { + b = inBytes.b; + length = inBytes.length; + + #if neko + alloced = length; + #end + } + + public inline function readBoolean():Bool + { + return(position < length) ? __get(position++) != 0 : ThrowEOFi() != 0; + } + + public inline function readByte():Int + { + var val:Int = readUnsignedByte(); + return((val & 0x80) != 0) ?(val - 0x100) : val; + } + + public function readBytes(outData:ByteArray, inOffset:Int = 0, inLen:Int = 0):Void + { + if (inLen == 0) + inLen = length - position; + + if (position + inLen > length) + ThrowEOFi(); + + if (outData.length < inOffset + inLen) + outData.ensureElem(inOffset + inLen - 1, true); + + #if neko + outData.blit(inOffset, this, position, inLen); + #else + var b1 = b; + var b2 = outData.b; + var p = position; + for(i in 0...inLen) + b2[inOffset + i] = b1[p + i]; + #end + + position += inLen; + } + + public function readDouble():Float + { + #if !lime_html5 + + if (position + 8 > length) + ThrowEOFi(); + + #if neko + var bytes = new Bytes(8, untyped __dollar__ssub(b, position, 8)); + #elseif cpp + var bytes = new Bytes(8, b.slice(position, position + 8)); + #end + + position += 8; + return _double_of_bytes(bytes.b, bigEndian); + + #end //!lime_html5 + + return 0.0; + } + + #if !no_lime_io + static public function readFile(inString:String):ByteArray { + return lime_byte_array_read_file(inString); + } + #end + + public function readFloat():Float + { + #if !lime_html5 + + if (position + 4 > length) + ThrowEOFi(); + + #if neko + var bytes = new Bytes(4, untyped __dollar__ssub(b, position, 4)); + #elseif cpp + var bytes = new Bytes(4, b.slice(position, position + 4)); + #end + + position += 4; + return _float_of_bytes(bytes.b, bigEndian); + + #end //!lime_html5 + + return 0.0; + } + + public function readInt():Int + { + var ch1 = readUnsignedByte(); + var ch2 = readUnsignedByte(); + var ch3 = readUnsignedByte(); + var ch4 = readUnsignedByte(); + + return bigEndian ?(ch1 << 24) |(ch2 << 16) |(ch3 << 8) | ch4 :(ch4 << 24) |(ch3 << 16) |(ch2 << 8) | ch1; + } + + public inline function readMultiByte(inLen:Int, charSet:String):String + { + // TODO - use code page + return readUTFBytes(inLen); + } + + public function readShort():Int + { + var ch1 = readUnsignedByte(); + var ch2 = readUnsignedByte(); + + var val = bigEndian ?((ch1 << 8) | ch2) :((ch2 << 8) | ch1); + + return((val & 0x8000) != 0) ?(val - 0x10000) : val; + } + + inline public function readUnsignedByte():Int + { + return(position < length) ? __get(position++) : ThrowEOFi(); + } + + public function readUnsignedInt():Int + { + var ch1 = readUnsignedByte(); + var ch2 = readUnsignedByte(); + var ch3 = readUnsignedByte(); + var ch4 = readUnsignedByte(); + + return bigEndian ?(ch1 << 24) |(ch2 << 16) |(ch3 << 8) | ch4 :(ch4 << 24) |(ch3 << 16) |(ch2 << 8) | ch1; + } + + public function readUnsignedShort():Int + { + var ch1 = readUnsignedByte(); + var ch2 = readUnsignedByte(); + + return bigEndian ?(ch1 << 8) | ch2 :(ch2 << 8) + ch1; + } + + public function readUTF():String + { + var len = readUnsignedShort(); + return readUTFBytes(len); + } + + public function readUTFBytes(inLen:Int):String + { + if (position + inLen > length) + ThrowEOFi(); + + var p = position; + position += inLen; + + #if lime_native + + #if neko + return new String(untyped __dollar__ssub(b, p, inLen)); + #elseif cpp + var result:String=""; + untyped __global__.__hxcpp_string_of_bytes(b, result, p, inLen); + return result; + #end + + #else + return "-"; + #end + + } + + public function setLength(inLength:Int):Void + { + if (inLength > 0) + ensureElem(inLength - 1, false); + length = inLength; + } + + // ArrayBuffer interface + public function slice(inBegin:Int, ?inEnd:Int):ByteArray + { + var begin = inBegin; + + if (begin < 0) + { + begin += length; + if (begin < 0) + begin = 0; + } + + var end:Int = inEnd == null ? length : inEnd; + + if (end < 0) + { + end += length; + + if (end < 0) + end = 0; + } + + if (begin >= end) + return new ByteArray(); + + var result = new ByteArray(end - begin); + + var opos = position; + result.blit(0, this, begin, end - begin); + + return result; + } + + /** @private */ private function ThrowEOFi():Int { + throw "new EOFError();"; //todo sven + return 0; + } + +#if !lime_html5 +//todo sven + + /*public function uncompress(algorithm:CompressionAlgorithm = null):Void + { + if (algorithm == null) algorithm = CompressionAlgorithm.GZIP; + + #if neko + var src = alloced == length ? this : sub(0, length); + #else + var src = this; + #end + + var result:Bytes; + + if (algorithm == CompressionAlgorithm.LZMA) + { + result = Bytes.ofData(lime_lzma_decode(src.getData())); + + } else + { + var windowBits = switch(algorithm) + { + case DEFLATE: -15; + case GZIP: 31; + default: 15; + } + + #if enable_deflate + result = Uncompress.run(src, null, windowBits); + #else + result = Uncompress.run(src, null); + #end + } + + b = result.b; + length = result.length; + position = 0; + #if neko + alloced = length; + #end + }*/ + +#end //!lime_html5 + + /** @private */ inline function write_uncheck(inByte:Int) { + #if cpp + untyped b.__unsafe_set(position++, inByte); + #else + untyped __dollar__sset(b, position++, inByte & 0xff); + #end + } + + public function writeBoolean(value:Bool) + { + writeByte(value ? 1 : 0); + } + + inline public function writeByte(value:Int) + { + ensureElem(position, true); + + #if cpp + b[position++] = untyped value; + #else + untyped __dollar__sset(b, position++, value & 0xff); + #end + } + + public function writeBytes(bytes:Bytes, inOffset:Int = 0, inLength:Int = 0) + { + if (inLength == 0) inLength = bytes.length - inOffset; + ensureElem(position + inLength - 1, true); + var opos = position; + position += inLength; + blit(opos, bytes, inOffset, inLength); + } + + public function writeDouble(x:Float) + { + #if !lime_html5 + + #if neko + var bytes = new Bytes(8, _double_bytes(x, bigEndian)); + #elseif cpp + var bytes = Bytes.ofData(_double_bytes(x, bigEndian)); + #end + + writeBytes(bytes); + + #end //!lime_html5 + } + + #if !no_lime_io + public function writeFile(inString:String):Void + { + lime_byte_array_overwrite_file(inString, this); + } + #end + + public function writeFloat(x:Float) + { + #if !lime_html5 + + #if neko + var bytes = new Bytes(4, _float_bytes(x, bigEndian)); + #elseif cpp + var bytes = Bytes.ofData(_float_bytes(x, bigEndian)); + #end + + writeBytes(bytes); + + #end //!lime_html5 + } + + public function writeInt(value:Int) + { + ensureElem(position + 3, true); + + if (bigEndian) + { + write_uncheck(value >> 24); + write_uncheck(value >> 16); + write_uncheck(value >> 8); + write_uncheck(value); + + } else + { + write_uncheck(value); + write_uncheck(value >> 8); + write_uncheck(value >> 16); + write_uncheck(value >> 24); + } + } + + // public function writeMultiByte(value:String, charSet:String) + // public function writeObject(object:*) + public function writeShort(value:Int) + { + ensureElem(position + 1, true); + + if (bigEndian) + { + write_uncheck(value >> 8); + write_uncheck(value); + + } else + { + write_uncheck(value); + write_uncheck(value >> 8); + } + } + + public function writeUnsignedInt(value:Int) + { + writeInt(value); + } + + public function writeUTF(s:String) + { + #if neko + var bytes = new Bytes(s.length, untyped s.__s); + #else + var bytes = Bytes.ofString(s); + #end + + writeShort(bytes.length); + writeBytes(bytes); + } + + public function writeUTFBytes(s:String) + { + #if neko + var bytes = new Bytes(s.length, untyped s.__s); + #else + var bytes = Bytes.ofString(s); + #end + + writeBytes(bytes); + } + + // Getters & Setters + private function get_bytesAvailable():Int { return length - position; } + private function get_byteLength():Int { return length; } + private function get_endian():String { return ""; /*return bigEndian ? lime.utils.compat.Endian.BIG_ENDIAN : lime.utils.compat.Endian.LITTLE_ENDIAN;*/ } + private function set_endian(s:String):String { return ""; /*bigEndian =(s == lime.utils.compat.Endian.BIG_ENDIAN); return s;*/ } + + // Native Methods + /** @private */ private static var _double_bytes = System.load("std", "double_bytes", 2); + /** @private */ private static var _double_of_bytes = System.load("std", "double_of_bytes", 2); + /** @private */ private static var _float_bytes = System.load("std", "float_bytes", 2); + /** @private */ private static var _float_of_bytes = System.load("std", "float_of_bytes", 2); + #if !no_lime_io + private static var lime_byte_array_overwrite_file = System.load("lime","lime_byte_array_overwrite_file", 2); + private static var lime_byte_array_read_file = System.load("lime", "lime_byte_array_read_file", 1); + #end + private static var lime_lzma_encode = System.load("lime", "lime_lzma_encode", 1); + private static var lime_lzma_decode = System.load("lime", "lime_lzma_decode", 1); +} diff --git a/lime/utils/Float32Array.hx b/lime/utils/Float32Array.hx new file mode 100644 index 000000000..56ef9a5ca --- /dev/null +++ b/lime/utils/Float32Array.hx @@ -0,0 +1,119 @@ +package lime.utils; + +//import lime.utils.compat.Matrix3D; + +class Float32Array extends ArrayBufferView implements ArrayAccess { + + public var BYTES_PER_ELEMENT (default, null) : Int; + public var length (default, null) : Int; + + public function new( bufferOrArray:Dynamic, start:Int = 0, length:Null = null ) { + + BYTES_PER_ELEMENT = 4; + + if (Std.is(bufferOrArray, Int)) { + + super(Std.int(bufferOrArray) << 2); + this.length = bufferOrArray; + + } else if (Std.is(bufferOrArray, Array)) { + + var floats:Array = bufferOrArray; + this.length = (length != null) ? length : floats.length - start; + super(this.length << 2); + + #if !cpp + buffer.position = 0; + #end + + for (i in 0...this.length) { + + #if cpp + untyped __global__.__hxcpp_memory_set_float(bytes, (i << 2), floats[i + start]); + #else + buffer.writeFloat(floats[i + start]); + #end + + } + + } else if (Std.is(bufferOrArray, Float32Array)) { + + var floats:Float32Array = bufferOrArray; + this.length = (length != null) ? length : floats.length - start; + super(this.length << 2); + + #if !cpp + buffer.position = 0; + #end + + for (i in 0...this.length) { + + #if cpp + untyped __global__.__hxcpp_memory_set_float(bytes, (i << 2), floats[i + start]); + #else + buffer.writeFloat(floats[i + start]); + #end + + } + + } else { + + super(bufferOrArray, start, (length != null) ? length << 2 : null); + + if ((byteLength & 0x03) > 0) { + throw "Invalid array size"; + } + + this.length = byteLength >> 2; + + if ((this.length << 2) != byteLength) { + throw "Invalid length multiple"; + } + + } + + } //new + + public function set( bufferOrArray:Dynamic, offset:Int = 0 ) { + + if (Std.is(bufferOrArray, Array)) { + + var floats:Array = bufferOrArray; + + for (i in 0...floats.length) { + setFloat32((i + offset) << 2, floats[i]); + } + + } else if (Std.is(bufferOrArray, Float32Array)) { + + var floats:Float32Array = bufferOrArray; + + for (i in 0...floats.length) { + setFloat32((i + offset) << 2, floats[i]); + } + + } else { + + throw "Invalid input buffer"; + + } + + } //set + + public function subarray( start:Int, end:Null = null ) : Float32Array { + + end = (end == null) ? length : end; + return new Float32Array(buffer, start << 2, end - start); + + } //subarray + + /*public static function fromMatrix( matrix:Matrix3D ) : Float32Array { + + return new Float32Array(matrix.rawData); + + } //fromMatrix*/ + + @:noCompletion @:keep inline public function __get( index:Int ):Float { return getFloat32(index << 2); } + @:noCompletion @:keep inline public function __set( index:Int, value:Float ) { setFloat32(index << 2, value); } + +} //Float32Array diff --git a/lime/utils/IDataInput.hx b/lime/utils/IDataInput.hx new file mode 100644 index 000000000..fd7a7ad8e --- /dev/null +++ b/lime/utils/IDataInput.hx @@ -0,0 +1,31 @@ +package lime.utils; + + +interface IDataInput { + + public var bytesAvailable(get_bytesAvailable, null):Int; + public var endian(get_endian, set_endian):String; + + public function readBoolean():Bool; + public function readByte():Int; + public function readBytes(outData:ByteArray, inOffset:Int = 0, inLen:Int = 0):Void; + public function readDouble():Float; + public function readFloat():Float; + public function readInt():Int; + + // not implemented ... + //var objectEncoding : UInt; + //public function readMultiByte(length : Int, charSet:String):String; + //public function readObject():Dynamic; + public function readShort():Int; + public function readUnsignedByte():Int; + public function readUnsignedInt():Int; + public function readUnsignedShort():Int; + public function readUTF():String; + public function readUTFBytes(inLen:Int):String; + + private function get_bytesAvailable():Int; + private function get_endian():String; + private function set_endian(s:String):String; + +} //IDataInput diff --git a/lime/utils/IMemoryRange.hx b/lime/utils/IMemoryRange.hx new file mode 100644 index 000000000..7486c1989 --- /dev/null +++ b/lime/utils/IMemoryRange.hx @@ -0,0 +1,11 @@ +package lime.utils; + +import lime.utils.ByteArray; + +interface IMemoryRange { + + public function getByteBuffer ():ByteArray; + public function getStart ():Int; + public function getLength ():Int; + +} \ No newline at end of file diff --git a/lime/utils/Int16Array.hx b/lime/utils/Int16Array.hx new file mode 100644 index 000000000..b37f8356b --- /dev/null +++ b/lime/utils/Int16Array.hx @@ -0,0 +1,112 @@ +package lime.utils; + + +class Int16Array extends ArrayBufferView implements ArrayAccess { + + public var BYTES_PER_ELEMENT (default, null) : Int; + public var length (default, null) : Int; + + public function new( bufferOrArray:Dynamic, start:Int = 0, length:Null = null ) { + + BYTES_PER_ELEMENT = 2; + + if (Std.is(bufferOrArray, Int)) { + + super(Std.int(bufferOrArray) << 1); + this.length = bufferOrArray; + + } else if (Std.is(bufferOrArray, Array)) { + + var ints:Array = bufferOrArray; + this.length = (length != null) ? length : ints.length - start; + super(this.length << 1); + + #if !cpp + buffer.position = 0; + #end + + for (i in 0...this.length) { + + #if cpp + untyped __global__.__hxcpp_memory_set_i16(bytes, (i << 1), ints[i + start]); + #else + buffer.writeShort(ints[i + start]); + #end + + } + + } else if (Std.is(bufferOrArray, Int16Array)) { + + var ints:Int16Array = bufferOrArray; + this.length = (length != null) ? length : ints.length - start; + super(this.length << 1); + + #if !cpp + buffer.position = 0; + #end + + for (i in 0...this.length) { + + #if cpp + untyped __global__.__hxcpp_memory_set_i16(bytes, (i << 1), ints[i + start]); + #else + buffer.writeShort(ints[i + start]); + #end + + } + + } else { + + super(bufferOrArray, start, (length != null) ? length << 1 : null); + + if ((byteLength & 0x01) > 0) { + throw "Invalid array size"; + } + + this.length = byteLength >> 1; + + if ((this.length << 1) != byteLength) { + throw "Invalid length multiple"; + } + + } + + } + + public function set( bufferOrArray:Dynamic, offset:Int = 0 ) { + + if (Std.is(bufferOrArray, Array)) { + + var ints:Array = bufferOrArray; + + for (i in 0...ints.length) { + setInt16((i + offset) << 1, ints[i]); + } + + } else if (Std.is(bufferOrArray, Int16Array)) { + + var ints:Int16Array = bufferOrArray; + + for (i in 0...ints.length) { + setInt16((i + offset) << 1, ints[i]); + } + + } else { + + throw "Invalid input buffer"; + + } + + } + + public function subarray( start:Int, end:Null = null ) : Int16Array { + + end = (end == null) ? length : end; + return new Int16Array(buffer, start << 1, end - start); + + } + + @:noCompletion @:keep inline public function __get( index:Int ):Int { return getInt16(index << 1); } + @:noCompletion @:keep inline public function __set( index:Int, value:Int ) { setInt16(index << 1, value); } + +} //Int16Array diff --git a/lime/utils/Int32Array.hx b/lime/utils/Int32Array.hx new file mode 100644 index 000000000..81ec3b6e6 --- /dev/null +++ b/lime/utils/Int32Array.hx @@ -0,0 +1,115 @@ +package lime.utils; + + + +class Int32Array extends ArrayBufferView implements ArrayAccess { + + + public var BYTES_PER_ELEMENT (default, null) : Int; + public var length (default, null) : Int; + + + public function new( bufferOrArray:Dynamic, start:Int = 0, length:Null = null ) { + + BYTES_PER_ELEMENT = 4; + + if (Std.is(bufferOrArray, Int)) { + + super(Std.int(bufferOrArray) << 2); + this.length = bufferOrArray; + + } else if (Std.is(bufferOrArray, Array)) { + + var ints:Array = bufferOrArray; + this.length = (length != null) ? length : ints.length - start; + super(this.length << 2); + + #if !cpp + buffer.position = 0; + #end + + for (i in 0...this.length) { + + #if cpp + untyped __global__.__hxcpp_memory_set_i32(bytes, (i << 2), ints[i + start]); + #else + buffer.writeInt(ints[i + start]); + #end + + } + + } else if (Std.is(bufferOrArray, Int32Array)) { + + var ints:Int32Array = bufferOrArray; + this.length = (length != null) ? length : ints.length - start; + super(this.length << 2); + + #if !cpp + buffer.position = 0; + #end + + for (i in 0...this.length) { + + #if cpp + untyped __global__.__hxcpp_memory_set_i32(bytes, (i << 2), ints[i + start]); + #else + buffer.writeInt(ints[i + start]); + #end + + } + + } else { + + super(bufferOrArray, start, (length != null) ? length << 2 : null); + + if ((byteLength & 0x03) > 0) { + throw "Invalid array size"; + } + + this.length = byteLength >> 2; + + if ((this.length << 2) != byteLength) { + throw "Invalid length multiple"; + } + + } + + } //new + + public function set( bufferOrArray:Dynamic, offset:Int = 0 ) { + + if (Std.is(bufferOrArray, Array)) { + + var ints:Array = bufferOrArray; + + for (i in 0...ints.length) { + setInt32((i + offset) << 2, ints[i]); + } + + } else if (Std.is(bufferOrArray, Int32Array)) { + + var ints:Int32Array = bufferOrArray; + + for (i in 0...ints.length) { + setInt32((i + offset) << 2, ints[i]); + } + + } else { + + throw "Invalid input buffer"; + + } + + } //set + + public function subarray( start:Int, end:Null = null ) : Int32Array { + + end = (end == null) ? length : end; + return new Int32Array(buffer, start << 2, end - start); + + } //subarray + + @:noCompletion @:keep inline public function __get( index:Int ):Int { return getInt32(index << 2); } + @:noCompletion @:keep inline public function __set( index:Int, value:Int ) { setInt32(index << 2, value); } + +} //Int32Array diff --git a/lime/utils/Int8Array.hx b/lime/utils/Int8Array.hx new file mode 100644 index 000000000..1db84e210 --- /dev/null +++ b/lime/utils/Int8Array.hx @@ -0,0 +1,106 @@ +package lime.utils; + + + +class Int8Array extends ArrayBufferView implements ArrayAccess { + + + public var BYTES_PER_ELEMENT (default, null) : Int; + public var length (default, null) : Int; + + + public function new( bufferOrArray:Dynamic, start:Int = 0, length:Null = null ) { + + BYTES_PER_ELEMENT = 1; + + if (Std.is(bufferOrArray, Int)) { + + super(Std.int(bufferOrArray)); + this.length = bufferOrArray; + + } else if (Std.is(bufferOrArray, Array)) { + + var ints:Array = bufferOrArray; + this.length = (length != null) ? length : ints.length - start; + super(this.length); + + #if !cpp + buffer.position = 0; + #end + + for (i in 0...this.length) { + + #if cpp + untyped __global__.__hxcpp_memory_set_byte(bytes, i, ints[i + start]); + #else + buffer.writeByte(ints[i + start]); + #end + + } + + } else if (Std.is(bufferOrArray, Int8Array)) { + + var ints:Int8Array = bufferOrArray; + this.length = (length != null) ? length : ints.length - start; + super(this.length); + + #if !cpp + buffer.position = 0; + #end + + for (i in 0...this.length) { + + #if cpp + untyped __global__.__hxcpp_memory_set_byte(bytes, i, ints[i + start]); + #else + buffer.writeByte(ints[i + start]); + #end + + } + + } else { + + super(bufferOrArray, start, length); + this.length = byteLength; + + } + + } //new + + public function set( bufferOrArray:Dynamic, offset:Int = 0 ) { + + if (Std.is(bufferOrArray, Array)) { + + var ints:Array = bufferOrArray; + + for (i in 0...ints.length) { + setInt8(i + offset, ints[i]); + } + + } else if (Std.is(bufferOrArray, Int8Array)) { + + var ints:Int8Array = bufferOrArray; + + for (i in 0...ints.length) { + setInt8(i + offset, ints[i]); + } + + } else { + + throw "Invalid input buffer"; + + } + + } //set + + public function subarray( start:Int, end:Null = null ) : Int8Array { + + end = (end == null) ? length : end; + return new Int8Array(buffer, start, end - start); + + } //subarray + + @:noCompletion @:keep inline public function __get( index:Int ):Int { return getInt8(index); } + @:noCompletion @:keep inline public function __set( index:Int, value:Int ) { setInt8(index, value); } + +} //Int8Array diff --git a/lime/utils/UInt16Array.hx b/lime/utils/UInt16Array.hx new file mode 100644 index 000000000..5fa4feaae --- /dev/null +++ b/lime/utils/UInt16Array.hx @@ -0,0 +1,115 @@ +package lime.utils; + + + +class UInt16Array extends ArrayBufferView implements ArrayAccess { + + + public var BYTES_PER_ELEMENT (default, null) : Int; + public var length (default, null) : Int; + + + public function new( bufferOrArray:Dynamic, start:Int = 0, length:Null = null ) { + + BYTES_PER_ELEMENT = 2; + + if (Std.is(bufferOrArray, Int)) { + + super(Std.int(bufferOrArray) << 1); + this.length = bufferOrArray; + + } else if (Std.is(bufferOrArray, Array)) { + + var ints:Array = bufferOrArray; + this.length = (length != null) ? length : ints.length - start; + super(this.length << 1); + + #if !cpp + buffer.position = 0; + #end + + for (i in 0...this.length) { + + #if cpp + untyped __global__.__hxcpp_memory_set_ui16(bytes, (i << 1), ints[i + start]); + #else + buffer.writeShort(ints[i + start]); + #end + + } + + } else if (Std.is(bufferOrArray, UInt16Array)) { + + var ints:UInt16Array = bufferOrArray; + this.length = (length != null) ? length : ints.length - start; + super(this.length << 1); + + #if !cpp + buffer.position = 0; + #end + + for (i in 0...this.length) { + + #if cpp + untyped __global__.__hxcpp_memory_set_i16(bytes, (i << 1), ints[i + start]); + #else + buffer.writeShort(ints[i + start]); + #end + + } + + } else { + + super(bufferOrArray, start, (length != null) ? length << 1 : null); + + if ((byteLength & 0x01) > 0) { + throw "Invalid array size"; + } + + this.length = byteLength >> 1; + + if ((this.length << 1) != byteLength) { + throw "Invalid length multiple"; + } + + } + + } //new + + public function set( bufferOrArray:Dynamic, offset:Int = 0 ) { + + if (Std.is(bufferOrArray, Array)) { + + var ints:Array = bufferOrArray; + + for (i in 0...ints.length) { + setUInt16((i + offset) << 1, ints[i]); + } + + } else if (Std.is(bufferOrArray, UInt16Array)) { + + var ints:UInt16Array = bufferOrArray; + + for (i in 0...ints.length) { + setUInt16((i + offset) << 1, ints[i]); + } + + } else { + + throw "Invalid input buffer"; + + } + + } //set + + public function subarray( start:Int, end:Null = null ) : UInt16Array { + + end = (end == null) ? length : end; + return new UInt16Array(buffer, start << 1, end - start); + + } //subarray + + @:noCompletion @:keep inline public function __get( index:Int ):Int { return getUInt16(index << 1); } + @:noCompletion @:keep inline public function __set( index:Int, value:Int ) { setUInt16(index << 1, value); } + +} //UInt16Array diff --git a/lime/utils/UInt32Array.hx b/lime/utils/UInt32Array.hx new file mode 100644 index 000000000..c0a9a61ec --- /dev/null +++ b/lime/utils/UInt32Array.hx @@ -0,0 +1,114 @@ +package lime.utils; + + +class UInt32Array extends ArrayBufferView implements ArrayAccess { + + + public var BYTES_PER_ELEMENT (default, null) : Int; + public var length (default, null) : Int; + + + public function new( bufferOrArray:Dynamic, start:Int = 0, length:Null = null ) { + + BYTES_PER_ELEMENT = 4; + + if (Std.is(bufferOrArray, Int)) { + + super(Std.int(bufferOrArray) << 2); + this.length = bufferOrArray; + + } else if (Std.is(bufferOrArray, Array)) { + + var ints:Array = bufferOrArray; + this.length = (length != null) ? length : ints.length - start; + super(this.length << 2); + + #if !cpp + buffer.position = 0; + #end + + for (i in 0...this.length) { + + #if cpp + untyped __global__.__hxcpp_memory_set_ui32(bytes, (i << 2), ints[i + start]); + #else + buffer.writeInt(ints[i + start]); + #end + + } + + } else if (Std.is(bufferOrArray, UInt32Array)) { + + var ints:UInt32Array = bufferOrArray; + this.length = (length != null) ? length : ints.length - start; + super(this.length << 2); + + #if !cpp + buffer.position = 0; + #end + + for (i in 0...this.length) { + + #if cpp + untyped __global__.__hxcpp_memory_set_ui32(bytes, (i << 2), ints[i + start]); + #else + buffer.writeInt(ints[i + start]); + #end + + } + + } else { + + super(bufferOrArray, start, (length != null) ? length << 2 : null); + + if ((byteLength & 0x03) > 0) { + throw "Invalid array size"; + } + + this.length = byteLength >> 2; + + if ((this.length << 2) != byteLength) { + throw "Invalid length multiple"; + } + + } + + } //new + + public function set( bufferOrArray:Dynamic, offset:Int = 0 ) { + + if (Std.is(bufferOrArray, Array)) { + + var ints:Array = bufferOrArray; + + for (i in 0...ints.length) { + setUInt32((i + offset) << 2, ints[i]); + } + + } else if (Std.is(bufferOrArray, UInt32Array)) { + + var ints:UInt32Array = bufferOrArray; + + for (i in 0...ints.length) { + setUInt32((i + offset) << 2, ints[i]); + } + + } else { + + throw "Invalid input buffer"; + + } + + } //set + + public function subarray( start:Int, end:Null = null ) : UInt32Array { + + end = (end == null) ? length : end; + return new UInt32Array(buffer, start << 2, end - start); + + } //subarray + + @:noCompletion @:keep inline public function __get( index:Int ):Int { return getUInt32(index << 2); } + @:noCompletion @:keep inline public function __set( index:Int, value:Int ) { setUInt32(index << 2, value); } + +} //UInt32Array diff --git a/lime/utils/UInt8Array.hx b/lime/utils/UInt8Array.hx new file mode 100644 index 000000000..dd004ab36 --- /dev/null +++ b/lime/utils/UInt8Array.hx @@ -0,0 +1,106 @@ +package lime.utils; + + + +class UInt8Array extends ArrayBufferView implements ArrayAccess { + + + public var BYTES_PER_ELEMENT (default, null) : Int; + public var length (default, null) : Int; + + + public function new( bufferOrArray:Dynamic, start:Int = 0, length:Null = null ) { + + BYTES_PER_ELEMENT = 1; + + if (Std.is(bufferOrArray, Int)) { + + super(Std.int(bufferOrArray)); + this.length = bufferOrArray; + + } else if (Std.is(bufferOrArray, Array)) { + + var ints:Array = bufferOrArray; + this.length = (length != null) ? length : ints.length - start; + super(this.length); + + #if !cpp + buffer.position = 0; + #end + + for (i in 0...this.length) { + + #if cpp + untyped __global__.__hxcpp_memory_set_byte(bytes, i, ints[i + start]); + #else + buffer.writeByte(ints[i + start]); + #end + + } + + } else if (Std.is(bufferOrArray, UInt8Array)) { + + var ints:UInt8Array = bufferOrArray; + this.length = (length != null) ? length : ints.length - start; + super(this.length); + + #if !cpp + buffer.position = 0; + #end + + for (i in 0...this.length) { + + #if cpp + untyped __global__.__hxcpp_memory_set_byte(bytes, i, ints[i + start]); + #else + buffer.writeByte(ints[i + start]); + #end + + } + + } else { + + super(bufferOrArray, start, length); + this.length = byteLength; + + } + + } //new + + public function set( bufferOrArray:Dynamic, offset:Int = 0 ) { + + if (Std.is(bufferOrArray, Array)) { + + var ints:Array = bufferOrArray; + + for (i in 0...ints.length) { + setUInt8(i + offset, ints[i]); + } + + } else if (Std.is(bufferOrArray, UInt8Array)) { + + var ints:UInt8Array = bufferOrArray; + + for (i in 0...ints.length) { + setUInt8(i + offset, ints[i]); + } + + } else { + + throw "Invalid input buffer"; + + } + + } //set + + public function subarray( start:Int, end:Null = null ) : UInt8Array { + + end = (end == null) ? length : end; + return new UInt8Array(buffer, start, end - start); + + } //subarray + + @:noCompletion @:keep inline public function __get( index:Int ):Int { return getUInt8(index); } + @:noCompletion @:keep inline public function __set( index:Int, value:Int ) { setUInt8(index, value); } + +} //UInt8Array diff --git a/project/Build.xml b/project/Build.xml index efdfe7e4c..e695f98ca 100644 --- a/project/Build.xml +++ b/project/Build.xml @@ -42,6 +42,14 @@ +
+ + + +
+ + + @@ -115,7 +123,7 @@
- + diff --git a/project/include/Application.h b/project/include/app/Application.h similarity index 68% rename from project/include/Application.h rename to project/include/app/Application.h index 48f6ab0be..736b52ded 100644 --- a/project/include/Application.h +++ b/project/include/app/Application.h @@ -1,5 +1,5 @@ -#ifndef LIME_APPLICATION_H -#define LIME_APPLICATION_H +#ifndef LIME_APP_APPLICATION_H +#define LIME_APP_APPLICATION_H namespace lime { diff --git a/project/include/Renderer.h b/project/include/app/Renderer.h similarity index 64% rename from project/include/Renderer.h rename to project/include/app/Renderer.h index fd56d728b..38566df28 100644 --- a/project/include/Renderer.h +++ b/project/include/app/Renderer.h @@ -1,8 +1,8 @@ -#ifndef LIME_RENDERER_H -#define LIME_RENDERER_H +#ifndef LIME_APP_RENDERER_H +#define LIME_APP_RENDERER_H -#include "Window.h" +#include namespace lime { diff --git a/project/include/Window.h b/project/include/app/Window.h similarity index 66% rename from project/include/Window.h rename to project/include/app/Window.h index 2aa3fbfd3..da2234ff8 100644 --- a/project/include/Window.h +++ b/project/include/app/Window.h @@ -1,8 +1,8 @@ -#ifndef LIME_WINDOW_H -#define LIME_WINDOW_H +#ifndef LIME_APP_WINDOW_H +#define LIME_APP_WINDOW_H -#include "Application.h" +#include namespace lime { diff --git a/project/include/utils/ByteArray.h b/project/include/utils/ByteArray.h new file mode 100644 index 000000000..5dc71def0 --- /dev/null +++ b/project/include/utils/ByteArray.h @@ -0,0 +1,60 @@ +#ifndef LIME_UTILS_BYTE_ARRAY_H +#define LIME_UTILS_BYTE_ARRAY_H + + +#include +#include +#include + + +namespace lime { + + + typedef unsigned char uint8; + + //this was //HX_WINDOWS, + //but we aren't using _wfopen by + //default anymore + #if 0 + + typedef wchar_t OSChar; + #define val_os_string val_wstring + + #else + + typedef char OSChar; + #define val_os_string val_string + + #endif + + + // If you put this structure on the stack, then you do not have to worry about GC. + // If you store this in a heap structure, then you will need to use GC roots for mValue... + struct ByteArray { + + + ByteArray (int inSize); + ByteArray (const ByteArray &inRHS); + ByteArray (); + ByteArray (struct _value *Value); + ByteArray (const QuickVec &inValue); + + void Resize (int inSize); + int Size() const; + unsigned char *Bytes (); + const unsigned char *Bytes () const; + bool Ok () { return mValue != 0; } + + struct _value *mValue; + + static ByteArray FromFile (const OSChar *inFilename); + static int ToFile (const OSChar *inFilename, const ByteArray array); + + + }; + + +} + + +#endif diff --git a/project/include/utils/Object.h b/project/include/utils/Object.h new file mode 100644 index 000000000..709ce21c1 --- /dev/null +++ b/project/include/utils/Object.h @@ -0,0 +1,48 @@ +#ifndef LIME_UTILS_OBJECT_H +#define LIME_UTILS_OBJECT_H + + +namespace lime { + + + class Object { + + + public: + + int ref_count; + + protected: + + virtual ~Object () {} + + public: + + Object (bool has_initial_ref = false) : ref_count (has_initial_ref ? 1 : 0) {} + + Object *grab () { + + ref_count++; + + return this; + + } + + void drop () { + + ref_count--; + + if (ref_count <= 0) { + delete this; + } + + } + + + }; + + +} + + +#endif \ No newline at end of file diff --git a/project/include/utils/QuickVec.h b/project/include/utils/QuickVec.h new file mode 100644 index 000000000..dc627e14f --- /dev/null +++ b/project/include/utils/QuickVec.h @@ -0,0 +1,497 @@ +#ifndef LIME_UTILS_QUICK_VEC_H +#define LIME_UTILS_QUICK_VEC_H + + +#include +#ifdef EPPC +#include +#else +#include +#endif +#include + + +namespace lime { + + + template + void DoDelete(T &item) { } + + template + void DoDelete(T *&item) { + delete item; + item = 0; + } + + + // Little vector/set class, optimised for small data and not using many malloc calls. + // Data are allocated with "malloc", so they should not rely on constructors etc. + template + class QuickVec { + + + enum { QBufSize = QBUF_SIZE_ }; + + + public: + + typedef T_ *iterator; + typedef const T_ * const_iterator; + + + public: + + QuickVec () { + + mPtr = QBUF_SIZE_==0 ? 0 : mQBuf; + mAlloc = QBufSize; + mSize = 0; + + } + + + QuickVec (const QuickVec &inRHS) { + + if (QBUF_SIZE_!=0 && inRHS.mSize<=QBufSize) { + mAlloc = QBufSize; + mPtr = mQBuf; + } else { + mAlloc = inRHS.mAlloc; + mPtr = (T_ *)malloc(mAlloc * sizeof(T_)); + } + + mSize = inRHS.mSize; + memcpy (mPtr,inRHS.mPtr,sizeof(T_)*mSize); + + } + + + int Mem() const { return mAlloc * sizeof(T_); } + + + QuickVec (const T_ *inData,int inLen) { + + mPtr = QBUF_SIZE_==0 ? 0 : mQBuf; + mAlloc = QBufSize; + mSize = 0; + + resize(inLen); + memcpy(mPtr,inData,sizeof(T_)*inLen); + + } + + + QuickVec (int inLen) { + + mPtr = QBUF_SIZE_==0 ? 0 : mQBuf; + mAlloc = QBufSize; + mSize = 0; + + resize(inLen); + + } + + + ~QuickVec () { + + if (QBUF_SIZE_==0 || mPtr!=mQBuf){ + if (mPtr) { + free(mPtr); + } + } + } + + + void clear () { + + if (QBUF_SIZE_==0) { + + if (mPtr) { + free(mPtr); + } + + mPtr = 0; + mAlloc = 0; + + } else if (mPtr!=mQBuf) { + + free(mPtr); + mPtr = mQBuf; + mAlloc = QBufSize; + + } + + mSize = 0; + + } + + + void Set(const T_ *inData,int inN) { + + resize(inN); + if (inN) { + memcpy(mPtr,inData,inN*sizeof(T_)); + } + + } + + + void Zero() { + if (mPtr && mSize) + memset(mPtr,0,mSize*sizeof(T_)); + } + + + // This assumes the values in the array are sorted. + template + void Change(X_ inValue,D_ inDiff) { + if (mSize==0) + { + mPtr[mSize++] = T_(inValue,inDiff); + return; + } + + // Before/at start + if (mPtr[0]==inValue) + { + mPtr[0] += inDiff; + } + else if (mPtr[0]>inValue) + { + InsertAt(0, T_(inValue,inDiff) ); + } + else + { + int last = mSize-1; + // After/on end + if (mPtr[last]==inValue) + { + mPtr[last] += inDiff; + } + else if (mPtr[last]min+1) + { + int middle = (max+min+1)/2; + T_ &v = mPtr[middle]; + if (v==inValue) + { + v += inDiff; + return; + } + if (v=mPtr[last]) + { + if (inValue==mPtr[last]) + EraseAt(last); + else + { + Grow(); + mPtr[mSize] = inValue; + ++mSize; + } + } + else + { + // between 0 ... last + int min = 0; + int max = last; + + while(max>min+1) + { + int middle = (max+min+1)/2; + T_ v = mPtr[middle]; + if (v==inValue) + { + EraseAt(middle); + return; + } + if (v=mAlloc) + { + if (QBUF_SIZE_!=0 && mPtr==mQBuf) + { + mPtr = (T_ *)malloc(sizeof(T_)*(QBufSize*2)); + memcpy(mPtr, mQBuf, sizeof(mQBuf)); + mAlloc = QBufSize*2; + } + else + { + if (mAlloc) + mAlloc *= 2; + else + mAlloc = 16; + mPtr = (T_*)realloc(mPtr, sizeof(T_)*mAlloc); + } + } + } + + + void reserve(int inSize) { + if (mAllocQBufSize) ) + { + mAlloc = inSize; + + if (QBUF_SIZE_==0 || mPtr!=mQBuf) + { + mPtr = (T_ *)realloc(mPtr,sizeof(T_)*mAlloc); + } + else + { + T_ *buf = (T_ *)malloc(sizeof(T_)*mAlloc); + memcpy(buf,mPtr,mSize*sizeof(T_)); + mPtr = buf; + } + } + } + + + void resize(int inSize) { + if (mAllocmSize || inFirst<0) + return; + if (inFirst+inLen>=mSize || inLen<0) + resize(inFirst); + else + { + memmove(mPtr + inFirst, mPtr + inFirst + inLen, (mSize-inFirst-inLen) * sizeof(T_) ); + mSize -= inLen; + } + } + + + inline void InsertAt(int inPos,const T_ &inValue) { + Grow(); + memmove(mPtr + inPos + 1, mPtr + inPos, (mSize-inPos) * sizeof(T_) ); + memcpy(mPtr+inPos,&inValue, sizeof(T_)); + ++mSize; + } + + + inline void InsertAt(int inPos,const T_ *inValues,int inN) { + resize(mSize+inN); + memmove(mPtr + inPos + inN, mPtr + inPos, (mSize-inPos-inN) * sizeof(T_) ); + memcpy(mPtr+inPos,inValues,inN*sizeof(T_)); + } + + + bool operator == (const QuickVec &inRHS) { return (*mPtr == *(inRHS.mPtr)); } + bool operator != (const QuickVec &inRHS) { return !(*mPtr == *(inRHS.mPtr)); } + + + inline int size() const { return mSize; } + inline bool empty() const { return mSize==0; } + inline T_& operator[](int inIndex) { return mPtr[inIndex]; } + inline T_& last() { return mPtr[mSize-1]; } + inline const T_& operator[](int inIndex) const { return mPtr[inIndex]; } + inline iterator begin() { return mPtr; } + inline iterator rbegin() { return mPtr + mSize -1; } + inline iterator end() { return mPtr + mSize; } + inline const_iterator begin() const { return mPtr; } + inline const_iterator rbegin() const { return mPtr + mSize - 1; } + inline const_iterator end() const { return mPtr + mSize; } + + + void swap( QuickVec &inRHS ) { + if (QBUF_SIZE_==0) + { + std::swap(mPtr,inRHS.mPtr); + } + else if (mPtr!=mQBuf) + { + // Both "real" pointers - just swap them + if (inRHS.mPtr!=inRHS.mQBuf) + { + std::swap(mPtr,inRHS.mPtr); + } + else + { + // RHS in in the qbuf, we have a pointer + memcpy(mQBuf,inRHS.mQBuf,inRHS.mSize*sizeof(T_)); + inRHS.mPtr = mPtr; + mPtr = mQBuf; + } + } + else + { + // We have a qbuf, rhs has a pointer + if (inRHS.mPtr!=inRHS.mQBuf) + { + memcpy(inRHS.mQBuf,mQBuf,mSize*sizeof(T_)); + mPtr = inRHS.mPtr; + inRHS.mPtr = inRHS.mQBuf; + } + else + { + // Both using QBuf ... + if (mSize && inRHS.mSize) + { + T_ tmp[QBufSize]; + memcpy(tmp,mPtr,mSize*sizeof(T_)); + memcpy(mPtr,inRHS.mPtr,inRHS.mSize*sizeof(T_)); + memcpy(inRHS.mPtr,tmp,mSize*sizeof(T_)); + } + else if (mSize) + memcpy(inRHS.mQBuf,mQBuf,mSize*sizeof(T_)); + else + memcpy(mQBuf,inRHS.mQBuf,inRHS.mSize*sizeof(T_)); + } + } + + std::swap(mAlloc,inRHS.mAlloc); + std::swap(mSize,inRHS.mSize); + } + + + QuickVec &operator=(const QuickVec &inRHS) { + if ( (QBUF_SIZE_==0 || mPtr!=mQBuf) && mPtr ) + free(mPtr); + + if (QBUF_SIZE_!=0 && inRHS.mSize<=QBufSize) + { + mPtr = mQBuf; + mAlloc = QBufSize; + } + else + { + mAlloc = inRHS.mAlloc; + mPtr = (T_ *)(mAlloc ? malloc( mAlloc * sizeof(T_)) : 0); + } + mSize = inRHS.mSize; + if (mSize) + memcpy(mPtr,inRHS.mPtr,mSize*sizeof(T_)); + return *this; + } + + + void DeleteAll() { + for(int i=0;i &inOther) { + int s = mSize; + resize(mSize+inOther.mSize); + for(int i=0;i -#include "Application.h" -#include "Window.h" -#include "Renderer.h" +#include +#include +#include namespace lime { @@ -48,6 +48,31 @@ namespace lime { } + value lime_lzma_encode(value input_value) { + + /*buffer input_buffer = val_to_buffer(input_value); + buffer output_buffer = alloc_buffer_len(0); + + Lzma::Encode(input_buffer, output_buffer); + + return buffer_val(output_buffer);*/ + return alloc_null(); + + } DEFINE_PRIM(lime_lzma_encode,1); + + value lime_lzma_decode(value input_value) { + + /*buffer input_buffer = val_to_buffer(input_value); + buffer output_buffer = alloc_buffer_len(0); + + Lzma::Decode(input_buffer, output_buffer); + + return buffer_val(output_buffer);*/ + return alloc_null(); + + } DEFINE_PRIM(lime_lzma_decode,1); + + DEFINE_PRIM (lime_application_create, 0); DEFINE_PRIM (lime_application_exec, 1); DEFINE_PRIM (lime_renderer_create, 1); diff --git a/project/src/backend/sdl/SDLApplication.h b/project/src/backend/sdl/SDLApplication.h index 2b6401a64..8becd7212 100644 --- a/project/src/backend/sdl/SDLApplication.h +++ b/project/src/backend/sdl/SDLApplication.h @@ -3,7 +3,7 @@ #include -#include "Application.h" +#include namespace lime { diff --git a/project/src/backend/sdl/SDLRenderer.cpp b/project/src/backend/sdl/SDLRenderer.cpp index 78ca7db62..166e4f821 100644 --- a/project/src/backend/sdl/SDLRenderer.cpp +++ b/project/src/backend/sdl/SDLRenderer.cpp @@ -1,14 +1,21 @@ #include "SDLWindow.h" #include "SDLRenderer.h" +#include namespace lime { + void InitOpenGLBindings (); + + + SDLRenderer::SDLRenderer (Window* window) { currentWindow = window; - sdlRenderer = SDL_CreateRenderer (((SDLWindow*)window)->sdlWindow, -1, 0); + sdlRenderer = SDL_CreateRenderer (((SDLWindow*)window)->sdlWindow, -1, SDL_RENDERER_ACCELERATED); + + InitOpenGLBindings (); } diff --git a/project/src/backend/sdl/SDLRenderer.h b/project/src/backend/sdl/SDLRenderer.h index 821a9c48f..679ae46e4 100644 --- a/project/src/backend/sdl/SDLRenderer.h +++ b/project/src/backend/sdl/SDLRenderer.h @@ -3,7 +3,7 @@ #include -#include "Renderer.h" +#include namespace lime { diff --git a/project/src/backend/sdl/SDLWindow.h b/project/src/backend/sdl/SDLWindow.h index a0ed0eeae..3518a8807 100644 --- a/project/src/backend/sdl/SDLWindow.h +++ b/project/src/backend/sdl/SDLWindow.h @@ -3,7 +3,7 @@ #include -#include "Window.h" +#include namespace lime { diff --git a/project/src/graphics/opengl/OpenGL.h b/project/src/graphics/opengl/OpenGL.h new file mode 100644 index 000000000..94b867c76 --- /dev/null +++ b/project/src/graphics/opengl/OpenGL.h @@ -0,0 +1,147 @@ +#ifndef LIME_GRAPHICS_OPENGL_H +#define LIME_GRAPHICS_OPENGL_H + + +#if defined (BLACKBERRY) || defined (ANDROID) || defined (WEBOS) || defined (GPH) || defined (RASPBERRYPI) || defined (EMSCRIPTEN) + +#define LIME_GLES +#include +#include + +#elif defined (TIZEN) + +#define LIME_GLES +#include +#include + +#elif defined (IPHONE) + +#define LIME_GLES +#include +#include +#include +#include + +#elif defined (HX_LINUX) + +#define NEED_EXTENSIONS +#define DYNAMIC_OGL +#define GL_GLEXT_PROTOTYPES +#include +#define FORCE_NON_PO2 + +#elif defined (HX_MACOS) + +#define GL_GLEXT_PROTOTYPES +#include +#define FORCE_NON_PO2 +#define glBindFramebuffer glBindFramebufferEXT +#define glBindRenderbuffer glBindRenderbufferEXT +#define glGenFramebuffers glGenFramebuffersEXT +#define glDeleteFramebuffers glDeleteFramebuffersEXT +#define glGenRenderbuffers glGenRenderbuffersEXT +#define glDeleteRenderbuffers glDeleteRenderbuffersEXT +#define glFramebufferRenderbuffer glFramebufferRenderbufferEXT +#define glFramebufferTexture2D glFramebufferTexture2DEXT +#define glRenderbufferStorage glRenderbufferStorageEXT +#define glCheckFramebufferStatus glCheckFramebufferStatusEXT +#define glCheckFramebufferStatus glCheckFramebufferStatusEXT +#define glGenerateMipmap glGenerateMipmapEXT +#define glGetFramebufferAttachmentParameteriv glGetFramebufferAttachmentParameterivEXT +#define glGetRenderbufferParameteriv glGetRenderbufferParameterivEXT +#define glIsFramebuffer glIsFramebufferEXT +#define glIsRenderbuffer glIsRenderbufferEXT + +#elif defined (HX_WINDOWS) + +#include +#include +typedef ptrdiff_t GLsizeiptrARB; +#define NEED_EXTENSIONS +#include + +#endif + + +#ifdef HX_WINDOWS +typedef HDC WinDC; +typedef HGLRC GLCtx; +#else +typedef void *WinDC; +typedef void *GLCtx; +#endif + + +#ifndef GL_BUFFER_SIZE + +#define GL_BUFFER_SIZE 0x8764 +#define GL_BUFFER_USAGE 0x8765 +#define GL_ARRAY_BUFFER 0x8892 +#define GL_ELEMENT_ARRAY_BUFFER 0x8893 +#define GL_ARRAY_BUFFER_BINDING 0x8894 +#define GL_ELEMENT_ARRAY_BUFFER_BINDING 0x8895 +#define GL_VERTEX_ARRAY_BUFFER_BINDING 0x8896 +#define GL_NORMAL_ARRAY_BUFFER_BINDING 0x8897 +#define GL_COLOR_ARRAY_BUFFER_BINDING 0x8898 +#define GL_INDEX_ARRAY_BUFFER_BINDING 0x8899 +#define GL_TEXTURE_COORD_ARRAY_BUFFER_BINDING 0x889A +#define GL_EDGE_FLAG_ARRAY_BUFFER_BINDING 0x889B +#define GL_SECONDARY_COLOR_ARRAY_BUFFER_BINDING 0x889C +#define GL_FOG_COORDINATE_ARRAY_BUFFER_BINDING 0x889D +#define GL_WEIGHT_ARRAY_BUFFER_BINDING 0x889E +#define GL_VERTEX_ATTRIB_ARRAY_BUFFER_BINDING 0x889F +#define GL_READ_ONLY 0x88B8 +#define GL_WRITE_ONLY 0x88B9 +#define GL_READ_WRITE 0x88BA +#define GL_BUFFER_ACCESS 0x88BB +#define GL_BUFFER_MAPPED 0x88BC +#define GL_BUFFER_MAP_POINTER 0x88BD +#define GL_STREAM_DRAW 0x88E0 +#define GL_STREAM_READ 0x88E1 +#define GL_STREAM_COPY 0x88E2 +#define GL_STATIC_DRAW 0x88E4 +#define GL_STATIC_READ 0x88E5 +#define GL_STATIC_COPY 0x88E6 +#define GL_DYNAMIC_DRAW 0x88E8 +#define GL_DYNAMIC_READ 0x88E9 +#define GL_DYNAMIC_COPY 0x88EA +#define GL_COMPILE_STATUS 0x8B81 +#define GL_LINK_STATUS 0x8B82 +#define GL_VALIDATE_STATUS 0x8B83 +#define GL_INFO_LOG_LENGTH 0x8B84 +#define GL_ATTACHED_SHADERS 0x8B85 +#define GL_ACTIVE_UNIFORMS 0x8B86 +#define GL_ACTIVE_UNIFORM_MAX_LENGTH 0x8B87 +#define GL_SHADER_SOURCE_LENGTH 0x8B88 +#define GL_VERTEX_SHADER 0x8B31 +#define GL_FRAGMENT_SHADER 0x8B30 +#define GL_TEXTURE0 0x84C0 +#endif + +#ifndef GL_CLAMP_TO_EDGE +#define GL_CLAMP_TO_EDGE 0x812F +#endif + +#ifndef GL_POINT_SMOOTH +#define GL_POINT_SMOOTH 0x0B10 +#endif + +#ifndef GL_LINE_SMOOTH +#define GL_LINE_SMOOTH 0x0B20 +#endif + +#ifdef NEED_EXTENSIONS + +#define DECLARE_EXTENSION +#include "OpenGLExtensions.h" +#undef DECLARE_EXTENSION +#define CHECK_EXT(x) x + +#else + +#define CHECK_EXT(x) true + +#endif + + +#endif \ No newline at end of file diff --git a/project/src/graphics/opengl/OpenGLBindings.cpp b/project/src/graphics/opengl/OpenGLBindings.cpp new file mode 100644 index 000000000..c57f34017 --- /dev/null +++ b/project/src/graphics/opengl/OpenGLBindings.cpp @@ -0,0 +1,1863 @@ +#ifdef HX_LINUX +#include +#endif + +#include +#include +#include "OpenGL.h" +#include + + +namespace lime { + + + #define INT(a) val_int(arg[a]) + + + value lime_gl_get_error() { + + return alloc_int( glGetError() ); + + } DEFINE_PRIM(lime_gl_get_error,0); + + + value lime_gl_finish() { + + glFinish(); + + return alloc_null(); + + } DEFINE_PRIM(lime_gl_finish,0); + + + value lime_gl_flush() { + + glFlush(); + + return alloc_null(); + + } DEFINE_PRIM(lime_gl_flush,0); + + + value lime_gl_version() { + + const char* gl_ver = (const char*)glGetString(GL_VERSION); + const char* gl_sl = (const char*)glGetString(GL_SHADING_LANGUAGE_VERSION); + const char* gl_ren = (const char*)glGetString(GL_RENDERER); + const char* gl_ven = (const char*)glGetString(GL_VENDOR); + + std::string glver ( gl_ver ? gl_ver : "GL version null" ); + std::string glslver ( gl_sl ? gl_sl : "GL SL version null" ); + std::string glren ( gl_ren ? gl_ren : "GL renderer version null" ); + std::string glven ( gl_ven ? gl_ven : "GL vendor version null" ); + + std::string res = "/ " + glver + " / " + glslver + " / " + glren + " / " + glven + " /"; + + return alloc_string( res.c_str() ); + + } DEFINE_PRIM(lime_gl_version,0); + + + value lime_gl_enable(value inCap) { + + //#ifndef lime_FORCE_GLES2 ? //:todo: + glEnable(val_int(inCap)); + //#endif + return alloc_null(); + + } DEFINE_PRIM(lime_gl_enable,1); + + + value lime_gl_disable(value inCap) { + + //#ifndef lime_FORCE_GLES2 //:todo: + glDisable(val_int(inCap)); + //#endif + + return alloc_null(); + + } DEFINE_PRIM(lime_gl_disable,1); + + + value lime_gl_hint(value inTarget, value inValue) { + + glHint(val_int(inTarget),val_int(inValue)); + + return alloc_null(); + + } DEFINE_PRIM(lime_gl_hint,2); + + + value lime_gl_line_width(value inWidth) { + + glLineWidth(val_number(inWidth)); + + return alloc_null(); + + } DEFINE_PRIM(lime_gl_line_width,1); + + + value lime_gl_get_context_attributes() { + + value result = alloc_empty_object( ); + + // TODO: //?//:todo: + alloc_field(result,val_id("alpha"),alloc_bool(true)); + alloc_field(result,val_id("depth"),alloc_bool(true)); + alloc_field(result,val_id("stencil"),alloc_bool(true)); + alloc_field(result,val_id("antialias"),alloc_bool(true)); + + return result; + + } DEFINE_PRIM(lime_gl_get_context_attributes,0); + + + value lime_gl_get_supported_extensions(value ioList) { + + const char *ext = (const char *)glGetString(GL_EXTENSIONS); + + if (ext && *ext) { + + while(true) { + + const char *next = ext; + + while(*next && *next!=' ') { + next++; + } + + val_array_push( ioList, alloc_string_len(ext, next-ext) ); + + if (!*next || !next[1]) { + break; + } + + ext = next+1; + + } //while true + + } //if ext and *ext + + return alloc_null(); + + } DEFINE_PRIM(lime_gl_get_supported_extensions,1); + + + value lime_gl_front_face(value inFace) { + + glFrontFace(val_int(inFace)); + + return alloc_null(); + + } DEFINE_PRIM(lime_gl_front_face,1); + + + value lime_gl_get_parameter(value pname_val) { + + int floats = 0; + int ints = 0; + int strings = 0; + int pname = val_int(pname_val); + + switch(pname) { + + case GL_ALIASED_LINE_WIDTH_RANGE: + case GL_ALIASED_POINT_SIZE_RANGE: + case GL_DEPTH_RANGE: + floats = 2; + break; + + case GL_BLEND_COLOR: + case GL_COLOR_CLEAR_VALUE: + floats = 4; + break; + + case GL_COLOR_WRITEMASK: + ints = 4; + break; + + //case GL_COMPRESSED_TEXTURE_FORMATS null + + case GL_MAX_VIEWPORT_DIMS: + ints = 2; + break; + + case GL_SCISSOR_BOX: + case GL_VIEWPORT: + ints = 4; + break; + + case GL_ARRAY_BUFFER_BINDING: + case GL_CURRENT_PROGRAM: + case GL_ELEMENT_ARRAY_BUFFER_BINDING: + case GL_FRAMEBUFFER_BINDING: + case GL_RENDERBUFFER_BINDING: + case GL_TEXTURE_BINDING_2D: + case GL_TEXTURE_BINDING_CUBE_MAP: + case GL_DEPTH_CLEAR_VALUE: + case GL_LINE_WIDTH: + case GL_POLYGON_OFFSET_FACTOR: + case GL_POLYGON_OFFSET_UNITS: + case GL_SAMPLE_COVERAGE_VALUE: + ints = 1; + break; + + case GL_BLEND: + case GL_DEPTH_WRITEMASK: + case GL_DITHER: + case GL_CULL_FACE: + case GL_POLYGON_OFFSET_FILL: + case GL_SAMPLE_COVERAGE_INVERT: + case GL_STENCIL_TEST: + //case GL_UNPACK_FLIP_Y_WEBGL: + //case GL_UNPACK_PREMULTIPLY_ALPHA_WEBGL: + ints = 1; + break; + + case GL_ALPHA_BITS: + case GL_ACTIVE_TEXTURE: + case GL_BLEND_DST_ALPHA: + case GL_BLEND_DST_RGB: + case GL_BLEND_EQUATION_ALPHA: + case GL_BLEND_EQUATION_RGB: + case GL_BLEND_SRC_ALPHA: + case GL_BLEND_SRC_RGB: + case GL_BLUE_BITS: + case GL_CULL_FACE_MODE: + case GL_DEPTH_BITS: + case GL_DEPTH_FUNC: + case GL_DEPTH_TEST: + case GL_FRONT_FACE: + case GL_GENERATE_MIPMAP_HINT: + case GL_GREEN_BITS: + case GL_MAX_COMBINED_TEXTURE_IMAGE_UNITS: + case GL_MAX_CUBE_MAP_TEXTURE_SIZE: + //case GL_MAX_FRAGMENT_UNIFORM_VECTORS: + //case GL_MAX_RENDERBUFFER_SIZE: + case GL_MAX_TEXTURE_IMAGE_UNITS: + case GL_MAX_TEXTURE_SIZE: + //case GL_MAX_VARYING_VECTORS: + case GL_MAX_VERTEX_ATTRIBS: + case GL_MAX_VERTEX_TEXTURE_IMAGE_UNITS: + case GL_MAX_VERTEX_UNIFORM_VECTORS: + case GL_NUM_COMPRESSED_TEXTURE_FORMATS: + case GL_PACK_ALIGNMENT: + case GL_RED_BITS: + case GL_SAMPLE_BUFFERS: + case GL_SAMPLES: + case GL_SCISSOR_TEST: + case GL_SHADING_LANGUAGE_VERSION: + case GL_STENCIL_BACK_FAIL: + case GL_STENCIL_BACK_FUNC: + case GL_STENCIL_BACK_PASS_DEPTH_FAIL: + case GL_STENCIL_BACK_PASS_DEPTH_PASS: + case GL_STENCIL_BACK_REF: + case GL_STENCIL_BACK_VALUE_MASK: + case GL_STENCIL_BACK_WRITEMASK: + case GL_STENCIL_BITS: + case GL_STENCIL_CLEAR_VALUE: + case GL_STENCIL_FAIL: + case GL_STENCIL_FUNC: + case GL_STENCIL_PASS_DEPTH_FAIL: + case GL_STENCIL_PASS_DEPTH_PASS: + case GL_STENCIL_REF: + case GL_STENCIL_VALUE_MASK: + case GL_STENCIL_WRITEMASK: + case GL_SUBPIXEL_BITS: + case GL_UNPACK_ALIGNMENT: + //case GL_UNPACK_COLORSPACE_CONVERSION_WEBGL: + ints = 1; + break; + + case GL_VENDOR: + case GL_VERSION: + case GL_RENDERER: + strings = 1; + break; + + } //switch pname + + if (ints==1) { + + int val; + glGetIntegerv(pname,&val); + + return alloc_int(val); + + } else if (strings==1) { + + return alloc_string((const char *)glGetString(pname)); + + } else if (floats==1) { + + float f; + glGetFloatv(pname,&f); + + return alloc_float(f); + + } else if (ints>0) { + + int vals[4]; + glGetIntegerv(pname,vals); + value result = alloc_array(ints); + + for(int i=0;i0) { + + float vals[4]; + glGetFloatv(pname,vals); + value result = alloc_array(ints); + + for(int i=0;i 0) { + + int buffer[4]; + glGetUniformiv(id,loc,buffer); + + value result = alloc_array( ints+bools ); + + for(int i=0;i0) { + + float buffer[16*3]; + glGetUniformfv(id,loc,buffer); + + value result = alloc_array( floats ); + + for(int i=0;i>2 ,trans,data); + case 3: glUniformMatrix3fv(loc,nbElems/9 ,trans,data); + case 4: glUniformMatrix4fv(loc,nbElems>>4 ,trans,data); + } + + return alloc_null(); + } DEFINE_PRIM(lime_gl_uniform_matrix,4); + + + #define GL_UNFORM_1(TYPE,GET) \ + value lime_gl_uniform1##TYPE(value inLocation, value inV0) \ + { \ + glUniform1##TYPE(val_int(inLocation),GET(inV0)); \ + return alloc_null(); \ + } DEFINE_PRIM(lime_gl_uniform1##TYPE,2); + + #define GL_UNFORM_2(TYPE,GET) \ + value lime_gl_uniform2##TYPE(value inLocation, value inV0,value inV1) \ + { \ + glUniform2##TYPE(val_int(inLocation),GET(inV0),GET(inV1)); \ + return alloc_null(); \ + } DEFINE_PRIM(lime_gl_uniform2##TYPE,3); + + #define GL_UNFORM_3(TYPE,GET) \ + value lime_gl_uniform3##TYPE(value inLocation, value inV0,value inV1,value inV2) \ + { \ + glUniform3##TYPE(val_int(inLocation),GET(inV0),GET(inV1),GET(inV2)); \ + return alloc_null(); \ + } DEFINE_PRIM(lime_gl_uniform3##TYPE,4); + + #define GL_UNFORM_4(TYPE,GET) \ + value lime_gl_uniform4##TYPE(value inLocation, value inV0,value inV1,value inV2,value inV3) \ + { \ + glUniform4##TYPE(val_int(inLocation),GET(inV0),GET(inV1),GET(inV2),GET(inV3)); \ + return alloc_null(); \ + } DEFINE_PRIM(lime_gl_uniform4##TYPE,5); + + GL_UNFORM_1(i,val_int) + GL_UNFORM_1(f,val_number) + GL_UNFORM_2(i,val_int) + GL_UNFORM_2(f,val_number) + GL_UNFORM_3(i,val_int) + GL_UNFORM_3(f,val_number) + GL_UNFORM_4(i,val_int) + GL_UNFORM_4(f,val_number) + + value lime_gl_uniform1iv(value inLocation,value inByteBuffer) { + + int loc = val_int(inLocation); + + ByteArray bytes(inByteBuffer); + int size = bytes.Size(); + const int *data = (int *)bytes.Bytes(); + int nbElems = size / sizeof(int); + + glUniform1iv(loc,nbElems,data); + + return alloc_null(); + + } DEFINE_PRIM(lime_gl_uniform1iv,2); + + + value lime_gl_uniform2iv(value inLocation,value inByteBuffer) { + + int loc = val_int(inLocation); + + ByteArray bytes(inByteBuffer); + int size = bytes.Size(); + const int *data = (int *)bytes.Bytes(); + int nbElems = size / sizeof(int); + + glUniform2iv(loc,nbElems>>1,data); + + return alloc_null(); + + } DEFINE_PRIM(lime_gl_uniform2iv,2); + + + value lime_gl_uniform3iv(value inLocation,value inByteBuffer) { + + int loc = val_int(inLocation); + + ByteArray bytes(inByteBuffer); + int size = bytes.Size(); + const int *data = (int *)bytes.Bytes(); + int nbElems = size / sizeof(int); + + glUniform3iv(loc,nbElems/3,data); + + return alloc_null(); + + } DEFINE_PRIM(lime_gl_uniform3iv,2); + + + value lime_gl_uniform4iv(value inLocation,value inByteBuffer) { + + int loc = val_int(inLocation); + + ByteArray bytes(inByteBuffer); + int size = bytes.Size(); + const int *data = (int *)bytes.Bytes(); + int nbElems = size / sizeof(int); + + glUniform4iv(loc,nbElems>>2,data); + + return alloc_null(); + + } DEFINE_PRIM(lime_gl_uniform4iv,2); + + + value lime_gl_uniform1fv(value inLocation,value inByteBuffer) { + + int loc = val_int(inLocation); + + ByteArray bytes(inByteBuffer); + int size = bytes.Size(); + const float *data = (float *)bytes.Bytes(); + int nbElems = size / sizeof(float); + + glUniform1fv(loc,nbElems,data); + + return alloc_null(); + + } DEFINE_PRIM(lime_gl_uniform1fv,2); + + + value lime_gl_uniform2fv(value inLocation,value inByteBuffer) { + + int loc = val_int(inLocation); + + ByteArray bytes(inByteBuffer); + int size = bytes.Size(); + const float *data = (float *)bytes.Bytes(); + int nbElems = size / sizeof(float); + + glUniform2fv(loc,nbElems>>1,data); + + return alloc_null(); + + } DEFINE_PRIM(lime_gl_uniform2fv,2); + + + value lime_gl_uniform3fv(value inLocation,value inByteBuffer) { + + int loc = val_int(inLocation); + + ByteArray bytes(inByteBuffer); + int size = bytes.Size(); + const float *data = (float *)bytes.Bytes(); + int nbElems = size / sizeof(float); + + glUniform3fv(loc,nbElems/3,data); + + return alloc_null(); + + } DEFINE_PRIM(lime_gl_uniform3fv,2); + + + value lime_gl_uniform4fv(value inLocation,value inByteBuffer) { + + int loc = val_int(inLocation); + + ByteArray bytes(inByteBuffer); + int size = bytes.Size(); + const float *data = (float *)bytes.Bytes(); + int nbElems = size / sizeof(float); + + glUniform4fv(loc,nbElems>>2,data); + + return alloc_null(); + + } DEFINE_PRIM(lime_gl_uniform4fv,2); + + // Attrib + + value lime_gl_vertex_attrib1f(value inLocation, value inV0) { + + glVertexAttrib1f(val_int(inLocation),val_number(inV0)); + + return alloc_null(); + + } DEFINE_PRIM(lime_gl_vertex_attrib1f,2); + + + value lime_gl_vertex_attrib2f(value inLocation, value inV0,value inV1) { + + glVertexAttrib2f(val_int(inLocation),val_number(inV0),val_number(inV1)); + + return alloc_null(); + + } DEFINE_PRIM(lime_gl_vertex_attrib2f,3); + + + value lime_gl_vertex_attrib3f(value inLocation, value inV0,value inV1,value inV2) { + + glVertexAttrib3f(val_int(inLocation),val_number(inV0),val_number(inV1),val_number(inV2)); + + return alloc_null(); + + } DEFINE_PRIM(lime_gl_vertex_attrib3f,4); + + + value lime_gl_vertex_attrib4f(value inLocation, value inV0,value inV1,value inV2, value inV3) { + + glVertexAttrib4f(val_int(inLocation),val_number(inV0),val_number(inV1),val_number(inV2),val_number(inV3)); + + return alloc_null(); + + } DEFINE_PRIM(lime_gl_vertex_attrib4f,5); + + + value lime_gl_vertex_attrib1fv(value inLocation,value inByteBuffer) { + + int loc = val_int(inLocation); + + ByteArray bytes(inByteBuffer); + int size = bytes.Size(); + const float *data = (float *)bytes.Bytes(); + + glVertexAttrib1fv(loc,data); + + return alloc_null(); + + } DEFINE_PRIM(lime_gl_vertex_attrib1fv,2); + + + value lime_gl_vertex_attrib2fv(value inLocation,value inByteBuffer) { + + int loc = val_int(inLocation); + + ByteArray bytes(inByteBuffer); + int size = bytes.Size(); + const float *data = (float *)bytes.Bytes(); + + glVertexAttrib2fv(loc,data); + + return alloc_null(); + + } DEFINE_PRIM(lime_gl_vertex_attrib2fv,2); + + + value lime_gl_vertex_attrib3fv(value inLocation,value inByteBuffer) { + + int loc = val_int(inLocation); + + ByteArray bytes(inByteBuffer); + int size = bytes.Size(); + const float *data = (float *)bytes.Bytes(); + + glVertexAttrib3fv(loc,data); + + return alloc_null(); + + } DEFINE_PRIM(lime_gl_vertex_attrib3fv,2); + + + value lime_gl_vertex_attrib4fv(value inLocation,value inByteBuffer) { + + int loc = val_int(inLocation); + + ByteArray bytes(inByteBuffer); + int size = bytes.Size(); + const float *data = (float *)bytes.Bytes(); + + glVertexAttrib4fv(loc,data); + + return alloc_null(); + + } DEFINE_PRIM(lime_gl_vertex_attrib4fv,2); + + +// --- Shader ------------------------------------------- + + + value lime_gl_create_shader(value inType) { + + return alloc_int(glCreateShader(val_int(inType))); + + } DEFINE_PRIM(lime_gl_create_shader,1); + + + value lime_gl_delete_shader(value inId) { + + int id = val_int(inId); + + glDeleteShader(id); + + return alloc_null(); + + } DEFINE_PRIM(lime_gl_delete_shader,1); + + + value lime_gl_shader_source(value inId,value inSource) { + + int id = val_int(inId); + const char *source = val_string(inSource); + + glShaderSource(id,1,&source,0); + + return alloc_null(); + + } DEFINE_PRIM(lime_gl_shader_source,2); + + + value lime_gl_attach_shader(value inProg,value inShader) { + + glAttachShader(val_int(inProg),val_int(inShader)); + + return alloc_null(); + + } DEFINE_PRIM(lime_gl_attach_shader,2); + + + value lime_gl_detach_shader(value inProg,value inShader) { + + glDetachShader(val_int(inProg),val_int(inShader)); + + return alloc_null(); + + } DEFINE_PRIM(lime_gl_detach_shader,2); + + + value lime_gl_compile_shader(value inId) { + + int id = val_int(inId); + + glCompileShader(id); + + return alloc_null(); + + } DEFINE_PRIM(lime_gl_compile_shader,1); + + + value lime_gl_get_shader_parameter(value inId,value inName) { + + int id = val_int(inId); + int result = 0; + + glGetShaderiv(id,val_int(inName), & result); + + return alloc_int(result); + + } DEFINE_PRIM(lime_gl_get_shader_parameter,2); + + + value lime_gl_get_shader_info_log(value inId) { + + int id = val_int(inId); + char buf[1024] = ""; + + glGetShaderInfoLog(id,1024,0,buf); + + return alloc_string(buf); + + } DEFINE_PRIM(lime_gl_get_shader_info_log,1); + + + value lime_gl_get_shader_source(value inId) { + + int id = val_int(inId); + + int len = 0; + glGetShaderiv(id,GL_SHADER_SOURCE_LENGTH,&len); + + if (len==0) { + return alloc_null(); + } + + char *buf = new char[len+1]; + glGetShaderSource(id,len+1,0,buf); + value result = alloc_string(buf); + + delete [] buf; + + return result; + + } DEFINE_PRIM(lime_gl_get_shader_source,1); + + + value lime_gl_get_shader_precision_format(value inShader,value inPrec) { + + #ifdef lime_GLES + + int range[2]; + int precision; + + glGetShaderPrecisionFormat(val_int(inShader), val_int(inPrec), range, &precision); + + value result = alloc_empty_object(); + + alloc_field(result,val_id("rangeMin"),alloc_int(range[0])); + alloc_field(result,val_id("rangeMax"),alloc_int(range[1])); + alloc_field(result,val_id("precision"),alloc_int(precision)); + + return result; + + #else + + return alloc_null(); + + #endif + + } DEFINE_PRIM(lime_gl_get_shader_precision_format,2); + + +// --- Buffer ------------------------------------------- + + + value lime_gl_create_buffer() { + + GLuint buffers; + + glGenBuffers(1,&buffers); + + return alloc_int(buffers); + + } DEFINE_PRIM(lime_gl_create_buffer,0); + + + value lime_gl_delete_buffer(value inId) { + + GLuint id = val_int(inId); + + glDeleteBuffers(1,&id); + + return alloc_null(); + + } DEFINE_PRIM(lime_gl_delete_buffer,1); + + + value lime_gl_bind_buffer(value inTarget, value inId ) { + + glBindBuffer(val_int(inTarget),val_int(inId)); + + return alloc_null(); + + } DEFINE_PRIM(lime_gl_bind_buffer,2); + + + value lime_gl_buffer_data(value inTarget, value inByteBuffer, value inStart, value inLen, value inUsage) { + + int len = val_int(inLen); + int start = val_int(inStart); + + ByteArray bytes(inByteBuffer); + const unsigned char *data = bytes.Bytes(); + int size = bytes.Size(); + + if (len+start>size) { + val_throw(alloc_string("Invalid byte length")); + } + + glBufferData(val_int(inTarget), len, data + start, val_int(inUsage) ); + + return alloc_null(); + + } DEFINE_PRIM(lime_gl_buffer_data,5); + + + value lime_gl_buffer_sub_data(value inTarget, value inOffset, value inByteBuffer, value inStart, value inLen) { + + int len = val_int(inLen); + int start = val_int(inStart); + + ByteArray bytes(inByteBuffer); + + const unsigned char *data = bytes.Bytes(); + int size = bytes.Size(); + + if (len+start>size) { + val_throw(alloc_string("Invalid byte length")); + } + + glBufferSubData(val_int(inTarget), val_int(inOffset), len, data + start ); + + return alloc_null(); + + } DEFINE_PRIM(lime_gl_buffer_sub_data,5); + + + value lime_gl_get_vertex_attrib_offset(value index, value name) { + + int result = 0; + + glGetVertexAttribPointerv(val_int(index), val_int(name), (void **)&result); + + return alloc_int(result); + + } DEFINE_PRIM(lime_gl_get_vertex_attrib_offset,2); + + + value lime_gl_get_vertex_attrib(value index, value name) { + + int result = 0; + + glGetVertexAttribiv(val_int(index), val_int(name), &result); + + return alloc_int(result); + + } DEFINE_PRIM(lime_gl_get_vertex_attrib,2); + + + value lime_gl_vertex_attrib_pointer(value *arg, int nargs) { + + enum { aIndex, aSize, aType, aNormalized, aStride, aOffset, aSIZE }; + + glVertexAttribPointer( val_int(arg[aIndex]), + val_int(arg[aSize]), + val_int(arg[aType]), + val_bool(arg[aNormalized]), + val_int(arg[aStride]), + (void *)(intptr_t)val_int(arg[aOffset]) ); + + return alloc_null(); + + } DEFINE_PRIM_MULT(lime_gl_vertex_attrib_pointer); + + + value lime_gl_enable_vertex_attrib_array(value inIndex) { + + glEnableVertexAttribArray(val_int(inIndex)); + + return alloc_null(); + + } DEFINE_PRIM(lime_gl_enable_vertex_attrib_array,1); + + + value lime_gl_disable_vertex_attrib_array(value inIndex) { + + glDisableVertexAttribArray(val_int(inIndex)); + + return alloc_null(); + + } DEFINE_PRIM(lime_gl_disable_vertex_attrib_array,1); + + + value lime_gl_get_buffer_paramerter(value inTarget, value inPname) { + + int result = 0; + + glGetBufferParameteriv(val_int(inTarget), val_int(inPname),&result); + + return alloc_int(result); + + } DEFINE_PRIM(lime_gl_get_buffer_paramerter,2); + + + value lime_gl_get_buffer_parameter(value inTarget, value inIndex) { + + GLint data = 0; + + glGetBufferParameteriv(val_int(inTarget), val_int(inIndex), &data); + + return alloc_int(data); + + } DEFINE_PRIM(lime_gl_get_buffer_parameter,2); + + +// --- Framebuffer ------------------------------- + + + value lime_gl_bind_framebuffer(value target, value framebuffer) { + + if (HAS_EXT_framebuffer_object) { + glBindFramebuffer(val_int(target), val_int(framebuffer) ); + } + + return alloc_null(); + + } DEFINE_PRIM(lime_gl_bind_framebuffer,2); + + + value lime_gl_bind_renderbuffer(value target, value renderbuffer) { + + if( HAS_EXT_framebuffer_object ) { + glBindRenderbuffer(val_int(target),val_int(renderbuffer)); + } + + return alloc_null(); + + } DEFINE_PRIM(lime_gl_bind_renderbuffer,2); + + + value lime_gl_create_framebuffer() { + + GLuint id = 0; + + if( HAS_EXT_framebuffer_object ) { + glGenFramebuffers( 1, &id ); + } + + return alloc_int(id); + + } DEFINE_PRIM(lime_gl_create_framebuffer,0); + + + value lime_gl_delete_framebuffer(value target) { + + GLuint id = val_int(target); + + if (HAS_EXT_framebuffer_object) { + glDeleteFramebuffers(1, &id); + } + + return alloc_null(); + + } DEFINE_PRIM(lime_gl_delete_framebuffer,1); + + + value lime_gl_create_render_buffer( ) { + + GLuint id = 0; + + if( HAS_EXT_framebuffer_object ) { + glGenRenderbuffers(1,&id); + } + + return alloc_int(id); + + } DEFINE_PRIM(lime_gl_create_render_buffer,0); + + + value lime_gl_delete_render_buffer(value target) { + + GLuint id = val_int(target); + + if( HAS_EXT_framebuffer_object ) { + glDeleteRenderbuffers(1, &id); + } + + return alloc_null(); + + } DEFINE_PRIM(lime_gl_delete_render_buffer,1); + + + value lime_gl_framebuffer_renderbuffer(value target, value attachment, value renderbuffertarget, value renderbuffer) { + + if( HAS_EXT_framebuffer_object ) { + glFramebufferRenderbuffer(val_int(target), val_int(attachment), val_int(renderbuffertarget), val_int(renderbuffer) ); + } + + return alloc_null(); + + } DEFINE_PRIM(lime_gl_framebuffer_renderbuffer,4); + + + value lime_gl_framebuffer_texture2D(value target, value attachment, value textarget, value texture, value level) { + + if( HAS_EXT_framebuffer_object ) { + glFramebufferTexture2D( val_int(target), val_int(attachment), val_int(textarget), val_int(texture), val_int(level) ); + } + + return alloc_null(); + + } DEFINE_PRIM(lime_gl_framebuffer_texture2D,5); + + + value lime_gl_renderbuffer_storage(value target, value internalFormat, value width, value height) { + + if( HAS_EXT_framebuffer_object ) { + glRenderbufferStorage( val_int(target), val_int(internalFormat), val_int(width), val_int(height) ); + } + + return alloc_null(); + + } DEFINE_PRIM(lime_gl_renderbuffer_storage,4); + + + value lime_gl_check_framebuffer_status(value inTarget) { + + if( HAS_EXT_framebuffer_object ) { + return alloc_int( glCheckFramebufferStatus(val_int(inTarget)) ); + } + + return alloc_int(0); + + } DEFINE_PRIM(lime_gl_check_framebuffer_status,1); + + + value lime_gl_get_framebuffer_attachment_parameter(value target, value attachment, value pname) { + + GLint result = 0; + + if( HAS_EXT_framebuffer_object ) { + glGetFramebufferAttachmentParameteriv( val_int(target), val_int(attachment), val_int(pname), &result); + } + + return alloc_int(result); + + } DEFINE_PRIM(lime_gl_get_framebuffer_attachment_parameter,3); + + + value lime_gl_get_render_buffer_parameter(value target, value pname) { + + int result = 0; + + if( HAS_EXT_framebuffer_object ) { + glGetRenderbufferParameteriv(val_int(target), val_int(pname), &result); + } + + return alloc_int(result); + + } DEFINE_PRIM(lime_gl_get_render_buffer_parameter,2); + + +// --- Drawing ------------------------------- + + + value lime_gl_draw_arrays(value inMode, value inFirst, value inCount) { + + glDrawArrays( val_int(inMode), val_int(inFirst), val_int(inCount) ); + + return alloc_null(); + + } DEFINE_PRIM(lime_gl_draw_arrays,3); + + + value lime_gl_draw_elements(value inMode, value inCount, value inType, value inOffset) { + + glDrawElements( val_int(inMode), val_int(inCount), val_int(inType), (void *)(intptr_t)val_int(inOffset) ); + + return alloc_null(); + + } DEFINE_PRIM(lime_gl_draw_elements,4); + + + +// --- Viewports ------------------------------- + + + + value lime_gl_viewport(value inX, value inY, value inW,value inH) { + + glViewport(val_int(inX),val_int(inY),val_int(inW),val_int(inH)); + + return alloc_null(); + + } DEFINE_PRIM(lime_gl_viewport,4); + + + value lime_gl_scissor(value inX, value inY, value inW,value inH) { + + glScissor(val_int(inX),val_int(inY),val_int(inW),val_int(inH)); + + return alloc_null(); + + } DEFINE_PRIM(lime_gl_scissor,4); + + + value lime_gl_clear(value inMask) { + + glClear(val_int(inMask)); + + return alloc_null(); + + } DEFINE_PRIM(lime_gl_clear,1); + + + value lime_gl_clear_color(value r,value g, value b, value a) { + + glClearColor(val_number(r),val_number(g),val_number(b),val_number(a)); + + return alloc_null(); + + } DEFINE_PRIM(lime_gl_clear_color,4); + + + value lime_gl_clear_depth(value depth) { + + #ifdef lime_GLES + glClearDepthf(val_number(depth)); + #else + glClearDepth(val_number(depth)); + #endif + + return alloc_null(); + + } DEFINE_PRIM(lime_gl_clear_depth,1); + + + value lime_gl_clear_stencil(value stencil) { + + glClearStencil(val_int(stencil)); + + return alloc_null(); + + } DEFINE_PRIM(lime_gl_clear_stencil,1); + + + value lime_gl_color_mask(value r,value g, value b, value a) { + + glColorMask(val_bool(r),val_bool(g),val_bool(b),val_bool(a)); + + return alloc_null(); + + } DEFINE_PRIM(lime_gl_color_mask,4); + + + value lime_gl_depth_func(value func) { + + glDepthFunc(val_int(func)); + + return alloc_null(); + + } DEFINE_PRIM(lime_gl_depth_func,1); + + + value lime_gl_depth_mask(value mask) { + + glDepthMask(val_bool(mask)); + + return alloc_null(); + + } DEFINE_PRIM(lime_gl_depth_mask,1); + + + value lime_gl_depth_range(value inNear, value inFar) { + + #ifdef lime_GLES + glDepthRangef(val_number(inNear), val_number(inFar)); + #else + glDepthRange(val_number(inNear), val_number(inFar)); + #endif + + return alloc_null(); + + } DEFINE_PRIM(lime_gl_depth_range,2); + + + value lime_gl_cull_face(value mode) { + + glCullFace(val_int(mode)); + + return alloc_null(); + + } DEFINE_PRIM(lime_gl_cull_face,1); + + + value lime_gl_polygon_offset(value factor, value units) { + + glPolygonOffset(val_number(factor), val_number(units)); + + return alloc_null(); + + } DEFINE_PRIM(lime_gl_polygon_offset,2); + + + value lime_gl_read_pixels(value *arg, int argCount) { + + enum { aX, aY, aWidth, aHeight, aFormat, aType, aBuffer, aOffset }; + + unsigned char *data = 0; + ByteArray bytes( arg[aBuffer] ); + + if (bytes.mValue) { + data = bytes.Bytes() + val_int(arg[aOffset]); + } + + glReadPixels( INT(aX), INT(aY), + INT(aWidth), INT(aHeight), + INT(aFormat), INT(aType), + data ); + + return alloc_null(); + + } DEFINE_PRIM_MULT(lime_gl_read_pixels); + + + value lime_gl_pixel_storei(value pname, value param) { + + glPixelStorei(val_int(pname), val_int(param)); + + return alloc_null(); + + } DEFINE_PRIM(lime_gl_pixel_storei,2); + + + value lime_gl_sample_coverage(value f, value invert) { + + glSampleCoverage(val_number(f), val_bool(invert)); + + return alloc_null(); + + } DEFINE_PRIM(lime_gl_sample_coverage,2); + + + +// --- Texture ------------------------------------------- + + + + value lime_gl_create_texture() { + + unsigned int id = 0; + glGenTextures(1,&id); + + return alloc_int(id); + + } DEFINE_PRIM(lime_gl_create_texture,0); + + + value lime_gl_active_texture(value inSlot) { + + glActiveTexture( val_int(inSlot) ); + + return alloc_null(); + + } DEFINE_PRIM(lime_gl_active_texture,1); + + + value lime_gl_delete_texture(value inId) { + + GLuint id = val_int(inId); + glDeleteTextures(1,&id); + + return alloc_null(); + + } DEFINE_PRIM(lime_gl_delete_texture,1); + + + value lime_gl_bind_texture(value inTarget, value inTexture) { + + glBindTexture(val_int(inTarget), val_int(inTexture) ); + + return alloc_null(); + + } DEFINE_PRIM(lime_gl_bind_texture,2); + + + value lime_gl_tex_image_2d(value *arg, int argCount) { + + enum { aTarget, aLevel, aInternal, aWidth, aHeight, aBorder, aFormat, aType, aBuffer, aOffset }; + + unsigned char *data = 0; + + ByteArray bytes( arg[aBuffer] ); + + if (!val_is_null(bytes.mValue)) { + data = bytes.Bytes() + val_int(arg[aOffset]); + } + + glTexImage2D(INT(aTarget), INT(aLevel), INT(aInternal), + INT(aWidth), INT(aHeight), INT(aBorder), + INT(aFormat), INT(aType), data ); + + return alloc_null(); + + } DEFINE_PRIM_MULT(lime_gl_tex_image_2d); + + + value lime_gl_tex_sub_image_2d(value *arg, int argCount) { + + enum { aTarget, aLevel, aXOffset, aYOffset, aWidth, aHeight, aFormat, aType, aBuffer, aOffset }; + + unsigned char *data = 0; + ByteArray bytes( arg[aBuffer] ); + + if (bytes.mValue) { + data = bytes.Bytes() + val_int(arg[aOffset]); + } + + glTexSubImage2D( INT(aTarget), INT(aLevel), + INT(aXOffset), INT(aYOffset), + INT(aWidth), INT(aHeight), + INT(aFormat), INT(aType), + data ); + + return alloc_null(); + + } DEFINE_PRIM_MULT(lime_gl_tex_sub_image_2d); + + + value lime_gl_compressed_tex_image_2d(value *arg, int argCount) { + + enum { aTarget, aLevel, aInternal, aWidth, aHeight, aBorder, aBuffer, aOffset }; + + unsigned char *data = 0; + int size = 0; + + ByteArray bytes( arg[aBuffer] ); + + if (!val_is_null(bytes.mValue)) { + data = bytes.Bytes() + INT(aOffset); + size = bytes.Size() - INT(aOffset); + } + + glCompressedTexImage2D(INT(aTarget), INT(aLevel), INT(aInternal), + INT(aWidth), INT(aHeight), INT(aBorder), + size, data ); + + return alloc_null(); + + } DEFINE_PRIM_MULT(lime_gl_compressed_tex_image_2d); + + + value lime_gl_compressed_tex_sub_image_2d(value *arg, int argCount) { + + enum { aTarget, aLevel, aXOffset, aYOffset, aWidth, aHeight, aFormat, aBuffer, aOffset }; + + unsigned char *data = 0; + int size = 0; + + ByteArray bytes( arg[aBuffer] ); + + if (!val_is_null(bytes.mValue)) { + data = bytes.Bytes() + INT(aOffset); + size = bytes.Size() - INT(aOffset); + } + + glCompressedTexSubImage2D(INT(aTarget), INT(aLevel), INT(aXOffset), INT(aYOffset), + INT(aWidth), INT(aHeight), INT(aFormat), + size, data ); + + return alloc_null(); + + } DEFINE_PRIM_MULT(lime_gl_compressed_tex_sub_image_2d); + + + value lime_gl_tex_parameterf(value inTarget, value inPName, value inVal) { + + glTexParameterf(val_int(inTarget), val_int(inPName), val_number(inVal) ); + + return alloc_null(); + + } DEFINE_PRIM(lime_gl_tex_parameterf,3); + + + value lime_gl_tex_parameteri(value inTarget, value inPName, value inVal) { + + glTexParameterf(val_int(inTarget), val_int(inPName), val_int(inVal) ); + + return alloc_null(); + + } DEFINE_PRIM(lime_gl_tex_parameteri,3); + + + value lime_gl_copy_tex_image_2d(value *arg, int argCount) { + + enum { aTarget, aLevel, aInternalFormat, aX, aY, aWidth, aHeight, aBorder }; + + glCopyTexImage2D( INT(aTarget), INT(aLevel), INT(aInternalFormat), + INT(aX), INT(aY), INT(aWidth), INT(aHeight), INT(aBorder) ); + + return alloc_null(); + + } DEFINE_PRIM_MULT(lime_gl_copy_tex_image_2d); + + + value lime_gl_copy_tex_sub_image_2d(value *arg, int argCount) { + + enum { aTarget, aLevel, aXOffset, aYOffset, aX, aY, aWidth, aHeight }; + + glCopyTexSubImage2D( INT(aTarget), INT(aLevel), INT(aXOffset), INT(aYOffset), + INT(aX), INT(aY), INT(aWidth), INT(aHeight) ); + + return alloc_null(); + + } DEFINE_PRIM_MULT(lime_gl_copy_tex_sub_image_2d); + + + value lime_gl_generate_mipmap(value inTarget) { + + //:todo: no fail safe + glGenerateMipmap(val_int(inTarget)); + + return alloc_null(); + + } DEFINE_PRIM(lime_gl_generate_mipmap,1); + + + value lime_gl_get_tex_parameter(value inTarget,value inPname) { + + int result = 0; + glGetTexParameteriv(val_int(inTarget), val_int(inPname), &result); + + return alloc_int(result); + + } DEFINE_PRIM(lime_gl_get_tex_parameter,2); + + + void *gOGLLibraryHandle; + bool extentions_init = false; + + bool InitOpenGLBindings () + { + static bool result = true; + if (!extentions_init) + { + extentions_init = true; + + #ifdef HX_LINUX + gOGLLibraryHandle = dlopen("libGL.so.1", RTLD_NOW|RTLD_GLOBAL); + if (!gOGLLibraryHandle) + gOGLLibraryHandle = dlopen("libGL.so", RTLD_NOW|RTLD_GLOBAL); + if (!gOGLLibraryHandle) + { + //printf("Could not load %s (%s)\n",path, dlerror()); + result = false; + return result; + } + #endif + + #ifdef NEED_EXTENSIONS + #define GET_EXTENSION + #include "OpenGLExtensions.h" + #undef DEFINE_EXTENSION + #endif + } + return result; + } + + +} //namespace lime + + +extern "C" int lime_opengl_register_prims () { + return 0; +} diff --git a/project/src/graphics/opengl/OpenGLExtensions.h b/project/src/graphics/opengl/OpenGLExtensions.h new file mode 100644 index 000000000..aee4a390a --- /dev/null +++ b/project/src/graphics/opengl/OpenGLExtensions.h @@ -0,0 +1,263 @@ +#ifndef GL_UNSIGNED_SHORT_4_4_4_4 +#define GL_UNSIGNED_SHORT_4_4_4_4 0x8033 +#define GL_UNSIGNED_SHORT_5_6_5 0x8363 +#endif + + +#ifdef HX_WINDOWS +#define CALLING_CONVENTION APIENTRY +#else +#define CALLING_CONVENTION APIENTRY +#endif + + +#ifdef DECLARE_EXTENSION + +namespace lime { extern void *gOGLLibraryHandle; } + +#define OGL_EXT(func,ret,args) \ + namespace lime { ret (CALLING_CONVENTION *func)args; } + +#elif defined(DEFINE_EXTENSION) + +#define OGL_EXT(func,ret,args) \ + namespace lime { ret (CALLING_CONVENTION *func)args=0; } + +#elif defined(GET_EXTENSION) + +#ifdef HX_WINDOWS + #define OGL_EXT(func,ret,args) \ + {\ + *(void **)&lime::func = (void *)wglGetProcAddress(#func);\ + if (!func) \ + *(void **)&lime::func = (void *)wglGetProcAddress(#func "ARB");\ + } +#elif defined(HX_LINUX) + #define OGL_EXT(func,ret,args) \ + {\ + *(void **)&lime::func = (void *)dlsym(lime::gOGLLibraryHandle,#func);\ + if (!func) \ + *(void **)&lime::func = (void *)dlsym(lime::gOGLLibraryHandle,#func "ARB");\ + } +#endif + +#endif + +OGL_EXT(glBindBuffer,void,(GLenum,GLuint)); +OGL_EXT(glDeleteBuffers,void,(GLsizei,const GLuint *)); +OGL_EXT(glGenBuffers,void,(GLsizei,GLuint*)); +OGL_EXT(glBufferData,void,(GLenum,GLuint,const void *, GLenum)); +OGL_EXT(glCreateShader,GLuint,(GLenum)); +OGL_EXT(glGetUniformLocation,GLint,(GLuint,const char *)); +OGL_EXT(glUniform4f,void,(GLint,float,float,float,float)); +OGL_EXT(glUniformMatrix2fv,void,(GLint,GLsizei,GLboolean,const float *)); +OGL_EXT(glUniformMatrix3fv,void,(GLint,GLsizei,GLboolean,const float *)); +OGL_EXT(glUniformMatrix4fv,void,(GLint,GLsizei,GLboolean,const float *)); +OGL_EXT(glDeleteShader,void,(GLint)); +OGL_EXT(glDeleteProgram,void,(GLint)); +OGL_EXT(glGetAttribLocation,GLint,(GLuint,const char *)); +OGL_EXT(glShaderSource,void,(GLuint,GLsizei,const char **, const GLint *)); +OGL_EXT(glDisableVertexAttribArray,void,(GLuint)); +OGL_EXT(glEnableVertexAttribArray,void,(GLuint)); +OGL_EXT(glAttachShader,void,(GLuint,GLuint)); +OGL_EXT(glCreateProgram,GLuint,()); +OGL_EXT(glCompileShader,void,(GLuint)); +OGL_EXT(glLinkProgram,void,(GLuint)); +OGL_EXT(glGetShaderiv,void,(GLuint,GLenum,GLint *)); +OGL_EXT(glValidateProgram,void,(GLuint)); +OGL_EXT(glGetShaderInfoLog,void,(GLuint,GLsizei,GLsizei *,char *)); +OGL_EXT(glGetProgramiv,void,(GLuint,GLenum,GLint *)); +OGL_EXT(glGetProgramInfoLog,void,(GLuint,GLsizei,GLsizei *,char *)); +OGL_EXT(glUseProgram,void,(GLuint)); +OGL_EXT(glUniform1i,void,(GLuint,GLint)); +OGL_EXT(glVertexAttribPointer,void,(GLuint,GLint,GLenum,GLboolean,GLsizei,const void *)); +OGL_EXT(glActiveTexture,void,(GLenum)); + +OGL_EXT(glIsBuffer,GLboolean,(GLuint)); +OGL_EXT(glIsFramebuffer,GLboolean,(GLuint)); +OGL_EXT(glIsRenderbuffer,GLboolean,(GLuint)); +OGL_EXT(glBlendColor,void,(GLclampf, GLclampf, GLclampf, GLclampf)); +OGL_EXT(glBlendEquation,void,(GLenum)); +OGL_EXT(glBlendFuncSeparate,void,(GLenum, GLenum, GLenum, GLenum)); +OGL_EXT(glBufferSubData,void,(GLenum, GLintptr, GLsizeiptr, const GLvoid *)); +OGL_EXT(glGetBufferParameteriv,void,(GLenum, GLenum, GLint *)); +OGL_EXT(glBindFramebuffer,void,(GLenum, GLuint)); +OGL_EXT(glGenFramebuffers,void,(GLsizei, GLuint *)); +OGL_EXT(glDeleteFramebuffers,void,(GLsizei, GLuint *)); +OGL_EXT(glBindRenderbuffer,void,(GLenum, GLuint)); +OGL_EXT(glFramebufferRenderbuffer,void,(GLenum, GLenum, GLenum, GLuint)); +OGL_EXT(glFramebufferTexture2D,void,(GLenum, GLenum, GLenum, GLuint, GLint)); +OGL_EXT(glRenderbufferStorage,void,(GLenum, GLenum, GLsizei, GLsizei)); +OGL_EXT(glCheckFramebufferStatus,GLenum,(GLenum)); +OGL_EXT(glSampleCoverage,void,(GLclampf, GLboolean)); +OGL_EXT(glCompressedTexSubImage2D,void,(GLenum, GLint, GLint, GLint, GLsizei, GLsizei, GLenum, GLsizei, const GLvoid *)); +OGL_EXT(glCompressedTexImage2D,void,(GLenum, GLint, GLenum, GLsizei, GLsizei, GLint, GLsizei, const GLvoid *)); +OGL_EXT(glGenerateMipmap,void,(GLenum)); +OGL_EXT(glGenRenderbuffers,void,(GLsizei, GLuint *)); +OGL_EXT(glDeleteRenderbuffers,void,(GLsizei, GLuint *)); +OGL_EXT(glGetFramebufferAttachmentParameteriv,void,(GLenum, GLenum, GLenum, GLint *)); +OGL_EXT(glGetRenderbufferParameteriv,void,(GLenum, GLenum, GLint *)); + +OGL_EXT(glBlendEquationSeparate,void,(GLenum, GLenum)); +OGL_EXT(glDrawBuffers,void,(GLsizei, const GLenum *)); +OGL_EXT(glStencilOpSeparate,void,(GLenum, GLenum, GLenum, GLenum)); +OGL_EXT(glStencilFuncSeparate,void,(GLenum, GLenum, GLint, GLuint)); +OGL_EXT(glStencilMaskSeparate,void,(GLenum, GLuint)); +OGL_EXT(glBindAttribLocation,void,(GLuint, GLuint, const GLchar *)); +OGL_EXT(glDetachShader,void,(GLuint, GLuint)); +OGL_EXT(glGetActiveAttrib,void,(GLuint, GLuint, GLsizei, GLsizei *, GLint *, GLenum *, GLchar *)); +OGL_EXT(glGetActiveUniform,void,(GLuint, GLuint, GLsizei, GLsizei *, GLint *, GLenum *, GLchar *)); +OGL_EXT(glGetAttachedShaders,void,(GLuint, GLsizei, GLsizei *, GLuint *)); +OGL_EXT(glGetShaderSource,void,(GLuint, GLsizei, GLsizei *, GLchar *)); +OGL_EXT(glGetUniformfv,void,(GLuint, GLint, GLfloat *)); +OGL_EXT(glGetUniformiv,void,(GLuint, GLint, GLint *)); +OGL_EXT(glGetVertexAttribfv,void,(GLuint, GLenum, GLfloat *)); +OGL_EXT(glGetVertexAttribiv,void,(GLuint, GLenum, GLint *)); +OGL_EXT(glGetVertexAttribPointerv,void,(GLuint, GLenum, GLvoid* *)); +OGL_EXT(glIsProgram,GLboolean,(GLuint)); +OGL_EXT(glIsShader,GLboolean,(GLuint)); + +OGL_EXT(glUniform1f,void,(GLint, GLfloat)); +OGL_EXT(glUniform2f,void,(GLint, GLfloat, GLfloat)); +OGL_EXT(glUniform3f,void,(GLint, GLfloat, GLfloat, GLfloat)); +OGL_EXT(glUniform2i,void,(GLint, GLint, GLint)); +OGL_EXT(glUniform3i,void,(GLint, GLint, GLint, GLint)); +OGL_EXT(glUniform4i,void,(GLint, GLint, GLint, GLint, GLint)); +OGL_EXT(glUniform1fv,void,(GLint, GLsizei, const GLfloat *)); +OGL_EXT(glUniform2fv,void,(GLint, GLsizei, const GLfloat *)); +OGL_EXT(glUniform3fv,void,(GLint, GLsizei, const GLfloat *)); +OGL_EXT(glUniform4fv,void,(GLint, GLsizei, const GLfloat *)); +OGL_EXT(glUniform1iv,void,(GLint, GLsizei, const GLint *)); +OGL_EXT(glUniform2iv,void,(GLint, GLsizei, const GLint *)); +OGL_EXT(glUniform3iv,void,(GLint, GLsizei, const GLint *)); +OGL_EXT(glUniform4iv,void,(GLint, GLsizei, const GLint *)); + +OGL_EXT(glVertexAttrib1f,void,(GLuint, GLfloat)); +OGL_EXT(glVertexAttrib1fv,void,(GLuint, const GLfloat *)); +OGL_EXT(glVertexAttrib2f,void,(GLuint, GLfloat, GLfloat)); +OGL_EXT(glVertexAttrib2fv,void,(GLuint, const GLfloat *)); +OGL_EXT(glVertexAttrib3f,void,(GLuint, GLfloat, GLfloat, GLfloat)); +OGL_EXT(glVertexAttrib3fv,void,(GLuint, const GLfloat *)); +OGL_EXT(glVertexAttrib4f,void,(GLuint, GLfloat, GLfloat, GLfloat, GLfloat)); +OGL_EXT(glVertexAttrib4fv,void,(GLuint, const GLfloat *)); + +#ifdef DYNAMIC_OGL + +//OGL_EXT(glActiveTexture,void, (GLenum texture)); +OGL_EXT(glAlphaFunc,void, (GLenum func, GLclampf ref)); +//OGL_EXT(glAlphaFuncx,void, (GLenum func, GLclampx ref)); +OGL_EXT(glBindTexture,void, (GLenum target, GLuint texture)); +OGL_EXT(glBlendFunc,void, (GLenum sfactor, GLenum dfactor)); +OGL_EXT(glClear,void, (GLbitfield mask)); +OGL_EXT(glClearColor,void, (GLclampf red, GLclampf green, GLclampf blue, GLclampf alpha)); +//OGL_EXT(glClearColorx,void, (GLclampx red, GLclampx green, GLclampx blue, GLclampx alpha)); +OGL_EXT(glClearDepth,void, (GLclampf depth)); +//OGL_EXT(glClearDepthx,void, (GLclampx depth)); +OGL_EXT(glClearStencil,void, (GLint s)); +OGL_EXT(glClientActiveTexture,void, (GLenum texture)); +OGL_EXT(glColor4f,void, (GLfloat red, GLfloat green, GLfloat blue, GLfloat alpha)); +//OGL_EXT(glColor4x,void, (GLfixed red, GLfixed green, GLfixed blue, GLfixed alpha)); +OGL_EXT(glColorMask,void, (GLboolean red, GLboolean green, GLboolean blue, GLboolean alpha)); +OGL_EXT(glColorPointer,void, (GLint size, GLenum type, GLsizei stride, const GLvoid *pointer)); +//OGL_EXT(glCompressedTexImage2D,void, (GLenum target, GLint level, GLenum internalformat, GLsizei width, GLsizei height, GLint border, GLsizei imageSize, const GLvoid *data)); +//OGL_EXT(glCompressedTexSubImage2D,void, (GLenum target, GLint level, GLint xoffset, GLint yoffset, GLsizei width, GLsizei height, GLenum format, GLsizei imageSize, const GLvoid *data)); +OGL_EXT(glCopyTexImage2D,void, (GLenum target, GLint level, GLenum internalformat, GLint x, GLint y, GLsizei width, GLsizei height, GLint border)); +OGL_EXT(glCopyTexSubImage2D,void, (GLenum target, GLint level, GLint xoffset, GLint yoffset, GLint x, GLint y, GLsizei width, GLsizei height)); +OGL_EXT(glCullFace,void, (GLenum mode)); +OGL_EXT(glDeleteTextures,void, (GLsizei n, const GLuint *textures)); +OGL_EXT(glDepthFunc,void, (GLenum func)); +OGL_EXT(glDepthMask,void, (GLboolean flag)); +OGL_EXT(glDepthRange,void, (GLclampf zNear, GLclampf zFar)); +//OGL_EXT(glDepthRangex,void, (GLclampx zNear, GLclampx zFar)); +OGL_EXT(glDisable,void, (GLenum cap)); +OGL_EXT(glDisableClientState,void, (GLenum array)); +OGL_EXT(glDrawArrays,void, (GLenum mode, GLint first, GLsizei count)); +OGL_EXT(glDrawElements,void, (GLenum mode, GLsizei count, GLenum type, const GLvoid *indices)); +OGL_EXT(glEnable,void, (GLenum cap)); +OGL_EXT(glEnableClientState,void, (GLenum array)); +OGL_EXT(glFinish,void, (void)); +OGL_EXT(glFlush,void, (void)); +OGL_EXT(glFogf,void, (GLenum pname, GLfloat param)); +OGL_EXT(glFogfv,void, (GLenum pname, const GLfloat *params)); +//OGL_EXT(glFogx,void, (GLenum pname, GLfixed param)); +//OGL_EXT(glFogxv,void, (GLenum pname, const GLfixed *params)); +OGL_EXT(glFrontFace,void, (GLenum mode)); +OGL_EXT(glFrustumf,void, (GLfloat left, GLfloat right, GLfloat bottom, GLfloat top, GLfloat zNear, GLfloat zFar)); +//OGL_EXT(glFrustumx,void, (GLfixed left, GLfixed right, GLfixed bottom, GLfixed top, GLfixed zNear, GLfixed zFar)); +OGL_EXT(glGenTextures,void, (GLsizei n, GLuint *textures)); +OGL_EXT(glGetError,GLenum, (void)); +OGL_EXT(glGetFloatv,void, (GLenum pname, GLfloat* params)); +OGL_EXT(glGetIntegerv,void, (GLenum pname, GLint *params)); +OGL_EXT(glGetString, const GLubyte *,(GLenum name)); +OGL_EXT(glHint,void, (GLenum target, GLenum mode)); +OGL_EXT(glLightModelf,void, (GLenum pname, GLfloat param)); +OGL_EXT(glLightModelfv,void, (GLenum pname, const GLfloat *params)); +//OGL_EXT(glLightModelx,void, (GLenum pname, GLfixed param)); +//OGL_EXT(glLightModelxv,void, (GLenum pname, const GLfixed *params)); +OGL_EXT(glLightf,void, (GLenum light, GLenum pname, GLfloat param)); +OGL_EXT(glLightfv,void, (GLenum light, GLenum pname, const GLfloat *params)); +//OGL_EXT(glLightx,void, (GLenum light, GLenum pname, GLfixed param)); +//OGL_EXT(glLightxv,void, (GLenum light, GLenum pname, const GLfixed *params)); +OGL_EXT(glLineWidth,void, (GLfloat width)); +//OGL_EXT(glLineWidthx,void, (GLfixed width)); +OGL_EXT(glLoadIdentity,void, (void)); +OGL_EXT(glLoadMatrixf,void, (const GLfloat *m)); +//OGL_EXT(glLoadMatrixx,void, (const GLfixed *m)); +OGL_EXT(glLogicOp,void, (GLenum opcode)); +OGL_EXT(glMaterialf,void, (GLenum face, GLenum pname, GLfloat param)); +OGL_EXT(glMaterialfv,void, (GLenum face, GLenum pname, const GLfloat *params)); +//OGL_EXT(glMaterialx,void, (GLenum face, GLenum pname, GLfixed param)); +//OGL_EXT(glMaterialxv,void, (GLenum face, GLenum pname, const GLfixed *params)); +OGL_EXT(glMatrixMode,void, (GLenum mode)); +OGL_EXT(glMultMatrixf,void, (const GLfloat *m)); +//OGL_EXT(glMultMatrixx,void, (const GLfixed *m)); +OGL_EXT(glMultiTexCoord4f,void, (GLenum target, GLfloat s, GLfloat t, GLfloat r, GLfloat q)); +//OGL_EXT(glMultiTexCoord4x,void, (GLenum target, GLfixed s, GLfixed t, GLfixed r, GLfixed q)); +OGL_EXT(glNormal3f,void, (GLfloat nx, GLfloat ny, GLfloat nz)); +//OGL_EXT(glNormal3x,void, (GLfixed nx, GLfixed ny, GLfixed nz)); +OGL_EXT(glNormalPointer,void, (GLenum type, GLsizei stride, const GLvoid *pointer)); +OGL_EXT(glOrthof,void, (GLfloat left, GLfloat right, GLfloat bottom, GLfloat top, GLfloat zNear, GLfloat zFar)); +//OGL_EXT(glOrthox,void, (GLfixed left, GLfixed right, GLfixed bottom, GLfixed top, GLfixed zNear, GLfixed zFar)); +OGL_EXT(glPixelStorei,void, (GLenum pname, GLint param)); +OGL_EXT(glPointSize,void, (GLfloat size)); +//OGL_EXT(glPointSizex,void, (GLfixed size)); +OGL_EXT(glPolygonOffset,void, (GLfloat factor, GLfloat units)); +//OGL_EXT(glPolygonOffsetx,void, (GLfixed factor, GLfixed units)); +OGL_EXT(glPopMatrix,void, (void)); +OGL_EXT(glPushMatrix,void, (void)); +OGL_EXT(glReadPixels,void, (GLint x, GLint y, GLsizei width, GLsizei height, GLenum format, GLenum type, GLvoid *pixels)); +OGL_EXT(glRotatef,void, (GLfloat angle, GLfloat x, GLfloat y, GLfloat z)); +//OGL_EXT(glRotatex,void, (GLfixed angle, GLfixed x, GLfixed y, GLfixed z)); +//OGL_EXT(glSampleCoverage,void, (GLclampf value, GLboolean invert)); +//OGL_EXT(glSampleCoveragex,void, (GLclampx value, GLboolean invert)); +OGL_EXT(glScalef,void, (GLfloat x, GLfloat y, GLfloat z)); +//OGL_EXT(glScalex,void, (GLfixed x, GLfixed y, GLfixed z)); +OGL_EXT(glScissor,void, (GLint x, GLint y, GLsizei width, GLsizei height)); +OGL_EXT(glShadeModel,void, (GLenum mode)); +OGL_EXT(glStencilFunc,void, (GLenum func, GLint ref, GLuint mask)); +OGL_EXT(glStencilMask,void, (GLuint mask)); +OGL_EXT(glStencilOp,void, (GLenum fail, GLenum zfail, GLenum zpass)); +OGL_EXT(glTexCoordPointer,void, (GLint size, GLenum type, GLsizei stride, const GLvoid *pointer)); +OGL_EXT(glTexEnvf,void, (GLenum target, GLenum pname, GLfloat param)); +OGL_EXT(glTexEnvfv,void, (GLenum target, GLenum pname, const GLfloat *params)); +//OGL_EXT(glTexEnvx,void, (GLenum target, GLenum pname, GLfixed param)); +//OGL_EXT(glTexEnvxv,void, (GLenum target, GLenum pname, const GLfixed *params)); +OGL_EXT(glTexImage2D,void, (GLenum target, GLint level, GLint internalformat, GLsizei width, GLsizei height, GLint border, GLenum format, GLenum type, const GLvoid *pixels)); +OGL_EXT(glTexParameterf,void, (GLenum target, GLenum pname, GLfloat param)); +OGL_EXT(glTexParameteri,void, (GLenum target, GLenum pname, GLint param)); +OGL_EXT(glTexSubImage2D,void, (GLenum target, GLint level, GLint xoffset, GLint yoffset, GLsizei width, GLsizei height, GLenum format, GLenum type, const GLvoid *pixels)); +OGL_EXT(glTranslatef,void, (GLfloat x, GLfloat y, GLfloat z)); +//OGL_EXT(glTranslatex,void, (GLfixed x, GLfixed y, GLfixed z)); +OGL_EXT(glVertexPointer,void, (GLint size, GLenum type, GLsizei stride, const GLvoid *pointer)); +OGL_EXT(glViewport,void, (GLint x, GLint y, GLsizei width, GLsizei height)); +OGL_EXT(glGetTexParameteriv,void,(GLenum target, GLenum pname, GLint * params)); +OGL_EXT(glIsTexture, GLboolean, ( GLuint texture) ); +OGL_EXT(glIsEnabled, GLboolean, ( GLuint texture) ); + + + +#endif + + +#undef OGL_EXT +#undef CALLING_CONVENTION diff --git a/project/src/utils/ByteArray.cpp b/project/src/utils/ByteArray.cpp new file mode 100644 index 000000000..4bdc3f97d --- /dev/null +++ b/project/src/utils/ByteArray.cpp @@ -0,0 +1,213 @@ + +#include + +#include +#include + + +namespace lime { + + + // --- ByteArray ----------------------------------------------------- + + AutoGCRoot *gByteArrayCreate = 0; + AutoGCRoot *gByteArrayLen = 0; + AutoGCRoot *gByteArrayResize = 0; + AutoGCRoot *gByteArrayBytes = 0; + + value lime_byte_array_init(value inFactory, value inLen, value inResize, value inBytes) { + + gByteArrayCreate = new AutoGCRoot(inFactory); + gByteArrayLen = new AutoGCRoot(inLen); + gByteArrayResize = new AutoGCRoot(inResize); + gByteArrayBytes = new AutoGCRoot(inBytes); + + return alloc_null(); + + } DEFINE_PRIM(lime_byte_array_init,4); + + + ByteArray::ByteArray(int inSize) + { + mValue = val_call1(gByteArrayCreate->get(), alloc_int(inSize) ); + } + + ByteArray::ByteArray() : mValue(0) { } + + ByteArray::ByteArray(const QuickVec &inData) + { + mValue = val_call1(gByteArrayCreate->get(), alloc_int(inData.size()) ); + uint8 *bytes = Bytes(); + if (bytes) + memcpy(bytes, &inData[0], inData.size() ); + } + + ByteArray::ByteArray(const ByteArray &inRHS) : mValue(inRHS.mValue) { } + + ByteArray::ByteArray(value inValue) : mValue(inValue) { } + + void ByteArray::Resize(int inSize) + { + val_call2(gByteArrayResize->get(), mValue, alloc_int(inSize) ); + } + + int ByteArray::Size() const + { + return val_int( val_call1(gByteArrayLen->get(), mValue )); + } + + + const unsigned char *ByteArray::Bytes() const + { + value bytes = val_call1(gByteArrayBytes->get(),mValue); + if (val_is_string(bytes)) + return (unsigned char *)val_string(bytes); + buffer buf = val_to_buffer(bytes); + if (buf==0) + { + val_throw(alloc_string("Bad ByteArray")); + } + return (unsigned char *)buffer_data(buf); + } + + + unsigned char *ByteArray::Bytes() + { + value bytes = val_call1(gByteArrayBytes->get(),mValue); + if (val_is_string(bytes)) + return (unsigned char *)val_string(bytes); + buffer buf = val_to_buffer(bytes); + if (buf==0) + { + val_throw(alloc_string("Bad ByteArray")); + } + return (unsigned char *)buffer_data(buf); + } + + + + + + value lime_byte_array_read_file(value inFilename) { + + ByteArray result = ByteArray::FromFile(val_os_string(inFilename)); + + return result.mValue; + + } DEFINE_PRIM(lime_byte_array_read_file,1); + + + value lime_byte_array_get_native_pointer(value inByteArray) { + + ByteArray bytes(inByteArray); + + if (!val_is_null (bytes.mValue)) { + return alloc_int((intptr_t)bytes.Bytes ()); + } + + return alloc_null(); + + } DEFINE_PRIM(lime_byte_array_get_native_pointer,1); + + + #ifdef HX_WINDOWS +typedef wchar_t OSChar; +#define val_os_string val_wstring +#define OpenRead(x) _wfopen(x,L"rb") +#define OpenOverwrite(x) _wfopen(x,L"wb") // [ddc] + +#else +typedef char OSChar; +#define val_os_string val_string + +#if defined(IPHONE) +FILE *OpenRead(const char *inName); +FILE *OpenOverwrite(const char *inName); // [ddc] +extern int gFixedOrientation; + +#elif defined(HX_MACOS) +} // close namespace nme +extern "C" FILE *OpenRead(const char *inName); +extern "C" bool GetBundleFilename(const char *inName, char *outBuffer,int inBufSize); +extern "C" FILE *OpenOverwrite(const char *inName); +namespace nme { +#else +#ifdef TIZEN +extern int gFixedOrientation; +#endif +#define OpenRead(x) fopen(x,"rb") +#define OpenOverwrite(x) fopen(x,"wb") // [ddc] +#endif +#endif + + + ByteArray ByteArray::FromFile(const OSChar *inFilename) +{ + FILE *file = OpenRead(inFilename); + if (!file) + { + #ifdef ANDROID + return AndroidGetAssetBytes(inFilename); + #endif + return ByteArray(); + } + + fseek(file,0,SEEK_END); + int len = ftell(file); + fseek(file,0,SEEK_SET); + + ByteArray result(len); + int status = fread(result.Bytes(),len,1,file); + fclose(file); + + return result; +} + + +#ifdef HX_WINDOWS +ByteArray ByteArray::FromFile(const char *inFilename) +{ + FILE *file = fopen(inFilename,"rb"); + if (!file) + return ByteArray(); + + fseek(file,0,SEEK_END); + int len = ftell(file); + fseek(file,0,SEEK_SET); + + ByteArray result(len); + fread(result.Bytes(),len,1,file); + fclose(file); + + return result; +} +#endif + + +value lime_byte_array_overwrite_file(value inFilename, value inBytes) { + + // file is created if it doesn't exist, + // if it exists, it is truncated to zero + FILE *file = OpenOverwrite(val_os_string(inFilename)); + if (!file) + { + #ifdef ANDROID + // [todo] + #endif + return alloc_null(); + } + + ByteArray array(inBytes); + + // The function fwrite() writes nitems objects, each size bytes long, to the + // stream pointed to by stream, obtaining them from the location given by + // ptr. + // fwrite(const void *restrict ptr, size_t size, size_t nitems, FILE *restrict stream); + fwrite( array.Bytes() , 1, array.Size() , file); + + fclose(file); + return alloc_null(); + + } DEFINE_PRIM(lime_byte_array_overwrite_file, 2); + +} \ No newline at end of file diff --git a/templates/haxe/ApplicationMain.hx b/templates/haxe/ApplicationMain.hx index 9abda5b11..ce6b3fba2 100644 --- a/templates/haxe/ApplicationMain.hx +++ b/templates/haxe/ApplicationMain.hx @@ -30,8 +30,10 @@ class ApplicationMain { app.create (config); + var result = app.exec (); + #if sys - Sys.exit (app.exec ()); + Sys.exit (result); #end }