aboutsummaryrefslogtreecommitdiff
path: root/files/zh-cn/web/api/webglrenderingcontext/pixelstorei/index.html
blob: 1a84fa6f9a50e97933d173e0678b96e5388a3b3b (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
---
title: WebGLRenderingContext.pixelStorei()
slug: Web/API/WebGLRenderingContext/pixelStorei
translation_of: Web/API/WebGLRenderingContext/pixelStorei
---
<div>{{APIRef("WebGL")}}</div>

<p><strong><code>WebGLRenderingContext.pixelStorei()</code></strong> 是 <a href="/en-US/docs/Web/API/WebGL_API">WebGL API</a> 中用于图像预处理的函数。</p>

<h2 id="语法">语法</h2>

<pre class="syntaxbox">void <var>gl</var>.pixelStorei(<var>pname</var>, <var>param</var>);
</pre>

<h3 id="参数">参数</h3>

<dl>
 <dt>pname</dt>
 <dd> {{domxref("Glenum")}} 类型 ,表示处理的方式。关于该参数可选值,请见下面表格。</dd>
 <dt>param</dt>
 <dd> {{domxref("GLint")}}  类型,表示 pname 处理方式的参数。关于该参数可选值,请见下面表格。</dd>
</dl>

<h3 id="返回值">返回值</h3>

<p>None.</p>

<h2 id="像素存储参数">像素存储参数</h2>

<table class="standard-table">
 <thead>
  <tr>
   <th scope="col">模式名称 (<code>pname</code>)</th>
   <th scope="col">描述</th>
   <th scope="col">类型</th>
   <th scope="col">默认值</th>
   <th scope="col"> param 的可选值</th>
   <th scope="col">Specified in</th>
  </tr>
 </thead>
 <tbody>
  <tr>
   <td><code>gl.PACK_ALIGNMENT</code></td>
   <td>Packing of pixel data into memory</td>
   <td>{{domxref("GLint")}}</td>
   <td>4</td>
   <td>1, 2, 4, 8</td>
   <td>OpenGL ES 2.0</td>
  </tr>
  <tr>
   <td><code>gl.UNPACK_ALIGNMENT</code></td>
   <td>Unpacking of pixel data from memory.</td>
   <td>{{domxref("GLint")}}</td>
   <td>4</td>
   <td>1, 2, 4, 8</td>
   <td>OpenGL ES 2.0</td>
  </tr>
  <tr>
   <td><code>gl.UNPACK_FLIP_Y_WEBGL</code></td>
   <td>
    <p dir="ltr" id="tw-target-text">如果为true,则把图片上下对称翻转坐标轴(图片本身不变)。</p>
   </td>
   <td>{{domxref("GLboolean")}}</td>
   <td>false</td>
   <td>true, false</td>
   <td>WebGL</td>
  </tr>
  <tr>
   <td><code>gl.UNPACK_PREMULTIPLY_ALPHA_WEBGL</code></td>
   <td>Multiplies the alpha channel into the other color channels</td>
   <td>{{domxref("GLboolean")}}</td>
   <td>false</td>
   <td>true, false</td>
   <td>WebGL</td>
  </tr>
  <tr>
   <td><code>gl.UNPACK_COLORSPACE_CONVERSION_WEBGL</code></td>
   <td>Default color space conversion or no color space conversion.</td>
   <td>{{domxref("GLenum")}}</td>
   <td><code>gl.BROWSER_DEFAULT_WEBGL</code></td>
   <td><code>gl.BROWSER_DEFAULT_WEBGL</code>, <code>gl.NONE</code></td>
   <td>WebGL</td>
  </tr>
 </tbody>
</table>

<p>When using a {{domxref("WebGL2RenderingContext", "WebGL 2 context", "", 1)}}, the following values are available additionally:</p>

<table class="standard-table">
 <thead>
  <tr>
   <th scope="col">Constant</th>
   <th scope="col">Description</th>
   <th scope="col">Type</th>
   <th scope="col">Default value</th>
   <th scope="col">Allowed values (for <code>param</code>)</th>
   <th scope="col">Specified in</th>
  </tr>
 </thead>
 <tbody>
  <tr>
   <td><code>gl.PACK_ROW_LENGTH</code></td>
   <td>Number of pixels in a row.</td>
   <td>{{domxref("GLint")}}</td>
   <td>0</td>
   <td>0 to <code>Infinity</code></td>
   <td>OpenGL ES 3.0</td>
  </tr>
  <tr>
   <td><code>gl.PACK_SKIP_PIXELS</code></td>
   <td>Number of pixel locations skipped before the first pixel is written into memory.</td>
   <td>{{domxref("GLint")}}</td>
   <td>0</td>
   <td>0 to <code>Infinity</code></td>
   <td>OpenGL ES 3.0</td>
  </tr>
  <tr>
   <td><code>gl.PACK_SKIP_ROWS</code></td>
   <td>Number of rows of pixel locations skipped before the first pixel is written into memory</td>
   <td>{{domxref("GLint")}}</td>
   <td>0</td>
   <td>0 to <code>Infinity</code></td>
   <td>OpenGL ES 3.0</td>
  </tr>
  <tr>
   <td><code>gl.UNPACK_ROW_LENGTH</code></td>
   <td>Number of pixels in a row.</td>
   <td>{{domxref("GLint")}}</td>
   <td>0</td>
   <td>0 to <code>Infinity</code></td>
   <td>OpenGL ES 3.0</td>
  </tr>
  <tr>
   <td><code>gl.UNPACK_IMAGE_HEIGHT</code></td>
   <td>Image height used for reading pixel data from memory</td>
   <td>{{domxref("GLint")}}</td>
   <td>0</td>
   <td>0 to <code>Infinity</code></td>
   <td>OpenGL ES 3.0</td>
  </tr>
  <tr>
   <td><code>gl.UNPACK_SKIP_PIXELS</code></td>
   <td>Number of pixel images skipped before the first pixel is read from memory</td>
   <td>{{domxref("GLint")}}</td>
   <td>0</td>
   <td>0 to <code>Infinity</code></td>
   <td>OpenGL ES 3.0</td>
  </tr>
  <tr>
   <td><code>gl.UNPACK_SKIP_ROWS</code></td>
   <td>Number of rows of pixel locations skipped before the first pixel is read from memory</td>
   <td>{{domxref("GLint")}}</td>
   <td>0</td>
   <td>0 to <code>Infinity</code></td>
   <td>OpenGL ES 3.0</td>
  </tr>
  <tr>
   <td><code>gl.UNPACK_SKIP_IMAGES</code></td>
   <td>Number of pixel images skipped before the first pixel is read from memory</td>
   <td>{{domxref("GLint")}}</td>
   <td>0</td>
   <td>0 to <code>Infinity</code></td>
   <td>OpenGL ES 3.0</td>
  </tr>
 </tbody>
</table>

<h2 id="Examples">Examples</h2>

<p>Setting the pixel storage mode affects the {{domxref("WebGLRenderingContext.readPixels()")}} operations, as well as unpacking of textures with the {{domxref("WebGLRenderingContext.texImage2D()")}} and {{domxref("WebGLRenderingContext.texSubImage2D()")}} methods.<br>
  </p>

<pre class="brush: js">var tex = gl.createTexture();
gl.bindTexture(gl.TEXTURE_2D, tex);
gl.pixelStorei(gl.PACK_ALIGNMENT, 4);
</pre>

<p>To check the values for packing and unpacking of pixel data, you can query the same pixel storage parameters with {{domxref("WebGLRenderingContext.getParameter()")}}.</p>

<pre class="brush: js">gl.getParameter(gl.PACK_ALIGNMENT);
gl.getParameter(gl.UNPACK_ALIGNMENT);
</pre>

<h2 id="Specifications">Specifications</h2>

<table class="standard-table">
 <tbody>
  <tr>
   <th scope="col">Specification</th>
   <th scope="col">Status</th>
   <th scope="col">Comment</th>
  </tr>
  <tr>
   <td>{{SpecName('WebGL', "#5.14.3", "pixelStorei")}}</td>
   <td>{{Spec2('WebGL')}}</td>
   <td>Initial definition for WebGL.</td>
  </tr>
  <tr>
   <td>{{SpecName('WebGL', "#PIXEL_STORAGE_PARAMETERS", "Pixel Storage Parameters")}}</td>
   <td>{{Spec2('WebGL')}}</td>
   <td>Additional pixel storage parameters that aren't specified in OpenGL.</td>
  </tr>
  <tr>
   <td>{{SpecName('OpenGL ES 2.0', "glPixelStorei.xml", "glPixelStorei")}}</td>
   <td>{{Spec2('OpenGL ES 2.0')}}</td>
   <td>Man page of the OpenGL ES 2.0 API.</td>
  </tr>
  <tr>
   <td>{{SpecName('WebGL2', "#3.7.2", "pixelStorei")}}</td>
   <td>{{Spec2('WebGL2')}}</td>
   <td>Updated definition for WebGL 2.</td>
  </tr>
  <tr>
   <td>{{SpecName('OpenGL ES 3.0', "glPixelStorei.xhtml", "glPixelStorei")}}</td>
   <td>{{Spec2('OpenGL ES 3.0')}}</td>
   <td>Man page of the OpenGL ES 3.0 API.</td>
  </tr>
 </tbody>
</table>

<h2 id="Browser_compatibility">Browser compatibility</h2>

<p class="hidden">The compatibility table in this page is generated from structured data. If you'd like to contribute to the data, please check out <a href="https://github.com/mdn/browser-compat-data">https://github.com/mdn/browser-compat-data</a> and send us a pull request.</p>

<p>{{Compat("api/WebGLRenderingContext", "WebGLRenderingContext.pixelStorei")}}</p>

<h2 id="See_also">See also</h2>

<ul>
 <li>{{domxref("WebGLRenderingContext.readPixels()")}}</li>
 <li>{{domxref("WebGLRenderingContext.texImage2D()")}}</li>
 <li>{{domxref("WebGLRenderingContext.texSubImage2D()")}}</li>
</ul>