processing / processing-android

Processing mode and core library to create Android apps with Processing
http://android.processing.org
779 stars 293 forks source link

Better integration of P2DX renderer #565

Open codeanticode opened 4 years ago

codeanticode commented 4 years ago

The P2DX renderer by @hazmatsuitor improves 2D rendering performance significantly, as discussed in #265.

This experimental renderer has its own vertex data structures and shaders uniforms/attributes that allow memory transfer speedups, but on the other hand makes it harder to integrate with standard Processing's shaders. Work needs to be done to make that integration possible, or at least to document the caveats associated with the use of P2DX:

Next step would probably be to encapsulate the shader's uniform and attribute locations into an inner Shader2D class extending PShader. Or better still, making the 2D shader in the new renderer compatible with the existing color and texture shaders, so there is no need for a new type. What's tricky is that in its current implementation, the position attribute is a vec3 since it does not use w, but the P2D and P3D shaders expect a vec4. Perhaps the texFactor could be put in the w coordinate of position? Or add an unused w just for compatibility purposes.

notnullnotvoid commented 4 years ago

If I understand correctly, if the texFactor is moved into the W component of position and the vec2 texScale is changed to use a mat4 texMatrix instead, it will be compatible with the existing PShader API, right? If so, that's a lot less change than I expected.

codeanticode commented 4 years ago

Yes, that's right. Planning to look closer into it after releasing version 4.1 of the mode.