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 GFXGLVertexBuffer; 40class GFXGLPrimitiveBuffer; 41class GFXGLTextureTarget; 42class GFXGLCubemap; 43class GFXGLStateCache; 44class GFXGLVertexDecl; 45 46class GFXGLDevice : public GFXDevice 47{ 48public: 49 struct GLCapabilities 50 { 51 bool anisotropicFiltering; 52 bool bufferStorage; 53 bool shaderModel5; 54 bool textureStorage; 55 bool samplerObjects; 56 bool copyImage; 57 bool vertexAttributeBinding; 58 }; 59 GLCapabilities mCapabilities; 60 61 void zombify(); 62 void resurrect(); 63 GFXGLDevice(U32 adapterIndex); 64 virtual ~GFXGLDevice(); 65 66 static void enumerateAdapters( Vector<GFXAdapter*> &adapterList ); 67 static GFXDevice *createInstance( U32 adapterIndex ); 68 69 virtual void init( const GFXVideoMode &mode, PlatformWindow *window = NULL ); 70 71 virtual void activate() { } 72 virtual void deactivate() { } 73 virtual GFXAdapterType getAdapterType() { return OpenGL; } 74 75 virtual void enterDebugEvent(ColorI color, const char *name); 76 virtual void leaveDebugEvent(); 77 virtual void setDebugMarker(ColorI color, const char *name); 78 79 virtual void enumerateVideoModes(); 80 81 virtual U32 getTotalVideoMemory_GL_EXT(); 82 virtual U32 getTotalVideoMemory(); 83 84 virtual GFXCubemap * createCubemap(); 85 86 virtual F32 getFillConventionOffset() const { return 0.0f; } 87 88 89 ///@} 90 91 /// @name Render Target functions 92 /// @{ 93 94 /// 95 virtual GFXTextureTarget *allocRenderToTextureTarget(); 96 virtual GFXWindowTarget *allocWindowTarget(PlatformWindow *window); 97 virtual void _updateRenderTargets(); 98 99 ///@} 100 101 /// @name Shader functions 102 /// @{ 103 virtual F32 getPixelShaderVersion() const { return mPixelShaderVersion; } 104 virtual void setPixelShaderVersion( F32 version ) { mPixelShaderVersion = version; } 105 106 virtual void setShader(GFXShader *shader, bool force = false); 107 108 /// @attention GL cannot check if the given format supports blending or filtering! 109 virtual GFXFormat selectSupportedFormat(GFXTextureProfile *profile, 110 const Vector<GFXFormat> &formats, bool texture, bool mustblend, bool mustfilter); 111 112 /// Returns the number of texture samplers that can be used in a shader rendering pass 113 virtual U32 getNumSamplers() const; 114 115 /// Returns the number of simultaneous render targets supported by the device. 116 virtual U32 getNumRenderTargets() const; 117 118 virtual GFXShader* createShader(); 119 120 virtual void clear( U32 flags, ColorI color, F32 z, U32 stencil ); 121 virtual bool beginSceneInternal(); 122 virtual void endSceneInternal(); 123 124 virtual void drawPrimitive( GFXPrimitiveType primType, U32 vertexStart, U32 primitiveCount ); 125 126 virtual void drawIndexedPrimitive( GFXPrimitiveType primType, 127 U32 startVertex, 128 U32 minIndex, 129 U32 numVerts, 130 U32 startIndex, 131 U32 primitiveCount ); 132 133 virtual void setClipRect( const RectI &rect ); 134 virtual const RectI &getClipRect() const { return mClip; } 135 136 virtual void preDestroy() { Parent::preDestroy(); } 137 138 virtual U32 getMaxDynamicVerts() { return MAX_DYNAMIC_VERTS; } 139 virtual U32 getMaxDynamicIndices() { return MAX_DYNAMIC_INDICES; } 140 141 GFXFence *createFence(); 142 143 GFXOcclusionQuery* createOcclusionQuery(); 144 145 GFXGLStateBlockRef getCurrentStateBlock() { return mCurrentGLStateBlock; } 146 147 virtual void setupGenericShaders( GenericShaderType type = GSColor ); 148 149 /// 150 bool supportsAnisotropic() const { return mSupportsAnisotropic; } 151 152 GFXGLStateCache* getOpenglCache() { return mOpenglStateCache; } 153 154 GFXTextureObject* getDefaultDepthTex() const; 155 156 /// Returns the number of vertex streams supported by the device. 157 const U32 getNumVertexStreams() const { return mNumVertexStream; } 158 159 bool glUseMap() const { return mUseGlMap; } 160 161protected: 162 /// Called by GFXDevice to create a device specific stateblock 163 virtual GFXStateBlockRef createStateBlockInternal(const GFXStateBlockDesc& desc); 164 /// Called by GFXDevice to actually set a stateblock. 165 virtual void setStateBlockInternal(GFXStateBlock* block, bool force); 166 167 /// Called by base GFXDevice to actually set a const buffer 168 virtual void setShaderConstBufferInternal(GFXShaderConstBuffer* buffer); 169 170 virtual void setTextureInternal(U32 textureUnit, const GFXTextureObject*texture); 171 virtual void setCubemapInternal(U32 cubemap, const GFXGLCubemap* texture); 172 173 virtual void setLightInternal(U32 lightStage, const GFXLightInfo light, bool lightEnable); 174 virtual void setLightMaterialInternal(const GFXLightMaterial mat); 175 virtual void setGlobalAmbientInternal(ColorF color); 176 177 /// @name State Initalization. 178 /// @{ 179 180 /// State initalization. This MUST BE CALLED in setVideoMode after the device 181 /// is created. 182 virtual void initStates() { } 183 184 virtual void setMatrix( GFXMatrixType mtype, const MatrixF &mat ); 185 186 virtual GFXVertexBuffer *allocVertexBuffer( U32 numVerts, 187 const GFXVertexFormat *vertexFormat, 188 U32 vertSize, 189 GFXBufferType bufferType, 190 void* data = NULL); 191 virtual GFXPrimitiveBuffer *allocPrimitiveBuffer( U32 numIndices, U32 numPrimitives, GFXBufferType bufferType, void* data = NULL ); 192 193 // NOTE: The GL device doesn't need a vertex declaration at 194 // this time, but we need to return something to keep the system 195 // from retrying to allocate one on every call. 196 virtual GFXVertexDecl* allocVertexDecl( const GFXVertexFormat *vertexFormat ); 197 198 virtual void setVertexDecl( const GFXVertexDecl *decl ); 199 200 virtual void setVertexStream( U32 stream, GFXVertexBuffer *buffer ); 201 virtual void setVertexStreamFrequency( U32 stream, U32 frequency ); 202 203private: 204 typedef GFXDevice Parent; 205 206 friend class GFXGLTextureObject; 207 friend class GFXGLCubemap; 208 friend class GFXGLWindowTarget; 209 friend class GFXGLPrimitiveBuffer; 210 friend class GFXGLVertexBuffer; 211 212 static GFXAdapter::CreateDeviceInstanceDelegate mCreateDeviceInstance; 213 214 U32 mAdapterIndex; 215 216 StrongRefPtr<GFXGLVertexBuffer> mCurrentVB[VERTEX_STREAM_COUNT]; 217 U32 mCurrentVB_Divisor[VERTEX_STREAM_COUNT]; 218 bool mNeedUpdateVertexAttrib; 219 StrongRefPtr<GFXGLPrimitiveBuffer> mCurrentPB; 220 U32 mDrawInstancesCount; 221 222 GFXShader* mCurrentShader; 223 GFXShaderRef mGenericShader[GS_COUNT]; 224 GFXShaderConstBufferRef mGenericShaderBuffer[GS_COUNT]; 225 GFXShaderConstHandle *mModelViewProjSC[GS_COUNT]; 226 227 /// Since GL does not have separate world and view matrices we need to track them 228 MatrixF m_mCurrentWorld; 229 MatrixF m_mCurrentView; 230 231 void* mContext; 232 void* mPixelFormat; 233 234 F32 mPixelShaderVersion; 235 236 bool mSupportsAnisotropic; 237 238 U32 mNumVertexStream; 239 240 U32 mMaxShaderTextures; 241 U32 mMaxFFTextures; 242 243 U32 mMaxTRColors; 244 245 RectI mClip; 246 247 GFXGLStateBlockRef mCurrentGLStateBlock; 248 249 GLenum mActiveTextureType[TEXTURE_STAGE_COUNT]; 250 251 Vector< StrongRefPtr<GFXGLVertexBuffer> > mVolatileVBs; ///< Pool of existing volatile VBs so we can reuse previously created ones 252 Vector< StrongRefPtr<GFXGLPrimitiveBuffer> > mVolatilePBs; ///< Pool of existing volatile PBs so we can reuse previously created ones 253 254 GLsizei primCountToIndexCount(GFXPrimitiveType primType, U32 primitiveCount); 255 void preDrawPrimitive(); 256 void postDrawPrimitive(U32 primitiveCount); 257 258 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 259 GFXPrimitiveBuffer* findVolatilePBO(U32 numIndices, U32 numPrimitives); ///< Returns an existing volatile PB which has >= numIndices, or creates a new PB if necessary 260 261 void initGLState(); ///< Guaranteed to be called after all extensions have been loaded, use to init card profiler, shader version, max samplers, etc. 262 263 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 264 265 void setPB(GFXGLPrimitiveBuffer* pb); ///< Sets mCurrentPB 266 267 GFXGLStateCache *mOpenglStateCache; 268 269 GFXWindowTargetRef *mWindowRT; 270 271 bool mUseGlMap; 272}; 273 274#define GFXGL static_cast<GFXGLDevice*>(GFXDevice::get()) 275#endif 276
