mirror of
https://github.com/cocos/cocos4.git
synced 2026-11-21 08:02:39 +08:00
62d8b4daae
The operation of swapping (presenting) buffers is done in gfx::Device::present. To swap multi-systemwindows, multiple gfx swapchains need be created, and relevant gfx backend will iterate each swapchain and present them. Therefore, `swap buffers` operation doesn't need to be in SystemWindow or SystemWindowManager.
```c++
void GLES3Device::present() {
CC_PROFILE(GLES3DevicePresent);
auto *queue = static_cast<GLES3Queue *>(_queue);
_numDrawCalls = queue->_numDrawCalls;
_numInstances = queue->_numInstances;
_numTriangles = queue->_numTriangles;
bool isGFXDeviceNeedsPresent = _xr ? _xr->isGFXDeviceNeedsPresent(_api) : true;
for (auto *swapchain : _swapchains) { // We iterate each swapchain and do the present thing here.
if (isGFXDeviceNeedsPresent) _gpuContext->present(swapchain);
}
if (_xr) _xr->postGFXDevicePresent(_api);
// Clear queue stats
queue->_numDrawCalls = 0;
queue->_numInstances = 0;
queue->_numTriangles = 0;
}
```
Besides, `SDL_GL_SwapWindow` invocation is doing nothing on Windows & Linux platforms, it will generate an SDL an error that `The specified window isn't an OpenGL window` because GL context is not created by SDL_GL_CreateContext. We create contexts in our gfx code.
https://github.com/libsdl-org/SDL/blob/main/src/video/SDL_video.c#L4192
```c++
#define NOT_AN_OPENGL_WINDOW "The specified window isn't an OpenGL window"
int
SDL_GL_SwapWindowWithResult(SDL_Window * window)
{
CHECK_WINDOW_MAGIC(window, -1);
if (!(window->flags & SDL_WINDOW_OPENGL)) {
return SDL_SetError(NOT_AN_OPENGL_WINDOW);
}
if (SDL_GL_GetCurrentWindow() != window) {
return SDL_SetError("The specified window has not been made current");
}
return _this->GL_SwapWindow(_this, window);
}
void
SDL_GL_SwapWindow(SDL_Window * window)
{
SDL_GL_SwapWindowWithResult(window);
}
```
Also, SDL_GL_SwapWindow could not take any effect if running on gfx Vulkan backend.
```c++
void SDLHelper::swapWindow(SDL_Window *window) {
SDL_GL_SwapWindow(window);
}
```
76 lines
2.7 KiB
C++
76 lines
2.7 KiB
C++
/****************************************************************************
|
|
Copyright (c) 2021-2022 Xiamen Yaji Software Co., Ltd.
|
|
|
|
http://www.cocos.com
|
|
|
|
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
of this software and associated engine source code (the "Software"), a limited,
|
|
worldwide, royalty-free, non-assignable, revocable and non-exclusive license
|
|
to use Cocos Creator solely to develop games on your target platforms. You shall
|
|
not use Cocos Creator software for developing other software or tools that's
|
|
used for developing games. You are not granted to publish, distribute,
|
|
sublicense, and/or sell copies of Cocos Creator.
|
|
|
|
The software or tools in this License Agreement are licensed, not sold.
|
|
Xiamen Yaji Software Co., Ltd. reserves all rights not expressly granted to you.
|
|
|
|
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
|
THE SOFTWARE.
|
|
****************************************************************************/
|
|
|
|
#pragma once
|
|
|
|
#include <iostream>
|
|
|
|
#include "platform/interfaces/modules/ISystemWindow.h"
|
|
|
|
struct SDL_Window;
|
|
namespace cc {
|
|
class SDLHelper;
|
|
class CC_DLL SystemWindow : public ISystemWindow {
|
|
friend class SystemWindowManager;
|
|
|
|
public:
|
|
explicit SystemWindow(uint32_t windowId, void* externalHandle);
|
|
~SystemWindow() override;
|
|
|
|
bool createWindow(const char* title,
|
|
int w, int h, int flags) override;
|
|
bool createWindow(const char* title,
|
|
int x, int y, int w,
|
|
int h, int flags) override;
|
|
void closeWindow() override;
|
|
|
|
virtual uint32_t getWindowId() const override { return _windowId; }
|
|
uintptr_t getWindowHandle() const override;
|
|
|
|
uintptr_t getDisplay() const;
|
|
Size getViewSize() const override;
|
|
void setViewSize(uint32_t w, uint32_t h) override {
|
|
_width = w;
|
|
_height = h;
|
|
}
|
|
/*
|
|
@brief enable/disable(lock) the cursor, default is enabled
|
|
*/
|
|
void setCursorEnabled(bool value) override;
|
|
void copyTextToClipboard(const std::string& text) override;
|
|
|
|
private:
|
|
SDL_Window* getSDLWindow() const { return _window; }
|
|
|
|
uint32_t _width{0};
|
|
uint32_t _height{0};
|
|
|
|
uint32_t _windowId{0};
|
|
uintptr_t _windowHandle{0};
|
|
SDL_Window* _window{nullptr};
|
|
};
|
|
|
|
} // namespace cc
|