gm-docs-parser 1.0.0

A collection of typings for GameMaker Studio 2 manual pages
Documentation
<?xml version="1.0" encoding="utf-8" ?>

<!DOCTYPE html>
<html xmlns="http://www.w3.org/1999/xhtml"><head>

  <script type="text/javascript" language="JavaScript">
    //<![CDATA[
    function reDo() {
      if (innerWidth != origWidth || innerHeight != origHeight)
        location.reload();
    }
    if ((parseInt(navigator.appVersion) == 4) && (navigator.appName == "Netscape")) {
      origWidth = innerWidth;
      origHeight = innerHeight;
      onresize = reDo;
    }
    onerror = null;
  //]]>
  </script>
  <style type="text/css">/*<![CDATA[*/

    < !-- div.WebHelpPopupMenu {
      position: absolute;
      left: 0px;
      top: 0px;
      z-index: 4;
      visibility: hidden;
    }

    p.WebHelpNavBar {
      text-align: right;
    }

    -->
  
/*]]>*/</style>

  <script type="text/javascript">//<![CDATA[

    gRootRelPath = "../../../..";
    gCommonRootRelPath = "../../../..";
    gTopicId = "9.2.5.8.0_12";
  
//]]></script>

  <script type="text/javascript" src="../../../../template/scripts/rh.min.js"></script>
  <script type="text/javascript" src="../../../../template/scripts/common.min.js"></script>
  <script type="text/javascript" src="../../../../template/scripts/topic.min.js"></script>
  <script type="text/javascript" src="../../../../template/scripts/topicwidgets.min.js"></script>
<script type="text/javascript" src="../../../../whxdata/projectsettings.js"></script>
  <link rel="stylesheet" type="text/css" href="../../../../template/styles/topic.min.css"/>
  <link rel="stylesheet" type="text/css" href="../../../../template/Charcoal_Grey/topicheader.css"/>
  <meta name="topic-status" content="Draft"/>

  <meta http-equiv="Content-Type" content="text/html; charset=utf-8"/>
  <title>surface_depth_disable</title>
  <meta name="generator" content="Adobe RoboHelp 2019"/>
  <link rel="stylesheet" href="../../../../assets/css/default.css" type="text/css"/>
  <meta name="rh-authors" content="Mark Alexander"/>
  <meta name="topic-comment" content="Reference for surface_depth_disable"/>
  <meta name="rh-index-keywords" content="surface_depth_disable"/>
  <meta name="search-keywords" content="surface_depth_disable"/>
</head>

<body>
  <div class="topic-header rh-hide" id="rh-topic-header" onclick="rh._.goToFullLayout()">
    <div class="logo">
    </div>
    <div class="nav">
      <div class="title" title="surface_depth_disable">
        <span>surface_depth_disable</span>
      </div>
      <div class="gotohome" title="Click here to see this page in full context">
        <span>Click here to see this page in full context</span>
      </div>
    </div>
  </div>
  <div class="topic-header-shadow rh-hide" id="rh-topic-header-shadow"></div>



  <!--<div class="body-scroll" style="top: 150px;">-->
  <h1>surface_depth_disable</h1>
  <p>This function disables the automatic depth buffer generation for <i>all</i> surfaces that are created after it has been disabled. Normally all surfaces have depth buffers so if you draw 3D objects to them then it&#39;ll sort them properly by depth in
    order to maintain functional parity between rendering to surfaces and rendering to the back buffer, however allocating depth buffers essentially doubles the amount of memory required for surfaces, which could be an excessive and unnecessary overhead
    especially if your game is very memory intensive, and for 2D games they aren&#39;t generally required.</p>
  <p>To use this function you would call it <i>before</i> creating a surface, and then you can enable it again after (if required). All surfaces created when the depth buffer is disabled will no longer use a depth buffer when being drawn to, this results
    in the things being drawn to the surface having parity of depth. The images below illustrate this in practice:</p>
  <p><img alt="Surface depth buffer example" class="center" src="../../../../assets/Images/Scripting_Reference/GML/Reference/Drawing/Surface_Depth_Buffer.png"/>In the above image, we are drawing a rectangle and a triangle using a vertex buffer in 3D. The
    coordinates for the red triangle places it behind the green rectangle, but the code for drawing the triangle is called <i>after</i> the code for the rectangle, and when the depth buffer is enabled, the triangle is still drawn behind the rectangle
    as the 3D depth is being respected. However when we disable the depth buffer for the surface, only the code order is respected and so the triangle is drawn over the rectangle.</p>
  <p class="note"><b>NOTE</b>: To properly preserve depth in 3D when using surfaces, not only should you have the depth buffer enabled, but you should also have z-writing and z-testing enabled. See the functions <a href="../GPU_Control/gpu_get_ztestenable.htm"><tt><span style="font-size:14px;">gpu_set_ztestenable()</span></tt></a>    and <a href="../GPU_Control/gpu_get_zwriteenable.htm"><tt><span style="font-size:14px;">gpu_set_zwriteenable()</span></tt></a> for more information.</p>
  <p class="note"><b>NOTE</b>: If your game is 100% 2D or you know that you don&#39;t need a surface depth buffer, then it should be fine to simply call this function once at the start of the game to disable the buffer.</p>
  <p> </p>
  <h4>Syntax:</h4>
  <p class="code">surface_depth_disable(disable);</p>
  <table>
    <tbody>
      <tr>
        <th>Argument</th>
        <th>Description</th>
      </tr>
      <tr>
        <td>disable</td>
        <td>If set to <tt>true</tt> the depth buffer will be disabled for created surfaces.</td>
      </tr>
    </tbody>
  </table>
  <p> </p>
  <h4>Returns:</h4>
  <p class="code">N/A</p>
  <p> </p>
  <h4>Example:</h4>
  <p class="code">var _depth_setting = surface_get_depth_disable();<br/> surface_depth_disable(false);
    <br/> surface_with_depth = surface_create(room_width, room_height);<br/> surface_depth_disable(true);
    <br/> surface_without_depth = surface_create(room_width, room_height);<br/> surface_depth_disable(_depth_setting);
  </p>
  <p>The above code stores the current depth buffer setting in a variable and then creates two surfaces, one with depth buffering enabled and one without, before restoring the original setting again.</p>
  <p> </p>
  <p> </p>
  <p> </p>
  <div class="footer">
    <div class="buttons">
      <div class="clear">
        <div style="float:left">Back: <a href="Surfaces.htm">Surfaces</a></div>
        <div style="float:right">Next: <a href="surface_get_height.htm">surface_get_height</a></div>
      </div>
    </div>
    <h5>© Copyright YoYo Games Ltd. 2020 All Rights Reserved</h5>
  </div>
  <!-- KEYWORDS
surface_depth_disable
-->
  <!-- TAGS
surface_depth_disable
-->

</body></html>