Skip to content

Add _render.Texture.scale_mode#3740

Open
damusss wants to merge 3 commits into
pygame-community:mainfrom
damusss:_render-texture-scale-mode
Open

Add _render.Texture.scale_mode#3740
damusss wants to merge 3 commits into
pygame-community:mainfrom
damusss:_render-texture-scale-mode

Conversation

@damusss
Copy link
Copy Markdown
Member

@damusss damusss commented Mar 13, 2026

Should be straight forward. It's one of the texture properties you can freely get or set with SDL (both 2 and 3). Keeping it a constructor only argument makes no sense. That constructor only argument is also not conformed to SDL3. If this gets in I will make a follow up pull request that removes that argument (no deprecation needed since the module isn't public).
Currently to change the scale mode of a texture made from a surface your only option is create the texture and then use Texture.update, but when you do that the alpha of the surface isn't ported properly. One could say that's a bug of its own, but even if, doesn't make this property less useful.

SDL2 scale mode: https://wiki.libsdl.org/SDL2/SDL_ScaleMode
SDL3 scale mode: https://wiki.libsdl.org/SDL3/SDL_ScaleMode

I added SCALEMODE_PIXELART even if SDL2 doesn't have it, as it can just fall back to SCALEMODE_NEAREST, given the similarities between them.

Since the module isn't public and doesn't have a dedicated docs page I'm forced to add the docs to the stubs, which is what would have happened anyways when the docs were added to it.

Also, the C code for the scale mode isn't SDL3 compatible yet (the error macros have to branch for sdl3), a future pull request will make the whole module SDL3 compatible.

@damusss damusss requested a review from a team as a code owner March 13, 2026 12:26
@damusss damusss added New API This pull request may need extra debate as it adds a new class or function to pygame _render pygame._render labels Mar 13, 2026
@coderabbitai
Copy link
Copy Markdown
Contributor

coderabbitai Bot commented Mar 13, 2026

No actionable comments were generated in the recent review. 🎉

ℹ️ Recent review info
⚙️ Run configuration

Configuration used: Path: .coderabbit.yaml

Review profile: CHILL

Plan: Pro

Run ID: 87fa5580-74cf-432c-828d-d7b4216d679c

📥 Commits

Reviewing files that changed from the base of the PR and between 051077e and c25d5f8.

📒 Files selected for processing (1)
  • buildconfig/stubs/pygame/_render.pyi
🚧 Files skipped from review as they are similar to previous changes (1)
  • buildconfig/stubs/pygame/_render.pyi

📝 Walkthrough

Walkthrough

Adds texture scale-mode support: three new constants (SCALEMODE_LINEAR, SCALEMODE_NEAREST, SCALEMODE_PIXELART) and a Texture.scale_mode property implemented in C, exposed in type stubs, and covered by a unit test.

Changes

Cohort / File(s) Summary
Type Stubs - Constants
buildconfig/stubs/pygame/constants.pyi, buildconfig/stubs/pygame/locals.pyi
Added int constants SCALEMODE_LINEAR, SCALEMODE_NEAREST, SCALEMODE_PIXELART and updated __all__.
Type Stubs - Module Exports
buildconfig/stubs/pygame/__init__.pyi
Exported the three new scale mode constants from the public API.
Type Stubs - Texture Property
buildconfig/stubs/pygame/_render.pyi
Added Texture.scale_mode property (getter -> int, setter -> int) with docstring and version note.
C Implementation - Constants
src_c/constants.c
Introduced SDL-version-gated constants for SCALEMODE_NEAREST, SCALEMODE_LINEAR, SCALEMODE_PIXELART (native on SDL3, mapped on older SDL).
C Implementation - Texture Property
src_c/render.c
Added texture_get_scale_mode and texture_set_scale_mode and registered scale_mode in texture_getset to get/set SDL texture scale mode.
Tests
test/render_test.py
Added test_scale_mode to assert default is SCALEMODE_NEAREST and that setting to SCALEMODE_LINEAR updates the property.

Sequence Diagram(s)

sequenceDiagram
    participant Py as Python (Texture)
    participant C as C Extension (render.c)
    participant SDL as SDL Library

    Py->>C: getattr(Texture.scale_mode)
    C->>SDL: SDL_GetTextureScaleMode(texture)
    SDL-->>C: scale_mode (int)
    C-->>Py: return int

    Py->>C: setattr(Texture.scale_mode = value)
    C->>SDL: SDL_SetTextureScaleMode(texture, value)
    SDL-->>C: success / error
    C-->>Py: None or raise error
Loading

Estimated code review effort

🎯 3 (Moderate) | ⏱️ ~20 minutes

🚥 Pre-merge checks | ✅ 2 | ❌ 1

❌ Failed checks (1 warning)

Check name Status Explanation Resolution
Docstring Coverage ⚠️ Warning Docstring coverage is 7.69% which is insufficient. The required threshold is 80.00%. Write docstrings for the functions missing them to satisfy the coverage threshold.
✅ Passed checks (2 passed)
Check name Status Explanation
Title check ✅ Passed The title accurately summarizes the main change: adding a scale_mode property to _render.Texture, which is the core purpose of this PR.
Description check ✅ Passed The description is clearly related to the changeset, explaining the rationale for adding the scale_mode property, SDL compatibility details, and implementation notes.

✏️ Tip: You can configure your own custom pre-merge checks in the settings.

✨ Finishing Touches
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Post copyable unit tests in a comment
📝 Coding Plan
  • Generate coding plan for human review comments

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands and usage tips.

Copy link
Copy Markdown
Contributor

@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

🤖 Prompt for all review comments with AI agents
Verify each finding against the current code and only fix it if needed.

Inline comments:
In `@test/render_test.py`:
- Around line 276-279: The test uses a no-op comparison instead of setting the
property: replace the comparison expression "self.texture.scale_mode ==
pygame.SCALEMODE_LINEAR" with an assignment to set the scale mode (i.e., assign
pygame.SCALEMODE_LINEAR to self.texture.scale_mode) so that the subsequent
assertion in test_scale_mode actually verifies the setter behavior for the
texture.scale_mode property.

ℹ️ Review info
⚙️ Run configuration

Configuration used: Path: .coderabbit.yaml

Review profile: CHILL

Plan: Pro

Run ID: 7881fd59-7219-43f0-bfc0-8710ec05fe58

📥 Commits

Reviewing files that changed from the base of the PR and between bda4eae and 38a27f6.

📒 Files selected for processing (7)
  • buildconfig/stubs/pygame/__init__.pyi
  • buildconfig/stubs/pygame/_render.pyi
  • buildconfig/stubs/pygame/constants.pyi
  • buildconfig/stubs/pygame/locals.pyi
  • src_c/constants.c
  • src_c/render.c
  • test/render_test.py

Comment thread test/render_test.py
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

New API This pull request may need extra debate as it adds a new class or function to pygame _render pygame._render

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant