#include "ge_math.h"
#include "operatingsystem.h"
#include "c4d_gl.h"

#define GlStringCall(fn) (this->*C4DOS.GL->fn)
#define GlPFCall(fn) (this->*C4DOS.GL->fn)
#define GlVBCall(fn) (this->*C4DOS.GL->fn)

/************************************************************************/
/* GlString                                                             */
/************************************************************************/
GlString::GlString()
{
	GlStringCall(SDKInit1)();
}

GlString::GlString(const char* pszString)
{
	GlStringCall(SDKInit2)(pszString);
}

GlString::GlString(const GlString& str)
{
	GlStringCall(SDKInit3)(str);
}

GlString::GlString(LONG n)
{
	GlStringCall(SDKInit4)(n);
}

GlString::GlString(Real r, const char* pszFormat)
{
	GlStringCall(SDKInit5)(r, pszFormat);
}

GlString::~GlString()
{
	GlStringCall(SDKFree)();
}

const GlString& GlString::operator = (const GlString &str)
{
	return GlStringCall(SDKAssign1)(str);
}

const GlString& GlString::operator = (const char* pszString)
{
	return GlStringCall(SDKAssign2)(pszString);
}

const GlString operator + (const GlString &str1, const GlString &str2)
{
	return C4DOS.GL->GlStringAdd1(str1, str2);
}

const GlString& GlString::operator += (const GlString &str)
{
	return GlStringCall(GlStringAdd3)(str);
}

const GlString operator + (const GlString &str1, const char* str2)
{
	return C4DOS.GL->GlStringAdd2(str1, str2);
}

const GlString& GlString::operator += (const char* str)
{
	return GlStringCall(GlStringAdd4)(str);
}

LONG GlString::Compare(const GlString& s) const
{
	return GlStringCall(Compare)(s);
}

const char* GlString::GetCString() const
{
	return GlStringCall(GetCString)();
}

VLONG GlString::GetLength() const
{
	return GlStringCall(GetLength)();
}

LONG GlString::Replace(const GlString& strSearch, const GlString &strReplace, VLONG lStart, Bool bReplaceAll, Bool bOnlyWord)
{
	return GlStringCall(Replace)(strSearch, strReplace, lStart, bReplaceAll, bOnlyWord);
}



/************************************************************************/
/* GlProgramFactory                                                   */
/************************************************************************/
GlProgramFactory::GlProgramFactory()
{
}

GlProgramFactory::~GlProgramFactory()
{
}

GlProgramFactory* GlProgramFactory::GetFactory(const BaseDraw* pBaseDraw, C4DAtom* pObj, LONG lIndex, GlProgramFactoryMessageCallback fnCallback, void* pIdentity, VLONG lIdentityLength,
																							 const GlLight* const* ppLights, LONG lLightCount, LULONG ulFlags,
																							 const GlVertexBufferAttributeInfo* const* ppBufferAttributeInfo, LONG lBufferAttributeInfoCount,
																							 const GlVertexBufferVectorInfo* const* ppBufferVectorInfo, LONG lBufferVectorInfoCount,
																							 GlFBAdditionalTextureInfo* pAdditionalTextures)
{
	return C4DOS.GL->GetFactory(pBaseDraw, pObj, lIndex, fnCallback, pIdentity, lIdentityLength, ppLights, lLightCount, ulFlags, ppBufferAttributeInfo,
		lBufferAttributeInfoCount, ppBufferVectorInfo, lBufferVectorInfoCount, pAdditionalTextures);
}

void GlProgramFactory::RemoveReference(C4DAtom* pObj, LULONG ulIndex)
{
	C4DOS.GL->RemoveReference(pObj, ulIndex);
}

void GlProgramFactory::RemoveTextureReference(C4DAtom* pObj, LONG lIndex)
{
	C4DOS.GL->RemoveTextureReferenceA(pObj, lIndex);
}

void GlProgramFactory::RemoveTextureReference(const Filename &fn)
{
	C4DOS.GL->RemoveTextureReferenceB(fn);
}

#undef IncreaseBufferSize
void* GlProgramFactory::_IncreaseBufferSize(GlGetIdentity* pIdentity, VLONG lNeededSize, LONG lLine, const char* pszFile)
{
	return C4DOS.GL->IncreaseBufferSize(pIdentity, lNeededSize, lLine, pszFile);
}

Bool GlProgramFactory::BindToView(const BaseDraw* pDraw)
{
	return GlPFCall(BindToView)(pDraw);
}

Bool GlProgramFactory::CompilePrograms()
{
	return GlPFCall(CompilePrograms)();
}

Bool GlProgramFactory::CompileCgFX(const Filename& fn, ULONG ulFlags)
{
	return GlPFCall(CompileCgFX)(fn, ulFlags);
}

Bool GlProgramFactory::IsPrecompiled() const
{
	return GlPFCall(IsPrecompiled)();
}

Bool GlProgramFactory::BindPrograms()
{
	return GlPFCall(BindPrograms)();
}

Bool GlProgramFactory::BindCgFXPrograms(LONG lTechnique, LONG lPass)
{
	return GlPFCall(BindCgFXPrograms)(lTechnique, lPass);
}

Bool GlProgramFactory::UnbindPrograms()
{
	return GlPFCall(UnbindPrograms)();
}

Bool GlProgramFactory::DestroyPrograms()
{
	return GlPFCall(DestroyPrograms)(FALSE);
}

void GlProgramFactory::LockFactory()
{
	GlPFCall(LockFactory)();
}

void GlProgramFactory::UnlockFactory()
{
	GlPFCall(UnlockFactory)();
}

Bool GlProgramFactory::InitLightParameters()
{
	return GlPFCall(InitLightParameters)();
}

LONG GlProgramFactory::GetMaxLights()
{
	return GlPFCall(GetMaxLights)();
}

void* GlProgramFactory::GetPrivateData(const void* pObj, LONG lDataIndex, GlProgramFactoryAllocPrivate fnAlloc, GlProgramFactoryFreePrivate fnFree)
{
	return GlPFCall(GetPrivateData)(pObj, lDataIndex, fnAlloc, fnFree);
}

void* GlProgramFactory::GetDescriptionData(LONG lObjIndex, LONG lDataIndex, GlProgramFactoryAllocPrivate fnAlloc, GlProgramFactoryFreePrivate fnFree, GlProgramFactoryReadDescription fnRead, GlProgramFactoryWriteDescription fnWrite)
{
	return GlPFCall(GetDescriptionData)(lObjIndex, lDataIndex, fnAlloc, fnFree, fnRead, fnWrite);
}

Bool GlProgramFactory::IsProgram(GlProgramType t)
{
	return GlPFCall(IsProgram)(t);
}

void GlProgramFactory::InitSetParameters()
{
	GlPFCall(InitSetParameters)();
}

void GlProgramFactory::SetScreenCoordinates(BaseDraw* pBaseDraw)
{
	GlPFCall(SetScreenCoordinates)(pBaseDraw);
}

void GlProgramFactory::AddErrorHandler(GlProgramFactoryErrorHandler fn)
{
	GlPFCall(AddErrorHandler)(fn);
}

Bool GlProgramFactory::SetParameterMatrixTransform(GlProgramParameter param)
{
	return GlPFCall(SetParameterMatrixTransform)(param);
}

Bool GlProgramFactory::SetParameterMatrix(GlProgramParameter param, const SMatrix4 &m)
{
	return GlPFCall(SetParameterMatrix1)(param, m);
}

Bool GlProgramFactory::SetParameterMatrix(GlProgramParameter paramOffset, GlProgramParameter paramAxes, GlProgramParameter paramNormalTrans, const SMatrix &m)
{
	return GlPFCall(SetParameterMatrix2)(paramOffset, paramAxes, paramNormalTrans, m);
}

Bool GlProgramFactory::SetParameterMatrix3x3(GlProgramParameter param, const SReal* r)
{
	return GlPFCall(SetParameterMatrix3x3)(param, r);
}

Bool GlProgramFactory::SetParameterMatrix4x4(GlProgramParameter param, const SReal* r)
{
	return GlPFCall(SetParameterMatrix4x4)(param, r);
}

Bool GlProgramFactory::SetParameterVector(GlProgramParameter param, const SVector &v)
{
	return GlPFCall(SetParameterVector1)(param, v);
}

Bool GlProgramFactory::SetParameterVector(GlProgramParameter param, const SVector4 &v)
{
	return GlPFCall(SetParameterVector2)(param, v);
}

Bool GlProgramFactory::SetParameterVector(GlProgramParameter param, const SVector &v, SReal w)
{
	return GlPFCall(SetParameterVector3)(param, v, w);
}

Bool GlProgramFactory::SetParameterColor(GlProgramParameter param, const Vector &v, Real rBrightness)
{
	return GlPFCall(SetParameterColor1)(param, v, rBrightness);
}

Bool GlProgramFactory::SetParameterColor(GlProgramParameter param, const Vector &v, Real rBrightness, SReal rAlpha)
{
	return GlPFCall(SetParameterColor2)(param, v, rBrightness, rAlpha);
}

Bool GlProgramFactory::SetParameterColorReverse(GlProgramParameter param, const Vector &v, Real rBrightness)
{
	return GlPFCall(SetParameterColorReverse1)(param, v, rBrightness);
}

Bool GlProgramFactory::SetParameterColorReverse(GlProgramParameter param, const Vector &v, Real rBrightness, SReal rAlpha)
{
	return GlPFCall(SetParameterColorReverse2)(param, v, rBrightness, rAlpha);
}

Bool GlProgramFactory::SetParameterReal(GlProgramParameter param, const SReal r)
{
	return GlPFCall(SetParameterReal)(param, r);
}

Bool GlProgramFactory::SetParameterReal2(GlProgramParameter param, SReal a, SReal b)
{
	return GlPFCall(SetParameterReal2a)(param, a, b);
}

Bool GlProgramFactory::SetParameterReal2(GlProgramParameter param, const SReal* v)
{
	return GlPFCall(SetParameterReal2b)(param, v);
}

Bool GlProgramFactory::SetParameterReal3(GlProgramParameter param, SReal a, SReal b, SReal c)
{
	return GlPFCall(SetParameterReal3a)(param, a, b, c);
}

Bool GlProgramFactory::SetParameterReal3(GlProgramParameter param, const SReal* v)
{
	return GlPFCall(SetParameterReal3b)(param, v);
}

Bool GlProgramFactory::SetParameterReal4(GlProgramParameter param, SReal a, SReal b, SReal c, SReal d)
{
	return GlPFCall(SetParameterReal4a)(param, a, b, c, d);
}

Bool GlProgramFactory::SetParameterReal4(GlProgramParameter param, const SReal* v)
{
	return GlPFCall(SetParameterReal4b)(param, v);
}

Bool GlProgramFactory::SetParameterInt(GlProgramParameter param, int a)
{
	return GlPFCall(SetParameterInt)(param, a);
}

Bool GlProgramFactory::SetParameterInt2(GlProgramParameter param, int a, int b)
{
	return GlPFCall(SetParameterInt2a)(param, a, b);
}

Bool GlProgramFactory::SetParameterInt2(GlProgramParameter param, const int* v)
{
	return GlPFCall(SetParameterInt2b)(param, v);
}

Bool GlProgramFactory::SetParameterInt3(GlProgramParameter param, int a, int b, int c)
{
	return GlPFCall(SetParameterInt3a)(param, a, b, c);
}

Bool GlProgramFactory::SetParameterInt3(GlProgramParameter param, const int* v)
{
	return GlPFCall(SetParameterInt3b)(param, v);
}

Bool GlProgramFactory::SetParameterInt4(GlProgramParameter param, int a, int b, int c, int d)
{
	return GlPFCall(SetParameterInt4a)(param, a, b, c, d);
}

Bool GlProgramFactory::SetParameterInt4(GlProgramParameter param, const int* v)
{
	return GlPFCall(SetParameterInt4b)(param, v);
}

Bool GlProgramFactory::SetParameterUint(GlProgramParameter param, unsigned int l)
{
	return GlPFCall(SetParameterUint)(param, l);
}

Bool GlProgramFactory::SetParameterUint2(GlProgramParameter param, unsigned int a, unsigned int b)
{
	return GlPFCall(SetParameterUint2a)(param, a, b);
}

Bool GlProgramFactory::SetParameterUint2(GlProgramParameter param, const unsigned int* v)
{
	return GlPFCall(SetParameterUint2b)(param, v);
}

Bool GlProgramFactory::SetParameterUint3(GlProgramParameter param, unsigned int a, unsigned int b, unsigned int c)
{
	return GlPFCall(SetParameterUint3a)(param, a, b, c);
}

Bool GlProgramFactory::SetParameterUint3(GlProgramParameter param, const unsigned int* v)
{
	return GlPFCall(SetParameterUint3b)(param, v);
}

Bool GlProgramFactory::SetParameterUint4(GlProgramParameter param, unsigned int a, unsigned int b, unsigned int c, unsigned int d)
{
	return GlPFCall(SetParameterUint4a)(param, a, b, c, d);
}

Bool GlProgramFactory::SetParameterUint4(GlProgramParameter param, const unsigned int* v)
{
	return GlPFCall(SetParameterUint4b)(param, v);
}

Bool GlProgramFactory::SetParameterRealArray(GlProgramParameter param, LONG lElements, const SReal *r)
{
	return GlPFCall(SetParameterRealArray)(param, lElements, r);
}

Bool GlProgramFactory::SetParameterTexture2D(GlProgramParameter param, const BaseBitmap* pBmp, LONG lFlags, DRAW_ALPHA alphamode, C4DGLuint* pnHandle)
{
	return GlPFCall(SetParameterTexture2D1)(param, pBmp, lFlags, alphamode, pnHandle);
}

Bool GlProgramFactory::SetParameterTexture2D(GlProgramParameter param, const Filename &fn, LONG lFrame, C4DAtom* pObj, LONG lIndex, LONG lFlags, DRAW_ALPHA alphamode, LONG lMaxSize, const LayerSet* pLayerSet, GlTextureInfo* pInfo, C4DGLuint* pnHandle)
{
	return GlPFCall(SetParameterTexture2D2)(param, fn, lFrame, pObj, lIndex, lFlags, alphamode, lMaxSize, pLayerSet, pInfo, pnHandle);
}

Bool GlProgramFactory::SetParameterTexture2D(GlProgramParameter param, const BaseBitmap* pBmp, ULONG ulDirty, C4DAtom* pObj, LONG lIndex, LONG lFlags, DRAW_ALPHA alphamode, LONG lMaxSize, GlTextureInfo* pInfo, C4DGLuint* pnHandle)
{
	return GlPFCall(SetParameterTexture2D3)(param, pBmp, ulDirty, pObj, lIndex, lFlags, alphamode, lMaxSize, pInfo, pnHandle);
}

Bool GlProgramFactory::CacheTextureFn(BaseDraw* pBaseDraw, const Filename &fn, LONG lFrame, C4DAtom* pObj, LONG lIndex, LONG lFlags, DRAW_ALPHA alphamode, LONG lMaxSize, GlProgramType progType, const LayerSet* pLayerSet, GlTextureInfo* pInfo, C4DGLuint* pnHandle)
{
	return C4DOS.GL->CacheTextureFn(pBaseDraw, fn, lFrame, pObj, lIndex, lFlags, alphamode, lMaxSize, progType, pLayerSet, pInfo, pnHandle);
}

Bool GlProgramFactory::CacheTextureBmp(BaseDraw* pBaseDraw, const BaseBitmap* pBmp, ULONG ulDirty, C4DAtom* pObj, LONG lIndex, LONG lFlags, DRAW_ALPHA alphamode, LONG lMaxSize, GlProgramType progType, GlTextureInfo* pInfo, C4DGLuint* pnHandle)
{
	return C4DOS.GL->CacheTextureBmp(pBaseDraw, pBmp, ulDirty, pObj, lIndex, lFlags, alphamode, lMaxSize, progType, pInfo, pnHandle);
}

Bool GlProgramFactory::SetParameterTexture(GlProgramParameter param, LONG lDimension, C4DGLuint nTexture)
{
	return GlPFCall(SetParameterTexture)(param, lDimension, nTexture);
}

Bool GlProgramFactory::SetParameterTextureCube(GlProgramParameter param, C4DGLuint nTexture)
{
	return GlPFCall(SetParameterTextureCube)(param, nTexture);
}

Bool GlProgramFactory::SetParameterTexture2DDepth(GlProgramParameter param, C4DGLuint nTexture)
{
	return GlPFCall(SetParameterTexture2DDepth)(param, nTexture);
}

Bool GlProgramFactory::SetParameterTextureCubeDepth(GlProgramParameter param, C4DGLuint nTexture)
{
	return GlPFCall(SetParameterTextureCubeDepth)(param, nTexture);
}

Bool GlProgramFactory::SetParameterTextureGradient(GlProgramParameter param, const Gradient* pGradient, C4DAtom* pObj, LONG lIndex, LONG lFlags, C4DGLuint* pnHandle)
{
	return GlPFCall(SetParameterTextureGradient)(param, pGradient, pObj, lIndex, lFlags, pnHandle);
}

Bool GlProgramFactory::SetParameterTextureFunction(GlProgramParameter param, C4DAtom* pObj, LONG lIndex, LONG lFlags, LONG lDataType, GlProgramFactoryCreateTextureFunctionCallback fn, void* pData, VLONG lDataLen,
		LONG lInParams, LONG lOutParams, LONG lCycle, Bool bInterpolate, LONG lSizeX, LONG lSizeY, LONG lSizeZ, Bool bParallel, C4DGLuint* pnHandle)
{
	return GlPFCall(SetParameterTextureFunction)(param, pObj, lIndex, lFlags, lDataType, fn, pData, lDataLen, lInParams, lOutParams, lCycle, bInterpolate, lSizeX, lSizeY, lSizeZ, bParallel, pnHandle);
}

Bool GlProgramFactory::SetParameterTextureRaw(GlProgramParameter param, C4DAtom* pObj, LONG lIndex, LONG lFlags, LONG lDataType, const void* pData, VLONG lDataLen, ULONG ulDirty,
														LONG lDimension, LONG lComponents, LONG lCycle, Bool bInterpolate, LONG lSizeX, LONG lSizeY, LONG lSizeZ, C4DGLuint* pnHandle)
{
	return GlPFCall(SetParameterTextureRaw)(param, pObj, lIndex, lFlags, lDataType, pData, lDataLen, ulDirty, lDimension, lComponents, lCycle, bInterpolate, lSizeX, lSizeY, lSizeZ, pnHandle);
}

Bool GlProgramFactory::SetParameterTextureCubeMap(GlProgramParameter param, C4DAtom* pObj, LONG lIndex, LONG lFlags, LONG lDataType, GlProgramFactoryCreateTextureFunctionCallback fn, void* pData, VLONG lDataLen,
																LONG lOutParams, LONG lCycle, Bool bInterpolate, LONG lSize, Bool bParallel, C4DGLuint* pnHandle)
{
	return GlPFCall(SetParameterTextureCubeMap)(param, pObj, lIndex, lFlags, lDataType, fn, pData, lDataLen, lOutParams, lCycle, bInterpolate, lSize, bParallel, pnHandle);
}

Bool GlProgramFactory::SetLightParameters(const GlLight* const* ppLights, LONG lLightCount, const SMatrix4& mObject)
{
	return GlPFCall(SetLightParameters)(ppLights, lLightCount, mObject);
}

LULONG GlProgramFactory::Init(LONG lSubdivisionCount, LONG lGeometryTypeIn, LONG lGeometryTypeOut, LONG lMaxOutVertices)
{
	return GlPFCall(Init)(lSubdivisionCount, lGeometryTypeIn, lGeometryTypeOut, lMaxOutVertices);
}

void GlProgramFactory::AddParameters(LULONG ulParameters, LULONG ulFormat)
{
	GlPFCall(AddParameters)(ulParameters, ulFormat);
}

LULONG GlProgramFactory::GetParameters() const
{
	return GlPFCall(GetParameters)();
}

LULONG GlProgramFactory::GetParameterFormats() const
{
	return GlPFCall(GetParameterFormats)();
}

GlString GlProgramFactory::AddUniformParameter(GlProgramType t, GlUniformParamType p, const char* pszName)
{
	return GlPFCall(AddUniformParameter1)(t, p, pszName);
}

GlString GlProgramFactory::AddUniformParameter(GlProgramType t, GlUniformParamType p, LONG lCount, const char* pszName)
{
	return GlPFCall(AddUniformParameter2)(t, p, lCount, pszName);
}

Bool GlProgramFactory::HeaderFinished()
{
	return GlPFCall(HeaderFinished)();
}

const UCHAR* GlProgramFactory::GetIdentity() const
{
	return GlPFCall(GetIdentity)();
}

GlProgramParameter GlProgramFactory::GetParameterHandle(GlProgramType t, const char* pszName) const
{
	return GlPFCall(GetParameterHandle)(t, pszName);
}

Bool GlProgramFactory::GetCgFXDescription(BaseContainer* pbcDescription)
{
	return GlPFCall(GetCgFXDescription)(pbcDescription);
}

Bool GlProgramFactory::AddLightProjection()
{
	return GlPFCall(AddLightProjection)();
}

void GlProgramFactory::AddLine(GlProgramType t, const GlString &strLine)
{
	GlPFCall(AddLine)(t, strLine);
}

void GlProgramFactory::AddDepthCompareCondition(GlProgramType t, const GlString &strPeelTexture)
{
	GlPFCall(AddDepthCompareCondition)(t, strPeelTexture);
}

Bool GlProgramFactory::AddEncryptedBlock(GlProgramType t, const char* pchData, VLONG lDataLength, const UCHAR* pchKey, LONG lKeyLength)
{
	return GlPFCall(AddEncryptedBlock)(t, pchData, lDataLength, pchKey, lKeyLength);
}

GlString GlProgramFactory::AddColorBlendFunction(GlProgramType t, LONG lBlendMode)
{
	return GlPFCall(AddColorBlendFunction)(t, lBlendMode);
}

GlString GlProgramFactory::AddRGBToHSVFunction(GlProgramType t)
{
	return GlPFCall(AddRGBToHSVFunction)(t);
}

GlString GlProgramFactory::AddHSVToRGBFunction(GlProgramType t)
{
	return GlPFCall(AddHSVToRGBFunction)(t);
}

GlString GlProgramFactory::AddRGBToHSLFunction(GlProgramType t)
{
	return GlPFCall(AddRGBToHSLFunction)(t);
}

GlString GlProgramFactory::AddHSLToRGBFunction(GlProgramType t)
{
	return GlPFCall(AddHSLToRGBFunction)(t);
}

Bool GlProgramFactory::AddFunction(GlProgramType t, const GlString &strFunction)
{
	return GlPFCall(AddFunction)(t, strFunction);
}

void GlProgramFactory::StartLightLoop()
{
	GlPFCall(StartLightLoop)();
}

Bool GlProgramFactory::EndLightLoop()
{
	return GlPFCall(EndLightLoop)();
}

GlString GlProgramFactory::GetUniqueID()
{
	return GlPFCall(GetUniqueID)();
}

Bool GlProgramFactory::HasNoiseSupport(GlProgramType t, LONG lNoise, BaseDraw* pBaseDraw, LONG lCompiler)
{
	return C4DOS.GL->HasNoiseSupport(t, lNoise, pBaseDraw, lCompiler);
}

const GlString& GlProgramFactory::AddNoiseFunction(GlProgramType t, LONG lNoise, LONG lFlags)
{
	return GlPFCall(AddNoiseFunction)(t, lNoise, lFlags);
}

void GlProgramFactory::GetVectorInfo(LONG &lVectorCount, const GlVertexBufferVectorInfo* const* &ppVectorInfo) const
{
	return GlPFCall(GetVectorInfo)(lVectorCount, ppVectorInfo);
}

ULONG GlProgramFactory::GetLanguageFeatures(LONG lCompiler, LONG lFlags)
{
	return C4DOS.GL->GetLanguageFeatures(lCompiler, lFlags);
}

LONG GlProgramFactory::GetCompiler()
{
	return GlPFCall(GetCompiler)();
}

Bool GlProgramFactory::WriteParameter(GlWriteDescriptionData* pFile, GlProgramParameter param)
{
	return C4DOS.GL->WriteParameter(pFile, param);
}

Bool GlProgramFactory::ReadParameter(GlReadDescriptionData* pFile, GlProgramParameter& param)
{
	return C4DOS.GL->ReadParameter(pFile, param);
}

/************************************************************************/
/* GlFrameBuffer                                                        */
/************************************************************************/
GlFrameBuffer* GlFrameBuffer::GetFrameBuffer(BaseDraw* pBaseDraw, VULONG lID1, LONG lID2, UINT nWidth, UINT nHeight, LONG lColorTextureCount, 
																						 LONG lDepthTextureCount, LONG lColorCubeCount, LONG lDepthCubeCount, ULONG ulFlags,
																						 LONG lAAMode, GlFBAdditionalTextureInfo* pAdditionalTextures)
{
	return C4DOS.GL->GetFrameBuffer(pBaseDraw, lID1, lID2, nWidth, nHeight, lColorTextureCount, lDepthTextureCount, lColorCubeCount, lDepthCubeCount, ulFlags, lAAMode, pAdditionalTextures);
}

GlFrameBuffer* GlFrameBuffer::FindFrameBuffer(BaseDraw* pBaseDraw, VULONG lID1, LONG lID2)
{
	return C4DOS.GL->FindFrameBuffer(pBaseDraw, lID1, lID2);
}

void GlFrameBuffer::RemoveObject(BaseDraw* pBaseDraw, VULONG lID1, LONG lID2)
{
	C4DOS.GL->RemoveObjectF(pBaseDraw, lID1, lID2);
}

void GlFrameBuffer::PrepareForRendering(BaseDraw* pBaseDraw, LONG lTexture)
{
	GlPFCall(PrepareForRendering)(pBaseDraw, lTexture);
}

void GlFrameBuffer::SetInterpolation(BaseDraw* pBaseDraw, LONG lInterpolate, LONG lTexture, LONG lFlags)
{
	GlPFCall(SetInterpolation)(pBaseDraw, lInterpolate, lTexture, lFlags);
}

Bool GlFrameBuffer::Activate(BaseDraw* pBaseDraw)
{
	return GlPFCall(Activate)(pBaseDraw);
}

void GlFrameBuffer::Deactivate(BaseDraw* pBaseDraw)
{
	GlPFCall(Deactivate)(pBaseDraw);
}

Bool GlFrameBuffer::SetRenderTarget(LONG lTexture, LONG lFlags)
{
	return GlPFCall(SetRenderTarget)(lTexture, lFlags);
}

void GlFrameBuffer::GetRatios(LONG lFlags, Real& rWidth, Real& rHeight)
{
	GlPFCall(GetRatios)(lFlags, rWidth, rHeight);
}

void GlFrameBuffer::GetSize(LONG lFlags, UINT &nWidth, UINT &nHeight, Bool bFramesize)
{
	GlPFCall(GetSize)(lFlags, nWidth, nHeight, bFramesize);
}

C4DGLuint GlFrameBuffer::GetTexture(LONG lTexture, LONG lFlags)
{
	return GlPFCall(GetTexture)(lTexture, lFlags);
}

GlFBAdditionalTextureInfo* GlFrameBuffer::GetAdditionalTexture(LONG lType, void* pBuffer)
{
	return GlPFCall(GetAdditionalTexture)(lType, pBuffer);
}

LONG GlFrameBuffer::SaveTextureToDisk(BaseDraw* pBaseDraw, const Filename &fn, LONG lTexture, LONG lFlags)
{
	return GlPFCall(SaveTextureToDisk)(pBaseDraw, fn, lTexture, lFlags);
}

Bool GlFrameBuffer::CopyToBitmap(BaseDraw* pBaseDraw, BaseBitmap* pBmp, LONG lTexture, LONG lFlags)
{
	return GlPFCall(CopyToBitmap)(pBaseDraw, pBmp, lTexture, lFlags);
}

Bool GlFrameBuffer::GetTextureData(BaseDraw* pBaseDraw, LONG x1, LONG y1, LONG x2, LONG y2, void* pData, LONG lTexture, LONG lFlags)
{
	return GlPFCall(GetTextureData)(pBaseDraw, x1, y1, x2, y2, pData, lTexture, lFlags);
}

Bool GlFrameBuffer::CopyToBuffer(void* pBuffer, VLONG lBufferSize, LONG lTexture, LONG lFlags)
{
	return GlPFCall(CopyToBuffer)(pBuffer, lBufferSize, lTexture, lFlags);
}

Bool GlFrameBuffer::DrawBuffer(LONG lTexture, LONG lFlags, Bool bCopyAlpha, LONG lColorConversion, C4DGLint nConversionTexture, SReal rAlpha, const SVector &vColor, SReal xs1, SReal ys1, SReal xs2, SReal ys2, SReal xd1, SReal yd1, SReal xd2, SReal yd2)
{
	return GlPFCall(DrawBuffer)(lTexture, lFlags, bCopyAlpha, lColorConversion, nConversionTexture, rAlpha, vColor, xs1, ys1, xs2, ys2, xd1, yd1, xd2, yd2);
}

void GlFrameBuffer::Clear()
{
	GlPFCall(Clear1)();
}

void GlFrameBuffer::Clear(const SVector &vColor, SReal rAlpha)
{
	GlPFCall(Clear2)(vColor, rAlpha);
}

Bool GlFrameBuffer::IsNPOTBuffer()
{
	return GlPFCall(IsNPOTBuffer)();
}

/************************************************************************/
/* GlVertexBuffer                                                       */
/************************************************************************/
GlVertexBuffer* GlVertexBuffer::GetVertexBuffer(const BaseDraw* pBaseDraw, C4DAtom* pObj, LONG lIndex, void* pIdentity, VLONG lIdentityLen, ULONG ulFlags)
{
	return C4DOS.GL->GetVertexBuffer(pBaseDraw, pObj, lIndex, pIdentity, lIdentityLen, ulFlags);
}

void GlVertexBuffer::RemoveObject(C4DAtom* pObj, LONG lIndex)
{
	C4DOS.GL->RemoveObjectV(pObj, lIndex);
}

Bool GlVertexBuffer::IsDirty()
{
	return GlVBCall(IsDirty)();
}

void GlVertexBuffer::SetDirty(Bool bDirty)
{
	GlVBCall(SetDirty)(bDirty);
}

Bool GlVertexBuffer::DrawSubBuffer(const BaseDraw* pBaseDraw, const GlVertexSubBufferData* pVertexSubBuffer, const GlVertexSubBufferData* pElementSubBuffer, 
									 LONG lDrawinfoCount, const GlVertexBufferDrawSubbuffer* pDrawInfo,
									 LONG lVectorCount, const GlVertexBufferVectorInfo* const* ppVectorInfo,
									 GlVertexBufferDrawElementCallback fnCallback, void* pCallbackData)
{
	return C4DOS.GL->DrawSubBuffer(pBaseDraw, pVertexSubBuffer, pElementSubBuffer, lDrawinfoCount, pDrawInfo, lVectorCount, ppVectorInfo, fnCallback, pCallbackData);
}

GlVertexSubBufferData* GlVertexBuffer::AllocSubBuffer(const BaseDraw* pBaseDraw, GlVertexBufferSubBufferType type, VLONG lSize, const void* pData)
{
	return GlVBCall(AllocSubBuffer)(pBaseDraw, type, lSize, pData);
}

GlVertexSubBufferData* GlVertexBuffer::AllocIndexSubBuffer(const BaseDraw* pBaseDraw, LONG lCount, ULONG* pulIndex, LONG lMaxIndex)
{
	return GlVBCall(AllocIndexSubBuffer1)(pBaseDraw, lCount, pulIndex, lMaxIndex);
}

GlVertexSubBufferData* GlVertexBuffer::AllocIndexSubBuffer(const BaseDraw* pBaseDraw, LONG lCount, const UWORD* puwIndex)
{
	return GlVBCall(AllocIndexSubBuffer2)(pBaseDraw, lCount, puwIndex);
}

Bool GlVertexBuffer::FlushAllSubBuffers(const BaseDraw* pBaseDraw)
{
	return GlVBCall(FlushAllSubBuffers)(pBaseDraw);
}

Bool GlVertexBuffer::FreeBuffers(const BaseDraw* pBaseDraw, GlVertexBufferSubBufferType type)
{
	return GlVBCall(FreeBuffers)(pBaseDraw, type);
}

Bool GlVertexBuffer::FreeBuffer(const BaseDraw* pBaseDraw, GlVertexSubBufferData* pBuffer)
{
	return GlVBCall(FreeBuffer)(pBaseDraw, pBuffer);
}

Bool GlVertexBuffer::MarkAllForDelete()
{
	return GlVBCall(MarkAllForDelete)();
}

Bool GlVertexBuffer::MarkBuffersForDelete(GlVertexBufferSubBufferType type)
{
	return GlVBCall(MarkBuffersForDelete)(type);
}

Bool GlVertexBuffer::MarkBufferForDelete(GlVertexSubBufferData* pBuffer)
{
	return GlVBCall(MarkBufferForDelete)(pBuffer);
}

Bool GlVertexBuffer::DeleteMarkedBuffers(const BaseDraw* pBaseDraw)
{
	return GlVBCall(DeleteMarkedBuffers)(pBaseDraw);
}

Bool GlVertexBuffer::SetSubBufferData(const BaseDraw* pBaseDraw, GlVertexSubBufferData* pSubBuffer, VLONG lSize, const void* pData)
{
	return GlVBCall(SetSubBufferData)(pBaseDraw, pSubBuffer, lSize, pData);
}

LONG GlVertexBuffer::GetSubBufferCount() const
{
	return GlVBCall(GetSubBufferCount)();
}

GlVertexSubBufferData* GlVertexBuffer::GetSubBuffer(LONG n)
{
	return GlVBCall(GetSubBuffer)(n);
}

void* GlVertexBuffer::MapBuffer(const BaseDraw* pBaseDraw, GlVertexSubBufferData* pSubBuffer, GlVertexBufferAccessFlags flags)
{
	return GlVBCall(MapBuffer)(pBaseDraw, pSubBuffer, flags);
}

Bool GlVertexBuffer::UnmapBuffer(const BaseDraw* pBaseDraw, GlVertexSubBufferData* pSubBuffer)
{
	return GlVBCall(UnmapBuffer)(pBaseDraw, pSubBuffer);
}
