Closed GuntherDW closed 9 years ago
@MamiyaOtaru discusses this in a bit more depth in this minecraftforums post.
Thanks very much for this @GuntherDW and thanks @tompreuss for the handy link. The diffs look straightforward. I'll merge and do a release tomorrow. Right now I've just got home from work and it's beer-o-clock. ;)
since that post I am fully on board with the state manager. avoiding unnecessary gl calls does save a lot of CPU cycles, much more than I thought at first. Definitely good seeing people get on board with it.
semi-related: I'm using a wrapper around it such that all the calls look identical. ie GL11.glDisable(GL11.GL_BLEND) becomes GLWrapper.glDisable(GLWrapper.GL_BLEND) instead of GlStateManager. disableBlend() which honestly isn't too different, but by using my wrapper I can just search/replace GL11 to GLWrapper and still use the familiar idioms. The wrapper of course calls the state manager underneath. If you have a lot of opengl calls that might be worth doing, otherwise it's not that much work to switch to calling the state manager directly!
Good on you @MamiyaOtaru. I read that post and my main reaction was that, at least historically, state changes were well known to be very expensive in OpenGL and if the Mojang guys have gone to the trouble to do this, they have most likely done some performance measurements to justify it.
Mojang recently introduced the GlStateManager into their codebase. This actually handles GL calls a bit smarter by caching and checking before everything is sent off to lwjgl.
However this does in turn then cause problems for mods/plugins that don't use the GlStateManager class or work around it. The issue comes from mods that for example bind textures or change colors (or even just glEnable/glDisable) stuff, and minecraft not changing stuff before rendering because it did not know about it.
This is most notable when you for example use the voxel minimap. Waypoint beacons tend to flicker/render oddly when the watson renderer is being used.
This pull request changes most of the GL calls I found that have GlStateManager methods that do (more or less) the same.