Corentin Wallez | 4a9ef4e | 2018-07-18 11:40:26 +0200 | [diff] [blame] | 1 | // Copyright 2017 The Dawn Authors |
Corentin Wallez | 1bd219d | 2017-06-19 12:53:38 -0400 | [diff] [blame] | 2 | // |
| 3 | // Licensed under the Apache License, Version 2.0 (the "License"); |
| 4 | // you may not use this file except in compliance with the License. |
| 5 | // You may obtain a copy of the License at |
| 6 | // |
| 7 | // http://www.apache.org/licenses/LICENSE-2.0 |
| 8 | // |
| 9 | // Unless required by applicable law or agreed to in writing, software |
| 10 | // distributed under the License is distributed on an "AS IS" BASIS, |
| 11 | // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
| 12 | // See the License for the specific language governing permissions and |
| 13 | // limitations under the License. |
| 14 | |
Corentin Wallez | fffe6df | 2017-07-06 14:41:13 -0400 | [diff] [blame] | 15 | #include "utils/BackendBinding.h" |
Corentin Wallez | 1bd219d | 2017-06-19 12:53:38 -0400 | [diff] [blame] | 16 | |
Kai Ninomiya | c16a67a | 2017-07-27 18:30:57 -0700 | [diff] [blame] | 17 | #include "common/Assert.h" |
Corentin Wallez | dab0638 | 2017-07-14 14:05:14 -0400 | [diff] [blame] | 18 | #include "common/Platform.h" |
Corentin Wallez | cc407ae | 2018-01-15 15:44:38 -0500 | [diff] [blame] | 19 | #include "common/SwapChainUtils.h" |
Corentin Wallez | 3e371b1 | 2018-07-18 14:32:45 +0200 | [diff] [blame] | 20 | #include "dawn/dawn_wsi.h" |
Corentin Wallez | 196ade6 | 2018-07-25 13:37:28 +0200 | [diff] [blame] | 21 | #include "dawn_native/OpenGLBackend.h" |
Corentin Wallez | dab0638 | 2017-07-14 14:05:14 -0400 | [diff] [blame] | 22 | |
Corentin Wallez | 9d01c6c | 2017-11-24 11:45:29 -0500 | [diff] [blame] | 23 | #include <cstdio> |
Corentin Wallez | 1bd219d | 2017-06-19 12:53:38 -0400 | [diff] [blame] | 24 | #include "GLFW/glfw3.h" |
| 25 | |
Corentin Wallez | 1bd219d | 2017-06-19 12:53:38 -0400 | [diff] [blame] | 26 | namespace utils { |
Kai Ninomiya | c16a67a | 2017-07-27 18:30:57 -0700 | [diff] [blame] | 27 | |
Corentin Wallez | 1bd219d | 2017-06-19 12:53:38 -0400 | [diff] [blame] | 28 | class OpenGLBinding : public BackendBinding { |
Corentin Wallez | 9d01c6c | 2017-11-24 11:45:29 -0500 | [diff] [blame] | 29 | public: |
Corentin Wallez | 04863c4 | 2019-10-25 11:36:47 +0000 | [diff] [blame] | 30 | OpenGLBinding(GLFWwindow* window, WGPUDevice device) : BackendBinding(window, device) { |
Corentin Wallez | 9d01c6c | 2017-11-24 11:45:29 -0500 | [diff] [blame] | 31 | } |
Kai Ninomiya | c16a67a | 2017-07-27 18:30:57 -0700 | [diff] [blame] | 32 | |
Corentin Wallez | 9d01c6c | 2017-11-24 11:45:29 -0500 | [diff] [blame] | 33 | uint64_t GetSwapChainImplementation() override { |
| 34 | if (mSwapchainImpl.userData == nullptr) { |
Corentin Wallez | ec9cf2a | 2022-01-12 09:17:35 +0000 | [diff] [blame] | 35 | mSwapchainImpl = dawn::native::opengl::CreateNativeSwapChainImpl( |
Corentin Wallez | abdb566 | 2019-06-17 09:01:09 +0000 | [diff] [blame] | 36 | mDevice, |
| 37 | [](void* userdata) { glfwSwapBuffers(static_cast<GLFWwindow*>(userdata)); }, |
| 38 | mWindow); |
Corentin Wallez | 1bd219d | 2017-06-19 12:53:38 -0400 | [diff] [blame] | 39 | } |
Corentin Wallez | 9d01c6c | 2017-11-24 11:45:29 -0500 | [diff] [blame] | 40 | return reinterpret_cast<uint64_t>(&mSwapchainImpl); |
| 41 | } |
Kai Ninomiya | e66fcd8 | 2017-07-11 17:49:20 -0700 | [diff] [blame] | 42 | |
Corentin Wallez | 04863c4 | 2019-10-25 11:36:47 +0000 | [diff] [blame] | 43 | WGPUTextureFormat GetPreferredSwapChainTextureFormat() override { |
Corentin Wallez | ec9cf2a | 2022-01-12 09:17:35 +0000 | [diff] [blame] | 44 | return dawn::native::opengl::GetNativeSwapChainPreferredFormat(&mSwapchainImpl); |
Corentin Wallez | 9d01c6c | 2017-11-24 11:45:29 -0500 | [diff] [blame] | 45 | } |
Corentin Wallez | 2e31e8f | 2017-09-21 12:54:53 -0400 | [diff] [blame] | 46 | |
Corentin Wallez | 9d01c6c | 2017-11-24 11:45:29 -0500 | [diff] [blame] | 47 | private: |
Austin Eng | 45f9730 | 2019-03-11 16:52:42 +0000 | [diff] [blame] | 48 | DawnSwapChainImplementation mSwapchainImpl = {}; |
Corentin Wallez | 1bd219d | 2017-06-19 12:53:38 -0400 | [diff] [blame] | 49 | }; |
| 50 | |
Corentin Wallez | 04863c4 | 2019-10-25 11:36:47 +0000 | [diff] [blame] | 51 | BackendBinding* CreateOpenGLBinding(GLFWwindow* window, WGPUDevice device) { |
Corentin Wallez | bb5696b | 2019-02-12 15:48:15 +0000 | [diff] [blame] | 52 | return new OpenGLBinding(window, device); |
Corentin Wallez | 1bd219d | 2017-06-19 12:53:38 -0400 | [diff] [blame] | 53 | } |
| 54 | |
Corentin Wallez | 9d01c6c | 2017-11-24 11:45:29 -0500 | [diff] [blame] | 55 | } // namespace utils |