ScummVM API documentation
LowLevelGraphics.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_H
29 #define HPL_LOWLEVELGRAPHICS_H
30 
31 #include "hpl1/engine/graphics/GPUProgram.h"
32 #include "hpl1/engine/graphics/GraphicsTypes.h"
33 #include "hpl1/engine/graphics/Texture.h"
34 #include "hpl1/engine/graphics/VertexBuffer.h"
35 #include "hpl1/engine/graphics/bitmap2D.h"
36 #include "hpl1/engine/math/MathTypes.h"
37 #include "hpl1/engine/system/SystemTypes.h"
38 
39 namespace hpl {
40 
41 enum eBlendFunc {
42  eBlendFunc_Zero,
43  eBlendFunc_One,
44  eBlendFunc_SrcColor,
45  eBlendFunc_OneMinusSrcColor,
46  eBlendFunc_DestColor,
47  eBlendFunc_OneMinusDestColor,
48  eBlendFunc_SrcAlpha,
49  eBlendFunc_OneMinusSrcAlpha,
50  eBlendFunc_DestAlpha,
51  eBlendFunc_OneMinusDestAlpha,
52  eBlendFunc_SrcAlphaSaturate,
53  eBlendFunc_LastEnum
54 };
55 
56 enum eTextureParam {
57  eTextureParam_ColorFunc,
58  eTextureParam_AlphaFunc,
59  eTextureParam_ColorSource0,
60  eTextureParam_ColorSource1,
61  eTextureParam_ColorSource2,
62  eTextureParam_AlphaSource0,
63  eTextureParam_AlphaSource1,
64  eTextureParam_AlphaSource2,
65  eTextureParam_ColorOp0,
66  eTextureParam_ColorOp1,
67  eTextureParam_ColorOp2,
68  eTextureParam_AlphaOp0,
69  eTextureParam_AlphaOp1,
70  eTextureParam_AlphaOp2,
71  eTextureParam_ColorScale,
72  eTextureParam_AlphaScale,
73  eTextureParam_LastEnum
74 };
75 
76 enum eTextureOp {
77  eTextureOp_Color,
78  eTextureOp_OneMinusColor,
79  eTextureOp_Alpha,
80  eTextureOp_OneMinusAlpha,
81  eTextureOp_LasEnum
82 };
83 
84 enum eTextureSource {
85  eTextureSource_Texture,
86  eTextureSource_Constant,
87  eTextureSource_Primary,
88  eTextureSource_Previous,
89  eTextureSource_LastEnum
90 };
91 
92 enum eTextureFunc {
93  eTextureFunc_Modulate,
94  eTextureFunc_Replace,
95  eTextureFunc_Add,
96  eTextureFunc_Subtract,
97  eTextureFunc_AddSigned,
98  eTextureFunc_Interpolate,
99  eTextureFunc_Dot3RGB,
100  eTextureFunc_Dot3RGBA,
101  eTextureFunc_LastEnum
102 };
103 
104 enum eStencilFunc {
105  eStencilFunc_Never,
106  eStencilFunc_Less,
107  eStencilFunc_LessOrEqual,
108  eStencilFunc_Greater,
109  eStencilFunc_GreaterOrEqual,
110  eStencilFunc_Equal,
111  eStencilFunc_NotEqual,
112  eStencilFunc_Always,
113  eStencilFunc_LastEnum
114 };
115 
116 enum eStencilFace {
117  eStencilFace_Front,
118  eStencilFace_Back,
119  eStencilFace_LastEnum,
120 };
121 
122 enum eDepthTestFunc {
123  eDepthTestFunc_Never,
124  eDepthTestFunc_Less,
125  eDepthTestFunc_LessOrEqual,
126  eDepthTestFunc_Greater,
127  eDepthTestFunc_GreaterOrEqual,
128  eDepthTestFunc_Equal,
129  eDepthTestFunc_NotEqual,
130  eDepthTestFunc_Always,
131  eDepthTestFunc_LastEnum
132 };
133 
134 enum eAlphaTestFunc {
135  eAlphaTestFunc_Never,
136  eAlphaTestFunc_Less,
137  eAlphaTestFunc_LessOrEqual,
138  eAlphaTestFunc_Greater,
139  eAlphaTestFunc_GreaterOrEqual,
140  eAlphaTestFunc_Equal,
141  eAlphaTestFunc_NotEqual,
142  eAlphaTestFunc_Always,
143  eAlphaTestFunc_LastEnum
144 };
145 
146 enum eStencilOp {
147  eStencilOp_Keep,
148  eStencilOp_Zero,
149  eStencilOp_Replace,
150  eStencilOp_Increment,
151  eStencilOp_Decrement,
152  eStencilOp_Invert,
153  eStencilOp_IncrementWrap,
154  eStencilOp_DecrementWrap,
155  eStencilOp_LastEnum
156 };
157 
158 enum eCullMode {
159  eCullMode_Clockwise,
160  eCullMode_CounterClockwise,
161  eCullMode_LastEnum
162 };
163 
164 enum eGraphicCaps {
165  eGraphicCaps_TextureTargetRectangle,
166  eGraphicCaps_VertexBufferObject,
167  eGraphicCaps_TwoSideStencil,
168 
169  eGraphicCaps_MaxTextureImageUnits,
170  eGraphicCaps_MaxTextureCoordUnits,
171 
172  eGraphicCaps_AnisotropicFiltering,
173  eGraphicCaps_MaxAnisotropicFiltering,
174 
175  eGraphicCaps_Multisampling,
176 
177  eGraphicCaps_GL_GpuPrograms,
178  eGraphicCaps_GL_NVRegisterCombiners,
179  eGraphicCaps_GL_NVRegisterCombiners_MaxStages,
180  eGraphicCaps_GL_BlendFunctionSeparate,
181  eGraphicCaps_GL_MultiTexture,
182 
183  eGraphicCaps_LastEnum
184 };
185 
186 typedef tFlag tVtxBatchFlag;
187 
188 #define eVtxBatchFlag_Normal (0x00000001)
189 #define eVtxBatchFlag_Position (0x00000002)
190 #define eVtxBatchFlag_Color0 (0x00000004)
191 #define eVtxBatchFlag_Texture0 (0x00000008)
192 #define eVtxBatchFlag_Texture1 (0x00000010)
193 #define eVtxBatchFlag_Texture2 (0x00000020)
194 
195 #define kMaxClipPlanes (6)
196 
197 class FontData;
198 class iOcclusionQuery;
199 
201 public:
202  virtual ~iLowLevelGraphics() {}
212  virtual bool Init(int alWidth, int alHeight, int alBpp, int abFullscreen, int alMultisampling,
213  const tString &asWindowCaption) = 0;
214 
220  virtual int GetCaps(eGraphicCaps aType) const = 0;
225  virtual void ShowCursor(bool abX) = 0;
226 
227  virtual int GetMultisampling() = 0;
232  virtual cVector2f GetScreenSize() = 0;
233  virtual cVector2f GetVirtualSize() = 0;
238  virtual void SetVirtualSize(cVector2f avSize) = 0;
239 
240  virtual void SetMultisamplingActive(bool abX) = 0;
241 
242  virtual void SetGammaCorrection(float afX) = 0;
243  virtual float GetGammaCorrection() = 0;
244 
245  virtual void SetClipPlane(int alIdx, const cPlanef &aPlane) = 0;
246  virtual cPlanef GetClipPlane(int alIdx, const cPlanef &aPlane) = 0;
247  virtual void SetClipPlaneActive(int alIdx, bool abX) = 0;
248 
249  virtual Bitmap2D *CreateBitmap2D(const cVector2l &avSize) = 0;
250  virtual FontData *CreateFontData(const tString &asName) = 0;
251 
252  virtual iTexture *CreateTexture(bool abUseMipMaps, eTextureType aType, eTextureTarget aTarget) = 0;
253  virtual iTexture *CreateTexture(const tString &asName, bool abUseMipMaps, eTextureType aType, eTextureTarget aTarget) = 0;
254  virtual iTexture *CreateTexture(Bitmap2D *apBmp, bool abUseMipMaps, eTextureType aType,
255  eTextureTarget aTarget) = 0;
256  virtual iTexture *CreateTexture(const cVector2l &avSize, int alBpp, cColor aFillCol,
257  bool abUseMipMaps, eTextureType aType, eTextureTarget aTarget) = 0;
258 
259  virtual Graphics::PixelFormat *GetPixelFormat() = 0;
260 
261  virtual iGpuProgram *CreateGpuProgram(const tString &vertex, const tString &fragment) = 0;
262 
263  // TODO: Kinda quick and diry, better to have a screen to Bitmap.
264  // and then a save as in the Bitmap.
265  virtual void SaveScreenToBMP(const tString &asFile) = 0;
266 
268 
269  virtual void PushMatrix(eMatrix aMtxType) = 0;
270  virtual void PopMatrix(eMatrix aMtxType) = 0;
271  virtual void SetIdentityMatrix(eMatrix aMtxType) = 0;
272 
273  virtual void SetMatrix(eMatrix aMtxType, const cMatrixf &a_mtxA) = 0;
274 
275  virtual void TranslateMatrix(eMatrix aMtxType, const cVector3f &avPos) = 0;
276  virtual void RotateMatrix(eMatrix aMtxType, const cVector3f &avRot) = 0;
277  virtual void ScaleMatrix(eMatrix aMtxType, const cVector3f &avScale) = 0;
278 
279  virtual void SetOrthoProjection(const cVector2f &avSize, float afMin, float afMax) = 0;
280 
282 
283  // OCCLUSION
284  virtual iOcclusionQuery *CreateOcclusionQuery() = 0;
285  virtual void DestroyOcclusionQuery(iOcclusionQuery *apQuery) = 0;
286 
287  // CLEARING THE FRAMEBUFFER
288  virtual void ClearScreen() = 0;
289 
290  virtual void SetClearColor(const cColor &aCol) = 0;
291  virtual void SetClearDepth(float afDepth) = 0;
292  virtual void SetClearStencil(int alVal) = 0;
293 
294  virtual void SetClearColorActive(bool abX) = 0;
295  virtual void SetClearDepthActive(bool abX) = 0;
296  virtual void SetClearStencilActive(bool abX) = 0;
297 
298  virtual void SetColorWriteActive(bool abR, bool abG, bool abB, bool abA) = 0;
299  virtual void SetDepthWriteActive(bool abX) = 0;
300 
301  virtual void SetCullActive(bool abX) = 0;
302  virtual void SetCullMode(eCullMode aMode) = 0;
303 
304  // DEPTH
305  virtual void SetDepthTestActive(bool abX) = 0;
306  virtual void SetDepthTestFunc(eDepthTestFunc aFunc) = 0;
307 
308  // ALPHA
309  virtual void SetAlphaTestActive(bool abX) = 0;
310  virtual void SetAlphaTestFunc(eAlphaTestFunc aFunc, float afRef) = 0;
311 
312  // STENCIL
313  virtual void SetStencilActive(bool abX) = 0;
314  /*virtual void SetStencilTwoSideActive(bool abX)=0;
315  virtual void SetStencilFace(eStencilFace aFace)=0;
316  virtual void SetStencilFunc(eStencilFunc aFunc,int alRef, unsigned int aMask)=0;
317  virtual void SetStencilOp(eStencilOp aFailOp,eStencilOp aZFailOp,eStencilOp aZPassOp)=0;*/
318  virtual void SetStencil(eStencilFunc aFunc, int alRef, unsigned int aMask,
319  eStencilOp aFailOp, eStencilOp aZFailOp, eStencilOp aZPassOp) = 0;
320  virtual void SetStencilTwoSide(eStencilFunc aFrontFunc, eStencilFunc aBackFunc,
321  int alRef, unsigned int aMask,
322  eStencilOp aFrontFailOp, eStencilOp aFrontZFailOp, eStencilOp aFrontZPassOp,
323  eStencilOp aBackFailOp, eStencilOp aBackZFailOp, eStencilOp aBackZPassOp) = 0;
324  virtual void SetStencilTwoSide(bool abX) = 0;
325 
326  // SCISSOR
327  virtual void SetScissorActive(bool abX) = 0;
328  virtual void SetScissorRect(const cRect2l &aRect) = 0;
329 
330  // TEXTURE
331  virtual void SetTexture(unsigned int alUnit, iTexture *apTex) = 0;
332  virtual void SetActiveTextureUnit(unsigned int alUnit) = 0;
333  virtual void SetTextureEnv(eTextureParam aParam, int alVal) = 0;
334  virtual void SetTextureConstantColor(const cColor &aColor) = 0;
335 
336  // COLOR
337  virtual void SetColor(const cColor &aColor) = 0;
338 
339  // BLENDING
340  virtual void SetBlendActive(bool abX) = 0;
341  virtual void SetBlendFunc(eBlendFunc aSrcFactor, eBlendFunc aDestFactor) = 0;
342  virtual void SetBlendFuncSeparate(eBlendFunc aSrcFactorColor, eBlendFunc aDestFactorColor,
343  eBlendFunc aSrcFactorAlpha, eBlendFunc aDestFactorAlpha) = 0;
344 
345  // POLYGONS
346  virtual iVertexBuffer *CreateVertexBuffer(tVertexFlag aFlags, eVertexBufferDrawType aDrawType,
347  eVertexBufferUsageType aUsageType,
348  int alReserveVtxSize = 0, int alReserveIdxSize = 0) = 0;
349 
350  virtual void DrawRect(const cVector2f &avPos, const cVector2f &avSize, float afZ) = 0;
351 
352  virtual void DrawTri(const tVertexVec &avVtx) = 0;
353  virtual void DrawTri(const cVertex *avVtx) = 0;
354 
355  virtual void DrawQuad(const tVertexVec &avVtx) = 0;
356  virtual void DrawQuad(const tVertexVec &avVtx, const cColor aCol) = 0;
357  virtual void DrawQuad(const tVertexVec &avVtx, const float afZ) = 0;
358  virtual void DrawQuad(const tVertexVec &avVtx, const float afZ, const cColor &aCol) = 0;
359  virtual void DrawQuadMultiTex(const tVertexVec &avVtx, const tVector3fVec &avExtraUvs) = 0;
360 
361  // VERTEX BATCHER
362  virtual void AddVertexToBatch(const cVertex &apVtx) = 0;
363  virtual void AddVertexToBatch(const cVertex *apVtx, const cVector3f *avTransform) = 0;
364  virtual void AddVertexToBatch(const cVertex *apVtx, const cMatrixf *aMtx) = 0;
365 
366  virtual void AddVertexToBatch_Size2D(const cVertex *apVtx, const cVector3f *avTransform,
367  const cColor *apCol, const float &mfW, const float &mfH) = 0;
368 
369  virtual void AddVertexToBatch_Raw(const cVector3f &avPos, const cColor &aColor,
370  const cVector3f &avTex) = 0;
371 
372  virtual void AddIndexToBatch(int alIndex) = 0;
373 
374  virtual void AddTexCoordToBatch(unsigned int alUnit, const cVector3f *apCoord) = 0;
375  virtual void SetBatchTextureUnitActive(unsigned int alUnit, bool abActive) = 0;
376 
377  // Add more ways to add Vertex to the batch?
378  // Index array, vtxArray, etc perhaps?
379 
380  virtual void FlushTriBatch(tVtxBatchFlag aTypeFlags, bool abAutoClear = true) = 0;
381  virtual void FlushQuadBatch(tVtxBatchFlag aTypeFlags, bool abAutoClear = true) = 0;
382  virtual void ClearBatch() = 0;
383 
384  // some primitive:
385  virtual void DrawLine(const cVector3f &avBegin, const cVector3f &avEnd, cColor aCol) = 0;
386  virtual void DrawBoxMaxMin(const cVector3f &avMax, const cVector3f &avMin, cColor aCol) = 0;
387  virtual void DrawSphere(const cVector3f &avPos, float afRadius, cColor aCol) = 0;
388 
389  virtual void DrawLine2D(const cVector2f &avBegin, const cVector2f &avEnd, float afZ, cColor aCol) = 0;
390  virtual void DrawLineRect2D(const cRect2f &aRect, float afZ, cColor aCol) = 0;
391  virtual void DrawLineCircle2D(const cVector2f &avCenter, float afRadius, float afZ, cColor aCol) = 0;
392 
393  virtual void DrawFilledRect2D(const cRect2f &aRect, float afZ, cColor aCol) = 0;
394  // GENERAL
399  virtual void SetRenderTarget(iTexture *pTex) = 0;
404  virtual bool RenderTargetHasZBuffer() = 0;
409  virtual void FlushRenderTarget() = 0;
410 
418  virtual void CopyContextToTexure(iTexture *apTex, const cVector2l &avPos,
419  const cVector2l &avSize, const cVector2l &avTexOffset = 0) = 0;
420  virtual void FlushRendering() = 0;
421  virtual void SwapBuffers() = 0;
422 };
423 
424 } // namespace hpl
425 
426 #endif // HPL_LOWLEVELGRAPHICS_H
Definition: AI.h:36
Definition: str.h:59
Definition: VertexBuffer.h:90
Definition: pixelformat.h:138
virtual void FlushRenderTarget()=0
Definition: bitmap2D.h:42
Definition: font_data.h:67
Definition: Texture.h:88
virtual bool RenderTargetHasZBuffer()=0
Definition: GraphicsTypes.h:137
virtual bool Init(int alWidth, int alHeight, int alBpp, int abFullscreen, int alMultisampling, const tString &asWindowCaption)=0
virtual cVector2f GetScreenSize()=0
Definition: OcclusionQuery.h:33
Definition: Color.h:37
virtual void SetVirtualSize(cVector2f avSize)=0
virtual void CopyContextToTexure(iTexture *apTex, const cVector2l &avPos, const cVector2l &avSize, const cVector2l &avTexOffset=0)=0
virtual void SetRenderTarget(iTexture *pTex)=0
Definition: LowLevelGraphics.h:200
virtual int GetCaps(eGraphicCaps aType) const =0
Definition: GPUProgram.h:62
virtual void ShowCursor(bool abX)=0