Neatware Company

An ISV for Mobile, Cloud, and Video Technologies and Software.

Objects

MCL consists of some objects for 3D graphics. The relatioship of these objects are demostrated in the following diagram.

application is the root of other objects. You can think it as a game environment. shader is a child of application. Each shader can refer to its parent. And each shader may have three children: vertex, pixel, and texture. vertex object is an instance of vertex shader; pixel object is an instance of pixel shader; and texture is an instance of texture shader. In some shading language such as Cg the texture inherits from the pixel shader. The mesh object inherits from the application deals with the mesh procecessing. The vbuufer and ibuffer handle the vertex buffer and the index buffer. Finally, the light and material objects work for the lights and materials in the fixed-function shaders.

  • Application

    set app [MCL::application] creates an application object with the name app. Later you can use $app to call functions for the object. [$app create] will create a window with default position, size, and title. [$app run] starts running program in the windows message loop. [$app release] will release the resource of the application instance. [$app version vertex major minor] sets the required vertex version with major and minor.

  • Shader

    [$app shader asm] creates an asm shader that will execute vertex and pixel program in assembly. [$app shader cg path] creates a Cg shader that will execute vertex and pixel program in Cg. The path is the Cg path usually it is ..

  • Vertex

    The declaration specifies the stream, type and the allocation of registers.

      set Decl {{stream type0 register0 type1 register1 ...} ...}
    
    The stream is an integer index from 0. The type could be float, float2, float3, float4, etc. The register number specifies the index of register. for example
      set vtDecl {{0 float3 0 float3 3 float2 6}
                  {1 float3 1 float3 4 float2 7}
                  {2 float3 2 float3 5 float2 8}}
    
    Following statement creates an asm vertex shader,
      set vt [$asmShader vertex vshfile $vtDecl]
    
    The vertex means to create a vertex shader, it could be pixel to create a pixel shader. The vshfile is the file name includes the assembly vertex program. vtDecl is the declaration of the vertex stream.

    [$vt active] command will execute the vertex shader.

    To create a Cg vertex shader you are required to do

      set vt [$cgShader vertex vertexName [cgVertexProgram] cgDX8VertexProfile]
      $vt bind {m0 m1 v0 v1 ...}
    

    The vertexName is a string for the vertex shader. cgVertexProgram is a procedure name declares in MCL::procedure which includes Cg vertex code. cgDX8VertexProfile is the profile specification for DirectX 8 compatible drivers.

    [$vt bind ...] command build the binding among the Cg program and the MCL code.

  • Pixel
      set pl [$sh pixel pixelName [cgPixelProgram] cgDX8PixelProfile]
      $pl bind {arg0 arg1 ...}
      $pl active
    

    It creates a pixel shader pl with pixelName. The cgPixelProgram is the Cg pixel program declared in the MCL::procedure. cgDX8PixelProfile is the profile specification for DirectX 8. [$pl bind ...] will bind the arg0, arg1, ... to the pixel program.

  • Texture
      set tex [$asmShader texture picture] 
      [$tex set 0]
    

    texture command creates a texture object with the picture as the file name. [$tex set 0] will set texture object as texture with index 0. In the Cg shader you need to create a texture from a pixel shader. For example,

      set tex [$pl texture image0 image1 ...]
      $tex bind {tex0 tex1}
    

    $pl is the pixel shader object, it may create a list of textures with image0 and others. [$tex bind ...] binds the textures with the pixel shader program.

  • Mesh

    To handle the mesh, the [$app mesh xfile] command creates a x-file mesh object by opening a xfile. This command [$mesh setFVF {xyz normal tex1}] clones the old mesh vertex and index buffer with the new vertex definition by FVF argument. xyz represents the position of with vector float3. normal is the noraml vector, and the tex1 is the 2 dimentional texture coordinates.

    Furthermore, [$mesh vlock] and [$mesh ilock] lock the vertex and index buffers respectively. And the [$mesh vunlock] and [$mesh iunlock] unlock the vertex and index buffers.

      [$mesh vcopy [$vbuffer getBuffer] verticesSize
      [$mesh icopy [$ibuffer getBuffer] faceSize
    

    The first command copies vertex buffer from the mesh to the vertex buffer of [$vbuffer getBuffer]. The verticesSize is the verttice size. The second command copies index buffer from the mesh to the index buffer of [$ibuffer getBuffer].

  • Vertex buffer
      set vb [$app vbuffer numOfVertices verticeSize writeonly fvf managed]
    

    Above [$app vbuffer ...] command creates a new vertex buffer with the number of vertices and the vertice size. writeonly specifies that the vbuffer is for write purpose. You may refer to DX8 document for details. The FVF is the FVF dword value in DX8. When it is 0 the vbuffer is created as a dynamic buffer. The managed specifies that the vetext buffer could be in the main memory or video memory for optimization.

    [$vbuffer lock] and [$vbuffer unlock] are used to lock and unlock the vertex buffer.

  • Index buffer
      [$app ibuffer nNumOfFaceSize writeonly index16 managed]
    

    Above [$app ibuffer ...] command creates a new index buffer with the number of surface faces. writeonly specifies that the index buffer is for write. index16 specifies that the index is a 16-bit integer. It could index32 for 32-bit integer. The managed specefies that the index buffer could be allocated in main memory or video memory.

    [$ibuffer lock] and [$ibuffer unlock] commands are used to lock and unlock the index buffer.

  • Light
      set lit [$app light directional 0.0 1.0 1.0]
    

    Above command creates a directional light lit in position vector <0.0, 1.0, 1.0>. [$lit set 0] sets the lit as first light. [$lit enable true] makes the light enable. When you using the pixel shader you can ignore this fixed-function lighting.

  • Material
      set mtrl [$app material 1.0 1.0 1.0 1.0]
      $mtrl set
    

    These two commands will create a material mtrl with float4 vector <1.0, 1.0, 1.0, 1.0> and sets it with [$mtrl set] command.