public void RipModel(SlimDX.Direct3D9.Device device, SlimDX.Direct3D9.PrimitiveType primitiveType,
                             int baseVertexIndex, int startIndex, int primCount)
        {
            IndexBuffer ib = device.Indices;

            if (primitiveType == PrimitiveType.TriangleList)
            {
                RipTriangleList(baseVertexIndex, startIndex, primCount, ref ib);
            }
            if (primitiveType == PrimitiveType.TriangleStrip)
            {
                RipTriangleStrip(baseVertexIndex, startIndex, primCount, ref ib);
            }
        }
Exemplo n.º 2
0
        public override void Draw(int start, int count)
        {
            int primitiveCount = count;

            // after calling GetPrimitiveType, primitiveCount is the number of primitives
            // instead of the number of vertices.
            Direct3D.PrimitiveType primType = GetPrimitiveType(ref primitiveCount);

            SetTextures();


            mDisplay.D3D_Device.Device.SetStreamSource(0, mBuffer, 0, VertexLayout.VertexSize);
            mDisplay.D3D_Device.Device.VertexDeclaration = mDeclaration;
            mDisplay.D3D_Device.Device.DrawPrimitives(primType, start, primitiveCount);
        }
Exemplo n.º 3
0
        public override void DrawIndexed(IndexBuffer _indexbuffer, int start, int count)
        {
            int             primitiveCount = count;
            SDX_IndexBuffer indexbuffer    = _indexbuffer.Impl as SDX_IndexBuffer;

            // after calling GetPrimitiveType, primitiveCount is the number of primitives
            // instead of the number of vertices.
            Direct3D.PrimitiveType primType = GetPrimitiveType(ref primitiveCount);

            SetTextures();

            mDisplay.D3D_Device.AlphaArgument1 = Direct3D.TextureArgument.Texture;

            mDisplay.D3D_Device.Device.VertexDeclaration = mDeclaration;
            mDisplay.D3D_Device.Device.Indices           = indexbuffer.DeviceIndexBuffer;
            mDisplay.D3D_Device.Device.SetStreamSource(0, mBuffer, 0, mLayout.VertexSize);
            mDisplay.D3D_Device.Device.DrawIndexedPrimitives(
                primType, 0, 0, indexbuffer.MaxIndex, start, primitiveCount);
        }
        int DrawIndexedPrimitivesHook(IntPtr devicePtr, SlimDX.Direct3D9.PrimitiveType primitiveType,
                                      int baseVertexIndex, int minimumVertexIndex,
                                      int numVertices, int startIndex, int primCount)
        {
            using (SlimDX.Direct3D9.Device device = SlimDX.Direct3D9.Device.FromPointer(devicePtr))
            {
                Primitive prim = new Primitive(primCount, numVertices);
                int       hRet = 0;
                try
                {
                    if (Interface.CaptureFrame)
                    {
                        RipModel(device, primitiveType, baseVertexIndex, startIndex, primCount);
                    }

                    //if new primitive being rendered, add it to our list
                    if (!prims.Contains(prim))
                    {
                        prims.Add(prim);
                    }

                    Primitive selectedPrim = prims.GetSelectedPrimitive();

                    if (selectedPrim != null)
                    {
                        if (selectedPrim.Equals(prim))
                        {
                            if (RedTexture == null)
                            {
                                RedTexture = SlimDX.Direct3D9.Texture.FromMemory(device, red);
                            }

                            if (Interface.chamed == true)
                            {
                                selectedPrim.Chamed = true;
                                Interface.Togglecham();
                            }

                            device.SetRenderState(SlimDX.Direct3D9.RenderState.FillMode, SlimDX.Direct3D9.FillMode.Solid);
                            device.SetTexture(0, RedTexture);


                            if (selectedPrim.Chamed)
                            {
                                //device.Clear(ClearFlags.ZBuffer, Color.Red, 1.0f, 0);
                                device.SetRenderState(SlimDX.Direct3D9.RenderState.ZEnable, false);
                                hRet = device.DrawIndexedPrimitives(primitiveType, baseVertexIndex, minimumVertexIndex,
                                                                    numVertices, startIndex, primCount).Code;
                                device.SetRenderState(SlimDX.Direct3D9.RenderState.ZEnable, true);
                            }


                            if (Interface.rip)
                            {
                                if (!Interface.CaptureFrame)
                                {
                                    RipModel(device, primitiveType, baseVertexIndex, startIndex, primCount);
                                    Interface.ToggleRip();
                                }
                            }

                            hRet = device.DrawIndexedPrimitives(primitiveType, baseVertexIndex, minimumVertexIndex,
                                                                numVertices, startIndex, primCount).Code;
                        }
                    }
                    //if not to display, don't render
                    if (prims.IndexOf(prim) != -1)
                    {
                        if (prims[prims.IndexOf(prim)].Displayed == false)
                        {
                            return(0);
                        }
                    }
                }
                catch (Exception e)
                {
                    Interface.ReportException(e);
                    return(hRet);
                }

                if (hRet == 0)
                {
                    if (prims[prims.IndexOf(prim)].Chamed == false)
                    {
                        hRet = device.DrawIndexedPrimitives(primitiveType, baseVertexIndex, minimumVertexIndex,
                                                            numVertices, startIndex, primCount).Code;
                    }
                    else
                    {
                        PixelShader previous = device.PixelShader;
                        if (chamPixelShader == null)
                        {
                            chamPixelShader = new PixelShader(device, ShaderBytecode.Compile("float4 PShader(float4 position : SV_POSITION) : SV_Target\n" +
                                                                                             "{\nreturn float4(1.0f, 1.0f, 0.0f, 1.0f);\n}", "PShader", "ps_3_0", ShaderFlags.None));
                        }

                        device.PixelShader = chamPixelShader;

                        hRet = device.DrawIndexedPrimitives(primitiveType, baseVertexIndex, minimumVertexIndex,
                                                            numVertices, startIndex, primCount).Code;

                        device.SetRenderState(SlimDX.Direct3D9.RenderState.ZEnable, false);
                        hRet = device.DrawIndexedPrimitives(primitiveType, baseVertexIndex, minimumVertexIndex,
                                                            numVertices, startIndex, primCount).Code;
                        device.SetRenderState(RenderState.ZEnable, true);

                        device.PixelShader = previous;
                    }
                }
                return(hRet);
            }
        }