io7m / jcanephora

OpenGL plus static safety
ISC License
1 stars 0 forks source link

Control over state shadowing? #3

Open io7m opened 8 years ago

io7m commented 8 years ago

The rewrite of the jcanephora package has moved towards doing full state shadowing. Previous versions added partial state shadowing to allow for the removal of redundant GL calls. For example, it would maintain a boolean flag that indicated whether or not depth clamping is enabled:

  @Override public void depthClampingDisable()
    throws JCGLException, JCGLExceptionNoDepthBuffer
  {
    this.checkDepthBits();

    if (this.clamp) {
      this.gl.glDisable(GL3.GL_DEPTH_CLAMP);
      this.clamp = false;
    }
  }

  @Override public void depthClampingEnable()
    throws JCGLException, JCGLExceptionNoDepthBuffer
  {
    this.checkDepthBits();

    if (!this.clamp) {
      this.gl.glEnable(GL3.GL_DEPTH_CLAMP);
      this.clamp = true;
    }
  }

The "problem" here is that somebody could call this.gl.glEnable(GL3.GL_DEPTH_CLAMP); outside of the jcanephora package and essentially cause the shadowed state to go out of sync with the actual GPU state.

io7m commented 8 years ago

It won't be possible to prevent deliberate sabotage, obviously. It is possible through testing to show that the state tracking doesn't go out of sync on its own.

It is possible to provide a single "reset state cache" method that causes the state tracker to re-fetch all state from the GPU, but in what situation would this be useful? For the user to call this method, they would have to know that the state cache had gone out of sync, and if they knew that, then presumably that's an indication of a bug or deliberate sabotage!

io7m commented 8 years ago

Actually, this may be useful in the case that the user is using the plain OpenGL API and is using a library that is using jcanephora internally. The user may make changes to the state machine and jcanephora will then need to be told that its own view of the state is now out of date.

io7m commented 7 years ago

This is vital towards allowing jcanephora to be composed with other OpenGL libraries (of which there aren't many, because OpenGL isn't composable).