HPL1: add basic tinygl impl classes

This commit is contained in:
grisenti 2022-09-13 21:36:35 +02:00 committed by Eugene Sandulenko
parent 029fcb96bf
commit 304a2df165
No known key found for this signature in database
GPG Key ID: 014D387312D34F08
9 changed files with 3033 additions and 11 deletions

View File

@ -142,10 +142,12 @@ cRenderer3D::cRenderer3D(iLowLevelGraphics *apLowLevelGraphics, cResources *apRe
pFogArray[i * 2 + 1] = 255 - (unsigned char)i;
}
pTex->CreateFromArray(pFogArray, 2, cVector3l(256, 1, 1));
pTex->SetWrapR(eTextureWrap_ClampToEdge);
pTex->SetWrapS(eTextureWrap_ClampToEdge);
pTex->SetWrapT(eTextureWrap_ClampToEdge);
if (pTex) {
pTex->CreateFromArray(pFogArray, 2, cVector3l(256, 1, 1));
pTex->SetWrapR(eTextureWrap_ClampToEdge);
pTex->SetWrapS(eTextureWrap_ClampToEdge);
pTex->SetWrapT(eTextureWrap_ClampToEdge);
}
mpFogLinearSolidTexture = pTex;
@ -158,9 +160,11 @@ cRenderer3D::cRenderer3D(iLowLevelGraphics *apLowLevelGraphics, cResources *apRe
pFogArray[i * 2 + 1] = (unsigned char)i;
}
pTex->CreateFromArray(pFogArray, 2, cVector3l(256, 1, 1));
pTex->SetWrapR(eTextureWrap_ClampToEdge);
pTex->SetWrapS(eTextureWrap_ClampToEdge);
if (pTex) {
pTex->CreateFromArray(pFogArray, 2, cVector3l(256, 1, 1));
pTex->SetWrapR(eTextureWrap_ClampToEdge);
pTex->SetWrapS(eTextureWrap_ClampToEdge);
}
mpFogLinearAddTexture = pTex;
@ -173,9 +177,11 @@ cRenderer3D::cRenderer3D(iLowLevelGraphics *apLowLevelGraphics, cResources *apRe
pFogArray[i * 2 + 1] = (unsigned char)i;
}
pTex->CreateFromArray(pFogArray, 2, cVector3l(256, 1, 1));
pTex->SetWrapR(eTextureWrap_ClampToEdge);
pTex->SetWrapS(eTextureWrap_ClampToEdge);
if (pTex) {
pTex->CreateFromArray(pFogArray, 2, cVector3l(256, 1, 1));
pTex->SetWrapR(eTextureWrap_ClampToEdge);
pTex->SetWrapS(eTextureWrap_ClampToEdge);
}
mpFogLinearAlphaTexture = pTex;

File diff suppressed because it is too large Load Diff

View File

@ -0,0 +1,280 @@
/* ScummVM - Graphic Adventure Engine
*
* ScummVM is the legal property of its developers, whose names
* are too numerous to list here. Please refer to the COPYRIGHT
* file distributed with this source distribution.
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*
*/
#ifndef HPL_LOW_LEVEL_GRAPHICS_TGL_H
#define HPL_LOW_LEVEL_GRAPHICS_TGL_H
#include "hpl1/engine/graphics/LowLevelGraphics.h"
#include "graphics/pixelformat.h"
#include "hpl1/engine/math/MathTypes.h"
#include "graphics/surface.h"
#include "common/ptr.h"
#include "graphics/tinygl/tinygl.h"
namespace hpl {
TGLenum ColorFormatToTGL(eColorDataFormat format);
TGLenum TextureTargetToTGL(eTextureTarget target);
TGLenum GetTGLTextureTargetEnum(eTextureTarget type);
//-------------------------------------------------
class LowLevelGraphicsTGL : public iLowLevelGraphics {
public:
LowLevelGraphicsTGL();
~LowLevelGraphicsTGL();
bool Init(int alWidth, int alHeight, int alBpp, int abFullscreen, int alMultisampling,
const tString &asWindowCaption);
int GetCaps(eGraphicCaps aType) const;
void ShowCursor(bool abX);
void SetVsyncActive(bool abX);
void SetMultisamplingActive(bool abX);
void SetGammaCorrection(float afX);
float GetGammaCorrection();
int GetMultisampling() { return mlMultisampling; }
void SetClipPlane(int alIdx, const cPlanef &aPlane);
cPlanef GetClipPlane(int alIdx, const cPlanef &aPlane);
void SetClipPlaneActive(int alIdx, bool abX);
cVector2f GetScreenSize();
cVector2f GetVirtualSize();
void SetVirtualSize(cVector2f avSize);
Bitmap2D *CreateBitmap2D(const cVector2l &avSize);
FontData *CreateFontData(const tString &asName);
iTexture *CreateTexture(bool abUseMipMaps, eTextureType aType, eTextureTarget aTarget);
iTexture *CreateTexture(const tString &asName, bool abUseMipMaps, eTextureType aType, eTextureTarget aTarget);
iTexture *CreateTexture(Bitmap2D *apBmp, bool abUseMipMaps, eTextureType aType, eTextureTarget aTarget);
iTexture *CreateTexture(const cVector2l &avSize, int alBpp, cColor aFillCol,
bool abUseMipMaps, eTextureType aType, eTextureTarget aTarget);
Graphics::PixelFormat *GetPixelFormat();
iGpuProgram *CreateGpuProgram(const tString &vertex, const tString &fragment);
void SaveScreenToBMP(const tString &asFile);
/////////// MATRIX METHODS /////////////////////////
void PushMatrix(eMatrix aMtxType);
void PopMatrix(eMatrix aMtxType);
void SetIdentityMatrix(eMatrix aMtxType);
void SetMatrix(eMatrix aMtxType, const cMatrixf &a_mtxA);
void TranslateMatrix(eMatrix aMtxType, const cVector3f &avPos);
void RotateMatrix(eMatrix aMtxType, const cVector3f &avRot);
void ScaleMatrix(eMatrix aMtxType, const cVector3f &avScale);
void SetOrthoProjection(const cVector2f &avSize, float afMin, float afMax);
/////////// DRAWING METHODS /////////////////////////
// OCCLUSION
iOcclusionQuery *CreateOcclusionQuery();
void DestroyOcclusionQuery(iOcclusionQuery *apQuery);
// CLEARING THE FRAMEBUFFER
void ClearScreen();
void SetClearColor(const cColor &aCol);
void SetClearDepth(float afDepth);
void SetClearStencil(int alVal);
void SetClearColorActive(bool abX);
void SetClearDepthActive(bool abX);
void SetClearStencilActive(bool abX);
void SetColorWriteActive(bool abR, bool abG, bool abB, bool abA);
void SetDepthWriteActive(bool abX);
void SetCullActive(bool abX);
void SetCullMode(eCullMode aMode);
// DEPTH
void SetDepthTestActive(bool abX);
void SetDepthTestFunc(eDepthTestFunc aFunc);
// ALPHA
void SetAlphaTestActive(bool abX);
void SetAlphaTestFunc(eAlphaTestFunc aFunc, float afRef);
// STENCIL
void SetStencilActive(bool abX);
void SetStencil(eStencilFunc aFunc, int alRef, unsigned int aMask,
eStencilOp aFailOp, eStencilOp aZFailOp, eStencilOp aZPassOp);
void SetStencilTwoSide(eStencilFunc aFrontFunc, eStencilFunc aBackFunc,
int alRef, unsigned int aMask,
eStencilOp aFrontFailOp, eStencilOp aFrontZFailOp, eStencilOp aFrontZPassOp,
eStencilOp aBackFailOp, eStencilOp aBackZFailOp, eStencilOp aBackZPassOp);
void SetStencilTwoSide(bool abX);
// SCISSOR
void SetScissorActive(bool abX);
void SetScissorRect(const cRect2l &aRect);
// BLENDING
void SetBlendActive(bool abX);
void SetBlendFunc(eBlendFunc aSrcFactor, eBlendFunc aDestFactor);
void SetBlendFuncSeparate(eBlendFunc aSrcFactorColor, eBlendFunc aDestFactorColor,
eBlendFunc aSrcFactorAlpha, eBlendFunc aDestFactorAlpha);
// TEXTURE
void SetTexture(unsigned int alUnit, iTexture *apTex);
void SetActiveTextureUnit(unsigned int alUnit);
void SetTextureEnv(eTextureParam aParam, int alVal);
void SetTextureConstantColor(const cColor &color);
void SetColor(const cColor &aColor);
// POLYGONS
iVertexBuffer *CreateVertexBuffer(tVertexFlag aFlags, eVertexBufferDrawType aDrawType,
eVertexBufferUsageType aUsageType,
int alReserveVtxSize = 0, int alReserveIdxSize = 0);
void DrawRect(const cVector2f &avPos, const cVector2f &avSize, float afZ);
void DrawTri(const tVertexVec &avVtx);
void DrawTri(const cVertex *avVtx);
void DrawQuad(const tVertexVec &avVtx);
void DrawQuad(const tVertexVec &avVtx, const cColor aCol);
void DrawQuad(const tVertexVec &avVtx, const float afZ);
void DrawQuad(const tVertexVec &avVtx, const float afZ, const cColor &aCol);
void DrawQuadMultiTex(const tVertexVec &avVtx, const tVector3fVec &avExtraUvs);
void AddVertexToBatch(const cVertex &apVtx);
void AddVertexToBatch(const cVertex *apVtx, const cVector3f *avTransform);
void AddVertexToBatch(const cVertex *apVtx, const cMatrixf *aMtx);
void AddVertexToBatch_Size2D(const cVertex *apVtx, const cVector3f *avTransform,
const cColor *apCol, const float &mfW, const float &mfH);
void AddVertexToBatch_Raw(const cVector3f &avPos, const cColor &aColor,
const cVector3f &avTex);
void AddTexCoordToBatch(unsigned int alUnit, const cVector3f *apCoord);
void SetBatchTextureUnitActive(unsigned int alUnit, bool abActive);
void AddIndexToBatch(int alIndex);
void FlushTriBatch(tVtxBatchFlag aTypeFlags, bool abAutoClear = true);
void FlushQuadBatch(tVtxBatchFlag aTypeFlags, bool abAutoClear = true);
void ClearBatch();
// PRIMITIVES
void DrawLine(const cVector3f &avBegin, const cVector3f &avEnd, cColor aCol);
void DrawBoxMaxMin(const cVector3f &avMax, const cVector3f &avMin, cColor aCol);
void DrawSphere(const cVector3f &avPos, float afRadius, cColor aCol);
void DrawLine2D(const cVector2f &avBegin, const cVector2f &avEnd, float afZ, cColor aCol);
void DrawLineRect2D(const cRect2f &aRect, float afZ, cColor aCol);
void DrawLineCircle2D(const cVector2f &avCenter, float afRadius, float afZ, cColor aCol);
void DrawFilledRect2D(const cRect2f &aRect, float afZ, cColor aCol);
// FRAMEBUFFER
void CopyContextToTexure(iTexture *apTex, const cVector2l &avPos,
const cVector2l &avSize, const cVector2l &avTexOffset = 0);
void SetRenderTarget(iTexture *pTex);
bool RenderTargetHasZBuffer();
void FlushRenderTarget();
void FlushRendering();
void SwapBuffers();
///// SDL Specific ////////////////////////////
void SetupGL();
private:
cVector2l mvScreenSize;
cVector2f mvVirtualSize;
int mlMultisampling;
int mlBpp;
// Gamma
//uint16 mvStartGammaArray[3][256];
float mfGammaCorrection;
// Clipping
cPlanef mvClipPlanes[kMaxClipPlanes];
// SDL Variables
//SDL_Surface *mpScreen;
Graphics::PixelFormat mpPixelFormat;
// Vertex Array variables
// The vertex arrays used:
float *mpVertexArray;
unsigned int mlVertexCount;
unsigned int *mpIndexArray;
unsigned int mlIndexCount;
unsigned int mlBatchStride;
float *mpTexCoordArray[MAX_TEXTUREUNITS];
bool mbTexCoordArrayActive[MAX_TEXTUREUNITS];
unsigned int mlTexCoordArrayCount[MAX_TEXTUREUNITS];
unsigned int mlBatchArraySize;
// Clearing
bool mbClearColor;
bool mbClearDepth;
bool mbClearStencil;
// Rendertarget variables
iTexture *mpRenderTarget;
// Texture
iTexture *mpCurrentTexture[MAX_TEXTUREUNITS];
// CG Compiler Variables
//CGcontext mCG_Context;
// Multisample
void CheckMultisampleCaps();
// Batch helper
void SetUpBatchArrays();
// Matrix Helper
void SetMatrixMode(eMatrix mType);
// Vtx helper
void SetVtxBatchStates(tVtxBatchFlag flags);
};
} // namespace hpl
#endif // HPL_LOWLEVELGRAPHICS_TGL_H

View File

@ -0,0 +1,541 @@
/* ScummVM - Graphic Adventure Engine
*
* ScummVM is the legal property of its developers, whose names
* are too numerous to list here. Please refer to the COPYRIGHT
* file distributed with this source distribution.
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*
*/
#include "hpl1/engine/impl/texture_tgl.h"
#include "common/str.h"
#include "graphics/pixelformat.h"
#include "hpl1/engine/graphics/bitmap2D.h"
#include "hpl1/debug.h"
#include "hpl1/engine/math/Math.h"
#include "hpl1/engine/system/low_level_system.h"
namespace hpl {
static void getSettings(Bitmap2D *apSrc, int &alChannels, TGLint &internalFormat, TGLenum &format) {
alChannels = apSrc->getNumChannels();
tString sType = cString::ToLowerCase(apSrc->getType());
const Common::String bmpFormat = apSrc->format().toString();
if (alChannels == 4) {
internalFormat = TGL_RGBA;
if (bmpFormat.contains("BGRA")) {
format = TGL_BGRA;
} else {
format = TGL_RGBA;
}
}
if (alChannels == 3) {
internalFormat = TGL_RGB;
if (bmpFormat.contains("BGR")) {
format = TGL_BGR;
} else {
format = TGL_RGB;
}
}
if (alChannels == 1) {
format = TGL_RED;
internalFormat = TGL_RED;
}
}
//////////////////////////////////////////////////////////////////////////
// CONSTRUCTORS
//////////////////////////////////////////////////////////////////////////
//-----------------------------------------------------------------------
TGLTexture::TGLTexture(const tString &asName, Graphics::PixelFormat *apPxlFmt, iLowLevelGraphics *apLowLevelGraphics,
eTextureType aType, bool abUseMipMaps, eTextureTarget aTarget,
bool abCompress)
: iTexture(asName, "OGL", apPxlFmt, apLowLevelGraphics, aType, abUseMipMaps, aTarget, abCompress) {
mbContainsData = false;
if (aType == eTextureType_RenderTarget) {
Hpl1::logError(Hpl1::kDebugGraphics, "use of render target%s", ".");
// mpPBuffer = hplNew( cPBuffer, (mpLowLevelGraphics,true) );
}
// Cubemap does not like mipmaps
if (aTarget == eTextureTarget_CubeMap)
mbUseMipMaps = false;
mpGfxSDL = static_cast<LowLevelGraphicsTGL *>(mpLowLevelGraphics);
mlTextureIndex = 0;
mfTimeCount = 0;
mfTimeDir = 1;
}
TGLTexture::~TGLTexture() {
for (unsigned int &mvTextureHandle : mvTextureHandles) {
tglDeleteTextures(1, &mvTextureHandle);
}
}
//-----------------------------------------------------------------------
//////////////////////////////////////////////////////////////////////////
// PUBLIC METHODS
//////////////////////////////////////////////////////////////////////////
//-----------------------------------------------------------------------
bool TGLTexture::CreateFromBitmap(Bitmap2D *pBmp) {
// Generate handles
if (mvTextureHandles.empty()) {
mvTextureHandles.resize(1);
tglGenTextures(1, &mvTextureHandles[0]);
} else {
// Log("Delete + Generate!\n");
// glDeleteTextures(1,(GLuint *)&mvTextureHandles[0]);
// glGenTextures(1,(GLuint *)&mvTextureHandles[0]);
}
return CreateFromBitmapToHandle(pBmp, 0);
}
//-----------------------------------------------------------------------
bool TGLTexture::CreateAnimFromBitmapVec(tBitmap2DVec *avBitmaps) {
mvTextureHandles.resize(avBitmaps->size());
for (size_t i = 0; i < mvTextureHandles.size(); ++i) {
tglGenTextures(1, &mvTextureHandles[i]);
if (CreateFromBitmapToHandle((*avBitmaps)[i], (int)i) == false) {
return false;
}
}
return true;
}
//-----------------------------------------------------------------------
bool TGLTexture::CreateCubeFromBitmapVec(tBitmap2DVec *avBitmaps) {
HPL1_UNIMPLEMENTED(TGLTexture::CreateCubeFromBitmapVec);
}
//-----------------------------------------------------------------------
bool TGLTexture::Create(unsigned int alWidth, unsigned int alHeight, cColor aCol) {
HPL1_UNIMPLEMENTED(TGLTexture::Create);
}
//-----------------------------------------------------------------------
static void generateMipmaps(eTextureTarget target) {
}
bool TGLTexture::CreateFromArray(unsigned char *apPixelData, int alChannels, const cVector3l &avSize) {
if (mvTextureHandles.empty()) {
mvTextureHandles.resize(1);
tglGenTextures(1, &mvTextureHandles[0]);
}
TGLenum GLTarget = InitCreation(0);
int lChannels = alChannels;
TGLenum format = 0;
switch (lChannels) {
case 1:
case 2:
case 3:
format = TGL_RGB;
break;
case 4:
format = TGL_RGBA;
break;
}
_width = avSize.x;
_height = avSize.y;
_bpp = lChannels * 8;
if (!cMath::IsPow2(_height) || !cMath::IsPow2(_width) || !cMath::IsPow2(avSize.z)) {
Hpl1::logWarning(Hpl1::kDebugGraphics, "Texture '%s' does not have a pow2 size", msName.c_str());
}
if (mTarget == eTextureTarget_1D) {
tglTexImage2D(GLTarget, 0, format, _width, 1, 0, format,
TGL_UNSIGNED_BYTE, apPixelData);
} else if (mTarget == eTextureTarget_2D) {
tglTexImage2D(GLTarget, 0, format, _width, _height,
0, format, TGL_UNSIGNED_BYTE, apPixelData);
} else if (mTarget == eTextureTarget_3D) {
error("trying to create a texture 3D in TGLTexture");
}
if (mbUseMipMaps && mTarget != eTextureTarget_Rect && mTarget != eTextureTarget_3D)
generateMipmaps(mTarget);
PostCreation(GLTarget);
return true;
}
//-----------------------------------------------------------------------
void TGLTexture::SetPixels2D(int alLevel, const cVector2l &avOffset, const cVector2l &avSize,
eColorDataFormat aDataFormat, void *apPixelData) {
HPL1_UNIMPLEMENTED(TGLTexture::SetPixels2D);
}
//-----------------------------------------------------------------------
void TGLTexture::Update(float afTimeStep) {
if (mvTextureHandles.size() > 1) {
float fMax = (float)(mvTextureHandles.size());
mfTimeCount += afTimeStep * (1.0f / mfFrameTime) * mfTimeDir;
if (mfTimeDir > 0) {
if (mfTimeCount >= fMax) {
if (mAnimMode == eTextureAnimMode_Loop) {
mfTimeCount = 0;
} else {
mfTimeCount = fMax - 1.0f;
mfTimeDir = -1.0f;
}
}
} else {
if (mfTimeCount < 0) {
mfTimeCount = 1;
mfTimeDir = 1.0f;
}
}
}
}
//-----------------------------------------------------------------------
bool TGLTexture::HasAnimation() {
return mvTextureHandles.size() > 1;
}
void TGLTexture::NextFrame() {
mfTimeCount += mfTimeDir;
if (mfTimeDir > 0) {
float fMax = (float)(mvTextureHandles.size());
if (mfTimeCount >= fMax) {
if (mAnimMode == eTextureAnimMode_Loop) {
mfTimeCount = 0;
} else {
mfTimeCount = fMax - 1.0f;
mfTimeDir = -1.0f;
}
}
} else {
if (mfTimeCount < 0) {
mfTimeCount = 1;
mfTimeDir = 1.0f;
}
}
}
void TGLTexture::PrevFrame() {
mfTimeCount -= mfTimeDir;
if (mfTimeDir < 0) {
float fMax = (float)(mvTextureHandles.size());
if (mfTimeCount >= fMax) {
if (mAnimMode == eTextureAnimMode_Loop) {
mfTimeCount = 0;
} else {
mfTimeCount = fMax - 1.0f;
mfTimeDir = -1.0f;
}
}
} else {
if (mfTimeCount < 0) {
mfTimeCount = 1;
mfTimeDir = 1.0f;
}
}
}
float TGLTexture::GetT() {
return cMath::Modulus(mfTimeCount, 1.0f);
}
float TGLTexture::GetTimeCount() {
return mfTimeCount;
}
void TGLTexture::SetTimeCount(float afX) {
mfTimeCount = afX;
}
int TGLTexture::GetCurrentLowlevelHandle() {
return GetTextureHandle();
}
//-----------------------------------------------------------------------
void TGLTexture::SetFilter(eTextureFilter aFilter) {
if (mFilter == aFilter)
return;
mFilter = aFilter;
if (mbContainsData) {
TGLenum GLTarget =GetTGLTextureTargetEnum(mTarget);
tglEnable(GLTarget);
for (size_t i = 0; i < mvTextureHandles.size(); ++i) {
tglBindTexture(GLTarget, mvTextureHandles[i]);
if (mbUseMipMaps && mTarget != eTextureTarget_Rect) {
if (mFilter == eTextureFilter_Bilinear)
tglTexParameteri(GLTarget, TGL_TEXTURE_MIN_FILTER, TGL_LINEAR_MIPMAP_NEAREST);
else
tglTexParameteri(GLTarget, TGL_TEXTURE_MIN_FILTER, TGL_LINEAR_MIPMAP_LINEAR);
} else {
tglTexParameteri(GLTarget, TGL_TEXTURE_MIN_FILTER, TGL_LINEAR);
}
}
tglDisable(GLTarget);
}
}
//-----------------------------------------------------------------------
void TGLTexture::SetAnisotropyDegree(float afX) {
}
//-----------------------------------------------------------------------
void TGLTexture::SetWrapS(eTextureWrap aMode) {
if (mbContainsData) {
TGLenum GLTarget = GetTGLTextureTargetEnum(mTarget);
tglEnable(GLTarget);
for (size_t i = 0; i < mvTextureHandles.size(); ++i) {
tglBindTexture(GLTarget, mvTextureHandles[i]);
tglTexParameteri(GLTarget, TGL_TEXTURE_WRAP_S, GetGLWrap(aMode));
}
tglDisable(GLTarget);
}
}
//-----------------------------------------------------------------------
void TGLTexture::SetWrapT(eTextureWrap aMode) {
if (mbContainsData) {
TGLenum GLTarget = GetTGLTextureTargetEnum(mTarget);
tglEnable(GLTarget);
for (size_t i = 0; i < mvTextureHandles.size(); ++i) {
tglBindTexture(GLTarget, mvTextureHandles[i]);
tglTexParameteri(GLTarget, TGL_TEXTURE_WRAP_T, GetGLWrap(aMode));
}
tglDisable(GLTarget);
}
}
//-----------------------------------------------------------------------
void TGLTexture::SetWrapR(eTextureWrap aMode) {
if (mbContainsData) {
TGLenum GLTarget = GetTGLTextureTargetEnum(mTarget);
tglEnable(GLTarget);
tglEnable(GLTarget);
for (size_t i = 0; i < mvTextureHandles.size(); ++i) {
tglBindTexture(GLTarget, mvTextureHandles[i]);
//tglTexParameteri(GLTarget, TGL_TEXTURE_WRAP_R, GetGLWrap(aMode));
}
tglDisable(GLTarget);
tglDisable(GLTarget);
}
}
//-----------------------------------------------------------------------
unsigned int TGLTexture::GetTextureHandle() {
if (mvTextureHandles.size() > 1) {
int lFrame = (int)mfTimeCount;
return mvTextureHandles[lFrame];
} else {
return mvTextureHandles[0];
}
}
//-----------------------------------------------------------------------
//////////////////////////////////////////////////////////////////////////
// PRIVATE METHODS
//////////////////////////////////////////////////////////////////////////
//-----------------------------------------------------------------------
bool TGLTexture::CreateFromBitmapToHandle(Bitmap2D *pBmp, int alHandleIdx) {
if (mType == eTextureType_RenderTarget)
error("trying to create a rendertarget in SDLTexture::CreateBitmapToHandle");
// For some reason checking for ARB texture is not working on radeon cards.
/*if(mTarget == eTextureTarget_Rect && !GLEE_ARB_texture_rectangle)
{
Error("Rectangle texture target not supported\n");
return false;
}*/
TGLenum GLTarget = InitCreation(alHandleIdx);
Bitmap2D *pBitmapSrc = pBmp;
_width = pBitmapSrc->getWidth();
_height = pBitmapSrc->getHeight();
if ((!cMath::IsPow2(_height) || !cMath::IsPow2(_width)) && mTarget != eTextureTarget_Rect)
Hpl1::logWarning(Hpl1::kDebugGraphics, "Texture '%s' does not have a pow2 size", msName.c_str());
int lChannels = 0;
TGLint internalFormat = 0;
TGLenum format = 0;
getSettings(pBitmapSrc, lChannels, internalFormat, format);
_bpp = lChannels * 8;
const unsigned char *pPixelSrc = (const unsigned char *)pBitmapSrc->getRawData();
unsigned char *pNewSrc = nullptr;
if (mlSizeLevel > 0 && (int)_width > mvMinLevelSize.x * 2) {
// Log("OldSize: %d x %d ",mlWidth,mlHeight);
int lOldW = _width;
//int lOldH = _height;
int lSizeDiv = (int)pow((float)2, (int)mlSizeLevel);
_width /= lSizeDiv;
_height /= lSizeDiv;
while (_width < (unsigned int)mvMinLevelSize.x) {
_width *= 2;
_height *= 2;
lSizeDiv /= 2;
}
// Log("NewSize: %d x %d SizeDiv: %d\n",mlWidth,mlHeight,lSizeDiv);
pNewSrc = hplNewArray(unsigned char, lChannels *_width *_height);
int lWidthCount = _width;
int lHeightCount = _height;
int lOldAdd = lChannels * lSizeDiv;
int lOldHeightAdd = lChannels * lOldW * (lSizeDiv - 1);
const unsigned char *pOldPixel = pPixelSrc;
unsigned char *pNewPixel = pNewSrc;
while (lHeightCount) {
memcpy(pNewPixel, pOldPixel, lChannels);
pOldPixel += lOldAdd;
pNewPixel += lChannels;
lWidthCount--;
if (!lWidthCount) {
lWidthCount = _width;
lHeightCount--;
pOldPixel += lOldHeightAdd;
}
}
pPixelSrc = pNewSrc;
}
// Log("Loading %s %d x %d\n",msName.c_str(), pSrc->GetWidth(), pSrc->GetHeight());
// Log("Channels: %d Format: %x\n",lChannels, format);
if (mTarget == eTextureTarget_1D)
tglTexImage2D(GLTarget, 0, internalFormat, _width, 1, 0, format,
TGL_UNSIGNED_BYTE, pPixelSrc);
else
tglTexImage2D(GLTarget, 0, internalFormat, _width, _height,
0, format, TGL_UNSIGNED_BYTE, pPixelSrc);
//if (tglGetError() != TGL_NO_ERROR)
// return false;
if (mbUseMipMaps && mTarget != eTextureTarget_Rect)
generateMipmaps(mTarget);
PostCreation(GLTarget);
if (mlSizeLevel > 0 && pNewSrc)
hplDeleteArray(pNewSrc);
return true;
}
//-----------------------------------------------------------------------
TGLenum TGLTexture::InitCreation(int alHandleIdx) {
TGLenum GLTarget = GetTGLTextureTargetEnum(mTarget);
tglEnable(GLTarget);
tglBindTexture(GLTarget, mvTextureHandles[alHandleIdx]);
return GLTarget;
}
//-----------------------------------------------------------------------
void TGLTexture::PostCreation(TGLenum aGLTarget) {
if (mbUseMipMaps && mTarget != eTextureTarget_Rect) {
if (mFilter == eTextureFilter_Bilinear)
tglTexParameteri(aGLTarget, TGL_TEXTURE_MIN_FILTER, TGL_LINEAR_MIPMAP_NEAREST);
else
tglTexParameteri(aGLTarget, TGL_TEXTURE_MIN_FILTER, TGL_LINEAR_MIPMAP_LINEAR);
} else {
tglTexParameteri(aGLTarget, TGL_TEXTURE_MIN_FILTER, TGL_LINEAR);
}
tglTexParameteri(aGLTarget, TGL_TEXTURE_MAG_FILTER, TGL_LINEAR);
tglDisable(aGLTarget);
mbContainsData = true;
}
//-----------------------------------------------------------------------
TGLenum TGLTexture::GetGLWrap(eTextureWrap aMode) {
switch (aMode) {
case eTextureWrap_Clamp:
return TGL_CLAMP;
case eTextureWrap_Repeat:
return TGL_REPEAT;
case eTextureWrap_ClampToEdge:
return TGL_CLAMP_TO_EDGE;
case eTextureWrap_ClampToBorder:
return TGL_CLAMP_TO_EDGE;//TGL_CLAMP_TO_BORDER;
default:
break;
}
return TGL_REPEAT;
}
}
//-----------------------------------------------------------------------

View File

@ -0,0 +1,95 @@
/* ScummVM - Graphic Adventure Engine
*
* ScummVM is the legal property of its developers, whose names
* are too numerous to list here. Please refer to the COPYRIGHT
* file distributed with this source distribution.
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*
*/
#ifndef HPL_TEXTURE_TGL_H
#define HPL_TEXTURE_TGL_H
#include "hpl1/engine/graphics/Texture.h"
#include "hpl1/engine/impl/low_level_graphics_tgl.h"
#include "hpl1/engine/graphics/bitmap2D.h"
namespace hpl {
class TGLTexture : public iTexture {
public:
TGLTexture(const tString &asName, Graphics::PixelFormat *apPxlFmt, iLowLevelGraphics *apLowLevelGraphics,
eTextureType aType, bool abUseMipMaps, eTextureTarget aTarget,
bool abCompress = false);
~TGLTexture();
bool CreateFromBitmap(Bitmap2D *pBmp);
bool CreateAnimFromBitmapVec(tBitmap2DVec *avBitmaps);
bool CreateCubeFromBitmapVec(tBitmap2DVec *avBitmaps);
bool Create(unsigned int alWidth, unsigned int alHeight, cColor aCol);
bool CreateFromArray(unsigned char *apPixelData, int alChannels, const cVector3l &avSize);
void SetPixels2D(int alLevel, const cVector2l &avOffset, const cVector2l &avSize,
eColorDataFormat aDataFormat, void *apPixelData);
float GetGamma() { return 0; }
void SetGamma(float afGamma) {}
int GetHandle() { return (int)mvTextureHandles[0]; }
void SetFilter(eTextureFilter aFilter);
void SetAnisotropyDegree(float afX);
void SetWrapS(eTextureWrap aMode);
void SetWrapT(eTextureWrap aMode);
void SetWrapR(eTextureWrap aMode);
void Update(float afTimeStep);
bool HasAnimation();
void NextFrame();
void PrevFrame();
float GetT();
float GetTimeCount();
void SetTimeCount(float afX);
int GetCurrentLowlevelHandle();
/// SDL / OGL Specific ///////////
unsigned int GetTextureHandle();
//cPBuffer *GetPBuffer() { return mpPBuffer; }
private:
bool CreateFromBitmapToHandle(Bitmap2D *pBmp, int alHandleIdx);
TGLenum InitCreation(int alHandleIdx);
void PostCreation(TGLenum aGLTarget);
TGLenum GetGLWrap(eTextureWrap aMode);
tUIntVec mvTextureHandles;
bool mbContainsData;
LowLevelGraphicsTGL *mpGfxSDL;
float mfTimeCount;
int mlTextureIndex;
float mfTimeDir;
};
} // namespace hpl
#endif // HPL_TEXTURE_TGL_H

View File

@ -0,0 +1,492 @@
/* ScummVM - Graphic Adventure Engine
*
* ScummVM is the legal property of its developers, whose names
* are too numerous to list here. Please refer to the COPYRIGHT
* file distributed with this source distribution.
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*
*/
#include "hpl1/engine/impl/vertex_buffer_tgl.h"
#include "hpl1/engine/math/Math.h"
#include "hpl1/engine/system/low_level_system.h"
#include "hpl1/debug.h"
#include "graphics/tinygl/tinygl.h"
namespace hpl {
//////////////////////////////////////////////////////////////////////////
// CONSTRUCTORS
//////////////////////////////////////////////////////////////////////////
//-----------------------------------------------------------------------
VertexBufferTGL::VertexBufferTGL(iLowLevelGraphics *apLowLevelGraphics, tVertexFlag aFlags,
eVertexBufferDrawType aDrawType, eVertexBufferUsageType aUsageType,
int alReserveVtxSize, int alReserveIdxSize) : iVertexBuffer(apLowLevelGraphics, aFlags, aDrawType, aUsageType, alReserveVtxSize, alReserveIdxSize) {
if (alReserveVtxSize > 0) {
for (int i = 0; i < klNumOfVertexFlags; i++) {
if (aFlags & kvVertexFlags[i]) {
mvVertexArray[i].reserve(alReserveVtxSize * kvVertexElements[i]);
}
}
}
if (alReserveIdxSize > 0)
mvIndexArray.reserve(alReserveIdxSize);
mbTangents = false;
mbHasShadowDouble = false;
mpLowLevelGraphics = apLowLevelGraphics;
}
VertexBufferTGL::~VertexBufferTGL() {
for (int i = 0; i < klNumOfVertexFlags; i++)
mvVertexArray[i].clear();
mvIndexArray.clear();
}
//-----------------------------------------------------------------------
//////////////////////////////////////////////////////////////////////////
// PUBLIC METHODS
//////////////////////////////////////////////////////////////////////////
//-----------------------------------------------------------------------
void VertexBufferTGL::AddVertex(tVertexFlag aType, const cVector3f &avVtx) {
int idx = cMath::Log2ToInt((int)aType);
mvVertexArray[idx].push_back(avVtx.x);
mvVertexArray[idx].push_back(avVtx.y);
mvVertexArray[idx].push_back(avVtx.z);
if (kvVertexElements[idx] == 4)
mvVertexArray[idx].push_back(1);
}
//-----------------------------------------------------------------------
void VertexBufferTGL::AddColor(tVertexFlag aType, const cColor &aColor) {
int idx = cMath::Log2ToInt((int)aType);
mvVertexArray[idx].push_back(aColor.r);
mvVertexArray[idx].push_back(aColor.g);
mvVertexArray[idx].push_back(aColor.b);
mvVertexArray[idx].push_back(aColor.a);
}
//-----------------------------------------------------------------------
void VertexBufferTGL::AddIndex(unsigned int alIndex) {
mvIndexArray.push_back(alIndex);
}
//-----------------------------------------------------------------------
bool VertexBufferTGL::Compile(tVertexCompileFlag aFlags) {
if (aFlags & eVertexCompileFlag_CreateTangents) {
mbTangents = true;
mVertexFlags |= eVertexFlag_Texture1;
int idx = cMath::Log2ToInt((int)eVertexFlag_Texture1);
int lSize = GetVertexNum() * 4;
mvVertexArray[idx].resize(lSize);
cMath::CreateTriTangentVectors(&(mvVertexArray[cMath::Log2ToInt((int)eVertexFlag_Texture1)][0]),
&mvIndexArray[0], GetIndexNum(),
&(mvVertexArray[cMath::Log2ToInt((int)eVertexFlag_Position)][0]),
kvVertexElements[cMath::Log2ToInt((int)eVertexFlag_Position)],
&(mvVertexArray[cMath::Log2ToInt((int)eVertexFlag_Texture0)][0]),
&(mvVertexArray[cMath::Log2ToInt((int)eVertexFlag_Normal)][0]),
GetVertexNum());
}
return true;
}
//-----------------------------------------------------------------------
void VertexBufferTGL::UpdateData(tVertexFlag aTypes, bool abIndices) {
}
//-----------------------------------------------------------------------
void VertexBufferTGL::CreateShadowDouble(bool abUpdateData) {
int lIdx = cMath::Log2ToInt(eVertexFlag_Position);
// Set to new size.
int lSize = (int)mvVertexArray[lIdx].size();
mvVertexArray[lIdx].reserve(lSize * 2);
int lCount = lSize / 4;
for (int i = 0; i < lCount; i++) {
mvVertexArray[lIdx].push_back(mvVertexArray[lIdx][i * 4 + 0]);
mvVertexArray[lIdx].push_back(mvVertexArray[lIdx][i * 4 + 1]);
mvVertexArray[lIdx].push_back(mvVertexArray[lIdx][i * 4 + 2]);
mvVertexArray[lIdx].push_back(0); // 0);
}
mbHasShadowDouble = true;
if (abUpdateData) {
UpdateData(eVertexFlag_Position, false);
}
}
//-----------------------------------------------------------------------
void VertexBufferTGL::Transform(const cMatrixf &a_mtxTransform) {
float *pPosArray = GetArray(eVertexFlag_Position);
float *pNormalArray = GetArray(eVertexFlag_Normal);
float *pTangentArray = NULL;
if (mbTangents)
pTangentArray = GetArray(eVertexFlag_Texture1);
int lVtxNum = GetVertexNum();
cMatrixf mtxRot = a_mtxTransform.GetRotation();
int lVtxStride = kvVertexElements[cMath::Log2ToInt(eVertexFlag_Position)];
int lOffset = GetVertexNum() * 4;
for (int i = 0; i < lVtxNum; i++) {
float *pPos = &pPosArray[i * lVtxStride];
float *pNorm = &pNormalArray[i * 3];
float *pTan = NULL;
if (mbTangents)
pTan = &pTangentArray[i * 4];
cVector3f vPos = cMath::MatrixMul(a_mtxTransform, cVector3f(pPos[0], pPos[1], pPos[2]));
pPos[0] = vPos.x;
pPos[1] = vPos.y;
pPos[2] = vPos.z;
if (mbHasShadowDouble) {
float *pExtraPos = &pPosArray[i * lVtxStride + lOffset];
pExtraPos[0] = vPos.x;
pExtraPos[1] = vPos.y;
pExtraPos[2] = vPos.z;
}
cVector3f vNorm = cMath::MatrixMul(mtxRot, cVector3f(pNorm[0], pNorm[1], pNorm[2]));
vNorm.Normalise();
pNorm[0] = vNorm.x;
pNorm[1] = vNorm.y;
pNorm[2] = vNorm.z;
if (mbTangents) {
cVector3f vTan = cMath::MatrixMul(mtxRot, cVector3f(pTan[0], pTan[1], pTan[2]));
vTan.Normalise();
pTan[0] = vTan.x;
pTan[1] = vTan.y;
pTan[2] = vTan.z;
}
}
if (mbTangents)
UpdateData(eVertexFlag_Position | eVertexFlag_Normal | eVertexFlag_Texture1, false);
else
UpdateData(eVertexFlag_Position | eVertexFlag_Normal, false);
}
//-----------------------------------------------------------------------
void VertexBufferTGL::Draw(eVertexBufferDrawType aDrawType) {
eVertexBufferDrawType drawType = aDrawType == eVertexBufferDrawType_LastEnum ? mDrawType : aDrawType;
///////////////////////////////
//Get the draw type
TGLenum mode = TGL_TRIANGLES;
if(drawType==eVertexBufferDrawType_Quad) mode = TGL_QUADS;
else if(drawType==eVertexBufferDrawType_Lines) mode = TGL_LINE_STRIP;
int lSize = mlElementNum;
if(mlElementNum<0) lSize = GetIndexNum();
tglDrawElements(mode,lSize,TGL_UNSIGNED_INT, &mvIndexArray[0]);
}
void VertexBufferTGL::DrawIndices(unsigned int *apIndices, int alCount,
eVertexBufferDrawType aDrawType) {
eVertexBufferDrawType drawType = aDrawType == eVertexBufferDrawType_LastEnum ? mDrawType : aDrawType;
///////////////////////////////
//Get the draw type
TGLenum mode = TGL_TRIANGLES;
if(drawType==eVertexBufferDrawType_Quad) mode = TGL_QUADS;
else if(drawType==eVertexBufferDrawType_Lines) mode = TGL_LINE_STRIP;
//////////////////////////////////
//Bind and draw the buffer
tglDrawElements(mode, alCount, TGL_UNSIGNED_INT, apIndices);
}
//-----------------------------------------------------------------------
void VertexBufferTGL::Bind() {
SetVertexStates(mVertexFlags);
}
//-----------------------------------------------------------------------
void VertexBufferTGL::UnBind() {
}
//-----------------------------------------------------------------------
iVertexBuffer *VertexBufferTGL::CreateCopy(eVertexBufferUsageType aUsageType) {
VertexBufferTGL *pVtxBuff = hplNew(VertexBufferTGL, (mpLowLevelGraphics,
mVertexFlags, mDrawType, aUsageType,
GetVertexNum(), GetIndexNum()));
// Copy the vertices to the new buffer.
for (int i = 0; i < klNumOfVertexFlags; i++) {
if (kvVertexFlags[i] & mVertexFlags) {
#if 0
int lElements = kvVertexElements[i];
if (mbTangents && kvVertexFlags[i] == eVertexFlag_Texture1)
lElements = 4;
#endif
pVtxBuff->ResizeArray(kvVertexFlags[i], (int)mvVertexArray[i].size());
memcpy(pVtxBuff->GetArray(kvVertexFlags[i]),
&mvVertexArray[i][0], mvVertexArray[i].size() * sizeof(float));
}
}
// Copy indices to the new buffer
pVtxBuff->ResizeIndices(GetIndexNum());
memcpy(pVtxBuff->GetIndices(), GetIndices(), GetIndexNum() * sizeof(unsigned int));
pVtxBuff->mbTangents = mbTangents;
pVtxBuff->mbHasShadowDouble = mbHasShadowDouble;
pVtxBuff->Compile(0);
return pVtxBuff;
}
//-----------------------------------------------------------------------
cBoundingVolume VertexBufferTGL::CreateBoundingVolume() {
cBoundingVolume bv;
int lNum = cMath::Log2ToInt((int)eVertexFlag_Position);
bv.AddArrayPoints(&(mvVertexArray[lNum][0]), GetVertexNum());
bv.CreateFromPoints(kvVertexElements[cMath::Log2ToInt(eVertexFlag_Position)]);
return bv;
}
float *VertexBufferTGL::GetArray(tVertexFlag aType) {
int idx = cMath::Log2ToInt((int)aType);
return &mvVertexArray[idx][0];
}
//-----------------------------------------------------------------------
unsigned int *VertexBufferTGL::GetIndices() {
return &mvIndexArray[0];
}
//-----------------------------------------------------------------------
void VertexBufferTGL::ResizeArray(tVertexFlag aType, int alSize) {
int idx = cMath::Log2ToInt((int)aType);
mvVertexArray[idx].resize(alSize);
}
//-----------------------------------------------------------------------
void VertexBufferTGL::ResizeIndices(int alSize) {
mvIndexArray.resize(alSize);
}
//-----------------------------------------------------------------------
int VertexBufferTGL::GetVertexNum() {
int idx = cMath::Log2ToInt((int)eVertexFlag_Position);
int lSize = (int)mvVertexArray[idx].size() / kvVertexElements[idx];
// If there is a shadow double, just return the length of the first half.
if (mbHasShadowDouble)
return lSize / 2;
else
return lSize;
}
int VertexBufferTGL::GetIndexNum() {
return (int)mvIndexArray.size();
}
cVector3f VertexBufferTGL::GetVector3(tVertexFlag aType, unsigned alIdx) {
if (!(aType & mVertexFlags))
return cVector3f(0, 0, 0);
int idx = cMath::Log2ToInt((int)aType);
int pos = alIdx * kvVertexElements[idx];
return cVector3f(mvVertexArray[idx][pos + 0], mvVertexArray[idx][pos + 1],
mvVertexArray[idx][pos + 2]);
}
cVector3f VertexBufferTGL::GetVector4(tVertexFlag aType, unsigned alIdx) {
if (!(aType & mVertexFlags))
return cVector3f(0, 0, 0);
int idx = cMath::Log2ToInt((int)aType);
int pos = alIdx * 4; // kvVertexElements[idx];
return cVector3f(mvVertexArray[idx][pos + 0], mvVertexArray[idx][pos + 1],
mvVertexArray[idx][pos + 2]);
}
cColor VertexBufferTGL::GetColor(tVertexFlag aType, unsigned alIdx) {
if (!(aType & mVertexFlags))
return cColor();
int idx = cMath::Log2ToInt((int)aType);
int pos = alIdx * kvVertexElements[idx];
return cColor(mvVertexArray[idx][pos + 0], mvVertexArray[idx][pos + 1],
mvVertexArray[idx][pos + 2], mvVertexArray[idx][pos + 3]);
}
unsigned int VertexBufferTGL::GetIndex(tVertexFlag aType, unsigned alIdx) {
return mvIndexArray[alIdx];
}
//-----------------------------------------------------------------------
/////////////////////////////////////////////////////////////////////////
// PRIVATE METHODS
/////////////////////////////////////////////////////////////////////////
//-----------------------------------------------------------------------
void VertexBufferTGL::SetVertexStates(tVertexFlag aFlags) {
/// POSITION /////////////////////////
if(aFlags & eVertexFlag_Position){
tglEnableClientState(TGL_VERTEX_ARRAY);
int idx = cMath::Log2ToInt(eVertexFlag_Position);
tglVertexPointer(kvVertexElements[idx],TGL_FLOAT, sizeof(float)*kvVertexElements[idx], &mvVertexArray[idx][0]);
}
else
{
tglDisableClientState(TGL_VERTEX_ARRAY);
}
/// COLOR 0 /////////////////////////
if(aFlags & eVertexFlag_Color0)
{
tglEnableClientState(TGL_COLOR_ARRAY);
int idx = cMath::Log2ToInt(eVertexFlag_Color0);
tglColorPointer(kvVertexElements[idx],TGL_FLOAT, sizeof(float)*kvVertexElements[idx], &mvVertexArray[idx][0]);
}
else
{
tglDisableClientState(TGL_COLOR_ARRAY);
}
/// NORMAL /////////////////////////
if(aFlags & eVertexFlag_Normal)
{
tglEnableClientState(TGL_NORMAL_ARRAY);
tglNormalPointer(TGL_FLOAT, sizeof(float)*3, &mvVertexArray[cMath::Log2ToInt(eVertexFlag_Normal)][0]);
}
else
{
tglDisableClientState(TGL_NORMAL_ARRAY);
}
/// TEXTURE 0 /////////////////////////
if(aFlags & eVertexFlag_Texture0)
{
tglEnableClientState(TGL_TEXTURE_COORD_ARRAY);
int idx = cMath::Log2ToInt(eVertexFlag_Texture0);
tglTexCoordPointer(kvVertexElements[idx],TGL_FLOAT,sizeof(float)*kvVertexElements[idx],&mvVertexArray[idx][0]);
}
else {
tglDisableClientState(TGL_TEXTURE_COORD_ARRAY);
}
#if 0
/// TEXTURE 1 /////////////////////////
if(aFlags & eVertexFlag_Texture1){
tglClientActiveTextureARB(TGL_TEXTURE1_ARB);
tglEnableClientState(TGL_TEXTURE_COORD_ARRAY);
int idx = cMath::Log2ToInt(eVertexFlag_Texture1);
if(mbTangents)
tglTexCoordPointer(4,TGL_FLOAT,sizeof(float)*4,&mvVertexArray[idx][0]);
else
tglTexCoordPointer(kvVertexElements[idx],TGL_FLOAT,sizeof(float)*kvVertexElements[idx],&mvVertexArray[idx][0]);
}
else {
//tglClientActiveTextureARB(TGL_TEXTURE1_ARB);
//tglDisableClientState(TGL_TEXTURE_COORD_ARRAY);
}
/// TEXTURE 2 /////////////////////////
if(aFlags & eVertexFlag_Texture2){
tglClientActiveTextureARB(TGL_TEXTURE2_ARB);
tglEnableClientState(TGL_TEXTURE_COORD_ARRAY);
int idx = cMath::Log2ToInt(eVertexFlag_Texture2);
tglTexCoordPointer(kvVertexElements[idx],TGL_FLOAT,sizeof(float)*kvVertexElements[idx],&mvVertexArray[idx][0]);
}
else {
//tglClientActiveTextureARB(TGL_TEXTURE2_ARB);
//tglDisableClientState(TGL_TEXTURE_COORD_ARRAY);
}
/// TEXTURE 3 /////////////////////////
if(aFlags & eVertexFlag_Texture3){
tglClientActiveTextureARB(TGL_TEXTURE3_ARB);
tglEnableClientState(TGL_TEXTURE_COORD_ARRAY);
int idx = cMath::Log2ToInt(eVertexFlag_Texture3);
tglTexCoordPointer(kvVertexElements[idx],TGL_FLOAT,sizeof(float)*kvVertexElements[idx],&mvVertexArray[idx][0]);
}
else {
//tglClientActiveTextureARB(TGL_TEXTURE3_ARB);
//tglDisableClientState(TGL_TEXTURE_COORD_ARRAY);
}
/// TEXTURE 4 /////////////////////////
if(aFlags & eVertexFlag_Texture4){
tglClientActiveTextureARB(TGL_TEXTURE4_ARB);
tglEnableClientState(TGL_TEXTURE_COORD_ARRAY);
int idx = cMath::Log2ToInt(eVertexFlag_Texture4);
tglTexCoordPointer(kvVertexElements[idx],TGL_FLOAT,sizeof(float)*kvVertexElements[idx],&mvVertexArray[idx][0]);
}
else {
//tglClientActiveTextureARB(TGL_TEXTURE4_ARB);
//tglDisableClientState(TGL_TEXTURE_COORD_ARRAY);
}
#endif
}
//-----------------------------------------------------------------------
} // namespace hpl

View File

@ -0,0 +1,86 @@
/* ScummVM - Graphic Adventure Engine
*
* ScummVM is the legal property of its developers, whose names
* are too numerous to list here. Please refer to the COPYRIGHT
* file distributed with this source distribution.
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*
*/
#ifndef HPL_VERTEXBUFFER_TGL_H
#define HPL_VERTEXBUFFER_TGL_H
#include "hpl1/engine/graphics/VertexBuffer.h"
namespace hpl {
class VertexBufferTGL : public iVertexBuffer {
public:
VertexBufferTGL(iLowLevelGraphics *apLowLevelGraphics, tVertexFlag aFlags,
eVertexBufferDrawType aDrawType, eVertexBufferUsageType aUsageType,
int alReserveVtxSize, int alReserveIdxSize);
~VertexBufferTGL();
void AddVertex(tVertexFlag aType, const cVector3f &avVtx);
void AddColor(tVertexFlag aType, const cColor &aColor);
void AddIndex(unsigned int alIndex);
bool Compile(tVertexCompileFlag aFlags);
void UpdateData(tVertexFlag aTypes, bool abIndices);
void CreateShadowDouble(bool abUpdateData);
void Transform(const cMatrixf &mtxTransform);
void Draw(eVertexBufferDrawType aDrawType);
void DrawIndices(unsigned int *apIndices, int alCount,
eVertexBufferDrawType aDrawType = eVertexBufferDrawType_LastEnum);
void Bind();
void UnBind();
iVertexBuffer *CreateCopy(eVertexBufferUsageType aUsageType);
cBoundingVolume CreateBoundingVolume();
float *GetArray(tVertexFlag aType);
unsigned int *GetIndices();
void ResizeArray(tVertexFlag aType, int alSize);
void ResizeIndices(int alSize);
// For debugging purposes
int GetVertexNum();
int GetIndexNum();
cVector3f GetVector3(tVertexFlag aType, unsigned alIdx);
cVector3f GetVector4(tVertexFlag aType, unsigned alIdx);
cColor GetColor(tVertexFlag aType, unsigned alIdx);
unsigned int GetIndex(tVertexFlag aType, unsigned alIdx);
private:
void SetVertexStates(tVertexFlag aFlags);
tFloatVec mvVertexArray[klNumOfVertexFlags];
tUIntVec mvIndexArray;
bool mbTangents;
bool mbHasShadowDouble;
};
} // namespace hpl
#endif // HPL_RENDERER3D_OGL_H

View File

@ -98,6 +98,9 @@ MODULE_OBJS := \
engine/impl/CollideShapeNewton.o \
engine/impl/KeyboardSDL.o \
engine/impl/LowLevelGraphicsSDL.o \
engine/impl/low_level_graphics_tgl.o \
engine/impl/texture_tgl.o \
engine/impl/vertex_buffer_tgl.o \
engine/impl/LowLevelInputSDL.o \
engine/impl/LowLevelPhysicsNewton.o \
engine/impl/LowLevelSoundOpenAL.o \

View File

@ -261,7 +261,7 @@ void GLContext::init(int screenW, int screenH, Graphics::PixelFormat pixelFormat
// color mask
color_mask_red = color_mask_green = color_mask_blue = color_mask_alpha = true;
const int kDrawCallMemory = 5 * 1024 * 1024;
const size_t kDrawCallMemory = 1024 * 1024 * 1024;
_currentAllocatorIndex = 0;
_drawCallAllocator[0].initialize(kDrawCallMemory);