mirror of
https://github.com/love2d/love.git
synced 2026-08-16 08:11:02 +02:00
Merge remote-tracking branch 'origin/12.0-development' into vulkan
This commit is contained in:
@@ -34,7 +34,7 @@ static Variant::SharedTable *putSourcesAsSharedTable(std::vector<audio::Source *
|
||||
{
|
||||
Variant::SharedTable *table = new Variant::SharedTable();
|
||||
|
||||
for (int i = 0; i < sources.size(); i++)
|
||||
for (int i = 0; i < (int) sources.size(); i++)
|
||||
table->pairs.emplace_back((double) (i + 1), Variant(&Source::type, sources[i]));
|
||||
|
||||
return table;
|
||||
|
||||
@@ -34,19 +34,19 @@ love::Type DataStream::type("DataStream", &Stream::type);
|
||||
|
||||
DataStream::DataStream(Data *data)
|
||||
: data(data)
|
||||
, offset(0)
|
||||
, size(data->getSize())
|
||||
, memory((const uint8 *) data->getData())
|
||||
, writableMemory((uint8 *) data->getData()) // TODO: disallow writing sometimes?
|
||||
, offset(0)
|
||||
, size(data->getSize())
|
||||
{
|
||||
}
|
||||
|
||||
DataStream::DataStream(const DataStream &other)
|
||||
: data(other.data)
|
||||
, offset(0)
|
||||
, size(other.size)
|
||||
, memory(other.memory)
|
||||
, writableMemory(other.writableMemory)
|
||||
, offset(0)
|
||||
, size(other.size)
|
||||
{
|
||||
}
|
||||
|
||||
@@ -79,7 +79,7 @@ int64 DataStream::read(void* data, int64 size)
|
||||
if (size <= 0)
|
||||
return 0;
|
||||
|
||||
if (offset >= getSize())
|
||||
if ((int64) offset >= getSize())
|
||||
return 0;
|
||||
|
||||
int64 readsize = std::min<int64>(size, getSize() - offset);
|
||||
@@ -95,7 +95,7 @@ bool DataStream::write(const void* data, int64 size)
|
||||
if (size <= 0 || writableMemory == nullptr)
|
||||
return false;
|
||||
|
||||
if (offset >= getSize())
|
||||
if ((int64) offset >= getSize())
|
||||
return false;
|
||||
|
||||
int64 writesize = std::min<int64>(size, getSize() - offset);
|
||||
@@ -123,7 +123,7 @@ bool DataStream::seek(int64 pos, SeekOrigin origin)
|
||||
else if (origin == SEEKORIGIN_END)
|
||||
pos += size;
|
||||
|
||||
if (pos < 0 || pos > size)
|
||||
if (pos < 0 || pos > (int64) size)
|
||||
return false;
|
||||
|
||||
offset = pos;
|
||||
|
||||
@@ -124,7 +124,6 @@ void Text::addTextData(const TextData &t)
|
||||
|
||||
size_t voffset = vertOffset;
|
||||
|
||||
// Must be before the early exit below.
|
||||
if (!t.appendVertices)
|
||||
{
|
||||
voffset = 0;
|
||||
@@ -133,8 +132,8 @@ void Text::addTextData(const TextData &t)
|
||||
textData.clear();
|
||||
}
|
||||
|
||||
if (t.useMatrix)
|
||||
t.matrix.transformXY(&vertices[0], &vertices[0], (int) vertices.size());
|
||||
if (t.useMatrix && !vertices.empty())
|
||||
t.matrix.transformXY(vertices.data(), vertices.data(), (int) vertices.size());
|
||||
|
||||
uploadVertices(vertices, voffset);
|
||||
|
||||
|
||||
@@ -527,7 +527,7 @@ void Graphics::setActive(bool enable)
|
||||
|
||||
void Graphics::setShaderChanged()
|
||||
{
|
||||
dirtyRenderState |= STATE_SHADER;
|
||||
dirtyRenderState |= STATEBIT_SHADER;
|
||||
++shaderSwitches;
|
||||
}
|
||||
|
||||
|
||||
@@ -1414,12 +1414,17 @@ void Graphics::setStencilMode(StencilAction action, CompareMode compare, int val
|
||||
if (enablestencil != gl.isStateEnabled(OpenGL::ENABLE_STENCIL_TEST))
|
||||
gl.setEnableState(OpenGL::ENABLE_STENCIL_TEST, enablestencil);
|
||||
|
||||
GLenum glaction = GL_REPLACE;
|
||||
GLenum glaction = GL_KEEP;
|
||||
|
||||
switch (action)
|
||||
{
|
||||
case STENCIL_KEEP:
|
||||
glaction = GL_KEEP;
|
||||
break;
|
||||
case STENCIL_ZERO:
|
||||
glaction = GL_ZERO;
|
||||
break;
|
||||
case STENCIL_REPLACE:
|
||||
default:
|
||||
glaction = GL_REPLACE;
|
||||
break;
|
||||
case STENCIL_INCREMENT:
|
||||
@@ -1437,6 +1442,9 @@ void Graphics::setStencilMode(StencilAction action, CompareMode compare, int val
|
||||
case STENCIL_INVERT:
|
||||
glaction = GL_INVERT;
|
||||
break;
|
||||
case STENCIL_MAX_ENUM:
|
||||
glaction = GL_KEEP;
|
||||
break;
|
||||
}
|
||||
|
||||
/**
|
||||
|
||||
@@ -298,20 +298,18 @@ void Texture::createTexture()
|
||||
{
|
||||
if (isCompressed() && (texType == TEXTURE_2D_ARRAY || texType == TEXTURE_VOLUME))
|
||||
{
|
||||
int slicecount = slices.getSliceCount(mip);
|
||||
size_t mipsize = 0;
|
||||
|
||||
if (texType == TEXTURE_2D_ARRAY || texType == TEXTURE_VOLUME)
|
||||
for (int slice = 0; slice < slicecount; slice++)
|
||||
{
|
||||
for (int slice = 0; slice < slices.getSliceCount(mip); slice++)
|
||||
{
|
||||
auto id = slices.get(slice, mip);
|
||||
if (id != nullptr)
|
||||
mipsize += id->getSize();
|
||||
}
|
||||
auto id = slices.get(slice, mip);
|
||||
if (id != nullptr)
|
||||
mipsize += id->getSize();
|
||||
}
|
||||
|
||||
if (mipsize > 0)
|
||||
glCompressedTexImage3D(gltype, mip, fmt.internalformat, w, h, d, 0, mipsize, nullptr);
|
||||
glCompressedTexImage3D(gltype, mip, fmt.internalformat, w, h, slicecount, 0, mipsize, nullptr);
|
||||
}
|
||||
|
||||
for (int slice = 0; slice < slicecount; slice++)
|
||||
|
||||
@@ -25,9 +25,12 @@
|
||||
// SDL
|
||||
#include <SDL_clipboard.h>
|
||||
#include <SDL_cpuinfo.h>
|
||||
#include <SDL_locale.h>
|
||||
#include <SDL_version.h>
|
||||
|
||||
#if SDL_VERSION_ATLEAST(2, 0, 14)
|
||||
#include <SDL_locale.h>
|
||||
#endif
|
||||
|
||||
namespace love
|
||||
{
|
||||
namespace system
|
||||
|
||||
@@ -43,14 +43,14 @@ public:
|
||||
virtual ~System() {}
|
||||
|
||||
// Implements Module.
|
||||
const char *getName() const;
|
||||
const char *getName() const override;
|
||||
|
||||
int getProcessorCount() const;
|
||||
int getProcessorCount() const override;
|
||||
|
||||
void setClipboardText(const std::string &text) const;
|
||||
std::string getClipboardText() const;
|
||||
void setClipboardText(const std::string &text) const override;
|
||||
std::string getClipboardText() const override;
|
||||
|
||||
PowerState getPowerInfo(int &seconds, int &percent) const;
|
||||
PowerState getPowerInfo(int &seconds, int &percent) const override;
|
||||
std::vector<std::string> getPreferredLocales() const override;
|
||||
|
||||
private:
|
||||
|
||||
@@ -28,8 +28,13 @@ namespace window
|
||||
|
||||
static bool highDPIAllowed = false;
|
||||
|
||||
// TODO: find a cleaner way to do this...
|
||||
// The window backend (e.g. love.window.sdl) is expected to implement this.
|
||||
void setHighDPIAllowedImplementation(bool enable);
|
||||
|
||||
void setHighDPIAllowed(bool enable)
|
||||
{
|
||||
setHighDPIAllowedImplementation(enable);
|
||||
highDPIAllowed = enable;
|
||||
}
|
||||
|
||||
|
||||
@@ -45,6 +45,8 @@
|
||||
|
||||
#if defined(LOVE_WINDOWS)
|
||||
#include <windows.h>
|
||||
#include <dwmapi.h>
|
||||
#include <VersionHelpers.h>
|
||||
#elif defined(LOVE_MACOS)
|
||||
#include "common/macos.h"
|
||||
#endif
|
||||
@@ -53,10 +55,27 @@
|
||||
#define APIENTRY
|
||||
#endif
|
||||
|
||||
#ifndef SDL_HINT_WINDOWS_DPI_SCALING
|
||||
#define SDL_HINT_WINDOWS_DPI_SCALING "SDL_WINDOWS_DPI_SCALING"
|
||||
#endif
|
||||
|
||||
namespace love
|
||||
{
|
||||
namespace window
|
||||
{
|
||||
|
||||
// See src/modules/window/Window.cpp.
|
||||
void setHighDPIAllowedImplementation(bool enable)
|
||||
{
|
||||
#if defined(LOVE_WINDOWS)
|
||||
// Windows uses a different API than SDL_WINDOW_ALLOW_HIGHDPI.
|
||||
// This must be set before the video subsystem is initialized.
|
||||
SDL_SetHint(SDL_HINT_WINDOWS_DPI_SCALING, enable ? "1" : "0");
|
||||
#else
|
||||
LOVE_UNUSED(enable);
|
||||
#endif
|
||||
}
|
||||
|
||||
namespace sdl
|
||||
{
|
||||
|
||||
@@ -72,12 +91,6 @@ Window::Window()
|
||||
, hasSDL203orEarlier(false)
|
||||
, contextAttribs()
|
||||
{
|
||||
// Windows uses a different API than SDL_WINDOW_ALLOW_HIGHDPI.
|
||||
#if defined(LOVE_WINDOWS) && defined(SDL_HINT_WINDOWS_DPI_SCALING)
|
||||
// This must be set before the video subsystem is initialized.
|
||||
SDL_SetHint(SDL_HINT_WINDOWS_DPI_SCALING, isHighDPIAllowed() ? "1" : "0");
|
||||
#endif
|
||||
|
||||
if (SDL_InitSubSystem(SDL_INIT_VIDEO) < 0)
|
||||
throw love::Exception("Could not initialize SDL video subsystem (%s)", SDL_GetError());
|
||||
|
||||
@@ -1183,7 +1196,59 @@ bool Window::isMinimized() const
|
||||
void Window::swapBuffers()
|
||||
{
|
||||
if (glcontext)
|
||||
{
|
||||
#ifdef LOVE_WINDOWS
|
||||
bool useDwmFlush = false;
|
||||
int swapInterval = getVSync();
|
||||
|
||||
// https://github.com/love2d/love/issues/1628
|
||||
// VSync can interact badly with Windows desktop composition (DWM) in windowed mode. DwmFlush can be used instead
|
||||
// of vsync, but it's much less flexible so we're very conservative here with where it's used:
|
||||
// - It won't work with exclusive or desktop fullscreen.
|
||||
// - DWM refreshes don't always match the refresh rate of the monitor the window is in (or the requested swap
|
||||
// interval), so we only use it when they do match.
|
||||
// - The user may force GL vsync, and DwmFlush shouldn't be used together with GL vsync.
|
||||
if (!settings.fullscreen && swapInterval == 1)
|
||||
{
|
||||
// Desktop composition is always enabled in Windows 8+. But DwmIsCompositionEnabled won't always return true...
|
||||
// (see DwmIsCompositionEnabled docs).
|
||||
BOOL compositionEnabled = IsWindows8OrGreater();
|
||||
if (compositionEnabled || (SUCCEEDED(DwmIsCompositionEnabled(&compositionEnabled)) && compositionEnabled))
|
||||
{
|
||||
DWM_TIMING_INFO info = {};
|
||||
info.cbSize = sizeof(DWM_TIMING_INFO);
|
||||
double dwmRefreshRate = 0;
|
||||
if (SUCCEEDED(DwmGetCompositionTimingInfo(nullptr, &info)))
|
||||
dwmRefreshRate = (double)info.rateRefresh.uiNumerator / (double)info.rateRefresh.uiDenominator;
|
||||
|
||||
SDL_DisplayMode dmode = {};
|
||||
int displayindex = SDL_GetWindowDisplayIndex(window);
|
||||
|
||||
if (displayindex >= 0)
|
||||
SDL_GetCurrentDisplayMode(displayindex, &dmode);
|
||||
|
||||
if (dmode.refresh_rate > 0 && dwmRefreshRate > 0 && (fabs(dmode.refresh_rate - dwmRefreshRate) < 2))
|
||||
{
|
||||
SDL_GL_SetSwapInterval(0);
|
||||
if (SDL_GL_GetSwapInterval() == 0)
|
||||
useDwmFlush = true;
|
||||
else
|
||||
SDL_GL_SetSwapInterval(swapInterval);
|
||||
}
|
||||
}
|
||||
}
|
||||
#endif
|
||||
|
||||
SDL_GL_SwapWindow(window);
|
||||
|
||||
#ifdef LOVE_WINDOWS
|
||||
if (useDwmFlush)
|
||||
{
|
||||
DwmFlush();
|
||||
SDL_GL_SetSwapInterval(swapInterval);
|
||||
}
|
||||
#endif
|
||||
}
|
||||
}
|
||||
|
||||
bool Window::hasFocus() const
|
||||
|
||||
Reference in New Issue
Block a user