MCPcopy Create free account
hub / github.com/WolfireGames/overgrowth / TextureBuffer

Method TextureBuffer

Source/Main/engine.cpp:203–277  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

201 Sizei texSize;
202
203 TextureBuffer(ovrSession session, bool rendertarget, bool displayableOnHmd, Sizei size, int mipLevels, unsigned char* data, int sampleCount) : Session(session),
204 TextureChain(NULL),
205 texId(0),
206 fboId(0),
207 texSize(0, 0) {
208 UNREFERENCED_PARAMETER(sampleCount);
209
210 assert(sampleCount <= 1); // The code doesn't currently handle MSAA textures.
211
212 texSize = size;
213
214 if (displayableOnHmd) {
215 // This texture isn't necessarily going to be a rendertarget, but it usually is.
216 assert(session); // No HMD? A little odd.
217 assert(sampleCount == 1); // ovr_CreateSwapTextureSetD3D11 doesn't support MSAA.
218
219 ovrTextureSwapChainDesc desc = {};
220 desc.Type = ovrTexture_2D;
221 desc.ArraySize = 1;
222 desc.Width = size.w;
223 desc.Height = size.h;
224 desc.MipLevels = 1;
225 desc.Format = OVR_FORMAT_R8G8B8A8_UNORM_SRGB;
226 desc.SampleCount = 1;
227 desc.StaticImage = ovrFalse;
228
229 ovrResult result = ovr_CreateTextureSwapChainGL(Session, &desc, &TextureChain);
230
231 int length = 0;
232 ovr_GetTextureSwapChainLength(session, TextureChain, &length);
233
234 if (OVR_SUCCESS(result)) {
235 for (int i = 0; i < length; ++i) {
236 GLuint chainTexId;
237 ovr_GetTextureSwapChainBufferGL(Session, TextureChain, i, &chainTexId);
238 glBindTexture(GL_TEXTURE_2D, chainTexId);
239
240 if (rendertarget) {
241 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR);
242 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR);
243 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_CLAMP_TO_EDGE);
244 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_CLAMP_TO_EDGE);
245 } else {
246 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR_MIPMAP_LINEAR);
247 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR);
248 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_REPEAT);
249 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_REPEAT);
250 }
251 }
252 }
253 } else {
254 glGenTextures(1, &texId);
255 glBindTexture(GL_TEXTURE_2D, texId);
256
257 if (rendertarget) {
258 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR);
259 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR);
260 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_CLAMP_TO_EDGE);

Callers

nothing calls this directly

Calls 4

genFramebuffersMethod · 0.80

Tested by

no test coverage detected