blob: 322d6bfbb60978e0cd93dce66fbba07555d15f38 [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 "glenum.api"
alias map!(TextureUnit, map!(TextureTarget, TextureId)) TextureUnitMap
extern u32 strlen(any s)
extern u32 imageSize(u32 width, u32 height, TexelFormat format, TexelType type)
extern s32 stateVariableSize(StateVariable v)
/////////////////////////////////////////////////////////////////
// Macros
/////////////////////////////////////////////////////////////////
macro u32 vertexAttribTypeSize(VertexAttribType 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_ARB_half_float_vertex: 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, TexelFormat format, TexelType 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(StateVariable 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 {
f32 Red
f32 Green
f32 Blue
f32 Alpha
}
@internal
class Rect {
s32 X
s32 Y
s32 Width
s32 Height
}
@internal
class Image {
s32 Width
s32 Height
u8[] Data
u32 Size
ImageTexelFormat Format
}
@internal
class Renderbuffer {
s32 Width
s32 Height
u8[] Data
RenderbufferFormat Format
}
@internal
class Texture {
TextureKind Kind
ImageTexelFormat Format
map!(s32, Image) Texture2D
map!(s32, CubemapLevel) Cubemap
TextureFilterMode MagFilter = GL_LINEAR
TextureFilterMode MinFilter = GL_NEAREST_MIPMAP_LINEAR
TextureWrapMode WrapS = GL_REPEAT
TextureWrapMode WrapT = GL_REPEAT
TexelComponent SwizzleR = GL_RED
TexelComponent SwizzleG = GL_GREEN
TexelComponent SwizzleB = GL_BLUE
TexelComponent SwizzleA = GL_ALPHA
f32 MaxAnisotropy = 1.0 // EXT/texture_filter_anisotropic
}
@internal
class CubemapLevel {
map!(CubeMapImageTarget, Image) Faces
}
@internal
class FramebufferAttachmentInfo {
u32 Object
FramebufferAttachmentType Type
s32 TextureLevel
CubeMapImageTarget CubeMapFace
}
@internal
class Framebuffer {
map!(FramebufferAttachment, FramebufferAttachmentInfo) Attachments
}
@internal
class Buffer {
u8[] Data
s32 Size = 0
BufferUsage Usage = GL_STATIC_DRAW
}
@internal
class Shader {
u8[] Binary
bool Compiled = false
bool Deletable = false
char[] InfoLog
string Source
ShaderType Type
}
@internal
class VertexAttribute {
char[] Name
s32 VectorCount
ShaderAttribType Type
}
@internal
class Vec2i { s32 X, s32 Y }
@internal
class Vec3i { s32 X, s32 Y, s32 Z }
@internal
class Vec4i { s32 X, s32 Y, s32 Z, s32 W }
@internal
class Vec2f { f32 X, f32 Y }
@internal
class Vec3f { f32 X, f32 Y, f32 Z }
@internal
class Vec4f { f32 X, f32 Y, f32 Z, f32 W }
@internal
class Mat2f {
Vec2f Col0
Vec2f Col1
}
@internal
class Mat3f {
Vec3f Col0
Vec3f Col1
Vec3f Col2
}
@internal
class Mat4f {
Vec4f Col0
Vec4f Col1
Vec4f Col2
Vec4f Col3
}
@internal
@union
class UniformValue {
f32 F32
Vec2f Vec2f
Vec3f Vec3f
Vec4f Vec4f
s32 S32
Vec2i Vec2i
Vec3i Vec3i
Vec4i Vec4i
Mat2f Mat2f
Mat3f Mat3f
Mat4f Mat4f
}
@internal
class Uniform {
string Name
ShaderUniformType Type
UniformValue Value
}
@internal
class Program {
map!(ShaderType, ShaderId) Shaders
bool Linked
u8[] Binary
map!(string, AttributeLocation) AttributeBindings
map!(s32, VertexAttribute) Attributes
map!(UniformLocation, Uniform) Uniforms
char[] InfoLog
}
@internal
class VertexArray {}
@internal
class VertexAttributeArray {
bool Enabled = false
u32 Size = 4 // Number of components. 1, 2, 3 or 4.
VertexAttribType Type = GL_FLOAT // Type of each component.
bool Normalized = false
s32 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 {
BlendFactor SrcRgbBlendFactor = GL_ONE
BlendFactor SrcAlphaBlendFactor = GL_ZERO
BlendFactor DstRgbBlendFactor = GL_ONE
BlendFactor DstAlphaBlendFactor = GL_ZERO
BlendEquation BlendEquationRgb = GL_FUNC_ADD
BlendEquation BlendEquationAlpha = GL_FUNC_ADD
Color BlendColor
}
@internal
class RasterizerState {
bool DepthMask = true
TestFunction DepthTestFunction = GL_LESS
f32 DepthNear = 0.0
f32 DepthFar = 1.0
bool ColorMaskRed = true
bool ColorMaskGreen = true
bool ColorMaskBlue = true
bool ColorMaskAlpha = true
map!(FaceMode, u32) StencilMask
Rect Viewport
Rect Scissor
FaceOrientation FrontFace = GL_CCW
FaceMode CullFace = GL_BACK
f32 LineWidth = 1.0
f32 PolygonOffsetFactor
f32 PolygonOffsetUnits
f32 SampleCoverageValue = 1.0
bool SampleCoverageInvert
}
@internal
class ClearState {
Color ClearColor
f32 ClearDepth = 1.0
s32 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 u32 SyncObjectId
@replay_remap type s32 UniformLocation
type u32 AttributeLocation
@replay_custom_value type void* IndicesPointer
@replay_custom_value type void* VertexPointer
@replay_custom_value type void* TexturePointer
@replay_custom_value type 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!(SyncObjectId, ref!SyncObject) SyncObjects
map!(QueryId, ref!Query) Queries
}
@internal type u32 ContextID
@internal
class Context {
ContextID Identifier
BlendState Blending
RasterizerState Rasterizing
ClearState Clearing
map!(FramebufferTarget, FramebufferId) BoundFramebuffers
map!(RenderbufferTarget, RenderbufferId) BoundRenderbuffers
map!(BufferTarget, BufferId) BoundBuffers
ProgramId BoundProgram
VertexArrayId BoundVertexArray
map!(AttributeLocation, ref!VertexAttributeArray) VertexAttributeArrays
TextureUnitMap TextureUnits
TextureUnit ActiveTextureUnit = GL_TEXTURE0
map!(Capability, bool) Capabilities
HintMode GenerateMipmapHint = GL_DONT_CARE
map!(PixelStoreParameter, s32) PixelStorage
Objects Instances
}
type u32 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
}
/////////////////////////////////////////////////////////////////
// Synthetic commands
/////////////////////////////////////////////////////////////////
// replayCreateRenderer constructs a GLES renderer for replay without making it active.
@synthetic
cmd void replayCreateRenderer(u32 id) {}
// replayBindRenderer makes the renderer constructed with replayCreateRenderer active.
@synthetic
cmd void replayBindRenderer(u32 id) {}
@synthetic
cmd void backbufferInfo(s32 width,
s32 height,
RenderbufferFormat color_fmt,
RenderbufferFormat depth_fmt,
RenderbufferFormat stencil_fmt,
bool resetViewportScissor) {
ctx := GetContext()
backbuffer := ctx.Instances.Framebuffers[0]
color_id := as!RenderbufferId(backbuffer.Attachments[GL_COLOR_ATTACHMENT0].Object)
color_buffer := ctx.Instances.Renderbuffers[color_id]
depth_id := as!RenderbufferId(backbuffer.Attachments[GL_DEPTH_ATTACHMENT].Object)
depth_buffer := ctx.Instances.Renderbuffers[depth_id]
stencil_id := as!RenderbufferId(backbuffer.Attachments[GL_STENCIL_ATTACHMENT].Object)
stencil_buffer := ctx.Instances.Renderbuffers[stencil_id]
color_buffer.Width = width
color_buffer.Height = height
color_buffer.Format = color_fmt
depth_buffer.Width = width
depth_buffer.Height = height
depth_buffer.Format = depth_fmt
stencil_buffer.Width = width
stencil_buffer.Height = height
stencil_buffer.Format = stencil_fmt
if resetViewportScissor {
ctx.Rasterizing.Scissor.Width = width
ctx.Rasterizing.Scissor.Height = height
ctx.Rasterizing.Viewport.Width = width
ctx.Rasterizing.Viewport.Height = height
}
}
@synthetic
cmd void startTimer(u8 index) {}
@synthetic
cmd u64 stopTimer(u8 index) { return ? } // Time returned in nanoseconds
@synthetic
cmd void flushPostBuffer() {}
/////////////////////////////////////////////////////////////////
// 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) {
major[0] = ?
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
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 void glXMakeContextCurrent(void* display, GLXDrawable draw, GLXDrawable read, GLXContext ctx) {
SetContext(GLXContexts[ctx])
}
@no_replay
@EndOfFrame
cmd void glXSwapBuffers(void* display, GLXDrawable drawable) {
}
/////////////////////////////////////////////////////////////////
// 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
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 ?
}
/////////////////////////////////////////////////////////////////
// GLES 1 APIs
/////////////////////////////////////////////////////////////////
///http://www.khronos.org/opengles/sdk/1.1/docs/man/glEnableClientState.xml
cmd void glEnableClientState(ArrayType type) {
ctx := GetContext()
ctx.Capabilities[as!Capability(type)] = true
}
///http://www.khronos.org/opengles/sdk/1.1/docs/man/glEnableClientState.xml
cmd void glDisableClientState(ArrayType type) {
ctx := GetContext()
ctx.Capabilities[as!Capability(type)] = false
}
/////////////////////////////////////////////////////////////////
// GLES 1 extension APIs
/////////////////////////////////////////////////////////////////
// OES_get_program_binary
///http://www.khronos.org/registry/gles/extensions/OES/OES_get_program_binary.txt
cmd void glGetProgramBinaryOES(ProgramId program,
s32 buffer_size,
s32* bytes_written,
u32* binary_format,
void* binary) {
l := as!s32(?)
bytes_written[0] = l
binary_format[0] = ?
write(binary[0:l])
}
///http://www.khronos.org/registry/gles/extensions/OES/OES_get_program_binary.txt
cmd void glProgramBinaryOES(ProgramId program,
u32 binary_format,
void* binary,
s32 binary_size) {
}
// QCOM_tiled_rendering
///http://www.khronos.org/registry/gles/extensions/QCOM/QCOM_tiled_rendering.txt
cmd void glStartTilingQCOM(s32 x, s32 y, s32 width, s32 height, TilePreserveMaskQCOM preserveMask) {
}
///http://www.khronos.org/registry/gles/extensions/QCOM/QCOM_tiled_rendering.txt
cmd void glEndTilingQCOM(TilePreserveMaskQCOM preserve_mask) {
}
// EXT_discard_framebuffer
///http://www.khronos.org/registry/gles/extensions/EXT/EXT_discard_framebuffer.txt
cmd void glDiscardFramebufferEXT(FramebufferTarget target, s32 numAttachments, DiscardFramebufferAttachment* attachments) {
}
// EXT_debug_marker
///http://www.khronos.org/registry/gles/extensions/EXT/EXT_debug_marker.txt
cmd void glInsertEventMarkerEXT(s32 length, string marker) {
}
///http://www.khronos.org/registry/gles/extensions/EXT/EXT_debug_marker.txt
cmd void glPushGroupMarkerEXT(s32 length, string marker) {
}
///http://www.khronos.org/registry/gles/extensions/EXT/EXT_debug_marker.txt
cmd void glPopGroupMarkerEXT() {
}
// EXT_texture_storage
///http://www.khronos.org/registry/gles/extensions/EXT/EXT_texture_storage.txt
cmd void glTexStorage1DEXT(TextureTarget target, s32 levels, TexelFormat format, s32 width) {
}
///http://www.khronos.org/registry/gles/extensions/EXT/EXT_texture_storage.txt
cmd void glTexStorage2DEXT(TextureTarget target, s32 levels, TexelFormat format, s32 width, s32 height) {
}
///http://www.khronos.org/registry/gles/extensions/EXT/EXT_texture_storage.txt
cmd void glTexStorage3DEXT(TextureTarget target, s32 levels, TexelFormat format, s32 width, s32 height, s32 depth) {
}
///http://www.khronos.org/registry/gles/extensions/EXT/EXT_texture_storage.txt
cmd void glTextureStorage1DEXT(TextureId texture, TextureTarget target, s32 levels, TexelFormat format, s32 width) {
}
///http://www.khronos.org/registry/gles/extensions/EXT/EXT_texture_storage.txt
cmd void glTextureStorage2DEXT(TextureId texture, TextureTarget target, s32 levels, TexelFormat format, s32 width, s32 height) {
}
///http://www.khronos.org/registry/gles/extensions/EXT/EXT_texture_storage.txt
cmd void glTextureStorage3DEXT(TextureId texture, TextureTarget target, s32 levels, TexelFormat format, s32 width, s32 height, s32 depth) {
}
// OES_vertex_array_object
///http://www.khronos.org/registry/gles/extensions/OES/OES_vertex_array_object.txt
cmd void glGenVertexArraysOES(s32 count, VertexArrayId* arrays) {
a := arrays[0:count]
ctx := GetContext()
for i in (0 .. count) {
id := as!VertexArrayId(?)
ctx.Instances.VertexArrays[id] = new!VertexArray()
a[i] = id
}
}
///http://www.khronos.org/registry/gles/extensions/OES/OES_vertex_array_object.txt
cmd void glBindVertexArrayOES(VertexArrayId array) {
ctx := GetContext()
if !(array in ctx.Instances.VertexArrays) {
ctx.Instances.VertexArrays[array] = new!VertexArray()
}
ctx.BoundVertexArray = array
}
///http://www.khronos.org/registry/gles/extensions/OES/OES_vertex_array_object.txt
cmd void glDeleteVertexArraysOES(s32 count, VertexArrayId* arrays) {
ctx := GetContext()
a := arrays[0:count]
for i in (0 .. count) {
ctx.Instances.VertexArrays[a[i]] = null
}
}
///http://www.khronos.org/registry/gles/extensions/OES/OES_vertex_array_object.txt
cmd bool glIsVertexArrayOES(VertexArrayId array) {
ctx := GetContext()
return array in ctx.Instances.VertexArrays
}
// OES_EGL_image extension:
@replay_custom_value type void* ImageOES
///http://www.khronos.org/registry/gles/extensions/OES/OES_EGL_image.txt
cmd void glEGLImageTargetTexture2DOES(ImageTargetTexture target, ImageOES image) {
}
///http://www.khronos.org/registry/gles/extensions/OES/OES_EGL_image.txt
cmd void glEGLImageTargetRenderbufferStorageOES(ImageTargetRenderbufferStorage target, TexturePointer image) {
}
// EXT_robustness
///http://www.khronos.org/registry/gles/extensions/EXT/EXT_robustness.txt
cmd ResetStatus glGetGraphicsResetStatusEXT() {
return ?
}
/*
///http://www.khronos.org/registry/gles/extensions/EXT/EXT_robustness.txt
cmd void glReadnPixelsEXT(s32 x,
s32 y,
s32 width,
s32 height,
enum format,
enum type,
s32 buffer_size,
void* data) {
}
///http://www.khronos.org/registry/gles/extensions/EXT/EXT_robustness.txt
cmd void glGetnUniformfvEXT(u32 program,
UniformLocation location,
s32 buffer_size,
f32* params) {
}
///http://www.khronos.org/registry/gles/extensions/EXT/EXT_robustness.txt
cmd void glGetnUniformivEXT(u32 program,
UniformLocation location,
s32 buffer_size,
s32* params) {
}
*/
/////////////////////////////////////////////////////////////////
// GLES 2 APIs
/////////////////////////////////////////////////////////////////
///http://www.khronos.org/opengles/sdk/docs/man/xhtml/glBindAttribLocation.xml
cmd void glBindAttribLocation(ProgramId program, AttributeLocation location, string name) {
ctx := GetContext()
p := ctx.Instances.Programs[program]
p.AttributeBindings[name] = location
}
///http://www.khronos.org/opengles/sdk/docs/man/xhtml/glBlendFunc.xml
cmd void glBlendFunc(BlendFactor src_factor, BlendFactor dst_factor) {
ctx := GetContext()
ctx.Blending.SrcRgbBlendFactor = src_factor
ctx.Blending.SrcAlphaBlendFactor = src_factor
ctx.Blending.DstRgbBlendFactor = dst_factor
ctx.Blending.DstAlphaBlendFactor = dst_factor
}
///http://www.khronos.org/opengles/sdk/docs/man/xhtml/glBlendFuncSeparate.xml
cmd void glBlendFuncSeparate(BlendFactor src_factor_rgb,
BlendFactor dst_factor_rgb,
BlendFactor src_factor_alpha,
BlendFactor dst_factor_alpha) {
ctx := GetContext()
ctx.Blending.SrcRgbBlendFactor = src_factor_rgb
ctx.Blending.DstRgbBlendFactor = dst_factor_rgb
ctx.Blending.SrcAlphaBlendFactor = src_factor_alpha
ctx.Blending.DstAlphaBlendFactor = dst_factor_alpha
}
///http://www.khronos.org/opengles/sdk/docs/man/xhtml/glBlendEquation.xml
cmd void glBlendEquation(BlendEquation equation) {
ctx := GetContext()
ctx.Blending.BlendEquationRgb = equation
ctx.Blending.BlendEquationAlpha = equation
}
///http://www.khronos.org/opengles/sdk/docs/man/xhtml/glBlendEquationSeparate.xml
cmd void glBlendEquationSeparate(BlendEquation rgb, BlendEquation alpha) {
ctx := GetContext()
ctx.Blending.BlendEquationRgb = rgb
ctx.Blending.BlendEquationAlpha = alpha
}
///http://www.khronos.org/opengles/sdk/docs/man/xhtml/glBlendColor.xml
cmd void glBlendColor(f32 red, f32 green, f32 blue, f32 alpha) {
ctx := GetContext()
ctx.Blending.BlendColor = Color(
Red: red,
Green: green,
Blue: blue,
Alpha: alpha,
)
}
///http://www.khronos.org/opengles/sdk/docs/man/xhtml/glEnableVertexAttribArray.xml
cmd void glEnableVertexAttribArray(AttributeLocation location) {
ctx := GetContext()
ctx.VertexAttributeArrays[location].Enabled = true
}
///http://www.khronos.org/opengles/sdk/docs/man/xhtml/glDisableVertexAttribArray.xml
cmd void glDisableVertexAttribArray(AttributeLocation location) {
ctx := GetContext()
ctx.VertexAttributeArrays[location].Enabled = false
}
///http://www.khronos.org/opengles/sdk/docs/man/xhtml/glVertexAttribPointer.xml
cmd void glVertexAttribPointer(AttributeLocation location,
s32 size,
VertexAttribType type,
bool normalized,
s32 stride,
VertexPointer data) {
assert((size >= 1) && (size <= 4))
assert(stride >= 0)
ctx := GetContext()
a := ctx.VertexAttributeArrays[location]
a.Size = as!u32(size)
a.Type = type
a.Normalized = normalized
a.Stride = stride
a.Pointer = data
a.Buffer = ctx.BoundBuffers[GL_ARRAY_BUFFER]
}
///http://www.khronos.org/opengles/sdk/docs/man/xhtml/glGetActiveAttrib.xml
cmd void glGetActiveAttrib(ProgramId program,
AttributeLocation location,
s32 buffer_size,
s32* buffer_bytes_written,
s32* vector_count,
ShaderAttribType* type,
char* name) {
}
// TODO: This method cannot use UniformLocation as the location type
// as this will create an unwanted self-mapping to<->from the captured
// location.
///http://www.khronos.org/opengles/sdk/docs/man/xhtml/glGetActiveUniform.xml
cmd void glGetActiveUniform(ProgramId program,
s32 location,
s32 buffer_size,
s32* buffer_bytes_written,
s32* size,
ShaderUniformType* type,
char* name) {
}
///http://www.khronos.org/opengles/sdk/docs/man/xhtml/glGetError.xml
cmd Error glGetError() {
return ?
}
///http://www.khronos.org/opengles/sdk/docs/man/xhtml/glGetProgram.xml
cmd void glGetProgramiv(ProgramId program, ProgramParameter parameter, s32* value) {
value[0] = ?
}
///http://www.khronos.org/opengles/sdk/docs/man/xhtml/glGetShaderiv.xml
cmd void glGetShaderiv(ShaderId shader, ShaderParameter parameter, s32* value) {
ctx := GetContext()
s := ctx.Instances.Shaders[shader]
value[0] = switch (parameter) {
case GL_SHADER_TYPE: as!s32(s.Type)
case GL_DELETE_STATUS: switch (s.Deletable) { case true: 1 case false: 0 }
case GL_COMPILE_STATUS: switch (s.Compiled) { case true: 1 case false: 0 }
case GL_INFO_LOG_LENGTH: as!s32(strlen(s.InfoLog))
case GL_SHADER_SOURCE_LENGTH: as!s32(strlen(s.Source))
}
}
///http://www.khronos.org/opengles/sdk/docs/man/xhtml/glGetUniformLocation.xml
cmd UniformLocation glGetUniformLocation(ProgramId program, string name) {
return ?
}
@replay_custom // Translates to glBindAttribLocation
///http://www.khronos.org/opengles/sdk/docs/man/xhtml/glGetAttribLocation.xml
cmd AttributeLocation glGetAttribLocation(ProgramId program, string name) {
return ?
}
///http://www.khronos.org/opengles/sdk/docs/man/xhtml/glPixelStorei.xml
cmd void glPixelStorei(PixelStoreParameter parameter, s32 value) {
assert((value == 1) || (value == 2) || (value == 4) || (value == 8))
ctx := GetContext()
ctx.PixelStorage[parameter] = value
}
///http://www.khronos.org/opengles/sdk/docs/man/xhtml/glTexParameter.xml
cmd void glTexParameteri(TextureTarget target,
TextureParameter parameter,
s32 value) {
ctx := GetContext()
id := ctx.TextureUnits[ctx.ActiveTextureUnit][target]
t := ctx.Instances.Textures[id]
switch (parameter) {
case GL_TEXTURE_MAG_FILTER: t.MagFilter = as!TextureFilterMode(value)
case GL_TEXTURE_MIN_FILTER: t.MinFilter = as!TextureFilterMode(value)
case GL_TEXTURE_WRAP_S: t.WrapS = as!TextureWrapMode(value)
case GL_TEXTURE_WRAP_T: t.WrapT = as!TextureWrapMode(value)
case GL_TEXTURE_MAX_ANISOTROPY_EXT: t.MaxAnisotropy = as!f32(value)
case GL_TEXTURE_SWIZZLE_R: t.SwizzleR = as!TexelComponent(value)
case GL_TEXTURE_SWIZZLE_G: t.SwizzleG = as!TexelComponent(value)
case GL_TEXTURE_SWIZZLE_B: t.SwizzleB = as!TexelComponent(value)
case GL_TEXTURE_SWIZZLE_A: t.SwizzleA = as!TexelComponent(value)
}
}
///http://www.khronos.org/opengles/sdk/docs/man/xhtml/glTexParameter.xml
cmd void glTexParameterf(TextureTarget target,
TextureParameter parameter,
f32 value) {
ctx := GetContext()
id := ctx.TextureUnits[ctx.ActiveTextureUnit][target]
t := ctx.Instances.Textures[id]
switch (parameter) {
case GL_TEXTURE_MAG_FILTER: t.MagFilter = as!TextureFilterMode(value)
case GL_TEXTURE_MIN_FILTER: t.MinFilter = as!TextureFilterMode(value)
case GL_TEXTURE_WRAP_S: t.WrapS = as!TextureWrapMode(value)
case GL_TEXTURE_WRAP_T: t.WrapT = as!TextureWrapMode(value)
case GL_TEXTURE_MAX_ANISOTROPY_EXT: t.MaxAnisotropy = as!f32(value)
case GL_TEXTURE_SWIZZLE_R: t.SwizzleR = as!TexelComponent(value)
case GL_TEXTURE_SWIZZLE_G: t.SwizzleG = as!TexelComponent(value)
case GL_TEXTURE_SWIZZLE_B: t.SwizzleB = as!TexelComponent(value)
case GL_TEXTURE_SWIZZLE_A: t.SwizzleA = as!TexelComponent(value)
}
}
///http://www.khronos.org/opengles/sdk/docs/man/xhtml/glGetTexParameter.xml
cmd void glGetTexParameteriv(TextureTarget target,
TextureParameter parameter,
s32* values) {
ctx := GetContext()
id := ctx.TextureUnits[ctx.ActiveTextureUnit][target]
t := ctx.Instances.Textures[id]
values[0] = switch (parameter) {
case GL_TEXTURE_MAG_FILTER: as!s32(t.MagFilter)
case GL_TEXTURE_MIN_FILTER: as!s32(t.MinFilter)
case GL_TEXTURE_WRAP_S: as!s32(t.WrapS)
case GL_TEXTURE_WRAP_T: as!s32(t.WrapT)
case GL_TEXTURE_MAX_ANISOTROPY_EXT: as!s32(t.MaxAnisotropy)
case GL_TEXTURE_SWIZZLE_R: as!s32(t.SwizzleR)
case GL_TEXTURE_SWIZZLE_G: as!s32(t.SwizzleG)
case GL_TEXTURE_SWIZZLE_B: as!s32(t.SwizzleB)
case GL_TEXTURE_SWIZZLE_A: as!s32(t.SwizzleA)
}
}
///http://www.khronos.org/opengles/sdk/docs/man/xhtml/glGetTexParameter.xml
cmd void glGetTexParameterfv(TextureTarget target,
TextureParameter parameter,
f32* values) {
ctx := GetContext()
id := ctx.TextureUnits[ctx.ActiveTextureUnit][target]
t := ctx.Instances.Textures[id]
values[0] = switch (parameter) {
case GL_TEXTURE_MAG_FILTER: as!f32(t.MagFilter)
case GL_TEXTURE_MIN_FILTER: as!f32(t.MinFilter)
case GL_TEXTURE_WRAP_S: as!f32(t.WrapS)
case GL_TEXTURE_WRAP_T: as!f32(t.WrapT)
case GL_TEXTURE_MAX_ANISOTROPY_EXT: as!f32(t.MaxAnisotropy)
case GL_TEXTURE_SWIZZLE_R: as!f32(t.SwizzleR)
case GL_TEXTURE_SWIZZLE_G: as!f32(t.SwizzleG)
case GL_TEXTURE_SWIZZLE_B: as!f32(t.SwizzleB)
case GL_TEXTURE_SWIZZLE_A: as!f32(t.SwizzleA)
}
}
///http://www.khronos.org/opengles/sdk/docs/man/xhtml/glUniform.xml
cmd void glUniform1i(UniformLocation location, s32 value) {
ctx := GetContext()
program := ctx.Instances.Programs[ctx.BoundProgram]
uniform := program.Uniforms[location]
uniform.Type = GL_INT
uniform.Value.S32 = value
program.Uniforms[location] = uniform
}
///http://www.khronos.org/opengles/sdk/docs/man/xhtml/glUniform.xml
cmd void glUniform2i(UniformLocation location, s32 value0, s32 value1) {
ctx := GetContext()
program := ctx.Instances.Programs[ctx.BoundProgram]
uniform := program.Uniforms[location]
uniform.Type = GL_INT_VEC2
uniform.Value.Vec2i = Vec2i(value0, value1)
program.Uniforms[location] = uniform
}
///http://www.khronos.org/opengles/sdk/docs/man/xhtml/glUniform.xml
cmd void glUniform3i(UniformLocation location, s32 value0, s32 value1, s32 value2) {
ctx := GetContext()
program := ctx.Instances.Programs[ctx.BoundProgram]
uniform := program.Uniforms[location]
uniform.Type = GL_INT_VEC3
uniform.Value.Vec3i = Vec3i(value0, value1, value2)
program.Uniforms[location] = uniform
}
///http://www.khronos.org/opengles/sdk/docs/man/xhtml/glUniform.xml
cmd void glUniform4i(UniformLocation location, s32 value0, s32 value1, s32 value2, s32 value3) {
ctx := GetContext()
program := ctx.Instances.Programs[ctx.BoundProgram]
uniform := program.Uniforms[location]
uniform.Type = GL_INT_VEC4
uniform.Value.Vec4i = Vec4i(value0, value1, value2, value3)
program.Uniforms[location] = uniform
}
///http://www.khronos.org/opengles/sdk/docs/man/xhtml/glUniform.xml
cmd void glUniform1iv(UniformLocation location, s32 count, s32* value) {
ctx := GetContext()
program := ctx.Instances.Programs[ctx.BoundProgram]
// TODO: Use count
uniform := program.Uniforms[location]
uniform.Type = GL_INT
uniform.Value.S32 = value[0]
program.Uniforms[location] = uniform
}
///http://www.khronos.org/opengles/sdk/docs/man/xhtml/glUniform.xml
cmd void glUniform2iv(UniformLocation location, s32 count, s32* value) {
ctx := GetContext()
v := value[0:count*2]
program := ctx.Instances.Programs[ctx.BoundProgram]
// TODO: Use count
uniform := program.Uniforms[location]
uniform.Type = GL_INT_VEC2
uniform.Value.Vec2i = Vec2i(v[0], v[1])
program.Uniforms[location] = uniform
}
///http://www.khronos.org/opengles/sdk/docs/man/xhtml/glUniform.xml
cmd void glUniform3iv(UniformLocation location, s32 count, s32* value) {
ctx := GetContext()
v := value[0:count*3]
program := ctx.Instances.Programs[ctx.BoundProgram]
// TODO: Use count
uniform := program.Uniforms[location]
uniform.Type = GL_INT_VEC3
uniform.Value.Vec3i = Vec3i(v[0], v[1], v[2])
program.Uniforms[location] = uniform
}
///http://www.khronos.org/opengles/sdk/docs/man/xhtml/glUniform.xml
cmd void glUniform4iv(UniformLocation location, s32 count, s32* value) {
ctx := GetContext()
v := value[0:count*4]
program := ctx.Instances.Programs[ctx.BoundProgram]
// TODO: Use count
uniform := program.Uniforms[location]
uniform.Type = GL_INT_VEC4
uniform.Value.Vec4i = Vec4i(v[0], v[1], v[2], v[3])
program.Uniforms[location] = uniform
}
///http://www.khronos.org/opengles/sdk/docs/man/xhtml/glUniform.xml
cmd void glUniform1f(UniformLocation location, f32 value) {
ctx := GetContext()
program := ctx.Instances.Programs[ctx.BoundProgram]
uniform := program.Uniforms[location]
uniform.Type = GL_FLOAT
uniform.Value.F32 = value
program.Uniforms[location] = uniform
}
///http://www.khronos.org/opengles/sdk/docs/man/xhtml/glUniform.xml
cmd void glUniform2f(UniformLocation location, f32 value0, f32 value1) {
ctx := GetContext()
program := ctx.Instances.Programs[ctx.BoundProgram]
uniform := program.Uniforms[location]
uniform.Type = GL_FLOAT_VEC2
uniform.Value.Vec2f = Vec2f(value0, value1)
program.Uniforms[location] = uniform
}
///http://www.khronos.org/opengles/sdk/docs/man/xhtml/glUniform.xml
cmd void glUniform3f(UniformLocation location, f32 value0, f32 value1, f32 value2) {
ctx := GetContext()
program := ctx.Instances.Programs[ctx.BoundProgram]
uniform := program.Uniforms[location]
uniform.Type = GL_FLOAT_VEC3
uniform.Value.Vec3f = Vec3f(value0, value1, value2)
program.Uniforms[location] = uniform
}
///http://www.khronos.org/opengles/sdk/docs/man/xhtml/glUniform.xml
cmd void glUniform4f(UniformLocation location, f32 value0, f32 value1, f32 value2, f32 value3) {
ctx := GetContext()
program := ctx.Instances.Programs[ctx.BoundProgram]
uniform := program.Uniforms[location]
uniform.Type = GL_FLOAT_VEC4
uniform.Value.Vec4f = Vec4f(value0, value1, value2, value3)
program.Uniforms[location] = uniform
}
///http://www.khronos.org/opengles/sdk/docs/man/xhtml/glUniform.xml
cmd void glUniform1fv(UniformLocation location, s32 count, f32* value) {
ctx := GetContext()
v := value[0:count]
program := ctx.Instances.Programs[ctx.BoundProgram]
// TODO: Use count
uniform := program.Uniforms[location]
uniform.Type = GL_FLOAT
uniform.Value.F32 = v[0]
program.Uniforms[location] = uniform
}
///http://www.khronos.org/opengles/sdk/docs/man/xhtml/glUniform.xml
cmd void glUniform2fv(UniformLocation location, s32 count, f32* value) {
ctx := GetContext()
v := value[0:count*2]
program := ctx.Instances.Programs[ctx.BoundProgram]
// TODO: Use count
uniform := program.Uniforms[location]
uniform.Type = GL_FLOAT_VEC2
uniform.Value.Vec2f = Vec2f(v[0], v[1])
program.Uniforms[location] = uniform
}
///http://www.khronos.org/opengles/sdk/docs/man/xhtml/glUniform.xml
cmd void glUniform3fv(UniformLocation location, s32 count, f32* value) {
ctx := GetContext()
v := value[0:count*3]
// TODO: Use count
program := ctx.Instances.Programs[ctx.BoundProgram]
uniform := program.Uniforms[location]
uniform.Type = GL_FLOAT_VEC3
uniform.Value.Vec3f = Vec3f(v[0], v[1], v[2])
program.Uniforms[location] = uniform
}
///http://www.khronos.org/opengles/sdk/docs/man/xhtml/glUniform.xml
cmd void glUniform4fv(UniformLocation location, s32 count, f32* value) {
ctx := GetContext()
v := value[0:count*4]
// TODO: Use count
program := ctx.Instances.Programs[ctx.BoundProgram]
uniform := program.Uniforms[location]
uniform.Type = GL_FLOAT_VEC4
uniform.Value.Vec4f = Vec4f(v[0], v[1], v[2], v[3])
program.Uniforms[location] = uniform
}
///http://www.khronos.org/opengles/sdk/docs/man/xhtml/glUniform.xml
cmd void glUniformMatrix2fv(UniformLocation location, s32 count, bool transpose, f32* values) {
ctx := GetContext()
v := values[0:count*4]
// TODO: Use count
program := ctx.Instances.Programs[ctx.BoundProgram]
uniform := program.Uniforms[location]
uniform.Type = GL_FLOAT_MAT2
uniform.Value.Mat2f = Mat2f(
Vec2f(v[0], v[1]),
Vec2f(v[3], v[4]),
)
program.Uniforms[location] = uniform
}
///http://www.khronos.org/opengles/sdk/docs/man/xhtml/glUniform.xml
cmd void glUniformMatrix3fv(UniformLocation location, s32 count, bool transpose, f32* values) {
ctx := GetContext()
v := values[0:count*9]
// TODO: Use count
program := ctx.Instances.Programs[ctx.BoundProgram]
uniform := program.Uniforms[location]
uniform.Type = GL_FLOAT_MAT3
uniform.Value.Mat3f = Mat3f(
Vec3f(v[0], v[1], v[2]),
Vec3f(v[3], v[4], v[5]),
Vec3f(v[6], v[7], v[8]),
)
program.Uniforms[location] = uniform
}
///http://www.khronos.org/opengles/sdk/docs/man/xhtml/glUniform.xml
cmd void glUniformMatrix4fv(UniformLocation location, s32 count, bool transpose, f32* values) {
ctx := GetContext()
v := values[0:count*16]
// TODO: Use count
program := ctx.Instances.Programs[ctx.BoundProgram]
uniform := program.Uniforms[location]
uniform.Value.Mat4f = Mat4f(
Vec4f(v[0], v[1], v[2], v[3]),
Vec4f(v[4], v[5], v[6], v[7]),
Vec4f(v[8], v[9], v[10], v[11]),
Vec4f(v[12], v[13], v[14], v[15]),
)
program.Uniforms[location] = uniform
}
///http://www.khronos.org/opengles/sdk/docs/man/xhtml/glGetUniform.xml
cmd void glGetUniformfv(ProgramId program, UniformLocation location, f32* values) {
// p := Instances.Programs[program]
// uniform := p.Uniforms[location]
}
///http://www.khronos.org/opengles/sdk/docs/man/xhtml/glGetUniform.xml
cmd void glGetUniformiv(ProgramId program, UniformLocation location, s32* values) {
// p := Instances.Programs[program]
// uniform := p.Uniforms[location]
}
///http://www.khronos.org/opengles/sdk/docs/man/xhtml/glVertexAttrib.xml
cmd void glVertexAttrib1f(AttributeLocation location, f32 value0) {
}
///http://www.khronos.org/opengles/sdk/docs/man/xhtml/glVertexAttrib.xml
cmd void glVertexAttrib2f(AttributeLocation location, f32 value0, f32 value1) {
}
///http://www.khronos.org/opengles/sdk/docs/man/xhtml/glVertexAttrib.xml
cmd void glVertexAttrib3f(AttributeLocation location, f32 value0, f32 value1, f32 value2) {
}
///http://www.khronos.org/opengles/sdk/docs/man/xhtml/glVertexAttrib.xml
cmd void glVertexAttrib4f(AttributeLocation location, f32 value0, f32 value1, f32 value2, f32 value3) {
}
///http://www.khronos.org/opengles/sdk/docs/man/xhtml/glVertexAttrib.xml
cmd void glVertexAttrib1fv(AttributeLocation location, f32* value) {
read(value[0:1])
}
///http://www.khronos.org/opengles/sdk/docs/man/xhtml/glVertexAttrib.xml
cmd void glVertexAttrib2fv(AttributeLocation location, f32* value) {
read(value[0:2])
}
///http://www.khronos.org/opengles/sdk/docs/man/xhtml/glVertexAttrib.xml
cmd void glVertexAttrib3fv(AttributeLocation location, f32* value) {
read(value[0:3])
}
///http://www.khronos.org/opengles/sdk/docs/man/xhtml/glVertexAttrib.xml
cmd void glVertexAttrib4fv(AttributeLocation location, f32* value) {
read(value[0:4])
}
///http://www.khronos.org/opengles/sdk/docs/man/xhtml/glGetShaderPrecisionFormat.xml
cmd void glGetShaderPrecisionFormat(ShaderType shader_type, PrecisionType precision_type, s32* range, s32* precision) {
write(range[0:2])
precision[0] = ?
}
///http://www.khronos.org/opengles/sdk/docs/man/xhtml/glDepthMask.xml
cmd void glDepthMask(bool enabled) {
ctx := GetContext()
ctx.Rasterizing.DepthMask = enabled
}
///http://www.khronos.org/opengles/sdk/docs/man/xhtml/glDepthFunc.xml
cmd void glDepthFunc(TestFunction function) {
ctx := GetContext()
ctx.Rasterizing.DepthTestFunction = function
}
///http://www.khronos.org/opengles/sdk/docs/man/xhtml/glDepthRangef.xml
cmd void glDepthRangef(f32 near, f32 far) {
ctx := GetContext()
ctx.Rasterizing.DepthNear = near
ctx.Rasterizing.DepthFar = far
}
///http://www.khronos.org/opengles/sdk/docs/man/xhtml/glColorMask.xml
cmd void glColorMask(bool red, bool green, bool blue, bool alpha) {
ctx := GetContext()
ctx.Rasterizing.ColorMaskRed = red
ctx.Rasterizing.ColorMaskGreen = green
ctx.Rasterizing.ColorMaskBlue = blue
ctx.Rasterizing.ColorMaskAlpha = alpha
}
///http://www.khronos.org/opengles/sdk/docs/man/xhtml/glStencilMask.xml
cmd void glStencilMask(u32 mask) {
ctx := GetContext()
ctx.Rasterizing.StencilMask[GL_FRONT] = mask
ctx.Rasterizing.StencilMask[GL_BACK] = mask
}
///http://www.khronos.org/opengles/sdk/docs/man/xhtml/glStencilMaskSeparate.xml
cmd void glStencilMaskSeparate(FaceMode face, u32 mask) {
ctx := GetContext()
switch (face) {
case GL_FRONT: ctx.Rasterizing.StencilMask[GL_FRONT] = mask
case GL_BACK: ctx.Rasterizing.StencilMask[GL_BACK] = mask
case GL_FRONT_AND_BACK: {
ctx.Rasterizing.StencilMask[GL_FRONT] = mask
ctx.Rasterizing.StencilMask[GL_BACK] = mask
}
}
}
///http://www.khronos.org/opengles/sdk/docs/man/xhtml/glStencilFuncSeparate.xml
cmd void glStencilFuncSeparate(FaceMode face,
TestFunction function,
s32 reference_value,
s32 mask) {
}
///http://www.khronos.org/opengles/sdk/docs/man/xhtml/glStencilOpSeparate.xml
cmd void glStencilOpSeparate(FaceMode face,
StencilAction stencil_fail,
StencilAction stencil_pass_depth_fail,
StencilAction stencil_pass_depth_pass) {
}
///http://www.khronos.org/opengles/sdk/docs/man/xhtml/glFrontFace.xml
cmd void glFrontFace(FaceOrientation orientation) {
ctx := GetContext()
ctx.Rasterizing.FrontFace = orientation
}
///http://www.khronos.org/opengles/sdk/docs/man/xhtml/glViewport.xml
cmd void glViewport(s32 x, s32 y, s32 width, s32 height) {
ctx := GetContext()
ctx.Rasterizing.Viewport = Rect(x, y, width, height)
}
///http://www.khronos.org/opengles/sdk/docs/man/xhtml/glScissor.xml
cmd void glScissor(s32 x, s32 y, s32 width, s32 height) {
ctx := GetContext()
ctx.Rasterizing.Scissor = Rect(x, y, width, height)
}
///http://www.khronos.org/opengles/sdk/docs/man/xhtml/glActiveTexture.xml
cmd void glActiveTexture(TextureUnit unit) {
ctx := GetContext()
ctx.ActiveTextureUnit = unit
if !(unit in ctx.TextureUnits) {
ctx.TextureUnits[unit] = ctx.TextureUnits[unit]
}
}
///http://www.khronos.org/opengles/sdk/docs/man/xhtml/glGenTextures.xml
cmd void glGenTextures(s32 count, TextureId* textures) {
t := textures[0:count]
ctx := GetContext()
for i in (0 .. count) {
id := as!TextureId(?)
ctx.Instances.Textures[id] = new!Texture()
t[i] = id
}
}
///http://www.khronos.org/opengles/sdk/docs/man/xhtml/glDeleteTextures.xml
cmd void glDeleteTextures(s32 count, TextureId* textures) {
t := textures[0:count]
ctx := GetContext()
for i in (0 .. count) {
ctx.Instances.Textures[t[i]] = null
}
}
///http://www.khronos.org/opengles/sdk/docs/man/xhtml/glIsTexture.xml
cmd bool glIsTexture(TextureId texture) {
ctx := GetContext()
return texture in ctx.Instances.Textures
}
///http://www.khronos.org/opengles/sdk/docs/man/xhtml/glBindTexture.xml
cmd void glBindTexture(TextureTarget target, TextureId texture) {
ctx := GetContext()
if !(texture in ctx.Instances.Textures) {
ctx.Instances.Textures[texture] = new!Texture()
}
ctx.TextureUnits[ctx.ActiveTextureUnit][target] = texture
}
///http://www.khronos.org/opengles/sdk/docs/man/xhtml/glTexImage2D.xml
cmd void glTexImage2D(TextureImageTarget target,
s32 level,
TexelFormat internal_format,
s32 width,
s32 height,
s32 border,
TexelFormat format,
TexelType type,
TexturePointer data) {
assert(internal_format == format)
assert(border == 0)
ctx := GetContext()
switch(target) {
case GL_TEXTURE_2D: {
id := ctx.TextureUnits[ctx.ActiveTextureUnit][GL_TEXTURE_2D]
t := ctx.Instances.Textures[id]
l := Image(
Width: width,
Height: height,
Size: imageSize(as!u32(width), as!u32(height), format, type),
Format: as!ImageTexelFormat(format) /* TODO: Implicit cast? */,
)
if (data != null) {
if (ctx.BoundBuffers[GL_PIXEL_UNPACK_BUFFER] == 0) {
l.Data = clone(as!u8*(data)[0:l.Size])
}
} else {
l.Data = make!u8(l.Size)
}
t.Texture2D[level] = l
t.Kind = TEXTURE2D // TODO: Warning/Error if kind has changed?
// TODO: Warning/Error if format has changed
t.Format = as!ImageTexelFormat(format) // TODO: Implicit cast?
}
case GL_TEXTURE_CUBE_MAP_POSITIVE_X, GL_TEXTURE_CUBE_MAP_POSITIVE_Y, GL_TEXTURE_CUBE_MAP_POSITIVE_Z,
GL_TEXTURE_CUBE_MAP_NEGATIVE_X, GL_TEXTURE_CUBE_MAP_NEGATIVE_Y, GL_TEXTURE_CUBE_MAP_NEGATIVE_Z: {
id := ctx.TextureUnits[ctx.ActiveTextureUnit][GL_TEXTURE_CUBE_MAP]
t := ctx.Instances.Textures[id]
l := Image(
Width: width,
Height: height,
Size: imageSize(as!u32(width), as!u32(height), format, type),
Format: as!ImageTexelFormat(format) /* TODO: Implicit cast? */,
)
if (data != null) {
if (ctx.BoundBuffers[GL_PIXEL_UNPACK_BUFFER] == 0) {
l.Data = clone(as!u8*(data)[0:l.Size])
}
} else {
l.Data = make!u8(l.Size)
}
cube := t.Cubemap[level]
cube.Faces[as!CubeMapImageTarget(target)] = l
t.Cubemap[level] = cube
t.Kind = CUBEMAP // TODO: Warning/Error if kind has changed?
// TODO: Warning/Error if format has changed
t.Format = as!ImageTexelFormat(format) // TODO: Implicit cast?
}
}
}
///http://www.khronos.org/opengles/sdk/docs/man/xhtml/glTexSubImage2D.xml
cmd void glTexSubImage2D(TextureImageTarget target,
s32 level,
s32 xoffset,
s32 yoffset,
s32 width,
s32 height,
TexelFormat format,
TexelType type,
TexturePointer data) {
ctx := GetContext()
// TODO: This does not consider xoffset or yoffset and completely replaces the level.
// FIX.
switch(target) {
case GL_TEXTURE_2D: {
id := ctx.TextureUnits[ctx.ActiveTextureUnit][GL_TEXTURE_2D]
t := ctx.Instances.Textures[id]
l := Image(
Width: width,
Height: height,
Size: imageSize(as!u32(width), as!u32(height), format, type),
Format: as!ImageTexelFormat(format) /* TODO: Implicit cast? */,
)
if (ctx.BoundBuffers[GL_PIXEL_UNPACK_BUFFER] == 0) && (data != null) {
l.Data = clone(as!u8*(data)[0:l.Size])
}
t.Texture2D[level] = l
t.Kind = TEXTURE2D // TODO: Warning/Error if kind has changed?
// TODO: Warning/Error if format has changed
t.Format = as!ImageTexelFormat(format) // TODO: Implicit cast?
}
case GL_TEXTURE_CUBE_MAP_POSITIVE_X, GL_TEXTURE_CUBE_MAP_POSITIVE_Y, GL_TEXTURE_CUBE_MAP_POSITIVE_Z,
GL_TEXTURE_CUBE_MAP_NEGATIVE_X, GL_TEXTURE_CUBE_MAP_NEGATIVE_Y, GL_TEXTURE_CUBE_MAP_NEGATIVE_Z: {
id := ctx.TextureUnits[ctx.ActiveTextureUnit][GL_TEXTURE_CUBE_MAP]
t := ctx.Instances.Textures[id]
l := Image(
Width: width,
Height: height,
Size: imageSize(as!u32(width), as!u32(height), format, type),
Format: as!ImageTexelFormat(format) /* TODO: Implicit cast? */,
)
if (ctx.BoundBuffers[GL_PIXEL_UNPACK_BUFFER] == 0) && (data != null) {
l.Data = clone(as!u8*(data)[0:l.Size])
}
cube := t.Cubemap[level]
cube.Faces[as!CubeMapImageTarget(target)] = l
t.Cubemap[level] = cube
t.Kind = CUBEMAP // TODO: Warning/Error if kind has changed?
// TODO: Warning/Error if format has changed
t.Format = as!ImageTexelFormat(format) // TODO: Implicit cast?
}
}
}
///http://www.khronos.org/opengles/sdk/docs/man/xhtml/glCopyTexImage2D.xml
cmd void glCopyTexImage2D(TextureImageTarget target,
s32 level,
TexelFormat format,
s32 x,
s32 y,
s32 width,
s32 height,
s32 border) {
}
///http://www.khronos.org/opengles/sdk/docs/man/xhtml/glCopyTexSubImage2D.xml
cmd void glCopyTexSubImage2D(TextureImageTarget target,
s32 level,
s32 xoffset,
s32 yoffset,
s32 x,
s32 y,
s32 width,
s32 height) {
}
///http://www.khronos.org/opengles/sdk/docs/man/xhtml/glCompressedTexImage2D.xml
cmd void glCompressedTexImage2D(TextureImageTarget target,
s32 level,
CompressedTexelFormat format,
s32 width,
s32 height,
s32 border,
s32 image_size,
TexturePointer data) {
assert(border == 0)
ctx := GetContext()
switch(target) {
case GL_TEXTURE_2D: {
id := ctx.TextureUnits[ctx.ActiveTextureUnit][GL_TEXTURE_2D]
t := ctx.Instances.Textures[id]
l := Image(
Width: width,
Height: height,
Size: as!u32(image_size),
Format: as!ImageTexelFormat(format) /* TODO: Implicit cast? */,
)
if (ctx.BoundBuffers[GL_PIXEL_UNPACK_BUFFER] == 0) && (data != null) {
l.Data = clone(as!u8*(data)[0:l.Size])
}
t.Texture2D[level] = l
t.Kind = TEXTURE2D // TODO: Warning/Error if kind has changed?
// TODO: Warning/Error if format has changed
t.Format = as!ImageTexelFormat(format) // TODO: Implicit cast?
}
case GL_TEXTURE_CUBE_MAP_POSITIVE_X, GL_TEXTURE_CUBE_MAP_POSITIVE_Y, GL_TEXTURE_CUBE_MAP_POSITIVE_Z,
GL_TEXTURE_CUBE_MAP_NEGATIVE_X, GL_TEXTURE_CUBE_MAP_NEGATIVE_Y, GL_TEXTURE_CUBE_MAP_NEGATIVE_Z: {
id := ctx.TextureUnits[ctx.ActiveTextureUnit][GL_TEXTURE_CUBE_MAP]
t := ctx.Instances.Textures[id]
l := Image(
Width: width,
Height: height,
Size: as!u32(image_size),
Format: as!ImageTexelFormat(format) /* TODO: Implicit cast? */,
)
if (ctx.BoundBuffers[GL_PIXEL_UNPACK_BUFFER] == 0) && (data != null) {
l.Data = clone(as!u8*(data)[0:l.Size])
}
cube := t.Cubemap[level]
cube.Faces[as!CubeMapImageTarget(target)] = l
t.Cubemap[level] = cube
t.Kind = CUBEMAP // TODO: Warning/Error if kind has changed?
// TODO: Warning/Error if format has changed
t.Format = as!ImageTexelFormat(format) // TODO: Implicit cast?
}
}
}
///http://www.khronos.org/opengles/sdk/docs/man/xhtml/glCompressedTexSubImage2D.xml
cmd void glCompressedTexSubImage2D(TextureImageTarget target,
s32 level,
s32 xoffset,
s32 yoffset,
s32 width,
s32 height,
CompressedTexelFormat format,
s32 image_size,
TexturePointer data) {
}
///http://www.khronos.org/opengles/sdk/docs/man/xhtml/glGenerateMipmap.xml
cmd void glGenerateMipmap(TextureImageTarget target) {
}
///http://www.khronos.org/opengles/sdk/docs/man/xhtml/glReadPixels.xml
cmd void glReadPixels(s32 x,
s32 y,
s32 width,
s32 height,
BaseTexelFormat format,
TexelType type,
void* data) {
write(data[0:imageSize(as!u32(width), as!u32(height), as!TexelFormat(format), type)])
}
///http://www.khronos.org/opengles/sdk/docs/man/xhtml/glGenFramebuffers.xml
cmd void glGenFramebuffers(s32 count, FramebufferId* framebuffers) {
f := framebuffers[0:count]
ctx := GetContext()
for i in (0 .. count) {
id := as!FramebufferId(?)
ctx.Instances.Framebuffers[id] = new!Framebuffer()
f[i] = id
}
}
///http://www.khronos.org/opengles/sdk/docs/man/xhtml/glBindFramebuffer.xml
cmd void glBindFramebuffer(FramebufferTarget target, FramebufferId framebuffer) {
ctx := GetContext()
if !(framebuffer in ctx.Instances.Framebuffers) {
ctx.Instances.Framebuffers[framebuffer] = new!Framebuffer()
}
if target == GL_FRAMEBUFFER {
ctx.BoundFramebuffers[GL_READ_FRAMEBUFFER] = framebuffer
ctx.BoundFramebuffers[GL_DRAW_FRAMEBUFFER] = framebuffer
} else {
ctx.BoundFramebuffers[target] = framebuffer
}
}
///http://www.khronos.org/opengles/sdk/docs/man/xhtml/glCheckFramebufferStatus.xml
cmd FramebufferStatus glCheckFramebufferStatus(FramebufferTarget target) {
return ?
}
///http://www.khronos.org/opengles/sdk/docs/man/xhtml/glDeleteFramebuffers.xml
cmd void glDeleteFramebuffers(s32 count, FramebufferId* framebuffers) {
f := framebuffers[0:count]
ctx := GetContext()
for i in (0 .. count) {
ctx.Instances.Framebuffers[f[i]] = null
}
}
///http://www.khronos.org/opengles/sdk/docs/man/xhtml/glIsFramebuffer.xml
cmd bool glIsFramebuffer(FramebufferId framebuffer) {
ctx := GetContext()
return framebuffer in ctx.Instances.Framebuffers
}
///http://www.khronos.org/opengles/sdk/docs/man/xhtml/glGenRenderbuffers.xml
cmd void glGenRenderbuffers(s32 count, RenderbufferId* renderbuffers) {
r := renderbuffers[0:count]
ctx := GetContext()
for i in (0 .. count) {
id := as!RenderbufferId(?)
ctx.Instances.Renderbuffers[id] = new!Renderbuffer()
r[i] = id
}
}
///http://www.khronos.org/opengles/sdk/docs/man/xhtml/glBindRenderbuffer.xml
cmd void glBindRenderbuffer(RenderbufferTarget target, RenderbufferId renderbuffer) {
ctx := GetContext()
if !(renderbuffer in ctx.Instances.Renderbuffers) {
ctx.Instances.Renderbuffers[renderbuffer] = new!Renderbuffer()
}
ctx.BoundRenderbuffers[target] = renderbuffer
}
///http://www.khronos.org/opengles/sdk/docs/man/xhtml/glRenderbufferStorage.xml
cmd void glRenderbufferStorage(RenderbufferTarget target,
RenderbufferFormat format,
s32 width,
s32 height) {
ctx := GetContext()
id := ctx.BoundRenderbuffers[target]
rb := ctx.Instances.Renderbuffers[id]
rb.Format = format
rb.Width = width
rb.Height = height
}
///http://www.khronos.org/opengles/sdk/docs/man/xhtml/glDeleteRenderbuffers.xml
cmd void glDeleteRenderbuffers(s32 count, RenderbufferId* renderbuffers) {
r := renderbuffers[0:count]
ctx := GetContext()
for i in (0 .. count) {
ctx.Instances.Renderbuffers[r[i]] = null
}
}
///http://www.khronos.org/opengles/sdk/docs/man/xhtml/glIsRenderbuffer.xml
cmd bool glIsRenderbuffer(RenderbufferId renderbuffer) {
ctx := GetContext()
return renderbuffer in ctx.Instances.Renderbuffers
}
///http://www.khronos.org/opengles/sdk/docs/man/xhtml/glGetRenderbufferParameteriv.xml
cmd void glGetRenderbufferParameteriv(RenderbufferTarget target,
RenderbufferParameter parameter,
s32* values) {
ctx := GetContext()
id := ctx.BoundRenderbuffers[target]
rb := ctx.Instances.Renderbuffers[id]
values[0] = switch (parameter) {
case GL_RENDERBUFFER_WIDTH: rb.Width
case GL_RENDERBUFFER_HEIGHT: rb.Height
case GL_RENDERBUFFER_INTERNAL_FORMAT: as!s32(rb.Format)
// TODO:
// case GL_RENDERBUFFER_RED_SIZE: ?
// case GL_RENDERBUFFER_GREEN_SIZE: ?
// case GL_RENDERBUFFER_BLUE_SIZE: ?
// case GL_RENDERBUFFER_ALPHA_SIZE: ?
// case GL_RENDERBUFFER_DEPTH_SIZE: ?
// case GL_RENDERBUFFER_STENCIL_SIZE: ?
}
}
///http://www.khronos.org/opengles/sdk/docs/man/xhtml/glGenBuffers.xml
cmd void glGenBuffers(s32 count, BufferId* buffers) {
b := buffers[0:count]
ctx := GetContext()
for i in (0 .. count) {
id := as!BufferId(?)
ctx.Instances.Buffers[id] = new!Buffer()
b[i] = id
}
}
///http://www.khronos.org/opengles/sdk/docs/man/xhtml/glBindBuffer.xml
cmd void glBindBuffer(BufferTarget target, BufferId buffer) {
ctx := GetContext()
if !(buffer in ctx.Instances.Buffers) {
ctx.Instances.Buffers[buffer] = new!Buffer()
}
ctx.BoundBuffers[target] = buffer
}
///http://www.khronos.org/opengles/sdk/docs/man/xhtml/glBufferData.xml
cmd void glBufferData(BufferTarget target, s32 size, BufferDataPointer data, BufferUsage usage) {
ctx := GetContext()
id := ctx.BoundBuffers[target]
b := ctx.Instances.Buffers[id]
b.Data = switch(data != null) {
case true: clone(as!u8*(data)[0:size])
case false: make!u8(size)
}
b.Size = size
b.Usage = usage
}
///http://www.khronos.org/opengles/sdk/docs/man/xhtml/glBufferSubData.xml
cmd void glBufferSubData(BufferTarget target, s32 offset, s32 size, void* data) {
read(data[0:size])
// TODO: Assignment to subset
}
///http://www.khronos.org/opengles/sdk/docs/man/xhtml/glDeleteBuffers.xml
cmd void glDeleteBuffers(s32 count, BufferId* buffers) {
b := buffers[0:count]
ctx := GetContext()
for i in (0 .. count) {
ctx.Instances.Buffers[b[i]] = null
}
}
///http://www.khronos.org/opengles/sdk/docs/man/xhtml/glIsBuffer.xml
cmd bool glIsBuffer(BufferId buffer) {
ctx := GetContext()
return buffer in ctx.Instances.Buffers
}
///http://www.khronos.org/opengles/sdk/docs/man/xhtml/glGetBufferParameteriv.xml
cmd void glGetBufferParameteriv(BufferTarget target,
BufferParameter parameter,
s32* value) {
ctx := GetContext()
id := ctx.BoundBuffers[target]
b := ctx.Instances.Buffers[id]
value[0] = switch (parameter) {
case GL_BUFFER_SIZE: as!s32(b.Size)
case GL_BUFFER_USAGE: as!s32(b.Usage)
}
}
///http://www.khronos.org/opengles/sdk/docs/man/xhtml/glCreateShader.xml
cmd ShaderId glCreateShader(ShaderType type) {
ctx := GetContext()
id := as!ShaderId(?)
ctx.Instances.Shaders[id] = new!Shader()
s := ctx.Instances.Shaders[id]
s.Type = type
return id
}
///http://www.khronos.org/opengles/sdk/docs/man/xhtml/glDeleteShader.xml
cmd void glDeleteShader(ShaderId shader) {
ctx := GetContext()
s := ctx.Instances.Shaders[shader]
s.Deletable = true
// TODO: refcount shader attachment and only destroy if zero
ctx.Instances.Shaders[shader] = null
}
///http://www.khronos.org/opengles/sdk/docs/man/xhtml/glShaderSource.xml
cmd void glShaderSource(ShaderId shader, s32 count, char** source, s32* length) {
sources := source[0:count]
lengths := length[0:count]
ctx := GetContext()
s := ctx.Instances.Shaders[shader]
for i in (0 .. count) {
l := switch ((length == null) || (lengths[i] < 0)) {
case true: strlen(sources[i])
case false: as!u32(lengths[i])
}
// TODO: We should have a newline between sources to avoid unintentional
// concatenation. The language currently does not support string literals.
s.Source += as!string(sources[i][0:l])
}
}
///http://www.khronos.org/opengles/sdk/docs/man/xhtml/glShaderBinary.xml
cmd void glShaderBinary(s32 count,
ShaderId* shaders,
u32 binary_format,
void* binary,
s32 binary_size) {
for i in (0 .. count) {
// TODO: shaders[i].Binary = ?
}
}
///http://www.khronos.org/opengles/sdk/docs/man/xhtml/glGetShaderInfoLog.xml
cmd void glGetShaderInfoLog(ShaderId shader,
s32 buffer_length,
s32* string_length_written,
char* info) {
ctx := GetContext()
s := ctx.Instances.Shaders[shader]
l := min(buffer_length, as!s32(strlen(s.InfoLog)))
copy(info[0:l], s.InfoLog[0:l])
string_length_written[0] = l
}
///http://www.khronos.org/opengles/sdk/docs/man/xhtml/glGetShaderSource.xml
cmd void glGetShaderSource(ShaderId shader,
s32 buffer_length,
s32* string_length_written,
char* source) {
ctx := GetContext()
s := ctx.Instances.Shaders[shader]
l := min(buffer_length, as!s32(strlen(s.Source)))
copy(source[0:l], as!char[](s.Source)[0:l])
string_length_written[0] = l
}
///http://www.khronos.org/opengles/sdk/docs/man/xhtml/glReleaseShaderCompiler.xml
cmd void glReleaseShaderCompiler() {
}
///http://www.khronos.org/opengles/sdk/docs/man/xhtml/glCompileShader.xml
cmd void glCompileShader(ShaderId shader) {
// TODO: shader.Binary < ?
}
///http://www.khronos.org/opengles/sdk/docs/man/xhtml/glIsShader.xml
cmd bool glIsShader(ShaderId shader) {
ctx := GetContext()
return shader in ctx.Instances.Shaders
}
///http://www.khronos.org/opengles/sdk/docs/man/xhtml/glCreateProgram.xml
cmd ProgramId glCreateProgram() {
ctx := GetContext()
id := as!ProgramId(?)
ctx.Instances.Programs[id] = new!Program()
return id
}
///http://www.khronos.org/opengles/sdk/docs/man/xhtml/glDeleteProgram.xml
cmd void glDeleteProgram(ProgramId program) {
ctx := GetContext()
ctx.Instances.Programs[program] = null
}
///http://www.khronos.org/opengles/sdk/docs/man/xhtml/glAttachShader.xml
cmd void glAttachShader(ProgramId program, ShaderId shader) {
ctx := GetContext()
p := ctx.Instances.Programs[program]
s := ctx.Instances.Shaders[shader]
p.Shaders[s.Type] = shader
}
///http://www.khronos.org/opengles/sdk/docs/man/xhtml/glDetachShader.xml
cmd void glDetachShader(ProgramId program, ShaderId shader) {
ctx := GetContext()
p := ctx.Instances.Programs[program]
s := ctx.Instances.Shaders[shader]
p.Shaders[s.Type] = null
}
///http://www.khronos.org/opengles/sdk/docs/man/xhtml/glGetAttachedShaders.xml
cmd void glGetAttachedShaders(ProgramId program,
s32 buffer_length,
s32* shaders_length_written,
ShaderId* shaders) {
ctx := GetContext()
p := ctx.Instances.Programs[program]
l := min(buffer_length, len(p.Shaders))
shaders_length_written[0] = l
// TODO: Requires language support.
// for i, k, v in p.Shaders {
// if i < l {
// shaders[i] = v
// }
// }
}
///http://www.khronos.org/opengles/sdk/docs/man/xhtml/glLinkProgram.xml
cmd void glLinkProgram(ProgramId program) {
//for s in (program.Shaders) {
// TODO: use(s.Binary)
//}
// TODO: program.Binary < ?
}
///http://www.khronos.org/opengles/sdk/docs/man/xhtml/glGetProgramInfoLog.xml
cmd void glGetProgramInfoLog(ProgramId program,
s32 buffer_length,
s32* string_length_written,
char* info) {
ctx := GetContext()
p := ctx.Instances.Programs[program]
l := min(buffer_length, as!s32(strlen(p.InfoLog)))
copy(info[0:l], p.InfoLog[0:l])
string_length_written[0] = l
}
///http://www.khronos.org/opengles/sdk/docs/man/xhtml/glUseProgram.xml
cmd void glUseProgram(ProgramId program) {
ctx := GetContext()
ctx.BoundProgram = program
}
///http://www.khronos.org/opengles/sdk/docs/man/xhtml/glIsProgram.xml
cmd bool glIsProgram(ProgramId program) {
ctx := GetContext()
return program in ctx.Instances.Programs
}
///http://www.khronos.org/opengles/sdk/docs/man/xhtml/glValidateProgram.xml
cmd void glValidateProgram(ProgramId program) {
}
///http://www.khronos.org/opengles/sdk/docs/man/xhtml/glClearColor.xml
cmd void glClearColor(f32 r, f32 g, f32 b, f32 a) {
ctx := GetContext()
ctx.Clearing.ClearColor = Color(r, g, b, a)
}
///http://www.khronos.org/opengles/sdk/docs/man/xhtml/glClearDepthf.xml
cmd void glClearDepthf(f32 depth) {
ctx := GetContext()
ctx.Clearing.ClearDepth = depth
}
///http://www.khronos.org/opengles/sdk/docs/man/xhtml/glClearStencil.xml
cmd void glClearStencil(s32 stencil) {
ctx := GetContext()
ctx.Clearing.ClearStencil = stencil
}
///http://www.khronos.org/opengles/sdk/docs/man/xhtml/glClear.xml
cmd void glClear(ClearMask mask) {
// TODO: use(Clearing.ClearColor) when mask[GL_COLOR_BUFFER_BIT] == true
if (GL_COLOR_BUFFER_BIT in mask) {
// color := BoundFramebuffers[GL_FRAMEBUFFER].Attachments[GL_COLOR_ATTACHMENT0]
// error("Attempting to clear missing color buffer") if !exists(color)
// modifies(color.Levels[0].Data) // COMPILATION ERROR
}
}
///http://www.khronos.org/opengles/sdk/docs/man/xhtml/glCullFace.xml
cmd void glCullFace(FaceMode mode) {
ctx := GetContext()
ctx.Rasterizing.CullFace = mode
}
///http://www.khronos.org/opengles/sdk/docs/man/xhtml/glPolygonOffset.xml
cmd void glPolygonOffset(f32 scale_factor, f32 units) {
ctx := GetContext()
ctx.Rasterizing.PolygonOffsetUnits = units
ctx.Rasterizing.PolygonOffsetFactor = scale_factor
}
///http://www.khronos.org/opengles/sdk/docs/man/xhtml/glLineWidth.xml
cmd void glLineWidth(f32 width) {
ctx := GetContext()
ctx.Rasterizing.LineWidth = width
}
///http://www.khronos.org/opengles/sdk/docs/man/xhtml/glSampleCoverage.xml
cmd void glSampleCoverage(f32 value, bool invert) {
ctx := GetContext()
ctx.Rasterizing.SampleCoverageValue = value
ctx.Rasterizing.SampleCoverageInvert = invert
}
///http://www.khronos.org/opengles/sdk/docs/man/xhtml/glHint.xml
cmd void glHint(HintTarget target, HintMode mode) {
ctx := GetContext()
ctx.GenerateMipmapHint = mode
}
///http://www.khronos.org/opengles/sdk/docs/man/xhtml/glFramebufferRenderbuffer.xml
cmd void glFramebufferRenderbuffer(FramebufferTarget framebuffer_target,
FramebufferAttachment framebuffer_attachment,
RenderbufferTarget renderbuffer_target,
RenderbufferId renderbuffer) {
ctx := GetContext()
target := switch (framebuffer_target) {
case GL_FRAMEBUFFER: as!FramebufferTarget(GL_DRAW_FRAMEBUFFER)
case GL_DRAW_FRAMEBUFFER: as!FramebufferTarget(GL_DRAW_FRAMEBUFFER)
case GL_READ_FRAMEBUFFER: as!FramebufferTarget(GL_READ_FRAMEBUFFER)
}
framebufferId := ctx.BoundFramebuffers[target]
framebuffer := ctx.Instances.Framebuffers[framebufferId]
attachment := framebuffer.Attachments[framebuffer_attachment]
if (renderbuffer == 0) {
attachment.Type = GL_NONE
} else {
attachment.Type = GL_RENDERBUFFER
}
attachment.Object = as!u32(renderbuffer)
attachment.TextureLevel = 0
attachment.CubeMapFace = GL_TEXTURE_CUBE_MAP_POSITIVE_X
framebuffer.Attachments[framebuffer_attachment] = attachment
}
///http://www.khronos.org/opengles/sdk/docs/man/xhtml/glFramebufferTexture2D.xml
cmd void glFramebufferTexture2D(FramebufferTarget framebuffer_target,
FramebufferAttachment framebuffer_attachment,
TextureImageTarget texture_target,
TextureId texture,
s32 level) {
ctx := GetContext()
target := switch (framebuffer_target) {
case GL_FRAMEBUFFER: as!FramebufferTarget(GL_DRAW_FRAMEBUFFER)
case GL_DRAW_FRAMEBUFFER: as!FramebufferTarget(GL_DRAW_FRAMEBUFFER)
case GL_READ_FRAMEBUFFER: as!FramebufferTarget(GL_READ_FRAMEBUFFER)
}
framebufferId := ctx.BoundFramebuffers[target]
framebuffer := ctx.Instances.Framebuffers[framebufferId]
attachment := framebuffer.Attachments[framebuffer_attachment]
if (texture == 0) {
attachment.Type = GL_NONE
attachment.Object = 0
attachment.TextureLevel = 0
attachment.CubeMapFace = GL_TEXTURE_CUBE_MAP_POSITIVE_X
} else {
attachment.Type = GL_TEXTURE
attachment.Object = as!u32(texture)
attachment.TextureLevel = level
attachment.CubeMapFace = switch (texture_target) {
case GL_TEXTURE_2D: GL_TEXTURE_CUBE_MAP_POSITIVE_X
case GL_TEXTURE_CUBE_MAP_POSITIVE_X: GL_TEXTURE_CUBE_MAP_POSITIVE_X
case GL_TEXTURE_CUBE_MAP_POSITIVE_Y: GL_TEXTURE_CUBE_MAP_POSITIVE_Y
case GL_TEXTURE_CUBE_MAP_POSITIVE_Z: GL_TEXTURE_CUBE_MAP_POSITIVE_Z
case GL_TEXTURE_CUBE_MAP_NEGATIVE_X: GL_TEXTURE_CUBE_MAP_NEGATIVE_X
case GL_TEXTURE_CUBE_MAP_NEGATIVE_Y: GL_TEXTURE_CUBE_MAP_NEGATIVE_Y
case GL_TEXTURE_CUBE_MAP_NEGATIVE_Z: GL_TEXTURE_CUBE_MAP_NEGATIVE_Z
}
}
framebuffer.Attachments[framebuffer_attachment] = attachment
}
///http://www.khronos.org/opengles/sdk/docs/man/xhtml/glGetFramebufferAttachmentParameteriv.xml
cmd void glGetFramebufferAttachmentParameteriv(FramebufferTarget framebuffer_target,
FramebufferAttachment attachment,
FramebufferAttachmentParameter parameter,
s32* value) {
ctx := GetContext()
target := switch (framebuffer_target) {
case GL_FRAMEBUFFER: as!FramebufferTarget(GL_DRAW_FRAMEBUFFER)
case GL_DRAW_FRAMEBUFFER: as!FramebufferTarget(GL_DRAW_FRAMEBUFFER)
case GL_READ_FRAMEBUFFER: as!FramebufferTarget(GL_READ_FRAMEBUFFER)
}
framebufferId := ctx.BoundFramebuffers[target]
framebuffer := ctx.Instances.Framebuffers[framebufferId]
a := framebuffer.Attachments[attachment]
value[0] = switch (parameter) {
case GL_FRAMEBUFFER_ATTACHMENT_OBJECT_TYPE: as!s32(a.Type)
case GL_FRAMEBUFFER_ATTACHMENT_OBJECT_NAME: as!s32(a.Object)
case GL_FRAMEBUFFER_ATTACHMENT_TEXTURE_LEVEL: as!s32(a.TextureLevel)
case GL_FRAMEBUFFER_ATTACHMENT_TEXTURE_CUBE_MAP_FACE: as!s32(a.CubeMapFace)
}
}
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(IndicesType 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, IndicesType indices_type, u32 offset, u32 count)
extern u32 maxIndex(u8* indices, IndicesType indices_type, u32 offset, u32 count)
@DrawCall
///http://www.khronos.org/opengles/sdk/docs/man/xhtml/glDrawElements.xml
cmd void glDrawElements(DrawMode draw_mode,
s32 element_count,
IndicesType indices_type,
IndicesPointer indices) {
ctx := GetContext()
count := as!u32(element_count)
id := ctx.BoundBuffers[GL_ELEMENT_ARRAY_BUFFER]
if (id != 0) {
// Element array buffer bound - indices is an offset on the buffer.
index_data := ctx.Instances.Buffers[id].Data
offset := as!u32(as!u64(indices))
// Read the vertices
first := minIndex(as!u8*(index_data), indices_type, offset, count)
last := maxIndex(as!u8*(index_data), indices_type, offset, count)
ReadVertexArrays(ctx, first, last)
// No need to read the indices - they're already in a GPU-side buffer.
} else {
// No element array buffer bound - indices is a pointer.
index_data := as!u8*(indices)
// Read the vertices
first := minIndex(index_data, indices_type, 0, count)
last := maxIndex(index_data, indices_type, 0, count)
ReadVertexArrays(ctx, first, last)
// Read the indices
read(index_data[0:(as!u32(element_count)) * IndexSize(indices_type)])
}
}
@DrawCall
///http://www.khronos.org/opengles/sdk/docs/man/xhtml/glDrawArrays.xml
cmd void glDrawArrays(DrawMode draw_mode, s32 first_index, s32 index_count) {
ctx := GetContext()
last_index := first_index + index_count - 1
ReadVertexArrays(ctx, as!u32(first_index), as!u32(last_index))
}
///http://www.khronos.org/opengles/sdk/docs/man/xhtml/glFlush.xml
cmd void glFlush() {
}
///http://www.khronos.org/opengles/sdk/docs/man/xhtml/glFinish.xml
cmd void glFinish() {
}
///http://www.khronos.org/opengles/sdk/docs/man/xhtml/glGet.xml
cmd void glGetBooleanv(StateVariable param, bool* values) {
v := values[0:stateVariableSize(param)]
ctx := GetContext()
switch (param) {
case GL_BLEND:
v[0] = ctx.Capabilities[GL_BLEND]
case GL_CULL_FACE:
v[0] = ctx.Capabilities[GL_CULL_FACE]
case GL_DEPTH_TEST:
v[0] = ctx.Capabilities[GL_DEPTH_TEST]
case GL_DITHER:
v[0] = ctx.Capabilities[GL_DITHER]
case GL_POLYGON_OFFSET_FILL:
v[0] = ctx.Capabilities[GL_POLYGON_OFFSET_FILL]
case GL_SAMPLE_ALPHA_TO_COVERAGE:
v[0] = ctx.Capabilities[GL_SAMPLE_ALPHA_TO_COVERAGE]
case GL_SAMPLE_COVERAGE:
v[0] = ctx.Capabilities[GL_SAMPLE_COVERAGE]
case GL_SCISSOR_TEST:
v[0] = ctx.Capabilities[GL_SCISSOR_TEST]
case GL_STENCIL_TEST:
v[0] = ctx.Capabilities[GL_STENCIL_TEST]
case GL_DEPTH_WRITEMASK:
v[0] = ctx.Rasterizing.DepthMask
case GL_COLOR_WRITEMASK: {
v[0] = ctx.Rasterizing.ColorMaskRed
v[1] = ctx.Rasterizing.ColorMaskGreen
v[2] = ctx.Rasterizing.ColorMaskBlue
v[3] = ctx.Rasterizing.ColorMaskAlpha
}
case GL_SAMPLE_COVERAGE_INVERT:
v[0] = ctx.Rasterizing.SampleCoverageInvert
case GL_SHADER_COMPILER:
v[0] = ?
case GL_MAX_TEXTURE_MAX_ANISOTROPY_EXT:
v[0] = ?
// TODO: all the values returned by glGetFloatv and glGetIntegerv can
// be returned here with a type conversion where GL_FALSE is only returned
// if the value is 0.0 (or 0).
}
}
///http://www.khronos.org/opengles/sdk/docs/man/xhtml/glGet.xml
cmd void glGetFloatv(StateVariable param, f32* values) {
v := values[0:stateVariableSize(param)]
ctx := GetContext()
switch (param) {
case GL_DEPTH_RANGE: {
v[0] = ctx.Rasterizing.DepthNear
v[1] = ctx.Rasterizing.DepthFar
}
case GL_LINE_WIDTH:
v[0] = ctx.Rasterizing.LineWidth
case GL_POLYGON_OFFSET_FACTOR:
v[0] = ctx.Rasterizing.PolygonOffsetFactor
case GL_POLYGON_OFFSET_UNITS:
v[0] = ctx.Rasterizing.PolygonOffsetUnits
case GL_SAMPLE_COVERAGE_VALUE:
v[0] = ctx.Rasterizing.SampleCoverageValue
case GL_COLOR_CLEAR_VALUE: {
v[0] = ctx.Clearing.ClearColor.Red
v[1] = ctx.Clearing.ClearColor.Green
v[2] = ctx.Clearing.ClearColor.Blue
v[3] = ctx.Clearing.ClearColor.Alpha
}
case GL_DEPTH_CLEAR_VALUE:
v[0] = ctx.Clearing.ClearDepth
case GL_ALIASED_LINE_WIDTH_RANGE: {
v[0] = ? /* smallest */
v[1] = ? /* largest */
}
case GL_ALIASED_POINT_SIZE_RANGE: {
v[0] = ? /* smallest */
v[1] = ? /* largest */
}
case GL_MAX_TEXTURE_MAX_ANISOTROPY_EXT:
v[0] = ?
// TODO: all the values returned by glGetBooleanv and glGetIntegerv can
// be returned here with a type conversion.
}
}
///http://www.khronos.org/opengles/sdk/docs/man/xhtml/glGet.xml
cmd void glGetIntegerv(StateVariable param, s32* values) {
v := values[0:stateVariableSize(param)]
ctx := GetContext()
switch (param) {
case GL_ACTIVE_TEXTURE:
v[0] = as!s32(ctx.ActiveTextureUnit)
case GL_ARRAY_BUFFER_BINDING:
v[0] = as!s32(ctx.BoundBuffers[GL_ARRAY_BUFFER])
case GL_ELEMENT_ARRAY_BUFFER_BINDING:
v[0] = as!s32(ctx.BoundBuffers[GL_ELEMENT_ARRAY_BUFFER])
case GL_BLEND_SRC_ALPHA:
v[0] = as!s32(ctx.Blending.SrcAlphaBlendFactor)
case GL_BLEND_SRC_RGB:
v[0] = as!s32(ctx.Blending.SrcRgbBlendFactor)
case GL_BLEND_DST_ALPHA:
v[0] = as!s32(ctx.Blending.DstAlphaBlendFactor)
case GL_BLEND_DST_RGB:
v[0] = as!s32(ctx.Blending.DstRgbBlendFactor)
case GL_BLEND_EQUATION_RGB:
v[0] = as!s32(ctx.Blending.BlendEquationRgb)
case GL_BLEND_EQUATION_ALPHA:
v[0] = as!s32(ctx.Blending.BlendEquationAlpha)
case GL_BLEND_COLOR: {
v[0] = as!s32(ctx.Blending.BlendColor.Red)
v[1] = as!s32(ctx.Blending.BlendColor.Green)
v[2] = as!s32(ctx.Blending.BlendColor.Blue)
v[3] = as!s32(ctx.Blending.BlendColor.Alpha)
}
case GL_DEPTH_FUNC:
v[0] = as!s32(ctx.Rasterizing.DepthTestFunction)
case GL_DEPTH_CLEAR_VALUE:
v[0] = as!s32(ctx.Clearing.ClearDepth)
case GL_STENCIL_WRITEMASK:
v[0] = as!s32(ctx.Rasterizing.StencilMask[GL_FRONT])
case GL_STENCIL_BACK_WRITEMASK:
v[0] = as!s32(ctx.Rasterizing.StencilMask[GL_BACK])
case GL_VIEWPORT: {
v[0] = ctx.Rasterizing.Viewport.X
v[1] = ctx.Rasterizing.Viewport.Y
v[2] = ctx.Rasterizing.Viewport.Width
v[3] = ctx.Rasterizing.Viewport.Height
}
case GL_SCISSOR_BOX: {
v[0] = ctx.Rasterizing.Scissor.X
v[1] = ctx.Rasterizing.Scissor.Y
v[2] = ctx.Rasterizing.Scissor.Width
v[3] = ctx.Rasterizing.Scissor.Height
}
case GL_FRONT_FACE:
v[0] = as!s32(ctx.Rasterizing.FrontFace)
case GL_CULL_FACE_MODE:
v[0] = as!s32(ctx.Rasterizing.CullFace)
case GL_STENCIL_CLEAR_VALUE:
v[0] = ctx.Clearing.ClearStencil
case GL_FRAMEBUFFER_BINDING:
v[0] = as!s32(ctx.BoundFramebuffers[GL_FRAMEBUFFER])
case GL_READ_FRAMEBUFFER_BINDING:
v[0] = as!s32(ctx.BoundFramebuffers[GL_READ_FRAMEBUFFER])
case GL_RENDERBUFFER_BINDING:
v[0] = as!s32(ctx.BoundRenderbuffers[GL_RENDERBUFFER])
case GL_CURRENT_PROGRAM:
v[0] = as!s32(ctx.BoundProgram)
case GL_TEXTURE_BINDING_2D:
v[0] = as!s32(ctx.TextureUnits[ctx.ActiveTextureUnit][GL_TEXTURE_2D])
case GL_TEXTURE_BINDING_CUBE_MAP:
v[0] = as!s32(ctx.TextureUnits[ctx.ActiveTextureUnit][GL_TEXTURE_CUBE_MAP])
case GL_GENERATE_MIPMAP_HINT:
v[0] = as!s32(ctx.GenerateMipmapHint)
case GL_MAX_COMBINED_TEXTURE_IMAGE_UNITS: {
result := ?
assert(result > 7)
v[0] = result
}
case GL_MAX_CUBE_MAP_TEXTURE_SIZE: {
result := ?
assert(result > 15)
v[0] = result
}
case GL_MAX_FRAGMENT_UNIFORM_VECTORS: {
result := ?
assert(result > 15)
v[0] = result
}
case GL_MAX_RENDERBUFFER_SIZE: {
result := ?
assert(result > 0)
v[0] = result
}
case GL_MAX_TEXTURE_IMAGE_UNITS: {
result := ?
assert(result > 7)
v[0] = result
}
case GL_MAX_TEXTURE_SIZE: {
result := ?
assert(result > 63)
v[0] = result
}
case GL_MAX_VARYING_VECTORS: {
result := ?
assert(result > 7)
v[0] = result
}
case GL_MAX_VERTEX_ATTRIBS: {
result := ?
assert(result > 7)
v[0] = result
}
case GL_MAX_VERTEX_TEXTURE_IMAGE_UNITS:
v[0] = ?
case GL_MAX_VERTEX_UNIFORM_VECTORS: {
result := ?
assert(result > 127)
v[0] = result
}
case GL_MAX_VIEWPORT_DIMS: {
max_width := ?
max_height := ?
assert(max_width > ctx.Rasterizing.Viewport.Width-1)
assert(max_height > ctx.Rasterizing.Viewport.Height-1)
v[0] = max_width
v[1] = max_height
}
case GL_NUM_COMPRESSED_TEXTURE_FORMATS: {
result := ?
assert(result > -1)
v[0] = result
}
case GL_NUM_SHADER_BINARY_FORMATS: {
result := ?
assert(result > -1)
v[0] = result
}
case GL_PACK_ALIGNMENT:
v[0] = ctx.PixelStorage[GL_PACK_ALIGNMENT]
case GL_UNPACK_ALIGNMENT:
v[0] = ctx.PixelStorage[GL_UNPACK_ALIGNMENT]
case GL_ALPHA_BITS:
v[0] = ?
case GL_BLUE_BITS:
v[0] = ?
case GL_GREEN_BITS:
v[0] = ?
case GL_RED_BITS:
v[0] = ?
case GL_DEPTH_BITS:
v[0] = ?
case GL_SAMPLE_BUFFERS:
v[0] = ?
case GL_SAMPLES:
v[0] = ?
/*
case GL_SHADER_BINARY_FORMATS:
values = ? // list of length GL_NUM_SHADER_BINARY_FORMATS
case GL_COMPRESSED_TEXTURE_FORMATS:
values = ? // list of length GL_NUM_COMPRESSED_TEXTURE_FORMATS
*/
case GL_STENCIL_BITS:
v[0] = ?
case GL_SUBPIXEL_BITS: {
result := ?
assert(result > 3)
v[0] = result
}
case GL_IMPLEMENTATION_COLOR_READ_FORMAT:
v[0] = ?
case GL_IMPLEMENTATION_COLOR_READ_TYPE:
v[0] = ?
case GL_MAX_TEXTURE_MAX_ANISOTROPY_EXT:
v[0] = ?
case GL_GPU_DISJOINT_EXT:
v[0] = ?
// TODO: implement the following which depend on:
// glStencilOp, glStencilOpSeparate, glStencilFuncSeparate.
// GL_STENCIL_BACK_FAIL
// GL_STENCIL_BACK_FUNC
// GL_STENCIL_BACK_PASS_DEPTH_FAIL
// GL_STENCIL_BACK_PASS_DEPTH_PASS
// GL_STENCIL_BACK_REF
// GL_STENCIL_BACK_VALUE_MASK
// GL_STENCIL_FAIL
// GL_STENCIL_FUNC
// GL_STENCIL_PASS_DEPTH_FAIL
// GL_STENCIL_PASS_DEPTH_PASS
// GL_STENCIL_REF
// GL_STENCIL_VALUE_MASK
// TODO: all the values returned by glGetFloatv and glGetBooleanv can
// be returned here with a type conversion: "_most_ floating-point values
// are rounded to the nearest integer value".
}
}
///http://www.khronos.org/opengles/sdk/docs/man/xhtml/glGetString.xml
cmd char* glGetString(StringConstant param) {
return null
}
///http://www.khronos.org/opengles/sdk/docs/man/xhtml/glEnable.xml
cmd void glEnable(Capability capability) {
ctx := GetContext()
ctx.Capabilities[capability] = true
}
///http://www.khronos.org/opengles/sdk/docs/man/xhtml/glDisable.xml
cmd void glDisable(Capability capability) {
ctx := GetContext()
ctx.Capabilities[capability] = false
}
///http://www.khronos.org/opengles/sdk/docs/man/xhtml/glIsEnabled.xml
cmd bool glIsEnabled(Capability capability) {
ctx := GetContext()
return ctx.Capabilities[capability]
}
/////////////////////////////////////////////////////////////////
// GLES 3 APIs
/////////////////////////////////////////////////////////////////
/*
// TODO: SyncObject is not a regular class/GL object, alias it handle<separately>.
class SyncObject{}
enum SyncCondition {
GL_SYNC_GPU_COMMANDS_COMPLETE = 0x9117,
}
enum ClientWaitSyncSignal {
GL_ALREADY_SIGNALED = 0x911A,
GL_TIMEOUT_EXPIRED = 0x911B,
GL_CONDITION_SATISFIED = 0x911C,
GL_WAIT_FAILED = 0x911D,
}
bitfield SyncFlags {}
///http://www.khronos.org/opengles/sdk/docs/man3/html/glFenceSync.xhtml
cmd SyncObject glFenceSync(SyncCondition condition, SyncFlags flags) {
return ?
create(result)
}
///http://www.khronos.org/opengles/sdk/docs/man3/html/glDeleteSync.xhtml
cmd void glDeleteSync(SyncObject sync) {
Instances.SyncObjects.Delete(sync)
}
///http://www.khronos.org/opengles/sdk/docs/man3/html/glClientWaitSync.xhtml
cmd ClientWaitSyncSignal glClientWaitSync(SyncObject sync, SyncFlags flags, s32 timeout) {
}
*/
///http://www.khronos.org/opengles/sdk/docs/man3/html/glMapBufferRange.xhtml
cmd void* glMapBufferRange(BufferTarget target, s32 offset, s32 length, MapBufferRangeAccess access) {
return ?
}
///http://www.khronos.org/opengles/sdk/docs/man3/html/glMapBufferRange.xhtml
cmd void glUnmapBuffer(BufferTarget target) {
}
///http://www.khronos.org/opengles/sdk/docs/man3/html/glInvalidateFramebuffer.xhtml
cmd void glInvalidateFramebuffer(FramebufferTarget target,
s32 count,
FramebufferAttachment* attachments) {
}
///http://www.opengl.org/registry/specs/EXT/framebuffer_multisample.txt
cmd void glRenderbufferStorageMultisample(RenderbufferTarget target,
s32 samples,
RenderbufferFormat format,
s32 width,
s32 height) {
}
///http://www.khronos.org/opengles/sdk/docs/man3/html/glBlitFramebuffer.xhtml
cmd void glBlitFramebuffer(s32 srcX0,
s32 srcY0,
s32 srcX1,
s32 srcY1,
s32 dstX0,
s32 dstY0,
s32 dstX1,
s32 dstY1,
ClearMask mask,
TextureFilterMode filter) {
}
///http://www.khronos.org/opengles/sdk/docs/man3/html/glGenQueries.xhtml
cmd void glGenQueries(s32 count, QueryId* queries) {
q := queries[0:count]
ctx := GetContext()
for i in (0 .. count) {
id := as!QueryId(?)
ctx.Instances.Queries[id] = new!Query()
q[i] = id
}
}
///http://www.khronos.org/opengles/sdk/docs/man3/html/glBeginQuery.xhtml
cmd void glBeginQuery(QueryTarget target, QueryId query) {
}
///http://www.khronos.org/opengles/sdk/docs/man3/html/glEndQuery.xhtml
cmd void glEndQuery(QueryTarget target) {
}
///http://www.khronos.org/opengles/sdk/docs/man3/html/glDeleteQueries.xhtml
cmd void glDeleteQueries(s32 count, QueryId* queries) {
q := queries[0:count]
ctx := GetContext()
for i in (0 .. count) {
ctx.Instances.Queries[q[i]] = null
}
}
///http://www.khronos.org/opengles/sdk/docs/man3/html/glIsQuery.xhtml
cmd bool glIsQuery(QueryId query) {
ctx := GetContext()
return query in ctx.Instances.Queries
}
///http://www.khronos.org/opengles/sdk/docs/man3/html/glGetQueryiv.xhtml
cmd void glGetQueryiv(QueryTarget target, QueryParameter parameter, s32* value) {
value[0] = ?
}
///http://www.khronos.org/opengles/sdk/docs/man3/html/glGetQueryObjectuiv.xhtml
cmd void glGetQueryObjectuiv(QueryId query, QueryObjectParameter parameter, u32* value) {
value[0] = ?
}
// EXT_disjoint_timer_query
///http://www.khronos.org/registry/gles/extensions/EXT/EXT_disjoint_timer_query.txt
cmd void glGenQueriesEXT(s32 count, QueryId* queries) {
q := queries[0:count]
ctx := GetContext()
for i in (0 .. count) {
id := as!QueryId(?)
ctx.Instances.Queries[id] = new!Query()
q[i] = id
}
}
///http://www.khronos.org/registry/gles/extensions/EXT/EXT_disjoint_timer_query.txt
cmd void glBeginQueryEXT(QueryTarget target, QueryId query) {
}
///http://www.khronos.org/registry/gles/extensions/EXT/EXT_disjoint_timer_query.txt
cmd void glEndQueryEXT(QueryTarget target) {
}
///http://www.khronos.org/registry/gles/extensions/EXT/EXT_disjoint_timer_query.txt
cmd void glDeleteQueriesEXT(s32 count, QueryId* queries) {
q := queries[0:count]
ctx := GetContext()
for i in (0 .. count) {
ctx.Instances.Queries[q[i]] = null
}
}
///http://www.khronos.org/registry/gles/extensions/EXT/EXT_disjoint_timer_query.txt
cmd bool glIsQueryEXT(QueryId query) {
ctx := GetContext()
return query in ctx.Instances.Queries
}
///http://www.khronos.org/registry/gles/extensions/EXT/EXT_disjoint_timer_query.txt
cmd void glQueryCounterEXT(QueryId query, QueryTarget target) {
}
///http://www.khronos.org/registry/gles/extensions/EXT/EXT_disjoint_timer_query.txt
cmd void glGetQueryivEXT(QueryTarget target, QueryParameter parameter, s32* value) {
value[0] = ?
}
///http://www.khronos.org/registry/gles/extensions/EXT/EXT_disjoint_timer_query.txt
cmd void glGetQueryObjectivEXT(QueryId query, QueryObjectParameter parameter, s32* value) {
value[0] = ?
}
///http://www.khronos.org/registry/gles/extensions/EXT/EXT_disjoint_timer_query.txt
cmd void glGetQueryObjectuivEXT(QueryId query, QueryObjectParameter parameter, u32* value) {
value[0] = ?
}
///http://www.khronos.org/registry/gles/extensions/EXT/EXT_disjoint_timer_query.txt
cmd void glGetQueryObjecti64vEXT(QueryId query, QueryObjectParameter parameter, s64* value) {
value[0] = ?
}
///http://www.khronos.org/registry/gles/extensions/EXT/EXT_disjoint_timer_query.txt
cmd void glGetQueryObjectui64vEXT(QueryId query, QueryObjectParameter parameter, u64* value) {
value[0] = ?
}