| 42 | } |
| 43 | |
| 44 | std::unique_ptr<GLMultisampleTexture> GLMultisampleTexture::MakeFrom( |
| 45 | GLGPU* gpu, const GPUTextureDescriptor& descriptor) { |
| 46 | DEBUG_ASSERT(gpu != nullptr); |
| 47 | DEBUG_ASSERT(descriptor.sampleCount > 1); |
| 48 | if (!(descriptor.usage & GPUTextureUsage::RENDER_ATTACHMENT)) { |
| 49 | LOGE("GLMultisampleTexture::MakeFrom() usage does not include RENDER_ATTACHMENT!"); |
| 50 | return nullptr; |
| 51 | } |
| 52 | if (descriptor.usage & GPUTextureUsage::TEXTURE_BINDING) { |
| 53 | LOGE("GLMultisampleTexture::MakeFrom() usage includes TEXTURE_BINDING!"); |
| 54 | return nullptr; |
| 55 | } |
| 56 | if (descriptor.mipLevelCount > 1) { |
| 57 | LOGE("GLMultisampleTexture::MakeFrom() mipLevelCount should be 1 for multisample textures!"); |
| 58 | return nullptr; |
| 59 | } |
| 60 | auto caps = static_cast<const GLCaps*>(gpu->caps()); |
| 61 | if (!caps->isFormatRenderable(descriptor.format)) { |
| 62 | LOGE("GLMultisampleTexture::MakeFrom() format is not renderable!"); |
| 63 | return nullptr; |
| 64 | } |
| 65 | unsigned frameBufferID = 0; |
| 66 | auto gl = gpu->functions(); |
| 67 | gl->genFramebuffers(1, &frameBufferID); |
| 68 | if (frameBufferID == 0) { |
| 69 | LOGE("GLMultisampleTexture::MakeFrom() failed to generate framebuffer!"); |
| 70 | return nullptr; |
| 71 | } |
| 72 | auto texture = |
| 73 | std::unique_ptr<GLMultisampleTexture>(new GLMultisampleTexture(descriptor, frameBufferID)); |
| 74 | gl->genRenderbuffers(1, &texture->renderBufferID); |
| 75 | if (texture->renderBufferID == 0) { |
| 76 | texture->release(gpu); |
| 77 | LOGE("GLMultisampleTexture::MakeFrom() failed to generate renderbuffer!"); |
| 78 | return nullptr; |
| 79 | } |
| 80 | gl->bindRenderbuffer(GL_RENDERBUFFER, texture->renderBufferID); |
| 81 | if (!RenderbufferStorageMSAA(gpu, descriptor.sampleCount, descriptor.format, descriptor.width, |
| 82 | descriptor.height)) { |
| 83 | texture->release(gpu); |
| 84 | return nullptr; |
| 85 | } |
| 86 | auto state = gpu->state(); |
| 87 | state->bindFramebuffer(texture.get()); |
| 88 | gl->framebufferRenderbuffer(GL_FRAMEBUFFER, GL_COLOR_ATTACHMENT0, GL_RENDERBUFFER, |
| 89 | texture->renderBufferID); |
| 90 | #ifndef TGFX_BUILD_FOR_WEB |
| 91 | if (gl->checkFramebufferStatus(GL_FRAMEBUFFER) != GL_FRAMEBUFFER_COMPLETE) { |
| 92 | LOGE("GLMultisampleTexture::MakeFrom() framebuffer is not complete!"); |
| 93 | texture->release(gpu); |
| 94 | return nullptr; |
| 95 | } |
| 96 | #endif |
| 97 | return texture; |
| 98 | } |
| 99 | |
| 100 | void GLMultisampleTexture::onRelease(GLGPU* gpu) { |
| 101 | auto gl = gpu->functions(); |
nothing calls this directly
no test coverage detected