--- title: WebGL2RenderingContext.createSampler() slug: Web/API/WebGL2RenderingContext/createSampler translation_of: Web/API/WebGL2RenderingContext/createSampler --- <div>{{APIRef("WebGL")}} {{SeeCompatTable}}</div> <p><a href="/en-US/docs/Web/API/WebGL_API">WebGL 2 API</a> 定义的 <code><strong>WebGL2RenderingContext.createSampler()</strong></code> 方法用于创建并初始化 {{domxref("WebGLSampler")}} 对象.</p> <h2 id="句法">句法</h2> <pre class="syntaxbox">WebGLSampler <var>gl</var>.createSampler(); </pre> <h3 id="参数">参数</h3> <p>无.</p> <h3 id="返回值">返回值</h3> <p>{{domxref("WebGLSampler")}} 对象.</p> <h2 id="例子">例子</h2> <p><code>gl</code> 必须是 {{domxref("WebGL2RenderingContext")}} 类型. WebGL 1 不支持 <code>WebGLSampler</code> 对象.</p> <pre class="brush: js">var sampler = gl.createSampler(); </pre> <h2 id="相关规范">相关规范</h2> <table class="standard-table"> <tbody> <tr> <th scope="col">规范名</th> <th scope="col">状态</th> <th scope="col">备注</th> </tr> <tr> <td>{{SpecName('WebGL2', "#3.7.13", "createSampler")}}</td> <td>{{Spec2('WebGL2')}}</td> <td>初稿.</td> </tr> <tr> <td>{{SpecName('OpenGL ES 3.0', "glGenSamplers.xhtml", "glGenSamplers")}}</td> <td>{{Spec2('OpenGL ES 3.0')}}</td> <td>OpenGL API 的手册.</td> </tr> </tbody> </table> <h2 id="浏览器兼容">浏览器兼容</h2> <p>{{Compat("api.WebGL2RenderingContext.createSampler")}}</p> <h2 id="另见">另见</h2> <ul> <li>{{domxref("WebGLSampler")}}</li> </ul>