Пример #1
0
        public ShaderProgram(ShaderContext shaderContext, bool hasGeometryShader)
        {
            this.hasGeometryShader = hasGeometryShader;
            for (int i = 0; i < lightType.Length; i++)
            {
                lightType[i]    = shaderContext.getLightType(i);
                lightKind[i]    = shaderContext.getLightKind(i);
                lightEnabled[i] = shaderContext.getLightEnabled(i);
            }
            matFlags[0]       = shaderContext.getMatFlags(0);
            matFlags[1]       = shaderContext.getMatFlags(1);
            matFlags[2]       = shaderContext.getMatFlags(2);
            texShade[0]       = shaderContext.getTexShade(0);
            texShade[1]       = shaderContext.getTexShade(1);
            texEnvMode[0]     = shaderContext.getTexEnvMode(0);
            texEnvMode[1]     = shaderContext.getTexEnvMode(1);
            ctestFunc         = shaderContext.CtestFunc;
            texMapMode        = shaderContext.TexMapMode;
            texMapProj        = shaderContext.TexMapProj;
            vinfoColor        = shaderContext.VinfoColor;
            vinfoPosition     = shaderContext.VinfoPosition;
            vinfoTexture      = shaderContext.VinfoTexture;
            vinfoNormal       = shaderContext.VinfoNormal;
            colorDoubling     = shaderContext.ColorDoubling;
            texEnable         = shaderContext.TexEnable;
            lightingEnable    = shaderContext.LightingEnable;
            vinfoTransform2D  = shaderContext.VinfoTransform2D;
            ctestEnable       = shaderContext.CtestEnable;
            lightMode         = shaderContext.LightMode;
            texPixelFormat    = shaderContext.TexPixelFormat;
            numberBones       = shaderContext.NumberBones;
            clutIndexHint     = shaderContext.ClutIndexHint;
            alphaTestEnable   = shaderContext.AlphaTestEnable;
            alphaTestFunc     = shaderContext.AlphaTestFunc;
            stencilTestEnable = shaderContext.StencilTestEnable;
            stencilFunc       = shaderContext.StencilFunc;
            stencilOpFail     = shaderContext.StencilOpFail;
            stencilOpZFail    = shaderContext.StencilOpZFail;
            stencilOpZPass    = shaderContext.StencilOpZPass;
            depthTestEnable   = shaderContext.DepthTestEnable;
            depthFunc         = shaderContext.DepthFunc;
            blendTestEnable   = shaderContext.BlendTestEnable;
            blendEquation     = shaderContext.BlendEquation;
            blendSrc          = shaderContext.BlendSrc;
            blendDst          = shaderContext.BlendDst;
            colorMaskEnable   = shaderContext.ColorMaskEnable;
            copyRedToAlpha    = shaderContext.CopyRedToAlpha;
            fogEnable         = shaderContext.FogEnable;

            key = getKey(shaderContext, hasGeometryShader);
        }
Пример #2
0
        public static ShaderProgramKey getKey(ShaderContext shaderContext, bool hasGeometryShader)
        {
            long key = 0;
            long key1;
            long key2;
            int  shift = 0;

            key += hasGeometryShader ? 1 : 0;
            shift++;
            for (int i = 0; i < VideoEngine.NUM_LIGHTS; i++)
            {
                // LightType and LightKind are currently not used as defines in the shaders
                //key += shaderContext.getLightType(i) << shift;
                //shift += 2;
                //key += shaderContext.getLightKind(i) << shift;
                //shift += 2;
                key += shaderContext.getLightEnabled(i) << shift;
                shift++;
            }
            key += ((long)shaderContext.getMatFlags(0)) << shift;
            shift++;
            key += ((long)shaderContext.getMatFlags(1)) << shift;
            shift++;
            key += ((long)shaderContext.getMatFlags(2)) << shift;
            shift++;
            key   += ((long)shaderContext.getTexShade(0)) << shift;
            shift += 2;
            key   += ((long)shaderContext.getTexShade(1)) << shift;
            shift += 2;
            key   += ((long)shaderContext.getTexEnvMode(0)) << shift;
            shift += 3;
            key   += ((long)shaderContext.getTexEnvMode(1)) << shift;
            shift++;
            key   += ((long)shaderContext.CtestFunc) << shift;
            shift += 2;
            key   += ((long)shaderContext.TexMapMode) << shift;
            shift += 2;
            key   += ((long)shaderContext.TexMapProj) << shift;
            shift += 2;
            key   += ((long)shaderContext.VinfoColor) << shift;
            shift += 4;
            key   += ((long)shaderContext.VinfoPosition) << shift;
            shift += 2;
            key   += ((long)shaderContext.VinfoTexture) << shift;
            shift += 2;
            key   += ((long)shaderContext.VinfoNormal) << shift;
            shift += 2;
            key   += (shaderContext.ColorDoubling == 2.0f ? 1L : 0L) << shift;
            shift++;
            key += ((long)shaderContext.TexEnable) << shift;
            shift++;
            key += ((long)shaderContext.LightingEnable) << shift;
            shift++;
            key += ((long)shaderContext.VinfoTransform2D) << shift;
            shift++;
            key += ((long)shaderContext.CtestEnable) << shift;
            shift++;
            key += ((long)shaderContext.LightMode) << shift;
            shift++;
            key   += ((long)shaderContext.TexPixelFormat) << shift;
            shift += 4;
            key   += ((long)shaderContext.NumberBones) << shift;
            shift += 4;
            key   += ((long)shaderContext.ClutIndexHint) << shift;
            shift += 3;
            key   += ((long)shaderContext.AlphaTestEnable) << shift;
            shift++;
            key   += ((long)shaderContext.AlphaTestFunc) << shift;
            shift += 3;
            key   += ((long)shaderContext.StencilTestEnable) << shift;
            shift++;
            key   += ((long)shaderContext.StencilFunc) << shift;
            shift += 3;
            key   += ((long)shaderContext.StencilOpFail) << shift;
            shift += 3;
            key   += ((long)shaderContext.StencilOpZFail) << shift;
            shift += 3;

            if (shift > (sizeof(long) * 8))
            {
                VideoEngine.log_Renamed.error(string.Format("ShaderProgram: too long key1: {0:D} bits", shift));
            }
            key1  = key;
            key   = 0;
            shift = 0;

            key   += ((long)shaderContext.StencilOpZPass) << shift;
            shift += 3;
            key   += ((long)shaderContext.DepthTestEnable) << shift;
            shift += 3;
            key   += ((long)shaderContext.DepthFunc) << shift;
            shift += 3;
            key   += ((long)shaderContext.BlendTestEnable) << shift;
            shift++;
            key   += ((long)shaderContext.BlendEquation) << shift;
            shift += 3;
            key   += ((long)shaderContext.BlendSrc) << shift;
            shift += 4;
            key   += ((long)shaderContext.BlendDst) << shift;
            shift += 4;
            key   += ((long)shaderContext.ColorMaskEnable) << shift;
            shift++;
            key += ((long)shaderContext.CopyRedToAlpha) << shift;
            shift++;
            key += ((long)shaderContext.FogEnable) << shift;
            shift++;

            if (shift > (sizeof(long) * 8))
            {
                VideoEngine.log_Renamed.error(string.Format("ShaderProgram: too long key2: {0:D} bits", shift));
            }
            key2 = key;

            return(new ShaderProgramKey(key1, key2));
        }