📄 textool.c
字号:
/*****************************************************************************
Name : Textool.C
Title : Texture stage lookup table generation
C Author : Ben Bowman
Created : 27/11/2003
Copyright : 2003 by Imaginations Technologies Limited. All rights reserved.
No part of this software, either material or conceptual
may be copied or distributed, transmitted, transcribed,
stored in a retrieval system or translated into any
human or computer language in any form by any means,
electronic, mechanical, manual or other-wise, or
disclosed to third parties without the express written
permission of Imaginations Technologies Limited, HomePark
Industrial Estate, King's Langley, Hertfordshire,
WD4 8LZ, U.K.
Description : Tools for generating and using a lookup table for mapping
OGLES texture/alpha operations and arguments to HW control words.
Version : $Revision: 1.7 $
Modifications :
$Log: textool.c $
*****************************************************************************/
#include "img_defs.h"
#include "mbx13ddef.h"
#include "tstable.h"
#include <stdio.h>
/*
Mapping of HW color source codes to HW CS1 control (in TSPLLCtl3)
*/
static IMG_UINT32 ui32CS1ColorSourceTransLCtl3[] =
{
0, /* no Diffuse color for CS1 */
MBX1_TSPPL3_CS1SELCURRENT,
MBX1_TSPPL3_CS1SELTEXTURE,
MBX1_TSPPL3_CS1SELFACTOR,
0, /* no Diffuse Alpha for CS1 */
0, /* no Current Alpha for CS1 */
0, /* no Texture Alpha for CS1 */
0, /* no Factor Alpha for CS1 */
0, /* no Diffuse color for CS1 */
MBX1_TSPPL3_CS1SELCURRENT | MBX1_TSPPL3_INVCS1,
MBX1_TSPPL3_CS1SELTEXTURE | MBX1_TSPPL3_INVCS1,
MBX1_TSPPL3_CS1SELFACTOR | MBX1_TSPPL3_INVCS1,
0, /* no Diffuse Alpha for CS1 */
0, /* no Current Alpha for CS1 */
0, /* no Texture Alpha for CS1 */
0, /* no Factor Alpha for CS1 */
MBX1_TSPPL3_CS1SELONE,
MBX1_TSPPL3_CS1SELONE | MBX1_TSPPL3_INVCS1,
MBX1_TSPPL3_CS1SELCURRENT,
MBX1_TSPPL3_CS1SELCURRENT | MBX1_TSPPL3_INVCS1
};
/*
Mapping of color source codes to HW CS2 control (in TSPLCtl3)
*/
static IMG_UINT32 ui32CS2ColorSourceTransLCtl3[] =
{
MBX1_TSPPL3_CS2SELDIFFUSE,
MBX1_TSPPL3_CS2SELCURRENT,
MBX1_TSPPL3_CS2SELTEXTURE,
MBX1_TSPPL3_CS2SELFACTOR,
MBX1_TSPPL3_CS2SELDIFFUSEALPHA,
MBX1_TSPPL3_CS2SELCURRENTALPHA,
MBX1_TSPPL3_CS2SELTEXTUREALPHA,
MBX1_TSPPL3_CS2SELFACTORALPHA,
MBX1_TSPPL3_CS2SELDIFFUSE|MBX1_TSPPL3_INVCS2,
MBX1_TSPPL3_CS2SELCURRENT|MBX1_TSPPL3_INVCS2,
MBX1_TSPPL3_CS2SELTEXTURE|MBX1_TSPPL3_INVCS2,
MBX1_TSPPL3_CS2SELFACTOR|MBX1_TSPPL3_INVCS2,
MBX1_TSPPL3_CS2SELDIFFUSEALPHA|MBX1_TSPPL3_INVCS2,
MBX1_TSPPL3_CS2SELCURRENTALPHA|MBX1_TSPPL3_INVCS2,
MBX1_TSPPL3_CS2SELTEXTUREALPHA|MBX1_TSPPL3_INVCS2,
MBX1_TSPPL3_CS2SELFACTORALPHA|MBX1_TSPPL3_INVCS2,
0, /* no ONE for CS2 */
0, /* no ONE for CS2 */
MBX1_TSPPL3_CS2SELDIFFUSE,
MBX1_TSPPL3_CS2SELDIFFUSE|MBX1_TSPPL3_INVCS2
};
/*
Mapping of color source codes to HW CS3 control (in TSPLCtl1)
*/
static IMG_UINT32 ui32CS3ColorSourceTransLCtl3[] =
{
MBX1_TSPPL3_CS3SELDIFFUSE,
MBX1_TSPPL3_CS3SELCURRENT,
MBX1_TSPPL3_CS3SELTEXTURE,
0, /* no Factor color for CS3 */
0, /* no Diffuse Alpha for CS3 */
0, /* no Current Alpha for CS3 */
0, /* no Texture Alpha for CS3 */
0, /* no Factor Alpha for CS3 */
MBX1_TSPPL3_CS3SELDIFFUSE | MBX1_TSPPL3_INVCS3,
MBX1_TSPPL3_CS3SELCURRENT | MBX1_TSPPL3_INVCS3,
MBX1_TSPPL3_CS3SELTEXTURE | MBX1_TSPPL3_INVCS3,
0, /* no Factor color for CS3 */
0, /* no Diffuse Alpha for CS3 */
0, /* no Current Alpha for CS3 */
0, /* no Texture Alpha for CS3 */
0, /* no Factor Alpha for CS3 */
MBX1_TSPPL3_CS3SELONE,
MBX1_TSPPL3_CS3SELONE | MBX1_TSPPL3_INVCS3,
MBX1_TSPPL3_CS3SELDIFFUSE,
MBX1_TSPPL3_CS3SELDIFFUSE | MBX1_TSPPL3_INVCS3
};
/*
Mapping of color source codes to HW CS4 control (in TSPLCtl3)
*/
static IMG_UINT32 ui32CS4ColorSourceTransLCtl3[] =
{
MBX1_TSPPL3_CS4SELDIFFUSE,
MBX1_TSPPL3_CS4SELCURRENT,
MBX1_TSPPL3_CS4SELTEXTURE,
MBX1_TSPPL3_CS4SELFACTOR,
MBX1_TSPPL3_CS4SELDIFFUSEALPHA,
MBX1_TSPPL3_CS4SELCURRENTALPHA,
MBX1_TSPPL3_CS4SELTEXTUREALPHA,
MBX1_TSPPL3_CS4SELFACTORALPHA,
MBX1_TSPPL3_CS4SELDIFFUSE|MBX1_TSPPL3_INVCS4,
MBX1_TSPPL3_CS4SELCURRENT|MBX1_TSPPL3_INVCS4,
MBX1_TSPPL3_CS4SELTEXTURE|MBX1_TSPPL3_INVCS4,
MBX1_TSPPL3_CS4SELFACTOR|MBX1_TSPPL3_INVCS4,
MBX1_TSPPL3_CS4SELDIFFUSEALPHA|MBX1_TSPPL3_INVCS4,
MBX1_TSPPL3_CS4SELCURRENTALPHA|MBX1_TSPPL3_INVCS4,
MBX1_TSPPL3_CS4SELTEXTUREALPHA|MBX1_TSPPL3_INVCS4,
MBX1_TSPPL3_CS4SELFACTORALPHA|MBX1_TSPPL3_INVCS4,
0, /* no ONE for CS2 */
0, /* no ONE for CS2 */
MBX1_TSPPL3_CS4SELDIFFUSE,
MBX1_TSPPL3_CS4SELDIFFUSE|MBX1_TSPPL3_INVCS4
};
/*
Mapping of alpha source codes to HW AS1 control (in TSPLLCtl3)
*/
static IMG_UINT32 ui32AS1AlphaSourceTransLCtl3[] =
{
MBX1_TSPPL3_AS1SELDIFFUSEALPHA,
MBX1_TSPPL3_AS1SELCURRENTALPHA,
MBX1_TSPPL3_AS1SELTEXTUREALPHA,
0, /* no Factor alpha for AS1 */
MBX1_TSPPL3_AS1SELDIFFUSEALPHA|MBX1_TSPPL3_INVAS1,
MBX1_TSPPL3_AS1SELCURRENTALPHA|MBX1_TSPPL3_INVAS1,
MBX1_TSPPL3_AS1SELTEXTUREALPHA|MBX1_TSPPL3_INVAS1,
0, /* no Factor alpha for AS1 */
MBX1_TSPPL3_AS1SELONE,
MBX1_TSPPL3_AS1SELONE|MBX1_TSPPL3_INVAS1,
MBX1_TSPPL3_AS1SELCURRENTALPHA,
MBX1_TSPPL3_AS1SELCURRENTALPHA|MBX1_TSPPL3_INVAS1
};
/*
Mapping of alpha source codes to HW AS2 control (in TSPLLCtl3)
*/
static IMG_UINT32 ui32AS2AlphaSourceTransLCtl3[] =
{
MBX1_TSPPL3_AS2SELDIFFUSEALPHA,
MBX1_TSPPL3_AS2SELCURRENTALPHA,
MBX1_TSPPL3_AS2SELTEXTUREALPHA,
MBX1_TSPPL3_AS2SELFACTORALPHA,
MBX1_TSPPL3_AS2SELDIFFUSEALPHA|MBX1_TSPPL3_INVAS2,
MBX1_TSPPL3_AS2SELCURRENTALPHA|MBX1_TSPPL3_INVAS2,
MBX1_TSPPL3_AS2SELTEXTUREALPHA|MBX1_TSPPL3_INVAS2,
MBX1_TSPPL3_AS2SELFACTORALPHA|MBX1_TSPPL3_INVAS2,
0, /* no ONE for AS2 */
0, /* no ONE for AS2 */
MBX1_TSPPL3_AS2SELDIFFUSEALPHA,
MBX1_TSPPL3_AS2SELDIFFUSEALPHA|MBX1_TSPPL3_INVAS2
};
/*
Mapping of alpha source codes to HW AS3 control (in TSPLLCtl3)
*/
static IMG_UINT32 ui32AS3AlphaSourceTransLCtl3[] =
{
MBX1_TSPPL3_AS3SELDIFFUSEALPHA,
MBX1_TSPPL3_AS3SELCURRENTALPHA,
MBX1_TSPPL3_AS3SELTEXTUREALPHA,
0, /* no Factor alpha for AS3 */
MBX1_TSPPL3_AS3SELDIFFUSEALPHA|MBX1_TSPPL3_INVAS3,
MBX1_TSPPL3_AS3SELCURRENTALPHA|MBX1_TSPPL3_INVAS3,
MBX1_TSPPL3_AS3SELTEXTUREALPHA|MBX1_TSPPL3_INVAS3,
0, /* no Factor alpha for AS3 */
MBX1_TSPPL3_AS3SELONE,
MBX1_TSPPL3_AS3SELONE|MBX1_TSPPL3_INVAS3,
MBX1_TSPPL3_AS3SELDIFFUSEALPHA,
MBX1_TSPPL3_AS3SELDIFFUSEALPHA|MBX1_TSPPL3_INVAS3
};
/*
Mapping of alpha source codes to HW AS4 control (in TSPLLCtl3)
*/
static IMG_UINT32 ui32AS4AlphaSourceTransLCtl3[] =
{
MBX1_TSPPL3_AS4SELDIFFUSEALPHA,
MBX1_TSPPL3_AS4SELCURRENTALPHA,
MBX1_TSPPL3_AS4SELTEXTUREALPHA,
MBX1_TSPPL3_AS4SELFACTORALPHA,
MBX1_TSPPL3_AS4SELDIFFUSEALPHA|MBX1_TSPPL3_INVAS4,
MBX1_TSPPL3_AS4SELCURRENTALPHA|MBX1_TSPPL3_INVAS4,
MBX1_TSPPL3_AS4SELTEXTUREALPHA|MBX1_TSPPL3_INVAS4,
MBX1_TSPPL3_AS4SELFACTORALPHA|MBX1_TSPPL3_INVAS4,
0, /* no ONE for AS4 */
0, /* no ONE for AS4 */
MBX1_TSPPL3_AS4SELDIFFUSEALPHA,
MBX1_TSPPL3_AS4SELDIFFUSEALPHA|MBX1_TSPPL3_INVAS4
};
/*
Source permutation table, representing different ways to map required
sources for an OP onto the four HW sources (CS1-4 / AS1-4).
*/
static IMG_UINT32 ui32SourceOrder[8][4] =
{
{ 0, 1, 2, 3 }, /* S1=Src0, S2=Src1, S3=Sre2, S4=Src3 */
{ 1, 0, 2, 3 }, /* S1=Src1, S2=Src0, S3=Src2, S4=Src3 */
{ 0, 1, 3, 2 }, /* etc... */
{ 1, 0, 3, 2 },
{ 2, 3, 0, 1 },
{ 2, 3, 1, 0 },
{ 3, 2, 0, 1 },
{ 3, 2, 1, 0 }
};
/*
Source validation tables. Indicating which color/alpha sources are valid for
each of the four HW color/alpha sources (CS1-4/AS1-4). Each bit indicating if
a particular source (see color/alpha source-codes above) are available from
the HW.
*/
static IMG_UINT32 uValidColorSource[] =
{
0x000F0E0E, /* CS1 - no DIFFUSE, no alpha */
0x000CFFFF, /* CS2 - no ONE, ZERO */
0x000F0707, /* CS3 - no FACTOR, no alpha */
0x000CFFFF /* CS4 - no ONE, ZERO */
};
static IMG_UINT32 uValidAlphaSource[] =
{
0x00000F77, /* AS1 - no FACTOR alpha */
0x00000CFF, /* AS2 - no ONE, ZERO*/
0x00000F77, /* AS3 - no FACTOR alpha */
0x00000CFF /* AS4 - no ONE, ZERO*/
};
/*
Number of entries in the color/alpha-op tables.
*/
#define GLES_COLOROP3LCTLTABLE_SIZE (GLES_COLORARG_COUNT * \
GLES_COLORARG_COUNT * \
GLES_COLORARG_COUNT * \
GLES_COLOROP3_COUNT)
#define GLES_ALPHAOP3LCTLTABLE_SIZE (GLES_ALPHAARG_COUNT * \
GLES_ALPHAARG_COUNT * \
GLES_ALPHAARG_COUNT * \
GLES_ALPHAOP3_COUNT)
#define GLES_COLOROP2LCTLTABLE_SIZE (GLES_COLORARG_COUNT * \
GLES_COLORARG_COUNT * \
GLES_COLOROP2_COUNT)
#define GLES_ALPHAOP2LCTLTABLE_SIZE (GLES_ALPHAARG_COUNT * \
GLES_ALPHAARG_COUNT * \
GLES_ALPHAOP2_COUNT)
/*
IMG_BOOL indicating if the tables have been setup yet, as they only need to
be done once (on the first context create)
*/
//static IMG_BOOL bTextureOpTablesSetup = IMG_FALSE;
/*****************************************************************************
FUNCTION : SetupColorArgs
PURPOSE : Maps the given sources onto the four HW color sources by
searching for a permutation that can be handled. If successful,
the given layer-control words are updated
PARAMETERS : ui32Sources - the required sources (see tstable.h for the
available source codes)
pui32LCtl1 - TSPLCtl1 to be updated
pui32LCtl3 - TSPLCtl3 to be updated
RETURNS : IMG_BOOL - IMG_TRUE indicates the requested sources could be
setup
*****************************************************************************/
IMG_BOOL SetupColorArgs(IMG_UINT32 ui32Sources[4], IMG_UINT32 *pui32LCtl1, IMG_UINT32 *pui32LCtl3)
{
IMG_UINT32 ui32Source[4];
IMG_UINT32 uMaxOrder;
IMG_UINT32 i, j;
/*
If CSUM is enabled in LCtl1, then we can't swap CS1+2 with CS3+4, so limit
the search to the first four source orders.
*/
if (*pui32LCtl1 & MBX1_TSPPL1_CSUM)
{
uMaxOrder = (sizeof(ui32SourceOrder) / (sizeof(IMG_UINT32)*4)) / 2;
}
else
{
uMaxOrder = (sizeof(ui32SourceOrder) / (sizeof(IMG_UINT32)*4));
}
/*
Try all variations until we find one that we can do
*/
for (i = 0; i < uMaxOrder; i++)
{
/*
Check that each HW source can provide the desired source color
*/
for (j = 0; j < 4; j++)
{
ui32Source[j] = ui32Sources[ ui32SourceOrder[i][j] ];
if (!((1 << ui32Source[j]) & uValidColorSource[j]))
{
break;
}
}
/*
If all sources were valid, then update the control-words and return.
*/
if (j == 4)
{
*pui32LCtl3 &= MBX1_TSPPL3_CS1SELCLRMASK &
MBX1_TSPPL3_CS2SELCLRMASK &
MBX1_TSPPL3_CS3SELCLRMASK &
MBX1_TSPPL3_CS4SELCLRMASK &
(~MBX1_TSPPL3_INVCS1) &
(~MBX1_TSPPL3_INVCS2) &
(~MBX1_TSPPL3_INVCS3) &
(~MBX1_TSPPL3_INVCS4);
*pui32LCtl3 |= ui32CS1ColorSourceTransLCtl3[ ui32Source[0] ] |
ui32CS2ColorSourceTransLCtl3[ ui32Source[1] ] |
ui32CS3ColorSourceTransLCtl3[ ui32Source[2] ] |
ui32CS4ColorSourceTransLCtl3[ ui32Source[3] ] | (i << COLOR_SWIZ_SHIFT);
return IMG_TRUE;
}
}
/*
Unable to provide the requested sources
*/
return IMG_FALSE;
}
/*****************************************************************************
FUNCTION : SetupAlphaArgs
PURPOSE : Maps the given sources onto the four HW alpha sources by
searching for a permutation that can be handled. If successful,
the given layer-control word is updated.
PARAMETERS : ui32Sources - the required sources (see tstable.h for the
available source codes)
pui32LCtl3 - TSPLCtl3 to be updated
RETURNS : IMG_BOOL - IMG_TRUE indicates the requested sources could be
setup
*****************************************************************************/
IMG_BOOL SetupAlphaArgs(IMG_UINT32 ui32Sources[4], IMG_UINT32 *pui32LCtl3)
{
IMG_UINT32 ui32Source[4];
IMG_UINT32 i, j;
/*
Try all variations until we find one that we can do
*/
for (i = 0; i < (sizeof(ui32SourceOrder) / (sizeof(IMG_UINT32)*4)); i++)
{
/*
Check that each HW source can provide the desired source color
*/
for (j = 0; j < 4; j++)
{
ui32Source[j] = ui32Sources[ ui32SourceOrder[i][j] ];
if (!((1 << ui32Source[j]) & uValidAlphaSource[j]))
{
break;
}
}
/*
If all sources were valid, then update the control-word and return.
*/
if (j == 4)
{
*pui32LCtl3 &= MBX1_TSPPL3_AS1SELCLRMASK &
MBX1_TSPPL3_AS2SELCLRMASK &
MBX1_TSPPL3_AS3SELCLRMASK &
MBX1_TSPPL3_AS4SELCLRMASK &
(~MBX1_TSPPL3_INVAS1) &
(~MBX1_TSPPL3_INVAS2) &
(~MBX1_TSPPL3_INVAS3) &
(~MBX1_TSPPL3_INVAS4);
*pui32LCtl3 |= ui32AS1AlphaSourceTransLCtl3[ ui32Source[0] ] |
ui32AS2AlphaSourceTransLCtl3[ ui32Source[1] ] |
ui32AS3AlphaSourceTransLCtl3[ ui32Source[2] ] |
ui32AS4AlphaSourceTransLCtl3[ ui32Source[3] ] | (i << ALPHA_SWIZ_SHIFT);
return IMG_TRUE;
}
}
/*
Unable to provide the requested sources
*/
return IMG_FALSE;
}
/*****************************************************************************
FUNCTION : SetupColorOp
PURPOSE : Attempts to setup the HW TSP layer control words for a given
color-op and arguments. If the requested arguments cannot
be supplied, the control words are not changed.
PARAMETERS : ui32Op - Color Op
ui32Arg1 - Color Arg 1
ui32Arg2 - Color Arg 2
ui32Arg3 - Color Arg 3
RETURNS : IMG_BOOL - IMG_TRUE is the selected argument/op combination
can be achieved
*****************************************************************************/
IMG_BOOL SetupColorOp(IMG_UINT32 ui32Op, IMG_UINT32 ui32Arg1, IMG_UINT32 ui32Arg2, IMG_UINT32 ui32Arg3, IMG_UINT32 *pui32LCtl3)
{
IMG_UINT32 ui32Sources[4];
IMG_UINT32 uLCtl1, ui32LCtl3;
/*
Choose the required args and setup the base control words to
produce the correct behaviour for this Op
*/
switch (ui32Op)
{
case GLES_COMBINEOP_INTERPOLATE:
{
/*
Arg1*Arg3 + Arg2*(1-Arg3)
*/
ui32Sources[0] = ui32Arg1;
ui32Sources[1] = ui32Arg3;
ui32Sources[2] = ui32Arg2;
ui32Sources[3] = ui32Arg3;
uLCtl1 = 0;
ui32LCtl3 = MBX1_TSPPL3_CBEOP1X;
break;
}
case GLES_COMBINEOP_REPLACE:
{
/*
One*Arg1 + Zero*Current
*/
ui32Sources[0] = GLES_COLORSOURCE_ONE;
ui32Sources[1] = ui32Arg1;
ui32Sources[2] = GLES_COLORSOURCE_ZERO;
ui32Sources[3] = GLES_COLORSOURCE_ANY;
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -