ScummVM API documentation
LowLevelGraphicsSDL.h
1/* ScummVM - Graphic Adventure Engine
2 *
3 * ScummVM is the legal property of its developers, whose names
4 * are too numerous to list here. Please refer to the COPYRIGHT
5 * file distributed with this source distribution.
6 *
7 * This program is free software: you can redistribute it and/or modify
8 * it under the terms of the GNU General Public License as published by
9 * the Free Software Foundation, either version 3 of the License, or
10 * (at your option) any later version.
11 *
12 * This program is distributed in the hope that it will be useful,
13 * but WITHOUT ANY WARRANTY; without even the implied warranty of
14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 * GNU General Public License for more details.
16 *
17 * You should have received a copy of the GNU General Public License
18 * along with this program. If not, see <http://www.gnu.org/licenses/>.
19 *
20 */
21
22/*
23 * Copyright (C) 2006-2010 - Frictional Games
24 *
25 * This file is part of HPL1 Engine.
26 */
27
28#ifndef HPL_LOWLEVELGRAPHICS_SDL_H
29#define HPL_LOWLEVELGRAPHICS_SDL_H
30
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"
37
38#ifdef HPL1_USE_OPENGL
39
40namespace hpl {
41
42//-------------------------------------------------
43
44GLenum TextureTargetToGL(eTextureTarget target);
45
46//-------------------------------------------------
47
48class cLowLevelGraphicsSDL : public iLowLevelGraphics {
49public:
50 cLowLevelGraphicsSDL();
51 ~cLowLevelGraphicsSDL();
52
53 bool Init(int alWidth, int alHeight, int alBpp, int abFullscreen, int alMultisampling,
54 const tString &asWindowCaption);
55
56 int GetCaps(eGraphicCaps aType) const;
57
58 void ShowCursor(bool abX);
59
60 void SetMultisamplingActive(bool abX);
61
62 void SetGammaCorrection(float afX);
63 float GetGammaCorrection();
64
65 int GetMultisampling() { return mlMultisampling; }
66
67 void SetClipPlane(int alIdx, const cPlanef &aPlane);
68 cPlanef GetClipPlane(int alIdx, const cPlanef &aPlane);
69 void SetClipPlaneActive(int alIdx, bool abX);
70
71 cVector2f GetScreenSize();
72 cVector2f GetVirtualSize();
73 void SetVirtualSize(cVector2f avSize);
74
75 Bitmap2D *CreateBitmap2D(const cVector2l &avSize);
76 FontData *CreateFontData(const tString &asName);
77
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);
83
84 Graphics::PixelFormat *GetPixelFormat();
85
86 iGpuProgram *CreateGpuProgram(const tString &vertex, const tString &fragment);
87
88 void SaveScreenToBMP(const tString &asFile);
89
91
92 void PushMatrix(eMatrix aMtxType);
93 void PopMatrix(eMatrix aMtxType);
94 void SetIdentityMatrix(eMatrix aMtxType);
95
96 void SetMatrix(eMatrix aMtxType, const cMatrixf &a_mtxA);
97
98 void TranslateMatrix(eMatrix aMtxType, const cVector3f &avPos);
99 void RotateMatrix(eMatrix aMtxType, const cVector3f &avRot);
100 void ScaleMatrix(eMatrix aMtxType, const cVector3f &avScale);
101
102 void SetOrthoProjection(const cVector2f &avSize, float afMin, float afMax);
103
105
106 // OCCLUSION
107 iOcclusionQuery *CreateOcclusionQuery();
108 void DestroyOcclusionQuery(iOcclusionQuery *apQuery);
109
110 // CLEARING THE FRAMEBUFFER
111 void ClearScreen();
112
113 void SetClearColor(const cColor &aCol);
114 void SetClearDepth(float afDepth);
115 void SetClearStencil(int alVal);
116
117 void SetClearColorActive(bool abX);
118 void SetClearDepthActive(bool abX);
119 void SetClearStencilActive(bool abX);
120
121 void SetColorWriteActive(bool abR, bool abG, bool abB, bool abA);
122 void SetDepthWriteActive(bool abX);
123
124 void SetCullActive(bool abX);
125 void SetCullMode(eCullMode aMode);
126
127 // DEPTH
128 void SetDepthTestActive(bool abX);
129 void SetDepthTestFunc(eDepthTestFunc aFunc);
130
131 // ALPHA
132 void SetAlphaTestActive(bool abX);
133 void SetAlphaTestFunc(eAlphaTestFunc aFunc, float afRef);
134
135 // STENCIL
136 void SetStencilActive(bool abX);
137 /*void SetStencilTwoSideActive(bool abX);
138 void SetStencilFace(eStencilFace aFace);
139 void SetStencilFunc(eStencilFunc aFunc,int alRef, unsigned int aMask);
140 void SetStencilOp(eStencilOp aFailOp,eStencilOp aZFailOp,eStencilOp aZPassOp);*/
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);
148
149 // SCISSOR
150 void SetScissorActive(bool abX);
151 void SetScissorRect(const cRect2l &aRect);
152
153 // BLENDING
154 void SetBlendActive(bool abX);
155 void SetBlendFunc(eBlendFunc aSrcFactor, eBlendFunc aDestFactor);
156 void SetBlendFuncSeparate(eBlendFunc aSrcFactorColor, eBlendFunc aDestFactorColor,
157 eBlendFunc aSrcFactorAlpha, eBlendFunc aDestFactorAlpha);
158
159 // TEXTURE
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);
164
165 void SetColor(const cColor &aColor);
166
167 // POLYGONS
168 iVertexBuffer *CreateVertexBuffer(tVertexFlag aFlags, eVertexBufferDrawType aDrawType,
169 eVertexBufferUsageType aUsageType,
170 int alReserveVtxSize = 0, int alReserveIdxSize = 0);
171
172 void DrawRect(const cVector2f &avPos, const cVector2f &avSize, float afZ);
173
174 void DrawTri(const tVertexVec &avVtx);
175 void DrawTri(const cVertex *avVtx);
176
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);
182
183 void AddVertexToBatch(const cVertex &apVtx);
184 void AddVertexToBatch(const cVertex *apVtx, const cVector3f *avTransform);
185 void AddVertexToBatch(const cVertex *apVtx, const cMatrixf *aMtx);
186
187 void AddVertexToBatch_Size2D(const cVertex *apVtx, const cVector3f *avTransform,
188 const cColor *apCol, const float &mfW, const float &mfH);
189
190 void AddVertexToBatch_Raw(const cVector3f &avPos, const cColor &aColor,
191 const cVector3f &avTex);
192
193 void AddTexCoordToBatch(unsigned int alUnit, const cVector3f *apCoord);
194 void SetBatchTextureUnitActive(unsigned int alUnit, bool abActive);
195
196 void AddIndexToBatch(int alIndex);
197
198 void FlushTriBatch(tVtxBatchFlag aTypeFlags, bool abAutoClear = true);
199 void FlushQuadBatch(tVtxBatchFlag aTypeFlags, bool abAutoClear = true);
200 void ClearBatch();
201
202 // PRIMITIVES
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);
206
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);
210
211 void DrawFilledRect2D(const cRect2f &aRect, float afZ, cColor aCol);
212
213 // FRAMEBUFFER
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();
219
220 void FlushRendering();
221 void SwapBuffers();
222
224
225 void SetupGL();
226
227 GLenum GetGLTextureTargetEnum(eTextureTarget aType);
228
229private:
230 cVector2l mvScreenSize;
231 cVector2f mvVirtualSize;
232 int mlMultisampling;
233 int mlBpp;
234
235 // Gamma
236 // uint16 mvStartGammaArray[3][256];
237 float mfGammaCorrection;
238
239 // Clipping
240 cPlanef mvClipPlanes[kMaxClipPlanes];
241
242 // SDL Variables
243 // SDL_Surface *mpScreen;
244 Graphics::PixelFormat mpPixelFormat;
245
246 // Vertex Array variables
247 // The vertex arrays used:
248 float *mpVertexArray;
249 unsigned int mlVertexCount;
250 unsigned int *mpIndexArray;
251 unsigned int mlIndexCount;
252
253 unsigned int mlBatchStride;
254
255 float *mpTexCoordArray[MAX_TEXTUREUNITS];
256 bool mbTexCoordArrayActive[MAX_TEXTUREUNITS];
257 unsigned int mlTexCoordArrayCount[MAX_TEXTUREUNITS];
258
259 unsigned int mlBatchArraySize;
260
261 // Clearing
262 bool mbClearColor;
263 bool mbClearDepth;
264 bool mbClearStencil;
265
266 // Rendertarget variables
267 iTexture *mpRenderTarget;
268
269 // Texture
270 iTexture *mpCurrentTexture[MAX_TEXTUREUNITS];
271
272 iTexture *_screenBuffer;
273 iGpuProgram *_gammaCorrectionProgram;
274
275 // CG Compiler Variables
276 // CGcontext mCG_Context;
277
278 // Multisample
279 void CheckMultisampleCaps();
280
281 void applyGammaCorrection();
282
283 // Batch helper
284 void SetUpBatchArrays();
285
286 // Depth helper
287 GLenum GetGLDepthTestFuncEnum(eDepthTestFunc aType);
288
289 // Alpha Helper
290 GLenum GetGLAlphaTestFuncEnum(eAlphaTestFunc aType);
291
292 // Stencil helper
293 GLenum GetGLStencilFuncEnum(eStencilFunc aType);
294 GLenum GetGLStencilOpEnum(eStencilOp aType);
295
296 // Matrix Helper
297 void SetMatrixMode(eMatrix mType);
298
299 // Texture helper
300 GLenum GetGLTextureParamEnum(eTextureParam aType);
301 GLenum GetGLTextureOpEnum(eTextureOp aType);
302 GLenum GetGLTextureFuncEnum(eTextureFunc aType);
303 GLenum GetGLTextureSourceEnum(eTextureSource aType);
304
305 // Blend helper
306 GLenum GetGLBlendEnum(eBlendFunc aType);
307
308 // Vtx helper
309 void SetVtxBatchStates(tVtxBatchFlag flags);
310};
311
312} // namespace hpl
313
314#endif // HPL1_USE_OPENGL
315#endif // HPL_LOWLEVELGRAPHICS_SDL_H
Definition: pixelformat.h:138