private void initTexture(int width, int height)
        {
            if (_texture == null)
            {
                _texture = new Texture(_device, width, height, 0, Usage.AutoGenerateMipMap, Format.X8R8G8B8, Pool.Default);
            }
            else
            {
                _graphicsres[0].Unregister();
                _graphicsres.Clear();
                _texture.Dispose();
                _texture = new Texture(_device, width, height, 0, Usage.AutoGenerateMipMap, Format.X8R8G8B8, Pool.Default);
            }

            CudaDirectXInteropResource resource = new CudaDirectXInteropResource(_texture.ComPointer, CUGraphicsRegisterFlags.None, CudaContext.DirectXVersion.D3D9, CUGraphicsMapResourceFlags.None);

            _graphicsres.Add(resource);

            if (_vertexBufferTexture == null)
            {
                _vertexBufferTexture = new VertexBuffer(_device, 4 * Marshal.SizeOf(typeof(vertex)), Usage.None, VertexFormat.Position | VertexFormat.Texture1, Pool.Default);
            }

            DataStream str = _vertexBufferTexture.Lock(0, 4 * Marshal.SizeOf(typeof(vertex)), LockFlags.None);

            str.Position = 0;
            str.WriteRange <vertex>(GetVertices(width, height));
            _vertexBufferTexture.Unlock();

            //_device.SetTexture(0, _texture);
        }
Example #2
0
        void m_renderControl_KeyDown(object sender, KeyEventArgs e)
        {
            if (e.KeyCode == Keys.Escape)
            {
                Close();
            }

            if (e.KeyCode == Keys.R)
            {
                Array.Clear(hvfield, 0, DS);
                dvfield.CopyToDevice(hvfield);
                initParticles(particles, DIM, DIM);

                cuda_vbo_resource.Clear();

                GL.BindBuffer(BufferTarget.ArrayBuffer, vbo);
                GL.BufferData <cData>(BufferTarget.ArrayBuffer, new IntPtr(cData.SizeOf * DS), particles, BufferUsageHint.DynamicDraw);
                GL.BindBuffer(BufferTarget.ArrayBuffer, 0);

                cuda_vbo_resource.Add(new CudaOpenGLBufferInteropResource(vbo, CUGraphicsRegisterFlags.None));
            }
        }