Skip to content

Commit

Permalink
Fixed video textures not updating correctly after recent changes to h…
Browse files Browse the repository at this point in the history
…ow texture data is uploaded to the GPU.
  • Loading branch information
kromenak committed Feb 6, 2022
1 parent 6f6df4e commit e076244
Show file tree
Hide file tree
Showing 3 changed files with 13 additions and 4 deletions.
5 changes: 5 additions & 0 deletions Source/Rendering/Texture.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -287,6 +287,11 @@ void Texture::ApplyAlphaChannel(const Texture& alphaTexture)
}
}

void Texture::AddDirtyFlags(DirtyFlags flags)
{
mDirtyFlags |= flags;
}

void Texture::UploadToGPU()
{
// Nothing to do.
Expand Down
7 changes: 5 additions & 2 deletions Source/Rendering/Texture.h
Original file line number Diff line number Diff line change
Expand Up @@ -95,9 +95,12 @@ class Texture : public Asset
// Alpha and transparency
void SetTransparentColor(Color32 color);
void ApplyAlphaChannel(const Texture& alphaTexture);


// GPU upload
void AddDirtyFlags(DirtyFlags flags);
void UploadToGPU();


// Export/save
void WriteToFile(const std::string& filePath);

private:
Expand Down
5 changes: 3 additions & 2 deletions Source/Video/Playback/VideoPlayback.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -194,8 +194,8 @@ bool VideoPlayback::UpdateVideoTexture(Frame* videoFrame)
//TODO: There may be more efficient options for displaying a video frame. Ex: YUV420 data can be loaded into texture and rendered with special shader.
//TODO: But for now, just convert all formats to RGBA for simplicity.
mRGBAConvertContext = sws_getCachedContext(mRGBAConvertContext,
avFrame->width, avFrame->height, (AVPixelFormat)avFrame->format, // from format
avFrame->width, avFrame->height, AV_PIX_FMT_RGBA, // to format
avFrame->width, avFrame->height, (AVPixelFormat)avFrame->format, // from format
avFrame->width, avFrame->height, AV_PIX_FMT_RGBA, // to format
SWS_BICUBIC, nullptr, nullptr, nullptr);
if(mRGBAConvertContext == nullptr)
{
Expand All @@ -211,6 +211,7 @@ bool VideoPlayback::UpdateVideoTexture(Frame* videoFrame)
dest, dest_linesize); // dest

// Upload texture data to GPU.
mVideoTexture->AddDirtyFlags(Texture::DirtyFlags::Pixels);
mVideoTexture->UploadToGPU();

// Yep, we are uploaded.
Expand Down

0 comments on commit e076244

Please sign in to comment.