blob: 49fe15f7341e16454a7d7dc29d350b92addcfc2b [file] [log] [blame]
// Copyright (C) 2015 The Android Open Source Project
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.
import "api/android_extension_pack.api"
import "api/asynchronous_queries.api"
import "api/buffer_objects.api"
import "api/draw_commands.api"
import "api/extensions.api"
import "api/fragment_operations.api"
import "api/framebuffer.api"
import "api/glbitfield.api"
import "api/glenum.api"
import "api/other.api"
import "api/programs_and_shaders.api"
import "api/rasterization.api"
import "api/state_queries.api"
import "api/synchronization.api"
import "api/textures_and_samplers.api"
import "api/transform_feedback.api"
import "api/vertex_arrays.api"
import "types.api"
import "synthetic.api"
// HACK: We want to use these types in non-generated code
@internal @no_replay
class generate_types {
u16[] u16_slice
u32[] u32_slice
}
alias map!(GLenum, map!(GLenum, TextureId)) TextureUnitMap
extern u32 imageSize(u32 width, u32 height, GLenum format, GLenum type)
extern s32 stateVariableSize(GLenum v)
macro void minRequiredVersion(u32 major, u32 minor) {}
macro void supportsBits(GLbitfield seenBits, GLbitfield validBits) {}
macro void requiresExtension(ExtensionId ext) {}
macro void glErrorInvalidEnum(GLenum param) {}
enum ExtensionId {
GL_AMD_performance_monitor = 1 ,
GL_ANGLE_framebuffer_blit = 2 ,
GL_ANGLE_framebuffer_multisample = 3 ,
GL_ANGLE_instanced_arrays = 4 ,
GL_ANGLE_translated_shader_source = 5 ,
GL_APPLE_copy_texture_levels = 6 ,
GL_APPLE_framebuffer_multisample = 7 ,
GL_APPLE_sync = 8 ,
GL_EXT_base_instance = 9 ,
GL_EXT_buffer_storage = 10,
GL_EXT_copy_image = 11,
GL_EXT_debug_label = 12,
GL_EXT_debug_marker = 13,
GL_EXT_discard_framebuffer = 14,
GL_EXT_disjoint_timer_query = 15,
GL_EXT_draw_buffers = 16,
GL_EXT_draw_buffers_indexed = 17,
GL_EXT_draw_elements_base_vertex = 18,
GL_EXT_draw_instanced = 19,
GL_EXT_geometry_shader = 20,
GL_EXT_instanced_arrays = 21,
GL_EXT_map_buffer_range = 22,
GL_EXT_multi_draw_arrays = 23,
GL_EXT_multi_draw_indirect = 24,
GL_EXT_multisampled_render_to_texture = 25,
GL_EXT_multiview_draw_buffers = 26,
GL_EXT_occlusion_query_boolean = 27,
GL_EXT_primitive_bounding_box = 28,
GL_EXT_raster_multisample = 29,
GL_EXT_robustness = 30,
GL_EXT_separate_shader_objects = 31,
GL_EXT_sparse_texture = 32,
GL_EXT_tessellation_shader = 33,
GL_EXT_texture_border_clamp = 34,
GL_EXT_texture_buffer = 35,
GL_EXT_texture_filter_minmax = 36,
GL_EXT_texture_storage = 37,
GL_EXT_texture_view = 38,
GL_IMG_multisampled_render_to_texture = 39,
GL_INTEL_performance_query = 40,
GL_KHR_blend_equation_advanced = 41,
GL_KHR_debug = 42,
GL_KHR_robustness = 43,
GL_NV_bindless_texture = 44,
GL_NV_blend_equation_advanced = 45,
GL_NV_conditional_render = 46,
GL_NV_conservative_raster = 47,
GL_NV_copy_buffer = 48,
GL_NV_coverage_sample = 49,
GL_NV_draw_buffers = 50,
GL_NV_draw_instanced = 51,
GL_NV_fence = 52,
GL_NV_fragment_coverage_to_color = 53,
GL_NV_framebuffer_blit = 54,
GL_NV_framebuffer_mixed_samples = 55,
GL_NV_framebuffer_multisample = 56,
GL_NV_instanced_arrays = 57,
GL_NV_internalformat_sample_query = 58,
GL_NV_non_square_matrices = 59,
GL_NV_path_rendering = 60,
GL_NV_polygon_mode = 61,
GL_NV_read_buffer = 62,
GL_NV_sample_locations = 63,
GL_NV_viewport_array = 64,
GL_OES_copy_image = 65,
GL_OES_draw_buffers_indexed = 66,
GL_OES_draw_elements_base_vertex = 67,
GL_OES_EGL_image = 68,
GL_OES_geometry_shader = 69,
GL_OES_get_program_binary = 70,
GL_OES_mapbuffer = 71,
GL_OES_primitive_bounding_box = 72,
GL_OES_sample_shading = 73,
GL_OES_tessellation_shader = 74,
GL_OES_texture_3D = 75,
GL_OES_texture_border_clamp = 76,
GL_OES_texture_buffer = 77,
GL_OES_texture_storage_multisample_2d_array = 78,
GL_OES_texture_view = 79,
GL_OES_vertex_array_object = 80,
GL_OVR_multiview = 81,
GL_QCOM_alpha_test = 82,
GL_QCOM_driver_control = 83,
GL_QCOM_extended_get = 84,
GL_QCOM_extended_get2 = 85,
GL_QCOM_tiled_rendering = 86,
GL_AMD_compressed_ATC_texture = 87,
GL_OES_texture_half_float = 88,
GL_OES_vertex_half_float = 89,
}
enum TextureKind {
UNDEFINED = 0,
TEXTURE2D = 1,
CUBEMAP = 2,
}
/////////////////////////////////////////////////////////////////
// Macros
/////////////////////////////////////////////////////////////////
macro u32 vertexAttribTypeSize(GLenum t) {
return switch (t) {
case GL_BYTE: 1
case GL_UNSIGNED_BYTE: 1
case GL_SHORT: 2
case GL_UNSIGNED_SHORT: 2
case GL_FIXED: 4
case GL_FLOAT: 4
case GL_HALF_FLOAT_ARB: 2
case GL_HALF_FLOAT_OES: 2
}
}
macro s32 min(s32 a, s32 b) {
return switch (a < b) {
case true: a
case false: b
}
}
/* Not ready for primetime yet...
macro u32 imageSize(u32 width, u32 height, GLenum format, GLenum type) {
return switch (format) { // TODO: Consider ty
case GL_ALPHA: width * height
case GL_LUMINANCE: width * height
case GL_LUMINANCE_ALPHA: width * height * 2
case GL_RGB: width * height * 3
case GL_RGBA: width * height * 4
case GL_RED: width * height
case GL_RED_INTEGER: width * height
case GL_RG: width * height * 2
case GL_RG_INTEGER: width * height * 2
case GL_RGB_INTEGER: width * height * 3
case GL_RGBA_INTEGER: width * height * 3
case GL_DEPTH_COMPONENT: width * height
case GL_DEPTH_STENCIL: width * height
}
}
macro s32 stateVariableSize(GLenum v) {
return switch (v) {
case GL_ACTIVE_TEXTURE: 1
case GL_ALIASED_LINE_WIDTH_RANGE: 2
case GL_ALIASED_POINT_SIZE_RANGE: 2
case GL_ALPHA_BITS: 1
case GL_ARRAY_BUFFER_BINDING: 1
case GL_BLEND: 1
case GL_BLEND_COLOR: 4
case GL_BLEND_DST_ALPHA: 1
case GL_BLEND_DST_RGB: 1
case GL_BLEND_EQUATION_ALPHA: 1
case GL_BLEND_EQUATION_RGB: 1
case GL_BLEND_SRC_ALPHA: 1
case GL_BLEND_SRC_RGB: 1
case GL_BLUE_BITS: 1
case GL_COLOR_CLEAR_VALUE: 4
case GL_COLOR_WRITEMASK: 4
case GL_CULL_FACE: 1
case GL_CULL_FACE_MODE: 1
case GL_CURRENT_PROGRAM: 1
case GL_DEPTH_BITS: 1
case GL_DEPTH_CLEAR_VALUE: 1
case GL_DEPTH_FUNC: 1
case GL_DEPTH_RANGE: 2
case GL_DEPTH_TEST: 1
case GL_DEPTH_WRITEMASK: 1
case GL_DITHER: 1
case GL_ELEMENT_ARRAY_BUFFER_BINDING: 1
case GL_FRAMEBUFFER_BINDING: 1
case GL_FRONT_FACE: 1
case GL_GENERATE_MIPMAP_HINT: 1
case GL_GREEN_BITS: 1
case GL_IMPLEMENTATION_COLOR_READ_FORMAT: 1
case GL_IMPLEMENTATION_COLOR_READ_TYPE: 1
case GL_LINE_WIDTH: 1
case GL_MAX_COMBINED_TEXTURE_IMAGE_UNITS: 1
case GL_MAX_CUBE_MAP_TEXTURE_SIZE: 1
case GL_MAX_FRAGMENT_UNIFORM_VECTORS: 1
case GL_MAX_RENDERBUFFER_SIZE: 1
case GL_MAX_TEXTURE_IMAGE_UNITS: 1
case GL_MAX_TEXTURE_SIZE: 1
case GL_MAX_VARYING_VECTORS: 1
case GL_MAX_VERTEX_ATTRIBS: 1
case GL_MAX_VERTEX_TEXTURE_IMAGE_UNITS: 1
case GL_MAX_VERTEX_UNIFORM_VECTORS: 1
case GL_MAX_VIEWPORT_DIMS: 2
case GL_NUM_COMPRESSED_TEXTURE_FORMATS: 1
case GL_NUM_SHADER_BINARY_FORMATS: 1
case GL_PACK_ALIGNMENT: 1
case GL_POLYGON_OFFSET_FACTOR: 1
case GL_POLYGON_OFFSET_FILL: 1
case GL_POLYGON_OFFSET_UNITS: 1
case GL_RED_BITS: 1
case GL_RENDERBUFFER_BINDING: 1
case GL_SAMPLE_ALPHA_TO_COVERAGE: 1
case GL_SAMPLE_BUFFERS: 1
case GL_SAMPLE_COVERAGE: 1
case GL_SAMPLE_COVERAGE_INVERT: 1
case GL_SAMPLE_COVERAGE_VALUE: 1
case GL_SAMPLES: 1
case GL_SCISSOR_BOX: 4
case GL_SCISSOR_TEST: 1
case GL_SHADER_COMPILER: 1
case GL_STENCIL_BACK_FAIL: 1
case GL_STENCIL_BACK_FUNC: 1
case GL_STENCIL_BACK_PASS_DEPTH_FAIL: 1
case GL_STENCIL_BACK_PASS_DEPTH_PASS: 1
case GL_STENCIL_BACK_REF: 1
case GL_STENCIL_BACK_VALUE_MASK: 1
case GL_STENCIL_BACK_WRITEMASK: 1
case GL_STENCIL_BITS: 1
case GL_STENCIL_CLEAR_VALUE: 1
case GL_STENCIL_FAIL: 1
case GL_STENCIL_FUNC: 1
case GL_STENCIL_PASS_DEPTH_FAIL: 1
case GL_STENCIL_PASS_DEPTH_PASS: 1
case GL_STENCIL_REF: 1
case GL_STENCIL_TEST: 1
case GL_STENCIL_VALUE_MASK: 1
case GL_STENCIL_WRITEMASK: 1
case GL_SUBPIXEL_BITS: 1
case GL_TEXTURE_BINDING_2D: 1
case GL_TEXTURE_BINDING_CUBE_MAP: 1
case GL_UNPACK_ALIGNMENT: 1
case GL_VIEWPORT: 4
case GL_MAX_TEXTURE_MAX_ANISOTROPY_EXT: 1
case GL_GPU_DISJOINT_EXT: 1
}
}
*/
@internal
class Color {
GLfloat Red
GLfloat Green
GLfloat Blue
GLfloat Alpha
}
@internal
class Rect {
GLint X
GLint Y
GLsizei Width
GLsizei Height
}
@internal
class Image {
GLsizei Width
GLsizei Height
u8[] Data
u32 Size
GLenum Format
}
@internal
class Renderbuffer {
GLsizei Width
GLsizei Height
u8[] Data
GLenum Format
}
@internal
class Texture {
TextureKind Kind
GLenum Format
map!(GLint, Image) Texture2D
map!(GLint, CubemapLevel) Cubemap
GLenum MagFilter = GL_LINEAR
GLenum MinFilter = GL_NEAREST_MIPMAP_LINEAR
GLenum WrapS = GL_REPEAT
GLenum WrapT = GL_REPEAT
GLenum SwizzleR = GL_RED
GLenum SwizzleG = GL_GREEN
GLenum SwizzleB = GL_BLUE
GLenum SwizzleA = GL_ALPHA
f32 MaxAnisotropy = 1.0 // EXT/texture_filter_anisotropic
}
@internal
class CubemapLevel {
map!(GLenum, Image) Faces
}
@internal
class FramebufferAttachmentInfo {
u32 Object
GLenum Type
GLint TextureLevel
GLenum CubeMapFace
}
@internal
class Framebuffer {
map!(GLenum, FramebufferAttachmentInfo) Attachments
}
@internal
class Buffer {
u8[] Data
GLsizeiptr Size = as!GLsizeiptr(0)
GLenum Usage = GL_STATIC_DRAW
GLbitfield MappingAccess // The mapping access passed to glMapBufferRange.
s32 MappingOffset // The mapping offset passed to glMapBufferRange.
u8[] MappingData // The mapping data returned from glMapBufferRange.
}
@internal
class Shader {
u8[] Binary
bool Compiled = false
bool Deletable = false
GLchar[] InfoLog
string Source
GLenum Type
}
@internal
class VertexAttribute {
char[] Name
s32 VectorCount
GLenum Type
}
@internal type GLint[2] Vec2i
@internal type GLint[3] Vec3i
@internal type GLint[4] Vec4i
@internal type GLfloat[2] Vec2f
@internal type GLfloat[3] Vec3f
@internal type GLfloat[4] Vec4f
@internal type Vec2f[2] Mat2f
@internal type Vec3f[3] Mat3f
@internal type Vec4f[4] Mat4f
@internal
class Uniform {
string Name
GLenum Type
u8[] Value
}
@internal
class Program {
map!(GLenum, ShaderId) Shaders
bool Linked
u8[] Binary
map!(string, AttributeLocation) AttributeBindings
map!(s32, VertexAttribute) Attributes
map!(UniformLocation, Uniform) Uniforms
GLchar[] InfoLog
}
@internal
class VertexArray {}
@internal
class VertexAttributeArray {
bool Enabled = false
u32 Size = 4 // Number of components. 1, 2, 3 or 4.
GLenum Type = GL_FLOAT // Type of each component.
bool Normalized = false
GLsizei Stride = 0 // Byte offset between each consecutive attribute, or 0 for tight.
BufferId Buffer = 0
VertexPointer Pointer // Used if Buffer == 0
}
@internal
class Query {}
/////////////////////////////////////////////////////////////////
// State
/////////////////////////////////////////////////////////////////
@internal
class BlendState {
GLenum SrcRgbBlendFactor = GL_ONE
GLenum SrcAlphaBlendFactor = GL_ZERO
GLenum DstRgbBlendFactor = GL_ONE
GLenum DstAlphaBlendFactor = GL_ZERO
GLenum BlendEquationRgb = GL_FUNC_ADD
GLenum BlendEquationAlpha = GL_FUNC_ADD
Color BlendColor
}
@internal
class RasterizerState {
bool DepthMask = true
GLenum DepthTestFunction = GL_LESS
GLfloat DepthNear = 0.0
GLfloat DepthFar = 1.0
bool ColorMaskRed = true
bool ColorMaskGreen = true
bool ColorMaskBlue = true
bool ColorMaskAlpha = true
map!(GLenum, GLuint) StencilMask
Rect Viewport
Rect Scissor
GLenum FrontFace = GL_CCW
GLenum CullFace = GL_BACK
GLfloat LineWidth = 1.0
GLfloat PolygonOffsetFactor
GLfloat PolygonOffsetUnits
GLfloat SampleCoverageValue = 1.0
bool SampleCoverageInvert
}
@internal
class ClearState {
Color ClearColor
GLfloat ClearDepth = 1.0
GLint ClearStencil
}
@replay_remap type u32 RenderbufferId
@replay_remap type u32 TextureId
@replay_remap type u32 FramebufferId
@replay_remap type u32 BufferId
@replay_remap type u32 ShaderId
@replay_remap type u32 ProgramId
@replay_remap type u32 VertexArrayId
@replay_remap type u32 QueryId
@replay_remap type s32 UniformLocation
type u32 SamplerId
type u32 PipelineId
type u32 UniformBlockId
type u32 TransformFeedbackId
type u32 AttributeLocation
@replay_custom_value type const void* IndicesPointer
@replay_custom_value type const void* VertexPointer
@replay_custom_value type const void* TexturePointer
@replay_custom_value type const void* BufferDataPointer
@internal
class Objects {
map!(RenderbufferId, ref!Renderbuffer) Renderbuffers
map!(TextureId, ref!Texture) Textures
map!(FramebufferId, ref!Framebuffer) Framebuffers
map!(BufferId, ref!Buffer) Buffers
map!(ShaderId, ref!Shader) Shaders
map!(ProgramId, ref!Program) Programs
map!(VertexArrayId, ref!VertexArray) VertexArrays
map!(QueryId, ref!Query) Queries
}
@internal type u32 ContextID
@internal
class Context {
ContextID Identifier
BlendState Blending
RasterizerState Rasterizing
ClearState Clearing
map!(GLenum, FramebufferId) BoundFramebuffers
map!(GLenum, RenderbufferId) BoundRenderbuffers
map!(GLenum, BufferId) BoundBuffers
ProgramId BoundProgram
VertexArrayId BoundVertexArray
map!(AttributeLocation, ref!VertexAttributeArray) VertexAttributeArrays
TextureUnitMap TextureUnits
GLenum ActiveTextureUnit = GL_TEXTURE0
map!(GLenum, bool) Capabilities
GLenum GenerateMipmapHint = GL_DONT_CARE
map!(GLenum, GLint) PixelStorage
Objects Instances
bool PreserveBuffersOnSwap
}
type u64 ThreadID
// Globals
ContextID NextContextID
ThreadID CurrentThread
map!(ThreadID, ref!Context) Contexts
macro ref!Context GetContext() {
context := Contexts[CurrentThread]
assert(context != null)
return context
}
macro void SetContext(ref!Context context) {
Contexts[CurrentThread] = context
}
macro ref!Context CreateContext() {
identifier := NextContextID
NextContextID = NextContextID + 1
ctx := new!Context()
ctx.Identifier = identifier
ctx.Instances.Buffers[0] = new!Buffer()
ctx.Instances.Textures[0] = new!Texture()
ctx.Instances.Renderbuffers[0] = new!Renderbuffer()
color_id := as!RenderbufferId(0xffffffff)
depth_id := as!RenderbufferId(0xfffffffe)
stencil_id := as!RenderbufferId(0xfffffffd)
ctx.Instances.Renderbuffers[color_id] = new!Renderbuffer()
ctx.Instances.Renderbuffers[depth_id] = new!Renderbuffer()
ctx.Instances.Renderbuffers[stencil_id] = new!Renderbuffer()
backbuffer := new!Framebuffer()
backbuffer.Attachments[GL_COLOR_ATTACHMENT0] = FramebufferAttachmentInfo(
Object: as!u32(color_id),
Type: GL_RENDERBUFFER,
CubeMapFace: GL_TEXTURE_CUBE_MAP_POSITIVE_X,
)
backbuffer.Attachments[GL_DEPTH_ATTACHMENT] = FramebufferAttachmentInfo(
Object: as!u32(depth_id),
Type: GL_RENDERBUFFER,
CubeMapFace: GL_TEXTURE_CUBE_MAP_POSITIVE_X,
)
backbuffer.Attachments[GL_STENCIL_ATTACHMENT] = FramebufferAttachmentInfo(
Object: as!u32(stencil_id),
Type: GL_RENDERBUFFER,
CubeMapFace: GL_TEXTURE_CUBE_MAP_POSITIVE_X,
)
ctx.Instances.Framebuffers[0] = backbuffer
ctx.BoundFramebuffers[GL_DRAW_FRAMEBUFFER] = 0
ctx.BoundFramebuffers[GL_READ_FRAMEBUFFER] = 0
// TODO: Stencil function
ctx.Rasterizing.StencilMask[GL_FRONT] = 0xFFFFFFFF
ctx.Rasterizing.StencilMask[GL_BACK] = 0xFFFFFFFF
ctx.PixelStorage[GL_PACK_ALIGNMENT] = 4
ctx.PixelStorage[GL_UNPACK_ALIGNMENT] = 4
for i in (0 .. 64) { // TODO: Count
ctx.VertexAttributeArrays[as!AttributeLocation(i)] = new!VertexAttributeArray()
}
return ctx
}
/////////////////////////////////////////////////////////////////
// EGL APIs
/////////////////////////////////////////////////////////////////
type int EGLBoolean
type int EGLint
type void* EGLConfig
type void* EGLContext
type void* EGLDisplay
type void* EGLSurface
map!(EGLContext, ref!Context) EGLContexts
@no_replay
///http://www.khronos.org/registry/egl/sdk/docs/man/html/eglInitialize.xhtml
cmd EGLBoolean eglInitialize(EGLDisplay dpy, EGLint* major, EGLint* minor) {
if major != null {
major[0] = ?
}
if major != null {
minor[0] = ?
}
return ?
}
@no_replay
///http://www.khronos.org/registry/egl/sdk/docs/man/html/eglCreateContext.xhtml
cmd EGLContext eglCreateContext(EGLDisplay display,
EGLConfig config,
EGLContext share_context,
EGLint* attrib_list) {
context := as!EGLContext(?)
EGLContexts[context] = CreateContext()
return context
}
@no_replay
///http://www.khronos.org/registry/egl/sdk/docs/man/html/eglMakeCurrent.xhtml
cmd EGLBoolean eglMakeCurrent(EGLDisplay display,
EGLSurface draw,
EGLSurface read,
EGLContext context) {
SetContext(EGLContexts[context])
return ?
}
@no_replay
@EndOfFrame
///http://www.khronos.org/registry/egl/sdk/docs/man/html/eglSwapBuffers.xhtml
cmd EGLBoolean eglSwapBuffers(EGLDisplay display, void* surface) {
return ?
}
@no_replay
cmd EGLBoolean eglQuerySurface(EGLDisplay display, EGLSurface surface, EGLint attribute, EGLint* value) {
value[0] = ?
return ?
}
/////////////////////////////////////////////////////////////////
// GLX APIs
/////////////////////////////////////////////////////////////////
type void* GLXContext
type void* GLXDrawable
type int Bool
map!(GLXContext, ref!Context) GLXContexts
@no_replay
cmd GLXContext glXCreateContext(void* dpy, void* vis, GLXContext shareList, bool direct) {
context := as!GLXContext(?)
GLXContexts[context] = CreateContext()
return context
}
@no_replay
cmd GLXContext glXCreateNewContext(void* display, void* fbconfig, u32 type, GLXContext shared, bool direct) {
context := as!GLXContext(?)
GLXContexts[context] = CreateContext()
return context
}
@no_replay
cmd Bool glXMakeContextCurrent(void* display, GLXDrawable draw, GLXDrawable read, GLXContext ctx) {
SetContext(GLXContexts[ctx])
return ?
}
@no_replay
cmd Bool glXMakeCurrent(void* display, GLXDrawable drawable, GLXContext ctx) {
SetContext(GLXContexts[ctx])
return ?
}
@no_replay
@EndOfFrame
cmd void glXSwapBuffers(void* display, GLXDrawable drawable) {
}
@no_replay
cmd int glXQueryDrawable(void* display, GLXDrawable draw, int attribute, int* value) {
value[0] = ?
return ?
}
/////////////////////////////////////////////////////////////////
// WGL APIs
/////////////////////////////////////////////////////////////////
type void* HGLRC
type void* HDC
type int BOOL
map!(HGLRC, ref!Context) WGLContexts
@no_replay
///http://msdn.microsoft.com/en-us/library/windows/desktop/dd374379(v=vs.85).aspx
cmd HGLRC wglCreateContext(HDC hdc) {
context := as!HGLRC(?)
WGLContexts[context] = CreateContext()
return context
}
@no_replay
///http://www.opengl.org/registry/specs/ARB/wgl_create_context.txt
cmd HGLRC wglCreateContextAttribsARB(HDC hdc, HGLRC hShareContext, int* attribList) {
context := as!HGLRC(?)
WGLContexts[context] = CreateContext()
return context
}
@no_replay
///http://msdn.microsoft.com/en-us/library/windows/desktop/dd374387(v=vs.85).aspx
cmd BOOL wglMakeCurrent(HDC hdc, HGLRC hglrc) {
SetContext(WGLContexts[hglrc])
return ?
}
@no_replay
@EndOfFrame
///http://msdn.microsoft.com/en-us/library/dd369060(v=vs.85)
cmd void wglSwapBuffers(HDC hdc) { }
/////////////////////////////////////////////////////////////////
// CGL APIs
/////////////////////////////////////////////////////////////////
type int CGLError
type void* CGLPixelFormatObj
type void* CGLContextObj
type void* CGSConnectionID
type s32 CGSWindowID
type s32 CGSSurfaceID
map!(CGLContextObj, ref!Context) CGLContexts
@no_replay
///http://developer.apple.com/library/mac/documentation/GraphicsImaging/Reference/CGL_OpenGL/index.html#//apple_ref/c/func/CGLCreateContext
cmd CGLError CGLCreateContext(CGLPixelFormatObj pix, CGLContextObj share, CGLContextObj* ctx) {
context := as!CGLContextObj(?)
CGLContexts[context] = CreateContext()
ctx[0] = context
return ?
}
@no_replay
cmd CGLError CGLSetCurrentContext(CGLContextObj ctx) {
SetContext(CGLContexts[ctx])
return ?
}
@no_replay
cmd int CGLGetSurface(CGLContextObj ctx, CGSConnectionID* cid, CGSWindowID* wid, CGSSurfaceID* sid) {
cid[0] = ?
wid[0] = ?
sid[0] = ?
return ?
}
@no_replay
cmd int CGSGetSurfaceBounds(CGSConnectionID cid, CGSWindowID wid, CGSSurfaceID sid, f64* bounds) {
write(bounds[0:4])
return ?
}
@no_replay
@EndOfFrame
cmd CGLError CGLFlushDrawable(CGLContextObj ctx) {
return ?
}
/////////////////////////////////////////////////////////////////
// GLES 2 APIs
/////////////////////////////////////////////////////////////////
macro void ReadVertexArrays(ref!Context ctx, u32 first_index, u32 last_index) {
for i in (0 .. len(ctx.VertexAttributeArrays)) { // TODO: HACK: We need to iterate a map.
arr := ctx.VertexAttributeArrays[as!AttributeLocation(i)]
if arr.Enabled && arr.Buffer == 0 {
elsize := vertexAttribTypeSize(arr.Type) * arr.Size
elstride := switch (arr.Stride == 0) {
case true: elsize
case false: as!u32(arr.Stride)
}
for v in (first_index .. (last_index + 1)) {
offset := elstride * v
read(arr.Pointer[offset:offset + elsize])
}
}
}
}
macro u32 IndexSize(GLenum indices_type) {
return switch (indices_type) {
case GL_UNSIGNED_BYTE: 1
case GL_UNSIGNED_SHORT: 2
case GL_UNSIGNED_INT: 4
}
}
extern u32 minIndex(u8* indices, GLenum indices_type, u32 offset, u32 count)
extern u32 maxIndex(u8* indices, GLenum indices_type, u32 offset, u32 count)
/////////////////////////////////////////////////////////////////
// Desktop GL
/////////////////////////////////////////////////////////////////
// EXT_disjoint_timer_query
// TODO: Always use glGetQueryObjectui64vEXT?
cmd void glGetQueryObjecti64v(QueryId query, GLenum parameter, s64* value) {
value[0] = ?
}
cmd void glGetQueryObjectui64v(QueryId query, GLenum parameter, u64* value) {
value[0] = ?
}