Skip to content

Commit

Permalink
Populate glInternalFormat when creating OpenGL texture as externally …
Browse files Browse the repository at this point in the history
…managed (#171)

Summary:
Pull Request resolved: #171

If creating `TextureBuffer` via `createTextureBufferExternal`, the `glInternalFormat_` wasn't correctly populated (remaining at 0), violating the internal consistency of the corresponding Texture object.

When tried to be used later by a client with OpenGL ES backend, this would assert in `getGLInternalTextureFormat` because of that.

This diff correspondingly makes sure that if we use ` createTextureBufferExternal` then `glInternalFormat_` is set to whatever value corresponds to that externally managed texture.

Reviewed By: christophpurrer

Differential Revision: D61905498

fbshipit-source-id: 44588677a0168054371382a6ca9ce4528158b8dd
  • Loading branch information
rshest authored and facebook-github-bot committed Aug 28, 2024
1 parent fdc586d commit fa1618b
Show file tree
Hide file tree
Showing 3 changed files with 26 additions and 4 deletions.
3 changes: 1 addition & 2 deletions src/igl/opengl/PlatformDevice.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -43,9 +43,8 @@ std::unique_ptr<TextureBufferExternal> PlatformDevice::createTextureBufferExtern
GLsizei height,
TextureFormat format,
GLsizei numLayers) const {
auto textureBuffer = std::make_unique<TextureBufferExternal>(getContext(), format);
auto textureBuffer = std::make_unique<TextureBufferExternal>(getContext(), format, usage);
textureBuffer->setTextureBufferProperties(textureID, target);
textureBuffer->setUsage(usage);
textureBuffer->setTextureProperties(width, height, numLayers);
if (auto resourceTracker = owner_.getResourceTracker()) {
textureBuffer->initResourceTracker(resourceTracker);
Expand Down
22 changes: 22 additions & 0 deletions src/igl/opengl/TextureBufferExternal.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
/*
* Copyright (c) Meta Platforms, Inc. and affiliates.
*
* This source code is licensed under the MIT license found in the
* LICENSE file in the root directory of this source tree.
*/

#include <igl/opengl/TextureBufferExternal.h>

namespace igl::opengl {
TextureBufferExternal::TextureBufferExternal(IContext& context,
TextureFormat format,
TextureDesc::TextureUsage usage) :
Super(context, format) {
FormatDescGL formatDescGL;
toFormatDescGL(format, usage, formatDescGL);
glInternalFormat_ = formatDescGL.internalFormat;

setUsage(usage);
}

} // namespace igl::opengl
5 changes: 3 additions & 2 deletions src/igl/opengl/TextureBufferExternal.h
Original file line number Diff line number Diff line change
Expand Up @@ -18,8 +18,9 @@ class TextureBufferExternal : public TextureBufferBase {
friend class PlatformDevice; // So that PlatformDevice can do setTextureBufferProperties

public:
explicit TextureBufferExternal(IContext& context, TextureFormat format) :
Super(context, format) {}
explicit TextureBufferExternal(IContext& context,
TextureFormat format,
TextureDesc::TextureUsage usage);
~TextureBufferExternal() override = default;

[[nodiscard]] bool supportsUpload() const final {
Expand Down

0 comments on commit fa1618b

Please sign in to comment.