| 85 | } |
| 86 | |
| 87 | bool TextureGL::Init(ovrTextureType Type, int Width, int Height, int MipLevels, int SampleCount, |
| 88 | int ArraySize, ovrTextureFormat Format, unsigned int MiscFlags, unsigned int BindFlags) |
| 89 | { |
| 90 | GLenum internalFormat = TextureFormatToInternalFormat(Format); |
| 91 | GLenum format = TextureFormatToGLFormat(Format); |
| 92 | |
| 93 | glCreateTextures(SampleCount > 1 ? GL_TEXTURE_2D_MULTISAMPLE : GL_TEXTURE_2D, 1, &Texture); |
| 94 | glTextureParameteri(Texture, GL_TEXTURE_BASE_LEVEL, 0); |
| 95 | glTextureParameteri(Texture, GL_TEXTURE_MAX_LEVEL, 0); |
| 96 | if (SampleCount > 1) |
| 97 | glTextureStorage2DMultisample(Texture, SampleCount, internalFormat, Width, Height, GL_FALSE); |
| 98 | else |
| 99 | glTextureStorage2D(Texture, 1, internalFormat, Width, Height); |
| 100 | |
| 101 | m_Width = Width; |
| 102 | m_Height = Height; |
| 103 | |
| 104 | if (SampleCount > 1 || Type == ovrTexture_2D_External) |
| 105 | { |
| 106 | GLenum attachment = format == GL_DEPTH_COMPONENT || format == GL_DEPTH_STENCIL ? |
| 107 | GL_DEPTH_ATTACHMENT : GL_COLOR_ATTACHMENT0; |
| 108 | |
| 109 | glCreateFramebuffers(1, &Framebuffer); |
| 110 | glNamedFramebufferTexture(Framebuffer, attachment, Texture, 0); |
| 111 | glNamedFramebufferReadBuffer(Framebuffer, attachment); |
| 112 | glNamedFramebufferDrawBuffer(Framebuffer, attachment); |
| 113 | GLenum completeness = glCheckNamedFramebufferStatus(Framebuffer, GL_FRAMEBUFFER); |
| 114 | if (completeness != GL_FRAMEBUFFER_COMPLETE) |
| 115 | return false; |
| 116 | |
| 117 | if (SampleCount > 1) |
| 118 | { |
| 119 | // SteamVR doesn't support OpenGL MSAA textures, so we have to resolve it before returning a VR texture |
| 120 | glCreateTextures(GL_TEXTURE_2D, 1, &ResolveTexture); |
| 121 | glTextureParameteri(ResolveTexture, GL_TEXTURE_BASE_LEVEL, 0); |
| 122 | glTextureParameteri(ResolveTexture, GL_TEXTURE_MAX_LEVEL, 0); |
| 123 | glTextureStorage2D(ResolveTexture, 1, internalFormat, Width, Height); |
| 124 | |
| 125 | glCreateFramebuffers(1, &ResolveFramebuffer); |
| 126 | glNamedFramebufferTexture(ResolveFramebuffer, attachment, ResolveTexture, 0); |
| 127 | glNamedFramebufferReadBuffer(ResolveFramebuffer, attachment); |
| 128 | glNamedFramebufferDrawBuffer(ResolveFramebuffer, attachment); |
| 129 | if (glCheckNamedFramebufferStatus(ResolveFramebuffer, GL_FRAMEBUFFER) != GL_FRAMEBUFFER_COMPLETE) |
| 130 | return false; |
| 131 | } |
| 132 | } |
| 133 | |
| 134 | return true; |
| 135 | } |
| 136 | |
| 137 | bool TextureGL::CreateSharedTextureGL(unsigned int* outName) |
| 138 | { |
nothing calls this directly
no outgoing calls
no test coverage detected