mirror of
https://github.com/encounter/dawn-cmake.git
synced 2025-12-14 07:36:15 +00:00
Swap chains, part 1 (#87)
Adds the swap chain interfaces to the API without changing the behavior of anything else. This includes the C APIs for applications to provide swap chain implementations. Also adds stub implementations on every backend.
This commit is contained in:
@@ -22,4 +22,5 @@
|
||||
#include "backend/opengl/RenderPipelineGL.h"
|
||||
#include "backend/opengl/SamplerGL.h"
|
||||
#include "backend/opengl/ShaderModuleGL.h"
|
||||
#include "backend/opengl/SwapChainGL.h"
|
||||
#include "backend/opengl/TextureGL.h"
|
||||
|
||||
@@ -21,6 +21,7 @@
|
||||
#include "backend/opengl/PipelineLayoutGL.h"
|
||||
#include "backend/opengl/RenderPipelineGL.h"
|
||||
#include "backend/opengl/ShaderModuleGL.h"
|
||||
#include "backend/opengl/SwapChainGL.h"
|
||||
#include "backend/opengl/SamplerGL.h"
|
||||
#include "backend/opengl/TextureGL.h"
|
||||
|
||||
@@ -103,6 +104,9 @@ namespace opengl {
|
||||
ShaderModuleBase* Device::CreateShaderModule(ShaderModuleBuilder* builder) {
|
||||
return new ShaderModule(builder);
|
||||
}
|
||||
SwapChainBase* Device::CreateSwapChain(SwapChainBuilder* builder) {
|
||||
return new SwapChain(builder);
|
||||
}
|
||||
TextureBase* Device::CreateTexture(TextureBuilder* builder) {
|
||||
return new Texture(builder);
|
||||
}
|
||||
|
||||
@@ -50,6 +50,7 @@ namespace opengl {
|
||||
class RenderPipeline;
|
||||
class Sampler;
|
||||
class ShaderModule;
|
||||
class SwapChain;
|
||||
class Texture;
|
||||
class TextureView;
|
||||
|
||||
@@ -70,6 +71,7 @@ namespace opengl {
|
||||
using RenderPipelineType = RenderPipeline;
|
||||
using SamplerType = Sampler;
|
||||
using ShaderModuleType = ShaderModule;
|
||||
using SwapChainType = SwapChain;
|
||||
using TextureType = Texture;
|
||||
using TextureViewType = TextureView;
|
||||
};
|
||||
@@ -97,6 +99,7 @@ namespace opengl {
|
||||
RenderPipelineBase* CreateRenderPipeline(RenderPipelineBuilder* builder) override;
|
||||
SamplerBase* CreateSampler(SamplerBuilder* builder) override;
|
||||
ShaderModuleBase* CreateShaderModule(ShaderModuleBuilder* builder) override;
|
||||
SwapChainBase* CreateSwapChain(SwapChainBuilder* builder) override;
|
||||
TextureBase* CreateTexture(TextureBuilder* builder) override;
|
||||
TextureViewBase* CreateTextureView(TextureViewBuilder* builder) override;
|
||||
|
||||
|
||||
43
src/backend/opengl/SwapChainGL.cpp
Normal file
43
src/backend/opengl/SwapChainGL.cpp
Normal file
@@ -0,0 +1,43 @@
|
||||
// Copyright 2017 The NXT 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 "backend/opengl/SwapChainGL.h"
|
||||
|
||||
#include "backend/opengl/TextureGL.h"
|
||||
|
||||
#include <nxt/nxt_wsi.h>
|
||||
|
||||
namespace backend {
|
||||
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
|
||||
}
|
||||
|
||||
SwapChain::~SwapChain() {
|
||||
// TODO(kainino@chromium.org): clean up FBO
|
||||
}
|
||||
|
||||
TextureBase* SwapChain::GetNextTextureImpl(TextureBuilder* builder) {
|
||||
return new Texture(builder, nativeTexture);
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
42
src/backend/opengl/SwapChainGL.h
Normal file
42
src/backend/opengl/SwapChainGL.h
Normal file
@@ -0,0 +1,42 @@
|
||||
// Copyright 2017 The NXT 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 BACKEND_OPENGL_SWAPCHAINGL_H_
|
||||
#define BACKEND_OPENGL_SWAPCHAINGL_H_
|
||||
|
||||
#include "backend/SwapChain.h"
|
||||
|
||||
#include "glad/glad.h"
|
||||
|
||||
namespace backend {
|
||||
namespace opengl {
|
||||
|
||||
class Device;
|
||||
|
||||
class SwapChain : public SwapChainBase {
|
||||
public:
|
||||
SwapChain(SwapChainBuilder* builder);
|
||||
~SwapChain();
|
||||
|
||||
protected:
|
||||
TextureBase* GetNextTextureImpl(TextureBuilder* builder) override;
|
||||
|
||||
private:
|
||||
GLuint nativeTexture = 0;
|
||||
};
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
#endif // BACKEND_OPENGL_SWAPCHAINGL_H_
|
||||
@@ -44,12 +44,22 @@ namespace opengl {
|
||||
}
|
||||
}
|
||||
|
||||
GLuint GenTexture() {
|
||||
GLuint handle = 0;
|
||||
glGenTextures(1, &handle);
|
||||
return handle;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
// Texture
|
||||
|
||||
Texture::Texture(TextureBuilder* builder)
|
||||
: TextureBase(builder) {
|
||||
: Texture(builder, GenTexture()) {
|
||||
}
|
||||
|
||||
Texture::Texture(TextureBuilder* builder, GLuint handle)
|
||||
: TextureBase(builder), handle(handle) {
|
||||
target = TargetForDimension(GetDimension());
|
||||
|
||||
uint32_t width = GetWidth();
|
||||
@@ -58,7 +68,6 @@ namespace opengl {
|
||||
|
||||
auto formatInfo = GetGLFormatInfo(GetFormat());
|
||||
|
||||
glGenTextures(1, &handle);
|
||||
glBindTexture(target, handle);
|
||||
|
||||
for (uint32_t i = 0; i < levels; ++i) {
|
||||
@@ -72,6 +81,10 @@ namespace opengl {
|
||||
glTexParameteri(target, GL_TEXTURE_MAX_LEVEL, levels - 1);
|
||||
}
|
||||
|
||||
Texture::~Texture() {
|
||||
// TODO(kainino@chromium.org): delete texture (but only when not using the native texture constructor?)
|
||||
}
|
||||
|
||||
GLuint Texture::GetHandle() const {
|
||||
return handle;
|
||||
}
|
||||
|
||||
@@ -33,6 +33,8 @@ namespace opengl {
|
||||
class Texture : public TextureBase {
|
||||
public:
|
||||
Texture(TextureBuilder* builder);
|
||||
Texture(TextureBuilder* builder, GLuint handle);
|
||||
~Texture();
|
||||
|
||||
GLuint GetHandle() const;
|
||||
GLenum GetGLTarget() const;
|
||||
|
||||
Reference in New Issue
Block a user