private static PropertyNameMap GetMap(BuildInSceneObject buildIn)
        {
            var map = new PropertyNameMap();

            switch (buildIn)
            {
                case BuildInSceneObject.Cube:
                    map.Add("in_Position", Cube.strPosition);
                    map.Add("in_Color", Cube.strColor);
                    break;
                case BuildInSceneObject.Sphere:
                    map.Add("in_Position", Sphere.strPosition);
                    map.Add("in_Color", Sphere.strColor);
                    break;
                case BuildInSceneObject.Ground:
                    map.Add("in_Position", Ground.strPosition);
                    map.Add("in_Color", Ground.strColor);
                    break;
                case BuildInSceneObject.Axis:
                    map.Add("in_Position", Axis.strPosition);
                    map.Add("in_Color", Axis.strColor);
                    break;
                default:
                    throw new NotImplementedException();
            }

            return map;
        }
Ejemplo n.º 2
0
 protected GridViewRenderer(vec3 originalWorldPosition, GridViewModel model, ShaderCode[] shaderCodes,
                            PropertyNameMap propertyNameMap, params GLSwitch[] switches)
     : base(model, shaderCodes, propertyNameMap, switches)
 {
     this.OriginalWorldPosition = originalWorldPosition;
     this.Grid = model;
 }
Ejemplo n.º 3
0
 private MovableRenderer(IBufferable bufferable, ShaderCode[] shaderCodes,
                         PropertyNameMap propertyNameMap, string positionNameInIBufferable,
                         params GLSwitch[] switches)
     : base(bufferable, shaderCodes, propertyNameMap, "position")
 {
     this.Scale = 1.0f;
 }
Ejemplo n.º 4
0
 public MovableRenderer(IBufferable bufferable, ShaderCode[] shaderCodes,
     PropertyNameMap propertyNameMap, string positionNameInIBufferable,
     params GLSwitch[] switches)
     : base(bufferable, shaderCodes, propertyNameMap, positionNameInIBufferable, switches)
 {
     this.Scale = 1.0f;
 }
 private void Form_Load(object sender, EventArgs e)
 {
     {
         var camera = new Camera(
             new vec3(0, 0, 5), new vec3(0, 0, 0), new vec3(0, 1, 0),
             CameraType.Perspecitive, this.glCanvas1.Width, this.glCanvas1.Height);
         var rotator = new SatelliteManipulater();
         rotator.Bind(camera, this.glCanvas1);
         this.camera = camera;
         this.rotator = rotator;
     }
     {
         IBufferable bufferable = new Teapot();
         var shaderCodes = new ShaderCode[2];
         shaderCodes[0] = new ShaderCode(File.ReadAllText(@"shaders\Transparent.vert"), ShaderType.VertexShader);
         shaderCodes[1] = new ShaderCode(File.ReadAllText(@"shaders\Transparent.frag"), ShaderType.FragmentShader);
         var map = new PropertyNameMap();
         map.Add("in_Position", "position");
         map.Add("in_Color", "color");
         var renderer = new PickableRenderer(bufferable, shaderCodes, map, "position");
         renderer.Name = "Order-Dependent Transparent Renderer";
         renderer.Initialize();
         {
             GLSwitch blendSwitch = new BlendSwitch(BlendingSourceFactor.SourceAlpha, BlendingDestinationFactor.OneMinusSourceAlpha);
             renderer.SwitchList.Add(blendSwitch);
         }
         this.renderer = renderer;
     }
     {
         var frmPropertyGrid = new FormProperyGrid();
         frmPropertyGrid.DisplayObject(this.renderer);
         frmPropertyGrid.Show();
         this.formPropertyGrid = frmPropertyGrid;
     }
 }
Ejemplo n.º 6
0
 private void Form02OrderIndependentTransparency_Load(object sender, EventArgs e)
 {
     {
         var camera = new Camera(
             new vec3(0, 0, 5), new vec3(0, 0, 0), new vec3(0, 1, 0),
             CameraType.Perspecitive, this.glCanvas1.Width, this.glCanvas1.Height);
         var rotator = new SatelliteRotator(camera);
         this.camera  = camera;
         this.rotator = rotator;
     }
     {
         IBufferable bufferable  = new Teapot();
         var         shaderCodes = new ShaderCode[2];
         shaderCodes[0] = new ShaderCode(File.ReadAllText(@"03OrderDependentTransparency\Transparent.vert"), ShaderType.VertexShader);
         shaderCodes[1] = new ShaderCode(File.ReadAllText(@"03OrderDependentTransparency\Transparent.frag"), ShaderType.FragmentShader);
         var map = new PropertyNameMap();
         map.Add("in_Position", "position");
         map.Add("in_Color", "color");
         var renderer = new PickableRenderer(bufferable, shaderCodes, map, "position");
         renderer.Name = "Order-Dependent Transparent Renderer";
         renderer.Initialize();
         {
             GLSwitch blendSwitch = new BlendSwitch(BlendingSourceFactor.SourceAlpha, BlendingDestinationFactor.OneMinusSourceAlpha);
             renderer.SwitchList.Add(blendSwitch);
         }
         this.renderer = renderer;
     }
     {
         var frmPropertyGrid = new FormProperyGrid();
         frmPropertyGrid.DisplayObject(this.renderer);
         frmPropertyGrid.Show();
         this.formPropertyGrid = frmPropertyGrid;
     }
 }
 public OrderIndependentTransparencyRenderer(IBufferable model,
                                             string positionName, string normalName)
 {
     {
         var map = new PropertyNameMap();
         map.Add("position", positionName);
         map.Add("normal", normalName);
         var build_lists = new ShaderCode[2];
         build_lists[0]          = new ShaderCode(File.ReadAllText(@"02OrderIndependentTransparency\build_lists.vert"), ShaderType.VertexShader);
         build_lists[1]          = new ShaderCode(File.ReadAllText(@"02OrderIndependentTransparency\build_lists.frag"), ShaderType.FragmentShader);
         this.buildListsRenderer = new PickableRenderer(model, build_lists, map, positionName);
     }
     {
         var map = new PropertyNameMap();
         map.Add("position", positionName);
         var resolve_lists = new ShaderCode[2];
         resolve_lists[0]   = new ShaderCode(File.ReadAllText(@"02OrderIndependentTransparency\resolve_lists.vert"), ShaderType.VertexShader);
         resolve_lists[1]   = new ShaderCode(File.ReadAllText(@"02OrderIndependentTransparency\resolve_lists.frag"), ShaderType.FragmentShader);
         this.resolve_lists = new PickableRenderer(model, resolve_lists, map, positionName);
     }
     {
         this.depthTestSwitch = new DepthTestSwitch(false);
         this.cullFaceSwitch  = new CullFaceSwitch(false);
     }
 }
Ejemplo n.º 8
0
        public UIText(
            System.Windows.Forms.AnchorStyles anchor, System.Windows.Forms.Padding margin,
            System.Drawing.Size size, int zNear, int zFar, FontResource fontResource = null, int maxCharCount = 100)
            : base(anchor, margin, size, zNear, zFar)
        {
            if (fontResource == null)
            { this.fontResource = FontResource.Default; }
            else
            { this.fontResource = fontResource; }

            this.Name = this.GetType().Name;
            var shaderCodes = new ShaderCode[2];
            shaderCodes[0] = new ShaderCode(ManifestResourceLoader.LoadTextFile(
            @"Resources.UIText.vert"), ShaderType.VertexShader);
            shaderCodes[1] = new ShaderCode(ManifestResourceLoader.LoadTextFile(
            @"Resources.UIText.frag"), ShaderType.FragmentShader);
            var map = new PropertyNameMap();
            map.Add("position", "position");
            map.Add("uv", "uv");
            var model = new TextModel(maxCharCount);
            Renderer renderer = new Renderer(model, shaderCodes, map);

            this.model = model;
            this.Renderer = renderer;
        }
Ejemplo n.º 9
0
 private TerrainRenderer(IBufferable bufferable, ShaderCode[] shaderCodes,
                         PropertyNameMap propertyNameMap, BoundingBox boundingBox, params GLSwitch[] switches)
     : base(bufferable, shaderCodes, propertyNameMap, switches)
 {
     this.BoundingBox = boundingBox;
     this.PointColor  = Color.Green;
 }
 public OrderIndependentTransparencyRenderer(IBufferable model,
     string positionName, string normalName)
 {
     {
         var map = new PropertyNameMap();
         map.Add("position", positionName);
         map.Add("normal", normalName);
         var build_lists = new ShaderCode[2];
         build_lists[0] = new ShaderCode(File.ReadAllText(@"shaders\build_lists.vert"), ShaderType.VertexShader);
         build_lists[1] = new ShaderCode(File.ReadAllText(@"shaders\build_lists.frag"), ShaderType.FragmentShader);
         this.buildListsRenderer =new PickableRenderer(model, build_lists, map, positionName);
     }
     {
         var map = new PropertyNameMap();
         map.Add("position", positionName);
         var resolve_lists = new ShaderCode[2];
         resolve_lists[0] = new ShaderCode(File.ReadAllText(@"shaders\resolve_lists.vert"), ShaderType.VertexShader);
         resolve_lists[1] = new ShaderCode(File.ReadAllText(@"shaders\resolve_lists.frag"), ShaderType.FragmentShader);
         this.resolve_lists = new PickableRenderer(model, resolve_lists, map, positionName);
     }
     {
         this.depthTestSwitch = new DepthTestSwitch(false);
         this.cullFaceSwitch = new CullFaceSwitch(false);
     }
 }
Ejemplo n.º 11
0
 private GroundRenderer(IBufferable bufferable, ShaderCode[] shaderCodes,
                        PropertyNameMap propertyNameMap, params GLSwitch[] switches)
     : base(bufferable, shaderCodes, propertyNameMap, switches)
 {
     this.LineColor = Color.White;
     this.Scale     = 1.0f;
 }
Ejemplo n.º 12
0
 static SimpleComputeRenderer()
 {
     staticShaderCodes    = new ShaderCode[2];
     staticShaderCodes[0] = new ShaderCode(File.ReadAllText(@"04SimpleCompute\compute.vert"), ShaderType.VertexShader);
     staticShaderCodes[1] = new ShaderCode(File.ReadAllText(@"04SimpleCompute\compute.frag"), ShaderType.FragmentShader);
     map = new PropertyNameMap();
     map.Add(SimpleCompute.strPosition, "position");
 }
Ejemplo n.º 13
0
 public BillboardRenderer(IBufferable bufferable, ShaderCode[] shaderCodes,
                          PropertyNameMap propertyNameMap, params GLSwitch[] switches)
     : base(bufferable, shaderCodes, propertyNameMap, switches)
 {
     this.Width      = 1.0f; this.Height = 0.125f;
     this.Percentage = new vec2(0.2f, 0.05f);
     this.PixelSize  = new ivec2(100, 10);
 }
Ejemplo n.º 14
0
 static AnalyzedPointSpriteRenderer()
 {
     staticShaderCodes = new ShaderCode[2];
     staticShaderCodes[0] = new ShaderCode(File.ReadAllText(@"08AnalyzedPointSprite\AnalyzedPointSprite.vert"), ShaderType.VertexShader);
     staticShaderCodes[1] = new ShaderCode(File.ReadAllText(@"08AnalyzedPointSprite\AnalyzedPointSprite.frag"), ShaderType.FragmentShader);
     map = new PropertyNameMap();
     map.Add("position", "position");
 }
Ejemplo n.º 15
0
 static BackgroundStarsRenderer()
 {
     staticShaderCodes    = new ShaderCode[2];
     staticShaderCodes[0] = new ShaderCode(File.ReadAllText(@"shaders\PointSprite.vert"), ShaderType.VertexShader);
     staticShaderCodes[1] = new ShaderCode(File.ReadAllText(@"shaders\PointSprite.frag"), ShaderType.FragmentShader);
     map = new PropertyNameMap();
     map.Add("position", "position");
 }
Ejemplo n.º 16
0
 static AnalyzedBillboardRenderer()
 {
     staticShaderCodes    = new ShaderCode[2];
     staticShaderCodes[0] = new ShaderCode(File.ReadAllText(@"08AnalyzedBillboard\AnalyzedBillboard.vert"), ShaderType.VertexShader);
     staticShaderCodes[1] = new ShaderCode(File.ReadAllText(@"08AnalyzedBillboard\AnalyzedBillboard.frag"), ShaderType.FragmentShader);
     map = new PropertyNameMap();
     map.Add("position", "position");
 }
Ejemplo n.º 17
0
        private void Form02OrderIndependentTransparency_Load(object sender, EventArgs e)
        {
            {
                var camera = new Camera(CameraType.Perspecitive, this.glCanvas1.Width, this.glCanvas1.Height);
                camera.Position = new vec3(0, 0, 5);
                camera.Target   = new vec3(0, 0, 0);
                camera.UpVector = new vec3(0, 1, 0);
                var rotator = new SatelliteRotator(camera);
                this.camera  = camera;
                this.rotator = rotator;
            }
            {
                var shaderCodes = new ShaderCode[2];
                shaderCodes[0] = new ShaderCode(File.ReadAllText(@"12Billboard\Cube.vert"), ShaderType.VertexShader);
                shaderCodes[1] = new ShaderCode(File.ReadAllText(@"12Billboard\Cube.frag"), ShaderType.FragmentShader);
                var map = new PropertyNameMap();
                map.Add("in_Position", "position");
                map.Add("in_Color", "color");
                var cubeRenderer = new PickableRenderer(new Cube(), shaderCodes, map, "position");
                cubeRenderer.Initialize();
                this.cubeRenderer = cubeRenderer;
            }
            {
                var shaderCodes = new ShaderCode[2];
                shaderCodes[0] = new ShaderCode(File.ReadAllText(@"12Billboard\billboard.vert"), ShaderType.VertexShader);
                shaderCodes[1] = new ShaderCode(File.ReadAllText(@"12Billboard\billboard.frag"), ShaderType.FragmentShader);
                var map = new PropertyNameMap();
                map.Add("squareVertices", "position");
                var billboardRenderer = new Renderer(new BillboardModel(), shaderCodes, map);
                billboardRenderer.Initialize();
                var texture = new sampler2D();
                var bitmap  = new Bitmap(@"12Billboard\ExampleBillboard.png");
                texture.Initialize(bitmap);
                bitmap.Dispose();
                billboardRenderer.SetUniform("myTextureSampler", new samplerValue(BindTextureTarget.Texture2D, texture.Id, OpenGL.GL_TEXTURE0));

                this.billboardRenderer = billboardRenderer;
            }
            {
                var UIRoot = new GLControl(this.glCanvas1.Size, -100, 100);
                UIRoot.Initialize();
                this.uiRoot = UIRoot;

                var glAxis = new GLAxis(AnchorStyles.Right | AnchorStyles.Bottom,
                                        new Padding(3, 3, 3, 3), new Size(70, 70), -100, 100);
                glAxis.Initialize();
                this.glAxis = glAxis;

                UIRoot.Controls.Add(glAxis);
            }
            {
                var frmPropertyGrid = new FormProperyGrid();
                frmPropertyGrid.DisplayObject(this.glAxis);
                frmPropertyGrid.Show();
                this.formPropertyGrid = frmPropertyGrid;
            }
        }
Ejemplo n.º 18
0
 /// <summary>
 /// 支持"拾取"的渲染器
 /// </summary>
 /// <param name="bufferable">一种渲染方式</param>
 /// <param name="shaderCodes">各种类型的shader代码</param>
 /// <param name="propertyNameMap">关联<see cref="PropertyBufferPtr"/>和<see cref="shaderCode"/>中的属性</param>
 /// <param name="positionNameInIBufferable">描述顶点位置信息的buffer的名字</param>
 ///<param name="switches"></param>
 public PickableRenderer(IBufferable bufferable, ShaderCode[] shaderCodes,
     PropertyNameMap propertyNameMap, string positionNameInIBufferable,
     params GLSwitch[] switches)
     : base(bufferable, shaderCodes, propertyNameMap, switches)
 {
     var innerPickableRenderer = InnerPickableRendererFactory.GetRenderer(
         bufferable, propertyNameMap, positionNameInIBufferable);
     this.innerPickableRenderer = innerPickableRenderer;
 }
Ejemplo n.º 19
0
        public static PropertyNameMap LoadPropertyNameMap(string shaderName)
        {
            string content = ManifestResourceLoader.LoadTextFile(string.Format(
                                                                     "{0}.{0}.PropertyNameMap.xml", shaderName));

            PropertyNameMap result = PropertyNameMap.Parse(XElement.Parse(content));

            return(result);
        }
Ejemplo n.º 20
0
        /// <summary>
        /// 用Shader+VBO(VAO)进行渲染。
        /// </summary>
        /// <param name="bufferable">将具体模型转换为可被OpenGL拿来渲染的格式</param>
        /// <param name="shaderCodes">各种类型的shader代码</param>
        /// <param name="propertyNameMap">关联<see cref="PropertyBufferPtr"/>和<see cref="shaderCodes"/>中的属性</param>
        /// <param name="positionNameInIBufferable">描述顶点位置信息的buffer的名字</param>
        ///<param name="switches"></param>
        public Renderer(IBufferable bufferable, ShaderCode[] shaderCodes,
            PropertyNameMap propertyNameMap, params GLSwitch[] switches)
        {
            this.Name = this.GetType().Name;

            this.bufferable = bufferable;
            this.shaderCodes = shaderCodes;
            this.propertyNameMap = propertyNameMap;
            this.switchList.AddRange(switches);
        }
        private void Form_Load(object sender, EventArgs e)
        {
            {
                var camera = new Camera(
                    new vec3(0, 0, 5), new vec3(0, 0, 0), new vec3(0, 1, 0),
                    CameraType.Perspecitive, this.glCanvas1.Width, this.glCanvas1.Height);
                this.camera = camera;
                var cameraManipulater = new SatelliteManipulater();
                cameraManipulater.Bind(camera, this.glCanvas1);
                this.cameraManipulater = cameraManipulater;
                var arcballManipulater = new ArcBallManipulater();
                arcballManipulater.Bind(camera, this.glCanvas1);
                this.arcballManipulater = arcballManipulater;
            }
            {
                const int      gridsPer2Unit = 20;
                const int      scale         = 2;
                GroundRenderer ground        = GroundRenderer.Create(new GroundModel(gridsPer2Unit * scale));
                ground.Initialize();
                ground.Scale = scale;
                this.ground  = ground;
            }
            {
                var shaderCodes = new ShaderCode[2];
                shaderCodes[0] = new ShaderCode(File.ReadAllText(@"shaders\Teapot.vert"), ShaderType.VertexShader);
                shaderCodes[1] = new ShaderCode(File.ReadAllText(@"shaders\Teapot.frag"), ShaderType.FragmentShader);
                var map = new PropertyNameMap();
                map.Add("in_Position", "position");
                map.Add("in_Color", "color");
                var teapotRenderer = new Renderer(new Teapot(), shaderCodes, map);
                teapotRenderer.Initialize();
                this.teapotRenderer = teapotRenderer;
            }
            {
                var UIRoot = new UIRoot();
                UIRoot.Initialize();
                this.uiRoot = UIRoot;

                var uiAxis = new UIAxis(AnchorStyles.Left | AnchorStyles.Bottom,
                                        new Padding(3, 3, 3, 3), new Size(128, 128), -100, 100);
                uiAxis.Initialize();
                this.uiAxis = uiAxis;

                UIRoot.Children.Add(uiAxis);
            }
            {
                var frmPropertyGrid = new FormProperyGrid(this.teapotRenderer);
                frmPropertyGrid.Show();
            }
            {
                var frmPropertyGrid = new FormProperyGrid(this.glCanvas1);
                frmPropertyGrid.Show();
            }
        }
 private void InitBackfaceRenderer()
 {
     var shaderCodes = new ShaderCode[2];
     shaderCodes[0] = new ShaderCode(File.ReadAllText(@"10RaycastVolumeRender\backface.vert"), ShaderType.VertexShader);
     shaderCodes[1] = new ShaderCode(File.ReadAllText(@"10RaycastVolumeRender\backface.frag"), ShaderType.FragmentShader);
     var map = new PropertyNameMap();
     map.Add(RaycastModel.strPosition, RaycastModel.strPosition);
     map.Add(RaycastModel.strBoundingBox, RaycastModel.strBoundingBox);
     this.backfaceRenderer = new Renderer(model, shaderCodes, map);
     this.backfaceRenderer.Initialize();
     this.backfaceRenderer.SwitchList.Add(new CullFaceSwitch(CullFaceMode.Front, true));
 }
Ejemplo n.º 23
0
        public static BillboardRenderer GetRenderer(IBufferable model)
        {
            var shaderCodes = new ShaderCode[2];

            shaderCodes[0] = new ShaderCode(File.ReadAllText(@"shaders\billboard.vert"), ShaderType.VertexShader);
            shaderCodes[1] = new ShaderCode(File.ReadAllText(@"shaders\billboard.frag"), ShaderType.FragmentShader);
            var map = new PropertyNameMap();

            map.Add("in_Positions", BillboardModel.strPosition);
            var billboardRenderer = new BillboardRenderer(model, shaderCodes, map);

            return(billboardRenderer);
        }
Ejemplo n.º 24
0
        public static GroundRenderer Create(GroundModel model)
        {
            var shaderCodes = new ShaderCode[2];

            shaderCodes[0] = new ShaderCode(File.ReadAllText(@"shaders\Ground.vert"), ShaderType.VertexShader);
            shaderCodes[1] = new ShaderCode(File.ReadAllText(@"shaders\Ground.frag"), ShaderType.FragmentShader);
            var map = new PropertyNameMap();

            map.Add("in_Position", GroundModel.strPosition);
            var ground = new GroundRenderer(model, shaderCodes, map);

            return(ground);
        }
Ejemplo n.º 25
0
        public static MovableRenderer Create(IBufferable model)
        {
            var shaderCodes = new ShaderCode[2];

            shaderCodes[0] = new ShaderCode(File.ReadAllText(@"shaders\Teapot.vert"), ShaderType.VertexShader);
            shaderCodes[1] = new ShaderCode(File.ReadAllText(@"shaders\Teapot.frag"), ShaderType.FragmentShader);
            var propertyNameMap = new PropertyNameMap();

            propertyNameMap.Add("in_Position", "position");
            propertyNameMap.Add("in_Color", "color");
            var result = new MovableRenderer(model, shaderCodes, propertyNameMap, "position");

            return(result);
        }
Ejemplo n.º 26
0
        public static UpdatingTextureRenderer Create(TexturedRectangleModel model)
        {
            var shaderCodes = new ShaderCode[2];

            shaderCodes[0] = new ShaderCode(File.ReadAllText(@"shaders\UpdatingTexture.vert"), ShaderType.VertexShader);
            shaderCodes[1] = new ShaderCode(File.ReadAllText(@"shaders\UpdatingTexture.frag"), ShaderType.FragmentShader);
            var map = new PropertyNameMap();

            map.Add("in_Position", TexturedRectangleModel.strPosition);
            map.Add("in_TexCoord", TexturedRectangleModel.strTexCoord);
            var renderer = new UpdatingTextureRenderer(model, shaderCodes, map);

            return(renderer);
        }
        private void InitBackfaceRenderer()
        {
            var shaderCodes = new ShaderCode[2];

            shaderCodes[0] = new ShaderCode(File.ReadAllText(@"shaders\backface.vert"), ShaderType.VertexShader);
            shaderCodes[1] = new ShaderCode(File.ReadAllText(@"shaders\backface.frag"), ShaderType.FragmentShader);
            var map = new PropertyNameMap();

            map.Add(RaycastModel.strPosition, RaycastModel.strPosition);
            map.Add(RaycastModel.strBoundingBox, RaycastModel.strBoundingBox);
            this.backfaceRenderer = new Renderer(model, shaderCodes, map);
            this.backfaceRenderer.Initialize();
            this.backfaceRenderer.SwitchList.Add(new CullFaceSwitch(CullFaceMode.Front, true));
        }
Ejemplo n.º 28
0
        public static WellRenderer Create(WellModel model)
        {
            var shaderCodes = new ShaderCode[2];

            shaderCodes[0] = new ShaderCode(File.ReadAllText(@"shaders\Well.vert"), ShaderType.VertexShader);
            shaderCodes[1] = new ShaderCode(File.ReadAllText(@"shaders\Well.frag"), ShaderType.FragmentShader);
            var map = new PropertyNameMap();

            map.Add("in_Position", WellModel.strPosition);
            map.Add("in_Brightness", WellModel.strBrightness);
            var renderer = new WellRenderer(model, shaderCodes, map);

            return(renderer);
        }
Ejemplo n.º 29
0
 //private vec3 scale;
 //public vec3 Scale
 //{
 //    get { return scale; }
 //    set
 //    {
 //        if (value != scale)
 //        {
 //            scale = value;
 //            if (this.initialized)
 //            {
 //                this.SetUniform("modelMatrix",
 //                    glm.scale(glm.translate(mat4.identity(), this.translate), this.scale));
 //            }
 //        }
 //    }
 //}
 //private vec3 translate;
 //public vec3 Translate
 //{
 //    get { return translate; }
 //    set
 //    {
 //        if (value != translate)
 //        {
 //            translate = value;
 //            if (this.initialized)
 //            {
 //                this.SetUniform("modelMatrix",
 //           glm.scale(glm.translate(mat4.identity(), this.translate), this.scale));
 //            }
 //        }
 //    }
 //}
 public BoudingBoxRenderer(vec3 lengths)
     : base(null, null, null)
 {
     this.bufferable = new BoundingBox(lengths);
     var shaderCodes = new ShaderCode[2];
     shaderCodes[0] = new ShaderCode(File.ReadAllText(
         @"shaders\BoundingBox.vert"), ShaderType.VertexShader);
     shaderCodes[1] = new ShaderCode(File.ReadAllText(
         @"shaders\BoundingBox.frag"), ShaderType.FragmentShader);
     this.shaderCodes = shaderCodes;
     var map = new PropertyNameMap();
     map.Add("in_Position", BoundingBox.strPosition);
     this.propertyNameMap = map;
     this.switchList.Add(new PolygonModeSwitch(PolygonModes.Lines));
 }
Ejemplo n.º 30
0
        public static LinesRenderer Create(LinesModel model)
        {
            var shaderCodes = new ShaderCode[2];

            shaderCodes[0] = new ShaderCode(File.ReadAllText(@"shaders\Lines.vert"), ShaderType.VertexShader);
            shaderCodes[1] = new ShaderCode(File.ReadAllText(@"shaders\Lines.frag"), ShaderType.FragmentShader);
            var map = new PropertyNameMap();

            map.Add("in_Position", LinesModel.position);
            var renderer = new LinesRenderer(model, shaderCodes, map);

            renderer.markerCount = model.markerCount;

            return(renderer);
        }
Ejemplo n.º 31
0
        public static QuadStripRenderer Create(QuadStripModel model)
        {
            var shaderCodes = new ShaderCode[2];

            shaderCodes[0] = new ShaderCode(File.ReadAllText(@"shaders\QuadStripTexture.vert"), ShaderType.VertexShader);
            shaderCodes[1] = new ShaderCode(File.ReadAllText(@"shaders\QuadStripTexture.frag"), ShaderType.FragmentShader);
            var map = new PropertyNameMap();

            map.Add("in_Position", QuadStripModel.position);
            map.Add("in_TexCoord", QuadStripModel.texCoord);

            var renderer = new QuadStripRenderer(model, shaderCodes, map);

            return(renderer);
        }
Ejemplo n.º 32
0
        public static OrderDependentTransparencyRenderer Create(IBufferable model, string position, string color)
        {
            var shaderCodes = new ShaderCode[2];

            shaderCodes[0] = new ShaderCode(File.ReadAllText(@"shaders\Transparent.vert"), ShaderType.VertexShader);
            shaderCodes[1] = new ShaderCode(File.ReadAllText(@"shaders\Transparent.frag"), ShaderType.FragmentShader);
            var map = new PropertyNameMap();

            map.Add("in_Position", position);
            map.Add("in_Color", color);
            var renderer = new OrderDependentTransparencyRenderer(model, shaderCodes, map, position, new BlendSwitch(BlendingSourceFactor.SourceAlpha, BlendingDestinationFactor.OneMinusSourceAlpha));

            renderer.Name = "Order-Dependent Transparent Renderer";

            return(renderer);
        }
Ejemplo n.º 33
0
        public static QuadStripColoredRenderer Create(QuadStripColoredModel model)
        {
            var shaderCodes = new ShaderCode[2];

            shaderCodes[0] = new ShaderCode(File.ReadAllText(@"shaders\QuadStripColor.vert"), ShaderType.VertexShader);
            shaderCodes[1] = new ShaderCode(File.ReadAllText(@"shaders\QuadStripColor.frag"), ShaderType.FragmentShader);
            var map = new PropertyNameMap();

            map.Add("in_Position", QuadStripColoredModel.position);
            map.Add("in_Color", QuadStripColoredModel.color);

            var renderer = new QuadStripColoredRenderer(model, shaderCodes, map);

            renderer.quadCount = model.quadCount;
            return(renderer);
        }
Ejemplo n.º 34
0
        /// <summary>
        /// get a bounding box renderer.
        /// </summary>
        /// <param name="lengths">bounding box's length at x, y, z axis.</param>
        /// <returns></returns>
        public static Renderer GetBoundingBoxRenderer(vec3 lengths)
        {
            var bufferable  = new BoundingBox(lengths);
            var shaderCodes = new ShaderCode[2];

            shaderCodes[0] = new ShaderCode(File.ReadAllText(
                                                @"shaders\BoundingBox.vert"), ShaderType.VertexShader);
            shaderCodes[1] = new ShaderCode(File.ReadAllText(
                                                @"shaders\BoundingBox.frag"), ShaderType.FragmentShader);
            var map = new PropertyNameMap();

            map.Add("in_Position", BoundingBox.strPosition);
            var result = new Renderer(bufferable, shaderCodes, map, new PolygonModeSwitch(PolygonModes.Lines), new PolygonOffsetFillSwitch());

            return(result);
        }
Ejemplo n.º 35
0
        public static CatesianGridRenderer Create(vec3 originalWorldPosition, CatesianGrid grid, Texture codedColorSampler)
        {
            var shaderCodes = new ShaderCode[2];

            shaderCodes[0] = new ShaderCode(File.ReadAllText(@"shaders\HexahedronGrid.vert"), ShaderType.VertexShader);
            shaderCodes[1] = new ShaderCode(File.ReadAllText(@"shaders\HexahedronGrid.frag"), ShaderType.FragmentShader);
            var map = new PropertyNameMap();

            map.Add("in_Position", CatesianGrid.strPosition);
            map.Add("in_uv", CatesianGrid.strColor);
            var renderer = new CatesianGridRenderer(originalWorldPosition, grid, shaderCodes, map, codedColorSampler);

            renderer.lengths     = grid.DataSource.SourceActiveBounds.Max - grid.DataSource.SourceActiveBounds.Min;
            renderer.ModelMatrix = glm.translate(mat4.identity(), -grid.DataSource.Position);
            return(renderer);
        }
Ejemplo n.º 36
0
        //Camera modelRotationCamera;
        //SatelliteRotator modelRotator;
        //private float rotateAngle;

        public FormSimpleRenderer()
        {
            InitializeComponent();

            this.camera          = new Camera(CameraType.Perspecitive, this.glCanvas1.Width, this.glCanvas1.Height);
            this.camera.Position = new GLM.vec3(5, 5, 5);

            this.cameraRotator = new SatelliteRotator(this.camera);

            //this.modelRotationCamera = new Camera(CameraType.Perspecitive, this.glCanvas1.Width, this.glCanvas1.Height);
            //this.modelRotator = new SatelliteRotator(this.modelRotationCamera);
            this.modelRotator = new ArcBallRotator(this.camera);

            {
                const string           strGround = "Ground";
                IConvert2BufferPointer model     = new Ground();
                CodeShader[]           shaders   = new CodeShader[2];
                shaders[0] = CSharpGL.Objects.Common.ShaderLoadingHelper.LoadShaderSourceCode(strGround, CodeShader.GLSLShaderType.VertexShader);
                shaders[1] = CSharpGL.Objects.Common.ShaderLoadingHelper.LoadShaderSourceCode(strGround, CodeShader.GLSLShaderType.FragmentShader);
                PropertyNameMap propertyNameMap = CSharpGL.Objects.Common.ShaderLoadingHelper.LoadPropertyNameMap(strGround);
                UniformNameMap  uniformNameMap  = CSharpGL.Objects.Common.ShaderLoadingHelper.LoadUniformNameMap(strGround);
                this.groundRenderer = new ModernRenderer(model, shaders, propertyNameMap, uniformNameMap);
                this.groundRenderer.Initialize();
            }

            Padding        uiPadding = new System.Windows.Forms.Padding(10, 10, 10, 10);
            Size           uiSize    = new System.Drawing.Size(50, 50);
            IUILayoutParam uiParam   = new IUILayoutParam(AnchorStyles.Left | AnchorStyles.Bottom, uiPadding, uiSize);

            uiAxis = new SimpleUIAxis(uiParam);
            uiAxis.Initialize();

            {
                IModel model = (new TeapotFactory()).Create(1.0f);
                this.renderer = new SimpleRenderer(model);
                this.renderer.Initialize();//不在此显式初始化也可以。
            }

            this.glCanvas1.MouseWheel += glCanvas1_MouseWheel;
            this.glCanvas1.KeyPress   += glCanvas1_KeyPress;
            this.glCanvas1.MouseDown  += glCanvas1_MouseDown;
            this.glCanvas1.MouseMove  += glCanvas1_MouseMove;
            this.glCanvas1.MouseUp    += glCanvas1_MouseUp;
            this.glCanvas1.OpenGLDraw += glCanvas1_OpenGLDraw;
            this.glCanvas1.Resize     += glCanvas1_Resize;
        }
Ejemplo n.º 37
0
        public static TerrainRenderer GetRenderer(IList <vec3> positions)
        {
            BoundingBox boundingBox = positions.Move2Center();

            IBufferable model       = new TerrainModel(positions);
            var         shaderCodes = new ShaderCode[2];

            shaderCodes[0] = new ShaderCode(File.ReadAllText(@"shaders\Terrain.vert"), ShaderType.VertexShader);
            shaderCodes[1] = new ShaderCode(File.ReadAllText(@"shaders\Terrain.frag"), ShaderType.FragmentShader);
            var map = new PropertyNameMap();

            map.Add("in_Position", TerrainModel.strPosition);
            var renderer = new TerrainRenderer(model, shaderCodes, map, boundingBox,
                                               new PointSizeSwitch(10));

            return(renderer);
        }
Ejemplo n.º 38
0
        //private vec3 scale;

        //public vec3 Scale
        //{
        //    get { return scale; }
        //    set
        //    {
        //        if (value != scale)
        //        {
        //            scale = value;
        //            if (this.initialized)
        //            {
        //                this.SetUniform("modelMatrix",
        //                    glm.scale(glm.translate(mat4.identity(), this.translate), this.scale));
        //            }
        //        }
        //    }
        //}

        //private vec3 translate;

        //public vec3 Translate
        //{
        //    get { return translate; }
        //    set
        //    {
        //        if (value != translate)
        //        {
        //            translate = value;
        //            if (this.initialized)
        //            {
        //                this.SetUniform("modelMatrix",
        //           glm.scale(glm.translate(mat4.identity(), this.translate), this.scale));
        //            }
        //        }
        //    }
        //}

        public BoudingBoxRenderer(vec3 lengths)
            : base(null, null, null)
        {
            this.bufferable = new BoundingBox(lengths);
            var shaderCodes = new ShaderCode[2];

            shaderCodes[0] = new ShaderCode(File.ReadAllText(
                                                @"shaders\BoundingBox.vert"), ShaderType.VertexShader);
            shaderCodes[1] = new ShaderCode(File.ReadAllText(
                                                @"shaders\BoundingBox.frag"), ShaderType.FragmentShader);
            this.shaderCodes = shaderCodes;
            var map = new PropertyNameMap();

            map.Add("in_Position", BoundingBox.strPosition);
            this.propertyNameMap = map;
            this.switchList.Add(new PolygonModeSwitch(PolygonModes.Lines));
        }
Ejemplo n.º 39
0
 private void Form01ModernRenderer_Load(object sender, EventArgs e)
 {
     {
         var camera = new Camera(CameraType.Perspecitive, this.glCanvas1.Width, this.glCanvas1.Height);
         camera.Position = new vec3(0, 0, 5);
         var rotator = new SatelliteRotator(camera);
         this.camera  = camera;
         this.rotator = rotator;
     }
     {
         IBufferable  bufferable = new BigDipperAdapter(new BigDipper());
         ShaderCode[] shaders    = new ShaderCode[2];
         shaders[0] = new ShaderCode(File.ReadAllText(@"Shaders\BigDipper.vert"), ShaderType.VertexShader);
         shaders[1] = new ShaderCode(File.ReadAllText(@"Shaders\BigDipper.frag"), ShaderType.FragmentShader);
         var propertyNameMap = new PropertyNameMap();
         propertyNameMap.Add("in_Position", "position");
         propertyNameMap.Add("in_Color", "color");
         var renderer = new ModernRenderer(bufferable, shaders, propertyNameMap, "position");
         renderer.Initialize();
         GLSwitch lineWidthSwitch = new LineWidthSwitch(10.0f);
         renderer.SwitchList.Add(lineWidthSwitch);
         GLSwitch pointSizeSwitch = new PointSizeSwitch(10.0f);
         renderer.SwitchList.Add(pointSizeSwitch);
         this.renderer = renderer;
     }
     {
         var frmBulletinBoard = new FormBulletinBoard();
         frmBulletinBoard.Dump = true;
         frmBulletinBoard.Show();
         this.bulletinBoard = frmBulletinBoard;
     }
     {
         var frmPropertyGrid = new FormProperyGrid();
         frmPropertyGrid.DisplayObject(this.renderer);
         frmPropertyGrid.Show();
         this.rendererPropertyGrid = frmPropertyGrid;
     }
     {
         var frmPropertyGrid = new FormProperyGrid();
         frmPropertyGrid.DisplayObject(this.camera);
         frmPropertyGrid.Show();
         this.cameraPropertyGrid = frmPropertyGrid;
     }
 }
Ejemplo n.º 40
0
        /// <summary>
        /// opengl UI for Axis
        /// </summary>
        /// <param name="anchor"></param>
        /// <param name="margin"></param>
        /// <param name="size"></param>
        /// <param name="zNear"></param>
        /// <param name="zFar"></param>
        public UIAxis(
            System.Windows.Forms.AnchorStyles anchor, System.Windows.Forms.Padding margin,
            System.Drawing.Size size, int zNear, int zFar)
            : base(anchor, margin, size, zNear, zFar)
        {
            this.Name = typeof(UIAxis).Name;
            var shaderCodes = new ShaderCode[2];
            shaderCodes[0] = new ShaderCode(ManifestResourceLoader.LoadTextFile(
            @"Resources.UIAxis.vert"), ShaderType.VertexShader);
            shaderCodes[1] = new ShaderCode(ManifestResourceLoader.LoadTextFile(
            @"Resources.UIAxis.frag"), ShaderType.FragmentShader);
            var map = new PropertyNameMap();
            map.Add("in_Position", "position");
            map.Add("in_Color", "color");
            //PickableRenderer renderer = (new Axis()).GetRenderer(shaderCodes, map, "position");
            PickableRenderer renderer = new PickableRenderer(new Axis(), shaderCodes, map, "position");

            this.Renderer = renderer;
        }
Ejemplo n.º 41
0
        /// <summary>
        /// 支持UI布局的渲染器
        /// </summary>
        /// <param name="modernRenderer">要渲染的对象</param>
        /// <param name="Anchor">绑定到窗口的哪些边?</param>
        /// <param name="Margin">到绑定边的距离</param>
        /// <param name="Size">UI大小</param>
        /// <param name="zNear"></param>
        /// <param name="zFar"></param>
        public UIAxisRenderer(
            System.Windows.Forms.AnchorStyles Anchor,
            System.Windows.Forms.Padding Margin,
            System.Drawing.Size Size,
            int zNear = -1000,
            int zFar  = 1000
            )
            : base(null, Anchor, Margin, Size, zNear, zFar)
        {
            ShaderCode[] shaderCodes = new ShaderCode[2];
            shaderCodes[0] = new ShaderCode(File.ReadAllText(@"01Renderer\Simple.vert"), ShaderType.VertexShader);
            shaderCodes[1] = new ShaderCode(File.ReadAllText(@"01Renderer\Simple.frag"), ShaderType.FragmentShader);
            var propertyNameMap = new PropertyNameMap();

            propertyNameMap.Add("in_Position", "position");
            propertyNameMap.Add("in_Color", "color");

            PickableRenderer pickableRenderer = PickableRendererFactory.GetRenderer(
                new Axis(), shaderCodes, propertyNameMap, "position");

            pickableRenderer.Name = string.Format("Pickable: [{0}]", "Axis");
            pickableRenderer.Initialize();
            {
                GLSwitch lineWidthSwitch = new LineWidthSwitch(10);
                pickableRenderer.SwitchList.Add(lineWidthSwitch);
                GLSwitch pointSizeSwitch = new PointSizeSwitch(10);
                pickableRenderer.SwitchList.Add(pointSizeSwitch);
                GLSwitch polygonModeSwitch = new PolygonModeSwitch(PolygonModes.Filled);
                pickableRenderer.SwitchList.Add(polygonModeSwitch);
                if (pickableRenderer is OneIndexRenderer)
                {
                    GLSwitch primitiveRestartSwitch = new PrimitiveRestartSwitch((pickableRenderer as OneIndexRenderer).IndexBufferPtr);
                    pickableRenderer.SwitchList.Add(primitiveRestartSwitch);
                }
            }
            this.renderer = pickableRenderer;

            this.textList.Add(new Tuple <vec3, string, Font, Color>(new vec3(offset, 0, 0), "X", new Font("Courier New", fontSize), Color.Red));
            this.textList.Add(new Tuple <vec3, string, Font, Color>(new vec3(0, offset, 0), "Y", new Font("Courier New", fontSize), Color.Green));
            this.textList.Add(new Tuple <vec3, string, Font, Color>(new vec3(0, 0, offset), "Z", new Font("Courier New", fontSize), Color.Blue));
        }
        /// <summary>
        /// 根据<see cref="IndexBufferPtr"/>的具体类型获取一个<see cref="PickableRenderer"/>
        /// </summary>
        /// <param name="bufferable"></param>
        /// <param name="shaderCodes"></param>
        /// <param name="propertyNameMap"></param>
        /// <param name="positionNameInIBufferable"></param>
        /// <param name="switches"></param>
        /// <returns></returns>
        public static InnerPickableRenderer GetRenderer(
            this IBufferable bufferable,
            PropertyNameMap propertyNameMap,
            string positionNameInIBufferable,
            params GLSwitch[] switches)
        {
            if (bufferable == null || propertyNameMap == null || string.IsNullOrEmpty(positionNameInIBufferable))
            { throw new ArgumentNullException(); }

            IndexBufferPtr indexBufferPtr = bufferable.GetIndex();
            if (indexBufferPtr is ZeroIndexBufferPtr)
            {
                return new ZeroIndexRenderer(bufferable, PickingShaderHelper.GetShaderCodes(), propertyNameMap, positionNameInIBufferable, switches);
            }
            else if (indexBufferPtr is OneIndexBufferPtr)
            {
                return new OneIndexRenderer(bufferable, PickingShaderHelper.GetShaderCodes(), propertyNameMap, positionNameInIBufferable, switches);
            }
            else
            { throw new NotImplementedException(); }
        }
Ejemplo n.º 43
0
 /// <summary>
 /// 支持"拾取"的渲染器
 /// </summary>
 /// <param name="bufferable">一种渲染方式</param>
 /// <param name="shaderCodes">各种类型的shader代码</param>
 /// <param name="propertyNameMap">关联<see cref="PropertyBufferPtr"/>和<see cref="shaderCode"/>中的属性</param>
 /// <param name="positionNameInIBufferable">描述顶点位置信息的buffer的名字</param>
 ///<param name="switches"></param>
 internal InnerPickableRenderer(IBufferable bufferable, ShaderCode[] shaderCodes,
     PropertyNameMap propertyNameMap, string positionNameInIBufferable,
     params GLSwitch[] switches)
     : base(bufferable, shaderCodes, propertyNameMap, switches)
 {
     {
         this.positionNameInIBufferable = positionNameInIBufferable;
     }
     {
         this.switchList.Add(polygonModeSwitch);
     }
     {
         float min, max;
         OpenGL.LineWidthRange(out min, out max);
         this.switchList.Add(new LineWidthSwitch(max));
     }
     {
         float min, max;
         OpenGL.PointSizeRange(out min, out max);
         this.switchList.Add(new PointSizeSwitch(max));
     }
 }
Ejemplo n.º 44
0
 protected override void DoInitialize()
 {
     {
         var computeProgram = new ShaderProgram();
         var shaderCode = new ShaderCode(File.ReadAllText(
             @"06ImageProcessing\ImageProcessing.comp"), ShaderType.ComputeShader);
         var shader = shaderCode.CreateShader();
         computeProgram.Create(shader);
         shader.Delete();
         this.computeProgram = computeProgram;
     }
     {
         Bitmap bitmap = new System.Drawing.Bitmap(this.textureFilename);
         if (bitmap.Width != 512 || bitmap.Height != 512)
         {
             bitmap = (Bitmap)bitmap.GetThumbnailImage(512, 512, null, IntPtr.Zero);
         }
         OpenGL.GenTextures(1, this.input_image);
         OpenGL.BindTexture(OpenGL.GL_TEXTURE_2D, this.input_image[0]);
         //  Lock the image bits (so that we can pass them to OGL).
         BitmapData bitmapData = bitmap.LockBits(
             new Rectangle(0, 0, bitmap.Width, bitmap.Height),
             ImageLockMode.ReadOnly, PixelFormat.Format32bppArgb);
         //GL.ActiveTexture(GL.GL_TEXTURE0);
         OpenGL.TexImage2D(OpenGL.GL_TEXTURE_2D, 0, (int)OpenGL.GL_RGBA32F,
             bitmap.Width, bitmap.Height, 0, OpenGL.GL_BGRA, OpenGL.GL_UNSIGNED_BYTE,
             bitmapData.Scan0);
         //  Unlock the image.
         bitmap.UnlockBits(bitmapData);
         /* We require 1 byte alignment when uploading texture data */
         //GL.PixelStorei(GL.GL_UNPACK_ALIGNMENT, 1);
         /* Clamping to edges is important to prevent artifacts when scaling */
         OpenGL.TexParameteri(OpenGL.GL_TEXTURE_2D, OpenGL.GL_TEXTURE_WRAP_S, (int)OpenGL.GL_CLAMP_TO_EDGE);
         OpenGL.TexParameteri(OpenGL.GL_TEXTURE_2D, OpenGL.GL_TEXTURE_WRAP_T, (int)OpenGL.GL_CLAMP_TO_EDGE);
         /* Linear filtering usually looks best for text */
         OpenGL.TexParameteri(OpenGL.GL_TEXTURE_2D, OpenGL.GL_TEXTURE_MIN_FILTER, (int)OpenGL.GL_LINEAR);
         OpenGL.TexParameteri(OpenGL.GL_TEXTURE_2D, OpenGL.GL_TEXTURE_MAG_FILTER, (int)OpenGL.GL_LINEAR);
         bitmap.Dispose();
     }
     {
         //GL.ActiveTexture(GL.GL_TEXTURE0);
         OpenGL.GenTextures(1, this.intermediate_image);
         OpenGL.BindTexture(OpenGL.GL_TEXTURE_2D, this.intermediate_image[0]);
         OpenGL.TexStorage2D(TexStorage2DTarget.Texture2D, 8, OpenGL.GL_RGBA32F, 512, 512);
     }
     {
         // This is the texture that the compute program will write into
         //GL.ActiveTexture(GL.GL_TEXTURE0);
         OpenGL.GenTextures(1, this.output_image);
         OpenGL.BindTexture(OpenGL.GL_TEXTURE_2D, this.output_image[0]);
         OpenGL.TexStorage2D(TexStorage2DTarget.Texture2D, 8, OpenGL.GL_RGBA32F, 512, 512);
     }
     {
         var bufferable = new ImageProcessingModel();
         ShaderCode[] simpleShader = new ShaderCode[2];
         simpleShader[0] = new ShaderCode(File.ReadAllText(@"06ImageProcessing\ImageProcessing.vert"), ShaderType.VertexShader);
         simpleShader[1] = new ShaderCode(File.ReadAllText(@"06ImageProcessing\ImageProcessing.frag"), ShaderType.FragmentShader);
         var propertyNameMap = new PropertyNameMap();
         propertyNameMap.Add("vert", "position");
         propertyNameMap.Add("uv", "uv");
         var pickableRenderer = new PickableRenderer(
             bufferable, simpleShader, propertyNameMap, "position");
         pickableRenderer.Name = string.Format("Pickable: [ImageProcessingRenderer]");
         pickableRenderer.Initialize();
         pickableRenderer.SetUniform("output_image",
             new samplerValue(
                 BindTextureTarget.Texture2D, this.output_image[0], OpenGL.GL_TEXTURE0));
         this.renderer = pickableRenderer;
     }
 }
Ejemplo n.º 45
0
 /// <summary>
 /// 用glDrawElements进行渲染。
 /// </summary>
 /// <param name="bufferable">一种渲染方式</param>
 /// <param name="shaderCodes">各种类型的shader代码</param>
 /// <param name="propertyNameMap">关联<see cref="PropertyBufferPtr"/>和<see cref="shaderCode"/>中的属性</param>
 /// <param name="positionNameInIBufferable">描述顶点位置信息的buffer的名字</param>
 ///<param name="switches"></param>
 internal OneIndexRenderer(IBufferable bufferable, ShaderCode[] shaderCodes,
     PropertyNameMap propertyNameMap, string positionNameInIBufferable,
     params GLSwitch[] switches)
     : base(bufferable, shaderCodes, propertyNameMap, positionNameInIBufferable, switches)
 {
 }
Ejemplo n.º 46
0
        private void mniLoadECLGrid_Click(object sender, EventArgs e)
        {
            if (openFileDialog1.ShowDialog() != DialogResult.OK)
            {
                return;
            }

            //ModelContainer modelContainer = this.ModelContainer;

            string fileName = openFileDialog1.FileName;
            SimulationInputData inputData;
            try
            {
                inputData = this.LoadEclInputData(fileName);
            }
            catch (Exception err)
            {
                MessageBox.Show(String.Format("Load Error,{0}", err.Message), "Error", MessageBoxButtons.OK, MessageBoxIcon.Error);
                return;
            }

            try
            {
                List<GridBlockProperty> gridProps = inputData.RootDataFile.GetGridProperties();
                GridBlockProperty gbp = gridProps[0];
                double axisMin, axisMax, step;
                ColorIndicatorAxisAutomator.Automate(gbp.MinValue, gbp.MaxValue, out axisMin, out axisMax, out step);
                CatesianGrid grid = inputData.DumpCatesianGrid((float)axisMin, (float)axisMax);
                var shaderCodes = new ShaderCode[2];
                shaderCodes[0] = new ShaderCode(File.ReadAllText(@"shaders\HexahedronGrid.vert"), ShaderType.VertexShader);
                shaderCodes[1] = new ShaderCode(File.ReadAllText(@"shaders\HexahedronGrid.frag"), ShaderType.FragmentShader);
                var map = new PropertyNameMap();
                map.Add("in_Position", CatesianGrid.strPosition);
                map.Add("in_uv", CatesianGrid.strColor);
                var scientificRenderer = new Renderer(grid, shaderCodes, map);
                var boundedRenderer = new BoundedRenderer(scientificRenderer,
                    grid.DataSource.SourceActiveBounds.Max - grid.DataSource.SourceActiveBounds.Min);
                boundedRenderer.Initialize();
                SceneObject sceneObject = new SceneObject();
                sceneObject.Name = typeof(CatesianGrid).Name;
                sceneObject.Renderer = new BoundedRendererComponent(boundedRenderer);
                //sceneObject.Transform.Position = grid.DataSource.TranslateMatrix;
                this.scientificCanvas.Scene.ObjectList.Add(sceneObject);
                //sceneObject.Renderer=ne
                //SimLabGrid gridder = null;
                //try
                //{
                //    gridderSource = CreateGridderSource(inputData);
                //}
                //catch (Exception err)
                //{
                //    MessageBox.Show(String.Format("Create Gridder Failed,{0}", err.Message), "Error", MessageBoxButtons.OK, MessageBoxIcon.Error);
                //    return;
                //}

                //if (gridderSource != null)
                //{
                //    string caseFileName = System.IO.Path.GetFileName(fileName);
                //    TreeNode gridderNode = this.objectsTreeView.Nodes.Add(caseFileName);
                //    gridderNode.ToolTipText = fileName;
                //    List<GridBlockProperty> gridProps = inputData.RootDataFile.GetGridProperties();
                //    if (gridProps.Count <= 0)
                //    {
                //        GridBlockProperty gbp = this.CreateGridSequenceGridBlockProperty(gridderSource, "INDEX");
                //        gridProps.Add(gbp);
                //    }
                //    foreach (GridBlockProperty gbp in gridProps)
                //    {
                //        TreeNode propNode = gridderNode.Nodes.Add(gbp.Name);
                //        propNode.Tag = gbp;
                //    }

                //    vec3 boundMin;
                //    vec3 boundMax;
                //    gridder = CreateGridder(gridderSource, gridProps[0], out boundMin, out boundMax);
                //    if (gridder != null)
                //    {
                //        this.objectsTreeView.ExpandAll();
                //        //modelContainer.AddChild(gridder);
                //        //modelContainer.BoundingBox.SetBounds(gridderSource.TransformedActiveBounds.Min, gridderSource.TransformedActiveBounds.Max);
                //        //this.scene.ViewType = ViewTypes.UserView;
                //        gridderNode.Tag = gridder;
                //        gridder.Tag = gridderSource;
                //        gridderSource.Tag = gridderNode.Nodes[0];
                //        gridderNode.Checked = gridder.IsEnabled;
                //        gridderNode.Nodes[0].Checked = true;
                //    }

                //List<Well> well3dList;
                //try
                //{
                //    well3dList = this.CreateWell3D(inputData, this.scene, gridderSource);
                //}
                //catch (Exception err)
                //{
                //    MessageBox.Show(String.Format("Create Well3d,{0}", err.Message), "Error", MessageBoxButtons.OK, MessageBoxIcon.Error);
                //    return;
                //}
                //if (well3dList != null && well3dList.Count > 0)
                //    this.AddWellNodes(gridderNode, this.scene, well3dList);
                //}
            }
            catch (Exception ex)
            {
                MessageBox.Show(ex.ToString());
            }
        }