OpenGL API - jgoffeney/Cesium4Unreal GitHub Wiki

Back

Data Types

GLenum

GLsizei

A platform independent 32 bit unsigned integer for sizes.

GLuint

A platform independent 32 bit unsigned integer.

Functions

glBindBuffer

Binds a buffer object to a specified buffer id.

  • void glBindBuffer(GLenum target, GLuint bufferId)
    • target: an enum for the buffer type to bind the buffer id
    • bufferId: an id for the buffer object of interest (if is does not exist via glGenBuffers then it is created. If bufferId is set to 0 then it unbinds any previously bound buffers.
GLuint bufferId;
glGenBuffers(1, &bufferId);
glBindBuffer(GL_ARRAY_BUFFER, bufferId);

glBindTexture

Binds a texture object to a specified texture id.

  • void glBindTexture(GLenum target, GLuint textureId)
    • target: an enum for the texture type to bind the texture id
    • textureId: an id for the texture object of interest (if is does not exist via glGenTextures then it is created.
GLuint texId;
glGenTextures(1, &texid);
glBindTexture(GL_TEXTURE_2D, texId);

glBufferData

Creates and initializes a buffer object's data store for the buffer object bound to the target.

  • void glBufferData(GLenum target, GLsizeiptr size, const void * data, GLenum usage);
    • target: an enum for the buffer type
    • size: the size in bytes of the buffer's data store
    • data: either a pointer to an array to copy into the data store or NULL to leave it empty
    • usage: an enum for the expected usage pattern for the data depending on how often the data will be modified, read and how it will be accessed by the application (read, write, or update).

glCreateShader

  • Definition
    • GLuint glCreateShader(GLenum shaderType);
  • Creates a shader object of the specified type and returns a value greater then 0 to reference it.
  • The parameter shaderType takes a value of GL_COMPUTE_SHADER, GL_VERTEX_SHADER, GL_TESS_CONTROL_SHADER, GL_TESS_EVALUATION_SHADER, GL_GEOMETRY_SHADER or GL_FRAGMENT_SHADER.

glDeleteTextures

  • Definition
    • void glDeleteTextures(GLsizei n, GLuint * textures)
  • Deletes n texture names within the texture array textures.
GLuint texId;
glGenTextures(1, &texid);
glDeleteTextures(1, &texId);

glDrawBuffers / glNamedFramebufferDrawBuffers

Used to define an array of buffers to write the outputs from the fragment shader.

The function glDrawBuffers will automatically use a framebuffer bound to GL_DRAW_FRAMEBUFFER while glNamedFramebufferDrawBuffers uses a specified framebuffer.

  • void glDrawBuffers(GLsizei n, const GLenum *bufs);
  • void glNamedFramebufferDrawBuffers(GLuint framebuffer, GLsizei n, const GLenum *bufs);
  • Parameters
    • framebuffer: a specific framebuffer to use
    • n: the number of buffers to target with the maximum values as GL_MAX_DRAW_BUFFERS.
    • bufs: the array of buffers as below. Aside from GL_NONE they can only be used once.
      • GL_NONE: don't write to any color buffer
      • GL_FRONT_LEFT: write to front left color buffer
      • GL_FRONT_RIGHT: write to front right color buffer
      • GL_BACK_LEFT: write to back left color buffer
      • GL_BACK_RIGHT: write to back right color buffer
      • GL_COLOR_ATTACHMENT n: the nth color attachment of the current framebuffer where n is 0 to GL_MAX_COLOR_ATTACHMENTS.

glDrawElements

Render primitives from array data

  • void glDrawElements(GLenum mode, GLsizei count, GLenum type, const void * indices)
    • mode: specifies the type of GL primitives to render
    • count: the number of elements to render
    • type: the enum type of values in indices (GL_UNSIGNED_BYTE, GL_UNSIGNED_SHORT, or GL_UNSIGNED_INT).
    • indices: the pointer to where the indices are stored

glEnableVertexAttribArray

Enables a vertex shader attribute for the currently bound vertex array object

  • void glEnableVertexAttribArray(GLuint index)
    • Parameters
      • index: the index of the attribute to enable for the currently bound vertex array object

glGenBuffers

Allocates a set of buffer object ids. The ids are not associated with buffer objects until glBindBuffer is called.

  • void glGenBuffers(GLsizei n, GLuint * bufferIds)
    • n: the number of buffer ids
    • bufferIds: an array to hold the n ids which map to allocated buffer objects
GLuint bufferId;
glGenBuffers(1, &bufferId);

glGenFramebuffers

glGenTextures

Allocates a set of texture objects. The ids are not associated with texture objects until glBindTexture is called.

  • void glGenTextures(GLsizei n, GLuint * textureIds)
    • n: the number of texture object ids to allocate
    • textureIds: an array to hold the n ids
GLuint texId;
glGenTextures(1, &texId);

glGetAttribLocation

A form of shader reflection to get an index for a given attribute within a shader program.

  • Definition
    • GLint glGetAttribLocation(GLuint program, const GLchar * name)
      • program : the id of the shader program of interest
      • name: the name of the attribute of interest within the shader program
      • returns the index of the attribute location

glMapBuffer

Writes the contents of a buffer to a host array

  • void *glMapBuffer(GLenum target, GLenum access)
    • target:
    • access:

glOrtho

Creates a parallel projection by multiplying the current matrix by the matrix generated by this function.

Note that the OpenGL coordinates

  • void glOrtho( GLdouble left, GLdouble right, GLdouble bottom, GLdouble top, GLdouble nearVal, GLdouble farVal)
  • Parameters
    • left: the coordinate for the left vertical clipping plane
    • right: the coordinate for the right vertical clipping plane
    • bottom: the coordinate for the bottom horizontal clipping plane
    • top: the coordinate for the top horizontal clipping plane
    • nearVal: the coordinate for the near depth clipping plane
    • farVal: the coordinate for the far depth clipping plane

glPixelStorei

  • Definition
    • void glPixelStorei(GLenum storageMode, GLint alignmentSize)
  • Sets the pixel storage mode that affects glReadPixels
  • storageMode can be packed or unpacked using GL_PACK_ALIGNMENT or GL_UNPACK_ALIGNMENT
  • alignment can be 1 (byte), 2 (even bytes), 4 (word) or 8 (double)
glPixelStorei(GL_UNPACK_ALIGNMENT, 1);

glReadPixels

  • Definition
    • void glReadPixels(GLint x, GLint y, GLsizei width, GLsizei height, GLenum format, GLenum type, viod * data)
  • Reads a block of pixels from a buffer
  • The parameters x and y define the origin offsets to start reading the pixel block while width and height are the dimensions of the block in pixels.
  • The format defines the format of the pixels (GL_STENCIL_INDEX, GL_DEPTH_COMPONENT, GL_DEPTH_STENCIL, GL_RED, GL_GREEN, GL_BLUE, GL_RGB, GL_BGR, GL_RGBA, and GL_BGRA).
  • The type defines the data type of the pixel data (GL_UNSIGNED_BYTE, GL_BYTE, GL_UNSIGNED_SHORT, GL_SHORT, GL_UNSIGNED_INT, GL_INT, GL_HALF_FLOAT, GL_FLOAT, GL_UNSIGNED_BYTE_3_3_2, GL_UNSIGNED_BYTE_2_3_3_REV, GL_UNSIGNED_SHORT_5_6_5, GL_UNSIGNED_SHORT_5_6_5_REV, GL_UNSIGNED_SHORT_4_4_4_4, GL_UNSIGNED_SHORT_4_4_4_4_REV, GL_UNSIGNED_SHORT_5_5_5_1, GL_UNSIGNED_SHORT_1_5_5_5_REV, GL_UNSIGNED_INT_8_8_8_8, GL_UNSIGNED_INT_8_8_8_8_REV, GL_UNSIGNED_INT_10_10_10_2, GL_UNSIGNED_INT_2_10_10_10_REV, GL_UNSIGNED_INT_24_8, GL_UNSIGNED_INT_10F_11F_11F_REV, GL_UNSIGNED_INT_5_9_9_9_REV, or GL_FLOAT_32_UNSIGNED_INT_24_8_REV).
  • The data is the array to write the output pixel data.
glPixelStorei(GL_UNPACK_ALIGNMENT, 1);

glShaderSource

  • Definition
    • void glShaderSource(GLuint shader, GLsizei count, const GLchar **string, const GLint *length);
    • Parameters
      • shader: the shader reference value
      • count: the number of elements in the string and length arrays
      • string:

glTexImage2D

This method essentially loads a host array into GPU memory. It can be thought of like a malloc for the GPU to define a device array.

The target enums containing PROXY do not load data to the GPU but instead check to see if the GPU is capable of handling the parameters.

The format and internalFormat parameters specify how the pixel data is represented in the host memory and will be stored in device memory. If they are different then a conversion will occur.

  • Definition
    • void glTexImage2D( GLenum target, GLint level, GLint internalformat, GLsizei width, GLsizei height, GLint border, GLenum format, GLenum type, const void * data)
    • Parameters
      • target: the texture target. This operation will affect the currently bound texture to this target.
      • level: specifies the mipmap level of the texture. For texture targets containing RECTANGLE
      • internalFormat: the internal format of the color data to tell the shader how to access the data. It defines the format of each pixel on the GPU.
      • width: the width of the data in pixels.
      • height: the height of the data in pixels
      • border: required to be 0. Does nothing currently.
      • format: the format of the host pixel data in terms of color channels and ordering.
      • type: the data type of the pixel data. It allows for data channels to split a byte, short or int.
      • data: the host array to load to the GPU. Set to 0 to create an empty texture.

glTexParameter

Sets a filter or function on a texture target. Use a series of these after glTexImage2D to specify a transformation to the data as it is read from the bound texture.

Examples of the filters/functions are:

  • GL_TEXTURE_WRAP_S, GL_TEXTURE_WRAP_T or GL_TEXTURE_WRAP_R
  • Defines how to handle texture coordinates outside of the array by wrapping, mirroring or clamping.
  • GL_TEXTURE_MIN_FILTER or GL_TEXTURE_MAG_FILTER
    • Defines how textures are read as nearest neighbor or linear interpolation.

There are several different versions depending on the target's data type.

  • void glTexParameterf(GLenum target, GLenum pname, GLfloat param);
    • Parameters
      • target: the texture target
      • pname: an enum value for a specific filter/function
      • param: an enum value that supplies a parameter to the pname. Multiple parameters can be specified by the vector form (has a v at the end) of the glTexParameter or by calling the scalar form multiple times.
// Create an empty texture
glTexImage2D(GL_TEXTURE_2D, 0,GL_RGB, 1024, 768, 0, GL_RGB, GL_UNSIGNED_BYTE, 0);

// Read from the nearest neighbor when sampling from the texture
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_NEAREST);
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_NEAREST);

glVertexAttribPointer

Defines an array of generic vertex attribute data

  • void glVertexAttribPointer(GLuint index, GLint size, GLenum type, GLboolean normalized, GLsizei stride, const void * pointer)
    • Parameters
      • index: the index of the generic vertex attribute to be modified.
      • size: the number of components per vertex attribute (must be 1, 2, 3 or 4).
      • type: the data type each component
      • normalized: set to GL_TRUE to normalize fixed point data values when accessed
      • stride: the byte offset between vertex attributes
      • pointer: the offset of the first component of the vertex attribute in the array in the data store of the buffer currently bound to GL_ARRAY_BUFFER.

glViewport

Sets the viewport as the affine transform from normalized device coordinates (ex. xdn) to window coordinates (ex. xw) based on the lower-left corner coordinates (ex. xp) and the width and height.

xw = (xnd + 1)(width/2) + xp

yw = (ynd + 1)(height/2) + yp

If glViewport is not called explicitly then it is equivalent to

  • void glViewport(GLint x, GLint y, GLsizei width, GLsizei height)
    • Parameters
      • x: the left corner of the viewport rectangle in pixels
      • y: the lower corner of the viewport rectangle in pixels
      • width: the width of the viewport in pixels
      • height: the height of the viewpoint in pixels
⚠️ **GitHub.com Fallback** ⚠️