예제 #1
0
        internal unsafe void RecordCommands(MyRenderableProxy proxy, VertexBufferId stream, int voxelMatId)
        {
            MyObjectData objectData = proxy.ObjectData;

            var foliageType = MyVoxelMaterials1.Table[voxelMatId].FoliageType;

            MyMapping mapping;

            mapping = MyMapping.MapDiscard(RC.Context, proxy.ObjectBuffer);
            void *ptr = &objectData;

            mapping.stream.Write(new IntPtr(ptr), 0, sizeof(MyObjectData));
            mapping.Unmap();

            RC.SetCB(MyCommon.OBJECT_SLOT, proxy.ObjectBuffer);

            RC.SetGS(m_GS[foliageType]);
            RC.SetPS(m_PS[foliageType]);

            if (MyVoxelMaterials1.Table[voxelMatId].FoliageColorTextureArray != null)
            {
                RC.BindRawSRV(0, MyVoxelMaterials1.Table[voxelMatId].FoliageColorTextureArray.ShaderView);
                RC.BindRawSRV(1, MyVoxelMaterials1.Table[voxelMatId].FoliageNormalTextureArray.ShaderView);
            }
            else
            {
                RC.BindRawSRV(0, MyTextures.GetView(MyTextures.GetTexture(MyVoxelMaterials1.Table[voxelMatId].FoliageArray_Texture, MyTextureEnum.COLOR_METAL, true)));
                RC.BindRawSRV(1, MyTextures.GetView(MyTextures.GetTexture(MyVoxelMaterials1.Table[voxelMatId].FoliageArray_NormalTexture, MyTextureEnum.NORMALMAP_GLOSS, true)));
            }

            RC.SetVB(0, stream.Buffer, stream.Stride);
            Context.DrawAuto();
            RC.Stats.DrawAuto++;
        }
예제 #2
0
        internal static VertexBufferId CreateVertexBuffer(BufferDescription description, int stride, IntPtr?data, string debugName)
        {
            if (description.SizeInBytes == 0)
            {
                return(VertexBufferId.NULL);
            }

            var id = new VertexBufferId {
                Index = VBuffers.Allocate()
            };

            MyArrayHelpers.Reserve(ref VBuffersData, id.Index + 1);
            VBuffers.Data[id.Index] = new MyHwBufferDesc {
                Description = description, DebugName = debugName
            };
            VBuffersData[id.Index] = new MyVertexBufferData {
                Stride = stride
            };

            VbIndices.Add(id);

            if (!data.HasValue)
            {
                InitVertexBuffer(id);
            }
            else
            {
                InitVertexBuffer(id, data.Value);
            }

            return(id);
        }
        internal unsafe void RecordCommands(MyRenderableProxy proxy, VertexBufferId stream, int voxelMatId)
        {
            if (stream == VertexBufferId.NULL)
            {
                return;
            }

            var foliageType = MyVoxelMaterials1.Table[voxelMatId].FoliageType;

            MyMapping mapping = MyMapping.MapDiscard(RC.DeviceContext, proxy.ObjectBuffer);

            mapping.WriteAndPosition(ref proxy.NonVoxelObjectData);
            mapping.WriteAndPosition(ref proxy.CommonObjectData);
            mapping.Unmap();

            RC.SetCB(MyCommon.OBJECT_SLOT, proxy.ObjectBuffer);

            RC.SetGS(m_GS[foliageType]);
            RC.SetPS(m_PS[foliageType]);

            if (MyVoxelMaterials1.Table[voxelMatId].FoliageColorTextureArray != null)
            {
                RC.BindRawSRV(0, MyVoxelMaterials1.Table[voxelMatId].FoliageColorTextureArray.ShaderView);
                RC.BindRawSRV(1, MyVoxelMaterials1.Table[voxelMatId].FoliageNormalTextureArray.ShaderView);
            }
            else
            {
                RC.BindRawSRV(0, MyTextures.GetView(MyTextures.GetTexture(MyVoxelMaterials1.Table[voxelMatId].FoliageArray_Texture, MyTextureEnum.COLOR_METAL, true)));
                RC.BindRawSRV(1, MyTextures.GetView(MyTextures.GetTexture(MyVoxelMaterials1.Table[voxelMatId].FoliageArray_NormalTexture, MyTextureEnum.NORMALMAP_GLOSS, true)));
            }

            RC.SetVB(0, stream.Buffer, stream.Stride);
            Context.DrawAuto();
            RC.Stats.DrawAuto++;
        }
        internal static void Init()
        {
            //MyRender11.RegisterSettingsChangedListener(new OnSettingsChangedDelegate(RecreateShadersForSettings));
            m_screenVertexShader    = MyShaders.CreateVs("Debug/DebugBaseColor.hlsl");
            m_baseColorShader       = MyShaders.CreatePs("Debug/DebugBaseColor.hlsl");
            m_albedoShader          = MyShaders.CreatePs("Debug/DebugAlbedo.hlsl");
            m_normalShader          = MyShaders.CreatePs("Debug/DebugNormal.hlsl");
            m_normalViewShader      = MyShaders.CreatePs("Debug/DebugNormalView.hlsl");
            m_glossinessShader      = MyShaders.CreatePs("Debug/DebugGlossiness.hlsl");
            m_metalnessShader       = MyShaders.CreatePs("Debug/DebugMetalness.hlsl");
            m_aoShader              = MyShaders.CreatePs("Debug/DebugAmbientOcclusion.hlsl");
            m_emissiveShader        = MyShaders.CreatePs("Debug/DebugEmissive.hlsl");
            m_ambientDiffuseShader  = MyShaders.CreatePs("Debug/DebugAmbientDiffuse.hlsl");
            m_ambientSpecularShader = MyShaders.CreatePs("Debug/DebugAmbientSpecular.hlsl");
            m_edgeDebugShader       = MyShaders.CreatePs("Debug/DebugEdge.hlsl");
            m_shadowsDebugShader    = MyShaders.CreatePs("Debug/DebugCascadesShadow.hlsl");
            m_NDotLShader           = MyShaders.CreatePs("Debug/DebugNDotL.hlsl");
            m_depthShader           = MyShaders.CreatePs("Debug/DebugDepth.hlsl");
            m_stencilShader         = MyShaders.CreatePs("Debug/DebugStencil.hlsl");
            m_rtShader              = MyShaders.CreatePs("Debug/DebugRt.hlsl");

            m_blitTextureShader      = MyShaders.CreatePs("Debug/DebugBlitTexture.hlsl");
            m_blitTexture3DShader    = MyShaders.CreatePs("Debug/DebugBlitTexture3D.hlsl");
            m_blitTextureArrayShader = MyShaders.CreatePs("Debug/DebugBlitTextureArray.hlsl");
            m_inputLayout            = MyShaders.CreateIL(m_screenVertexShader.BytecodeId, MyVertexLayouts.GetLayout(MyVertexInputComponentType.POSITION2, MyVertexInputComponentType.TEXCOORD0));

            m_quadBuffer = MyHwBuffers.CreateVertexBuffer(6, MyVertexFormatPosition2Texcoord.STRIDE, BindFlags.VertexBuffer, ResourceUsage.Dynamic, null, "MyDebugRenderer quad");
        }
        internal unsafe void RecordCommands(MyRenderableProxy proxy, VertexBufferId stream, int voxelMatId)
        {
            if (stream == VertexBufferId.NULL) return;

            var foliageType = MyVoxelMaterials1.Table[voxelMatId].FoliageType;

            MyMapping mapping = MyMapping.MapDiscard(RC.DeviceContext, proxy.ObjectBuffer);
            mapping.WriteAndPosition(ref proxy.NonVoxelObjectData);
            mapping.WriteAndPosition(ref proxy.CommonObjectData);
            mapping.Unmap();

            RC.SetCB(MyCommon.OBJECT_SLOT, proxy.ObjectBuffer);

            RC.SetGS(m_GS[foliageType]);
            RC.SetPS(m_PS[foliageType]);

            if (MyVoxelMaterials1.Table[voxelMatId].FoliageColorTextureArray != null)
            {
                RC.BindRawSRV(0, MyVoxelMaterials1.Table[voxelMatId].FoliageColorTextureArray);
                RC.BindRawSRV(1, MyVoxelMaterials1.Table[voxelMatId].FoliageNormalTextureArray);
            }
            else
            {
                RC.BindRawSRV(0, MyTextures.GetTexture(MyVoxelMaterials1.Table[voxelMatId].FoliageArray_Texture, MyTextureEnum.COLOR_METAL, true));
                RC.BindRawSRV(1, MyTextures.GetTexture(MyVoxelMaterials1.Table[voxelMatId].FoliageArray_NormalTexture, MyTextureEnum.NORMALMAP_GLOSS, true));
            }

            RC.SetVB(0, stream.Buffer, stream.Stride);
            Context.DrawAuto();
            RC.Stats.DrawAuto++;
        }
예제 #6
0
        internal unsafe static void Init()
        {
            m_cbCustomProjections = MyHwBuffers.CreateConstantsBuffer(sizeof(Matrix) * MAX_CUSTOM_PROJECTIONS_SIZE, "BilloardCustomProjections");

            m_vs          = MyShaders.CreateVs("Transparent/Billboards.hlsl");
            m_vsDepthOnly = MyShaders.CreateVs("Transparent/BillboardsDepthOnly.hlsl");
            m_ps          = MyShaders.CreatePs("Transparent/Billboards.hlsl");
            m_psDepthOnly = MyShaders.CreatePs("Transparent/BillboardsDepthOnly.hlsl");
            m_psOIT       = MyShaders.CreatePs("Transparent/Billboards.hlsl", new[] { new ShaderMacro("OIT", null) });
            m_vsLit       = MyShaders.CreateVs("Transparent/Billboards.hlsl", new[] { new ShaderMacro("LIT_PARTICLE", null) });
            m_psLit       = MyShaders.CreatePs("Transparent/Billboards.hlsl", new[] { new ShaderMacro("LIT_PARTICLE", null) });
            m_psLitOIT    = MyShaders.CreatePs("Transparent/Billboards.hlsl", new[] { new ShaderMacro("LIT_PARTICLE", null), new ShaderMacro("OIT", null) });

            m_psAlphaCutout       = MyShaders.CreatePs("Transparent/Billboards.hlsl", new[] { new ShaderMacro("ALPHA_CUTOUT", null) });
            m_psAlphaCutoutAndLit = MyShaders.CreatePs("Transparent/Billboards.hlsl",
                                                       new[] { new ShaderMacro("ALPHA_CUTOUT", null), new ShaderMacro("LIT_PARTICLE", null) });
            m_psAlphaCutoutOIT = MyShaders.CreatePs("Transparent/Billboards.hlsl",
                                                    new[] { new ShaderMacro("ALPHA_CUTOUT", null), new ShaderMacro("OIT", null) });
            m_psAlphaCutoutAndLitOIT = MyShaders.CreatePs("Transparent/Billboards.hlsl",
                                                          new[] { new ShaderMacro("ALPHA_CUTOUT", null), new ShaderMacro("LIT_PARTICLE", null), new ShaderMacro("OIT", null) });

            m_psDebugUniformAccum    = MyShaders.CreatePs("Transparent/Billboards.hlsl", new[] { new ShaderMacro("DEBUG_UNIFORM_ACCUM", null) });
            m_psDebugUniformAccumOIT = MyShaders.CreatePs("Transparent/Billboards.hlsl", new[] { new ShaderMacro("DEBUG_UNIFORM_ACCUM", null), new ShaderMacro("OIT", null) });

            m_inputLayout = MyShaders.CreateIL(m_vs.BytecodeId, MyVertexLayouts.GetLayout(MyVertexInputComponentType.POSITION3, MyVertexInputComponentType.TEXCOORD0_H));

            InitBillboardsIndexBuffer();

            m_VB = MyHwBuffers.CreateVertexBuffer(MAX_BILLBOARDS_SIZE * 4, sizeof(MyVertexFormatPositionTextureH), BindFlags.VertexBuffer, ResourceUsage.Dynamic, null, "MyBillboardRenderer");

            var stride = sizeof(MyBillboardData);

            m_SB    = MyHwBuffers.CreateStructuredBuffer(MAX_BILLBOARDS_SIZE, stride, true, null, "MyBillboardRenderer");
            m_atlas = new MyTextureAtlas("Textures\\Particles\\", "Textures\\Particles\\ParticlesAtlas.tai");
        }
        internal unsafe void UpdateGeneric(List <MyInstanceData> instanceData, int capacity)
        {
            Debug.Assert(m_type == MyRenderInstanceBufferType.Generic);

            var instancesNum = instanceData.Count;

            if (m_capacity < instancesNum && VB != VertexBufferId.NULL)
            {
                MyHwBuffers.Destroy(VB);
                VB = VertexBufferId.NULL;
            }
            if (m_capacity < instancesNum)
            {
                m_capacity = Math.Max(instancesNum, capacity);
                VB         = MyHwBuffers.CreateVertexBuffer(m_capacity, sizeof(MyVertexFormatGenericInstance), null, m_debugName + " instances buffer");
            }

            fixed(MyInstanceData *dataPtr = instanceData.ToArray())
            {
                DataBox        srcBox    = new DataBox(new IntPtr(dataPtr));
                ResourceRegion dstRegion = new ResourceRegion(0, 0, 0, sizeof(MyVertexFormatGenericInstance) * instancesNum, 1, 1);

                MyRender11.ImmediateContext.UpdateSubresource(srcBox, VB.Buffer, 0, dstRegion);
            }

            BumpRenderable();
        }
예제 #8
0
        internal static void Init()
        {
            //MyRender11.RegisterSettingsChangedListener(new OnSettingsChangedDelegate(RecreateShadersForSettings));
			m_baseColorShader = MyShaders.CreatePs("debug.hlsl", "base_color");
            m_baseColorLinearShader = MyShaders.CreatePs("debug.hlsl", "base_color_linear");
            m_normalShader = MyShaders.CreatePs("debug.hlsl", "normal");
            m_glossinessShader = MyShaders.CreatePs("debug.hlsl", "glossiness");
            m_metalnessShader = MyShaders.CreatePs("debug.hlsl", "metalness");
            m_matIDShader = MyShaders.CreatePs("debug.hlsl", "mat_id");
            m_aoShader = MyShaders.CreatePs("debug.hlsl", "ambient_occlusion");
            m_emissiveShader = MyShaders.CreatePs("debug.hlsl", "emissive");
            m_ambientDiffuseShader = MyShaders.CreatePs("debug.hlsl", "debug_ambient_diffuse");
            m_ambientSpecularShader = MyShaders.CreatePs("debug.hlsl", "debug_ambient_specular");
            m_edgeDebugShader = MyShaders.CreatePs("debug.hlsl", "debug_edge");
			m_shadowsDebugShader = MyShaders.CreatePs("debug.hlsl", "cascades_shadow", MyRender11.ShaderCascadesNumberHeader());
            m_NDotLShader = MyShaders.CreatePs("debug.hlsl", "NDotL");


            m_screenVertexShader = MyShaders.CreateVs("debug.hlsl", "screenVertex");
            m_blitTextureShader = MyShaders.CreatePs("debug.hlsl", "blitTexture");
            m_blitTexture3DShader = MyShaders.CreatePs("debug.hlsl", "blitTexture3D");
            m_blitTextureArrayShader = MyShaders.CreatePs("debug.hlsl", "blitTextureArray");
            m_inputLayout = MyShaders.CreateIL(m_screenVertexShader.BytecodeId, MyVertexLayouts.GetLayout(MyVertexInputComponentType.POSITION2, MyVertexInputComponentType.TEXCOORD0));

            m_quadBuffer = MyHwBuffers.CreateVertexBuffer(6, MyVertexFormatPosition2Texcoord.STRIDE, BindFlags.VertexBuffer, ResourceUsage.Dynamic);
        }
예제 #9
0
        internal unsafe void RecordCommands(MyRenderableProxy proxy, VertexBufferId stream, int voxelMatId)
        {
            if (stream == VertexBufferId.NULL)
            {
                return;
            }

            var foliageType = MyVoxelMaterials1.Table[voxelMatId].FoliageType;

            MyMapping mapping = MyMapping.MapDiscard(RC, proxy.ObjectBuffer);

            mapping.WriteAndPosition(ref proxy.NonVoxelObjectData);
            mapping.WriteAndPosition(ref proxy.CommonObjectData);
            mapping.Unmap();

            RC.AllShaderStages.SetConstantBuffer(MyCommon.OBJECT_SLOT, proxy.ObjectBuffer);

            RC.GeometryShader.Set(m_GS[foliageType]);
            RC.PixelShader.Set(m_PS[foliageType]);

            if (MyVoxelMaterials1.Table[voxelMatId].FoliageColorTextureArray != null)
            {
                RC.AllShaderStages.SetSrv(0, MyVoxelMaterials1.Table[voxelMatId].FoliageColorTextureArray);
                RC.AllShaderStages.SetSrv(1, MyVoxelMaterials1.Table[voxelMatId].FoliageNormalTextureArray);
            }
            else
            {
                MyFileTextureManager texManager = MyManagers.FileTextures;
                RC.AllShaderStages.SetSrv(0, texManager.GetTexture(MyVoxelMaterials1.Table[voxelMatId].FoliageArray_Texture, MyFileTextureEnum.COLOR_METAL, true));
                RC.AllShaderStages.SetSrv(1, texManager.GetTexture(MyVoxelMaterials1.Table[voxelMatId].FoliageArray_NormalTexture, MyFileTextureEnum.NORMALMAP_GLOSS, true));
            }

            RC.SetVertexBuffer(0, stream.Buffer, stream.Stride);
            RC.DrawAuto();
        }
예제 #10
0
        internal unsafe void RecordCommands(MyRenderableProxy proxy, VertexBufferId stream, int voxelMatId)
        {
            //var worldMat = proxy.WorldMatrix;
            //worldMat.Translation -= MyEnvironment.CameraPosition;
            //proxy.ObjectData.LocalMatrix = worldMat;

            //var worldMatrix = Matrix.CreateTranslation(-MyEnvironment.CameraPosition);
            MyObjectData objectData = proxy.ObjectData;
            //objectData.LocalMatrix = worldMat;

            MyMapping mapping;

            mapping = MyMapping.MapDiscard(RC.Context, proxy.objectBuffer);
            void *ptr = &objectData;

            mapping.stream.Write(new IntPtr(ptr), 0, sizeof(MyObjectData));
            mapping.Unmap();

            RC.SetCB(MyCommon.OBJECT_SLOT, proxy.objectBuffer);

            RC.BindRawSRV(0, MyTextures.GetView(MyTextures.GetTexture(MyVoxelMaterials1.Table[voxelMatId].FoliageArray_Texture, MyTextureEnum.COLOR_METAL, true)));

            RC.SetVB(0, stream.Buffer, stream.Stride);
            Context.DrawAuto();
            RC.Stats.DrawAuto++;
        }
예제 #11
0
        internal unsafe void UpdateCube(List<MyCubeInstanceData> instanceData, int capacity)
        {
            var instancesNum = instanceData.Count;
            if (m_capacity < instancesNum && VertexBuffer != VertexBufferId.NULL)
            {
                MyHwBuffers.Destroy(VertexBuffer);
                VertexBuffer = VertexBufferId.NULL;
            }
            if (m_capacity < instancesNum)
            {
                m_capacity = Math.Max(instancesNum, capacity);

                VertexBuffer = MyHwBuffers.CreateVertexBuffer(m_capacity, sizeof(MyVertexFormatCubeInstance), null, m_debugName + " instances buffer");
            }

            var rawBuffer = new MyVertexFormatCubeInstance[m_capacity];
            for (int i = 0; i < instancesNum; i++)
            {
                fixed (byte* pSource = instanceData[i].RawBones(), pTarget = rawBuffer[i].bones)
                {
                    for (int j = 0; j < MyRender11Constants.CUBE_INSTANCE_BONES_NUM * 4; j++)
                        pTarget[j] = pSource[j];
                }
                rawBuffer[i].translationRotation = new HalfVector4(instanceData[i].m_translationAndRot);
                rawBuffer[i].colorMaskHSV = new HalfVector4(instanceData[i].ColorMaskHSV);
            }

            fixed (MyVertexFormatCubeInstance* dataPtr = rawBuffer)
            {
                DataBox srcBox = new DataBox(new IntPtr(dataPtr));
                ResourceRegion dstRegion = new ResourceRegion(0, 0, 0, sizeof(MyVertexFormatCubeInstance) * instancesNum, 1, 1);

                MyRender11.ImmediateContext.UpdateSubresource(srcBox, VertexBuffer.Buffer, 0, dstRegion);
            }
        }
예제 #12
0
        internal static void Init()
        {
            //MyRender11.RegisterSettingsChangedListener(new OnSettingsChangedDelegate(RecreateShadersForSettings));
            m_screenVertexShader    = MyShaders.CreateVs("debug_base_color.hlsl");
            m_baseColorShader       = MyShaders.CreatePs("debug_base_color.hlsl");
            m_baseColorLinearShader = MyShaders.CreatePs("debug_base_color_linear.hlsl");
            m_normalShader          = MyShaders.CreatePs("debug_normal.hlsl");
            m_glossinessShader      = MyShaders.CreatePs("debug_glossiness.hlsl");
            m_metalnessShader       = MyShaders.CreatePs("debug_metalness.hlsl");
            m_matIDShader           = MyShaders.CreatePs("debug_mat_id.hlsl");
            m_aoShader              = MyShaders.CreatePs("debug_ambient_occlusion.hlsl");
            m_emissiveShader        = MyShaders.CreatePs("debug_emissive.hlsl");
            m_ambientDiffuseShader  = MyShaders.CreatePs("debug_ambient_diffuse.hlsl");
            m_ambientSpecularShader = MyShaders.CreatePs("debug_ambient_specular.hlsl");
            m_edgeDebugShader       = MyShaders.CreatePs("debug_edge.hlsl");
            m_shadowsDebugShader    = MyShaders.CreatePs("debug_cascades_shadow.hlsl");
            m_NDotLShader           = MyShaders.CreatePs("debug_NDotL.hlsl");
            m_stencilShader         = MyShaders.CreatePs("debug_Stencil.hlsl");

            m_blitTextureShader      = MyShaders.CreatePs("debug_blitTexture.hlsl");
            m_blitTexture3DShader    = MyShaders.CreatePs("debug_blitTexture3D.hlsl");
            m_blitTextureArrayShader = MyShaders.CreatePs("debug_blitTextureArray.hlsl");
            m_inputLayout            = MyShaders.CreateIL(m_screenVertexShader.BytecodeId, MyVertexLayouts.GetLayout(MyVertexInputComponentType.POSITION2, MyVertexInputComponentType.TEXCOORD0));

            m_quadBuffer = MyHwBuffers.CreateVertexBuffer(6, MyVertexFormatPosition2Texcoord.STRIDE, BindFlags.VertexBuffer, ResourceUsage.Dynamic);
        }
예제 #13
0
        internal static void Init()
        {
            //MyRender11.RegisterSettingsChangedListener(new OnSettingsChangedDelegate(RecreateShadersForSettings));
            m_screenVertexShader = MyShaders.CreateVs("debug_base_color.hlsl");
            m_baseColorShader = MyShaders.CreatePs("debug_base_color.hlsl");
            m_baseColorLinearShader = MyShaders.CreatePs("debug_base_color_linear.hlsl");
            m_normalShader = MyShaders.CreatePs("debug_normal.hlsl");
            m_glossinessShader = MyShaders.CreatePs("debug_glossiness.hlsl");
            m_metalnessShader = MyShaders.CreatePs("debug_metalness.hlsl");
            m_matIDShader = MyShaders.CreatePs("debug_mat_id.hlsl");
            m_aoShader = MyShaders.CreatePs("debug_ambient_occlusion.hlsl");
            m_emissiveShader = MyShaders.CreatePs("debug_emissive.hlsl");
            m_ambientDiffuseShader = MyShaders.CreatePs("debug_ambient_diffuse.hlsl");
            m_ambientSpecularShader = MyShaders.CreatePs("debug_ambient_specular.hlsl");
            m_edgeDebugShader = MyShaders.CreatePs("debug_edge.hlsl");
            m_shadowsDebugShader = MyShaders.CreatePs("debug_cascades_shadow.hlsl");
            m_NDotLShader = MyShaders.CreatePs("debug_NDotL.hlsl");
            m_depthShader = MyShaders.CreatePs("debug_Depth.hlsl");
            m_stencilShader = MyShaders.CreatePs("debug_Stencil.hlsl");

            m_blitTextureShader = MyShaders.CreatePs("debug_blitTexture.hlsl");
            m_blitTexture3DShader = MyShaders.CreatePs("debug_blitTexture3D.hlsl");
            m_blitTextureArrayShader = MyShaders.CreatePs("debug_blitTextureArray.hlsl");
            m_inputLayout = MyShaders.CreateIL(m_screenVertexShader.BytecodeId, MyVertexLayouts.GetLayout(MyVertexInputComponentType.POSITION2, MyVertexInputComponentType.TEXCOORD0));

            m_quadBuffer = MyHwBuffers.CreateVertexBuffer(6, MyVertexFormatPosition2Texcoord.STRIDE, BindFlags.VertexBuffer, ResourceUsage.Dynamic, null, "MyDebugRenderer quad");
        }
예제 #14
0
 private void DestroyVertexBuffer()
 {
     if (m_cascadesBoundingsVertices != VertexBufferId.NULL)
     {
         MyHwBuffers.Destroy(m_cascadesBoundingsVertices);
         m_cascadesBoundingsVertices = VertexBufferId.NULL;
     }
 }
예제 #15
0
 public void Dispose()
 {
     if (m_stream != VertexBufferId.NULL)
     {
         MyHwBuffers.Destroy(m_stream);
         m_stream = VertexBufferId.NULL;
     }
 }
예제 #16
0
 internal static void InitVertexBuffer(VertexBufferId id, IntPtr data)
 {
     VBuffersData[id.Index].Buffer = new Buffer(MyRender11.Device, data, VBuffers.Data[id.Index].Description);
     if (VBuffers.Data[id.Index].DebugName != null)
     {
         VBuffersData[id.Index].Buffer.DebugName = VBuffers.Data[id.Index].DebugName;
     }
 }
예제 #17
0
 public void Dispose()
 {
     if (m_stream != VertexBufferId.NULL)
     {
         MyHwBuffers.Destroy(m_stream);
         m_stream = VertexBufferId.NULL;
     }
 }
예제 #18
0
        internal unsafe static void Init()
        {
            m_vs          = MyShaders.CreateVs("line.hlsl");
            m_ps          = MyShaders.CreatePs("line.hlsl");
            m_inputLayout = MyShaders.CreateIL(m_vs.BytecodeId, MyVertexLayouts.GetLayout(MyVertexInputComponentType.POSITION3, MyVertexInputComponentType.COLOR4));

            m_currentBufferSize = 100000;
            m_VB = MyHwBuffers.CreateVertexBuffer(m_currentBufferSize, sizeof(MyVertexFormatPositionColor), BindFlags.VertexBuffer, ResourceUsage.Dynamic);
        }
 internal void Dispose()
 {
     if (VB != VertexBufferId.NULL)
     {
         MyHwBuffers.Destroy(VB);
         VB = VertexBufferId.NULL;
     }
     m_capacity = 0;
 }
예제 #20
0
 internal void Dispose()
 {
     if (VB != VertexBufferId.NULL)
     {
         MyHwBuffers.Destroy(VB);
         VB = VertexBufferId.NULL;
     }
     m_capacity = 0;
 }
        internal static void Init()
        {
            m_VSCopy = MyShaders.CreateVs("postprocess_copy.hlsl");

            {
                m_VBFullscreen = MyHwBuffers.CreateVertexBuffer(4, VRageRender.Vertex.MyVertexFormatPositionTextureH.STRIDE,
                    BindFlags.VertexBuffer, ResourceUsage.Dynamic, null, "MyScreenPass.VBFullscreen");
                m_vbData[0] = new VRageRender.Vertex.MyVertexFormatPositionTextureH(new Vector3(-1, -1, 0),
                    new VRageMath.PackedVector.HalfVector2(0, 1f));
                m_vbData[1] = new VRageRender.Vertex.MyVertexFormatPositionTextureH(new Vector3(-1, 1, 0),
                    new VRageMath.PackedVector.HalfVector2(0, 0));
                m_vbData[2] = new VRageRender.Vertex.MyVertexFormatPositionTextureH(new Vector3(1, -1, 0),
                    new VRageMath.PackedVector.HalfVector2(1, 1f));
                m_vbData[3] = new VRageRender.Vertex.MyVertexFormatPositionTextureH(new Vector3(1, 1, 0),
                    new VRageMath.PackedVector.HalfVector2(1, 0f));
                MyMapping mapping = MyMapping.MapDiscard(RC.DeviceContext, m_VBFullscreen.Buffer);
                mapping.WriteAndPosition(m_vbData, 0, 4);
                mapping.Unmap();
            }

            {
                m_VBLeftPart = MyHwBuffers.CreateVertexBuffer(4, VRageRender.Vertex.MyVertexFormatPositionTextureH.STRIDE,
                    BindFlags.VertexBuffer, ResourceUsage.Dynamic, null, "MyVRScreenPass.VBLeftPart");
                m_vbData[0] = new VRageRender.Vertex.MyVertexFormatPositionTextureH(new Vector3(-1, -1, 0),
                    new VRageMath.PackedVector.HalfVector2(0, 1));
                m_vbData[1] = new VRageRender.Vertex.MyVertexFormatPositionTextureH(new Vector3(-1, 1, 0),
                    new VRageMath.PackedVector.HalfVector2(0, 0));
                m_vbData[2] = new VRageRender.Vertex.MyVertexFormatPositionTextureH(new Vector3(0, -1, 0),
                    new VRageMath.PackedVector.HalfVector2(0.5f, 1));
                m_vbData[3] = new VRageRender.Vertex.MyVertexFormatPositionTextureH(new Vector3(0, 1, 0),
                    new VRageMath.PackedVector.HalfVector2(0.5f, 0f));
                MyMapping mapping = MyMapping.MapDiscard(RC.DeviceContext, m_VBLeftPart.Buffer);
                mapping.WriteAndPosition(m_vbData, 0, 4);
                mapping.Unmap();
            }

            {
                m_VBRightPart = MyHwBuffers.CreateVertexBuffer(4, VRageRender.Vertex.MyVertexFormatPositionTextureH.STRIDE,
                    BindFlags.VertexBuffer, ResourceUsage.Dynamic, null, "MyVRScreenPass.VBRightPart");
                m_vbData[0] = new VRageRender.Vertex.MyVertexFormatPositionTextureH(new Vector3(0, -1, 0),
                    new VRageMath.PackedVector.HalfVector2(0.5f, 1));
                m_vbData[1] = new VRageRender.Vertex.MyVertexFormatPositionTextureH(new Vector3(0, 1, 0),
                    new VRageMath.PackedVector.HalfVector2(0.5f, 0));
                m_vbData[2] = new VRageRender.Vertex.MyVertexFormatPositionTextureH(new Vector3(1, -1, 0),
                    new VRageMath.PackedVector.HalfVector2(1, 1));
                m_vbData[3] = new VRageRender.Vertex.MyVertexFormatPositionTextureH(new Vector3(1, 1, 0),
                    new VRageMath.PackedVector.HalfVector2(1, 0));
                MyMapping mapping = MyMapping.MapDiscard(RC.DeviceContext, m_VBRightPart.Buffer);
                mapping.WriteAndPosition(m_vbData, 0, 4);
                mapping.Unmap();
            }

            // just some shader bytecode is selected
            m_IL = MyShaders.CreateIL(m_VSCopy.BytecodeId, MyVertexLayouts.GetLayout(MyVertexInputComponentType.POSITION3, MyVertexInputComponentType.TEXCOORD0_H));

        }
예제 #22
0
        //internal static void CreateInputLayout(byte[] bytecode)
        //{
        //    m_inputLayout = MyVertexInputLayout.CreateLayout(MyVertexInputLayout.Empty().Append(MyVertexInputComponentType.POSITION3).Append(MyVertexInputComponentType.COLOR4), bytecode);
        //}

        internal unsafe static void Init()
        {
            m_currentBufferSize = 100000;

            m_VB = MyHwBuffers.CreateVertexBuffer(m_currentBufferSize, sizeof(MyVertexFormatPositionColor), BindFlags.VertexBuffer, ResourceUsage.Dynamic);

            m_vs = MyShaders.CreateVs("primitive.hlsl", "vs");
            m_ps = MyShaders.CreatePs("primitive.hlsl", "ps");
            m_inputLayout = MyShaders.CreateIL(m_vs.BytecodeId, MyVertexLayouts.GetLayout(MyVertexInputComponentType.POSITION3, MyVertexInputComponentType.COLOR4));
        }
예제 #23
0
        internal static void Init()
        {
            m_VSCopy = MyShaders.CreateVs("postprocess_copy.hlsl");

            {
                m_VBFullscreen = MyHwBuffers.CreateVertexBuffer(4, VRageRender.Vertex.MyVertexFormatPositionTextureH.STRIDE,
                                                                BindFlags.VertexBuffer, ResourceUsage.Dynamic, null, "MyScreenPass.VBFullscreen");
                m_vbData[0] = new VRageRender.Vertex.MyVertexFormatPositionTextureH(new Vector3(-1, -1, 0),
                                                                                    new VRageMath.PackedVector.HalfVector2(0, 1f));
                m_vbData[1] = new VRageRender.Vertex.MyVertexFormatPositionTextureH(new Vector3(-1, 1, 0),
                                                                                    new VRageMath.PackedVector.HalfVector2(0, 0));
                m_vbData[2] = new VRageRender.Vertex.MyVertexFormatPositionTextureH(new Vector3(1, -1, 0),
                                                                                    new VRageMath.PackedVector.HalfVector2(1, 1f));
                m_vbData[3] = new VRageRender.Vertex.MyVertexFormatPositionTextureH(new Vector3(1, 1, 0),
                                                                                    new VRageMath.PackedVector.HalfVector2(1, 0f));
                MyMapping mapping = MyMapping.MapDiscard(RC.DeviceContext, m_VBFullscreen.Buffer);
                mapping.WriteAndPosition(m_vbData, 0, 4);
                mapping.Unmap();
            }

            {
                m_VBLeftPart = MyHwBuffers.CreateVertexBuffer(4, VRageRender.Vertex.MyVertexFormatPositionTextureH.STRIDE,
                                                              BindFlags.VertexBuffer, ResourceUsage.Dynamic, null, "MyVRScreenPass.VBLeftPart");
                m_vbData[0] = new VRageRender.Vertex.MyVertexFormatPositionTextureH(new Vector3(-1, -1, 0),
                                                                                    new VRageMath.PackedVector.HalfVector2(0, 1));
                m_vbData[1] = new VRageRender.Vertex.MyVertexFormatPositionTextureH(new Vector3(-1, 1, 0),
                                                                                    new VRageMath.PackedVector.HalfVector2(0, 0));
                m_vbData[2] = new VRageRender.Vertex.MyVertexFormatPositionTextureH(new Vector3(0, -1, 0),
                                                                                    new VRageMath.PackedVector.HalfVector2(0.5f, 1));
                m_vbData[3] = new VRageRender.Vertex.MyVertexFormatPositionTextureH(new Vector3(0, 1, 0),
                                                                                    new VRageMath.PackedVector.HalfVector2(0.5f, 0f));
                MyMapping mapping = MyMapping.MapDiscard(RC.DeviceContext, m_VBLeftPart.Buffer);
                mapping.WriteAndPosition(m_vbData, 0, 4);
                mapping.Unmap();
            }

            {
                m_VBRightPart = MyHwBuffers.CreateVertexBuffer(4, VRageRender.Vertex.MyVertexFormatPositionTextureH.STRIDE,
                                                               BindFlags.VertexBuffer, ResourceUsage.Dynamic, null, "MyVRScreenPass.VBRightPart");
                m_vbData[0] = new VRageRender.Vertex.MyVertexFormatPositionTextureH(new Vector3(0, -1, 0),
                                                                                    new VRageMath.PackedVector.HalfVector2(0.5f, 1));
                m_vbData[1] = new VRageRender.Vertex.MyVertexFormatPositionTextureH(new Vector3(0, 1, 0),
                                                                                    new VRageMath.PackedVector.HalfVector2(0.5f, 0));
                m_vbData[2] = new VRageRender.Vertex.MyVertexFormatPositionTextureH(new Vector3(1, -1, 0),
                                                                                    new VRageMath.PackedVector.HalfVector2(1, 1));
                m_vbData[3] = new VRageRender.Vertex.MyVertexFormatPositionTextureH(new Vector3(1, 1, 0),
                                                                                    new VRageMath.PackedVector.HalfVector2(1, 0));
                MyMapping mapping = MyMapping.MapDiscard(RC.DeviceContext, m_VBRightPart.Buffer);
                mapping.WriteAndPosition(m_vbData, 0, 4);
                mapping.Unmap();
            }

            // just some shader bytecode is selected
            m_IL = MyShaders.CreateIL(m_VSCopy.BytecodeId, MyVertexLayouts.GetLayout(MyVertexInputComponentType.POSITION3, MyVertexInputComponentType.TEXCOORD0_H));
        }
예제 #24
0
 internal static void Destroy(VertexBufferId id)
 {
     Debug.Assert(VbIndices.Contains(id));
     VbIndices.Remove(id);
     if (VBuffersData[id.Index].Buffer != null)
     {
         VBuffersData[id.Index].Buffer.Dispose();
         VBuffersData[id.Index].Buffer = null;
     }
     VBuffers.Free(id.Index);
 }
예제 #25
0
        internal unsafe void AllocateStreamOutBuffer(int vertexStride)
        {
            Dispose();

            // padding to some power of 2
            m_allocationSize = ((m_allocationSize + 511) / 512) * 512;
            const int maxAlloc = 5 * 1024 * 1024;
            m_allocationSize = Math.Min(maxAlloc, m_allocationSize);

            Debug.Assert(m_stream == VertexBufferId.NULL);
            m_stream = MyHwBuffers.CreateVertexBuffer(m_allocationSize, vertexStride, BindFlags.VertexBuffer | BindFlags.StreamOutput, ResourceUsage.Default);
        }
        private static void InitInternal(Vector2[] vertsForMask)
        {
            m_VB = MyHwBuffers.CreateVertexBuffer(vertsForMask.Length, MyVertexFormat2DPosition.STRIDE, BindFlags.VertexBuffer, ResourceUsage.Dynamic, null, "MyStereoStencilMask.VB");
            MyMapping mapping = MyMapping.MapDiscard(RC.DeviceContext, m_VB.Buffer);
            mapping.WriteAndPosition(vertsForMask, 0, vertsForMask.Length);
            mapping.Unmap();

            m_vs = MyShaders.CreateVs("stereo_stencil_mask.hlsl");
            m_ps = MyShaders.CreatePs("stereo_stencil_mask.hlsl");

            m_il = MyShaders.CreateIL(m_vs.BytecodeId, MyVertexLayouts.GetLayout(MyVertexInputComponentType.POSITION2));
        }
예제 #27
0
        internal unsafe void AllocateStreamOutBuffer(int vertexStride)
        {
            Dispose();

            // padding to some power of 2
            m_allocationSize = ((m_allocationSize + 511) / 512) * 512;
            const int maxAlloc = 5 * 1024 * 1024;

            m_allocationSize = Math.Min(maxAlloc, m_allocationSize);

            Debug.Assert(m_stream == VertexBufferId.NULL);
            m_stream = MyHwBuffers.CreateVertexBuffer(m_allocationSize, vertexStride, BindFlags.VertexBuffer | BindFlags.StreamOutput, ResourceUsage.Default);
        }
        internal unsafe void AllocateStreamOutBuffer()
        {
            Dispose();

            var stride = sizeof(Vector3) + sizeof(uint);

            // padding to some power of 2
            m_allocationSize = ((m_allocationSize + 511) / 512) * 512;
            const int maxAlloc = 5 * 1024 * 1024;
            m_allocationSize = m_allocationSize > maxAlloc ? maxAlloc : m_allocationSize;

            m_stream = MyHwBuffers.CreateVertexBuffer(m_allocationSize, stride, BindFlags.VertexBuffer | BindFlags.StreamOutput, ResourceUsage.Default);
        }
        private static void InitInternal(Vector2[] vertsForMask)
        {
            m_VB = MyHwBuffers.CreateVertexBuffer(vertsForMask.Length, MyVertexFormat2DPosition.STRIDE, BindFlags.VertexBuffer, ResourceUsage.Dynamic, null, "MyStereoStencilMask.VB");
            MyMapping mapping = MyMapping.MapDiscard(RC.DeviceContext, m_VB.Buffer);

            mapping.WriteAndPosition(vertsForMask, 0, vertsForMask.Length);
            mapping.Unmap();

            m_vs = MyShaders.CreateVs("stereo_stencil_mask.hlsl");
            m_ps = MyShaders.CreatePs("stereo_stencil_mask.hlsl");

            m_il = MyShaders.CreateIL(m_vs.BytecodeId, MyVertexLayouts.GetLayout(MyVertexInputComponentType.POSITION2));
        }
예제 #30
0
        internal unsafe void AllocateStreamOutBuffer()
        {
            Dispose();

            var stride = sizeof(Vector3) + sizeof(uint);

            // padding to some power of 2
            m_allocationSize = ((m_allocationSize + 511) / 512) * 512;
            const int maxAlloc = 5 * 1024 * 1024;

            m_allocationSize = m_allocationSize > maxAlloc ? maxAlloc : m_allocationSize;

            m_stream = MyHwBuffers.CreateVertexBuffer(m_allocationSize, stride, BindFlags.VertexBuffer | BindFlags.StreamOutput, ResourceUsage.Default);
        }
예제 #31
0
        internal unsafe static void Init()
        {
            m_vs = MyShaders.CreateVs("sprite.hlsl");
            m_ps = MyShaders.CreatePs("sprite.hlsl");

            m_inputLayout = MyShaders.CreateIL(m_vs.BytecodeId, MyVertexLayouts.GetLayout(
                                                   new MyVertexInputComponent(MyVertexInputComponentType.CUSTOM_HALF4_0, MyVertexInputComponentFreq.PER_INSTANCE),
                                                   new MyVertexInputComponent(MyVertexInputComponentType.CUSTOM_HALF4_1, MyVertexInputComponentFreq.PER_INSTANCE),
                                                   new MyVertexInputComponent(MyVertexInputComponentType.CUSTOM_HALF4_2, MyVertexInputComponentFreq.PER_INSTANCE),
                                                   new MyVertexInputComponent(MyVertexInputComponentType.COLOR4, MyVertexInputComponentFreq.PER_INSTANCE)
                                                   ));

            m_currentBufferSize = 100000;
            m_VB = MyHwBuffers.CreateVertexBuffer(m_currentBufferSize, sizeof(MyVertexFormatSpritePositionTextureRotationColor), BindFlags.VertexBuffer, ResourceUsage.Dynamic);

            m_contextsStack.Add(new MySpritesContext());
        }
        internal override void Construct()
        {
            base.Construct();
            Type = MyActorComponentEnum.Instancing;

            MyUtils.Init(ref m_owners);
            m_owners.Clear();

            MyUtils.Init(ref m_ID);
            m_ID.Clear();

            VB = VertexBufferId.NULL;
            m_input = MyVertexInputLayout.Empty;
            m_stride = -1;
            m_type = MyRenderInstanceBufferType.Invalid;
            m_capacity = -1;
        }
예제 #33
0
        internal override void Construct()
        {
            base.Construct();
            Type = MyActorComponentEnum.Instancing;

            MyUtils.Init(ref m_owners);
            m_owners.Clear();

            MyUtils.Init(ref m_ID);
            m_ID.Clear();

            VB         = VertexBufferId.NULL;
            m_input    = MyVertexInputLayout.Empty;
            m_stride   = -1;
            m_type     = MyRenderInstanceBufferType.Invalid;
            m_capacity = -1;
        }
        internal unsafe void UpdateCube(List <MyCubeInstanceData> instanceData, int capacity)
        {
            Debug.Assert(m_type == MyRenderInstanceBufferType.Cube);

            var instancesNum = instanceData.Count;

            if (m_capacity < instancesNum && VB != VertexBufferId.NULL)
            {
                MyHwBuffers.Destroy(VB);
                VB = VertexBufferId.NULL;
            }
            if (m_capacity < instancesNum)
            {
                m_capacity = Math.Max(instancesNum, capacity);
                VB         = MyHwBuffers.CreateVertexBuffer(m_capacity, sizeof(MyVertexFormatCubeInstance), null, m_debugName + " instances buffer");
            }

            var rawBuffer = new MyVertexFormatCubeInstance[m_capacity];

            for (int i = 0; i < instancesNum; i++)
            {
                fixed(byte *pSource = instanceData[i].RawBones(), pTarget = rawBuffer[i].bones)
                {
                    for (int j = 0; j < MyRender11Constants.CUBE_INSTANCE_BONES_NUM * 4; j++)
                    {
                        pTarget[j] = pSource[j];
                    }
                }

                rawBuffer[i].translationRotation = new HalfVector4(instanceData[i].m_translationAndRot);
                rawBuffer[i].colorMaskHSV        = new HalfVector4(instanceData[i].ColorMaskHSV);
            }

            fixed(MyVertexFormatCubeInstance *dataPtr = rawBuffer)
            {
                DataBox        srcBox    = new DataBox(new IntPtr(dataPtr));
                ResourceRegion dstRegion = new ResourceRegion(0, 0, 0, sizeof(MyVertexFormatCubeInstance) * instancesNum, 1, 1);

                MyRender11.ImmediateContext.UpdateSubresource(srcBox, VB.Buffer, 0, dstRegion);
            }

            BumpRenderable();
        }
        internal unsafe static void Init()
        {
            m_vs          = MyShaders.CreateVs("billboard.hlsl", "vs");
            m_ps          = MyShaders.CreatePs("billboard.hlsl", "ps");
            m_vsLit       = MyShaders.CreateVs("billboard.hlsl", "vs", MyShaderHelpers.FormatMacros("LIT_PARTICLE"));
            m_psLit       = MyShaders.CreatePs("billboard.hlsl", "ps", MyShaderHelpers.FormatMacros("LIT_PARTICLE"));
            m_inputLayout = MyShaders.CreateIL(m_vs.BytecodeId, MyVertexLayouts.GetLayout(MyVertexInputComponentType.POSITION3, MyVertexInputComponentType.TEXCOORD0_H));

            //MyCallbacks.RegisterDeviceResetListener(new OnDeviceResetDelegate(OnDeviceRestart));

            InitBillboardsIndexBuffer(MaxBillboards);

            m_VB = MyHwBuffers.CreateVertexBuffer(MaxBillboards * 4, sizeof(MyVertexFormatPositionTextureH), BindFlags.VertexBuffer, ResourceUsage.Dynamic);

            var stride = sizeof(MyBillboardData);

            m_SB = MyHwBuffers.CreateStructuredBuffer(MaxBillboards, stride, true);

            MyTextureAtlas.ParseAtlasDescription("Textures\\Particles\\", "Textures\\Particles\\ParticlesAtlas.tai", m_atlasedTextures);
        }
        internal override void Construct()
        {
            base.Construct();
            Type = MyActorComponentEnum.Instancing;


            m_capacity = 0;
            m_input    = MyVertexInputLayout.Empty();
            m_ID       = new MyIDTracker <MyInstancingComponent>();
            VB         = VertexBufferId.NULL;

            if (m_owners == null)
            {
                m_owners = new List <MyActor>();
            }
            else
            {
                m_owners.Clear();
            }
        }
예제 #37
0
        internal unsafe void Construct(MyRenderInstanceBufferType type)
        {
            m_capacity = 0;

            m_input = MyVertexInputLayout.Empty;

            if(type == MyRenderInstanceBufferType.Cube)
            { 
                m_input.Append(MyVertexInputComponentType.CUBE_INSTANCE, 2, MyVertexInputComponentFreq.PER_INSTANCE);
                m_stride = sizeof(MyVertexFormatCubeInstance);
            }
            else if (type == MyRenderInstanceBufferType.Generic)
            {
                m_input.Append(MyVertexInputComponentType.GENERIC_INSTANCE, 2, MyVertexInputComponentFreq.PER_INSTANCE);
                m_stride = sizeof(MyVertexFormatGenericInstance);
            }

            m_type = type;
            VertexBuffer = VertexBufferId.NULL;
        }
예제 #38
0
        internal unsafe void Construct(MyRenderInstanceBufferType type)
        {
            m_capacity = 0;

            m_input = MyVertexInputLayout.Empty;

            if (type == MyRenderInstanceBufferType.Cube)
            {
                m_input.Append(MyVertexInputComponentType.CUBE_INSTANCE, 2, MyVertexInputComponentFreq.PER_INSTANCE);
                m_stride = sizeof(MyVertexFormatCubeInstance);
            }
            else if (type == MyRenderInstanceBufferType.Generic)
            {
                m_input.Append(MyVertexInputComponentType.GENERIC_INSTANCE, 2, MyVertexInputComponentFreq.PER_INSTANCE);
                m_stride = sizeof(MyVertexFormatGenericInstance);
            }

            m_type       = type;
            VertexBuffer = VertexBufferId.NULL;
        }
예제 #39
0
        internal static void ResizeAndUpdateStaticVertexBuffer(ref VertexBufferId id, int capacity, int stride, IntPtr data, string debugName)
        {
            if (id == VertexBufferId.NULL)
            {
                id = CreateVertexBuffer(capacity, stride, data, debugName);
            }
            else
            {
                Debug.Assert(stride == id.Stride);

                if (id.Capacity != capacity)
                {
                    VBuffersData[id.Index].Buffer.Dispose();
                    VBuffers.Data[id.Index].Description.SizeInBytes = VBuffersData[id.Index].Stride * capacity;
                    InitVertexBuffer(id, data);
                }
                else
                {
                    UpdateVertexBuffer(id, data);
                }
            }
        }
예제 #40
0
        internal unsafe void UpdateGeneric(List<MyInstanceData> instanceData, int capacity)
        {
            var instancesNum = instanceData.Count;
            if (m_capacity < instancesNum && VertexBuffer != VertexBufferId.NULL)
            {
                MyHwBuffers.Destroy(VertexBuffer);
                VertexBuffer = VertexBufferId.NULL;
            }
            if (m_capacity < instancesNum)
            {
                m_capacity = Math.Max(instancesNum, capacity);
                VertexBuffer = MyHwBuffers.CreateVertexBuffer(m_capacity, sizeof(MyVertexFormatGenericInstance), null, m_debugName + " instances buffer");
            }

            fixed (MyInstanceData* dataPtr = instanceData.ToArray())
            {
                DataBox srcBox = new DataBox(new IntPtr(dataPtr));
                ResourceRegion dstRegion = new ResourceRegion(0, 0, 0, sizeof(MyVertexFormatGenericInstance) * instancesNum, 1, 1);

                MyRender11.ImmediateContext.UpdateSubresource(srcBox, VertexBuffer.Buffer, 0, dstRegion);
            }
        }
        internal unsafe static void Init()
        {
            m_vs    = MyShaders.CreateVs("billboard.hlsl");
            m_ps    = MyShaders.CreatePs("billboard.hlsl");
            m_vsLit = MyShaders.CreateVs("billboard.hlsl", new [] { new ShaderMacro("LIT_PARTICLE", null) });
            m_psLit = MyShaders.CreatePs("billboard.hlsl", new[] { new ShaderMacro("LIT_PARTICLE", null) });

            m_psAlphaCutout       = MyShaders.CreatePs("billboard.hlsl", new[] { new ShaderMacro("ALPHA_CUTOUT", null) });
            m_psAlphaCutoutAndLit = MyShaders.CreatePs("billboard.hlsl", new[] { new ShaderMacro("ALPHA_CUTOUT", null), new ShaderMacro("LIT_PARTICLE", null) });

            m_inputLayout = MyShaders.CreateIL(m_vs.BytecodeId, MyVertexLayouts.GetLayout(MyVertexInputComponentType.POSITION3, MyVertexInputComponentType.TEXCOORD0_H));

            //MyCallbacks.RegisterDeviceResetListener(new OnDeviceResetDelegate(OnDeviceRestart));

            InitBillboardsIndexBuffer(MaxBillboards);

            m_VB = MyHwBuffers.CreateVertexBuffer(MaxBillboards * 4, sizeof(MyVertexFormatPositionTextureH), BindFlags.VertexBuffer, ResourceUsage.Dynamic, null, "MyBillboardRenderer");

            var stride = sizeof(MyBillboardData);

            m_SB    = MyHwBuffers.CreateStructuredBuffer(MaxBillboards, stride, true, null, "MyBillboardRenderer");
            m_atlas = new MyTextureAtlas("Textures\\Particles\\", "Textures\\Particles\\ParticlesAtlas.tai");
        }
예제 #42
0
 internal static int GetVertexBufferStride(VertexBufferId id)
 {
     return VBuffersData[id.Index].Stride;
 }
예제 #43
0
 internal static int GetVertexBufferCapacity(VertexBufferId id)
 {
     return VBuffers.Data[id.Index].Description.SizeInBytes / VBuffersData[id.Index].Stride;
 }
예제 #44
0
 internal static void InitVertexBuffer(VertexBufferId id, IntPtr data)
 {
     VBuffersData[id.Index].Buffer = new Buffer(MyRender11.Device, data, VBuffers.Data[id.Index].Description);
     if (VBuffers.Data[id.Index].DebugName != null)
     {
         VBuffersData[id.Index].Buffer.DebugName = VBuffers.Data[id.Index].DebugName;
     }
 }
예제 #45
0
 internal static Buffer GetVertexBuffer(VertexBufferId id)
 {
     return VBuffersData[id.Index].Buffer;
 }
예제 #46
0
 internal static void UpdateVertexBuffer(VertexBufferId id, IntPtr data)
 {
     MyRender11.DeviceContext.UpdateSubresource(new DataBox(data), VBuffersData[id.Index].Buffer);
 }
예제 #47
0
 internal static void ResizeVertexBuffer(VertexBufferId id, int size)
 {
     VBuffersData[id.Index].Buffer.Dispose();
     VBuffers.Data[id.Index].Description.SizeInBytes = VBuffersData[id.Index].Stride * size;
     InitVertexBuffer(id);
 }
예제 #48
0
 internal static int GetVertexBufferCapacity(VertexBufferId id)
 {
     return(VBuffers.Data[id.Index].Description.SizeInBytes / VBuffersData[id.Index].Stride);
 }
예제 #49
0
        internal unsafe static void Init()
        {
            m_vs = MyShaders.CreateVs("sprite.hlsl", "vs");
            m_ps = MyShaders.CreatePs("sprite.hlsl", "ps");

            m_inputLayout = MyShaders.CreateIL(m_vs.BytecodeId, MyVertexLayouts.GetLayout(
                new MyVertexInputComponent(MyVertexInputComponentType.CUSTOM_HALF4_0, MyVertexInputComponentFreq.PER_INSTANCE),
                new MyVertexInputComponent(MyVertexInputComponentType.CUSTOM_HALF4_1, MyVertexInputComponentFreq.PER_INSTANCE),
                new MyVertexInputComponent(MyVertexInputComponentType.CUSTOM_HALF4_2, MyVertexInputComponentFreq.PER_INSTANCE),
                new MyVertexInputComponent(MyVertexInputComponentType.COLOR4, MyVertexInputComponentFreq.PER_INSTANCE)
                ));

            m_currentBufferSize = 100000;
            m_VB = MyHwBuffers.CreateVertexBuffer(m_currentBufferSize, sizeof(MyVertexFormatSpritePositionTextureRotationColor), BindFlags.VertexBuffer, ResourceUsage.Dynamic);

            m_contextsStack.Add(new MySpritesContext());
        }
예제 #50
0
 internal static int GetVertexBufferStride(VertexBufferId id)
 {
     return(VBuffersData[id.Index].Stride);
 }
        internal unsafe static void Init()
        {
            m_vs = MyShaders.CreateVs("billboard.hlsl", "vs");
            m_ps = MyShaders.CreatePs("billboard.hlsl", "ps");
            m_vsLit = MyShaders.CreateVs("billboard.hlsl", "vs", MyShaderHelpers.FormatMacros("LIT_PARTICLE"));
            m_psLit = MyShaders.CreatePs("billboard.hlsl", "ps", MyShaderHelpers.FormatMacros("LIT_PARTICLE"));
            m_inputLayout = MyShaders.CreateIL(m_vs.BytecodeId, MyVertexLayouts.GetLayout(MyVertexInputComponentType.POSITION3, MyVertexInputComponentType.TEXCOORD0_H));

            //MyCallbacks.RegisterDeviceResetListener(new OnDeviceResetDelegate(OnDeviceRestart));

            InitBillboardsIndexBuffer(MaxBillboards);

            m_VB = MyHwBuffers.CreateVertexBuffer(MaxBillboards * 4, sizeof(MyVertexFormatPositionTextureH), BindFlags.VertexBuffer, ResourceUsage.Dynamic);

            var stride = sizeof(MyBillboardData);
            m_SB = MyHwBuffers.CreateStructuredBuffer(MaxBillboards, stride, true);

            MyTextureAtlas.ParseAtlasDescription("Textures\\Particles\\", "Textures\\Particles\\ParticlesAtlas.tai", m_atlasedTextures);
        }
 private void DestroyVertexBuffer()
 {
     if (m_cascadesBoundingsVertices != VertexBufferId.NULL)
     {
         MyHwBuffers.Destroy(m_cascadesBoundingsVertices);
         m_cascadesBoundingsVertices = VertexBufferId.NULL;
     }
 }
 private unsafe void InitVertexBuffer(int numberOfCascades)
 {
     DestroyVertexBuffer();
     m_cascadesBoundingsVertices = MyHwBuffers.CreateVertexBuffer(8 * numberOfCascades, sizeof(Vector3), BindFlags.VertexBuffer, ResourceUsage.Dynamic);
 }
예제 #54
0
 internal static void ResizeAndUpdateStaticVertexBuffer(ref VertexBufferId id, int capacity, int stride, IntPtr data, string debugName)
 {
     if (id == VertexBufferId.NULL)
     {
         id = CreateVertexBuffer(capacity, stride, data, debugName);
     }
     else 
     {
         Debug.Assert(stride == id.Stride);
         
         if (id.Capacity != capacity)
         {
             VBuffersData[id.Index].Buffer.Dispose();
             VBuffers.Data[id.Index].Description.SizeInBytes = VBuffersData[id.Index].Stride * capacity;
             InitVertexBuffer(id, data);
         }
         else
         {
             UpdateVertexBuffer(id, data);
         }
     }
 }
예제 #55
0
 internal static BufferDescription GetBufferDesc(VertexBufferId id)
 {
     return VBuffers.Data[id.Index].Description;
 }
예제 #56
0
        internal static VertexBufferId CreateVertexBuffer(BufferDescription description, int stride, IntPtr ? data = null, string debugName = null)
        {
            var id = new VertexBufferId { Index = VBuffers.Allocate() };
            
            MyArrayHelpers.Reserve(ref VBuffersData, id.Index + 1);
            VBuffers.Data[id.Index] = new MyHwBufferDesc { Description = description, DebugName = debugName };
            VBuffersData[id.Index] = new MyVertexBufferData { Stride = stride };

            VbIndices.Add(id);

            if(!data.HasValue)
            {
                InitVertexBuffer(id);
            }
            else
            {
                InitVertexBuffer(id, data.Value);
            }

            return id;
        }
예제 #57
0
 internal static BufferDescription GetBufferDesc(VertexBufferId id)
 {
     return(VBuffers.Data[id.Index].Description);
 }
예제 #58
0
 internal static void Destroy(VertexBufferId id)
 {
     Debug.Assert(VbIndices.Contains(id));
     VbIndices.Remove(id);
     if(VBuffersData[id.Index].Buffer != null)
     {
         VBuffersData[id.Index].Buffer.Dispose();
         VBuffersData[id.Index].Buffer = null;
     }
     VBuffers.Free(id.Index);
 }
예제 #59
0
        internal override void Construct()
        {
            base.Construct();
            Type = MyActorComponentEnum.Instancing;


            m_capacity = 0;
            m_input = MyVertexInputLayout.Empty();
            m_ID = new MyIDTracker<MyInstancingComponent>();
            VB = VertexBufferId.NULL;
            
            if(m_owners == null)
            {
                m_owners = new List<MyActor>();
            }
            else
            {
                m_owners.Clear();
            }
        }
        public unsafe MyDebugMesh(MyRenderMessageDebugDrawMesh message)
        {
            vbuffer = MyHwBuffers.CreateVertexBuffer(message.VertexCount, sizeof(MyVertexFormatPositionColor), BindFlags.VertexBuffer, ResourceUsage.Dynamic, null, "MyDebugMesh");

            Update(message);
        }