public StereoDrawContext(DrawSystem.D3DData d3d, DrawResourceRepository repository, HmdDevice hmd, DrawContext context)
        {
            m_d3d        = d3d;
            m_repository = repository;
            m_context    = context;
            m_hmd        = hmd;

            // Create render targets for each HMD eye
            m_textureSets = new HmdSwapTextureSet[2];
            var eyeResolution = hmd.EyeResolution;
            var resNames      = new string[] { "OVRLeftEye", "OVRRightEye" };

            for (int index = 0; index < 2; ++index)
            {
                var textureSet = m_hmd.CreateSwapTextureSet(d3d.Device, eyeResolution.Width, eyeResolution.Height);
                m_textureSets[index] = textureSet;

                var renderTargetList = RenderTarget.FromSwapTextureSet(m_d3d, resNames[index], textureSet);
                foreach (var renderTarget in renderTargetList)
                {
                    m_repository.AddResource(renderTarget);
                }
            }

            // Create temporaly render target
            var tmpRt = RenderTarget.CreateRenderTarget(d3d, "Temp", eyeResolution.Width, eyeResolution.Height);

            m_repository.AddResource(tmpRt);

            // Create texture for Mirroring
            Size defaultRenderTargetSize = m_repository.GetDefaultRenderTarget().Resolution;

            m_mirrorTexture = m_hmd.CreateMirrorTexture(m_d3d.Device, defaultRenderTargetSize.Width, defaultRenderTargetSize.Height);

            m_commandListTable = new List <CommandList>();
        }
Esempio n. 2
0
            public Factory(DrawSystem.D3DData d3d, DrawResourceRepository repository)
            {
                m_initParam.D3D        = d3d;
                m_initParam.Repository = repository;

                m_initParam.WorldVtxConst = DrawUtil.CreateConstantBuffer <_VertexShaderConst_World>(d3d, 1);
                m_initParam.WorldPixConst = DrawUtil.CreateConstantBuffer <_PixelShaderConst_World>(d3d, 1);

                m_initParam.RasterizerState = new RasterizerState(d3d.Device, new RasterizerStateDescription()
                {
                    CullMode = CullMode.Back,
                    FillMode = FillMode.Solid,
                    IsAntialiasedLineEnabled = false,                           // we do not use wireframe
                    IsDepthClipEnabled       = true,
                    IsMultisampleEnabled     = false,
                });

                var renderModes = new[] { DrawSystem.RenderMode.Opaque, DrawSystem.RenderMode.Transparency };

                m_initParam.BlendStates = new BlendState[renderModes.Length];
                foreach (DrawSystem.RenderMode mode in renderModes)
                {
                    int index = (int)mode;
                    m_initParam.BlendStates[index] = _CreateBlendState(d3d, mode);
                }
                m_initParam.DepthStencilStates = new DepthStencilState[renderModes.Length];
                foreach (DrawSystem.RenderMode mode in renderModes)
                {
                    int index = (int)mode;
                    m_initParam.DepthStencilStates[index] = _CreateDepthStencilState(d3d, mode);
                }

                {
                    var shader = new Effect(
                        "Std",
                        d3d,
                        new InputElement[]
                    {
                        new InputElement("POSITION", 0, Format.R32G32B32A32_Float, 0, 0),
                        new InputElement("NORMAL", 0, Format.R32G32B32_Float, 16, 0),
                        new InputElement("TEXCOORD", 0, Format.R32G32_Float, 28, 0),
                        new InputElement("TANGENT", 0, Format.R32G32B32_Float, 0, 1),
                        new InputElement("BONEINDEX", 0, Format.R32G32B32A32_UInt, 0, 2),
                        new InputElement("BONEWEIGHT", 0, Format.R32G32B32A32_Float, 16, 2),
                    },
                        "Shader/VS_Std.fx",
                        "Shader/PS_Std.fx");

                    repository.AddResource(shader);
                }

                {
                    var shader = new Effect(
                        "Minimap",
                        d3d,
                        new InputElement[]
                    {
                        new InputElement("POSITION", 0, Format.R32G32B32A32_Float, 0, 0),
                        new InputElement("NORMAL", 0, Format.R32G32B32_Float, 16, 0),
                        new InputElement("TEXCOORD", 0, Format.R32G32_Float, 28, 0),
                        new InputElement("TANGENT", 0, Format.R32G32B32_Float, 0, 1),
                        new InputElement("BONEINDEX", 0, Format.R32G32B32A32_UInt, 0, 2),
                        new InputElement("BONEWEIGHT", 0, Format.R32G32B32A32_Float, 16, 2),
                    },
                        "Shader/VS_Std.fx",
                        "Shader/PS_Minimap.fx");

                    repository.AddResource(shader);
                }

                {
                    var shader = new Effect(
                        "Debug",
                        d3d,
                        new InputElement[]
                    {
                        new InputElement("POSITION", 0, Format.R32G32B32A32_Float, 0, 0),
                        new InputElement("COLOR", 0, Format.R32G32B32A32_Float, 16, 0),
                    },
                        "Shader/VS_Debug.fx",
                        "Shader/PS_Debug.fx");

                    repository.AddResource(shader);
                }
            }