WebGL Textures & Vertices

Beginner's Guide

Page Seventy Seven

WebGL Entity Summary

The GLEntity class prepares a texture and matrix for use with WebGL. The section titled Default Matrix for Each Entity discusses the GLEntity matrix property. This section detailed texture initialization. A set of GLEntity may share one texture, or each entity may retain a unique texture. A set of GLEntity may share shader variables, or each entity can use a unique set of shader variables. The GLEntity property uSampler maintains the location of a uniform sampler2D. The aTexCoord property saves the location of an attribute for processing texture coordinates.

This section discussed GLEntity methods getImageVariables(), setImage(), setActiveTexture(), setMinMagFilters(), and last setWrapToEdges(). Method getImageVariables() saves the location of shader variables associated with the entity's texture. Method setImage() activates and creates a WebGLTexture for the entity. Method setMinMagFilters() assigns minification and magnification filters for the active texture. Method setWrapToEdges() assigns wrapping types for the active texture.

GLEntity follows the sequence listed below, to prepare a texture for processing in the shader.

  1. Assign a texture unit to a sampler with WebGL method uniform1i().
  2. Create a texture with WebGL method createTexture().
  3. Activate a texture unit with WebGL method activeTexture().
  4. Bind the texture to a target with WebGL method bindTexture().
  5. Tell the GPU how to store pixel data with WebGL method pixelStorei().
  6. Upload image data with WebGL method texImage2D().
  7. Assign wrapping modes with WebGL method texParameteri().
  8. Assign minification and magnification filters with WebGL method texParameteri().

WebGL API methods covered include getUniformLocation(), getAttribLocation(), vertexAttribPointer(), enableVertexAttribArray(), uniformi(), createTexture(), texParameteri(), activeTexture(), bindTexture(), pixelStorei(), and texImage2D().

WebGL Beginner's Guide Introduction WebGL Beginner's Guide
Copyright © 2015 Seven Thunder Software. All Rights Reserved.