CanvasTarget.html 15 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398
  1. <!DOCTYPE html>
  2. <html lang="en">
  3. <head>
  4. <meta charset="utf-8">
  5. <title>CanvasTarget - Three.js Docs</title>
  6. <meta name="viewport" content="width=device-width, user-scalable=no, minimum-scale=1.0, maximum-scale=1.0">
  7. <script src="../scripts/highlight.min.js"></script>
  8. <link type="text/css" rel="stylesheet" href="../styles/highlight-three.css">
  9. <link type="text/css" rel="stylesheet" href="../styles/page.css">
  10. </head>
  11. <body>
  12. <p class="inheritance" translate="no"><a href="EventDispatcher.html">EventDispatcher</a> → </p>
  13. <h1 translate="no">CanvasTarget</h1>
  14. <section>
  15. <header>
  16. <div class="class-description"><p>CanvasTarget is a class that represents the final output destination of the renderer.</p></div>
  17. </header>
  18. <article>
  19. <div class="container-overview">
  20. <h2>Constructor</h2>
  21. <h3 class="name name-method" id="CanvasTarget" translate="no">new <a href="#CanvasTarget">CanvasTarget</a><span class="signature">( domElement : <span class="param-type">HTMLCanvasElement | OffscreenCanvas</span> )</span> </h3>
  22. <div class="method">
  23. <div class="description">
  24. <p>Constructs a new CanvasTarget.</p>
  25. </div>
  26. <table class="params">
  27. <tbody>
  28. <tr>
  29. <td class="name">
  30. <strong>domElement</strong>
  31. </td>
  32. <td class="description last">
  33. <p>The canvas element to render to.</p>
  34. </td>
  35. </tr>
  36. </tbody>
  37. </table>
  38. </div>
  39. </div>
  40. <h2 class="subsection-title">Properties</h2>
  41. <div class="member">
  42. <h3 class="name" id="colorTexture" translate="no">.<a href="#colorTexture">colorTexture</a><span class="type-signature"> : <a href="FramebufferTexture.html">FramebufferTexture</a></span> </h3>
  43. <div class="description">
  44. <p>The color texture of the default framebuffer.</p>
  45. </div>
  46. </div>
  47. <div class="member">
  48. <h3 class="name" id="depthTexture" translate="no">.<a href="#depthTexture">depthTexture</a><span class="type-signature"> : <a href="DepthTexture.html">DepthTexture</a></span> </h3>
  49. <div class="description">
  50. <p>The depth texture of the default framebuffer.</p>
  51. </div>
  52. </div>
  53. <div class="member">
  54. <h3 class="name" id="domElement" translate="no">.<a href="#domElement">domElement</a><span class="type-signature"> : HTMLCanvasElement | OffscreenCanvas</span> </h3>
  55. <div class="description">
  56. <p>A reference to the canvas element the renderer is drawing to.
  57. This value of this property will automatically be created by
  58. the renderer.</p>
  59. </div>
  60. </div>
  61. <h2 class="subsection-title">Methods</h2>
  62. <h3 class="name name-method" id="dispose" translate="no">.<a href="#dispose">dispose</a><span class="signature">()</span> </h3>
  63. <div class="method">
  64. <div class="description">
  65. <p>Frees the GPU-related resources allocated by this instance. Call this
  66. method whenever this instance is no longer used in your app.</p>
  67. </div>
  68. <h5>Fires:</h5>
  69. <ul>
  70. <li>RenderTarget#event:dispose</li>
  71. </ul>
  72. </div>
  73. <h3 class="name name-method" id="getDrawingBufferSize" translate="no">.<a href="#getDrawingBufferSize">getDrawingBufferSize</a><span class="signature">( target : <span class="param-type"><a href="Vector2.html">Vector2</a></span> )</span><span class="type-signature"> : <a href="Vector2.html">Vector2</a></span> </h3>
  74. <div class="method">
  75. <div class="description">
  76. <p>Returns the drawing buffer size in physical pixels. This method honors the pixel ratio.</p>
  77. </div>
  78. <table class="params">
  79. <tbody>
  80. <tr>
  81. <td class="name">
  82. <strong>target</strong>
  83. </td>
  84. <td class="description last">
  85. <p>The method writes the result in this target object.</p>
  86. </td>
  87. </tr>
  88. </tbody>
  89. </table>
  90. <dl class="details">
  91. <dt class="tag-returns"><strong>Returns:</strong> The drawing buffer size.</dt>
  92. </dl>
  93. </div>
  94. <h3 class="name name-method" id="getPixelRatio" translate="no">.<a href="#getPixelRatio">getPixelRatio</a><span class="signature">()</span><span class="type-signature"> : number</span> </h3>
  95. <div class="method">
  96. <div class="description">
  97. <p>Returns the pixel ratio.</p>
  98. </div>
  99. <dl class="details">
  100. <dt class="tag-returns"><strong>Returns:</strong> The pixel ratio.</dt>
  101. </dl>
  102. </div>
  103. <h3 class="name name-method" id="getScissor" translate="no">.<a href="#getScissor">getScissor</a><span class="signature">( target : <span class="param-type"><a href="Vector4.html">Vector4</a></span> )</span><span class="type-signature"> : <a href="Vector4.html">Vector4</a></span> </h3>
  104. <div class="method">
  105. <div class="description">
  106. <p>Returns the scissor rectangle.</p>
  107. </div>
  108. <table class="params">
  109. <tbody>
  110. <tr>
  111. <td class="name">
  112. <strong>target</strong>
  113. </td>
  114. <td class="description last">
  115. <p>The method writes the result in this target object.</p>
  116. </td>
  117. </tr>
  118. </tbody>
  119. </table>
  120. <dl class="details">
  121. <dt class="tag-returns"><strong>Returns:</strong> The scissor rectangle.</dt>
  122. </dl>
  123. </div>
  124. <h3 class="name name-method" id="getScissorTest" translate="no">.<a href="#getScissorTest">getScissorTest</a><span class="signature">()</span><span class="type-signature"> : boolean</span> </h3>
  125. <div class="method">
  126. <div class="description">
  127. <p>Returns the scissor test value.</p>
  128. </div>
  129. <dl class="details">
  130. <dt class="tag-returns"><strong>Returns:</strong> Whether the scissor test should be enabled or not.</dt>
  131. </dl>
  132. </div>
  133. <h3 class="name name-method" id="getSize" translate="no">.<a href="#getSize">getSize</a><span class="signature">( target : <span class="param-type"><a href="Vector2.html">Vector2</a></span> )</span><span class="type-signature"> : <a href="Vector2.html">Vector2</a></span> </h3>
  134. <div class="method">
  135. <div class="description">
  136. <p>Returns the renderer's size in logical pixels. This method does not honor the pixel ratio.</p>
  137. </div>
  138. <table class="params">
  139. <tbody>
  140. <tr>
  141. <td class="name">
  142. <strong>target</strong>
  143. </td>
  144. <td class="description last">
  145. <p>The method writes the result in this target object.</p>
  146. </td>
  147. </tr>
  148. </tbody>
  149. </table>
  150. <dl class="details">
  151. <dt class="tag-returns"><strong>Returns:</strong> The renderer's size in logical pixels.</dt>
  152. </dl>
  153. </div>
  154. <h3 class="name name-method" id="getViewport" translate="no">.<a href="#getViewport">getViewport</a><span class="signature">( target : <span class="param-type"><a href="Vector4.html">Vector4</a></span> )</span><span class="type-signature"> : <a href="Vector4.html">Vector4</a></span> </h3>
  155. <div class="method">
  156. <div class="description">
  157. <p>Returns the viewport definition.</p>
  158. </div>
  159. <table class="params">
  160. <tbody>
  161. <tr>
  162. <td class="name">
  163. <strong>target</strong>
  164. </td>
  165. <td class="description last">
  166. <p>The method writes the result in this target object.</p>
  167. </td>
  168. </tr>
  169. </tbody>
  170. </table>
  171. <dl class="details">
  172. <dt class="tag-returns"><strong>Returns:</strong> The viewport definition.</dt>
  173. </dl>
  174. </div>
  175. <h3 class="name name-method" id="setDrawingBufferSize" translate="no">.<a href="#setDrawingBufferSize">setDrawingBufferSize</a><span class="signature">( width : <span class="param-type">number</span>, height : <span class="param-type">number</span>, pixelRatio : <span class="param-type">number</span> )</span> </h3>
  176. <div class="method">
  177. <div class="description">
  178. <p>This method allows to define the drawing buffer size by specifying
  179. width, height and pixel ratio all at once. The size of the drawing
  180. buffer is computed with this formula:</p>
  181. <pre><code class="language-js">size.x = width * pixelRatio;
  182. size.y = height * pixelRatio;
  183. </code></pre>
  184. </div>
  185. <table class="params">
  186. <tbody>
  187. <tr>
  188. <td class="name">
  189. <strong>width</strong>
  190. </td>
  191. <td class="description last">
  192. <p>The width in logical pixels.</p>
  193. </td>
  194. </tr>
  195. <tr>
  196. <td class="name">
  197. <strong>height</strong>
  198. </td>
  199. <td class="description last">
  200. <p>The height in logical pixels.</p>
  201. </td>
  202. </tr>
  203. <tr>
  204. <td class="name">
  205. <strong>pixelRatio</strong>
  206. </td>
  207. <td class="description last">
  208. <p>The pixel ratio.</p>
  209. </td>
  210. </tr>
  211. </tbody>
  212. </table>
  213. </div>
  214. <h3 class="name name-method" id="setPixelRatio" translate="no">.<a href="#setPixelRatio">setPixelRatio</a><span class="signature">( value : <span class="param-type">number</span> )</span> </h3>
  215. <div class="method">
  216. <div class="description">
  217. <p>Sets the given pixel ratio and resizes the canvas if necessary.</p>
  218. </div>
  219. <table class="params">
  220. <tbody>
  221. <tr>
  222. <td class="name">
  223. <strong>value</strong>
  224. </td>
  225. <td class="description last">
  226. <p>The pixel ratio.</p>
  227. <p>Default is <code>1</code>.</p>
  228. </td>
  229. </tr>
  230. </tbody>
  231. </table>
  232. </div>
  233. <h3 class="name name-method" id="setScissor" translate="no">.<a href="#setScissor">setScissor</a><span class="signature">( x : <span class="param-type">number | <a href="Vector4.html">Vector4</a></span>, y : <span class="param-type">number</span>, width : <span class="param-type">number</span>, height : <span class="param-type">number</span> )</span> </h3>
  234. <div class="method">
  235. <div class="description">
  236. <p>Defines the scissor rectangle.</p>
  237. </div>
  238. <table class="params">
  239. <tbody>
  240. <tr>
  241. <td class="name">
  242. <strong>x</strong>
  243. </td>
  244. <td class="description last">
  245. <p>The horizontal coordinate for the lower left corner of the box in logical pixel unit.
  246. Instead of passing four arguments, the method also works with a single four-dimensional vector.</p>
  247. </td>
  248. </tr>
  249. <tr>
  250. <td class="name">
  251. <strong>y</strong>
  252. </td>
  253. <td class="description last">
  254. <p>The vertical coordinate for the lower left corner of the box in logical pixel unit.</p>
  255. </td>
  256. </tr>
  257. <tr>
  258. <td class="name">
  259. <strong>width</strong>
  260. </td>
  261. <td class="description last">
  262. <p>The width of the scissor box in logical pixel unit.</p>
  263. </td>
  264. </tr>
  265. <tr>
  266. <td class="name">
  267. <strong>height</strong>
  268. </td>
  269. <td class="description last">
  270. <p>The height of the scissor box in logical pixel unit.</p>
  271. </td>
  272. </tr>
  273. </tbody>
  274. </table>
  275. </div>
  276. <h3 class="name name-method" id="setScissorTest" translate="no">.<a href="#setScissorTest">setScissorTest</a><span class="signature">( boolean : <span class="param-type">boolean</span> )</span> </h3>
  277. <div class="method">
  278. <div class="description">
  279. <p>Defines the scissor test.</p>
  280. </div>
  281. <table class="params">
  282. <tbody>
  283. <tr>
  284. <td class="name">
  285. <strong>boolean</strong>
  286. </td>
  287. <td class="description last">
  288. <p>Whether the scissor test should be enabled or not.</p>
  289. </td>
  290. </tr>
  291. </tbody>
  292. </table>
  293. </div>
  294. <h3 class="name name-method" id="setSize" translate="no">.<a href="#setSize">setSize</a><span class="signature">( width : <span class="param-type">number</span>, height : <span class="param-type">number</span>, updateStyle : <span class="param-type">boolean</span> )</span> </h3>
  295. <div class="method">
  296. <div class="description">
  297. <p>Sets the size of the renderer.</p>
  298. </div>
  299. <table class="params">
  300. <tbody>
  301. <tr>
  302. <td class="name">
  303. <strong>width</strong>
  304. </td>
  305. <td class="description last">
  306. <p>The width in logical pixels.</p>
  307. </td>
  308. </tr>
  309. <tr>
  310. <td class="name">
  311. <strong>height</strong>
  312. </td>
  313. <td class="description last">
  314. <p>The height in logical pixels.</p>
  315. </td>
  316. </tr>
  317. <tr>
  318. <td class="name">
  319. <strong>updateStyle</strong>
  320. </td>
  321. <td class="description last">
  322. <p>Whether to update the <code>style</code> attribute of the canvas or not.</p>
  323. <p>Default is <code>true</code>.</p>
  324. </td>
  325. </tr>
  326. </tbody>
  327. </table>
  328. </div>
  329. <h3 class="name name-method" id="setViewport" translate="no">.<a href="#setViewport">setViewport</a><span class="signature">( x : <span class="param-type">number | <a href="Vector4.html">Vector4</a></span>, y : <span class="param-type">number</span>, width : <span class="param-type">number</span>, height : <span class="param-type">number</span>, minDepth : <span class="param-type">number</span>, maxDepth : <span class="param-type">number</span> )</span> </h3>
  330. <div class="method">
  331. <div class="description">
  332. <p>Defines the viewport.</p>
  333. </div>
  334. <table class="params">
  335. <tbody>
  336. <tr>
  337. <td class="name">
  338. <strong>x</strong>
  339. </td>
  340. <td class="description last">
  341. <p>The horizontal coordinate for the lower left corner of the viewport origin in logical pixel unit.</p>
  342. </td>
  343. </tr>
  344. <tr>
  345. <td class="name">
  346. <strong>y</strong>
  347. </td>
  348. <td class="description last">
  349. <p>The vertical coordinate for the lower left corner of the viewport origin in logical pixel unit.</p>
  350. </td>
  351. </tr>
  352. <tr>
  353. <td class="name">
  354. <strong>width</strong>
  355. </td>
  356. <td class="description last">
  357. <p>The width of the viewport in logical pixel unit.</p>
  358. </td>
  359. </tr>
  360. <tr>
  361. <td class="name">
  362. <strong>height</strong>
  363. </td>
  364. <td class="description last">
  365. <p>The height of the viewport in logical pixel unit.</p>
  366. </td>
  367. </tr>
  368. <tr>
  369. <td class="name">
  370. <strong>minDepth</strong>
  371. </td>
  372. <td class="description last">
  373. <p>The minimum depth value of the viewport. WebGPU only.</p>
  374. <p>Default is <code>0</code>.</p>
  375. </td>
  376. </tr>
  377. <tr>
  378. <td class="name">
  379. <strong>maxDepth</strong>
  380. </td>
  381. <td class="description last">
  382. <p>The maximum depth value of the viewport. WebGPU only.</p>
  383. <p>Default is <code>1</code>.</p>
  384. </td>
  385. </tr>
  386. </tbody>
  387. </table>
  388. </div>
  389. <h2 class="subsection-title">Source</h2>
  390. <p>
  391. <a href="https://github.com/mrdoob/three.js/blob/master/src/renderers/common/CanvasTarget.js" translate="no" target="_blank" rel="noopener">src/renderers/common/CanvasTarget.js</a>
  392. </p>
  393. </article>
  394. </section>
  395. <script src="../scripts/linenumber.js"></script>
  396. <script src="../scripts/page.js"></script>
  397. </body>
  398. </html>
粤ICP备19079148号