28#ifndef HPL_LOWLEVELGRAPHICS_SDL_H
29#define HPL_LOWLEVELGRAPHICS_SDL_H
31#include "common/ptr.h"
32#include "graphics/pixelformat.h"
33#include "graphics/surface.h"
34#include "hpl1/engine/graphics/LowLevelGraphics.h"
35#include "hpl1/engine/math/MathTypes.h"
36#include "hpl1/opengl.h"
44GLenum TextureTargetToGL(eTextureTarget target);
48class cLowLevelGraphicsSDL :
public iLowLevelGraphics {
50 cLowLevelGraphicsSDL();
51 ~cLowLevelGraphicsSDL();
53 bool Init(
int alWidth,
int alHeight,
int alBpp,
int abFullscreen,
int alMultisampling,
54 const tString &asWindowCaption);
56 int GetCaps(eGraphicCaps aType)
const;
58 void ShowCursor(
bool abX);
60 void SetMultisamplingActive(
bool abX);
62 void SetGammaCorrection(
float afX);
63 float GetGammaCorrection();
65 int GetMultisampling() {
return mlMultisampling; }
67 void SetClipPlane(
int alIdx,
const cPlanef &aPlane);
68 cPlanef GetClipPlane(
int alIdx,
const cPlanef &aPlane);
69 void SetClipPlaneActive(
int alIdx,
bool abX);
71 cVector2f GetScreenSize();
72 cVector2f GetVirtualSize();
73 void SetVirtualSize(cVector2f avSize);
75 Bitmap2D *CreateBitmap2D(
const cVector2l &avSize);
76 FontData *CreateFontData(
const tString &asName);
78 iTexture *CreateTexture(
bool abUseMipMaps, eTextureType aType, eTextureTarget aTarget);
79 iTexture *CreateTexture(
const tString &asName,
bool abUseMipMaps, eTextureType aType, eTextureTarget aTarget);
80 iTexture *CreateTexture(Bitmap2D *apBmp,
bool abUseMipMaps, eTextureType aType, eTextureTarget aTarget);
81 iTexture *CreateTexture(
const cVector2l &avSize,
int alBpp, cColor aFillCol,
82 bool abUseMipMaps, eTextureType aType, eTextureTarget aTarget);
86 iGpuProgram *CreateGpuProgram(
const tString &vertex,
const tString &fragment);
88 void SaveScreenToBMP(
const tString &asFile);
92 void PushMatrix(eMatrix aMtxType);
93 void PopMatrix(eMatrix aMtxType);
94 void SetIdentityMatrix(eMatrix aMtxType);
96 void SetMatrix(eMatrix aMtxType,
const cMatrixf &a_mtxA);
98 void TranslateMatrix(eMatrix aMtxType,
const cVector3f &avPos);
99 void RotateMatrix(eMatrix aMtxType,
const cVector3f &avRot);
100 void ScaleMatrix(eMatrix aMtxType,
const cVector3f &avScale);
102 void SetOrthoProjection(
const cVector2f &avSize,
float afMin,
float afMax);
107 iOcclusionQuery *CreateOcclusionQuery();
108 void DestroyOcclusionQuery(iOcclusionQuery *apQuery);
113 void SetClearColor(
const cColor &aCol);
114 void SetClearDepth(
float afDepth);
115 void SetClearStencil(
int alVal);
117 void SetClearColorActive(
bool abX);
118 void SetClearDepthActive(
bool abX);
119 void SetClearStencilActive(
bool abX);
121 void SetColorWriteActive(
bool abR,
bool abG,
bool abB,
bool abA);
122 void SetDepthWriteActive(
bool abX);
124 void SetCullActive(
bool abX);
125 void SetCullMode(eCullMode aMode);
128 void SetDepthTestActive(
bool abX);
129 void SetDepthTestFunc(eDepthTestFunc aFunc);
132 void SetAlphaTestActive(
bool abX);
133 void SetAlphaTestFunc(eAlphaTestFunc aFunc,
float afRef);
136 void SetStencilActive(
bool abX);
141 void SetStencil(eStencilFunc aFunc,
int alRef,
unsigned int aMask,
142 eStencilOp aFailOp, eStencilOp aZFailOp, eStencilOp aZPassOp);
143 void SetStencilTwoSide(eStencilFunc aFrontFunc, eStencilFunc aBackFunc,
144 int alRef,
unsigned int aMask,
145 eStencilOp aFrontFailOp, eStencilOp aFrontZFailOp, eStencilOp aFrontZPassOp,
146 eStencilOp aBackFailOp, eStencilOp aBackZFailOp, eStencilOp aBackZPassOp);
147 void SetStencilTwoSide(
bool abX);
150 void SetScissorActive(
bool abX);
151 void SetScissorRect(
const cRect2l &aRect);
154 void SetBlendActive(
bool abX);
155 void SetBlendFunc(eBlendFunc aSrcFactor, eBlendFunc aDestFactor);
156 void SetBlendFuncSeparate(eBlendFunc aSrcFactorColor, eBlendFunc aDestFactorColor,
157 eBlendFunc aSrcFactorAlpha, eBlendFunc aDestFactorAlpha);
160 void SetTexture(
unsigned int alUnit, iTexture *apTex);
161 void SetActiveTextureUnit(
unsigned int alUnit);
162 void SetTextureEnv(eTextureParam aParam,
int alVal);
163 void SetTextureConstantColor(
const cColor &color);
165 void SetColor(
const cColor &aColor);
168 iVertexBuffer *CreateVertexBuffer(tVertexFlag aFlags, eVertexBufferDrawType aDrawType,
169 eVertexBufferUsageType aUsageType,
170 int alReserveVtxSize = 0,
int alReserveIdxSize = 0);
172 void DrawRect(
const cVector2f &avPos,
const cVector2f &avSize,
float afZ);
174 void DrawTri(
const tVertexVec &avVtx);
175 void DrawTri(
const cVertex *avVtx);
177 void DrawQuad(
const tVertexVec &avVtx);
178 void DrawQuad(
const tVertexVec &avVtx,
const cColor aCol);
179 void DrawQuad(
const tVertexVec &avVtx,
const float afZ);
180 void DrawQuad(
const tVertexVec &avVtx,
const float afZ,
const cColor &aCol);
181 void DrawQuadMultiTex(
const tVertexVec &avVtx,
const tVector3fVec &avExtraUvs);
183 void AddVertexToBatch(
const cVertex &apVtx);
184 void AddVertexToBatch(
const cVertex *apVtx,
const cVector3f *avTransform);
185 void AddVertexToBatch(
const cVertex *apVtx,
const cMatrixf *aMtx);
187 void AddVertexToBatch_Size2D(
const cVertex *apVtx,
const cVector3f *avTransform,
188 const cColor *apCol,
const float &mfW,
const float &mfH);
190 void AddVertexToBatch_Raw(
const cVector3f &avPos,
const cColor &aColor,
191 const cVector3f &avTex);
193 void AddTexCoordToBatch(
unsigned int alUnit,
const cVector3f *apCoord);
194 void SetBatchTextureUnitActive(
unsigned int alUnit,
bool abActive);
196 void AddIndexToBatch(
int alIndex);
198 void FlushTriBatch(tVtxBatchFlag aTypeFlags,
bool abAutoClear =
true);
199 void FlushQuadBatch(tVtxBatchFlag aTypeFlags,
bool abAutoClear =
true);
203 void DrawLine(
const cVector3f &avBegin,
const cVector3f &avEnd, cColor aCol);
204 void DrawBoxMaxMin(
const cVector3f &avMax,
const cVector3f &avMin, cColor aCol);
205 void DrawSphere(
const cVector3f &avPos,
float afRadius, cColor aCol);
207 void DrawLine2D(
const cVector2f &avBegin,
const cVector2f &avEnd,
float afZ, cColor aCol);
208 void DrawLineRect2D(
const cRect2f &aRect,
float afZ, cColor aCol);
209 void DrawLineCircle2D(
const cVector2f &avCenter,
float afRadius,
float afZ, cColor aCol);
211 void DrawFilledRect2D(
const cRect2f &aRect,
float afZ, cColor aCol);
214 void CopyContextToTexure(iTexture *apTex,
const cVector2l &avPos,
215 const cVector2l &avSize,
const cVector2l &avTexOffset = 0);
216 void SetRenderTarget(iTexture *pTex);
217 bool RenderTargetHasZBuffer();
218 void FlushRenderTarget();
220 void FlushRendering();
227 GLenum GetGLTextureTargetEnum(eTextureTarget aType);
230 cVector2l mvScreenSize;
231 cVector2f mvVirtualSize;
237 float mfGammaCorrection;
240 cPlanef mvClipPlanes[kMaxClipPlanes];
248 float *mpVertexArray;
249 unsigned int mlVertexCount;
250 unsigned int *mpIndexArray;
251 unsigned int mlIndexCount;
253 unsigned int mlBatchStride;
255 float *mpTexCoordArray[MAX_TEXTUREUNITS];
256 bool mbTexCoordArrayActive[MAX_TEXTUREUNITS];
257 unsigned int mlTexCoordArrayCount[MAX_TEXTUREUNITS];
259 unsigned int mlBatchArraySize;
267 iTexture *mpRenderTarget;
270 iTexture *mpCurrentTexture[MAX_TEXTUREUNITS];
272 iTexture *_screenBuffer;
273 iGpuProgram *_gammaCorrectionProgram;
279 void CheckMultisampleCaps();
281 void applyGammaCorrection();
284 void SetUpBatchArrays();
287 GLenum GetGLDepthTestFuncEnum(eDepthTestFunc aType);
290 GLenum GetGLAlphaTestFuncEnum(eAlphaTestFunc aType);
293 GLenum GetGLStencilFuncEnum(eStencilFunc aType);
294 GLenum GetGLStencilOpEnum(eStencilOp aType);
297 void SetMatrixMode(eMatrix mType);
300 GLenum GetGLTextureParamEnum(eTextureParam aType);
301 GLenum GetGLTextureOpEnum(eTextureOp aType);
302 GLenum GetGLTextureFuncEnum(eTextureFunc aType);
303 GLenum GetGLTextureSourceEnum(eTextureSource aType);
306 GLenum GetGLBlendEnum(eBlendFunc aType);
309 void SetVtxBatchStates(tVtxBatchFlag flags);