Init
This commit is contained in:
152
physx/samples/sampleframework/platform/include/SamplePlatform.h
Normal file
152
physx/samples/sampleframework/platform/include/SamplePlatform.h
Normal file
@ -0,0 +1,152 @@
|
||||
//
|
||||
// Redistribution and use in source and binary forms, with or without
|
||||
// modification, are permitted provided that the following conditions
|
||||
// are met:
|
||||
// * Redistributions of source code must retain the above copyright
|
||||
// notice, this list of conditions and the following disclaimer.
|
||||
// * Redistributions in binary form must reproduce the above copyright
|
||||
// notice, this list of conditions and the following disclaimer in the
|
||||
// documentation and/or other materials provided with the distribution.
|
||||
// * Neither the name of NVIDIA CORPORATION nor the names of its
|
||||
// contributors may be used to endorse or promote products derived
|
||||
// from this software without specific prior written permission.
|
||||
//
|
||||
// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS ''AS IS'' AND ANY
|
||||
// EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
|
||||
// IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
|
||||
// PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR
|
||||
// CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
|
||||
// EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
|
||||
// PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
|
||||
// PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY
|
||||
// OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
|
||||
// (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
|
||||
// OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||
//
|
||||
// Copyright (c) 2008-2021 NVIDIA Corporation. All rights reserved.
|
||||
|
||||
#ifndef SAMPLE_PLATFORM_H
|
||||
#define SAMPLE_PLATFORM_H
|
||||
|
||||
#include <RendererDesc.h>
|
||||
#include <RendererWindow.h>
|
||||
#include <RendererTexture2D.h>
|
||||
|
||||
namespace SampleFramework
|
||||
{
|
||||
class SampleApplication;
|
||||
class SampleUserInput;
|
||||
|
||||
/* This class declares and partly implements platform-abstraction level.
|
||||
Do not use platform-specific types and functions here.
|
||||
*/
|
||||
class SamplePlatform
|
||||
{
|
||||
protected:
|
||||
SampleRenderer::RendererWindow* m_app;
|
||||
SampleApplication* m_sf_app;
|
||||
static SamplePlatform* m_platform;
|
||||
|
||||
public:
|
||||
// access
|
||||
static SamplePlatform* platform();
|
||||
static void setPlatform(SamplePlatform*);
|
||||
SampleApplication* application();
|
||||
|
||||
// creation
|
||||
explicit SamplePlatform(SampleRenderer::RendererWindow* _app);
|
||||
virtual ~SamplePlatform() = 0;
|
||||
// System
|
||||
virtual void showCursor(bool);
|
||||
|
||||
virtual size_t getCWD(char* path, size_t len);
|
||||
virtual void setCWDToEXE(void);
|
||||
virtual void popPathSpec(char *path);
|
||||
virtual bool preOpenWindow(void * ptr);
|
||||
virtual bool openWindow(physx::PxU32& width,
|
||||
physx::PxU32& height,
|
||||
const char* title,
|
||||
bool fullscreen);
|
||||
virtual bool useWindow(physx::PxU64 hwnd);
|
||||
virtual void update();
|
||||
virtual bool closeWindow();
|
||||
virtual bool updateWindow();
|
||||
virtual bool hasFocus() const;
|
||||
virtual void setFocus(bool b);
|
||||
virtual bool isOpen();
|
||||
virtual physx::PxU64 getWindowHandle();
|
||||
virtual void setWindowSize(physx::PxU32 width,
|
||||
physx::PxU32 height);
|
||||
virtual void getWindowSize(physx::PxU32& width, physx::PxU32& height);
|
||||
virtual void getTitle(char *title, physx::PxU32 maxLength) const;
|
||||
virtual void setTitle(const char *title);
|
||||
|
||||
virtual void setMouseCursorRecentering(bool val) {}
|
||||
virtual bool getMouseCursorRecentering() const { return false; }
|
||||
|
||||
virtual void showMessage(const char* title, const char* message);
|
||||
virtual bool saveBitmap(const char* fileName,
|
||||
physx::PxU32 width,
|
||||
physx::PxU32 height,
|
||||
physx::PxU32 sizeInBytes,
|
||||
const void* data);
|
||||
virtual void* compileProgram(void * context,
|
||||
const char* assetDir,
|
||||
const char *programPath,
|
||||
physx::PxU64 profile,
|
||||
const char* passString,
|
||||
const char *entry,
|
||||
const char **args);
|
||||
virtual void* initializeD3D9();
|
||||
virtual void* initializeD3D11();
|
||||
virtual bool isD3D9ok();
|
||||
virtual const char* getPathSeparator();
|
||||
virtual bool isD3D11ok();
|
||||
// Rendering
|
||||
virtual void initializeCGRuntimeCompiler();
|
||||
virtual void initializeOGLDisplay(const SampleRenderer::RendererDesc& desc,
|
||||
physx::PxU32& width,
|
||||
physx::PxU32& height);
|
||||
virtual physx::PxU32 initializeD3D9Display(void * presentParameters,
|
||||
char* m_deviceName,
|
||||
physx::PxU32& width,
|
||||
physx::PxU32& height,
|
||||
void * m_d3dDevice_out);
|
||||
virtual physx::PxU32 initializeD3D11Display(void *dxgiSwapChainDesc,
|
||||
char *m_deviceName,
|
||||
physx::PxU32& width,
|
||||
physx::PxU32& height,
|
||||
void *m_d3dDevice_out,
|
||||
void *m_d3dDeviceContext_out,
|
||||
void *m_dxgiSwap_out);
|
||||
virtual physx::PxU32 D3D9Present();
|
||||
virtual void D3D9BlockUntilNotBusy(void * resource);
|
||||
virtual void D3D9DeviceBlockUntilIdle();
|
||||
virtual physx::PxU64 getD3D9TextureFormat(SampleRenderer::RendererTexture2D::Format format);
|
||||
virtual physx::PxU32 D3D11Present(bool vsync);
|
||||
virtual physx::PxU64 getD3D11TextureFormat(SampleRenderer::RendererTexture2D::Format format);
|
||||
virtual void postInitializeOGLDisplay();
|
||||
virtual void setOGLVsync(bool on);
|
||||
virtual bool makeContextCurrent();
|
||||
virtual bool isContextValid();
|
||||
virtual void freeDisplay();
|
||||
virtual void swapBuffers();
|
||||
virtual void postRendererRelease();
|
||||
virtual void preRendererSetup();
|
||||
virtual void postRendererSetup(SampleRenderer::Renderer* renderer);
|
||||
virtual void setupRendererDescription(SampleRenderer::RendererDesc& renDesc);
|
||||
// Input
|
||||
virtual void doInput();
|
||||
|
||||
virtual const SampleUserInput* getSampleUserInput() const = 0;
|
||||
virtual SampleUserInput* getSampleUserInput() = 0;
|
||||
|
||||
virtual const char* getPlatformName() const { return NULL; }
|
||||
// File System
|
||||
virtual bool makeSureDirectoryPathExists(const char* dirPath);
|
||||
};
|
||||
|
||||
SamplePlatform* createPlatform(SampleRenderer::RendererWindow* _app);
|
||||
}
|
||||
|
||||
#endif
|
||||
229
physx/samples/sampleframework/platform/include/SampleUserInput.h
Normal file
229
physx/samples/sampleframework/platform/include/SampleUserInput.h
Normal file
@ -0,0 +1,229 @@
|
||||
//
|
||||
// Redistribution and use in source and binary forms, with or without
|
||||
// modification, are permitted provided that the following conditions
|
||||
// are met:
|
||||
// * Redistributions of source code must retain the above copyright
|
||||
// notice, this list of conditions and the following disclaimer.
|
||||
// * Redistributions in binary form must reproduce the above copyright
|
||||
// notice, this list of conditions and the following disclaimer in the
|
||||
// documentation and/or other materials provided with the distribution.
|
||||
// * Neither the name of NVIDIA CORPORATION nor the names of its
|
||||
// contributors may be used to endorse or promote products derived
|
||||
// from this software without specific prior written permission.
|
||||
//
|
||||
// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS ''AS IS'' AND ANY
|
||||
// EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
|
||||
// IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
|
||||
// PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR
|
||||
// CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
|
||||
// EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
|
||||
// PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
|
||||
// PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY
|
||||
// OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
|
||||
// (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
|
||||
// OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||
//
|
||||
// Copyright (c) 2008-2021 NVIDIA Corporation. All rights reserved.
|
||||
|
||||
#ifndef SAMPLE_USER_INPUT_H
|
||||
#define SAMPLE_USER_INPUT_H
|
||||
|
||||
#include <foundation/PxSimpleTypes.h>
|
||||
#include <vector>
|
||||
#include "PsString.h"
|
||||
|
||||
#if PX_VC
|
||||
#pragma warning(push)
|
||||
#pragma warning(disable:4702)
|
||||
#include <map>
|
||||
#pragma warning(pop)
|
||||
#else
|
||||
#include <map>
|
||||
#endif
|
||||
|
||||
namespace SampleRenderer
|
||||
{
|
||||
class Renderer;
|
||||
}
|
||||
|
||||
namespace SampleFramework
|
||||
{
|
||||
class InputEventListener;
|
||||
|
||||
struct UserInput
|
||||
{
|
||||
physx::PxU16 m_Id;
|
||||
char m_IdName[256]; // this name is used for mapping (enum name)
|
||||
char m_Name[256]; // this name is used for help
|
||||
};
|
||||
|
||||
struct InputEvent
|
||||
{
|
||||
InputEvent(physx::PxU16 id, bool analog = false, float sens = 1.0f)
|
||||
:m_Id(id), m_Analog(analog), m_Sensitivity(sens)
|
||||
{
|
||||
}
|
||||
|
||||
InputEvent(const InputEvent& e)
|
||||
:m_Id(e.m_Id), m_Analog(e.m_Analog), m_Sensitivity(e.m_Sensitivity)
|
||||
{
|
||||
}
|
||||
|
||||
InputEvent()
|
||||
: m_Analog(false), m_Sensitivity(1.0f)
|
||||
{
|
||||
}
|
||||
|
||||
physx::PxU16 m_Id;
|
||||
bool m_Analog;
|
||||
float m_Sensitivity;
|
||||
};
|
||||
|
||||
struct InputEventName
|
||||
{
|
||||
char m_Name[256];
|
||||
};
|
||||
|
||||
struct SampleInputData
|
||||
{
|
||||
char m_InputEventName[256];
|
||||
char m_UserInputName[256];
|
||||
};
|
||||
|
||||
struct SampleInputMapping
|
||||
{
|
||||
physx::PxU16 m_InputEventId;
|
||||
size_t m_InputEventIndex;
|
||||
physx::PxU16 m_UserInputId;
|
||||
size_t m_UserInputIndex;
|
||||
};
|
||||
|
||||
typedef std::vector<SampleInputData> T_SampleInputData;
|
||||
|
||||
enum InputType
|
||||
{
|
||||
UNDEFINED_INPUT = 0,
|
||||
KEYBOARD_INPUT = (1 << 0),
|
||||
GAMEPAD_INPUT = (1 << 1),
|
||||
TOUCH_BUTTON_INPUT = (1 << 2),
|
||||
TOUCH_PAD_INPUT = (1 << 3),
|
||||
MOUSE_INPUT = (1 << 4),
|
||||
};
|
||||
|
||||
enum InputDataReadState
|
||||
{
|
||||
STATE_INPUT_EVENT_ID,
|
||||
STATE_USER_INPUT_ID,
|
||||
STATE_DIGITAL,
|
||||
STATE_INPUT_EVENT_NAME,
|
||||
};
|
||||
|
||||
class SampleUserInput
|
||||
{
|
||||
public:
|
||||
// key codes for console and raw key info
|
||||
enum KeyCode
|
||||
{
|
||||
KEY_UNKNOWN = 0,
|
||||
|
||||
KEY_A, KEY_B, KEY_C, KEY_D, KEY_E, KEY_F, KEY_G,
|
||||
KEY_H, KEY_I, KEY_J, KEY_K, KEY_L, KEY_M, KEY_N,
|
||||
KEY_O, KEY_P, KEY_Q, KEY_R, KEY_S, KEY_T, KEY_U,
|
||||
KEY_V, KEY_W, KEY_X, KEY_Y, KEY_Z,
|
||||
|
||||
KEY_0, KEY_1, KEY_2, KEY_3, KEY_4, KEY_5, KEY_6,
|
||||
KEY_7, KEY_8, KEY_9,
|
||||
|
||||
KEY_SPACE, KEY_RETURN, KEY_SHIFT, KEY_CONTROL, KEY_ESCAPE, KEY_COMMA,
|
||||
KEY_NUMPAD0, KEY_NUMPAD1, KEY_NUMPAD2, KEY_NUMPAD3, KEY_NUMPAD4, KEY_NUMPAD5, KEY_NUMPAD6, KEY_NUMPAD7, KEY_NUMPAD8, KEY_NUMPAD9,
|
||||
KEY_MULTIPLY, KEY_ADD, KEY_SEPARATOR, KEY_SUBTRACT, KEY_DECIMAL, KEY_DIVIDE,
|
||||
|
||||
KEY_F1, KEY_F2, KEY_F3, KEY_F4, KEY_F5, KEY_F6,
|
||||
KEY_F7, KEY_F8, KEY_F9, KEY_F10, KEY_F11, KEY_F12,
|
||||
|
||||
KEY_TAB, KEY_PRIOR, KEY_NEXT,
|
||||
KEY_UP, KEY_DOWN, KEY_LEFT, KEY_RIGHT,
|
||||
|
||||
NUM_KEY_CODES,
|
||||
};
|
||||
|
||||
SampleUserInput();
|
||||
|
||||
virtual ~SampleUserInput();
|
||||
|
||||
void registerUserInput(physx::PxU16 id, const char* idName, const char* name);
|
||||
virtual const InputEvent* registerInputEvent(const InputEvent& inputEvent, physx::PxU16 userInputId, const char* name);
|
||||
virtual const InputEvent* registerTouchInputEvent(const InputEvent& inputEvent, physx::PxU16 userInputId, const char* caption, const char* name)
|
||||
{
|
||||
PX_UNUSED(inputEvent);
|
||||
PX_UNUSED(userInputId);
|
||||
PX_UNUSED(caption);
|
||||
return NULL;
|
||||
}
|
||||
virtual void unregisterInputEvent(physx::PxU16 inputEventId);
|
||||
virtual void registerInputEvent(const SampleInputMapping& mapping);
|
||||
|
||||
virtual bool keyboardSupported() const { return false; }
|
||||
virtual bool gamepadSupported() const { return false; }
|
||||
virtual bool mouseSupported() const { return false; }
|
||||
|
||||
virtual InputType getInputType(const UserInput& ) const { return UNDEFINED_INPUT; }
|
||||
|
||||
void registerInputEventListerner(InputEventListener* listener) { mListener = listener; }
|
||||
InputEventListener* getInputEventListener() const { return mListener; }
|
||||
|
||||
virtual void updateInput();
|
||||
virtual void shutdown();
|
||||
|
||||
virtual void setRenderer(SampleRenderer::Renderer* ) {}
|
||||
|
||||
virtual bool getDigitalInputEventState(physx::PxU16 inputEventId ) const = 0;
|
||||
virtual float getAnalogInputEventState(physx::PxU16 inputEventId ) const = 0;
|
||||
|
||||
const std::vector<size_t>* getUserInputs(physx::PxI32 inputEventId) const;
|
||||
const std::vector<size_t>* getInputEvents(physx::PxU16 userInputId) const;
|
||||
|
||||
const std::vector<InputEvent>& getInputEventList() const { return mInputEvents; }
|
||||
const std::vector<InputEventName>& getInputEventNameList() const { return mInputEventNames; }
|
||||
const std::vector<UserInput>& getUserInputList() const { return mUserInputs; }
|
||||
const std::map<physx::PxU16, std::vector<size_t> >& getInputEventUserInputMap() const { return mInputEventUserInputMap; }
|
||||
|
||||
physx::PxU16 getUserInputKeys(physx::PxU16 inputEventId, const char* names[], physx::PxU16 maxNames, physx::PxU32 inputTypeMask) const;
|
||||
|
||||
physx::PxI32 translateUserInputNameToId(const char* name, size_t& index) const;
|
||||
physx::PxI32 translateInputEventNameToId(const char* name, size_t& index) const;
|
||||
const char* translateInputEventIdToName(physx::PxI32 id) const;
|
||||
|
||||
const InputEvent* getInputEventSlow(physx::PxU16 inputEventId) const;
|
||||
|
||||
protected:
|
||||
virtual void processGamepads();
|
||||
|
||||
std::vector<UserInput> mUserInputs;
|
||||
std::vector<InputEvent> mInputEvents;
|
||||
std::vector<InputEventName> mInputEventNames;
|
||||
|
||||
private:
|
||||
|
||||
InputEventListener* mListener;
|
||||
std::map<physx::PxU16, std::vector<size_t> > mInputEventUserInputMap;
|
||||
std::map<physx::PxU16, std::vector<size_t> > mUserInputInputEventMap;
|
||||
};
|
||||
|
||||
class InputEventListener
|
||||
{
|
||||
public:
|
||||
InputEventListener() {}
|
||||
|
||||
virtual ~InputEventListener() {}
|
||||
|
||||
// special case for text console
|
||||
virtual void onKeyDownEx(SampleUserInput::KeyCode, physx::PxU32) {}
|
||||
|
||||
virtual void onPointerInputEvent(const InputEvent&, physx::PxU32, physx::PxU32, physx::PxReal, physx::PxReal, bool val) {}
|
||||
virtual void onAnalogInputEvent(const InputEvent& , float val) = 0;
|
||||
virtual void onDigitalInputEvent(const InputEvent& , bool val) = 0;
|
||||
};
|
||||
}
|
||||
|
||||
#endif
|
||||
@ -0,0 +1,42 @@
|
||||
//
|
||||
// Redistribution and use in source and binary forms, with or without
|
||||
// modification, are permitted provided that the following conditions
|
||||
// are met:
|
||||
// * Redistributions of source code must retain the above copyright
|
||||
// notice, this list of conditions and the following disclaimer.
|
||||
// * Redistributions in binary form must reproduce the above copyright
|
||||
// notice, this list of conditions and the following disclaimer in the
|
||||
// documentation and/or other materials provided with the distribution.
|
||||
// * Neither the name of NVIDIA CORPORATION nor the names of its
|
||||
// contributors may be used to endorse or promote products derived
|
||||
// from this software without specific prior written permission.
|
||||
//
|
||||
// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS ''AS IS'' AND ANY
|
||||
// EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
|
||||
// IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
|
||||
// PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR
|
||||
// CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
|
||||
// EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
|
||||
// PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
|
||||
// PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY
|
||||
// OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
|
||||
// (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
|
||||
// OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||
//
|
||||
// Copyright (c) 2008-2021 NVIDIA Corporation. All rights reserved.
|
||||
|
||||
#ifndef SAMPLE_USER_INPUT_IDS_H
|
||||
#define SAMPLE_USER_INPUT_IDS_H
|
||||
|
||||
|
||||
#if defined (RENDERER_WINDOWS)
|
||||
#include <windows/WindowsSampleUserInputIds.h>
|
||||
#elif defined (RENDERER_LINUX)
|
||||
#include <linux/LinuxSampleUserInputIds.h>
|
||||
#elif defined (RENDERER_MACOSX)
|
||||
#include <osx/OSXSampleUserInputIds.h>
|
||||
#else
|
||||
#error Unknown platform!
|
||||
#endif
|
||||
|
||||
#endif
|
||||
@ -0,0 +1,131 @@
|
||||
//
|
||||
// Redistribution and use in source and binary forms, with or without
|
||||
// modification, are permitted provided that the following conditions
|
||||
// are met:
|
||||
// * Redistributions of source code must retain the above copyright
|
||||
// notice, this list of conditions and the following disclaimer.
|
||||
// * Redistributions in binary form must reproduce the above copyright
|
||||
// notice, this list of conditions and the following disclaimer in the
|
||||
// documentation and/or other materials provided with the distribution.
|
||||
// * Neither the name of NVIDIA CORPORATION nor the names of its
|
||||
// contributors may be used to endorse or promote products derived
|
||||
// from this software without specific prior written permission.
|
||||
//
|
||||
// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS ''AS IS'' AND ANY
|
||||
// EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
|
||||
// IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
|
||||
// PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR
|
||||
// CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
|
||||
// EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
|
||||
// PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
|
||||
// PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY
|
||||
// OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
|
||||
// (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
|
||||
// OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||
//
|
||||
// Copyright (c) 2008-2021 NVIDIA Corporation. All rights reserved.
|
||||
|
||||
#ifndef LINUX_SAMPLE_PLATFORM_H
|
||||
#define LINUX_SAMPLE_PLATFORM_H
|
||||
|
||||
#include <SamplePlatform.h>
|
||||
#include <linux/LinuxSampleUserInput.h>
|
||||
|
||||
#include <X11/Xlib.h>
|
||||
#include <X11/extensions/xf86vmode.h>
|
||||
|
||||
#if defined(RENDERER_ENABLE_OPENGL)
|
||||
#define GLEW_STATIC
|
||||
#include <GL/glew.h>
|
||||
#endif
|
||||
|
||||
#include <GL/gl.h>
|
||||
#include <GL/glx.h>
|
||||
#include <GL/glu.h>
|
||||
|
||||
namespace SampleFramework
|
||||
{
|
||||
class LinuxPlatform : public SamplePlatform
|
||||
{
|
||||
public:
|
||||
explicit LinuxPlatform(SampleRenderer::RendererWindow* _app);
|
||||
// System
|
||||
virtual void showCursor(bool);
|
||||
virtual void setCWDToEXE(void);
|
||||
const char* getPathSeparator();
|
||||
bool makeSureDirectoryPathExists(const char* dirPath);
|
||||
void showMessage(const char* title, const char* message);
|
||||
// Rendering
|
||||
virtual void initializeOGLDisplay(const SampleRenderer::RendererDesc& desc,
|
||||
physx::PxU32& width,
|
||||
physx::PxU32& height);
|
||||
virtual void postInitializeOGLDisplay();
|
||||
virtual void postRendererSetup(SampleRenderer::Renderer* renderer);
|
||||
virtual void setupRendererDescription(SampleRenderer::RendererDesc& renDesc);
|
||||
virtual bool hasFocus() const;
|
||||
virtual void setFocus(bool b);
|
||||
virtual void getTitle(char *title, physx::PxU32 maxLength) const;
|
||||
virtual void setTitle(const char *title);
|
||||
virtual bool updateWindow();
|
||||
virtual bool openWindow(physx::PxU32& width,
|
||||
physx::PxU32& height,
|
||||
const char* title,
|
||||
bool fullscreen);
|
||||
virtual void getWindowSize(physx::PxU32& width, physx::PxU32& height);
|
||||
virtual void update();
|
||||
virtual bool closeWindow();
|
||||
virtual void freeDisplay();
|
||||
virtual void swapBuffers();
|
||||
|
||||
virtual void* compileProgram(void * context,
|
||||
const char* assetDir,
|
||||
const char *programPath,
|
||||
physx::PxU64 profile,
|
||||
const char* passString,
|
||||
const char *entry,
|
||||
const char **args);
|
||||
|
||||
// Input
|
||||
virtual void doInput();
|
||||
|
||||
virtual const SampleUserInput* getSampleUserInput() const { return &m_linuxSampleUserInput; }
|
||||
virtual SampleUserInput* getSampleUserInput() { return &m_linuxSampleUserInput; }
|
||||
|
||||
virtual const char* getPlatformName() const { return "linux"; }
|
||||
|
||||
virtual void setMouseCursorRecentering(bool val);
|
||||
virtual bool getMouseCursorRecentering() const;
|
||||
|
||||
physx::PxVec2 getMouseCursorPos() const { return m_mouseCursorPos; }
|
||||
void setMouseCursorPos(const physx::PxVec2& pos) { m_mouseCursorPos = pos; }
|
||||
void recenterMouseCursor(bool generateEvent);
|
||||
|
||||
LinuxSampleUserInput& getLinuxSampleUserInput() { return m_linuxSampleUserInput; }
|
||||
const LinuxSampleUserInput& getLinuxSampleUserInput() const { return m_linuxSampleUserInput; }
|
||||
|
||||
protected:
|
||||
bool filterKeyRepeat(const XEvent& keyReleaseEvent);
|
||||
void handleMouseEvent(const XEvent& event);
|
||||
void showCursorInternal(bool show);
|
||||
|
||||
protected:
|
||||
Display* m_display;
|
||||
XVisualInfo* m_visualInfo;
|
||||
Window m_window;
|
||||
Atom m_wmDelete;
|
||||
GLXContext m_glxContext;
|
||||
XF86VidModeModeInfo m_desktopMode;
|
||||
int m_screen;
|
||||
bool m_isFullScreen;
|
||||
bool m_hasFocus;
|
||||
bool m_hasContentFocus;
|
||||
physx::PxU32 m_windowWidth;
|
||||
physx::PxU32 m_windowHeight;
|
||||
LinuxSampleUserInput m_linuxSampleUserInput;
|
||||
physx::PxVec2 m_mouseCursorPos;
|
||||
bool m_recenterMouseCursor;
|
||||
bool m_showCursor;
|
||||
};
|
||||
}
|
||||
|
||||
#endif
|
||||
@ -0,0 +1,76 @@
|
||||
//
|
||||
// Redistribution and use in source and binary forms, with or without
|
||||
// modification, are permitted provided that the following conditions
|
||||
// are met:
|
||||
// * Redistributions of source code must retain the above copyright
|
||||
// notice, this list of conditions and the following disclaimer.
|
||||
// * Redistributions in binary form must reproduce the above copyright
|
||||
// notice, this list of conditions and the following disclaimer in the
|
||||
// documentation and/or other materials provided with the distribution.
|
||||
// * Neither the name of NVIDIA CORPORATION nor the names of its
|
||||
// contributors may be used to endorse or promote products derived
|
||||
// from this software without specific prior written permission.
|
||||
//
|
||||
// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS ''AS IS'' AND ANY
|
||||
// EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
|
||||
// IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
|
||||
// PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR
|
||||
// CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
|
||||
// EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
|
||||
// PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
|
||||
// PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY
|
||||
// OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
|
||||
// (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
|
||||
// OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||
//
|
||||
// Copyright (c) 2008-2021 NVIDIA Corporation. All rights reserved.
|
||||
|
||||
#ifndef LINUX_SAMPLE_USER_INPUT_H
|
||||
#define LINUX_SAMPLE_USER_INPUT_H
|
||||
|
||||
#include <X11/Xlib.h>
|
||||
#include <SampleUserInput.h>
|
||||
#include <linux/LinuxSampleUserInputIds.h>
|
||||
#include <set>
|
||||
|
||||
|
||||
namespace SampleFramework
|
||||
{
|
||||
class LinuxSampleUserInput: public SampleUserInput
|
||||
{
|
||||
public:
|
||||
|
||||
LinuxSampleUserInput();
|
||||
~LinuxSampleUserInput();
|
||||
|
||||
void doOnMouseMove( physx::PxU32 x, physx::PxU32 y, physx::PxReal dx, physx::PxReal dy, physx::PxU16 button);
|
||||
void doOnMouseDown( physx::PxU32 x, physx::PxU32 y, physx::PxU16 button);
|
||||
void doOnMouseUp( physx::PxU32 x, physx::PxU32 y, physx::PxU16 button);
|
||||
void doOnKeyDown( KeySym keySym, physx::PxU16 keyCode, physx::PxU8 ascii);
|
||||
void doOnKeyUp( KeySym keySym, physx::PxU16 keyCode, physx::PxU8 ascii);
|
||||
|
||||
virtual void updateInput();
|
||||
|
||||
virtual void shutdown();
|
||||
|
||||
virtual bool keyboardSupported() const { return true; }
|
||||
virtual bool gamepadSupported() const { return false; }
|
||||
virtual bool mouseSupported() const { return true; }
|
||||
|
||||
virtual bool getDigitalInputEventState(physx::PxU16 inputEventId) const;
|
||||
virtual float getAnalogInputEventState(physx::PxU16 inputEventId) const;
|
||||
|
||||
protected:
|
||||
|
||||
void registerScanCode(LinuxSampleUserInputIds scanCodeId, physx::PxU16 scanCode, LinuxSampleUserInputIds nameId, const char* name);
|
||||
LinuxSampleUserInputIds getInputIdFromKeySym(const KeySym keySym) const;
|
||||
LinuxSampleUserInputIds getInputIdFromMouseButton(const physx::PxU16 button) const;
|
||||
const UserInput* getUserInputFromId(LinuxSampleUserInputIds id) const;
|
||||
|
||||
std::map<physx::PxU16, physx::PxU16> m_ScanCodesMap;
|
||||
std::map<physx::PxU16,float> m_AnalogStates;
|
||||
std::map<physx::PxU16,bool> m_DigitalStates;
|
||||
};
|
||||
}
|
||||
|
||||
#endif
|
||||
@ -0,0 +1,141 @@
|
||||
//
|
||||
// Redistribution and use in source and binary forms, with or without
|
||||
// modification, are permitted provided that the following conditions
|
||||
// are met:
|
||||
// * Redistributions of source code must retain the above copyright
|
||||
// notice, this list of conditions and the following disclaimer.
|
||||
// * Redistributions in binary form must reproduce the above copyright
|
||||
// notice, this list of conditions and the following disclaimer in the
|
||||
// documentation and/or other materials provided with the distribution.
|
||||
// * Neither the name of NVIDIA CORPORATION nor the names of its
|
||||
// contributors may be used to endorse or promote products derived
|
||||
// from this software without specific prior written permission.
|
||||
//
|
||||
// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS ''AS IS'' AND ANY
|
||||
// EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
|
||||
// IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
|
||||
// PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR
|
||||
// CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
|
||||
// EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
|
||||
// PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
|
||||
// PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY
|
||||
// OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
|
||||
// (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
|
||||
// OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||
//
|
||||
// Copyright (c) 2008-2021 NVIDIA Corporation. All rights reserved.
|
||||
|
||||
#ifndef LINUX_SAMPLE_USER_INPUT_IDS_H
|
||||
#define LINUX_SAMPLE_USER_INPUT_IDS_H
|
||||
|
||||
namespace SampleFramework
|
||||
{
|
||||
enum LinuxSampleUserInputIds
|
||||
{
|
||||
LINUXKEY_UNKNOWN = 0,
|
||||
|
||||
// the following keys are keyboard layout dependent
|
||||
// its not a complete list
|
||||
LINUXKEY_A,
|
||||
LINUXKEY_B,
|
||||
LINUXKEY_C,
|
||||
LINUXKEY_D,
|
||||
LINUXKEY_E,
|
||||
LINUXKEY_F,
|
||||
LINUXKEY_G,
|
||||
LINUXKEY_H,
|
||||
LINUXKEY_I,
|
||||
LINUXKEY_J,
|
||||
LINUXKEY_K,
|
||||
LINUXKEY_L,
|
||||
LINUXKEY_M,
|
||||
LINUXKEY_N,
|
||||
LINUXKEY_O,
|
||||
LINUXKEY_P,
|
||||
LINUXKEY_Q,
|
||||
LINUXKEY_R,
|
||||
LINUXKEY_S,
|
||||
LINUXKEY_T,
|
||||
LINUXKEY_U,
|
||||
LINUXKEY_V,
|
||||
LINUXKEY_W,
|
||||
LINUXKEY_X,
|
||||
LINUXKEY_Y,
|
||||
LINUXKEY_Z,
|
||||
|
||||
LINUXKEY_0,
|
||||
LINUXKEY_1,
|
||||
LINUXKEY_2,
|
||||
LINUXKEY_3,
|
||||
LINUXKEY_4,
|
||||
LINUXKEY_5,
|
||||
LINUXKEY_6,
|
||||
LINUXKEY_7,
|
||||
LINUXKEY_8,
|
||||
LINUXKEY_9,
|
||||
|
||||
LINUXKEY_NUMPAD0,
|
||||
LINUXKEY_NUMPAD1,
|
||||
LINUXKEY_NUMPAD2,
|
||||
LINUXKEY_NUMPAD3,
|
||||
LINUXKEY_NUMPAD4,
|
||||
LINUXKEY_NUMPAD5,
|
||||
LINUXKEY_NUMPAD6,
|
||||
LINUXKEY_NUMPAD7,
|
||||
LINUXKEY_NUMPAD8,
|
||||
LINUXKEY_NUMPAD9,
|
||||
|
||||
LINUXKEY_SHIFT,
|
||||
LINUXKEY_CONTROL,
|
||||
LINUXKEY_SPACE,
|
||||
LINUXKEY_RETURN,
|
||||
LINUXKEY_ESCAPE,
|
||||
LINUXKEY_COMMA,
|
||||
LINUXKEY_DIVIDE,
|
||||
LINUXKEY_SUBTRACT,
|
||||
LINUXKEY_ADD,
|
||||
|
||||
LINUXKEY_F1,
|
||||
LINUXKEY_F2,
|
||||
LINUXKEY_F3,
|
||||
LINUXKEY_F4,
|
||||
LINUXKEY_F5,
|
||||
LINUXKEY_F6,
|
||||
LINUXKEY_F7,
|
||||
LINUXKEY_F8,
|
||||
LINUXKEY_F9,
|
||||
LINUXKEY_F10,
|
||||
LINUXKEY_F11,
|
||||
LINUXKEY_F12,
|
||||
|
||||
LINUXKEY_TAB,
|
||||
LINUXKEY_BACKSPACE,
|
||||
LINUXKEY_PRIOR,
|
||||
LINUXKEY_NEXT,
|
||||
LINUXKEY_UP,
|
||||
LINUXKEY_DOWN,
|
||||
LINUXKEY_LEFT,
|
||||
LINUXKEY_RIGHT,
|
||||
|
||||
MOUSE_BUTTON_LEFT,
|
||||
MOUSE_BUTTON_RIGHT,
|
||||
MOUSE_BUTTON_CENTER,
|
||||
|
||||
MOUSE_MOVE,
|
||||
|
||||
SCAN_CODE_UP ,
|
||||
SCAN_CODE_DOWN ,
|
||||
SCAN_CODE_LEFT,
|
||||
SCAN_CODE_RIGHT,
|
||||
SCAN_CODE_FORWARD,
|
||||
SCAN_CODE_BACKWARD,
|
||||
SCAN_CODE_L,
|
||||
SCAN_CODE_9,
|
||||
SCAN_CODE_0,
|
||||
|
||||
NUM_KEY_CODES,
|
||||
};
|
||||
|
||||
}
|
||||
|
||||
#endif
|
||||
@ -0,0 +1,164 @@
|
||||
//
|
||||
// Redistribution and use in source and binary forms, with or without
|
||||
// modification, are permitted provided that the following conditions
|
||||
// are met:
|
||||
// * Redistributions of source code must retain the above copyright
|
||||
// notice, this list of conditions and the following disclaimer.
|
||||
// * Redistributions in binary form must reproduce the above copyright
|
||||
// notice, this list of conditions and the following disclaimer in the
|
||||
// documentation and/or other materials provided with the distribution.
|
||||
// * Neither the name of NVIDIA CORPORATION nor the names of its
|
||||
// contributors may be used to endorse or promote products derived
|
||||
// from this software without specific prior written permission.
|
||||
//
|
||||
// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS ''AS IS'' AND ANY
|
||||
// EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
|
||||
// IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
|
||||
// PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR
|
||||
// CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
|
||||
// EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
|
||||
// PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
|
||||
// PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY
|
||||
// OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
|
||||
// (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
|
||||
// OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||
//
|
||||
// Copyright (c) 2008-2021 NVIDIA Corporation. All rights reserved.
|
||||
|
||||
#ifndef WINDOWS_SAMPLE_PLATFORM_H
|
||||
#define WINDOWS_SAMPLE_PLATFORM_H
|
||||
|
||||
#include <SamplePlatform.h>
|
||||
#include <windows/WindowsSampleUserInput.h>
|
||||
|
||||
struct IDirect3D9;
|
||||
struct IDirect3DDevice9;
|
||||
|
||||
struct ID3D11Device;
|
||||
struct ID3D11DeviceContext;
|
||||
struct IDXGIFactory1;
|
||||
struct IDXGISwapChain;
|
||||
|
||||
namespace SampleFramework
|
||||
{
|
||||
class WindowsPlatform : public SamplePlatform
|
||||
{
|
||||
public:
|
||||
explicit WindowsPlatform(SampleRenderer::RendererWindow* _app);
|
||||
virtual ~WindowsPlatform();
|
||||
// System
|
||||
virtual void showCursor(bool);
|
||||
virtual void postRendererSetup(SampleRenderer::Renderer* renderer);
|
||||
virtual size_t getCWD(char* path, size_t len);
|
||||
virtual void setCWDToEXE(void);
|
||||
virtual bool openWindow(physx::PxU32& width,
|
||||
physx::PxU32& height,
|
||||
const char* title,
|
||||
bool fullscreen);
|
||||
virtual bool useWindow(physx::PxU64 hwnd);
|
||||
virtual void update();
|
||||
virtual bool isOpen();
|
||||
virtual bool closeWindow();
|
||||
virtual bool hasFocus() const;
|
||||
virtual void getTitle(char *title, physx::PxU32 maxLength) const;
|
||||
virtual void setTitle(const char *title);
|
||||
virtual void setFocus(bool b);
|
||||
virtual physx::PxU64 getWindowHandle();
|
||||
virtual void setWindowSize(physx::PxU32 width,
|
||||
physx::PxU32 height);
|
||||
virtual void getWindowSize(physx::PxU32& width, physx::PxU32& height);
|
||||
virtual void showMessage(const char* title, const char* message);
|
||||
virtual bool saveBitmap(const char* fileName,
|
||||
physx::PxU32 width,
|
||||
physx::PxU32 height,
|
||||
physx::PxU32 sizeInBytes,
|
||||
const void* data);
|
||||
virtual void* compileProgram(void * context,
|
||||
const char* assetDir,
|
||||
const char *programPath,
|
||||
physx::PxU64 profile,
|
||||
const char* passString,
|
||||
const char *entry,
|
||||
const char **args);
|
||||
virtual void* initializeD3D9();
|
||||
virtual bool isD3D9ok();
|
||||
virtual void* initializeD3D11();
|
||||
virtual bool isD3D11ok();
|
||||
// Rendering
|
||||
virtual void initializeOGLDisplay(const SampleRenderer::RendererDesc& desc,
|
||||
physx::PxU32& width,
|
||||
physx::PxU32& height);
|
||||
virtual void postInitializeOGLDisplay();
|
||||
virtual void setOGLVsync(bool on);
|
||||
virtual physx::PxU32 initializeD3D9Display(void * presentParameters,
|
||||
char* m_deviceName,
|
||||
physx::PxU32& width,
|
||||
physx::PxU32& height,
|
||||
void * m_d3dDevice_out);
|
||||
virtual physx::PxU32 initializeD3D11Display(void *dxgiSwapChainDesc,
|
||||
char *m_deviceName,
|
||||
physx::PxU32& width,
|
||||
physx::PxU32& height,
|
||||
void *m_d3dDevice_out,
|
||||
void *m_d3dDeviceContext_out,
|
||||
void *m_dxgiSwap_out);
|
||||
|
||||
virtual physx::PxU32 D3D9Present();
|
||||
virtual physx::PxU64 getD3D9TextureFormat(SampleRenderer::RendererTexture2D::Format format);
|
||||
virtual physx::PxU32 D3D11Present(bool vsync);
|
||||
virtual physx::PxU64 getD3D11TextureFormat(SampleRenderer::RendererTexture2D::Format format);
|
||||
virtual bool makeContextCurrent();
|
||||
virtual void freeDisplay();
|
||||
virtual bool isContextValid();
|
||||
virtual void swapBuffers();
|
||||
virtual void setupRendererDescription(SampleRenderer::RendererDesc& renDesc);
|
||||
// Input
|
||||
virtual void doInput();
|
||||
// File System
|
||||
virtual bool makeSureDirectoryPathExists(const char* dirPath);
|
||||
|
||||
virtual const SampleUserInput* getSampleUserInput() const { return &m_windowsSampleUserInput; }
|
||||
virtual SampleUserInput* getSampleUserInput() { return &m_windowsSampleUserInput; }
|
||||
|
||||
WindowsSampleUserInput& getWindowsSampleUserInput() { return m_windowsSampleUserInput; }
|
||||
const WindowsSampleUserInput& getWindowsSampleUserInput() const { return m_windowsSampleUserInput; }
|
||||
|
||||
virtual const char* getPlatformName() const { return m_platformName; }
|
||||
|
||||
virtual void setMouseCursorRecentering(bool val);
|
||||
virtual bool getMouseCursorRecentering() const;
|
||||
|
||||
|
||||
physx::PxVec2 getMouseCursorPos() const { return m_mouseCursorPos; }
|
||||
void setMouseCursorPos(const physx::PxVec2& pos) { m_mouseCursorPos = pos; }
|
||||
void recenterMouseCursor(bool generateEvent);
|
||||
void setWorkaroundMouseMoved() { m_workaroundMouseMoved = true; }
|
||||
|
||||
protected:
|
||||
IDirect3D9* m_d3d;
|
||||
IDirect3DDevice9* m_d3dDevice;
|
||||
IDXGIFactory1* m_dxgiFactory;
|
||||
IDXGISwapChain* m_dxgiSwap;
|
||||
ID3D11Device* m_d3d11Device;
|
||||
ID3D11DeviceContext* m_d3d11DeviceContext;
|
||||
HWND m_hwnd;
|
||||
HDC m_hdc;
|
||||
HGLRC m_hrc;
|
||||
HMODULE m_library;
|
||||
HMODULE m_dxgiLibrary;
|
||||
HMODULE m_d3d11Library;
|
||||
bool m_ownsWindow;
|
||||
bool m_isHandlingMessages;
|
||||
bool m_destroyWindow;
|
||||
bool m_hasFocus;
|
||||
bool m_showCursor;
|
||||
char m_platformName[256];
|
||||
WindowsSampleUserInput m_windowsSampleUserInput;
|
||||
physx::PxVec2 m_mouseCursorPos;
|
||||
bool m_workaroundMouseMoved;
|
||||
bool m_recenterMouseCursor;
|
||||
bool m_vsync;
|
||||
};
|
||||
}
|
||||
|
||||
#endif
|
||||
@ -0,0 +1,158 @@
|
||||
//
|
||||
// Redistribution and use in source and binary forms, with or without
|
||||
// modification, are permitted provided that the following conditions
|
||||
// are met:
|
||||
// * Redistributions of source code must retain the above copyright
|
||||
// notice, this list of conditions and the following disclaimer.
|
||||
// * Redistributions in binary form must reproduce the above copyright
|
||||
// notice, this list of conditions and the following disclaimer in the
|
||||
// documentation and/or other materials provided with the distribution.
|
||||
// * Neither the name of NVIDIA CORPORATION nor the names of its
|
||||
// contributors may be used to endorse or promote products derived
|
||||
// from this software without specific prior written permission.
|
||||
//
|
||||
// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS ''AS IS'' AND ANY
|
||||
// EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
|
||||
// IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
|
||||
// PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR
|
||||
// CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
|
||||
// EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
|
||||
// PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
|
||||
// PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY
|
||||
// OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
|
||||
// (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
|
||||
// OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||
//
|
||||
// Copyright (c) 2008-2021 NVIDIA Corporation. All rights reserved.
|
||||
|
||||
#ifndef WINDOWS_SAMPLE_USER_INPUT_H
|
||||
#define WINDOWS_SAMPLE_USER_INPUT_H
|
||||
|
||||
|
||||
#include <SampleUserInput.h>
|
||||
#include <windows/WindowsSampleUserInputIds.h>
|
||||
#include <WTypes.h>
|
||||
#include <XInput.h>
|
||||
|
||||
namespace SampleFramework
|
||||
{
|
||||
class WindowsSampleUserInput: public SampleUserInput
|
||||
{
|
||||
public:
|
||||
enum KeyEventFlag
|
||||
{
|
||||
KEY_EVENT_NONE = 0,
|
||||
KEY_EVENT_UP,
|
||||
KEY_EVENT_DOWN,
|
||||
};
|
||||
|
||||
enum MouseButtons
|
||||
{
|
||||
LEFT_MOUSE_BUTTON,
|
||||
RIGHT_MOUSE_BUTTON,
|
||||
CENTER_MOUSE_BUTTON,
|
||||
};
|
||||
|
||||
struct KeyEvent
|
||||
{
|
||||
WPARAM m_Param;
|
||||
USHORT m_ScanCode;
|
||||
KeyEventFlag m_Flags;
|
||||
};
|
||||
|
||||
struct InputState
|
||||
{
|
||||
InputState()
|
||||
{
|
||||
};
|
||||
|
||||
InputState(bool val)
|
||||
{
|
||||
m_State = val;
|
||||
};
|
||||
|
||||
InputState(float val)
|
||||
{
|
||||
m_Value = val;
|
||||
};
|
||||
|
||||
union
|
||||
{
|
||||
bool m_State;
|
||||
float m_Value;
|
||||
};
|
||||
};
|
||||
|
||||
WindowsSampleUserInput();
|
||||
~WindowsSampleUserInput();
|
||||
|
||||
bool keyCodeToASCII( WindowsSampleUserInputIds code, char& c )
|
||||
{
|
||||
if( code >= KEY_A && code <= KEY_Z )
|
||||
{
|
||||
c = (char)code + 'A' - 1;
|
||||
}
|
||||
else if( code >= KEY_0 && code <= KEY_9 )
|
||||
{
|
||||
c = (char)code + '0' - 1;
|
||||
}
|
||||
else if( code == KEY_SPACE )
|
||||
{
|
||||
c = ' ';
|
||||
}
|
||||
else
|
||||
{
|
||||
return false;
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
void doOnMouseMove(physx::PxU32 x, physx::PxU32 y, physx::PxReal dx, physx::PxReal dy, WindowsSampleUserInputIds button);
|
||||
void doOnMouseButton(physx::PxU32 x, physx::PxU32 y, MouseButtons button, bool down);
|
||||
void onKeyDownEx(WPARAM wParam);
|
||||
void onKeyDown(WPARAM wParam, LPARAM lParam);
|
||||
void onKeyUp(WPARAM wParam, LPARAM lParam);
|
||||
void onKeyEvent(const KeyEvent& keyEvent);
|
||||
|
||||
void onGamepadButton(physx::PxU32 buttonIndex, bool buttonDown);
|
||||
void onGamepadAnalogButton(physx::PxU32 buttonIndex,const BYTE oldValue,const BYTE newValue);
|
||||
void onGamepadAxis(physx::PxU32 axis, physx::PxReal val);
|
||||
|
||||
virtual void updateInput();
|
||||
virtual void processGamepads();
|
||||
|
||||
virtual void shutdown();
|
||||
|
||||
virtual bool keyboardSupported() const { return true; }
|
||||
virtual bool gamepadSupported() const;
|
||||
virtual bool mouseSupported() const { return true; }
|
||||
virtual InputType getInputType(const UserInput&) const;
|
||||
|
||||
virtual bool getDigitalInputEventState(physx::PxU16 inputEventId ) const;
|
||||
virtual float getAnalogInputEventState(physx::PxU16 inputEventId ) const;
|
||||
|
||||
protected:
|
||||
WindowsSampleUserInputIds getKeyCode(WPARAM wParam) const;
|
||||
SampleUserInput::KeyCode getSampleUserInputKeyCode(WPARAM wParam) const;
|
||||
|
||||
const UserInput* getUserInputFromId(WindowsSampleUserInputIds id) const;
|
||||
|
||||
bool hasXInput() const { return mpXInputGetState && mpXInputGetCapabilities; }
|
||||
|
||||
std::map<physx::PxU16, physx::PxU16> mScanCodesMap;
|
||||
std::map<physx::PxU16,float> mAnalogStates;
|
||||
std::map<physx::PxU16,bool> mDigitalStates;
|
||||
|
||||
bool mGamePadConnected;
|
||||
physx::PxU32 mConnectedPad;
|
||||
|
||||
typedef DWORD (WINAPI *LPXINPUTGETSTATE)(DWORD, XINPUT_STATE*);
|
||||
typedef DWORD (WINAPI *LPXINPUTGETCAPABILITIES)(DWORD,DWORD,XINPUT_CAPABILITIES*);
|
||||
|
||||
HMODULE mXInputLibrary;
|
||||
LPXINPUTGETSTATE mpXInputGetState;
|
||||
LPXINPUTGETCAPABILITIES mpXInputGetCapabilities;
|
||||
};
|
||||
}
|
||||
|
||||
#endif
|
||||
@ -0,0 +1,178 @@
|
||||
//
|
||||
// Redistribution and use in source and binary forms, with or without
|
||||
// modification, are permitted provided that the following conditions
|
||||
// are met:
|
||||
// * Redistributions of source code must retain the above copyright
|
||||
// notice, this list of conditions and the following disclaimer.
|
||||
// * Redistributions in binary form must reproduce the above copyright
|
||||
// notice, this list of conditions and the following disclaimer in the
|
||||
// documentation and/or other materials provided with the distribution.
|
||||
// * Neither the name of NVIDIA CORPORATION nor the names of its
|
||||
// contributors may be used to endorse or promote products derived
|
||||
// from this software without specific prior written permission.
|
||||
//
|
||||
// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS ''AS IS'' AND ANY
|
||||
// EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
|
||||
// IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
|
||||
// PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR
|
||||
// CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
|
||||
// EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
|
||||
// PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
|
||||
// PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY
|
||||
// OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
|
||||
// (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
|
||||
// OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||
//
|
||||
// Copyright (c) 2008-2021 NVIDIA Corporation. All rights reserved.
|
||||
|
||||
#ifndef WINDOWS_SAMPLE_USER_INPUT_IDS_H
|
||||
#define WINDOWS_SAMPLE_USER_INPUT_IDS_H
|
||||
|
||||
|
||||
namespace SampleFramework
|
||||
{
|
||||
enum WindowsSampleUserInputIds
|
||||
{
|
||||
WKEY_UNKNOWN = 0,
|
||||
|
||||
WKEY_DEFINITION_START,
|
||||
|
||||
WKEY_A,
|
||||
WKEY_B,
|
||||
WKEY_C,
|
||||
WKEY_D,
|
||||
WKEY_E,
|
||||
WKEY_F,
|
||||
WKEY_G,
|
||||
WKEY_H,
|
||||
WKEY_I,
|
||||
WKEY_J,
|
||||
WKEY_K,
|
||||
WKEY_L,
|
||||
WKEY_M,
|
||||
WKEY_N,
|
||||
WKEY_O,
|
||||
WKEY_P,
|
||||
WKEY_Q,
|
||||
WKEY_R,
|
||||
WKEY_S,
|
||||
WKEY_T,
|
||||
WKEY_U,
|
||||
WKEY_V,
|
||||
WKEY_W,
|
||||
WKEY_X,
|
||||
WKEY_Y,
|
||||
WKEY_Z,
|
||||
|
||||
WKEY_0,
|
||||
WKEY_1,
|
||||
WKEY_2,
|
||||
WKEY_3,
|
||||
WKEY_4,
|
||||
WKEY_5,
|
||||
WKEY_6,
|
||||
WKEY_7,
|
||||
WKEY_8,
|
||||
WKEY_9,
|
||||
|
||||
WKEY_SPACE,
|
||||
WKEY_RETURN,
|
||||
WKEY_SHIFT,
|
||||
WKEY_CONTROL,
|
||||
WKEY_ESCAPE,
|
||||
WKEY_COMMA,
|
||||
WKEY_NUMPAD0,
|
||||
WKEY_NUMPAD1,
|
||||
WKEY_NUMPAD2,
|
||||
WKEY_NUMPAD3,
|
||||
WKEY_NUMPAD4,
|
||||
WKEY_NUMPAD5,
|
||||
WKEY_NUMPAD6,
|
||||
WKEY_NUMPAD7,
|
||||
WKEY_NUMPAD8,
|
||||
WKEY_NUMPAD9,
|
||||
WKEY_MULTIPLY,
|
||||
WKEY_ADD,
|
||||
WKEY_SEPARATOR,
|
||||
WKEY_SUBTRACT,
|
||||
WKEY_DECIMAL,
|
||||
WKEY_DIVIDE,
|
||||
|
||||
WKEY_F1,
|
||||
WKEY_F2,
|
||||
WKEY_F3,
|
||||
WKEY_F4,
|
||||
WKEY_F5,
|
||||
WKEY_F6,
|
||||
WKEY_F7,
|
||||
WKEY_F8,
|
||||
WKEY_F9,
|
||||
WKEY_F10,
|
||||
WKEY_F11,
|
||||
WKEY_F12,
|
||||
|
||||
WKEY_TAB,
|
||||
WKEY_BACKSPACE,
|
||||
WKEY_PRIOR,
|
||||
WKEY_NEXT,
|
||||
WKEY_UP,
|
||||
WKEY_DOWN,
|
||||
WKEY_LEFT,
|
||||
WKEY_RIGHT,
|
||||
|
||||
SCAN_CODE_UP ,
|
||||
SCAN_CODE_DOWN ,
|
||||
SCAN_CODE_LEFT,
|
||||
SCAN_CODE_RIGHT,
|
||||
SCAN_CODE_FORWARD,
|
||||
SCAN_CODE_BACKWARD,
|
||||
SCAN_CODE_LEFT_SHIFT,
|
||||
SCAN_CODE_SPACE,
|
||||
SCAN_CODE_L,
|
||||
SCAN_CODE_9,
|
||||
SCAN_CODE_0,
|
||||
|
||||
WKEY_DEFINITION_END,
|
||||
|
||||
MOUSE_DEFINITION_START,
|
||||
|
||||
MOUSE_BUTTON_LEFT,
|
||||
MOUSE_BUTTON_RIGHT,
|
||||
MOUSE_BUTTON_CENTER,
|
||||
|
||||
MOUSE_MOVE,
|
||||
|
||||
MOUSE_DEFINITION_END,
|
||||
|
||||
GAMEPAD_DEFINITION_START,
|
||||
|
||||
GAMEPAD_DIGI_UP,
|
||||
GAMEPAD_DIGI_DOWN,
|
||||
GAMEPAD_DIGI_LEFT,
|
||||
GAMEPAD_DIGI_RIGHT,
|
||||
GAMEPAD_START,
|
||||
GAMEPAD_SELECT,
|
||||
GAMEPAD_LEFT_STICK,
|
||||
GAMEPAD_RIGHT_STICK,
|
||||
GAMEPAD_NORTH,
|
||||
GAMEPAD_SOUTH,
|
||||
GAMEPAD_WEST,
|
||||
GAMEPAD_EAST,
|
||||
GAMEPAD_LEFT_SHOULDER_TOP,
|
||||
GAMEPAD_RIGHT_SHOULDER_TOP,
|
||||
GAMEPAD_LEFT_SHOULDER_BOT,
|
||||
GAMEPAD_RIGHT_SHOULDER_BOT,
|
||||
|
||||
GAMEPAD_RIGHT_STICK_X,
|
||||
GAMEPAD_RIGHT_STICK_Y,
|
||||
GAMEPAD_LEFT_STICK_X ,
|
||||
GAMEPAD_LEFT_STICK_Y ,
|
||||
|
||||
GAMEPAD_DEFINITION_END,
|
||||
|
||||
NUM_KEY_CODES,
|
||||
};
|
||||
|
||||
}
|
||||
|
||||
#endif
|
||||
Reference in New Issue
Block a user