graphics: handle default textures in high level code.

Previously each backend had to set up default textures with its own code, which needs some care for it to be robust.
This commit is contained in:
Sasha Szpakowski
2023-12-27 21:28:02 +01:00
parent e42019c59e
commit 8872497561
15 changed files with 167 additions and 189 deletions
-22
View File
@@ -281,7 +281,6 @@ Graphics::Graphics()
, renderBindings()
, uniformBufferOffset(0)
, defaultAttributesBuffer(nullptr)
, defaultTextures()
, families()
{ @autoreleasepool {
if (@available(macOS 10.15, iOS 13.0, *))
@@ -346,17 +345,6 @@ Graphics::Graphics()
defaultAttributesBuffer = newBuffer(attribsettings, dataformat, &defaults, sizeof(DefaultVertexAttributes), 0);
}
uint8 defaultpixel[] = {255, 255, 255, 255};
for (int i = 0; i < TEXTURE_MAX_ENUM; i++)
{
Texture::Settings settings;
settings.type = (TextureType) i;
settings.format = PIXELFORMAT_RGBA8_UNORM;
defaultTextures[i] = newTexture(settings);
Rect r = {0, 0, 1, 1};
defaultTextures[i]->replacePixels(defaultpixel, sizeof(defaultpixel), 0, 0, r, false);
}
if (batchedDrawState.vb[0] == nullptr)
{
// Initial sizes that should be good enough for most cases. It will
@@ -426,9 +414,6 @@ Graphics::~Graphics()
commandQueue = nil;
device = nil;
for (int i = 0; i < TEXTURE_MAX_ENUM; i++)
defaultTextures[i]->release();
for (auto &kvp : cachedSamplers)
CFBridgingRelease(kvp.second);
@@ -1144,13 +1129,6 @@ void Graphics::applyShaderUniforms(id<MTLRenderCommandEncoder> renderEncoder, lo
if (b.isMainTexture)
{
if (maintex == nullptr)
{
auto texinfo = shader->getMainTextureInfo();
if (texinfo != nullptr && texinfo->textureType != TEXTURE_MAX_ENUM)
maintex = defaultTextures[texinfo->textureType];
}
texture = getMTLTexture(maintex);
samplertex = maintex;
}