feat: add alpha channel blending support#7
Open
tslmy wants to merge 6 commits into
Open
Conversation
- Add 'a' field to ZBufferPoint (8.16 fixed-point, same as r,g,b) - Propagate vertex alpha from glColor4f through the vertex pipeline - Add GL_SRC_ALPHA / GL_ONE_MINUS_SRC_ALPHA blend factors to TGL_BLEND_FUNC and TGL_BLEND_FUNC_RGB macros - Use TGL_ALPHA_MUL helper with (factor + factor>>7) correction to map [0,255] -> [0,256], ensuring alpha=255 is identity and alpha=0 produces exactly zero (no darkening artifacts) - Preserve texture alpha through RGB_MIX_FUNC in 32-bit mode - Add INTERP_A support to ztriangle.h for per-vertex alpha interpolation - Update smooth-shaded blend triangles to interpolate and use alpha - Update flat-shaded blend triangles to pack vertex alpha into pixel - Update line/point blend paths to pass alpha
- Add gl_convertRGBA_to_8A8R8G8B() that preserves the alpha channel when converting from RGBA byte data to internal 0xAARRGGBB format - Add gl_resizeImageNoInterpolate4() for resizing 4-channel textures - Update glopTexImage2D to accept GL_RGBA with components=4 - Texture alpha is preserved through TGL_BLEND_FUNC via the pixel's high byte, enabling proper alpha-blended textured geometry
Add 7 tests covering alpha channel rendering correctness: Untextured: - alpha_zero_transparent: alpha=0 produces fully transparent output - alpha_full_opaque: alpha=1 produces fully opaque output - alpha_half_blend: alpha=0.5 produces correct 50/50 blend - alpha_smooth_interp: GL_SMOOTH interpolates alpha per-vertex Textured (GL_RGBA): - alpha_texture_transparent: RGBA texture with alpha=0 is invisible - alpha_texture_opaque: RGBA texture with alpha=255 is fully visible - alpha_texture_half_blend: RGBA texture with alpha=128 blends correctly All tests use direct framebuffer readback and verify pixel values with a small tolerance for fixed-point rounding.
Owner
|
Please provide sample programs to illustrate the use of newly-introduced APIs. |
tslmy
marked this pull request as ready for review
May 20, 2026 14:46
Author
|
@jserv good idea. Added a |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
afield toZBufferPoint(8.16 fixed-point, same asr,g,b)glColor4fthrough the vertex pipelineGL_SRC_ALPHA/GL_ONE_MINUS_SRC_ALPHAblend factors toTGL_BLEND_FUNCandTGL_BLEND_FUNC_RGBmacrosTGL_ALPHA_MULhelper with (factor + factor>>7) correction to map[0,255]->[0,256], ensuringalpha=255is identity andalpha=0produces exactly zero (no darkening artifacts)RGB_MIX_FUNCin 32-bit modeINTERP_Asupport toztriangle.hfor per-vertex alpha interpolationAdded tests, for both textured and untextured models, to ensure that alpha blending works correctly.
Also added a compilable demo,
examples/raw/alpha.c, to illustrate how transparency may look like. It renders a scene like the image below:closes #6
Disclaimer: Coding agent (GitHub Copilot + Claude Sonnet 4.6) is heavily used in this PR.