mirror of
https://github.com/encounter/dawn-cmake.git
synced 2025-12-14 15:46:28 +00:00
Remove OpenGLBinding's dependency on glad
This move all the OpenGL-specific code for swapchain handling in a new NativeSwapChainImpl in the OpenGL backend so no code outside of dawn_native needs OpenGL. BUG=dawn:165 Change-Id: I3c0c1055e3215a59fdc8e9550baf30762a7014b5 Reviewed-on: https://dawn-review.googlesource.com/c/dawn/+/8161 Reviewed-by: Kai Ninomiya <kainino@chromium.org> Reviewed-by: Austin Eng <enga@chromium.org> Commit-Queue: Corentin Wallez <cwallez@chromium.org>
This commit is contained in:
committed by
Commit Bot service account
parent
21eba761b5
commit
abdb566c30
87
src/dawn_native/opengl/NativeSwapChainImplGL.cpp
Normal file
87
src/dawn_native/opengl/NativeSwapChainImplGL.cpp
Normal file
@@ -0,0 +1,87 @@
|
||||
// Copyright 2019 The Dawn Authors
|
||||
//
|
||||
// Licensed under the Apache License, Version 2.0 (the "License");
|
||||
// you may not use this file except in compliance with the License.
|
||||
// You may obtain a copy of the License at
|
||||
//
|
||||
// http://www.apache.org/licenses/LICENSE-2.0
|
||||
//
|
||||
// Unless required by applicable law or agreed to in writing, software
|
||||
// distributed under the License is distributed on an "AS IS" BASIS,
|
||||
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
// See the License for the specific language governing permissions and
|
||||
// limitations under the License.
|
||||
|
||||
#include "dawn_native/opengl/NativeSwapChainImplGL.h"
|
||||
|
||||
#include "dawn_native/opengl/DeviceGL.h"
|
||||
|
||||
namespace dawn_native { namespace opengl {
|
||||
|
||||
NativeSwapChainImpl::NativeSwapChainImpl(Device* device,
|
||||
PresentCallback present,
|
||||
void* presentUserdata)
|
||||
: mPresentCallback(present), mPresentUserdata(presentUserdata), mDevice(device) {
|
||||
}
|
||||
|
||||
NativeSwapChainImpl::~NativeSwapChainImpl() {
|
||||
const OpenGLFunctions& gl = mDevice->gl;
|
||||
gl.DeleteTextures(1, &mBackTexture);
|
||||
gl.DeleteFramebuffers(1, &mBackFBO);
|
||||
}
|
||||
|
||||
void NativeSwapChainImpl::Init(DawnWSIContextGL* /*context*/) {
|
||||
const OpenGLFunctions& gl = mDevice->gl;
|
||||
gl.GenTextures(1, &mBackTexture);
|
||||
gl.BindTexture(GL_TEXTURE_2D, mBackTexture);
|
||||
gl.TexImage2D(GL_TEXTURE_2D, 0, GL_RGBA8, 0, 0, 0, GL_RGBA, GL_UNSIGNED_BYTE, nullptr);
|
||||
|
||||
gl.GenFramebuffers(1, &mBackFBO);
|
||||
gl.BindFramebuffer(GL_READ_FRAMEBUFFER, mBackFBO);
|
||||
gl.FramebufferTexture2D(GL_READ_FRAMEBUFFER, GL_COLOR_ATTACHMENT0, GL_TEXTURE_2D,
|
||||
mBackTexture, 0);
|
||||
}
|
||||
|
||||
DawnSwapChainError NativeSwapChainImpl::Configure(DawnTextureFormat format,
|
||||
DawnTextureUsageBit usage,
|
||||
uint32_t width,
|
||||
uint32_t height) {
|
||||
if (format != DAWN_TEXTURE_FORMAT_R8_G8_B8_A8_UNORM) {
|
||||
return "unsupported format";
|
||||
}
|
||||
ASSERT(width > 0);
|
||||
ASSERT(height > 0);
|
||||
mWidth = width;
|
||||
mHeight = height;
|
||||
|
||||
const OpenGLFunctions& gl = mDevice->gl;
|
||||
gl.BindTexture(GL_TEXTURE_2D, mBackTexture);
|
||||
// Reallocate the texture
|
||||
gl.TexImage2D(GL_TEXTURE_2D, 0, GL_RGBA8, width, height, 0, GL_RGBA, GL_UNSIGNED_BYTE,
|
||||
nullptr);
|
||||
|
||||
return DAWN_SWAP_CHAIN_NO_ERROR;
|
||||
}
|
||||
|
||||
DawnSwapChainError NativeSwapChainImpl::GetNextTexture(DawnSwapChainNextTexture* nextTexture) {
|
||||
nextTexture->texture.u32 = mBackTexture;
|
||||
return DAWN_SWAP_CHAIN_NO_ERROR;
|
||||
}
|
||||
|
||||
DawnSwapChainError NativeSwapChainImpl::Present() {
|
||||
const OpenGLFunctions& gl = mDevice->gl;
|
||||
gl.BindFramebuffer(GL_READ_FRAMEBUFFER, mBackFBO);
|
||||
gl.BindFramebuffer(GL_DRAW_FRAMEBUFFER, 0);
|
||||
gl.BlitFramebuffer(0, 0, mWidth, mHeight, 0, mHeight, mWidth, 0, GL_COLOR_BUFFER_BIT,
|
||||
GL_NEAREST);
|
||||
|
||||
mPresentCallback(mPresentUserdata);
|
||||
|
||||
return DAWN_SWAP_CHAIN_NO_ERROR;
|
||||
}
|
||||
|
||||
dawn::TextureFormat NativeSwapChainImpl::GetPreferredFormat() const {
|
||||
return dawn::TextureFormat::R8G8B8A8Unorm;
|
||||
}
|
||||
|
||||
}} // namespace dawn_native::opengl
|
||||
58
src/dawn_native/opengl/NativeSwapChainImplGL.h
Normal file
58
src/dawn_native/opengl/NativeSwapChainImplGL.h
Normal file
@@ -0,0 +1,58 @@
|
||||
// Copyright 2017 The Dawn Authors
|
||||
//
|
||||
// Licensed under the Apache License, Version 2.0 (the "License");
|
||||
// you may not use this file except in compliance with the License.
|
||||
// You may obtain a copy of the License at
|
||||
//
|
||||
// http://www.apache.org/licenses/LICENSE-2.0
|
||||
//
|
||||
// Unless required by applicable law or agreed to in writing, software
|
||||
// distributed under the License is distributed on an "AS IS" BASIS,
|
||||
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
// See the License for the specific language governing permissions and
|
||||
// limitations under the License.
|
||||
|
||||
#ifndef DAWNNATIVE_OPENGL_NATIVESWAPCHAINIMPLGL_H_
|
||||
#define DAWNNATIVE_OPENGL_NATIVESWAPCHAINIMPLGL_H_
|
||||
|
||||
#include "dawn_native/OpenGLBackend.h"
|
||||
|
||||
#include "dawn_native/dawn_platform.h"
|
||||
#include "glad/glad.h"
|
||||
|
||||
namespace dawn_native { namespace opengl {
|
||||
|
||||
class Device;
|
||||
|
||||
class NativeSwapChainImpl {
|
||||
public:
|
||||
using WSIContext = DawnWSIContextGL;
|
||||
|
||||
NativeSwapChainImpl(Device* device, PresentCallback present, void* presentUserdata);
|
||||
~NativeSwapChainImpl();
|
||||
|
||||
void Init(DawnWSIContextGL* context);
|
||||
DawnSwapChainError Configure(DawnTextureFormat format,
|
||||
DawnTextureUsageBit,
|
||||
uint32_t width,
|
||||
uint32_t height);
|
||||
DawnSwapChainError GetNextTexture(DawnSwapChainNextTexture* nextTexture);
|
||||
DawnSwapChainError Present();
|
||||
|
||||
dawn::TextureFormat GetPreferredFormat() const;
|
||||
|
||||
private:
|
||||
PresentCallback mPresentCallback;
|
||||
void* mPresentUserdata;
|
||||
|
||||
uint32_t mWidth = 0;
|
||||
uint32_t mHeight = 0;
|
||||
GLuint mBackFBO = 0;
|
||||
GLuint mBackTexture = 0;
|
||||
|
||||
Device* mDevice = nullptr;
|
||||
};
|
||||
|
||||
}} // namespace dawn_native::opengl
|
||||
|
||||
#endif // DAWNNATIVE_OPENGL_NATIVESWAPCHAINIMPLGL_H_
|
||||
@@ -17,7 +17,9 @@
|
||||
|
||||
#include "dawn_native/OpenGLBackend.h"
|
||||
|
||||
#include "common/SwapChainUtils.h"
|
||||
#include "dawn_native/opengl/DeviceGL.h"
|
||||
#include "dawn_native/opengl/NativeSwapChainImplGL.h"
|
||||
|
||||
namespace dawn_native { namespace opengl {
|
||||
|
||||
@@ -25,4 +27,23 @@ namespace dawn_native { namespace opengl {
|
||||
: AdapterDiscoveryOptionsBase(BackendType::OpenGL) {
|
||||
}
|
||||
|
||||
DawnSwapChainImplementation CreateNativeSwapChainImpl(DawnDevice device,
|
||||
PresentCallback present,
|
||||
void* presentUserdata) {
|
||||
Device* backendDevice = reinterpret_cast<Device*>(device);
|
||||
|
||||
DawnSwapChainImplementation impl;
|
||||
impl = CreateSwapChainImplementation(
|
||||
new NativeSwapChainImpl(backendDevice, present, presentUserdata));
|
||||
impl.textureUsage = DAWN_TEXTURE_USAGE_BIT_PRESENT;
|
||||
|
||||
return impl;
|
||||
}
|
||||
|
||||
DawnTextureFormat GetNativeSwapChainPreferredFormat(
|
||||
const DawnSwapChainImplementation* swapChain) {
|
||||
NativeSwapChainImpl* impl = reinterpret_cast<NativeSwapChainImpl*>(swapChain->userData);
|
||||
return static_cast<DawnTextureFormat>(impl->GetPreferredFormat());
|
||||
}
|
||||
|
||||
}} // namespace dawn_native::opengl
|
||||
|
||||
Reference in New Issue
Block a user