📄 vgpcodegen.c
字号:
GLES_VGP_SWIZ1(&pui32VGPCode, VGP_MOV, VGP_DEST_R8, VGP_DMASK_W, VGP_MAT_SHININESS, VGP_SWIZ_ALL_X);
/* r2 = r2 + distance attenuation * colour-material ambient * light ambient */
GLES_VGP3(&pui32VGPCode, VGP_MAD, VGP_DEST_R2, VGP_DMASK_ALL, VGP_SRC_R5,
VGP_LIGHT_AMBIENT | VGP_SRC_CADDR_REL, VGP_SRC_R2);
/* r5 = distance attenuation * colour/material diffuse */
GLES_VGP2(&pui32VGPCode, VGP_MUL, VGP_DEST_R5, VGP_DMASK_ALL, VGP_SRC_R11, VGP_SRC_R7);
/* After execution of the lit instruction:
r8.y = diffuse lighting term (or 0)
r8.z = specular lighting term (or 0)
*/
GLES_VGP1(&pui32VGPCode, VGP_LIT, VGP_DEST_R8, VGP_DMASK_ALL, VGP_SRC_R8);
/* r5 = distance attenuation * colour-material diffuse * light Diffuse */
GLES_VGP2(&pui32VGPCode, VGP_MUL, VGP_DEST_R5, VGP_DMASK_ALL, VGP_SRC_R5, VGP_LIGHT_DIFFUSE | VGP_SRC_CADDR_REL);
/* r2 = dot (r8.y) * distance attenuation * colour/material diffuse * light diffuse + r2 */
GLES_VGP_SWIZ3(&pui32VGPCode, VGP_MAD, VGP_DEST_R2, VGP_DMASK_ALL, VGP_SRC_R8, VGP_SWIZ_ALL_Y, VGP_SRC_R5,
VGP_SWIZ_NONE, VGP_SRC_R2, VGP_SWIZ_NONE);
/* r5 = distance attenuation * material specular * light specular */
GLES_VGP2(&pui32VGPCode, VGP_MUL, VGP_DEST_R5, VGP_DMASK_ALL, VGP_SRC_R13, VGP_SRC_R7);
GLES_VGP2(&pui32VGPCode, VGP_MUL, VGP_DEST_R5, VGP_DMASK_ALL, VGP_SRC_R5, VGP_LIGHT_SPECULAR | VGP_SRC_CADDR_REL);
/* a0 = new relative addressing offset for next light */
GLES_VGP1(&pui32VGPCode, VGP_AMV, VGP_DEST_R1, VGP_DMASK_ALL, VGP_SRC_R12);
/* r3 = specular lighting term (r8.z) * material specular * light specular + r3 */
GLES_VGP_SWIZ3(&pui32VGPCode, VGP_MAD, VGP_DEST_R3, VGP_DMASK_ALL, VGP_SRC_R8, VGP_SWIZ_ALL_Z, VGP_SRC_R5,
VGP_SWIZ_NONE, VGP_SRC_R3, VGP_SWIZ_NONE);
VGP_SECTION_END()
pui32VGPSectionDefinitions[ui32SectionNum++] = VGP_SECTIONDEF_STARTADDR(ui32SectionStartAddress) |
VGP_SECTIONDEF_ENDADDR(ui32SectionEndAddress) |
VGP_SECTIONDEF_EXECOUNT(1) |
VGP_SECTIONDEF_CONST_OFFSET(VGP_MATERIAL_START) |
VGP_SECTIONDEF_CONST_END(VGP_FIXED_CONSTANTS_END);
/*
Section 8: Lighting output:
Base colour = base + offset
Base alpha = material diffuse alpha
*/
gui32ConstantRemap = VGP_CONSTANT_REMAP(VGP_MATERIAL_START);
VGP_SECTION_START()
GLES_VGP_SWIZ2(&pui32VGPCode, VGP_ADD, VGP_OUT_BASE, VGP_DMASK_ALL, VGP_SRC_R3, VGP_SWIZ_COLOR,
VGP_SRC_R2, VGP_SWIZ_COLOR);
GLES_VGP1(&pui32VGPCode, VGP_MOV, VGP_OUT_BASE, VGP_DMASK_W, VGP_MAT_DIFFUSE);
VGP_SECTION_END()
pui32VGPSectionDefinitions[ui32SectionNum++] = VGP_SECTIONDEF_STARTADDR(ui32SectionStartAddress) |
VGP_SECTIONDEF_ENDADDR(ui32SectionEndAddress) |
VGP_SECTIONDEF_EXECOUNT(1) |
VGP_SECTIONDEF_CONST_OFFSET(VGP_MAT_DIFFUSE) |
VGP_SECTIONDEF_CONST_END(VGP_MAT_DIFFUSE);
/*
Sections 9-12: Pass through :
*/
/* Section 9: XYZW */
VGP_SECTION_START()
GLES_VGP1(&pui32VGPCode, VGP_MOV, VGP_OUT_POS, VGP_DMASK_ALL, VGP_SRC_V(VGP_VERTEX_POS));
GLES_VGP_SWIZ1(&pui32VGPCode, VGP_MOV, VGP_OUT_BASE, VGP_DMASK_ALL,
VGP_SRC_V(VGP_VERTEX_BASECOL), VGP_SWIZ_COLOR);
VGP_SECTION_END()
pui32VGPSectionDefinitions[ui32SectionNum++] = VGP_SECTIONDEF_STARTADDR(ui32SectionStartAddress) |
VGP_SECTIONDEF_ENDADDR(ui32SectionEndAddress) |
VGP_SECTIONDEF_EXECOUNT(1) |
VGP_SECTIONDEF_CONST_OFFSET(128) |
VGP_SECTIONDEF_CONST_END(0);
/* Sections 10->11 textures */
VGP_SECTION_START()
GLES_VGP1(&pui32VGPCode, VGP_MOV, VGP_OUT_TEX0, VGP_DMASK_ALL, VGP_SRC_V(VGP_VERTEX_TEX_START));
VGP_SECTION_END()
pui32VGPSectionDefinitions[ui32SectionNum++] = VGP_SECTIONDEF_STARTADDR(ui32SectionStartAddress) |
VGP_SECTIONDEF_ENDADDR(ui32SectionEndAddress) |
VGP_SECTIONDEF_EXECOUNT(1) |
VGP_SECTIONDEF_CONST_OFFSET(128) |
VGP_SECTIONDEF_CONST_END(0);
VGP_SECTION_START()
GLES_VGP1(&pui32VGPCode, VGP_MOV, VGP_OUT_TEX1, VGP_DMASK_ALL, VGP_SRC_V(VGP_VERTEX_TEX_START+1));
VGP_SECTION_END()
pui32VGPSectionDefinitions[ui32SectionNum++] = VGP_SECTIONDEF_STARTADDR(ui32SectionStartAddress) |
VGP_SECTIONDEF_ENDADDR(ui32SectionEndAddress) |
VGP_SECTIONDEF_EXECOUNT(1) |
VGP_SECTIONDEF_CONST_OFFSET(128) |
VGP_SECTIONDEF_CONST_END(0);
gui32ConstantRemap = VGP_CONSTANT_REMAP(VGP_TEX_MATRIX0_START);
/* Section 12: Texture matrix 0 */
VGP_SECTION_START()
GLES_VGP2(&pui32VGPCode, VGP_DP4, VGP_OUT_TEX0, VGP_DMASK_X, VGP_SRC_V(VGP_VERTEX_TEX_START), VGP_TEX_MATRIX00);
GLES_VGP2(&pui32VGPCode, VGP_DP4, VGP_OUT_TEX0, VGP_DMASK_Y, VGP_SRC_V(VGP_VERTEX_TEX_START), VGP_TEX_MATRIX01);
VGP_SECTION_END()
pui32VGPSectionDefinitions[ui32SectionNum++] = VGP_SECTIONDEF_STARTADDR(ui32SectionStartAddress) |
VGP_SECTIONDEF_ENDADDR(ui32SectionEndAddress) |
VGP_SECTIONDEF_EXECOUNT(1) |
VGP_SECTIONDEF_CONST_OFFSET(VGP_TEX_MATRIX0_START) |
VGP_SECTIONDEF_CONST_END(VGP_TEX_MATRIX0_END);
gui32ConstantRemap = VGP_CONSTANT_REMAP(VGP_TEX_MATRIX1_START);
/* Section 13: Texture matrix 1 */
VGP_SECTION_START()
GLES_VGP2(&pui32VGPCode, VGP_DP4, VGP_OUT_TEX1, VGP_DMASK_X, VGP_SRC_V(VGP_VERTEX_TEX_START + 1), VGP_TEX_MATRIX10);
GLES_VGP2(&pui32VGPCode, VGP_DP4, VGP_OUT_TEX1, VGP_DMASK_Y, VGP_SRC_V(VGP_VERTEX_TEX_START + 1), VGP_TEX_MATRIX11);
VGP_SECTION_END()
pui32VGPSectionDefinitions[ui32SectionNum++] = VGP_SECTIONDEF_STARTADDR(ui32SectionStartAddress) |
VGP_SECTIONDEF_ENDADDR(ui32SectionEndAddress) |
VGP_SECTIONDEF_EXECOUNT(1) |
VGP_SECTIONDEF_CONST_OFFSET(VGP_TEX_MATRIX1_START) |
VGP_SECTIONDEF_CONST_END(VGP_TEX_MATRIX1_END);
/*
Sections 14-15: Fog factor calculation
--------------------------------------
Register usage:
r5,r6 - Temp
r9 - Eye Z
FOG PARAMS: (End, 1/End-Start, Density/Log 2, Density/sqrt(Log2))
*/
gui32ConstantRemap = VGP_CONSTANT_REMAP(VGP_FOG_PARAMS_START);
/* Section 14: Fog linear */
VGP_SECTION_START()
GLES_VGP_SWIZ2(&pui32VGPCode, VGP_ADD, VGP_DEST_R5, VGP_DMASK_ALL, VGP_FOG_PARAMS, VGP_SWIZ_ALL_X,
VGP_NEGATE(VGP_SRC_R9), VGP_SWIZ_NONE);
GLES_VGP_SWIZ2(&pui32VGPCode, VGP_MUL, VGP_OUT_OFFSET, VGP_DMASK_W, VGP_FOG_PARAMS, VGP_SWIZ_ALL_Y,
VGP_SRC_R5, VGP_SWIZ_NONE);
VGP_SECTION_END()
pui32VGPSectionDefinitions[ui32SectionNum++] = VGP_SECTIONDEF_STARTADDR(ui32SectionStartAddress) |
VGP_SECTIONDEF_ENDADDR(ui32SectionEndAddress) |
VGP_SECTIONDEF_EXECOUNT(1) |
VGP_SECTIONDEF_CONST_OFFSET(VGP_FOG_PARAMS_START) |
VGP_SECTIONDEF_CONST_END(VGP_FOG_PARAMS_END);
gui32ConstantRemap = VGP_CONSTANT_REMAP(VGP_FOG_PARAMS_START);
/* Section 15: Fog EXP, EXP2 */
VGP_SECTION_START()
GLES_VGP_SWIZ2(&pui32VGPCode, VGP_MUL, VGP_DEST_R5, VGP_DMASK_ALL, VGP_FOG_PARAMS, VGP_SWIZ_ALL_Z,
VGP_SRC_R9, VGP_SWIZ_NONE);
GLES_VGP1(&pui32VGPCode, VGP_EXP, VGP_DEST_R6, VGP_DMASK_W, VGP_NEGATE(VGP_SRC_R5));
GLES_VGP_SWIZ2(&pui32VGPCode, VGP_MUL, VGP_DEST_R5, VGP_DMASK_ALL, VGP_FOG_PARAMS, VGP_SWIZ_ALL_W,
VGP_SRC_R9, VGP_SWIZ_NONE);
GLES_VGP_SWIZ2(&pui32VGPCode, VGP_MUL, VGP_DEST_R6, VGP_DMASK_ALL, VGP_SRC_R6, VGP_SWIZ_NONE,
VGP_FOG_IS_EXP2, VGP_SWIZ_ALL_Y);
GLES_VGP2(&pui32VGPCode, VGP_MUL, VGP_DEST_R5, VGP_DMASK_ALL, VGP_SRC_R5, VGP_SRC_R5);
GLES_VGP_SWIZ1(&pui32VGPCode, VGP_EXP, VGP_DEST_R5, VGP_DMASK_W, VGP_NEGATE(VGP_SRC_R5), VGP_SWIZ_NONE);
GLES_VGP_SWIZ3(&pui32VGPCode, VGP_MAD, VGP_OUT_OFFSET, VGP_DMASK_W, VGP_SRC_R5, VGP_SWIZ_NONE,
VGP_FOG_IS_EXP2, VGP_SWIZ_ALL_X, VGP_SRC_R6, VGP_SWIZ_NONE);
VGP_SECTION_END()
pui32VGPSectionDefinitions[ui32SectionNum++] = VGP_SECTIONDEF_STARTADDR(ui32SectionStartAddress) |
VGP_SECTIONDEF_ENDADDR(ui32SectionEndAddress) |
VGP_SECTIONDEF_EXECOUNT(1) |
VGP_SECTIONDEF_CONST_OFFSET(VGP_FOG_PARAMS_START) |
VGP_SECTIONDEF_CONST_END(VGP_FOG_PARAMS_END);
/* Return the size of the VGP program */
gui32VGPProgramSize = (IMG_UINT32)(pui32VGPCode - pui32VGPCodeBase);
}
int main()
{
IMG_UINT32 ui32Count=0,ui32Count2=0;
FILE *stream;
IMG_CHAR pszRevision[40];
#if defined(SUPPORT_VGP)
stream = fopen("vgpcode.h", "wt");
strncpy(pszRevision,VGPCODE_DRIVER_REV+1, strlen(VGPCODE_DRIVER_REV));
#else
stream = fopen("vgplitecode.h", "wt");
strncpy(pszRevision,VGPCODE_DRIVER_REV_LITE+1, strlen(VGPCODE_DRIVER_REV_LITE));
#endif
if(!stream)
return 1;
fprintf(stream,"/***************************************************************************************\n");
fprintf(stream,"* Title : VGP code for fixed function TNL on MBX *\n");
fprintf(stream,"* *\n");
fprintf(stream,"* Copyright : 2003-2004 by Imaginations Technologies Limited. All rights reserved. *\n");
fprintf(stream,"* No part of this software, either material or conceptual *\n");
fprintf(stream,"* may be copied or distributed, transmitted, transcribed, *\n");
fprintf(stream,"* stored in a retrieval system or translated into any *\n");
fprintf(stream,"* human or computer language in any form by any means, *\n");
fprintf(stream,"* electronic, mechanical, manual or other-wise, or *\n");
fprintf(stream,"* disclosed to third parties without the express written *\n");
fprintf(stream,"* permission of Imaginations Technologies Limited, HomePark *\n");
fprintf(stream,"* Industrial Estate, King's Langley, Hertfordshire, *\n");
fprintf(stream,"* WD4 8LZ, U.K. *\n");
fprintf(stream,"* *\n");
fprintf(stream,"* *\n");
fprintf(stream,"* This is an autogenerated file (by vgpcodegen). DO NOT EDIT! *\n");
fprintf(stream,"****************************************************************************************/\n\n\n");
fprintf(stream,"/* VGP code from vgpcodegen %s */\n\n",pszRevision);
fprintf(stream,"/*\nBasic Transformation and Lighting VGP Code for an INFINITE viewer\n");
fprintf(stream,"-----------------------------------------------------------------\n\n");
fprintf(stream,"VGP code to perform basic transformation and lighting for an infinite viewer\n\n");
fprintf(stream,"Sections\n--------\n");
fprintf(stream,"0 -> Transform position to clip-space, do front/back clip\n");
fprintf(stream,"1 -> Transform position to eye-space\n");
fprintf(stream,"2 -> User clip planes\n");
fprintf(stream,"3 -> Lighting set-up, Colour Material setup & global lighting\n");
fprintf(stream,"4 -> Normalise normal\n");
fprintf(stream,"5 -> Infinite lights\n");
fprintf(stream,"6 -> Point lights\n");
fprintf(stream,"7 -> Spot lights\n");
fprintf(stream,"8 -> Lighting output\n");
fprintf(stream,"9 -> Pass through position\n");
fprintf(stream,"10 -> Pass through texture layers 0\n");
fprintf(stream,"11 -> Pass through texture layers 1\n");
fprintf(stream,"12 -> Texture matrices transform 0\n");
fprintf(stream,"13 -> Texture matrices transform 1\n");
fprintf(stream,"14 -> Fog linear\n");
fprintf(stream,"15 -> Fog exp/exp2\n");
fprintf(stream,"\nConstants\n---------\nSee vgp.h\n\n");
fprintf(stream,"Register usage\n--------------\n");
fprintf(stream,"r0 -> Transformed vertex\n");
fprintf(stream,"r1 -> Transformed normal (normalised, if required)\n");
fprintf(stream,"r2 -> Accumulating base colour\n");
fprintf(stream,"r3 -> Clip-space vertex position/Accumulating specular colour\n");
fprintf(stream,"r4 -> Eye->vertex vector\n");
fprintf(stream,"r5-r8 -> Various uses\n");
fprintf(stream,"r9 -> Eye Z\n");
fprintf(stream,"r10 -> Colour Material ambient\n");
fprintf(stream,"r11 -> Colour Material diffuse\n");
fprintf(stream,"r12 -> Constant relative addressing amount\n\n*/\n\n");
#if defined(SUPPORT_VGP)
fprintf(stream,"#ifndef _VGPCODE_H_\n");
fprintf(stream,"#define _VGPCODE_H_\n\n\n");
#else
fprintf(stream,"#ifndef _VGPLITECODE_H_\n");
fprintf(stream,"#define _VGPLITECODE_H_\n\n\n");
#endif
fprintf(stream,"extern IMG_CHAR * GetVGPCodeRev(IMG_VOID);\n\n");
#if defined(SUPPORT_VGP)
fprintf(stream,"#if defined(SUPPORT_VGP)\n\n");
#else
fprintf(stream,"#if defined(SUPPORT_VGP_LITE)\n\n");
#endif
fprintf(stream,"#define VGPCODE_HEADER_REV \"%s\"\n\n",pszRevision);
SetupVGPCode();
fprintf(stream,"const static IMG_UINT32 gaui32VGPSectionDefinitions[] = {\n");
for(ui32Count=0,ui32Count2 = 1; ui32Count < VGP_FF_TNL_NUM_SECTIONS; ui32Count++, ui32Count2++)
{
fprintf(stream, "0x%08lx,\t", gaui32VGPSectionDefinitions[ui32Count]);
if(ui32Count2 > 9)
{
ui32Count2 = 0;
fprintf(stream, "\n");
}
}
fprintf(stream,"0};\n\n\n\n");
fprintf(stream,"const static IMG_UINT32 gui32VGPCodeSize = %lu;\n\n", gui32VGPProgramSize);
fprintf(stream,"const static IMG_UINT32 gaui32VGPCode[] = {\n");
for(ui32Count = 0, ui32Count2 = 1; ui32Count < gui32VGPProgramSize; ui32Count++, ui32Count2++)
{
fprintf(stream, "0x%08lx,\t", gaui32VGPProgram[ui32Count]);
if(ui32Count2 > 9)
{
ui32Count2 = 0;
fprintf(stream, "\n");
}
}
fprintf(stream,"0};\n\n\n\n");
fprintf(stream,"#endif /* SUPPORT_VGP */\n\n");
fprintf(stream,"#endif /* _VGP_CODE_H_ */\n\n");
fclose(stream);
return 0;
}
#else /* GENERATE_VGPCODE */
IMG_CHAR *GetVGPCodeRev(IMG_VOID)
{
#if defined(SUPPORT_VGP)
return (VGPCODE_DRIVER_REV+1);
#else
return (VGPCODE_DRIVER_REV_LITE+1);
#endif
}
#endif /* GENERATE_VGPCODE */
#endif /* SUPPORT_VGP || SUPPORT_VGP_LITE */
/***************************************************************************
End of file (vgpcodegen.c)
***************************************************************************/
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -