예제 #1
0
        /// <summary>
        /// Initializes the render object</summary>
        /// <returns>true, iff initialization was successful</returns>
        public override bool Init(SceneNode node)
        {
            IMesh mesh = TryGetMesh();

            if (mesh != null)
            {
                m_bindingCount = m_primitives.BindingCount;

                // determine primitive type
                if (m_primitives.PrimitiveType == "POLYGONS")
                {
                    m_drawMode = Gl.GL_POLYGON;
                }
                else if (m_primitives.PrimitiveType == "TRIANGLES")
                {
                    m_drawMode = Gl.GL_TRIANGLES;
                }
                else if (m_primitives.PrimitiveType == "TRISTRIPS")
                {
                    m_drawMode = Gl.GL_TRIANGLE_STRIP;
                }

                // add draw commands
                AddCommand(NormalsTag, Function.glNormal3fv);
                AddCommand(TextureCoordinatesTag, Function.glTexCoord2fv);
                AddCommand(ColorsTag, Function.glColor3fv);
                AddCommand(VerticesTag, Function.glVertex3fv);

                // get the shader
                IShader             shader             = m_primitives.Shader;
                IRenderStateCreator renderStateCreator = null;
                if (shader != null)
                {
                    renderStateCreator = shader.As <IRenderStateCreator>();
                }

                if (renderStateCreator != null)
                {
                    RenderState renderState = renderStateCreator.CreateRenderState();
                    node.StateStack.Push(renderState);
                }
            }

            return(true);
        }