Correct and revise OpenGL texture pooling (#2709)
This commit is contained in:
@@ -76,12 +76,12 @@ std::unique_ptr<gfx::TextureResource> UploadPass::createTextureResource(const Si
|
||||
const void* data,
|
||||
gfx::TexturePixelType format,
|
||||
gfx::TextureChannelDataType type) {
|
||||
auto obj = commandEncoder.context.createUniqueTexture();
|
||||
const int textureByteSize = gl::TextureResource::getStorageSize(size, format, type);
|
||||
commandEncoder.context.renderingStats().memTextures += textureByteSize;
|
||||
auto resource = std::make_unique<gl::TextureResource>(std::move(obj), textureByteSize);
|
||||
MLN_TRACE_FUNC();
|
||||
|
||||
auto obj = commandEncoder.context.createUniqueTexture(size, format, type);
|
||||
auto resource = std::make_unique<gl::TextureResource>(std::move(obj));
|
||||
commandEncoder.context.pixelStoreUnpack = {1};
|
||||
updateTextureResource(*resource, size, data, format, type);
|
||||
updateTextureResourceSub(*resource, 0, 0, size, data, format, type);
|
||||
// We are using clamp to edge here since OpenGL ES doesn't allow GL_REPEAT
|
||||
// on NPOT textures. We use those when the pixelRatio isn't a power of two,
|
||||
// e.g. on iPhone 6 Plus.
|
||||
@@ -97,18 +97,9 @@ void UploadPass::updateTextureResource(gfx::TextureResource& resource,
|
||||
const void* data,
|
||||
gfx::TexturePixelType format,
|
||||
gfx::TextureChannelDataType type) {
|
||||
// Always use texture unit 0 for manipulating it.
|
||||
commandEncoder.context.activeTextureUnit = 0;
|
||||
commandEncoder.context.texture[0] = static_cast<gl::TextureResource&>(resource).texture;
|
||||
MBGL_CHECK_ERROR(glTexImage2D(GL_TEXTURE_2D,
|
||||
0,
|
||||
Enum<gfx::TexturePixelType>::to(format),
|
||||
size.width,
|
||||
size.height,
|
||||
0,
|
||||
Enum<gfx::TexturePixelType>::to(format),
|
||||
Enum<gfx::TextureChannelDataType>::to(type),
|
||||
data));
|
||||
MLN_TRACE_FUNC();
|
||||
|
||||
updateTextureResourceSub(resource, 0, 0, size, data, format, type);
|
||||
}
|
||||
|
||||
void UploadPass::updateTextureResourceSub(gfx::TextureResource& resource,
|
||||
@@ -118,9 +109,20 @@ void UploadPass::updateTextureResourceSub(gfx::TextureResource& resource,
|
||||
const void* data,
|
||||
gfx::TexturePixelType format,
|
||||
gfx::TextureChannelDataType type) {
|
||||
MLN_TRACE_FUNC();
|
||||
|
||||
auto& ctx = commandEncoder.context;
|
||||
assert(ctx.getTexturePool().isUsed(static_cast<gl::TextureResource&>(resource).texture));
|
||||
assert(ctx.getTexturePool().desc(static_cast<gl::TextureResource&>(resource).texture).channelType == type);
|
||||
assert(ctx.getTexturePool().desc(static_cast<gl::TextureResource&>(resource).texture).pixelFormat == format);
|
||||
assert(ctx.getTexturePool().desc(static_cast<gl::TextureResource&>(resource).texture).size.width >=
|
||||
xOffset + size.width);
|
||||
assert(ctx.getTexturePool().desc(static_cast<gl::TextureResource&>(resource).texture).size.height >=
|
||||
yOffset + size.height);
|
||||
|
||||
// Always use texture unit 0 for manipulating it.
|
||||
commandEncoder.context.activeTextureUnit = 0;
|
||||
commandEncoder.context.texture[0] = static_cast<const gl::TextureResource&>(resource).texture;
|
||||
ctx.activeTextureUnit = 0;
|
||||
ctx.texture[0] = static_cast<const gl::TextureResource&>(resource).texture;
|
||||
MBGL_CHECK_ERROR(glTexSubImage2D(GL_TEXTURE_2D,
|
||||
0,
|
||||
xOffset,
|
||||
|
||||
Reference in New Issue
Block a user