Refactoring Axmol Rendering: RenderTexture, Camera Projection, and Explicit Offscreen Semantics #3211
halx99
announced in
Announcements
Replies: 0 comments
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Uh oh!
There was an error while loading. Please reload this page.
Uh oh!
There was an error while loading. Please reload this page.
PR 3208 is an important step in the Axmol v3 rendering refactor. It is not just a file move or an API cleanup. It clarifies several long-standing assumptions in the rendering system:
RenderTexturesize expressed in canvas coordinates or physical texture pixels?Director's global matrix stack or the active visiting camera?RenderTextureitself or by an explicit render pass?This PR moves the engine toward explicit rendering semantics.
RenderTexture no longer applies content scale implicitly
Previously,
RenderTexture::create(width, height, ...)accepted what looked like a normal size, but internally multiplied it byAX_CONTENT_SCALE_FACTOR().That was convenient for some legacy code, but it also made the API ambiguous. Callers could not easily tell whether they were passing a logical canvas size or a physical texture size.
After this PR:
RenderTexture::create(textureSize, ...)means
textureSizeis the actual physical texture size.RenderTextureno longer silently multiplies it by the content scale factor.If the input is in canvas coordinates and you want high-DPI density, convert it explicitly:
This makes the API clearer:
create()creates a render target with the exact texture size you request.This PR also provides a convenience API:
RenderTexture::createForCanvas(size, ...)Its meaning is: the input size is measured in canvas coordinates and is converted internally using
Director::canvasToPixels(). In other words,create(...)is for physical texture sizes, whilecreateForCanvas(...)is for canvas-coordinate sizes.RenderTexture is decoupled from 2D Node behavior
The old
RenderTexturecarried many responsibilities:begin()andend().That made it difficult to align with a modern renderer, explicit render passes, VR rendering, and multiple graphics backends.
The new direction is for
RenderTextureto behave more like a texture-backed render target resource. The actual rendering process is controlled byRenderTexturePass.The new flow is easier to reason about:
RenderTexturePassis responsible for begin/end, clear, viewport, render target restore, camera override behavior, and other pass-level state.RenderTextureremains the texture resource and readback/save target.2D rendering now uses the visiting camera view-projection
Many 2D draw paths previously read the global projection matrix:
This made 2D rendering depend on
Director's global matrix stack.Those paths now use:
Camera::getVisitingViewProjectionMatrix()This affects rendering components such as
Sprite,Label,DrawNode,ParticleSystemQuad,AtlasNode,FastTMXLayer, and Grid rendering.The benefit is that both 2D and 3D rendering now depend on the active visiting camera rather than a global projection matrix. This model works better for offscreen rendering, Grid effects, VR rendering, and multi-camera rendering.
Legacy matrix stack usage is removed from visit paths
Some 2D nodes used to push and pop
MATRIX_STACK_MODELVIEWinsidevisit(). That was part of the legacy rendering compatibility layer.This PR removes multiple instances of that pattern. Rendering now relies more directly on each node's
_modelViewTransformand the current visiting camera.The result is more local and explicit rendering state, with fewer hidden interactions between different rendering paths.
Grid rendering moves to the camera model
Grid effects previously modified
Director's projection temporarily and restored it afterward. That model does not fit well with the new renderer, especially when RenderTexture, cameras, VR rendering, resizing, and resolution policies interact.NodeGridnow uses a dedicated canvas-orthographic camera for Grid capture and rendering. Grid blit paths also use the visiting camera view-projection.This avoids mutating global projection state and makes Grid effects compatible with the new camera-based rendering model.
Texture size APIs are clearer
This PR also replaces several older texture-size APIs:
getPixelsWide() -> getWidth() getPixelsHigh() -> getHeight() getContentSizeInPixels() -> getPixelSize()This reduces confusion between content size and pixel size.
Under the new semantics:
getWidth()andgetHeight()mean texture pixel dimensions.getPixelSize()means texture pixel size.Generic VR rendering benefits from the same model
The generic VR renderer now separates the final output size from the offscreen texture size.
Important concepts are:
outputSize: the final distortion output viewport size.textureSize: the physical offscreen RenderTexture size.renderScale: the supersampling scale for the generic VR render texture.For example:
This keeps the final output size unchanged while rendering the side-by-side eye texture at a higher resolution before distortion.
This is clearer than implicitly tying VR render density to the content scale factor.
Why this matters
The core of this PR is not just an API rename. It separates concepts that used to be mixed together:
Previously, these concepts were often connected through implicit conversions and global state. That was convenient in simple cases, but it made RenderTexture, Grid, VR, high-DPI rendering, resizing, and multi-backend rendering harder to maintain.
PR 3208 makes those relationships explicit and lays groundwork for the Axmol v3 rendering architecture.
Migration cost
The main migration point is
RenderTexture::create().If old code passed a canvas size and relied on internal content-scale multiplication, prefer:
If you want manual conversion, use:
If the old code already passed a physical texture size, continue using
create(...)and no conversion is needed.Custom rendering code should also migrate from
Directorprojection matrix access toCamera::getVisitingViewProjectionMatrix().Summary
This refactor clarifies Axmol's rendering semantics:
RenderTexture::create()creates a render target with an explicit physical texture size.RenderTexturePasscontrols offscreen rendering.Together, these changes provide a cleaner foundation for RenderTexture, camera rendering, VR, and the v3 renderer architecture.
All reactions