# Buffer block

The small game framework provides a mesh Mesh to store vertex data that is almost unchanged in rendering, but there are some data that may need to change every frame, and these data have significant characteristics:

  1. The amount of data is not large
  2. High flexibility, need to be able to make real-time low-overhead changes

In order to achieve these requirements, the mini game framework draws on the design of modern graphics interfaces and provides a buffer block UniformBlock.

# UniformDescriptor

Just as the vertex data needs VertexLayout to describe the structure, UniformBlock also needs something to describe its deconstruction, which is the buffer block descriptor UniformDescriptor:

const myUD = new engine.UniformDescriptor({
  uniforms: [
    {name:'u_color', type: engine.EUniformType.FLOAT4},
    {name:'u_texture', type: engine.EUniformType.SAMPLER},
  ]}
);

Here we create a descriptor, which means that the UniformBlock with this descriptor has two values ​​of u_color and u_texture, and their types are vector float4 and texture respectively (texture will be mentioned in a later chapter).

# Create and use

With UniformDescriptor, you can create UniformBlock directly:

const uniforms = new engine.UniformBlock(myUD);

However, in the framework of small games, developers are generally not asked to create it manually, but used in conjunction with other resources or components.

# Runtime

In the design of the mini game framework, UniformBlock is divided into three dimensions: global, object, and material.

This is actually very easy to understand. For the rendering of an object, it needs to know some global information such as light, fog, observation location, and also need to know own location, light map, etc. Data, also need to know the material information such as color, texture.

The built-in global uniform is not open to developers to modify, but developers can customize their own global uniform, see Rendering System for details.

The customization of object uniform will be discussed in the chapter Renderer.

The customization of material uniform will be discussed in effects and materials.

# Shader中

After the material is set in the Runtime, it needs to be used in the Shader to complete the final drawing, and the developer must ensure the consistency of the two definitions in the Runtime and the Shader.

For details of this part, please refer to Shader.