Skip to content

Commit

Permalink
Minimum required opengl version is now OpenGL 3.3 / OpenGL ES 3.0.
Browse files Browse the repository at this point in the history
  • Loading branch information
slime73 committed Jun 19, 2024
1 parent 5112345 commit 54a31ec
Show file tree
Hide file tree
Showing 17 changed files with 119 additions and 621 deletions.
3 changes: 0 additions & 3 deletions src/modules/graphics/Buffer.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -86,9 +86,6 @@ Buffer::Buffer(Graphics *gfx, const Settings &settings, const std::vector<DataDe

if (indexbuffer)
{
if (!caps.features[Graphics::FEATURE_INDEX_BUFFER_32BIT] && format == DATAFORMAT_UINT32)
throw love::Exception("32 bit index buffer formats are not supported on this system.");

if (format != DATAFORMAT_UINT16 && format != DATAFORMAT_UINT32)
throw love::Exception("Index buffers only support uint16 and uint32 data types.");

Expand Down
15 changes: 0 additions & 15 deletions src/modules/graphics/Graphics.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1604,9 +1604,6 @@ void Graphics::captureScreenshot(const ScreenshotInfo &info)

void Graphics::copyBuffer(Buffer *source, Buffer *dest, size_t sourceoffset, size_t destoffset, size_t size)
{
if (!capabilities.features[FEATURE_COPY_BUFFER])
throw love::Exception("Buffer copying is not supported on this system.");

Range sourcerange(sourceoffset, size);
Range destrange(destoffset, size);

Expand Down Expand Up @@ -1640,9 +1637,6 @@ void Graphics::copyTextureToBuffer(Texture *source, Buffer *dest, int slice, int
{
if (!source->isRenderTarget())
throw love::Exception("Copying a non-render target Texture to a Buffer is not supported on this system.");

if (!capabilities.features[FEATURE_COPY_RENDER_TARGET_TO_BUFFER])
throw love::Exception("Copying a render target Texture to a Buffer is not supported on this system.");
}

PixelFormat format = source->getPixelFormat();
Expand Down Expand Up @@ -1728,9 +1722,6 @@ void Graphics::copyTextureToBuffer(Texture *source, Buffer *dest, int slice, int

void Graphics::copyBufferToTexture(Buffer *source, Texture *dest, size_t sourceoffset, int sourcewidth, int slice, int mipmap, const Rect &rect)
{
if (!capabilities.features[FEATURE_COPY_BUFFER_TO_TEXTURE])
throw love::Exception("Copying a Buffer to a Texture is not supported on this system.");

if (source->getDataUsage() == BUFFERDATAUSAGE_READBACK)
throw love::Exception("Buffers created with 'readback' data usage cannot be used as a copy source.");

Expand Down Expand Up @@ -2914,7 +2905,6 @@ STRINGMAP_CLASS_BEGIN(Graphics, Graphics::Feature, Graphics::FEATURE_MAX_ENUM, f
{ "multirendertargetformats", Graphics::FEATURE_MULTI_RENDER_TARGET_FORMATS },
{ "clampzero", Graphics::FEATURE_CLAMP_ZERO },
{ "clampone", Graphics::FEATURE_CLAMP_ONE },
{ "blendminmax", Graphics::FEATURE_BLEND_MINMAX },
{ "lighten", Graphics::FEATURE_LIGHTEN },
{ "fullnpot", Graphics::FEATURE_FULL_NPOT },
{ "pixelshaderhighp", Graphics::FEATURE_PIXEL_SHADER_HIGHP },
Expand All @@ -2923,12 +2913,7 @@ STRINGMAP_CLASS_BEGIN(Graphics, Graphics::Feature, Graphics::FEATURE_MAX_ENUM, f
{ "glsl4", Graphics::FEATURE_GLSL4 },
{ "instancing", Graphics::FEATURE_INSTANCING },
{ "texelbuffer", Graphics::FEATURE_TEXEL_BUFFER },
{ "indexbuffer32bit", Graphics::FEATURE_INDEX_BUFFER_32BIT },
{ "copybuffer", Graphics::FEATURE_COPY_BUFFER },
{ "copybuffertotexture", Graphics::FEATURE_COPY_BUFFER_TO_TEXTURE },
{ "copytexturetobuffer", Graphics::FEATURE_COPY_TEXTURE_TO_BUFFER },
{ "copyrendertargettobuffer", Graphics::FEATURE_COPY_RENDER_TARGET_TO_BUFFER },
{ "mipmaprange", Graphics::FEATURE_MIPMAP_RANGE },
{ "indirectdraw", Graphics::FEATURE_INDIRECT_DRAW },
}
STRINGMAP_CLASS_END(Graphics, Graphics::Feature, Graphics::FEATURE_MAX_ENUM, feature)
Expand Down
18 changes: 6 additions & 12 deletions src/modules/graphics/Graphics.h
Original file line number Diff line number Diff line change
Expand Up @@ -147,24 +147,18 @@ class Graphics : public Module

enum Feature
{
FEATURE_MULTI_RENDER_TARGET_FORMATS,
FEATURE_MULTI_RENDER_TARGET_FORMATS, // Deprecated
FEATURE_CLAMP_ZERO,
FEATURE_CLAMP_ONE,
FEATURE_BLEND_MINMAX,
FEATURE_LIGHTEN, // Deprecated
FEATURE_FULL_NPOT,
FEATURE_PIXEL_SHADER_HIGHP,
FEATURE_SHADER_DERIVATIVES,
FEATURE_GLSL3,
FEATURE_FULL_NPOT, // Deprecated
FEATURE_PIXEL_SHADER_HIGHP, // Deprecated
FEATURE_SHADER_DERIVATIVES, // Deprecated
FEATURE_GLSL3, // Deprecated
FEATURE_GLSL4,
FEATURE_INSTANCING,
FEATURE_INSTANCING, // Deprecated
FEATURE_TEXEL_BUFFER,
FEATURE_INDEX_BUFFER_32BIT,
FEATURE_COPY_BUFFER,
FEATURE_COPY_BUFFER_TO_TEXTURE,
FEATURE_COPY_TEXTURE_TO_BUFFER,
FEATURE_COPY_RENDER_TARGET_TO_BUFFER,
FEATURE_MIPMAP_RANGE,
FEATURE_INDIRECT_DRAW,
FEATURE_MAX_ENUM
};
Expand Down
7 changes: 1 addition & 6 deletions src/modules/graphics/GraphicsReadback.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -40,9 +40,6 @@ GraphicsReadback::GraphicsReadback(Graphics *gfx, ReadbackMethod method, Buffer
{
const auto &caps = gfx->getCapabilities();

if (!caps.features[Graphics::FEATURE_COPY_BUFFER])
throw love::Exception("readbackBuffer is not supported on this system (buffer copy support is required).");

if (offset + size > buffer->getSize())
throw love::Exception("Invalid offset or size for the given Buffer.");

Expand Down Expand Up @@ -94,9 +91,7 @@ GraphicsReadback::GraphicsReadback(Graphics *gfx, ReadbackMethod method, Texture

if (method == READBACK_ASYNC)
{
if (isRT && !caps.features[Graphics::FEATURE_COPY_RENDER_TARGET_TO_BUFFER])
throw love::Exception("readbackTextureAsync is not supported on this system.");
else if (!isRT && !caps.features[Graphics::FEATURE_COPY_TEXTURE_TO_BUFFER])
if (!isRT && !caps.features[Graphics::FEATURE_COPY_TEXTURE_TO_BUFFER])
throw love::Exception("readbackTextureAsync with a non-render-target texture is not supported on this system.");
}
else
Expand Down
28 changes: 2 additions & 26 deletions src/modules/graphics/Shader.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -51,11 +51,7 @@ static const char global_syntax[] = R"(
#define mediump
#define highp
#endif
#if defined(VERTEX) || __VERSION__ > 100 || defined(GL_FRAGMENT_PRECISION_HIGH)
#define LOVE_HIGHP_OR_MEDIUMP highp
#else
#define LOVE_HIGHP_OR_MEDIUMP mediump
#endif
#define LOVE_HIGHP_OR_MEDIUMP highp
#if __VERSION__ >= 300
#define LOVE_IO_LOCATION(x) layout (location = x)
#else
Expand Down Expand Up @@ -88,15 +84,7 @@ static const char global_syntax[] = R"(
)";

static const char render_uniforms[] = R"(
// According to the GLSL ES 1.0 spec, uniform precision must match between stages,
// but we can't guarantee that highp is always supported in fragment shaders...
// We *really* don't want to use mediump for these in vertex shaders though.
#ifdef LOVE_SPLIT_UNIFORMS_PER_DRAW
uniform LOVE_HIGHP_OR_MEDIUMP vec4 love_UniformsPerDraw[11];
uniform LOVE_HIGHP_OR_MEDIUMP vec4 love_UniformsPerDraw2[1];
#else
uniform LOVE_HIGHP_OR_MEDIUMP vec4 love_UniformsPerDraw[12];
#endif
uniform highp vec4 love_UniformsPerDraw[12];
// Older GLSL doesn't support preprocessor line continuations...
#define TransformMatrix mat4(love_UniformsPerDraw[0], love_UniformsPerDraw[1], love_UniformsPerDraw[2], love_UniformsPerDraw[3])
Expand All @@ -105,16 +93,9 @@ uniform LOVE_HIGHP_OR_MEDIUMP vec4 love_UniformsPerDraw[12];
#define CurrentDPIScale (love_UniformsPerDraw[8].x)
#define ConstantPointSize (love_UniformsPerDraw[8].y)
#define love_ClipSpaceParams (love_UniformsPerDraw[9])
#define ConstantColor (love_UniformsPerDraw[10])
#ifdef LOVE_SPLIT_UNIFORMS_PER_DRAW
#define love_ScreenSize (love_UniformsPerDraw2[0])
#else
#define love_ScreenSize (love_UniformsPerDraw[11])
#endif
// Alternate names
#define ViewSpaceFromLocal TransformMatrix
Expand Down Expand Up @@ -667,11 +648,6 @@ std::string Shader::createShaderStageCode(Graphics *gfx, ShaderStageType stage,
if (info.usesMRT)
ss << "#define LOVE_MULTI_RENDER_TARGETS 1\n";

// Note: backends are expected to handle this situation if highp is ever
// conditional in that backend.
if (!gfx->getCapabilities().features[Graphics::FEATURE_PIXEL_SHADER_HIGHP])
ss << "#define LOVE_SPLIT_UNIFORMS_PER_DRAW 1\n";

for (const auto &def : options.defines)
ss << "#define " + def.first + " " + def.second + "\n";

Expand Down
3 changes: 0 additions & 3 deletions src/modules/graphics/Texture.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -253,9 +253,6 @@ Texture::Texture(Graphics *gfx, const Settings &settings, const Slices *slices)
mipmapCount = std::min(totalMipmapCount, requestedMipmapCount);
else
mipmapCount = totalMipmapCount;

if (mipmapCount != totalMipmapCount && !caps.features[Graphics::FEATURE_MIPMAP_RANGE])
throw love::Exception("Custom mipmap ranges for a texture are not supported on this system (%d mipmap levels are required but only %d levels were provided.)", totalMipmapCount, mipmapCount);
}

const char *miperr = nullptr;
Expand Down
8 changes: 1 addition & 7 deletions src/modules/graphics/metal/Graphics.mm
Original file line number Diff line number Diff line change
Expand Up @@ -2227,7 +2227,6 @@ static inline void advanceVertexOffsets(const VertexAttributes &attributes, Buff
if (families.mac[1] || families.macCatalyst[1] || families.apple[7])
capabilities.features[FEATURE_CLAMP_ONE] = true;
}
capabilities.features[FEATURE_BLEND_MINMAX] = true;
capabilities.features[FEATURE_LIGHTEN] = true;
capabilities.features[FEATURE_FULL_NPOT] = true;
capabilities.features[FEATURE_PIXEL_SHADER_HIGHP] = true;
Expand All @@ -2236,19 +2235,14 @@ static inline void advanceVertexOffsets(const VertexAttributes &attributes, Buff
capabilities.features[FEATURE_GLSL4] = true;
capabilities.features[FEATURE_INSTANCING] = true;
capabilities.features[FEATURE_TEXEL_BUFFER] = true;
capabilities.features[FEATURE_INDEX_BUFFER_32BIT] = true;
capabilities.features[FEATURE_COPY_BUFFER] = true;
capabilities.features[FEATURE_COPY_BUFFER_TO_TEXTURE] = true;
capabilities.features[FEATURE_COPY_TEXTURE_TO_BUFFER] = true;
capabilities.features[FEATURE_COPY_RENDER_TARGET_TO_BUFFER] = true;
capabilities.features[FEATURE_MIPMAP_RANGE] = true;

if (families.mac[1] || families.macCatalyst[1] || families.apple[3])
capabilities.features[FEATURE_INDIRECT_DRAW] = true;
else
capabilities.features[FEATURE_INDIRECT_DRAW] = false;

static_assert(FEATURE_MAX_ENUM == 19, "Graphics::initCapabilities must be updated when adding a new graphics feature!");
static_assert(FEATURE_MAX_ENUM == 13, "Graphics::initCapabilities must be updated when adding a new graphics feature!");

// https://developer.apple.com/metal/Metal-Feature-Set-Tables.pdf
capabilities.limits[LIMIT_POINT_SIZE] = 511;
Expand Down
6 changes: 1 addition & 5 deletions src/modules/graphics/opengl/Buffer.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -196,11 +196,7 @@ void *Buffer::map(MapType map, size_t offset, size_t size)
if (map == MAP_READ_ONLY)
{
gl.bindBuffer(mapUsage, buffer);

if (GLAD_VERSION_3_0 || GLAD_ES_VERSION_3_0)
data = (char *) glMapBufferRange(target, offset, size, GL_MAP_READ_BIT);
else if (GLAD_VERSION_1_1)
data = (char *) glMapBuffer(target, GL_READ_ONLY) + offset;
data = (char *) glMapBufferRange(target, offset, size, GL_MAP_READ_BIT);
}
else if (ownsMemoryMap)
{
Expand Down
Loading

0 comments on commit 54a31ec

Please sign in to comment.