blob: 5ab5cebab5fdb3b14ffa50bcb567d47c7e0502f8 [file] [log] [blame]
// SwiftShader Software Renderer
//
// Copyright(c) 2005-2013 TransGaming Inc.
//
// All rights reserved. No part of this software may be copied, distributed, transmitted,
// transcribed, stored in a retrieval system, translated into any human or computer
// language by any means, or disclosed to third parties without the explicit written
// agreement of TransGaming Inc. Without such an agreement, no rights or licenses, express
// or implied, including but not limited to any patent rights, are granted to you.
//
// libGL.cpp: Implements the exported OpenGL functions.
#include "main.h"
#include "mathutil.h"
#include "utilities.h"
#include "Buffer.h"
#include "Context.h"
#include "Fence.h"
#include "Framebuffer.h"
#include "Program.h"
#include "Renderbuffer.h"
#include "Shader.h"
#include "Texture.h"
#include "Query.h"
#include "common/debug.h"
#include "Common/Version.h"
#include "Main/Register.hpp"
#define _GDI32_
#include <windows.h>
#include <GL/GL.h>
#include <GL/glext.h>
#include <limits>
static bool validImageSize(GLint level, GLsizei width, GLsizei height)
{
if(level < 0 || level >= gl::IMPLEMENTATION_MAX_TEXTURE_LEVELS || width < 0 || height < 0)
{
return false;
}
return true;
}
static bool validateSubImageParams(bool compressed, GLsizei width, GLsizei height, GLint xoffset, GLint yoffset, GLenum target, GLint level, GLenum format, gl::Texture *texture)
{
if(!texture)
{
return error(GL_INVALID_OPERATION, false);
}
if(compressed != texture->isCompressed(target, level))
{
return error(GL_INVALID_OPERATION, false);
}
if(format != GL_NONE && format != texture->getFormat(target, level) && target != GL_TEXTURE_1D)
{
return error(GL_INVALID_OPERATION, false);
}
if(compressed)
{
if((width % 4 != 0 && width != texture->getWidth(target, 0)) ||
(height % 4 != 0 && height != texture->getHeight(target, 0)))
{
return error(GL_INVALID_OPERATION, false);
}
}
if(xoffset + width > texture->getWidth(target, level) ||
yoffset + height > texture->getHeight(target, level))
{
return error(GL_INVALID_VALUE, false);
}
return true;
}
// Check for combinations of format and type that are valid for ReadPixels
static bool validReadFormatType(GLenum format, GLenum type)
{
switch(format)
{
case GL_RGBA:
switch(type)
{
case GL_UNSIGNED_BYTE:
break;
default:
return false;
}
break;
case GL_BGRA_EXT:
switch(type)
{
case GL_UNSIGNED_BYTE:
case GL_UNSIGNED_SHORT_4_4_4_4_REV:
case GL_UNSIGNED_SHORT_1_5_5_5_REV:
break;
default:
return false;
}
break;
case gl::IMPLEMENTATION_COLOR_READ_FORMAT:
switch(type)
{
case gl::IMPLEMENTATION_COLOR_READ_TYPE:
break;
default:
return false;
}
break;
default:
return false;
}
return true;
}
extern "C"
{
void APIENTRY glActiveTexture(GLenum texture)
{
TRACE("(GLenum texture = 0x%X)", texture);
gl::Context *context = gl::getContext();
if(context)
{
if(context->getListIndex() != 0)
{
UNIMPLEMENTED();
}
if(texture < GL_TEXTURE0 || texture > GL_TEXTURE0 + gl::MAX_COMBINED_TEXTURE_IMAGE_UNITS - 1)
{
return error(GL_INVALID_ENUM);
}
context->setActiveSampler(texture - GL_TEXTURE0);
}
}
void APIENTRY glAttachShader(GLuint program, GLuint shader)
{
TRACE("(GLuint program = %d, GLuint shader = %d)", program, shader);
gl::Context *context = gl::getContext();
if(context)
{
gl::Program *programObject = context->getProgram(program);
gl::Shader *shaderObject = context->getShader(shader);
if(!programObject)
{
if(context->getShader(program))
{
return error(GL_INVALID_OPERATION);
}
else
{
return error(GL_INVALID_VALUE);
}
}
if(!shaderObject)
{
if(context->getProgram(shader))
{
return error(GL_INVALID_OPERATION);
}
else
{
return error(GL_INVALID_VALUE);
}
}
if(!programObject->attachShader(shaderObject))
{
return error(GL_INVALID_OPERATION);
}
}
}
void APIENTRY glBeginQueryEXT(GLenum target, GLuint name)
{
TRACE("(GLenum target = 0x%X, GLuint name = %d)", target, name);
switch(target)
{
case GL_ANY_SAMPLES_PASSED:
case GL_ANY_SAMPLES_PASSED_CONSERVATIVE:
break;
default:
return error(GL_INVALID_ENUM);
}
if(name == 0)
{
return error(GL_INVALID_OPERATION);
}
gl::Context *context = gl::getContext();
if(context)
{
if(context->getListIndex() != 0)
{
UNIMPLEMENTED();
}
context->beginQuery(target, name);
}
}
void APIENTRY glBindAttribLocation(GLuint program, GLuint index, const GLchar* name)
{
TRACE("(GLuint program = %d, GLuint index = %d, const GLchar* name = %s)", program, index, name);
if(index >= gl::MAX_VERTEX_ATTRIBS)
{
return error(GL_INVALID_VALUE);
}
gl::Context *context = gl::getContext();
if(context)
{
gl::Program *programObject = context->getProgram(program);
if(!programObject)
{
if(context->getShader(program))
{
return error(GL_INVALID_OPERATION);
}
else
{
return error(GL_INVALID_VALUE);
}
}
if(strncmp(name, "gl_", 3) == 0)
{
return error(GL_INVALID_OPERATION);
}
programObject->bindAttributeLocation(index, name);
}
}
void APIENTRY glBindBuffer(GLenum target, GLuint buffer)
{
TRACE("(GLenum target = 0x%X, GLuint buffer = %d)", target, buffer);
gl::Context *context = gl::getContext();
if(context)
{
switch(target)
{
case GL_ARRAY_BUFFER:
context->bindArrayBuffer(buffer);
return;
case GL_ELEMENT_ARRAY_BUFFER:
context->bindElementArrayBuffer(buffer);
return;
default:
return error(GL_INVALID_ENUM);
}
}
}
void APIENTRY glBindFramebuffer(GLenum target, GLuint framebuffer)
{
TRACE("(GLenum target = 0x%X, GLuint framebuffer = %d)", target, framebuffer);
if(target != GL_FRAMEBUFFER && target != GL_DRAW_FRAMEBUFFER_EXT && target != GL_READ_FRAMEBUFFER_EXT)
{
return error(GL_INVALID_ENUM);
}
gl::Context *context = gl::getContext();
if(context)
{
if(context->getListIndex() != 0)
{
UNIMPLEMENTED();
}
if(target == GL_READ_FRAMEBUFFER_EXT || target == GL_FRAMEBUFFER)
{
context->bindReadFramebuffer(framebuffer);
}
if(target == GL_DRAW_FRAMEBUFFER_EXT || target == GL_FRAMEBUFFER)
{
context->bindDrawFramebuffer(framebuffer);
}
}
}
void APIENTRY glBindRenderbuffer(GLenum target, GLuint renderbuffer)
{
TRACE("(GLenum target = 0x%X, GLuint renderbuffer = %d)", target, renderbuffer);
if(target != GL_RENDERBUFFER)
{
return error(GL_INVALID_ENUM);
}
gl::Context *context = gl::getContext();
if(context)
{
if(context->getListIndex() != 0)
{
UNIMPLEMENTED();
}
context->bindRenderbuffer(renderbuffer);
}
}
void APIENTRY glBindTexture(GLenum target, GLuint texture)
{
TRACE("(GLenum target = 0x%X, GLuint texture = %d)", target, texture);
gl::Context *context = gl::getContext();
if(context)
{
if(context->getListIndex() != 0)
{
UNIMPLEMENTED();
}
gl::Texture *textureObject = context->getTexture(texture);
if(textureObject && textureObject->getTarget() != target && texture != 0)
{
return error(GL_INVALID_OPERATION);
}
switch(target)
{
case GL_TEXTURE_1D:
context->bindTexture1D(texture);
return;
case GL_TEXTURE_2D:
context->bindTexture2D(texture);
return;
case GL_TEXTURE_CUBE_MAP:
context->bindTextureCubeMap(texture);
return;
default:
return error(GL_INVALID_ENUM);
}
}
}
void APIENTRY glBlendColor(GLclampf red, GLclampf green, GLclampf blue, GLclampf alpha)
{
TRACE("(GLclampf red = %f, GLclampf green = %f, GLclampf blue = %f, GLclampf alpha = %f)",
red, green, blue, alpha);
gl::Context* context = gl::getContext();
if(context)
{
if(context->getListIndex() != 0)
{
UNIMPLEMENTED();
}
context->setBlendColor(gl::clamp01(red), gl::clamp01(green), gl::clamp01(blue), gl::clamp01(alpha));
}
}
void APIENTRY glBlendEquation(GLenum mode)
{
glBlendEquationSeparate(mode, mode);
}
void APIENTRY glBlendEquationSeparate(GLenum modeRGB, GLenum modeAlpha)
{
TRACE("(GLenum modeRGB = 0x%X, GLenum modeAlpha = 0x%X)", modeRGB, modeAlpha);
switch(modeRGB)
{
case GL_FUNC_ADD:
case GL_FUNC_SUBTRACT:
case GL_FUNC_REVERSE_SUBTRACT:
case GL_MIN_EXT:
case GL_MAX_EXT:
break;
default:
return error(GL_INVALID_ENUM);
}
switch(modeAlpha)
{
case GL_FUNC_ADD:
case GL_FUNC_SUBTRACT:
case GL_FUNC_REVERSE_SUBTRACT:
case GL_MIN_EXT:
case GL_MAX_EXT:
break;
default:
return error(GL_INVALID_ENUM);
}
gl::Context *context = gl::getContext();
if(context)
{
if(context->getListIndex() != 0)
{
UNIMPLEMENTED();
}
context->setBlendEquation(modeRGB, modeAlpha);
}
}
void APIENTRY glBlendFunc(GLenum sfactor, GLenum dfactor)
{
glBlendFuncSeparate(sfactor, dfactor, sfactor, dfactor);
}
void APIENTRY glBlendFuncSeparate(GLenum srcRGB, GLenum dstRGB, GLenum srcAlpha, GLenum dstAlpha)
{
TRACE("(GLenum srcRGB = 0x%X, GLenum dstRGB = 0x%X, GLenum srcAlpha = 0x%X, GLenum dstAlpha = 0x%X)",
srcRGB, dstRGB, srcAlpha, dstAlpha);
switch(srcRGB)
{
case GL_ZERO:
case GL_ONE:
case GL_SRC_COLOR:
case GL_ONE_MINUS_SRC_COLOR:
case GL_DST_COLOR:
case GL_ONE_MINUS_DST_COLOR:
case GL_SRC_ALPHA:
case GL_ONE_MINUS_SRC_ALPHA:
case GL_DST_ALPHA:
case GL_ONE_MINUS_DST_ALPHA:
case GL_CONSTANT_COLOR:
case GL_ONE_MINUS_CONSTANT_COLOR:
case GL_CONSTANT_ALPHA:
case GL_ONE_MINUS_CONSTANT_ALPHA:
case GL_SRC_ALPHA_SATURATE:
break;
default:
return error(GL_INVALID_ENUM);
}
switch(dstRGB)
{
case GL_ZERO:
case GL_ONE:
case GL_SRC_COLOR:
case GL_ONE_MINUS_SRC_COLOR:
case GL_DST_COLOR:
case GL_ONE_MINUS_DST_COLOR:
case GL_SRC_ALPHA:
case GL_ONE_MINUS_SRC_ALPHA:
case GL_DST_ALPHA:
case GL_ONE_MINUS_DST_ALPHA:
case GL_CONSTANT_COLOR:
case GL_ONE_MINUS_CONSTANT_COLOR:
case GL_CONSTANT_ALPHA:
case GL_ONE_MINUS_CONSTANT_ALPHA:
break;
default:
return error(GL_INVALID_ENUM);
}
switch(srcAlpha)
{
case GL_ZERO:
case GL_ONE:
case GL_SRC_COLOR:
case GL_ONE_MINUS_SRC_COLOR:
case GL_DST_COLOR:
case GL_ONE_MINUS_DST_COLOR:
case GL_SRC_ALPHA:
case GL_ONE_MINUS_SRC_ALPHA:
case GL_DST_ALPHA:
case GL_ONE_MINUS_DST_ALPHA:
case GL_CONSTANT_COLOR:
case GL_ONE_MINUS_CONSTANT_COLOR:
case GL_CONSTANT_ALPHA:
case GL_ONE_MINUS_CONSTANT_ALPHA:
case GL_SRC_ALPHA_SATURATE:
break;
default:
return error(GL_INVALID_ENUM);
}
switch(dstAlpha)
{
case GL_ZERO:
case GL_ONE:
case GL_SRC_COLOR:
case GL_ONE_MINUS_SRC_COLOR:
case GL_DST_COLOR:
case GL_ONE_MINUS_DST_COLOR:
case GL_SRC_ALPHA:
case GL_ONE_MINUS_SRC_ALPHA:
case GL_DST_ALPHA:
case GL_ONE_MINUS_DST_ALPHA:
case GL_CONSTANT_COLOR:
case GL_ONE_MINUS_CONSTANT_COLOR:
case GL_CONSTANT_ALPHA:
case GL_ONE_MINUS_CONSTANT_ALPHA:
break;
default:
return error(GL_INVALID_ENUM);
}
gl::Context *context = gl::getContext();
if(context)
{
if(context->getListIndex() != 0)
{
UNIMPLEMENTED();
}
context->setBlendFactors(srcRGB, dstRGB, srcAlpha, dstAlpha);
}
}
void APIENTRY glBufferData(GLenum target, GLsizeiptr size, const GLvoid* data, GLenum usage)
{
TRACE("(GLenum target = 0x%X, GLsizeiptr size = %d, const GLvoid* data = %p, GLenum usage = %d)",
target, size, data, usage);
if(size < 0)
{
return error(GL_INVALID_VALUE);
}
switch(usage)
{
case GL_STREAM_DRAW:
case GL_STATIC_DRAW:
case GL_DYNAMIC_DRAW:
break;
default:
return error(GL_INVALID_ENUM);
}
gl::Context *context = gl::getContext();
if(context)
{
gl::Buffer *buffer;
switch(target)
{
case GL_ARRAY_BUFFER:
buffer = context->getArrayBuffer();
break;
case GL_ELEMENT_ARRAY_BUFFER:
buffer = context->getElementArrayBuffer();
break;
default:
return error(GL_INVALID_ENUM);
}
if(!buffer)
{
return error(GL_INVALID_OPERATION);
}
buffer->bufferData(data, size, usage);
}
}
void APIENTRY glBufferSubData(GLenum target, GLintptr offset, GLsizeiptr size, const GLvoid* data)
{
TRACE("(GLenum target = 0x%X, GLintptr offset = %d, GLsizeiptr size = %d, const GLvoid* data = %p)",
target, offset, size, data);
if(size < 0 || offset < 0)
{
return error(GL_INVALID_VALUE);
}
if(data == NULL)
{
return;
}
gl::Context *context = gl::getContext();
if(context)
{
gl::Buffer *buffer;
switch(target)
{
case GL_ARRAY_BUFFER:
buffer = context->getArrayBuffer();
break;
case GL_ELEMENT_ARRAY_BUFFER:
buffer = context->getElementArrayBuffer();
break;
default:
return error(GL_INVALID_ENUM);
}
if(!buffer)
{
return error(GL_INVALID_OPERATION);
}
if((size_t)size + offset > buffer->size())
{
return error(GL_INVALID_VALUE);
}
buffer->bufferSubData(data, size, offset);
}
}
GLenum APIENTRY glCheckFramebufferStatus(GLenum target)
{
TRACE("(GLenum target = 0x%X)", target);
if(target != GL_FRAMEBUFFER && target != GL_DRAW_FRAMEBUFFER_EXT && target != GL_READ_FRAMEBUFFER_EXT)
{
return error(GL_INVALID_ENUM, 0);
}
gl::Context *context = gl::getContext();
if(context)
{
if(context->getListIndex() != 0)
{
UNIMPLEMENTED();
}
gl::Framebuffer *framebuffer = NULL;
if(target == GL_READ_FRAMEBUFFER_EXT)
{
framebuffer = context->getReadFramebuffer();
}
else
{
framebuffer = context->getDrawFramebuffer();
}
return framebuffer->completeness();
}
return 0;
}
void APIENTRY glClear(GLbitfield mask)
{
TRACE("(GLbitfield mask = %X)", mask);
if((mask & ~(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT | GL_STENCIL_BUFFER_BIT)) != 0)
{
return error(GL_INVALID_VALUE);
}
gl::Context *context = gl::getContext();
if(context)
{
if(context->getListIndex() != 0)
{
return context->listCommand(gl::newCommand(glClear, mask));
}
context->clear(mask);
}
}
void APIENTRY glClearColor(GLclampf red, GLclampf green, GLclampf blue, GLclampf alpha)
{
TRACE("(GLclampf red = %f, GLclampf green = %f, GLclampf blue = %f, GLclampf alpha = %f)",
red, green, blue, alpha);
gl::Context *context = gl::getContext();
if(context)
{
if(context->getListIndex() != 0)
{
UNIMPLEMENTED();
}
context->setClearColor(red, green, blue, alpha);
}
}
void APIENTRY glClearDepthf(GLclampf depth)
{
TRACE("(GLclampf depth = %f)", depth);
gl::Context *context = gl::getContext();
if(context)
{
if(context->getListIndex() != 0)
{
UNIMPLEMENTED();
}
context->setClearDepth(depth);
}
}
void APIENTRY glVertexAttrib1dv(GLuint index, const GLdouble *v)
{
TRACE("*");
UNIMPLEMENTED();
}
void APIENTRY glVertexAttrib1sv(GLuint index, const GLshort *v)
{
TRACE("*");
UNIMPLEMENTED();
}
void APIENTRY glVertexAttrib2dv(GLuint index, const GLdouble *v)
{
TRACE("*");
UNIMPLEMENTED();
}
void APIENTRY glVertexAttrib2sv(GLuint index, const GLshort *v)
{
TRACE("*");
UNIMPLEMENTED();
}
void APIENTRY glVertexAttrib3dv(GLuint index, const GLdouble *v)
{
TRACE("*");
UNIMPLEMENTED();
}
void APIENTRY glVertexAttrib3sv(GLuint index, const GLshort *v)
{
TRACE("*");
UNIMPLEMENTED();
}
void APIENTRY glVertexAttrib4Nbv(GLuint index, const GLbyte *v)
{
TRACE("*");
UNIMPLEMENTED();
}
void APIENTRY glVertexAttrib4Niv(GLuint index, const GLint *v)
{
TRACE("*");
UNIMPLEMENTED();
}
void APIENTRY glVertexAttrib4Nsv(GLuint index, const GLshort *v)
{
TRACE("*");
UNIMPLEMENTED();
}
void APIENTRY glVertexAttrib4Nubv(GLuint index, const GLubyte *v)
{
TRACE("*");
UNIMPLEMENTED();
}
void APIENTRY glVertexAttrib4Nuiv(GLuint index, const GLuint *v)
{
TRACE("*");
UNIMPLEMENTED();
}
void APIENTRY glVertexAttrib4Nusv(GLuint index, const GLushort *v)
{
TRACE("*");
UNIMPLEMENTED();
}
void APIENTRY glFogCoordfv(const GLfloat *coord)
{
TRACE("*");
UNIMPLEMENTED();
}
void APIENTRY glFogCoorddv(const GLdouble *coord)
{
TRACE("*");
UNIMPLEMENTED();
}
void APIENTRY glMultiDrawElements(GLenum mode, const GLsizei *count, GLenum type, const void *const*indices, GLsizei drawcount)
{
TRACE("*");
UNIMPLEMENTED();
}
void APIENTRY glSecondaryColor3bv(const GLbyte *v)
{
TRACE("*");
UNIMPLEMENTED();
}
void APIENTRY glSecondaryColor3dv(const GLdouble *v)
{
TRACE("*");
UNIMPLEMENTED();
}
void APIENTRY glSecondaryColor3fv(const GLfloat *v)
{
TRACE("*");
UNIMPLEMENTED();
}
void APIENTRY glSecondaryColor3i(GLint red, GLint green, GLint blue)
{
TRACE("*");
UNIMPLEMENTED();
}
void APIENTRY glSecondaryColor3iv(const GLint *v)
{
TRACE("*");
UNIMPLEMENTED();
}
void APIENTRY glSecondaryColor3s(GLshort red, GLshort green, GLshort blue)
{
TRACE("*");
UNIMPLEMENTED();
}
void APIENTRY glSecondaryColor3sv(const GLshort *v)
{
TRACE("*");
UNIMPLEMENTED();
}
void APIENTRY glSecondaryColor3ubv(const GLubyte *v)
{
TRACE("*");
UNIMPLEMENTED();
}
void APIENTRY glSecondaryColor3ui(GLuint red, GLuint green, GLuint blue)
{
TRACE("*");
UNIMPLEMENTED();
}
void APIENTRY glSecondaryColor3uiv(const GLuint *v)
{
TRACE("*");
UNIMPLEMENTED();
}
void APIENTRY glSecondaryColor3us(GLushort red, GLushort green, GLushort blue)
{
TRACE("*");
UNIMPLEMENTED();
}
void APIENTRY glSecondaryColor3usv(const GLushort *v)
{
TRACE("*");
UNIMPLEMENTED();
}
void APIENTRY glWindowPos2dv(const GLdouble *v)
{
TRACE("*");
UNIMPLEMENTED();
}
void APIENTRY glWindowPos2fv(const GLfloat *v)
{
TRACE("*");
UNIMPLEMENTED();
}
void APIENTRY glWindowPos2iv(const GLint *v)
{
TRACE("*");
UNIMPLEMENTED();
}
void APIENTRY glWindowPos2s(GLshort x, GLshort y)
{
TRACE("*");
UNIMPLEMENTED();
}
void APIENTRY glWindowPos2sv(const GLshort *v)
{
TRACE("*");
UNIMPLEMENTED();
}
void APIENTRY glWindowPos3dv(const GLdouble *v)
{
TRACE("*");
UNIMPLEMENTED();
}
void APIENTRY glWindowPos3fv(const GLfloat *v)
{
TRACE("*");
UNIMPLEMENTED();
}
void APIENTRY glWindowPos3iv(const GLint *v)
{
TRACE("*");
UNIMPLEMENTED();
}
void APIENTRY glWindowPos3s(GLshort x, GLshort y, GLshort z)
{
TRACE("*");
UNIMPLEMENTED();
}
void APIENTRY glWindowPos3sv(const GLshort *v)
{
TRACE("*");
UNIMPLEMENTED();
}
void APIENTRY glMultiTexCoord1dv(GLenum target, const GLdouble *v)
{
TRACE("*");
UNIMPLEMENTED();
}
void APIENTRY glMultiTexCoord1fv(GLenum target, const GLfloat *v)
{
TRACE("*");
UNIMPLEMENTED();
}
void APIENTRY glMultiTexCoord1i(GLenum target, GLint s)
{
TRACE("*");
UNIMPLEMENTED();
}
void APIENTRY glMultiTexCoord1iv(GLenum target, const GLint *v)
{
TRACE("*");
UNIMPLEMENTED();
}
void APIENTRY glMultiTexCoord1s(GLenum target, GLshort s)
{
TRACE("*");
UNIMPLEMENTED();
}
void APIENTRY glMultiTexCoord1sv(GLenum target, const GLshort *v)
{
TRACE("*");
UNIMPLEMENTED();
}
void APIENTRY glMultiTexCoord2dv(GLenum target, const GLdouble *v)
{
TRACE("*");
UNIMPLEMENTED();
}
void APIENTRY glMultiTexCoord2fv(GLenum target, const GLfloat *v)
{
TRACE("*");
UNIMPLEMENTED();
}
void APIENTRY glMultiTexCoord2i(GLenum target, GLint s, GLint t)
{
TRACE("*");
UNIMPLEMENTED();
}
void APIENTRY glMultiTexCoord2iv(GLenum target, const GLint *v)
{
TRACE("*");
UNIMPLEMENTED();
}
void APIENTRY glMultiTexCoord2s(GLenum target, GLshort s, GLshort t)
{
TRACE("*");
UNIMPLEMENTED();
}
void APIENTRY glMultiTexCoord2sv(GLenum target, const GLshort *v)
{
TRACE("*");
UNIMPLEMENTED();
}
void APIENTRY glMultiTexCoord3dv(GLenum target, const GLdouble *v)
{
TRACE("*");
UNIMPLEMENTED();
}
void APIENTRY glMultiTexCoord3fv(GLenum target, const GLfloat *v)
{
TRACE("*");
UNIMPLEMENTED();
}
void APIENTRY glMultiTexCoord3i(GLenum target, GLint s, GLint t, GLint r)
{
TRACE("*");
UNIMPLEMENTED();
}
void APIENTRY glMultiTexCoord3iv(GLenum target, const GLint *v)
{
TRACE("*");
UNIMPLEMENTED();
}
void APIENTRY glMultiTexCoord3s(GLenum target, GLshort s, GLshort t, GLshort r)
{
TRACE("*");
UNIMPLEMENTED();
}
void APIENTRY glMultiTexCoord3sv(GLenum target, const GLshort *v)
{
TRACE("*");
UNIMPLEMENTED();
}
void APIENTRY glMultiTexCoord4dv(GLenum target, const GLdouble *v)
{
TRACE("*");
UNIMPLEMENTED();
}
void APIENTRY glMultiTexCoord4fv(GLenum target, const GLfloat *v)
{
TRACE("*");
UNIMPLEMENTED();
}
void APIENTRY glMultiTexCoord4i(GLenum target, GLint s, GLint t, GLint r, GLint q)
{
TRACE("*");
UNIMPLEMENTED();
}
void APIENTRY glMultiTexCoord4iv(GLenum target, const GLint *v)
{
TRACE("*");
UNIMPLEMENTED();
}
void APIENTRY glMultiTexCoord4s(GLenum target, GLshort s, GLshort t, GLshort r, GLshort q)
{
TRACE("*");
UNIMPLEMENTED();
}
void APIENTRY glMultiTexCoord4sv(GLenum target, const GLshort *v)
{
TRACE("*");
UNIMPLEMENTED();
}
void APIENTRY glBlendEquationEXT(GLenum mode)
{
TRACE("*");
UNIMPLEMENTED();
}
void APIENTRY glBlendFuncSeparateEXT(GLenum sfactorRGB, GLenum dfactorRGB, GLenum sfactorAlpha, GLenum dfactorAlpha)
{
TRACE("*");
UNIMPLEMENTED();
}
void APIENTRY glSecondaryColor3bEXT(GLbyte red, GLbyte green, GLbyte blue)
{
TRACE("*");
UNIMPLEMENTED();
}
void APIENTRY glSecondaryColor3bvEXT(const GLbyte *v)
{
TRACE("*");
UNIMPLEMENTED();
}
void APIENTRY glSecondaryColor3dEXT(GLdouble red, GLdouble green, GLdouble blue)
{
TRACE("*");
UNIMPLEMENTED();
}
void APIENTRY glSecondaryColor3dvEXT(const GLdouble *v)
{
TRACE("*");
UNIMPLEMENTED();
}
void APIENTRY glSecondaryColor3fEXT(GLfloat red, GLfloat green, GLfloat blue)
{
TRACE("*");
UNIMPLEMENTED();
}
void APIENTRY glSecondaryColor3fvEXT(const GLfloat *v)
{
TRACE("*");
UNIMPLEMENTED();
}
void APIENTRY glSecondaryColor3iEXT(GLint red, GLint green, GLint blue)
{
TRACE("*");
UNIMPLEMENTED();
}
void APIENTRY glSecondaryColor3ivEXT(const GLint *v)
{
TRACE("*");
UNIMPLEMENTED();
}
void APIENTRY glSecondaryColor3sEXT(GLshort red, GLshort green, GLshort blue)
{
TRACE("*");
UNIMPLEMENTED();
}
void APIENTRY glSecondaryColor3svEXT(const GLshort *v)
{
TRACE("*");
UNIMPLEMENTED();
}
void APIENTRY glSecondaryColor3ubEXT(GLubyte red, GLubyte green, GLubyte blue)
{
TRACE("*");
UNIMPLEMENTED();
}
void APIENTRY glSecondaryColor3ubvEXT(const GLubyte *v)
{
TRACE("*");
UNIMPLEMENTED();
}
void APIENTRY glSecondaryColor3uiEXT(GLuint red, GLuint green, GLuint blue)
{
TRACE("*");
UNIMPLEMENTED();
}
void APIENTRY glSecondaryColor3uivEXT(const GLuint *v)
{
TRACE("*");
UNIMPLEMENTED();
}
void APIENTRY glSecondaryColor3usEXT(GLushort red, GLushort green, GLushort blue)
{
TRACE("*");
UNIMPLEMENTED();
}
void APIENTRY glSecondaryColor3usvEXT(const GLushort *v)
{
TRACE("*");
UNIMPLEMENTED();
}
void APIENTRY glSecondaryColorPointerEXT(GLint size, GLenum type, GLsizei stride, const void *pointer)
{
TRACE("*");
UNIMPLEMENTED();
}
void APIENTRY glBlitFramebufferEXT(GLint srcX0, GLint srcY0, GLint srcX1, GLint srcY1, GLint dstX0, GLint dstY0, GLint dstX1, GLint dstY1, GLbitfield mask, GLenum filter)
{
TRACE("*");
UNIMPLEMENTED();
}
void APIENTRY glRenderbufferStorageMultisampleEXT(GLenum target, GLsizei samples, GLenum internalformat, GLsizei width, GLsizei height)
{
TRACE("*");
UNIMPLEMENTED();
}
void APIENTRY glClearStencil(GLint s)
{
TRACE("(GLint s = %d)", s);
gl::Context *context = gl::getContext();
if(context)
{
if(context->getListIndex() != 0)
{
UNIMPLEMENTED();
}
context->setClearStencil(s);
}
}
void APIENTRY glColorMask(GLboolean red, GLboolean green, GLboolean blue, GLboolean alpha)
{
TRACE("(GLboolean red = %d, GLboolean green = %d, GLboolean blue = %d, GLboolean alpha = %d)",
red, green, blue, alpha);
gl::Context *context = gl::getContext();
if(context)
{
if(context->getListIndex() != 0)
{
UNIMPLEMENTED();
}
context->setColorMask(red == GL_TRUE, green == GL_TRUE, blue == GL_TRUE, alpha == GL_TRUE);
}
}
void APIENTRY glCompileShader(GLuint shader)
{
TRACE("(GLuint shader = %d)", shader);
gl::Context *context = gl::getContext();
if(context)
{
gl::Shader *shaderObject = context->getShader(shader);
if(!shaderObject)
{
if(context->getProgram(shader))
{
return error(GL_INVALID_OPERATION);
}
else
{
return error(GL_INVALID_VALUE);
}
}
shaderObject->compile();
}
}
void APIENTRY glCompressedTexImage2D(GLenum target, GLint level, GLenum internalformat, GLsizei width, GLsizei height,
GLint border, GLsizei imageSize, const GLvoid* data)
{
TRACE("(GLenum target = 0x%X, GLint level = %d, GLenum internalformat = 0x%X, GLsizei width = %d, "
"GLsizei height = %d, GLint border = %d, GLsizei imageSize = %d, const GLvoid* data = %p)",
target, level, internalformat, width, height, border, imageSize, data);
if(!validImageSize(level, width, height) || border != 0 || imageSize < 0)
{
return error(GL_INVALID_VALUE);
}
switch(internalformat)
{
case GL_COMPRESSED_RGB_S3TC_DXT1_EXT:
case GL_COMPRESSED_RGBA_S3TC_DXT1_EXT:
case GL_COMPRESSED_RGBA_S3TC_DXT3_EXT:
case GL_COMPRESSED_RGBA_S3TC_DXT5_EXT:
if(!S3TC_SUPPORT)
{
return error(GL_INVALID_ENUM);
}
break;
case GL_DEPTH_COMPONENT:
case GL_DEPTH_COMPONENT16:
case GL_DEPTH_COMPONENT32:
case GL_DEPTH_STENCIL_EXT:
case GL_DEPTH24_STENCIL8_EXT:
return error(GL_INVALID_OPERATION);
default:
return error(GL_INVALID_ENUM);
}
if(border != 0)
{
return error(GL_INVALID_VALUE);
}
gl::Context *context = gl::getContext();
if(context)
{
if(context->getListIndex() != 0)
{
UNIMPLEMENTED();
}
if(level > gl::IMPLEMENTATION_MAX_TEXTURE_LEVELS)
{
return error(GL_INVALID_VALUE);
}
switch(target)
{
case GL_TEXTURE_2D:
if(width > (gl::IMPLEMENTATION_MAX_TEXTURE_SIZE >> level) ||
height > (gl::IMPLEMENTATION_MAX_TEXTURE_SIZE >> level))
{
return error(GL_INVALID_VALUE);
}
break;
case GL_TEXTURE_CUBE_MAP_POSITIVE_X:
case GL_TEXTURE_CUBE_MAP_NEGATIVE_X:
case GL_TEXTURE_CUBE_MAP_POSITIVE_Y:
case GL_TEXTURE_CUBE_MAP_NEGATIVE_Y:
case GL_TEXTURE_CUBE_MAP_POSITIVE_Z:
case GL_TEXTURE_CUBE_MAP_NEGATIVE_Z:
if(width != height)
{
return error(GL_INVALID_VALUE);
}
if(width > (gl::IMPLEMENTATION_MAX_CUBE_MAP_TEXTURE_SIZE >> level) ||
height > (gl::IMPLEMENTATION_MAX_CUBE_MAP_TEXTURE_SIZE >> level))
{
return error(GL_INVALID_VALUE);
}
break;
default:
return error(GL_INVALID_ENUM);
}
if(imageSize != gl::ComputeCompressedSize(width, height, internalformat))
{
return error(GL_INVALID_VALUE);
}
if(target == GL_TEXTURE_2D)
{
gl::Texture2D *texture = context->getTexture2D(target);
if(!texture)
{
return error(GL_INVALID_OPERATION);
}
texture->setCompressedImage(level, internalformat, width, height, imageSize, data);
}
else
{
gl::TextureCubeMap *texture = context->getTextureCubeMap();
if(!texture)
{
return error(GL_INVALID_OPERATION);
}
switch(target)
{
case GL_TEXTURE_CUBE_MAP_POSITIVE_X:
case GL_TEXTURE_CUBE_MAP_NEGATIVE_X:
case GL_TEXTURE_CUBE_MAP_POSITIVE_Y:
case GL_TEXTURE_CUBE_MAP_NEGATIVE_Y:
case GL_TEXTURE_CUBE_MAP_POSITIVE_Z:
case GL_TEXTURE_CUBE_MAP_NEGATIVE_Z:
texture->setCompressedImage(target, level, internalformat, width, height, imageSize, data);
break;
default: UNREACHABLE();
}
}
}
}
void APIENTRY glCompressedTexSubImage2D(GLenum target, GLint level, GLint xoffset, GLint yoffset, GLsizei width, GLsizei height,
GLenum format, GLsizei imageSize, const GLvoid* data)
{
TRACE("(GLenum target = 0x%X, GLint level = %d, GLint xoffset = %d, GLint yoffset = %d, "
"GLsizei width = %d, GLsizei height = %d, GLenum format = 0x%X, "
"GLsizei imageSize = %d, const GLvoid* data = %p)",
target, level, xoffset, yoffset, width, height, format, imageSize, data);
if(!gl::IsTextureTarget(target))
{
return error(GL_INVALID_ENUM);
}
if(xoffset < 0 || yoffset < 0 || !validImageSize(level, width, height) || imageSize < 0)
{
return error(GL_INVALID_VALUE);
}
switch(format)
{
case GL_COMPRESSED_RGB_S3TC_DXT1_EXT:
case GL_COMPRESSED_RGBA_S3TC_DXT1_EXT:
case GL_COMPRESSED_RGBA_S3TC_DXT3_EXT:
case GL_COMPRESSED_RGBA_S3TC_DXT5_EXT:
if(!S3TC_SUPPORT)
{
return error(GL_INVALID_ENUM);
}
break;
default:
return error(GL_INVALID_ENUM);
}
if(width == 0 || height == 0 || data == NULL)
{
return;
}
gl::Context *context = gl::getContext();
if(context)
{
if(context->getListIndex() != 0)
{
UNIMPLEMENTED();
}
if(level > gl::IMPLEMENTATION_MAX_TEXTURE_LEVELS)
{
return error(GL_INVALID_VALUE);
}
if(imageSize != gl::ComputeCompressedSize(width, height, format))
{
return error(GL_INVALID_VALUE);
}
if(xoffset % 4 != 0 || yoffset % 4 != 0)
{
// We wait to check the offsets until this point, because the multiple-of-four restriction does not exist unless DXT1 textures are supported
return error(GL_INVALID_OPERATION);
}
if(target == GL_TEXTURE_2D)
{
gl::Texture2D *texture = context->getTexture2D(target);
if(validateSubImageParams(true, width, height, xoffset, yoffset, target, level, format, texture))
{
texture->subImageCompressed(level, xoffset, yoffset, width, height, format, imageSize, data);
}
}
else if(gl::IsCubemapTextureTarget(target))
{
gl::TextureCubeMap *texture = context->getTextureCubeMap();
if(validateSubImageParams(true, width, height, xoffset, yoffset, target, level, format, texture))
{
texture->subImageCompressed(target, level, xoffset, yoffset, width, height, format, imageSize, data);
}
}
else
{
UNREACHABLE();
}
}
}
void APIENTRY glCopyTexImage2D(GLenum target, GLint level, GLenum internalformat, GLint x, GLint y, GLsizei width, GLsizei height, GLint border)
{
TRACE("(GLenum target = 0x%X, GLint level = %d, GLenum internalformat = 0x%X, "
"GLint x = %d, GLint y = %d, GLsizei width = %d, GLsizei height = %d, GLint border = %d)",
target, level, internalformat, x, y, width, height, border);
if(!validImageSize(level, width, height))
{
return error(GL_INVALID_VALUE);
}
if(border != 0)
{
return error(GL_INVALID_VALUE);
}
gl::Context *context = gl::getContext();
if(context)
{
if(context->getListIndex() != 0)
{
UNIMPLEMENTED();
}
switch(target)
{
case GL_TEXTURE_2D:
if(width > (gl::IMPLEMENTATION_MAX_TEXTURE_SIZE >> level) ||
height > (gl::IMPLEMENTATION_MAX_TEXTURE_SIZE >> level))
{
return error(GL_INVALID_VALUE);
}
break;
case GL_TEXTURE_CUBE_MAP_POSITIVE_X:
case GL_TEXTURE_CUBE_MAP_NEGATIVE_X:
case GL_TEXTURE_CUBE_MAP_POSITIVE_Y:
case GL_TEXTURE_CUBE_MAP_NEGATIVE_Y:
case GL_TEXTURE_CUBE_MAP_POSITIVE_Z:
case GL_TEXTURE_CUBE_MAP_NEGATIVE_Z:
if(width != height)
{
return error(GL_INVALID_VALUE);
}
if(width > (gl::IMPLEMENTATION_MAX_CUBE_MAP_TEXTURE_SIZE >> level) ||
height > (gl::IMPLEMENTATION_MAX_CUBE_MAP_TEXTURE_SIZE >> level))
{
return error(GL_INVALID_VALUE);
}
break;
default:
return error(GL_INVALID_ENUM);
}
gl::Framebuffer *framebuffer = context->getReadFramebuffer();
if(framebuffer->completeness() != GL_FRAMEBUFFER_COMPLETE)
{
return error(GL_INVALID_FRAMEBUFFER_OPERATION);
}
if(context->getReadFramebufferName() != 0 && framebuffer->getColorbuffer()->getSamples() > 1)
{
return error(GL_INVALID_OPERATION);
}
gl::Renderbuffer *source = framebuffer->getColorbuffer();
GLenum colorbufferFormat = source->getFormat();
switch(internalformat)
{
case GL_ALPHA:
if(colorbufferFormat != GL_ALPHA &&
colorbufferFormat != GL_RGBA &&
colorbufferFormat != GL_RGBA4 &&
colorbufferFormat != GL_RGB5_A1 &&
colorbufferFormat != GL_RGBA8_EXT)
{
return error(GL_INVALID_OPERATION);
}
break;
case GL_LUMINANCE:
case GL_RGB:
if(colorbufferFormat != GL_RGB &&
colorbufferFormat != GL_RGB565 &&
colorbufferFormat != GL_RGB8_EXT &&
colorbufferFormat != GL_RGBA &&
colorbufferFormat != GL_RGBA4 &&
colorbufferFormat != GL_RGB5_A1 &&
colorbufferFormat != GL_RGBA8_EXT)
{
return error(GL_INVALID_OPERATION);
}
break;
case GL_LUMINANCE_ALPHA:
case GL_RGBA:
if(colorbufferFormat != GL_RGBA &&
colorbufferFormat != GL_RGBA4 &&
colorbufferFormat != GL_RGB5_A1 &&
colorbufferFormat != GL_RGBA8_EXT)
{
return error(GL_INVALID_OPERATION);
}
break;
case GL_COMPRESSED_RGB_S3TC_DXT1_EXT:
case GL_COMPRESSED_RGBA_S3TC_DXT1_EXT:
case GL_COMPRESSED_RGBA_S3TC_DXT3_EXT:
case GL_COMPRESSED_RGBA_S3TC_DXT5_EXT:
if(S3TC_SUPPORT)
{
return error(GL_INVALID_OPERATION);
}
else
{
return error(GL_INVALID_ENUM);
}
default:
return error(GL_INVALID_ENUM);
}
if(target == GL_TEXTURE_2D)
{
gl::Texture2D *texture = context->getTexture2D(target);
if(!texture)
{
return error(GL_INVALID_OPERATION);
}
texture->copyImage(level, internalformat, x, y, width, height, framebuffer);
}
else if(gl::IsCubemapTextureTarget(target))
{
gl::TextureCubeMap *texture = context->getTextureCubeMap();
if(!texture)
{
return error(GL_INVALID_OPERATION);
}
texture->copyImage(target, level, internalformat, x, y, width, height, framebuffer);
}
else UNREACHABLE();
}
}
void APIENTRY glCopyTexSubImage2D(GLenum target, GLint level, GLint xoffset, GLint yoffset, GLint x, GLint y, GLsizei width, GLsizei height)
{
TRACE("(GLenum target = 0x%X, GLint level = %d, GLint xoffset = %d, GLint yoffset = %d, "
"GLint x = %d, GLint y = %d, GLsizei width = %d, GLsizei height = %d)",
target, level, xoffset, yoffset, x, y, width, height);
if(!gl::IsTextureTarget(target))
{
return error(GL_INVALID_ENUM);
}
if(level < 0 || xoffset < 0 || yoffset < 0 || width < 0 || height < 0)
{
return error(GL_INVALID_VALUE);
}
if(std::numeric_limits<GLsizei>::max() - xoffset < width || std::numeric_limits<GLsizei>::max() - yoffset < height)
{
return error(GL_INVALID_VALUE);
}
if(width == 0 || height == 0)
{
return;
}
gl::Context *context = gl::getContext();
if(context)
{
if(context->getListIndex() != 0)
{
UNIMPLEMENTED();
}
if(level > gl::IMPLEMENTATION_MAX_TEXTURE_LEVELS)
{
return error(GL_INVALID_VALUE);
}
gl::Framebuffer *framebuffer = context->getReadFramebuffer();
if(framebuffer->completeness() != GL_FRAMEBUFFER_COMPLETE)
{
return error(GL_INVALID_FRAMEBUFFER_OPERATION);
}
if(context->getReadFramebufferName() != 0 && framebuffer->getColorbuffer()->getSamples() > 1)
{
return error(GL_INVALID_OPERATION);
}
gl::Renderbuffer *source = framebuffer->getColorbuffer();
GLenum colorbufferFormat = source->getFormat();
gl::Texture *texture = NULL;
if(target == GL_TEXTURE_2D)
{
texture = context->getTexture2D(target);
}
else if(gl::IsCubemapTextureTarget(target))
{
texture = context->getTextureCubeMap();
}
else UNREACHABLE();
if(!validateSubImageParams(false, width, height, xoffset, yoffset, target, level, GL_NONE, texture))
{
return;
}
GLenum textureFormat = texture->getFormat(target, level);
switch(textureFormat)
{
case GL_ALPHA:
if(colorbufferFormat != GL_ALPHA &&
colorbufferFormat != GL_RGBA &&
colorbufferFormat != GL_RGBA4 &&
colorbufferFormat != GL_RGB5_A1 &&
colorbufferFormat != GL_RGBA8_EXT)
{
return error(GL_INVALID_OPERATION);
}
break;
case GL_LUMINANCE:
case GL_RGB:
if(colorbufferFormat != GL_RGB &&
colorbufferFormat != GL_RGB565 &&
colorbufferFormat != GL_RGB8_EXT &&
colorbufferFormat != GL_RGBA &&
colorbufferFormat != GL_RGBA4 &&
colorbufferFormat != GL_RGB5_A1 &&
colorbufferFormat != GL_RGBA8_EXT)
{
return error(GL_INVALID_OPERATION);
}
break;
case GL_LUMINANCE_ALPHA:
case GL_RGBA:
if(colorbufferFormat != GL_RGBA &&
colorbufferFormat != GL_RGBA4 &&
colorbufferFormat != GL_RGB5_A1 &&
colorbufferFormat != GL_RGBA8_EXT)
{
return error(GL_INVALID_OPERATION);
}
break;
case GL_COMPRESSED_RGB_S3TC_DXT1_EXT:
case GL_COMPRESSED_RGBA_S3TC_DXT1_EXT:
case GL_COMPRESSED_RGBA_S3TC_DXT3_EXT:
case GL_COMPRESSED_RGBA_S3TC_DXT5_EXT:
return error(GL_INVALID_OPERATION);
case GL_DEPTH_COMPONENT:
case GL_DEPTH_STENCIL_EXT:
return error(GL_INVALID_OPERATION);
case GL_BGRA_EXT:
if(colorbufferFormat != GL_RGB8)
{
UNIMPLEMENTED();
return error(GL_INVALID_OPERATION);
}
break;
default:
return error(GL_INVALID_ENUM);
}
texture->copySubImage(target, level, xoffset, yoffset, x, y, width, height, framebuffer);
}
}
GLuint APIENTRY glCreateProgram(void)
{
TRACE("()");
gl::Context *context = gl::getContext();
if(context)
{
return context->createProgram();
}
return 0;
}
GLuint APIENTRY glCreateShader(GLenum type)
{
TRACE("(GLenum type = 0x%X)", type);
gl::Context *context = gl::getContext();
if(context)
{
switch(type)
{
case GL_FRAGMENT_SHADER:
case GL_VERTEX_SHADER:
return context->createShader(type);
default:
return error(GL_INVALID_ENUM, 0);
}
}
return 0;
}
void APIENTRY glCullFace(GLenum mode)
{
TRACE("(GLenum mode = 0x%X)", mode);
switch(mode)
{
case GL_FRONT:
case GL_BACK:
case GL_FRONT_AND_BACK:
{
gl::Context *context = gl::getContext();
if(context)
{
context->setCullMode(mode);
}
}
break;
default:
return error(GL_INVALID_ENUM);
}
}
void APIENTRY glDeleteBuffers(GLsizei n, const GLuint* buffers)
{
TRACE("(GLsizei n = %d, const GLuint* buffers = %p)", n, buffers);
if(n < 0)
{
return error(GL_INVALID_VALUE);
}
gl::Context *context = gl::getContext();
if(context)
{
for(int i = 0; i < n; i++)
{
context->deleteBuffer(buffers[i]);
}
}
}
void APIENTRY glDeleteFencesNV(GLsizei n, const GLuint* fences)
{
TRACE("(GLsizei n = %d, const GLuint* fences = %p)", n, fences);
if(n < 0)
{
return error(GL_INVALID_VALUE);
}
gl::Context *context = gl::getContext();
if(context)
{
if(context->getListIndex() != 0)
{
UNIMPLEMENTED();
}
for(int i = 0; i < n; i++)
{
context->deleteFence(fences[i]);
}
}
}
void APIENTRY glDeleteFramebuffers(GLsizei n, const GLuint* framebuffers)
{
TRACE("(GLsizei n = %d, const GLuint* framebuffers = %p)", n, framebuffers);
if(n < 0)
{
return error(GL_INVALID_VALUE);
}
gl::Context *context = gl::getContext();
if(context)
{
if(context->getListIndex() != 0)
{
UNIMPLEMENTED();
}
for(int i = 0; i < n; i++)
{
if(framebuffers[i] != 0)
{
context->deleteFramebuffer(framebuffers[i]);
}
}
}
}
void APIENTRY glDeleteProgram(GLuint program)
{
TRACE("(GLuint program = %d)", program);
if(program == 0)
{
return;
}
gl::Context *context = gl::getContext();
if(context)
{
if(!context->getProgram(program))
{
if(context->getShader(program))
{
return error(GL_INVALID_OPERATION);
}
else
{
return error(GL_INVALID_VALUE);
}
}
context->deleteProgram(program);
}
}
void APIENTRY glDeleteQueriesEXT(GLsizei n, const GLuint *ids)
{
TRACE("(GLsizei n = %d, const GLuint *ids = %p)", n, ids);
if(n < 0)
{
return error(GL_INVALID_VALUE);
}
gl::Context *context = gl::getContext();
if(context)
{
for(int i = 0; i < n; i++)
{
context->deleteQuery(ids[i]);
}
}
}
void APIENTRY glDeleteRenderbuffers(GLsizei n, const GLuint* renderbuffers)
{
TRACE("(GLsizei n = %d, const GLuint* renderbuffers = %p)", n, renderbuffers);
if(n < 0)
{
return error(GL_INVALID_VALUE);
}
gl::Context *context = gl::getContext();
if(context)
{
if(context->getListIndex() != 0)
{
UNIMPLEMENTED();
}
for(int i = 0; i < n; i++)
{
context->deleteRenderbuffer(renderbuffers[i]);
}
}
}
void APIENTRY glDeleteShader(GLuint shader)
{
TRACE("(GLuint shader = %d)", shader);
if(shader == 0)
{
return;
}
gl::Context *context = gl::getContext();
if(context)
{
if(!context->getShader(shader))
{
if(context->getProgram(shader))
{
return error(GL_INVALID_OPERATION);
}
else
{
return error(GL_INVALID_VALUE);
}
}
context->deleteShader(shader);
}
}
void APIENTRY glDeleteTextures(GLsizei n, const GLuint* textures)
{
TRACE("(GLsizei n = %d, const GLuint* textures = %p)", n, textures);
if(n < 0)
{
return error(GL_INVALID_VALUE);
}
gl::Context *context = gl::getContext();
if(context)
{
for(int i = 0; i < n; i++)
{
if(textures[i] != 0)
{
context->deleteTexture(textures[i]);
}
}
}
}
void APIENTRY glDepthFunc(GLenum func)
{
TRACE("(GLenum func = 0x%X)", func);
switch(func)
{
case GL_NEVER:
case GL_ALWAYS:
case GL_LESS:
case GL_LEQUAL:
case GL_EQUAL:
case GL_GREATER:
case GL_GEQUAL:
case GL_NOTEQUAL:
break;
default:
return error(GL_INVALID_ENUM);
}
gl::Context *context = gl::getContext();
if(context)
{
if(context->getListIndex() != 0)
{
UNIMPLEMENTED();
}
context->setDepthFunc(func);
}
}
void APIENTRY glDepthMask(GLboolean flag)
{
TRACE("(GLboolean flag = %d)", flag);
gl::Context *context = gl::getContext();
if(context)
{
if(context->getListIndex() != 0)
{
UNIMPLEMENTED();
}
context->setDepthMask(flag != GL_FALSE);
}
}
void APIENTRY glDepthRangef(GLclampf zNear, GLclampf zFar)
{
TRACE("(GLclampf zNear = %f, GLclampf zFar = %f)", zNear, zFar);
gl::Context *context = gl::getContext();
if(context)
{
if(context->getListIndex() != 0)
{
UNIMPLEMENTED();
}
context->setDepthRange(zNear, zFar);
}
}
void APIENTRY glDetachShader(GLuint program, GLuint shader)
{
TRACE("(GLuint program = %d, GLuint shader = %d)", program, shader);
gl::Context *context = gl::getContext();
if(context)
{
gl::Program *programObject = context->getProgram(program);
gl::Shader *shaderObject = context->getShader(shader);
if(!programObject)
{
gl::Shader *shaderByProgramHandle;
shaderByProgramHandle = context->getShader(program);
if(!shaderByProgramHandle)
{
return error(GL_INVALID_VALUE);
}
else
{
return error(GL_INVALID_OPERATION);
}
}
if(!shaderObject)
{
gl::Program *programByShaderHandle = context->getProgram(shader);
if(!programByShaderHandle)
{
return error(GL_INVALID_VALUE);
}
else
{
return error(GL_INVALID_OPERATION);
}
}
if(!programObject->detachShader(shaderObject))
{
return error(GL_INVALID_OPERATION);
}
}
}
void APIENTRY glDisable(GLenum cap)
{
TRACE("(GLenum cap = 0x%X)", cap);
gl::Context *context = gl::getContext();
if(context)
{
if(context->getListIndex() != 0)
{
UNIMPLEMENTED();
}
switch(cap)
{
case GL_CULL_FACE: context->setCullFace(false); break;
case GL_POLYGON_OFFSET_FILL: context->setPolygonOffsetFill(false); break;
case GL_SAMPLE_ALPHA_TO_COVERAGE: context->setSampleAlphaToCoverage(false); break;
case GL_SAMPLE_COVERAGE: context->setSampleCoverage(false); break;
case GL_SCISSOR_TEST: context->setScissorTest(false); break;
case GL_STENCIL_TEST: context->setStencilTest(false); break;
case GL_DEPTH_TEST: context->setDepthTest(false); break;
case GL_BLEND: context->setBlend(false); break;
case GL_DITHER: context->setDither(false); break;
case GL_LIGHTING: context->setLighting(false); break;
case GL_FOG: context->setFog(false); break;
case GL_ALPHA_TEST: context->setAlphaTest(false); break;
case GL_TEXTURE_2D: context->setTexture2D(false); break;
case GL_LIGHT0: context->setLight(0, false); break;
case GL_LIGHT1: context->setLight(1, false); break;
case GL_LIGHT2: context->setLight(2, false); break;
case GL_LIGHT3: context->setLight(3, false); break;
case GL_LIGHT4: context->setLight(4, false); break;
case GL_LIGHT5: context->setLight(5, false); break;
case GL_LIGHT6: context->setLight(6, false); break;
case GL_LIGHT7: context->setLight(7, false); break;
case GL_COLOR_MATERIAL: context->setColorMaterial(false); break;
case GL_RESCALE_NORMAL: context->setNormalizeNormals(false); break;
case GL_TEXTURE_1D: context->set1DTextureEnable(false); break;
default:
return error(GL_INVALID_ENUM);
}
}
}
void APIENTRY glDisableVertexAttribArray(GLuint index)
{
TRACE("(GLuint index = %d)", index);
if(index >= gl::MAX_VERTEX_ATTRIBS)
{
return error(GL_INVALID_VALUE);
}
gl::Context *context = gl::getContext();
if(context)
{
context->setEnableVertexAttribArray(index, false);
}
}
void APIENTRY glCaptureAttribs()
{
TRACE("()");
gl::Context *context = gl::getContext();
if(context)
{
context->captureAttribs();
}
}
void APIENTRY glRestoreAttribs()
{
TRACE("()");
gl::Context *context = gl::getContext();
if(context)
{
context->restoreAttribs();
}
}
void APIENTRY glDrawArrays(GLenum mode, GLint first, GLsizei count)
{
TRACE("(GLenum mode = 0x%X, GLint first = %d, GLsizei count = %d)", mode, first, count);
if(count < 0 || first < 0)
{
return error(GL_INVALID_VALUE);
}
gl::Context *context = gl::getContext();
if(context)
{
if(context->getListIndex() != 0)
{
ASSERT(context->getListMode() != GL_COMPILE_AND_EXECUTE); // UNIMPLEMENTED!
context->listCommand(gl::newCommand(glCaptureAttribs));
context->captureDrawArrays(mode, first, count);
context->listCommand(gl::newCommand(glDrawArrays, mode, first, count));
context->listCommand(gl::newCommand(glRestoreAttribs));
return;
}
context->drawArrays(mode, first, count);
}
}
void APIENTRY glDrawElements(GLenum mode, GLsizei count, GLenum type, const GLvoid* indices)
{
TRACE("(GLenum mode = 0x%X, GLsizei count = %d, GLenum type = 0x%X, const GLvoid* indices = %p)",
mode, count, type, indices);
if(count < 0)
{
return error(GL_INVALID_VALUE);
}
gl::Context *context = gl::getContext();
if(context)
{
if(context->getListIndex() != 0)
{
UNIMPLEMENTED();
}
switch(type)
{
case GL_UNSIGNED_BYTE:
case GL_UNSIGNED_SHORT:
case GL_UNSIGNED_INT:
break;
default:
return error(GL_INVALID_ENUM);
}
context->drawElements(mode, count, type, indices);
}
}
void APIENTRY glEnable(GLenum cap)
{
TRACE("(GLenum cap = 0x%X)", cap);
gl::Context *context = gl::getContext();
if(context)
{
if(context->getListIndex() != 0)
{
UNIMPLEMENTED();
}
switch(cap)
{
case GL_CULL_FACE: context->setCullFace(true); break;
case GL_POLYGON_OFFSET_FILL: context->setPolygonOffsetFill(true); break;
case GL_SAMPLE_ALPHA_TO_COVERAGE: context->setSampleAlphaToCoverage(true); break;
case GL_SAMPLE_COVERAGE: context->setSampleCoverage(true); break;
case GL_SCISSOR_TEST: context->setScissorTest(true); break;
case GL_STENCIL_TEST: context->setStencilTest(true); break;
case GL_DEPTH_TEST: context->setDepthTest(true); break;
case GL_BLEND: context->setBlend(true); break;
case GL_DITHER: context->setDither(true); break;
case GL_TEXTURE_2D: context->setTexture2D(true); break;
case GL_ALPHA_TEST: context->setAlphaTest(true); break;
case GL_COLOR_MATERIAL: context->setColorMaterial(true); break;
case GL_FOG: context->setFog(true); break;
case GL_LIGHTING: context->setLighting(true); break;
case GL_LIGHT0: context->setLight(0, true); break;
case GL_LIGHT1: context->setLight(1, true); break;
case GL_LIGHT2: context->setLight(2, true); break;
case GL_LIGHT3: context->setLight(3, true); break;
case GL_LIGHT4: context->setLight(4, true); break;
case GL_LIGHT5: context->setLight(5, true); break;
case GL_LIGHT6: context->setLight(6, true); break;
case GL_LIGHT7: context->setLight(7, true); break;
case GL_RESCALE_NORMAL: context->setNormalizeNormals(true); break;
case GL_TEXTURE_1D: context->set1DTextureEnable(true); break;
default:
return error(GL_INVALID_ENUM);
}
}
}
void APIENTRY glEnableVertexAttribArray(GLuint index)
{
TRACE("(GLuint index = %d)", index);
if(index >= gl::MAX_VERTEX_ATTRIBS)
{
return error(GL_INVALID_VALUE);
}
gl::Context *context = gl::getContext();
if(context)
{
context->setEnableVertexAttribArray(index, true);
}
}
void APIENTRY glEndQueryEXT(GLenum target)
{
TRACE("GLenum target = 0x%X)", target);
switch(target)
{
case GL_ANY_SAMPLES_PASSED:
case GL_ANY_SAMPLES_PASSED_CONSERVATIVE:
break;
default:
return error(GL_INVALID_ENUM);
}
gl::Context *context = gl::getContext();
if(context)
{
if(context->getListIndex() != 0)
{
UNIMPLEMENTED();
}
context->endQuery(target);
}
}
void APIENTRY glFinishFenceNV(GLuint fence)
{
TRACE("(GLuint fence = %d)", fence);
gl::Context *context = gl::getContext();
if(context)
{
if(context->getListIndex() != 0)
{
UNIMPLEMENTED();
}
gl::Fence* fenceObject = context->getFence(fence);
if(fenceObject == NULL)
{
return error(GL_INVALID_OPERATION);
}
fenceObject->finishFence();
}
}
void APIENTRY glFinish(void)
{
TRACE("()");
gl::Context *context = gl::getContext();
if(context)
{
context->finish();
}
}
void APIENTRY glFlush(void)
{
TRACE("()");
gl::Context *context = gl::getContext();
if(context)
{
context->flush();
}
}
void APIENTRY glFramebufferRenderbuffer(GLenum target, GLenum attachment, GLenum renderbuffertarget, GLuint renderbuffer)
{
TRACE("(GLenum target = 0x%X, GLenum attachment = 0x%X, GLenum renderbuffertarget = 0x%X, "
"GLuint renderbuffer = %d)", target, attachment, renderbuffertarget, renderbuffer);
if((target != GL_FRAMEBUFFER && target != GL_DRAW_FRAMEBUFFER_EXT && target != GL_READ_FRAMEBUFFER_EXT) ||
(renderbuffertarget != GL_RENDERBUFFER && renderbuffer != 0))
{
return error(GL_INVALID_ENUM);
}
gl::Context *context = gl::getContext();
if(context)
{
if(context->getListIndex() != 0)
{
UNIMPLEMENTED();
}
gl::Framebuffer *framebuffer = NULL;
GLuint framebufferName = 0;
if(target == GL_READ_FRAMEBUFFER_EXT)
{
framebuffer = context->getReadFramebuffer();
framebufferName = context->getReadFramebufferName();
}
else
{
framebuffer = context->getDrawFramebuffer();
framebufferName = context->getDrawFramebufferName();
}
if(!framebuffer || (framebufferName == 0 && renderbuffer != 0))
{
return error(GL_INVALID_OPERATION);
}
switch(attachment)
{
case GL_COLOR_ATTACHMENT0:
framebuffer->setColorbuffer(GL_RENDERBUFFER, renderbuffer);
break;
case GL_DEPTH_ATTACHMENT:
framebuffer->setDepthbuffer(GL_RENDERBUFFER, renderbuffer);
break;
case GL_STENCIL_ATTACHMENT:
framebuffer->setStencilbuffer(GL_RENDERBUFFER, renderbuffer);
break;
default:
return error(GL_INVALID_ENUM);
}
}
}
void APIENTRY glFramebufferTexture1D(GLenum target, GLenum attachment, GLenum textarget, GLuint texture, GLint level)
{
UNIMPLEMENTED();
}
void APIENTRY glFramebufferTexture2D(GLenum target, GLenum attachment, GLenum textarget, GLuint texture, GLint level)
{
TRACE("(GLenum target = 0x%X, GLenum attachment = 0x%X, GLenum textarget = 0x%X, "
"GLuint texture = %d, GLint level = %d)", target, attachment, textarget, texture, level);
if(target != GL_FRAMEBUFFER && target != GL_DRAW_FRAMEBUFFER_EXT && target != GL_READ_FRAMEBUFFER_EXT)
{
return error(GL_INVALID_ENUM);
}
switch(attachment)
{
case GL_COLOR_ATTACHMENT0:
case GL_DEPTH_ATTACHMENT:
case GL_STENCIL_ATTACHMENT:
break;
default:
return error(GL_INVALID_ENUM);
}
gl::Context *context = gl::getContext();
if(context)
{
if(context->getListIndex() != 0)
{
UNIMPLEMENTED();
}
if(texture == 0)
{
textarget = GL_NONE;
}
else
{
gl::Texture *tex = context->getTexture(texture);
if(tex == NULL)
{
return error(GL_INVALID_OPERATION);
}
if(tex->isCompressed(textarget, level))
{
return error(GL_INVALID_OPERATION);
}
switch(textarget)
{
case GL_TEXTURE_2D:
if(tex->getTarget() != GL_TEXTURE_2D)
{
return error(GL_INVALID_OPERATION);
}
break;
case GL_TEXTURE_CUBE_MAP_POSITIVE_X:
case GL_TEXTURE_CUBE_MAP_NEGATIVE_X:
case GL_TEXTURE_CUBE_MAP_POSITIVE_Y:
case GL_TEXTURE_CUBE_MAP_NEGATIVE_Y:
case GL_TEXTURE_CUBE_MAP_POSITIVE_Z:
case GL_TEXTURE_CUBE_MAP_NEGATIVE_Z:
if(tex->getTarget() != GL_TEXTURE_CUBE_MAP)
{
return error(GL_INVALID_OPERATION);
}
break;
default:
return error(GL_INVALID_ENUM);
}
if(level != 0)
{
return error(GL_INVALID_VALUE);
}
}
gl::Framebuffer *framebuffer = NULL;
GLuint framebufferName = 0;
if(target == GL_READ_FRAMEBUFFER_EXT)
{
framebuffer = context->getReadFramebuffer();
framebufferName = context->getReadFramebufferName();
}
else
{
framebuffer = context->getDrawFramebuffer();
framebufferName = context->getDrawFramebufferName();
}
if(framebufferName == 0 || !framebuffer)
{
return error(GL_INVALID_OPERATION);
}
switch(attachment)
{
case GL_COLOR_ATTACHMENT0: framebuffer->setColorbuffer(textarget, texture); break;
case GL_DEPTH_ATTACHMENT: framebuffer->setDepthbuffer(textarget, texture); break;
case GL_STENCIL_ATTACHMENT: framebuffer->setStencilbuffer(textarget, texture); break;
}
}
}
void APIENTRY glFramebufferTexture3D(GLenum target, GLenum attachment, GLenum textarget, GLuint texture, GLint level, GLint zoffset)
{
UNIMPLEMENTED();
}
void APIENTRY glFrontFace(GLenum mode)
{
TRACE("(GLenum mode = 0x%X)", mode);
switch(mode)
{
case GL_CW:
case GL_CCW:
{
gl::Context *context = gl::getContext();
if(context)
{
context->setFrontFace(mode);
}
}
break;
default:
return error(GL_INVALID_ENUM);
}
}
void APIENTRY glGenBuffers(GLsizei n, GLuint* buffers)
{
TRACE("(GLsizei n = %d, GLuint* buffers = %p)", n, buffers);
if(n < 0)
{
return error(GL_INVALID_VALUE);
}
gl::Context *context = gl::getContext();
if(context)
{
for(int i = 0; i < n; i++)
{
buffers[i] = context->createBuffer();
}
}
}
void APIENTRY glGenerateMipmap(GLenum target)
{
TRACE("(GLenum target = 0x%X)", target);
gl::Context *context = gl::getContext();
if(context)
{
if(context->getListIndex() != 0)
{
UNIMPLEMENTED();
}
gl::Texture *texture;
switch(target)
{
case GL_TEXTURE_2D:
texture = context->getTexture2D(target);
break;
case GL_TEXTURE_CUBE_MAP:
texture = context->getTextureCubeMap();
break;
default:
return error(GL_INVALID_ENUM);
}
if(texture->isCompressed(target, 0) || texture->isDepth(target, 0))
{
return error(GL_INVALID_OPERATION);
}
texture->generateMipmaps();
}
}
void APIENTRY glGenFencesNV(GLsizei n, GLuint* fences)
{
TRACE("(GLsizei n = %d, GLuint* fences = %p)", n, fences);
if(n < 0)
{
return error(GL_INVALID_VALUE);
}
gl::Context *context = gl::getContext();
if(context)
{
if(context->getListIndex() != 0)
{
UNIMPLEMENTED();
}
for(int i = 0; i < n; i++)
{
fences[i] = context->createFence();
}
}
}
void APIENTRY glGenFramebuffers(GLsizei n, GLuint* framebuffers)
{
TRACE("(GLsizei n = %d, GLuint* framebuffers = %p)", n, framebuffers);
if(n < 0)
{
return error(GL_INVALID_VALUE);
}
gl::Context *context = gl::getContext();
if(context)
{
if(context->getListIndex() != 0)
{
UNIMPLEMENTED();
}
for(int i = 0; i < n; i++)
{
framebuffers[i] = context->createFramebuffer();
}
}
}
void APIENTRY glGenQueriesEXT(GLsizei n, GLuint* ids)
{
TRACE("(GLsizei n = %d, GLuint* ids = %p)", n, ids);
if(n < 0)
{
return error(GL_INVALID_VALUE);
}
gl::Context *context = gl::getContext();
if(context)
{
for(int i = 0; i < n; i++)
{
ids[i] = context->createQuery();
}
}
}
void APIENTRY glGenRenderbuffers(GLsizei n, GLuint* renderbuffers)
{
TRACE("(GLsizei n = %d, GLuint* renderbuffers = %p)", n, renderbuffers);
if(n < 0)
{
return error(GL_INVALID_VALUE);
}
gl::Context *context = gl::getContext();
if(context)
{
if(context->getListIndex() != 0)
{
UNIMPLEMENTED();
}
for(int i = 0; i < n; i++)
{
renderbuffers[i] = context->createRenderbuffer();
}
}
}
void APIENTRY glGenTextures(GLsizei n, GLuint* textures)
{
TRACE("(GLsizei n = %d, GLuint* textures = %p)", n, textures);
if(n < 0)
{
return error(GL_INVALID_VALUE);
}
gl::Context *context = gl::getContext();
if(context)
{
for(int i = 0; i < n; i++)
{
textures[i] = context->createTexture();
}
}
}
void APIENTRY glGetActiveAttrib(GLuint program, GLuint index, GLsizei bufsize, GLsizei *length, GLint *size, GLenum *type, GLchar *name)
{
TRACE("(GLuint program = %d, GLuint index = %d, GLsizei bufsize = %d, GLsizei *length = %p, "
"GLint *size = %p, GLenum *type = %p, GLchar *name = %p)",
program, index, bufsize, length, size, type, name);
if(bufsize < 0)
{
return error(GL_INVALID_VALUE);
}
gl::Context *context = gl::getContext();
if(context)
{
gl::Program *programObject = context->getProgram(program);
if(!programObject)
{
if(context->getShader(program))
{
return error(GL_INVALID_OPERATION);
}
else
{
return error(GL_INVALID_VALUE);
}
}