Example #1
0
        public Capabilities GetCapabilities(DeviceQueryType deviceQueryType)
        {
            Capabilities capabilities;

            ErrorCodeHelper.ToResult(SharpDX.XInput.XInput.XInputGetCapabilities((int)this.userIndex, deviceQueryType, out capabilities)).CheckError();
            return(capabilities);
        }
        /// <summary>Gets the state.</summary>
        /// <returns>The state of this controller.</returns>
        public State GetState()
        {
            State stateRef;

            ErrorCodeHelper.ToResult(xinput.XInputGetState((int)this.userIndex, out stateRef)).CheckError();
            return(stateRef);
        }
Example #3
0
        public BatteryInformation GetBatteryInformation(BatteryDeviceType batteryDeviceType)
        {
            BatteryInformation batteryInformationRef;

            ErrorCodeHelper.ToResult(XInput.XInputGetBatteryInformation((int)this.userIndex, batteryDeviceType, out batteryInformationRef)).CheckError();
            return(batteryInformationRef);
        }
Example #4
0
        /// <summary>
        /// Gets the keystroke.
        /// </summary>
        /// <param name="deviceQueryType">The flag.</param>
        /// <param name="keystroke">The keystroke.</param>
        /// <returns></returns>
        /// <unmanaged>unsigned int XInputGetKeystroke([In] XUSER_INDEX dwUserIndex,[In] unsigned int dwReserved,[Out] XINPUT_KEYSTROKE* pKeystroke)</unmanaged>
        public Result GetKeystroke(DeviceQueryType deviceQueryType, out Keystroke keystroke)
        {
            var result = ErrorCodeHelper.ToResult(XInput.XInputGetKeystroke((int)userIndex, (int)deviceQueryType, out keystroke));

            result.CheckError();
            return(result);
        }
        /// <summary>Sets the vibration.</summary>
        /// <param name="vibration">The vibration.</param>
        /// <returns></returns>
        public Result SetVibration(Vibration vibration)
        {
            Result result = ErrorCodeHelper.ToResult(xinput.XInputSetState((int)this.userIndex, vibration));

            result.CheckError();
            return(result);
        }
Example #6
0
        /// <summary>
        /// Sets the vibration.
        /// </summary>
        /// <param name="vibration">The vibration.</param>
        /// <returns></returns>
        public Result SetVibration(Vibration vibration)
        {
            var result = ErrorCodeHelper.ToResult(XInputSetState((int)userIndex, vibration));

            result.CheckError();
            return(result);
        }
Example #7
0
        public BatteryInformation GetBatteryInformation(BatteryDeviceType batteryDeviceType)
        {
            BatteryInformation information;

            ErrorCodeHelper.ToResult(SharpDX.XInput.XInput.XInputGetBatteryInformation((int)this.userIndex, batteryDeviceType, out information)).CheckError();
            return(information);
        }
Example #8
0
        /// <summary>Reloads settings from INI file.</summary>
        public static Result Reset()
        {
            var result = ErrorCodeHelper.ToResult(xinput.Reset());

            result.CheckError();
            return(result);
        }
        /// <summary>
        /// Gets the capabilities.
        /// </summary>
        /// <param name="deviceQueryType">Type of the device query.</param>
        /// <returns></returns>
        /// <unmanaged>unsigned int XInputGetCapabilities([In] XUSER_INDEX dwUserIndex,[In] XINPUT_DEVQUERYTYPE dwFlags,[Out] XINPUT_CAPABILITIES* pCapabilities)</unmanaged>
        public Capabilities GetCapabilities(DeviceQueryType deviceQueryType)
        {
            Capabilities temp;
            var          result = ErrorCodeHelper.ToResult(xinput.XInputGetCapabilities((int)userIndex, deviceQueryType, out temp));

            result.CheckError();
            return(temp);
        }
        /// <summary>
        /// Gets the battery information.
        /// </summary>
        /// <param name="batteryDeviceType">Type of the battery device.</param>
        /// <returns></returns>
        /// <unmanaged>unsigned int XInputGetBatteryInformation([In] XUSER_INDEX dwUserIndex,[In] BATTERY_DEVTYPE devType,[Out] XINPUT_BATTERY_INFORMATION* pBatteryInformation)</unmanaged>
        public BatteryInformation GetBatteryInformation(BatteryDeviceType batteryDeviceType)
        {
            BatteryInformation temp;
            var result = ErrorCodeHelper.ToResult(xinput.XInputGetBatteryInformation((int)userIndex, batteryDeviceType, out temp));

            result.CheckError();
            return(temp);
        }
        /// <summary>
        /// Gets the state.
        /// </summary>
        /// <returns>The state of this controller.</returns>
        public State GetState()
        {
            State temp;
            var   result = ErrorCodeHelper.ToResult(xinput.XInputGetState((int)userIndex, out temp));

            result.CheckError();
            return(temp);
        }
 public Result GetKeystroke(DeviceQueryType deviceQueryType, out Keystroke keystroke)
 {
     return(ErrorCodeHelper.ToResult(
                openXinput ?
                NativeOpenXinput.XInputGetKeystroke(userIndex, (int)deviceQueryType, out keystroke) :
                NativeXinput.XInputGetKeystroke(userIndex, (int)deviceQueryType, out keystroke)
                ));
 }
        public Result SetVibration(Vibration vibration)
        {
            Result result = ErrorCodeHelper.ToResult(openXinput ?
                                                     NativeOpenXinput.XInputSetState(userIndex, vibration) : NativeXinput.XInputSetState(userIndex, vibration));

            result.CheckError();
            return(result);
        }
        public State GetState()
        {
            State temp;

            ErrorCodeHelper.ToResult(
                openXinput ? NativeOpenXinput.XInputGetState(userIndex, out temp) : NativeXinput.XInputGetState(userIndex, out temp)).CheckError();
            return(temp);
        }
        public Capabilities GetCapabilities(DeviceQueryType deviceQueryType)
        {
            Capabilities temp;

            ErrorCodeHelper.ToResult(
                openXinput ? NativeOpenXinput.XInputGetCapabilities(userIndex, deviceQueryType, out temp) :
                NativeXinput.XInputGetCapabilities(userIndex, deviceQueryType, out temp)
                ).CheckError();
            return(temp);
        }
        public BatteryInformation GetBatteryInformation(BatteryDeviceType batteryDeviceType)
        {
            BatteryInformation temp;

            ErrorCodeHelper.ToResult(
                openXinput ? NativeOpenXinput.XInputGetBatteryInformation((int)this.userIndex, batteryDeviceType, out temp) :
                NativeXinput.XInputGetBatteryInformation((int)this.userIndex, batteryDeviceType, out temp)
                ).CheckError();
            return(temp);
        }
Example #17
0
    private static void FillInitData(
        int width,
        int height,
        int depth,
        int mipCount,
        int arraySize,
        Format format,
        int maxsize,
        int bitSize,
        IntPtr bitData,
        out int twidth,
        out int theight,
        out int tdepth,
        out int skipMip,
        DataBox[] initData)
    {
        if (bitData == IntPtr.Zero || initData == null)
        {
            throw new SharpDXException(Result.InvalidPointer);
        }

        skipMip = 0;
        twidth  = 0;
        theight = 0;
        tdepth  = 0;

        IntPtr pSrcBits = bitData;
        IntPtr pEndBits = bitData + bitSize;

        int index = 0;

        for (int j = 0; j < arraySize; j++)
        {
            int w = width;
            int h = height;
            int d = depth;
            for (int i = 0; i < mipCount; i++)
            {
                GetSurfaceInfo(w,
                               h,
                               format,
                               out int NumBytes,
                               out int RowBytes,
                               out int NumRows
                               );

                if ((mipCount <= 1) || (maxsize == 0) || (w <= maxsize && h <= maxsize && d <= maxsize))
                {
                    if (twidth == 0)
                    {
                        twidth  = w;
                        theight = h;
                        tdepth  = d;
                    }

                    Debug.Assert(index < mipCount * arraySize);
                    initData[index].DataPointer = pSrcBits;
                    initData[index].RowPitch    = RowBytes;
                    initData[index].SlicePitch  = NumBytes;
                    ++index;
                }
                else if (j == 0)
                {
                    // Count number of skipped mipmaps (first item only)
                    ++skipMip;
                }

                if ((long)pSrcBits + (NumBytes * d) > (long)pEndBits)
                {
                    throw new SharpDXException(ErrorCodeHelper.ToResult(ErrorCode.HandleEof));
                }

                pSrcBits += NumBytes * d;

                w = w >> 1;
                h = h >> 1;
                d = d >> 1;
                if (w == 0)
                {
                    w = 1;
                }
                if (h == 0)
                {
                    h = 1;
                }
                if (d == 0)
                {
                    d = 1;
                }
            }
        }

        if (index > 0)
        {
            return;
        }
        else
        {
            throw new SharpDXException(Result.Fail);
        }
    }
Example #18
0
    private static void CreateTextureFromDDS(
        Device d3dDevice,
        DdsHeader header,
        DdsHeaderDxt10?headerDxt10,
        IntPtr bitData,
        int bitSize,
        int maxsize,
        ResourceUsage usage,
        BindFlags bindFlags,
        CpuAccessFlags cpuAccessFlags,
        ResourceOptionFlags miscFlags,
        bool forceSRGB,
        out Resource texture,
        out ShaderResourceView textureView)
    {
        Result hr = Result.Ok;

        int width  = (int)header.width;
        int height = (int)header.height;
        int depth  = (int)header.depth;

        ResourceDimension resDim = ResourceDimension.Unknown;
        uint arraySize           = 1;

        SharpDX.DXGI.Format format = SharpDX.DXGI.Format.Unknown;
        bool isCubeMap             = false;

        int mipCount = (int)header.mipMapCount;

        if (0 == mipCount)
        {
            mipCount = 1;
        }

        if (headerDxt10.HasValue)
        {
            DdsHeaderDxt10 d3d10ext = headerDxt10.Value;

            arraySize = d3d10ext.arraySize;
            if (arraySize == 0)
            {
                throw new SharpDXException(ErrorCodeHelper.ToResult(ErrorCode.InvalidData));
            }

            switch (d3d10ext.dxgiFormat)
            {
            case Format.AI44:
            case Format.IA44:
            case Format.P8:
            case Format.A8P8:
                throw new SharpDXException(ErrorCodeHelper.ToResult(ErrorCode.NotSupported));

            default:
                if (BitsPerPixel(d3d10ext.dxgiFormat) == 0)
                {
                    throw new SharpDXException(ErrorCodeHelper.ToResult(ErrorCode.NotSupported));
                }
                break;
            }

            format = d3d10ext.dxgiFormat;

            switch (d3d10ext.resourceDimension)
            {
            case ResourceDimension.Texture1D:
                // D3DX writes 1D textures with a fixed Height of 1
                if ((header.flags & DDS_HEIGHT) != 0 && height != 1)
                {
                    throw new SharpDXException(ErrorCodeHelper.ToResult(ErrorCode.InvalidData));
                }
                height = depth = 1;
                break;

            case ResourceDimension.Texture2D:
                if ((d3d10ext.miscFlag & ResourceOptionFlags.TextureCube) != 0)
                {
                    arraySize *= 6;
                    isCubeMap  = true;
                }
                depth = 1;
                break;

            case ResourceDimension.Texture3D:
                if ((header.flags & DDS_HEADER_FLAGS_VOLUME) == 0)
                {
                    throw new SharpDXException(ErrorCodeHelper.ToResult(ErrorCode.InvalidData));
                }

                if (arraySize > 1)
                {
                    throw new SharpDXException(ErrorCodeHelper.ToResult(ErrorCode.InvalidData));
                }
                break;

            default:
                throw new SharpDXException(ErrorCodeHelper.ToResult(ErrorCode.InvalidData));
            }

            resDim = d3d10ext.resourceDimension;
        }
        else
        {
            format = GetDXGIFormat(header.ddspf);

            if (format == Format.Unknown)
            {
                throw new SharpDXException(ErrorCodeHelper.ToResult(ErrorCode.NotSupported));
            }

            if ((header.flags & DDS_HEADER_FLAGS_VOLUME) != 0)
            {
                resDim = ResourceDimension.Texture3D;
            }
            else
            {
                if ((header.caps2 & DDS_CUBEMAP) != 0)
                {
                    // We require all six faces to be defined
                    if ((header.caps2 & DDS_CUBEMAP_ALLFACES) != DDS_CUBEMAP_ALLFACES)
                    {
                        throw new SharpDXException(ErrorCodeHelper.ToResult(ErrorCode.NotSupported));
                    }

                    arraySize = 6;
                    isCubeMap = true;
                }

                depth  = 1;
                resDim = ResourceDimension.Texture2D;

                // Note there's no way for a legacy Direct3D 9 DDS to express a '1D' texture
            }

            Debug.Assert(BitsPerPixel(format) != 0);
        }

        // Bound sizes (for security purposes we don't trust DDS file metadata larger than the D3D 11.x hardware requirements)
        if (mipCount > Resource.MaximumMipLevels)
        {
            throw new SharpDXException(ErrorCodeHelper.ToResult(ErrorCode.NotSupported));
        }

        switch (resDim)
        {
        case ResourceDimension.Texture1D:
            if ((arraySize > Resource.MaximumTexture1DArraySize) ||
                (width > Resource.MaximumTexture1DSize))
            {
                throw new SharpDXException(ErrorCodeHelper.ToResult(ErrorCode.NotSupported));
            }
            break;

        case ResourceDimension.Texture2D:
            if (isCubeMap)
            {
                // This is the right bound because we set arraySize to (NumCubes*6) above
                if ((arraySize > Resource.MaximumTexture2DArraySize) ||
                    (width > Resource.MaximumTextureCubeSize) ||
                    (height > Resource.MaximumTextureCubeSize))
                {
                    throw new SharpDXException(ErrorCodeHelper.ToResult(ErrorCode.NotSupported));
                }
            }
            else if ((arraySize > Resource.MaximumTexture2DArraySize) ||
                     (width > Resource.MaximumTexture2DSize) ||
                     (height > Resource.MaximumTexture2DSize))
            {
                throw new SharpDXException(ErrorCodeHelper.ToResult(ErrorCode.NotSupported));
            }
            break;

        case ResourceDimension.Texture3D:
            if ((arraySize > 1) ||
                (width > Resource.MaximumTexture3DSize) ||
                (height > Resource.MaximumTexture3DSize) ||
                (depth > Resource.MaximumTexture3DSize))
            {
                throw new SharpDXException(ErrorCodeHelper.ToResult(ErrorCode.NotSupported));
            }
            break;

        default:
            throw new SharpDXException(ErrorCodeHelper.ToResult(ErrorCode.NotSupported));
        }

        // Create the texture
        DataBox[] initData = new DataBox[mipCount * arraySize];

        FillInitData(width, height, depth, mipCount, (int)arraySize, format, maxsize, bitSize, bitData,
                     out int twidth, out int theight, out int tdepth, out int skipMip, initData);

        CreateD3DResources(d3dDevice, resDim, twidth, theight, tdepth, mipCount - skipMip, (int)arraySize,
                           format, usage, bindFlags, cpuAccessFlags, miscFlags, forceSRGB,
                           isCubeMap, initData, out texture, out textureView);
    }
 /// <summary>Gets the keystroke.</summary>
 /// <param name="deviceQueryType">The flag.</param>
 /// <param name="keystroke">The keystroke.</param>
 /// <returns></returns>
 /// <unmanaged>unsigned int XInputGetKeystroke([In] XUSER_INDEX dwUserIndex,[In] unsigned int dwReserved,[Out] XINPUT_KEYSTROKE* pKeystroke)</unmanaged>
 public Result GetKeystroke(DeviceQueryType deviceQueryType, out Keystroke keystroke)
 {
     return(ErrorCodeHelper.ToResult(xinput.XInputGetKeystroke((int)this.userIndex, (int)deviceQueryType,
                                                               out keystroke)));
 }
Example #20
0
 public SharpDX.XInput.State GetState()
 {
     SharpDX.XInput.State state;
     ErrorCodeHelper.ToResult(SharpDX.XInput.XInput.XInputGetState((int)this.userIndex, out state)).CheckError();
     return(state);
 }