Driver.hx 8.1 KB

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