Engine directory for ticket #1

This commit is contained in:
DavidWyand-GG 2012-09-19 11:15:01 -04:00
parent 352279af7a
commit 7dbfe6994d
3795 changed files with 1363358 additions and 0 deletions

View file

@ -0,0 +1,71 @@
//-----------------------------------------------------------------------------
// Copyright (c) 2012 GarageGames, LLC
//
// Permission is hereby granted, free of charge, to any person obtaining a copy
// of this software and associated documentation files (the "Software"), to
// deal in the Software without restriction, including without limitation the
// rights to use, copy, modify, merge, publish, distribute, sublicense, and/or
// sell copies of the Software, and to permit persons to whom the Software is
// furnished to do so, subject to the following conditions:
//
// The above copyright notice and this permission notice shall be included in
// all copies or substantial portions of the Software.
//
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
// FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS
// IN THE SOFTWARE.
//-----------------------------------------------------------------------------
#include "gfx/gl/gfxGLAppleFence.h"
GFXGLAppleFence::GFXGLAppleFence(GFXDevice* device) : GFXFence(device), mIssued(false)
{
glGenFencesAPPLE(1, &mHandle);
}
GFXGLAppleFence::~GFXGLAppleFence()
{
glDeleteFencesAPPLE(1, &mHandle);
}
void GFXGLAppleFence::issue()
{
glSetFenceAPPLE(mHandle);
mIssued = true;
}
GFXFence::FenceStatus GFXGLAppleFence::getStatus() const
{
if(!mIssued)
return GFXFence::Unset;
GLboolean res = glTestFenceAPPLE(mHandle);
return res ? GFXFence::Processed : GFXFence::Pending;
}
void GFXGLAppleFence::block()
{
if(!mIssued)
return;
glFinishFenceAPPLE(mHandle);
}
void GFXGLAppleFence::zombify()
{
glDeleteFencesAPPLE(1, &mHandle);
}
void GFXGLAppleFence::resurrect()
{
glGenFencesAPPLE(1, &mHandle);
}
const String GFXGLAppleFence::describeSelf() const
{
return String::ToString(" GL Handle: %i", mHandle);
}

View file

@ -0,0 +1,50 @@
//-----------------------------------------------------------------------------
// Copyright (c) 2012 GarageGames, LLC
//
// Permission is hereby granted, free of charge, to any person obtaining a copy
// of this software and associated documentation files (the "Software"), to
// deal in the Software without restriction, including without limitation the
// rights to use, copy, modify, merge, publish, distribute, sublicense, and/or
// sell copies of the Software, and to permit persons to whom the Software is
// furnished to do so, subject to the following conditions:
//
// The above copyright notice and this permission notice shall be included in
// all copies or substantial portions of the Software.
//
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
// FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS
// IN THE SOFTWARE.
//-----------------------------------------------------------------------------
#ifndef _GFXGLAPPLEFENCE_H_
#define _GFXGLAPPLEFENCE_H_
#include "gfx/gfxFence.h"
#include "gfx/gl/ggl/ggl.h"
class GFXGLAppleFence : public GFXFence
{
public:
GFXGLAppleFence(GFXDevice* device);
virtual ~GFXGLAppleFence();
// GFXFence interface
virtual void issue();
virtual FenceStatus getStatus() const;
virtual void block();
// GFXResource interface
virtual void zombify();
virtual void resurrect();
virtual const String describeSelf() const;
private:
GLuint mHandle;
bool mIssued;
};
#endif

View file

@ -0,0 +1,133 @@
//-----------------------------------------------------------------------------
// Copyright (c) 2012 GarageGames, LLC
//
// Permission is hereby granted, free of charge, to any person obtaining a copy
// of this software and associated documentation files (the "Software"), to
// deal in the Software without restriction, including without limitation the
// rights to use, copy, modify, merge, publish, distribute, sublicense, and/or
// sell copies of the Software, and to permit persons to whom the Software is
// furnished to do so, subject to the following conditions:
//
// The above copyright notice and this permission notice shall be included in
// all copies or substantial portions of the Software.
//
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
// FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS
// IN THE SOFTWARE.
//-----------------------------------------------------------------------------
#include "gfx/gl/gfxGLCardProfiler.h"
#include "gfx/gl/gfxGLDevice.h"
#include "gfx/gl/gfxGLEnumTranslate.h"
void GFXGLCardProfiler::init()
{
mChipSet = reinterpret_cast<const char*>(glGetString(GL_VENDOR));
// get the major and minor parts of the GL version. These are defined to be
// in the order "[major].[minor] [other]|[major].[minor].[release] [other] in the spec
const char *versionStart = reinterpret_cast<const char*>(glGetString(GL_VERSION));
const char *versionEnd = versionStart;
// get the text for the version "x.x.xxxx "
for( S32 tok = 0; tok < 2; ++tok )
{
char *text = dStrdup( versionEnd );
dStrtok(text, ". ");
versionEnd += dStrlen( text ) + 1;
dFree( text );
}
mRendererString = "GL";
mRendererString += String::SpanToString(versionStart, versionEnd - 1);
mCardDescription = reinterpret_cast<const char*>(glGetString(GL_RENDERER));
mVersionString = reinterpret_cast<const char*>(glGetString(GL_VERSION));
mVideoMemory = static_cast<GFXGLDevice*>(GFX)->getTotalVideoMemory();
Parent::init();
// Set new enums here so if our profile script forces this to be false we keep the GL_ZEROs.
if(queryProfile("GL::suppFloatTexture"))
{
GFXGLTextureInternalFormat[GFXFormatR16G16F] = GL_RGBA_FLOAT16_ATI;
GFXGLTextureFormat[GFXFormatR16G16F] = GL_RGBA;
GFXGLTextureInternalFormat[GFXFormatR16G16B16A16F] = GL_RGBA_FLOAT16_ATI;
GFXGLTextureInternalFormat[GFXFormatR32G32B32A32F] = GL_RGBA_FLOAT32_ATI;
GFXGLTextureInternalFormat[GFXFormatR32F] = GL_RGBA_FLOAT32_ATI;
}
}
void GFXGLCardProfiler::setupCardCapabilities()
{
GLint maxTexSize;
glGetIntegerv(GL_MAX_TEXTURE_SIZE, &maxTexSize);
const char* versionString = reinterpret_cast<const char*>(glGetString(GL_VERSION));
F32 glVersion = dAtof(versionString);
// OpenGL doesn't have separate maximum width/height.
setCapability("maxTextureWidth", maxTexSize);
setCapability("maxTextureHeight", maxTexSize);
setCapability("maxTextureSize", maxTexSize);
// If extensions haven't been inited, we're in trouble here.
bool suppVBO = (gglHasExtension(GL_ARB_vertex_buffer_object) || glVersion >= 1.499f);
setCapability("GL::suppVertexBufferObject", suppVBO);
// check if render to texture supported is available
bool suppRTT = gglHasExtension(GL_EXT_framebuffer_object);
setCapability("GL::suppRenderTexture", suppRTT);
bool suppBlit = gglHasExtension(GL_EXT_framebuffer_blit);
setCapability("GL::suppRTBlit", suppBlit);
bool suppFloatTex = gglHasExtension(GL_ATI_texture_float);
setCapability("GL::suppFloatTexture", suppFloatTex);
// Check for anisotropic filtering support.
bool suppAnisotropic = gglHasExtension( GL_EXT_texture_filter_anisotropic );
setCapability( "GL::suppAnisotropic", suppAnisotropic );
// check to see if we have the fragment shader extension or the gl version is high enough for glsl to be core
// also check to see if the language version is high enough
F32 glslVersion = dAtof(reinterpret_cast<const char*>(glGetString( GL_SHADING_LANGUAGE_VERSION)));
bool suppSPU = (gglHasExtension(GL_ARB_fragment_shader) || glVersion >= 1.999f) && glslVersion >= 1.0999;
setCapability("GL::suppFragmentShader", suppSPU);
bool suppAppleFence = gglHasExtension(GL_APPLE_fence);
setCapability("GL::APPLE::suppFence", suppAppleFence);
// When enabled, call glGenerateMipmapEXT() to generate mipmaps instead of relying on GL_GENERATE_MIPMAP
setCapability("GL::Workaround::needsExplicitGenerateMipmap", false);
// When enabled, binds and unbinds a texture target before doing the depth buffer copy. Failure to do
// so will cause a hard freeze on Mac OS 10.4 with a Radeon X1600
setCapability("GL::Workaround::X1600DepthBufferCopy", false);
// When enabled, does not copy the last column and row of the depth buffer in a depth buffer copy. Failure
// to do so will cause a kernel panic on Mac OS 10.5(.1) with a Radeon HD 2600 (fixed in 10.5.2)
setCapability("GL::Workaround::HD2600DepthBufferCopy", false);
// Certain Intel drivers have a divide by 0 crash if mipmaps are specified with
// glTexSubImage2D.
setCapability("GL::Workaround::noManualMips", false);
}
bool GFXGLCardProfiler::_queryCardCap(const String& query, U32& foundResult)
{
// Just doing what the D3D9 layer does
return 0;
}
bool GFXGLCardProfiler::_queryFormat(const GFXFormat fmt, const GFXTextureProfile *profile, bool &inOutAutogenMips)
{
// We assume if the format is valid that we can use it for any purpose.
// This may not be the case, but we have no way to check short of in depth
// testing of every format for every purpose. And by testing, I mean sitting
// down and doing it by hand, because there is no OpenGL API to check these
// things.
return GFXGLTextureInternalFormat[fmt] != GL_ZERO;
}

View file

@ -0,0 +1,54 @@
//-----------------------------------------------------------------------------
// Copyright (c) 2012 GarageGames, LLC
//
// Permission is hereby granted, free of charge, to any person obtaining a copy
// of this software and associated documentation files (the "Software"), to
// deal in the Software without restriction, including without limitation the
// rights to use, copy, modify, merge, publish, distribute, sublicense, and/or
// sell copies of the Software, and to permit persons to whom the Software is
// furnished to do so, subject to the following conditions:
//
// The above copyright notice and this permission notice shall be included in
// all copies or substantial portions of the Software.
//
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
// FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS
// IN THE SOFTWARE.
//-----------------------------------------------------------------------------
#ifndef _GFXGLCARDPROFILE_H
#define _GFXGLCARDPROFILE_H
#include "gfx/gfxCardProfile.h"
/// A note on workarounds - The following settings are used exclusively to work around driver bugs:
/// GL::Workaround::needsExplicitGenerateMipmap
/// GL::Workaround::X1600DepthBufferCopy
/// GL::Workaround::HD2600DepthBufferCopy
/// If you find that you need to work around additional driver bugs, add a new setting
/// of the form GL::Workaround::<name> and set it to false in GFXGLCardProfiler::setupCardCapabilities()
/// Enclose your workaround code in if(GFX->getCardProfiler()->queryProfile("GL::Workaround::<name>")) {
/// <workaround> }
/// Remember to set the work around to true in the card profile script!
class GFXGLCardProfiler : public GFXCardProfiler
{
public:
void init();
protected:
virtual const String& getRendererString() const { return mRendererString; }
virtual void setupCardCapabilities();
virtual bool _queryCardCap(const String& query, U32& foundResult);
virtual bool _queryFormat(const GFXFormat fmt, const GFXTextureProfile *profile, bool &inOutAutogenMips);
private:
String mRendererString;
typedef GFXCardProfiler Parent;
};
#endif

View file

@ -0,0 +1,248 @@
//-----------------------------------------------------------------------------
// Copyright (c) 2012 GarageGames, LLC
//
// Permission is hereby granted, free of charge, to any person obtaining a copy
// of this software and associated documentation files (the "Software"), to
// deal in the Software without restriction, including without limitation the
// rights to use, copy, modify, merge, publish, distribute, sublicense, and/or
// sell copies of the Software, and to permit persons to whom the Software is
// furnished to do so, subject to the following conditions:
//
// The above copyright notice and this permission notice shall be included in
// all copies or substantial portions of the Software.
//
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
// FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS
// IN THE SOFTWARE.
//-----------------------------------------------------------------------------
#include "gfx/gl/gfxGLDevice.h"
#include "gfx/gl/gfxGLTextureObject.h"
#include "gfx/gl/gfxGLEnumTranslate.h"
#include "gfx/gl/gfxGLUtils.h"
#include "gfx/gl/gfxGLCubemap.h"
#include "gfx/gfxTextureManager.h"
#include "gfx/gfxCardProfile.h"
#include "gfx/bitmap/DDSFile.h"
GLenum GFXGLCubemap::faceList[6] =
{
GL_TEXTURE_CUBE_MAP_POSITIVE_X, GL_TEXTURE_CUBE_MAP_NEGATIVE_X,
GL_TEXTURE_CUBE_MAP_POSITIVE_Y, GL_TEXTURE_CUBE_MAP_NEGATIVE_Y,
GL_TEXTURE_CUBE_MAP_POSITIVE_Z, GL_TEXTURE_CUBE_MAP_NEGATIVE_Z
};
GFXGLCubemap::GFXGLCubemap() :
mCubemap(0),
mDynamicTexSize(0),
mFaceFormat( GFXFormatR8G8B8A8 )
{
for(U32 i = 0; i < 6; i++)
mTextures[i] = NULL;
GFXTextureManager::addEventDelegate( this, &GFXGLCubemap::_onTextureEvent );
}
GFXGLCubemap::~GFXGLCubemap()
{
glDeleteTextures(1, &mCubemap);
GFXTextureManager::removeEventDelegate( this, &GFXGLCubemap::_onTextureEvent );
}
void GFXGLCubemap::fillCubeTextures(GFXTexHandle* faces)
{
glActiveTexture(GL_TEXTURE0);
glBindTexture(GL_TEXTURE_CUBE_MAP, mCubemap);
glTexParameteri(GL_TEXTURE_CUBE_MAP, GL_GENERATE_MIPMAP, GL_TRUE);
glTexParameteri(GL_TEXTURE_CUBE_MAP, GL_TEXTURE_MIN_FILTER, GL_NEAREST);
glTexParameteri(GL_TEXTURE_CUBE_MAP, GL_TEXTURE_MAG_FILTER, GL_NEAREST);
glTexParameteri(GL_TEXTURE_CUBE_MAP, GL_TEXTURE_WRAP_S, GL_CLAMP_TO_EDGE);
glTexParameteri(GL_TEXTURE_CUBE_MAP, GL_TEXTURE_WRAP_T, GL_CLAMP_TO_EDGE);
glTexParameteri(GL_TEXTURE_CUBE_MAP, GL_TEXTURE_WRAP_R, GL_CLAMP_TO_EDGE);
U32 reqWidth = faces[0]->getWidth();
U32 reqHeight = faces[0]->getHeight();
GFXFormat regFaceFormat = faces[0]->getFormat();
mWidth = reqWidth;
mHeight = reqHeight;
mFaceFormat = regFaceFormat;
mMipLevels = 1; // Lie for now
AssertFatal(reqWidth == reqHeight, "GFXGLCubemap::fillCubeTextures - Width and height must be equal!");
for(U32 i = 0; i < 6; i++)
{
AssertFatal(faces[i], avar("GFXGLCubemap::fillCubeFaces - texture %i is NULL!", i));
AssertFatal((faces[i]->getWidth() == reqWidth) && (faces[i]->getHeight() == reqHeight), "GFXGLCubemap::fillCubeFaces - All textures must have identical dimensions!");
AssertFatal(faces[i]->getFormat() == regFaceFormat, "GFXGLCubemap::fillCubeFaces - All textures must have identical formats!");
mTextures[i] = faces[i];
GFXFormat faceFormat = faces[i]->getFormat();
GFXGLTextureObject* glTex = static_cast<GFXGLTextureObject*>(faces[i].getPointer());
U8* buf = glTex->getTextureData();
glTexImage2D(faceList[i], 0, GFXGLTextureInternalFormat[faceFormat], faces[i]->getWidth(), faces[i]->getHeight(),
0, GFXGLTextureFormat[faceFormat], GFXGLTextureType[faceFormat], buf);
delete[] buf;
}
glBindTexture(GL_TEXTURE_CUBE_MAP, 0);
glBindBuffer(GL_PIXEL_UNPACK_BUFFER_ARB, 0);
}
void GFXGLCubemap::initStatic(GFXTexHandle* faces)
{
if(mCubemap)
return;
if(faces)
{
AssertFatal(faces[0], "GFXGLCubemap::initStatic - empty texture passed");
glGenTextures(1, &mCubemap);
fillCubeTextures(faces);
}
}
void GFXGLCubemap::initStatic( DDSFile *dds )
{
if(mCubemap)
return;
AssertFatal( dds, "GFXGLCubemap::initStatic - Got null DDS file!" );
AssertFatal( dds->isCubemap(), "GFXGLCubemap::initStatic - Got non-cubemap DDS file!" );
AssertFatal( dds->mSurfaces.size() == 6, "GFXGLCubemap::initStatic - DDS has less than 6 surfaces!" );
// HACK: I cannot put the genie back in the bottle and assign a
// DDSFile pointer back to a Resource<>.
//
// So we do a second lookup which works out ok for now, but shows
// the weakness in the ResourceManager not having a common base
// reference type.
//
mDDSFile = ResourceManager::get().load( dds->getSourcePath() );
AssertFatal( mDDSFile == dds, "GFXGLCubemap::initStatic - Couldn't find DDSFile resource!" );
glGenTextures(1, &mCubemap);
glActiveTexture(GL_TEXTURE0);
glBindTexture(GL_TEXTURE_CUBE_MAP, mCubemap);
glTexParameteri(GL_TEXTURE_CUBE_MAP, GL_GENERATE_MIPMAP, GL_TRUE);
glTexParameteri(GL_TEXTURE_CUBE_MAP, GL_TEXTURE_MIN_FILTER, GL_NEAREST);
glTexParameteri(GL_TEXTURE_CUBE_MAP, GL_TEXTURE_MAG_FILTER, GL_NEAREST);
glTexParameteri(GL_TEXTURE_CUBE_MAP, GL_TEXTURE_WRAP_S, GL_CLAMP_TO_EDGE);
glTexParameteri(GL_TEXTURE_CUBE_MAP, GL_TEXTURE_WRAP_T, GL_CLAMP_TO_EDGE);
glTexParameteri(GL_TEXTURE_CUBE_MAP, GL_TEXTURE_WRAP_R, GL_CLAMP_TO_EDGE);
mWidth = dds->getWidth();
mHeight = dds->getHeight();
mFaceFormat = dds->getFormat();
mMipLevels = 1;
// TODO: Support mipmaps here as well as decompressing the
// DDS if the format is unsupported.
AssertFatal(mWidth == mHeight, "GFXGLCubemap::initStatic - Width and height must be equal!");
for(U32 i = 0; i < 6; i++)
{
if ( !dds->mSurfaces[i] )
{
// TODO: The DDS can skip surfaces, but i'm unsure what i should
// do here when creating the cubemap. Ignore it for now.
continue;
}
const U8 *buffer = dds->mSurfaces[i]->mMips[0];
U32 surfaceSize = dds->getSurfaceSize( mHeight, mWidth, i );
glCompressedTexImage2D( faceList[i], 0, GFXGLTextureInternalFormat[mFaceFormat],
mWidth, mHeight, 0, surfaceSize, buffer );
}
glBindTexture(GL_TEXTURE_CUBE_MAP, 0);
glBindBuffer(GL_PIXEL_UNPACK_BUFFER_ARB, 0);
}
void GFXGLCubemap::initDynamic(U32 texSize, GFXFormat faceFormat)
{
mDynamicTexSize = texSize;
mFaceFormat = faceFormat;
glGenTextures(1, &mCubemap);
glBindTexture(GL_TEXTURE_CUBE_MAP, mCubemap);
glTexParameteri(GL_TEXTURE_CUBE_MAP, GL_TEXTURE_MIN_FILTER, GL_NEAREST);
glTexParameteri(GL_TEXTURE_CUBE_MAP, GL_TEXTURE_MAG_FILTER, GL_NEAREST);
glTexParameteri(GL_TEXTURE_CUBE_MAP, GL_TEXTURE_WRAP_S, GL_CLAMP_TO_EDGE);
glTexParameteri(GL_TEXTURE_CUBE_MAP, GL_TEXTURE_WRAP_T, GL_CLAMP_TO_EDGE);
glTexParameteri(GL_TEXTURE_CUBE_MAP, GL_TEXTURE_WRAP_R, GL_CLAMP_TO_EDGE);
mWidth = texSize;
mHeight = texSize;
mMipLevels = 1;
for(U32 i = 0; i < 6; i++)
{
glTexImage2D( faceList[i], 0, GFXGLTextureInternalFormat[faceFormat], texSize, texSize,
0, GFXGLTextureFormat[faceFormat], GFXGLTextureType[faceFormat], NULL);
}
glBindTexture(GL_TEXTURE_CUBE_MAP, 0);
}
void GFXGLCubemap::zombify()
{
glDeleteTextures(1, &mCubemap);
mCubemap = 0;
}
void GFXGLCubemap::resurrect()
{
// Handled in tmResurrect
}
void GFXGLCubemap::tmResurrect()
{
if(mDynamicTexSize)
initDynamic(mDynamicTexSize,mFaceFormat);
else
{
if ( mDDSFile )
initStatic( mDDSFile );
else
initStatic( mTextures );
}
}
void GFXGLCubemap::setToTexUnit(U32 tuNum)
{
static_cast<GFXGLDevice*>(getOwningDevice())->setCubemapInternal(tuNum, this);
}
void GFXGLCubemap::bind(U32 textureUnit) const
{
glActiveTexture(GL_TEXTURE0 + textureUnit);
glBindTexture(GL_TEXTURE_CUBE_MAP, mCubemap);
GFXGLStateBlockRef sb = static_cast<GFXGLDevice*>(GFX)->getCurrentStateBlock();
AssertFatal(sb, "GFXGLCubemap::bind - No active stateblock!");
if (!sb)
return;
const GFXSamplerStateDesc& ssd = sb->getDesc().samplers[textureUnit];
glTexParameteri(GL_TEXTURE_CUBE_MAP, GL_TEXTURE_MIN_FILTER, minificationFilter(ssd.minFilter, ssd.mipFilter, 0));
glTexParameteri(GL_TEXTURE_CUBE_MAP, GL_TEXTURE_MAG_FILTER, GFXGLTextureFilter[ssd.magFilter]);
glTexParameteri(GL_TEXTURE_CUBE_MAP, GL_TEXTURE_WRAP_S, GFXGLTextureAddress[ssd.addressModeU]);
glTexParameteri(GL_TEXTURE_CUBE_MAP, GL_TEXTURE_WRAP_T, GFXGLTextureAddress[ssd.addressModeV]);
glTexParameteri(GL_TEXTURE_CUBE_MAP, GL_TEXTURE_WRAP_R, GFXGLTextureAddress[ssd.addressModeW]);
glTexEnvf(GL_TEXTURE_FILTER_CONTROL, GL_TEXTURE_LOD_BIAS, ssd.mipLODBias);
}
void GFXGLCubemap::_onTextureEvent( GFXTexCallbackCode code )
{
if ( code == GFXZombify )
zombify();
else
tmResurrect();
}

View file

@ -0,0 +1,93 @@
//-----------------------------------------------------------------------------
// Copyright (c) 2012 GarageGames, LLC
//
// Permission is hereby granted, free of charge, to any person obtaining a copy
// of this software and associated documentation files (the "Software"), to
// deal in the Software without restriction, including without limitation the
// rights to use, copy, modify, merge, publish, distribute, sublicense, and/or
// sell copies of the Software, and to permit persons to whom the Software is
// furnished to do so, subject to the following conditions:
//
// The above copyright notice and this permission notice shall be included in
// all copies or substantial portions of the Software.
//
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
// FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS
// IN THE SOFTWARE.
//-----------------------------------------------------------------------------
#ifndef _GFXGLCUBEMAP_H_
#define _GFXGLCUBEMAP_H_
#ifndef _GFXCUBEMAP_H_
#include "gfx/gfxCubemap.h"
#endif
#ifndef __RESOURCE_H__
#include "core/resource.h"
#endif
class GFXGLCubemap : public GFXCubemap
{
public:
GFXGLCubemap();
virtual ~GFXGLCubemap();
virtual void initStatic( GFXTexHandle *faces );
virtual void initStatic( DDSFile *dds );
virtual void initDynamic( U32 texSize, GFXFormat faceFormat = GFXFormatR8G8B8A8 );
virtual U32 getSize() const { return mWidth; }
virtual GFXFormat getFormat() const { return mFaceFormat; }
// Convenience methods for GFXGLTextureTarget
U32 getWidth() { return mWidth; }
U32 getHeight() { return mHeight; }
U32 getNumMipLevels() { return mMipLevels; }
U32 getHandle() { return mCubemap; }
// GFXResource interface
virtual void zombify();
virtual void resurrect();
/// Called by texCB; this is to ensure that all textures have been resurrected before we attempt to res the cubemap.
void tmResurrect();
static GLenum getEnumForFaceNumber(U32 face) { return faceList[face]; } ///< Performs lookup to get a GLenum for the given face number
protected:
friend class GFXDevice;
friend class GFXGLDevice;
/// The callback used to get texture events.
/// @see GFXTextureManager::addEventDelegate
void _onTextureEvent( GFXTexCallbackCode code );
GLuint mCubemap; ///< Internal GL handle
U32 mDynamicTexSize; ///< Size of faces for a dynamic texture (used in resurrect)
// Self explanatory
U32 mWidth;
U32 mHeight;
U32 mMipLevels;
GFXFormat mFaceFormat;
GFXTexHandle mTextures[6]; ///< Keep refs to our textures for resurrection of static cubemaps
/// The backing DDSFile uses to restore the faces
/// when the surface is lost.
Resource<DDSFile> mDDSFile;
// should only be called by GFXDevice
virtual void setToTexUnit( U32 tuNum ); ///< Binds the cubemap to the given texture unit
virtual void bind(U32 textureUnit) const; ///< Notifies our owning device that we want to be set to the given texture unit (used for GL internal state tracking)
void fillCubeTextures(GFXTexHandle* faces); ///< Copies the textures in faces into the cubemap
static GLenum faceList[6]; ///< Lookup table
};
#endif

View file

@ -0,0 +1,769 @@
//-----------------------------------------------------------------------------
// Copyright (c) 2012 GarageGames, LLC
//
// Permission is hereby granted, free of charge, to any person obtaining a copy
// of this software and associated documentation files (the "Software"), to
// deal in the Software without restriction, including without limitation the
// rights to use, copy, modify, merge, publish, distribute, sublicense, and/or
// sell copies of the Software, and to permit persons to whom the Software is
// furnished to do so, subject to the following conditions:
//
// The above copyright notice and this permission notice shall be included in
// all copies or substantial portions of the Software.
//
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
// FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS
// IN THE SOFTWARE.
//-----------------------------------------------------------------------------
#include "platform/platform.h"
#include "gfx/gl/gfxGLDevice.h"
#include "gfx/gfxCubemap.h"
#include "gfx/screenshot.h"
#include "gfx/gfxDrawUtil.h"
#include "gfx/gl/gfxGLEnumTranslate.h"
#include "gfx/gl/gfxGLVertexBuffer.h"
#include "gfx/gl/gfxGLPrimitiveBuffer.h"
#include "gfx/gl/gfxGLTextureTarget.h"
#include "gfx/gl/gfxGLTextureManager.h"
#include "gfx/gl/gfxGLTextureObject.h"
#include "gfx/gl/gfxGLCubemap.h"
#include "gfx/gl/gfxGLCardProfiler.h"
#include "gfx/gl/gfxGLWindowTarget.h"
#include "gfx/gl/ggl/ggl.h"
#include "platform/platformDlibrary.h"
#include "gfx/gl/gfxGLShader.h"
#include "gfx/primBuilder.h"
#include "console/console.h"
#include "gfx/gl/gfxGLOcclusionQuery.h"
GFXAdapter::CreateDeviceInstanceDelegate GFXGLDevice::mCreateDeviceInstance(GFXGLDevice::createInstance);
GFXDevice *GFXGLDevice::createInstance( U32 adapterIndex )
{
return new GFXGLDevice(adapterIndex);
}
namespace GL
{
extern void gglPerformBinds();
extern void gglPerformExtensionBinds(void *context);
}
void loadGLCore()
{
static bool coreLoaded = false; // Guess what this is for.
if(coreLoaded)
return;
coreLoaded = true;
// Make sure we've got our GL bindings.
GL::gglPerformBinds();
}
void loadGLExtensions(void *context)
{
static bool extensionsLoaded = false;
if(extensionsLoaded)
return;
extensionsLoaded = true;
GL::gglPerformExtensionBinds(context);
}
void GFXGLDevice::initGLState()
{
// We don't currently need to sync device state with a known good place because we are
// going to set everything in GFXGLStateBlock, but if we change our GFXGLStateBlock strategy, this may
// need to happen.
// Deal with the card profiler here when we know we have a valid context.
mCardProfiler = new GFXGLCardProfiler();
mCardProfiler->init();
glGetIntegerv(GL_MAX_TEXTURE_IMAGE_UNITS, (GLint*)&mMaxShaderTextures);
glGetIntegerv(GL_MAX_TEXTURE_UNITS, (GLint*)&mMaxFFTextures);
glPixelStorei(GL_UNPACK_ALIGNMENT, 1);
// Apple's drivers lie and claim that everything supports fragment shaders. Conveniently they don't lie about the number
// of supported image units. Checking for 16 or more image units ensures that we don't try and use pixel shaders on
// cards which don't support them.
if(mCardProfiler->queryProfile("GL::suppFragmentShader") && mMaxShaderTextures >= 16)
mPixelShaderVersion = 2.0f;
else
mPixelShaderVersion = 0.0f;
// MACHAX - Setting mPixelShaderVersion to 3.0 will allow Advanced Lighting
// to run. At the time of writing (6/18) it doesn't quite work yet.
if(Con::getBoolVariable("$pref::machax::enableAdvancedLighting", false))
mPixelShaderVersion = 3.0f;
mSupportsAnisotropic = mCardProfiler->queryProfile( "GL::suppAnisotropic" );
}
GFXGLDevice::GFXGLDevice(U32 adapterIndex) :
mAdapterIndex(adapterIndex),
mCurrentVB(NULL),
mCurrentPB(NULL),
m_mCurrentWorld(true),
m_mCurrentView(true),
mContext(NULL),
mPixelFormat(NULL),
mPixelShaderVersion(0.0f),
mMaxShaderTextures(2),
mMaxFFTextures(2),
mClip(0, 0, 0, 0)
{
loadGLCore();
GFXGLEnumTranslate::init();
GFXVertexColor::setSwizzle( &Swizzles::rgba );
mDeviceSwizzle32 = &Swizzles::bgra;
mDeviceSwizzle24 = &Swizzles::bgr;
mTextureManager = new GFXGLTextureManager();
gScreenShot = new ScreenShot();
for(U32 i = 0; i < TEXTURE_STAGE_COUNT; i++)
mActiveTextureType[i] = GL_ZERO;
}
GFXGLDevice::~GFXGLDevice()
{
mCurrentStateBlock = NULL;
mCurrentPB = NULL;
mCurrentVB = NULL;
for(U32 i = 0; i < mVolatileVBs.size(); i++)
mVolatileVBs[i] = NULL;
for(U32 i = 0; i < mVolatilePBs.size(); i++)
mVolatilePBs[i] = NULL;
GFXResource* walk = mResourceListHead;
while(walk)
{
walk->zombify();
walk = walk->getNextResource();
}
if( mCardProfiler )
SAFE_DELETE( mCardProfiler );
SAFE_DELETE( gScreenShot );
}
void GFXGLDevice::zombify()
{
mTextureManager->zombify();
if(mCurrentVB)
mCurrentVB->finish();
if(mCurrentPB)
mCurrentPB->finish();
//mVolatileVBs.clear();
//mVolatilePBs.clear();
GFXResource* walk = mResourceListHead;
while(walk)
{
walk->zombify();
walk = walk->getNextResource();
}
}
void GFXGLDevice::resurrect()
{
GFXResource* walk = mResourceListHead;
while(walk)
{
walk->resurrect();
walk = walk->getNextResource();
}
if(mCurrentVB)
mCurrentVB->prepare();
if(mCurrentPB)
mCurrentPB->prepare();
mTextureManager->resurrect();
}
GFXVertexBuffer* GFXGLDevice::findVolatileVBO(U32 numVerts, const GFXVertexFormat *vertexFormat, U32 vertSize)
{
for(U32 i = 0; i < mVolatileVBs.size(); i++)
if ( mVolatileVBs[i]->mNumVerts >= numVerts &&
mVolatileVBs[i]->mVertexFormat.isEqual( *vertexFormat ) &&
mVolatileVBs[i]->mVertexSize == vertSize &&
mVolatileVBs[i]->getRefCount() == 1 )
return mVolatileVBs[i];
// No existing VB, so create one
StrongRefPtr<GFXGLVertexBuffer> buf(new GFXGLVertexBuffer(GFX, numVerts, vertexFormat, vertSize, GFXBufferTypeVolatile));
buf->registerResourceWithDevice(this);
mVolatileVBs.push_back(buf);
return buf.getPointer();
}
GFXPrimitiveBuffer* GFXGLDevice::findVolatilePBO(U32 numIndices, U32 numPrimitives)
{
for(U32 i = 0; i < mVolatilePBs.size(); i++)
if((mVolatilePBs[i]->mIndexCount >= numIndices) && (mVolatilePBs[i]->getRefCount() == 1))
return mVolatilePBs[i];
// No existing PB, so create one
StrongRefPtr<GFXGLPrimitiveBuffer> buf(new GFXGLPrimitiveBuffer(GFX, numIndices, numPrimitives, GFXBufferTypeVolatile));
buf->registerResourceWithDevice(this);
mVolatilePBs.push_back(buf);
return buf.getPointer();
}
GFXVertexBuffer *GFXGLDevice::allocVertexBuffer( U32 numVerts,
const GFXVertexFormat *vertexFormat,
U32 vertSize,
GFXBufferType bufferType )
{
if(bufferType == GFXBufferTypeVolatile)
return findVolatileVBO(numVerts, vertexFormat, vertSize);
GFXGLVertexBuffer* buf = new GFXGLVertexBuffer( GFX, numVerts, vertexFormat, vertSize, bufferType );
buf->registerResourceWithDevice(this);
return buf;
}
GFXPrimitiveBuffer *GFXGLDevice::allocPrimitiveBuffer( U32 numIndices, U32 numPrimitives, GFXBufferType bufferType )
{
if(bufferType == GFXBufferTypeVolatile)
return findVolatilePBO(numIndices, numPrimitives);
GFXGLPrimitiveBuffer* buf = new GFXGLPrimitiveBuffer(GFX, numIndices, numPrimitives, bufferType);
buf->registerResourceWithDevice(this);
return buf;
}
void GFXGLDevice::setVertexStream( U32 stream, GFXVertexBuffer *buffer )
{
AssertFatal( stream == 0, "GFXGLDevice::setVertexStream - We don't support multiple vertex streams!" );
// Reset the state the old VB required, then set the state the new VB requires.
if ( mCurrentVB )
mCurrentVB->finish();
mCurrentVB = static_cast<GFXGLVertexBuffer*>( buffer );
if ( mCurrentVB )
mCurrentVB->prepare();
}
void GFXGLDevice::setVertexStreamFrequency( U32 stream, U32 frequency )
{
// We don't support vertex stream frequency or mesh instancing in OGL yet.
}
GFXCubemap* GFXGLDevice::createCubemap()
{
GFXGLCubemap* cube = new GFXGLCubemap();
cube->registerResourceWithDevice(this);
return cube;
};
void GFXGLDevice::endSceneInternal()
{
// nothing to do for opengl
mCanCurrentlyRender = false;
}
void GFXGLDevice::clear(U32 flags, ColorI color, F32 z, U32 stencil)
{
// Make sure we have flushed our render target state.
_updateRenderTargets();
bool zwrite = true;
if (mCurrentGLStateBlock)
{
zwrite = mCurrentGLStateBlock->getDesc().zWriteEnable;
}
glDepthMask(true);
ColorF c = color;
glClearColor(c.red, c.green, c.blue, c.alpha);
glClearDepth(z);
glClearStencil(stencil);
GLbitfield clearflags = 0;
clearflags |= (flags & GFXClearTarget) ? GL_COLOR_BUFFER_BIT : 0;
clearflags |= (flags & GFXClearZBuffer) ? GL_DEPTH_BUFFER_BIT : 0;
clearflags |= (flags & GFXClearStencil) ? GL_STENCIL_BUFFER_BIT : 0;
glClear(clearflags);
if(!zwrite)
glDepthMask(false);
}
// Given a primitive type and a number of primitives, return the number of indexes/vertexes used.
GLsizei GFXGLDevice::primCountToIndexCount(GFXPrimitiveType primType, U32 primitiveCount)
{
switch (primType)
{
case GFXPointList :
return primitiveCount;
break;
case GFXLineList :
return primitiveCount * 2;
break;
case GFXLineStrip :
return primitiveCount + 1;
break;
case GFXTriangleList :
return primitiveCount * 3;
break;
case GFXTriangleStrip :
return 2 + primitiveCount;
break;
case GFXTriangleFan :
return 2 + primitiveCount;
break;
default:
AssertFatal(false, "GFXGLDevice::primCountToIndexCount - unrecognized prim type");
break;
}
return 0;
}
inline void GFXGLDevice::preDrawPrimitive()
{
if( mStateDirty )
{
updateStates();
}
if(mCurrentShaderConstBuffer)
setShaderConstBufferInternal(mCurrentShaderConstBuffer);
}
inline void GFXGLDevice::postDrawPrimitive(U32 primitiveCount)
{
mDeviceStatistics.mDrawCalls++;
mDeviceStatistics.mPolyCount += primitiveCount;
}
void GFXGLDevice::drawPrimitive( GFXPrimitiveType primType, U32 vertexStart, U32 primitiveCount )
{
preDrawPrimitive();
// There are some odd performance issues if a buffer is bound to GL_ELEMENT_ARRAY_BUFFER when glDrawArrays is called. Unbinding the buffer
// improves performance by 10%.
if(mCurrentPB)
mCurrentPB->finish();
glDrawArrays(GFXGLPrimType[primType], vertexStart, primCountToIndexCount(primType, primitiveCount));
if(mCurrentPB)
mCurrentPB->prepare();
postDrawPrimitive(primitiveCount);
}
void GFXGLDevice::drawIndexedPrimitive( GFXPrimitiveType primType,
U32 startVertex,
U32 minIndex,
U32 numVerts,
U32 startIndex,
U32 primitiveCount )
{
AssertFatal( startVertex == 0, "GFXGLDevice::drawIndexedPrimitive() - Non-zero startVertex unsupported!" );
preDrawPrimitive();
U16* buf = (U16*)static_cast<GFXGLPrimitiveBuffer*>(mCurrentPrimitiveBuffer.getPointer())->getBuffer() + startIndex;
glDrawElements(GFXGLPrimType[primType], primCountToIndexCount(primType, primitiveCount), GL_UNSIGNED_SHORT, buf);
postDrawPrimitive(primitiveCount);
}
void GFXGLDevice::setPB(GFXGLPrimitiveBuffer* pb)
{
if(mCurrentPB)
mCurrentPB->finish();
mCurrentPB = pb;
}
void GFXGLDevice::setLightInternal(U32 lightStage, const GFXLightInfo light, bool lightEnable)
{
if(!lightEnable)
{
glDisable(GL_LIGHT0 + lightStage);
return;
}
if(light.mType == GFXLightInfo::Ambient)
{
AssertFatal(false, "Instead of setting an ambient light you should set the global ambient color.");
return;
}
GLenum lightEnum = GL_LIGHT0 + lightStage;
glLightfv(lightEnum, GL_AMBIENT, (GLfloat*)&light.mAmbient);
glLightfv(lightEnum, GL_DIFFUSE, (GLfloat*)&light.mColor);
glLightfv(lightEnum, GL_SPECULAR, (GLfloat*)&light.mColor);
F32 pos[4];
if(light.mType != GFXLightInfo::Vector)
{
dMemcpy(pos, &light.mPos, sizeof(light.mPos));
pos[3] = 1.0;
}
else
{
dMemcpy(pos, &light.mDirection, sizeof(light.mDirection));
pos[3] = 0.0;
}
// Harcoded attenuation
glLightf(lightEnum, GL_CONSTANT_ATTENUATION, 1.0f);
glLightf(lightEnum, GL_LINEAR_ATTENUATION, 0.1f);
glLightf(lightEnum, GL_QUADRATIC_ATTENUATION, 0.0f);
glLightfv(lightEnum, GL_POSITION, (GLfloat*)&pos);
glEnable(lightEnum);
}
void GFXGLDevice::setLightMaterialInternal(const GFXLightMaterial mat)
{
// CodeReview - Setting these for front and back is unnecessary. We should consider
// checking what faces we're culling and setting this only for the unculled faces.
glMaterialfv(GL_FRONT_AND_BACK, GL_AMBIENT, (GLfloat*)&mat.ambient);
glMaterialfv(GL_FRONT_AND_BACK, GL_DIFFUSE, (GLfloat*)&mat.diffuse);
glMaterialfv(GL_FRONT_AND_BACK, GL_SPECULAR, (GLfloat*)&mat.specular);
glMaterialfv(GL_FRONT_AND_BACK, GL_EMISSION, (GLfloat*)&mat.emissive);
glMaterialf(GL_FRONT_AND_BACK, GL_SHININESS, mat.shininess);
}
void GFXGLDevice::setGlobalAmbientInternal(ColorF color)
{
glLightModelfv(GL_LIGHT_MODEL_AMBIENT, (GLfloat*)&color);
}
void GFXGLDevice::setTextureInternal(U32 textureUnit, const GFXTextureObject*texture)
{
const GFXGLTextureObject *tex = static_cast<const GFXGLTextureObject*>(texture);
glActiveTexture(GL_TEXTURE0 + textureUnit);
if (tex)
{
// GFXGLTextureObject::bind also handles applying the current sampler state.
if(mActiveTextureType[textureUnit] != tex->getBinding() && mActiveTextureType[textureUnit] != GL_ZERO)
{
glBindTexture(mActiveTextureType[textureUnit], 0);
glDisable(mActiveTextureType[textureUnit]);
}
mActiveTextureType[textureUnit] = tex->getBinding();
tex->bind(textureUnit);
}
else if(mActiveTextureType[textureUnit] != GL_ZERO)
{
glBindTexture(mActiveTextureType[textureUnit], 0);
glDisable(mActiveTextureType[textureUnit]);
mActiveTextureType[textureUnit] = GL_ZERO;
}
glActiveTexture(GL_TEXTURE0);
}
void GFXGLDevice::setCubemapInternal(U32 textureUnit, const GFXGLCubemap* texture)
{
glActiveTexture(GL_TEXTURE0 + textureUnit);
if(texture)
{
if(mActiveTextureType[textureUnit] != GL_TEXTURE_CUBE_MAP && mActiveTextureType[textureUnit] != GL_ZERO)
{
glBindTexture(mActiveTextureType[textureUnit], 0);
glDisable(mActiveTextureType[textureUnit]);
}
mActiveTextureType[textureUnit] = GL_TEXTURE_CUBE_MAP;
texture->bind(textureUnit);
}
else if(mActiveTextureType[textureUnit] != GL_ZERO)
{
glBindTexture(mActiveTextureType[textureUnit], 0);
glDisable(mActiveTextureType[textureUnit]);
mActiveTextureType[textureUnit] = GL_ZERO;
}
glActiveTexture(GL_TEXTURE0);
}
void GFXGLDevice::setMatrix( GFXMatrixType mtype, const MatrixF &mat )
{
MatrixF modelview;
switch (mtype)
{
case GFXMatrixWorld :
{
glMatrixMode(GL_MODELVIEW);
m_mCurrentWorld = mat;
modelview = m_mCurrentWorld;
modelview *= m_mCurrentView;
modelview.transpose();
glLoadMatrixf((F32*) modelview);
}
break;
case GFXMatrixView :
{
glMatrixMode(GL_MODELVIEW);
m_mCurrentView = mat;
modelview = m_mCurrentView;
modelview *= m_mCurrentWorld;
modelview.transpose();
glLoadMatrixf((F32*) modelview);
}
break;
case GFXMatrixProjection :
{
glMatrixMode(GL_PROJECTION);
MatrixF t(mat);
t.transpose();
glLoadMatrixf((F32*) t);
glMatrixMode(GL_MODELVIEW);
}
break;
// CodeReview - Add support for texture transform matrix types
default:
AssertFatal(false, "GFXGLDevice::setMatrix - Unknown matrix mode!");
return;
}
}
void GFXGLDevice::setClipRect( const RectI &inRect )
{
AssertFatal(mCurrentRT.isValid(), "GFXGLDevice::setClipRect - must have a render target set to do any rendering operations!");
// Clip the rect against the renderable size.
Point2I size = mCurrentRT->getSize();
RectI maxRect(Point2I(0,0), size);
mClip = inRect;
mClip.intersect(maxRect);
// Create projection matrix. See http://www.opengl.org/documentation/specs/man_pages/hardcopy/GL/html/gl/ortho.html
const F32 left = mClip.point.x;
const F32 right = mClip.point.x + mClip.extent.x;
const F32 bottom = mClip.extent.y;
const F32 top = 0.0f;
const F32 near = 0.0f;
const F32 far = 1.0f;
const F32 tx = -(right + left)/(right - left);
const F32 ty = -(top + bottom)/(top - bottom);
const F32 tz = -(far + near)/(far - near);
static Point4F pt;
pt.set(2.0f / (right - left), 0.0f, 0.0f, 0.0f);
mProjectionMatrix.setColumn(0, pt);
pt.set(0.0f, 2.0f/(top - bottom), 0.0f, 0.0f);
mProjectionMatrix.setColumn(1, pt);
pt.set(0.0f, 0.0f, -2.0f/(far - near), 0.0f);
mProjectionMatrix.setColumn(2, pt);
pt.set(tx, ty, tz, 1.0f);
mProjectionMatrix.setColumn(3, pt);
// Translate projection matrix.
static MatrixF translate(true);
pt.set(0.0f, -mClip.point.y, 0.0f, 1.0f);
translate.setColumn(3, pt);
mProjectionMatrix *= translate;
setMatrix(GFXMatrixProjection, mProjectionMatrix);
MatrixF mTempMatrix(true);
setViewMatrix( mTempMatrix );
setWorldMatrix( mTempMatrix );
// Set the viewport to the clip rect (with y flip)
RectI viewport(mClip.point.x, size.y - (mClip.point.y + mClip.extent.y), mClip.extent.x, mClip.extent.y);
setViewport(viewport);
}
/// Creates a state block object based on the desc passed in. This object
/// represents an immutable state.
GFXStateBlockRef GFXGLDevice::createStateBlockInternal(const GFXStateBlockDesc& desc)
{
return GFXStateBlockRef(new GFXGLStateBlock(desc));
}
/// Activates a stateblock
void GFXGLDevice::setStateBlockInternal(GFXStateBlock* block, bool force)
{
AssertFatal(dynamic_cast<GFXGLStateBlock*>(block), "GFXGLDevice::setStateBlockInternal - Incorrect stateblock type for this device!");
GFXGLStateBlock* glBlock = static_cast<GFXGLStateBlock*>(block);
GFXGLStateBlock* glCurrent = static_cast<GFXGLStateBlock*>(mCurrentStateBlock.getPointer());
if (force)
glCurrent = NULL;
glBlock->activate(glCurrent); // Doesn't use current yet.
mCurrentGLStateBlock = glBlock;
}
//------------------------------------------------------------------------------
GFXTextureTarget * GFXGLDevice::allocRenderToTextureTarget()
{
GFXGLTextureTarget *targ = new GFXGLTextureTarget();
targ->registerResourceWithDevice(this);
return targ;
}
GFXFence * GFXGLDevice::createFence()
{
GFXFence* fence = _createPlatformSpecificFence();
if(!fence)
fence = new GFXGeneralFence( this );
fence->registerResourceWithDevice(this);
return fence;
}
GFXOcclusionQuery* GFXGLDevice::createOcclusionQuery()
{
GFXOcclusionQuery *query = new GFXGLOcclusionQuery( this );
query->registerResourceWithDevice(this);
return query;
}
void GFXGLDevice::setupGenericShaders( GenericShaderType type )
{
TORQUE_UNUSED(type);
// We have FF support, use that.
disableShaders();
}
GFXShader* GFXGLDevice::createShader()
{
GFXGLShader* shader = new GFXGLShader();
shader->registerResourceWithDevice( this );
return shader;
}
void GFXGLDevice::setShader( GFXShader *shader )
{
if ( shader )
{
GFXGLShader *glShader = static_cast<GFXGLShader*>( shader );
glShader->useProgram();
}
else
glUseProgram(0);
}
void GFXGLDevice::disableShaders()
{
setShader(NULL);
setShaderConstBuffer( NULL );
}
void GFXGLDevice::setShaderConstBufferInternal(GFXShaderConstBuffer* buffer)
{
static_cast<GFXGLShaderConstBuffer*>(buffer)->activate();
}
U32 GFXGLDevice::getNumSamplers() const
{
return mPixelShaderVersion > 0.001f ? mMaxShaderTextures : mMaxFFTextures;
}
U32 GFXGLDevice::getNumRenderTargets() const
{
return 1;
}
void GFXGLDevice::_updateRenderTargets()
{
if ( mRTDirty || mCurrentRT->isPendingState() )
{
if ( mRTDeactivate )
{
mRTDeactivate->deactivate();
mRTDeactivate = NULL;
}
// NOTE: The render target changes is not really accurate
// as the GFXTextureTarget supports MRT internally. So when
// we activate a GFXTarget it could result in multiple calls
// to SetRenderTarget on the actual device.
mDeviceStatistics.mRenderTargetChanges++;
GFXGLTextureTarget *tex = dynamic_cast<GFXGLTextureTarget*>( mCurrentRT.getPointer() );
if ( tex )
{
tex->applyState();
tex->makeActive();
}
else
{
GFXGLWindowTarget *win = dynamic_cast<GFXGLWindowTarget*>( mCurrentRT.getPointer() );
AssertFatal( win != NULL,
"GFXGLDevice::_updateRenderTargets() - invalid target subclass passed!" );
win->makeActive();
if( win->mContext != static_cast<GFXGLDevice*>(GFX)->mContext )
{
mRTDirty = false;
GFX->updateStates(true);
}
}
mRTDirty = false;
}
if ( mViewportDirty )
{
glViewport( mViewport.point.x, mViewport.point.y, mViewport.extent.x, mViewport.extent.y );
mViewportDirty = false;
}
}
GFXFormat GFXGLDevice::selectSupportedFormat( GFXTextureProfile* profile,
const Vector<GFXFormat>& formats,
bool texture,
bool mustblend,
bool mustfilter )
{
for(U32 i = 0; i < formats.size(); i++)
{
// Single channel textures are not supported by FBOs.
if(profile->testFlag(GFXTextureProfile::RenderTarget) && (formats[i] == GFXFormatA8 || formats[i] == GFXFormatL8 || formats[i] == GFXFormatL16))
continue;
if(GFXGLTextureInternalFormat[formats[i]] == GL_ZERO)
continue;
return formats[i];
}
return GFXFormatR8G8B8A8;
}
//
// Register this device with GFXInit
//
class GFXGLRegisterDevice
{
public:
GFXGLRegisterDevice()
{
GFXInit::getRegisterDeviceSignal().notify(&GFXGLDevice::enumerateAdapters);
}
};
static GFXGLRegisterDevice pGLRegisterDevice;
ConsoleFunction(cycleResources, void, 1, 1, "")
{
static_cast<GFXGLDevice*>(GFX)->zombify();
static_cast<GFXGLDevice*>(GFX)->resurrect();
}

View file

@ -0,0 +1,237 @@
//-----------------------------------------------------------------------------
// Copyright (c) 2012 GarageGames, LLC
//
// Permission is hereby granted, free of charge, to any person obtaining a copy
// of this software and associated documentation files (the "Software"), to
// deal in the Software without restriction, including without limitation the
// rights to use, copy, modify, merge, publish, distribute, sublicense, and/or
// sell copies of the Software, and to permit persons to whom the Software is
// furnished to do so, subject to the following conditions:
//
// The above copyright notice and this permission notice shall be included in
// all copies or substantial portions of the Software.
//
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
// FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS
// IN THE SOFTWARE.
//-----------------------------------------------------------------------------
#ifndef _GFXGLDEVICE_H_
#define _GFXGLDEVICE_H_
#include "platform/platform.h"
#include "gfx/gfxDevice.h"
#include "gfx/gfxInit.h"
#ifndef GL_GGL_H
#include "gfx/gl/ggl/ggl.h"
#endif
#include "windowManager/platformWindow.h"
#include "gfx/gfxFence.h"
#include "gfx/gfxResource.h"
#include "gfx/gl/gfxGLStateBlock.h"
class GFXGLVertexBuffer;
class GFXGLPrimitiveBuffer;
class GFXGLTextureTarget;
class GFXGLCubemap;
class GFXGLDevice : public GFXDevice
{
public:
void zombify();
void resurrect();
GFXGLDevice(U32 adapterIndex);
virtual ~GFXGLDevice();
static void enumerateAdapters( Vector<GFXAdapter*> &adapterList );
static GFXDevice *createInstance( U32 adapterIndex );
virtual void init( const GFXVideoMode &mode, PlatformWindow *window = NULL );
virtual void activate() { }
virtual void deactivate() { }
virtual GFXAdapterType getAdapterType() { return OpenGL; }
virtual void enterDebugEvent(ColorI color, const char *name) { }
virtual void leaveDebugEvent() { }
virtual void setDebugMarker(ColorI color, const char *name) { }
virtual void enumerateVideoModes();
virtual U32 getTotalVideoMemory();
virtual GFXCubemap * createCubemap();
virtual F32 getFillConventionOffset() const { return 0.0f; }
///@}
/// @name Render Target functions
/// @{
///
virtual GFXTextureTarget *allocRenderToTextureTarget();
virtual GFXWindowTarget *allocWindowTarget(PlatformWindow *window);
virtual void _updateRenderTargets();
///@}
/// @name Shader functions
/// @{
virtual F32 getPixelShaderVersion() const { return mPixelShaderVersion; }
virtual void setPixelShaderVersion( F32 version ) { mPixelShaderVersion = version; }
virtual void setShader(GFXShader* shd);
virtual void disableShaders(); ///< Equivalent to setShader(NULL)
/// @attention GL cannot check if the given format supports blending or filtering!
virtual GFXFormat selectSupportedFormat(GFXTextureProfile *profile,
const Vector<GFXFormat> &formats, bool texture, bool mustblend, bool mustfilter);
/// Returns the number of texture samplers that can be used in a shader rendering pass
virtual U32 getNumSamplers() const;
/// Returns the number of simultaneous render targets supported by the device.
virtual U32 getNumRenderTargets() const;
virtual GFXShader* createShader();
virtual void clear( U32 flags, ColorI color, F32 z, U32 stencil );
virtual bool beginSceneInternal();
virtual void endSceneInternal();
virtual void drawPrimitive( GFXPrimitiveType primType, U32 vertexStart, U32 primitiveCount );
virtual void drawIndexedPrimitive( GFXPrimitiveType primType,
U32 startVertex,
U32 minIndex,
U32 numVerts,
U32 startIndex,
U32 primitiveCount );
virtual void setClipRect( const RectI &rect );
virtual const RectI &getClipRect() const { return mClip; }
virtual void preDestroy() { Parent::preDestroy(); }
virtual U32 getMaxDynamicVerts() { return MAX_DYNAMIC_VERTS; }
virtual U32 getMaxDynamicIndices() { return MAX_DYNAMIC_INDICES; }
GFXFence *createFence();
GFXOcclusionQuery* createOcclusionQuery();
GFXGLStateBlockRef getCurrentStateBlock() { return mCurrentGLStateBlock; }
virtual void setupGenericShaders( GenericShaderType type = GSColor );
///
bool supportsAnisotropic() const { return mSupportsAnisotropic; }
protected:
/// Called by GFXDevice to create a device specific stateblock
virtual GFXStateBlockRef createStateBlockInternal(const GFXStateBlockDesc& desc);
/// Called by GFXDevice to actually set a stateblock.
virtual void setStateBlockInternal(GFXStateBlock* block, bool force);
/// Called by base GFXDevice to actually set a const buffer
virtual void setShaderConstBufferInternal(GFXShaderConstBuffer* buffer);
virtual void setTextureInternal(U32 textureUnit, const GFXTextureObject*texture);
virtual void setCubemapInternal(U32 cubemap, const GFXGLCubemap* texture);
virtual void setLightInternal(U32 lightStage, const GFXLightInfo light, bool lightEnable);
virtual void setLightMaterialInternal(const GFXLightMaterial mat);
virtual void setGlobalAmbientInternal(ColorF color);
/// @name State Initalization.
/// @{
/// State initalization. This MUST BE CALLED in setVideoMode after the device
/// is created.
virtual void initStates() { }
virtual void setMatrix( GFXMatrixType mtype, const MatrixF &mat );
virtual GFXVertexBuffer *allocVertexBuffer( U32 numVerts,
const GFXVertexFormat *vertexFormat,
U32 vertSize,
GFXBufferType bufferType );
virtual GFXPrimitiveBuffer *allocPrimitiveBuffer( U32 numIndices, U32 numPrimitives, GFXBufferType bufferType );
// NOTE: The GL device doesn't need a vertex declaration at
// this time, but we need to return something to keep the system
// from retrying to allocate one on every call.
virtual GFXVertexDecl* allocVertexDecl( const GFXVertexFormat *vertexFormat )
{
static GFXVertexDecl decl;
return &decl;
}
virtual void setVertexDecl( const GFXVertexDecl *decl ) { }
virtual void setVertexStream( U32 stream, GFXVertexBuffer *buffer );
virtual void setVertexStreamFrequency( U32 stream, U32 frequency );
private:
typedef GFXDevice Parent;
friend class GFXGLTextureObject;
friend class GFXGLCubemap;
friend class GFXGLWindowTarget;
friend class GFXGLPrimitiveBuffer;
friend class GFXGLVertexBuffer;
static GFXAdapter::CreateDeviceInstanceDelegate mCreateDeviceInstance;
U32 mAdapterIndex;
StrongRefPtr<GFXGLVertexBuffer> mCurrentVB;
StrongRefPtr<GFXGLPrimitiveBuffer> mCurrentPB;
/// Since GL does not have separate world and view matrices we need to track them
MatrixF m_mCurrentWorld;
MatrixF m_mCurrentView;
void* mContext;
void* mPixelFormat;
F32 mPixelShaderVersion;
bool mSupportsAnisotropic;
U32 mMaxShaderTextures;
U32 mMaxFFTextures;
RectI mClip;
GFXGLStateBlockRef mCurrentGLStateBlock;
GLenum mActiveTextureType[TEXTURE_STAGE_COUNT];
Vector< StrongRefPtr<GFXGLVertexBuffer> > mVolatileVBs; ///< Pool of existing volatile VBs so we can reuse previously created ones
Vector< StrongRefPtr<GFXGLPrimitiveBuffer> > mVolatilePBs; ///< Pool of existing volatile PBs so we can reuse previously created ones
GLsizei primCountToIndexCount(GFXPrimitiveType primType, U32 primitiveCount);
void preDrawPrimitive();
void postDrawPrimitive(U32 primitiveCount);
GFXVertexBuffer* findVolatileVBO(U32 numVerts, const GFXVertexFormat *vertexFormat, U32 vertSize); ///< Returns an existing volatile VB which has >= numVerts and the same vert flags/size, or creates a new VB if necessary
GFXPrimitiveBuffer* findVolatilePBO(U32 numIndices, U32 numPrimitives); ///< Returns an existing volatile PB which has >= numIndices, or creates a new PB if necessary
void initGLState(); ///< Guaranteed to be called after all extensions have been loaded, use to init card profiler, shader version, max samplers, etc.
GFXFence* _createPlatformSpecificFence(); ///< If our platform (e.g. OS X) supports a fence extenstion (e.g. GL_APPLE_fence) this will create one, otherwise returns NULL
void setPB(GFXGLPrimitiveBuffer* pb); ///< Sets mCurrentPB
};
#endif

View file

@ -0,0 +1,357 @@
//-----------------------------------------------------------------------------
// Copyright (c) 2012 GarageGames, LLC
//
// Permission is hereby granted, free of charge, to any person obtaining a copy
// of this software and associated documentation files (the "Software"), to
// deal in the Software without restriction, including without limitation the
// rights to use, copy, modify, merge, publish, distribute, sublicense, and/or
// sell copies of the Software, and to permit persons to whom the Software is
// furnished to do so, subject to the following conditions:
//
// The above copyright notice and this permission notice shall be included in
// all copies or substantial portions of the Software.
//
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
// FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS
// IN THE SOFTWARE.
//-----------------------------------------------------------------------------
// Don't include Apple's GL header
#define __gl_h_
// Include our GL header before Apple headers.
#include "gfx/gl/ggl/ggl.h"
#include "platform/tmm_off.h"
#include <Cocoa/Cocoa.h>
#include <OpenGL/OpenGL.h>
#include "gfx/gl/gfxGLDevice.h"
#include "platform/tmm_on.h"
#include "gfx/gl/gfxGLTextureTarget.h"
#include "gfx/gl/gfxGLCardProfiler.h"
#include "gfx/gl/gfxGLAppleFence.h"
#include "gfx/gl/gfxGLWindowTarget.h"
#include "platformMac/macGLUtils.h"
#include "windowManager/mac/macWindow.h"
extern void loadGLCore();
extern void loadGLExtensions(void* context);
static String _getRendererForDisplay(CGDirectDisplayID display)
{
Vector<NSOpenGLPixelFormatAttribute> attributes = _createStandardPixelFormatAttributesForDisplay(display);
NSOpenGLPixelFormat* fmt = [[NSOpenGLPixelFormat alloc] initWithAttributes:attributes.address()];
AssertFatal(fmt, "_getRendererForDisplay - Unable to create a pixel format object");
NSOpenGLContext* ctx = [[NSOpenGLContext alloc] initWithFormat:fmt shareContext:nil];
AssertFatal(ctx, "_getRendererForDisplay - Unable to create an OpenGL context");
// Save the current context, just in case
NSOpenGLContext* currCtx = [NSOpenGLContext currentContext];
[ctx makeCurrentContext];
// CodeReview [ags 12/19/07] This is a hack. We should call loadGLCore somewhere else, before we reach here.
// On Macs we can safely assume access to the OpenGL framework at anytime, perhaps this should go in main()?
loadGLCore();
// get the renderer string
String ret((const char*)glGetString(GL_RENDERER));
// Restore our old context, release the context and pixel format.
[currCtx makeCurrentContext];
[ctx release];
[fmt release];
return ret;
}
static void _createInitialContextAndFormat(void* &ctx, void* &fmt)
{
AssertFatal(!fmt && !ctx, "_createInitialContextAndFormat - Already created initial context and format");
fmt = _createStandardPixelFormat();
AssertFatal(fmt, "_createInitialContextAndFormat - Unable to create an OpenGL pixel format");
ctx = [[NSOpenGLContext alloc] initWithFormat: (NSOpenGLPixelFormat*)fmt shareContext: nil];
AssertFatal(ctx, "_createInitialContextAndFormat - Unable to create an OpenGL context");
}
static NSOpenGLContext* _createContextForWindow(PlatformWindow *window, void* &context, void* &pixelFormat)
{
NSOpenGLView* view = (NSOpenGLView*)window->getPlatformDrawable();
AssertFatal([view isKindOfClass:[NSOpenGLView class]], avar("_createContextForWindow - Supplied a %s instead of a NSOpenGLView", [[view className] UTF8String]));
NSOpenGLContext* ctx = NULL;
if(!context || !pixelFormat)
{
// Create the initial opengl context that the device and the first window will hold.
_createInitialContextAndFormat(context, pixelFormat);
ctx = (NSOpenGLContext*)context;
}
else
{
// Create a context which shares its resources with the device's initial context
ctx = [[NSOpenGLContext alloc] initWithFormat: (NSOpenGLPixelFormat*)pixelFormat shareContext: (NSOpenGLContext*)context];
AssertFatal(ctx, "Unable to create a shared OpenGL context");
}
[view setPixelFormat: (NSOpenGLPixelFormat*)pixelFormat];
[view setOpenGLContext: ctx];
return ctx;
}
void GFXGLDevice::init( const GFXVideoMode &mode, PlatformWindow *window )
{
if(mInitialized)
return;
NSOpenGLContext* ctx = _createContextForWindow(window, mContext, mPixelFormat);
[ctx makeCurrentContext];
loadGLCore();
loadGLExtensions(ctx);
initGLState();
mInitialized = true;
deviceInited();
}
void GFXGLDevice::enumerateAdapters( Vector<GFXAdapter*> &adapterList )
{
GFXAdapter *toAdd;
Vector<GFXVideoMode> videoModes;
CGDirectDisplayID display = CGMainDisplayID();
// Enumerate all available resolutions:
NSArray* modeArray = (NSArray*)CGDisplayAvailableModes(display);
GFXVideoMode vmAdd;
NSEnumerator* enumerator = [modeArray objectEnumerator];
NSDictionary* mode;
while((mode = [enumerator nextObject]))
{
vmAdd.resolution.x = [[mode valueForKey:@"Width"] intValue];
vmAdd.resolution.y = [[mode valueForKey:@"Height"] intValue];
vmAdd.bitDepth = [[mode valueForKey:@"BitsPerPixel"] intValue];
vmAdd.refreshRate = [[mode valueForKey:@"RefreshRate"] intValue];
vmAdd.fullScreen = false;
// skip if mode claims to be 8bpp
if( vmAdd.bitDepth == 8 )
continue;
// Only add this resolution if it is not already in the list:
bool alreadyInList = false;
for(Vector<GFXVideoMode>::iterator i = videoModes.begin(); i != videoModes.end(); i++)
{
if(vmAdd == *i)
{
alreadyInList = true;
break;
}
}
if( !alreadyInList )
{
videoModes.push_back( vmAdd );
}
}
// Get number of displays
CGDisplayCount dispCnt;
CGGetActiveDisplayList(0, NULL, &dispCnt);
// Take advantage of GNU-C
CGDirectDisplayID displays[dispCnt];
CGGetActiveDisplayList(dispCnt, displays, &dispCnt);
for(U32 i = 0; i < dispCnt; i++)
{
toAdd = new GFXAdapter();
toAdd->mType = OpenGL;
toAdd->mIndex = (U32)displays[i];
toAdd->mCreateDeviceInstanceDelegate = mCreateDeviceInstance;
String renderer = _getRendererForDisplay(displays[i]);
AssertFatal(dStrlen(renderer.c_str()) < GFXAdapter::MaxAdapterNameLen, "GFXGLDevice::enumerateAdapter - renderer name too long, increae the size of GFXAdapter::MaxAdapterNameLen (or use String!)");
dStrncpy(toAdd->mName, renderer.c_str(), GFXAdapter::MaxAdapterNameLen);
adapterList.push_back(toAdd);
for (S32 j = videoModes.size() - 1 ; j >= 0 ; j--)
toAdd->mAvailableModes.push_back(videoModes[j]);
}
}
void GFXGLDevice::enumerateVideoModes()
{
mVideoModes.clear();
CGDirectDisplayID display = CGMainDisplayID();
// Enumerate all available resolutions:
NSArray* modeArray = (NSArray*)CGDisplayAvailableModes(display);
GFXVideoMode toAdd;
NSEnumerator* enumerator = [modeArray objectEnumerator];
NSDictionary* mode;
while((mode = [enumerator nextObject]))
{
toAdd.resolution.x = [[mode valueForKey:@"Width"] intValue];
toAdd.resolution.y = [[mode valueForKey:@"Height"] intValue];
toAdd.bitDepth = [[mode valueForKey:@"BitsPerPixel"] intValue];
toAdd.refreshRate = [[mode valueForKey:@"RefreshRate"] intValue];
toAdd.fullScreen = false;
// skip if mode claims to be 8bpp
if( toAdd.bitDepth == 8 )
continue;
// Only add this resolution if it is not already in the list:
bool alreadyInList = false;
for(Vector<GFXVideoMode>::iterator i = mVideoModes.begin(); i != mVideoModes.end(); i++)
{
if(toAdd == *i)
{
alreadyInList = true;
break;
}
}
if( !alreadyInList )
{
mVideoModes.push_back( toAdd );
}
}
}
bool GFXGLDevice::beginSceneInternal()
{
// Nothing to do here for GL.
mCanCurrentlyRender = true;
return true;
}
U32 GFXGLDevice::getTotalVideoMemory()
{
// Convert our adapterIndex (i.e. our CGDirectDisplayID) into an OpenGL display mask
GLuint display = CGDisplayIDToOpenGLDisplayMask((CGDirectDisplayID)mAdapterIndex);
CGLRendererInfoObj rend;
#if MAC_OS_X_VERSION_MIN_REQUIRED >= MAC_OS_X_VERSION_10_5
GLint nrend;
#else
long int nrend;
#endif
CGLQueryRendererInfo(display, &rend, &nrend);
if(!nrend)
return 0;
#if MAC_OS_X_VERSION_MIN_REQUIRED >= MAC_OS_X_VERSION_10_5
GLint vidMem;
#else
long int vidMem;
#endif
CGLDescribeRenderer(rend, 0, kCGLRPVideoMemory, &vidMem);
CGLDestroyRendererInfo(rend);
// convert bytes to MB
vidMem /= (1024 * 1024);
return vidMem;
}
//-----------------------------------------------------------------------------
GFXWindowTarget *GFXGLDevice::allocWindowTarget(PlatformWindow *window)
{
void *ctx = NULL;
// Init if needed, or create a new context
if(!mInitialized)
init(window->getVideoMode(), window);
else
ctx = _createContextForWindow(window, mContext, mPixelFormat);
// Allocate the wintarget and create a new context.
GFXGLWindowTarget *gwt = new GFXGLWindowTarget(window, this);
gwt->mContext = ctx ? ctx : mContext;
// And return...
return gwt;
}
GFXFence* GFXGLDevice::_createPlatformSpecificFence()
{
if(!mCardProfiler->queryProfile("GL::APPLE::suppFence"))
return NULL;
return new GFXGLAppleFence(this);
}
void GFXGLWindowTarget::makeActive()
{
// If we're supposed to be running fullscreen, but haven't yet set up for it,
// do it now.
if( !mFullscreenContext && mWindow->getVideoMode().fullScreen )
{
static_cast< GFXGLDevice* >( mDevice )->zombify();
_setupNewMode();
}
mFullscreenContext ? [(NSOpenGLContext*)mFullscreenContext makeCurrentContext] : [(NSOpenGLContext*)mContext makeCurrentContext];
}
bool GFXGLWindowTarget::present()
{
GFX->updateStates();
mFullscreenContext ? [(NSOpenGLContext*)mFullscreenContext flushBuffer] : [(NSOpenGLContext*)mContext flushBuffer];
return true;
}
void GFXGLWindowTarget::_teardownCurrentMode()
{
GFX->setActiveRenderTarget(this);
static_cast<GFXGLDevice*>(mDevice)->zombify();
if(mFullscreenContext)
{
[NSOpenGLContext clearCurrentContext];
[(NSOpenGLContext*)mFullscreenContext clearDrawable];
}
}
void GFXGLWindowTarget::_setupNewMode()
{
if(mWindow->getVideoMode().fullScreen && !mFullscreenContext)
{
// We have to create a fullscreen context.
Vector<NSOpenGLPixelFormatAttribute> attributes = _beginPixelFormatAttributesForDisplay(static_cast<MacWindow*>(mWindow)->getDisplay());
_addColorAlphaDepthStencilAttributes(attributes, 24, 8, 24, 8);
_addFullscreenAttributes(attributes);
_endAttributeList(attributes);
NSOpenGLPixelFormat* fmt = [[NSOpenGLPixelFormat alloc] initWithAttributes:attributes.address()];
mFullscreenContext = [[NSOpenGLContext alloc] initWithFormat:fmt shareContext:nil];
[fmt release];
[(NSOpenGLContext*)mFullscreenContext setFullScreen];
[(NSOpenGLContext*)mFullscreenContext makeCurrentContext];
// Restore resources in new context
static_cast<GFXGLDevice*>(mDevice)->resurrect();
GFX->updateStates(true);
}
else if(!mWindow->getVideoMode().fullScreen && mFullscreenContext)
{
[(NSOpenGLContext*)mFullscreenContext release];
mFullscreenContext = NULL;
[(NSOpenGLContext*)mContext makeCurrentContext];
GFX->clear(GFXClearTarget | GFXClearZBuffer | GFXClearStencil, ColorI(0, 0, 0), 1.0f, 0);
static_cast<GFXGLDevice*>(mDevice)->resurrect();
GFX->updateStates(true);
}
}

View file

@ -0,0 +1,403 @@
//-----------------------------------------------------------------------------
// Copyright (c) 2012 GarageGames, LLC
//
// Permission is hereby granted, free of charge, to any person obtaining a copy
// of this software and associated documentation files (the "Software"), to
// deal in the Software without restriction, including without limitation the
// rights to use, copy, modify, merge, publish, distribute, sublicense, and/or
// sell copies of the Software, and to permit persons to whom the Software is
// furnished to do so, subject to the following conditions:
//
// The above copyright notice and this permission notice shall be included in
// all copies or substantial portions of the Software.
//
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
// FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS
// IN THE SOFTWARE.
//-----------------------------------------------------------------------------
#include "platformWin32/platformWin32.h"
#include "gfx/gfxCubemap.h"
#include "gfx/screenshot.h"
#include "gfx/GL/gfxGLDevice.h"
#include "gfx/GL/gfxGLEnumTranslate.h"
#include "gfx/GL/gfxGLVertexBuffer.h"
#include "gfx/GL/gfxGLPrimitiveBuffer.h"
#include "gfx/gl/gfxGLTextureTarget.h"
#include "gfx/GL/gfxGLWindowTarget.h"
#include "gfx/GL/gfxGLTextureManager.h"
#include "gfx/GL/gfxGLTextureObject.h"
#include "gfx/GL/gfxGLCubemap.h"
#include "gfx/GL/gfxGLCardProfiler.h"
#include "windowManager/win32/win32Window.h"
#include "ggl/Win32/wgl.h"
#define GETHWND(x) static_cast<Win32Window*>(x)->getHWND()
// yonked from winWindow.cc
void CreatePixelFormat( PIXELFORMATDESCRIPTOR *pPFD, S32 colorBits, S32 depthBits, S32 stencilBits, bool stereo )
{
PIXELFORMATDESCRIPTOR src =
{
sizeof(PIXELFORMATDESCRIPTOR), // size of this pfd
1, // version number
PFD_DRAW_TO_WINDOW | // support window
PFD_SUPPORT_OPENGL | // support OpenGL
PFD_DOUBLEBUFFER, // double buffered
PFD_TYPE_RGBA, // RGBA type
colorBits, // color depth
0, 0, 0, 0, 0, 0, // color bits ignored
0, // no alpha buffer
0, // shift bit ignored
0, // no accumulation buffer
0, 0, 0, 0, // accum bits ignored
depthBits, // z-buffer
stencilBits, // stencil buffer
0, // no auxiliary buffer
PFD_MAIN_PLANE, // main layer
0, // reserved
0, 0, 0 // layer masks ignored
};
if ( stereo )
{
//ri.Printf( PRINT_ALL, "...attempting to use stereo\n" );
src.dwFlags |= PFD_STEREO;
//glConfig.stereoEnabled = true;
}
else
{
//glConfig.stereoEnabled = qfalse;
}
*pPFD = src;
}
extern void loadGLCore();
extern void loadGLExtensions(void* context);
void GFXGLDevice::enumerateAdapters( Vector<GFXAdapter*> &adapterList )
{
// GL_ERROR_CHECK();
WNDCLASS windowclass;
dMemset( &windowclass, 0, sizeof( WNDCLASS ) );
windowclass.lpszClassName = L"GFX-OpenGL";
windowclass.style = CS_OWNDC;
windowclass.lpfnWndProc = DefWindowProc;
windowclass.hInstance = winState.appInstance;
if( !RegisterClass( &windowclass ) )
AssertFatal( false, "Failed to register the window class for the GL test window." );
// Now create a window
HWND hwnd = CreateWindow( L"GFX-OpenGL", L"", WS_POPUP, 0, 0, 640, 480,
NULL, NULL, winState.appInstance, NULL );
AssertFatal( hwnd != NULL, "Failed to create the window for the GL test window." );
// Create a device context
HDC tempDC = GetDC( hwnd );
AssertFatal( tempDC != NULL, "Failed to create device context" );
// Create pixel format descriptor...
PIXELFORMATDESCRIPTOR pfd;
CreatePixelFormat( &pfd, 16, 16, 8, false ); // 16 bit color, 16 bit depth, 8 bit stencil...everyone can do this
if( !SetPixelFormat( tempDC, ChoosePixelFormat( tempDC, &pfd ), &pfd ) )
AssertFatal( false, "I don't know who's responcible for this, but I want caught..." );
// Create a rendering context!
HGLRC tempGLRC = wglCreateContext( tempDC );
if( !wglMakeCurrent( tempDC, tempGLRC ) )
AssertFatal( false, "I want them caught and killed." );
// Add the GL renderer
loadGLCore();
loadGLExtensions(tempDC);
GFXAdapter *toAdd = new GFXAdapter;
toAdd->mIndex = 0;
const char* renderer = (const char*) glGetString( GL_RENDERER );
AssertFatal( renderer != NULL, "GL_RENDERER returned NULL!" );
if (renderer)
{
dStrcpy(toAdd->mName, renderer);
dStrncat(toAdd->mName, " OpenGL", GFXAdapter::MaxAdapterNameLen);
}
else
dStrcpy(toAdd->mName, "OpenGL");
toAdd->mType = OpenGL;
toAdd->mShaderModel = 0.f;
toAdd->mCreateDeviceInstanceDelegate = mCreateDeviceInstance;
// Enumerate all available resolutions:
DEVMODE devMode;
U32 modeNum = 0;
U32 stillGoing = true;
while ( stillGoing )
{
dMemset( &devMode, 0, sizeof( devMode ) );
devMode.dmSize = sizeof( devMode );
stillGoing = EnumDisplaySettings( NULL, modeNum++, &devMode );
if (( devMode.dmPelsWidth >= 480) && (devMode.dmPelsHeight >= 360 )
&& ( devMode.dmBitsPerPel == 16 || devMode.dmBitsPerPel == 32 ))
{
GFXVideoMode vmAdd;
vmAdd.bitDepth = devMode.dmBitsPerPel;
vmAdd.fullScreen = true;
vmAdd.refreshRate = devMode.dmDisplayFrequency;
vmAdd.resolution.x = devMode.dmPelsWidth;
vmAdd.resolution.y = devMode.dmPelsHeight;
// Only add this resolution if it is not already in the list:
bool alreadyInList = false;
for (Vector<GFXVideoMode>::iterator i = toAdd->mAvailableModes.begin(); i != toAdd->mAvailableModes.end(); i++)
{
if (vmAdd == *i)
{
alreadyInList = true;
break;
}
}
if(alreadyInList)
continue;
toAdd->mAvailableModes.push_back( vmAdd );
}
}
// Add to the list of available adapters.
adapterList.push_back(toAdd);
// Cleanup our window
wglMakeCurrent(NULL, NULL);
wglDeleteContext(tempGLRC);
ReleaseDC(hwnd, tempDC);
DestroyWindow(hwnd);
UnregisterClass(L"GFX-OpenGL", winState.appInstance);
}
void GFXGLDevice::enumerateVideoModes()
{
mVideoModes.clear();
// Enumerate all available resolutions:
DEVMODE devMode;
U32 modeNum = 0;
U32 stillGoing = true;
while ( stillGoing )
{
dMemset( &devMode, 0, sizeof( devMode ) );
devMode.dmSize = sizeof( devMode );
stillGoing = EnumDisplaySettings( NULL, modeNum++, &devMode );
if (( devMode.dmPelsWidth >= 480) && (devMode.dmPelsHeight >= 360 )
&& ( devMode.dmBitsPerPel == 16 || devMode.dmBitsPerPel == 32 ))
//( smCanSwitchBitDepth || devMode.dmBitsPerPel == winState.desktopBitsPixel ) )
{
GFXVideoMode toAdd;
toAdd.bitDepth = devMode.dmBitsPerPel;
toAdd.fullScreen = false;
toAdd.refreshRate = devMode.dmDisplayFrequency;
toAdd.resolution.x = devMode.dmPelsWidth;
toAdd.resolution.y = devMode.dmPelsHeight;
// Only add this resolution if it is not already in the list:
bool alreadyInList = false;
for (Vector<GFXVideoMode>::iterator i = mVideoModes.begin(); i != mVideoModes.end(); i++)
{
if (toAdd == *i)
{
alreadyInList = true;
break;
}
}
if ( !alreadyInList )
{
//Con::printf("Resolution: %dx%d %d bpp %d Refresh rate: %d", toAdd.resolution.x, toAdd.resolution.y, toAdd.bitDepth, toAdd.refreshRate);
mVideoModes.push_back( toAdd );
}
}
}
}
void GFXGLDevice::init( const GFXVideoMode &mode, PlatformWindow *window )
{
AssertFatal(window, "GFXGLDevice::init - no window specified, can't init device without a window!");
AssertFatal(dynamic_cast<Win32Window*>(window), "Invalid window class type!");
HWND hwnd = GETHWND(window);
RECT rect;
GetClientRect(hwnd, &rect);
Point2I resolution;
resolution.x = rect.right - rect.left;
resolution.y = rect.bottom - rect.top;
// Create a device context
HDC hdcGL = GetDC( hwnd );
AssertFatal( hdcGL != NULL, "Failed to create device context" );
// Create pixel format descriptor...
PIXELFORMATDESCRIPTOR pfd;
CreatePixelFormat( &pfd, 16, 16, 8, false ); // 16 bit color, 16 bit depth, 8 bit stencil...everyone can do this
if( !SetPixelFormat( hdcGL, ChoosePixelFormat( hdcGL, &pfd ), &pfd ) )
{
AssertFatal( false, "GFXGLDevice::init - cannot get the one and only pixel format we check for." );
}
// Create a rendering context!
mContext = wglCreateContext( hdcGL );
if( !wglMakeCurrent( hdcGL, (HGLRC)mContext ) )
AssertFatal( false , "GFXGLDevice::init - cannot make our context current. Or maybe we can't create it." );
loadGLCore();
loadGLExtensions(hdcGL);
wglSwapIntervalEXT(0);
// It is very important that extensions be loaded
// before we call initGLState()
initGLState();
mProjectionMatrix.identity();
mInitialized = true;
deviceInited();
}
bool GFXGLDevice::beginSceneInternal()
{
glGetError();
return true;
}
U32 GFXGLDevice::getTotalVideoMemory()
{
// CodeReview [ags 12/21/07] Figure out how to do this.
return 0;
}
//------------------------------------------------------------------------------
GFXWindowTarget *GFXGLDevice::allocWindowTarget( PlatformWindow *window )
{
HDC hdcGL = GetDC(GETHWND(window));
if(!mContext)
{
init(window->getVideoMode(), window);
GFXGLWindowTarget *ggwt = new GFXGLWindowTarget(window, this);
ggwt->registerResourceWithDevice(this);
ggwt->mContext = wglCreateContext(hdcGL);
AssertFatal(ggwt->mContext, "GFXGLDevice::allocWindowTarget - failed to allocate window target!");
return ggwt;
}
GFXGLWindowTarget *ggwt = new GFXGLWindowTarget(window, this);
ggwt->registerResourceWithDevice(this);
// Create pixel format descriptor...
PIXELFORMATDESCRIPTOR pfd;
CreatePixelFormat( &pfd, 16, 16, 8, false ); // 16 bit color, 16 bit depth, 8 bit stencil...everyone can do this
if( !SetPixelFormat( hdcGL, ChoosePixelFormat( hdcGL, &pfd ), &pfd ) )
{
AssertFatal( false, "GFXGLDevice::allocWindowTarget - cannot get the one and only pixel format we check for." );
}
ggwt->mContext = wglCreateContext(hdcGL);
DWORD w = GetLastError();
AssertFatal(ggwt->mContext, "GFXGLDevice::allocWindowTarget - failed to allocate window target!");
wglMakeCurrent(NULL, NULL);
bool res = wglShareLists((HGLRC)mContext, (HGLRC)ggwt->mContext);
w = GetLastError();
wglMakeCurrent(hdcGL, (HGLRC)ggwt->mContext);
AssertFatal(res, "GFXGLDevice::allocWindowTarget - wasn't able to share contexts!");
return ggwt;
}
void GFXGLDevice::_updateRenderTargets()
{
if ( mRTDirty || mCurrentRT->isPendingState() )
{
// GL doesn't need to deactivate targets.
mRTDeactivate = NULL;
// NOTE: The render target changes is not really accurate
// as the GFXTextureTarget supports MRT internally. So when
// we activate a GFXTarget it could result in multiple calls
// to SetRenderTarget on the actual device.
mDeviceStatistics.mRenderTargetChanges++;
GFXGLTextureTarget *tex = dynamic_cast<GFXGLTextureTarget*>( mCurrentRT.getPointer() );
if ( tex )
{
tex->applyState();
tex->makeActive();
}
else
{
GFXGLWindowTarget *win = dynamic_cast<GFXGLWindowTarget*>( mCurrentRT.getPointer() );
AssertFatal( win != NULL,
"GFXGLDevice::_updateRenderTargets() - invalid target subclass passed!" );
//DWORD w1 = GetLastError();
HWND hwnd = GETHWND(win->getWindow());
HDC winDc = GetDC(hwnd);
bool res = wglMakeCurrent(winDc,(HGLRC)win->mContext);
//DWORD w2 = GetLastError();
AssertFatal(res==true,"GFXGLDevice::setActiveRenderTarget - failed");
}
mRTDirty = false;
}
if ( mViewportDirty )
{
glViewport( mViewport.point.x, mViewport.point.y, mViewport.extent.x, mViewport.extent.y );
mViewportDirty = false;
}
}
GFXFence* GFXGLDevice::_createPlatformSpecificFence()
{
return NULL;
}
//-----------------------------------------------------------------------------
void GFXGLWindowTarget::makeActive()
{
}
bool GFXGLWindowTarget::present()
{
HWND hwnd = GETHWND(getWindow());
SwapBuffers(GetDC(hwnd));
return true;
}
void GFXGLWindowTarget::_teardownCurrentMode()
{
}
void GFXGLWindowTarget::_setupNewMode()
{
}

View file

@ -0,0 +1,211 @@
//-----------------------------------------------------------------------------
// Copyright (c) 2012 GarageGames, LLC
//
// Permission is hereby granted, free of charge, to any person obtaining a copy
// of this software and associated documentation files (the "Software"), to
// deal in the Software without restriction, including without limitation the
// rights to use, copy, modify, merge, publish, distribute, sublicense, and/or
// sell copies of the Software, and to permit persons to whom the Software is
// furnished to do so, subject to the following conditions:
//
// The above copyright notice and this permission notice shall be included in
// all copies or substantial portions of the Software.
//
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
// FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS
// IN THE SOFTWARE.
//-----------------------------------------------------------------------------
#include "platform/platform.h"
#include "gfx/gl/gfxGLEnumTranslate.h"
GLenum GFXGLPrimType[GFXPT_COUNT];
GLenum GFXGLBlend[GFXBlend_COUNT];
GLenum GFXGLBlendOp[GFXBlendOp_COUNT];
GLenum GFXGLSamplerState[GFXSAMP_COUNT];
GLenum GFXGLTextureFilter[GFXTextureFilter_COUNT];
GLenum GFXGLTextureAddress[GFXAddress_COUNT];
GLenum GFXGLCmpFunc[GFXCmp_COUNT];
GLenum GFXGLStencilOp[GFXStencilOp_COUNT];
GLenum GFXGLTextureInternalFormat[GFXFormat_COUNT];
GLenum GFXGLTextureFormat[GFXFormat_COUNT];
GLenum GFXGLTextureType[GFXFormat_COUNT];
GLenum GFXGLBufferType[GFXBufferType_COUNT];
GLenum GFXGLCullMode[GFXCull_COUNT];
GLenum GFXGLFillMode[GFXFill_COUNT];
void GFXGLEnumTranslate::init()
{
// Buffer types
GFXGLBufferType[GFXBufferTypeStatic] = GL_STATIC_DRAW;
GFXGLBufferType[GFXBufferTypeDynamic] = GL_DYNAMIC_DRAW;
GFXGLBufferType[GFXBufferTypeVolatile] = GL_STREAM_DRAW;
// Primitives
GFXGLPrimType[GFXPointList] = GL_POINTS;
GFXGLPrimType[GFXLineList] = GL_LINES;
GFXGLPrimType[GFXLineStrip] = GL_LINE_STRIP;
GFXGLPrimType[GFXTriangleList] = GL_TRIANGLES;
GFXGLPrimType[GFXTriangleStrip] = GL_TRIANGLE_STRIP;
GFXGLPrimType[GFXTriangleFan] = GL_TRIANGLE_FAN;
// Blend
GFXGLBlend[GFXBlendZero] = GL_ZERO;
GFXGLBlend[GFXBlendOne] = GL_ONE;
GFXGLBlend[GFXBlendSrcColor] = GL_SRC_COLOR;
GFXGLBlend[GFXBlendInvSrcColor] = GL_ONE_MINUS_SRC_COLOR;
GFXGLBlend[GFXBlendSrcAlpha] = GL_SRC_ALPHA;
GFXGLBlend[GFXBlendInvSrcAlpha] = GL_ONE_MINUS_SRC_ALPHA;
GFXGLBlend[GFXBlendDestAlpha] = GL_DST_ALPHA;
GFXGLBlend[GFXBlendInvDestAlpha] = GL_ONE_MINUS_DST_ALPHA;
GFXGLBlend[GFXBlendDestColor] = GL_DST_COLOR;
GFXGLBlend[GFXBlendInvDestColor] = GL_ONE_MINUS_DST_COLOR;
GFXGLBlend[GFXBlendSrcAlphaSat] = GL_SRC_ALPHA_SATURATE;
// Blend op
GFXGLBlendOp[GFXBlendOpAdd] = GL_FUNC_ADD;
GFXGLBlendOp[GFXBlendOpSubtract] = GL_FUNC_SUBTRACT;
GFXGLBlendOp[GFXBlendOpRevSubtract] = GL_FUNC_REVERSE_SUBTRACT;
GFXGLBlendOp[GFXBlendOpMin] = GL_MIN;
GFXGLBlendOp[GFXBlendOpMax] = GL_MAX;
// Sampler
GFXGLSamplerState[GFXSAMPMagFilter] = GL_TEXTURE_MAG_FILTER;
GFXGLSamplerState[GFXSAMPMinFilter] = GL_TEXTURE_MIN_FILTER;
GFXGLSamplerState[GFXSAMPAddressU] = GL_TEXTURE_WRAP_S;
GFXGLSamplerState[GFXSAMPAddressV] = GL_TEXTURE_WRAP_T;
GFXGLSamplerState[GFXSAMPAddressW] = GL_TEXTURE_WRAP_R;
GFXGLSamplerState[GFXSAMPMipMapLODBias] = GL_TEXTURE_LOD_BIAS;
// Comparison
GFXGLCmpFunc[GFXCmpNever] = GL_NEVER;
GFXGLCmpFunc[GFXCmpLess] = GL_LESS;
GFXGLCmpFunc[GFXCmpEqual] = GL_EQUAL;
GFXGLCmpFunc[GFXCmpLessEqual] = GL_LEQUAL;
GFXGLCmpFunc[GFXCmpGreater] = GL_GREATER;
GFXGLCmpFunc[GFXCmpNotEqual] = GL_NOTEQUAL;
GFXGLCmpFunc[GFXCmpGreaterEqual] = GL_GEQUAL;
GFXGLCmpFunc[GFXCmpAlways] = GL_ALWAYS;
GFXGLTextureFilter[GFXTextureFilterNone] = GL_NEAREST;
GFXGLTextureFilter[GFXTextureFilterPoint] = GL_NEAREST;
GFXGLTextureFilter[GFXTextureFilterLinear] = GL_LINEAR;
GFXGLTextureFilter[GFXTextureFilterAnisotropic] = GL_LINEAR;
GFXGLTextureFilter[GFXTextureFilterPyramidalQuad] = GL_LINEAR;
GFXGLTextureFilter[GFXTextureFilterGaussianQuad] = GL_LINEAR;
GFXGLTextureAddress[GFXAddressWrap] = GL_REPEAT;
GFXGLTextureAddress[GFXAddressMirror] = GL_REPEAT;
GFXGLTextureAddress[GFXAddressClamp] = GL_CLAMP_TO_EDGE;
GFXGLTextureAddress[GFXAddressBorder] = GL_REPEAT;
GFXGLTextureAddress[GFXAddressMirrorOnce] = GL_REPEAT;
// Stencil ops
GFXGLStencilOp[GFXStencilOpKeep] = GL_KEEP;
GFXGLStencilOp[GFXStencilOpZero] = GL_ZERO;
GFXGLStencilOp[GFXStencilOpReplace] = GL_REPLACE;
GFXGLStencilOp[GFXStencilOpIncrSat] = GL_INCR;
GFXGLStencilOp[GFXStencilOpDecrSat] = GL_DECR;
GFXGLStencilOp[GFXStencilOpInvert] = GL_INVERT;
GFXGLStencilOp[GFXStencilOpIncr] = GL_INCR_WRAP;
GFXGLStencilOp[GFXStencilOpDecr] = GL_DECR_WRAP;
// Texture formats
GFXGLTextureInternalFormat[GFXFormatA8] = GL_ALPHA8;
GFXGLTextureInternalFormat[GFXFormatL8] = GL_LUMINANCE8;
GFXGLTextureInternalFormat[GFXFormatR5G6B5] = GL_RGB5_A1; // OpenGL has no R5G6B5 format.
GFXGLTextureInternalFormat[GFXFormatR5G5B5A1] = GL_RGB5_A1;
GFXGLTextureInternalFormat[GFXFormatR5G5B5X1] = GL_RGB5_A1;
GFXGLTextureInternalFormat[GFXFormatL16] = GL_LUMINANCE16;
GFXGLTextureInternalFormat[GFXFormatR16F] = GL_ZERO;
GFXGLTextureInternalFormat[GFXFormatD16] = GL_DEPTH_COMPONENT;
GFXGLTextureInternalFormat[GFXFormatR8G8B8] = GL_RGB8;
GFXGLTextureInternalFormat[GFXFormatR8G8B8A8] = GL_RGBA8;
GFXGLTextureInternalFormat[GFXFormatR8G8B8X8] = GL_RGBA8;
GFXGLTextureInternalFormat[GFXFormatR32F] = GL_ZERO;
GFXGLTextureInternalFormat[GFXFormatR16G16] = GL_RGBA16;
GFXGLTextureInternalFormat[GFXFormatR16G16F] = GL_ZERO;
GFXGLTextureInternalFormat[GFXFormatR10G10B10A2] = GL_ZERO;
GFXGLTextureInternalFormat[GFXFormatD32] = GL_DEPTH_COMPONENT32;
GFXGLTextureInternalFormat[GFXFormatD24X8] = GL_DEPTH_COMPONENT24;
GFXGLTextureInternalFormat[GFXFormatD24S8] = GL_DEPTH_COMPONENT24;
GFXGLTextureInternalFormat[GFXFormatR16G16B16A16] = GL_ZERO;
GFXGLTextureInternalFormat[GFXFormatR16G16B16A16F] = GL_ZERO;
GFXGLTextureInternalFormat[GFXFormatR32G32B32A32F] = GL_ZERO;
GFXGLTextureInternalFormat[GFXFormatDXT1] = GL_COMPRESSED_RGBA_S3TC_DXT1_EXT;
GFXGLTextureInternalFormat[GFXFormatDXT2] = GL_ZERO;
GFXGLTextureInternalFormat[GFXFormatDXT3] = GL_COMPRESSED_RGBA_S3TC_DXT3_EXT;
GFXGLTextureInternalFormat[GFXFormatDXT4] = GL_ZERO;
GFXGLTextureInternalFormat[GFXFormatDXT5] = GL_COMPRESSED_RGBA_S3TC_DXT5_EXT;
GFXGLTextureFormat[GFXFormatA8] = GL_ALPHA;
GFXGLTextureFormat[GFXFormatL8] = GL_LUMINANCE;
GFXGLTextureFormat[GFXFormatR5G6B5] = GL_RGBA;
GFXGLTextureFormat[GFXFormatR5G5B5A1] = GL_RGBA;
GFXGLTextureFormat[GFXFormatR5G5B5X1] = GL_RGBA;
GFXGLTextureFormat[GFXFormatL16] = GL_LUMINANCE;
GFXGLTextureFormat[GFXFormatR16F] = GL_ZERO;
GFXGLTextureFormat[GFXFormatD16] = GL_DEPTH_COMPONENT;
GFXGLTextureFormat[GFXFormatR8G8B8] = GL_RGB;
GFXGLTextureFormat[GFXFormatR8G8B8A8] = GL_BGRA;
GFXGLTextureFormat[GFXFormatR8G8B8X8] = GL_BGRA;
GFXGLTextureFormat[GFXFormatR32F] = GL_RGBA;
GFXGLTextureFormat[GFXFormatR16G16] = GL_RGBA;
GFXGLTextureFormat[GFXFormatR16G16F] = GL_ZERO;
GFXGLTextureFormat[GFXFormatR10G10B10A2] = GL_RGBA;
GFXGLTextureFormat[GFXFormatD32] = GL_DEPTH_COMPONENT;
GFXGLTextureFormat[GFXFormatD24X8] = GL_DEPTH_COMPONENT;
GFXGLTextureFormat[GFXFormatD24S8] = GL_DEPTH_COMPONENT;
GFXGLTextureFormat[GFXFormatR16G16B16A16] = GL_RGBA;
GFXGLTextureFormat[GFXFormatR16G16B16A16F] = GL_RGBA;
GFXGLTextureFormat[GFXFormatR32G32B32A32F] = GL_RGBA;
GFXGLTextureFormat[GFXFormatDXT1] = GL_RGBA;
GFXGLTextureFormat[GFXFormatDXT2] = GL_ZERO;
GFXGLTextureFormat[GFXFormatDXT3] = GL_RGBA;
GFXGLTextureFormat[GFXFormatDXT4] = GL_ZERO;
GFXGLTextureFormat[GFXFormatDXT5] = GL_RGBA;
GFXGLTextureType[GFXFormatA8] = GL_UNSIGNED_BYTE;
GFXGLTextureType[GFXFormatL8] = GL_UNSIGNED_BYTE;
GFXGLTextureType[GFXFormatR5G6B5] = GL_UNSIGNED_BYTE;
GFXGLTextureType[GFXFormatR5G5B5A1] = GL_UNSIGNED_BYTE;
GFXGLTextureType[GFXFormatR5G5B5X1] = GL_UNSIGNED_BYTE;
GFXGLTextureType[GFXFormatL16] = GL_UNSIGNED_SHORT;
GFXGLTextureType[GFXFormatR16F] = GL_ZERO;
GFXGLTextureType[GFXFormatD16] = GL_UNSIGNED_SHORT;
GFXGLTextureType[GFXFormatR8G8B8] = GL_UNSIGNED_BYTE;
GFXGLTextureType[GFXFormatR8G8B8A8] = GL_UNSIGNED_BYTE;
GFXGLTextureType[GFXFormatR8G8B8X8] = GL_UNSIGNED_BYTE;
GFXGLTextureType[GFXFormatR32F] = GL_FLOAT;
GFXGLTextureType[GFXFormatR16G16] = GL_UNSIGNED_SHORT;
GFXGLTextureType[GFXFormatR16G16F] = GL_FLOAT;
GFXGLTextureType[GFXFormatR10G10B10A2] = GL_UNSIGNED_SHORT;
GFXGLTextureType[GFXFormatD32] = GL_UNSIGNED_BYTE;
GFXGLTextureType[GFXFormatD24X8] = GL_UNSIGNED_BYTE;
GFXGLTextureType[GFXFormatD24S8] = GL_UNSIGNED_BYTE;
GFXGLTextureType[GFXFormatR16G16B16A16] = GL_UNSIGNED_SHORT;
GFXGLTextureType[GFXFormatR16G16B16A16F] = GL_FLOAT;
GFXGLTextureType[GFXFormatR32G32B32A32F] = GL_FLOAT;
GFXGLTextureType[GFXFormatDXT1] = GL_UNSIGNED_BYTE;
GFXGLTextureType[GFXFormatDXT2] = GL_ZERO;
GFXGLTextureType[GFXFormatDXT3] = GL_UNSIGNED_BYTE;
GFXGLTextureType[GFXFormatDXT4] = GL_ZERO;
GFXGLTextureType[GFXFormatDXT5] = GL_UNSIGNED_BYTE;
// Cull
GFXGLCullMode[GFXCullNone] = GL_BACK;
GFXGLCullMode[GFXCullCW] = GL_BACK;
GFXGLCullMode[GFXCullCCW] = GL_FRONT;
// Fill
GFXGLFillMode[GFXFillPoint] = GL_POINT;
GFXGLFillMode[GFXFillWireframe] = GL_LINE;
GFXGLFillMode[GFXFillSolid] = GL_FILL;
}

View file

@ -0,0 +1,52 @@
//-----------------------------------------------------------------------------
// Copyright (c) 2012 GarageGames, LLC
//
// Permission is hereby granted, free of charge, to any person obtaining a copy
// of this software and associated documentation files (the "Software"), to
// deal in the Software without restriction, including without limitation the
// rights to use, copy, modify, merge, publish, distribute, sublicense, and/or
// sell copies of the Software, and to permit persons to whom the Software is
// furnished to do so, subject to the following conditions:
//
// The above copyright notice and this permission notice shall be included in
// all copies or substantial portions of the Software.
//
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
// FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS
// IN THE SOFTWARE.
//-----------------------------------------------------------------------------
#ifndef _GFXGLENUMTRANSLATE_H_
#define _GFXGLENUMTRANSLATE_H_
#include "gfx/gfxEnums.h"
#include "gfx/gl/gfxGLDevice.h"
namespace GFXGLEnumTranslate
{
void init();
};
extern GLenum GFXGLPrimType[GFXPT_COUNT];
extern GLenum GFXGLBlend[GFXBlend_COUNT];
extern GLenum GFXGLBlendOp[GFXBlendOp_COUNT];
extern GLenum GFXGLSamplerState[GFXSAMP_COUNT];
extern GLenum GFXGLTextureFilter[GFXTextureFilter_COUNT];
extern GLenum GFXGLTextureAddress[GFXAddress_COUNT];
extern GLenum GFXGLCmpFunc[GFXCmp_COUNT];
extern GLenum GFXGLStencilOp[GFXStencilOp_COUNT];
extern GLenum GFXGLTextureInternalFormat[GFXFormat_COUNT];
extern GLenum GFXGLTextureFormat[GFXFormat_COUNT];
extern GLenum GFXGLTextureType[GFXFormat_COUNT];
extern GLenum GFXGLBufferType[GFXBufferType_COUNT];
extern GLenum GFXGLCullMode[GFXCull_COUNT];
extern GLenum GFXGLFillMode[GFXFill_COUNT];
#endif

View file

@ -0,0 +1,89 @@
//-----------------------------------------------------------------------------
// Copyright (c) 2012 GarageGames, LLC
//
// Permission is hereby granted, free of charge, to any person obtaining a copy
// of this software and associated documentation files (the "Software"), to
// deal in the Software without restriction, including without limitation the
// rights to use, copy, modify, merge, publish, distribute, sublicense, and/or
// sell copies of the Software, and to permit persons to whom the Software is
// furnished to do so, subject to the following conditions:
//
// The above copyright notice and this permission notice shall be included in
// all copies or substantial portions of the Software.
//
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
// FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS
// IN THE SOFTWARE.
//-----------------------------------------------------------------------------
#include "platform/platform.h"
#include "gfx/gl/gfxGLOcclusionQuery.h"
#include "gfx/gl/ggl/ggl.h"
GFXGLOcclusionQuery::GFXGLOcclusionQuery(GFXDevice* device) :
GFXOcclusionQuery(device), mQuery(0)
{
glGenQueries(1, &mQuery);
}
GFXGLOcclusionQuery::~GFXGLOcclusionQuery()
{
glDeleteQueries(1, &mQuery);
}
bool GFXGLOcclusionQuery::begin()
{
glBeginQuery(GL_SAMPLES_PASSED, mQuery);
return true;
}
void GFXGLOcclusionQuery::end()
{
glEndQuery(GL_SAMPLES_PASSED);
}
GFXOcclusionQuery::OcclusionQueryStatus GFXGLOcclusionQuery::getStatus(bool block, U32* data)
{
// If this ever shows up near the top of a profile
// then your system is GPU bound.
PROFILE_SCOPE(GFXGLOcclusionQuery_getStatus);
GLint numPixels = 0;
GLint queryDone = false;
if (block)
queryDone = true;
else
glGetQueryObjectiv(mQuery, GL_QUERY_RESULT_AVAILABLE, &queryDone);
if (queryDone)
glGetQueryObjectiv(mQuery, GL_QUERY_RESULT, &numPixels);
else
return Waiting;
if (data)
*data = numPixels;
return numPixels > 0 ? NotOccluded : Occluded;
}
void GFXGLOcclusionQuery::zombify()
{
glDeleteQueries(1, &mQuery);
mQuery = 0;
}
void GFXGLOcclusionQuery::resurrect()
{
glGenQueries(1, &mQuery);
}
const String GFXGLOcclusionQuery::describeSelf() const
{
// We've got nothing
return String();
}

View file

@ -0,0 +1,49 @@
//-----------------------------------------------------------------------------
// Copyright (c) 2012 GarageGames, LLC
//
// Permission is hereby granted, free of charge, to any person obtaining a copy
// of this software and associated documentation files (the "Software"), to
// deal in the Software without restriction, including without limitation the
// rights to use, copy, modify, merge, publish, distribute, sublicense, and/or
// sell copies of the Software, and to permit persons to whom the Software is
// furnished to do so, subject to the following conditions:
//
// The above copyright notice and this permission notice shall be included in
// all copies or substantial portions of the Software.
//
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
// FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS
// IN THE SOFTWARE.
//-----------------------------------------------------------------------------
#ifndef _GFX_GL_OCCLUSIONQUERY_H_
#define _GFX_GL_OCCLUSIONQUERY_H_
#ifndef _GFXOCCLUSIONQUERY_H_
#include "gfx/gfxOcclusionQuery.h"
#endif
class GFXGLOcclusionQuery : public GFXOcclusionQuery
{
public:
GFXGLOcclusionQuery( GFXDevice *device );
virtual ~GFXGLOcclusionQuery();
virtual bool begin();
virtual void end();
virtual OcclusionQueryStatus getStatus( bool block, U32 *data = NULL );
// GFXResource
virtual void zombify();
virtual void resurrect();
virtual const String describeSelf() const;
private:
U32 mQuery;
};
#endif // _GFX_GL_OCCLUSIONQUERY_H_

View file

@ -0,0 +1,116 @@
//-----------------------------------------------------------------------------
// Copyright (c) 2012 GarageGames, LLC
//
// Permission is hereby granted, free of charge, to any person obtaining a copy
// of this software and associated documentation files (the "Software"), to
// deal in the Software without restriction, including without limitation the
// rights to use, copy, modify, merge, publish, distribute, sublicense, and/or
// sell copies of the Software, and to permit persons to whom the Software is
// furnished to do so, subject to the following conditions:
//
// The above copyright notice and this permission notice shall be included in
// all copies or substantial portions of the Software.
//
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
// FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS
// IN THE SOFTWARE.
//-----------------------------------------------------------------------------
#include "gfx/gl/gfxGLDevice.h"
#include "gfx/gl/gfxGLPrimitiveBuffer.h"
#include "gfx/gl/gfxGLEnumTranslate.h"
#include "gfx/gl/ggl/ggl.h"
#include "gfx/gl/gfxGLUtils.h"
GFXGLPrimitiveBuffer::GFXGLPrimitiveBuffer(GFXDevice *device, U32 indexCount, U32 primitiveCount, GFXBufferType bufferType) :
GFXPrimitiveBuffer(device, indexCount, primitiveCount, bufferType), mZombieCache(NULL)
{
PRESERVE_INDEX_BUFFER();
// Generate a buffer and allocate the needed memory
glGenBuffers(1, &mBuffer);
glBindBuffer(GL_ELEMENT_ARRAY_BUFFER, mBuffer);
glBufferData(GL_ELEMENT_ARRAY_BUFFER, indexCount * sizeof(U16), NULL, GFXGLBufferType[bufferType]);
}
GFXGLPrimitiveBuffer::~GFXGLPrimitiveBuffer()
{
// This is heavy handed, but it frees the buffer memory
glDeleteBuffersARB(1, &mBuffer);
if( mZombieCache )
delete [] mZombieCache;
}
void GFXGLPrimitiveBuffer::lock(U32 indexStart, U32 indexEnd, void **indexPtr)
{
// Preserve previous binding
PRESERVE_INDEX_BUFFER();
// Bind ourselves and map
glBindBuffer(GL_ELEMENT_ARRAY_BUFFER, mBuffer);
glBufferData(GL_ELEMENT_ARRAY_BUFFER, mIndexCount * sizeof(U16), NULL, GFXGLBufferType[mBufferType]);
// Offset the buffer to indexStart
*indexPtr = (void*)((U8*)glMapBuffer(GL_ELEMENT_ARRAY_BUFFER, GL_WRITE_ONLY) + (indexStart * sizeof(U16)));
}
void GFXGLPrimitiveBuffer::unlock()
{
// Preserve previous binding
PRESERVE_INDEX_BUFFER();
// Bind ourselves and unmap
glBindBuffer(GL_ELEMENT_ARRAY_BUFFER, mBuffer);
bool res = glUnmapBuffer(GL_ELEMENT_ARRAY_BUFFER);
AssertFatal(res, "GFXGLPrimitiveBuffer::unlock - shouldn't fail!");
}
void GFXGLPrimitiveBuffer::prepare()
{
// Bind
static_cast<GFXGLDevice*>(mDevice)->setPB(this);
glBindBuffer(GL_ELEMENT_ARRAY_BUFFER, mBuffer);
}
void GFXGLPrimitiveBuffer::finish()
{
glBindBuffer(GL_ELEMENT_ARRAY_BUFFER, 0);
}
GLvoid* GFXGLPrimitiveBuffer::getBuffer()
{
// NULL specifies no offset into the hardware buffer
return (GLvoid*)NULL;
}
void GFXGLPrimitiveBuffer::zombify()
{
if(mZombieCache)
return;
mZombieCache = new U8[mIndexCount * sizeof(U16)];
glBindBuffer(GL_ELEMENT_ARRAY_BUFFER, mBuffer);
glGetBufferSubData(GL_ELEMENT_ARRAY_BUFFER, 0, mIndexCount * sizeof(U16), mZombieCache);
glBindBuffer(GL_ELEMENT_ARRAY_BUFFER, 0);
glDeleteBuffers(1, &mBuffer);
mBuffer = 0;
}
void GFXGLPrimitiveBuffer::resurrect()
{
if(!mZombieCache)
return;
glGenBuffers(1, &mBuffer);
glBindBuffer(GL_ELEMENT_ARRAY_BUFFER, mBuffer);
glBufferData(GL_ELEMENT_ARRAY_BUFFER, mIndexCount * sizeof(U16), mZombieCache, GFXGLBufferType[mBufferType]);
glBindBuffer(GL_ELEMENT_ARRAY_BUFFER, 0);
delete[] mZombieCache;
mZombieCache = NULL;
}

View file

@ -0,0 +1,53 @@
//-----------------------------------------------------------------------------
// Copyright (c) 2012 GarageGames, LLC
//
// Permission is hereby granted, free of charge, to any person obtaining a copy
// of this software and associated documentation files (the "Software"), to
// deal in the Software without restriction, including without limitation the
// rights to use, copy, modify, merge, publish, distribute, sublicense, and/or
// sell copies of the Software, and to permit persons to whom the Software is
// furnished to do so, subject to the following conditions:
//
// The above copyright notice and this permission notice shall be included in
// all copies or substantial portions of the Software.
//
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
// FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS
// IN THE SOFTWARE.
//-----------------------------------------------------------------------------
#ifndef _GFXGLPRIMITIVEBUFFER_H_
#define _GFXGLPRIMITIVEBUFFER_H_
#include "gfx/gfxPrimitiveBuffer.h"
/// This is a primitive buffer (index buffer to GL users) which uses VBOs.
class GFXGLPrimitiveBuffer : public GFXPrimitiveBuffer
{
public:
GFXGLPrimitiveBuffer(GFXDevice *device, U32 indexCount, U32 primitiveCount, GFXBufferType bufferType);
~GFXGLPrimitiveBuffer();
virtual void lock(U32 indexStart, U32 indexEnd, void **indexPtr); ///< calls glMapBuffer, offets pointer by indexStart
virtual void unlock(); ///< calls glUnmapBuffer, unbinds the buffer
virtual void prepare(); ///< binds the buffer
virtual void finish(); ///< We're done with this buffer
virtual void* getBuffer(); ///< returns NULL
// GFXResource interface
virtual void zombify();
virtual void resurrect();
private:
/// Handle to our GL buffer object
GLuint mBuffer;
U8* mZombieCache;
};
#endif

View file

@ -0,0 +1,929 @@
//-----------------------------------------------------------------------------
// Copyright (c) 2012 GarageGames, LLC
//
// Permission is hereby granted, free of charge, to any person obtaining a copy
// of this software and associated documentation files (the "Software"), to
// deal in the Software without restriction, including without limitation the
// rights to use, copy, modify, merge, publish, distribute, sublicense, and/or
// sell copies of the Software, and to permit persons to whom the Software is
// furnished to do so, subject to the following conditions:
//
// The above copyright notice and this permission notice shall be included in
// all copies or substantial portions of the Software.
//
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
// FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS
// IN THE SOFTWARE.
//-----------------------------------------------------------------------------
#include "platform/platform.h"
#include "gfx/gl/gfxGLShader.h"
#include "core/frameAllocator.h"
#include "core/stream/fileStream.h"
#include "core/strings/stringFunctions.h"
#include "math/mPoint2.h"
#include "gfx/gfxStructs.h"
#include "console/console.h"
class GFXGLShaderConstHandle : public GFXShaderConstHandle
{
friend class GFXGLShader;
public:
GFXGLShaderConstHandle( GFXGLShader *shader );
GFXGLShaderConstHandle( GFXGLShader *shader, const GFXShaderConstDesc &desc, GLuint loc, S32 samplerNum );
virtual ~GFXGLShaderConstHandle();
void reinit( const GFXShaderConstDesc &desc, GLuint loc, S32 samplerNum );
const String& getName() const { return mDesc.name; }
GFXShaderConstType getType() const { return mDesc.constType; }
U32 getArraySize() const { return mDesc.arraySize; }
U32 getSize() const;
void setValid( bool valid ) { mValid = valid; }
/// @warning This will always return the value assigned when the shader was
/// initialized. If the value is later changed this method won't reflect that.
S32 getSamplerRegister() const { return mSamplerNum; }
GFXShaderConstDesc mDesc;
GFXGLShader* mShader;
GLuint mLocation;
U32 mOffset;
U32 mSize;
S32 mSamplerNum;
};
GFXGLShaderConstHandle::GFXGLShaderConstHandle( GFXGLShader *shader )
: mShader( shader ), mSamplerNum(-1)
{
mValid = false;
}
static U32 shaderConstTypeSize(GFXShaderConstType type)
{
switch(type)
{
case GFXSCT_Float:
case GFXSCT_Int:
case GFXSCT_Sampler:
case GFXSCT_SamplerCube:
return 4;
case GFXSCT_Float2:
case GFXSCT_Int2:
return 8;
case GFXSCT_Float3:
case GFXSCT_Int3:
return 12;
case GFXSCT_Float4:
case GFXSCT_Int4:
return 16;
case GFXSCT_Float2x2:
return 16;
case GFXSCT_Float3x3:
return 36;
case GFXSCT_Float4x4:
return 64;
default:
AssertFatal(false,"shaderConstTypeSize - Unrecognized constant type");
return 0;
}
}
GFXGLShaderConstHandle::GFXGLShaderConstHandle( GFXGLShader *shader, const GFXShaderConstDesc &desc, GLuint loc, S32 samplerNum )
: mShader(shader)
{
reinit(desc, loc, samplerNum);
}
void GFXGLShaderConstHandle::reinit( const GFXShaderConstDesc& desc, GLuint loc, S32 samplerNum )
{
mDesc = desc;
mLocation = loc;
mSamplerNum = samplerNum;
mOffset = 0;
U32 elemSize = shaderConstTypeSize(mDesc.constType);
AssertFatal(elemSize, "GFXGLShaderConst::GFXGLShaderConst - elemSize is 0");
mSize = mDesc.arraySize * elemSize;
mValid = true;
}
U32 GFXGLShaderConstHandle::getSize() const
{
return mSize;
}
GFXGLShaderConstHandle::~GFXGLShaderConstHandle()
{
}
GFXGLShaderConstBuffer::GFXGLShaderConstBuffer(GFXGLShader* shader, U32 bufSize, U8* existingConstants)
{
mShader = shader;
mBuffer = new U8[bufSize];
mWasLost = true;
// Copy the existing constant buffer to preserve sampler numbers
/// @warning This preserves a lot more than sampler numbers, obviously. If there
/// is any code that assumes a new constant buffer will have everything set to
/// 0, it will break.
dMemcpy(mBuffer, existingConstants, bufSize);
}
GFXGLShaderConstBuffer::~GFXGLShaderConstBuffer()
{
delete[] mBuffer;
if ( mShader )
mShader->_unlinkBuffer( this );
}
template<typename ConstType>
void GFXGLShaderConstBuffer::internalSet(GFXShaderConstHandle* handle, const ConstType& param)
{
AssertFatal(handle, "GFXGLShaderConstBuffer::internalSet - Handle is NULL!" );
AssertFatal(handle->isValid(), "GFXGLShaderConstBuffer::internalSet - Handle is not valid!" );
AssertFatal(dynamic_cast<GFXGLShaderConstHandle*>(handle), "GFXGLShaderConstBuffer::set - Incorrect const buffer type");
GFXGLShaderConstHandle* _glHandle = static_cast<GFXGLShaderConstHandle*>(handle);
AssertFatal(mShader == _glHandle->mShader, "GFXGLShaderConstBuffer::set - Should only set handles which are owned by our shader");
dMemcpy(mBuffer + _glHandle->mOffset, &param, sizeof(ConstType));
}
void GFXGLShaderConstBuffer::set(GFXShaderConstHandle* handle, const F32 fv)
{
internalSet(handle, fv);
}
void GFXGLShaderConstBuffer::set(GFXShaderConstHandle* handle, const Point2F& fv)
{
internalSet(handle, fv);
}
void GFXGLShaderConstBuffer::set(GFXShaderConstHandle* handle, const Point3F& fv)
{
internalSet(handle, fv);
}
void GFXGLShaderConstBuffer::set(GFXShaderConstHandle* handle, const Point4F& fv)
{
internalSet(handle, fv);
}
void GFXGLShaderConstBuffer::set(GFXShaderConstHandle* handle, const PlaneF& fv)
{
internalSet(handle, fv);
}
void GFXGLShaderConstBuffer::set(GFXShaderConstHandle* handle, const ColorF& fv)
{
internalSet(handle, fv);
}
void GFXGLShaderConstBuffer::set(GFXShaderConstHandle* handle, const S32 fv)
{
internalSet(handle, fv);
}
void GFXGLShaderConstBuffer::set(GFXShaderConstHandle* handle, const Point2I& fv)
{
internalSet(handle, fv);
}
void GFXGLShaderConstBuffer::set(GFXShaderConstHandle* handle, const Point3I& fv)
{
internalSet(handle, fv);
}
void GFXGLShaderConstBuffer::set(GFXShaderConstHandle* handle, const Point4I& fv)
{
internalSet(handle, fv);
}
template<typename ConstType>
void GFXGLShaderConstBuffer::internalSet(GFXShaderConstHandle* handle, const AlignedArray<ConstType>& fv)
{
AssertFatal(handle, "GFXGLShaderConstBuffer::internalSet - Handle is NULL!" );
AssertFatal(handle->isValid(), "GFXGLShaderConstBuffer::internalSet - Handle is not valid!" );
AssertFatal(dynamic_cast<GFXGLShaderConstHandle*>(handle), "GFXGLShaderConstBuffer::set - Incorrect const buffer type");
GFXGLShaderConstHandle* _glHandle = static_cast<GFXGLShaderConstHandle*>(handle);
AssertFatal(mShader == _glHandle->mShader, "GFXGLShaderConstBuffer::set - Should only set handles which are owned by our shader");
const U8* fvBuffer = static_cast<const U8*>(fv.getBuffer());
for(U32 i = 0; i < fv.size(); ++i)
{
dMemcpy(mBuffer + _glHandle->mOffset + i * sizeof(ConstType), fvBuffer, sizeof(ConstType));
fvBuffer += fv.getElementSize();
}
}
void GFXGLShaderConstBuffer::set(GFXShaderConstHandle* handle, const AlignedArray<F32>& fv)
{
internalSet(handle, fv);
}
void GFXGLShaderConstBuffer::set(GFXShaderConstHandle* handle, const AlignedArray<Point2F>& fv)
{
internalSet(handle, fv);
}
void GFXGLShaderConstBuffer::set(GFXShaderConstHandle* handle, const AlignedArray<Point3F>& fv)
{
internalSet(handle, fv);
}
void GFXGLShaderConstBuffer::set(GFXShaderConstHandle* handle, const AlignedArray<Point4F>& fv)
{
internalSet(handle, fv);
}
void GFXGLShaderConstBuffer::set(GFXShaderConstHandle* handle, const AlignedArray<S32>& fv)
{
internalSet(handle, fv);
}
void GFXGLShaderConstBuffer::set(GFXShaderConstHandle* handle, const AlignedArray<Point2I>& fv)
{
internalSet(handle, fv);
}
void GFXGLShaderConstBuffer::set(GFXShaderConstHandle* handle, const AlignedArray<Point3I>& fv)
{
internalSet(handle, fv);
}
void GFXGLShaderConstBuffer::set(GFXShaderConstHandle* handle, const AlignedArray<Point4I>& fv)
{
internalSet(handle, fv);
}
void GFXGLShaderConstBuffer::set(GFXShaderConstHandle* handle, const MatrixF& mat, const GFXShaderConstType matType)
{
AssertFatal(handle, "GFXGLShaderConstBuffer::set - Handle is NULL!" );
AssertFatal(handle->isValid(), "GFXGLShaderConstBuffer::set - Handle is not valid!" );
AssertFatal(dynamic_cast<GFXGLShaderConstHandle*>(handle), "GFXGLShaderConstBuffer::set - Incorrect const buffer type");
GFXGLShaderConstHandle* _glHandle = static_cast<GFXGLShaderConstHandle*>(handle);
AssertFatal(mShader == _glHandle->mShader, "GFXGLShaderConstBuffer::set - Should only set handles which are owned by our shader");
switch(matType)
{
case GFXSCT_Float2x2:
reinterpret_cast<F32*>(mBuffer + _glHandle->mOffset)[0] = mat[0];
reinterpret_cast<F32*>(mBuffer + _glHandle->mOffset)[1] = mat[1];
reinterpret_cast<F32*>(mBuffer + _glHandle->mOffset)[2] = mat[4];
reinterpret_cast<F32*>(mBuffer + _glHandle->mOffset)[3] = mat[5];
break;
case GFXSCT_Float3x3:
reinterpret_cast<F32*>(mBuffer + _glHandle->mOffset)[0] = mat[0];
reinterpret_cast<F32*>(mBuffer + _glHandle->mOffset)[1] = mat[1];
reinterpret_cast<F32*>(mBuffer + _glHandle->mOffset)[2] = mat[2];
reinterpret_cast<F32*>(mBuffer + _glHandle->mOffset)[3] = mat[4];
reinterpret_cast<F32*>(mBuffer + _glHandle->mOffset)[4] = mat[5];
reinterpret_cast<F32*>(mBuffer + _glHandle->mOffset)[5] = mat[6];
reinterpret_cast<F32*>(mBuffer + _glHandle->mOffset)[6] = mat[8];
reinterpret_cast<F32*>(mBuffer + _glHandle->mOffset)[7] = mat[9];
reinterpret_cast<F32*>(mBuffer + _glHandle->mOffset)[8] = mat[10];
break;
case GFXSCT_Float4x4:
dMemcpy(mBuffer + _glHandle->mOffset, (const F32*)mat, sizeof(MatrixF));
break;
default:
AssertFatal(false, "GFXGLShaderConstBuffer::set - Invalid matrix type");
break;
}
}
void GFXGLShaderConstBuffer::set(GFXShaderConstHandle* handle, const MatrixF* mat, const U32 arraySize, const GFXShaderConstType matrixType)
{
AssertFatal(handle, "GFXGLShaderConstBuffer::set - Handle is NULL!" );
AssertFatal(handle->isValid(), "GFXGLShaderConstBuffer::set - Handle is not valid!" );
GFXGLShaderConstHandle* _glHandle = static_cast<GFXGLShaderConstHandle*>(handle);
AssertFatal(mShader == _glHandle->mShader, "GFXGLShaderConstBuffer::set - Should only set handles which are owned by our shader");
switch (matrixType) {
case GFXSCT_Float4x4:
dMemcpy(mBuffer + _glHandle->mOffset, (F32*)mat, _glHandle->getSize());
break;
default:
AssertFatal(false, "GFXGLShaderConstBuffer::set - setting array of non 4x4 matrices!");
break;
}
}
void GFXGLShaderConstBuffer::activate()
{
mShader->setConstantsFromBuffer(this);
mWasLost = false;
}
const String GFXGLShaderConstBuffer::describeSelf() const
{
return String();
}
void GFXGLShaderConstBuffer::onShaderReload( GFXGLShader *shader )
{
AssertFatal( shader == mShader, "GFXGLShaderConstBuffer::onShaderReload, mismatched shaders!" );
delete[] mBuffer;
mBuffer = new U8[mShader->mConstBufferSize];
dMemset(mBuffer, 0, mShader->mConstBufferSize);
mWasLost = true;
}
GFXGLShader::GFXGLShader() :
mVertexShader(0),
mPixelShader(0),
mProgram(0),
mConstBufferSize(0),
mConstBuffer(NULL)
{
}
GFXGLShader::~GFXGLShader()
{
clearShaders();
for(HandleMap::Iterator i = mHandles.begin(); i != mHandles.end(); i++)
delete i->value;
delete[] mConstBuffer;
}
void GFXGLShader::clearShaders()
{
glDeleteProgram(mProgram);
glDeleteShader(mVertexShader);
glDeleteShader(mPixelShader);
mProgram = 0;
mVertexShader = 0;
mPixelShader = 0;
}
bool GFXGLShader::_init()
{
// Don't initialize empty shaders.
if ( mVertexFile.isEmpty() && mPixelFile.isEmpty() )
return false;
clearShaders();
mProgram = glCreateProgram();
// Set the macros and add the global ones.
Vector<GFXShaderMacro> macros;
macros.merge( mMacros );
macros.merge( smGlobalMacros );
// Add the shader version to the macros.
const U32 mjVer = (U32)mFloor( mPixVersion );
const U32 mnVer = (U32)( ( mPixVersion - F32( mjVer ) ) * 10.01f );
macros.increment();
macros.last().name = "TORQUE_SM";
macros.last().value = String::ToString( mjVer * 10 + mnVer );
// Default to true so we're "successful" if a vertex/pixel shader wasn't specified.
bool compiledVertexShader = true;
bool compiledPixelShader = true;
// Compile the vertex and pixel shaders if specified.
if(!mVertexFile.isEmpty())
compiledVertexShader = initShader(mVertexFile, true, macros);
if(!mPixelFile.isEmpty())
compiledPixelShader = initShader(mPixelFile, false, macros);
// If either shader was present and failed to compile, bail.
if(!compiledVertexShader || !compiledPixelShader)
return false;
// Link it!
glLinkProgram( mProgram );
GLint linkStatus;
glGetProgramiv( mProgram, GL_LINK_STATUS, &linkStatus );
// Dump the info log to the console
U32 logLength = 0;
glGetProgramiv(mProgram, GL_INFO_LOG_LENGTH, (GLint*)&logLength);
if ( logLength )
{
FrameAllocatorMarker fam;
char* log = (char*)fam.alloc( logLength );
glGetProgramInfoLog( mProgram, logLength, NULL, log );
if ( linkStatus == GL_FALSE )
{
if ( smLogErrors )
{
Con::errorf( "GFXGLShader::init - Error linking shader!" );
Con::errorf( "Program %s / %s: %s",
mVertexFile.getFullPath().c_str(), mPixelFile.getFullPath().c_str(), log);
}
}
else if ( smLogWarnings )
{
Con::warnf( "Program %s / %s: %s",
mVertexFile.getFullPath().c_str(), mPixelFile.getFullPath().c_str(), log);
}
}
// If we failed to link, bail.
if ( linkStatus == GL_FALSE )
return false;
initConstantDescs();
initHandles();
// Notify Buffers we might have changed in size.
// If this was our first init then we won't have any activeBuffers
// to worry about unnecessarily calling.
Vector<GFXShaderConstBuffer*>::iterator biter = mActiveBuffers.begin();
for ( ; biter != mActiveBuffers.end(); biter++ )
((GFXGLShaderConstBuffer*)(*biter))->onShaderReload( this );
return true;
}
void GFXGLShader::initConstantDescs()
{
mConstants.clear();
GLint numUniforms;
glGetProgramiv(mProgram, GL_ACTIVE_UNIFORMS, &numUniforms);
GLint maxNameLength;
glGetProgramiv(mProgram, GL_ACTIVE_UNIFORM_MAX_LENGTH, &maxNameLength);
FrameTemp<GLchar> uniformName(maxNameLength);
for(U32 i = 0; i < numUniforms; i++)
{
GLint size;
GLenum type;
glGetActiveUniform(mProgram, i, maxNameLength, NULL, &size, &type, uniformName);
GFXShaderConstDesc desc;
desc.name = String((char*)uniformName);
// Remove array brackets from the name
desc.name = desc.name.substr(0, desc.name.find('['));
// Insert $ to match D3D behavior of having a $ prepended to parameters to main.
desc.name.insert(0, '$');
desc.arraySize = size;
switch(type)
{
case GL_FLOAT:
desc.constType = GFXSCT_Float;
break;
case GL_FLOAT_VEC2:
desc.constType = GFXSCT_Float2;
break;
case GL_FLOAT_VEC3:
desc.constType = GFXSCT_Float3;
break;
case GL_FLOAT_VEC4:
desc.constType = GFXSCT_Float4;
break;
case GL_INT:
desc.constType = GFXSCT_Int;
break;
case GL_INT_VEC2:
desc.constType = GFXSCT_Int2;
break;
case GL_INT_VEC3:
desc.constType = GFXSCT_Int3;
break;
case GL_INT_VEC4:
desc.constType = GFXSCT_Int4;
break;
case GL_FLOAT_MAT2:
desc.constType = GFXSCT_Float2x2;
break;
case GL_FLOAT_MAT3:
desc.constType = GFXSCT_Float3x3;
break;
case GL_FLOAT_MAT4:
desc.constType = GFXSCT_Float4x4;
break;
case GL_SAMPLER_1D:
case GL_SAMPLER_2D:
case GL_SAMPLER_3D:
case GL_SAMPLER_1D_SHADOW:
case GL_SAMPLER_2D_SHADOW:
desc.constType = GFXSCT_Sampler;
break;
case GL_SAMPLER_CUBE:
desc.constType = GFXSCT_SamplerCube;
break;
default:
AssertFatal(false, "GFXGLShader::initConstantDescs - unrecognized uniform type");
// If we don't recognize the constant don't add its description.
continue;
}
mConstants.push_back(desc);
}
}
void GFXGLShader::initHandles()
{
// Mark all existing handles as invalid.
// Those that are found when parsing the descriptions will then be marked valid again.
for ( HandleMap::Iterator iter = mHandles.begin(); iter != mHandles.end(); ++iter )
(iter->value)->setValid( false );
mValidHandles.clear();
// Loop through all ConstantDescriptions,
// if they aren't in the HandleMap add them, if they are reinitialize them.
S32 assignedSamplerNum = 0;
for ( U32 i = 0; i < mConstants.size(); i++ )
{
GFXShaderConstDesc &desc = mConstants[i];
// Index element 1 of the name to skip the '$' we inserted earier.
U32 loc = glGetUniformLocation(mProgram, &desc.name.c_str()[1]);
HandleMap::Iterator handle = mHandles.find(desc.name);
S32 sampler = (desc.constType == GFXSCT_Sampler || desc.constType == GFXSCT_SamplerCube) ?
assignedSamplerNum++ : -1;
if ( handle != mHandles.end() )
{
handle->value->reinit( desc, loc, sampler );
}
else
{
mHandles[desc.name] = new GFXGLShaderConstHandle( this, desc, loc, sampler );
}
}
// Loop through handles once more to set their offset and calculate our
// constBuffer size.
if ( mConstBuffer )
delete[] mConstBuffer;
mConstBufferSize = 0;
for ( HandleMap::Iterator iter = mHandles.begin(); iter != mHandles.end(); ++iter )
{
GFXGLShaderConstHandle* handle = iter->value;
if ( handle->isValid() )
{
mValidHandles.push_back(handle);
handle->mOffset = mConstBufferSize;
mConstBufferSize += handle->getSize();
}
}
mConstBuffer = new U8[mConstBufferSize];
dMemset(mConstBuffer, 0, mConstBufferSize);
// Set our program so uniforms are assigned properly.
glUseProgram(mProgram);
// Iterate through uniforms to set sampler numbers.
for (HandleMap::Iterator iter = mHandles.begin(); iter != mHandles.end(); ++iter)
{
GFXGLShaderConstHandle* handle = iter->value;
if(handle->isValid() && (handle->getType() == GFXSCT_Sampler || handle->getType() == GFXSCT_SamplerCube))
{
// Set sampler number on our program.
glUniform1i(handle->mLocation, handle->mSamplerNum);
// Set sampler in constant buffer so it does not get unset later.
dMemcpy(mConstBuffer + handle->mOffset, &handle->mLocation, handle->getSize());
}
}
glUseProgram(0);
}
GFXShaderConstHandle* GFXGLShader::getShaderConstHandle(const String& name)
{
HandleMap::Iterator i = mHandles.find(name);
if(i != mHandles.end())
return i->value;
else
{
GFXGLShaderConstHandle* handle = new GFXGLShaderConstHandle( this );
mHandles[ name ] = handle;
return handle;
}
}
void GFXGLShader::setConstantsFromBuffer(GFXGLShaderConstBuffer* buffer)
{
for(Vector<GFXGLShaderConstHandle*>::iterator i = mValidHandles.begin(); i != mValidHandles.end(); ++i)
{
GFXGLShaderConstHandle* handle = *i;
AssertFatal(handle, "GFXGLShader::setConstantsFromBuffer - Null handle");
// Don't set if the value has not be changed.
if(dMemcmp(mConstBuffer + handle->mOffset, buffer->mBuffer + handle->mOffset, handle->getSize()) == 0)
continue;
// Copy new value into our const buffer and set in GL.
dMemcpy(mConstBuffer + handle->mOffset, buffer->mBuffer + handle->mOffset, handle->getSize());
switch(handle->mDesc.constType)
{
case GFXSCT_Float:
glUniform1fv(handle->mLocation, handle->mDesc.arraySize, (GLfloat*)(mConstBuffer + handle->mOffset));
break;
case GFXSCT_Float2:
glUniform2fv(handle->mLocation, handle->mDesc.arraySize, (GLfloat*)(mConstBuffer + handle->mOffset));
break;
case GFXSCT_Float3:
glUniform3fv(handle->mLocation, handle->mDesc.arraySize, (GLfloat*)(mConstBuffer + handle->mOffset));
break;
case GFXSCT_Float4:
glUniform4fv(handle->mLocation, handle->mDesc.arraySize, (GLfloat*)(mConstBuffer + handle->mOffset));
break;
case GFXSCT_Int:
case GFXSCT_Sampler:
case GFXSCT_SamplerCube:
glUniform1iv(handle->mLocation, handle->mDesc.arraySize, (GLint*)(mConstBuffer + handle->mOffset));
break;
case GFXSCT_Int2:
glUniform2iv(handle->mLocation, handle->mDesc.arraySize, (GLint*)(mConstBuffer + handle->mOffset));
break;
case GFXSCT_Int3:
glUniform3iv(handle->mLocation, handle->mDesc.arraySize, (GLint*)(mConstBuffer + handle->mOffset));
break;
case GFXSCT_Int4:
glUniform4iv(handle->mLocation, handle->mDesc.arraySize, (GLint*)(mConstBuffer + handle->mOffset));
break;
case GFXSCT_Float2x2:
glUniformMatrix2fv(handle->mLocation, handle->mDesc.arraySize, true, (GLfloat*)(mConstBuffer + handle->mOffset));
break;
case GFXSCT_Float3x3:
glUniformMatrix3fv(handle->mLocation, handle->mDesc.arraySize, true, (GLfloat*)(mConstBuffer + handle->mOffset));
break;
case GFXSCT_Float4x4:
glUniformMatrix4fv(handle->mLocation, handle->mDesc.arraySize, true, (GLfloat*)(mConstBuffer + handle->mOffset));
break;
}
}
}
GFXShaderConstBufferRef GFXGLShader::allocConstBuffer()
{
GFXGLShaderConstBuffer* buffer = new GFXGLShaderConstBuffer(this, mConstBufferSize, mConstBuffer);
buffer->registerResourceWithDevice(getOwningDevice());
mActiveBuffers.push_back( buffer );
return buffer;
}
void GFXGLShader::useProgram()
{
glUseProgram(mProgram);
}
void GFXGLShader::zombify()
{
clearShaders();
dMemset(mConstBuffer, 0, mConstBufferSize);
}
char* GFXGLShader::_handleIncludes( const Torque::Path& path, FileStream *s )
{
// TODO: The #line pragma on GLSL takes something called a
// "source-string-number" which it then never explains.
//
// Until i resolve this mystery i disabled this.
//
//String linePragma = String::ToString( "#line 1 \r\n");
//U32 linePragmaLen = linePragma.length();
U32 shaderLen = s->getStreamSize();
char* buffer = (char*)dMalloc(shaderLen + 1);
//dStrncpy( buffer, linePragma.c_str(), linePragmaLen );
s->read(shaderLen, buffer);
buffer[shaderLen] = 0;
char* p = dStrstr(buffer, "#include");
while(p)
{
char* q = p;
p += 8;
if(dIsspace(*p))
{
U32 n = 0;
while(dIsspace(*p)) ++p;
AssertFatal(*p == '"', "Bad #include directive");
++p;
static char includeFile[256];
while(*p != '"')
{
AssertFatal(*p != 0, "Bad #include directive");
includeFile[n++] = *p++;
AssertFatal(n < sizeof(includeFile), "#include directive too long");
}
++p;
includeFile[n] = 0;
// First try it as a local file.
Torque::Path includePath = Torque::Path::Join(path.getPath(), '/', includeFile);
includePath = Torque::Path::CompressPath(includePath);
FileStream includeStream;
if ( !includeStream.open( includePath, Torque::FS::File::Read ) )
{
// Try again assuming the path is absolute
// and/or relative.
includePath = String( includeFile );
includePath = Torque::Path::CompressPath(includePath);
if ( !includeStream.open( includePath, Torque::FS::File::Read ) )
{
AssertISV(false, avar("failed to open include '%s'.", includePath.getFullPath().c_str()));
if ( smLogErrors )
Con::errorf( "GFXGLShader::_handleIncludes - Failed to open include '%s'.",
includePath.getFullPath().c_str() );
// Fail... don't return the buffer.
dFree(buffer);
return NULL;
}
}
char* includedText = _handleIncludes(includePath, &includeStream);
// If a sub-include fails... cleanup and return.
if ( !includedText )
{
dFree(buffer);
return NULL;
}
// TODO: Disabled till this is fixed correctly.
//
// Count the number of lines in the file
// before the include.
/*
U32 includeLine = 0;
{
char* nl = dStrstr( buffer, "\n" );
while ( nl )
{
includeLine++;
nl = dStrstr( nl, "\n" );
if(nl) ++nl;
}
}
*/
String manip(buffer);
manip.erase(q-buffer, p-q);
String sItx(includedText);
// TODO: Disabled till this is fixed correctly.
//
// Add a new line pragma to restore the proper
// file and line number after the include.
//sItx += String::ToString( "\r\n#line %d \r\n", includeLine );
dFree(includedText);
manip.insert(q-buffer, sItx);
char* manipBuf = dStrdup(manip.c_str());
p = manipBuf + (p - buffer);
dFree(buffer);
buffer = manipBuf;
}
p = dStrstr(p, "#include");
}
return buffer;
}
bool GFXGLShader::_loadShaderFromStream( GLuint shader,
const Torque::Path &path,
FileStream *s,
const Vector<GFXShaderMacro> &macros )
{
Vector<char*> buffers;
Vector<U32> lengths;
// The GLSL version declaration must go first!
const char *versionDecl = "#version 120\r\n\r\n";
buffers.push_back( dStrdup( versionDecl ) );
lengths.push_back( dStrlen( versionDecl ) );
// Now add all the macros.
for( U32 i = 0; i < macros.size(); i++ )
{
String define = String::ToString( "#define %s %s\n", macros[i].name.c_str(), macros[i].value.c_str() );
buffers.push_back( dStrdup( define.c_str() ) );
lengths.push_back( define.length() );
}
// Now finally add the shader source.
U32 shaderLen = s->getStreamSize();
char *buffer = _handleIncludes(path, s);
if ( !buffer )
return false;
buffers.push_back(buffer);
lengths.push_back(shaderLen);
glShaderSource(shader, buffers.size(), (const GLchar**)const_cast<const char**>(buffers.address()), NULL);
// Cleanup the shader source buffer.
for ( U32 i=0; i < buffers.size(); i++ )
dFree( buffers[i] );
glCompileShader(shader);
return true;
}
bool GFXGLShader::initShader( const Torque::Path &file,
bool isVertex,
const Vector<GFXShaderMacro> &macros )
{
GLuint activeShader = glCreateShader(isVertex ? GL_VERTEX_SHADER : GL_FRAGMENT_SHADER);
if(isVertex)
mVertexShader = activeShader;
else
mPixelShader = activeShader;
glAttachShader(mProgram, activeShader);
// Ok it's not in the shader gen manager, so ask Torque for it
FileStream stream;
if ( !stream.open( file, Torque::FS::File::Read ) )
{
AssertISV(false, avar("GFXGLShader::initShader - failed to open shader '%s'.", file.getFullPath().c_str()));
if ( smLogErrors )
Con::errorf( "GFXGLShader::initShader - Failed to open shader file '%s'.",
file.getFullPath().c_str() );
return false;
}
if ( !_loadShaderFromStream( activeShader, file, &stream, macros ) )
return false;
GLint compile;
glGetShaderiv(activeShader, GL_COMPILE_STATUS, &compile);
// Dump the info log to the console
U32 logLength = 0;
glGetShaderiv(activeShader, GL_INFO_LOG_LENGTH, (GLint*)&logLength);
GLint compileStatus = GL_TRUE;
if ( logLength )
{
FrameAllocatorMarker fam;
char* log = (char*)fam.alloc(logLength);
glGetShaderInfoLog(activeShader, logLength, NULL, log);
// Always print errors
glGetShaderiv( activeShader, GL_COMPILE_STATUS, &compileStatus );
if ( compileStatus == GL_FALSE )
{
if ( smLogErrors )
{
Con::errorf( "GFXGLShader::initShader - Error compiling shader!" );
Con::errorf( "Program %s: %s", file.getFullPath().c_str(), log );
}
}
else if ( smLogWarnings )
Con::warnf( "Program %s: %s", file.getFullPath().c_str(), log );
}
return compileStatus != GL_FALSE;
}
/// Returns our list of shader constants, the material can get this and just set the constants it knows about
const Vector<GFXShaderConstDesc>& GFXGLShader::getShaderConstDesc() const
{
return mConstants;
}
/// Returns the alignment value for constType
U32 GFXGLShader::getAlignmentValue(const GFXShaderConstType constType) const
{
// Alignment is the same thing as size for us.
return shaderConstTypeSize(constType);
}
const String GFXGLShader::describeSelf() const
{
String ret;
ret = String::ToString(" Program: %i", mProgram);
ret += String::ToString(" Vertex Path: %s", mVertexFile.getFullPath().c_str());
ret += String::ToString(" Pixel Path: %s", mPixelFile.getFullPath().c_str());
return ret;
}

View file

@ -0,0 +1,157 @@
//-----------------------------------------------------------------------------
// Copyright (c) 2012 GarageGames, LLC
//
// Permission is hereby granted, free of charge, to any person obtaining a copy
// of this software and associated documentation files (the "Software"), to
// deal in the Software without restriction, including without limitation the
// rights to use, copy, modify, merge, publish, distribute, sublicense, and/or
// sell copies of the Software, and to permit persons to whom the Software is
// furnished to do so, subject to the following conditions:
//
// The above copyright notice and this permission notice shall be included in
// all copies or substantial portions of the Software.
//
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
// FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS
// IN THE SOFTWARE.
//-----------------------------------------------------------------------------
#ifndef _GFXGLSHADER_H_
#define _GFXGLSHADER_H_
#include "core/util/refBase.h"
#include "gfx/gfxShader.h"
#include "gfx/gl/ggl/ggl.h"
#include "core/util/tSignal.h"
#include "core/util/tDictionary.h"
class GFXGLShaderConstHandle;
class FileStream;
class GFXGLShaderConstBuffer;
class GFXGLShader : public GFXShader
{
typedef Map<String, GFXGLShaderConstHandle*> HandleMap;
public:
GFXGLShader();
virtual ~GFXGLShader();
/// @name GFXShader interface
/// @{
virtual GFXShaderConstHandle* getShaderConstHandle(const String& name);
/// Returns our list of shader constants, the material can get this and just set the constants it knows about
virtual const Vector<GFXShaderConstDesc>& getShaderConstDesc() const;
/// Returns the alignment value for constType
virtual U32 getAlignmentValue(const GFXShaderConstType constType) const;
virtual GFXShaderConstBufferRef allocConstBuffer();
/// @}
/// @name GFXResource interface
/// @{
virtual void zombify();
virtual void resurrect() { reload(); }
virtual const String describeSelf() const;
/// @}
/// Activates this shader in the GL context.
void useProgram();
protected:
friend class GFXGLShaderConstBuffer;
friend class GFXGLShaderConstHandle;
virtual bool _init();
bool initShader( const Torque::Path &file,
bool isVertex,
const Vector<GFXShaderMacro> &macros );
void clearShaders();
void initConstantDescs();
void initHandles();
void setConstantsFromBuffer(GFXGLShaderConstBuffer* buffer);
static char* _handleIncludes( const Torque::Path &path, FileStream *s );
static bool _loadShaderFromStream( GLuint shader,
const Torque::Path& path,
FileStream* s,
const Vector<GFXShaderMacro>& macros );
/// @name Internal GL handles
/// @{
GLuint mVertexShader;
GLuint mPixelShader;
GLuint mProgram;
/// @}
Vector<GFXShaderConstDesc> mConstants;
U32 mConstBufferSize;
U8* mConstBuffer;
HandleMap mHandles;
Vector<GFXGLShaderConstHandle*> mValidHandles;
};
class GFXGLShaderConstBuffer : public GFXShaderConstBuffer
{
public:
GFXGLShaderConstBuffer(GFXGLShader* shader, U32 bufSize, U8* existingConstants);
~GFXGLShaderConstBuffer();
/// Called by GFXGLDevice to activate this buffer.
void activate();
/// Called when the shader this buffer references is reloaded.
void onShaderReload( GFXGLShader *shader );
// GFXShaderConstBuffer
virtual GFXShader* getShader() { return mShader; }
virtual void set(GFXShaderConstHandle* handle, const F32 fv);
virtual void set(GFXShaderConstHandle* handle, const Point2F& fv);
virtual void set(GFXShaderConstHandle* handle, const Point3F& fv);
virtual void set(GFXShaderConstHandle* handle, const Point4F& fv);
virtual void set(GFXShaderConstHandle* handle, const PlaneF& fv);
virtual void set(GFXShaderConstHandle* handle, const ColorF& fv);
virtual void set(GFXShaderConstHandle* handle, const S32 f);
virtual void set(GFXShaderConstHandle* handle, const Point2I& fv);
virtual void set(GFXShaderConstHandle* handle, const Point3I& fv);
virtual void set(GFXShaderConstHandle* handle, const Point4I& fv);
virtual void set(GFXShaderConstHandle* handle, const AlignedArray<F32>& fv);
virtual void set(GFXShaderConstHandle* handle, const AlignedArray<Point2F>& fv);
virtual void set(GFXShaderConstHandle* handle, const AlignedArray<Point3F>& fv);
virtual void set(GFXShaderConstHandle* handle, const AlignedArray<Point4F>& fv);
virtual void set(GFXShaderConstHandle* handle, const AlignedArray<S32>& fv);
virtual void set(GFXShaderConstHandle* handle, const AlignedArray<Point2I>& fv);
virtual void set(GFXShaderConstHandle* handle, const AlignedArray<Point3I>& fv);
virtual void set(GFXShaderConstHandle* handle, const AlignedArray<Point4I>& fv);
virtual void set(GFXShaderConstHandle* handle, const MatrixF& mat, const GFXShaderConstType matType = GFXSCT_Float4x4);
virtual void set(GFXShaderConstHandle* handle, const MatrixF* mat, const U32 arraySize, const GFXShaderConstType matrixType = GFXSCT_Float4x4);
// GFXResource
virtual const String describeSelf() const;
virtual void zombify() {}
virtual void resurrect() {}
private:
friend class GFXGLShader;
U8* mBuffer;
WeakRefPtr<GFXGLShader> mShader;
template<typename ConstType>
void internalSet(GFXShaderConstHandle* handle, const ConstType& param);
template<typename ConstType>
void internalSet(GFXShaderConstHandle* handle, const AlignedArray<ConstType>& fv);
};
#endif // _GFXGLSHADER_H_

View file

@ -0,0 +1,187 @@
//-----------------------------------------------------------------------------
// Copyright (c) 2012 GarageGames, LLC
//
// Permission is hereby granted, free of charge, to any person obtaining a copy
// of this software and associated documentation files (the "Software"), to
// deal in the Software without restriction, including without limitation the
// rights to use, copy, modify, merge, publish, distribute, sublicense, and/or
// sell copies of the Software, and to permit persons to whom the Software is
// furnished to do so, subject to the following conditions:
//
// The above copyright notice and this permission notice shall be included in
// all copies or substantial portions of the Software.
//
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
// FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS
// IN THE SOFTWARE.
//-----------------------------------------------------------------------------
#include "gfx/gl/gfxGLStateBlock.h"
#include "gfx/gl/gfxGLDevice.h"
#include "gfx/gl/gfxGLEnumTranslate.h"
#include "gfx/gl/gfxGLUtils.h"
#include "gfx/gl/gfxGLTextureObject.h"
GFXGLStateBlock::GFXGLStateBlock(const GFXStateBlockDesc& desc) :
mDesc(desc),
mCachedHashValue(desc.getHashValue())
{
}
GFXGLStateBlock::~GFXGLStateBlock()
{
}
/// Returns the hash value of the desc that created this block
U32 GFXGLStateBlock::getHashValue() const
{
return mCachedHashValue;
}
/// Returns a GFXStateBlockDesc that this block represents
const GFXStateBlockDesc& GFXGLStateBlock::getDesc() const
{
return mDesc;
}
/// Called by OpenGL device to active this state block.
/// @param oldState The current state, used to make sure we don't set redundant states on the device. Pass NULL to reset all states.
void GFXGLStateBlock::activate(const GFXGLStateBlock* oldState)
{
// Big scary warning copied from Apple docs
// http://developer.apple.com/documentation/GraphicsImaging/Conceptual/OpenGL-MacProgGuide/opengl_performance/chapter_13_section_2.html#//apple_ref/doc/uid/TP40001987-CH213-SW12
// Don't set a state that's already set. Once a feature is enabled, it does not need to be enabled again.
// Calling an enable function more than once does nothing except waste time because OpenGL does not check
// the state of a feature when you call glEnable or glDisable. For instance, if you call glEnable(GL_LIGHTING)
// more than once, OpenGL does not check to see if the lighting state is already enabled. It simply updates
// the state value even if that value is identical to the current value.
#define STATE_CHANGE(state) (!oldState || oldState->mDesc.state != mDesc.state)
#define TOGGLE_STATE(state, enum) if(mDesc.state) glEnable(enum); else glDisable(enum)
#define CHECK_TOGGLE_STATE(state, enum) if(!oldState || oldState->mDesc.state != mDesc.state) if(mDesc.state) glEnable(enum); else glDisable(enum)
// Blending
CHECK_TOGGLE_STATE(blendEnable, GL_BLEND);
if(STATE_CHANGE(blendSrc) || STATE_CHANGE(blendDest))
glBlendFunc(GFXGLBlend[mDesc.blendSrc], GFXGLBlend[mDesc.blendDest]);
if(STATE_CHANGE(blendOp))
glBlendEquation(GFXGLBlendOp[mDesc.blendOp]);
// Alpha testing
CHECK_TOGGLE_STATE(alphaTestEnable, GL_ALPHA_TEST);
if(STATE_CHANGE(alphaTestFunc) || STATE_CHANGE(alphaTestRef))
glAlphaFunc(GFXGLCmpFunc[mDesc.alphaTestFunc], (F32) mDesc.alphaTestRef * 1.0f/255.0f);
// Color write masks
if(STATE_CHANGE(colorWriteRed) || STATE_CHANGE(colorWriteBlue) || STATE_CHANGE(colorWriteGreen) || STATE_CHANGE(colorWriteAlpha))
glColorMask(mDesc.colorWriteRed, mDesc.colorWriteBlue, mDesc.colorWriteGreen, mDesc.colorWriteAlpha);
// Culling
if(STATE_CHANGE(cullMode))
{
TOGGLE_STATE(cullMode, GL_CULL_FACE);
glCullFace(GFXGLCullMode[mDesc.cullMode]);
}
// Depth
CHECK_TOGGLE_STATE(zEnable, GL_DEPTH_TEST);
if(STATE_CHANGE(zFunc))
glDepthFunc(GFXGLCmpFunc[mDesc.zFunc]);
if(STATE_CHANGE(zBias))
{
if (mDesc.zBias == 0)
{
glDisable(GL_POLYGON_OFFSET_FILL);
} else {
F32 bias = mDesc.zBias * 10000.0f;
glEnable(GL_POLYGON_OFFSET_FILL);
glPolygonOffset(bias, bias);
}
}
if(STATE_CHANGE(zWriteEnable))
glDepthMask(mDesc.zWriteEnable);
// Stencil
CHECK_TOGGLE_STATE(stencilEnable, GL_STENCIL_TEST);
if(STATE_CHANGE(stencilFunc) || STATE_CHANGE(stencilRef) || STATE_CHANGE(stencilMask))
glStencilFunc(GFXGLCmpFunc[mDesc.stencilFunc], mDesc.stencilRef, mDesc.stencilMask);
if(STATE_CHANGE(stencilFailOp) || STATE_CHANGE(stencilZFailOp) || STATE_CHANGE(stencilPassOp))
glStencilOp(GFXGLStencilOp[mDesc.stencilFailOp], GFXGLStencilOp[mDesc.stencilZFailOp], GFXGLStencilOp[mDesc.stencilPassOp]);
if(STATE_CHANGE(stencilWriteMask))
glStencilMask(mDesc.stencilWriteMask);
// "Misc"
CHECK_TOGGLE_STATE(ffLighting, GL_LIGHTING);
glColorMaterial(GL_FRONT_AND_BACK, GL_AMBIENT_AND_DIFFUSE);
CHECK_TOGGLE_STATE(vertexColorEnable, GL_COLOR_MATERIAL);
if(STATE_CHANGE(fillMode))
glPolygonMode(GL_FRONT_AND_BACK, GFXGLFillMode[mDesc.fillMode]);
#undef CHECK_STATE
#undef TOGGLE_STATE
#undef CHECK_TOGGLE_STATE
// TODO: states added for detail blend
// Non per object texture mode states
for (U32 i = 0; i < getMin(getOwningDevice()->getNumSamplers(), (U32) TEXTURE_STAGE_COUNT); i++)
{
GFXGLTextureObject* tex = static_cast<GFXGLTextureObject*>(getOwningDevice()->getCurrentTexture(i));
const GFXSamplerStateDesc &ssd = mDesc.samplers[i];
bool updateTexParam = true;
glActiveTexture(GL_TEXTURE0 + i);
switch (ssd.textureColorOp)
{
case GFXTOPDisable :
if(!tex)
break;
glDisable(GL_TEXTURE_2D);
updateTexParam = false;
break;
case GFXTOPModulate :
glEnable(GL_TEXTURE_2D);
glTexEnvi(GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_MODULATE);
break;
case GFXTOPAdd :
glEnable(GL_TEXTURE_2D);
glTexEnvi(GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_ADD);
break;
default :
glEnable(GL_TEXTURE_2D);
glTexEnvi(GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_MODULATE);
break;
}
#define SSF(state, enum, value, tex) if(!oldState || oldState->mDesc.samplers[i].state != mDesc.samplers[i].state) glTexParameteri(tex->getBinding(), enum, value)
#define SSW(state, enum, value, tex) if(!oldState || oldState->mDesc.samplers[i].state != mDesc.samplers[i].state) glTexParameteri(tex->getBinding(), enum, !tex->mIsNPoT2 ? value : GL_CLAMP_TO_EDGE)
// Per object texture mode states.
// TODO: Check dirty flag of samplers[i] and don't do this if it's dirty (it'll happen in the texture bind)
if (updateTexParam && tex)
{
SSF(minFilter, GL_TEXTURE_MIN_FILTER, minificationFilter(ssd.minFilter, ssd.mipFilter, tex->mMipLevels), tex);
SSF(mipFilter, GL_TEXTURE_MIN_FILTER, minificationFilter(ssd.minFilter, ssd.mipFilter, tex->mMipLevels), tex);
SSF(magFilter, GL_TEXTURE_MAG_FILTER, GFXGLTextureFilter[ssd.magFilter], tex);
SSW(addressModeU, GL_TEXTURE_WRAP_S, GFXGLTextureAddress[ssd.addressModeU], tex);
SSW(addressModeV, GL_TEXTURE_WRAP_T, GFXGLTextureAddress[ssd.addressModeV], tex);
if( ( !oldState || oldState->mDesc.samplers[i].maxAnisotropy != ssd.maxAnisotropy ) &&
static_cast< GFXGLDevice* >( GFX )->supportsAnisotropic() )
glTexParameterf(GL_TEXTURE_2D, GL_TEXTURE_MAX_ANISOTROPY_EXT, ssd.maxAnisotropy);
if( ( !oldState || oldState->mDesc.samplers[i].mipLODBias != ssd.mipLODBias ) )
glTexEnvf(GL_TEXTURE_FILTER_CONTROL_EXT, GL_TEXTURE_LOD_BIAS_EXT, ssd.mipLODBias);
}
}
#undef SSF
#undef SSW
}

View file

@ -0,0 +1,65 @@
//-----------------------------------------------------------------------------
// Copyright (c) 2012 GarageGames, LLC
//
// Permission is hereby granted, free of charge, to any person obtaining a copy
// of this software and associated documentation files (the "Software"), to
// deal in the Software without restriction, including without limitation the
// rights to use, copy, modify, merge, publish, distribute, sublicense, and/or
// sell copies of the Software, and to permit persons to whom the Software is
// furnished to do so, subject to the following conditions:
//
// The above copyright notice and this permission notice shall be included in
// all copies or substantial portions of the Software.
//
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
// FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS
// IN THE SOFTWARE.
//-----------------------------------------------------------------------------
#ifndef _GFXGLSTATEBLOCK_H_
#define _GFXGLSTATEBLOCK_H_
#include "gfx/gfxStateBlock.h"
class GFXGLStateBlock : public GFXStateBlock
{
public:
//
// GFXGLStateBlock interface
//
GFXGLStateBlock(const GFXStateBlockDesc& desc);
virtual ~GFXGLStateBlock();
/// Called by OpenGL device to active this state block.
/// @param oldState The current state, used to make sure we don't set redundant states on the device. Pass NULL to reset all states.
void activate(const GFXGLStateBlock* oldState);
//
// GFXStateBlock interface
//
/// Returns the hash value of the desc that created this block
virtual U32 getHashValue() const;
/// Returns a GFXStateBlockDesc that this block represents
virtual const GFXStateBlockDesc& getDesc() const;
//
// GFXResource
//
virtual void zombify() { }
/// When called the resource should restore all device sensitive information destroyed by zombify()
virtual void resurrect() { }
private:
GFXStateBlockDesc mDesc;
U32 mCachedHashValue;
};
typedef StrongRefPtr<GFXGLStateBlock> GFXGLStateBlockRef;
#endif

View file

@ -0,0 +1,333 @@
//-----------------------------------------------------------------------------
// Copyright (c) 2012 GarageGames, LLC
//
// Permission is hereby granted, free of charge, to any person obtaining a copy
// of this software and associated documentation files (the "Software"), to
// deal in the Software without restriction, including without limitation the
// rights to use, copy, modify, merge, publish, distribute, sublicense, and/or
// sell copies of the Software, and to permit persons to whom the Software is
// furnished to do so, subject to the following conditions:
//
// The above copyright notice and this permission notice shall be included in
// all copies or substantial portions of the Software.
//
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
// FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS
// IN THE SOFTWARE.
//-----------------------------------------------------------------------------
#include "platform/platform.h"
#include "gfx/gl/gfxGLTextureManager.h"
#include "gfx/gl/gfxGLEnumTranslate.h"
#include "gfx/gfxCardProfile.h"
#include "core/util/safeDelete.h"
#include "gfx/gl/gfxGLUtils.h"
#include <squish.h>
//-----------------------------------------------------------------------------
// Constructor
//-----------------------------------------------------------------------------
GFXGLTextureManager::GFXGLTextureManager()
{
}
//-----------------------------------------------------------------------------
// Destructor
//-----------------------------------------------------------------------------
GFXGLTextureManager::~GFXGLTextureManager()
{
SAFE_DELETE_ARRAY( mHashTable );
}
//-----------------------------------------------------------------------------
// createTexture
//-----------------------------------------------------------------------------
GFXTextureObject *GFXGLTextureManager::_createTextureObject( U32 height,
U32 width,
U32 depth,
GFXFormat format,
GFXTextureProfile *profile,
U32 numMipLevels,
bool forceMips,
S32 antialiasLevel,
GFXTextureObject *inTex )
{
AssertFatal(format >= 0 && format < GFXFormat_COUNT, "GFXGLTextureManager::_createTexture - invalid format!");
GFXGLTextureObject *retTex;
if ( inTex )
{
AssertFatal( dynamic_cast<GFXGLTextureObject*>( inTex ), "GFXGLTextureManager::_createTexture() - Bad inTex type!" );
retTex = static_cast<GFXGLTextureObject*>( inTex );
retTex->release();
}
else
{
retTex = new GFXGLTextureObject( GFX, profile );
retTex->registerResourceWithDevice( GFX );
}
innerCreateTexture(retTex, height, width, depth, format, profile, numMipLevels, forceMips);
return retTex;
}
//-----------------------------------------------------------------------------
// innerCreateTexture
//-----------------------------------------------------------------------------
// This just creates the texture, no info is actually loaded to it. We do that later.
void GFXGLTextureManager::innerCreateTexture( GFXGLTextureObject *retTex,
U32 height,
U32 width,
U32 depth,
GFXFormat format,
GFXTextureProfile *profile,
U32 numMipLevels,
bool forceMips)
{
// No 24 bit formats. They trigger various oddities because hardware (and Apple's drivers apparently...) don't natively support them.
if(format == GFXFormatR8G8B8)
format = GFXFormatR8G8B8A8;
retTex->mFormat = format;
retTex->mIsZombie = false;
retTex->mIsNPoT2 = false;
GLenum binding = (depth == 0) ? GL_TEXTURE_2D : GL_TEXTURE_3D;
if((profile->testFlag(GFXTextureProfile::RenderTarget) || profile->testFlag(GFXTextureProfile::ZTarget)) && (!isPow2(width) || !isPow2(height)) && !depth)
retTex->mIsNPoT2 = true;
retTex->mBinding = binding;
// Bind it
glActiveTexture(GL_TEXTURE0);
PRESERVE_2D_TEXTURE();
PRESERVE_3D_TEXTURE();
glBindTexture(binding, retTex->getHandle());
// Create it
// TODO: Reenable mipmaps on render targets when Apple fixes their drivers
if(forceMips && !retTex->mIsNPoT2)
{
glTexParameteri(binding, GL_GENERATE_MIPMAP_SGIS, GL_TRUE);
retTex->mMipLevels = 0;
}
else if(profile->testFlag(GFXTextureProfile::NoMipmap) || profile->testFlag(GFXTextureProfile::RenderTarget) || numMipLevels == 1 || retTex->mIsNPoT2)
{
retTex->mMipLevels = 1;
}
else
{
glTexParameteri(binding, GL_GENERATE_MIPMAP_SGIS, GL_TRUE);
retTex->mMipLevels = 0;
}
if(!retTex->mIsNPoT2)
{
if(!isPow2(width))
width = getNextPow2(width);
if(!isPow2(height))
height = getNextPow2(height);
if(depth && !isPow2(depth))
depth = getNextPow2(depth);
}
AssertFatal(GFXGLTextureInternalFormat[format] != GL_ZERO, "GFXGLTextureManager::innerCreateTexture - invalid internal format");
AssertFatal(GFXGLTextureFormat[format] != GL_ZERO, "GFXGLTextureManager::innerCreateTexture - invalid format");
AssertFatal(GFXGLTextureType[format] != GL_ZERO, "GFXGLTextureManager::innerCreateTexture - invalid type");
if(binding != GL_TEXTURE_3D)
glTexImage2D(binding, 0, GFXGLTextureInternalFormat[format], width, height, 0, GFXGLTextureFormat[format], GFXGLTextureType[format], NULL);
else
glTexImage3D(GL_TEXTURE_3D, 0, GFXGLTextureInternalFormat[format], width, height, depth, 0, GFXGLTextureFormat[format], GFXGLTextureType[format], NULL);
// Complete the texture
glTexParameteri(binding, GL_TEXTURE_MIN_FILTER, GL_LINEAR);
glTexParameteri(binding, GL_TEXTURE_MAG_FILTER, GL_LINEAR);
glTexParameteri(binding, GL_TEXTURE_WRAP_S, GL_CLAMP_TO_EDGE);
glTexParameteri(binding, GL_TEXTURE_WRAP_T, GL_CLAMP_TO_EDGE);
if(binding == GL_TEXTURE_3D)
glTexParameteri(binding, GL_TEXTURE_WRAP_R, GL_CLAMP_TO_EDGE);
// Get the size from GL (you never know...)
GLint texHeight, texWidth, texDepth = 0;
glGetTexLevelParameteriv(binding, 0, GL_TEXTURE_WIDTH, &texWidth);
glGetTexLevelParameteriv(binding, 0, GL_TEXTURE_HEIGHT, &texHeight);
if(binding == GL_TEXTURE_3D)
glGetTexLevelParameteriv(binding, 0, GL_TEXTURE_DEPTH, &texDepth);
retTex->mTextureSize.set(texWidth, texHeight, texDepth);
}
//-----------------------------------------------------------------------------
// loadTexture - GBitmap
//-----------------------------------------------------------------------------
static void _fastTextureLoad(GFXGLTextureObject* texture, GBitmap* pDL)
{
glBindBuffer(GL_PIXEL_UNPACK_BUFFER_ARB, texture->getBuffer());
U32 bufSize = pDL->getWidth(0) * pDL->getHeight(0) * pDL->getBytesPerPixel();
glBufferData(GL_PIXEL_UNPACK_BUFFER_ARB, bufSize, NULL, GL_STREAM_DRAW);
U8* pboMemory = (U8*)glMapBuffer(GL_PIXEL_UNPACK_BUFFER_ARB, GL_WRITE_ONLY);
if(pDL->getFormat() == GFXFormatR8G8B8A8 || pDL->getFormat() == GFXFormatR8G8B8X8)
GFX->getDeviceSwizzle32()->ToBuffer(pboMemory, pDL->getBits(0), bufSize);
else
dMemcpy(pboMemory, pDL->getBits(0), bufSize);
glUnmapBuffer(GL_PIXEL_UNPACK_BUFFER_ARB);
glTexSubImage2D(texture->getBinding(), 0, 0, 0, pDL->getWidth(0), pDL->getHeight(0), GFXGLTextureFormat[pDL->getFormat()], GFXGLTextureType[pDL->getFormat()], NULL);
glBindBuffer(GL_PIXEL_UNPACK_BUFFER_ARB, 0);
}
static void _slowTextureLoad(GFXGLTextureObject* texture, GBitmap* pDL)
{
glTexSubImage2D(texture->getBinding(), 0, 0, 0, pDL->getWidth(0), pDL->getHeight(0), GFXGLTextureFormat[pDL->getFormat()], GFXGLTextureType[pDL->getFormat()], pDL->getBits(0));
}
bool GFXGLTextureManager::_loadTexture(GFXTextureObject *aTexture, GBitmap *pDL)
{
GFXGLTextureObject *texture = static_cast<GFXGLTextureObject*>(aTexture);
AssertFatal(texture->getBinding() == GL_TEXTURE_2D,
"GFXGLTextureManager::_loadTexture(GBitmap) - This method can only be used with 2D textures");
if(texture->getBinding() != GL_TEXTURE_2D)
return false;
// No 24bit formats.
if(pDL->getFormat() == GFXFormatR8G8B8)
pDL->setFormat(GFXFormatR8G8B8A8);
// Bind to edit
glActiveTexture(GL_TEXTURE0);
PRESERVE_2D_TEXTURE();
glBindTexture(texture->getBinding(), texture->getHandle());
if(pDL->getFormat() == GFXFormatR8G8B8A8 || pDL->getFormat() == GFXFormatR8G8B8X8)
_fastTextureLoad(texture, pDL);
else
_slowTextureLoad(texture, pDL);
glBindTexture(texture->getBinding(), 0);
return true;
}
bool GFXGLTextureManager::_loadTexture(GFXTextureObject *aTexture, DDSFile *dds)
{
AssertFatal(!(dds->mFormat == GFXFormatDXT2 || dds->mFormat == GFXFormatDXT4), "GFXGLTextureManager::_loadTexture - OpenGL does not support DXT2 or DXT4 compressed textures");
GFXGLTextureObject* texture = static_cast<GFXGLTextureObject*>(aTexture);
AssertFatal(texture->getBinding() == GL_TEXTURE_2D,
"GFXGLTextureManager::_loadTexture(DDSFile) - This method can only be used with 2D textures");
if(texture->getBinding() != GL_TEXTURE_2D)
return false;
glActiveTexture(GL_TEXTURE0);
PRESERVE_2D_TEXTURE();
glBindTexture(texture->getBinding(), texture->getHandle());
U32 numMips = dds->mSurfaces[0]->mMips.size();
if(GFX->getCardProfiler()->queryProfile("GL::Workaround::noManualMips"))
numMips = 1;
for(U32 i = 0; i < numMips; i++)
{
if(dds->mFormat == GFXFormatDXT1 || dds->mFormat == GFXFormatDXT3 || dds->mFormat == GFXFormatDXT5)
{
if((!isPow2(dds->getWidth()) || !isPow2(dds->getHeight())) && GFX->getCardProfiler()->queryProfile("GL::Workaround::noCompressedNPoTTextures"))
{
U32 squishFlag = squish::kDxt1;
switch (dds->mFormat)
{
case GFXFormatDXT3:
squishFlag = squish::kDxt3;
break;
case GFXFormatDXT5:
squishFlag = squish::kDxt5;
break;
default:
break;
}
U8* uncompressedTex = new U8[dds->getWidth(i) * dds->getHeight(i) * 4];
squish::DecompressImage(uncompressedTex, dds->getWidth(i), dds->getHeight(i), dds->mSurfaces[0]->mMips[i], squishFlag);
glTexSubImage2D(texture->getBinding(), i, 0, 0, dds->getWidth(i), dds->getHeight(i), GL_RGBA, GL_UNSIGNED_BYTE, uncompressedTex);
delete[] uncompressedTex;
}
else
glCompressedTexSubImage2D(texture->getBinding(), i, 0, 0, dds->getWidth(i), dds->getHeight(i), GFXGLTextureInternalFormat[dds->mFormat], dds->getSurfaceSize(dds->getHeight(), dds->getWidth(), i), dds->mSurfaces[0]->mMips[i]);
}
else
glTexSubImage2D(texture->getBinding(), i, 0, 0, dds->getWidth(i), dds->getHeight(i), GFXGLTextureFormat[dds->mFormat], GFXGLTextureType[dds->mFormat], dds->mSurfaces[0]->mMips[i]);
}
glBindTexture(texture->getBinding(), 0);
return true;
}
bool GFXGLTextureManager::_loadTexture(GFXTextureObject *aTexture, void *raw)
{
if(aTexture->getDepth() < 1)
return false;
GFXGLTextureObject* texture = static_cast<GFXGLTextureObject*>(aTexture);
glActiveTexture(GL_TEXTURE0);
PRESERVE_3D_TEXTURE();
glBindTexture(GL_TEXTURE_3D, texture->getHandle());
glTexSubImage3D(GL_TEXTURE_3D, 0, 0, 0, 0, texture->getWidth(), texture->getHeight(), texture->getDepth(), GFXGLTextureFormat[texture->mFormat], GFXGLTextureType[texture->mFormat], raw);
glBindTexture(GL_TEXTURE_3D, 0);
return true;
}
bool GFXGLTextureManager::_freeTexture(GFXTextureObject *texture, bool zombify /*= false*/)
{
if(zombify)
static_cast<GFXGLTextureObject*>(texture)->zombify();
else
static_cast<GFXGLTextureObject*>(texture)->release();
return true;
}
bool GFXGLTextureManager::_refreshTexture(GFXTextureObject *texture)
{
U32 usedStrategies = 0;
GFXGLTextureObject* realTex = static_cast<GFXGLTextureObject*>(texture);
if(texture->mProfile->doStoreBitmap())
{
if(realTex->isZombie())
{
realTex->resurrect();
innerCreateTexture(realTex, texture->getHeight(), texture->getWidth(), texture->getDepth(), texture->mFormat, texture->mProfile, texture->mMipLevels);
}
if(texture->mBitmap)
_loadTexture(texture, texture->mBitmap);
if(texture->mDDS)
return false;
usedStrategies++;
}
if(texture->mProfile->isRenderTarget() || texture->mProfile->isDynamic() || texture->mProfile->isZTarget() || !usedStrategies)
{
realTex->release();
realTex->resurrect();
innerCreateTexture(realTex, texture->getHeight(), texture->getWidth(), texture->getDepth(), texture->mFormat, texture->mProfile, texture->mMipLevels);
realTex->reloadFromCache();
usedStrategies++;
}
AssertFatal(usedStrategies < 2, "GFXGLTextureManager::_refreshTexture - Inconsistent profile flags (store bitmap and dynamic/target");
return true;
}

View file

@ -0,0 +1,62 @@
//-----------------------------------------------------------------------------
// Copyright (c) 2012 GarageGames, LLC
//
// Permission is hereby granted, free of charge, to any person obtaining a copy
// of this software and associated documentation files (the "Software"), to
// deal in the Software without restriction, including without limitation the
// rights to use, copy, modify, merge, publish, distribute, sublicense, and/or
// sell copies of the Software, and to permit persons to whom the Software is
// furnished to do so, subject to the following conditions:
//
// The above copyright notice and this permission notice shall be included in
// all copies or substantial portions of the Software.
//
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
// FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS
// IN THE SOFTWARE.
//-----------------------------------------------------------------------------
#ifndef _GFXGLTEXTUREMANAGER_H
#define _GFXGLTEXTUREMANAGER_H
#include "gfx/gfxDevice.h"
#include "gfx/gfxTextureManager.h"
#include "gfx/gl/gfxGLTextureObject.h"
#include "gfx/gl/ggl/ggl.h"
class GFXGLTextureManager : public GFXTextureManager
{
public:
GFXGLTextureManager();
~GFXGLTextureManager();
protected:
// GFXTextureManager
GFXTextureObject *_createTextureObject( U32 height,
U32 width,
U32 depth,
GFXFormat format,
GFXTextureProfile *profile,
U32 numMipLevels,
bool forceMips = false,
S32 antialiasLevel = 0,
GFXTextureObject *inTex = NULL );
bool _loadTexture(GFXTextureObject *texture, DDSFile *dds);
bool _loadTexture(GFXTextureObject *texture, GBitmap *bmp);
bool _loadTexture(GFXTextureObject *texture, void *raw);
bool _refreshTexture(GFXTextureObject *texture);
bool _freeTexture(GFXTextureObject *texture, bool zombify = false);
private:
friend class GFXGLTextureObject;
/// Creates internal GL texture
void innerCreateTexture(GFXGLTextureObject *obj, U32 height, U32 width, U32 depth, GFXFormat format, GFXTextureProfile *profile, U32 numMipLevels, bool forceMips = false);
};
#endif

View file

@ -0,0 +1,238 @@
//-----------------------------------------------------------------------------
// Copyright (c) 2012 GarageGames, LLC
//
// Permission is hereby granted, free of charge, to any person obtaining a copy
// of this software and associated documentation files (the "Software"), to
// deal in the Software without restriction, including without limitation the
// rights to use, copy, modify, merge, publish, distribute, sublicense, and/or
// sell copies of the Software, and to permit persons to whom the Software is
// furnished to do so, subject to the following conditions:
//
// The above copyright notice and this permission notice shall be included in
// all copies or substantial portions of the Software.
//
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
// FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS
// IN THE SOFTWARE.
//-----------------------------------------------------------------------------
#include "console/console.h"
#include "gfx/gl/ggl/ggl.h"
#include "math/mRect.h"
#include "gfx/gl/gfxGLTextureObject.h"
#include "gfx/gfxDevice.h"
#include "gfx/gl/gfxGLEnumTranslate.h"
#include "gfx/gl/gfxGLTextureManager.h"
#include "gfx/gl/gfxGLUtils.h"
#include "gfx/gfxCardProfile.h"
GFXGLTextureObject::GFXGLTextureObject(GFXDevice * aDevice, GFXTextureProfile *profile) :
GFXTextureObject(aDevice, profile),
mBinding(GL_TEXTURE_2D),
mBytesPerTexel(4),
mLockedRectRect(0, 0, 0, 0),
mGLDevice(static_cast<GFXGLDevice*>(mDevice)),
mZombieCache(NULL)
{
AssertFatal(dynamic_cast<GFXGLDevice*>(mDevice), "GFXGLTextureObject::GFXGLTextureObject - Invalid device type, expected GFXGLDevice!");
glGenTextures(1, &mHandle);
glGenBuffers(1, &mBuffer);
}
GFXGLTextureObject::~GFXGLTextureObject()
{
glDeleteBuffers(1, &mBuffer);
delete[] mZombieCache;
kill();
}
GFXLockedRect* GFXGLTextureObject::lock(U32 mipLevel, RectI *inRect)
{
AssertFatal(mBinding != GL_TEXTURE_3D, "GFXGLTextureObject::lock - We don't support locking 3D textures yet");
U32 width = mTextureSize.x >> mipLevel;
U32 height = mTextureSize.y >> mipLevel;
if(inRect)
{
if((inRect->point.x + inRect->extent.x > width) || (inRect->point.y + inRect->extent.y > height))
AssertFatal(false, "GFXGLTextureObject::lock - Rectangle too big!");
mLockedRectRect = *inRect;
}
else
{
mLockedRectRect = RectI(0, 0, width, height);
}
mLockedRect.pitch = mLockedRectRect.extent.x * mBytesPerTexel;
glBindBuffer(GL_PIXEL_UNPACK_BUFFER_ARB, mBuffer);
// CodeReview [ags 12/19/07] This one texel boundary is necessary to keep the clipmap code from crashing. Figure out why.
glBufferData(GL_PIXEL_UNPACK_BUFFER_ARB, (mLockedRectRect.extent.x + 1) * (mLockedRectRect.extent.y + 1) * mBytesPerTexel, NULL, GL_STREAM_DRAW);
mLockedRect.bits = (U8*)glMapBuffer(GL_PIXEL_UNPACK_BUFFER_ARB, GL_WRITE_ONLY);
glBindBuffer(GL_PIXEL_UNPACK_BUFFER_ARB, 0);
if( !mLockedRect.bits )
return NULL;
return &mLockedRect;
}
void GFXGLTextureObject::unlock(U32 mipLevel)
{
if(!mLockedRect.bits)
return;
glActiveTexture(GL_TEXTURE0);
U32 boundTexture;
glGetIntegerv(GL_TEXTURE_BINDING_2D, (GLint*)&boundTexture);
glBindTexture(GL_TEXTURE_2D, mHandle);
glBindBuffer(GL_PIXEL_UNPACK_BUFFER_ARB, mBuffer);
glUnmapBuffer(GL_PIXEL_UNPACK_BUFFER_ARB);
glTexSubImage2D(GL_TEXTURE_2D, mipLevel, mLockedRectRect.point.x, mLockedRectRect.point.y,
mLockedRectRect.extent.x, mLockedRectRect.extent.y, GL_BGRA, GL_UNSIGNED_BYTE, NULL);
glBindBuffer(GL_PIXEL_UNPACK_BUFFER_ARB, 0);
mLockedRect.bits = NULL;
glBindTexture(GL_TEXTURE_2D, boundTexture);
}
void GFXGLTextureObject::release()
{
glDeleteTextures(1, &mHandle);
glDeleteBuffers(1, &mBuffer);
mHandle = 0;
mBuffer = 0;
}
bool GFXGLTextureObject::copyToBmp(GBitmap * bmp)
{
GLint oldTex;
glGetIntegerv(0x8069, &oldTex);
glBindTexture(GL_TEXTURE_2D, mHandle);
GLint textureFormat = GFXGLTextureFormat[bmp->getFormat()];
// Don't swizzle outgoing textures.
if(textureFormat == GL_BGRA)
textureFormat = GL_RGBA;
glGetTexImage(GL_TEXTURE_2D, 0, textureFormat, GL_UNSIGNED_BYTE, bmp->getWritableBits());
glBindTexture(GL_TEXTURE_2D, oldTex);
return true;
}
void GFXGLTextureObject::bind(U32 textureUnit) const
{
glActiveTexture(GL_TEXTURE0 + textureUnit);
glBindTexture(mBinding, mHandle);
glEnable(mBinding);
GFXGLStateBlockRef sb = mGLDevice->getCurrentStateBlock();
AssertFatal(sb, "GFXGLTextureObject::bind - No active stateblock!");
if (!sb)
return;
const GFXSamplerStateDesc ssd = sb->getDesc().samplers[textureUnit];
glTexParameteri(mBinding, GL_TEXTURE_MIN_FILTER, minificationFilter(ssd.minFilter, ssd.mipFilter, mMipLevels));
glTexParameteri(mBinding, GL_TEXTURE_MAG_FILTER, GFXGLTextureFilter[ssd.magFilter]);
glTexParameteri(mBinding, GL_TEXTURE_WRAP_S, !mIsNPoT2 ? GFXGLTextureAddress[ssd.addressModeU] : GL_CLAMP_TO_EDGE);
glTexParameteri(mBinding, GL_TEXTURE_WRAP_T, !mIsNPoT2 ? GFXGLTextureAddress[ssd.addressModeV] : GL_CLAMP_TO_EDGE);
if(mBinding == GL_TEXTURE_3D)
glTexParameteri(mBinding, GL_TEXTURE_WRAP_R, GFXGLTextureAddress[ssd.addressModeW]);
glTexEnvf(GL_TEXTURE_FILTER_CONTROL, GL_TEXTURE_LOD_BIAS, ssd.mipLODBias);
}
U8* GFXGLTextureObject::getTextureData()
{
U8* data = new U8[mTextureSize.x * mTextureSize.y * mBytesPerTexel];
glBindTexture(GL_TEXTURE_2D, mHandle);
glGetTexImage(GL_TEXTURE_2D, 0, GL_BGRA, GL_UNSIGNED_INT_8_8_8_8_REV, data);
return data;
}
void GFXGLTextureObject::copyIntoCache()
{
glBindTexture(mBinding, mHandle);
U32 cacheSize = mTextureSize.x * mTextureSize.y;
if(mBinding == GL_TEXTURE_3D)
cacheSize *= mTextureSize.z;
cacheSize *= mBytesPerTexel;
mZombieCache = new U8[cacheSize];
glGetTexImage(mBinding, 0, GFXGLTextureFormat[mFormat], GFXGLTextureType[mFormat], mZombieCache);
glBindTexture(mBinding, 0);
}
void GFXGLTextureObject::reloadFromCache()
{
if(!mZombieCache)
return;
if(mBinding == GL_TEXTURE_3D)
{
static_cast<GFXGLTextureManager*>(TEXMGR)->_loadTexture(this, mZombieCache);
delete[] mZombieCache;
mZombieCache = NULL;
return;
}
glBindTexture(mBinding, mHandle);
glTexSubImage2D(mBinding, 0, 0, 0, mTextureSize.x, mTextureSize.y, GFXGLTextureFormat[mFormat], GFXGLTextureType[mFormat], mZombieCache);
if(GFX->getCardProfiler()->queryProfile("GL::Workaround::needsExplicitGenerateMipmap") && mMipLevels != 1)
glGenerateMipmapEXT(mBinding);
delete[] mZombieCache;
mZombieCache = NULL;
mIsZombie = false;
}
void GFXGLTextureObject::zombify()
{
if(mIsZombie)
return;
mIsZombie = true;
if(!mProfile->doStoreBitmap() && !mProfile->isRenderTarget() && !mProfile->isDynamic() && !mProfile->isZTarget())
copyIntoCache();
release();
}
void GFXGLTextureObject::resurrect()
{
if(!mIsZombie)
return;
glGenTextures(1, &mHandle);
glGenBuffers(1, &mBuffer);
}
F32 GFXGLTextureObject::getMaxUCoord() const
{
return mBinding == GL_TEXTURE_2D ? 1.0f : (F32)getWidth();
}
F32 GFXGLTextureObject::getMaxVCoord() const
{
return mBinding == GL_TEXTURE_2D ? 1.0f : (F32)getHeight();
}
const String GFXGLTextureObject::describeSelf() const
{
String ret = Parent::describeSelf();
ret += String::ToString(" GL Handle: %i", mHandle);
return ret;
}

View file

@ -0,0 +1,99 @@
//-----------------------------------------------------------------------------
// Copyright (c) 2012 GarageGames, LLC
//
// Permission is hereby granted, free of charge, to any person obtaining a copy
// of this software and associated documentation files (the "Software"), to
// deal in the Software without restriction, including without limitation the
// rights to use, copy, modify, merge, publish, distribute, sublicense, and/or
// sell copies of the Software, and to permit persons to whom the Software is
// furnished to do so, subject to the following conditions:
//
// The above copyright notice and this permission notice shall be included in
// all copies or substantial portions of the Software.
//
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
// FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS
// IN THE SOFTWARE.
//-----------------------------------------------------------------------------
#ifndef _GFXGLTEXTUREOBJECT_H
#define _GFXGLTEXTUREOBJECT_H
#include "gfx/gfxTextureObject.h"
#include "gfx/gl/ggl/ggl.h"
class GFXGLDevice;
class GFXGLTextureObject : public GFXTextureObject
{
public:
GFXGLTextureObject(GFXDevice * aDevice, GFXTextureProfile *profile);
virtual ~GFXGLTextureObject();
void release();
inline GLuint getHandle() const { return mHandle; }
inline GLenum getBinding() const { return mBinding; }
inline GLuint getBuffer() const { return mBuffer; }
inline bool isZombie() const { return mIsZombie; }
/// Binds the texture to the given texture unit
/// and applies the current sampler state because GL tracks
/// filtering and wrapper per object, while GFX tracks per sampler.
void bind(U32 textureUnit) const;
/// @return An array containing the texture data
/// @note You are responsible for deleting the returned data! (Use delete[])
U8* getTextureData();
virtual F32 getMaxUCoord() const;
virtual F32 getMaxVCoord() const;
void reloadFromCache(); ///< Reloads texture from zombie cache, used by GFXGLTextureManager to resurrect the texture.
#ifdef TORQUE_DEBUG
virtual void pureVirtualCrash() {}
#endif
/// Get/set data from texture (for dynamic textures and render targets)
/// @attention DO NOT READ FROM THE RETURNED RECT! It is not guaranteed to work and may incur significant performance penalties.
virtual GFXLockedRect* lock(U32 mipLevel = 0, RectI *inRect = NULL);
virtual void unlock(U32 mipLevel = 0 );
virtual bool copyToBmp(GBitmap *); ///< Not implemented
bool mIsNPoT2;
// GFXResource interface
virtual void zombify();
virtual void resurrect();
virtual const String describeSelf() const;
private:
friend class GFXGLTextureManager;
typedef GFXTextureObject Parent;
/// Internal GL object
GLuint mHandle;
GLuint mBuffer;
GLenum mBinding;
U32 mBytesPerTexel;
GFXLockedRect mLockedRect;
RectI mLockedRectRect;
/// Pointer to owner device
GFXGLDevice* mGLDevice;
bool mIsZombie;
U8* mZombieCache;
void copyIntoCache();
};
#endif

View file

@ -0,0 +1,438 @@
//-----------------------------------------------------------------------------
// Copyright (c) 2012 GarageGames, LLC
//
// Permission is hereby granted, free of charge, to any person obtaining a copy
// of this software and associated documentation files (the "Software"), to
// deal in the Software without restriction, including without limitation the
// rights to use, copy, modify, merge, publish, distribute, sublicense, and/or
// sell copies of the Software, and to permit persons to whom the Software is
// furnished to do so, subject to the following conditions:
//
// The above copyright notice and this permission notice shall be included in
// all copies or substantial portions of the Software.
//
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
// FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS
// IN THE SOFTWARE.
//-----------------------------------------------------------------------------
#include "console/console.h"
#include "gfx/gl/gfxGLDevice.h"
#include "gfx/gl/gfxGLTextureTarget.h"
#include "gfx/gl/gfxGLTextureObject.h"
#include "gfx/gl/gfxGLCubemap.h"
#include "gfx/gfxTextureManager.h"
#include "gfx/gl/gfxGLUtils.h"
/// Internal struct used to track texture information for FBO attachments
/// This serves as an abstract base so we can deal with cubemaps and standard
/// 2D/Rect textures through the same interface
class _GFXGLTargetDesc
{
public:
_GFXGLTargetDesc(U32 _mipLevel, U32 _zOffset) :
mipLevel(_mipLevel), zOffset(_zOffset)
{
}
virtual ~_GFXGLTargetDesc() {}
virtual U32 getHandle() = 0;
virtual U32 getWidth() = 0;
virtual U32 getHeight() = 0;
virtual U32 getDepth() = 0;
virtual bool hasMips() = 0;
virtual GLenum getBinding() = 0;
U32 getMipLevel() { return mipLevel; }
U32 getZOffset() { return zOffset; }
private:
U32 mipLevel;
U32 zOffset;
};
/// Internal struct used to track 2D/Rect texture information for FBO attachment
class _GFXGLTextureTargetDesc : public _GFXGLTargetDesc
{
public:
_GFXGLTextureTargetDesc(GFXGLTextureObject* tex, U32 _mipLevel, U32 _zOffset)
: _GFXGLTargetDesc(_mipLevel, _zOffset), mTex(tex)
{
}
virtual ~_GFXGLTextureTargetDesc() {}
virtual U32 getHandle() { return mTex->getHandle(); }
virtual U32 getWidth() { return mTex->getWidth(); }
virtual U32 getHeight() { return mTex->getHeight(); }
virtual U32 getDepth() { return mTex->getDepth(); }
virtual bool hasMips() { return mTex->mMipLevels != 1; }
virtual GLenum getBinding() { return mTex->getBinding(); }
private:
StrongRefPtr<GFXGLTextureObject> mTex;
};
/// Internal struct used to track Cubemap texture information for FBO attachment
class _GFXGLCubemapTargetDesc : public _GFXGLTargetDesc
{
public:
_GFXGLCubemapTargetDesc(GFXGLCubemap* tex, U32 _face, U32 _mipLevel, U32 _zOffset)
: _GFXGLTargetDesc(_mipLevel, _zOffset), mTex(tex), mFace(_face)
{
}
virtual ~_GFXGLCubemapTargetDesc() {}
virtual U32 getHandle() { return mTex->getHandle(); }
virtual U32 getWidth() { return mTex->getWidth(); }
virtual U32 getHeight() { return mTex->getHeight(); }
virtual U32 getDepth() { return 0; }
virtual bool hasMips() { return mTex->getNumMipLevels() != 1; }
virtual GLenum getBinding() { return GFXGLCubemap::getEnumForFaceNumber(mFace); }
private:
StrongRefPtr<GFXGLCubemap> mTex;
U32 mFace;
};
// Internal implementations
class _GFXGLTextureTargetImpl
{
public:
GFXGLTextureTarget* mTarget;
virtual ~_GFXGLTextureTargetImpl() {}
virtual void applyState() = 0;
virtual void makeActive() = 0;
virtual void finish() = 0;
};
// Use FBOs to render to texture. This is the preferred implementation and is almost always used.
class _GFXGLTextureTargetFBOImpl : public _GFXGLTextureTargetImpl
{
public:
GLuint mFramebuffer;
_GFXGLTextureTargetFBOImpl(GFXGLTextureTarget* target);
virtual ~_GFXGLTextureTargetFBOImpl();
virtual void applyState();
virtual void makeActive();
virtual void finish();
};
// Handy macro for checking the status of a framebuffer. Framebuffers can fail in
// all sorts of interesting ways, these are just the most common. Further, no existing GL profiling
// tool catches framebuffer errors when the framebuffer is created, so we actually need this.
#define CHECK_FRAMEBUFFER_STATUS()\
{\
GLenum status;\
status = glCheckFramebufferStatusEXT(GL_FRAMEBUFFER_EXT);\
switch(status) {\
case GL_FRAMEBUFFER_COMPLETE_EXT:\
break;\
case GL_FRAMEBUFFER_UNSUPPORTED_EXT:\
AssertFatal(false, "Unsupported FBO");\
break;\
case GL_FRAMEBUFFER_INCOMPLETE_ATTACHMENT_EXT:\
AssertFatal(false, "Incomplete FBO Attachment");\
break;\
case GL_FRAMEBUFFER_INCOMPLETE_DIMENSIONS_EXT:\
AssertFatal(false, "Incomplete FBO dimensions");\
break;\
case GL_FRAMEBUFFER_INCOMPLETE_FORMATS_EXT:\
AssertFatal(false, "Incomplete FBO formats");\
default:\
/* programming error; will fail on all hardware */\
AssertFatal(false, "Something really bad happened with an FBO");\
}\
}
_GFXGLTextureTargetFBOImpl::_GFXGLTextureTargetFBOImpl(GFXGLTextureTarget* target)
{
mTarget = target;
glGenFramebuffersEXT(1, &mFramebuffer);
}
_GFXGLTextureTargetFBOImpl::~_GFXGLTextureTargetFBOImpl()
{
glDeleteFramebuffersEXT(1, &mFramebuffer);
}
void _GFXGLTextureTargetFBOImpl::applyState()
{
// REMINDER: When we implement MRT support, check against GFXGLDevice::getNumRenderTargets()
glBindFramebufferEXT(GL_FRAMEBUFFER_EXT, mFramebuffer);
_GFXGLTargetDesc* color0 = mTarget->getTargetDesc(GFXTextureTarget::Color0);
if(color0)
{
if(color0->getDepth() == 0)
glFramebufferTexture2DEXT(GL_FRAMEBUFFER_EXT, GL_COLOR_ATTACHMENT0_EXT, color0->getBinding(), color0->getHandle(), color0->getMipLevel());
else
glFramebufferTexture3DEXT(GL_FRAMEBUFFER_EXT, GL_COLOR_ATTACHMENT0_EXT, color0->getBinding(), color0->getHandle(), color0->getMipLevel(), color0->getZOffset());
}
else
{
// Clears the texture (note that the binding is irrelevent)
glFramebufferTexture2DEXT(GL_FRAMEBUFFER_EXT, GL_COLOR_ATTACHMENT0_EXT, GL_TEXTURE_2D, 0, 0);
}
_GFXGLTargetDesc* depthStecil = mTarget->getTargetDesc(GFXTextureTarget::DepthStencil);
if(depthStecil)
{
// Certain drivers have issues with depth only FBOs. That and the next two asserts assume we have a color target.
AssertFatal(color0, "GFXGLTextureTarget::applyState() - Cannot set DepthStencil target without Color0 target!");
AssertFatal(depthStecil->getWidth() == color0->getWidth(), "GFXGLTextureTarget::applyState() - DepthStencil and Color0 targets MUST have the same width!");
AssertFatal(depthStecil->getHeight() == color0->getHeight(), "GFXGLTextureTarget::applyState() - DepthStencil and Color0 targets MUST have the same height!");
glFramebufferTexture2DEXT(GL_FRAMEBUFFER_EXT, GL_DEPTH_ATTACHMENT_EXT, depthStecil->getBinding(), depthStecil->getHandle(), depthStecil->getMipLevel());
}
else
{
// Clears the texture (note that the binding is irrelevent)
glFramebufferTexture2DEXT(GL_FRAMEBUFFER_EXT, GL_DEPTH_ATTACHMENT_EXT, GL_TEXTURE_2D, 0, 0);
}
glBindFramebufferEXT(GL_FRAMEBUFFER_EXT, 0);
}
void _GFXGLTextureTargetFBOImpl::makeActive()
{
glBindFramebufferEXT(GL_DRAW_FRAMEBUFFER_EXT, mFramebuffer);
glBindFramebufferEXT(GL_READ_FRAMEBUFFER_EXT, mFramebuffer);
}
void _GFXGLTextureTargetFBOImpl::finish()
{
glBindFramebufferEXT(GL_DRAW_FRAMEBUFFER_EXT, 0);
glBindFramebufferEXT(GL_READ_FRAMEBUFFER_EXT, 0);
_GFXGLTargetDesc* color0 = mTarget->getTargetDesc(GFXTextureTarget::Color0);
if(!color0 || !(color0->hasMips()))
return;
// Generate mips if necessary
// Assumes a 2D texture.
glActiveTexture(GL_TEXTURE0);
PRESERVE_2D_TEXTURE();
glBindTexture(GL_TEXTURE_2D, color0->getHandle());
glGenerateMipmapEXT(GL_TEXTURE_2D);
}
// This implementations uses AUX buffers (we should always have at least one) to do render to texture. It is currently only used when we need access to the windows depth buffer.
class _GFXGLTextureTargetAUXBufferImpl : public _GFXGLTextureTargetImpl
{
public:
_GFXGLTextureTargetAUXBufferImpl(GFXGLTextureTarget* target);
virtual void applyState();
virtual void makeActive();
virtual void finish();
};
_GFXGLTextureTargetAUXBufferImpl::_GFXGLTextureTargetAUXBufferImpl(GFXGLTextureTarget* target)
{
mTarget = target;
}
void _GFXGLTextureTargetAUXBufferImpl::applyState()
{
}
void _GFXGLTextureTargetAUXBufferImpl::makeActive()
{
glDrawBuffer(GL_AUX0);
glReadBuffer(GL_AUX0);
}
void _GFXGLTextureTargetAUXBufferImpl::finish()
{
// Bind the Color0 texture
_GFXGLTargetDesc* color0 = mTarget->getTargetDesc(GFXTextureTarget::Color0);
glActiveTexture(GL_TEXTURE0);
// Assume we're a 2D texture for now.
PRESERVE_2D_TEXTURE();
glBindTexture(color0->getBinding(), color0->getHandle());
glCopyTexSubImage2D(color0->getBinding(), 0, 0, 0, 0, 0, color0->getWidth(), color0->getHeight());
glDrawBuffer(GL_BACK);
glReadBuffer(GL_BACK);
}
// Actual GFXGLTextureTarget interface
GFXGLTextureTarget::GFXGLTextureTarget()
{
for(U32 i=0; i<MaxRenderSlotId; i++)
mTargets[i] = NULL;
GFXTextureManager::addEventDelegate( this, &GFXGLTextureTarget::_onTextureEvent );
_impl = new _GFXGLTextureTargetFBOImpl(this);
_needsAux = false;
}
GFXGLTextureTarget::~GFXGLTextureTarget()
{
GFXTextureManager::removeEventDelegate( this, &GFXGLTextureTarget::_onTextureEvent );
}
const Point2I GFXGLTextureTarget::getSize()
{
if(mTargets[Color0].isValid())
return Point2I(mTargets[Color0]->getWidth(), mTargets[Color0]->getHeight());
return Point2I(0, 0);
}
GFXFormat GFXGLTextureTarget::getFormat()
{
// TODO: Fix me!
return GFXFormatR8G8B8A8;
}
void GFXGLTextureTarget::attachTexture( RenderSlot slot, GFXTextureObject *tex, U32 mipLevel/*=0*/, U32 zOffset /*= 0*/ )
{
// GFXTextureTarget::sDefaultDepthStencil is a hint that we want the window's depth buffer.
if(tex == GFXTextureTarget::sDefaultDepthStencil)
_needsAux = true;
if(slot == DepthStencil && tex != GFXTextureTarget::sDefaultDepthStencil)
_needsAux = false;
// Triggers an update when we next render
invalidateState();
// We stash the texture and info into an internal struct.
GFXGLTextureObject* glTexture = static_cast<GFXGLTextureObject*>(tex);
if(tex && tex != GFXTextureTarget::sDefaultDepthStencil)
mTargets[slot] = new _GFXGLTextureTargetDesc(glTexture, mipLevel, zOffset);
else
mTargets[slot] = NULL;
}
void GFXGLTextureTarget::attachTexture( RenderSlot slot, GFXCubemap *tex, U32 face, U32 mipLevel/*=0*/ )
{
// No depth cubemaps, sorry
AssertFatal(slot != DepthStencil, "GFXGLTextureTarget::attachTexture (cube) - Cube depth textures not supported!");
if(slot == DepthStencil)
return;
// Triggers an update when we next render
invalidateState();
// We stash the texture and info into an internal struct.
GFXGLCubemap* glTexture = static_cast<GFXGLCubemap*>(tex);
if(tex)
mTargets[slot] = new _GFXGLCubemapTargetDesc(glTexture, face, mipLevel, 0);
else
mTargets[slot] = NULL;
}
void GFXGLTextureTarget::clearAttachments()
{
deactivate();
for(S32 i=1; i<MaxRenderSlotId; i++)
attachTexture((RenderSlot)i, NULL);
}
void GFXGLTextureTarget::zombify()
{
invalidateState();
// Will be recreated in applyState
_impl = NULL;
}
void GFXGLTextureTarget::resurrect()
{
// Dealt with when the target is next bound
}
void GFXGLTextureTarget::makeActive()
{
_impl->makeActive();
}
void GFXGLTextureTarget::deactivate()
{
_impl->finish();
}
void GFXGLTextureTarget::applyState()
{
if(!isPendingState())
return;
// So we don't do this over and over again
stateApplied();
// Ensure we have the proper implementation (consider changing to an enum?)
if(_needsAux && dynamic_cast<_GFXGLTextureTargetAUXBufferImpl*>(_impl.ptr()) == NULL)
_impl = new _GFXGLTextureTargetAUXBufferImpl(this);
else if(!_needsAux && dynamic_cast<_GFXGLTextureTargetFBOImpl*>(_impl.ptr()) == NULL)
_impl = new _GFXGLTextureTargetFBOImpl(this);
_impl->applyState();
}
_GFXGLTargetDesc* GFXGLTextureTarget::getTargetDesc(RenderSlot slot) const
{
// This can only be called by our implementations, and then will not actually store the pointer so this is (almost) safe
return mTargets[slot].ptr();
}
void GFXGLTextureTarget::_onTextureEvent( GFXTexCallbackCode code )
{
invalidateState();
}
const String GFXGLTextureTarget::describeSelf() const
{
String ret = String::ToString(" Color0 Attachment: %i", mTargets[Color0].isValid() ? mTargets[Color0]->getHandle() : 0);
ret += String::ToString(" Depth Attachment: %i", mTargets[DepthStencil].isValid() ? mTargets[DepthStencil]->getHandle() : 0);
return ret;
}
void GFXGLTextureTarget::resolve()
{
}
void GFXGLTextureTarget::resolveTo(GFXTextureObject* obj)
{
AssertFatal(dynamic_cast<GFXGLTextureObject*>(obj), "GFXGLTextureTarget::resolveTo - Incorrect type of texture, expected a GFXGLTextureObject");
GFXGLTextureObject* glTexture = static_cast<GFXGLTextureObject*>(obj);
PRESERVE_FRAMEBUFFER();
GLuint dest;
GLuint src;
glGenFramebuffersEXT(1, &dest);
glGenFramebuffersEXT(1, &src);
glBindFramebufferEXT(GL_DRAW_FRAMEBUFFER_EXT, dest);
glFramebufferTexture2DEXT(GL_DRAW_FRAMEBUFFER_EXT, GL_COLOR_ATTACHMENT0_EXT, GL_TEXTURE_2D, glTexture->getHandle(), 0);
glBindFramebufferEXT(GL_READ_FRAMEBUFFER_EXT, src);
glFramebufferTexture2DEXT(GL_READ_FRAMEBUFFER_EXT, GL_COLOR_ATTACHMENT0_EXT, GL_TEXTURE_2D,mTargets[Color0]->getHandle(), 0);
glBlitFramebufferEXT(0, 0, mTargets[Color0]->getWidth(), mTargets[Color0]->getHeight(),
0, 0, glTexture->getWidth(), glTexture->getHeight(), GL_COLOR_BUFFER_BIT, GL_NEAREST);
glBindFramebufferEXT(GL_DRAW_FRAMEBUFFER_EXT, 0);
glBindFramebufferEXT(GL_READ_FRAMEBUFFER_EXT, 0);
glDeleteFramebuffersEXT(1, &dest);
glDeleteFramebuffersEXT(1, &src);
}

View file

@ -0,0 +1,101 @@
//-----------------------------------------------------------------------------
// Copyright (c) 2012 GarageGames, LLC
//
// Permission is hereby granted, free of charge, to any person obtaining a copy
// of this software and associated documentation files (the "Software"), to
// deal in the Software without restriction, including without limitation the
// rights to use, copy, modify, merge, publish, distribute, sublicense, and/or
// sell copies of the Software, and to permit persons to whom the Software is
// furnished to do so, subject to the following conditions:
//
// The above copyright notice and this permission notice shall be included in
// all copies or substantial portions of the Software.
//
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
// FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS
// IN THE SOFTWARE.
//-----------------------------------------------------------------------------
#ifndef _GFXGLTEXTURETARGET_H_
#define _GFXGLTEXTURETARGET_H_
#include "gfx/gfxTarget.h"
#include "core/util/autoPtr.h"
class GFXGLTextureObject;
class _GFXGLTargetDesc;
class _GFXGLTextureTargetImpl;
/// Render to texture support for OpenGL.
/// This class needs to make a number of assumptions due to the requirements
/// and complexity of render to texture in OpenGL.
/// 1) This class is only guaranteed to work with 2D textures or cubemaps. 3D textures
/// may or may not work.
/// 2) This class does not currently support multiple texture targets. Regardless
/// of how many targets you bind, only Color0 will be used.
/// 3) This class requires that the DepthStencil and Color0 targets have identical
/// dimensions.
/// 4) If the DepthStencil target is GFXTextureTarget::sDefaultStencil, then the
/// Color0 target should be the same size as the current backbuffer and should also
/// be the same format (typically R8G8B8A8)
class GFXGLTextureTarget : public GFXTextureTarget
{
public:
GFXGLTextureTarget();
virtual ~GFXGLTextureTarget();
virtual const Point2I getSize();
virtual GFXFormat getFormat();
virtual void attachTexture(RenderSlot slot, GFXTextureObject *tex, U32 mipLevel=0, U32 zOffset = 0);
virtual void attachTexture(RenderSlot slot, GFXCubemap *tex, U32 face, U32 mipLevel=0);
virtual void clearAttachments();
/// Functions to query internal state
/// @{
/// Returns the internal structure for the given slot. This should only be called by our internal implementations.
_GFXGLTargetDesc* getTargetDesc(RenderSlot slot) const;
/// @}
void deactivate();
void zombify();
void resurrect();
virtual const String describeSelf() const;
virtual void resolve();
virtual void resolveTo(GFXTextureObject* obj);
protected:
friend class GFXGLDevice;
/// The callback used to get texture events.
/// @see GFXTextureManager::addEventDelegate
void _onTextureEvent( GFXTexCallbackCode code );
/// If true our implementation should use AUX buffers
bool _needsAux;
/// Pointer to our internal implementation
AutoPtr<_GFXGLTextureTargetImpl> _impl;
/// Array of _GFXGLTargetDesc's, an internal struct used to keep track of texture data.
AutoPtr<_GFXGLTargetDesc> mTargets[MaxRenderSlotId];
/// These redirect to our internal implementation
/// @{
void applyState();
void makeActive();
/// @}
};
#endif

View file

@ -0,0 +1,111 @@
//-----------------------------------------------------------------------------
// Copyright (c) 2012 GarageGames, LLC
//
// Permission is hereby granted, free of charge, to any person obtaining a copy
// of this software and associated documentation files (the "Software"), to
// deal in the Software without restriction, including without limitation the
// rights to use, copy, modify, merge, publish, distribute, sublicense, and/or
// sell copies of the Software, and to permit persons to whom the Software is
// furnished to do so, subject to the following conditions:
//
// The above copyright notice and this permission notice shall be included in
// all copies or substantial portions of the Software.
//
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
// FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS
// IN THE SOFTWARE.
//-----------------------------------------------------------------------------
#ifndef TORQUE_GFX_GL_GFXGLUTILS_H_
#define TORQUE_GFX_GL_GFXGLUTILS_H_
#include "core/util/preprocessorHelpers.h"
#include "gfx/gl/gfxGLEnumTranslate.h"
static inline GLenum minificationFilter(U32 minFilter, U32 mipFilter, U32 mipLevels)
{
if(mipLevels == 1)
return GFXGLTextureFilter[minFilter];
// the compiler should interpret this as array lookups
switch( minFilter )
{
case GFXTextureFilterLinear:
switch( mipFilter )
{
case GFXTextureFilterLinear:
return GL_LINEAR_MIPMAP_LINEAR;
case GFXTextureFilterPoint:
return GL_LINEAR_MIPMAP_NEAREST;
default:
return GL_LINEAR;
}
default:
switch( mipFilter ) {
case GFXTextureFilterLinear:
return GL_NEAREST_MIPMAP_LINEAR;
case GFXTextureFilterPoint:
return GL_NEAREST_MIPMAP_NEAREST;
default:
return GL_NEAREST;
}
}
}
/// Simple class which preserves a given GL integer.
/// This class determines the integer to preserve on construction and restores
/// it on destruction.
class GFXGLPreserveInteger
{
public:
typedef void(*BindFn)(GLenum, GLuint);
/// Preserve the integer.
/// @param binding The binding which should be set on destruction.
/// @param getBinding The parameter to be passed to glGetIntegerv to determine
/// the integer to be preserved.
/// @param binder The gl function to call to restore the integer.
GFXGLPreserveInteger(GLenum binding, GLint getBinding, BindFn binder) :
mBinding(binding), mPreserved(0), mBinder(binder)
{
AssertFatal(mBinder, "GFXGLPreserveInteger - Need a valid binder function");
glGetIntegerv(getBinding, &mPreserved);
}
/// Restores the integer.
~GFXGLPreserveInteger()
{
mBinder(mBinding, mPreserved);
}
private:
GLenum mBinding;
GLint mPreserved;
BindFn mBinder;
};
/// Helper macro to preserve the current VBO binding.
#define PRESERVE_VERTEX_BUFFER() \
GFXGLPreserveInteger TORQUE_CONCAT(preserve_, __LINE__) (GL_ARRAY_BUFFER, GL_ARRAY_BUFFER_BINDING, glBindBuffer)
/// Helper macro to preserve the current element array binding.
#define PRESERVE_INDEX_BUFFER() \
GFXGLPreserveInteger TORQUE_CONCAT(preserve_, __LINE__) (GL_ELEMENT_ARRAY_BUFFER, GL_ELEMENT_ARRAY_BUFFER_BINDING, glBindBuffer)
/// Helper macro to preserve the current 2D texture binding.
#define PRESERVE_2D_TEXTURE() \
GFXGLPreserveInteger TORQUE_CONCAT(preserve_, __LINE__) (GL_TEXTURE_2D, GL_TEXTURE_BINDING_2D, glBindTexture)
/// Helper macro to preserve the current 3D texture binding.
#define PRESERVE_3D_TEXTURE() \
GFXGLPreserveInteger TORQUE_CONCAT(preserve_, __LINE__) (GL_TEXTURE_3D, GL_TEXTURE_BINDING_3D, glBindTexture)
#define PRESERVE_FRAMEBUFFER() \
GFXGLPreserveInteger TORQUE_CONCAT(preserve_, __LINE__) (GL_READ_FRAMEBUFFER_EXT, GL_READ_FRAMEBUFFER_BINDING_EXT, glBindFramebufferEXT);\
GFXGLPreserveInteger TORQUE_CONCAT(preserve2_, __LINE__) (GL_DRAW_FRAMEBUFFER_EXT, GL_DRAW_FRAMEBUFFER_BINDING_EXT, glBindFramebufferEXT)
#endif

View file

@ -0,0 +1,177 @@
//-----------------------------------------------------------------------------
// Copyright (c) 2012 GarageGames, LLC
//
// Permission is hereby granted, free of charge, to any person obtaining a copy
// of this software and associated documentation files (the "Software"), to
// deal in the Software without restriction, including without limitation the
// rights to use, copy, modify, merge, publish, distribute, sublicense, and/or
// sell copies of the Software, and to permit persons to whom the Software is
// furnished to do so, subject to the following conditions:
//
// The above copyright notice and this permission notice shall be included in
// all copies or substantial portions of the Software.
//
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
// FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS
// IN THE SOFTWARE.
//-----------------------------------------------------------------------------
#include "platform/platform.h"
#include "gfx/gl/gfxGLVertexBuffer.h"
#include "gfx/gl/gfxGLDevice.h"
#include "gfx/gl/gfxGLEnumTranslate.h"
#include "gfx/gl/gfxGLUtils.h"
GFXGLVertexBuffer::GFXGLVertexBuffer( GFXDevice *device,
U32 numVerts,
const GFXVertexFormat *vertexFormat,
U32 vertexSize,
GFXBufferType bufferType )
: GFXVertexBuffer( device, numVerts, vertexFormat, vertexSize, bufferType ),
mZombieCache(NULL)
{
PRESERVE_VERTEX_BUFFER();
// Generate a buffer and allocate the needed memory.
glGenBuffers(1, &mBuffer);
glBindBuffer(GL_ARRAY_BUFFER, mBuffer);
glBufferData(GL_ARRAY_BUFFER, numVerts * vertexSize, NULL, GFXGLBufferType[bufferType]);
glBindBuffer(GL_ARRAY_BUFFER, 0);
}
GFXGLVertexBuffer::~GFXGLVertexBuffer()
{
// While heavy handed, this does delete the buffer and frees the associated memory.
glDeleteBuffers(1, &mBuffer);
if( mZombieCache )
delete [] mZombieCache;
}
void GFXGLVertexBuffer::lock( U32 vertexStart, U32 vertexEnd, void **vertexPtr )
{
PRESERVE_VERTEX_BUFFER();
// Bind us, get a pointer into the buffer, then
// offset it by vertexStart so we act like the D3D layer.
glBindBuffer(GL_ARRAY_BUFFER, mBuffer);
glBufferData(GL_ARRAY_BUFFER, mNumVerts * mVertexSize, NULL, GFXGLBufferType[mBufferType]);
*vertexPtr = (void*)((U8*)glMapBuffer(GL_ARRAY_BUFFER, GL_WRITE_ONLY) + (vertexStart * mVertexSize));
lockedVertexStart = vertexStart;
lockedVertexEnd = vertexEnd;
}
void GFXGLVertexBuffer::unlock()
{
PRESERVE_VERTEX_BUFFER();
// Unmap the buffer and bind 0 to GL_ARRAY_BUFFER
glBindBuffer(GL_ARRAY_BUFFER, mBuffer);
bool res = glUnmapBuffer(GL_ARRAY_BUFFER);
AssertFatal(res, "GFXGLVertexBuffer::unlock - shouldn't fail!");
lockedVertexStart = 0;
lockedVertexEnd = 0;
}
void GFXGLVertexBuffer::prepare()
{
// Bind the buffer...
glBindBuffer(GL_ARRAY_BUFFER, mBuffer);
U8* buffer = (U8*)getBuffer();
// Loop thru the vertex format elements adding the array state...
U32 texCoordIndex = 0;
for ( U32 i=0; i < mVertexFormat.getElementCount(); i++ )
{
const GFXVertexElement &element = mVertexFormat.getElement( i );
if ( element.isSemantic( GFXSemantic::POSITION ) )
{
glEnableClientState( GL_VERTEX_ARRAY );
glVertexPointer( element.getSizeInBytes() / 4, GL_FLOAT, mVertexSize, buffer );
buffer += element.getSizeInBytes();
}
else if ( element.isSemantic( GFXSemantic::NORMAL ) )
{
glEnableClientState( GL_NORMAL_ARRAY );
glNormalPointer( GL_FLOAT, mVertexSize, buffer );
buffer += element.getSizeInBytes();
}
else if ( element.isSemantic( GFXSemantic::COLOR ) )
{
glEnableClientState( GL_COLOR_ARRAY );
glColorPointer( element.getSizeInBytes(), GL_UNSIGNED_BYTE, mVertexSize, buffer );
buffer += element.getSizeInBytes();
}
else // Everything else is a texture coordinate.
{
glClientActiveTexture( GL_TEXTURE0 + texCoordIndex );
glEnableClientState( GL_TEXTURE_COORD_ARRAY );
glTexCoordPointer( element.getSizeInBytes() / 4, GL_FLOAT, mVertexSize, buffer );
buffer += element.getSizeInBytes();
++texCoordIndex;
}
}
}
void GFXGLVertexBuffer::finish()
{
glBindBuffer(GL_ARRAY_BUFFER, 0);
U32 texCoordIndex = 0;
for ( U32 i=0; i < mVertexFormat.getElementCount(); i++ )
{
const GFXVertexElement &element = mVertexFormat.getElement( i );
if ( element.isSemantic( GFXSemantic::POSITION ) )
glDisableClientState( GL_VERTEX_ARRAY );
else if ( element.isSemantic( GFXSemantic::NORMAL ) )
glDisableClientState( GL_NORMAL_ARRAY );
else if ( element.isSemantic( GFXSemantic::COLOR ) )
glDisableClientState( GL_COLOR_ARRAY );
else
{
glClientActiveTexture( GL_TEXTURE0 + texCoordIndex );
glDisableClientState(GL_TEXTURE_COORD_ARRAY);
++texCoordIndex;
}
}
}
GLvoid* GFXGLVertexBuffer::getBuffer()
{
// NULL specifies no offset into the hardware buffer
return (GLvoid*)NULL;
}
void GFXGLVertexBuffer::zombify()
{
if(mZombieCache || !mBuffer)
return;
mZombieCache = new U8[mNumVerts * mVertexSize];
glBindBuffer(GL_ARRAY_BUFFER, mBuffer);
glGetBufferSubData(GL_ARRAY_BUFFER, 0, mNumVerts * mVertexSize, mZombieCache);
glBindBuffer(GL_ARRAY_BUFFER, 0);
glDeleteBuffers(1, &mBuffer);
mBuffer = 0;
}
void GFXGLVertexBuffer::resurrect()
{
if(!mZombieCache)
return;
glGenBuffers(1, &mBuffer);
glBindBuffer(GL_ARRAY_BUFFER, mBuffer);
glBufferData(GL_ARRAY_BUFFER, mNumVerts * mVertexSize, mZombieCache, GFXGLBufferType[mBufferType]);
glBindBuffer(GL_ARRAY_BUFFER, 0);
delete[] mZombieCache;
mZombieCache = NULL;
}

View file

@ -0,0 +1,64 @@
//-----------------------------------------------------------------------------
// Copyright (c) 2012 GarageGames, LLC
//
// Permission is hereby granted, free of charge, to any person obtaining a copy
// of this software and associated documentation files (the "Software"), to
// deal in the Software without restriction, including without limitation the
// rights to use, copy, modify, merge, publish, distribute, sublicense, and/or
// sell copies of the Software, and to permit persons to whom the Software is
// furnished to do so, subject to the following conditions:
//
// The above copyright notice and this permission notice shall be included in
// all copies or substantial portions of the Software.
//
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
// FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS
// IN THE SOFTWARE.
//-----------------------------------------------------------------------------
#ifndef _GFXGLVERTEXBUFFER_H_
#define _GFXGLVERTEXBUFFER_H_
#ifndef _GFXVERTEXBUFFER_H_
#include "gfx/gfxVertexBuffer.h"
#endif
#ifndef GL_GGL_H
#include "gfx/gl/ggl/ggl.h"
#endif
/// This is a vertex buffer which uses GL_ARB_vertex_buffer_object.
class GFXGLVertexBuffer : public GFXVertexBuffer
{
public:
GFXGLVertexBuffer( GFXDevice *device,
U32 numVerts,
const GFXVertexFormat *vertexFormat,
U32 vertexSize,
GFXBufferType bufferType );
~GFXGLVertexBuffer();
virtual void lock(U32 vertexStart, U32 vertexEnd, void **vertexPtr); ///< calls glMapBuffer and offsets the pointer by vertex start
virtual void unlock(); ///< calls glUnmapBuffer, unbinds the buffer
virtual void prepare(); ///< Binds the buffer
virtual void finish(); ///< We're done here
GLvoid* getBuffer(); ///< returns NULL
// GFXResource interface
virtual void zombify();
virtual void resurrect();
private:
friend class GFXGLDevice;
/// GL buffer handle
GLuint mBuffer;
U8* mZombieCache;
};
#endif

View file

@ -0,0 +1,79 @@
//-----------------------------------------------------------------------------
// Copyright (c) 2012 GarageGames, LLC
//
// Permission is hereby granted, free of charge, to any person obtaining a copy
// of this software and associated documentation files (the "Software"), to
// deal in the Software without restriction, including without limitation the
// rights to use, copy, modify, merge, publish, distribute, sublicense, and/or
// sell copies of the Software, and to permit persons to whom the Software is
// furnished to do so, subject to the following conditions:
//
// The above copyright notice and this permission notice shall be included in
// all copies or substantial portions of the Software.
//
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
// FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS
// IN THE SOFTWARE.
//-----------------------------------------------------------------------------
#include "windowManager/platformWindow.h"
#include "gfx/gl/gfxGLDevice.h"
#include "gfx/gl/gfxGLWindowTarget.h"
#include "gfx/gl/gfxGLTextureObject.h"
#include "gfx/gl/gfxGLUtils.h"
GFXGLWindowTarget::GFXGLWindowTarget(PlatformWindow *win, GFXDevice *d)
: GFXWindowTarget(win), mDevice(d), mContext(NULL), mFullscreenContext(NULL)
{
win->appEvent.notify(this, &GFXGLWindowTarget::_onAppSignal);
}
void GFXGLWindowTarget::resetMode()
{
if(mWindow->getVideoMode().fullScreen != mWindow->isFullscreen())
{
_teardownCurrentMode();
_setupNewMode();
}
}
void GFXGLWindowTarget::_onAppSignal(WindowId wnd, S32 event)
{
if(event != WindowHidden)
return;
// TODO: Investigate this further.
// Opening and then closing the console results in framerate dropping at an alarming rate down to 3-4 FPS and then
// rebounding to it's usual level. Clearing all the volatile VBs prevents this behavior, but I can't explain why.
// My fear is there is something fundamentally wrong with how we share objects between contexts and this is simply
// masking the issue for the most common case.
static_cast<GFXGLDevice*>(mDevice)->mVolatileVBs.clear();
}
void GFXGLWindowTarget::resolveTo(GFXTextureObject* obj)
{
AssertFatal(dynamic_cast<GFXGLTextureObject*>(obj), "GFXGLTextureTarget::resolveTo - Incorrect type of texture, expected a GFXGLTextureObject");
GFXGLTextureObject* glTexture = static_cast<GFXGLTextureObject*>(obj);
PRESERVE_FRAMEBUFFER();
GLuint dest;
glGenFramebuffersEXT(1, &dest);
glBindFramebufferEXT(GL_DRAW_FRAMEBUFFER_EXT, dest);
glFramebufferTexture2DEXT(GL_DRAW_FRAMEBUFFER_EXT, GL_COLOR_ATTACHMENT0_EXT, GL_TEXTURE_2D, glTexture->getHandle(), 0);
glBindFramebufferEXT(GL_READ_FRAMEBUFFER_EXT, 0);
glBlitFramebufferEXT(0, 0, getSize().x, getSize().y,
0, 0, glTexture->getWidth(), glTexture->getHeight(), GL_COLOR_BUFFER_BIT, GL_NEAREST);
glBindFramebufferEXT(GL_DRAW_FRAMEBUFFER_EXT, 0);
glDeleteFramebuffersEXT(1, &dest);
}

View file

@ -0,0 +1,62 @@
//-----------------------------------------------------------------------------
// Copyright (c) 2012 GarageGames, LLC
//
// Permission is hereby granted, free of charge, to any person obtaining a copy
// of this software and associated documentation files (the "Software"), to
// deal in the Software without restriction, including without limitation the
// rights to use, copy, modify, merge, publish, distribute, sublicense, and/or
// sell copies of the Software, and to permit persons to whom the Software is
// furnished to do so, subject to the following conditions:
//
// The above copyright notice and this permission notice shall be included in
// all copies or substantial portions of the Software.
//
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
// FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS
// IN THE SOFTWARE.
//-----------------------------------------------------------------------------
#ifndef _GFXGLWINDOWTARGET_H_
#define _GFXGLWINDOWTARGET_H_
#include "gfx/gfxTarget.h"
class GFXGLWindowTarget : public GFXWindowTarget
{
public:
GFXGLWindowTarget(PlatformWindow *win, GFXDevice *d);
const Point2I getSize()
{
return mWindow->getClientExtent();
}
virtual GFXFormat getFormat()
{
// TODO: Fix me!
return GFXFormatR8G8B8A8;
}
void makeActive();
virtual bool present();
virtual void resetMode();
virtual void zombify() { }
virtual void resurrect() { }
virtual void resolveTo(GFXTextureObject* obj);
void _onAppSignal(WindowId wnd, S32 event);
private:
friend class GFXGLDevice;
Point2I size;
GFXDevice* mDevice;
void* mContext;
void* mFullscreenContext;
void _teardownCurrentMode();
void _setupNewMode();
};
#endif

View file

@ -0,0 +1,666 @@
//-----------------------------------------------------------------------------
// Copyright (c) 2012 GarageGames, LLC
//
// Permission is hereby granted, free of charge, to any person obtaining a copy
// of this software and associated documentation files (the "Software"), to
// deal in the Software without restriction, including without limitation the
// rights to use, copy, modify, merge, publish, distribute, sublicense, and/or
// sell copies of the Software, and to permit persons to whom the Software is
// furnished to do so, subject to the following conditions:
//
// The above copyright notice and this permission notice shall be included in
// all copies or substantial portions of the Software.
//
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
// FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS
// IN THE SOFTWARE.
//-----------------------------------------------------------------------------
/*
** License Applicability. Except to the extent portions of this file are
** made subject to an alternative license as permitted in the SGI Free
** Software License B, Version 1.1 (the "License"), the contents of this
** file are subject only to the provisions of the License. You may not use
** this file except in compliance with the License. You may obtain a copy
** of the License at Silicon Graphics, Inc., attn: Legal Services, 1600
** Amphitheatre Parkway, Mountain View, CA 94043-1351, or at:
**
** http://oss.sgi.com/projects/FreeB
**
** Note that, as provided in the License, the Software is distributed on an
** "AS IS" basis, with ALL EXPRESS AND IMPLIED WARRANTIES AND CONDITIONS
** DISCLAIMED, INCLUDING, WITHOUT LIMITATION, ANY IMPLIED WARRANTIES AND
** CONDITIONS OF MERCHANTABILITY, SATISFACTORY QUALITY, FITNESS FOR A
** PARTICULAR PURPOSE, AND NON-INFRINGEMENT.
**
** Original Code. The Original Code is: OpenGL Sample Private,
** Version 1.2.1, released January 26, 2000, developed by Silicon Graphics,
** Inc. The Original Code is Copyright (c) 1991-2002 Silicon Graphics, Inc.
** Copyright in any portions created by third parties is as indicated
** elsewhere herein. All Rights Reserved.
**
** Additional Notice Provisions: This software was created using the
** OpenGL(R) version 1.2.1 Sample Private published by SGI, but has
** not been independently verified as being compliant with the OpenGL(R)
** version 1.2.1 Specification.
*/
typedef unsigned int GLenum;
typedef unsigned char GLboolean;
typedef unsigned int GLbitfield;
typedef void GLvoid;
typedef signed char GLbyte; /* 1-byte signed */
typedef short GLshort; /* 2-byte signed */
typedef int GLint; /* 4-byte signed */
typedef unsigned char GLubyte; /* 1-byte unsigned */
typedef unsigned short GLushort; /* 2-byte unsigned */
typedef unsigned int GLuint; /* 4-byte unsigned */
typedef int GLsizei; /* 4-byte signed */
typedef float GLfloat; /* single precision float */
typedef float GLclampf; /* single precision float in [0,1] */
typedef double GLdouble; /* double precision float */
typedef double GLclampd; /* double precision float in [0,1] */
/* Boolean values */
#define GL_FALSE 0x0
#define GL_TRUE 0x1
/* Data types */
#define GL_BYTE 0x1400
#define GL_UNSIGNED_BYTE 0x1401
#define GL_SHORT 0x1402
#define GL_UNSIGNED_SHORT 0x1403
#define GL_INT 0x1404
#define GL_UNSIGNED_INT 0x1405
#define GL_FLOAT 0x1406
#define GL_DOUBLE 0x140A
#define GL_2_BYTES 0x1407
#define GL_3_BYTES 0x1408
#define GL_4_BYTES 0x1409
/* Primitives */
#define GL_POINTS 0x0000
#define GL_LINES 0x0001
#define GL_LINE_LOOP 0x0002
#define GL_LINE_STRIP 0x0003
#define GL_TRIANGLES 0x0004
#define GL_TRIANGLE_STRIP 0x0005
#define GL_TRIANGLE_FAN 0x0006
#define GL_QUADS 0x0007
#define GL_QUAD_STRIP 0x0008
#define GL_POLYGON 0x0009
/* Vertex Arrays */
#define GL_VERTEX_ARRAY 0x8074
#define GL_NORMAL_ARRAY 0x8075
#define GL_COLOR_ARRAY 0x8076
#define GL_INDEX_ARRAY 0x8077
#define GL_TEXTURE_COORD_ARRAY 0x8078
#define GL_EDGE_FLAG_ARRAY 0x8079
#define GL_VERTEX_ARRAY_SIZE 0x807A
#define GL_VERTEX_ARRAY_TYPE 0x807B
#define GL_VERTEX_ARRAY_STRIDE 0x807C
#define GL_NORMAL_ARRAY_TYPE 0x807E
#define GL_NORMAL_ARRAY_STRIDE 0x807F
#define GL_COLOR_ARRAY_SIZE 0x8081
#define GL_COLOR_ARRAY_TYPE 0x8082
#define GL_COLOR_ARRAY_STRIDE 0x8083
#define GL_INDEX_ARRAY_TYPE 0x8085
#define GL_INDEX_ARRAY_STRIDE 0x8086
#define GL_TEXTURE_COORD_ARRAY_SIZE 0x8088
#define GL_TEXTURE_COORD_ARRAY_TYPE 0x8089
#define GL_TEXTURE_COORD_ARRAY_STRIDE 0x808A
#define GL_EDGE_FLAG_ARRAY_STRIDE 0x808C
#define GL_VERTEX_ARRAY_POINTER 0x808E
#define GL_NORMAL_ARRAY_POINTER 0x808F
#define GL_COLOR_ARRAY_POINTER 0x8090
#define GL_INDEX_ARRAY_POINTER 0x8091
#define GL_TEXTURE_COORD_ARRAY_POINTER 0x8092
#define GL_EDGE_FLAG_ARRAY_POINTER 0x8093
#define GL_V2F 0x2A20
#define GL_V3F 0x2A21
#define GL_C4UB_V2F 0x2A22
#define GL_C4UB_V3F 0x2A23
#define GL_C3F_V3F 0x2A24
#define GL_N3F_V3F 0x2A25
#define GL_C4F_N3F_V3F 0x2A26
#define GL_T2F_V3F 0x2A27
#define GL_T4F_V4F 0x2A28
#define GL_T2F_C4UB_V3F 0x2A29
#define GL_T2F_C3F_V3F 0x2A2A
#define GL_T2F_N3F_V3F 0x2A2B
#define GL_T2F_C4F_N3F_V3F 0x2A2C
#define GL_T4F_C4F_N3F_V4F 0x2A2D
/* Matrix Mode */
#define GL_MATRIX_MODE 0x0BA0
#define GL_MODELVIEW 0x1700
#define GL_PROJECTION 0x1701
#define GL_TEXTURE 0x1702
/* Points */
#define GL_POINT_SMOOTH 0x0B10
#define GL_POINT_SIZE 0x0B11
#define GL_POINT_SIZE_GRANULARITY 0x0B13
#define GL_POINT_SIZE_RANGE 0x0B12
/* Lines */
#define GL_LINE_SMOOTH 0x0B20
#define GL_LINE_STIPPLE 0x0B24
#define GL_LINE_STIPPLE_PATTERN 0x0B25
#define GL_LINE_STIPPLE_REPEAT 0x0B26
#define GL_LINE_WIDTH 0x0B21
#define GL_LINE_WIDTH_GRANULARITY 0x0B23
#define GL_LINE_WIDTH_RANGE 0x0B22
/* Polygons */
#define GL_POINT 0x1B00
#define GL_LINE 0x1B01
#define GL_FILL 0x1B02
#define GL_CW 0x0900
#define GL_CCW 0x0901
#define GL_FRONT 0x0404
#define GL_BACK 0x0405
#define GL_POLYGON_MODE 0x0B40
#define GL_POLYGON_SMOOTH 0x0B41
#define GL_POLYGON_STIPPLE 0x0B42
#define GL_EDGE_FLAG 0x0B43
#define GL_CULL_FACE 0x0B44
#define GL_CULL_FACE_MODE 0x0B45
#define GL_FRONT_FACE 0x0B46
#define GL_POLYGON_OFFSET_FACTOR 0x8038
#define GL_POLYGON_OFFSET_UNITS 0x2A00
#define GL_POLYGON_OFFSET_POINT 0x2A01
#define GL_POLYGON_OFFSET_LINE 0x2A02
#define GL_POLYGON_OFFSET_FILL 0x8037
/* Display Lists */
#define GL_COMPILE 0x1300
#define GL_COMPILE_AND_EXECUTE 0x1301
#define GL_LIST_BASE 0x0B32
#define GL_LIST_INDEX 0x0B33
#define GL_LIST_MODE 0x0B30
/* Depth buffer */
#define GL_NEVER 0x0200
#define GL_LESS 0x0201
#define GL_EQUAL 0x0202
#define GL_LEQUAL 0x0203
#define GL_GREATER 0x0204
#define GL_NOTEQUAL 0x0205
#define GL_GEQUAL 0x0206
#define GL_ALWAYS 0x0207
#define GL_DEPTH_TEST 0x0B71
#define GL_DEPTH_BITS 0x0D56
#define GL_DEPTH_CLEAR_VALUE 0x0B73
#define GL_DEPTH_FUNC 0x0B74
#define GL_DEPTH_RANGE 0x0B70
#define GL_DEPTH_WRITEMASK 0x0B72
#define GL_DEPTH_COMPONENT 0x1902
/* Lighting */
#define GL_LIGHTING 0x0B50
#define GL_LIGHT0 0x4000
#define GL_LIGHT1 0x4001
#define GL_LIGHT2 0x4002
#define GL_LIGHT3 0x4003
#define GL_LIGHT4 0x4004
#define GL_LIGHT5 0x4005
#define GL_LIGHT6 0x4006
#define GL_LIGHT7 0x4007
#define GL_SPOT_EXPONENT 0x1205
#define GL_SPOT_CUTOFF 0x1206
#define GL_CONSTANT_ATTENUATION 0x1207
#define GL_LINEAR_ATTENUATION 0x1208
#define GL_QUADRATIC_ATTENUATION 0x1209
#define GL_AMBIENT 0x1200
#define GL_DIFFUSE 0x1201
#define GL_SPECULAR 0x1202
#define GL_SHININESS 0x1601
#define GL_EMISSION 0x1600
#define GL_POSITION 0x1203
#define GL_SPOT_DIRECTION 0x1204
#define GL_AMBIENT_AND_DIFFUSE 0x1602
#define GL_COLOR_INDEXES 0x1603
#define GL_LIGHT_MODEL_TWO_SIDE 0x0B52
#define GL_LIGHT_MODEL_LOCAL_VIEWER 0x0B51
#define GL_LIGHT_MODEL_AMBIENT 0x0B53
#define GL_FRONT_AND_BACK 0x0408
#define GL_SHADE_MODEL 0x0B54
#define GL_FLAT 0x1D00
#define GL_SMOOTH 0x1D01
#define GL_COLOR_MATERIAL 0x0B57
#define GL_COLOR_MATERIAL_FACE 0x0B55
#define GL_COLOR_MATERIAL_PARAMETER 0x0B56
#define GL_NORMALIZE 0x0BA1
/* User clipping planes */
#define GL_CLIP_PLANE0 0x3000
#define GL_CLIP_PLANE1 0x3001
#define GL_CLIP_PLANE2 0x3002
#define GL_CLIP_PLANE3 0x3003
#define GL_CLIP_PLANE4 0x3004
#define GL_CLIP_PLANE5 0x3005
/* Accumulation buffer */
#define GL_ACCUM_RED_BITS 0x0D58
#define GL_ACCUM_GREEN_BITS 0x0D59
#define GL_ACCUM_BLUE_BITS 0x0D5A
#define GL_ACCUM_ALPHA_BITS 0x0D5B
#define GL_ACCUM_CLEAR_VALUE 0x0B80
#define GL_ACCUM 0x0100
#define GL_ADD 0x0104
#define GL_LOAD 0x0101
#define GL_MULT 0x0103
#define GL_RETURN 0x0102
/* Alpha testing */
#define GL_ALPHA_TEST 0x0BC0
#define GL_ALPHA_TEST_REF 0x0BC2
#define GL_ALPHA_TEST_FUNC 0x0BC1
/* Blending */
#define GL_BLEND 0x0BE2
#define GL_BLEND_SRC 0x0BE1
#define GL_BLEND_DST 0x0BE0
#define GL_ZERO 0x0
#define GL_ONE 0x1
#define GL_SRC_COLOR 0x0300
#define GL_ONE_MINUS_SRC_COLOR 0x0301
#define GL_SRC_ALPHA 0x0302
#define GL_ONE_MINUS_SRC_ALPHA 0x0303
#define GL_DST_ALPHA 0x0304
#define GL_ONE_MINUS_DST_ALPHA 0x0305
#define GL_DST_COLOR 0x0306
#define GL_ONE_MINUS_DST_COLOR 0x0307
#define GL_SRC_ALPHA_SATURATE 0x0308
/* Render Mode */
#define GL_FEEDBACK 0x1C01
#define GL_RENDER 0x1C00
#define GL_SELECT 0x1C02
/* Feedback */
#define GL_2D 0x0600
#define GL_3D 0x0601
#define GL_3D_COLOR 0x0602
#define GL_3D_COLOR_TEXTURE 0x0603
#define GL_4D_COLOR_TEXTURE 0x0604
#define GL_POINT_TOKEN 0x0701
#define GL_LINE_TOKEN 0x0702
#define GL_LINE_RESET_TOKEN 0x0707
#define GL_POLYGON_TOKEN 0x0703
#define GL_BITMAP_TOKEN 0x0704
#define GL_DRAW_PIXEL_TOKEN 0x0705
#define GL_COPY_PIXEL_TOKEN 0x0706
#define GL_PASS_THROUGH_TOKEN 0x0700
#define GL_FEEDBACK_BUFFER_POINTER 0x0DF0
#define GL_FEEDBACK_BUFFER_SIZE 0x0DF1
#define GL_FEEDBACK_BUFFER_TYPE 0x0DF2
/* Selection */
#define GL_SELECTION_BUFFER_POINTER 0x0DF3
#define GL_SELECTION_BUFFER_SIZE 0x0DF4
/* Fog */
#define GL_FOG 0x0B60
#define GL_FOG_MODE 0x0B65
#define GL_FOG_DENSITY 0x0B62
#define GL_FOG_COLOR 0x0B66
#define GL_FOG_INDEX 0x0B61
#define GL_FOG_START 0x0B63
#define GL_FOG_END 0x0B64
#define GL_LINEAR 0x2601
#define GL_EXP 0x0800
#define GL_EXP2 0x0801
/* Logic Ops */
#define GL_LOGIC_OP 0x0BF1
#define GL_INDEX_LOGIC_OP 0x0BF1
#define GL_COLOR_LOGIC_OP 0x0BF2
#define GL_LOGIC_OP_MODE 0x0BF0
#define GL_CLEAR 0x1500
#define GL_SET 0x150F
#define GL_COPY 0x1503
#define GL_COPY_INVERTED 0x150C
#define GL_NOOP 0x1505
#define GL_INVERT 0x150A
#define GL_AND 0x1501
#define GL_NAND 0x150E
#define GL_OR 0x1507
#define GL_NOR 0x1508
#define GL_XOR 0x1506
#define GL_EQUIV 0x1509
#define GL_AND_REVERSE 0x1502
#define GL_AND_INVERTED 0x1504
#define GL_OR_REVERSE 0x150B
#define GL_OR_INVERTED 0x150D
/* Stencil */
#define GL_STENCIL_TEST 0x0B90
#define GL_STENCIL_WRITEMASK 0x0B98
#define GL_STENCIL_BITS 0x0D57
#define GL_STENCIL_FUNC 0x0B92
#define GL_STENCIL_VALUE_MASK 0x0B93
#define GL_STENCIL_REF 0x0B97
#define GL_STENCIL_FAIL 0x0B94
#define GL_STENCIL_PASS_DEPTH_PASS 0x0B96
#define GL_STENCIL_PASS_DEPTH_FAIL 0x0B95
#define GL_STENCIL_CLEAR_VALUE 0x0B91
#define GL_STENCIL_INDEX 0x1901
#define GL_KEEP 0x1E00
#define GL_REPLACE 0x1E01
#define GL_INCR 0x1E02
#define GL_DECR 0x1E03
/* Buffers, Pixel Drawing/Reading */
#define GL_NONE 0x0
#define GL_LEFT 0x0406
#define GL_RIGHT 0x0407
/*GL_FRONT 0x0404 */
/*GL_BACK 0x0405 */
/*GL_FRONT_AND_BACK 0x0408 */
#define GL_FRONT_LEFT 0x0400
#define GL_FRONT_RIGHT 0x0401
#define GL_BACK_LEFT 0x0402
#define GL_BACK_RIGHT 0x0403
#define GL_AUX0 0x0409
#define GL_AUX1 0x040A
#define GL_AUX2 0x040B
#define GL_AUX3 0x040C
#define GL_COLOR_INDEX 0x1900
#define GL_RED 0x1903
#define GL_GREEN 0x1904
#define GL_BLUE 0x1905
#define GL_ALPHA 0x1906
#define GL_LUMINANCE 0x1909
#define GL_LUMINANCE_ALPHA 0x190A
#define GL_ALPHA_BITS 0x0D55
#define GL_RED_BITS 0x0D52
#define GL_GREEN_BITS 0x0D53
#define GL_BLUE_BITS 0x0D54
#define GL_INDEX_BITS 0x0D51
#define GL_SUBPIXEL_BITS 0x0D50
#define GL_AUX_BUFFERS 0x0C00
#define GL_READ_BUFFER 0x0C02
#define GL_DRAW_BUFFER 0x0C01
#define GL_DOUBLEBUFFER 0x0C32
#define GL_STEREO 0x0C33
#define GL_BITMAP 0x1A00
#define GL_COLOR 0x1800
#define GL_DEPTH 0x1801
#define GL_STENCIL 0x1802
#define GL_DITHER 0x0BD0
#define GL_RGB 0x1907
#define GL_RGBA 0x1908
#define GL_ALPHA4 0x803B
#define GL_ALPHA8 0x803C
#define GL_ALPHA12 0x803D
#define GL_ALPHA16 0x803E
#define GL_LUMINANCE4 0x803F
#define GL_LUMINANCE8 0x8040
#define GL_LUMINANCE12 0x8041
#define GL_LUMINANCE16 0x8042
#define GL_LUMINANCE4_ALPHA4 0x8043
#define GL_LUMINANCE6_ALPHA2 0x8044
#define GL_LUMINANCE8_ALPHA8 0x8045
#define GL_LUMINANCE12_ALPHA4 0x8046
#define GL_LUMINANCE12_ALPHA12 0x8047
#define GL_LUMINANCE16_ALPHA16 0x8048
#define GL_INTENSITY 0x8049
#define GL_INTENSITY4 0x804A
#define GL_INTENSITY8 0x804B
#define GL_INTENSITY12 0x804C
#define GL_INTENSITY16 0x804D
#define GL_RGB2 0x804E
#define GL_RGB4 0x804F
#define GL_RGB5 0x8050
#define GL_RGB8 0x8051
#define GL_RGB10 0x8052
#define GL_RGB12 0x8053
#define GL_RGB16 0x8054
#define GL_RGBA2 0x8055
#define GL_RGBA4 0x8056
#define GL_RGB5_A1 0x8057
#define GL_RGBA8 0x8058
#define GL_RGB10_A2 0x8059
#define GL_RGBA12 0x805A
#define GL_RGBA16 0x805B
#define GL_TEXTURE_RED_SIZE 0x805C
#define GL_TEXTURE_GREEN_SIZE 0x805D
#define GL_TEXTURE_BLUE_SIZE 0x805E
#define GL_TEXTURE_ALPHA_SIZE 0x805F
#define GL_TEXTURE_LUMINANCE_SIZE 0x8060
#define GL_TEXTURE_INTENSITY_SIZE 0x8061
/*#define GL_REPLACE 0x8062*/
#define GL_PROXY_TEXTURE_1D 0x8063
#define GL_PROXY_TEXTURE_2D 0x8064
/* Private limits */
#define GL_MAX_LIST_NESTING 0x0B31
#define GL_MAX_ATTRIB_STACK_DEPTH 0x0D35
#define GL_MAX_MODELVIEW_STACK_DEPTH 0x0D36
#define GL_MAX_NAME_STACK_DEPTH 0x0D37
#define GL_MAX_PROJECTION_STACK_DEPTH 0x0D38
#define GL_MAX_TEXTURE_STACK_DEPTH 0x0D39
#define GL_MAX_EVAL_ORDER 0x0D30
#define GL_MAX_LIGHTS 0x0D31
#define GL_MAX_CLIP_PLANES 0x0D32
#define GL_MAX_TEXTURE_SIZE 0x0D33
#define GL_MAX_PIXEL_MAP_TABLE 0x0D34
#define GL_MAX_VIEWPORT_DIMS 0x0D3A
#define GL_MAX_CLIENT_ATTRIB_STACK_DEPTH 0x0D3B
/* Gets */
#define GL_ATTRIB_STACK_DEPTH 0x0BB0
#define GL_CLIENT_ATTRIB_STACK_DEPTH 0x0BB1
#define GL_COLOR_CLEAR_VALUE 0x0C22
#define GL_COLOR_WRITEMASK 0x0C23
#define GL_CURRENT_INDEX 0x0B01
#define GL_CURRENT_COLOR 0x0B00
#define GL_CURRENT_NORMAL 0x0B02
#define GL_CURRENT_RASTER_COLOR 0x0B04
#define GL_CURRENT_RASTER_DISTANCE 0x0B09
#define GL_CURRENT_RASTER_INDEX 0x0B05
#define GL_CURRENT_RASTER_POSITION 0x0B07
#define GL_CURRENT_RASTER_TEXTURE_COORDS 0x0B06
#define GL_CURRENT_RASTER_POSITION_VALID 0x0B08
#define GL_CURRENT_TEXTURE_COORDS 0x0B03
#define GL_INDEX_CLEAR_VALUE 0x0C20
#define GL_INDEX_MODE 0x0C30
#define GL_INDEX_WRITEMASK 0x0C21
#define GL_MODELVIEW_MATRIX 0x0BA6
#define GL_MODELVIEW_STACK_DEPTH 0x0BA3
#define GL_NAME_STACK_DEPTH 0x0D70
#define GL_PROJECTION_MATRIX 0x0BA7
#define GL_PROJECTION_STACK_DEPTH 0x0BA4
#define GL_RENDER_MODE 0x0C40
#define GL_RGBA_MODE 0x0C31
#define GL_TEXTURE_MATRIX 0x0BA8
#define GL_TEXTURE_STACK_DEPTH 0x0BA5
#define GL_VIEWPORT 0x0BA2
/* Evaluators */
#define GL_AUTO_NORMAL 0x0D80
#define GL_MAP1_COLOR_4 0x0D90
#define GL_MAP1_INDEX 0x0D91
#define GL_MAP1_NORMAL 0x0D92
#define GL_MAP1_TEXTURE_COORD_1 0x0D93
#define GL_MAP1_TEXTURE_COORD_2 0x0D94
#define GL_MAP1_TEXTURE_COORD_3 0x0D95
#define GL_MAP1_TEXTURE_COORD_4 0x0D96
#define GL_MAP1_VERTEX_3 0x0D97
#define GL_MAP1_VERTEX_4 0x0D98
#define GL_MAP2_COLOR_4 0x0DB0
#define GL_MAP2_INDEX 0x0DB1
#define GL_MAP2_NORMAL 0x0DB2
#define GL_MAP2_TEXTURE_COORD_1 0x0DB3
#define GL_MAP2_TEXTURE_COORD_2 0x0DB4
#define GL_MAP2_TEXTURE_COORD_3 0x0DB5
#define GL_MAP2_TEXTURE_COORD_4 0x0DB6
#define GL_MAP2_VERTEX_3 0x0DB7
#define GL_MAP2_VERTEX_4 0x0DB8
#define GL_MAP1_GRID_DOMAIN 0x0DD0
#define GL_MAP1_GRID_SEGMENTS 0x0DD1
#define GL_MAP2_GRID_DOMAIN 0x0DD2
#define GL_MAP2_GRID_SEGMENTS 0x0DD3
#define GL_COEFF 0x0A00
#define GL_DOMAIN 0x0A02
#define GL_ORDER 0x0A01
/* Hints */
#define GL_FOG_HINT 0x0C54
#define GL_LINE_SMOOTH_HINT 0x0C52
#define GL_PERSPECTIVE_CORRECTION_HINT 0x0C50
#define GL_POINT_SMOOTH_HINT 0x0C51
#define GL_POLYGON_SMOOTH_HINT 0x0C53
#define GL_DONT_CARE 0x1100
#define GL_FASTEST 0x1101
#define GL_NICEST 0x1102
/* Scissor box */
#define GL_SCISSOR_TEST 0x0C11
#define GL_SCISSOR_BOX 0x0C10
/* Pixel Mode / Transfer */
#define GL_MAP_COLOR 0x0D10
#define GL_MAP_STENCIL 0x0D11
#define GL_INDEX_SHIFT 0x0D12
#define GL_INDEX_OFFSET 0x0D13
#define GL_RED_SCALE 0x0D14
#define GL_RED_BIAS 0x0D15
#define GL_GREEN_SCALE 0x0D18
#define GL_GREEN_BIAS 0x0D19
#define GL_BLUE_SCALE 0x0D1A
#define GL_BLUE_BIAS 0x0D1B
#define GL_ALPHA_SCALE 0x0D1C
#define GL_ALPHA_BIAS 0x0D1D
#define GL_DEPTH_SCALE 0x0D1E
#define GL_DEPTH_BIAS 0x0D1F
#define GL_PIXEL_MAP_S_TO_S_SIZE 0x0CB1
#define GL_PIXEL_MAP_I_TO_I_SIZE 0x0CB0
#define GL_PIXEL_MAP_I_TO_R_SIZE 0x0CB2
#define GL_PIXEL_MAP_I_TO_G_SIZE 0x0CB3
#define GL_PIXEL_MAP_I_TO_B_SIZE 0x0CB4
#define GL_PIXEL_MAP_I_TO_A_SIZE 0x0CB5
#define GL_PIXEL_MAP_R_TO_R_SIZE 0x0CB6
#define GL_PIXEL_MAP_G_TO_G_SIZE 0x0CB7
#define GL_PIXEL_MAP_B_TO_B_SIZE 0x0CB8
#define GL_PIXEL_MAP_A_TO_A_SIZE 0x0CB9
#define GL_PIXEL_MAP_S_TO_S 0x0C71
#define GL_PIXEL_MAP_I_TO_I 0x0C70
#define GL_PIXEL_MAP_I_TO_R 0x0C72
#define GL_PIXEL_MAP_I_TO_G 0x0C73
#define GL_PIXEL_MAP_I_TO_B 0x0C74
#define GL_PIXEL_MAP_I_TO_A 0x0C75
#define GL_PIXEL_MAP_R_TO_R 0x0C76
#define GL_PIXEL_MAP_G_TO_G 0x0C77
#define GL_PIXEL_MAP_B_TO_B 0x0C78
#define GL_PIXEL_MAP_A_TO_A 0x0C79
#define GL_PACK_ALIGNMENT 0x0D05
#define GL_PACK_LSB_FIRST 0x0D01
#define GL_PACK_ROW_LENGTH 0x0D02
#define GL_PACK_SKIP_PIXELS 0x0D04
#define GL_PACK_SKIP_ROWS 0x0D03
#define GL_PACK_SWAP_BYTES 0x0D00
#define GL_UNPACK_ALIGNMENT 0x0CF5
#define GL_UNPACK_LSB_FIRST 0x0CF1
#define GL_UNPACK_ROW_LENGTH 0x0CF2
#define GL_UNPACK_SKIP_PIXELS 0x0CF4
#define GL_UNPACK_SKIP_ROWS 0x0CF3
#define GL_UNPACK_SWAP_BYTES 0x0CF0
#define GL_ZOOM_X 0x0D16
#define GL_ZOOM_Y 0x0D17
/* Texture mapping */
#define GL_TEXTURE_ENV 0x2300
#define GL_TEXTURE_ENV_MODE 0x2200
#define GL_TEXTURE_1D 0x0DE0
#define GL_TEXTURE_2D 0x0DE1
#define GL_TEXTURE_WRAP_S 0x2802
#define GL_TEXTURE_WRAP_T 0x2803
#define GL_TEXTURE_MAG_FILTER 0x2800
#define GL_TEXTURE_MIN_FILTER 0x2801
#define GL_TEXTURE_ENV_COLOR 0x2201
#define GL_TEXTURE_GEN_S 0x0C60
#define GL_TEXTURE_GEN_T 0x0C61
#define GL_TEXTURE_GEN_MODE 0x2500
#define GL_TEXTURE_BORDER_COLOR 0x1004
#define GL_TEXTURE_WIDTH 0x1000
#define GL_TEXTURE_HEIGHT 0x1001
#define GL_TEXTURE_BORDER 0x1005
#define GL_TEXTURE_COMPONENTS 0x1003
#define GL_TEXTURE_RED_SIZE 0x805C
#define GL_TEXTURE_GREEN_SIZE 0x805D
#define GL_TEXTURE_BLUE_SIZE 0x805E
#define GL_TEXTURE_ALPHA_SIZE 0x805F
#define GL_TEXTURE_LUMINANCE_SIZE 0x8060
#define GL_TEXTURE_INTENSITY_SIZE 0x8061
#define GL_NEAREST_MIPMAP_NEAREST 0x2700
#define GL_NEAREST_MIPMAP_LINEAR 0x2702
#define GL_LINEAR_MIPMAP_NEAREST 0x2701
#define GL_LINEAR_MIPMAP_LINEAR 0x2703
#define GL_OBJECT_LINEAR 0x2401
#define GL_OBJECT_PLANE 0x2501
#define GL_EYE_LINEAR 0x2400
#define GL_EYE_PLANE 0x2502
#define GL_SPHERE_MAP 0x2402
#define GL_DECAL 0x2101
#define GL_MODULATE 0x2100
#define GL_NEAREST 0x2600
#define GL_REPEAT 0x2901
#define GL_CLAMP 0x2900
#define GL_S 0x2000
#define GL_T 0x2001
#define GL_R 0x2002
#define GL_Q 0x2003
#define GL_TEXTURE_GEN_R 0x0C62
#define GL_TEXTURE_GEN_Q 0x0C63
#define GL_TEXTURE_PRIORITY 0x8066
#define GL_TEXTURE_RESIDENT 0x8067
#define GL_TEXTURE_BINDING_1D 0x8068
#define GL_TEXTURE_BINDING_2D 0x8069
#define GL_TEXTURE_BINDING_3D 0x806A
/* Utility */
#define GL_VENDOR 0x1F00
#define GL_RENDERER 0x1F01
#define GL_VERSION 0x1F02
#define GL_EXTENSIONS 0x1F03
/* Errors */
#define GL_NO_ERROR 0x0
#define GL_INVALID_VALUE 0x0501
#define GL_INVALID_ENUM 0x0500
#define GL_INVALID_OPERATION 0x0502
#define GL_STACK_OVERFLOW 0x0503
#define GL_STACK_UNDERFLOW 0x0504
#define GL_OUT_OF_MEMORY 0x0505
/* glPush/PopAttrib bits */
#define GL_CURRENT_BIT 0x00000001
#define GL_POINT_BIT 0x00000002
#define GL_LINE_BIT 0x00000004
#define GL_POLYGON_BIT 0x00000008
#define GL_POLYGON_STIPPLE_BIT 0x00000010
#define GL_PIXEL_MODE_BIT 0x00000020
#define GL_LIGHTING_BIT 0x00000040
#define GL_FOG_BIT 0x00000080
#define GL_DEPTH_BUFFER_BIT 0x00000100
#define GL_ACCUM_BUFFER_BIT 0x00000200
#define GL_STENCIL_BUFFER_BIT 0x00000400
#define GL_VIEWPORT_BIT 0x00000800
#define GL_TRANSFORM_BIT 0x00001000
#define GL_ENABLE_BIT 0x00002000
#define GL_COLOR_BUFFER_BIT 0x00004000
#define GL_HINT_BIT 0x00008000
#define GL_EVAL_BIT 0x00010000
#define GL_LIST_BIT 0x00020000
#define GL_TEXTURE_BIT 0x00040000
#define GL_SCISSOR_BIT 0x00080000
#define GL_ALL_ATTRIB_BITS 0x000FFFFF

View file

@ -0,0 +1,347 @@
//-----------------------------------------------------------------------------
// Copyright (c) 2012 GarageGames, LLC
//
// Permission is hereby granted, free of charge, to any person obtaining a copy
// of this software and associated documentation files (the "Software"), to
// deal in the Software without restriction, including without limitation the
// rights to use, copy, modify, merge, publish, distribute, sublicense, and/or
// sell copies of the Software, and to permit persons to whom the Software is
// furnished to do so, subject to the following conditions:
//
// The above copyright notice and this permission notice shall be included in
// all copies or substantial portions of the Software.
//
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
// FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS
// IN THE SOFTWARE.
//-----------------------------------------------------------------------------
// OpenGL 1.1 core functions
GL_GROUP_BEGIN(GL_VERSION_1_1)
GL_FUNCTION(glAccum, void, (GLenum op, GLfloat value))
GL_FUNCTION(glAlphaFunc, void, (GLenum func, GLclampf ref))
GL_FUNCTION(glAreTexturesResident, void, (GLsizei n, const GLuint *textures, GLboolean *residences))
GL_FUNCTION(glArrayElement, void, (GLint i))
GL_FUNCTION(glBegin, void, (GLenum mode))
GL_FUNCTION(glBindTexture, void, (GLenum target, GLuint texture))
GL_FUNCTION(glBitmap, void, (GLsizei width, GLsizei height, GLfloat xorig, GLfloat yorig, GLfloat xmove, GLfloat ymove, const GLubyte *bitmap))
GL_FUNCTION(glBlendFunc, void, (GLenum sfactor, GLenum dfactor))
GL_FUNCTION(glCallList, void, (GLuint list))
GL_FUNCTION(glCallLists, void, (GLsizei n, GLenum type, const GLvoid *lists))
GL_FUNCTION(glClear, void, (GLbitfield mask))
GL_FUNCTION(glClearAccum, void, (GLfloat red, GLfloat green, GLfloat blue, GLfloat alpha))
GL_FUNCTION(glClearColor, void, (GLclampf red, GLclampf green, GLclampf blue, GLclampf alpha))
GL_FUNCTION(glClearDepth, void, (GLclampd depth))
GL_FUNCTION(glClearIndex, void, (GLfloat c))
GL_FUNCTION(glClearStencil, void, (GLint s))
GL_FUNCTION(glClipPlane, void, (GLenum plane, const GLdouble *equation))
GL_FUNCTION(glColor3b, void, (GLbyte red, GLbyte green, GLbyte blue))
GL_FUNCTION(glColor3bv, void, (const GLbyte *v))
GL_FUNCTION(glColor3d, void, (GLdouble red, GLdouble green, GLdouble blue))
GL_FUNCTION(glColor3dv, void, (const GLdouble *v))
GL_FUNCTION(glColor3f, void, (GLfloat red, GLfloat green, GLfloat blue))
GL_FUNCTION(glColor3fv, void, (const GLfloat *v))
GL_FUNCTION(glColor3i, void, (GLint red, GLint green, GLint blue))
GL_FUNCTION(glColor3iv, void, (const GLint *v))
GL_FUNCTION(glColor3s, void, (GLshort red, GLshort green, GLshort blue))
GL_FUNCTION(glColor3sv, void, (const GLshort *v))
GL_FUNCTION(glColor3ub, void, (GLubyte red, GLubyte green, GLubyte blue))
GL_FUNCTION(glColor3ubv, void, (const GLubyte *v))
GL_FUNCTION(glColor3ui, void, (GLuint red, GLuint green, GLuint blue))
GL_FUNCTION(glColor3uiv, void, (const GLuint *v))
GL_FUNCTION(glColor3us, void, (GLushort red, GLushort green, GLushort blue))
GL_FUNCTION(glColor3usv, void, (const GLushort *v))
GL_FUNCTION(glColor4b, void, (GLbyte red, GLbyte green, GLbyte blue, GLbyte alpha))
GL_FUNCTION(glColor4bv, void, (const GLbyte *v))
GL_FUNCTION(glColor4d, void, (GLdouble red, GLdouble green, GLdouble blue, GLdouble alpha))
GL_FUNCTION(glColor4dv, void, (const GLdouble *v))
GL_FUNCTION(glColor4f, void, (GLfloat red, GLfloat green, GLfloat blue, GLfloat alpha))
GL_FUNCTION(glColor4fv, void, (const GLfloat *v))
GL_FUNCTION(glColor4i, void, (GLint red, GLint green, GLint blue, GLint alpha))
GL_FUNCTION(glColor4iv, void, (const GLint *v))
GL_FUNCTION(glColor4s, void, (GLshort red, GLshort green, GLshort blue, GLshort alpha))
GL_FUNCTION(glColor4sv, void, (const GLshort *v))
GL_FUNCTION(glColor4ub, void, (GLubyte red, GLubyte green, GLubyte blue, GLubyte alpha))
GL_FUNCTION(glColor4ubv, void, (const GLubyte *v))
GL_FUNCTION(glColor4ui, void, (GLuint red, GLuint green, GLuint blue, GLuint alpha))
GL_FUNCTION(glColor4uiv, void, (const GLuint *v))
GL_FUNCTION(glColor4us, void, (GLushort red, GLushort green, GLushort blue, GLushort alpha))
GL_FUNCTION(glColor4usv, void, (const GLushort *v))
GL_FUNCTION(glColorMask, void, (GLboolean red, GLboolean green, GLboolean blue, GLboolean alpha))
GL_FUNCTION(glColorMaterial, void, (GLenum face, GLenum mode))
GL_FUNCTION(glCopyPixels, void, (GLint x, GLint y, GLsizei width, GLsizei height, GLenum type))
GL_FUNCTION(glCopyTexImage1D, void, (GLenum target, GLint level, GLenum internalformat, GLint x, GLint y, GLsizei width, GLint border))
GL_FUNCTION(glCopyTexImage2D, void, (GLenum target, GLint level, GLenum internalformat, GLint x, GLint y, GLsizei width, GLsizei height, GLint border))
GL_FUNCTION(glCopyTexSubImage1D, void, (GLenum target, GLint level, GLint xoffset, GLint x, GLint y, GLsizei width))
GL_FUNCTION(glCopyTexSubImage2D, void, (GLenum target, GLint level, GLint xoffset, GLint yoffset, GLint x, GLint y, GLsizei width, GLsizei height))
GL_FUNCTION(glCullFace, void, (GLenum mode))
GL_FUNCTION(glDeleteLists, void, (GLuint list, GLsizei range))
GL_FUNCTION(glDeleteTextures, void, (GLsizei n, const GLuint *textures))
GL_FUNCTION(glDepthFunc, void, (GLenum func))
GL_FUNCTION(glDepthMask, void, (GLboolean flag))
GL_FUNCTION(glDepthRange, void, (GLclampd zNear, GLclampd zFar))
GL_FUNCTION(glDisable, void, (GLenum cap))
GL_FUNCTION(glDisableClientState, void, (GLenum array))
GL_FUNCTION(glDrawArrays, void, (GLenum mode, GLint first, GLsizei count))
GL_FUNCTION(glDrawBuffer, void, (GLenum mode))
GL_FUNCTION(glDrawElements, void, (GLenum mode, GLsizei count, GLenum type, const GLvoid *indices))
GL_FUNCTION(glDrawPixels, void, (GLsizei width, GLsizei height, GLenum format, GLenum type, const GLvoid *pixels))
GL_FUNCTION(glEdgeFlag, void, (GLboolean flag))
GL_FUNCTION(glEdgeFlagPointer, void, (GLsizei stride, const GLboolean *pointer))
GL_FUNCTION(glEnable, void, (GLenum cap))
GL_FUNCTION(glEndList, void, (void))
GL_FUNCTION(glEnableClientState, void, (GLenum array))
GL_FUNCTION(glEnd, void, (void))
GL_FUNCTION(glEvalCoord1d, void, (GLdouble u))
GL_FUNCTION(glEvalCoord1f, void, (GLfloat u))
GL_FUNCTION(glEvalCoord2d, void, (GLdouble u, GLdouble v))
GL_FUNCTION(glEvalCoord2f, void, (GLfloat u, GLfloat v))
GL_FUNCTION(glEvalMesh1, void, (GLenum mode, GLint i1, GLint i2))
GL_FUNCTION(glEvalMesh2, void, (GLenum mode, GLint i1, GLint i2, GLint j1, GLint j2))
GL_FUNCTION(glEvalPoint1, void, (GLint i))
GL_FUNCTION(glEvalPoint2, void, (GLint i, GLint j))
GL_FUNCTION(glFeedbackBuffer, void, (GLsizei size, GLenum type, GLfloat *buffer))
GL_FUNCTION(glFinish, void, (void))
GL_FUNCTION(glFlush, void, (void))
GL_FUNCTION(glFogf, void, (GLenum pname, GLfloat param))
GL_FUNCTION(glFogfv, void, (GLenum pname, const GLfloat *params))
GL_FUNCTION(glFogi, void, (GLenum pname, GLint param))
GL_FUNCTION(glFogiv, void, (GLenum pname, const GLint *params))
GL_FUNCTION(glFrontFace, void, (GLenum mode))
GL_FUNCTION(glFrustum, void, (GLdouble left, GLdouble right, GLdouble bottom, GLdouble top, GLdouble zNear, GLdouble zFar))
GL_FUNCTION(glGenLists, GLuint, (GLsizei range))
GL_FUNCTION(glGenTextures, void, (GLsizei n, GLuint *textures))
GL_FUNCTION(glGetBooleanv, void, (GLenum pname, GLboolean *params))
GL_FUNCTION(glGetClipPlane, void, (GLenum plane, GLdouble *equation))
GL_FUNCTION(glColorPointer, void, (GLint size, GLenum type, GLsizei stride, const GLvoid *pointer))
GL_FUNCTION(glGetDoublev, void, (GLenum pname, GLdouble *params))
GL_FUNCTION(glGetFloatv, void, (GLenum pname, GLfloat *params))
GL_FUNCTION(glGetError, GLuint, (void))
GL_FUNCTION(glGetIntegerv, void, (GLenum pname, GLint *params))
GL_FUNCTION(glGetLightfv, void, (GLenum light, GLenum pname, GLfloat *params))
GL_FUNCTION(glGetLightiv, void, (GLenum light, GLenum pname, GLint *params))
GL_FUNCTION(glGetMapdv, void, (GLenum target, GLenum query, GLdouble *v))
GL_FUNCTION(glGetMapfv, void, (GLenum target, GLenum query, GLfloat *v))
GL_FUNCTION(glGetMapiv, void, (GLenum target, GLenum query, GLint *v))
GL_FUNCTION(glGetMaterialfv, void, (GLenum face, GLenum pname, GLfloat *params))
GL_FUNCTION(glGetMaterialiv, void, (GLenum face, GLenum pname, GLint *params))
GL_FUNCTION(glGetPixelMapfv, void, (GLenum map, GLfloat *values))
GL_FUNCTION(glGetPixelMapuiv, void, (GLenum map, GLuint *values))
GL_FUNCTION(glGetPixelMapusv, void, (GLenum map, GLushort *values))
GL_FUNCTION(glGetPointerv, void, (GLenum pname, GLvoid* *params))
GL_FUNCTION(glGetPolygonStipple, void, (GLubyte *mask))
GL_FUNCTION(glGetString, const GLubyte*, (GLenum name))
GL_FUNCTION(glGetTexEnvfv, void, (GLenum target, GLenum pname, GLfloat *params))
GL_FUNCTION(glGetTexEnviv, void, (GLenum target, GLenum pname, GLint *params))
GL_FUNCTION(glGetTexGendv, void, (GLenum coord, GLenum pname, GLdouble *params))
GL_FUNCTION(glGetTexGenfv, void, (GLenum coord, GLenum pname, GLfloat *params))
GL_FUNCTION(glGetTexGeniv, void, (GLenum coord, GLenum pname, GLint *params))
GL_FUNCTION(glGetTexImage, void, (GLenum target, GLint level, GLenum format, GLenum type, GLvoid *pixels))
GL_FUNCTION(glGetTexLevelParameterfv, void, (GLenum target, GLint level, GLenum pname, GLfloat *params))
GL_FUNCTION(glGetTexLevelParameteriv, void, (GLenum target, GLint level, GLenum pname, GLint *params))
GL_FUNCTION(glGetTexParameterfv, void, (GLenum target, GLenum pname, GLfloat *params))
GL_FUNCTION(glGetTexParameteriv, void, (GLenum target, GLenum pname, GLint *params))
GL_FUNCTION(glHint, void, (GLenum target, GLenum mode))
GL_FUNCTION(glIndexd, void, (GLdouble c))
GL_FUNCTION(glIndexf, void, (GLfloat c))
GL_FUNCTION(glIndexi, void, (GLint c))
GL_FUNCTION(glIndexs, void, (GLshort c))
GL_FUNCTION(glIndexub, void, (GLubyte c))
GL_FUNCTION(glIndexMask, void, (GLuint mask))
GL_FUNCTION(glIndexPointer, void, (GLenum type, GLsizei stride, const GLvoid *pointer))
GL_FUNCTION(glInitNames, void, (void))
GL_FUNCTION(glInterleavedArrays, void, (GLenum format, GLsizei stride, const GLvoid *pointer))
GL_FUNCTION(glIsEnabled, GLboolean, (GLenum cap))
GL_FUNCTION(glIsList, GLboolean, (GLuint list))
GL_FUNCTION(glIsTexture, GLboolean, (GLuint texture))
GL_FUNCTION(glLightf, void, (GLenum light, GLenum pname, GLfloat param))
GL_FUNCTION(glLightfv, void, (GLenum light, GLenum pname, const GLfloat *params))
GL_FUNCTION(glLighti, void, (GLenum light, GLenum pname, GLint param))
GL_FUNCTION(glLightiv, void, (GLenum light, GLenum pname, const GLint *params))
GL_FUNCTION(glLightModelf, void, (GLenum pname, GLfloat param))
GL_FUNCTION(glLightModelfv, void, (GLenum pname, const GLfloat *params))
GL_FUNCTION(glLightModeli, void, (GLenum pname, GLint param))
GL_FUNCTION(glLightModeliv, void, (GLenum pname, const GLint *params))
GL_FUNCTION(glLineStipple, void, (GLint factor, GLushort pattern))
GL_FUNCTION(glLineWidth, void, (GLfloat width))
GL_FUNCTION(glListBase, void, (GLuint base))
GL_FUNCTION(glLoadIdentity, void, (void))
GL_FUNCTION(glLoadMatrixd, void, (const GLdouble *m))
GL_FUNCTION(glLoadMatrixf, void, (const GLfloat *m))
GL_FUNCTION(glLoadName, void, (GLuint name))
GL_FUNCTION(glLogicOp, void, (GLenum opcode))
GL_FUNCTION(glMap1d, void, (GLenum target, GLdouble u1, GLdouble u2, GLint stride, GLint order, const GLdouble *points))
GL_FUNCTION(glMap1f, void, (GLenum target, GLfloat u1, GLfloat u2, GLint stride, GLint order, const GLdouble *points))
GL_FUNCTION(glMap2d, void, (GLenum target, GLdouble u1, GLdouble u2, GLint ustride, GLint uorder, GLdouble v1, GLdouble v2, GLint vstride, GLint vorder, const GLdouble *points))
GL_FUNCTION(glMap2f, void, (GLenum target, GLfloat u1, GLfloat u2, GLint ustride, GLint uorder, GLfloat v1, GLfloat v2, GLint vstride, GLint vorder, const GLfloat *points))
GL_FUNCTION(glMapGrid1d, void, (GLint un, GLdouble u1, GLdouble u2))
GL_FUNCTION(glMapGrid1f, void, (GLint un, GLfloat u1, GLfloat u2))
GL_FUNCTION(glMapGrid2d, void, (GLint un, GLdouble u1, GLdouble u2, GLint vn, GLdouble v1, GLdouble v2))
GL_FUNCTION(glMapGrid2f, void, (GLint un, GLfloat u1, GLfloat u2, GLint vn, GLfloat v1, GLfloat v2))
GL_FUNCTION(glMaterialf, void, (GLenum face, GLenum pname, GLfloat param))
GL_FUNCTION(glMaterialfv, void, (GLenum face, GLenum pname, const GLfloat* params))
GL_FUNCTION(glMateriali, void, (GLenum face, GLenum pname, GLint param))
GL_FUNCTION(glMaterialiv, void, (GLenum face, GLenum pname, const GLint* params))
GL_FUNCTION(glMatrixMode, void, (GLenum mode))
GL_FUNCTION(glMultMatrixd, void, (const GLdouble *m))
GL_FUNCTION(glMultMatrixf, void, (const GLfloat *m))
GL_FUNCTION(glNewList, void, (GLuint list, GLenum mode))
GL_FUNCTION(glNormal3b, void, (GLbyte nx, GLbyte ny, GLbyte nz))
GL_FUNCTION(glNormal3bv, void, (const GLbyte *v))
GL_FUNCTION(glNormal3d, void, (GLdouble nx, GLdouble ny, GLdouble nz))
GL_FUNCTION(glNormal3dv, void, (const GLdouble *v))
GL_FUNCTION(glNormal3f, void, (GLfloat nx, GLfloat ny, GLfloat nz))
GL_FUNCTION(glNormal3fv, void, (const GLfloat *v))
GL_FUNCTION(glNormal3i, void, (GLint nx, GLint ny, GLint nz))
GL_FUNCTION(glNormal3iv, void, (const GLint *v))
GL_FUNCTION(glNormal3s, void, (GLshort nx, GLshort ny, GLshort nz))
GL_FUNCTION(glNormal3sv, void, (const GLshort *v))
GL_FUNCTION(glNormalPointer, void, (GLenum type, GLsizei stride, const GLvoid *pointer))
GL_FUNCTION(glOrtho, void, (GLdouble left, GLdouble right, GLdouble bottom, GLdouble top, GLdouble zNear, GLdouble zFar))
GL_FUNCTION(glPassThrough, void, (GLfloat token))
GL_FUNCTION(glPixelMapfv, void, (GLenum map, GLint mapSize, const GLfloat *values))
GL_FUNCTION(glPixelMapuiv, void, (GLenum map, GLint mapSize, const GLuint *values))
GL_FUNCTION(glPixelMapusv, void, (GLenum map, GLint mapSize, const GLushort *values))
GL_FUNCTION(glPixelStoref, void, (GLenum pname, GLfloat param))
GL_FUNCTION(glPixelStorei, void, (GLenum pname, GLint param))
GL_FUNCTION(glPixelTransferf, void, (GLenum pname, GLfloat param))
GL_FUNCTION(glPixelTransferi, void, (GLenum pname, GLint param))
GL_FUNCTION(glPixelZoom, void, (GLfloat xfactor, GLfloat yfactor))
GL_FUNCTION(glPointSize, void, (GLfloat size))
GL_FUNCTION(glPolygonMode, void, (GLenum face, GLenum mode))
GL_FUNCTION(glPolygonOffset, void, (GLfloat factor, GLfloat units))
GL_FUNCTION(glPopAttrib, void, (void))
GL_FUNCTION(glPopMatrix, void, (void))
GL_FUNCTION(glPopName, void, (void))
GL_FUNCTION(glPrioritizeTextures, void, (GLsizei n, const GLuint *textures, const GLclampf *priorities))
GL_FUNCTION(glPushAttrib, void, (GLbitfield mask))
GL_FUNCTION(glPushMatrix, void, (void))
GL_FUNCTION(glPushName, void, (GLuint name))
GL_FUNCTION(glRasterPos2d, void, (GLdouble x, GLdouble y))
GL_FUNCTION(glRasterPos2dv, void, (const GLdouble *v))
GL_FUNCTION(glRasterPos2f, void, (GLfloat x, GLfloat y))
GL_FUNCTION(glRasterPos2fv, void, (const GLfloat *v))
GL_FUNCTION(glRasterPos2i, void, (GLint x, GLint y))
GL_FUNCTION(glRasterPos2iv, void, (const GLint *v))
GL_FUNCTION(glRasterPos2s, void, (GLshort x, GLshort y))
GL_FUNCTION(glRasterPos2sv, void, (const GLshort *v))
GL_FUNCTION(glRasterPos3d, void, (GLdouble x, GLdouble y, GLdouble z))
GL_FUNCTION(glRasterPos3dv, void, (const GLdouble *v))
GL_FUNCTION(glRasterPos3f, void, (GLfloat x, GLfloat y, GLfloat z))
GL_FUNCTION(glRasterPos3fv, void, (const GLfloat *v))
GL_FUNCTION(glRasterPos3i, void, (GLint x, GLint y, GLint z))
GL_FUNCTION(glRasterPos3iv, void, (const GLint *v))
GL_FUNCTION(glRasterPos3s, void, (GLshort x, GLshort y, GLshort z))
GL_FUNCTION(glRasterPos3sv, void, (const GLshort *v))
GL_FUNCTION(glRasterPos4d, void, (GLdouble x, GLdouble y, GLdouble z, GLdouble w))
GL_FUNCTION(glRasterPos4dv, void, (const GLdouble *v))
GL_FUNCTION(glRasterPos4f, void, (GLfloat x, GLfloat y, GLfloat z, GLfloat w))
GL_FUNCTION(glRasterPos4fv, void, (const GLfloat *v))
GL_FUNCTION(glRasterPos4i, void, (GLint x, GLint y, GLint z, GLint w))
GL_FUNCTION(glRasterPos4iv, void, (const GLint *v))
GL_FUNCTION(glRasterPos4s, void, (GLshort x, GLshort y, GLshort z, GLshort w))
GL_FUNCTION(glRasterPos4sv, void, (const GLshort *v))
GL_FUNCTION(glReadBuffer, void, (GLenum mode))
GL_FUNCTION(glReadPixels, void, (GLint x, GLint y, GLsizei width, GLsizei height, GLenum format, GLenum type, GLvoid *pixels))
GL_FUNCTION(glRectd, void, (GLdouble x1, GLdouble y1, GLdouble x2, GLdouble y2))
GL_FUNCTION(glRectdv, void, (const GLdouble *v))
GL_FUNCTION(glRectf, void, (GLfloat x1, GLfloat y1, GLfloat x2, GLfloat y2))
GL_FUNCTION(glRectfv, void, (const GLfloat *v))
GL_FUNCTION(glRecti, void, (GLint x1, GLint y1, GLint x2, GLint y2))
GL_FUNCTION(glRectiv, void, (const GLint *v))
GL_FUNCTION(glRects, void, (GLshort x1, GLshort y1, GLshort x2, GLshort y2))
GL_FUNCTION(glRectsv, void, (const GLshort *v))
GL_FUNCTION(glRenderMode, void, (GLenum mode))
GL_FUNCTION(glRotated, void, (GLdouble angle, GLdouble x, GLdouble y, GLdouble z))
GL_FUNCTION(glRotatef, void, (GLfloat angle, GLfloat x, GLfloat y, GLfloat z))
GL_FUNCTION(glScaled, void, (GLdouble x, GLdouble y, GLdouble z))
GL_FUNCTION(glScalef, void, (GLfloat x, GLfloat y, GLfloat z))
GL_FUNCTION(glScissor, void, (GLint x, GLint y, GLsizei width, GLsizei height))
GL_FUNCTION(glSelectBuffer, void, (GLsizei size, GLuint *buffer))
GL_FUNCTION(glShadeModel, void, (GLenum mode))
GL_FUNCTION(glStencilFunc, void, (GLenum func, GLint ref, GLuint mask))
GL_FUNCTION(glStencilMask, void, (GLuint mask))
GL_FUNCTION(glStencilOp, void, (GLenum fail, GLenum zfail, GLenum zpass))
GL_FUNCTION(glTexCoord1d, void, (GLdouble s))
GL_FUNCTION(glTexCoord1dv, void, (const GLdouble *v))
GL_FUNCTION(glTexCoord1f, void, (GLfloat s))
GL_FUNCTION(glTexCoord1fv, void, (const GLfloat *v))
GL_FUNCTION(glTexCoord1i, void, (GLint s))
GL_FUNCTION(glTexCoord1iv, void, (const GLint *v))
GL_FUNCTION(glTexCoord1s, void, (GLshort s))
GL_FUNCTION(glTexCoord1sv, void, (const GLshort *v))
GL_FUNCTION(glTexCoord2d, void, (GLdouble s, GLdouble t))
GL_FUNCTION(glTexCoord2dv, void, (const GLdouble *v))
GL_FUNCTION(glTexCoord2f, void, (GLfloat s, GLfloat t))
GL_FUNCTION(glTexCoord2fv, void, (const GLfloat *v))
GL_FUNCTION(glTexCoord2i, void, (GLint s, GLint t))
GL_FUNCTION(glTexCoord2iv, void, (const GLint *v))
GL_FUNCTION(glTexCoord2s, void, (GLshort s, GLshort t))
GL_FUNCTION(glTexCoord2sv, void, (const GLshort *v))
GL_FUNCTION(glTexCoord3d, void, (GLdouble s, GLdouble t, GLdouble r))
GL_FUNCTION(glTexCoord3dv, void, (const GLdouble *v))
GL_FUNCTION(glTexCoord3f, void, (GLfloat s, GLfloat t, GLfloat r))
GL_FUNCTION(glTexCoord3fv, void, (const GLfloat *v))
GL_FUNCTION(glTexCoord3i, void, (GLint s, GLint t, GLint r))
GL_FUNCTION(glTexCoord3iv, void, (const GLint *v))
GL_FUNCTION(glTexCoord3s, void, (GLshort s, GLshort t, GLshort r))
GL_FUNCTION(glTexCoord3sv, void, (const GLshort *v))
GL_FUNCTION(glTexCoord4d, void, (GLdouble s, GLdouble t, GLdouble r, GLdouble q))
GL_FUNCTION(glTexCoord4dv, void, (const GLdouble *v))
GL_FUNCTION(glTexCoord4f, void, (GLfloat s, GLfloat t, GLfloat r, GLfloat q))
GL_FUNCTION(glTexCoord4fv, void, (const GLfloat *v))
GL_FUNCTION(glTexCoord4i, void, (GLint s, GLint t, GLint r, GLint q))
GL_FUNCTION(glTexCoord4iv, void, (const GLint *v))
GL_FUNCTION(glTexCoord4s, void, (GLshort s, GLshort t, GLshort r, GLshort q))
GL_FUNCTION(glTexCoord4sv, void, (const GLshort *v))
GL_FUNCTION(glTexCoordPointer, void, (GLint size, GLenum type, GLsizei stride, const GLvoid *pointer))
GL_FUNCTION(glTexEnvf, void, (GLenum target, GLenum pname, GLfloat param))
GL_FUNCTION(glTexEnvfv, void, (GLenum target, GLenum pname, const GLfloat *params))
GL_FUNCTION(glTexEnvi, void, (GLenum target, GLenum pname, GLint param))
GL_FUNCTION(glTexEnviv, void, (GLenum target, GLenum pname, const GLint *params))
GL_FUNCTION(glTexGend, void, (GLenum coord, GLenum pname, GLdouble param))
GL_FUNCTION(glTexGendv, void, (GLenum coord, GLenum pname, const GLdouble *param))
GL_FUNCTION(glTexGenf, void, (GLenum coord, GLenum pname, GLfloat param))
GL_FUNCTION(glTexGenfv, void, (GLenum coord, GLenum pname, const GLfloat *param))
GL_FUNCTION(glTexGeni, void, (GLenum coord, GLenum pname, GLint param))
GL_FUNCTION(glTexGeniv, void, (GLenum coord, GLenum pname, const GLint *param))
GL_FUNCTION(glTexImage1D, void, (GLenum target, GLint level, GLint internalformat, GLsizei width, GLint border, GLenum format, GLenum type, const GLvoid *pixels))
GL_FUNCTION(glTexImage2D, void, (GLenum target, GLint level, GLint internalformat, GLsizei width, GLsizei height, GLint border, GLenum format, GLenum type, const GLvoid *pixels))
GL_FUNCTION(glTexParameterf, void, (GLenum target, GLenum pname, GLfloat param))
GL_FUNCTION(glTexParameteri, void, (GLenum target, GLenum pname, GLint param))
GL_FUNCTION(glTexSubImage1D, void, (GLenum target, GLint level, GLint xoffset, GLsizei width, GLenum format, GLenum type, const GLvoid *pixels))
GL_FUNCTION(glTexSubImage2D, void, (GLenum target, GLint level, GLint xoffset, GLint yoffset, GLsizei width, GLsizei height, GLenum format, GLenum type, const GLvoid *pixels))
GL_FUNCTION(glTranslated, void, (GLdouble x, GLdouble y, GLdouble z))
GL_FUNCTION(glTranslatef, void, (GLfloat x, GLfloat y, GLfloat z))
GL_FUNCTION(glVertex2d, void, (GLdouble x, GLdouble y))
GL_FUNCTION(glVertex2dv, void, (const GLdouble *v))
GL_FUNCTION(glVertex2f, void, (GLfloat x, GLfloat y))
GL_FUNCTION(glVertex2fv, void, (const GLfloat *v))
GL_FUNCTION(glVertex2i, void, (GLint x, GLint y))
GL_FUNCTION(glVertex2iv, void, (const GLint *v))
GL_FUNCTION(glVertex2s, void, (GLshort x, GLshort y))
GL_FUNCTION(glVertex2sv, void, (const GLshort *v))
GL_FUNCTION(glVertex3d, void, (GLdouble x, GLdouble y, GLdouble z))
GL_FUNCTION(glVertex3dv, void, (const GLdouble *v))
GL_FUNCTION(glVertex3f, void, (GLfloat x, GLfloat y, GLfloat z))
GL_FUNCTION(glVertex3fv, void, (const GLfloat *v))
GL_FUNCTION(glVertex3i, void, (GLint x, GLint y, GLint z))
GL_FUNCTION(glVertex3iv, void, (const GLint *v))
GL_FUNCTION(glVertex3s, void, (GLshort x, GLshort y, GLshort z))
GL_FUNCTION(glVertex3sv, void, (const GLshort *v))
GL_FUNCTION(glVertex4d, void, (GLdouble x, GLdouble y, GLdouble z, GLdouble w))
GL_FUNCTION(glVertex4dv, void, (const GLdouble *v))
GL_FUNCTION(glVertex4f, void, (GLfloat x, GLfloat y, GLfloat z, GLfloat w))
GL_FUNCTION(glVertex4fv, void, (const GLfloat *v))
GL_FUNCTION(glVertex4i, void, (GLint x, GLint y, GLint z, GLint w))
GL_FUNCTION(glVertex4iv, void, (const GLint *v))
GL_FUNCTION(glVertex4s, void, (GLshort x, GLshort y, GLshort z, GLshort w))
GL_FUNCTION(glVertex4sv, void, (const GLshort *v))
GL_FUNCTION(glVertexPointer, void, (GLint size, GLenum type, GLsizei stride, const GLvoid *pointer))
GL_FUNCTION(glViewport, void, (GLint x, GLint y, GLsizei width, GLsizei height))
GL_GROUP_END()

File diff suppressed because it is too large Load diff

File diff suppressed because it is too large Load diff

View file

@ -0,0 +1,405 @@
//-----------------------------------------------------------------------------
// Copyright (c) 2012 GarageGames, LLC
//
// Permission is hereby granted, free of charge, to any person obtaining a copy
// of this software and associated documentation files (the "Software"), to
// deal in the Software without restriction, including without limitation the
// rights to use, copy, modify, merge, publish, distribute, sublicense, and/or
// sell copies of the Software, and to permit persons to whom the Software is
// furnished to do so, subject to the following conditions:
//
// The above copyright notice and this permission notice shall be included in
// all copies or substantial portions of the Software.
//
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
// FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS
// IN THE SOFTWARE.
//-----------------------------------------------------------------------------
#ifdef GLX_3DFX_multisample
#define GLX_SAMPLE_BUFFERS_3DFX 0x8050
#define GLX_SAMPLES_3DFX 0x8051
#endif
#ifdef GLX_ARB_fbconfig_float
#define GLX_RGBA_FLOAT_BIT 0x00000004
#define GLX_RGBA_FLOAT_TYPE 0x20B9
#endif
#ifdef GLX_ARB_get_proc_address
#define glXGetProcAddressARB XGL_FUNCPTR(glXGetProcAddressARB)
#endif
#ifdef GLX_ARB_multisample
#define GLX_SAMPLE_BUFFERS_ARB 100000
#define GLX_SAMPLES_ARB 100001
#endif
#ifdef GLX_ATI_pixel_format_float
#define GLX_RGBA_FLOAT_ATI_BIT 0x00000100
#endif
#ifdef GLX_ATI_render_texture
#define GLX_BIND_TO_TEXTURE_RGB_ATI 0x9800
#define GLX_BIND_TO_TEXTURE_RGBA_ATI 0x9801
#define GLX_TEXTURE_FORMAT_ATI 0x9802
#define GLX_TEXTURE_TARGET_ATI 0x9803
#define GLX_MIPMAP_TEXTURE_ATI 0x9804
#define GLX_TEXTURE_RGB_ATI 0x9805
#define GLX_TEXTURE_RGBA_ATI 0x9806
#define GLX_NO_TEXTURE_ATI 0x9807
#define GLX_TEXTURE_CUBE_MAP_ATI 0x9808
#define GLX_TEXTURE_1D_ATI 0x9809
#define GLX_TEXTURE_2D_ATI 0x980A
#define GLX_MIPMAP_LEVEL_ATI 0x980B
#define GLX_CUBE_MAP_FACE_ATI 0x980C
#define GLX_TEXTURE_CUBE_MAP_POSITIVE_X_ATI 0x980D
#define GLX_TEXTURE_CUBE_MAP_NEGATIVE_X_ATI 0x980E
#define GLX_TEXTURE_CUBE_MAP_POSITIVE_Y_ATI 0x980F
#define GLX_TEXTURE_CUBE_MAP_NEGATIVE_Y_ATI 0x9810
#define GLX_TEXTURE_CUBE_MAP_POSITIVE_Z_ATI 0x9811
#define GLX_TEXTURE_CUBE_MAP_NEGATIVE_Z_ATI 0x9812
#define GLX_FRONT_LEFT_ATI 0x9813
#define GLX_FRONT_RIGHT_ATI 0x9814
#define GLX_BACK_LEFT_ATI 0x9815
#define GLX_BACK_RIGHT_ATI 0x9816
#define GLX_AUX0_ATI 0x9817
#define GLX_AUX1_ATI 0x9818
#define GLX_AUX2_ATI 0x9819
#define GLX_AUX3_ATI 0x981A
#define GLX_AUX4_ATI 0x981B
#define GLX_AUX5_ATI 0x981C
#define GLX_AUX6_ATI 0x981D
#define GLX_AUX7_ATI 0x981E
#define GLX_AUX8_ATI 0x981F
#define GLX_AUX9_ATI 0x9820
#define GLX_BIND_TO_TEXTURE_LUMINANCE_ATI 0x9821
#define GLX_BIND_TO_TEXTURE_INTENSITY_ATI 0x9822
#define glXBindTexImageATI XGL_FUNCPTR(glXBindTexImageATI)
#define glXReleaseTexImageATI XGL_FUNCPTR(glXReleaseTexImageATI)
#define glXDrawableAttribATI XGL_FUNCPTR(glXDrawableAttribATI)
#endif
#ifdef GLX_EXT_import_context
typedef XID GLXContextID;
#define GLX_SHARE_CONTEXT_EXT 0x800A
#define GLX_VISUAL_ID_EXT 0x800B
#define GLX_SCREEN_EXT 0x800C
#define glXFreeContextEXT XGL_FUNCPTR(glXFreeContextEXT)
#define glXGetContextIDEXT XGL_FUNCPTR(glXGetContextIDEXT)
#define glXImportContextEXT XGL_FUNCPTR(glXImportContextEXT)
#define glXQueryContextInfoEXT XGL_FUNCPTR(glXQueryContextInfoEXT)
#endif
#ifdef GLX_EXT_scene_marker
#endif
#ifdef GLX_EXT_visual_info
#define GLX_X_VISUAL_TYPE_EXT 0x22
#define GLX_TRANSPARENT_TYPE_EXT 0x23
#define GLX_TRANSPARENT_INDEX_VALUE_EXT 0x24
#define GLX_TRANSPARENT_RED_VALUE_EXT 0x25
#define GLX_TRANSPARENT_GREEN_VALUE_EXT 0x26
#define GLX_TRANSPARENT_BLUE_VALUE_EXT 0x27
#define GLX_TRANSPARENT_ALPHA_VALUE_EXT 0x28
#define GLX_NONE_EXT 0x8000
#define GLX_TRUE_COLOR_EXT 0x8002
#define GLX_DIRECT_COLOR_EXT 0x8003
#define GLX_PSEUDO_COLOR_EXT 0x8004
#define GLX_STATIC_COLOR_EXT 0x8005
#define GLX_GRAY_SCALE_EXT 0x8006
#define GLX_STATIC_GRAY_EXT 0x8007
#define GLX_TRANSPARENT_RGB_EXT 0x8008
#define GLX_TRANSPARENT_INDEX_EXT 0x8009
#endif
#ifdef GLX_EXT_visual_rating
#define GLX_VISUAL_CAVEAT_EXT 0x20
#define GLX_SLOW_VISUAL_EXT 0x8001
#define GLX_NON_CONFORMANT_VISUAL_EXT 0x800D
#endif
#ifdef GLX_MESA_agp_offset
#define glXGetAGPOffsetMESA XGL_FUNCPTR(glXGetAGPOffsetMESA)
#endif
#ifdef GLX_MESA_copy_sub_buffer
#define glXCopySubBufferMESA XGL_FUNCPTR(glXCopySubBufferMESA)
#endif
#ifdef GLX_MESA_pixmap_colormap
#define glXCreateGLXPixmapMESA XGL_FUNCPTR(glXCreateGLXPixmapMESA)
#endif
#ifdef GLX_MESA_release_buffers
#define glXReleaseBuffersMESA XGL_FUNCPTR(glXReleaseBuffersMESA)
#endif
#ifdef GLX_MESA_set_3dfx_mode
#define GLX_3DFX_WINDOW_MODE_MESA 0x1
#define GLX_3DFX_FULLSCREEN_MODE_MESA 0x2
#define glXSet3DfxModeMESA XGL_FUNCPTR(glXSet3DfxModeMESA)
#endif
#ifdef GLX_NV_float_buffer
#define GLX_FLOAT_COMPONENTS_NV 0x20B0
#endif
#ifdef GLX_NV_vertex_array_range
#define glXAllocateMemoryNV XGL_FUNCPTR(glXAllocateMemoryNV)
#define glXFreeMemoryNV XGL_FUNCPTR(glXFreeMemoryNV)
#endif
#ifdef GLX_OML_swap_method
#define GLX_SWAP_METHOD_OML 0x8060
#define GLX_SWAP_EXCHANGE_OML 0x8061
#define GLX_SWAP_COPY_OML 0x8062
#define GLX_SWAP_UNDEFINED_OML 0x8063
#endif
#ifdef GLX_OML_sync_control
#define glXGetMscRateOML XGL_FUNCPTR(glXGetMscRateOML)
#define glXGetSyncValuesOML XGL_FUNCPTR(glXGetSyncValuesOML)
#define glXSwapBuffersMscOML XGL_FUNCPTR(glXSwapBuffersMscOML)
#define glXWaitForMscOML XGL_FUNCPTR(glXWaitForMscOML)
#define glXWaitForSbcOML XGL_FUNCPTR(glXWaitForSbcOML)
#endif
#ifdef GLX_SGIS_blended_overlay
#define GLX_BLENDED_RGBA_SGIS 0x8025
#endif
#ifdef GLX_SGIS_color_range
#define GLX_MAX_GREEN_SGIS 0
#define GLX_MIN_RED_SGIS 0
#define GLX_MIN_BLUE_SGIS 0
#define GLX_MAX_RED_SGIS 0
#define GLX_MAX_ALPHA_SGIS 0
#define GLX_MIN_GREEN_SGIS 0
#define GLX_MIN_ALPHA_SGIS 0
#define GLX_EXTENDED_RANGE_SGIS 0
#define GLX_MAX_BLUE_SGIS 0
#endif
#ifdef GLX_SGIS_multisample
#define GLX_SAMPLE_BUFFERS_SGIS 100000
#define GLX_SAMPLES_SGIS 100001
#endif
#ifdef GLX_SGIS_shared_multisample
#define GLX_MULTISAMPLE_SUB_RECT_WIDTH_SGIS 0x8026
#define GLX_MULTISAMPLE_SUB_RECT_HEIGHT_SGIS 0x8027
#endif
#ifdef GLX_SGIX_fbconfig
typedef XID GLXFBConfigIDSGIX;
typedef struct __GLXFBConfigRec *GLXFBConfigSGIX;
#define GLX_WINDOW_BIT_SGIX 0x00000001
#define GLX_RGBA_BIT_SGIX 0x00000001
#define GLX_PIXMAP_BIT_SGIX 0x00000002
#define GLX_COLOR_INDEX_BIT_SGIX 0x00000002
#define GLX_SCREEN_EXT 0x800C
#define GLX_DRAWABLE_TYPE_SGIX 0x8010
#define GLX_RENDER_TYPE_SGIX 0x8011
#define GLX_X_RENDERABLE_SGIX 0x8012
#define GLX_FBCONFIG_ID_SGIX 0x8013
#define GLX_RGBA_TYPE_SGIX 0x8014
#define GLX_COLOR_INDEX_TYPE_SGIX 0x8015
#define glXChooseFBConfigSGIX XGL_FUNCPTR(glXChooseFBConfigSGIX)
#define glXCreateContextWithConfigSGIX XGL_FUNCPTR(glXCreateContextWithConfigSGIX)
#define glXCreateGLXPixmapWithConfigSGIX XGL_FUNCPTR(glXCreateGLXPixmapWithConfigSGIX)
#define glXGetFBConfigAttribSGIX XGL_FUNCPTR(glXGetFBConfigAttribSGIX)
#define glXGetFBConfigFromVisualSGIX XGL_FUNCPTR(glXGetFBConfigFromVisualSGIX)
#define glXGetVisualFromFBConfigSGIX XGL_FUNCPTR(glXGetVisualFromFBConfigSGIX)
#endif
#ifdef GLX_SGIX_pbuffer
typedef XID GLXPbufferSGIX;
typedef struct { int type; unsigned long serial; Bool send_event; Display *display; GLXDrawable drawable; int event_type; int draw_type; unsigned int mask; int x, y; int width, height; int count; } GLXBufferClobberEventSGIX;
#define GLX_FRONT_LEFT_BUFFER_BIT_SGIX 0x00000001
#define GLX_FRONT_RIGHT_BUFFER_BIT_SGIX 0x00000002
#define GLX_PBUFFER_BIT_SGIX 0x00000004
#define GLX_BACK_LEFT_BUFFER_BIT_SGIX 0x00000004
#define GLX_BACK_RIGHT_BUFFER_BIT_SGIX 0x00000008
#define GLX_AUX_BUFFERS_BIT_SGIX 0x00000010
#define GLX_DEPTH_BUFFER_BIT_SGIX 0x00000020
#define GLX_STENCIL_BUFFER_BIT_SGIX 0x00000040
#define GLX_ACCUM_BUFFER_BIT_SGIX 0x00000080
#define GLX_SAMPLE_BUFFERS_BIT_SGIX 0x00000100
#define GLX_MAX_PBUFFER_WIDTH_SGIX 0x8016
#define GLX_MAX_PBUFFER_HEIGHT_SGIX 0x8017
#define GLX_MAX_PBUFFER_PIXELS_SGIX 0x8018
#define GLX_OPTIMAL_PBUFFER_WIDTH_SGIX 0x8019
#define GLX_OPTIMAL_PBUFFER_HEIGHT_SGIX 0x801A
#define GLX_PRESERVED_CONTENTS_SGIX 0x801B
#define GLX_LARGEST_PBUFFER_SGIX 0x801C
#define GLX_WIDTH_SGIX 0x801D
#define GLX_HEIGHT_SGIX 0x801E
#define GLX_EVENT_MASK_SGIX 0x801F
#define GLX_DAMAGED_SGIX 0x8020
#define GLX_SAVED_SGIX 0x8021
#define GLX_WINDOW_SGIX 0x8022
#define GLX_PBUFFER_SGIX 0x8023
#define GLX_BUFFER_CLOBBER_MASK_SGIX 0x08000000
#define glXCreateGLXPbufferSGIX XGL_FUNCPTR(glXCreateGLXPbufferSGIX)
#define glXDestroyGLXPbufferSGIX XGL_FUNCPTR(glXDestroyGLXPbufferSGIX)
#define glXGetSelectedEventSGIX XGL_FUNCPTR(glXGetSelectedEventSGIX)
#define glXQueryGLXPbufferSGIX XGL_FUNCPTR(glXQueryGLXPbufferSGIX)
#define glXSelectEventSGIX XGL_FUNCPTR(glXSelectEventSGIX)
#endif
#ifdef GLX_SGIX_swap_barrier
#define glXBindSwapBarrierSGIX XGL_FUNCPTR(glXBindSwapBarrierSGIX)
#define glXQueryMaxSwapBarriersSGIX XGL_FUNCPTR(glXQueryMaxSwapBarriersSGIX)
#endif
#ifdef GLX_SGIX_swap_group
#define glXJoinSwapGroupSGIX XGL_FUNCPTR(glXJoinSwapGroupSGIX)
#endif
#ifdef GLX_SGIX_video_resize
#define GLX_SYNC_FRAME_SGIX 0x00000000
#define GLX_SYNC_SWAP_SGIX 0x00000001
#define glXBindChannelToWindowSGIX XGL_FUNCPTR(glXBindChannelToWindowSGIX)
#define glXChannelRectSGIX XGL_FUNCPTR(glXChannelRectSGIX)
#define glXChannelRectSyncSGIX XGL_FUNCPTR(glXChannelRectSyncSGIX)
#define glXQueryChannelDeltasSGIX XGL_FUNCPTR(glXQueryChannelDeltasSGIX)
#define glXQueryChannelRectSGIX XGL_FUNCPTR(glXQueryChannelRectSGIX)
#endif
#ifdef GLX_SGIX_visual_select_group
#define GLX_VISUAL_SELECT_GROUP_SGIX 0x8028
#endif
#ifdef GLX_SGI_cushion
#define glXCushionSGI XGL_FUNCPTR(glXCushionSGI)
#endif
#ifdef GLX_SGI_make_current_read
#define glXGetCurrentReadDrawableSGI XGL_FUNCPTR(glXGetCurrentReadDrawableSGI)
#define glXMakeCurrentReadSGI XGL_FUNCPTR(glXMakeCurrentReadSGI)
#endif
#ifdef GLX_SGI_swap_control
#define glXSwapIntervalSGI XGL_FUNCPTR(glXSwapIntervalSGI)
#endif
#ifdef GLX_SGI_video_sync
#define glXGetVideoSyncSGI XGL_FUNCPTR(glXGetVideoSyncSGI)
#define glXWaitVideoSyncSGI XGL_FUNCPTR(glXWaitVideoSyncSGI)
#endif
#ifdef GLX_SUN_get_transparent_index
#define glXGetTransparentIndexSUN XGL_FUNCPTR(glXGetTransparentIndexSUN)
#endif
#ifdef GLX_SUN_video_resize
#define GL_VIDEO_RESIZE_COMPENSATION_SUN 0x85CD
#define GLX_VIDEO_RESIZE_SUN 0x8171
#define glXVideoResizeSUN XGL_FUNCPTR(glXVideoResizeSUN)
#define glXGetVideoResizeSUN XGL_FUNCPTR(glXGetVideoResizeSUN)
#endif
#ifdef GLX_VERSION_1_1
#define glXQueryExtensionsString XGL_FUNCPTR(glXQueryExtensionsString)
#define glXGetClientString XGL_FUNCPTR(glXGetClientString)
#define glXQueryServerString XGL_FUNCPTR(glXQueryServerString)
#endif
#ifdef GLX_VERSION_1_2
#define glXGetCurrentDisplay XGL_FUNCPTR(glXGetCurrentDisplay)
#endif
#ifdef GLX_VERSION_1_3
typedef XID GLXWindow;
typedef XID GLXPbuffer;
typedef XID GLXFBConfigID;
typedef struct __GLXFBConfigRec *GLXFBConfig;
typedef struct { int event_type; int draw_type; unsigned long serial; Bool send_event; Display *display; GLXDrawable drawable; unsigned int buffer_mask; unsigned int aux_buffer; int x, y; int width, height; int count; } GLXPbufferClobberEvent;
typedef union __GLXEvent { GLXPbufferClobberEvent glxpbufferclobber; long pad[24]; } GLXEvent;
#define GLX_WINDOW_BIT 0x00000001
#define GLX_PIXMAP_BIT 0x00000002
#define GLX_PBUFFER_BIT 0x00000004
#define GLX_RGBA_BIT 0x00000001
#define GLX_COLOR_INDEX_BIT 0x00000002
#define GLX_PBUFFER_CLOBBER_MASK 0x08000000
#define GLX_FRONT_LEFT_BUFFER_BIT 0x00000001
#define GLX_FRONT_RIGHT_BUFFER_BIT 0x00000002
#define GLX_BACK_LEFT_BUFFER_BIT 0x00000004
#define GLX_BACK_RIGHT_BUFFER_BIT 0x00000008
#define GLX_AUX_BUFFERS_BIT 0x00000010
#define GLX_DEPTH_BUFFER_BIT 0x00000020
#define GLX_STENCIL_BUFFER_BIT 0x00000040
#define GLX_ACCUM_BUFFER_BIT 0x00000080
#define GLX_CONFIG_CAVEAT 0x20
#define GLX_X_VISUAL_TYPE 0x22
#define GLX_TRANSPARENT_TYPE 0x23
#define GLX_TRANSPARENT_INDEX_VALUE 0x24
#define GLX_TRANSPARENT_RED_VALUE 0x25
#define GLX_TRANSPARENT_GREEN_VALUE 0x26
#define GLX_TRANSPARENT_BLUE_VALUE 0x27
#define GLX_TRANSPARENT_ALPHA_VALUE 0x28
#define GLX_DONT_CARE 0xFFFFFFFF
#define GLX_NONE 0x8000
#define GLX_SLOW_CONFIG 0x8001
#define GLX_TRUE_COLOR 0x8002
#define GLX_DIRECT_COLOR 0x8003
#define GLX_PSEUDO_COLOR 0x8004
#define GLX_STATIC_COLOR 0x8005
#define GLX_GRAY_SCALE 0x8006
#define GLX_STATIC_GRAY 0x8007
#define GLX_TRANSPARENT_RGB 0x8008
#define GLX_TRANSPARENT_INDEX 0x8009
#define GLX_VISUAL_ID 0x800B
#define GLX_SCREEN 0x800C
#define GLX_NON_CONFORMANT_CONFIG 0x800D
#define GLX_DRAWABLE_TYPE 0x8010
#define GLX_RENDER_TYPE 0x8011
#define GLX_X_RENDERABLE 0x8012
#define GLX_FBCONFIG_ID 0x8013
#define GLX_RGBA_TYPE 0x8014
#define GLX_COLOR_INDEX_TYPE 0x8015
#define GLX_MAX_PBUFFER_WIDTH 0x8016
#define GLX_MAX_PBUFFER_HEIGHT 0x8017
#define GLX_MAX_PBUFFER_PIXELS 0x8018
#define GLX_PRESERVED_CONTENTS 0x801B
#define GLX_LARGEST_PBUFFER 0x801C
#define GLX_WIDTH 0x801D
#define GLX_HEIGHT 0x801E
#define GLX_EVENT_MASK 0x801F
#define GLX_DAMAGED 0x8020
#define GLX_SAVED 0x8021
#define GLX_WINDOW 0x8022
#define GLX_PBUFFER 0x8023
#define GLX_PBUFFER_HEIGHT 0x8040
#define GLX_PBUFFER_WIDTH 0x8041
#define glXChooseFBConfig XGL_FUNCPTR(glXChooseFBConfig)
#define glXGetFBConfigs XGL_FUNCPTR(glXGetFBConfigs)
#define glXGetVisualFromFBConfig XGL_FUNCPTR(glXGetVisualFromFBConfig)
#define glXGetFBConfigAttrib XGL_FUNCPTR(glXGetFBConfigAttrib)
#define glXCreateWindow XGL_FUNCPTR(glXCreateWindow)
#define glXDestroyWindow XGL_FUNCPTR(glXDestroyWindow)
#define glXCreatePixmap XGL_FUNCPTR(glXCreatePixmap)
#define glXDestroyPixmap XGL_FUNCPTR(glXDestroyPixmap)
#define glXCreatePbuffer XGL_FUNCPTR(glXCreatePbuffer)
#define glXDestroyPbuffer XGL_FUNCPTR(glXDestroyPbuffer)
#define glXQueryDrawable XGL_FUNCPTR(glXQueryDrawable)
#define glXCreateNewContext XGL_FUNCPTR(glXCreateNewContext)
#define glXMakeContextCurrent XGL_FUNCPTR(glXMakeContextCurrent)
#define glXGetCurrentReadDrawable XGL_FUNCPTR(glXGetCurrentReadDrawable)
#define glXQueryContext XGL_FUNCPTR(glXQueryContext)
#define glXSelectEvent XGL_FUNCPTR(glXSelectEvent)
#define glXGetSelectedEvent XGL_FUNCPTR(glXGetSelectedEvent)
#endif
#ifdef GLX_VERSION_1_4
#define GLX_SAMPLE_BUFFERS 100000
#define GLX_SAMPLES 100001
#define glXGetProcAddress XGL_FUNCPTR(glXGetProcAddress)
#endif

View file

@ -0,0 +1,288 @@
//-----------------------------------------------------------------------------
// Copyright (c) 2012 GarageGames, LLC
//
// Permission is hereby granted, free of charge, to any person obtaining a copy
// of this software and associated documentation files (the "Software"), to
// deal in the Software without restriction, including without limitation the
// rights to use, copy, modify, merge, publish, distribute, sublicense, and/or
// sell copies of the Software, and to permit persons to whom the Software is
// furnished to do so, subject to the following conditions:
//
// The above copyright notice and this permission notice shall be included in
// all copies or substantial portions of the Software.
//
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
// FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS
// IN THE SOFTWARE.
//-----------------------------------------------------------------------------
#ifdef GLX_3DFX_multisample
GL_GROUP_BEGIN(GLX_3DFX_multisample)
GL_GROUP_END()
#endif
#ifdef GLX_ARB_fbconfig_float
GL_GROUP_BEGIN(GLX_ARB_fbconfig_float)
GL_GROUP_END()
#endif
#ifdef GLX_ARB_get_proc_address
GL_GROUP_BEGIN(GLX_ARB_get_proc_address)
GL_FUNCTION(glXGetProcAddressARB, GLFunction, (const GLubyte*))
GL_GROUP_END()
#endif
#ifdef GLX_ARB_multisample
GL_GROUP_BEGIN(GLX_ARB_multisample)
GL_GROUP_END()
#endif
#ifdef GLX_ATI_pixel_format_float
GL_GROUP_BEGIN(GLX_ATI_pixel_format_float)
GL_GROUP_END()
#endif
#ifdef GLX_ATI_render_texture
GL_GROUP_BEGIN(GLX_ATI_render_texture)
GL_FUNCTION(glXBindTexImageATI,void,(Display *dpy, GLXPbuffer pbuf, int buffer))
GL_FUNCTION(glXReleaseTexImageATI,void,(Display *dpy, GLXPbuffer pbuf, int buffer))
GL_FUNCTION(glXDrawableAttribATI,void,(Display *dpy, GLXDrawable draw, const int *attrib_list))
GL_GROUP_END()
#endif
#ifdef GLX_EXT_import_context
GL_GROUP_BEGIN(GLX_EXT_import_context)
GL_FUNCTION(glXFreeContextEXT,void,(Display* dpy, GLXContext context))
GL_FUNCTION(glXGetContextIDEXT,GLXContextID,(const GLXContext context))
GL_FUNCTION(glXImportContextEXT,GLXContext,(Display* dpy, GLXContextID contextID))
GL_FUNCTION(glXQueryContextInfoEXT,int,(Display* dpy, GLXContext context, int attribute,int *value))
GL_GROUP_END()
#endif
#ifdef GLX_EXT_scene_marker
GL_GROUP_BEGIN(GLX_EXT_scene_marker)
GL_GROUP_END()
#endif
#ifdef GLX_EXT_visual_info
GL_GROUP_BEGIN(GLX_EXT_visual_info)
GL_GROUP_END()
#endif
#ifdef GLX_EXT_visual_rating
GL_GROUP_BEGIN(GLX_EXT_visual_rating)
GL_GROUP_END()
#endif
#ifdef GLX_MESA_agp_offset
GL_GROUP_BEGIN(GLX_MESA_agp_offset)
GL_FUNCTION(glXGetAGPOffsetMESA,unsigned int,(const void* pointer))
GL_GROUP_END()
#endif
#ifdef GLX_MESA_copy_sub_buffer
GL_GROUP_BEGIN(GLX_MESA_copy_sub_buffer)
GL_FUNCTION(glXCopySubBufferMESA,void,(Display* dpy, GLXDrawable drawable, int x, int y, int width, int height))
GL_GROUP_END()
#endif
#ifdef GLX_MESA_pixmap_colormap
GL_GROUP_BEGIN(GLX_MESA_pixmap_colormap)
GL_FUNCTION(glXCreateGLXPixmapMESA,GLXPixmap,(Display* dpy, XVisualInfo *visual, Pixmap pixmap, Colormap cmap))
GL_GROUP_END()
#endif
#ifdef GLX_MESA_release_buffers
GL_GROUP_BEGIN(GLX_MESA_release_buffers)
GL_FUNCTION(glXReleaseBuffersMESA,Bool,(Display* dpy, GLXDrawable d))
GL_GROUP_END()
#endif
#ifdef GLX_MESA_set_3dfx_mode
GL_GROUP_BEGIN(GLX_MESA_set_3dfx_mode)
GL_FUNCTION(glXSet3DfxModeMESA,GLboolean,(GLint mode))
GL_GROUP_END()
#endif
#ifdef GLX_NV_float_buffer
GL_GROUP_BEGIN(GLX_NV_float_buffer)
GL_GROUP_END()
#endif
#ifdef GLX_NV_vertex_array_range
GL_GROUP_BEGIN(GLX_NV_vertex_array_range)
GL_FUNCTION(glXAllocateMemoryNV,void *,(GLsizei size, GLfloat readFrequency, GLfloat writeFrequency, GLfloat priority))
GL_FUNCTION(glXFreeMemoryNV,void,(void *pointer))
GL_GROUP_END()
#endif
#ifdef GLX_OML_swap_method
GL_GROUP_BEGIN(GLX_OML_swap_method)
GL_GROUP_END()
#endif
#ifdef GLX_OML_sync_control
GL_GROUP_BEGIN(GLX_OML_sync_control)
GL_FUNCTION(glXGetMscRateOML,Bool,(Display* dpy, GLXDrawable drawable, int32_t* numerator, int32_t* denominator))
GL_FUNCTION(glXGetSyncValuesOML,Bool,(Display* dpy, GLXDrawable drawable, int64_t* ust, int64_t* msc, int64_t* sbc))
GL_FUNCTION(glXSwapBuffersMscOML,int64_t,(Display* dpy, GLXDrawable drawable, int64_t target_msc, int64_t divisor, int64_t remainder))
GL_FUNCTION(glXWaitForMscOML,Bool,(Display* dpy, GLXDrawable drawable, int64_t target_msc, int64_t divisor, int64_t remainder, int64_t* ust, int64_t* msc, int64_t* sbc))
GL_FUNCTION(glXWaitForSbcOML,Bool,(Display* dpy, GLXDrawable drawable, int64_t target_sbc, int64_t* ust, int64_t* msc, int64_t* sbc))
GL_GROUP_END()
#endif
#ifdef GLX_SGIS_blended_overlay
GL_GROUP_BEGIN(GLX_SGIS_blended_overlay)
GL_GROUP_END()
#endif
#ifdef GLX_SGIS_color_range
GL_GROUP_BEGIN(GLX_SGIS_color_range)
GL_GROUP_END()
#endif
#ifdef GLX_SGIS_multisample
GL_GROUP_BEGIN(GLX_SGIS_multisample)
GL_GROUP_END()
#endif
#ifdef GLX_SGIS_shared_multisample
GL_GROUP_BEGIN(GLX_SGIS_shared_multisample)
GL_GROUP_END()
#endif
#ifdef GLX_SGIX_fbconfig
GL_GROUP_BEGIN(GLX_SGIX_fbconfig)
GL_FUNCTION(glXChooseFBConfigSGIX,GLXFBConfigSGIX*,(Display *dpy, int screen, const int *attrib_list, int *nelements))
GL_FUNCTION(glXCreateContextWithConfigSGIX,GLXContext,(Display* dpy, GLXFBConfig config, int render_type, GLXContext share_list, Bool direct))
GL_FUNCTION(glXCreateGLXPixmapWithConfigSGIX,GLXPixmap,(Display* dpy, GLXFBConfig config, Pixmap pixmap))
GL_FUNCTION(glXGetFBConfigAttribSGIX,int,(Display* dpy, GLXFBConfigSGIX config, int attribute, int *value))
GL_FUNCTION(glXGetFBConfigFromVisualSGIX,GLXFBConfigSGIX,(Display* dpy, XVisualInfo *vis))
GL_FUNCTION(glXGetVisualFromFBConfigSGIX,XVisualInfo*,(Display *dpy, GLXFBConfig config))
GL_GROUP_END()
#endif
#ifdef GLX_SGIX_pbuffer
GL_GROUP_BEGIN(GLX_SGIX_pbuffer)
GL_FUNCTION(glXCreateGLXPbufferSGIX,GLXPbuffer,(Display* dpy, GLXFBConfig config, unsigned int width, unsigned int height, int *attrib_list))
GL_FUNCTION(glXDestroyGLXPbufferSGIX,void,(Display* dpy, GLXPbuffer pbuf))
GL_FUNCTION(glXGetSelectedEventSGIX,void,(Display* dpy, GLXDrawable drawable, unsigned long *mask))
GL_FUNCTION(glXQueryGLXPbufferSGIX,void,(Display* dpy, GLXPbuffer pbuf, int attribute, unsigned int *value))
GL_FUNCTION(glXSelectEventSGIX,void,(Display* dpy, GLXDrawable drawable, unsigned long mask))
GL_GROUP_END()
#endif
#ifdef GLX_SGIX_swap_barrier
GL_GROUP_BEGIN(GLX_SGIX_swap_barrier)
GL_FUNCTION(glXBindSwapBarrierSGIX,void,(Display *dpy, GLXDrawable drawable, int barrier))
GL_FUNCTION(glXQueryMaxSwapBarriersSGIX,Bool,(Display *dpy, int screen, int *max))
GL_GROUP_END()
#endif
#ifdef GLX_SGIX_swap_group
GL_GROUP_BEGIN(GLX_SGIX_swap_group)
GL_FUNCTION(glXJoinSwapGroupSGIX,void,(Display *dpy, GLXDrawable drawable, GLXDrawable member))
GL_GROUP_END()
#endif
#ifdef GLX_SGIX_video_resize
GL_GROUP_BEGIN(GLX_SGIX_video_resize)
GL_FUNCTION(glXBindChannelToWindowSGIX,int,(Display* display, int screen, int channel, Window window))
GL_FUNCTION(glXChannelRectSGIX,int,(Display* display, int screen, int channel, int x, int y, int w, int h))
GL_FUNCTION(glXChannelRectSyncSGIX,int,(Display* display, int screen, int channel, GLenum synctype))
GL_FUNCTION(glXQueryChannelDeltasSGIX,int,(Display* display, int screen, int channel, int *x, int *y, int *w, int *h))
GL_FUNCTION(glXQueryChannelRectSGIX,int,(Display* display, int screen, int channel, int *dx, int *dy, int *dw, int *dh))
GL_GROUP_END()
#endif
#ifdef GLX_SGIX_visual_select_group
GL_GROUP_BEGIN(GLX_SGIX_visual_select_group)
GL_GROUP_END()
#endif
#ifdef GLX_SGI_cushion
GL_GROUP_BEGIN(GLX_SGI_cushion)
GL_FUNCTION(glXCushionSGI,void,(Display* dpy, Window window, float cushion))
GL_GROUP_END()
#endif
#ifdef GLX_SGI_make_current_read
GL_GROUP_BEGIN(GLX_SGI_make_current_read)
GL_FUNCTION(glXGetCurrentReadDrawableSGI,GLXDrawable,(void))
GL_FUNCTION(glXMakeCurrentReadSGI,Bool,(Display* dpy, GLXDrawable draw, GLXDrawable read, GLXContext ctx))
GL_GROUP_END()
#endif
#ifdef GLX_SGI_swap_control
GL_GROUP_BEGIN(GLX_SGI_swap_control)
GL_FUNCTION(glXSwapIntervalSGI,int,(int interval))
GL_GROUP_END()
#endif
#ifdef GLX_SGI_video_sync
GL_GROUP_BEGIN(GLX_SGI_video_sync)
GL_FUNCTION(glXGetVideoSyncSGI,int,(uint* count))
GL_FUNCTION(glXWaitVideoSyncSGI,int,(int divisor, int remainder, unsigned int* count))
GL_GROUP_END()
#endif
#ifdef GLX_SUN_get_transparent_index
GL_GROUP_BEGIN(GLX_SUN_get_transparent_index)
GL_FUNCTION(glXGetTransparentIndexSUN,Status,(Display* dpy, Window overlay, Window underlay, unsigned long *pTransparentIndex))
GL_GROUP_END()
#endif
#ifdef GLX_SUN_video_resize
GL_GROUP_BEGIN(GLX_SUN_video_resize)
GL_FUNCTION(glXVideoResizeSUN,int,(Display* display, GLXDrawable window, float factor))
GL_FUNCTION(glXGetVideoResizeSUN,int,(Display* display, GLXDrawable window, float* factor))
GL_GROUP_END()
#endif
#ifdef GLX_VERSION_1_1
GL_GROUP_BEGIN(GLX_VERSION_1_1)
GL_FUNCTION(glXQueryExtensionsString, const char*, (Display *dpy, int screen))
GL_FUNCTION(glXGetClientString, const char*, (Display *dpy, int name))
GL_FUNCTION(glXQueryServerString, const char*, (Display *dpy, int screen, int name))
GL_GROUP_END()
#endif
#ifdef GLX_VERSION_1_2
GL_GROUP_BEGIN(GLX_VERSION_1_2)
GL_FUNCTION(glXGetCurrentDisplay, Display*, (void))
GL_GROUP_END()
#endif
#ifdef GLX_VERSION_1_3
GL_GROUP_BEGIN(GLX_VERSION_1_3)
GL_FUNCTION(glXChooseFBConfig,GLXFBConfig*,(Display *dpy, int screen, const int *attrib_list, int *nelements))
GL_FUNCTION(glXGetFBConfigs,GLXFBConfig*,(Display *dpy, int screen, int *nelements))
GL_FUNCTION(glXGetVisualFromFBConfig,XVisualInfo*,(Display *dpy, GLXFBConfig config))
GL_FUNCTION(glXGetFBConfigAttrib,int,(Display *dpy, GLXFBConfig config, int attribute, int *value))
GL_FUNCTION(glXCreateWindow,GLXWindow,(Display *dpy, GLXFBConfig config, Window win, const int *attrib_list))
GL_FUNCTION(glXDestroyWindow,void,(Display *dpy, GLXWindow win))
GL_FUNCTION(glXCreatePixmap,GLXPixmap,(Display *dpy, GLXFBConfig config, Pixmap pixmap, const int *attrib_list))
GL_FUNCTION(glXDestroyPixmap,void,(Display *dpy, GLXPixmap pixmap))
GL_FUNCTION(glXCreatePbuffer,GLXPbuffer,(Display *dpy, GLXFBConfig config, const int *attrib_list))
GL_FUNCTION(glXDestroyPbuffer,void,(Display *dpy, GLXPbuffer pbuf))
GL_FUNCTION(glXQueryDrawable,void,(Display *dpy, GLXDrawable draw, int attribute, unsigned int *value))
GL_FUNCTION(glXCreateNewContext,GLXContext,(Display *dpy, GLXFBConfig config, int render_type, GLXContext share_list, Bool direct))
GL_FUNCTION(glXMakeContextCurrent,Bool,(Display *display, GLXDrawable draw, GLXDrawable read, GLXContext ctx))
GL_FUNCTION(glXGetCurrentReadDrawable,GLXDrawable,(void))
GL_FUNCTION(glXQueryContext,int,(Display *dpy, GLXContext ctx, int attribute, int *value))
GL_FUNCTION(glXSelectEvent,void,(Display *dpy, GLXDrawable draw, unsigned long event_mask))
GL_FUNCTION(glXGetSelectedEvent,void,(Display *dpy, GLXDrawable draw, unsigned long *event_mask))
GL_GROUP_END()
#endif
#ifdef GLX_VERSION_1_4
GL_GROUP_BEGIN(GLX_VERSION_1_4)
GL_FUNCTION(glXGetProcAddress, GLFunction, (const GLubyte *procName))
GL_GROUP_END()
#endif

View file

@ -0,0 +1,43 @@
//-----------------------------------------------------------------------------
// Copyright (c) 2012 GarageGames, LLC
//
// Permission is hereby granted, free of charge, to any person obtaining a copy
// of this software and associated documentation files (the "Software"), to
// deal in the Software without restriction, including without limitation the
// rights to use, copy, modify, merge, publish, distribute, sublicense, and/or
// sell copies of the Software, and to permit persons to whom the Software is
// furnished to do so, subject to the following conditions:
//
// The above copyright notice and this permission notice shall be included in
// all copies or substantial portions of the Software.
//
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
// FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS
// IN THE SOFTWARE.
//-----------------------------------------------------------------------------
// X11 gl functions
GL_GROUP_BEGIN(ARB_glx)
GL_FUNCTION(glXQueryExtension, Bool, (Display *dpy, int *errorBase, int *eventBase))
GL_FUNCTION(glXQueryVersion, Bool, (Display *dpy, int *major, int *minor))
GL_FUNCTION(glXGetConfig, int, (Display *dpy, XVisualInfo *vis, int attrib, int *value))
GL_FUNCTION(glXChooseVisual, XVisualInfo*, (Display *dpy, int screen, int *attribList))
GL_FUNCTION(glXCreateGLXPixmap, GLXPixmap, (Display *dpy, XVisualInfo *vis, Pixmap pixmap))
GL_FUNCTION(glXDestroyGLXPixmap, void, (Display *dpy, GLXPixmap pix))
GL_FUNCTION(glXCreateContext, GLXContext, (Display *dpy, XVisualInfo *vis, GLXContext shareList, Bool direct))
GL_FUNCTION(glXDestroyContext, void, (Display *dpy, GLXContext ctx))
GL_FUNCTION(glXIsDirect, Bool, (Display *dpy, GLXContext ctx))
GL_FUNCTION(glXCopyContext, void, (Display *dpy, GLXContext src, GLXContext dst, GLuint mask))
GL_FUNCTION(glXMakeCurrent, Bool, (Display *dpy, GLXDrawable drawable, GLXContext ctx))
GL_FUNCTION(glXGetCurrentContext, GLXContext, (void))
GL_FUNCTION(glXGetCurrentDrawable, GLXDrawable, (void))
GL_FUNCTION(glXWaitGL, void, (void))
GL_FUNCTION(glXWaitX, void, (void))
GL_FUNCTION(glXSwapBuffers, void, (Display *dpy, GLXDrawable drawable))
GL_FUNCTION(glXUseXFont, void, (Font font, int first, int count, int listBase))
GL_GROUP_END()

View file

@ -0,0 +1,382 @@
//-----------------------------------------------------------------------------
// Copyright (c) 2012 GarageGames, LLC
//
// Permission is hereby granted, free of charge, to any person obtaining a copy
// of this software and associated documentation files (the "Software"), to
// deal in the Software without restriction, including without limitation the
// rights to use, copy, modify, merge, publish, distribute, sublicense, and/or
// sell copies of the Software, and to permit persons to whom the Software is
// furnished to do so, subject to the following conditions:
//
// The above copyright notice and this permission notice shall be included in
// all copies or substantial portions of the Software.
//
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
// FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS
// IN THE SOFTWARE.
//-----------------------------------------------------------------------------
#ifdef WGL_3DFX_multisample
#define WGL_SAMPLE_BUFFERS_3DFX 0x2060
#define WGL_SAMPLES_3DFX 0x2061
#endif
#ifdef WGL_ARB_buffer_region
#define WGL_FRONT_COLOR_BUFFER_BIT_ARB 0x00000001
#define WGL_BACK_COLOR_BUFFER_BIT_ARB 0x00000002
#define WGL_DEPTH_BUFFER_BIT_ARB 0x00000004
#define WGL_STENCIL_BUFFER_BIT_ARB 0x00000008
#define wglCreateBufferRegionARB XGL_FUNCPTR(wglCreateBufferRegionARB)
#define wglDeleteBufferRegionARB XGL_FUNCPTR(wglDeleteBufferRegionARB)
#define wglRestoreBufferRegionARB XGL_FUNCPTR(wglRestoreBufferRegionARB)
#define wglSaveBufferRegionARB XGL_FUNCPTR(wglSaveBufferRegionARB)
#endif
#ifdef WGL_ARB_extensions_string
#define wglGetExtensionsStringARB XGL_FUNCPTR(wglGetExtensionsStringARB)
#endif
#ifdef WGL_ARB_make_current_read
#define wglGetCurrentReadDCARB XGL_FUNCPTR(wglGetCurrentReadDCARB)
#define wglMakeContextCurrentARB XGL_FUNCPTR(wglMakeContextCurrentARB)
#endif
#ifdef WGL_ARB_multisample
#define WGL_SAMPLE_BUFFERS_ARB 0x2041
#define WGL_SAMPLES_ARB 0x2042
#endif
#ifdef WGL_ARB_pbuffer
DECLARE_HANDLE(HPBUFFERARB);
#define WGL_DRAW_TO_PBUFFER_ARB 0x202D
#define WGL_MAX_PBUFFER_PIXELS_ARB 0x202E
#define WGL_MAX_PBUFFER_WIDTH_ARB 0x202F
#define WGL_MAX_PBUFFER_HEIGHT_ARB 0x2030
#define WGL_PBUFFER_LARGEST_ARB 0x2033
#define WGL_PBUFFER_WIDTH_ARB 0x2034
#define WGL_PBUFFER_HEIGHT_ARB 0x2035
#define WGL_PBUFFER_LOST_ARB 0x2036
#define wglCreatePbufferARB XGL_FUNCPTR(wglCreatePbufferARB)
#define wglDestroyPbufferARB XGL_FUNCPTR(wglDestroyPbufferARB)
#define wglGetPbufferDCARB XGL_FUNCPTR(wglGetPbufferDCARB)
#define wglQueryPbufferARB XGL_FUNCPTR(wglQueryPbufferARB)
#define wglReleasePbufferDCARB XGL_FUNCPTR(wglReleasePbufferDCARB)
#endif
#ifdef WGL_ARB_pixel_format
#define WGL_NUMBER_PIXEL_FORMATS_ARB 0x2000
#define WGL_DRAW_TO_WINDOW_ARB 0x2001
#define WGL_DRAW_TO_BITMAP_ARB 0x2002
#define WGL_ACCELERATION_ARB 0x2003
#define WGL_NEED_PALETTE_ARB 0x2004
#define WGL_NEED_SYSTEM_PALETTE_ARB 0x2005
#define WGL_SWAP_LAYER_BUFFERS_ARB 0x2006
#define WGL_SWAP_METHOD_ARB 0x2007
#define WGL_NUMBER_OVERLAYS_ARB 0x2008
#define WGL_NUMBER_UNDERLAYS_ARB 0x2009
#define WGL_TRANSPARENT_ARB 0x200A
#define WGL_SHARE_DEPTH_ARB 0x200C
#define WGL_SHARE_STENCIL_ARB 0x200D
#define WGL_SHARE_ACCUM_ARB 0x200E
#define WGL_SUPPORT_GDI_ARB 0x200F
#define WGL_SUPPORT_OPENGL_ARB 0x2010
#define WGL_DOUBLE_BUFFER_ARB 0x2011
#define WGL_STEREO_ARB 0x2012
#define WGL_PIXEL_TYPE_ARB 0x2013
#define WGL_COLOR_BITS_ARB 0x2014
#define WGL_RED_BITS_ARB 0x2015
#define WGL_RED_SHIFT_ARB 0x2016
#define WGL_GREEN_BITS_ARB 0x2017
#define WGL_GREEN_SHIFT_ARB 0x2018
#define WGL_BLUE_BITS_ARB 0x2019
#define WGL_BLUE_SHIFT_ARB 0x201A
#define WGL_ALPHA_BITS_ARB 0x201B
#define WGL_ALPHA_SHIFT_ARB 0x201C
#define WGL_ACCUM_BITS_ARB 0x201D
#define WGL_ACCUM_RED_BITS_ARB 0x201E
#define WGL_ACCUM_GREEN_BITS_ARB 0x201F
#define WGL_ACCUM_BLUE_BITS_ARB 0x2020
#define WGL_ACCUM_ALPHA_BITS_ARB 0x2021
#define WGL_DEPTH_BITS_ARB 0x2022
#define WGL_STENCIL_BITS_ARB 0x2023
#define WGL_AUX_BUFFERS_ARB 0x2024
#define WGL_NO_ACCELERATION_ARB 0x2025
#define WGL_GENERIC_ACCELERATION_ARB 0x2026
#define WGL_FULL_ACCELERATION_ARB 0x2027
#define WGL_SWAP_EXCHANGE_ARB 0x2028
#define WGL_SWAP_COPY_ARB 0x2029
#define WGL_SWAP_UNDEFINED_ARB 0x202A
#define WGL_TYPE_RGBA_ARB 0x202B
#define WGL_TYPE_COLORINDEX_ARB 0x202C
#define WGL_TRANSPARENT_RED_VALUE_ARB 0x2037
#define WGL_TRANSPARENT_GREEN_VALUE_ARB 0x2038
#define WGL_TRANSPARENT_BLUE_VALUE_ARB 0x2039
#define WGL_TRANSPARENT_ALPHA_VALUE_ARB 0x203A
#define WGL_TRANSPARENT_INDEX_VALUE_ARB 0x203B
#define wglChoosePixelFormatARB XGL_FUNCPTR(wglChoosePixelFormatARB)
#define wglGetPixelFormatAttribfvARB XGL_FUNCPTR(wglGetPixelFormatAttribfvARB)
#define wglGetPixelFormatAttribivARB XGL_FUNCPTR(wglGetPixelFormatAttribivARB)
#endif
#ifdef WGL_ARB_pixel_format_float
#define WGL_TYPE_RGBA_FLOAT_ARB 0x21A0
#endif
#ifdef WGL_ARB_render_texture
#define WGL_BIND_TO_TEXTURE_RGB_ARB 0x2070
#define WGL_BIND_TO_TEXTURE_RGBA_ARB 0x2071
#define WGL_TEXTURE_FORMAT_ARB 0x2072
#define WGL_TEXTURE_TARGET_ARB 0x2073
#define WGL_MIPMAP_TEXTURE_ARB 0x2074
#define WGL_TEXTURE_RGB_ARB 0x2075
#define WGL_TEXTURE_RGBA_ARB 0x2076
#define WGL_NO_TEXTURE_ARB 0x2077
#define WGL_TEXTURE_CUBE_MAP_ARB 0x2078
#define WGL_TEXTURE_1D_ARB 0x2079
#define WGL_TEXTURE_2D_ARB 0x207A
#define WGL_MIPMAP_LEVEL_ARB 0x207B
#define WGL_CUBE_MAP_FACE_ARB 0x207C
#define WGL_TEXTURE_CUBE_MAP_POSITIVE_X_ARB 0x207D
#define WGL_TEXTURE_CUBE_MAP_NEGATIVE_X_ARB 0x207E
#define WGL_TEXTURE_CUBE_MAP_POSITIVE_Y_ARB 0x207F
#define WGL_TEXTURE_CUBE_MAP_NEGATIVE_Y_ARB 0x2080
#define WGL_TEXTURE_CUBE_MAP_POSITIVE_Z_ARB 0x2081
#define WGL_TEXTURE_CUBE_MAP_NEGATIVE_Z_ARB 0x2082
#define WGL_FRONT_LEFT_ARB 0x2083
#define WGL_FRONT_RIGHT_ARB 0x2084
#define WGL_BACK_LEFT_ARB 0x2085
#define WGL_BACK_RIGHT_ARB 0x2086
#define WGL_AUX0_ARB 0x2087
#define WGL_AUX1_ARB 0x2088
#define WGL_AUX2_ARB 0x2089
#define WGL_AUX3_ARB 0x208A
#define WGL_AUX4_ARB 0x208B
#define WGL_AUX5_ARB 0x208C
#define WGL_AUX6_ARB 0x208D
#define WGL_AUX7_ARB 0x208E
#define WGL_AUX8_ARB 0x208F
#define WGL_AUX9_ARB 0x2090
#define wglBindTexImageARB XGL_FUNCPTR(wglBindTexImageARB)
#define wglReleaseTexImageARB XGL_FUNCPTR(wglReleaseTexImageARB)
#define wglSetPbufferAttribARB XGL_FUNCPTR(wglSetPbufferAttribARB)
#endif
#ifdef WGL_ATI_pixel_format_float
#define WGL_TYPE_RGBA_FLOAT_ATI 0x21A0
#define GL_RGBA_FLOAT_MODE_ATI 0x8820
#define GL_COLOR_CLEAR_UNCLAMPED_VALUE_ATI 0x8835
#endif
#ifdef WGL_ATI_render_texture_rectangle
#define WGL_TEXTURE_RECTANGLE_ATI 0x21A5
#endif
#ifdef WGL_EXT_depth_float
#define WGL_DEPTH_FLOAT_EXT 0x2040
#endif
#ifdef WGL_EXT_display_color_table
#define wglBindDisplayColorTableEXT XGL_FUNCPTR(wglBindDisplayColorTableEXT)
#define wglCreateDisplayColorTableEXT XGL_FUNCPTR(wglCreateDisplayColorTableEXT)
#define wglDestroyDisplayColorTableEXT XGL_FUNCPTR(wglDestroyDisplayColorTableEXT)
#define wglLoadDisplayColorTableEXT XGL_FUNCPTR(wglLoadDisplayColorTableEXT)
#endif
#ifdef WGL_EXT_extensions_string
#define wglGetExtensionsStringEXT XGL_FUNCPTR(wglGetExtensionsStringEXT)
#endif
#ifdef WGL_EXT_make_current_read
#define wglGetCurrentReadDCEXT XGL_FUNCPTR(wglGetCurrentReadDCEXT)
#define wglMakeContextCurrentEXT XGL_FUNCPTR(wglMakeContextCurrentEXT)
#endif
#ifdef WGL_EXT_multisample
#define WGL_SAMPLE_BUFFERS_EXT 0x2041
#define WGL_SAMPLES_EXT 0x2042
#endif
#ifdef WGL_EXT_pbuffer
DECLARE_HANDLE(HPBUFFEREXT);;
#define WGL_DRAW_TO_PBUFFER_EXT 0x202D
#define WGL_MAX_PBUFFER_PIXELS_EXT 0x202E
#define WGL_MAX_PBUFFER_WIDTH_EXT 0x202F
#define WGL_MAX_PBUFFER_HEIGHT_EXT 0x2030
#define WGL_OPTIMAL_PBUFFER_WIDTH_EXT 0x2031
#define WGL_OPTIMAL_PBUFFER_HEIGHT_EXT 0x2032
#define WGL_PBUFFER_LARGEST_EXT 0x2033
#define WGL_PBUFFER_WIDTH_EXT 0x2034
#define WGL_PBUFFER_HEIGHT_EXT 0x2035
#define wglCreatePbufferEXT XGL_FUNCPTR(wglCreatePbufferEXT)
#define wglDestroyPbufferEXT XGL_FUNCPTR(wglDestroyPbufferEXT)
#define wglGetPbufferDCEXT XGL_FUNCPTR(wglGetPbufferDCEXT)
#define wglQueryPbufferEXT XGL_FUNCPTR(wglQueryPbufferEXT)
#define wglReleasePbufferDCEXT XGL_FUNCPTR(wglReleasePbufferDCEXT)
#endif
#ifdef WGL_EXT_pixel_format
#define WGL_NUMBER_PIXEL_FORMATS_EXT 0x2000
#define WGL_DRAW_TO_WINDOW_EXT 0x2001
#define WGL_DRAW_TO_BITMAP_EXT 0x2002
#define WGL_ACCELERATION_EXT 0x2003
#define WGL_NEED_PALETTE_EXT 0x2004
#define WGL_NEED_SYSTEM_PALETTE_EXT 0x2005
#define WGL_SWAP_LAYER_BUFFERS_EXT 0x2006
#define WGL_SWAP_METHOD_EXT 0x2007
#define WGL_NUMBER_OVERLAYS_EXT 0x2008
#define WGL_NUMBER_UNDERLAYS_EXT 0x2009
#define WGL_TRANSPARENT_EXT 0x200A
#define WGL_TRANSPARENT_VALUE_EXT 0x200B
#define WGL_SHARE_DEPTH_EXT 0x200C
#define WGL_SHARE_STENCIL_EXT 0x200D
#define WGL_SHARE_ACCUM_EXT 0x200E
#define WGL_SUPPORT_GDI_EXT 0x200F
#define WGL_SUPPORT_OPENGL_EXT 0x2010
#define WGL_DOUBLE_BUFFER_EXT 0x2011
#define WGL_STEREO_EXT 0x2012
#define WGL_PIXEL_TYPE_EXT 0x2013
#define WGL_COLOR_BITS_EXT 0x2014
#define WGL_RED_BITS_EXT 0x2015
#define WGL_RED_SHIFT_EXT 0x2016
#define WGL_GREEN_BITS_EXT 0x2017
#define WGL_GREEN_SHIFT_EXT 0x2018
#define WGL_BLUE_BITS_EXT 0x2019
#define WGL_BLUE_SHIFT_EXT 0x201A
#define WGL_ALPHA_BITS_EXT 0x201B
#define WGL_ALPHA_SHIFT_EXT 0x201C
#define WGL_ACCUM_BITS_EXT 0x201D
#define WGL_ACCUM_RED_BITS_EXT 0x201E
#define WGL_ACCUM_GREEN_BITS_EXT 0x201F
#define WGL_ACCUM_BLUE_BITS_EXT 0x2020
#define WGL_ACCUM_ALPHA_BITS_EXT 0x2021
#define WGL_DEPTH_BITS_EXT 0x2022
#define WGL_STENCIL_BITS_EXT 0x2023
#define WGL_AUX_BUFFERS_EXT 0x2024
#define WGL_NO_ACCELERATION_EXT 0x2025
#define WGL_GENERIC_ACCELERATION_EXT 0x2026
#define WGL_FULL_ACCELERATION_EXT 0x2027
#define WGL_SWAP_EXCHANGE_EXT 0x2028
#define WGL_SWAP_COPY_EXT 0x2029
#define WGL_SWAP_UNDEFINED_EXT 0x202A
#define WGL_TYPE_RGBA_EXT 0x202B
#define WGL_TYPE_COLORINDEX_EXT 0x202C
#define wglChoosePixelFormatEXT XGL_FUNCPTR(wglChoosePixelFormatEXT)
#define wglGetPixelFormatAttribfvEXT XGL_FUNCPTR(wglGetPixelFormatAttribfvEXT)
#define wglGetPixelFormatAttribivEXT XGL_FUNCPTR(wglGetPixelFormatAttribivEXT)
#endif
#ifdef WGL_EXT_swap_control
#define wglGetSwapIntervalEXT XGL_FUNCPTR(wglGetSwapIntervalEXT)
#define wglSwapIntervalEXT XGL_FUNCPTR(wglSwapIntervalEXT)
#endif
#ifdef WGL_I3D_digital_video_control
#define WGL_DIGITAL_VIDEO_CURSOR_ALPHA_FRAMEBUFFER_I3D 0x2050
#define WGL_DIGITAL_VIDEO_CURSOR_ALPHA_VALUE_I3D 0x2051
#define WGL_DIGITAL_VIDEO_CURSOR_INCLUDED_I3D 0x2052
#define WGL_DIGITAL_VIDEO_GAMMA_CORRECTED_I3D 0x2053
#define wglGetDigitalVideoParametersI3D XGL_FUNCPTR(wglGetDigitalVideoParametersI3D)
#define wglSetDigitalVideoParametersI3D XGL_FUNCPTR(wglSetDigitalVideoParametersI3D)
#endif
#ifdef WGL_I3D_gamma
#define WGL_GAMMA_TABLE_SIZE_I3D 0x204E
#define WGL_GAMMA_EXCLUDE_DESKTOP_I3D 0x204F
#define wglGetGammaTableI3D XGL_FUNCPTR(wglGetGammaTableI3D)
#define wglGetGammaTableParametersI3D XGL_FUNCPTR(wglGetGammaTableParametersI3D)
#define wglSetGammaTableI3D XGL_FUNCPTR(wglSetGammaTableI3D)
#define wglSetGammaTableParametersI3D XGL_FUNCPTR(wglSetGammaTableParametersI3D)
#endif
#ifdef WGL_I3D_genlock
#define WGL_GENLOCK_SOURCE_MULTIVIEW_I3D 0x2044
#define WGL_GENLOCK_SOURCE_EXTERNAL_SYNC_I3D 0x2045
#define WGL_GENLOCK_SOURCE_EXTERNAL_FIELD_I3D 0x2046
#define WGL_GENLOCK_SOURCE_EXTERNAL_TTL_I3D 0x2047
#define WGL_GENLOCK_SOURCE_DIGITAL_SYNC_I3D 0x2048
#define WGL_GENLOCK_SOURCE_DIGITAL_FIELD_I3D 0x2049
#define WGL_GENLOCK_SOURCE_EDGE_FALLING_I3D 0x204A
#define WGL_GENLOCK_SOURCE_EDGE_RISING_I3D 0x204B
#define WGL_GENLOCK_SOURCE_EDGE_BOTH_I3D 0x204C
#define wglDisableGenlockI3D XGL_FUNCPTR(wglDisableGenlockI3D)
#define wglEnableGenlockI3D XGL_FUNCPTR(wglEnableGenlockI3D)
#define wglGenlockSampleRateI3D XGL_FUNCPTR(wglGenlockSampleRateI3D)
#define wglGenlockSourceDelayI3D XGL_FUNCPTR(wglGenlockSourceDelayI3D)
#define wglGenlockSourceEdgeI3D XGL_FUNCPTR(wglGenlockSourceEdgeI3D)
#define wglGenlockSourceI3D XGL_FUNCPTR(wglGenlockSourceI3D)
#define wglGetGenlockSampleRateI3D XGL_FUNCPTR(wglGetGenlockSampleRateI3D)
#define wglGetGenlockSourceDelayI3D XGL_FUNCPTR(wglGetGenlockSourceDelayI3D)
#define wglGetGenlockSourceEdgeI3D XGL_FUNCPTR(wglGetGenlockSourceEdgeI3D)
#define wglGetGenlockSourceI3D XGL_FUNCPTR(wglGetGenlockSourceI3D)
#define wglIsEnabledGenlockI3D XGL_FUNCPTR(wglIsEnabledGenlockI3D)
#define wglQueryGenlockMaxSourceDelayI3D XGL_FUNCPTR(wglQueryGenlockMaxSourceDelayI3D)
#endif
#ifdef WGL_I3D_image_buffer
#define WGL_IMAGE_BUFFER_MIN_ACCESS_I3D 0x00000001
#define WGL_IMAGE_BUFFER_LOCK_I3D 0x00000002
#define wglAssociateImageBufferEventsI3D XGL_FUNCPTR(wglAssociateImageBufferEventsI3D)
#define wglCreateImageBufferI3D XGL_FUNCPTR(wglCreateImageBufferI3D)
#define wglDestroyImageBufferI3D XGL_FUNCPTR(wglDestroyImageBufferI3D)
#define wglReleaseImageBufferEventsI3D XGL_FUNCPTR(wglReleaseImageBufferEventsI3D)
#endif
#ifdef WGL_I3D_swap_frame_lock
#define wglDisableFrameLockI3D XGL_FUNCPTR(wglDisableFrameLockI3D)
#define wglEnableFrameLockI3D XGL_FUNCPTR(wglEnableFrameLockI3D)
#define wglIsEnabledFrameLockI3D XGL_FUNCPTR(wglIsEnabledFrameLockI3D)
#define wglQueryFrameLockMasterI3D XGL_FUNCPTR(wglQueryFrameLockMasterI3D)
#endif
#ifdef WGL_I3D_swap_frame_usage
#define wglBeginFrameTrackingI3D XGL_FUNCPTR(wglBeginFrameTrackingI3D)
#define wglEndFrameTrackingI3D XGL_FUNCPTR(wglEndFrameTrackingI3D)
#define wglGetFrameUsageI3D XGL_FUNCPTR(wglGetFrameUsageI3D)
#define wglQueryFrameTrackingI3D XGL_FUNCPTR(wglQueryFrameTrackingI3D)
#endif
#ifdef WGL_NV_float_buffer
#define WGL_FLOAT_COMPONENTS_NV 0x20B0
#define WGL_BIND_TO_TEXTURE_RECTANGLE_FLOAT_R_NV 0x20B1
#define WGL_BIND_TO_TEXTURE_RECTANGLE_FLOAT_RG_NV 0x20B2
#define WGL_BIND_TO_TEXTURE_RECTANGLE_FLOAT_RGB_NV 0x20B3
#define WGL_BIND_TO_TEXTURE_RECTANGLE_FLOAT_RGBA_NV 0x20B4
#define WGL_TEXTURE_FLOAT_R_NV 0x20B5
#define WGL_TEXTURE_FLOAT_RG_NV 0x20B6
#define WGL_TEXTURE_FLOAT_RGB_NV 0x20B7
#define WGL_TEXTURE_FLOAT_RGBA_NV 0x20B8
#endif
#ifdef WGL_NV_render_depth_texture
#define WGL_NO_TEXTURE_ARB 0x2077
#define WGL_BIND_TO_TEXTURE_DEPTH_NV 0x20A3
#define WGL_BIND_TO_TEXTURE_RECTANGLE_DEPTH_NV 0x20A4
#define WGL_DEPTH_TEXTURE_FORMAT_NV 0x20A5
#define WGL_TEXTURE_DEPTH_COMPONENT_NV 0x20A6
#define WGL_DEPTH_COMPONENT_NV 0x20A7
#endif
#ifdef WGL_NV_render_texture_rectangle
#define WGL_BIND_TO_TEXTURE_RECTANGLE_RGB_NV 0x20A0
#define WGL_BIND_TO_TEXTURE_RECTANGLE_RGBA_NV 0x20A1
#define WGL_TEXTURE_RECTANGLE_NV 0x20A2
#endif
#ifdef WGL_NV_vertex_array_range
#define wglAllocateMemoryNV XGL_FUNCPTR(wglAllocateMemoryNV)
#define wglFreeMemoryNV XGL_FUNCPTR(wglFreeMemoryNV)
#endif
#ifdef WGL_OML_sync_control
#define wglGetMscRateOML XGL_FUNCPTR(wglGetMscRateOML)
#define wglGetSyncValuesOML XGL_FUNCPTR(wglGetSyncValuesOML)
#define wglSwapBuffersMscOML XGL_FUNCPTR(wglSwapBuffersMscOML)
#define wglSwapLayerBuffersMscOML XGL_FUNCPTR(wglSwapLayerBuffersMscOML)
#define wglWaitForMscOML XGL_FUNCPTR(wglWaitForMscOML)
#define wglWaitForSbcOML XGL_FUNCPTR(wglWaitForSbcOML)
#endif

View file

@ -0,0 +1,245 @@
//-----------------------------------------------------------------------------
// Copyright (c) 2012 GarageGames, LLC
//
// Permission is hereby granted, free of charge, to any person obtaining a copy
// of this software and associated documentation files (the "Software"), to
// deal in the Software without restriction, including without limitation the
// rights to use, copy, modify, merge, publish, distribute, sublicense, and/or
// sell copies of the Software, and to permit persons to whom the Software is
// furnished to do so, subject to the following conditions:
//
// The above copyright notice and this permission notice shall be included in
// all copies or substantial portions of the Software.
//
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
// FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS
// IN THE SOFTWARE.
//-----------------------------------------------------------------------------
#ifdef WGL_3DFX_multisample
GL_GROUP_BEGIN(WGL_3DFX_multisample)
GL_GROUP_END()
#endif
#ifdef WGL_ARB_buffer_region
GL_GROUP_BEGIN(WGL_ARB_buffer_region)
GL_FUNCTION(wglCreateBufferRegionARB,HANDLE,(HDC hDC, int iLayerPlane, UINT uType))
GL_FUNCTION(wglDeleteBufferRegionARB,VOID,(HANDLE hRegion))
GL_FUNCTION(wglRestoreBufferRegionARB,BOOL,(HANDLE hRegion, int x, int y, int width, int height, int xSrc, int ySrc))
GL_FUNCTION(wglSaveBufferRegionARB,BOOL,(HANDLE hRegion, int x, int y, int width, int height))
GL_GROUP_END()
#endif
#ifdef WGL_ARB_extensions_string
GL_GROUP_BEGIN(WGL_ARB_extensions_string)
GL_FUNCTION(wglGetExtensionsStringARB,const char*,(HDC hdc))
GL_GROUP_END()
#endif
#ifdef WGL_ARB_make_current_read
GL_GROUP_BEGIN(WGL_ARB_make_current_read)
GL_FUNCTION(wglGetCurrentReadDCARB,HDC,(VOID))
GL_FUNCTION(wglMakeContextCurrentARB,BOOL,(HDC hDrawDC, HDC hReadDC, HGLRC hglrc))
GL_GROUP_END()
#endif
#ifdef WGL_ARB_multisample
GL_GROUP_BEGIN(WGL_ARB_multisample)
GL_GROUP_END()
#endif
#ifdef WGL_ARB_pbuffer
GL_GROUP_BEGIN(WGL_ARB_pbuffer)
GL_FUNCTION(wglCreatePbufferARB,HPBUFFERARB,(HDC hDC, int iPixelFormat, int iWidth, int iHeight, const int* piAttribList))
GL_FUNCTION(wglDestroyPbufferARB,BOOL,(HPBUFFERARB hPbuffer))
GL_FUNCTION(wglGetPbufferDCARB,HDC,(HPBUFFERARB hPbuffer))
GL_FUNCTION(wglQueryPbufferARB,BOOL,(HPBUFFERARB hPbuffer, int iAttribute, int* piValue))
GL_FUNCTION(wglReleasePbufferDCARB,int,(HPBUFFERARB hPbuffer, HDC hDC))
GL_GROUP_END()
#endif
#ifdef WGL_ARB_pixel_format
GL_GROUP_BEGIN(WGL_ARB_pixel_format)
GL_FUNCTION(wglChoosePixelFormatARB,BOOL,(HDC hdc, const int* piAttribIList, const FLOAT *pfAttribFList, UINT nMaxFormats, int *piFormats, UINT *nNumFormats))
GL_FUNCTION(wglGetPixelFormatAttribfvARB,BOOL,(HDC hdc, int iPixelFormat, int iLayerPlane, UINT nAttributes, const int* piAttributes, FLOAT *pfValues))
GL_FUNCTION(wglGetPixelFormatAttribivARB,BOOL,(HDC hdc, int iPixelFormat, int iLayerPlane, UINT nAttributes, const int* piAttributes, int *piValues))
GL_GROUP_END()
#endif
#ifdef WGL_ARB_pixel_format_float
GL_GROUP_BEGIN(WGL_ARB_pixel_format_float)
GL_GROUP_END()
#endif
#ifdef WGL_ARB_render_texture
GL_GROUP_BEGIN(WGL_ARB_render_texture)
GL_FUNCTION(wglBindTexImageARB,BOOL,(HPBUFFERARB hPbuffer, int iBuffer))
GL_FUNCTION(wglReleaseTexImageARB,BOOL,(HPBUFFERARB hPbuffer, int iBuffer))
GL_FUNCTION(wglSetPbufferAttribARB,BOOL,(HPBUFFERARB hPbuffer, const int* piAttribList))
GL_GROUP_END()
#endif
#ifdef WGL_ATI_pixel_format_float
GL_GROUP_BEGIN(WGL_ATI_pixel_format_float)
GL_GROUP_END()
#endif
#ifdef WGL_ATI_render_texture_rectangle
GL_GROUP_BEGIN(WGL_ATI_render_texture_rectangle)
GL_GROUP_END()
#endif
#ifdef WGL_EXT_depth_float
GL_GROUP_BEGIN(WGL_EXT_depth_float)
GL_GROUP_END()
#endif
#ifdef WGL_EXT_display_color_table
GL_GROUP_BEGIN(WGL_EXT_display_color_table)
GL_FUNCTION(wglBindDisplayColorTableEXT,GLboolean,(GLushort id))
GL_FUNCTION(wglCreateDisplayColorTableEXT,GLboolean,(GLushort id))
GL_FUNCTION(wglDestroyDisplayColorTableEXT,void,(GLushort id))
GL_FUNCTION(wglLoadDisplayColorTableEXT,GLboolean,(GLushort* table, GLuint length))
GL_GROUP_END()
#endif
#ifdef WGL_EXT_extensions_string
GL_GROUP_BEGIN(WGL_EXT_extensions_string)
GL_FUNCTION(wglGetExtensionsStringEXT,const char*,(void))
GL_GROUP_END()
#endif
#ifdef WGL_EXT_make_current_read
GL_GROUP_BEGIN(WGL_EXT_make_current_read)
GL_FUNCTION(wglGetCurrentReadDCEXT,HDC,(VOID))
GL_FUNCTION(wglMakeContextCurrentEXT,BOOL,(HDC hDrawDC, HDC hReadDC, HGLRC hglrc))
GL_GROUP_END()
#endif
#ifdef WGL_EXT_multisample
GL_GROUP_BEGIN(WGL_EXT_multisample)
GL_GROUP_END()
#endif
#ifdef WGL_EXT_pbuffer
GL_GROUP_BEGIN(WGL_EXT_pbuffer)
GL_FUNCTION(wglCreatePbufferEXT,HPBUFFEREXT,(HDC hDC, int iPixelFormat, int iWidth, int iHeight, const int* piAttribList))
GL_FUNCTION(wglDestroyPbufferEXT,BOOL,(HPBUFFEREXT hPbuffer))
GL_FUNCTION(wglGetPbufferDCEXT,HDC,(HPBUFFEREXT hPbuffer))
GL_FUNCTION(wglQueryPbufferEXT,BOOL,(HPBUFFEREXT hPbuffer, int iAttribute, int* piValue))
GL_FUNCTION(wglReleasePbufferDCEXT,int,(HPBUFFEREXT hPbuffer, HDC hDC))
GL_GROUP_END()
#endif
#ifdef WGL_EXT_pixel_format
GL_GROUP_BEGIN(WGL_EXT_pixel_format)
GL_FUNCTION(wglChoosePixelFormatEXT,BOOL,(HDC hdc, const int* piAttribIList, const FLOAT *pfAttribFList, UINT nMaxFormats, int *piFormats, UINT *nNumFormats))
GL_FUNCTION(wglGetPixelFormatAttribfvEXT,BOOL,(HDC hdc, int iPixelFormat, int iLayerPlane, UINT nAttributes, int* piAttributes, FLOAT *pfValues))
GL_FUNCTION(wglGetPixelFormatAttribivEXT,BOOL,(HDC hdc, int iPixelFormat, int iLayerPlane, UINT nAttributes, int* piAttributes, int *piValues))
GL_GROUP_END()
#endif
#ifdef WGL_EXT_swap_control
GL_GROUP_BEGIN(WGL_EXT_swap_control)
GL_FUNCTION(wglGetSwapIntervalEXT,int,(void))
GL_FUNCTION(wglSwapIntervalEXT,BOOL,(int interval))
GL_GROUP_END()
#endif
#ifdef WGL_I3D_digital_video_control
GL_GROUP_BEGIN(WGL_I3D_digital_video_control)
GL_FUNCTION(wglGetDigitalVideoParametersI3D,BOOL,(HDC hDC, int iAttribute, int* piValue))
GL_FUNCTION(wglSetDigitalVideoParametersI3D,BOOL,(HDC hDC, int iAttribute, const int* piValue))
GL_GROUP_END()
#endif
#ifdef WGL_I3D_gamma
GL_GROUP_BEGIN(WGL_I3D_gamma)
GL_FUNCTION(wglGetGammaTableI3D,BOOL,(HDC hDC, int iEntries, USHORT* puRed, USHORT *puGreen, USHORT *puBlue))
GL_FUNCTION(wglGetGammaTableParametersI3D,BOOL,(HDC hDC, int iAttribute, int* piValue))
GL_FUNCTION(wglSetGammaTableI3D,BOOL,(HDC hDC, int iEntries, const USHORT* puRed, const USHORT *puGreen, const USHORT *puBlue))
GL_FUNCTION(wglSetGammaTableParametersI3D,BOOL,(HDC hDC, int iAttribute, const int* piValue))
GL_GROUP_END()
#endif
#ifdef WGL_I3D_genlock
GL_GROUP_BEGIN(WGL_I3D_genlock)
GL_FUNCTION(wglDisableGenlockI3D,BOOL,(HDC hDC))
GL_FUNCTION(wglEnableGenlockI3D,BOOL,(HDC hDC))
GL_FUNCTION(wglGenlockSampleRateI3D,BOOL,(HDC hDC, UINT uRate))
GL_FUNCTION(wglGenlockSourceDelayI3D,BOOL,(HDC hDC, UINT uDelay))
GL_FUNCTION(wglGenlockSourceEdgeI3D,BOOL,(HDC hDC, UINT uEdge))
GL_FUNCTION(wglGenlockSourceI3D,BOOL,(HDC hDC, UINT uSource))
GL_FUNCTION(wglGetGenlockSampleRateI3D,BOOL,(HDC hDC, UINT* uRate))
GL_FUNCTION(wglGetGenlockSourceDelayI3D,BOOL,(HDC hDC, UINT* uDelay))
GL_FUNCTION(wglGetGenlockSourceEdgeI3D,BOOL,(HDC hDC, UINT* uEdge))
GL_FUNCTION(wglGetGenlockSourceI3D,BOOL,(HDC hDC, UINT* uSource))
GL_FUNCTION(wglIsEnabledGenlockI3D,BOOL,(HDC hDC, BOOL* pFlag))
GL_FUNCTION(wglQueryGenlockMaxSourceDelayI3D,BOOL,(HDC hDC, UINT* uMaxLineDelay, UINT *uMaxPixelDelay))
GL_GROUP_END()
#endif
#ifdef WGL_I3D_image_buffer
GL_GROUP_BEGIN(WGL_I3D_image_buffer)
GL_FUNCTION(wglAssociateImageBufferEventsI3D,BOOL,(HDC hdc, HANDLE* pEvent, LPVOID *pAddress, DWORD *pSize, UINT count))
GL_FUNCTION(wglCreateImageBufferI3D,LPVOID,(HDC hDC, DWORD dwSize, UINT uFlags))
GL_FUNCTION(wglDestroyImageBufferI3D,BOOL,(HDC hDC, LPVOID pAddress))
GL_FUNCTION(wglReleaseImageBufferEventsI3D,BOOL,(HDC hdc, LPVOID* pAddress, UINT count))
GL_GROUP_END()
#endif
#ifdef WGL_I3D_swap_frame_lock
GL_GROUP_BEGIN(WGL_I3D_swap_frame_lock)
GL_FUNCTION(wglDisableFrameLockI3D,BOOL,(VOID))
GL_FUNCTION(wglEnableFrameLockI3D,BOOL,(VOID))
GL_FUNCTION(wglIsEnabledFrameLockI3D,BOOL,(BOOL* pFlag))
GL_FUNCTION(wglQueryFrameLockMasterI3D,BOOL,(BOOL* pFlag))
GL_GROUP_END()
#endif
#ifdef WGL_I3D_swap_frame_usage
GL_GROUP_BEGIN(WGL_I3D_swap_frame_usage)
GL_FUNCTION(wglBeginFrameTrackingI3D,BOOL,(void))
GL_FUNCTION(wglEndFrameTrackingI3D,BOOL,(void))
GL_FUNCTION(wglGetFrameUsageI3D,BOOL,(float* pUsage))
GL_FUNCTION(wglQueryFrameTrackingI3D,BOOL,(DWORD* pFrameCount, DWORD *pMissedFrames, float *pLastMissedUsage))
GL_GROUP_END()
#endif
#ifdef WGL_NV_float_buffer
GL_GROUP_BEGIN(WGL_NV_float_buffer)
GL_GROUP_END()
#endif
#ifdef WGL_NV_render_depth_texture
GL_GROUP_BEGIN(WGL_NV_render_depth_texture)
GL_GROUP_END()
#endif
#ifdef WGL_NV_render_texture_rectangle
GL_GROUP_BEGIN(WGL_NV_render_texture_rectangle)
GL_GROUP_END()
#endif
#ifdef WGL_NV_vertex_array_range
GL_GROUP_BEGIN(WGL_NV_vertex_array_range)
GL_FUNCTION(wglAllocateMemoryNV,void *,(GLsizei size, GLfloat readFrequency, GLfloat writeFrequency, GLfloat priority))
GL_FUNCTION(wglFreeMemoryNV,void,(void *pointer))
GL_GROUP_END()
#endif
#ifdef WGL_OML_sync_control
GL_GROUP_BEGIN(WGL_OML_sync_control)
GL_FUNCTION(wglGetMscRateOML,BOOL,(HDC hdc, INT32* numerator, INT32 *denominator))
GL_FUNCTION(wglGetSyncValuesOML,BOOL,(HDC hdc, INT64* ust, INT64 *msc, INT64 *sbc))
GL_FUNCTION(wglSwapBuffersMscOML,INT64,(HDC hdc, INT64 target_msc, INT64 divisor, INT64 remainder))
GL_FUNCTION(wglSwapLayerBuffersMscOML,INT64,(HDC hdc, INT fuPlanes, INT64 target_msc, INT64 divisor, INT64 remainder))
GL_FUNCTION(wglWaitForMscOML,BOOL,(HDC hdc, INT64 target_msc, INT64 divisor, INT64 remainder, INT64* ust, INT64 *msc, INT64 *sbc))
GL_FUNCTION(wglWaitForSbcOML,BOOL,(HDC hdc, INT64 target_sbc, INT64* ust, INT64 *msc, INT64 *sbc))
GL_GROUP_END()
#endif

View file

@ -0,0 +1,47 @@
//-----------------------------------------------------------------------------
// Copyright (c) 2012 GarageGames, LLC
//
// Permission is hereby granted, free of charge, to any person obtaining a copy
// of this software and associated documentation files (the "Software"), to
// deal in the Software without restriction, including without limitation the
// rights to use, copy, modify, merge, publish, distribute, sublicense, and/or
// sell copies of the Software, and to permit persons to whom the Software is
// furnished to do so, subject to the following conditions:
//
// The above copyright notice and this permission notice shall be included in
// all copies or substantial portions of the Software.
//
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
// FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS
// IN THE SOFTWARE.
//-----------------------------------------------------------------------------
// Windows WGL functions
GL_GROUP_BEGIN(ARB_win32)
GL_FUNCTION(wglCopyContext, BOOL, (HGLRC, HGLRC, UINT))
GL_FUNCTION(wglCreateContext, HGLRC, (HDC))
GL_FUNCTION(wglCreateLayerContext, HGLRC, (HDC, GLint))
GL_FUNCTION(wglDeleteContext, BOOL, (HGLRC))
GL_FUNCTION(wglGetCurrentContext, HGLRC, (VOID))
GL_FUNCTION(wglGetCurrentDC, HDC, (VOID))
GL_FUNCTION(wglGetProcAddress, PROC, (LPCSTR))
GL_FUNCTION(wglMakeCurrent, BOOL, (HDC, HGLRC))
GL_FUNCTION(wglShareLists, BOOL, (HGLRC, HGLRC))
GL_FUNCTION(wglDescribeLayerPlane, BOOL, (HDC, GLint, GLint, UINT, LPLAYERPLANEDESCRIPTOR))
GL_FUNCTION(wglSetLayerPaletteEntries, GLint, (HDC, GLint, GLint, GLint, CONST COLORREF *))
GL_FUNCTION(wglGetLayerPaletteEntries, GLint, (HDC, GLint, GLint, GLint, COLORREF *))
GL_FUNCTION(wglRealizeLayerPalette, BOOL, (HDC, GLint, BOOL))
GL_FUNCTION(wglSwapLayerBuffers, BOOL, (HDC, UINT))
// Ascii and Unicode versions
GL_FUNCTION(wglUseFontBitmapsA, BOOL, (HDC, DWORD, DWORD, DWORD))
GL_FUNCTION(wglUseFontOutlinesA, BOOL, (HDC, DWORD, DWORD, DWORD, FLOAT, FLOAT, GLint, LPGLYPHMETRICSFLOAT))
GL_FUNCTION(wglUseFontBitmapsW, BOOL, (HDC, DWORD, DWORD, DWORD))
GL_FUNCTION(wglUseFontOutlinesW, BOOL, (HDC, DWORD, DWORD, DWORD, FLOAT, FLOAT, GLint, LPGLYPHMETRICSFLOAT))
GL_GROUP_END()

View file

@ -0,0 +1,626 @@
//-----------------------------------------------------------------------------
// Copyright (c) 2012 GarageGames, LLC
//
// Permission is hereby granted, free of charge, to any person obtaining a copy
// of this software and associated documentation files (the "Software"), to
// deal in the Software without restriction, including without limitation the
// rights to use, copy, modify, merge, publish, distribute, sublicense, and/or
// sell copies of the Software, and to permit persons to whom the Software is
// furnished to do so, subject to the following conditions:
//
// The above copyright notice and this permission notice shall be included in
// all copies or substantial portions of the Software.
//
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
// FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS
// IN THE SOFTWARE.
//-----------------------------------------------------------------------------
//-----------------------------------------------------------------------------
//-----------------------------------------------------------------------------
#include "os/osFile.h"
#include "os/osPrint.h"
#include "util/utilStr.h"
#include "util/utilString.h"
#include "util/utilArray.h"
#include "util/utilMap.h"
#include "util/utilSort.h"
using namespace Torque;
#include <stdio.h>
#include <dirent.h>
//-----------------------------------------------------------------------------
const char* OrderTable[] =
{
// Extension list as of 8.25.2005
// http://oss.sgi.com/projects/ogl-sample/registry/
// Core
"GL_VERSION_1_1",
"GL_VERSION_1_2",
"GL_VERSION_1_3",
"GL_VERSION_1_4",
"GL_VERSION_1_5",
// X Windows
"GLX_VERSION_1_1",
"GLX_VERSION_1_2",
"GLX_VERSION_1_3",
"GLX_VERSION_1_4",
"GLX_VERSION_1_5",
// Arb extension
"GL_ARB_multitexture",
"GLX_ARB_get_proc_address",
"GL_ARB_transpose_matrix",
"WGL_ARB_buffer_region",
"GL_ARB_multisample",
"GL_ARB_texture_env_add",
"GL_ARB_texture_cube_map",
"WGL_ARB_extensions_string",
"WGL_ARB_pixel_format",
"WGL_ARB_make_current_read",
"WGL_ARB_pbuffer",
"GL_ARB_texture_compression",
"GL_ARB_texture_border_clamp",
"GL_ARB_point_parameters",
"GL_ARB_vertex_blend",
"GL_ARB_matrix_palette",
"GL_ARB_texture_env_combine",
"GL_ARB_texture_env_crossbar",
"GL_ARB_texture_env_dot3",
"WGL_ARB_render_texture",
"GL_ARB_texture_mirrored_repeat",
"GL_ARB_depth_texture",
"GL_ARB_shadow",
"GL_ARB_shadow_ambient",
"GL_ARB_window_pos",
"GL_ARB_vertex_program",
"GL_ARB_fragment_program",
"GL_ARB_vertex_buffer_object",
"GL_ARB_occlusion_query",
"GL_ARB_shader_objects",
"GL_ARB_vertex_shader",
"GL_ARB_fragment_shader",
"GL_ARB_shading_language_100",
"GL_ARB_texture_non_power_of_two",
"GL_ARB_point_sprite",
"GL_ARB_fragment_program_shadow",
"GL_ARB_draw_buffers",
"GL_ARB_texture_rectangle",
"GL_ARB_color_buffer_float",
"GL_ARB_half_float_pixel",
"GL_ARB_texture_float",
"GL_ARB_pixel_buffer_object",
// Misc extensions
"GL_EXT_abgr",
"GL_EXT_blend_color",
"GL_EXT_polygon_offset",
"GL_EXT_texture",
"GL_EXT_texture3D",
"GL_SGIS_texture_filter4",
"GL_EXT_subtexture",
"GL_EXT_copy_texture",
"GL_EXT_histogram",
"GL_EXT_convolution",
"GL_SGI_color_matrix",
"GL_SGI_color_table",
"GL_SGIS_pixel_texture",
"GL_SGIX_pixel_texture",
"GL_SGIS_texture4D",
"GL_SGI_texture_color_table",
"GL_EXT_cmyka",
"GL_EXT_texture_object",
"GL_SGIS_detail_texture",
"GL_SGIS_sharpen_texture",
"GL_EXT_packed_pixels",
"GL_SGIS_texture_lod",
"GL_SGIS_multisample",
"GL_EXT_rescale_normal",
"GLX_EXT_visual_info",
"GL_EXT_vertex_array",
"GL_EXT_misc_attribute",
"GL_SGIS_generate_mipmap",
"GL_SGIX_clipmap",
"GL_SGIX_shadow",
"GL_SGIS_texture_edge_clamp",
"GL_SGIS_texture_border_clamp",
"GL_EXT_blend_minmax",
"GL_EXT_blend_subtract",
"GL_EXT_blend_logic_op",
"GLX_SGI_swap_control",
"GLX_SGI_video_sync",
"GLX_SGI_make_current_read",
"GLX_SGIX_video_source",
"GLX_EXT_visual_rating",
"GL_SGIX_interlace",
"GLX_EXT_import_context",
"GLX_SGIX_fbconfig",
"GLX_SGIX_pbuffer",
"GL_SGIS_texture_select",
"GL_SGIX_sprite",
"GL_SGIX_texture_multi_buffer",
"GL_EXT_point_parameters",
"GL_SGIX_instruments",
"GL_SGIX_texture_scale_bias",
"GL_SGIX_framezoom",
"GL_SGIX_tag_sample_buffer",
"GL_SGIX_reference_plane",
"GL_SGIX_flush_raster",
"GLX_SGI_cushion",
"GL_SGIX_depth_texture",
"GL_SGIS_fog_function",
"GL_SGIX_fog_offset",
"GL_HP_image_transform",
"GL_HP_convolution_border_modes",
"GL_SGIX_texture_add_env",
"GL_EXT_color_subtable",
"GLU_EXT_object_space_tess",
"GL_PGI_vertex_hints",
"GL_PGI_misc_hints",
"GL_EXT_paletted_texture",
"GL_EXT_clip_volume_hint",
"GL_SGIX_list_priority",
"GL_SGIX_ir_instrument1",
"GLX_SGIX_video_resize",
"GL_SGIX_texture_lod_bias",
"GLU_SGI_filter4_parameters",
"GLX_SGIX_dm_buffer",
"GL_SGIX_shadow_ambient",
"GLX_SGIX_swap_group",
"GLX_SGIX_swap_barrier",
"GL_EXT_index_texture",
"GL_EXT_index_material",
"GL_EXT_index_func",
"GL_EXT_index_array_formats",
"GL_EXT_compiled_vertex_array",
"GL_EXT_cull_vertex",
"GLU_EXT_nurbs_tessellator",
"GL_SGIX_ycrcb",
"GL_EXT_fragment_lighting",
"GL_IBM_rasterpos_clip",
"GL_HP_texture_lighting",
"GL_EXT_draw_range_elements",
"GL_WIN_phong_shading",
"GL_WIN_specular_fog",
"GLX_SGIS_color_range",
"GL_EXT_light_texture",
"GL_SGIX_blend_alpha_minmax",
"GL_EXT_scene_marker",
"GL_SGIX_pixel_texture_bits",
"GL_EXT_bgra",
"GL_SGIX_async",
"GL_SGIX_async_pixel",
"GL_SGIX_async_histogram",
"GL_INTEL_texture_scissor",
"GL_INTEL_parallel_arrays",
"GL_HP_occlusion_test",
"GL_EXT_pixel_transform",
"GL_EXT_pixel_transform_color_table",
"GL_EXT_shared_texture_palette",
"GLX_SGIS_blended_overlay",
"GL_EXT_separate_specular_color",
"GL_EXT_secondary_color",
"GL_EXT_texture_env",
"GL_EXT_texture_perturb_normal",
"GL_EXT_multi_draw_arrays",
"GL_EXT_fog_coord",
"GL_REND_screen_coordinates",
"GL_EXT_coordinate_frame",
"GL_EXT_texture_env_combine",
"GL_APPLE_specular_vector",
"GL_APPLE_transform_hint",
"GL_SUNX_constant_data",
"GL_SUN_global_alpha",
"GL_SUN_triangle_list",
"GL_SUN_vertex",
"WGL_EXT_display_color_table",
"WGL_EXT_extensions_string",
"WGL_EXT_make_current_read",
"WGL_EXT_pixel_format",
"WGL_EXT_pbuffer",
"WGL_EXT_swap_control",
"GL_EXT_blend_func_separate",
"GL_INGR_color_clamp",
"GL_INGR_interlace_read",
"GL_EXT_stencil_wrap",
"WGL_EXT_depth_float",
"GL_EXT_422_pixels",
"GL_NV_texgen_reflection",
"GL_SGIX_texture_range",
"GL_SUN_convolution_border_modes",
"GLX_SUN_get_transparent_index",
"GL_EXT_texture_env_add",
"GL_EXT_texture_lod_bias",
"GL_EXT_texture_filter_anisotropic",
"GL_EXT_vertex_weighting",
"GL_NV_light_max_exponent",
"GL_NV_vertex_array_range",
"GL_NV_register_combiners",
"GL_NV_fog_distance",
"GL_NV_texgen_emboss",
"GL_NV_blend_square",
"GL_NV_texture_env_combine4",
"GL_MESA_resize_buffers",
"GL_MESA_window_pos",
"GL_EXT_texture_compression_s3tc",
"GL_IBM_cull_vertex",
"GL_IBM_multimode_draw_arrays",
"GL_IBM_vertex_array_lists",
"GL_3DFX_texture_compression_FXT1",
"GL_3DFX_multisample",
"GL_3DFX_tbuffer",
"WGL_EXT_multisample",
"GL_SGIX_vertex_preclip",
"GL_SGIX_resample",
"GL_SGIS_texture_color_mask",
"GLX_MESA_copy_sub_buffer",
"GLX_MESA_pixmap_colormap",
"GLX_MESA_release_buffers",
"GLX_MESA_set_3dfx_mode",
"GL_EXT_texture_env_dot3",
"GL_ATI_texture_mirror_once",
"GL_NV_fence",
"GL_IBM_static_data",
"GL_IBM_texture_mirrored_repeat",
"GL_NV_evaluators",
"GL_NV_packed_depth_stencil",
"GL_NV_register_combiners2",
"GL_NV_texture_compression_vtc",
"GL_NV_texture_rectangle",
"GL_NV_texture_shader",
"GL_NV_texture_shader2",
"GL_NV_vertex_array_range2",
"GL_NV_vertex_program",
"GLX_SGIX_visual_select_group",
"GL_SGIX_texture_coordinate_clamp",
"GLX_OML_swap_method",
"GLX_OML_sync_control",
"GL_OML_interlace",
"GL_OML_subsample",
"GL_OML_resample",
"WGL_OML_sync_control",
"GL_NV_copy_depth_to_color",
"GL_ATI_envmap_bumpmap",
"GL_ATI_fragment_shader",
"GL_ATI_pn_triangles",
"GL_ATI_vertex_array_object",
"GL_EXT_vertex_shader",
"GL_ATI_vertex_streams",
"WGL_I3D_digital_video_control",
"WGL_I3D_gamma",
"WGL_I3D_genlock",
"WGL_I3D_image_buffer",
"WGL_I3D_swap_frame_lock",
"WGL_I3D_swap_frame_usage",
"GL_ATI_element_array",
"GL_SUN_mesh_array",
"GL_SUN_slice_accum",
"GL_NV_multisample_filter_hint",
"GL_NV_depth_clamp",
"GL_NV_occlusion_query",
"GL_NV_point_sprite",
"WGL_NV_render_depth_texture",
"WGL_NV_render_texture_rectangle",
"GL_NV_texture_shader3",
"GL_NV_vertex_program1_1",
"GL_EXT_shadow_funcs",
"GL_EXT_stencil_two_side",
"GL_ATI_text_fragment_shader",
"GL_APPLE_client_storage",
"GL_APPLE_element_array",
"GL_APPLE_fence",
"GL_APPLE_vertex_array_object",
"GL_APPLE_vertex_array_range",
"GL_APPLE_ycbcr_422",
"GL_S3_s3tc",
"GL_ATI_draw_buffers",
"WGL_ATI_pixel_format_float",
"GL_ATI_texture_env_combine3",
"GL_ATI_texture_float",
"GL_NV_float_buffer",
"GL_NV_fragment_program",
"GL_NV_half_float",
"GL_NV_pixel_data_range",
"GL_NV_primitive_restart",
"GL_NV_texture_expand_normal",
"GL_NV_vertex_program2",
"GL_ATI_map_object_buffer",
"GL_ATI_separate_stencil",
"GL_ATI_vertex_attrib_array_object",
"GL_OES_byte_coordinates",
"GL_OES_fixed_point",
"GL_OES_single_precision",
"GL_OES_compressed_paletted_texture",
"GL_OES_read_format",
"GL_OES_query_matrix",
"GL_EXT_depth_bounds_test",
"GL_EXT_texture_mirror_clamp",
"GL_EXT_blend_equation_separate",
"GL_MESA_pack_invert",
"GL_MESA_ycbcr_texture",
"GL_EXT_pixel_buffer_object",
"GL_NV_fragment_program_option",
"GL_NV_fragment_program2",
"GL_NV_vertex_program2_option",
"GL_NV_vertex_program3",
"GLX_SGIX_hyperpipe",
"GLX_MESA_agp_offset",
"GL_EXT_texture_compression_dxt1",
"GL_EXT_framebuffer_object",
"GL_GREMEDY_string_marker",
};
Map<String,int> OutputOrder;
//-----------------------------------------------------------------------------
String trim(const char* str)
{
String ts = "";
if (str) {
int s = 0, e = strLength(str);
for (; s != e; s++) {
C8 c = str[s];
if (c != ' ' && c != '\t' && c != '\n')
break;
}
while (s != e) {
C8 c = str[--e];
if (c != ' ' && c != '\t' && c != '\n')
break;
}
if (s != e)
ts.insert(0,str + s,e-s+1);
}
return ts;
}
//-----------------------------------------------------------------------------
struct Group
{
String name;
String link;
Array<String> defines;
Array<String> functions;
Array<String> types;
int order;
};
typedef Array<Group> GroupList;
static inline int weight(const String& str)
{
if (str.find("GL_VERSION") != String::NPos)
return 0;
String prefix = str.substr(0,3);
if (prefix == "GL_")
return 1;
if (prefix == "GLU")
return 2;
if (prefix == "GLX")
return 3;
if (prefix == "WGL")
return 4;
return 5;
}
bool operator<(const Group& a,const Group& b)
{
int wa = weight(a.name);
int wb = weight(b.name);
return (wa == wb)? a.name < b.name: wa < wb;
// return a.order < b.order;
}
bool loadFile(Group& group,String name)
{
FILE* file = fopen(name.c_str(),"r");
if (!file) {
Print("Could not open file " + name);
return false;
}
char buf[512];
group.name = trim(fgets(buf,sizeof(buf),file));
Map<String,int>::Iterator entry = OutputOrder.find(group.name);
if (entry == OutputOrder.end()) {
Print ("[" + group.name + "]");
}
group.order = (entry != OutputOrder.end())? entry->value: 2000;
while (!feof(file)) {
String str = trim(fgets(buf,sizeof(buf),file));
if (!str.length())
continue;
if (str.find("http:") != String::NPos) {
group.link = trim(str);
continue;
}
if (str.find("typedef") != String::NPos) {
group.types.pushBack(str);
continue;
}
if (str.find("DECLARE") != String::NPos) {
group.types.pushBack(str);
continue;
}
if (str.find("(") != String::NPos) {
group.functions.pushBack(str);
continue;
}
group.defines.pushBack(str);
}
fclose( file );
return true;
}
void loadDir(GroupList& groups,String name,const char* filter)
{
DIR *dir = opendir(name);
if (!dir) {
Print("Could not open file " + name);
return;
}
struct dirent *fEntry;
while ((fEntry = readdir(dir)) != 0) {
if (fEntry->d_name[0] == '.')
continue;
String file = name + "/" + String(fEntry->d_name);
if (filter[0] != '*' && file.find(filter) == String::NPos)
continue;
//Print("Loading " + file);
groups.pushBack(Group());
if (!loadFile(groups.last(),file))
groups.popBack();
}
quickSort(groups.begin(),groups.end());
}
//-----------------------------------------------------------------------------
void write(FILE* file,String line)
{
fwrite(line,1,line.length(),file);
}
void outputHeader(GroupList& groups, String name)
{
FILE* file = fopen(name.c_str(),"w");
if (!file)
Print("Could not open file " + name);
// Output all the group name together at the top
for (GroupList::Iterator grp = groups.begin(); grp != groups.end(); grp++)
write(file,"#define " + grp->name + "\n");
#if 0 // Types now with the group
// Output all the types for all the extensions
for (GroupList::Iterator grp = groups.begin(); grp != groups.end(); grp++)
for (Array<String>::Iterator itr = grp->types.begin();
itr != grp->types.end(); itr++)
write(file,*itr + ";\n");
#endif
// Output the defines for each group
for (GroupList::Iterator grp = groups.begin(); grp != groups.end(); grp++) {
if (!grp->name)
continue;
write(file,"\n#ifdef " + grp->name + "\n");
for (Array<String>::Iterator itr = grp->types.begin();
itr != grp->types.end(); itr++)
write(file,*itr + ";\n");
for (Array<String>::Iterator itr = grp->defines.begin();
itr != grp->defines.end(); itr++) {
write(file,"#define " + *itr + "\n");
}
for (Array<String>::Iterator itr = grp->functions.begin();
itr != grp->functions.end(); itr++) {
String& str = *itr;
// Parse function "return name (args)". Start at the back because
// args is enclosed in (), the name has no spaces, and the return type
// can be several tokens, such as "void *" or "const char *"
int b = str.length();
int a = b - 1;
while (str[a] != '(')
a--;
while (str[--a] == ' ')
;
b = a;
while (str[a] != ' ')
a--;
String name = str.substr(a+1,b - a);
//
write(file,"#define "+name+" XGL_FUNCPTR("+name+")\n");
}
write(file,"#endif\n");
}
fclose(file);
}
void outputFunctions(GroupList& groups, String name)
{
FILE* file = fopen(name.c_str(),"w");
if (!file)
Print("Could not open file " + name);
// Output the functions for each group
for (GroupList::Iterator grp = groups.begin(); grp != groups.end(); grp++) {
if (!grp->name)
continue;
if (grp->name == "GL_ARB_imaging")
// Imaging is include as part of 1.4...
write(file,"\n#if defined(GL_ARB_imaging) && !defined(GL_VERSION_1_4)\n");
else
write(file,"\n#ifdef " + grp->name + "\n");
write(file,"GL_GROUP_BEGIN(" + grp->name + ")\n");
for (Array<String>::Iterator itr = grp->functions.begin();
itr != grp->functions.end(); itr++) {
String& str = *itr;
// Parse function "return name (args)". Start at the back because
// args is enclosed in (), the name has no spaces, and the return type
// can be several tokens, such as "void *" or "const char *"
int b = str.length();
int a = b - 1;
while (str[a] != '(')
a--;
String args = str.substr(a,b - a);
while (str[--a] == ' ')
;
b = a;
while (str[a] != ' ')
a--;
String name = str.substr(a+1,b - a);
while (str[a] == ' ')
a--;
String rtype = str.substr(0,a+1);
//
write(file,"GL_FUNCTION("+name+","+rtype+","+args+")\n");
}
write(file,"GL_GROUP_END()\n#endif\n");
}
fclose(file);
}
//-----------------------------------------------------------------------------
int main(int argc, char* argv[])
{
Kernel::installDefaultPrint();
// Build a name -> order map for faster lookups.
for (int i = 0; i < sizeof(OrderTable) / sizeof(const char*); i++)
OutputOrder.insert(String(OrderTable[i]),i+1);
GroupList extensions;
extensions.reserve(800);
loadDir(extensions,"core","VERSION");
loadDir(extensions,"extensions","*");
outputHeader(extensions,"glext.h");
outputFunctions(extensions,"glfnext.h");
return 0;
}

View file

@ -0,0 +1,89 @@
//-----------------------------------------------------------------------------
// Copyright (c) 2012 GarageGames, LLC
//
// Permission is hereby granted, free of charge, to any person obtaining a copy
// of this software and associated documentation files (the "Software"), to
// deal in the Software without restriction, including without limitation the
// rights to use, copy, modify, merge, publish, distribute, sublicense, and/or
// sell copies of the Software, and to permit persons to whom the Software is
// furnished to do so, subject to the following conditions:
//
// The above copyright notice and this permission notice shall be included in
// all copies or substantial portions of the Software.
//
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
// FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS
// IN THE SOFTWARE.
//-----------------------------------------------------------------------------
#include "core/strings/stringFunctions.h"
#include "platform/platformDlibrary.h"
#include "console/console.h"
namespace GL
{
//-----------------------------------------------------------------------------
// Current active extensions
struct GLExtensionPtrs;
GLExtensionPtrs* _GGLptr;
struct GLExtensionFlags;
GLExtensionFlags* _GGLflag;
//-----------------------------------------------------------------------------
static inline int versionCombine( int major, int minor )
{
return major * 100 + minor;
}
bool bindFunction( DLibrary *dll, void *&fnAddress, const char *name )
{
fnAddress = dll->bind( name );
if (!fnAddress)
Con::warnf( "GLExtensions: DLL bind failed for %s", name );
return fnAddress != 0;
}
bool hasExtension( const char *name, const char *extensions )
{
// Extensions are compared against the extension strings
if (extensions && *extensions) {
const char* ptr = dStrstr(extensions,name);
if (ptr) {
char end = ptr[dStrlen(name)];
if (end == ' ' || end == 0)
return true;
}
}
return false;
}
bool hasVersion( const char *name, const char* prefix, int major, int minor )
{
// Extension group names are compared against the version number. The prefix
// string should be "GL_VERSION" or "GLX_VERSION".. group names are
// "GL_VERSION_1_1", "GL_VERSION_1_2", "GLX_VERSION_1_2", etc.
while (*name && *prefix && *name == *prefix)
name++, prefix++;
if (*name == '_' && *prefix == '\0') {
int maj = dAtoi(++name);
while (dIsdigit(*name))
*name++;
int min = dAtoi(++name);
return versionCombine(maj,min) <= versionCombine(major,minor);
}
return false;
}
} // Namespace

View file

@ -0,0 +1,117 @@
//-----------------------------------------------------------------------------
// Copyright (c) 2012 GarageGames, LLC
//
// Permission is hereby granted, free of charge, to any person obtaining a copy
// of this software and associated documentation files (the "Software"), to
// deal in the Software without restriction, including without limitation the
// rights to use, copy, modify, merge, publish, distribute, sublicense, and/or
// sell copies of the Software, and to permit persons to whom the Software is
// furnished to do so, subject to the following conditions:
//
// The above copyright notice and this permission notice shall be included in
// all copies or substantial portions of the Software.
//
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
// FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS
// IN THE SOFTWARE.
//-----------------------------------------------------------------------------
#ifndef GL_GGL_H
#define GL_GGL_H
#ifndef _MPOINT3_H_
#include "math/mPoint3.h"
#endif
//-----------------------------------------------------------------------------
// Configuration file which defines which parts of GL to include
#ifndef DOXYGEN
#include "gfx/gl/ggl/gglConfig.h"
//-----------------------------------------------------------------------------
#if defined(__CYGWIN__) || defined(WIN32) || defined(_WIN32) || defined(__WIN32)
#define XGL_DLL __stdcall
#else
#define XGL_DLL
#endif
//-----------------------------------------------------------------------------
// Include core (OpenGL 1.1) definitions
#include "gfx/gl/ggl/generated/glc.h"
#include "gfx/gl/ggl/generated/gle.h"
//-----------------------------------------------------------------------------
// All core functionality is implemented as function pointers.
#define GL_GROUP_BEGIN(name)
#define GL_FUNCTION(name, type, args) extern type (XGL_DLL *name) args;
#define GL_GROUP_END()
#include "gfx/gl/ggl/generated/glcfn.h"
#undef GL_GROUP_BEGIN
#undef GL_FUNCTION
#undef GL_GROUP_END
/// OpenGL interface.
namespace GL
{
//-----------------------------------------------------------------------------
// Extensions use indirection in order to support multiple contexts
struct GLExtensionPtrs {
bool bound;
// Include all OpenGL extensions for all platform
#define GL_GROUP_BEGIN(name)
#define GL_FUNCTION(name, type, args) type (XGL_DLL *_##name) args;
#define GL_GROUP_END()
#include "gfx/gl/ggl/generated/glefn.h"
#undef GL_GROUP_BEGIN
#undef GL_FUNCTION
#undef GL_GROUP_END
GLExtensionPtrs() { bound = false; }
};
struct GLExtensionFlags {
bool bound;
// Define extension "has" variables
#define GL_GROUP_BEGIN(name) bool has_##name;
#define GL_FUNCTION(name, type, args)
#define GL_GROUP_END()
#include "gfx/gl/ggl/generated/glefn.h"
#undef GL_GROUP_BEGIN
#undef GL_FUNCTION
#undef GL_GROUP_END
GLExtensionFlags() { bound = false; }
};
// Extension loading has been reimplemented on each platform, and each platform
// has a different version of GLExtensionPtrs and GLExtensionFlags. When binding
// extensions for that platform, you MUST use these pointers. From there the XGL_FUNCPTR
// define will handle converting a gl*EXT call into the proper member function call.
extern GLExtensionPtrs* _GGLptr;
#define XGL_FUNCPTR(name) (GL::_GGLptr->_##name)
#endif // Doxygen
extern GLExtensionFlags* _GGLflag;
#define gglHasExtension(name) (GL::_GGLflag->has_##name)
} // Namespace
#endif

View file

@ -0,0 +1,378 @@
//-----------------------------------------------------------------------------
// Copyright (c) 2012 GarageGames, LLC
//
// Permission is hereby granted, free of charge, to any person obtaining a copy
// of this software and associated documentation files (the "Software"), to
// deal in the Software without restriction, including without limitation the
// rights to use, copy, modify, merge, publish, distribute, sublicense, and/or
// sell copies of the Software, and to permit persons to whom the Software is
// furnished to do so, subject to the following conditions:
//
// The above copyright notice and this permission notice shall be included in
// all copies or substantial portions of the Software.
//
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
// FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS
// IN THE SOFTWARE.
//-----------------------------------------------------------------------------
//-----------------------------------------------------------------------------
// Undefine extensions not required
#define GL_VERSION_1_2
#define GL_VERSION_1_3
#define GL_VERSION_1_4
#define GL_VERSION_1_5
#define GL_VERSION_2_0
#define GL_3DFX_multisample
#define GL_3DFX_tbuffer
#define GL_3DFX_texture_compression_FXT1
#define GL_APPLE_client_storage
#define GL_APPLE_element_array
#define GL_APPLE_fence
#define GL_APPLE_specular_vector
#define GL_APPLE_transform_hint
#define GL_APPLE_vertex_array_object
#define GL_APPLE_vertex_array_range
#define GL_APPLE_ycbcr_422
#define GL_ARB_depth_texture
#define GL_ARB_fragment_program
#define GL_ARB_fragment_shader
#define GL_ARB_imaging
#define GL_ARB_matrix_palette
#define GL_ARB_multisample
#define GL_ARB_multitexture
#define GL_ARB_occlusion_query
#define GL_ARB_pixel_buffer_object
#define GL_ARB_point_parameters
#define GL_ARB_point_sprite
#define GL_ARB_shader_objects
#define GL_ARB_shading_language_100
#define GL_ARB_shadow
#define GL_ARB_shadow_ambient
#define GL_ARB_texture_border_clamp
#define GL_ARB_texture_compression
#define GL_ARB_texture_cube_map
#define GL_ARB_texture_env_add
#define GL_ARB_texture_env_combine
#define GL_ARB_texture_env_crossbar
#define GL_ARB_texture_env_dot3
#define GL_ARB_texture_mirrored_repeat
#define GL_ARB_texture_non_power_of_two
#define GL_ARB_texture_rectangle
#define GL_ARB_transpose_matrix
#define GL_ARB_vertex_blend
#define GL_ARB_vertex_buffer_object
#define GL_ARB_vertex_program
#define GL_ARB_vertex_shader
#define GL_ARB_window_pos
#define GL_ATIX_point_sprites
#define GL_ATIX_texture_env_combine3
#define GL_ATIX_texture_env_route
#define GL_ATIX_vertex_shader_output_point_size
#define GL_ATI_draw_buffers
#define GL_ATI_element_array
#define GL_ATI_envmap_bumpmap
#define GL_ATI_fragment_shader
#define GL_ATI_map_object_buffer
#define GL_ATI_pn_triangles
#define GL_ATI_separate_stencil
#define GL_ATI_text_fragment_shader
#define GL_ATI_texture_env_combine3
#define GL_ATI_texture_float
#define GL_ATI_texture_mirror_once
#define GL_ATI_vertex_array_object
#define GL_ATI_vertex_attrib_array_object
#define GL_ATI_vertex_streams
#define GL_EXT_422_pixels
#define GL_EXT_Cg_shader
#define GL_EXT_abgr
#define GL_EXT_bgra
#define GL_EXT_blend_color
#define GL_EXT_blend_equation_separate
#define GL_EXT_blend_func_separate
#define GL_EXT_blend_logic_op
#define GL_EXT_blend_minmax
#define GL_EXT_blend_subtract
#define GL_EXT_clip_volume_hint
#define GL_EXT_cmyka
#define GL_EXT_color_subtable
#define GL_EXT_compiled_vertex_array
#define GL_EXT_convolution
#define GL_EXT_coordinate_frame
#define GL_EXT_copy_texture
#define GL_EXT_cull_vertex
#define GL_EXT_depth_bounds_test
#define GL_EXT_draw_range_elements
#define GL_EXT_fog_coord
#define GL_EXT_fragment_lighting
#define GL_EXT_framebuffer_blit
#define GL_EXT_framebuffer_object
#define GL_EXT_histogram
#define GL_EXT_index_array_formats
#define GL_EXT_index_func
#define GL_EXT_index_material
#define GL_EXT_index_texture
#define GL_EXT_light_texture
#define GL_EXT_misc_attribute
#define GL_EXT_multi_draw_arrays
#define GL_EXT_multisample
#define GL_EXT_packed_pixels
#define GL_EXT_paletted_texture
#define GL_EXT_pixel_buffer_object
#define GL_EXT_pixel_transform
#define GL_EXT_pixel_transform_color_table
#define GL_EXT_point_parameters
#define GL_EXT_polygon_offset
#define GL_EXT_rescale_normal
#define GL_EXT_scene_marker
#define GL_EXT_secondary_color
#define GL_EXT_separate_specular_color
#define GL_EXT_shadow_funcs
#define GL_EXT_shared_texture_palette
#define GL_EXT_stencil_two_side
#define GL_EXT_stencil_wrap
#define GL_EXT_subtexture
#define GL_EXT_texture
#define GL_EXT_texture3D
#define GL_EXT_texture_compression_dxt1
#define GL_EXT_texture_compression_s3tc
#define GL_EXT_texture_cube_map
#define GL_EXT_texture_edge_clamp
#define GL_EXT_texture_env
#define GL_EXT_texture_env_add
#define GL_EXT_texture_env_combine
#define GL_EXT_texture_env_dot3
#define GL_EXT_texture_filter_anisotropic
#define GL_EXT_texture_lod_bias
#define GL_EXT_texture_mirror_clamp
#define GL_EXT_texture_object
#define GL_EXT_texture_perturb_normal
#define GL_EXT_texture_rectangle
#define GL_EXT_vertex_array
#define GL_EXT_vertex_shader
#define GL_EXT_vertex_weighting
#define GL_GREMEDY_string_marker
#define GL_HP_convolution_border_modes
#define GL_HP_image_transform
#define GL_HP_occlusion_test
#define GL_HP_texture_lighting
#define GL_IBM_cull_vertex
#define GL_IBM_multimode_draw_arrays
#define GL_IBM_rasterpos_clip
#define GL_IBM_static_data
#define GL_IBM_texture_mirrored_repeat
#define GL_IBM_vertex_array_lists
#define GL_INGR_color_clamp
#define GL_INGR_interlace_read
#define GL_INTEL_parallel_arrays
#define GL_INTEL_texture_scissor
#define GL_KTX_buffer_region
#define GL_MESA_pack_invert
#define GL_MESA_resize_buffers
#define GL_MESA_window_pos
#define GL_MESA_ycbcr_texture
#define GL_NV_blend_square
#define GL_NV_copy_depth_to_color
#define GL_NV_depth_clamp
#define GL_NV_evaluators
#define GL_NV_fence
#define GL_NV_float_buffer
#define GL_NV_fog_distance
#define GL_NV_fragment_program
#define GL_NV_fragment_program2
#define GL_NV_fragment_program_option
#define GL_NV_half_float
#define GL_NV_light_max_exponent
#define GL_NV_multisample_filter_hint
#define GL_NV_occlusion_query
#define GL_NV_packed_depth_stencil
#define GL_NV_pixel_data_range
#define GL_NV_point_sprite
#define GL_NV_primitive_restart
#define GL_NV_register_combiners
#define GL_NV_register_combiners2
#define GL_NV_texgen_emboss
#define GL_NV_texgen_reflection
#define GL_NV_texture_compression_vtc
#define GL_NV_texture_env_combine4
#define GL_NV_texture_expand_normal
#define GL_NV_texture_rectangle
#define GL_NV_texture_shader
#define GL_NV_texture_shader2
#define GL_NV_texture_shader3
#define GL_NV_vertex_array_range
#define GL_NV_vertex_array_range2
#define GL_NV_vertex_program
#define GL_NV_vertex_program1_1
#define GL_NV_vertex_program2
#define GL_NV_vertex_program2_option
#define GL_NV_vertex_program3
#define GL_OML_interlace
#define GL_OML_resample
#define GL_OML_subsample
#define GL_PGI_misc_hints
#define GL_PGI_vertex_hints
#define GL_REND_screen_coordinates
#define GL_S3_s3tc
#define GL_SGIS_color_range
#define GL_SGIS_detail_texture
#define GL_SGIS_fog_function
#define GL_SGIS_generate_mipmap
#define GL_SGIS_multisample
#define GL_SGIS_pixel_texture
#define GL_SGIS_sharpen_texture
#define GL_SGIS_texture4D
#define GL_SGIS_texture_border_clamp
#define GL_SGIS_texture_edge_clamp
#define GL_SGIS_texture_filter4
#define GL_SGIS_texture_lod
#define GL_SGIS_texture_select
#define GL_SGIX_async
#define GL_SGIX_async_histogram
#define GL_SGIX_async_pixel
#define GL_SGIX_blend_alpha_minmax
#define GL_SGIX_clipmap
#define GL_SGIX_depth_texture
#define GL_SGIX_flush_raster
#define GL_SGIX_fog_offset
#define GL_SGIX_fog_texture
#define GL_SGIX_fragment_specular_lighting
#define GL_SGIX_framezoom
#define GL_SGIX_interlace
#define GL_SGIX_ir_instrument1
#define GL_SGIX_list_priority
#define GL_SGIX_pixel_texture
#define GL_SGIX_pixel_texture_bits
#define GL_SGIX_reference_plane
#define GL_SGIX_resample
#define GL_SGIX_shadow
#define GL_SGIX_shadow_ambient
#define GL_SGIX_sprite
#define GL_SGIX_tag_sample_buffer
#define GL_SGIX_texture_add_env
#define GL_SGIX_texture_coordinate_clamp
#define GL_SGIX_texture_lod_bias
#define GL_SGIX_texture_multi_buffer
#define GL_SGIX_texture_range
#define GL_SGIX_texture_scale_bias
#define GL_SGIX_vertex_preclip
#define GL_SGIX_vertex_preclip_hint
#define GL_SGIX_ycrcb
#define GL_SGI_color_matrix
#define GL_SGI_color_table
#define GL_SGI_texture_color_table
#define GL_SUNX_constant_data
#define GL_SUN_convolution_border_modes
#define GL_SUN_global_alpha
#define GL_SUN_mesh_array
#define GL_SUN_slice_accum
#define GL_SUN_triangle_list
#define GL_SUN_vertex
#define GL_WIN_phong_shading
#define GL_WIN_specular_fog
#define GL_WIN_swap_hint
#define GLU_EXT_nurbs_tessellator
#define GLU_EXT_object_space_tess
#define GLU_SGI_filter4_parameters
#define GLX_VERSION_1_1
#define GLX_VERSION_1_2
#define GLX_VERSION_1_3
#define GLX_VERSION_1_4
#define GLX_3DFX_multisample
#define GLX_ARB_fbconfig_float
#define GLX_ARB_get_proc_address
#define GLX_ARB_multisample
#define GLX_ATI_pixel_format_float
#define GLX_ATI_render_texture
#define GLX_EXT_import_context
#define GLX_EXT_scene_marker
#define GLX_EXT_visual_info
#define GLX_EXT_visual_rating
#define GLX_MESA_agp_offset
#define GLX_MESA_copy_sub_buffer
#define GLX_MESA_pixmap_colormap
#define GLX_MESA_release_buffers
#define GLX_MESA_set_3dfx_mode
#define GLX_NV_float_buffer
#define GLX_NV_vertex_array_range
#define GLX_OML_swap_method
#define GLX_OML_sync_control
#define GLX_SGIS_blended_overlay
#define GLX_SGIS_color_range
#define GLX_SGIS_multisample
#define GLX_SGIS_shared_multisample
#define GLX_SGIX_fbconfig
#define GLX_SGIX_pbuffer
#define GLX_SGIX_swap_barrier
#define GLX_SGIX_swap_group
#define GLX_SGIX_video_resize
#define GLX_SGIX_visual_select_group
#define GLX_SGI_cushion
#define GLX_SGI_make_current_read
#define GLX_SGI_swap_control
#define GLX_SGI_video_sync
#define GLX_SUN_get_transparent_index
#define GLX_SUN_video_resize
#define WGL_3DFX_multisample
#define WGL_ARB_buffer_region
#define WGL_ARB_extensions_string
#define WGL_ARB_make_current_read
#define WGL_ARB_multisample
#define WGL_ARB_pbuffer
#define WGL_ARB_pixel_format
#define WGL_ARB_pixel_format_float
#define WGL_ARB_render_texture
#define WGL_ATI_pixel_format_float
#define WGL_ATI_render_texture_rectangle
#define WGL_EXT_depth_float
#define WGL_EXT_display_color_table
#define WGL_EXT_extensions_string
#define WGL_EXT_make_current_read
#define WGL_EXT_multisample
#define WGL_EXT_pbuffer
#define WGL_EXT_pixel_format
#define WGL_EXT_swap_control
#define WGL_I3D_digital_video_control
#define WGL_I3D_gamma
#define WGL_I3D_genlock
#define WGL_I3D_image_buffer
#define WGL_I3D_swap_frame_lock
#define WGL_I3D_swap_frame_usage
#define WGL_NV_float_buffer
#define WGL_NV_render_depth_texture
#define WGL_NV_render_texture_rectangle
#define WGL_NV_vertex_array_range
#define WGL_OML_sync_control

View file

@ -0,0 +1,110 @@
//-----------------------------------------------------------------------------
// Copyright (c) 2012 GarageGames, LLC
//
// Permission is hereby granted, free of charge, to any person obtaining a copy
// of this software and associated documentation files (the "Software"), to
// deal in the Software without restriction, including without limitation the
// rights to use, copy, modify, merge, publish, distribute, sublicense, and/or
// sell copies of the Software, and to permit persons to whom the Software is
// furnished to do so, subject to the following conditions:
//
// The above copyright notice and this permission notice shall be included in
// all copies or substantial portions of the Software.
//
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
// FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS
// IN THE SOFTWARE.
//-----------------------------------------------------------------------------
/*
** The contents of this file are subject to the GLX Public License Version 1.0
** (the "License"). You may not use this file except in compliance with the
** License. You may obtain a copy of the License at Silicon Graphics, Inc.,
** attn: Legal Services, 2011 N. Shoreline Blvd., Mountain View, CA 94043
** or at http://www.sgi.com/software/opensource/glx/license.html.
**
** Software distributed under the License is distributed on an "AS IS"
** basis. ALL WARRANTIES ARE DISCLAIMED, INCLUDING, WITHOUT LIMITATION, ANY
** IMPLIED WARRANTIES OF MERCHANTABILITY, OF FITNESS FOR A PARTICULAR
** PURPOSE OR OF NON- INFRINGEMENT. See the License for the specific
** language governing rights and limitations under the License.
**
** The Original Software is GLX version 1.2 source code, released February,
** 1999. The developer of the Original Software is Silicon Graphics, Inc.
** Those portions of the Subject Software created by Silicon Graphics, Inc.
** are Copyright (c) 1991-9 Silicon Graphics, Inc. All Rights Reserved.
*/
#ifndef GFX_GLX_H
#define GFX_GLX_H
#ifndef GFX_GGL_H
#include "../ggl.h"
#endif
#include "platform/tmm_off.h"
// AGL includes the standard gl defs, which we already provide in ggl.h
// Defining __gl_h_ here prevents osx's gl defs from being included.
#define __gl_h_
#include <Agl/agl.h>
#include "platform/tmm_on.h"
namespace GL
{
//-----------------------------------------------------------------------------
#ifndef DOXYGEN
#define GLX_VERSION_1_0 1
#define GLX_USE_GL 1
#define GLX_BUFFER_SIZE 2
#define GLX_LEVEL 3
#define GLX_RGBA 4
#define GLX_DOUBLEBUFFER 5
#define GLX_STEREO 6
#define GLX_AUX_BUFFERS 7
#define GLX_RED_SIZE 8
#define GLX_GREEN_SIZE 9
#define GLX_BLUE_SIZE 10
#define GLX_ALPHA_SIZE 11
#define GLX_DEPTH_SIZE 12
#define GLX_STENCIL_SIZE 13
#define GLX_ACCUM_RED_SIZE 14
#define GLX_ACCUM_GREEN_SIZE 15
#define GLX_ACCUM_BLUE_SIZE 16
#define GLX_ACCUM_ALPHA_SIZE 17
#define GLX_BAD_SCREEN 1
#define GLX_BAD_ATTRIBUTE 2
#define GLX_NO_EXTENSION 3
#define GLX_BAD_VISUAL 4
#define GLX_BAD_CONTEXT 5
#define GLX_BAD_VALUE 6
#define GLX_BAD_ENUM 7
//-----------------------------------------------------------------------------
// Extensions use indirection in order to support multiple contexts
struct AGLExtensionPtrs: public GLExtensionPtrs {
};
struct AGLExtensionFlags: public GLExtensionFlags {
};
#endif // Doxygen
//-----------------------------------------------------------------------------
#undef XGL_FUNCPTR
#define XGL_FUNCPTR(name) (((AGLExtensionPtrs*)GL::_GGLptr)->_##name)
} // Namespace
#endif

View file

@ -0,0 +1,195 @@
//-----------------------------------------------------------------------------
// Copyright (c) 2012 GarageGames, LLC
//
// Permission is hereby granted, free of charge, to any person obtaining a copy
// of this software and associated documentation files (the "Software"), to
// deal in the Software without restriction, including without limitation the
// rights to use, copy, modify, merge, publish, distribute, sublicense, and/or
// sell copies of the Software, and to permit persons to whom the Software is
// furnished to do so, subject to the following conditions:
//
// The above copyright notice and this permission notice shall be included in
// all copies or substantial portions of the Software.
//
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
// FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS
// IN THE SOFTWARE.
//-----------------------------------------------------------------------------
#include <err.h>
#include "agl.h"
#include "platform/platform.h"
//-----------------------------------------------------------------------------
// Instantiation of function pointers.
#define GL_GROUP_BEGIN(name)
#define GL_FUNCTION(name, type, args) type (XGL_DLL *name) args;
#define GL_GROUP_END()
#include "../generated/glcfn.h"
#undef GL_GROUP_BEGIN
#undef GL_FUNCTION
#undef GL_GROUP_END
#define EXECUTE_ONLY_ONCE() \
static bool _doneOnce = false; \
if(_doneOnce) return; \
_doneOnce = true;
namespace GL
{
//-----------------------------------------------------------------------------
// The OpenGL Bundle is shared by all the devices.
static CFBundleRef _openglFrameworkRef;
// Unlike WGL, AGL does not require a set of function pointers per
// context pixel format. All functions in the DLL are bound in a single
// table and shared by all contexts.
static AGLExtensionPtrs _LibraryFunctions;
static AGLExtensionFlags _ExtensionFlags;
bool hasExtension(const char *name,const char* extensions);
bool hasVersion(const char *name,const char* prefix,int major,int minor);
//-----------------------------------------------------------------------------
void* MacGetProcAddress(CFBundleRef bundle,char* name)
{
CFStringRef cfName = CFStringCreateWithCString(kCFAllocatorDefault, name, CFStringGetSystemEncoding());
void* ret = CFBundleGetFunctionPointerForName(bundle, cfName);
CFRelease(cfName);
return ret;
}
//-----------------------------------------------------------------------------
bool bindFunction(CFBundleRef bundle,void *&fnAddress, const char *name)
{
CFStringRef cfName = CFStringCreateWithCString(0,name,CFStringGetSystemEncoding());
fnAddress = CFBundleGetFunctionPointerForName(bundle, cfName);
CFRelease(cfName);
return fnAddress != 0;
}
//-----------------------------------------------------------------------------
bool gglBindCoreFunctions(CFBundleRef bundle,AGLExtensionPtrs* glp)
{
bool bound = true;
// Bind static functions which are quarenteed to be part of the
// OpenGL library. In this case, OpenGL 1.0 and GLX 1.0 functions
#define GL_GROUP_BEGIN(name)
#define GL_GROUP_END()
#define GL_FUNCTION(fn_name, fn_return, fn_args) \
bound &= bindFunction(bundle,*(void**)&fn_name, #fn_name);
#include "../generated/glcfn.h"
#undef GL_FUNCTION
#undef GL_GROUP_BEGIN
#undef GL_GROUP_END
// Try and bind all known extension functions. We'll check later to
// see which ones are actually valid for a context.
#define GL_GROUP_BEGIN(name)
#define GL_FUNCTION(fn_name, fn_return, fn_args) \
bindFunction(bundle,*(void**)&glp->_##fn_name, #fn_name);
#define GL_GROUP_END()
#include "../generated/glefn.h"
#undef GL_FUNCTION
#undef GL_GROUP_BEGIN
#undef GL_GROUP_END
return bound;
}
//-----------------------------------------------------------------------------
bool gglBindExtensions(GLExtensionFlags* gl)
{
dMemset(gl,0,sizeof(GLExtensionFlags));
// Get GL version and extensions
const char* glExtensions = (const char*)glGetString(GL_EXTENSIONS);
const char* glVersion = (const char*) glGetString(GL_VERSION);
if (!glExtensions || !glVersion)
return false;
// Parse the GL version string "major.minor"
const char *itr = glVersion;
int glMajor = atoi(itr);
while (isdigit(*itr))
*itr++;
int glMinor = atoi(++itr);
// Check which extensions are available on the active context.
// GL and GLX versions ubove 1.0 are also tested here.
#define GL_GROUP_BEGIN(name) \
gl->has_##name = hasVersion(#name,"GL_VERSION",glMajor,glMinor) || \
hasExtension(#name,glExtensions);
#define GL_FUNCTION(fn_name, fn_return, fn_args)
#define GL_GROUP_END()
#include "../generated/glefn.h"
#undef GL_FUNCTION
#undef GL_GROUP_BEGIN
#undef GL_GROUP_END
gl->bound = true;
return true;
}
#define _hasGLXExtension(display,name) (display->glx.has_##name)
//-----------------------------------------------------------------------------
void gglPerformBinds()
{
// Some of the following code is copied from the Apple Opengl Documentation.
// Load and bind OpenGL bundle functions
if (!_openglFrameworkRef) {
// Load OpenGL.framework
_openglFrameworkRef = CFBundleGetBundleWithIdentifier(CFSTR("com.apple.opengl"));
if (!_openglFrameworkRef) {
warn("Could not create OpenGL Framework bundle");
return;
}
if (!CFBundleLoadExecutable(_openglFrameworkRef)) {
warn("Could not load MachO executable");
return;
}
// Bind our functions.
if (!gglBindCoreFunctions(_openglFrameworkRef, &_LibraryFunctions)) {
warn("GLDevice: Failed to bind all core functions");
return;
}
// Save the pointer to the set of opengl functions
_GGLptr = &_LibraryFunctions;
}
}
//-----------------------------------------------------------------------------
void gglPerformExtensionBinds(void *context)
{
// we don't care about the passed context when binding the opengl functions,
// we only care about the current opengl context.
if( !_openglFrameworkRef || !_GGLptr )
{
gglPerformBinds();
}
gglBindExtensions( &_ExtensionFlags );
_GGLflag = &_ExtensionFlags;
}
} // Namespace

View file

@ -0,0 +1,102 @@
//-----------------------------------------------------------------------------
// Copyright (c) 2012 GarageGames, LLC
//
// Permission is hereby granted, free of charge, to any person obtaining a copy
// of this software and associated documentation files (the "Software"), to
// deal in the Software without restriction, including without limitation the
// rights to use, copy, modify, merge, publish, distribute, sublicense, and/or
// sell copies of the Software, and to permit persons to whom the Software is
// furnished to do so, subject to the following conditions:
//
// The above copyright notice and this permission notice shall be included in
// all copies or substantial portions of the Software.
//
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
// FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS
// IN THE SOFTWARE.
//-----------------------------------------------------------------------------
#ifndef GFX_WGL_H
#define GFX_WGL_H
#ifndef GFX_GGL_H
#include "../ggl.h"
#endif
#ifndef _PLATFORMDLIBRARY_H
#include "platform/platformDlibrary.h"
#endif
#ifndef _WIN32_WINNT
#define _WIN32_WINNT 0x0500
#endif
#include <windows.h>
namespace GL
{
//-----------------------------------------------------------------------------
// Include WGL 1.0 definitions
#ifndef DOXYGEN
#include "../generated/wgle.h"
//-----------------------------------------------------------------------------
// All core functionality is implemented as function pointers.
#define GL_GROUP_BEGIN(name)
#define GL_FUNCTION(name, type, args) extern type (XGL_DLL *name) args;
#define GL_GROUP_END()
#include "../generated/wglfn.h"
#undef GL_GROUP_BEGIN
#undef GL_FUNCTION
#undef GL_GROUP_END
//-----------------------------------------------------------------------------
// Extensions use indirection in order to support multiple contexts
struct WGLExtensionPtrs: public GLExtensionPtrs {
// Include all OpenGL extensions for all platform
#define GL_GROUP_BEGIN(name)
#define GL_FUNCTION(name, type, args) type (XGL_DLL *_##name) args;
#define GL_GROUP_END()
#include "../generated/wglefn.h"
#undef GL_GROUP_BEGIN
#undef GL_FUNCTION
#undef GL_GROUP_END
};
struct WGLExtensionFlags: public GLExtensionFlags {
// Define extension "has" variables
#define GL_GROUP_BEGIN(name) bool has_##name;
#define GL_FUNCTION(name, type, args)
#define GL_GROUP_END()
#include "../generated/wglefn.h"
#undef GL_GROUP_BEGIN
#undef GL_FUNCTION
#undef GL_GROUP_END
};
#endif // Doyxygen
//-----------------------------------------------------------------------------
bool gglBindExtensions(DLibrary*,WGLExtensionPtrs*,WGLExtensionFlags*,HDC);
#undef XGL_FUNCPTR
#define XGL_FUNCPTR(name) (((GL::WGLExtensionPtrs*)GL::_GGLptr)->_##name)
#undef gglHasExtension
#define gglHasExtension(name) (((GL::WGLExtensionFlags*)GL::_GGLflag)->has_##name)
} // Namespace
#endif

View file

@ -0,0 +1,173 @@
//-----------------------------------------------------------------------------
// Copyright (c) 2012 GarageGames, LLC
//
// Permission is hereby granted, free of charge, to any person obtaining a copy
// of this software and associated documentation files (the "Software"), to
// deal in the Software without restriction, including without limitation the
// rights to use, copy, modify, merge, publish, distribute, sublicense, and/or
// sell copies of the Software, and to permit persons to whom the Software is
// furnished to do so, subject to the following conditions:
//
// The above copyright notice and this permission notice shall be included in
// all copies or substantial portions of the Software.
//
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
// FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS
// IN THE SOFTWARE.
//-----------------------------------------------------------------------------
#include "wgl.h"
#include "core/strings/stringFunctions.h"
#include "console/console.h"
//-----------------------------------------------------------------------------
// Instantiation of GL function pointers in global namespace.
#define GL_GROUP_BEGIN(name)
#define GL_FUNCTION(name, type, args) type (__stdcall *name) args;
#define GL_GROUP_END()
#include "../generated/glcfn.h"
#undef GL_GROUP_BEGIN
#undef GL_FUNCTION
#undef GL_GROUP_END
namespace GL
{
bool bindFunction(DLibrary* dll,void *&fnAddress, const char *name);
bool hasExtension(const char *name,const char* extensions);
bool hasVersion(const char *name,const char* prefix,int major,int minor);
//-----------------------------------------------------------------------------
// Instantiation of WGL function pointers. These are in the GL namespace to
// avoid problems with definitions in windows.h
#define GL_GROUP_BEGIN(name)
#define GL_FUNCTION(name, type, args) type (__stdcall *name) args;
#define GL_GROUP_END()
#include "../generated/wglfn.h"
#undef GL_GROUP_BEGIN
#undef GL_FUNCTION
#undef GL_GROUP_END
//-----------------------------------------------------------------------------
static bool bindExtension(void *&fnAddress, const char *name)
{
fnAddress = (void*)wglGetProcAddress(name);
if (!fnAddress)
Con::printf("GLExtensions: Extension bind failed for %s",name);
return fnAddress != 0;
}
//-----------------------------------------------------------------------------
bool gglBindCoreFunctions(DLibrary* dll)
{
bool bound = true;
// Bind static functions which are quarenteed to be part of the
// OpenGL library. In this case, OpenGL 1.0 and WGL functions
#define GL_GROUP_BEGIN(name)
#define GL_GROUP_END()
#define GL_FUNCTION(fn_name, fn_return, fn_args) \
bound &= bindFunction(dll, *(void**)&fn_name, #fn_name);
#include "../generated/glcfn.h"
#include "../generated/wglfn.h"
#undef GL_FUNCTION
#undef GL_GROUP_BEGIN
#undef GL_GROUP_END
return bound;
}
bool gglBindExtensions(DLibrary* dll,WGLExtensionPtrs* glp,WGLExtensionFlags* glf,HDC hDC)
{
dMemset(glp,0,sizeof(WGLExtensionPtrs));
dMemset(glf,0,sizeof(WGLExtensionFlags));
// Get WGL extensions, there is no version
const char* wgl = 0;
if (bindExtension(*(void**)&glp->_wglGetExtensionsStringARB,"wglGetExtensionsStringARB"))
wgl = glp->_wglGetExtensionsStringARB(hDC);
else
if (bindExtension(*(void**)&glp->_wglGetExtensionsStringEXT,"wglGetExtensionsStringEXT"))
wgl = glp->_wglGetExtensionsStringEXT();
// Get OpenGL version and extensions
const char* glExtensions = (const char*)glGetString(GL_EXTENSIONS);
const char* glVersion = (const char*) glGetString(GL_VERSION);
if (!glExtensions || !glVersion)
return false;
// Parse the version string major.minor
const char *itr = glVersion;
int glMajor = dAtoi(itr);
while (dIsdigit(*itr))
*itr++;
int glMinor = dAtoi(++itr);
// Test for, and bind, all known extensions. GL and GLX versions ubove 1.0
// are also treated as extensions and bound here.
#define GL_GROUP_BEGIN(name) \
if (hasVersion(#name,"GL_VERSION",glMajor,glMinor) || \
hasExtension(#name,glExtensions) || \
hasExtension(#name,wgl)) \
{ \
glf->has_##name = true;
#define GL_FUNCTION(fn_name, fn_return, fn_args) \
bindExtension(*(void**)&glp->_##fn_name, #fn_name);
#define GL_GROUP_END() \
}
#include "../generated/glefn.h"
#include "../generated/wglefn.h"
#undef GL_FUNCTION
#undef GL_GROUP_BEGIN
#undef GL_GROUP_END
glf->bound = glp->bound = true;
return true;
}
static DLibraryRef _hGL = NULL;
void gglPerformBinds()
{
if(!_hGL)
{
_hGL = OsLoadLibrary("opengl32.dll");
gglBindCoreFunctions(_hGL);
}
}
void gglPerformExtensionBinds(void *context)
{
if(!_hGL)
{
_hGL = OsLoadLibrary("opengl32.dll");
}
if(!_GGLptr)
{
static WGLExtensionPtrs ptrs;
static WGLExtensionFlags flags;
_GGLptr = &ptrs;
_GGLflag = &flags;
}
gglBindExtensions(_hGL, (WGLExtensionPtrs*)_GGLptr, (WGLExtensionFlags*)_GGLflag, (HDC)context);
}
} // Namespace

View file

@ -0,0 +1,413 @@
//-----------------------------------------------------------------------------
// Copyright (c) 2012 GarageGames, LLC
//
// Permission is hereby granted, free of charge, to any person obtaining a copy
// of this software and associated documentation files (the "Software"), to
// deal in the Software without restriction, including without limitation the
// rights to use, copy, modify, merge, publish, distribute, sublicense, and/or
// sell copies of the Software, and to permit persons to whom the Software is
// furnished to do so, subject to the following conditions:
//
// The above copyright notice and this permission notice shall be included in
// all copies or substantial portions of the Software.
//
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
// FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS
// IN THE SOFTWARE.
//-----------------------------------------------------------------------------
#include "os/osDlibrary.h"
#include "os/osLog.h"
#include "util/utilArray.h"
#include "glx.h"
namespace GL
{
using namespace Torque;
using namespace GL;
extern bool gglBindCoreFunctions(DLibrary* dll,GLXExtensionPtrs*);
void gglBindGLX(::Display* display,int screen,GLXExtensionFlags* glx);
bool gglBindExtensions(GLExtensionFlags* gl);
struct GGLContext;
//-----------------------------------------------------------------------------
// The OpenGL DLL is shared by all the devices.
static DLibraryRef _hGL;
// Unlike WGL, GLX does not require a set of function pointers per
// context pixel format. All functions in the DLL are bound in a single
// table and shared by all contexts.
static GLXExtensionPtrs _LibraryFunctions;
//-----------------------------------------------------------------------------
struct GGLDisplay: public _GLDisplay
{
::Display* display;
int screen;
GLXExtensionFlags glx; // GLX extension flags
Array<GGLContext*> contextList;
};
#define _hasGLXExtension(display,name) (display->glx.has_##name)
GLDisplay gglCreateDisplay(::Display* display,int screen)
{
// Load and bind DLL functions
if (!_hGL) {
static LogCategory log("/Gfx/Device/GL");
_hGL = LoadLibrary("libGL.so");
if (!_hGL) {
log.print("GLDevice: OpenGL dll failed to load");
return false;
}
if (!gglBindCoreFunctions(_hGL.ptr(),&_LibraryFunctions)) {
log.print("GLDevice: Failed to bind all core functions");
return false;
}
_GGLptr = &_LibraryFunctions;
log.print("OpenGL library loaded");
}
//
GGLDisplay* dp = new GGLDisplay;
dp->display = display;
dp->screen = screen;
gglBindGLX(display,screen,&dp->glx);
return dp;
}
void gglDeleteDisplay(GLDisplay dp)
{
GGLDisplay* display = (GGLDisplay*)dp;
Assert(!display->contextList.size(),"gglDeleteDisplay: Not all context destroyed");
delete display;
}
//-----------------------------------------------------------------------------
struct GGLFormat: public _GLFormat {
GLFormatInfo mode;
U32 pformat;
};
static bool _getFBConfig(GGLDisplay* display,U32 pformat,GLXFBConfig& config)
{
// Get config info from format ID
int attributes[] = { GLX_FBCONFIG_ID, pformat, None };
int count = 0;
GLXFBConfig* configList = glXChooseFBConfig(display->display,
display->screen,attributes,&count);
if (!count)
return false;
config = *configList;
XFree(configList);
return true;
}
GLFormat gglSelectFormat(GLDisplay dp,GLFormatInfo& mode)
{
GGLDisplay* display = (GGLDisplay*)dp;
U32 pformat;
if (!_hasGLXExtension(display,GLX_VERSION_1_3)) {
// Find GL compatible X visual using 1.2 interface.
// 1.2 or earlier does not include pbuffer support.
if (mode.target != GLFormatInfo::Window)
return 0;
int attributes[] = {
GLX_RGBA,
GLX_RED_SIZE, mode.red,
GLX_BLUE_SIZE, mode.blue,
GLX_GREEN_SIZE, mode.green,
GLX_DEPTH_SIZE, mode.z,
GLX_ALPHA_SIZE, mode.alpha,
GLX_STENCIL_SIZE, mode.stencil,
GLX_DOUBLEBUFFER, true,
GLX_DOUBLEBUFFER,
None
};
XVisualInfo* visual = glXChooseVisual(display->display, display->screen, attributes);
if (!visual) {
static LogCategory log("/Gfx/Device/GL");
log.print("GGLContext: Could not get an accelerated visual");
return 0;
}
pformat = visual->visualid;
XFree(visual);
}
else {
// Find GL compatible X visual using 1.3 interface.
int attributes[] = {
GLX_DRAWABLE_TYPE, (mode.target == GLFormatInfo::Buffer)?
GLX_PBUFFER_BIT: GLX_WINDOW_BIT,
GLX_RENDER_TYPE, GLX_RGBA_BIT,
GLX_RED_SIZE, mode.red,
GLX_BLUE_SIZE, mode.blue,
GLX_GREEN_SIZE, mode.green,
GLX_DEPTH_SIZE, mode.z,
GLX_ALPHA_SIZE, mode.alpha,
GLX_STENCIL_SIZE, mode.stencil,
GLX_DOUBLEBUFFER, true,
None
};
int count = 0;
GLXFBConfig* configList = glXChooseFBConfig(display->display,
display->screen,attributes,&count);
if (!count)
return 0;
// Return the config ID
int xid;
glXGetFBConfigAttrib(display->display,configList[0],GLX_FBCONFIG_ID,&xid);
XFree(configList);
pformat = xid;
}
if (pformat) {
GGLFormat* format = new GGLFormat;
format->pformat = pformat;
format->mode = mode;
return format;
}
return 0;
}
bool gglFormatInfo(GLDisplay display,GLFormat pformat,GLFormatInfo& mode)
{
return 0;
}
bool gglAreCompatible(GLFormat,GLFormat)
{
return false;
}
void gglDeleteFormat(GLFormat fp)
{
GGLFormat* format = (GGLFormat*)fp;
delete format;
}
XVisualInfo* gglGetFormatVisual(GLDisplay dp,GLFormat fp)
{
GGLDisplay* display = (GGLDisplay*)dp;
GGLFormat* format = (GGLFormat*)fp;
if (!_hasGLXExtension(display,GLX_VERSION_1_3)) {
// Format is a visual id
int count;
XVisualInfo match;
match.visualid = format->pformat;
return XGetVisualInfo(display->display,VisualIDMask,&match,&count);
}
else {
// Format is an FBConfig id
GLXFBConfig config;
if (!_getFBConfig(display,format->pformat,config))
return 0;
return glXGetVisualFromFBConfig(display->display,config);
}
}
//-----------------------------------------------------------------------------
struct GGLSurface: public _GLSurface {
enum Type {
Window, PBuffer,
} type;
GGLDisplay* display;
GLXDrawable drawable; // Used with GLX 1.3 interface
::Window window; // Used with GLX 1.2 interface
};
GLSurface gglCreateSurface(GLDisplay dp,::Window hwin,GLFormat fp)
{
GGLDisplay* display = (GGLDisplay*)dp;
GGLFormat* format = (GGLFormat*)fp;
GGLSurface* surface = 0;
if (!_hasGLXExtension(display,GLX_VERSION_1_3)) {
// Return our own GGL surface rep.
surface = new GGLSurface;
surface->type = GGLSurface::Window;
surface->display = display;
surface->drawable = 0;
surface->window = hwin;
}
else {
// Get config info from format ID
GLXFBConfig config;
if (!_getFBConfig(display,format->pformat,config))
return 0;
// Create GLX window
GLXWindow window = glXCreateWindow(display->display,config,hwin,0);
if (!window) {
GLenum error = glGetError();
static LogCategory log("/Gfx/Device/GL");
log.print(format("Create window error: %d",error));
return 0;
}
// Return our own GGL surface rep.
surface = new GGLSurface;
surface->type = GGLSurface::Window;
surface->display = display;
surface->drawable = window;
surface->window = 0;
}
return surface;
}
bool gglGetSurfaceSize(GLSurface sp,Vector2I& size)
{
GGLSurface* surface = (GGLSurface*)sp;
if (surface->type != GGLSurface::Window)
return false;
if (!_hasGLXExtension(surface->display,GLX_VERSION_1_3)) {
size.x = 300; size.y = 300;
}
else {
glXQueryDrawable(surface->display->display,surface->drawable,
GLX_WIDTH,(U32*)&size.x);
glXQueryDrawable(surface->display->display,surface->drawable,
GLX_HEIGHT,(U32*)&size.y);
}
return true;
}
void gglDeleteSurface(GLSurface sp)
{
GGLSurface* surface = (GGLSurface*)sp;
if (surface->type = GGLSurface::Window) {
glXDestroyWindow(surface->display->display,surface->drawable);
delete surface;
}
}
//-----------------------------------------------------------------------------
struct GGLContext: public _GLContext
{
GGLDisplay* display;
GLXContext context;
GLExtensionFlags glf; // GL has extension flags
};
GLContext gglCreateContext(GLDisplay dp,GLFormat fp)
{
GGLDisplay* display = (GGLDisplay*)dp;
GGLFormat* format = (GGLFormat*)fp;
GGLContext* context = 0;
GLXContext ctx,share = display->contextList.size()?
display->contextList[0]->context: 0;
if (!_hasGLXExtension(display,GLX_VERSION_1_3)) {
// Get visual from format id.
int count;
XVisualInfo match;
match.visualid = format->pformat;
XVisualInfo* visual = XGetVisualInfo(display->display,VisualIDMask,&match,&count);
ctx = glXCreateContext(display->display,visual,share,true);
XFree(visual);
}
else {
// Get FBConfig from format id
GLXFBConfig config;
if (!_getFBConfig(display,format->pformat,config))
return 0;
// Need to share contexts...
ctx = glXCreateNewContext(display->display,config,
GLX_RGBA_TYPE,share,true);
}
if (ctx) {
context = new GGLContext;
context->context = ctx;
context->display = display;
display->contextList.pushBack(context);
return context;
}
return 0;
}
void gglDeleteContext(GLContext ctx)
{
GGLContext* context = (GGLContext*)ctx;
glXDestroyContext(context->display->display,context->context);
erase(context->display->contextList,context);
delete context;
}
bool gglMakeCurrent(GLSurface sp,GLContext ctx)
{
GGLSurface* surface = (GGLSurface*)sp;
GGLContext* context = (GGLContext*)ctx;
if (!_hasGLXExtension(surface->display,GLX_VERSION_1_3)) {
if (!glXMakeCurrent(surface->display->display,
surface->window,context->context))
return false;
}
else
if (!glXMakeContextCurrent(surface->display->display,
surface->drawable,surface->drawable,context->context))
return false;
// The first time a context is made current we need to
// check which extensions are valid.
if (!context->glf.bound)
gglBindExtensions(&context->glf);
_GGLflag = &context->glf;
return true;
}
void gglSwapBuffers(GLSurface sp)
{
GGLSurface* surface = (GGLSurface*)sp;
if (!_hasGLXExtension(surface->display,GLX_VERSION_1_3))
glXSwapBuffers(surface->display->display,surface->window);
else
glXSwapBuffers(surface->display->display,surface->drawable);
}
//-----------------------------------------------------------------------------
GLSurface gglCreatePBufferSurface(GLDisplay display,U32 width,U32 height,bool cubeMap,GLFormat pformat)
{
return 0;
}
bool gglBindPBufferSurface(GLSurface sp,U32 target)
{
return 0;
}
bool gglReleasePBufferSurface(GLSurface sp,U32 target)
{
return 0;
}
bool gglSetPbufferTarget(GLSurface sp,U32 mip,U32 face)
{
return 0;
}
} // Namespace

View file

@ -0,0 +1,141 @@
//-----------------------------------------------------------------------------
// Copyright (c) 2012 GarageGames, LLC
//
// Permission is hereby granted, free of charge, to any person obtaining a copy
// of this software and associated documentation files (the "Software"), to
// deal in the Software without restriction, including without limitation the
// rights to use, copy, modify, merge, publish, distribute, sublicense, and/or
// sell copies of the Software, and to permit persons to whom the Software is
// furnished to do so, subject to the following conditions:
//
// The above copyright notice and this permission notice shall be included in
// all copies or substantial portions of the Software.
//
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
// FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS
// IN THE SOFTWARE.
//-----------------------------------------------------------------------------
/*
** The contents of this file are subject to the GLX Public License Version 1.0
** (the "License"). You may not use this file except in compliance with the
** License. You may obtain a copy of the License at Silicon Graphics, Inc.,
** attn: Legal Services, 2011 N. Shoreline Blvd., Mountain View, CA 94043
** or at http://www.sgi.com/software/opensource/glx/license.html.
**
** Software distributed under the License is distributed on an "AS IS"
** basis. ALL WARRANTIES ARE DISCLAIMED, INCLUDING, WITHOUT LIMITATION, ANY
** IMPLIED WARRANTIES OF MERCHANTABILITY, OF FITNESS FOR A PARTICULAR
** PURPOSE OR OF NON- INFRINGEMENT. See the License for the specific
** language governing rights and limitations under the License.
**
** The Original Software is GLX version 1.2 source code, released February,
** 1999. The developer of the Original Software is Silicon Graphics, Inc.
** Those portions of the Subject Software created by Silicon Graphics, Inc.
** are Copyright (c) 1991-9 Silicon Graphics, Inc. All Rights Reserved.
*/
#ifndef GFX_GLX_H
#define GFX_GLX_H
#ifndef GFX_GGL_H
#include "../ggl.h"
#endif
#include <X11/Xlib.h>
#include <X11/Xutil.h>
namespace GL
{
//-----------------------------------------------------------------------------
#ifndef DOXYGEN
#define GLX_VERSION_1_0 1
#define GLX_USE_GL 1
#define GLX_BUFFER_SIZE 2
#define GLX_LEVEL 3
#define GLX_RGBA 4
#define GLX_DOUBLEBUFFER 5
#define GLX_STEREO 6
#define GLX_AUX_BUFFERS 7
#define GLX_RED_SIZE 8
#define GLX_GREEN_SIZE 9
#define GLX_BLUE_SIZE 10
#define GLX_ALPHA_SIZE 11
#define GLX_DEPTH_SIZE 12
#define GLX_STENCIL_SIZE 13
#define GLX_ACCUM_RED_SIZE 14
#define GLX_ACCUM_GREEN_SIZE 15
#define GLX_ACCUM_BLUE_SIZE 16
#define GLX_ACCUM_ALPHA_SIZE 17
#define GLX_BAD_SCREEN 1
#define GLX_BAD_ATTRIBUTE 2
#define GLX_NO_EXTENSION 3
#define GLX_BAD_VISUAL 4
#define GLX_BAD_CONTEXT 5
#define GLX_BAD_VALUE 6
#define GLX_BAD_ENUM 7
typedef XID GLXDrawable;
typedef XID GLXPixmap;
typedef struct __GLXcontextRec *GLXContext;
#include "../generated/glxe.h"
//-----------------------------------------------------------------------------
// All core functionality is implemented as function pointers.
#define GL_GROUP_BEGIN(name)
#define GL_FUNCTION(name, type, args) extern type (XGL_DLL *name) args;
#define GL_GROUP_END()
#include "../generated/glxfn.h"
#undef GL_GROUP_BEGIN
#undef GL_FUNCTION
#undef GL_GROUP_END
//-----------------------------------------------------------------------------
// Extensions use indirection in order to support multiple contexts
struct GLXExtensionPtrs: public GLExtensionPtrs {
// Include all GLX extentions in global function table
#define GL_GROUP_BEGIN(name)
#define GL_FUNCTION(name, type, args) type (XGL_DLL *_##name) args;
#define GL_GROUP_END()
#include "../generated/glxefn.h"
#undef GL_GROUP_BEGIN
#undef GL_FUNCTION
#undef GL_GROUP_END
};
struct GLXExtensionFlags {
// Define extension "has" variables
#define GL_GROUP_BEGIN(name) bool has_##name;
#define GL_FUNCTION(name, type, args)
#define GL_GROUP_END()
#include "../generated/glxefn.h"
#undef GL_GROUP_BEGIN
#undef GL_FUNCTION
#undef GL_GROUP_END
};
#endif // Doxygen
//-----------------------------------------------------------------------------
GLDisplay gglCreateDisplay(::Display*,int screen);
GLSurface gglCreateSurface(GLDisplay,Window,GLFormat);
XVisualInfo* gglGetFormatVisual(GLDisplay dp,GLFormat format);
#undef XGL_FUNCPTR
#define XGL_FUNCPTR(name) (((GLXExtensionPtrs*)GL::_GGLptr)->_##name)
} // Namespace
#endif

View file

@ -0,0 +1,176 @@
//-----------------------------------------------------------------------------
// Copyright (c) 2012 GarageGames, LLC
//
// Permission is hereby granted, free of charge, to any person obtaining a copy
// of this software and associated documentation files (the "Software"), to
// deal in the Software without restriction, including without limitation the
// rights to use, copy, modify, merge, publish, distribute, sublicense, and/or
// sell copies of the Software, and to permit persons to whom the Software is
// furnished to do so, subject to the following conditions:
//
// The above copyright notice and this permission notice shall be included in
// all copies or substantial portions of the Software.
//
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
// FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS
// IN THE SOFTWARE.
//-----------------------------------------------------------------------------
#include "glx.h"
#include "util/utilAssert.h"
#include "util/utilStr.h"
#include "util/utilString.h"
#include "util/utilMemory.h"
#include "os/osLog.h"
#include "os/osDlibrary.h"
//-----------------------------------------------------------------------------
// Instantiation of GL function pointers in global namespace.
#define GL_GROUP_BEGIN(name)
#define GL_FUNCTION(name, type, args) type (XGL_DLL *name) args;
#define GL_GROUP_END()
#include "../generated/glcfn.h"
#undef GL_GROUP_BEGIN
#undef GL_FUNCTION
#undef GL_GROUP_END
namespace GL
{
using namespace Torque;
bool bindFunction(DLibrary* dll,void *&fnAddress, const char *name);
bool hasExtension(const char *name,const char* extensions);
bool hasVersion(const char *name,const char* prefix,int major,int minor);
//-----------------------------------------------------------------------------
// Instantiation of GLX function pointers.
#define GL_GROUP_BEGIN(name)
#define GL_FUNCTION(name, type, args) type (XGL_DLL *name) args;
#define GL_GROUP_END()
#include "../generated/glxfn.h"
#undef GL_GROUP_BEGIN
#undef GL_FUNCTION
#undef GL_GROUP_END
//-----------------------------------------------------------------------------
bool bindFunction(DLibrary* dll,GLFunction (*gproc)(const GLubyte*),
void *&fnAddress, const char *name)
{
// Use the getProcAddress if we have it.
fnAddress = gproc? (void*)(*gproc)((const GLubyte*)name): dll->bind(name);
return fnAddress != 0;
}
//-----------------------------------------------------------------------------
bool gglBindCoreFunctions(DLibrary* dll,GLXExtensionPtrs* glp)
{
bool bound = true;
// Bind static functions which are quarenteed to be part of the
// OpenGL library. In this case, OpenGL 1.0 and GLX 1.0 functions
#define GL_GROUP_BEGIN(name)
#define GL_GROUP_END()
#define GL_FUNCTION(fn_name, fn_return, fn_args) \
bound &= bindFunction(dll,*(void**)&fn_name, #fn_name);
#include "../generated/glcfn.h"
#include "../generated/glxfn.h"
#undef GL_FUNCTION
#undef GL_GROUP_BEGIN
#undef GL_GROUP_END
// Check for the getProcAddress first, otherwise we'll expect everything
// to be in the DLL.
memset(glp,0,sizeof(GLXExtensionPtrs));
glp->_glXGetProcAddressARB = (GLFunction (*)(const GLubyte*))dll->bind("glXGetProcAddressARB");
// Try and bind all known extension functions. We'll check later to
// see which ones are actually valid for a context.
#define GL_GROUP_BEGIN(name)
#define GL_FUNCTION(fn_name, fn_return, fn_args) \
bindFunction(dll,glp->_glXGetProcAddressARB,*(void**)&glp->_##fn_name, #fn_name);
#define GL_GROUP_END()
#include "../generated/glefn.h"
#include "../generated/glxefn.h"
#undef GL_FUNCTION
#undef GL_GROUP_BEGIN
#undef GL_GROUP_END
return bound;
}
//-----------------------------------------------------------------------------
void gglBindGLX(::Display* display,int screen,GLXExtensionFlags* glx)
{
// Check GLX version and glx extensions
int glxMajor,glxMinor;
glXQueryVersion(display,&glxMajor,&glxMinor);
const char* glxExtensions = glXQueryExtensionsString(display,screen);
static LogCategory log("/Gfx/Device/GL");
log.print(format("GLX Version: %d.%d",glxMajor,glxMinor));
Assert(glxMajor == 1 && glxMinor >= 1,"GLXBind: Need GLX version 1.1 or greater");
#define GL_GROUP_BEGIN(name) \
glx->has_##name = hasVersion(#name,"GLX_VERSION",glxMajor,glxMinor) || \
hasExtension(#name,glxExtensions);
#define GL_FUNCTION(fn_name, fn_return, fn_args)
#define GL_GROUP_END()
#include "../generated/glxefn.h"
#undef GL_FUNCTION
#undef GL_GROUP_BEGIN
#undef GL_GROUP_END
}
//-----------------------------------------------------------------------------
bool gglBindExtensions(GLExtensionFlags* gl)
{
memset(gl,0,sizeof(GLExtensionFlags));
// Get GL version and extensions
const char* glExtensions = (const char*)glGetString(GL_EXTENSIONS);
const char* glVersion = (const char*) glGetString(GL_VERSION);
if (!glExtensions || !glVersion)
return false;
// Parse the GL version string "major.minor"
const char *itr = glVersion;
int glMajor = atoi(itr);
while (isDigit(*itr))
*itr++;
int glMinor = atoi(++itr);
// Check which extensions are available on the active context.
// GL and GLX versions ubove 1.0 are also tested here.
#define GL_GROUP_BEGIN(name) \
gl->has_##name = hasVersion(#name,"GL_VERSION",glMajor,glMinor) || \
hasExtension(#name,glExtensions);
#define GL_FUNCTION(fn_name, fn_return, fn_args)
#define GL_GROUP_END()
#include "../generated/glefn.h"
#undef GL_FUNCTION
#undef GL_GROUP_BEGIN
#undef GL_GROUP_END
gl->bound = true;
return true;
}
} // Namespace