Пример #1
0
        protected virtual void Display()
        {
            if (UsePBO)
            {
                DrawPbo();
            }
            else
            {
                BufferStream stream = OutputBuffer.Map();

                PixelType   type   = 0;
                PixelFormat format = 0;
                switch (OutputBuffer.Format)
                {
                case Format.UByte4:
                    format = PixelFormat.Bgra;
                    type   = PixelType.UnsignedByte;
                    break;

                case Format.Float4:
                    format = PixelFormat.Rgba;
                    type   = PixelType.Float;
                    break;

                case Format.Float3:
                    format = PixelFormat.Rgb;
                    type   = PixelType.Float;
                    break;

                case Format.Float:
                    format = PixelFormat.Luminance;
                    type   = PixelType.Float;
                    break;

                default:
                    throw new Exception("Unsupported format for glDrawPixels");
                }

                Gl.DrawPixels(Width, Height, format, type, stream.DataPointer);

                OutputBuffer.Unmap();
            }
            this.SwapBuffers();
        }
        private void CreateLights()
        {
            var light = new ParallelogramLight
            {
                corner = new Vector3(2.8096f, 17.1165f, 2.3659f),
                v1     = new Vector3(-5.0f, 0.0f, 0.0f),
                v2     = new Vector3(0.0f, 0.0f, 5.0f)
            };

            light.normal   = Vector3.Normalize(Vector3.Cross(light.v1, light.v2));
            light.emission = new Vector3(15.0f, 15.0f, 5.0f);

            var desc = new BufferDesc {
                Width = 1u, Format = Format.User, Type = BufferType.Input, ElemSize = (uint)Marshal.SizeOf(typeof(ParallelogramLight))
            };
            var lightBuffer = new OptixBuffer(OptixContext, desc);
            var stream      = lightBuffer.Map();

            stream.Write(light);
            lightBuffer.Unmap();

            OptixContext["plights"].Set(lightBuffer);
        }