mirror of
https://github.com/love2d/love.git
synced 2026-08-19 20:19:42 +02:00
Merge Image and Canvas GL backend classes into new common Texture class.
This commit is contained in:
+2
-4
@@ -580,14 +580,10 @@ set(LOVE_SRC_MODULE_GRAPHICS_ROOT
|
|||||||
set(LOVE_SRC_MODULE_GRAPHICS_OPENGL
|
set(LOVE_SRC_MODULE_GRAPHICS_OPENGL
|
||||||
src/modules/graphics/opengl/Buffer.cpp
|
src/modules/graphics/opengl/Buffer.cpp
|
||||||
src/modules/graphics/opengl/Buffer.h
|
src/modules/graphics/opengl/Buffer.h
|
||||||
src/modules/graphics/opengl/Canvas.cpp
|
|
||||||
src/modules/graphics/opengl/Canvas.h
|
|
||||||
src/modules/graphics/opengl/FenceSync.cpp
|
src/modules/graphics/opengl/FenceSync.cpp
|
||||||
src/modules/graphics/opengl/FenceSync.h
|
src/modules/graphics/opengl/FenceSync.h
|
||||||
src/modules/graphics/opengl/Graphics.cpp
|
src/modules/graphics/opengl/Graphics.cpp
|
||||||
src/modules/graphics/opengl/Graphics.h
|
src/modules/graphics/opengl/Graphics.h
|
||||||
src/modules/graphics/opengl/Image.cpp
|
|
||||||
src/modules/graphics/opengl/Image.h
|
|
||||||
src/modules/graphics/opengl/OpenGL.cpp
|
src/modules/graphics/opengl/OpenGL.cpp
|
||||||
src/modules/graphics/opengl/OpenGL.h
|
src/modules/graphics/opengl/OpenGL.h
|
||||||
src/modules/graphics/opengl/Shader.cpp
|
src/modules/graphics/opengl/Shader.cpp
|
||||||
@@ -596,6 +592,8 @@ set(LOVE_SRC_MODULE_GRAPHICS_OPENGL
|
|||||||
src/modules/graphics/opengl/ShaderStage.h
|
src/modules/graphics/opengl/ShaderStage.h
|
||||||
src/modules/graphics/opengl/StreamBuffer.cpp
|
src/modules/graphics/opengl/StreamBuffer.cpp
|
||||||
src/modules/graphics/opengl/StreamBuffer.h
|
src/modules/graphics/opengl/StreamBuffer.h
|
||||||
|
src/modules/graphics/opengl/Texture.cpp
|
||||||
|
src/modules/graphics/opengl/Texture.h
|
||||||
)
|
)
|
||||||
|
|
||||||
set(LOVE_SRC_MODULE_GRAPHICS
|
set(LOVE_SRC_MODULE_GRAPHICS
|
||||||
|
|||||||
@@ -403,15 +403,12 @@
|
|||||||
FA0B7D301A95902C000E1D17 /* Graphics.cpp in Sources */ = {isa = PBXBuildFile; fileRef = FA0B7B8A1A95902C000E1D17 /* Graphics.cpp */; };
|
FA0B7D301A95902C000E1D17 /* Graphics.cpp in Sources */ = {isa = PBXBuildFile; fileRef = FA0B7B8A1A95902C000E1D17 /* Graphics.cpp */; };
|
||||||
FA0B7D311A95902C000E1D17 /* Graphics.cpp in Sources */ = {isa = PBXBuildFile; fileRef = FA0B7B8A1A95902C000E1D17 /* Graphics.cpp */; };
|
FA0B7D311A95902C000E1D17 /* Graphics.cpp in Sources */ = {isa = PBXBuildFile; fileRef = FA0B7B8A1A95902C000E1D17 /* Graphics.cpp */; };
|
||||||
FA0B7D321A95902C000E1D17 /* Graphics.h in Headers */ = {isa = PBXBuildFile; fileRef = FA0B7B8B1A95902C000E1D17 /* Graphics.h */; };
|
FA0B7D321A95902C000E1D17 /* Graphics.h in Headers */ = {isa = PBXBuildFile; fileRef = FA0B7B8B1A95902C000E1D17 /* Graphics.h */; };
|
||||||
FA0B7D331A95902C000E1D17 /* Canvas.cpp in Sources */ = {isa = PBXBuildFile; fileRef = FA0B7B8D1A95902C000E1D17 /* Canvas.cpp */; };
|
|
||||||
FA0B7D341A95902C000E1D17 /* Canvas.cpp in Sources */ = {isa = PBXBuildFile; fileRef = FA0B7B8D1A95902C000E1D17 /* Canvas.cpp */; };
|
|
||||||
FA0B7D351A95902C000E1D17 /* Canvas.h in Headers */ = {isa = PBXBuildFile; fileRef = FA0B7B8E1A95902C000E1D17 /* Canvas.h */; };
|
|
||||||
FA0B7D391A95902C000E1D17 /* Graphics.cpp in Sources */ = {isa = PBXBuildFile; fileRef = FA0B7B911A95902C000E1D17 /* Graphics.cpp */; };
|
FA0B7D391A95902C000E1D17 /* Graphics.cpp in Sources */ = {isa = PBXBuildFile; fileRef = FA0B7B911A95902C000E1D17 /* Graphics.cpp */; };
|
||||||
FA0B7D3A1A95902C000E1D17 /* Graphics.cpp in Sources */ = {isa = PBXBuildFile; fileRef = FA0B7B911A95902C000E1D17 /* Graphics.cpp */; };
|
FA0B7D3A1A95902C000E1D17 /* Graphics.cpp in Sources */ = {isa = PBXBuildFile; fileRef = FA0B7B911A95902C000E1D17 /* Graphics.cpp */; };
|
||||||
FA0B7D3B1A95902C000E1D17 /* Graphics.h in Headers */ = {isa = PBXBuildFile; fileRef = FA0B7B921A95902C000E1D17 /* Graphics.h */; };
|
FA0B7D3B1A95902C000E1D17 /* Graphics.h in Headers */ = {isa = PBXBuildFile; fileRef = FA0B7B921A95902C000E1D17 /* Graphics.h */; };
|
||||||
FA0B7D3C1A95902C000E1D17 /* Image.cpp in Sources */ = {isa = PBXBuildFile; fileRef = FA0B7B931A95902C000E1D17 /* Image.cpp */; };
|
FA0B7D3C1A95902C000E1D17 /* Texture.cpp in Sources */ = {isa = PBXBuildFile; fileRef = FA0B7B931A95902C000E1D17 /* Texture.cpp */; };
|
||||||
FA0B7D3D1A95902C000E1D17 /* Image.cpp in Sources */ = {isa = PBXBuildFile; fileRef = FA0B7B931A95902C000E1D17 /* Image.cpp */; };
|
FA0B7D3D1A95902C000E1D17 /* Texture.cpp in Sources */ = {isa = PBXBuildFile; fileRef = FA0B7B931A95902C000E1D17 /* Texture.cpp */; };
|
||||||
FA0B7D3E1A95902C000E1D17 /* Image.h in Headers */ = {isa = PBXBuildFile; fileRef = FA0B7B941A95902C000E1D17 /* Image.h */; };
|
FA0B7D3E1A95902C000E1D17 /* Texture.h in Headers */ = {isa = PBXBuildFile; fileRef = FA0B7B941A95902C000E1D17 /* Texture.h */; };
|
||||||
FA0B7D421A95902C000E1D17 /* OpenGL.cpp in Sources */ = {isa = PBXBuildFile; fileRef = FA0B7B971A95902C000E1D17 /* OpenGL.cpp */; };
|
FA0B7D421A95902C000E1D17 /* OpenGL.cpp in Sources */ = {isa = PBXBuildFile; fileRef = FA0B7B971A95902C000E1D17 /* OpenGL.cpp */; };
|
||||||
FA0B7D431A95902C000E1D17 /* OpenGL.cpp in Sources */ = {isa = PBXBuildFile; fileRef = FA0B7B971A95902C000E1D17 /* OpenGL.cpp */; };
|
FA0B7D431A95902C000E1D17 /* OpenGL.cpp in Sources */ = {isa = PBXBuildFile; fileRef = FA0B7B971A95902C000E1D17 /* OpenGL.cpp */; };
|
||||||
FA0B7D441A95902C000E1D17 /* OpenGL.h in Headers */ = {isa = PBXBuildFile; fileRef = FA0B7B981A95902C000E1D17 /* OpenGL.h */; };
|
FA0B7D441A95902C000E1D17 /* OpenGL.h in Headers */ = {isa = PBXBuildFile; fileRef = FA0B7B981A95902C000E1D17 /* OpenGL.h */; };
|
||||||
@@ -1536,12 +1533,10 @@
|
|||||||
FA0B7B891A95902C000E1D17 /* Drawable.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = Drawable.h; sourceTree = "<group>"; };
|
FA0B7B891A95902C000E1D17 /* Drawable.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = Drawable.h; sourceTree = "<group>"; };
|
||||||
FA0B7B8A1A95902C000E1D17 /* Graphics.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; lineEnding = 0; path = Graphics.cpp; sourceTree = "<group>"; xcLanguageSpecificationIdentifier = xcode.lang.cpp; };
|
FA0B7B8A1A95902C000E1D17 /* Graphics.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; lineEnding = 0; path = Graphics.cpp; sourceTree = "<group>"; xcLanguageSpecificationIdentifier = xcode.lang.cpp; };
|
||||||
FA0B7B8B1A95902C000E1D17 /* Graphics.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = Graphics.h; sourceTree = "<group>"; };
|
FA0B7B8B1A95902C000E1D17 /* Graphics.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = Graphics.h; sourceTree = "<group>"; };
|
||||||
FA0B7B8D1A95902C000E1D17 /* Canvas.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; lineEnding = 0; path = Canvas.cpp; sourceTree = "<group>"; xcLanguageSpecificationIdentifier = xcode.lang.cpp; };
|
|
||||||
FA0B7B8E1A95902C000E1D17 /* Canvas.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = Canvas.h; sourceTree = "<group>"; };
|
|
||||||
FA0B7B911A95902C000E1D17 /* Graphics.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; lineEnding = 0; path = Graphics.cpp; sourceTree = "<group>"; xcLanguageSpecificationIdentifier = xcode.lang.cpp; };
|
FA0B7B911A95902C000E1D17 /* Graphics.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; lineEnding = 0; path = Graphics.cpp; sourceTree = "<group>"; xcLanguageSpecificationIdentifier = xcode.lang.cpp; };
|
||||||
FA0B7B921A95902C000E1D17 /* Graphics.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = Graphics.h; sourceTree = "<group>"; };
|
FA0B7B921A95902C000E1D17 /* Graphics.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = Graphics.h; sourceTree = "<group>"; };
|
||||||
FA0B7B931A95902C000E1D17 /* Image.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = Image.cpp; sourceTree = "<group>"; };
|
FA0B7B931A95902C000E1D17 /* Texture.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = Texture.cpp; sourceTree = "<group>"; };
|
||||||
FA0B7B941A95902C000E1D17 /* Image.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = Image.h; sourceTree = "<group>"; };
|
FA0B7B941A95902C000E1D17 /* Texture.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = Texture.h; sourceTree = "<group>"; };
|
||||||
FA0B7B971A95902C000E1D17 /* OpenGL.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = OpenGL.cpp; sourceTree = "<group>"; };
|
FA0B7B971A95902C000E1D17 /* OpenGL.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = OpenGL.cpp; sourceTree = "<group>"; };
|
||||||
FA0B7B981A95902C000E1D17 /* OpenGL.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = OpenGL.h; sourceTree = "<group>"; };
|
FA0B7B981A95902C000E1D17 /* OpenGL.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = OpenGL.h; sourceTree = "<group>"; };
|
||||||
FA0B7B9B1A95902C000E1D17 /* Polyline.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = Polyline.cpp; sourceTree = "<group>"; };
|
FA0B7B9B1A95902C000E1D17 /* Polyline.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = Polyline.cpp; sourceTree = "<group>"; };
|
||||||
@@ -2887,14 +2882,10 @@
|
|||||||
children = (
|
children = (
|
||||||
FA0B7BA41A95902C000E1D17 /* Buffer.cpp */,
|
FA0B7BA41A95902C000E1D17 /* Buffer.cpp */,
|
||||||
FA0B7BA51A95902C000E1D17 /* Buffer.h */,
|
FA0B7BA51A95902C000E1D17 /* Buffer.h */,
|
||||||
FA0B7B8D1A95902C000E1D17 /* Canvas.cpp */,
|
|
||||||
FA0B7B8E1A95902C000E1D17 /* Canvas.h */,
|
|
||||||
FA28EBD31E352DB5003446F4 /* FenceSync.cpp */,
|
FA28EBD31E352DB5003446F4 /* FenceSync.cpp */,
|
||||||
FA28EBD41E352DB5003446F4 /* FenceSync.h */,
|
FA28EBD41E352DB5003446F4 /* FenceSync.h */,
|
||||||
FA0B7B911A95902C000E1D17 /* Graphics.cpp */,
|
FA0B7B911A95902C000E1D17 /* Graphics.cpp */,
|
||||||
FA0B7B921A95902C000E1D17 /* Graphics.h */,
|
FA0B7B921A95902C000E1D17 /* Graphics.h */,
|
||||||
FA0B7B931A95902C000E1D17 /* Image.cpp */,
|
|
||||||
FA0B7B941A95902C000E1D17 /* Image.h */,
|
|
||||||
FA0B7B971A95902C000E1D17 /* OpenGL.cpp */,
|
FA0B7B971A95902C000E1D17 /* OpenGL.cpp */,
|
||||||
FA0B7B981A95902C000E1D17 /* OpenGL.h */,
|
FA0B7B981A95902C000E1D17 /* OpenGL.h */,
|
||||||
FA0B7B9D1A95902C000E1D17 /* Shader.cpp */,
|
FA0B7B9D1A95902C000E1D17 /* Shader.cpp */,
|
||||||
@@ -2903,6 +2894,8 @@
|
|||||||
FA3C5E461F8D80CA0003C579 /* ShaderStage.h */,
|
FA3C5E461F8D80CA0003C579 /* ShaderStage.h */,
|
||||||
FA7634481E28722A0066EF9E /* StreamBuffer.cpp */,
|
FA7634481E28722A0066EF9E /* StreamBuffer.cpp */,
|
||||||
FA7634491E28722A0066EF9E /* StreamBuffer.h */,
|
FA7634491E28722A0066EF9E /* StreamBuffer.h */,
|
||||||
|
FA0B7B931A95902C000E1D17 /* Texture.cpp */,
|
||||||
|
FA0B7B941A95902C000E1D17 /* Texture.h */,
|
||||||
);
|
);
|
||||||
path = opengl;
|
path = opengl;
|
||||||
sourceTree = "<group>";
|
sourceTree = "<group>";
|
||||||
@@ -3820,9 +3813,8 @@
|
|||||||
FA0B7CFC1A95902C000E1D17 /* Filesystem.h in Headers */,
|
FA0B7CFC1A95902C000E1D17 /* Filesystem.h in Headers */,
|
||||||
FA0B7AD81A958EA3000E1D17 /* lua-enet.h in Headers */,
|
FA0B7AD81A958EA3000E1D17 /* lua-enet.h in Headers */,
|
||||||
FA0B7A3A1A958EA3000E1D17 /* b2DynamicTree.h in Headers */,
|
FA0B7A3A1A958EA3000E1D17 /* b2DynamicTree.h in Headers */,
|
||||||
FA0B7D351A95902C000E1D17 /* Canvas.h in Headers */,
|
|
||||||
FA0B7EBA1A95902C000E1D17 /* Channel.h in Headers */,
|
FA0B7EBA1A95902C000E1D17 /* Channel.h in Headers */,
|
||||||
FA0B7D3E1A95902C000E1D17 /* Image.h in Headers */,
|
FA0B7D3E1A95902C000E1D17 /* Texture.h in Headers */,
|
||||||
FA0B7ECA1A95902C000E1D17 /* threads.h in Headers */,
|
FA0B7ECA1A95902C000E1D17 /* threads.h in Headers */,
|
||||||
FADF54361E3DAE6E00012CC0 /* wrap_SpriteBatch.h in Headers */,
|
FADF54361E3DAE6E00012CC0 /* wrap_SpriteBatch.h in Headers */,
|
||||||
FA0B7DB01A95902C000E1D17 /* wrap_CompressedImageData.h in Headers */,
|
FA0B7DB01A95902C000E1D17 /* wrap_CompressedImageData.h in Headers */,
|
||||||
@@ -4381,7 +4373,7 @@
|
|||||||
FA0B7D191A95902C000E1D17 /* TrueTypeRasterizer.cpp in Sources */,
|
FA0B7D191A95902C000E1D17 /* TrueTypeRasterizer.cpp in Sources */,
|
||||||
FAC271E723B5B5B400C200D3 /* renderstate.cpp in Sources */,
|
FAC271E723B5B5B400C200D3 /* renderstate.cpp in Sources */,
|
||||||
FA0B7CFB1A95902C000E1D17 /* Filesystem.cpp in Sources */,
|
FA0B7CFB1A95902C000E1D17 /* Filesystem.cpp in Sources */,
|
||||||
FA0B7D3D1A95902C000E1D17 /* Image.cpp in Sources */,
|
FA0B7D3D1A95902C000E1D17 /* Texture.cpp in Sources */,
|
||||||
FA0B7B351A958EA3000E1D17 /* wuff_convert.c in Sources */,
|
FA0B7B351A958EA3000E1D17 /* wuff_convert.c in Sources */,
|
||||||
FAF140941E20934C00F898D2 /* PpScanner.cpp in Sources */,
|
FAF140941E20934C00F898D2 /* PpScanner.cpp in Sources */,
|
||||||
FA9D53AD1F5307E900125C6B /* Deprecations.cpp in Sources */,
|
FA9D53AD1F5307E900125C6B /* Deprecations.cpp in Sources */,
|
||||||
@@ -4545,7 +4537,6 @@
|
|||||||
FA0B79411A958E3B000E1D17 /* utf8.cpp in Sources */,
|
FA0B79411A958E3B000E1D17 /* utf8.cpp in Sources */,
|
||||||
FAE64A862071363100BC7981 /* physfs_archiver_qpak.c in Sources */,
|
FAE64A862071363100BC7981 /* physfs_archiver_qpak.c in Sources */,
|
||||||
FA0B7ADF1A958EA3000E1D17 /* lodepng.cpp in Sources */,
|
FA0B7ADF1A958EA3000E1D17 /* lodepng.cpp in Sources */,
|
||||||
FA0B7D341A95902C000E1D17 /* Canvas.cpp in Sources */,
|
|
||||||
FAF140761E20934C00F898D2 /* IntermTraverse.cpp in Sources */,
|
FAF140761E20934C00F898D2 /* IntermTraverse.cpp in Sources */,
|
||||||
FA0B7E8C1A95902C000E1D17 /* FLACDecoder.cpp in Sources */,
|
FA0B7E8C1A95902C000E1D17 /* FLACDecoder.cpp in Sources */,
|
||||||
FA0B7A421A958EA3000E1D17 /* b2CircleShape.cpp in Sources */,
|
FA0B7A421A958EA3000E1D17 /* b2CircleShape.cpp in Sources */,
|
||||||
@@ -4778,7 +4769,7 @@
|
|||||||
FA0B7CFA1A95902C000E1D17 /* Filesystem.cpp in Sources */,
|
FA0B7CFA1A95902C000E1D17 /* Filesystem.cpp in Sources */,
|
||||||
FA1BA0A21E16D97500AA2803 /* wrap_Font.cpp in Sources */,
|
FA1BA0A21E16D97500AA2803 /* wrap_Font.cpp in Sources */,
|
||||||
FAC7CD781FE35E95006A60C7 /* physfs_platform_qnx.c in Sources */,
|
FAC7CD781FE35E95006A60C7 /* physfs_platform_qnx.c in Sources */,
|
||||||
FA0B7D3C1A95902C000E1D17 /* Image.cpp in Sources */,
|
FA0B7D3C1A95902C000E1D17 /* Texture.cpp in Sources */,
|
||||||
FA0B7A8C1A958EA3000E1D17 /* b2DistanceJoint.cpp in Sources */,
|
FA0B7A8C1A958EA3000E1D17 /* b2DistanceJoint.cpp in Sources */,
|
||||||
FADF53FD1E3D74F200012CC0 /* Text.cpp in Sources */,
|
FADF53FD1E3D74F200012CC0 /* Text.cpp in Sources */,
|
||||||
FA6A2B741F60B6710074C308 /* ByteData.cpp in Sources */,
|
FA6A2B741F60B6710074C308 /* ByteData.cpp in Sources */,
|
||||||
@@ -4939,7 +4930,6 @@
|
|||||||
FA0B7AD41A958EA3000E1D17 /* unix.c in Sources */,
|
FA0B7AD41A958EA3000E1D17 /* unix.c in Sources */,
|
||||||
FA0B7A771A958EA3000E1D17 /* b2CircleContact.cpp in Sources */,
|
FA0B7A771A958EA3000E1D17 /* b2CircleContact.cpp in Sources */,
|
||||||
FADF543B1E3DAFF700012CC0 /* wrap_Graphics.cpp in Sources */,
|
FADF543B1E3DAFF700012CC0 /* wrap_Graphics.cpp in Sources */,
|
||||||
FA0B7D331A95902C000E1D17 /* Canvas.cpp in Sources */,
|
|
||||||
FA0B7E941A95902C000E1D17 /* Mpg123Decoder.cpp in Sources */,
|
FA0B7E941A95902C000E1D17 /* Mpg123Decoder.cpp in Sources */,
|
||||||
FA0B7E8B1A95902C000E1D17 /* FLACDecoder.cpp in Sources */,
|
FA0B7E8B1A95902C000E1D17 /* FLACDecoder.cpp in Sources */,
|
||||||
FA0B7B3A1A958EA3000E1D17 /* wuff_memory.c in Sources */,
|
FA0B7B3A1A958EA3000E1D17 /* wuff_memory.c in Sources */,
|
||||||
|
|||||||
+123
-73
@@ -24,6 +24,87 @@
|
|||||||
namespace love
|
namespace love
|
||||||
{
|
{
|
||||||
|
|
||||||
|
static PixelFormatInfo formatInfo[] =
|
||||||
|
{
|
||||||
|
// components, blockW, blockH, blockSize, color, depth, stencil, compressed
|
||||||
|
{ 0, 1, 1, 0, false, false, false, false }, // PIXELFORMAT_UNKNOWN
|
||||||
|
|
||||||
|
{ 0, 1, 1, 0, true, false, false, false }, // PIXELFORMAT_NORMAL
|
||||||
|
{ 0, 1, 1, 0, true, false, false, false }, // PIXELFORMAT_HDR
|
||||||
|
|
||||||
|
{ 1, 1, 1, 1, true, false, false, false }, // PIXELFORMAT_R8_UNORM
|
||||||
|
{ 1, 1, 1, 2, true, false, false, false }, // PIXELFORMAT_R16_UNORM
|
||||||
|
{ 1, 1, 1, 2, true, false, false, false }, // PIXELFORMAT_R16_FLOAT
|
||||||
|
{ 1, 1, 1, 4, true, false, false, false }, // PIXELFORMAT_R32_FLOAT
|
||||||
|
|
||||||
|
{ 2, 1, 1, 2, true, false, false, false }, // PIXELFORMAT_RG8_UNORM
|
||||||
|
{ 2, 1, 1, 2, true, false, false, false }, // PIXELFORMAT_LA8_UNORM
|
||||||
|
{ 2, 1, 1, 4, true, false, false, false }, // PIXELFORMAT_RG16_UNORM
|
||||||
|
{ 2, 1, 1, 4, true, false, false, false }, // PIXELFORMAT_RG16_FLOAT
|
||||||
|
{ 2, 1, 1, 8, true, false, false, false }, // PIXELFORMAT_RG32_FLOAT
|
||||||
|
|
||||||
|
{ 4, 1, 1, 4, true, false, false, false }, // PIXELFORMAT_RGBA8_UNORM
|
||||||
|
{ 4, 1, 1, 4, true, false, false, false }, // PIXELFORMAT_sRGBA8_UNORM
|
||||||
|
{ 4, 1, 1, 8, true, false, false, false }, // PIXELFORMAT_RGBA16_UNORM
|
||||||
|
{ 4, 1, 1, 8, true, false, false, false }, // PIXELFORMAT_RGBA16_FLOAT
|
||||||
|
{ 4, 1, 1, 16, true, false, false, false }, // PIXELFORMAT_RGBA32_FLOAT
|
||||||
|
|
||||||
|
{ 4, 1, 1, 2, true, false, false, false }, // PIXELFORMAT_RGBA4_UNORM
|
||||||
|
{ 4, 1, 1, 2, true, false, false, false }, // PIXELFORMAT_RGB5A1_UNORM
|
||||||
|
{ 3, 1, 1, 2, true, false, false, false }, // PIXELFORMAT_RGB565_UNORM
|
||||||
|
{ 4, 1, 1, 4, true, false, false, false }, // PIXELFORMAT_RGB10A2_UNORM
|
||||||
|
{ 3, 1, 1, 4, true, false, false, false }, // PIXELFORMAT_RG11B10_FLOAT
|
||||||
|
|
||||||
|
{ 1, 1, 1, 1, false, false, true , false }, // PIXELFORMAT_STENCIL8
|
||||||
|
{ 1, 1, 1, 2, false, true, false, false }, // PIXELFORMAT_DEPTH16_UNORM
|
||||||
|
{ 1, 1, 1, 3, false, true, false, false }, // PIXELFORMAT_DEPTH24_UNORM
|
||||||
|
{ 1, 1, 1, 4, false, true, false, false }, // PIXELFORMAT_DEPTH32_FLOAT
|
||||||
|
{ 2, 1, 1, 4, false, true, true , false }, // PIXELFORMAT_DEPTH24_UNORM_STENCIL8
|
||||||
|
{ 2, 1, 1, 5, false, true, true , false }, // PIXELFORMAT_DEPTH32_FLOAT_STENCIL8
|
||||||
|
|
||||||
|
{ 3, 4, 4, 8, true, false, false, true }, // PIXELFORMAT_DXT1_UNORM
|
||||||
|
{ 4, 4, 4, 16, true, false, false, true }, // PIXELFORMAT_DXT3_UNORM
|
||||||
|
{ 4, 4, 4, 16, true, false, false, true }, // PIXELFORMAT_DXT5_UNORM
|
||||||
|
{ 1, 4, 4, 8, true, false, false, true }, // PIXELFORMAT_BC4_UNORM
|
||||||
|
{ 1, 4, 4, 8, true, false, false, true }, // PIXELFORMAT_BC4_SNORM
|
||||||
|
{ 2, 4, 4, 16, true, false, false, true }, // PIXELFORMAT_BC5_UNORM
|
||||||
|
{ 2, 4, 4, 16, true, false, false, true }, // PIXELFORMAT_BC5_SNORM
|
||||||
|
{ 3, 4, 4, 16, true, false, false, true }, // PIXELFORMAT_BC6H_UFLOAT
|
||||||
|
{ 3, 4, 4, 16, true, false, false, true }, // PIXELFORMAT_BC6H_FLOAT
|
||||||
|
{ 4, 4, 4, 16, true, false, false, true }, // PIXELFORMAT_BC7_UNORM
|
||||||
|
|
||||||
|
{ 3, 16, 8, 32, true, false, false, true }, // PIXELFORMAT_PVR1_RGB2_UNORM
|
||||||
|
{ 3, 8, 8, 32, true, false, false, true }, // PIXELFORMAT_PVR1_RGB4_UNORM
|
||||||
|
{ 4, 16, 8, 32, true, false, false, true }, // PIXELFORMAT_PVR1_RGBA2_UNORM
|
||||||
|
{ 4, 8, 8, 32, true, false, false, true }, // PIXELFORMAT_PVR1_RGBA4_UNORM
|
||||||
|
|
||||||
|
{ 3, 4, 4, 8, true, false, false, true }, // PIXELFORMAT_ETC1_UNORM
|
||||||
|
{ 3, 4, 4, 8, true, false, false, true }, // PIXELFORMAT_ETC2_RGB_UNORM
|
||||||
|
{ 4, 4, 4, 16, true, false, false, true }, // PIXELFORMAT_ETC2_RGBA_UNORM
|
||||||
|
{ 4, 4, 4, 8, true, false, false, true }, // PIXELFORMAT_ETC2_RGBA1_UNORM
|
||||||
|
{ 1, 4, 4, 8, true, false, false, true }, // PIXELFORMAT_EAC_R_UNORM
|
||||||
|
{ 1, 4, 4, 8, true, false, false, true }, // PIXELFORMAT_EAC_R_SNORM
|
||||||
|
{ 2, 4, 4, 16, true, false, false, true }, // PIXELFORMAT_EAC_RG_UNORM
|
||||||
|
{ 2, 4, 4, 16, true, false, false, true }, // PIXELFORMAT_EAC_RG_SNORM
|
||||||
|
|
||||||
|
{ 4, 4, 4, 1, true, false, false, true }, // PIXELFORMAT_ASTC_4x4
|
||||||
|
{ 4, 5, 4, 1, true, false, false, true }, // PIXELFORMAT_ASTC_5x4
|
||||||
|
{ 4, 5, 5, 1, true, false, false, true }, // PIXELFORMAT_ASTC_5x5
|
||||||
|
{ 4, 6, 5, 1, true, false, false, true }, // PIXELFORMAT_ASTC_6x5
|
||||||
|
{ 4, 6, 6, 1, true, false, false, true }, // PIXELFORMAT_ASTC_6x6
|
||||||
|
{ 4, 8, 5, 1, true, false, false, true }, // PIXELFORMAT_ASTC_8x5
|
||||||
|
{ 4, 8, 6, 1, true, false, false, true }, // PIXELFORMAT_ASTC_8x6
|
||||||
|
{ 4, 8, 8, 1, true, false, false, true }, // PIXELFORMAT_ASTC_8x8
|
||||||
|
{ 4, 8, 5, 1, true, false, false, true }, // PIXELFORMAT_ASTC_10x5
|
||||||
|
{ 4, 10, 6, 1, true, false, false, true }, // PIXELFORMAT_ASTC_10x6
|
||||||
|
{ 4, 10, 8, 1, true, false, false, true }, // PIXELFORMAT_ASTC_10x8
|
||||||
|
{ 4, 10, 10, 1, true, false, false, true }, // PIXELFORMAT_ASTC_10x10
|
||||||
|
{ 4, 12, 10, 1, true, false, false, true }, // PIXELFORMAT_ASTC_12x10
|
||||||
|
{ 4, 12, 12, 1, true, false, false, true }, // PIXELFORMAT_ASTC_12x12
|
||||||
|
};
|
||||||
|
|
||||||
|
static_assert(sizeof(formatInfo) / sizeof(PixelFormatInfo) == PIXELFORMAT_MAX_ENUM, "Update the formatInfo array when adding or removing a PixelFormat");
|
||||||
|
|
||||||
static StringMap<PixelFormat, PIXELFORMAT_MAX_ENUM>::Entry formatEntries[] =
|
static StringMap<PixelFormat, PIXELFORMAT_MAX_ENUM>::Entry formatEntries[] =
|
||||||
{
|
{
|
||||||
{ "unknown", PIXELFORMAT_UNKNOWN },
|
{ "unknown", PIXELFORMAT_UNKNOWN },
|
||||||
@@ -113,28 +194,30 @@ bool getConstant(PixelFormat in, const char *&out)
|
|||||||
return formats.find(in, out);
|
return formats.find(in, out);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
const PixelFormatInfo &getPixelFormatInfo(PixelFormat format)
|
||||||
|
{
|
||||||
|
return formatInfo[format];
|
||||||
|
}
|
||||||
|
|
||||||
bool isPixelFormatCompressed(PixelFormat format)
|
bool isPixelFormatCompressed(PixelFormat format)
|
||||||
{
|
{
|
||||||
// I'm lazy
|
return formatInfo[format].compressed;
|
||||||
int iformat = (int) format;
|
|
||||||
return iformat >= (int) PIXELFORMAT_DXT1_UNORM && iformat < (int) PIXELFORMAT_MAX_ENUM;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
bool isPixelFormatDepthStencil(PixelFormat format)
|
bool isPixelFormatDepthStencil(PixelFormat format)
|
||||||
{
|
{
|
||||||
int iformat = (int) format;
|
const PixelFormatInfo &info = formatInfo[format];
|
||||||
return iformat >= (int) PIXELFORMAT_STENCIL8 && iformat <= (int) PIXELFORMAT_DEPTH32_FLOAT_STENCIL8;
|
return info.depth || info.stencil;
|
||||||
}
|
}
|
||||||
|
|
||||||
bool isPixelFormatDepth(PixelFormat format)
|
bool isPixelFormatDepth(PixelFormat format)
|
||||||
{
|
{
|
||||||
int iformat = (int) format;
|
return formatInfo[format].depth;
|
||||||
return iformat >= (int) PIXELFORMAT_DEPTH16_UNORM && iformat <= (int) PIXELFORMAT_DEPTH32_FLOAT_STENCIL8;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
bool isPixelFormatStencil(PixelFormat format)
|
bool isPixelFormatStencil(PixelFormat format)
|
||||||
{
|
{
|
||||||
return format == PIXELFORMAT_STENCIL8 || format == PIXELFORMAT_DEPTH24_UNORM_STENCIL8 || format == PIXELFORMAT_DEPTH32_FLOAT_STENCIL8;
|
return formatInfo[format].stencil;
|
||||||
}
|
}
|
||||||
|
|
||||||
PixelFormat getSRGBPixelFormat(PixelFormat format)
|
PixelFormat getSRGBPixelFormat(PixelFormat format)
|
||||||
@@ -151,76 +234,43 @@ PixelFormat getLinearPixelFormat(PixelFormat format)
|
|||||||
return format;
|
return format;
|
||||||
}
|
}
|
||||||
|
|
||||||
size_t getPixelFormatSize(PixelFormat format)
|
size_t getPixelFormatBlockSize(PixelFormat format)
|
||||||
{
|
{
|
||||||
switch (format)
|
return formatInfo[format].blockSize;
|
||||||
{
|
}
|
||||||
case PIXELFORMAT_R8_UNORM:
|
|
||||||
case PIXELFORMAT_STENCIL8:
|
size_t getPixelFormatUncompressedRowSize(PixelFormat format, int width)
|
||||||
return 1;
|
{
|
||||||
case PIXELFORMAT_RG8_UNORM:
|
const PixelFormatInfo &info = formatInfo[format];
|
||||||
case PIXELFORMAT_R16_UNORM:
|
if (info.compressed) return 0;
|
||||||
case PIXELFORMAT_R16_FLOAT:
|
return info.blockSize * width / info.blockWidth;
|
||||||
case PIXELFORMAT_LA8_UNORM:
|
}
|
||||||
case PIXELFORMAT_RGBA4_UNORM:
|
|
||||||
case PIXELFORMAT_RGB5A1_UNORM:
|
size_t getPixelFormatCompressedBlockRowSize(PixelFormat format, int width)
|
||||||
case PIXELFORMAT_RGB565_UNORM:
|
{
|
||||||
case PIXELFORMAT_DEPTH16_UNORM:
|
const PixelFormatInfo &info = formatInfo[format];
|
||||||
return 2;
|
if (!info.compressed) return 0;
|
||||||
case PIXELFORMAT_RGBA8_UNORM:
|
return info.blockSize * ((width + info.blockWidth - 1) / info.blockWidth);
|
||||||
case PIXELFORMAT_sRGBA8_UNORM:
|
}
|
||||||
case PIXELFORMAT_RG16_UNORM:
|
|
||||||
case PIXELFORMAT_RG16_FLOAT:
|
size_t getPixelFormatCompressedBlockRowCount(PixelFormat format, int height)
|
||||||
case PIXELFORMAT_R32_FLOAT:
|
{
|
||||||
case PIXELFORMAT_RGB10A2_UNORM:
|
const PixelFormatInfo &info = formatInfo[format];
|
||||||
case PIXELFORMAT_RG11B10_FLOAT:
|
if (!info.compressed) return 0;
|
||||||
case PIXELFORMAT_DEPTH24_UNORM:
|
return (height + info.blockHeight - 1) / info.blockHeight;
|
||||||
case PIXELFORMAT_DEPTH32_FLOAT:
|
}
|
||||||
case PIXELFORMAT_DEPTH24_UNORM_STENCIL8:
|
|
||||||
return 4;
|
size_t getPixelFormatSliceSize(PixelFormat format, int width, int height)
|
||||||
case PIXELFORMAT_RGBA16_UNORM:
|
{
|
||||||
case PIXELFORMAT_RGBA16_FLOAT:
|
const PixelFormatInfo &info = formatInfo[format];
|
||||||
case PIXELFORMAT_RG32_FLOAT:
|
size_t blockW = (width + info.blockWidth - 1) / info.blockWidth;
|
||||||
case PIXELFORMAT_DEPTH32_FLOAT_STENCIL8:
|
size_t blockH = (height + info.blockHeight - 1) / info.blockHeight;
|
||||||
return 8;
|
return info.blockSize * blockW * blockH;
|
||||||
case PIXELFORMAT_RGBA32_FLOAT:
|
|
||||||
return 16;
|
|
||||||
default:
|
|
||||||
// TODO: compressed formats
|
|
||||||
return 0;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
int getPixelFormatColorComponents(PixelFormat format)
|
int getPixelFormatColorComponents(PixelFormat format)
|
||||||
{
|
{
|
||||||
switch (format)
|
return formatInfo[format].components;
|
||||||
{
|
|
||||||
case PIXELFORMAT_R8_UNORM:
|
|
||||||
case PIXELFORMAT_R16_UNORM:
|
|
||||||
case PIXELFORMAT_R16_FLOAT:
|
|
||||||
case PIXELFORMAT_R32_FLOAT:
|
|
||||||
return 1;
|
|
||||||
case PIXELFORMAT_RG8_UNORM:
|
|
||||||
case PIXELFORMAT_RG16_UNORM:
|
|
||||||
case PIXELFORMAT_RG16_FLOAT:
|
|
||||||
case PIXELFORMAT_RG32_FLOAT:
|
|
||||||
case PIXELFORMAT_LA8_UNORM:
|
|
||||||
return 2;
|
|
||||||
case PIXELFORMAT_RGB565_UNORM:
|
|
||||||
case PIXELFORMAT_RG11B10_FLOAT:
|
|
||||||
return 3;
|
|
||||||
case PIXELFORMAT_RGBA8_UNORM:
|
|
||||||
case PIXELFORMAT_sRGBA8_UNORM:
|
|
||||||
case PIXELFORMAT_RGBA16_UNORM:
|
|
||||||
case PIXELFORMAT_RGBA16_FLOAT:
|
|
||||||
case PIXELFORMAT_RGBA32_FLOAT:
|
|
||||||
case PIXELFORMAT_RGBA4_UNORM:
|
|
||||||
case PIXELFORMAT_RGB5A1_UNORM:
|
|
||||||
case PIXELFORMAT_RGB10A2_UNORM:
|
|
||||||
return 4;
|
|
||||||
default:
|
|
||||||
return 0;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
} // love
|
} // love
|
||||||
|
|||||||
@@ -109,9 +109,23 @@ enum PixelFormat
|
|||||||
PIXELFORMAT_MAX_ENUM
|
PIXELFORMAT_MAX_ENUM
|
||||||
};
|
};
|
||||||
|
|
||||||
|
struct PixelFormatInfo
|
||||||
|
{
|
||||||
|
int components;
|
||||||
|
size_t blockWidth;
|
||||||
|
size_t blockHeight;
|
||||||
|
size_t blockSize;
|
||||||
|
bool color;
|
||||||
|
bool depth;
|
||||||
|
bool stencil;
|
||||||
|
bool compressed;
|
||||||
|
};
|
||||||
|
|
||||||
bool getConstant(PixelFormat in, const char *&out);
|
bool getConstant(PixelFormat in, const char *&out);
|
||||||
bool getConstant(const char *in, PixelFormat &out);
|
bool getConstant(const char *in, PixelFormat &out);
|
||||||
|
|
||||||
|
const PixelFormatInfo &getPixelFormatInfo(PixelFormat format);
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Gets whether the specified pixel format is a compressed type.
|
* Gets whether the specified pixel format is a compressed type.
|
||||||
**/
|
**/
|
||||||
@@ -143,10 +157,36 @@ PixelFormat getSRGBPixelFormat(PixelFormat format);
|
|||||||
PixelFormat getLinearPixelFormat(PixelFormat format);
|
PixelFormat getLinearPixelFormat(PixelFormat format);
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Gets the size in bytes of the specified pixel format.
|
* Gets the block size in bytes of the specified pixel format.
|
||||||
* NOTE: Currently returns 0 for compressed formats.
|
* This is the size in bytes of a pixel for uncompressed formats, but *not*
|
||||||
|
* for compressed formats!
|
||||||
**/
|
**/
|
||||||
size_t getPixelFormatSize(PixelFormat format);
|
size_t getPixelFormatBlockSize(PixelFormat format);
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Gets the size in bytes of a row of an uncompressed pixel format.
|
||||||
|
**/
|
||||||
|
size_t getPixelFormatUncompressedRowSize(PixelFormat format, int width);
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Gets the size in bytes of a row of a compressed pixel format. This is the
|
||||||
|
* number of blocks used by the given width, multiplied by the block size. The
|
||||||
|
* number of rows of blocks for a given height can be computed by
|
||||||
|
* getPixelFormatCompressedBlockRowCount.
|
||||||
|
**/
|
||||||
|
size_t getPixelFormatCompressedBlockRowSize(PixelFormat format, int width);
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Gets the number of rows of blocks the given compressed pixel format will use,
|
||||||
|
* for the given height in pixels.
|
||||||
|
**/
|
||||||
|
size_t getPixelFormatCompressedBlockRowCount(PixelFormat format, int height);
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Gets the size in bytes of a slice (width x height 2D plane) which uses the
|
||||||
|
* given pixel format.
|
||||||
|
**/
|
||||||
|
size_t getPixelFormatSliceSize(PixelFormat format, int width, int height);
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Gets the number of color components in the given pixel format.
|
* Gets the number of color components in the given pixel format.
|
||||||
|
|||||||
@@ -78,7 +78,7 @@ void *GlyphData::getData() const
|
|||||||
|
|
||||||
size_t GlyphData::getPixelSize() const
|
size_t GlyphData::getPixelSize() const
|
||||||
{
|
{
|
||||||
return getPixelFormatSize(format);
|
return getPixelFormatBlockSize(format);
|
||||||
}
|
}
|
||||||
|
|
||||||
void *GlyphData::getData(int x, int y) const
|
void *GlyphData::getData(int x, int y) const
|
||||||
|
|||||||
@@ -158,7 +158,7 @@ void Font::createTexture()
|
|||||||
texture->setSamplerState(samplerState);
|
texture->setSamplerState(samplerState);
|
||||||
|
|
||||||
{
|
{
|
||||||
size_t bpp = getPixelFormatSize(pixelFormat);
|
size_t bpp = getPixelFormatBlockSize(pixelFormat);
|
||||||
size_t pixelcount = size.width * size.height;
|
size_t pixelcount = size.width * size.height;
|
||||||
|
|
||||||
// Initialize the texture with transparent white for Luminance-Alpha
|
// Initialize the texture with transparent white for Luminance-Alpha
|
||||||
|
|||||||
@@ -184,6 +184,9 @@ Texture::Texture(const Settings &settings, const Slices *slices)
|
|||||||
{
|
{
|
||||||
texType = slices->getTextureType();
|
texType = slices->getTextureType();
|
||||||
|
|
||||||
|
if (requestedMSAA > 1)
|
||||||
|
throw love::Exception("MSAA textures cannot be created from image data.");
|
||||||
|
|
||||||
int dataMipmaps = 1;
|
int dataMipmaps = 1;
|
||||||
if (slices->validate() && slices->getMipmapCount() > 1)
|
if (slices->validate() && slices->getMipmapCount() > 1)
|
||||||
dataMipmaps = slices->getMipmapCount();
|
dataMipmaps = slices->getMipmapCount();
|
||||||
@@ -218,7 +221,7 @@ Texture::Texture(const Settings &settings, const Slices *slices)
|
|||||||
if (settings.readable.hasValue)
|
if (settings.readable.hasValue)
|
||||||
readable = settings.readable.value;
|
readable = settings.readable.value;
|
||||||
else
|
else
|
||||||
readable = !isPixelFormatDepthStencil(format);
|
readable = !renderTarget || !isPixelFormatDepthStencil(format);
|
||||||
|
|
||||||
format = gfx->getSizedFormat(format, renderTarget, readable, sRGB);
|
format = gfx->getSizedFormat(format, renderTarget, readable, sRGB);
|
||||||
|
|
||||||
@@ -234,6 +237,9 @@ Texture::Texture(const Settings &settings, const Slices *slices)
|
|||||||
if (texType != TEXTURE_2D && requestedMSAA > 1)
|
if (texType != TEXTURE_2D && requestedMSAA > 1)
|
||||||
throw love::Exception("MSAA is only supported for textures with the 2D texture type.");
|
throw love::Exception("MSAA is only supported for textures with the 2D texture type.");
|
||||||
|
|
||||||
|
if (!renderTarget && requestedMSAA > 1)
|
||||||
|
throw love::Exception("MSAA is only supported with render target textures.");
|
||||||
|
|
||||||
if (readable && isPixelFormatDepthStencil(format) && settings.msaa > 1)
|
if (readable && isPixelFormatDepthStencil(format) && settings.msaa > 1)
|
||||||
throw love::Exception("Readable depth/stencil textures with MSAA are not currently supported.");
|
throw love::Exception("Readable depth/stencil textures with MSAA are not currently supported.");
|
||||||
|
|
||||||
@@ -269,7 +275,7 @@ Texture::Texture(const Settings &settings, const Slices *slices)
|
|||||||
throw love::Exception("%s textures are not supported on this system.", textypestr);
|
throw love::Exception("%s textures are not supported on this system.", textypestr);
|
||||||
}
|
}
|
||||||
|
|
||||||
validateDimensions(!renderTarget);
|
validateDimensions(renderTarget || !readable);
|
||||||
|
|
||||||
samplerState = gfx->getDefaultSamplerState();
|
samplerState = gfx->getDefaultSamplerState();
|
||||||
|
|
||||||
@@ -619,8 +625,11 @@ int Texture::getRequestedMSAA() const
|
|||||||
|
|
||||||
void Texture::setSamplerState(const SamplerState &s)
|
void Texture::setSamplerState(const SamplerState &s)
|
||||||
{
|
{
|
||||||
if (s.depthSampleMode.hasValue && (!readable || !isPixelFormatDepthStencil(format)))
|
if (!readable)
|
||||||
throw love::Exception("Only readable depth textures can have a depth sample compare mode.");
|
return;
|
||||||
|
|
||||||
|
if (s.depthSampleMode.hasValue && !isPixelFormatDepth(format))
|
||||||
|
throw love::Exception("Only depth textures can have a depth sample compare mode.");
|
||||||
|
|
||||||
Graphics::flushStreamDrawsGlobal();
|
Graphics::flushStreamDrawsGlobal();
|
||||||
|
|
||||||
|
|||||||
@@ -164,7 +164,7 @@ public:
|
|||||||
PixelFormat format = PIXELFORMAT_NORMAL;
|
PixelFormat format = PIXELFORMAT_NORMAL;
|
||||||
bool linear = false;
|
bool linear = false;
|
||||||
float dpiScale = 1.0f;
|
float dpiScale = 1.0f;
|
||||||
int msaa = 0;
|
int msaa = 1;
|
||||||
bool renderTarget = false;
|
bool renderTarget = false;
|
||||||
OptionalBool readable;
|
OptionalBool readable;
|
||||||
};
|
};
|
||||||
|
|||||||
@@ -90,7 +90,7 @@ Video::Video(Graphics *gfx, love::video::VideoStream *stream, float dpiscale)
|
|||||||
|
|
||||||
tex->setSamplerState(samplerState);
|
tex->setSamplerState(samplerState);
|
||||||
|
|
||||||
size_t bpp = getPixelFormatSize(PIXELFORMAT_R8_UNORM);
|
size_t bpp = getPixelFormatBlockSize(PIXELFORMAT_R8_UNORM);
|
||||||
size_t size = bpp * widths[i] * heights[i];
|
size_t size = bpp * widths[i] * heights[i];
|
||||||
|
|
||||||
Rect rect = {0, 0, widths[i], heights[i]};
|
Rect rect = {0, 0, widths[i], heights[i]};
|
||||||
@@ -167,7 +167,7 @@ void Video::update()
|
|||||||
|
|
||||||
for (int i = 0; i < 3; i++)
|
for (int i = 0; i < 3; i++)
|
||||||
{
|
{
|
||||||
size_t bpp = getPixelFormatSize(PIXELFORMAT_R8_UNORM);
|
size_t bpp = getPixelFormatBlockSize(PIXELFORMAT_R8_UNORM);
|
||||||
size_t size = bpp * widths[i] * heights[i];
|
size_t size = bpp * widths[i] * heights[i];
|
||||||
|
|
||||||
Rect rect = {0, 0, widths[i], heights[i]};
|
Rect rect = {0, 0, widths[i], heights[i]};
|
||||||
|
|||||||
@@ -132,10 +132,7 @@ love::graphics::StreamBuffer *Graphics::newStreamBuffer(BufferType type, size_t
|
|||||||
|
|
||||||
love::graphics::Texture *Graphics::newTexture(const Texture::Settings &settings, const Texture::Slices *data)
|
love::graphics::Texture *Graphics::newTexture(const Texture::Settings &settings, const Texture::Slices *data)
|
||||||
{
|
{
|
||||||
if (settings.renderTarget)
|
return new Texture(settings, data);
|
||||||
return new Canvas(settings);
|
|
||||||
else
|
|
||||||
return new Image(settings, data);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
love::graphics::ShaderStage *Graphics::newShaderStageInternal(ShaderStage::StageType stage, const std::string &cachekey, const std::string &source, bool gles)
|
love::graphics::ShaderStage *Graphics::newShaderStageInternal(ShaderStage::StageType stage, const std::string &cachekey, const std::string &source, bool gles)
|
||||||
@@ -569,8 +566,7 @@ void Graphics::endPass()
|
|||||||
|
|
||||||
for (int i = 0; i < (int) rts.colors.size(); i++)
|
for (int i = 0; i < (int) rts.colors.size(); i++)
|
||||||
{
|
{
|
||||||
// FIXME
|
Texture *c = (Texture *) rts.colors[i].texture.get();
|
||||||
Canvas *c = (Canvas *) rts.colors[i].texture.get();
|
|
||||||
|
|
||||||
if (!c->isReadable())
|
if (!c->isReadable())
|
||||||
continue;
|
continue;
|
||||||
@@ -588,7 +584,7 @@ void Graphics::endPass()
|
|||||||
|
|
||||||
if (depthstencil != nullptr && depthstencil->getMSAA() > 1 && depthstencil->isReadable())
|
if (depthstencil != nullptr && depthstencil->getMSAA() > 1 && depthstencil->isReadable())
|
||||||
{
|
{
|
||||||
gl.bindFramebuffer(OpenGL::FRAMEBUFFER_DRAW, ((Canvas *) depthstencil)->getFBO());
|
gl.bindFramebuffer(OpenGL::FRAMEBUFFER_DRAW, ((Texture *) depthstencil)->getFBO());
|
||||||
|
|
||||||
if (GLAD_APPLE_framebuffer_multisample)
|
if (GLAD_APPLE_framebuffer_multisample)
|
||||||
glResolveMultisampleFramebufferAPPLE();
|
glResolveMultisampleFramebufferAPPLE();
|
||||||
@@ -613,14 +609,13 @@ void Graphics::endPass()
|
|||||||
|
|
||||||
for (const auto &rt : rts.colors)
|
for (const auto &rt : rts.colors)
|
||||||
{
|
{
|
||||||
// TODO
|
if (rt.texture->getMipmapsMode() == Texture::MIPMAPS_AUTO && rt.mipmap == 0)
|
||||||
// if (rt.texture->getMipmapMode() == Canvas::MIPMAPS_AUTO && rt.mipmap == 0)
|
rt.texture->generateMipmaps();
|
||||||
// rt.texture->generateMipmaps();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// int dsmipmap = rts.depthStencil.mipmap;
|
int dsmipmap = rts.depthStencil.mipmap;
|
||||||
// if (depthstencil != nullptr && depthstencil->getMipmapMode() == Canvas::MIPMAPS_AUTO && dsmipmap == 0)
|
if (depthstencil != nullptr && depthstencil->getMipmapsMode() == Texture::MIPMAPS_AUTO && dsmipmap == 0)
|
||||||
// depthstencil->generateMipmaps();
|
depthstencil->generateMipmaps();
|
||||||
}
|
}
|
||||||
|
|
||||||
void Graphics::clear(OptionalColorf c, OptionalInt stencil, OptionalDouble depth)
|
void Graphics::clear(OptionalColorf c, OptionalInt stencil, OptionalDouble depth)
|
||||||
@@ -813,7 +808,7 @@ void Graphics::discard(OpenGL::FramebufferTarget target, const std::vector<bool>
|
|||||||
glDiscardFramebufferEXT(gltarget, (GLint) attachments.size(), &attachments[0]);
|
glDiscardFramebufferEXT(gltarget, (GLint) attachments.size(), &attachments[0]);
|
||||||
}
|
}
|
||||||
|
|
||||||
void Graphics::cleanupRenderTexture(Texture *texture)
|
void Graphics::cleanupRenderTexture(love::graphics::Texture *texture)
|
||||||
{
|
{
|
||||||
if (!texture->isRenderTarget())
|
if (!texture->isRenderTarget())
|
||||||
return;
|
return;
|
||||||
|
|||||||
@@ -36,8 +36,7 @@
|
|||||||
#include "image/Image.h"
|
#include "image/Image.h"
|
||||||
#include "image/ImageData.h"
|
#include "image/ImageData.h"
|
||||||
|
|
||||||
#include "Image.h"
|
#include "Texture.h"
|
||||||
#include "Canvas.h"
|
|
||||||
#include "Shader.h"
|
#include "Shader.h"
|
||||||
|
|
||||||
#include "libraries/xxHash/xxhash.h"
|
#include "libraries/xxHash/xxhash.h"
|
||||||
@@ -71,7 +70,7 @@ public:
|
|||||||
|
|
||||||
void draw(const DrawCommand &cmd) override;
|
void draw(const DrawCommand &cmd) override;
|
||||||
void draw(const DrawIndexedCommand &cmd) override;
|
void draw(const DrawIndexedCommand &cmd) override;
|
||||||
void drawQuads(int start, int count, const vertex::Attributes &attributes, const vertex::BufferBindings &buffers, Texture *texture) override;
|
void drawQuads(int start, int count, const vertex::Attributes &attributes, const vertex::BufferBindings &buffers, love::graphics::Texture *texture) override;
|
||||||
|
|
||||||
void clear(OptionalColorf color, OptionalInt stencil, OptionalDouble depth) override;
|
void clear(OptionalColorf color, OptionalInt stencil, OptionalDouble depth) override;
|
||||||
void clear(const std::vector<OptionalColorf> &colors, OptionalInt stencil, OptionalDouble depth) override;
|
void clear(const std::vector<OptionalColorf> &colors, OptionalInt stencil, OptionalDouble depth) override;
|
||||||
@@ -110,7 +109,7 @@ public:
|
|||||||
Shader::Language getShaderLanguageTarget() const override;
|
Shader::Language getShaderLanguageTarget() const override;
|
||||||
|
|
||||||
// Internal use.
|
// Internal use.
|
||||||
void cleanupRenderTexture(Texture *texture);
|
void cleanupRenderTexture(love::graphics::Texture *texture);
|
||||||
|
|
||||||
private:
|
private:
|
||||||
|
|
||||||
|
|||||||
@@ -1,296 +0,0 @@
|
|||||||
/**
|
|
||||||
* Copyright (c) 2006-2020 LOVE Development Team
|
|
||||||
*
|
|
||||||
* This software is provided 'as-is', without any express or implied
|
|
||||||
* warranty. In no event will the authors be held liable for any damages
|
|
||||||
* arising from the use of this software.
|
|
||||||
*
|
|
||||||
* Permission is granted to anyone to use this software for any purpose,
|
|
||||||
* including commercial applications, and to alter it and redistribute it
|
|
||||||
* freely, subject to the following restrictions:
|
|
||||||
*
|
|
||||||
* 1. The origin of this software must not be misrepresented; you must not
|
|
||||||
* claim that you wrote the original software. If you use this software
|
|
||||||
* in a product, an acknowledgment in the product documentation would be
|
|
||||||
* appreciated but is not required.
|
|
||||||
* 2. Altered source versions must be plainly marked as such, and must not be
|
|
||||||
* misrepresented as being the original software.
|
|
||||||
* 3. This notice may not be removed or altered from any source distribution.
|
|
||||||
**/
|
|
||||||
|
|
||||||
#include "Image.h"
|
|
||||||
|
|
||||||
#include "graphics/Graphics.h"
|
|
||||||
#include "common/int.h"
|
|
||||||
|
|
||||||
// STD
|
|
||||||
#include <algorithm> // for min/max
|
|
||||||
|
|
||||||
namespace love
|
|
||||||
{
|
|
||||||
namespace graphics
|
|
||||||
{
|
|
||||||
namespace opengl
|
|
||||||
{
|
|
||||||
|
|
||||||
Image::Image(const Settings &settings, const Slices *data)
|
|
||||||
: love::graphics::Texture(settings, data)
|
|
||||||
, slices(settings.type)
|
|
||||||
, texture(0)
|
|
||||||
{
|
|
||||||
if (data != nullptr)
|
|
||||||
slices = *data;
|
|
||||||
loadVolatile();
|
|
||||||
}
|
|
||||||
|
|
||||||
Image::~Image()
|
|
||||||
{
|
|
||||||
unloadVolatile();
|
|
||||||
}
|
|
||||||
|
|
||||||
void Image::generateMipmaps()
|
|
||||||
{
|
|
||||||
if (getMipmapCount() > 1 && !isCompressed() &&
|
|
||||||
(GLAD_ES_VERSION_2_0 || GLAD_VERSION_3_0 || GLAD_ARB_framebuffer_object || GLAD_EXT_framebuffer_object))
|
|
||||||
{
|
|
||||||
gl.bindTextureToUnit(this, 0, false);
|
|
||||||
|
|
||||||
GLenum gltextype = OpenGL::getGLTextureType(texType);
|
|
||||||
|
|
||||||
if (gl.bugs.generateMipmapsRequiresTexture2DEnable)
|
|
||||||
glEnable(gltextype);
|
|
||||||
|
|
||||||
glGenerateMipmap(gltextype);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
void Image::loadDefaultTexture()
|
|
||||||
{
|
|
||||||
usingDefaultTexture = true;
|
|
||||||
|
|
||||||
gl.bindTextureToUnit(this, 0, false);
|
|
||||||
setSamplerState(samplerState);
|
|
||||||
|
|
||||||
bool isSRGB = false;
|
|
||||||
gl.rawTexStorage(texType, 1, PIXELFORMAT_RGBA8_UNORM, isSRGB, 2, 2, 1);
|
|
||||||
|
|
||||||
// A nice friendly checkerboard to signify invalid textures...
|
|
||||||
GLubyte px[] = {0xFF,0xFF,0xFF,0xFF, 0xFF,0xA0,0xA0,0xFF,
|
|
||||||
0xFF,0xA0,0xA0,0xFF, 0xFF,0xFF,0xFF,0xFF};
|
|
||||||
|
|
||||||
int slices = texType == TEXTURE_CUBE ? 6 : 1;
|
|
||||||
Rect rect = {0, 0, 2, 2};
|
|
||||||
for (int slice = 0; slice < slices; slice++)
|
|
||||||
uploadByteData(PIXELFORMAT_RGBA8_UNORM, px, sizeof(px), 0, slice, rect, nullptr);
|
|
||||||
}
|
|
||||||
|
|
||||||
void Image::loadData()
|
|
||||||
{
|
|
||||||
int mipcount = getMipmapCount();
|
|
||||||
int slicecount = 1;
|
|
||||||
|
|
||||||
if (texType == TEXTURE_VOLUME)
|
|
||||||
slicecount = getDepth();
|
|
||||||
else if (texType == TEXTURE_2D_ARRAY)
|
|
||||||
slicecount = getLayerCount();
|
|
||||||
else if (texType == TEXTURE_CUBE)
|
|
||||||
slicecount = 6;
|
|
||||||
|
|
||||||
if (!isCompressed())
|
|
||||||
gl.rawTexStorage(texType, mipcount, format, sRGB, pixelWidth, pixelHeight, texType == TEXTURE_VOLUME ? depth : layers);
|
|
||||||
|
|
||||||
int w = pixelWidth;
|
|
||||||
int h = pixelHeight;
|
|
||||||
int d = depth;
|
|
||||||
|
|
||||||
OpenGL::TextureFormat fmt = gl.convertPixelFormat(format, false, sRGB);
|
|
||||||
|
|
||||||
for (int mip = 0; mip < mipcount; mip++)
|
|
||||||
{
|
|
||||||
if (isCompressed() && (texType == TEXTURE_2D_ARRAY || texType == TEXTURE_VOLUME))
|
|
||||||
{
|
|
||||||
size_t mipsize = 0;
|
|
||||||
|
|
||||||
if (texType == TEXTURE_2D_ARRAY || texType == TEXTURE_VOLUME)
|
|
||||||
{
|
|
||||||
for (int slice = 0; slice < slices.getSliceCount(mip); slice++)
|
|
||||||
{
|
|
||||||
auto id = slices.get(slice, mip);
|
|
||||||
if (id != nullptr)
|
|
||||||
mipsize += id->getSize();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
if (mipsize > 0)
|
|
||||||
{
|
|
||||||
GLenum gltarget = OpenGL::getGLTextureType(texType);
|
|
||||||
glCompressedTexImage3D(gltarget, mip, fmt.internalformat, w, h, d, 0, mipsize, nullptr);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
for (int slice = 0; slice < slicecount; slice++)
|
|
||||||
{
|
|
||||||
love::image::ImageDataBase *id = slices.get(slice, mip);
|
|
||||||
if (id != nullptr)
|
|
||||||
uploadImageData(id, mip, slice, 0, 0);
|
|
||||||
}
|
|
||||||
|
|
||||||
w = std::max(w / 2, 1);
|
|
||||||
h = std::max(h / 2, 1);
|
|
||||||
|
|
||||||
if (texType == TEXTURE_VOLUME)
|
|
||||||
d = std::max(d / 2, 1);
|
|
||||||
}
|
|
||||||
|
|
||||||
if (getMipmapCount() > 1 && slices.getMipmapCount() <= 1)
|
|
||||||
generateMipmaps();
|
|
||||||
}
|
|
||||||
|
|
||||||
void Image::uploadByteData(PixelFormat pixelformat, const void *data, size_t size, int level, int slice, const Rect &r, love::image::ImageDataBase *imgd)
|
|
||||||
{
|
|
||||||
love::image::ImageDataBase *oldd = slices.get(slice, level);
|
|
||||||
|
|
||||||
// We can only replace the internal Data (used when reloading due to setMode)
|
|
||||||
// if the dimensions match.
|
|
||||||
if (imgd != nullptr && oldd != nullptr && oldd->getWidth() == imgd->getWidth()
|
|
||||||
&& oldd->getHeight() == imgd->getHeight())
|
|
||||||
{
|
|
||||||
slices.set(slice, level, imgd);
|
|
||||||
}
|
|
||||||
|
|
||||||
OpenGL::TempDebugGroup debuggroup("Image data upload");
|
|
||||||
|
|
||||||
gl.bindTextureToUnit(this, 0, false);
|
|
||||||
|
|
||||||
OpenGL::TextureFormat fmt = OpenGL::convertPixelFormat(pixelformat, false, sRGB);
|
|
||||||
GLenum gltarget = OpenGL::getGLTextureType(texType);
|
|
||||||
|
|
||||||
if (texType == TEXTURE_CUBE)
|
|
||||||
gltarget = GL_TEXTURE_CUBE_MAP_POSITIVE_X + slice;
|
|
||||||
|
|
||||||
if (isPixelFormatCompressed(pixelformat))
|
|
||||||
{
|
|
||||||
if (r.x != 0 || r.y != 0)
|
|
||||||
throw love::Exception("x and y parameters must be 0 for compressed images.");
|
|
||||||
|
|
||||||
if (texType == TEXTURE_2D || texType == TEXTURE_CUBE)
|
|
||||||
glCompressedTexImage2D(gltarget, level, fmt.internalformat, r.w, r.h, 0, size, data);
|
|
||||||
else if (texType == TEXTURE_2D_ARRAY || texType == TEXTURE_VOLUME)
|
|
||||||
glCompressedTexSubImage3D(gltarget, level, 0, 0, slice, r.w, r.h, 1, fmt.internalformat, size, data);
|
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
if (texType == TEXTURE_2D || texType == TEXTURE_CUBE)
|
|
||||||
glTexSubImage2D(gltarget, level, r.x, r.y, r.w, r.h, fmt.externalformat, fmt.type, data);
|
|
||||||
else if (texType == TEXTURE_2D_ARRAY || texType == TEXTURE_VOLUME)
|
|
||||||
glTexSubImage3D(gltarget, level, r.x, r.y, slice, r.w, r.h, 1, fmt.externalformat, fmt.type, data);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
bool Image::loadVolatile()
|
|
||||||
{
|
|
||||||
if (texture != 0)
|
|
||||||
return true;
|
|
||||||
|
|
||||||
OpenGL::TempDebugGroup debuggroup("Image load");
|
|
||||||
|
|
||||||
// NPOT textures don't support mipmapping without full NPOT support.
|
|
||||||
if ((GLAD_ES_VERSION_2_0 && !(GLAD_ES_VERSION_3_0 || GLAD_OES_texture_npot))
|
|
||||||
&& (pixelWidth != nextP2(pixelWidth) || pixelHeight != nextP2(pixelHeight)))
|
|
||||||
{
|
|
||||||
mipmapCount = 1;
|
|
||||||
samplerState.mipmapFilter = SamplerState::MIPMAP_FILTER_NONE;
|
|
||||||
}
|
|
||||||
|
|
||||||
glGenTextures(1, &texture);
|
|
||||||
gl.bindTextureToUnit(this, 0, false);
|
|
||||||
|
|
||||||
// Use a default texture if the size is too big for the system.
|
|
||||||
if (!validateDimensions(false))
|
|
||||||
{
|
|
||||||
loadDefaultTexture();
|
|
||||||
return true;
|
|
||||||
}
|
|
||||||
|
|
||||||
setSamplerState(samplerState);
|
|
||||||
|
|
||||||
while (glGetError() != GL_NO_ERROR); // Clear errors.
|
|
||||||
|
|
||||||
try
|
|
||||||
{
|
|
||||||
loadData();
|
|
||||||
|
|
||||||
GLenum glerr = glGetError();
|
|
||||||
if (glerr != GL_NO_ERROR)
|
|
||||||
throw love::Exception("Cannot create image (OpenGL error: %s)", OpenGL::errorString(glerr));
|
|
||||||
}
|
|
||||||
catch (love::Exception &)
|
|
||||||
{
|
|
||||||
gl.deleteTexture(texture);
|
|
||||||
texture = 0;
|
|
||||||
throw;
|
|
||||||
}
|
|
||||||
|
|
||||||
int64 memsize = 0;
|
|
||||||
|
|
||||||
for (int slice = 0; slice < slices.getSliceCount(0); slice++)
|
|
||||||
memsize += slices.get(slice, 0)->getSize();
|
|
||||||
|
|
||||||
if (getMipmapCount() > 1)
|
|
||||||
memsize *= 1.33334;
|
|
||||||
|
|
||||||
setGraphicsMemorySize(memsize);
|
|
||||||
|
|
||||||
usingDefaultTexture = false;
|
|
||||||
return true;
|
|
||||||
}
|
|
||||||
|
|
||||||
void Image::unloadVolatile()
|
|
||||||
{
|
|
||||||
if (texture == 0)
|
|
||||||
return;
|
|
||||||
|
|
||||||
gl.deleteTexture(texture);
|
|
||||||
texture = 0;
|
|
||||||
|
|
||||||
setGraphicsMemorySize(0);
|
|
||||||
}
|
|
||||||
|
|
||||||
ptrdiff_t Image::getHandle() const
|
|
||||||
{
|
|
||||||
return texture;
|
|
||||||
}
|
|
||||||
|
|
||||||
void Image::setSamplerState(const SamplerState &s)
|
|
||||||
{
|
|
||||||
Texture::setSamplerState(s);
|
|
||||||
|
|
||||||
if (!OpenGL::hasTextureFilteringSupport(getPixelFormat()))
|
|
||||||
{
|
|
||||||
samplerState.magFilter = samplerState.minFilter = SamplerState::FILTER_NEAREST;
|
|
||||||
|
|
||||||
if (samplerState.mipmapFilter == SamplerState::MIPMAP_FILTER_LINEAR)
|
|
||||||
samplerState.mipmapFilter = SamplerState::MIPMAP_FILTER_NEAREST;
|
|
||||||
}
|
|
||||||
|
|
||||||
// We don't want filtering or (attempted) mipmaps on the default texture.
|
|
||||||
if (usingDefaultTexture)
|
|
||||||
{
|
|
||||||
samplerState.mipmapFilter = SamplerState::MIPMAP_FILTER_NONE;
|
|
||||||
samplerState.minFilter = samplerState.magFilter = SamplerState::FILTER_NEAREST;
|
|
||||||
}
|
|
||||||
|
|
||||||
// If we only have limited NPOT support then the wrap mode must be CLAMP.
|
|
||||||
if ((GLAD_ES_VERSION_2_0 && !(GLAD_ES_VERSION_3_0 || GLAD_OES_texture_npot))
|
|
||||||
&& (pixelWidth != nextP2(pixelWidth) || pixelHeight != nextP2(pixelHeight) || depth != nextP2(depth)))
|
|
||||||
{
|
|
||||||
samplerState.wrapU = samplerState.wrapV = samplerState.wrapW = SamplerState::WRAP_CLAMP;
|
|
||||||
}
|
|
||||||
|
|
||||||
gl.bindTextureToUnit(this, 0, false);
|
|
||||||
gl.setSamplerState(texType, samplerState);
|
|
||||||
}
|
|
||||||
|
|
||||||
} // opengl
|
|
||||||
} // graphics
|
|
||||||
} // love
|
|
||||||
@@ -1,72 +0,0 @@
|
|||||||
/**
|
|
||||||
* Copyright (c) 2006-2020 LOVE Development Team
|
|
||||||
*
|
|
||||||
* This software is provided 'as-is', without any express or implied
|
|
||||||
* warranty. In no event will the authors be held liable for any damages
|
|
||||||
* arising from the use of this software.
|
|
||||||
*
|
|
||||||
* Permission is granted to anyone to use this software for any purpose,
|
|
||||||
* including commercial applications, and to alter it and redistribute it
|
|
||||||
* freely, subject to the following restrictions:
|
|
||||||
*
|
|
||||||
* 1. The origin of this software must not be misrepresented; you must not
|
|
||||||
* claim that you wrote the original software. If you use this software
|
|
||||||
* in a product, an acknowledgment in the product documentation would be
|
|
||||||
* appreciated but is not required.
|
|
||||||
* 2. Altered source versions must be plainly marked as such, and must not be
|
|
||||||
* misrepresented as being the original software.
|
|
||||||
* 3. This notice may not be removed or altered from any source distribution.
|
|
||||||
**/
|
|
||||||
|
|
||||||
#pragma once
|
|
||||||
|
|
||||||
// LOVE
|
|
||||||
#include "graphics/Texture.h"
|
|
||||||
#include "graphics/Volatile.h"
|
|
||||||
|
|
||||||
// OpenGL
|
|
||||||
#include "OpenGL.h"
|
|
||||||
|
|
||||||
namespace love
|
|
||||||
{
|
|
||||||
namespace graphics
|
|
||||||
{
|
|
||||||
namespace opengl
|
|
||||||
{
|
|
||||||
|
|
||||||
class Image final : public love::graphics::Texture, public Volatile
|
|
||||||
{
|
|
||||||
public:
|
|
||||||
|
|
||||||
Image(const Settings &settings, const Slices *data);
|
|
||||||
|
|
||||||
virtual ~Image();
|
|
||||||
|
|
||||||
// Implements Volatile.
|
|
||||||
bool loadVolatile() override;
|
|
||||||
void unloadVolatile() override;
|
|
||||||
|
|
||||||
ptrdiff_t getHandle() const override;
|
|
||||||
ptrdiff_t getRenderTargetHandle() const override { return 0; }
|
|
||||||
|
|
||||||
int getMSAA() const override { return 1; }
|
|
||||||
void setSamplerState(const SamplerState &s) override;
|
|
||||||
void generateMipmaps() override;
|
|
||||||
|
|
||||||
private:
|
|
||||||
|
|
||||||
void uploadByteData(PixelFormat pixelformat, const void *data, size_t size, int level, int slice, const Rect &r, love::image::ImageDataBase *imgd = nullptr) override;
|
|
||||||
|
|
||||||
void loadDefaultTexture();
|
|
||||||
void loadData();
|
|
||||||
|
|
||||||
Slices slices;
|
|
||||||
|
|
||||||
// OpenGL texture identifier.
|
|
||||||
GLuint texture;
|
|
||||||
|
|
||||||
}; // Image
|
|
||||||
|
|
||||||
} // opengl
|
|
||||||
} // graphics
|
|
||||||
} // love
|
|
||||||
@@ -23,7 +23,6 @@
|
|||||||
#include "OpenGL.h"
|
#include "OpenGL.h"
|
||||||
|
|
||||||
#include "Shader.h"
|
#include "Shader.h"
|
||||||
#include "Canvas.h"
|
|
||||||
#include "common/Exception.h"
|
#include "common/Exception.h"
|
||||||
|
|
||||||
#include "graphics/Graphics.h"
|
#include "graphics/Graphics.h"
|
||||||
|
|||||||
@@ -195,7 +195,7 @@ void Shader::mapActiveUniforms()
|
|||||||
|
|
||||||
glUniform1iv(u.location, u.count, u.ints);
|
glUniform1iv(u.location, u.count, u.ints);
|
||||||
|
|
||||||
u.textures = new Texture*[u.count];
|
u.textures = new love::graphics::Texture*[u.count];
|
||||||
memset(u.textures, 0, sizeof(Texture *) * u.count);
|
memset(u.textures, 0, sizeof(Texture *) * u.count);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -564,12 +564,12 @@ void Shader::updateUniform(const UniformInfo *info, int count, bool internalupda
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void Shader::sendTextures(const UniformInfo *info, Texture **textures, int count)
|
void Shader::sendTextures(const UniformInfo *info, love::graphics::Texture **textures, int count)
|
||||||
{
|
{
|
||||||
Shader::sendTextures(info, textures, count, false);
|
Shader::sendTextures(info, textures, count, false);
|
||||||
}
|
}
|
||||||
|
|
||||||
void Shader::sendTextures(const UniformInfo *info, Texture **textures, int count, bool internalUpdate)
|
void Shader::sendTextures(const UniformInfo *info, love::graphics::Texture **textures, int count, bool internalUpdate)
|
||||||
{
|
{
|
||||||
if (info->baseType != UNIFORM_SAMPLER)
|
if (info->baseType != UNIFORM_SAMPLER)
|
||||||
return;
|
return;
|
||||||
@@ -584,7 +584,7 @@ void Shader::sendTextures(const UniformInfo *info, Texture **textures, int count
|
|||||||
// Bind the textures to the texture units.
|
// Bind the textures to the texture units.
|
||||||
for (int i = 0; i < count; i++)
|
for (int i = 0; i < count; i++)
|
||||||
{
|
{
|
||||||
Texture *tex = textures[i];
|
love::graphics::Texture *tex = textures[i];
|
||||||
|
|
||||||
if (tex != nullptr)
|
if (tex != nullptr)
|
||||||
{
|
{
|
||||||
@@ -671,7 +671,7 @@ int Shader::getVertexAttributeIndex(const std::string &name)
|
|||||||
return location;
|
return location;
|
||||||
}
|
}
|
||||||
|
|
||||||
void Shader::setVideoTextures(Texture *ytexture, Texture *cbtexture, Texture *crtexture)
|
void Shader::setVideoTextures(love::graphics::Texture *ytexture, love::graphics::Texture *cbtexture, love::graphics::Texture *crtexture)
|
||||||
{
|
{
|
||||||
const BuiltinUniform builtins[3] = {
|
const BuiltinUniform builtins[3] = {
|
||||||
BUILTIN_TEXTURE_VIDEO_Y,
|
BUILTIN_TEXTURE_VIDEO_Y,
|
||||||
@@ -679,7 +679,7 @@ void Shader::setVideoTextures(Texture *ytexture, Texture *cbtexture, Texture *cr
|
|||||||
BUILTIN_TEXTURE_VIDEO_CR,
|
BUILTIN_TEXTURE_VIDEO_CR,
|
||||||
};
|
};
|
||||||
|
|
||||||
Texture *textures[3] = {ytexture, cbtexture, crtexture};
|
love::graphics::Texture *textures[3] = {ytexture, cbtexture, crtexture};
|
||||||
|
|
||||||
for (int i = 0; i < 3; i++)
|
for (int i = 0; i < 3; i++)
|
||||||
{
|
{
|
||||||
|
|||||||
@@ -61,10 +61,10 @@ public:
|
|||||||
const UniformInfo *getUniformInfo(const std::string &name) const override;
|
const UniformInfo *getUniformInfo(const std::string &name) const override;
|
||||||
const UniformInfo *getUniformInfo(BuiltinUniform builtin) const override;
|
const UniformInfo *getUniformInfo(BuiltinUniform builtin) const override;
|
||||||
void updateUniform(const UniformInfo *info, int count) override;
|
void updateUniform(const UniformInfo *info, int count) override;
|
||||||
void sendTextures(const UniformInfo *info, Texture **textures, int count) override;
|
void sendTextures(const UniformInfo *info, love::graphics::Texture **textures, int count) override;
|
||||||
bool hasUniform(const std::string &name) const override;
|
bool hasUniform(const std::string &name) const override;
|
||||||
ptrdiff_t getHandle() const override;
|
ptrdiff_t getHandle() const override;
|
||||||
void setVideoTextures(Texture *ytexture, Texture *cbtexture, Texture *crtexture) override;
|
void setVideoTextures(love::graphics::Texture *ytexture, love::graphics::Texture *cbtexture, love::graphics::Texture *crtexture) override;
|
||||||
|
|
||||||
void updatePointSize(float size);
|
void updatePointSize(float size);
|
||||||
void updateBuiltinUniforms(love::graphics::Graphics *gfx, int viewportW, int viewportH);
|
void updateBuiltinUniforms(love::graphics::Graphics *gfx, int viewportW, int viewportH);
|
||||||
@@ -82,7 +82,7 @@ private:
|
|||||||
void mapActiveUniforms();
|
void mapActiveUniforms();
|
||||||
|
|
||||||
void updateUniform(const UniformInfo *info, int count, bool internalupdate);
|
void updateUniform(const UniformInfo *info, int count, bool internalupdate);
|
||||||
void sendTextures(const UniformInfo *info, Texture **textures, int count, bool internalupdate);
|
void sendTextures(const UniformInfo *info, love::graphics::Texture **textures, int count, bool internalupdate);
|
||||||
|
|
||||||
int getUniformTypeComponents(GLenum type) const;
|
int getUniformTypeComponents(GLenum type) const;
|
||||||
MatrixSize getMatrixSize(GLenum type) const;
|
MatrixSize getMatrixSize(GLenum type) const;
|
||||||
|
|||||||
+278
-139
@@ -18,11 +18,14 @@
|
|||||||
* 3. This notice may not be removed or altered from any source distribution.
|
* 3. This notice may not be removed or altered from any source distribution.
|
||||||
**/
|
**/
|
||||||
|
|
||||||
#include "Canvas.h"
|
#include "Texture.h"
|
||||||
|
|
||||||
#include "graphics/Graphics.h"
|
#include "graphics/Graphics.h"
|
||||||
#include "Graphics.h"
|
#include "Graphics.h"
|
||||||
|
#include "common/int.h"
|
||||||
|
|
||||||
#include <algorithm> // For min/max
|
// STD
|
||||||
|
#include <algorithm> // for min/max
|
||||||
|
|
||||||
namespace love
|
namespace love
|
||||||
{
|
{
|
||||||
@@ -31,7 +34,7 @@ namespace graphics
|
|||||||
namespace opengl
|
namespace opengl
|
||||||
{
|
{
|
||||||
|
|
||||||
static GLenum createFBO(GLuint &framebuffer, TextureType texType, PixelFormat format, GLuint texture, int layers)
|
static GLenum createFBO(GLuint &framebuffer, TextureType texType, PixelFormat format, GLuint texture, int layers, bool clear)
|
||||||
{
|
{
|
||||||
// get currently bound fbo to reset to it later
|
// get currently bound fbo to reset to it later
|
||||||
GLuint current_fbo = gl.getFramebuffer(OpenGL::FRAMEBUFFER_ALL);
|
GLuint current_fbo = gl.getFramebuffer(OpenGL::FRAMEBUFFER_ALL);
|
||||||
@@ -100,7 +103,7 @@ static GLenum createFBO(GLuint &framebuffer, TextureType texType, PixelFormat fo
|
|||||||
return status;
|
return status;
|
||||||
}
|
}
|
||||||
|
|
||||||
static bool createRenderbuffer(int width, int height, int &samples, PixelFormat pixelformat, GLuint &buffer)
|
static bool newRenderbuffer(int width, int height, int &samples, PixelFormat pixelformat, GLuint &buffer)
|
||||||
{
|
{
|
||||||
int reqsamples = samples;
|
int reqsamples = samples;
|
||||||
bool unusedSRGB = false;
|
bool unusedSRGB = false;
|
||||||
@@ -140,8 +143,6 @@ static bool createRenderbuffer(int width, int height, int &samples, PixelFormat
|
|||||||
|
|
||||||
if (samples > 1)
|
if (samples > 1)
|
||||||
glGetRenderbufferParameteriv(GL_RENDERBUFFER, GL_RENDERBUFFER_SAMPLES, &samples);
|
glGetRenderbufferParameteriv(GL_RENDERBUFFER, GL_RENDERBUFFER_SAMPLES, &samples);
|
||||||
else
|
|
||||||
samples = 0;
|
|
||||||
|
|
||||||
glBindRenderbuffer(GL_RENDERBUFFER, 0);
|
glBindRenderbuffer(GL_RENDERBUFFER, 0);
|
||||||
|
|
||||||
@@ -173,7 +174,7 @@ static bool createRenderbuffer(int width, int height, int &samples, PixelFormat
|
|||||||
{
|
{
|
||||||
glDeleteRenderbuffers(1, &buffer);
|
glDeleteRenderbuffers(1, &buffer);
|
||||||
buffer = 0;
|
buffer = 0;
|
||||||
samples = 0;
|
samples = 1;
|
||||||
}
|
}
|
||||||
|
|
||||||
gl.bindFramebuffer(OpenGL::FRAMEBUFFER_ALL, current_fbo);
|
gl.bindFramebuffer(OpenGL::FRAMEBUFFER_ALL, current_fbo);
|
||||||
@@ -182,110 +183,221 @@ static bool createRenderbuffer(int width, int height, int &samples, PixelFormat
|
|||||||
return status == GL_FRAMEBUFFER_COMPLETE;
|
return status == GL_FRAMEBUFFER_COMPLETE;
|
||||||
}
|
}
|
||||||
|
|
||||||
Canvas::Canvas(const Settings &settings)
|
Texture::Texture(const Settings &settings, const Slices *data)
|
||||||
: love::graphics::Texture(settings, nullptr)
|
: love::graphics::Texture(settings, data)
|
||||||
|
, slices(settings.type)
|
||||||
, fbo(0)
|
, fbo(0)
|
||||||
, texture(0)
|
, texture(0)
|
||||||
, renderbuffer(0)
|
, renderbuffer(0)
|
||||||
, actualSamples(0)
|
, framebufferStatus(GL_FRAMEBUFFER_COMPLETE)
|
||||||
|
, actualSamples(1)
|
||||||
{
|
{
|
||||||
auto gfx = Module::getInstance<Graphics>(Module::M_GRAPHICS);
|
if (data != nullptr)
|
||||||
if (gfx != nullptr)
|
slices = *data;
|
||||||
format = gfx->getSizedFormat(format, renderTarget, readable, sRGB);
|
|
||||||
|
|
||||||
loadVolatile();
|
loadVolatile();
|
||||||
|
|
||||||
if (status != GL_FRAMEBUFFER_COMPLETE)
|
|
||||||
throw love::Exception("Cannot create Canvas: %s", OpenGL::framebufferStatusString(status));
|
|
||||||
}
|
}
|
||||||
|
|
||||||
Canvas::~Canvas()
|
Texture::~Texture()
|
||||||
{
|
{
|
||||||
unloadVolatile();
|
unloadVolatile();
|
||||||
}
|
}
|
||||||
|
|
||||||
bool Canvas::loadVolatile()
|
bool Texture::createTexture()
|
||||||
{
|
{
|
||||||
if (texture != 0)
|
// The base class handles some validation. For example, if ImageData is
|
||||||
return true;
|
// given then it must exist for all mip levels, a render target can't use
|
||||||
|
// a compressed format, etc.
|
||||||
|
|
||||||
OpenGL::TempDebugGroup debuggroup("Canvas load");
|
glGenTextures(1, &texture);
|
||||||
|
gl.bindTextureToUnit(this, 0, false);
|
||||||
|
|
||||||
fbo = texture = 0;
|
// Use a default texture if the size is too big for the system.
|
||||||
renderbuffer = 0;
|
// validateDimensions is also called in the base class for RTs and
|
||||||
status = GL_FRAMEBUFFER_COMPLETE;
|
// non-readable textures.
|
||||||
|
if (!renderTarget && !validateDimensions(false))
|
||||||
// getMaxRenderbufferSamples will be 0 on systems that don't support
|
|
||||||
// multisampled renderbuffers / don't export FBO multisample extensions.
|
|
||||||
actualSamples = std::min(getRequestedMSAA(), gl.getMaxRenderbufferSamples());
|
|
||||||
actualSamples = std::max(actualSamples, 0);
|
|
||||||
actualSamples = actualSamples == 1 ? 0 : actualSamples;
|
|
||||||
|
|
||||||
if (isReadable())
|
|
||||||
{
|
{
|
||||||
glGenTextures(1, &texture);
|
usingDefaultTexture = true;
|
||||||
gl.bindTextureToUnit(this, 0, false);
|
|
||||||
|
|
||||||
GLenum gltype = OpenGL::getGLTextureType(texType);
|
|
||||||
|
|
||||||
if (GLAD_ANGLE_texture_usage)
|
|
||||||
glTexParameteri(gltype, GL_TEXTURE_USAGE_ANGLE, GL_FRAMEBUFFER_ATTACHMENT_ANGLE);
|
|
||||||
|
|
||||||
setSamplerState(samplerState);
|
setSamplerState(samplerState);
|
||||||
|
|
||||||
while (glGetError() != GL_NO_ERROR)
|
bool isSRGB = false;
|
||||||
/* Clear the error buffer. */;
|
gl.rawTexStorage(texType, 1, PIXELFORMAT_RGBA8_UNORM, isSRGB, 2, 2, 1);
|
||||||
|
|
||||||
bool isSRGB = format == PIXELFORMAT_sRGBA8_UNORM;
|
// A nice friendly checkerboard to signify invalid textures...
|
||||||
if (!gl.rawTexStorage(texType, mipmapCount, format, isSRGB, pixelWidth, pixelHeight, texType == TEXTURE_VOLUME ? depth : layers))
|
GLubyte px[] = {0xFF,0xFF,0xFF,0xFF, 0xFF,0xA0,0xA0,0xFF,
|
||||||
{
|
0xFF,0xA0,0xA0,0xFF, 0xFF,0xFF,0xFF,0xFF};
|
||||||
status = GL_FRAMEBUFFER_INCOMPLETE_ATTACHMENT;
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
|
|
||||||
if (glGetError() != GL_NO_ERROR)
|
int slices = texType == TEXTURE_CUBE ? 6 : 1;
|
||||||
{
|
Rect rect = {0, 0, 2, 2};
|
||||||
gl.deleteTexture(texture);
|
for (int slice = 0; slice < slices; slice++)
|
||||||
texture = 0;
|
uploadByteData(PIXELFORMAT_RGBA8_UNORM, px, sizeof(px), 0, slice, rect, nullptr);
|
||||||
status = GL_FRAMEBUFFER_INCOMPLETE_ATTACHMENT;
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
|
|
||||||
// Create a local FBO used for glReadPixels as well as MSAA blitting.
|
return true;
|
||||||
status = createFBO(fbo, texType, format, texture, texType == TEXTURE_VOLUME ? depth : layers);
|
|
||||||
|
|
||||||
if (status != GL_FRAMEBUFFER_COMPLETE)
|
|
||||||
{
|
|
||||||
if (fbo != 0)
|
|
||||||
{
|
|
||||||
gl.deleteFramebuffer(fbo);
|
|
||||||
fbo = 0;
|
|
||||||
}
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!isReadable() || actualSamples > 0)
|
GLenum gltype = OpenGL::getGLTextureType(texType);
|
||||||
createRenderbuffer(pixelWidth, pixelHeight, actualSamples, format, renderbuffer);
|
if (renderTarget && GLAD_ANGLE_texture_usage)
|
||||||
|
glTexParameteri(gltype, GL_TEXTURE_USAGE_ANGLE, GL_FRAMEBUFFER_ATTACHMENT_ANGLE);
|
||||||
|
|
||||||
int64 memsize = getPixelFormatSize(format) * pixelWidth * pixelHeight;
|
setSamplerState(samplerState);
|
||||||
if (getMipmapCount() > 1)
|
|
||||||
memsize *= 1.33334;
|
|
||||||
|
|
||||||
if (actualSamples > 1 && isReadable())
|
int mipcount = getMipmapCount();
|
||||||
memsize += getPixelFormatSize(format) * pixelWidth * pixelHeight * actualSamples;
|
int slicecount = 1;
|
||||||
else if (actualSamples > 1)
|
|
||||||
memsize *= actualSamples;
|
|
||||||
|
|
||||||
setGraphicsMemorySize(memsize);
|
if (texType == TEXTURE_VOLUME)
|
||||||
|
slicecount = getDepth();
|
||||||
|
else if (texType == TEXTURE_2D_ARRAY)
|
||||||
|
slicecount = getLayerCount();
|
||||||
|
else if (texType == TEXTURE_CUBE)
|
||||||
|
slicecount = 6;
|
||||||
|
|
||||||
if (getMipmapCount() > 1)
|
if (!isCompressed())
|
||||||
|
gl.rawTexStorage(texType, mipcount, format, sRGB, pixelWidth, pixelHeight, texType == TEXTURE_VOLUME ? depth : layers);
|
||||||
|
|
||||||
|
int w = pixelWidth;
|
||||||
|
int h = pixelHeight;
|
||||||
|
int d = depth;
|
||||||
|
|
||||||
|
OpenGL::TextureFormat fmt = gl.convertPixelFormat(format, false, sRGB);
|
||||||
|
|
||||||
|
for (int mip = 0; mip < mipcount; mip++)
|
||||||
|
{
|
||||||
|
if (isCompressed() && (texType == TEXTURE_2D_ARRAY || texType == TEXTURE_VOLUME))
|
||||||
|
{
|
||||||
|
size_t mipsize = 0;
|
||||||
|
|
||||||
|
if (texType == TEXTURE_2D_ARRAY || texType == TEXTURE_VOLUME)
|
||||||
|
{
|
||||||
|
for (int slice = 0; slice < slices.getSliceCount(mip); slice++)
|
||||||
|
{
|
||||||
|
auto id = slices.get(slice, mip);
|
||||||
|
if (id != nullptr)
|
||||||
|
mipsize += id->getSize();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
if (mipsize > 0)
|
||||||
|
{
|
||||||
|
GLenum gltarget = OpenGL::getGLTextureType(texType);
|
||||||
|
glCompressedTexImage3D(gltarget, mip, fmt.internalformat, w, h, d, 0, mipsize, nullptr);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
for (int slice = 0; slice < slicecount; slice++)
|
||||||
|
{
|
||||||
|
love::image::ImageDataBase *id = slices.get(slice, mip);
|
||||||
|
if (id != nullptr)
|
||||||
|
uploadImageData(id, mip, slice, 0, 0);
|
||||||
|
}
|
||||||
|
|
||||||
|
w = std::max(w / 2, 1);
|
||||||
|
h = std::max(h / 2, 1);
|
||||||
|
|
||||||
|
if (texType == TEXTURE_VOLUME)
|
||||||
|
d = std::max(d / 2, 1);
|
||||||
|
}
|
||||||
|
|
||||||
|
bool hasdata = slices.get(0, 0) != nullptr;
|
||||||
|
|
||||||
|
// Create a local FBO used for glReadPixels as well as MSAA blitting.
|
||||||
|
if (isRenderTarget())
|
||||||
|
{
|
||||||
|
bool clear = !hasdata;
|
||||||
|
int slices = texType == TEXTURE_VOLUME ? depth : layers;
|
||||||
|
framebufferStatus = createFBO(fbo, texType, format, texture, slices, clear);
|
||||||
|
}
|
||||||
|
else if (!hasdata)
|
||||||
|
{
|
||||||
|
// Initialize all slices to transparent black.
|
||||||
|
std::vector<uint8> emptydata(getPixelFormatSliceSize(format, w, h));
|
||||||
|
|
||||||
|
Rect r = {0, 0, w, h};
|
||||||
|
int slices = texType == TEXTURE_VOLUME ? depth : layers;
|
||||||
|
slices = texType == TEXTURE_CUBE ? 6 : slices;
|
||||||
|
for (int i = 0; i < slices; i++)
|
||||||
|
uploadByteData(format, emptydata.data(), emptydata.size(), 0, i, r);
|
||||||
|
}
|
||||||
|
|
||||||
|
// Non-readable textures can't have mipmaps (enforced in the base class),
|
||||||
|
// so generateMipmaps here is fine - when they aren't already initialized.
|
||||||
|
if (getMipmapCount() > 1 && slices.getMipmapCount() <= 1)
|
||||||
generateMipmaps();
|
generateMipmaps();
|
||||||
|
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
void Canvas::unloadVolatile()
|
bool Texture::createRenderbuffer()
|
||||||
|
{
|
||||||
|
if (isReadable() && actualSamples <= 1)
|
||||||
|
return true;
|
||||||
|
|
||||||
|
return newRenderbuffer(pixelWidth, pixelHeight, actualSamples, format, renderbuffer);
|
||||||
|
}
|
||||||
|
|
||||||
|
bool Texture::loadVolatile()
|
||||||
|
{
|
||||||
|
if (texture != 0 || renderbuffer != 0)
|
||||||
|
return true;
|
||||||
|
|
||||||
|
OpenGL::TempDebugGroup debuggroup("Texture load");
|
||||||
|
|
||||||
|
// NPOT textures don't support mipmapping without full NPOT support.
|
||||||
|
if ((GLAD_ES_VERSION_2_0 && !(GLAD_ES_VERSION_3_0 || GLAD_OES_texture_npot))
|
||||||
|
&& (pixelWidth != nextP2(pixelWidth) || pixelHeight != nextP2(pixelHeight)))
|
||||||
|
{
|
||||||
|
mipmapCount = 1;
|
||||||
|
samplerState.mipmapFilter = SamplerState::MIPMAP_FILTER_NONE;
|
||||||
|
}
|
||||||
|
|
||||||
|
// getMaxRenderbufferSamples will be 0 on systems that don't support
|
||||||
|
// multisampled renderbuffers / don't export FBO multisample extensions.
|
||||||
|
actualSamples = std::min(getRequestedMSAA(), gl.getMaxRenderbufferSamples());
|
||||||
|
actualSamples = std::max(actualSamples, 1);
|
||||||
|
|
||||||
|
while (glGetError() != GL_NO_ERROR); // Clear errors.
|
||||||
|
|
||||||
|
try
|
||||||
|
{
|
||||||
|
if (isReadable())
|
||||||
|
createTexture();
|
||||||
|
if (!isReadable() && actualSamples > 1)
|
||||||
|
createRenderbuffer();
|
||||||
|
|
||||||
|
GLenum glerr = glGetError();
|
||||||
|
if (glerr != GL_NO_ERROR)
|
||||||
|
throw love::Exception("Cannot create texture (OpenGL error: %s)", OpenGL::errorString(glerr));
|
||||||
|
}
|
||||||
|
catch (love::Exception &)
|
||||||
|
{
|
||||||
|
unloadVolatile();
|
||||||
|
throw;
|
||||||
|
}
|
||||||
|
|
||||||
|
int64 memsize = 0;
|
||||||
|
|
||||||
|
for (int mip = 0; mip < getMipmapCount(); mip++)
|
||||||
|
{
|
||||||
|
int w = getPixelWidth(mip);
|
||||||
|
int h = getPixelHeight(mip);
|
||||||
|
int slices = getDepth(mip) * layers * (texType == TEXTURE_CUBE ? 6 : 1);
|
||||||
|
memsize += getPixelFormatSliceSize(format, w, h) * slices;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (actualSamples > 1 && isReadable())
|
||||||
|
{
|
||||||
|
int slices = depth * layers * (texType == TEXTURE_CUBE ? 6 : 1);
|
||||||
|
memsize += getPixelFormatSliceSize(format, pixelWidth, pixelHeight) * slices * actualSamples;
|
||||||
|
}
|
||||||
|
else if (actualSamples > 1)
|
||||||
|
memsize *= actualSamples;
|
||||||
|
|
||||||
|
setGraphicsMemorySize(memsize);
|
||||||
|
|
||||||
|
usingDefaultTexture = false;
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
void Texture::unloadVolatile()
|
||||||
{
|
{
|
||||||
if (isRenderTarget() && (fbo != 0 || renderbuffer != 0 || texture != 0))
|
if (isRenderTarget() && (fbo != 0 || renderbuffer != 0 || texture != 0))
|
||||||
{
|
{
|
||||||
@@ -312,41 +424,73 @@ void Canvas::unloadVolatile()
|
|||||||
setGraphicsMemorySize(0);
|
setGraphicsMemorySize(0);
|
||||||
}
|
}
|
||||||
|
|
||||||
void Canvas::setSamplerState(const SamplerState &s)
|
void Texture::uploadByteData(PixelFormat pixelformat, const void *data, size_t size, int level, int slice, const Rect &r, love::image::ImageDataBase *imgd)
|
||||||
{
|
{
|
||||||
Texture::setSamplerState(s);
|
love::image::ImageDataBase *oldd = slices.get(slice, level);
|
||||||
|
|
||||||
if (samplerState.depthSampleMode.hasValue && !gl.isDepthCompareSampleSupported())
|
// We can only replace the internal Data (used when reloading due to setMode)
|
||||||
throw love::Exception("Depth comparison sampling in shaders is not supported on this system.");
|
// if the dimensions match.
|
||||||
|
if (imgd != nullptr && oldd != nullptr && oldd->getWidth() == imgd->getWidth()
|
||||||
if (!OpenGL::hasTextureFilteringSupport(getPixelFormat()))
|
&& oldd->getHeight() == imgd->getHeight())
|
||||||
{
|
{
|
||||||
samplerState.magFilter = samplerState.minFilter = SamplerState::FILTER_NEAREST;
|
slices.set(slice, level, imgd);
|
||||||
|
|
||||||
if (samplerState.mipmapFilter == SamplerState::MIPMAP_FILTER_LINEAR)
|
|
||||||
samplerState.mipmapFilter = SamplerState::MIPMAP_FILTER_NEAREST;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// If we only have limited NPOT support then the wrap mode must be CLAMP.
|
OpenGL::TempDebugGroup debuggroup("Texture data upload");
|
||||||
if ((GLAD_ES_VERSION_2_0 && !(GLAD_ES_VERSION_3_0 || GLAD_OES_texture_npot))
|
|
||||||
&& (pixelWidth != nextP2(pixelWidth) || pixelHeight != nextP2(pixelHeight) || depth != nextP2(depth)))
|
|
||||||
{
|
|
||||||
samplerState.wrapU = samplerState.wrapV = samplerState.wrapW = SamplerState::WRAP_CLAMP;
|
|
||||||
}
|
|
||||||
|
|
||||||
gl.bindTextureToUnit(this, 0, false);
|
gl.bindTextureToUnit(this, 0, false);
|
||||||
gl.setSamplerState(texType, samplerState);
|
|
||||||
|
OpenGL::TextureFormat fmt = OpenGL::convertPixelFormat(pixelformat, false, sRGB);
|
||||||
|
GLenum gltarget = OpenGL::getGLTextureType(texType);
|
||||||
|
|
||||||
|
if (texType == TEXTURE_CUBE)
|
||||||
|
gltarget = GL_TEXTURE_CUBE_MAP_POSITIVE_X + slice;
|
||||||
|
|
||||||
|
if (isPixelFormatCompressed(pixelformat))
|
||||||
|
{
|
||||||
|
if (r.x != 0 || r.y != 0)
|
||||||
|
throw love::Exception("x and y parameters must be 0 for compressed textures.");
|
||||||
|
|
||||||
|
if (texType == TEXTURE_2D || texType == TEXTURE_CUBE)
|
||||||
|
glCompressedTexImage2D(gltarget, level, fmt.internalformat, r.w, r.h, 0, size, data);
|
||||||
|
else if (texType == TEXTURE_2D_ARRAY || texType == TEXTURE_VOLUME)
|
||||||
|
glCompressedTexSubImage3D(gltarget, level, 0, 0, slice, r.w, r.h, 1, fmt.internalformat, size, data);
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
if (texType == TEXTURE_2D || texType == TEXTURE_CUBE)
|
||||||
|
glTexSubImage2D(gltarget, level, r.x, r.y, r.w, r.h, fmt.externalformat, fmt.type, data);
|
||||||
|
else if (texType == TEXTURE_2D_ARRAY || texType == TEXTURE_VOLUME)
|
||||||
|
glTexSubImage3D(gltarget, level, r.x, r.y, slice, r.w, r.h, 1, fmt.externalformat, fmt.type, data);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
ptrdiff_t Canvas::getHandle() const
|
void Texture::generateMipmaps()
|
||||||
{
|
{
|
||||||
return texture;
|
if (getMipmapCount() == 1 || getMipmapsMode() == MIPMAPS_NONE)
|
||||||
|
throw love::Exception("generateMipmaps can only be called on a Texture which was created with mipmaps enabled.");
|
||||||
|
|
||||||
|
if (isPixelFormatCompressed(format))
|
||||||
|
throw love::Exception("generateMipmaps cannot be called on a compressed Texture.");
|
||||||
|
|
||||||
|
gl.bindTextureToUnit(this, 0, false);
|
||||||
|
|
||||||
|
GLenum gltextype = OpenGL::getGLTextureType(texType);
|
||||||
|
|
||||||
|
if (gl.bugs.generateMipmapsRequiresTexture2DEnable)
|
||||||
|
glEnable(gltextype);
|
||||||
|
|
||||||
|
glGenerateMipmap(gltextype);
|
||||||
}
|
}
|
||||||
|
|
||||||
love::image::ImageData *Canvas::newImageData(love::image::Image *module, int slice, int mipmap, const Rect &r)
|
love::image::ImageData *Texture::newImageData(love::image::Image *module, int slice, int mipmap, const Rect &r)
|
||||||
{
|
{
|
||||||
|
// Base class does validation (only RTs allowed, etc) and creates ImageData.
|
||||||
love::image::ImageData *data = love::graphics::Texture::newImageData(module, slice, mipmap, r);
|
love::image::ImageData *data = love::graphics::Texture::newImageData(module, slice, mipmap, r);
|
||||||
|
|
||||||
|
if (fbo == 0) // Should never be reached.
|
||||||
|
return data;
|
||||||
|
|
||||||
bool isSRGB = false;
|
bool isSRGB = false;
|
||||||
OpenGL::TextureFormat fmt = gl.convertPixelFormat(data->getFormat(), false, isSRGB);
|
OpenGL::TextureFormat fmt = gl.convertPixelFormat(data->getFormat(), false, isSRGB);
|
||||||
|
|
||||||
@@ -370,53 +514,48 @@ love::image::ImageData *Canvas::newImageData(love::image::Image *module, int sli
|
|||||||
return data;
|
return data;
|
||||||
}
|
}
|
||||||
|
|
||||||
void Canvas::generateMipmaps()
|
void Texture::setSamplerState(const SamplerState &s)
|
||||||
{
|
{
|
||||||
if (getMipmapCount() == 1 || getMipmapsMode() == MIPMAPS_NONE)
|
if (samplerState.depthSampleMode.hasValue && !gl.isDepthCompareSampleSupported())
|
||||||
throw love::Exception("generateMipmaps can only be called on a Texture which was created with mipmaps enabled.");
|
throw love::Exception("Depth comparison sampling in shaders is not supported on this system.");
|
||||||
|
|
||||||
if (isPixelFormatCompressed(format))
|
// Base class does common validation and assigns samplerState.
|
||||||
throw love::Exception("generateMipmaps cannot be called on a compressed Texture.");
|
love::graphics::Texture::setSamplerState(s);
|
||||||
|
|
||||||
|
if (!OpenGL::hasTextureFilteringSupport(getPixelFormat()))
|
||||||
|
{
|
||||||
|
samplerState.magFilter = samplerState.minFilter = SamplerState::FILTER_NEAREST;
|
||||||
|
|
||||||
|
if (samplerState.mipmapFilter == SamplerState::MIPMAP_FILTER_LINEAR)
|
||||||
|
samplerState.mipmapFilter = SamplerState::MIPMAP_FILTER_NEAREST;
|
||||||
|
}
|
||||||
|
|
||||||
|
// We don't want filtering or (attempted) mipmaps on the default texture.
|
||||||
|
if (usingDefaultTexture)
|
||||||
|
{
|
||||||
|
samplerState.mipmapFilter = SamplerState::MIPMAP_FILTER_NONE;
|
||||||
|
samplerState.minFilter = samplerState.magFilter = SamplerState::FILTER_NEAREST;
|
||||||
|
}
|
||||||
|
|
||||||
|
// If we only have limited NPOT support then the wrap mode must be CLAMP.
|
||||||
|
if ((GLAD_ES_VERSION_2_0 && !(GLAD_ES_VERSION_3_0 || GLAD_OES_texture_npot))
|
||||||
|
&& (pixelWidth != nextP2(pixelWidth) || pixelHeight != nextP2(pixelHeight) || depth != nextP2(depth)))
|
||||||
|
{
|
||||||
|
samplerState.wrapU = samplerState.wrapV = samplerState.wrapW = SamplerState::WRAP_CLAMP;
|
||||||
|
}
|
||||||
|
|
||||||
gl.bindTextureToUnit(this, 0, false);
|
gl.bindTextureToUnit(this, 0, false);
|
||||||
|
gl.setSamplerState(texType, samplerState);
|
||||||
GLenum gltextype = OpenGL::getGLTextureType(texType);
|
|
||||||
|
|
||||||
if (gl.bugs.generateMipmapsRequiresTexture2DEnable)
|
|
||||||
glEnable(gltextype);
|
|
||||||
|
|
||||||
glGenerateMipmap(gltextype);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void Canvas::uploadByteData(PixelFormat pixelformat, const void *data, size_t size, int level, int slice, const Rect &r, love::image::ImageDataBase */*imgd*/)
|
ptrdiff_t Texture::getHandle() const
|
||||||
{
|
{
|
||||||
OpenGL::TempDebugGroup debuggroup("Texture data upload");
|
return texture;
|
||||||
|
}
|
||||||
|
|
||||||
gl.bindTextureToUnit(this, 0, false);
|
ptrdiff_t Texture::getRenderTargetHandle() const
|
||||||
|
{
|
||||||
OpenGL::TextureFormat fmt = OpenGL::convertPixelFormat(pixelformat, false, sRGB);
|
return renderTarget ? (renderbuffer != 0 ? renderbuffer : texture) : 0;
|
||||||
GLenum gltarget = OpenGL::getGLTextureType(texType);
|
|
||||||
|
|
||||||
if (texType == TEXTURE_CUBE)
|
|
||||||
gltarget = GL_TEXTURE_CUBE_MAP_POSITIVE_X + slice;
|
|
||||||
|
|
||||||
if (isPixelFormatCompressed(pixelformat))
|
|
||||||
{
|
|
||||||
if (r.x != 0 || r.y != 0)
|
|
||||||
throw love::Exception("x and y parameters must be 0 for compressed images.");
|
|
||||||
|
|
||||||
if (texType == TEXTURE_2D || texType == TEXTURE_CUBE)
|
|
||||||
glCompressedTexImage2D(gltarget, level, fmt.internalformat, r.w, r.h, 0, size, data);
|
|
||||||
else if (texType == TEXTURE_2D_ARRAY || texType == TEXTURE_VOLUME)
|
|
||||||
glCompressedTexSubImage3D(gltarget, level, 0, 0, slice, r.w, r.h, 1, fmt.internalformat, size, data);
|
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
if (texType == TEXTURE_2D || texType == TEXTURE_CUBE)
|
|
||||||
glTexSubImage2D(gltarget, level, r.x, r.y, r.w, r.h, fmt.externalformat, fmt.type, data);
|
|
||||||
else if (texType == TEXTURE_2D_ARRAY || texType == TEXTURE_VOLUME)
|
|
||||||
glTexSubImage3D(gltarget, level, r.x, r.y, slice, r.w, r.h, 1, fmt.externalformat, fmt.type, data);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
} // opengl
|
} // opengl
|
||||||
@@ -18,14 +18,13 @@
|
|||||||
* 3. This notice may not be removed or altered from any source distribution.
|
* 3. This notice may not be removed or altered from any source distribution.
|
||||||
**/
|
**/
|
||||||
|
|
||||||
#ifndef LOVE_GRAPHICS_OPENGL_CANVAS_H
|
#pragma once
|
||||||
#define LOVE_GRAPHICS_OPENGL_CANVAS_H
|
|
||||||
|
|
||||||
#include "common/config.h"
|
// LOVE
|
||||||
#include "common/Color.h"
|
|
||||||
#include "common/int.h"
|
|
||||||
#include "graphics/Texture.h"
|
#include "graphics/Texture.h"
|
||||||
#include "graphics/Volatile.h"
|
#include "graphics/Volatile.h"
|
||||||
|
|
||||||
|
// OpenGL
|
||||||
#include "OpenGL.h"
|
#include "OpenGL.h"
|
||||||
|
|
||||||
namespace love
|
namespace love
|
||||||
@@ -35,56 +34,48 @@ namespace graphics
|
|||||||
namespace opengl
|
namespace opengl
|
||||||
{
|
{
|
||||||
|
|
||||||
class Canvas final : public love::graphics::Texture, public Volatile
|
class Texture final : public love::graphics::Texture, public Volatile
|
||||||
{
|
{
|
||||||
public:
|
public:
|
||||||
|
|
||||||
Canvas(const Settings &settings);
|
Texture(const Settings &settings, const Slices *data);
|
||||||
virtual ~Canvas();
|
|
||||||
|
virtual ~Texture();
|
||||||
|
|
||||||
// Implements Volatile.
|
// Implements Volatile.
|
||||||
bool loadVolatile() override;
|
bool loadVolatile() override;
|
||||||
void unloadVolatile() override;
|
void unloadVolatile() override;
|
||||||
|
|
||||||
// Implements Texture.
|
|
||||||
void setSamplerState(const SamplerState &s) override;
|
|
||||||
ptrdiff_t getHandle() const override;
|
|
||||||
|
|
||||||
love::image::ImageData *newImageData(love::image::Image *module, int slice, int mipmap, const Rect &rect) override;
|
|
||||||
void generateMipmaps() override;
|
void generateMipmaps() override;
|
||||||
|
love::image::ImageData *newImageData(love::image::Image *module, int slice, int mipmap, const Rect &rect) override;
|
||||||
|
void setSamplerState(const SamplerState &s) override;
|
||||||
|
|
||||||
int getMSAA() const override
|
ptrdiff_t getHandle() const override;
|
||||||
{
|
ptrdiff_t getRenderTargetHandle() const override;
|
||||||
return actualSamples;
|
int getMSAA() const override { return actualSamples; }
|
||||||
}
|
|
||||||
|
|
||||||
ptrdiff_t getRenderTargetHandle() const override
|
inline GLuint getFBO() const { return fbo; }
|
||||||
{
|
|
||||||
return renderbuffer != 0 ? renderbuffer : texture;
|
|
||||||
}
|
|
||||||
|
|
||||||
inline GLuint getFBO() const
|
|
||||||
{
|
|
||||||
return fbo;
|
|
||||||
}
|
|
||||||
|
|
||||||
private:
|
private:
|
||||||
|
|
||||||
|
bool createTexture();
|
||||||
|
bool createRenderbuffer();
|
||||||
|
|
||||||
void uploadByteData(PixelFormat pixelformat, const void *data, size_t size, int level, int slice, const Rect &r, love::image::ImageDataBase *imgd = nullptr) override;
|
void uploadByteData(PixelFormat pixelformat, const void *data, size_t size, int level, int slice, const Rect &r, love::image::ImageDataBase *imgd = nullptr) override;
|
||||||
|
|
||||||
|
Slices slices;
|
||||||
|
|
||||||
GLuint fbo;
|
GLuint fbo;
|
||||||
|
|
||||||
GLuint texture;
|
GLuint texture;
|
||||||
GLuint renderbuffer;
|
GLuint renderbuffer;
|
||||||
|
|
||||||
GLenum status;
|
GLenum framebufferStatus;
|
||||||
|
|
||||||
int actualSamples;
|
int actualSamples;
|
||||||
|
|
||||||
}; // Canvas
|
}; // Texture
|
||||||
|
|
||||||
} // opengl
|
} // opengl
|
||||||
} // graphics
|
} // graphics
|
||||||
} // love
|
} // love
|
||||||
|
|
||||||
#endif // LOVE_GRAPHICS_OPENGL_CANVAS_H
|
|
||||||
@@ -84,7 +84,7 @@ love::image::ImageData *ImageData::clone() const
|
|||||||
|
|
||||||
void ImageData::create(int width, int height, PixelFormat format, void *data)
|
void ImageData::create(int width, int height, PixelFormat format, void *data)
|
||||||
{
|
{
|
||||||
size_t datasize = width * height * getPixelFormatSize(format);
|
size_t datasize = getPixelFormatSliceSize(format, width, height);
|
||||||
|
|
||||||
try
|
try
|
||||||
{
|
{
|
||||||
@@ -140,7 +140,7 @@ void ImageData::decode(Data *data)
|
|||||||
throw love::Exception("Could not decode data to ImageData: unsupported encoded format");
|
throw love::Exception("Could not decode data to ImageData: unsupported encoded format");
|
||||||
}
|
}
|
||||||
|
|
||||||
if (decodedimage.size != decodedimage.width * decodedimage.height * getPixelFormatSize(decodedimage.format))
|
if (decodedimage.size != getPixelFormatSliceSize(decodedimage.format, decodedimage.width, decodedimage.height))
|
||||||
{
|
{
|
||||||
decoder->freeRawPixels(decodedimage.data);
|
decoder->freeRawPixels(decodedimage.data);
|
||||||
throw love::Exception("Could not convert image!");
|
throw love::Exception("Could not convert image!");
|
||||||
@@ -782,7 +782,7 @@ love::thread::Mutex *ImageData::getMutex() const
|
|||||||
|
|
||||||
size_t ImageData::getPixelSize() const
|
size_t ImageData::getPixelSize() const
|
||||||
{
|
{
|
||||||
return getPixelFormatSize(format);
|
return getPixelFormatBlockSize(format);
|
||||||
}
|
}
|
||||||
|
|
||||||
bool ImageData::validPixelFormat(PixelFormat format)
|
bool ImageData::validPixelFormat(PixelFormat format)
|
||||||
|
|||||||
@@ -193,7 +193,7 @@ FormatHandler::DecodedImage EXRHandler::decode(Data *data)
|
|||||||
throw love::Exception("Could not decode EXR image: unknown pixel format.");
|
throw love::Exception("Could not decode EXR image: unknown pixel format.");
|
||||||
}
|
}
|
||||||
|
|
||||||
img.size = img.width * img.height * getPixelFormatSize(img.format);
|
img.size = getPixelFormatSliceSize(img.format, img.width, img.height);
|
||||||
|
|
||||||
FreeEXRImage(&exrImage);
|
FreeEXRImage(&exrImage);
|
||||||
|
|
||||||
|
|||||||
@@ -933,7 +933,7 @@ bool Window::setIcon(love::image::ImageData *imgd)
|
|||||||
|
|
||||||
int w = imgd->getWidth();
|
int w = imgd->getWidth();
|
||||||
int h = imgd->getHeight();
|
int h = imgd->getHeight();
|
||||||
int bytesperpixel = (int) getPixelFormatSize(imgd->getFormat());
|
int bytesperpixel = (int) getPixelFormatBlockSize(imgd->getFormat());
|
||||||
int pitch = w * bytesperpixel;
|
int pitch = w * bytesperpixel;
|
||||||
|
|
||||||
SDL_Surface *sdlicon = nullptr;
|
SDL_Surface *sdlicon = nullptr;
|
||||||
|
|||||||
Reference in New Issue
Block a user