After adding more new bugs than features, here's a version that will hopefully work well enough to test multi pass rendering:
http://www.jpct.net/download/beta/jpctapi110_pre2.zipThere are some drawbacks/problems with multi pass compared to one pass multi texturing. This affects the areas of transparency, fogging and accuracy.
I'm not sure if this approach is suitable for what you have in mind...well, we'll see...here's how the OpenGL pipeline handles one pass multi texturing:
As you can see, it's pretty straight forward. The texture in stage 1 is modulated with the vertex colors, then blended together with the one in stage 2...n. Then, the blending with the screen is done (which means applying transparency in this case) and the results are fogged.
Here's how the multi pass approach works:
The textures are applied in multiple passes now, which means that they are blended with the screens content one after the other. This has some problems.
Transparency: Can only be applied to the first texture, because it's the only one that won't be blended with the screen anyway because of the texture blending that's needed. But you can only do one blending, either the alpha blending for transparency or the color blending for the textures. Result: Transparency on multi pass polygons is there but much less than on single pass ones. And writing to the depth buffer has to be turned on for transparent multi pass polygons. For single pass, it's turned of by jPCT.
Fogging: You can either apply fog after each texturing pass (which is what i did) or just after the first or just after the last. In each case, you'll never get the same results as you would get with a single pass. Either the fogging will be too intense (my choice for the moment) or not intense enough (with both other options). So fogging multi pass textured polygons is a problem...maybe shifting the fog's starting position away in combination with no additional shadows (from characters or whatever) but the environment ones from that position on is an option?
Accuracy: That isn't much of a problem, but current hardware does the blending with a higher internal accuracy than the framebuffer provides. That means that you'll lose some color information by writing into the framebuffer for each pass. That's most noticable when using MODE_ADD. BLEND and MODULATE shouldn't be affected that much (if even).
How to enable multi pass: You don't have to. jPCT will use it on polygons that need it (i.e. that have a higher texture layer count than the hardware can render in one pass) automatically. There are some new settings in Config: maxTextureLayers, glMultiPassSorting and glOverrideStageCount.