Skip to content
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

Custom framebuffer formats: update to 1.21.2 #53

Open
wants to merge 2 commits into
base: 1.21.2
Choose a base branch
from

Conversation

williambl
Copy link
Contributor

Everything is records and sealed interfaces and stuff now. It's hard to inject stuff into there without screwing everything up. Even if it compiles fine it might cause random MatchExceptions another day. So we're instead passing the data around a weird roundabout way:

  1. Resource Loading starts.
    1. net.minecraft.client.gl.ShaderLoader#prepare(ResourceManager, Profiler) starts loading post-chains.
    2. net.minecraft.client.gl.ShaderLoader#loadPostEffect(Identifier, Resource, ImmutableMap.Builder) is called for each post-chain.
    3. In loadPostEffect, we parse the custom target formats and put them in LOADING_TARGET_FORMATS_BY_POSTCHAIN_ID (#parseTargetFormatMap(Identifier, JsonElement))
  2. The second phase of resource loading happens, and the prepared post-chains are put into a newly-created net.minecraft.client.gl.ShaderLoader.Cache.
    1. In the cache's constructor, we copy from LOADING_TARGET_FORMATS_BY_POSTCHAIN into a field injected into the cache. (#getPreparedTargetFormatMaps())
  3. A post-chain processor (net.minecraft.client.gl.PostEffectProcessor) is created.
    1. The ShaderLoader cache's net.minecraft.client.gl.ShaderLoader.Cache#loadProcessor(Identifier, Set) is run.
    2. In that method we find the post-chain's target format map (stored in the field we injected into the cache) and put it into TARGET_FORMATS_FOR_PROCESSOR_INIT. (#prepareFormatsForProcessor(Map))
    3. In the post-chain processor's constructor, we take the map out of TARGET_FORMATS_FOR_PROCESSOR_INIT and put it into an injected field on the processor. (#getFormatsForProcessor())
  4. The post-chain processor is called for rendering (in one frame) ( net.minecraft.client.gl.PostEffectProcessor#render(FrameGraphBuilder, int, int, PostEffectProcessor.FramebufferSet))
    1. The processor creates new framebuffer factories for each of its targets.
    2. When these factories are created, we look up the custom texture format for the target's ID and associate it with the factory in FORMATS_BY_FACTORY. (#setCustomFormatForFactory(SimpleFramebufferFactory, TextureFormat))
    3. When the factory has its SimpleFramebufferFactory#create() method run, we remove the factory's custom texture format map entry and place it in FORMAT. (#prepareCustomFormatForFramebufferInit(SimpleFramebufferFactory))
    4. In the framebuffer's constructor, we then take the format from FORMAT and use it. (#getCustomFormatForFramebufferInit())

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