gfxNullDevice.h 6.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185
  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. /// @name State Initalization.
  80. /// @{
  81. /// State initalization. This MUST BE CALLED in setVideoMode after the device
  82. /// is created.
  83. virtual void initStates() { };
  84. virtual GFXVertexBuffer *allocVertexBuffer( U32 numVerts,
  85. const GFXVertexFormat *vertexFormat,
  86. U32 vertSize,
  87. GFXBufferType bufferType,
  88. void* data = NULL );
  89. virtual GFXPrimitiveBuffer *allocPrimitiveBuffer( U32 numIndices,
  90. U32 numPrimitives,
  91. GFXBufferType bufferType,
  92. void* data = NULL );
  93. virtual GFXVertexDecl* allocVertexDecl( const GFXVertexFormat *vertexFormat ) { return NULL; }
  94. virtual void setVertexDecl( const GFXVertexDecl *decl ) { }
  95. virtual void setVertexStream( U32 stream, GFXVertexBuffer *buffer ) { }
  96. virtual void setVertexStreamFrequency( U32 stream, U32 frequency ) { }
  97. public:
  98. virtual GFXCubemap * createCubemap();
  99. virtual GFXCubemapArray *createCubemapArray();
  100. virtual GFXTextureArray *createTextureArray();
  101. virtual F32 getFillConventionOffset() const { return 0.0f; };
  102. ///@}
  103. virtual GFXTextureTarget *allocRenderToTextureTarget(bool genMips=true){return NULL;};
  104. virtual GFXWindowTarget *allocWindowTarget(PlatformWindow *window)
  105. {
  106. return new GFXNullWindowTarget();
  107. };
  108. virtual void _updateRenderTargets(){};
  109. virtual F32 getPixelShaderVersion() const { return 0.0f; };
  110. virtual void setPixelShaderVersion( F32 version ) { };
  111. virtual U32 getNumSamplers() const { return 0; };
  112. virtual U32 getNumRenderTargets() const { return 0; };
  113. virtual GFXShader* createShader() { return NULL; };
  114. virtual void copyResource(GFXTextureObject *pDst, GFXCubemap *pSrc, const U32 face) { };
  115. virtual void clear( U32 flags, const LinearColorF& color, F32 z, U32 stencil ) { };
  116. virtual void clearColorAttachment(const U32 attachment, const LinearColorF& color) { };
  117. virtual bool beginSceneInternal() { return true; };
  118. virtual void endSceneInternal() { };
  119. virtual void drawPrimitive( GFXPrimitiveType primType, U32 vertexStart, U32 primitiveCount ) { };
  120. virtual void drawIndexedPrimitive( GFXPrimitiveType primType,
  121. U32 startVertex,
  122. U32 minIndex,
  123. U32 numVerts,
  124. U32 startIndex,
  125. U32 primitiveCount ) { };
  126. virtual void setClipRect( const RectI &rect ) { };
  127. virtual const RectI &getClipRect() const { return clip; };
  128. virtual void preDestroy() { Parent::preDestroy(); };
  129. virtual U32 getMaxDynamicVerts() { return 16384; };
  130. virtual U32 getMaxDynamicIndices() { return 16384; };
  131. virtual GFXFormat selectSupportedFormat( GFXTextureProfile *profile,
  132. const Vector<GFXFormat> &formats,
  133. bool texture,
  134. bool mustblend,
  135. bool mustfilter ) { return GFXFormatR8G8B8A8; };
  136. GFXFence *createFence() { return new GFXGeneralFence( this ); }
  137. GFXOcclusionQuery* createOcclusionQuery() { return NULL; }
  138. private:
  139. typedef GFXDevice Parent;
  140. RectI clip;
  141. };
  142. #endif