gfxGLDevice.h
Engine/source/gfx/gl/gfxGLDevice.h
Classes:
class
Public Defines
define
GFXGL() static_cast<*>(())
Detailed Description
Public Defines
GFXGL() static_cast<*>(())
1 2//----------------------------------------------------------------------------- 3// Copyright (c) 2012 GarageGames, LLC 4// 5// Permission is hereby granted, free of charge, to any person obtaining a copy 6// of this software and associated documentation files (the "Software"), to 7// deal in the Software without restriction, including without limitation the 8// rights to use, copy, modify, merge, publish, distribute, sublicense, and/or 9// sell copies of the Software, and to permit persons to whom the Software is 10// furnished to do so, subject to the following conditions: 11// 12// The above copyright notice and this permission notice shall be included in 13// all copies or substantial portions of the Software. 14// 15// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 16// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 17// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 18// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 19// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING 20// FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS 21// IN THE SOFTWARE. 22//----------------------------------------------------------------------------- 23 24#ifndef _GFXGLDEVICE_H_ 25#define _GFXGLDEVICE_H_ 26 27#include "platform/platform.h" 28 29#include "gfx/gfxDevice.h" 30#include "gfx/gfxInit.h" 31 32#include "gfx/gl/tGL/tGL.h" 33 34#include "windowManager/platformWindow.h" 35#include "gfx/gfxFence.h" 36#include "gfx/gfxResource.h" 37#include "gfx/gl/gfxGLStateBlock.h" 38 39class GFXGLTextureArray; 40class GFXGLVertexBuffer; 41class GFXGLPrimitiveBuffer; 42class GFXGLTextureTarget; 43class GFXGLCubemap; 44class GFXGLCubemapArray; 45class GFXGLStateCache; 46class GFXGLVertexDecl; 47 48class GFXGLDevice : public GFXDevice 49{ 50public: 51 struct GLCapabilities 52 { 53 bool anisotropicFiltering; 54 bool bufferStorage; 55 bool textureStorage; 56 bool copyImage; 57 bool vertexAttributeBinding; 58 bool khrDebug; 59 bool extDebugMarker; 60 }; 61 GLCapabilities mCapabilities; 62 63 void zombify(); 64 void resurrect(); 65 GFXGLDevice(U32 adapterIndex); 66 virtual ~GFXGLDevice(); 67 68 static void enumerateAdapters( Vector<GFXAdapter*> &adapterList ); 69 static GFXDevice *createInstance( U32 adapterIndex ); 70 71 virtual void init( const GFXVideoMode &mode, PlatformWindow *window = NULL ); 72 73 virtual void activate() { } 74 virtual void deactivate() { } 75 virtual GFXAdapterType getAdapterType() { return OpenGL; } 76 77 virtual void enterDebugEvent(ColorI color, const char *name); 78 virtual void leaveDebugEvent(); 79 virtual void setDebugMarker(ColorI color, const char *name); 80 81 virtual void enumerateVideoModes(); 82 83 virtual U32 getTotalVideoMemory_GL_EXT(); 84 virtual U32 getTotalVideoMemory(); 85 86 virtual GFXCubemap * createCubemap(); 87 virtual GFXCubemapArray *createCubemapArray(); 88 virtual GFXTextureArray *createTextureArray(); 89 90 virtual F32 getFillConventionOffset() const { return 0.0f; } 91 92 93 ///@} 94 95 /// @name Render Target functions 96 /// @{ 97 98 /// 99 virtual GFXTextureTarget *allocRenderToTextureTarget(bool genMips = true); 100 virtual GFXWindowTarget *allocWindowTarget(PlatformWindow *window); 101 virtual void _updateRenderTargets(); 102 103 ///@} 104 105 /// @name Shader functions 106 /// @{ 107 virtual F32 getPixelShaderVersion() const { return mPixelShaderVersion; } 108 virtual void setPixelShaderVersion( F32 version ) { mPixelShaderVersion = version; } 109 110 virtual void setShader(GFXShader *shader, bool force = false); 111 112 /// @attention GL cannot check if the given format supports blending or filtering! 113 virtual GFXFormat selectSupportedFormat(GFXTextureProfile *profile, 114 const Vector<GFXFormat> &formats, bool texture, bool mustblend, bool mustfilter); 115 116 /// Returns the number of texture samplers that can be used in a shader rendering pass 117 virtual U32 getNumSamplers() const; 118 119 /// Returns the number of simultaneous render targets supported by the device. 120 virtual U32 getNumRenderTargets() const; 121 122 virtual GFXShader* createShader(); 123 //TODO: implement me! 124 virtual void copyResource(GFXTextureObject *pDst, GFXCubemap *pSrc, const U32 face); 125 virtual void clear( U32 flags, const LinearColorF& color, F32 z, U32 stencil ); 126 virtual void clearColorAttachment(const U32 attachment, const LinearColorF& color); 127 virtual bool beginSceneInternal(); 128 virtual void endSceneInternal(); 129 130 virtual void drawPrimitive( GFXPrimitiveType primType, U32 vertexStart, U32 primitiveCount ); 131 132 virtual void drawIndexedPrimitive( GFXPrimitiveType primType, 133 U32 startVertex, 134 U32 minIndex, 135 U32 numVerts, 136 U32 startIndex, 137 U32 primitiveCount ); 138 139 virtual void setClipRect( const RectI &rect ); 140 virtual const RectI &getClipRect() const { return mClip; } 141 142 virtual void preDestroy() { Parent::preDestroy(); } 143 144 virtual U32 getMaxDynamicVerts() { return GFX_MAX_DYNAMIC_VERTS; } 145 virtual U32 getMaxDynamicIndices() { return GFX_MAX_DYNAMIC_INDICES; } 146 147 GFXFence *createFence(); 148 149 GFXOcclusionQuery* createOcclusionQuery(); 150 151 GFXGLStateBlockRef getCurrentStateBlock() { return mCurrentGLStateBlock; } 152 153 virtual void setupGenericShaders( GenericShaderType type = GSColor ); 154 155 /// 156 bool supportsAnisotropic() const { return mSupportsAnisotropic; } 157 158 GFXGLStateCache* getOpenglCache() { return mOpenglStateCache; } 159 160 GFXTextureObject* getDefaultDepthTex() const; 161 162 /// Returns the number of vertex streams supported by the device. 163 const U32 getNumVertexStreams() const { return mNumVertexStream; } 164 165 bool glUseMap() const { return mUseGlMap; } 166 const char* interpretDebugResult(long result) { return "Not Implemented"; }; 167protected: 168 /// Called by GFXDevice to create a device specific stateblock 169 virtual GFXStateBlockRef createStateBlockInternal(const GFXStateBlockDesc& desc); 170 /// Called by GFXDevice to actually set a stateblock. 171 virtual void setStateBlockInternal(GFXStateBlock* block, bool force); 172 173 /// Called by base GFXDevice to actually set a const buffer 174 virtual void setShaderConstBufferInternal(GFXShaderConstBuffer* buffer); 175 176 virtual void setTextureInternal(U32 textureUnit, const GFXTextureObject*texture); 177 virtual void setCubemapInternal(U32 textureUnit, const GFXGLCubemap* texture); 178 virtual void setCubemapArrayInternal(U32 textureUnit, const GFXGLCubemapArray* texture); 179 virtual void setTextureArrayInternal(U32 textureUnit, const GFXGLTextureArray* texture); 180 181 /// @name State Initalization. 182 /// @{ 183 184 /// State initalization. This MUST BE CALLED in setVideoMode after the device 185 /// is created. 186 virtual void initStates() { } 187 188 virtual GFXVertexBuffer *allocVertexBuffer( U32 numVerts, 189 const GFXVertexFormat *vertexFormat, 190 U32 vertSize, 191 GFXBufferType bufferType, 192 void* data = NULL); 193 virtual GFXPrimitiveBuffer *allocPrimitiveBuffer( U32 numIndices, U32 numPrimitives, GFXBufferType bufferType, void* data = NULL ); 194 195 // NOTE: The GL device doesn't need a vertex declaration at 196 // this time, but we need to return something to keep the system 197 // from retrying to allocate one on every call. 198 virtual GFXVertexDecl* allocVertexDecl( const GFXVertexFormat *vertexFormat ); 199 200 virtual void setVertexDecl( const GFXVertexDecl *decl ); 201 202 virtual void setVertexStream( U32 stream, GFXVertexBuffer *buffer ); 203 virtual void setVertexStreamFrequency( U32 stream, U32 frequency ); 204 205private: 206 typedef GFXDevice Parent; 207 208 friend class GFXGLTextureObject; 209 friend class GFXGLCubemap; 210 friend class GFXGLCubemapArray; 211 friend class GFXGLTextureArray; 212 friend class GFXGLWindowTarget; 213 friend class GFXGLPrimitiveBuffer; 214 friend class GFXGLVertexBuffer; 215 216 static GFXAdapter::CreateDeviceInstanceDelegate mCreateDeviceInstance; 217 218 U32 mAdapterIndex; 219 220 StrongRefPtr<GFXGLVertexBuffer> mCurrentVB[VERTEX_STREAM_COUNT]; 221 U32 mCurrentVB_Divisor[VERTEX_STREAM_COUNT]; 222 bool mNeedUpdateVertexAttrib; 223 StrongRefPtr<GFXGLPrimitiveBuffer> mCurrentPB; 224 U32 mDrawInstancesCount; 225 226 GFXShader* mCurrentShader; 227 GFXShaderRef mGenericShader[GS_COUNT]; 228 GFXShaderConstBufferRef mGenericShaderBuffer[GS_COUNT]; 229 GFXShaderConstHandle *mModelViewProjSC[GS_COUNT]; 230 231 /// Since GL does not have separate world and view matrices we need to track them 232 MatrixF m_mCurrentWorld; 233 MatrixF m_mCurrentView; 234 235 void* mContext; 236 void* mPixelFormat; 237 238 F32 mPixelShaderVersion; 239 240 bool mSupportsAnisotropic; 241 242 U32 mNumVertexStream; 243 244 U32 mMaxShaderTextures; 245 U32 mMaxFFTextures; 246 247 U32 mMaxTRColors; 248 249 RectI mClip; 250 251 GFXGLStateBlockRef mCurrentGLStateBlock; 252 253 GLenum mActiveTextureType[GFX_TEXTURE_STAGE_COUNT]; 254 255 Vector< StrongRefPtr<GFXGLVertexBuffer> > mVolatileVBs; ///< Pool of existing volatile VBs so we can reuse previously created ones 256 Vector< StrongRefPtr<GFXGLPrimitiveBuffer> > mVolatilePBs; ///< Pool of existing volatile PBs so we can reuse previously created ones 257 258 GLsizei primCountToIndexCount(GFXPrimitiveType primType, U32 primitiveCount); 259 void preDrawPrimitive(); 260 void postDrawPrimitive(U32 primitiveCount); 261 262 GFXVertexBuffer* findVolatileVBO(U32 numVerts, const GFXVertexFormat *vertexFormat, U32 vertSize); ///< Returns an existing volatile VB which has >= numVerts and the same vert flags/size, or creates a new VB if necessary 263 GFXPrimitiveBuffer* findVolatilePBO(U32 numIndices, U32 numPrimitives); ///< Returns an existing volatile PB which has >= numIndices, or creates a new PB if necessary 264 265 void vsyncCallback(); ///< Vsync callback 266 267 void initGLState(); ///< Guaranteed to be called after all extensions have been loaded, use to init card profiler, shader version, max samplers, etc. 268 269 GFXFence* _createPlatformSpecificFence(); ///< If our platform (e.g. OS X) supports a fence extenstion (e.g. GL_APPLE_fence) this will create one, otherwise returns NULL 270 271 void setPB(GFXGLPrimitiveBuffer* pb); ///< Sets mCurrentPB 272 273 GFXGLStateCache *mOpenglStateCache; 274 275 GFXWindowTargetRef *mWindowRT; 276 277 bool mUseGlMap; 278}; 279 280#define GFXGL static_cast<GFXGLDevice*>(GFXDevice::get()) 281#endif 282