Ogre Gpuprogram Analysis

Source: Internet
Author: User

As explained in the previous compositor, Gpuprogram also corresponds to a resource file, meaning we can directly write a file to complete, do not need to know the relevant classes. But just like WinForm, the direct drag control can do most of the work, if we need to manually customize the corresponding control, the corresponding class and attributes need to understand, or we look at the ogre in the example of deferred rendering (deferredshading), you will find that can not understand.

Gpuprogram more important is the Gpuprogramparameters object, which encapsulates the shader's parameter settings.

from the shader language, the parameters are mainly distinguished from the advanced shader language and the assembly shader language. There are also some common parameters, such as the MVP matrix, that are used internally by Ogre. This part of the parameter is also individually encapsulated so that the ogre is automatically updated internally.

Ogre Internal Management parameter encapsulation.

Autoconstantdefinition: Defines some parameter definitions built into the ogre, such as Word_matrix,view_matrix ... such as.

actype: Parameter ID, which indicates the position of the parameter in all indexes that are predefined by ogre.

name: Parameter name. Word_matrix.

elementcount: contains more than one element, such as Word_matrix is a matrix of 4*4, it should be 16 elements.

elementtype: Indicates that the element type, such as the element in Word_matrix, should be float. It seems like most of them are float. , it is rare to see the type int.

datatype: Indicates the type of additional parameters required to update an element, with three kinds, none,int,real, such as World_ The matrix does not require additional parameters, it uses none, and then the attributes that involve light and texture, such as light_diffuse_colour,texture_size, are all int, because this is typically multiple, and int indicates the current index. and time,time_0_ x requires an additional float parameter to specify the period, then the type is real, you can refer to axiom3d: Manually create Manualobject and mesh, and how to use the CG shader language  

Autoconstantentry: Contains the parameter settings of the autoconstantdefinition specified ogre, the parameters are stored in the location, the number of parameters, the parameters need to update additional data. Visibility.

The paramtype:autoconstantdefinition type that specifies the parameter definition.

Physicalindex: It is important to specify where the data is stored in the ogre, and then say it carefully.

Elementcount: The number of elements currently contained.

Data/fdata: Corresponds to data,real corresponding to the Datatype,int type in the above Autoconstantdefinition FData.

Variability: Corresponds to the current element's range.

Advanced Shader Language parameter encapsulation.

Gpuconstantdefinition: Above autoconstantdefinition and Autoconstantentry indicated is ogre predefined corresponding parameter, does not need the user to update, And if the user wants to define their own parameters, use this representation.

Consttype: Data type, Float,float4,matrix4*4,sampler.

Physicalindex: As in Autoconstantentry, specify the position of the data in the list.

Association between Logicalindex:rendersystem and Physicalindex.

ElementSize: A 4-byte representation of a length, such as Float,int for 1,FLOAT4 4, if it is D3D open SM1, then the shortest 4 lengths, meaning Float,float4,int,int4 are all 4, Aligns with a minimum length of 4. See the Getelementsize method for calculations.

Variability: The element is in the same range.

Gpunamedconstants:gpuconstantdefinition with the dictionary corresponding to name, corresponding to the Float,int list of all lengths.

Assembly Shader Language parameter encapsulation

Gpulogicalindexuse: Records the parameters defined in the assembly shader language, corresponding to the gpuconstantdefinition in the advanced shader language.

Phsicalindex: Specifies the position of the data in the list.

CurrentSize: Specifies the current parameter size.

Variability: The element is in the same range

Gpulogicalindexusemap:logicalindex logical position corresponds to Gpulogicalindexuse dictionary.

Gpulogicalbufferstruct:gpulogicalindexusemap object with buffersize (buffer length), corresponding to gpunamedconstants.

Gpuprogramparameters description

Gpuprogramparameters: Encapsulates all parameters, following the description of some of the main properties.

Characters commonly used segment

Autoconstantdictionary:autoconstantdefinition a static array that contains all the parameter definitions built into the ogre.

The vector type of mautoconstants:autoconstantentry. Parameters that correspond to all ogre automatically managed.

The mnamedconstants:gpunamedconstants type, which corresponds to all advanced shader parameter settings.

Mfloatlogicaltophysical,mintlogicaltophysical: gpulogicalbufferstruct type, corresponding to the set of parameters in the assembly shader.

Mfloatconstants,mintconstants: An array of vector types corresponding to the float,int, whether assembled or advanced, the built-in parameter data is included here.

Method

_writerawconstants: Writes mfloatconstants and Mintconstants , respectively, according to the actual location passed in.

_getfloatconstantlogicalindexuse: The assembly shader parameter is based on the actual location to find the logical location.

_getfloatconstantphysicalindex: Assembly shader Parameters find the actual location based on the logical location.

SetConstant: Update assembly parameters, require incoming logical location and updated data, we need to call Getfloatconstantphysicalindex to convert the logical location to the actual location, and then call _writerawconstants.

setnamedconstant: Update the advanced shader parameters, according to the incoming name, find the corresponding mnamedconstants object, get actual position, call _writerawconstants.

setautoconstant: And above setconstant according to incoming parameters , indicate that this location is managed by ogre that internal parameter Note that this time does not update the corresponding mfloatconstants etc., but put mautoconstants.

Setnamedautoconstant: As with setautoconstant, locate the location according to the name and put it in the mautoconstants.

_updateautoparams: The above setautoconstant and setnamedautoconstant do not update the data, just indicate that the corresponding actual location is managed by the ogre that internal parameter, and this method, To update the corresponding data, like setconstant,setnamedconstant called _writerawconstants. Note This method is automatically called by Ogre per frame.

In addition Gpuprogramparameters is generally specified with Gpusharedparameters gpusharedparametersusage, because we sometimes have some shader code with the same parameter settings, so that, The common part can be expressed in gpusharedparameters, and the corresponding gpusharedparameters do not need to be updated for these parameters.

Gpuprogram Description: Characters commonly used section

Gpuprogram corresponds to a resource file, we can see that some fields correspond directly to the definition in the resource.

Mtype: Indicates what type of shader is, mainly vertex, geometry, fragment.

Mfilename: The resource file name in which the shader code is stored.

Msource: If the user has generated the shader code, the corresponding shader code can be written to this property.

Mloadformfile: Whether the shader code is stored in a resource file or customized by the user.

Msyntaxcode: The hardware settings required by the shader.

The Mdefaultparams:gpuprogramparameters reference calculates the pointer type and manages the parameters in the shader program.

Mconstantdefs,mfloatlogicaltophysical,mintlogicaltophysical: Shader parameter settings, generally point to the corresponding mdefaultparams share the same parameters.

Method

Createparameters: Creates a reference calculation pointer to the gpuprogramparameters.

Getdefaultparameters: Returns Mdefaultparams and, if empty, calls Createparameters.

GetLanguage: Returns what shader language, such as Hlsl,glsl,cg,asm.

Setmanualnamedconstants: Sets the parameters according to the incoming gpunamedconstants.

Loadfromsource: Abstract method.

Highlevelgpuprogram description characters commonly used segment

Mhighlevelloaded: Whether the advanced shader code is already loaded.

Massemblerprogram: Corresponds to assembly shader code.

Mconstantdefsbuilt: Whether the shader parameter has been loaded.

Method

Loadhighlevel: Load advanced shader code to unify advanced shader common logic.

Loadhighlevelimpl: Abstract methods, subclass objects need to instantiate this method. Corresponds to each advanced shader language loading logic.

Createparameters: Creates a gpuprogramparameters reference pointer to the shared object. If hardware is supported, call the following buildconstantdefinitions.

Buildconstantdefinitions: Abstract method to get advanced shader parameter information. Mainly mconstantdefs,mfloatlogicaltophysical, Mintlogicaltophysical.

Getconstantdefinitions: Get advanced shader parameter information. Above these.

Populateparameternames: Assigns the parameter information that buildconstantdefinitions obtains to mdefaultparams. It means associated sharing . Mdefaultparams with the corresponding Gpuprogram mconstantdefs,mfloatlogicaltophysical,mintlogicaltophysical.

Cg Gpuprogram Loading process:

In combination with the above class description, we choose an advanced shading language, combining all the elements of the above class together to see the loading process, as the CG shader file loading process:

Ogre Gpuprogram Analysis

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.