Driver.hx 7.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274
  1. package h3d.impl;
  2. #if flash
  3. typedef IndexBuffer = flash.display3D.IndexBuffer3D;
  4. typedef VertexBuffer = Stage3dDriver.VertexWrapper;
  5. typedef Texture = flash.display3D.textures.TextureBase;
  6. typedef DepthBuffer = {};
  7. typedef Query = {};
  8. #elseif js
  9. typedef IndexBuffer = js.html.webgl.Buffer;
  10. typedef VertexBuffer = { b : js.html.webgl.Buffer, stride : Int };
  11. typedef Texture = { t : js.html.webgl.Texture, width : Int, height : Int, internalFmt : Int, pixelFmt : Int, bits : Int };
  12. typedef DepthBuffer = { r : js.html.webgl.Renderbuffer };
  13. typedef Query = {};
  14. #elseif nme
  15. typedef IndexBuffer = nme.gl.GLBuffer;
  16. typedef VertexBuffer = { b : nme.gl.GLBuffer, stride : Int };
  17. typedef Texture = { t : nme.gl.GLTexture, width : Int, height : Int, internalFmt : Int, pixelFmt : Int, bits : Int };
  18. typedef DepthBuffer = { r : nme.gl.Renderbuffer };
  19. typedef Query = {};
  20. #elseif lime
  21. typedef IndexBuffer = lime.graphics.opengl.GLBuffer;
  22. typedef VertexBuffer = { b : lime.graphics.opengl.GLBuffer, stride : Int };
  23. typedef Texture = { t : lime.graphics.opengl.GLTexture, width : Int, height : Int, internalFmt : Int, pixelFmt : Int, bits : Int };
  24. typedef DepthBuffer = { r : lime.graphics.opengl.GLRenderbuffer };
  25. typedef Query = {};
  26. #elseif hlsdl
  27. typedef IndexBuffer = sdl.GL.Buffer;
  28. typedef VertexBuffer = { b : sdl.GL.Buffer, stride : Int };
  29. typedef Texture = { t : sdl.GL.Texture, width : Int, height : Int, internalFmt : Int, pixelFmt : Int, bits : Int };
  30. typedef DepthBuffer = { r : sdl.GL.Renderbuffer };
  31. typedef Query = { q : sdl.GL.Query, kind : QueryKind };
  32. #elseif psgl
  33. typedef IndexBuffer = psgl.GL.Buffer;
  34. typedef VertexBuffer = { b : psgl.GL.Buffer, stride : Int };
  35. typedef Texture = { t : psgl.GL.Texture, width : Int, height : Int, internalFmt : Int, pixelFmt : Int, bits : Int };
  36. typedef DepthBuffer = { r : psgl.GL.Renderbuffer };
  37. typedef Query = { q : psgl.GL.Query, kind : QueryKind };
  38. #elseif hldx
  39. typedef IndexBuffer = { res : dx.Resource, count : Int };
  40. typedef VertexBuffer = { res : dx.Resource, count : Int, stride : Int };
  41. typedef Texture = { res : dx.Resource, view : dx.Driver.ShaderResourceView, rt : dx.Driver.RenderTargetView, mips : Int };
  42. typedef DepthBuffer = { res : dx.Resource, view : dx.Driver.DepthStencilView };
  43. typedef Query = {};
  44. #else
  45. typedef IndexBuffer = {};
  46. typedef VertexBuffer = {};
  47. typedef Texture = {};
  48. typedef DepthBuffer = {};
  49. typedef Query = {};
  50. #end
  51. enum Feature {
  52. /*
  53. Do the shader support standard derivates functions (ddx ddy).
  54. */
  55. StandardDerivatives;
  56. /*
  57. Can use allocate floating point textures.
  58. */
  59. FloatTextures;
  60. /*
  61. Can we allocate custom depth buffers. If not, default depth buffer
  62. (queried with DepthBuffer.getDefault()) will be clear if we change
  63. the render target resolution or format.
  64. */
  65. AllocDepthBuffer;
  66. /*
  67. Is our driver hardware accelerated or CPU emulated.
  68. */
  69. HardwareAccelerated;
  70. /*
  71. Allows to render on several render targets with a single draw.
  72. */
  73. MultipleRenderTargets;
  74. /*
  75. Does it supports query objects API.
  76. */
  77. Queries;
  78. }
  79. enum QueryKind {
  80. /**
  81. The result will give the GPU Timestamp (in nanoseconds, 1e-9 seconds) at the time the endQuery is performed
  82. **/
  83. TimeStamp;
  84. /**
  85. The result will give the number of samples that passes the depth buffer between beginQuery/endQuery range
  86. **/
  87. Samples;
  88. }
  89. class Driver {
  90. public var logEnable : Bool;
  91. public function hasFeature( f : Feature ) {
  92. return false;
  93. }
  94. public function isSupportedFormat( fmt : h3d.mat.Data.TextureFormat ) {
  95. return false;
  96. }
  97. public function isDisposed() {
  98. return true;
  99. }
  100. public function dispose() {
  101. }
  102. public function begin( frame : Int ) {
  103. }
  104. public inline function log( str : String ) {
  105. #if debug
  106. if( logEnable ) logImpl(str);
  107. #end
  108. }
  109. public function generateMipMaps( texture : h3d.mat.Texture ) {
  110. throw "Mipmaps auto generation is not supported on this platform";
  111. }
  112. public function getNativeShaderCode( shader : hxsl.RuntimeShader ) : String {
  113. return null;
  114. }
  115. function logImpl( str : String ) {
  116. }
  117. public function clear( ?color : h3d.Vector, ?depth : Float, ?stencil : Int ) {
  118. }
  119. public function captureRenderBuffer( pixels : hxd.Pixels ) {
  120. }
  121. public function getDriverName( details : Bool ) {
  122. return "Not available";
  123. }
  124. public function init( onCreate : Bool -> Void, forceSoftware = false ) {
  125. }
  126. public function resize( width : Int, height : Int ) {
  127. }
  128. public function selectShader( shader : hxsl.RuntimeShader ) {
  129. return false;
  130. }
  131. public function selectMaterial( pass : h3d.mat.Pass ) {
  132. }
  133. public function uploadShaderBuffers( buffers : h3d.shader.Buffers, which : h3d.shader.Buffers.BufferKind ) {
  134. }
  135. public function getShaderInputNames() : Array<String> {
  136. return null;
  137. }
  138. public function selectBuffer( buffer : Buffer ) {
  139. }
  140. public function selectMultiBuffers( buffers : Buffer.BufferOffset ) {
  141. }
  142. public function draw( ibuf : IndexBuffer, startIndex : Int, ntriangles : Int ) {
  143. }
  144. public function setRenderZone( x : Int, y : Int, width : Int, height : Int ) {
  145. }
  146. public function setRenderTarget( tex : Null<h3d.mat.Texture>, face = 0, mipLevel = 0 ) {
  147. }
  148. public function setRenderTargets( textures : Array<h3d.mat.Texture> ) {
  149. }
  150. public function allocDepthBuffer( b : h3d.mat.DepthBuffer ) : DepthBuffer {
  151. return null;
  152. }
  153. public function disposeDepthBuffer( b : h3d.mat.DepthBuffer ) {
  154. }
  155. public function getDefaultDepthBuffer() : h3d.mat.DepthBuffer {
  156. return null;
  157. }
  158. public function present() {
  159. }
  160. public function setDebug( b : Bool ) {
  161. }
  162. public function allocTexture( t : h3d.mat.Texture ) : Texture {
  163. return null;
  164. }
  165. public function allocIndexes( count : Int ) : IndexBuffer {
  166. return null;
  167. }
  168. public function allocVertexes( m : ManagedBuffer ) : VertexBuffer {
  169. return null;
  170. }
  171. public function disposeTexture( t : h3d.mat.Texture ) {
  172. }
  173. public function disposeIndexes( i : IndexBuffer ) {
  174. }
  175. public function disposeVertexes( v : VertexBuffer ) {
  176. }
  177. public function uploadIndexBuffer( i : IndexBuffer, startIndice : Int, indiceCount : Int, buf : hxd.IndexBuffer, bufPos : Int ) {
  178. }
  179. public function uploadIndexBytes( i : IndexBuffer, startIndice : Int, indiceCount : Int, buf : haxe.io.Bytes , bufPos : Int ) {
  180. }
  181. public function uploadVertexBuffer( v : VertexBuffer, startVertex : Int, vertexCount : Int, buf : hxd.FloatBuffer, bufPos : Int ) {
  182. }
  183. public function uploadVertexBytes( v : VertexBuffer, startVertex : Int, vertexCount : Int, buf : haxe.io.Bytes, bufPos : Int ) {
  184. }
  185. public function uploadTextureBitmap( t : h3d.mat.Texture, bmp : hxd.BitmapData, mipLevel : Int, side : Int ) {
  186. }
  187. public function uploadTexturePixels( t : h3d.mat.Texture, pixels : hxd.Pixels, mipLevel : Int, side : Int ) {
  188. }
  189. public function readVertexBytes( v : VertexBuffer, startVertex : Int, vertexCount : Int, buf : haxe.io.Bytes, bufPos : Int ) {
  190. throw "Driver does not allow to read vertex bytes";
  191. }
  192. public function readIndexBytes( v : IndexBuffer, startVertex : Int, vertexCount : Int, buf : haxe.io.Bytes, bufPos : Int ) {
  193. throw "Driver does not allow to read index bytes";
  194. }
  195. /**
  196. Returns true if we could copy the texture, false otherwise (not supported by driver or mismatch in size/format)
  197. **/
  198. public function copyTexture( from : h3d.mat.Texture, to : h3d.mat.Texture ) {
  199. return false;
  200. }
  201. // --- QUERY API
  202. public function allocQuery( queryKind : QueryKind ) : Query {
  203. return null;
  204. }
  205. public function deleteQuery( q : Query ) {
  206. }
  207. public function beginQuery( q : Query ) {
  208. }
  209. public function endQuery( q : Query ) {
  210. }
  211. public function queryResultAvailable( q : Query ) {
  212. return true;
  213. }
  214. public function queryResult( q : Query ) {
  215. return 0.;
  216. }
  217. }