Skip to content

bugfix #540 : immutable texture can not be resized by glTexImage2D #541

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Mar 20, 2025

Conversation

wysaid
Copy link
Owner

@wysaid wysaid commented Mar 20, 2025

bugfix: immutable texture is used when creating textures, so glTexImage2D can not be used to change the texture size.

#540

Summary by CodeRabbit

  • Refactor
    • Streamlined image and texture update processes for more efficient and responsive media rendering.
    • Enhanced video playback handling to deliver smoother, more consistent performance during frame updates.
    • Improved error handling and logging for uniform variable checks in shader programs.
    • Updated member variable initializations in the video player class for clearer state management.

Copy link

coderabbitai bot commented Mar 20, 2025

Walkthrough

The pull request refines texture management and error logging throughout the project. The resize method in the TextureObject class has been logically inverted and streamlined for texture creation and updates. Comment formatting has been improved in one header file. The error logging for missing shader uniforms is now conditionally compiled using a debug flag. Additionally, the CGEVideoPlayerYUV420P class has been updated to eliminate redundant member initializations, relocate texture generation logic, and enhance error handling for texture updates, ensuring all resources have defined initial states.

Changes

File Path(s) Change Summary
library/src/main/jni/cge/common/cgeGLFunctions.cpp
library/src/main/jni/cge/common/cgeGLFunctions.h
Texture Resize Logic & Comments: Reversed and streamlined conditional checks in the resize method of TextureObject, consolidating texture creation and updates. Additionally, adjusted comment formatting by adding a leading space in the header file.
library/src/main/jni/cge/common/cgeShaderFunctions.h Shader Uniform Error Logging: Removed the macro-based logging and replaced it with a direct logging block wrapped in #ifdef DEBUG to conditionally log errors when a uniform variable is not found during debug builds.
library/src/main/jni/interface/cgeVideoPlayer.cpp
library/src/main/jni/interface/cgeVideoPlayer.h
Video Player Initialization & Texture Handling: Removed redundant member initializations in the constructor of CGEVideoPlayerYUV420P and shifted texture generation logic to the updateVideoFrame method. Updated default member values and refined error logging for uniform location retrieval, with a minor comment formatting update in the header.

Sequence Diagram(s)

sequenceDiagram
    participant Caller
    participant TextureObj as TextureObject::resize
    participant GL as GL API
    Caller->>TextureObj: call resize(buffer, width, height, format)
    alt Texture is valid, dimensions match, and buffer is null
      TextureObj->>Caller: return false
    else Width or height is zero
      TextureObj->>Caller: assert & return false
    else Texture is zero or dimensions differ
      TextureObj->>TextureObj: Delete existing texture (if any)
      TextureObj->>GL: Generate new texture using buffer
      TextureObj->>Caller: update texture size & return success
    else Texture exists & dimensions match
      TextureObj->>GL: Bind texture and update with glTexSubImage2D
      TextureObj->>Caller: return success
    end
Loading
sequenceDiagram
    participant VP as CGEVideoPlayerYUV420P
    participant GL as GL API
    VP->>VP: Constructor: bind attributes, retrieve uniform locations
    VP->>VP: Call updateVideoFrame(frameData, linesize)
    alt Texture Y location is zero or linesize changed
        VP->>GL: Generate new textures from framebuffer data
        VP->>VP: Update uniform values accordingly
    else
        VP->>GL: Update existing textures
    end
    VP->>VP: Log error if any uniform location is invalid (in DEBUG)
Loading

Poem

Hop, hop, through lines of code I bound,
Resizing textures so smooth and sound.
Debug whispers in conditional light,
Video frames gleam in the night.
CodeRabbit smiles with every byte found! 🐇✨


📜 Recent review details

Configuration used: CodeRabbit UI
Review profile: CHILL
Plan: Free

📥 Commits

Reviewing files that changed from the base of the PR and between 65654aa and 90578d3.

📒 Files selected for processing (5)
  • library/src/main/jni/cge/common/cgeGLFunctions.cpp (2 hunks)
  • library/src/main/jni/cge/common/cgeGLFunctions.h (1 hunks)
  • library/src/main/jni/cge/common/cgeShaderFunctions.h (1 hunks)
  • library/src/main/jni/interface/cgeVideoPlayer.cpp (3 hunks)
  • library/src/main/jni/interface/cgeVideoPlayer.h (2 hunks)

🪧 Tips

Chat

There are 3 ways to chat with CodeRabbit:

  • Review comments: Directly reply to a review comment made by CodeRabbit. Example:
    • I pushed a fix in commit <commit_id>, please review it.
    • Generate unit testing code for this file.
    • Open a follow-up GitHub issue for this discussion.
  • Files and specific lines of code (under the "Files changed" tab): Tag @coderabbitai in a new review comment at the desired location with your query. Examples:
    • @coderabbitai generate unit testing code for this file.
    • @coderabbitai modularize this function.
  • PR comments: Tag @coderabbitai in a new PR comment to ask questions about the PR branch. For the best results, please provide a very specific query, as very limited context is provided in this mode. Examples:
    • @coderabbitai gather interesting stats about this repository and render them as a table. Additionally, render a pie chart showing the language distribution in the codebase.
    • @coderabbitai read src/utils.ts and generate unit testing code.
    • @coderabbitai read the files in the src/scheduler package and generate a class diagram using mermaid and a README in the markdown format.
    • @coderabbitai help me debug CodeRabbit configuration file.

Note: Be mindful of the bot's finite context window. It's strongly recommended to break down tasks such as reading entire modules into smaller chunks. For a focused discussion, use review comments to chat about specific files and their changes, instead of using the PR comments.

CodeRabbit Commands (Invoked using PR comments)

  • @coderabbitai pause to pause the reviews on a PR.
  • @coderabbitai resume to resume the paused reviews.
  • @coderabbitai review to trigger an incremental review. This is useful when automatic reviews are disabled for the repository.
  • @coderabbitai full review to do a full review from scratch and review all the files again.
  • @coderabbitai summary to regenerate the summary of the PR.
  • @coderabbitai resolve resolve all the CodeRabbit review comments.
  • @coderabbitai configuration to show the current CodeRabbit configuration for the repository.
  • @coderabbitai help to get help.

Other keywords and placeholders

  • Add @coderabbitai ignore anywhere in the PR description to prevent this PR from being reviewed.
  • Add @coderabbitai summary to generate the high-level summary at a specific location in the PR description.
  • Add @coderabbitai anywhere in the PR title to generate the title automatically.

CodeRabbit Configuration File (.coderabbit.yaml)

  • You can programmatically configure CodeRabbit by adding a .coderabbit.yaml file to the root of your repository.
  • Please see the configuration documentation for more information.
  • If your editor has YAML language server enabled, you can add the path at the top of this file to enable auto-completion and validation: # yaml-language-server: $schema=https://coderabbit.ai/integrations/schema.v2.json

Documentation and Community

  • Visit our Documentation for detailed information on how to use CodeRabbit.
  • Join our Discord Community to get help, request features, and share feedback.
  • Follow us on X/Twitter for updates and announcements.

Copy link

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actionable comments posted: 1

🧹 Nitpick comments (1)
library/src/main/jni/cge/common/cgeGLFunctions.cpp (1)

276-280: Improved input validation for width and height

Adding explicit validation for zero dimensions is a good practice. However, the error message could be more specific about which parameter must not be zero.

- assert(0 && (void*)"TextureObject::resize must not be 0!");
+ assert(0 && (void*)"TextureObject::resize - width and height must not be 0!");
📜 Review details

Configuration used: CodeRabbit UI
Review profile: CHILL
Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between 65654aa and 3562e5f.

📒 Files selected for processing (5)
  • library/src/main/jni/cge/common/cgeGLFunctions.cpp (2 hunks)
  • library/src/main/jni/cge/common/cgeGLFunctions.h (1 hunks)
  • library/src/main/jni/cge/common/cgeShaderFunctions.h (1 hunks)
  • library/src/main/jni/interface/cgeVideoPlayer.cpp (3 hunks)
  • library/src/main/jni/interface/cgeVideoPlayer.h (2 hunks)
🧰 Additional context used
🧬 Code Definitions (1)
library/src/main/jni/interface/cgeVideoPlayer.cpp (1)
library/src/main/jni/interface/cgeVideoPlayer.h (6) (6)
  • CGEVideoPlayerYUV420P (46-46)
  • CGEVideoPlayerYUV420P (47-47)
  • m_texYUV (74-74)
  • m_texYUV (75-75)
  • m_texYUV (76-76)
  • m_linesize (80-80)
⏰ Context from checks skipped due to timeout of 90000ms (1)
  • GitHub Check: build
🔇 Additional comments (9)
library/src/main/jni/cge/common/cgeGLFunctions.h (1)

53-54: Code style improvement: Consistent comment formatting

Added spaces at the beginning of comments to improve readability and maintain consistent style throughout the codebase.

library/src/main/jni/cge/common/cgeShaderFunctions.h (1)

227-230: Improved error logging by using explicit conditional compilation

Replaced CGE_LOG_CODE macro with a direct #ifdef DEBUG conditional to make the error logging behavior more explicit. This ensures that error messages about missing uniforms only appear in debug builds and are completely excluded from release builds, improving performance.

library/src/main/jni/interface/cgeVideoPlayer.cpp (1)

72-100: Improved constructor implementation by moving initialization to class definition

Removed redundant member initializations from the constructor since they're now properly initialized in the class definition. This is a cleaner approach that ensures all members have defined default values.

Additionally, the uniform assignments were moved inside an else block to only execute if the texture locations are valid, improving error handling.

library/src/main/jni/interface/cgeVideoPlayer.h (2)

51-51: Code style improvement: Added space in comment

Added space after comment delimiter for improved readability and consistent style.


84-92: Improved initialization of member variables

Added in-class initialization for member variables to ensure they have defined default values before the constructor runs. This approach is more robust as it guarantees initialization even if constructor code changes, and follows modern C++ best practices.

  • Texture IDs initialize to zero with {}
  • Texture locations explicitly initialize to -1
  • Pointers initialize to nullptr
  • Other numeric values initialize to zero

This change provides better protection against undefined behavior and complements the constructor changes.

library/src/main/jni/cge/common/cgeGLFunctions.cpp (4)

271-274: Good early return optimization for texture resizing

This change correctly implements an early return when no resize is necessary (texture exists, dimensions match, and no new buffer data). This guards against unnecessary texture operations, making the code more efficient.


282-312: Fixed texture recreation handling for dimension changes

This change properly addresses the core issue with immutable textures. When dimensions change, the code now correctly deletes the existing texture and creates a new one instead of trying to resize an immutable texture with glTexImage2D, which isn't allowed by OpenGL specifications.


313-318: Correct usage of glTexSubImage2D for content updates

Using glTexSubImage2D to update the content of an existing texture (when dimensions are unchanged) follows OpenGL best practices. This approach avoids the expensive operation of recreating textures when only the content changes.


320-320: Proper function return value

Ensuring the function returns true when texture operations are successfully performed is correct and maintains consistency with the function's contract.

…Image2D` can not be used to change the texture size.
@wysaid wysaid force-pushed the fix_texture_resize branch from 3562e5f to 90578d3 Compare March 20, 2025 07:40
@wysaid wysaid merged commit 625e2e6 into master Mar 20, 2025
2 checks passed
@wysaid wysaid deleted the fix_texture_resize branch March 20, 2025 08:25
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

1 participant