Class Gl41CoreBackend

java.lang.Object
lol.trq.helios.gl.Gl41CoreBackend
All Implemented Interfaces:
GlBackend

public final class Gl41CoreBackend extends Object implements GlBackend
The backend on an OpenGL 4.1 core profile context, as Lazarus creates with -Dlazarus.gl=core.

Binding calls go through GL15, GL20 and GL30 without the C suffix, which Lazarus intercepts to keep its cache of the bound buffer, program and vertex array true. Draw calls go through the C classes, because Lazarus sends GL11.glDrawArrays to its fixed-function emulator. Capability toggles and texture binds use GL11 and GL13, which the emulator tracks without querying the driver.

  • Field Details

    • CONTEXT_PROFILE_MASK

      public static final int CONTEXT_PROFILE_MASK
      GL_CONTEXT_PROFILE_MASK.
      See Also:
    • CONTEXT_CORE_PROFILE_BIT

      public static final int CONTEXT_CORE_PROFILE_BIT
      GL_CONTEXT_CORE_PROFILE_BIT.
      See Also:
  • Constructor Details

    • Gl41CoreBackend

      public Gl41CoreBackend()
      Checks the context and binds to the emulated matrix stacks.
      Throws:
      IllegalStateException - if the context is not OpenGL 4.1 core, or Lazarus core mode is not running
  • Method Details

    • requireCoreContext

      public static void requireCoreContext()
      Checks that the current context is an OpenGL 4.1 or later core profile.
      Throws:
      IllegalStateException - with instructions when it is not
    • getInteger

      public int getInteger(int pname)
      Description copied from interface: GlBackend
      Reads one integer state value.
      Specified by:
      getInteger in interface GlBackend
      Parameters:
      pname - the state enum
      Returns:
      the value
    • getIntegers

      public void getIntegers(int pname, int[] out)
      Description copied from interface: GlBackend
      Reads an integer state vector.
      Specified by:
      getIntegers in interface GlBackend
      Parameters:
      pname - the state enum
      out - receives the values
    • matrices

      public void matrices(float[] modelView, float[] projection)
      Description copied from interface: GlBackend
      Reads the host's current model-view and projection matrices, column-major. On Lazarus core mode they come from the emulated matrix stacks without a driver query.
      Specified by:
      matrices in interface GlBackend
      Parameters:
      modelView - receives the model-view matrix, 16 floats
      projection - receives the projection matrix, 16 floats
    • isEnabled

      public boolean isEnabled(int cap)
      Description copied from interface: GlBackend
      Returns whether a capability is on.
      Specified by:
      isEnabled in interface GlBackend
      Parameters:
      cap - the capability
      Returns:
      true when enabled
    • setEnabled

      public void setEnabled(int cap, boolean on)
      Description copied from interface: GlBackend
      Turns a capability on or off.
      Specified by:
      setEnabled in interface GlBackend
      Parameters:
      cap - the capability
      on - the new state
    • blendFuncSeparate

      public void blendFuncSeparate(int srcRgb, int dstRgb, int srcAlpha, int dstAlpha)
      Description copied from interface: GlBackend
      Sets separate RGB and alpha blend factors.
      Specified by:
      blendFuncSeparate in interface GlBackend
      Parameters:
      srcRgb - source RGB factor
      dstRgb - destination RGB factor
      srcAlpha - source alpha factor
      dstAlpha - destination alpha factor
    • depthMask

      public void depthMask(boolean write)
      Description copied from interface: GlBackend
      Turns depth writes on or off.
      Specified by:
      depthMask in interface GlBackend
      Parameters:
      write - the new state
    • viewport

      public void viewport(int x, int y, int width, int height)
      Description copied from interface: GlBackend
      Sets the viewport, in framebuffer pixels.
      Specified by:
      viewport in interface GlBackend
      Parameters:
      x - left
      y - bottom
      width - width
      height - height
    • useProgram

      public void useProgram(int program)
      Description copied from interface: GlBackend
      Binds a program.
      Specified by:
      useProgram in interface GlBackend
      Parameters:
      program - the program, or 0
    • compileShader

      public int compileShader(int type, String source)
      Description copied from interface: GlBackend
      Creates and compiles a shader.
      Specified by:
      compileShader in interface GlBackend
      Parameters:
      type - GlBackend.VERTEX_SHADER or GlBackend.FRAGMENT_SHADER
      source - the full source
      Returns:
      the shader name
    • shaderCompiled

      public boolean shaderCompiled(int shader)
      Description copied from interface: GlBackend
      Returns whether a shader compiled.
      Specified by:
      shaderCompiled in interface GlBackend
      Parameters:
      shader - the shader
      Returns:
      true on success
    • shaderLog

      public String shaderLog(int shader)
      Description copied from interface: GlBackend
      Returns a shader's info log.
      Specified by:
      shaderLog in interface GlBackend
      Parameters:
      shader - the shader
      Returns:
      the log
    • deleteShader

      public void deleteShader(int shader)
      Description copied from interface: GlBackend
      Deletes a shader.
      Specified by:
      deleteShader in interface GlBackend
      Parameters:
      shader - the shader
    • linkProgram

      public int linkProgram(int... shaders)
      Description copied from interface: GlBackend
      Links a program from compiled shaders. Attribute and output locations come from layout(location) qualifiers in the source.
      Specified by:
      linkProgram in interface GlBackend
      Parameters:
      shaders - the shaders
      Returns:
      the program name
    • programLinked

      public boolean programLinked(int program)
      Description copied from interface: GlBackend
      Returns whether a program linked.
      Specified by:
      programLinked in interface GlBackend
      Parameters:
      program - the program
      Returns:
      true on success
    • programLog

      public String programLog(int program)
      Description copied from interface: GlBackend
      Returns a program's info log.
      Specified by:
      programLog in interface GlBackend
      Parameters:
      program - the program
      Returns:
      the log
    • deleteProgram

      public void deleteProgram(int program)
      Description copied from interface: GlBackend
      Deletes a program.
      Specified by:
      deleteProgram in interface GlBackend
      Parameters:
      program - the program
    • uniformLocation

      public int uniformLocation(int program, String name)
      Description copied from interface: GlBackend
      Looks up a uniform.
      Specified by:
      uniformLocation in interface GlBackend
      Parameters:
      program - the program
      name - the uniform name
      Returns:
      the location, or -1
    • uniform1i

      public void uniform1i(int location, int v)
      Description copied from interface: GlBackend
      Sets an int or sampler uniform on the bound program.
      Specified by:
      uniform1i in interface GlBackend
      Parameters:
      location - the location
      v - the value
    • uniform1f

      public void uniform1f(int location, float v)
      Description copied from interface: GlBackend
      Sets a float uniform on the bound program.
      Specified by:
      uniform1f in interface GlBackend
      Parameters:
      location - the location
      v - the value
    • uniform2f

      public void uniform2f(int location, float x, float y)
      Description copied from interface: GlBackend
      Sets a vec2 uniform on the bound program.
      Specified by:
      uniform2f in interface GlBackend
      Parameters:
      location - the location
      x - x
      y - y
    • uniform4f

      public void uniform4f(int location, float x, float y, float z, float w)
      Description copied from interface: GlBackend
      Sets a vec4 uniform on the bound program.
      Specified by:
      uniform4f in interface GlBackend
      Parameters:
      location - the location
      x - x
      y - y
      z - z
      w - w
    • uniformMatrix4

      public void uniformMatrix4(int location, float[] m)
      Description copied from interface: GlBackend
      Sets a mat4 uniform on the bound program.
      Specified by:
      uniformMatrix4 in interface GlBackend
      Parameters:
      location - the location
      m - the matrix, column-major
    • createFramebuffer

      public int[] createFramebuffer(int width, int height, boolean depthStencil)
      Description copied from interface: GlBackend
      Creates a framebuffer with an RGBA8 colour texture and optionally a depth-stencil renderbuffer. Leaves the previous bindings in place.
      Specified by:
      createFramebuffer in interface GlBackend
      Parameters:
      width - width in pixels
      height - height in pixels
      depthStencil - whether to attach a 24/8 depth-stencil buffer
      Returns:
      framebuffer, texture and renderbuffer names (renderbuffer 0 when none)
    • deleteFramebuffer

      public void deleteFramebuffer(int[] ids)
      Description copied from interface: GlBackend
      Specified by:
      deleteFramebuffer in interface GlBackend
      Parameters:
      ids - the names it returned
    • bindFramebuffer

      public void bindFramebuffer(int framebuffer)
      Description copied from interface: GlBackend
      Binds a framebuffer for drawing and reading.
      Specified by:
      bindFramebuffer in interface GlBackend
      Parameters:
      framebuffer - the framebuffer, or 0 for the default
    • clearColorTransparent

      public void clearColorTransparent()
      Description copied from interface: GlBackend
      Clears the bound framebuffer's colour to transparent black, keeping the clear colour.
      Specified by:
      clearColorTransparent in interface GlBackend
    • createVertexArray

      public int createVertexArray()
      Description copied from interface: GlBackend
      Creates a vertex array object.
      Specified by:
      createVertexArray in interface GlBackend
      Returns:
      its name
    • deleteVertexArray

      public void deleteVertexArray(int vao)
      Description copied from interface: GlBackend
      Deletes a vertex array object.
      Specified by:
      deleteVertexArray in interface GlBackend
      Parameters:
      vao - the name
    • bindVertexArray

      public void bindVertexArray(int vao)
      Description copied from interface: GlBackend
      Binds a vertex array object.
      Specified by:
      bindVertexArray in interface GlBackend
      Parameters:
      vao - the name, or 0
    • createBuffer

      public int createBuffer()
      Description copied from interface: GlBackend
      Creates a buffer object.
      Specified by:
      createBuffer in interface GlBackend
      Returns:
      its name
    • deleteBuffer

      public void deleteBuffer(int buffer)
      Description copied from interface: GlBackend
      Deletes a buffer object.
      Specified by:
      deleteBuffer in interface GlBackend
      Parameters:
      buffer - the name
    • bindBuffer

      public void bindBuffer(int target, int buffer)
      Description copied from interface: GlBackend
      Binds a buffer.
      Specified by:
      bindBuffer in interface GlBackend
      Parameters:
      target - GlBackend.ARRAY_BUFFER or GlBackend.ELEMENT_ARRAY_BUFFER
      buffer - the name, or 0
    • bufferData

      public void bufferData(int target, ByteBuffer data, int usage)
      Description copied from interface: GlBackend
      Uploads a buffer's whole contents, replacing its storage.
      Specified by:
      bufferData in interface GlBackend
      Parameters:
      target - the binding target
      data - the bytes, from position to limit
      usage - GlBackend.STREAM_DRAW or GlBackend.STATIC_DRAW
    • bufferStorage

      public void bufferStorage(int target, long size, int usage)
      Description copied from interface: GlBackend
      Allocates, or orphans, a buffer's storage without data.
      Specified by:
      bufferStorage in interface GlBackend
      Parameters:
      target - the binding target
      size - the size in bytes
      usage - the usage hint
    • bufferSubData

      public void bufferSubData(int target, long offset, ByteBuffer data)
      Description copied from interface: GlBackend
      Writes into part of a buffer.
      Specified by:
      bufferSubData in interface GlBackend
      Parameters:
      target - the binding target
      offset - the byte offset
      data - the bytes, from position to limit
    • bufferWriteUnsynchronized

      public void bufferWriteUnsynchronized(int target, long offset, ByteBuffer data)
      Description copied from interface: GlBackend
      Writes into part of a buffer through an unsynchronized mapping that invalidates the range: no wait on the GPU. The caller guarantees, with fences, that the GPU no longer reads that range.
      Specified by:
      bufferWriteUnsynchronized in interface GlBackend
      Parameters:
      target - the binding target
      offset - the byte offset
      data - the bytes, from position to limit
    • enableVertexAttrib

      public void enableVertexAttrib(int index)
      Description copied from interface: GlBackend
      Enables a vertex attribute in the bound vertex array.
      Specified by:
      enableVertexAttrib in interface GlBackend
      Parameters:
      index - the attribute location
    • vertexAttribPointer

      public void vertexAttribPointer(int index, int size, int type, boolean normalized, int stride, long offset)
      Description copied from interface: GlBackend
      Describes a vertex attribute in the bound vertex array, reading from the bound array buffer.
      Specified by:
      vertexAttribPointer in interface GlBackend
      Parameters:
      index - the attribute location
      size - components
      type - component type
      normalized - whether integers are normalized
      stride - bytes between vertices
      offset - byte offset of the first component
    • drawArrays

      public void drawArrays(int mode, int first, int count)
      Description copied from interface: GlBackend
      Draws non-indexed primitives from the bound vertex array.
      Specified by:
      drawArrays in interface GlBackend
      Parameters:
      mode - the primitive mode
      first - the first vertex
      count - the vertex count
    • drawElements

      public void drawElements(int mode, int count, int type, long offset, int baseVertex)
      Description copied from interface: GlBackend
      Draws indexed primitives from the bound vertex array, adding a base to every index.
      Specified by:
      drawElements in interface GlBackend
      Parameters:
      mode - the primitive mode
      count - the index count
      type - the index type
      offset - byte offset into the element buffer
      baseVertex - added to every index
    • fence

      public long fence()
      Description copied from interface: GlBackend
      Inserts a fence after the commands issued so far.
      Specified by:
      fence in interface GlBackend
      Returns:
      the sync object
    • waitFence

      public boolean waitFence(long sync, long timeoutNanos)
      Description copied from interface: GlBackend
      Waits for a fence, flushing commands first.
      Specified by:
      waitFence in interface GlBackend
      Parameters:
      sync - the fence
      timeoutNanos - the longest wait
      Returns:
      true when the fence signalled
    • deleteFence

      public void deleteFence(long sync)
      Description copied from interface: GlBackend
      Deletes a fence.
      Specified by:
      deleteFence in interface GlBackend
      Parameters:
      sync - the fence
    • activeTexture

      public void activeTexture(int unit)
      Description copied from interface: GlBackend
      Selects the active texture unit.
      Specified by:
      activeTexture in interface GlBackend
      Parameters:
      unit - GlBackend.TEXTURE0 plus the unit
    • bindTexture

      public void bindTexture(int texture)
      Description copied from interface: GlBackend
      Binds a 2D texture on the active unit.
      Specified by:
      bindTexture in interface GlBackend
      Parameters:
      texture - the name, or 0
    • copyToBoundTexture

      public void copyToBoundTexture(int width, int height)
      Description copied from interface: GlBackend
      Copies the bottom-left of the read framebuffer into the bound texture.
      Specified by:
      copyToBoundTexture in interface GlBackend
      Parameters:
      width - width in pixels
      height - height in pixels
    • createRgbTexture

      public int createRgbTexture(int width, int height, ByteBuffer rgb)
      Description copied from interface: GlBackend
      Creates a linear-filtered RGB8 texture.
      Specified by:
      createRgbTexture in interface GlBackend
      Parameters:
      width - width
      height - height
      rgb - tightly packed RGB bytes
      Returns:
      the texture name
    • deleteTexture

      public void deleteTexture(int texture)
      Description copied from interface: GlBackend
      Deletes a texture.
      Specified by:
      deleteTexture in interface GlBackend
      Parameters:
      texture - the name
    • stencilBits

      public int stencilBits()
      Description copied from interface: GlBackend
      Returns the stencil bits of the bound draw framebuffer.
      Specified by:
      stencilBits in interface GlBackend
      Returns:
      the bit count, 0 when there is no stencil buffer
    • stencilFunc

      public void stencilFunc(int func, int ref, int mask)
      Description copied from interface: GlBackend
      Sets the stencil test.
      Specified by:
      stencilFunc in interface GlBackend
      Parameters:
      func - the comparison
      ref - the reference value
      mask - the value mask
    • stencilOp

      public void stencilOp(int sfail, int dpfail, int dppass)
      Description copied from interface: GlBackend
      Sets the stencil operations.
      Specified by:
      stencilOp in interface GlBackend
      Parameters:
      sfail - on stencil fail
      dpfail - on depth fail
      dppass - on pass
    • stencilMask

      public void stencilMask(int mask)
      Description copied from interface: GlBackend
      Sets the stencil write mask.
      Specified by:
      stencilMask in interface GlBackend
      Parameters:
      mask - the mask
    • clearStencil

      public void clearStencil(int value)
      Description copied from interface: GlBackend
      Clears the bound framebuffer's stencil, keeping the clear value.
      Specified by:
      clearStencil in interface GlBackend
      Parameters:
      value - the value to clear to
    • colorMask

      public void colorMask(boolean r, boolean g, boolean b, boolean a)
      Description copied from interface: GlBackend
      Sets the colour write mask.
      Specified by:
      colorMask in interface GlBackend
      Parameters:
      r - red
      g - green
      b - blue
      a - alpha
    • scissor

      public void scissor(int x, int y, int width, int height)
      Description copied from interface: GlBackend
      Sets the scissor box, in framebuffer pixels.
      Specified by:
      scissor in interface GlBackend
      Parameters:
      x - left
      y - bottom
      width - width
      height - height