gfxNullDevice.h 7.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189
  1. //-----------------------------------------------------------------------------
  2. // Copyright (c) 2012 GarageGames, LLC
  3. //
  4. // Permission is hereby granted, free of charge, to any person obtaining a copy
  5. // of this software and associated documentation files (the "Software"), to
  6. // deal in the Software without restriction, including without limitation the
  7. // rights to use, copy, modify, merge, publish, distribute, sublicense, and/or
  8. // sell copies of the Software, and to permit persons to whom the Software is
  9. // furnished to do so, subject to the following conditions:
  10. //
  11. // The above copyright notice and this permission notice shall be included in
  12. // all copies or substantial portions of the Software.
  13. //
  14. // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
  15. // IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
  16. // FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
  17. // AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
  18. // LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
  19. // FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS
  20. // IN THE SOFTWARE.
  21. //-----------------------------------------------------------------------------
  22. #ifndef _GFXNullDevice_H_
  23. #define _GFXNullDevice_H_
  24. #include "platform/platform.h"
  25. //-----------------------------------------------------------------------------
  26. #include "gfx/gfxDevice.h"
  27. #include "gfx/gfxInit.h"
  28. #include "gfx/gfxFence.h"
  29. class GFXNullWindowTarget : public GFXWindowTarget
  30. {
  31. public:
  32. virtual bool present()
  33. {
  34. return true;
  35. }
  36. virtual const Point2I getSize()
  37. {
  38. // Return something stupid.
  39. return Point2I(1,1);
  40. }
  41. virtual GFXFormat getFormat() { return GFXFormatR8G8B8A8; }
  42. virtual void resetMode()
  43. {
  44. }
  45. virtual void zombify() {};
  46. virtual void resurrect() {};
  47. };
  48. class GFXNullDevice : public GFXDevice
  49. {
  50. public:
  51. GFXNullDevice();
  52. virtual ~GFXNullDevice();
  53. static GFXDevice *createInstance( U32 adapterIndex );
  54. static void enumerateAdapters( Vector<GFXAdapter*> &adapterList );
  55. void init( const GFXVideoMode &mode, PlatformWindow *window = NULL );
  56. virtual void activate() { };
  57. virtual void deactivate() { };
  58. virtual GFXAdapterType getAdapterType() { return NullDevice; };
  59. /// @name Debug Methods
  60. /// @{
  61. virtual void enterDebugEvent(ColorI color, const char *name) { };
  62. virtual void leaveDebugEvent() { };
  63. virtual void setDebugMarker(ColorI color, const char *name) { };
  64. /// @}
  65. /// Enumerates the supported video modes of the device
  66. virtual void enumerateVideoModes() { };
  67. /// Sets the video mode for the device
  68. virtual void setVideoMode( const GFXVideoMode &mode ) { };
  69. protected:
  70. static GFXAdapter::CreateDeviceInstanceDelegate mCreateDeviceInstance;
  71. /// Called by GFXDevice to create a device specific stateblock
  72. virtual GFXStateBlockRef createStateBlockInternal(const GFXStateBlockDesc& desc);
  73. /// Called by GFXDevice to actually set a stateblock.
  74. virtual void setStateBlockInternal(GFXStateBlock* block, bool force) { };
  75. /// @}
  76. /// Called by base GFXDevice to actually set a const buffer
  77. virtual void setShaderConstBufferInternal(GFXShaderConstBuffer* buffer) { };
  78. virtual void setTextureInternal(U32 textureUnit, const GFXTextureObject*texture) { };
  79. virtual void setLightInternal(U32 lightStage, const GFXLightInfo light, bool lightEnable);
  80. virtual void setLightMaterialInternal(const GFXLightMaterial mat) { };
  81. virtual void setGlobalAmbientInternal(LinearColorF color) { };
  82. /// @name State Initalization.
  83. /// @{
  84. /// State initalization. This MUST BE CALLED in setVideoMode after the device
  85. /// is created.
  86. virtual void initStates() { };
  87. virtual void setMatrix( GFXMatrixType mtype, const MatrixF &mat ) { };
  88. virtual GFXVertexBuffer *allocVertexBuffer( U32 numVerts,
  89. const GFXVertexFormat *vertexFormat,
  90. U32 vertSize,
  91. GFXBufferType bufferType,
  92. void* data = NULL );
  93. virtual GFXPrimitiveBuffer *allocPrimitiveBuffer( U32 numIndices,
  94. U32 numPrimitives,
  95. GFXBufferType bufferType,
  96. void* data = NULL );
  97. virtual GFXVertexDecl* allocVertexDecl( const GFXVertexFormat *vertexFormat ) { return NULL; }
  98. virtual void setVertexDecl( const GFXVertexDecl *decl ) { }
  99. virtual void setVertexStream( U32 stream, GFXVertexBuffer *buffer ) { }
  100. virtual void setVertexStreamFrequency( U32 stream, U32 frequency ) { }
  101. public:
  102. virtual GFXCubemap * createCubemap();
  103. virtual GFXCubemapArray *createCubemapArray();
  104. virtual F32 getFillConventionOffset() const { return 0.0f; };
  105. ///@}
  106. virtual GFXTextureTarget *allocRenderToTextureTarget(bool genMips=true){return NULL;};
  107. virtual GFXWindowTarget *allocWindowTarget(PlatformWindow *window)
  108. {
  109. return new GFXNullWindowTarget();
  110. };
  111. virtual void _updateRenderTargets(){};
  112. virtual F32 getPixelShaderVersion() const { return 0.0f; };
  113. virtual void setPixelShaderVersion( F32 version ) { };
  114. virtual U32 getNumSamplers() const { return 0; };
  115. virtual U32 getNumRenderTargets() const { return 0; };
  116. virtual GFXShader* createShader() { return NULL; };
  117. virtual void copyResource(GFXTextureObject *pDst, GFXCubemap *pSrc, const U32 face) { };
  118. virtual void clear( U32 flags, const LinearColorF& color, F32 z, U32 stencil ) { };
  119. virtual void clearColorAttachment(const U32 attachment, const LinearColorF& color) { };
  120. virtual bool beginSceneInternal() { return true; };
  121. virtual void endSceneInternal() { };
  122. virtual void drawPrimitive( GFXPrimitiveType primType, U32 vertexStart, U32 primitiveCount ) { };
  123. virtual void drawIndexedPrimitive( GFXPrimitiveType primType,
  124. U32 startVertex,
  125. U32 minIndex,
  126. U32 numVerts,
  127. U32 startIndex,
  128. U32 primitiveCount ) { };
  129. virtual void setClipRect( const RectI &rect ) { };
  130. virtual const RectI &getClipRect() const { return clip; };
  131. virtual void preDestroy() { Parent::preDestroy(); };
  132. virtual U32 getMaxDynamicVerts() { return 16384; };
  133. virtual U32 getMaxDynamicIndices() { return 16384; };
  134. virtual GFXFormat selectSupportedFormat( GFXTextureProfile *profile,
  135. const Vector<GFXFormat> &formats,
  136. bool texture,
  137. bool mustblend,
  138. bool mustfilter ) { return GFXFormatR8G8B8A8; };
  139. GFXFence *createFence() { return new GFXGeneralFence( this ); }
  140. GFXOcclusionQuery* createOcclusionQuery() { return NULL; }
  141. private:
  142. typedef GFXDevice Parent;
  143. RectI clip;
  144. };
  145. #endif