Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion Apps/Playground/Scripts/validation_native.js
Original file line number Diff line number Diff line change
Expand Up @@ -131,7 +131,7 @@
done(false);
}
});
});
}, true);
}

function loadPlayground(test, done, referenceImage, compareFunction) {
Expand Down
21 changes: 20 additions & 1 deletion Core/Graphics/Source/Texture.cpp
Original file line number Diff line number Diff line change
@@ -1,6 +1,22 @@
#include "Texture.h"
#include "DeviceContext.h"
#include <cassert>
#include <bimg/bimg.h>

namespace
{
const bgfx::Memory* GetZeroImageMemory(uint16_t width, uint16_t height, bool hasMips, uint16_t numLayers, bgfx::TextureFormat::Enum format)
{
bgfx::ReleaseFn releaseFn{[](void*, void* userData) {
bimg::imageFree(static_cast<bimg::ImageContainer*>(userData));
}};

bimg::ImageContainer* image = bimg::imageAlloc(&Babylon::Graphics::DeviceContext::GetDefaultAllocator(), static_cast<bimg::TextureFormat::Enum>(format), width, height, 1/*depth*/, numLayers, false/*cubeMap*/, hasMips);
const bgfx::Memory* mem = bgfx::makeRef(image->m_data, image->m_size, releaseFn, image);
bx::memSet(image->m_data, 0, image->m_size);
return mem;
}
}

namespace Babylon::Graphics
{
Expand Down Expand Up @@ -34,8 +50,11 @@ namespace Babylon::Graphics
{
Dispose();

// make sure render targets are filled with 0 : https://registry.khronos.org/webgl/specs/latest/1.0/#TEXIMAGE2D
const auto* mem = (flags & BGFX_TEXTURE_RT) ? GetZeroImageMemory(width, height, hasMips, numLayers, format) : nullptr;

// Always create with BGFX_TEXTURE_BLIT_DST to match web behavior.
m_handle = bgfx::createTexture2D(width, height, hasMips, numLayers, format, flags | BGFX_TEXTURE_BLIT_DST);
m_handle = bgfx::createTexture2D(width, height, hasMips, numLayers, format, flags | BGFX_TEXTURE_BLIT_DST, mem);
if (!bgfx::isValid(m_handle))
{
throw std::runtime_error{"Failed to create texture"};
Expand Down
11 changes: 10 additions & 1 deletion Polyfills/Canvas/Source/Canvas.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -114,8 +114,17 @@ namespace Babylon::Polyfills::Internal
{
if (m_dirty)
{
// make sure render targets are filled with 0 : https://registry.khronos.org/webgl/specs/latest/1.0/#TEXIMAGE2D
bgfx::ReleaseFn releaseFn{ [](void*, void* userData) {
bimg::imageFree(static_cast<bimg::ImageContainer*>(userData));
}};

bimg::ImageContainer* image = bimg::imageAlloc(&Babylon::Graphics::DeviceContext::GetDefaultAllocator(), bimg::TextureFormat::RGBA8, m_width, m_height, 1/*depth*/, 1, false/*cubeMap*/, false/*hasMips*/);
const bgfx::Memory* mem = bgfx::makeRef(image->m_data, image->m_size, releaseFn, image);
bx::memSet(image->m_data, 0, image->m_size);

std::array<bgfx::TextureHandle, 2> textures{
bgfx::createTexture2D(m_width, m_height, false, 1, bgfx::TextureFormat::RGBA8, BGFX_TEXTURE_RT),
bgfx::createTexture2D(m_width, m_height, false, 1, bgfx::TextureFormat::RGBA8, BGFX_TEXTURE_RT, mem),
bgfx::createTexture2D(m_width, m_height, false, 1, bgfx::TextureFormat::D24S8, BGFX_TEXTURE_RT)};

std::array<bgfx::Attachment, textures.size()> attachments{};
Expand Down
Loading