Swap chains, part 2 (#94)

This commit is contained in:
Kai Ninomiya
2017-07-27 18:30:57 -07:00
committed by GitHub
parent 3818e18c5c
commit c16a67ae52
49 changed files with 771 additions and 435 deletions

View File

@@ -104,21 +104,13 @@ namespace opengl {
glGenFramebuffers(1, &currentFBO);
glBindFramebuffer(GL_DRAW_FRAMEBUFFER, currentFBO);
auto* device = ToBackend(GetDevice());
const auto& info = currentRenderPass->GetSubpassInfo(currentSubpass);
for (uint32_t index = 0; index < info.colorAttachments.size(); ++index) {
uint32_t attachment = info.colorAttachments[index];
// TODO(kainino@chromium.org): currently a 'null' texture view
// falls back to the 'back buffer' but this should go away
// when we have WSI.
GLuint texture = 0;
if (auto textureView = currentFramebuffer->GetTextureView(attachment)) {
texture = ToBackend(textureView->GetTexture())->GetHandle();
} else {
texture = device->GetCurrentTexture();
}
auto textureView = currentFramebuffer->GetTextureView(attachment);
GLuint texture = ToBackend(textureView->GetTexture())->GetHandle();
glFramebufferTexture2D(GL_DRAW_FRAMEBUFFER,
GL_COLOR_ATTACHMENT0 + index,
GL_TEXTURE_2D, texture, 0);
@@ -131,6 +123,7 @@ namespace opengl {
nxt::TextureFormat format = textureView->GetTexture()->GetFormat();
GLenum glAttachment = 0;
// TODO(kainino@chromium.org): it may be valid to just always use GL_DEPTH_STENCIL_ATTACHMENT here.
if (TextureFormatHasDepth(format)) {
if (TextureFormatHasStencil(format)) {
glAttachment = GL_DEPTH_STENCIL_ATTACHMENT;

View File

@@ -30,11 +30,6 @@ namespace opengl {
nxtProcTable GetNonValidatingProcs();
nxtProcTable GetValidatingProcs();
void HACKCLEAR(nxtDevice device) {
Device* backendDevice = reinterpret_cast<Device*>(device);
backendDevice->HACKCLEAR();
}
void Init(void* (*getProc)(const char*), nxtProcTable* procs, nxtDevice* device) {
*device = nullptr;
@@ -44,17 +39,6 @@ namespace opengl {
*device = reinterpret_cast<nxtDevice>(new Device);
glEnable(GL_DEPTH_TEST);
HACKCLEAR(*device);
}
void InitBackbuffer(nxtDevice device) {
Device* backendDevice = reinterpret_cast<Device*>(device);
backendDevice->InitBackbuffer();
}
void CommitBackbuffer(nxtDevice device) {
Device* backendDevice = reinterpret_cast<Device*>(device);
backendDevice->CommitBackbuffer();
}
// Device
@@ -117,36 +101,6 @@ namespace opengl {
void Device::TickImpl() {
}
void Device::HACKCLEAR() {
glBindFramebuffer(GL_DRAW_FRAMEBUFFER, backFBO);
glClearColor(0, 0, 0, 1);
glClear(GL_COLOR_BUFFER_BIT);
}
void Device::InitBackbuffer() {
glGenTextures(1, &backTexture);
glBindTexture(GL_TEXTURE_2D, backTexture);
glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA8, 640, 480, 0, GL_RGBA, GL_UNSIGNED_BYTE, nullptr);
glGenFramebuffers(1, &backFBO);
glBindFramebuffer(GL_READ_FRAMEBUFFER, backFBO);
glFramebufferTexture2D(GL_READ_FRAMEBUFFER, GL_COLOR_ATTACHMENT0,
GL_TEXTURE_2D, backTexture, 0);
HACKCLEAR();
}
void Device::CommitBackbuffer() {
glBindFramebuffer(GL_READ_FRAMEBUFFER, backFBO);
glBindFramebuffer(GL_DRAW_FRAMEBUFFER, 0);
glBlitFramebuffer(0, 0, 640, 480, 0, 0, 640, 480,
GL_COLOR_BUFFER_BIT, GL_NEAREST);
}
GLuint Device::GetCurrentTexture() {
return backTexture;
}
// Bind Group
BindGroup::BindGroup(BindGroupBuilder* builder)

View File

@@ -104,15 +104,6 @@ namespace opengl {
TextureViewBase* CreateTextureView(TextureViewBuilder* builder) override;
void TickImpl() override;
void HACKCLEAR();
void InitBackbuffer();
void CommitBackbuffer();
GLuint GetCurrentTexture();
private:
GLuint backFBO = 0;
GLuint backTexture = 0;
};
class BindGroup : public BindGroupBase {

View File

@@ -14,6 +14,7 @@
#include "backend/opengl/SwapChainGL.h"
#include "backend/Device.h"
#include "backend/opengl/TextureGL.h"
#include <nxt/nxt_wsi.h>
@@ -24,18 +25,21 @@ namespace opengl {
SwapChain::SwapChain(SwapChainBuilder* builder)
: SwapChainBase(builder) {
const auto& im = GetImplementation();
nxtWSIContextGL wsiContext = {};
// TODO(kainino@chromium.org): set up wsiContext
im.Init(im.userData, &wsiContext);
// TODO(kainino@chromium.org): set up FBO
im.Init(im.userData, nullptr);
}
SwapChain::~SwapChain() {
// TODO(kainino@chromium.org): clean up FBO
}
TextureBase* SwapChain::GetNextTextureImpl(TextureBuilder* builder) {
const auto& im = GetImplementation();
nxtSwapChainNextTexture next = {};
nxtSwapChainError error = im.GetNextTexture(im.userData, &next);
if (error) {
GetDevice()->HandleError(error);
return nullptr;
}
GLuint nativeTexture = static_cast<GLuint>(reinterpret_cast<uintptr_t>(next.texture));
return new Texture(builder, nativeTexture);
}

View File

@@ -31,9 +31,6 @@ namespace opengl {
protected:
TextureBase* GetNextTextureImpl(TextureBuilder* builder) override;
private:
GLuint nativeTexture = 0;
};
}