示例#1
0
 /// <summary>
 ///
 /// </summary>
 /// <param name="model">从模型到buffer的renderer</param>
 /// <param name="allShaderCodes">shader代码</param>
 /// <param name="propertyNameMap">vertex shader中的in变量与<see cref="propertyBufferRenderers"/>中的元素名字的对应关系。</param>
 public ModernRenderer(IConvert2BufferPointer model, CodeShader[] allShaderCodes, PropertyNameMap propertyNameMap, UniformNameMap uniformNameMap)
 {
     this.model           = model;
     this.allShaderCodes  = allShaderCodes;
     this.propertyNameMap = propertyNameMap;
     this.uniformNameMap  = uniformNameMap;
 }
示例#2
0
        protected override void DoInitialize()
        {
            // init shader program
            ShaderProgram program = new ShaderProgram();
            string        vertexShaderCode = null, geometryShaderCode = null, fragmentShaderCode = null;

            FillShaderCodes(this.allShaderCodes, ref vertexShaderCode, ref geometryShaderCode, ref fragmentShaderCode);
            program.Create(vertexShaderCode, fragmentShaderCode, geometryShaderCode, null);
            this.shaderProgram = program;

            // init all uniform variables
            this.uniformVariables = GetAllUniformVariables(this.allShaderCodes);

            // init property buffer objects' renderer
            var propertyBufferRenderers = new BufferPointer[propertyNameMap.Count()];
            int index = 0;

            foreach (var item in propertyNameMap)
            {
                BufferPointer bufferRenderer = this.model.GetBufferRenderer(
                    item.NameInIConvert2BufferRenderer, item.VarNameInShader);
                if (bufferRenderer == null)
                {
                    throw new Exception();
                }
                propertyBufferRenderers[index++] = bufferRenderer;
            }
            this.propertyBufferRenderers = propertyBufferRenderers;

            // init index buffer object's renderer
            this.indexBufferRenderer = this.model.GetIndexBufferRenderer();

            this.model           = null;
            this.allShaderCodes  = null;
            this.propertyNameMap = null;
            //this.uniformNameMap = null;

            {
                IndexBufferPointer renderer = this.indexBufferRenderer as IndexBufferPointer;
                if (renderer != null)
                {
                    this.elementCount = renderer.ElementCount;
                }
            }
            {
                ZeroIndexBufferPointer renderer = this.indexBufferRenderer as ZeroIndexBufferPointer;
                if (renderer != null)
                {
                    this.elementCount = renderer.VertexCount;
                }
            }
        }
示例#3
0
        public static PropertyNameMap Parse(XElement xElement)
        {
            if (xElement.Name != typeof(PropertyNameMap).Name)
            {
                throw new Exception();
            }

            PropertyNameMap result = new PropertyNameMap();

            //result.DumperType = xElement.Attribute(strDumperType).Value;
            //result.RendererType = xElement.Attribute(strRendererType).Value;

            foreach (var item in xElement.Elements(typeof(NamePair).Name))
            {
                var pair = NamePair.Parse(item);
                result.namesInShader.Add(pair.VarNameInShader);
                result.namesInIConvert2BufferRenderer.Add(pair.NameInIConvert2BufferRenderer);
            }

            return(result);
        }