Ejemplo n.º 1
0
        private RendererTemplate compileRenderer(BasePrimitiveRenderer renderer, LongLongKey id, GeContext context)
        {
            if (log.InfoEnabled)
            {
                Console.WriteLine(string.Format("Compiling Renderer {0}", id));
            }

            Dictionary <string, object> variables = new Dictionary <string, object>();

            // All these variables have to be defined as static members in the class RendererTemplate.
            variables["hasMemInt"]                = Convert.ToBoolean(RuntimeContext.hasMemoryInt());
            variables["transform2D"]              = Convert.ToBoolean(renderer.transform2D);
            variables["clearMode"]                = Convert.ToBoolean(renderer.clearMode);
            variables["clearModeColor"]           = Convert.ToBoolean(context.clearModeColor);
            variables["clearModeStencil"]         = Convert.ToBoolean(context.clearModeStencil);
            variables["clearModeDepth"]           = Convert.ToBoolean(context.clearModeDepth);
            variables["needSourceDepthRead"]      = Convert.ToBoolean(renderer.needSourceDepthRead);
            variables["needDestinationDepthRead"] = Convert.ToBoolean(renderer.needDestinationDepthRead);
            variables["needDepthWrite"]           = Convert.ToBoolean(renderer.needDepthWrite);
            variables["needTextureUV"]            = Convert.ToBoolean(renderer.needTextureUV);
            variables["simpleTextureUV"]          = Convert.ToBoolean(renderer.simpleTextureUV);
            variables["swapTextureUV"]            = Convert.ToBoolean(renderer.swapTextureUV);
            variables["needScissoringX"]          = Convert.ToBoolean(renderer.needScissoringX);
            variables["needScissoringY"]          = Convert.ToBoolean(renderer.needScissoringY);
            variables["nearZ"] = new int?(renderer.nearZ);
            variables["farZ"]  = new int?(renderer.farZ);
            variables["colorTestFlagEnabled"]   = Convert.ToBoolean(context.colorTestFlag.Enabled);
            variables["colorTestFunc"]          = new int?(context.colorTestFunc);
            variables["alphaTestFlagEnabled"]   = Convert.ToBoolean(context.alphaTestFlag.Enabled);
            variables["alphaFunc"]              = new int?(context.alphaFunc);
            variables["alphaRef"]               = new int?(context.alphaRef);
            variables["alphaMask"]              = new int?(context.alphaMask);
            variables["stencilTestFlagEnabled"] = Convert.ToBoolean(context.stencilTestFlag.Enabled);
            variables["stencilFunc"]            = new int?(context.stencilFunc);
            variables["stencilOpFail"]          = new int?(context.stencilOpFail);
            variables["stencilOpZFail"]         = new int?(context.stencilOpZFail);
            variables["stencilOpZPass"]         = new int?(context.stencilOpZPass);
            variables["stencilRef"]             = new int?(context.stencilRef);
            variables["depthTestFlagEnabled"]   = Convert.ToBoolean(context.depthTestFlag.Enabled);
            variables["depthFunc"]              = new int?(context.depthFunc);
            variables["blendFlagEnabled"]       = Convert.ToBoolean(context.blendFlag.Enabled);
            variables["blendEquation"]          = new int?(context.blendEquation);
            variables["blendSrc"]               = new int?(context.blend_src);
            variables["blendDst"]               = new int?(context.blend_dst);
            variables["sfix"] = new int?(context.sfix);
            variables["dfix"] = new int?(context.dfix);
            variables["colorLogicOpFlagEnabled"] = Convert.ToBoolean(context.colorLogicOpFlag.Enabled);
            variables["logicOp"]                 = new int?(context.logicOp);
            variables["colorMask"]               = new int?(PixelColor.getColor(context.colorMask));
            variables["depthMask"]               = Convert.ToBoolean(context.depthMask);
            variables["textureFlagEnabled"]      = Convert.ToBoolean(context.textureFlag.Enabled);
            variables["useVertexTexture"]        = Convert.ToBoolean(renderer.useVertexTexture);
            variables["lightingFlagEnabled"]     = Convert.ToBoolean(context.lightingFlag.Enabled);
            variables["sameVertexColor"]         = Convert.ToBoolean(renderer.sameVertexColor);
            variables["setVertexPrimaryColor"]   = Convert.ToBoolean(renderer.setVertexPrimaryColor);
            variables["primaryColorSetGlobally"] = Convert.ToBoolean(renderer.primaryColorSetGlobally);
            variables["isTriangle"]              = Convert.ToBoolean(renderer.isTriangle);
            variables["matFlagAmbient"]          = Convert.ToBoolean((context.mat_flags & CMAT_FLAG_AMBIENT) != 0);
            variables["matFlagDiffuse"]          = Convert.ToBoolean((context.mat_flags & CMAT_FLAG_DIFFUSE) != 0);
            variables["matFlagSpecular"]         = Convert.ToBoolean((context.mat_flags & CMAT_FLAG_SPECULAR) != 0);
            variables["useVertexColor"]          = Convert.ToBoolean(context.useVertexColor);
            variables["textureColorDoubled"]     = Convert.ToBoolean(context.textureColorDoubled);
            variables["lightMode"]               = new int?(context.lightMode);
            variables["texMapMode"]              = new int?(context.tex_map_mode);
            variables["texProjMapMode"]          = new int?(context.tex_proj_map_mode);
            variables["texTranslateX"]           = new float?(context.tex_translate_x);
            variables["texTranslateY"]           = new float?(context.tex_translate_y);
            variables["texScaleX"]               = new float?(context.tex_scale_x);
            variables["texScaleY"]               = new float?(context.tex_scale_y);
            variables["texWrapS"]                = new int?(context.tex_wrap_s);
            variables["texWrapT"]                = new int?(context.tex_wrap_t);
            variables["textureFunc"]             = new int?(context.textureFunc);
            variables["textureAlphaUsed"]        = Convert.ToBoolean(context.textureAlphaUsed);
            variables["psm"]                  = new int?(context.psm);
            variables["texMagFilter"]         = new int?(context.tex_mag_filter);
            variables["needTextureWrapU"]     = Convert.ToBoolean(renderer.needTextureWrapU);
            variables["needTextureWrapV"]     = Convert.ToBoolean(renderer.needTextureWrapV);
            variables["needSourceDepthClamp"] = Convert.ToBoolean(renderer.needSourceDepthClamp);
            variables["isLogTraceEnabled"]    = Convert.ToBoolean(renderer.isLogTraceEnabled);
            variables["collectStatistics"]    = Convert.ToBoolean(DurationStatistics.collectStatistics);
            variables["ditherFlagEnabled"]    = Convert.ToBoolean(context.ditherFlag.Enabled);

            string           specializedClassName = NewCompiledRendererClassName;
            ClassSpecializer cs = new ClassSpecializer();
            Type             specializedClass = cs.specialize(specializedClassName, typeof(RendererTemplate), variables);
            RendererTemplate compiledRenderer = null;

            if (specializedClass != null)
            {
                try
                {
                    compiledRenderer = (RendererTemplate)System.Activator.CreateInstance(specializedClass);
                }
                catch (InstantiationException e)
                {
                    Console.WriteLine("Error while instanciating compiled renderer", e);
                }
                catch (IllegalAccessException e)
                {
                    Console.WriteLine("Error while instanciating compiled renderer", e);
                }
            }

            return(compiledRenderer);
        }