Driver.hx 8.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320
  1. package h3d.impl;
  2. #if macro
  3. typedef IndexBuffer = {};
  4. typedef GPUBuffer = {};
  5. typedef Texture = {};
  6. typedef Query = {};
  7. #elseif js
  8. typedef IndexBuffer = { b : js.html.webgl.Buffer, is32 : Bool };
  9. typedef GPUBuffer = js.html.webgl.Buffer;
  10. typedef Texture = { t : js.html.webgl.Texture, width : Int, height : Int, internalFmt : Int, pixelFmt : Int, bits : Int, bias : Float, bind : Int #if multidriver, driver : Driver #end, startMip : Int };
  11. typedef Query = {};
  12. #elseif hlsdl
  13. typedef IndexBuffer = { b : sdl.GL.Buffer, is32 : Bool };
  14. typedef GPUBuffer = sdl.GL.Buffer;
  15. typedef Texture = { t : sdl.GL.Texture, width : Int, height : Int, internalFmt : Int, pixelFmt : Int, bits : Int, bind : Int, bias : Float, startMip : Int };
  16. typedef Query = { q : sdl.GL.Query, kind : QueryKind };
  17. #elseif usegl
  18. typedef IndexBuffer = { b : haxe.GLTypes.Buffer, is32 : Bool };
  19. typedef GPUBuffer = haxe.GLTypes.Buffer;
  20. typedef Texture = { t : haxe.GLTypes.Texture, width : Int, height : Int, internalFmt : Int, pixelFmt : Int, bits : Int, bind : Int, bias : Float, startMip : Int };
  21. typedef Query = { q : haxe.GLTypes.Query, kind : QueryKind };
  22. #elseif (hldx && dx12)
  23. typedef IndexBuffer = DX12Driver.IndexBufferData;
  24. typedef GPUBuffer = DX12Driver.VertexBufferData;
  25. typedef Texture = h3d.impl.DX12Driver.TextureData;
  26. typedef Query = h3d.impl.DX12Driver.QueryData;
  27. #elseif hldx
  28. typedef IndexBuffer = { res : dx.Resource, count : Int, bits : Int };
  29. typedef GPUBuffer = dx.Resource;
  30. typedef Texture = { res : dx.Resource, view : dx.Driver.ShaderResourceView, ?depthView : dx.Driver.DepthStencilView, ?readOnlyDepthView : dx.Driver.DepthStencilView, rt : Array<dx.Driver.RenderTargetView>, mips : Int, ?views : Array<dx.Driver.ShaderResourceView> };
  31. typedef Query = {};
  32. #elseif usesys
  33. typedef IndexBuffer = haxe.GraphicsDriver.IndexBuffer;
  34. typedef GPUBuffer = haxe.GraphicsDriver.GPUBuffer;
  35. typedef Texture = haxe.GraphicsDriver.Texture;
  36. typedef Query = haxe.GraphicsDriver.Query;
  37. #else
  38. typedef IndexBuffer = {};
  39. typedef GPUBuffer = {};
  40. typedef Texture = {};
  41. typedef Query = {};
  42. #end
  43. enum Feature {
  44. /*
  45. Do the shader support standard derivates functions (ddx ddy).
  46. */
  47. StandardDerivatives;
  48. /*
  49. Can use allocate floating point textures.
  50. */
  51. FloatTextures;
  52. /*
  53. Can we allocate custom depth buffers. If not, default depth buffer
  54. (queried with DepthBuffer.getDefault()) will be clear if we change
  55. the render target resolution or format.
  56. */
  57. AllocDepthBuffer;
  58. /*
  59. Is our driver hardware accelerated or CPU emulated.
  60. */
  61. HardwareAccelerated;
  62. /*
  63. Allows to render on several render targets with a single draw.
  64. */
  65. MultipleRenderTargets;
  66. /*
  67. Does it supports query objects API.
  68. */
  69. Queries;
  70. /*
  71. Supports gamma correct textures
  72. */
  73. SRGBTextures;
  74. /*
  75. Allows advanced shader operations (webgl2, opengl3+, directx 9.0c+)
  76. */
  77. ShaderModel3;
  78. /*
  79. Tells if the driver uses bottom-left coordinates for textures.
  80. */
  81. BottomLeftCoords;
  82. /*
  83. Supports rendering in wireframe mode.
  84. */
  85. Wireframe;
  86. /*
  87. Supports instanced rendering
  88. */
  89. InstancedRendering;
  90. }
  91. enum QueryKind {
  92. /**
  93. The result will give the GPU Timestamp (in nanoseconds, 1e-9 seconds) at the time the endQuery is performed
  94. **/
  95. TimeStamp;
  96. /**
  97. The result will give the number of samples that passes the depth buffer between beginQuery/endQuery range
  98. **/
  99. Samples;
  100. }
  101. enum RenderFlag {
  102. /**
  103. 0 = LeftHanded (default), 1 = RightHanded. Affects the meaning of triangle culling value.
  104. **/
  105. CameraHandness;
  106. }
  107. class Driver {
  108. static var SHADER_CACHE : h3d.impl.ShaderCache;
  109. var shaderCache = SHADER_CACHE;
  110. public static function setShaderCache( cache : h3d.impl.ShaderCache ) {
  111. SHADER_CACHE = cache;
  112. }
  113. public var logEnable : Bool;
  114. public function hasFeature( f : Feature ) {
  115. return false;
  116. }
  117. public function setRenderFlag( r : RenderFlag, value : Int ) {
  118. }
  119. public function isSupportedFormat( fmt : h3d.mat.Data.TextureFormat ) {
  120. return false;
  121. }
  122. public function isDisposed() {
  123. return true;
  124. }
  125. public function dispose() {
  126. }
  127. public function begin( frame : Int ) {
  128. }
  129. public inline function log( str : String ) {
  130. #if debug
  131. if( logEnable ) logImpl(str);
  132. #end
  133. }
  134. public function generateMipMaps( texture : h3d.mat.Texture ) {
  135. throw "Mipmaps auto generation is not supported on this platform";
  136. }
  137. public function getNativeShaderCode( shader : hxsl.RuntimeShader ) : String {
  138. return null;
  139. }
  140. function logImpl( str : String ) {
  141. }
  142. public function clear( ?color : h3d.Vector, ?depth : Float, ?stencil : Int ) {
  143. }
  144. public function captureRenderBuffer( pixels : hxd.Pixels ) {
  145. }
  146. public function capturePixels( tex : h3d.mat.Texture, layer : Int, mipLevel : Int, ?region : h2d.col.IBounds ) : hxd.Pixels {
  147. throw "Can't capture pixels on this platform";
  148. return null;
  149. }
  150. public function getDriverName( details : Bool ) {
  151. return "Not available";
  152. }
  153. public function init( onCreate : Bool -> Void, forceSoftware = false ) {
  154. }
  155. public function resize( width : Int, height : Int ) {
  156. }
  157. public function selectShader( shader : hxsl.RuntimeShader ) {
  158. return false;
  159. }
  160. public function selectMaterial( pass : h3d.mat.Pass ) {
  161. }
  162. public function uploadShaderBuffers( buffers : h3d.shader.Buffers, which : h3d.shader.Buffers.BufferKind ) {
  163. }
  164. public function selectBuffer( buffer : Buffer ) {
  165. }
  166. public function selectMultiBuffers( format : hxd.BufferFormat.MultiFormat, buffers : Array<h3d.Buffer> ) {
  167. }
  168. public function draw( ibuf : IndexBuffer, startIndex : Int, ntriangles : Int ) {
  169. }
  170. public function drawInstanced( ibuf : IndexBuffer, commands : h3d.impl.InstanceBuffer ) {
  171. }
  172. public function setRenderZone( x : Int, y : Int, width : Int, height : Int ) {
  173. }
  174. public function setRenderTarget( tex : Null<h3d.mat.Texture>, layer = 0, mipLevel = 0, depthBinding : h3d.Engine.DepthBinding = ReadWrite ) {
  175. }
  176. public function setRenderTargets( textures : Array<h3d.mat.Texture>, depthBinding : h3d.Engine.DepthBinding = ReadWrite ) {
  177. }
  178. public function setDepth( tex : Null<h3d.mat.Texture> ) {
  179. }
  180. public function allocDepthBuffer( b : h3d.mat.Texture ) : Texture {
  181. return null;
  182. }
  183. public function disposeDepthBuffer( b : h3d.mat.Texture ) {
  184. }
  185. public function getDefaultDepthBuffer() : h3d.mat.Texture {
  186. return null;
  187. }
  188. public function present() {
  189. }
  190. public function end() {
  191. }
  192. public function setDebug( b : Bool ) {
  193. }
  194. public function allocTexture( t : h3d.mat.Texture ) : Texture {
  195. return null;
  196. }
  197. public function allocIndexes( count : Int, is32 : Bool ) : IndexBuffer {
  198. return null;
  199. }
  200. public function allocBuffer( b : h3d.Buffer ) : GPUBuffer {
  201. return null;
  202. }
  203. public function allocInstanceBuffer( b : h3d.impl.InstanceBuffer, bytes : haxe.io.Bytes ) {
  204. }
  205. public function disposeTexture( t : h3d.mat.Texture ) {
  206. }
  207. public function disposeIndexes( i : IndexBuffer ) {
  208. }
  209. public function disposeBuffer( b : Buffer ) {
  210. }
  211. public function disposeInstanceBuffer( b : h3d.impl.InstanceBuffer ) {
  212. }
  213. public function uploadIndexBuffer( i : IndexBuffer, startIndice : Int, indiceCount : Int, buf : hxd.IndexBuffer, bufPos : Int ) {
  214. }
  215. public function uploadIndexBytes( i : IndexBuffer, startIndice : Int, indiceCount : Int, buf : haxe.io.Bytes , bufPos : Int ) {
  216. }
  217. public function uploadBufferData( b : Buffer, startVertex : Int, vertexCount : Int, buf : hxd.FloatBuffer, bufPos : Int ) {
  218. }
  219. public function uploadBufferBytes( b : Buffer, startVertex : Int, vertexCount : Int, buf : haxe.io.Bytes, bufPos : Int ) {
  220. }
  221. public function uploadTextureBitmap( t : h3d.mat.Texture, bmp : hxd.BitmapData, mipLevel : Int, side : Int ) {
  222. }
  223. public function uploadTexturePixels( t : h3d.mat.Texture, pixels : hxd.Pixels, mipLevel : Int, side : Int ) {
  224. }
  225. public function readBufferBytes( b : Buffer, startVertex : Int, vertexCount : Int, buf : haxe.io.Bytes, bufPos : Int ) {
  226. throw "Driver does not allow to read vertex bytes";
  227. }
  228. public function readIndexBytes( v : IndexBuffer, startVertex : Int, vertexCount : Int, buf : haxe.io.Bytes, bufPos : Int ) {
  229. throw "Driver does not allow to read index bytes";
  230. }
  231. /**
  232. Returns true if we could copy the texture, false otherwise (not supported by driver or mismatch in size/format)
  233. **/
  234. public function copyTexture( from : h3d.mat.Texture, to : h3d.mat.Texture ) {
  235. return false;
  236. }
  237. // --- QUERY API
  238. public function allocQuery( queryKind : QueryKind ) : Query {
  239. return null;
  240. }
  241. public function deleteQuery( q : Query ) {
  242. }
  243. public function beginQuery( q : Query ) {
  244. }
  245. public function endQuery( q : Query ) {
  246. }
  247. public function queryResultAvailable( q : Query ) {
  248. return true;
  249. }
  250. public function queryResult( q : Query ) {
  251. return 0.;
  252. }
  253. }