26 #include <OVR_CAPI_GL.h>
31 size_t wdt = img.
width();
33 for (
size_t h = 0; h < hgt; h++)
35 for (
size_t w = 0; w < wdt; w++)
40 rgba[(wdt * h + w) * 4 + 3] = alpha;
52 yCError(
OVRHEADSET) <<
"wrong texture format.. must be VOCAB_PIXEL_RGBA or VOCAB_PIXEL_RGB";
77 createTextureAndBuffers();
83 textureSwapChain(nullptr),
84 textureSwapChainSize(0),
99 textureSwapChain(nullptr),
100 textureSwapChainSize(0),
103 components(
eye == 2 ? 4 : 3),
105 padding((4 - (w * components) % 4) % 4),
106 rowSize(w * components + padding),
107 bufferSize(rowSize * h),
121 createTextureAndBuffers();
128 deleteTextureAndBuffers();
134 deleteTextureAndBuffers();
142 createTextureAndBuffers();
193 glBindTexture(GL_TEXTURE_2D, texId);
194 glBindBuffer(GL_PIXEL_UNPACK_BUFFER,
pboIds[index]);
197 glUnmapBuffer(GL_PIXEL_UNPACK_BUFFER);
203 glTexSubImage2D(GL_TEXTURE_2D, 0, 0, 0,
width,
height, (
components == 3 ? GL_RGB : GL_RGBA), GL_UNSIGNED_BYTE, 0);
205 glBindBuffer(GL_PIXEL_UNPACK_BUFFER, 0);
211 glBindTexture(GL_TEXTURE_2D, texId);
214 glBindBuffer(GL_PIXEL_UNPACK_BUFFER,
pboIds[index]);
223 glBufferData(GL_PIXEL_UNPACK_BUFFER,
bufferSize, 0, GL_DYNAMIC_DRAW);
226 ptr = (GLubyte*)glMapBuffer(GL_PIXEL_UNPACK_BUFFER, GL_WRITE_ONLY);
234 glBindBuffer(GL_PIXEL_UNPACK_BUFFER, 0);
244 void TextureBuffer::createTextureAndBuffers()
249 ovrTextureSwapChainDesc desc = {};
250 desc.Type = ovrTexture_2D;
252 desc.Format = OVR_FORMAT_R8G8B8A8_UNORM_SRGB;
256 desc.SampleCount = 1;
257 desc.StaticImage = ovrFalse;
271 glBindTexture(GL_TEXTURE_2D, texId);
272 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR);
273 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR);
274 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_CLAMP_TO_EDGE);
275 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_CLAMP_TO_EDGE);
276 glBindTexture(GL_TEXTURE_2D, 0);
283 glBindBuffer(GL_PIXEL_UNPACK_BUFFER,
pboIds[0]);
284 glBufferData(GL_PIXEL_UNPACK_BUFFER,
bufferSize, 0, GL_DYNAMIC_DRAW);
286 ptr = (GLubyte*)glMapBuffer(GL_PIXEL_UNPACK_BUFFER, GL_WRITE_ONLY);
288 glUnmapBuffer(GL_PIXEL_UNPACK_BUFFER);
290 glBindBuffer(GL_PIXEL_UNPACK_BUFFER, 0);
299 glBindTexture(GL_TEXTURE_2D, texId);
300 glBindBuffer(GL_PIXEL_UNPACK_BUFFER,
pboIds[index]);
301 glBufferData(GL_PIXEL_UNPACK_BUFFER,
bufferSize, 0, GL_DYNAMIC_DRAW);
302 ptr = (GLubyte*)glMapBuffer(GL_PIXEL_UNPACK_BUFFER, GL_WRITE_ONLY);
303 glBindBuffer(GL_PIXEL_UNPACK_BUFFER, 0);
308 void TextureBuffer::deleteTextureAndBuffers()
315 glUnmapBuffer(GL_PIXEL_UNPACK_BUFFER);