Merge branch 'master' of github.com:teamfisk/AgileBreakOut into Tobias

This commit is contained in:
tleety
2015-10-20 15:57:40 +02:00
112 changed files with 11634 additions and 4179 deletions
+12 -2
View File
@@ -2,10 +2,8 @@ cmake_minimum_required(VERSION 3.0)
project(daydream)
set(CMAKE_MODULE_PATH ${CMAKE_MODULE_PATH} ${CMAKE_CURRENT_SOURCE_DIR}/cmake)
set(CMAKE_INCLUDE_PATH ${CMAKE_INCLUDE_PATH} "${PROJECT_SOURCE_DIR}/deps/include")
if(MINGW)
set(CMAKE_LIBRARY_PATH ${CMAKE_LIBRARY_PATH} "${PROJECT_SOURCE_DIR}/deps/lib/mingw/x64")
elseif(MSVC)
@@ -25,6 +23,18 @@ endif()
set(BUILD_SHARED_LIBS FALSE)
include_directories(${PROJECT_SOURCE_DIR}/include)
option(BUILD_RENDERER_OPENGL "Build with OpenGL 4.4 renderer" ON)
option(BUILD_RENDERER_DIRECTX "Build with DirectX 11 renderer" OFF)
# Compiling for OpenGL target
if(BUILD_RENDERER_OPENGL)
include_directories(${PROJECT_SOURCE_DIR}/include/Rendering/OpenGL)
endif()
# Compiling for DirectX target
if(BUILD_RENDERER_DIRECTX)
add_definitions(-DBUILD_RENDERER_DIRECTX)
include_directories(${PROJECT_SOURCE_DIR}/include/Rendering/DirectX)
endif()
#set(GLEW_INCLUDE_DIR ${daydream_SOURCE_DIR}/libs/glew-1.11.0/include)
#set(GLEW_LIBRARY ${daydream_SOURCE_DIR}/libs/glew-1.11.0/lib/Release/glew32.lib)
-12
View File
@@ -1,12 +0,0 @@
# Blender MTL File: 'submarine.blend'
# Material Count: 1
newmtl Material
Ns 96.078431
Ka 0.000000 0.000000 0.000000
Kd 0.640000 0.640000 0.640000
Ks 0.500000 0.500000 0.500000
Ni 1.000000
d 1.000000
illum 2
map_Kd SubmarineTexture.png
File diff suppressed because it is too large Load Diff
-12
View File
@@ -1,12 +0,0 @@
# Blender MTL File: 'submarine.blend'
# Material Count: 1
newmtl Material
Ns 96.078431
Ka 0.000000 0.000000 0.000000
Kd 0.640000 0.640000 0.640000
Ks 0.500000 0.500000 0.500000
Ni 1.000000
d 1.000000
illum 2
map_Kd SubmarineTexture.png
File diff suppressed because it is too large Load Diff
Binary file not shown.

Before

Width:  |  Height:  |  Size: 736 KiB

+716
View File
@@ -0,0 +1,716 @@
//--------------------------------------------------------------------------------------
// File: Audio.h
//
// DirectXTK for Audio header
//
// THIS CODE AND INFORMATION IS PROVIDED "AS IS" WITHOUT WARRANTY OF
// ANY KIND, EITHER EXPRESSED OR IMPLIED, INCLUDING BUT NOT LIMITED TO
// THE IMPLIED WARRANTIES OF MERCHANTABILITY AND/OR FITNESS FOR A
// PARTICULAR PURPOSE.
//
// Copyright (c) Microsoft Corporation. All rights reserved.
//
// http://go.microsoft.com/fwlink/?LinkId=248929
//--------------------------------------------------------------------------------------
#pragma once
#include <objbase.h>
#include <mmreg.h>
#include <audioclient.h>
#if defined(_XBOX_ONE) && defined(_TITLE)
#include <xma2defs.h>
#pragma comment(lib,"acphal.lib")
#endif
#if defined(WINAPI_FAMILY) && WINAPI_FAMILY == WINAPI_FAMILY_PHONE_APP
#pragma comment(lib,"PhoneAudioSes.lib")
#endif
#ifndef XAUDIO2_HELPER_FUNCTIONS
#define XAUDIO2_HELPER_FUNCTIONS
#endif
#if (_WIN32_WINNT >= 0x0602 /*_WIN32_WINNT_WIN8*/)
#if defined(_MSC_VER) && (_MSC_VER < 1700)
#error DirectX Tool Kit for Audio does not support VS 2010 without the DirectX SDK
#endif
#include <xaudio2.h>
#include <xaudio2fx.h>
#include <x3daudio.h>
#include <xapofx.h>
#pragma comment(lib,"xaudio2.lib")
#else
// Using XAudio 2.7 requires the DirectX SDK
#include <C:\Program Files (x86)\Microsoft DirectX SDK (June 2010)\Include\comdecl.h>
#include <C:\Program Files (x86)\Microsoft DirectX SDK (June 2010)\Include\xaudio2.h>
#include <C:\Program Files (x86)\Microsoft DirectX SDK (June 2010)\Include\xaudio2fx.h>
#include <C:\Program Files (x86)\Microsoft DirectX SDK (June 2010)\Include\xapofx.h>
#pragma warning(push)
#pragma warning( disable : 4005 )
#include <C:\Program Files (x86)\Microsoft DirectX SDK (June 2010)\Include\x3daudio.h>
#pragma warning(pop)
#pragma comment(lib,"x3daudio.lib")
#pragma comment(lib,"xapofx.lib")
#endif
#include <DirectXMath.h>
#pragma warning(push)
#pragma warning(disable : 4005)
#include <stdint.h>
#pragma warning(pop)
#include <functional>
#include <memory>
#include <string>
#include <vector>
// VS 2010 doesn't support explicit calling convention for std::function
#ifndef DIRECTX_STD_CALLCONV
#if defined(_MSC_VER) && (_MSC_VER < 1700)
#define DIRECTX_STD_CALLCONV
#else
#define DIRECTX_STD_CALLCONV __cdecl
#endif
#endif
// VS 2010/2012 do not support =default =delete
#ifndef DIRECTX_CTOR_DEFAULT
#if defined(_MSC_VER) && (_MSC_VER < 1800)
#define DIRECTX_CTOR_DEFAULT {}
#define DIRECTX_CTOR_DELETE ;
#else
#define DIRECTX_CTOR_DEFAULT =default;
#define DIRECTX_CTOR_DELETE =delete;
#endif
#endif
#pragma warning(push)
#pragma warning(disable : 4481)
// VS 2010 considers 'override' to be a extension, but it's part of C++11 as of VS 2012
namespace DirectX
{
#if (DIRECTX_MATH_VERSION < 305) && !defined(XM_CALLCONV)
#define XM_CALLCONV __fastcall
typedef const XMVECTOR& HXMVECTOR;
typedef const XMMATRIX& FXMMATRIX;
#endif
class SoundEffectInstance;
//----------------------------------------------------------------------------------
struct AudioStatistics
{
size_t playingOneShots; // Number of one-shot sounds currently playing
size_t playingInstances; // Number of sound effect instances currently playing
size_t allocatedInstances; // Number of SoundEffectInstance allocated
size_t allocatedVoices; // Number of XAudio2 voices allocated (standard, 3D, one-shots, and idle one-shots)
size_t allocatedVoices3d; // Number of XAudio2 voices allocated for 3D
size_t allocatedVoicesOneShot; // Number of XAudio2 voices allocated for one-shot sounds
size_t allocatedVoicesIdle; // Number of XAudio2 voices allocated for one-shot sounds but not currently in use
size_t audioBytes; // Total wave data (in bytes) in SoundEffects and in-memory WaveBanks
#if defined(_XBOX_ONE) && defined(_TITLE)
size_t xmaAudioBytes; // Total wave data (in bytes) in SoundEffects and in-memory WaveBanks allocated with ApuAlloc
#endif
};
//----------------------------------------------------------------------------------
class IVoiceNotify
{
public:
virtual void __cdecl OnBufferEnd() = 0;
// Notfication that a voice buffer has finished
// Note this is called from XAudio2's worker thread, so it should perform very minimal and thread-safe operations
virtual void __cdecl OnCriticalError() = 0;
// Notification that the audio engine encountered a critical error
virtual void __cdecl OnReset() = 0;
// Notification of an audio engine reset
virtual void __cdecl OnUpdate() = 0;
// Notification of an audio engine per-frame update (opt-in)
virtual void __cdecl OnDestroyEngine() = 0;
// Notification that the audio engine is being destroyed
virtual void __cdecl OnTrim() = 0;
// Notification of a request to trim the voice pool
virtual void __cdecl GatherStatistics( AudioStatistics& stats ) const = 0;
// Contribute to statistics request
};
//----------------------------------------------------------------------------------
enum AUDIO_ENGINE_FLAGS
{
AudioEngine_Default = 0x0,
AudioEngine_EnvironmentalReverb = 0x1,
AudioEngine_ReverbUseFilters = 0x2,
AudioEngine_UseMasteringLimiter = 0x4,
AudioEngine_Debug = 0x10000,
AudioEngine_ThrowOnNoAudioHW = 0x20000,
AudioEngine_DisableVoiceReuse = 0x40000,
};
inline AUDIO_ENGINE_FLAGS operator|(AUDIO_ENGINE_FLAGS a, AUDIO_ENGINE_FLAGS b) { return static_cast<AUDIO_ENGINE_FLAGS>( static_cast<int>(a) | static_cast<int>(b) ); }
enum SOUND_EFFECT_INSTANCE_FLAGS
{
SoundEffectInstance_Default = 0x0,
SoundEffectInstance_Use3D = 0x1,
SoundEffectInstance_ReverbUseFilters = 0x2,
SoundEffectInstance_NoSetPitch = 0x4,
SoundEffectInstance_UseRedirectLFE = 0x10000,
};
inline SOUND_EFFECT_INSTANCE_FLAGS operator|(SOUND_EFFECT_INSTANCE_FLAGS a, SOUND_EFFECT_INSTANCE_FLAGS b) { return static_cast<SOUND_EFFECT_INSTANCE_FLAGS>( static_cast<int>(a) | static_cast<int>(b) ); }
enum AUDIO_ENGINE_REVERB
{
Reverb_Off,
Reverb_Default,
Reverb_Generic,
Reverb_Forest,
Reverb_PaddedCell,
Reverb_Room,
Reverb_Bathroom,
Reverb_LivingRoom,
Reverb_StoneRoom,
Reverb_Auditorium,
Reverb_ConcertHall,
Reverb_Cave,
Reverb_Arena,
Reverb_Hangar,
Reverb_CarpetedHallway,
Reverb_Hallway,
Reverb_StoneCorridor,
Reverb_Alley,
Reverb_City,
Reverb_Mountains,
Reverb_Quarry,
Reverb_Plain,
Reverb_ParkingLot,
Reverb_SewerPipe,
Reverb_Underwater,
Reverb_SmallRoom,
Reverb_MediumRoom,
Reverb_LargeRoom,
Reverb_MediumHall,
Reverb_LargeHall,
Reverb_Plate,
Reverb_MAX
};
enum SoundState
{
STOPPED = 0,
PLAYING,
PAUSED
};
//----------------------------------------------------------------------------------
class AudioEngine
{
public:
explicit AudioEngine( AUDIO_ENGINE_FLAGS flags = AudioEngine_Default, _In_opt_ const WAVEFORMATEX* wfx = nullptr, _In_opt_z_ const wchar_t* deviceId = nullptr,
AUDIO_STREAM_CATEGORY category = AudioCategory_GameEffects );
AudioEngine(AudioEngine&& moveFrom);
AudioEngine& operator= (AudioEngine&& moveFrom);
virtual ~AudioEngine();
bool __cdecl Update();
// Performs per-frame processing for the audio engine, returns false if in 'silent mode'
bool __cdecl Reset( _In_opt_ const WAVEFORMATEX* wfx = nullptr, _In_opt_z_ const wchar_t* deviceId = nullptr );
// Reset audio engine from critical error/silent mode using a new device; can also 'migrate' the graph
// Returns true if succesfully reset, false if in 'silent mode' due to no default device
// Note: One shots are lost, all SoundEffectInstances are in the STOPPED state after successful reset
void __cdecl Suspend();
void __cdecl Resume();
// Suspend/resumes audio processing (i.e. global pause/resume)
float __cdecl GetMasterVolume() const;
void __cdecl SetMasterVolume( float volume );
// Master volume property for all sounds
void __cdecl SetReverb( AUDIO_ENGINE_REVERB reverb );
void __cdecl SetReverb( _In_opt_ const XAUDIO2FX_REVERB_PARAMETERS* native );
// Sets environmental reverb for 3D positional audio (if active)
void __cdecl SetMasteringLimit( int release, int loudness );
// Sets the mastering volume limiter properties (if active)
AudioStatistics __cdecl GetStatistics() const;
// Gathers audio engine statistics
WAVEFORMATEXTENSIBLE __cdecl GetOutputFormat() const;
// Returns the format consumed by the mastering voice (which is the same as the device output if defaults are used)
uint32_t __cdecl GetChannelMask() const;
// Returns the output channel mask
int __cdecl GetOutputChannels() const;
// Returns the number of output channels
bool __cdecl IsAudioDevicePresent() const;
// Returns true if the audio graph is operating normally, false if in 'silent mode'
bool __cdecl IsCriticalError() const;
// Returns true if the audio graph is halted due to a critical error (which also places the engine into 'silent mode')
// Voice pool management.
void __cdecl SetDefaultSampleRate( int sampleRate );
// Sample rate for voices in the reuse pool (defaults to 44100)
void __cdecl SetMaxVoicePool( size_t maxOneShots, size_t maxInstances );
// Maximum number of voices to allocate for one-shots and instances
// Note: one-shots over this limit are ignored; too many instance voices throws an exception
void __cdecl TrimVoicePool();
// Releases any currently unused voices
// Internal-use functions
void __cdecl AllocateVoice( _In_ const WAVEFORMATEX* wfx, SOUND_EFFECT_INSTANCE_FLAGS flags, bool oneshot, _Outptr_result_maybenull_ IXAudio2SourceVoice** voice );
void __cdecl DestroyVoice( _In_ IXAudio2SourceVoice* voice );
// Should only be called for instance voices, not one-shots
void __cdecl RegisterNotify( _In_ IVoiceNotify* notify, bool usesUpdate );
void __cdecl UnregisterNotify( _In_ IVoiceNotify* notify, bool usesOneShots, bool usesUpdate );
// XAudio2 interface access
IXAudio2* __cdecl GetInterface() const;
IXAudio2MasteringVoice* __cdecl GetMasterVoice() const;
IXAudio2SubmixVoice* __cdecl GetReverbVoice() const;
X3DAUDIO_HANDLE& __cdecl Get3DHandle() const;
// Static functions
struct RendererDetail
{
std::wstring deviceId;
std::wstring description;
};
static std::vector<RendererDetail> __cdecl GetRendererDetails();
// Returns a list of valid audio endpoint devices
private:
// Private implementation.
class Impl;
std::unique_ptr<Impl> pImpl;
// Prevent copying.
AudioEngine(AudioEngine const&) DIRECTX_CTOR_DELETE
AudioEngine& operator= (AudioEngine const&) DIRECTX_CTOR_DELETE
};
//----------------------------------------------------------------------------------
class WaveBank
{
public:
WaveBank( _In_ AudioEngine* engine, _In_z_ const wchar_t* wbFileName );
WaveBank(WaveBank&& moveFrom);
WaveBank& operator= (WaveBank&& moveFrom);
virtual ~WaveBank();
void __cdecl Play( int index );
void __cdecl Play( int index, float volume, float pitch, float pan );
void __cdecl Play( _In_z_ const char* name );
void __cdecl Play( _In_z_ const char* name, float volume, float pitch, float pan );
std::unique_ptr<SoundEffectInstance> __cdecl CreateInstance( int index, SOUND_EFFECT_INSTANCE_FLAGS flags = SoundEffectInstance_Default );
std::unique_ptr<SoundEffectInstance> __cdecl CreateInstance( _In_z_ const char* name, SOUND_EFFECT_INSTANCE_FLAGS flags = SoundEffectInstance_Default );
bool __cdecl IsPrepared() const;
bool __cdecl IsInUse() const;
bool __cdecl IsStreamingBank() const;
size_t __cdecl GetSampleSizeInBytes( int index ) const;
// Returns size of wave audio data
size_t __cdecl GetSampleDuration( int index ) const;
// Returns the duration in samples
size_t __cdecl GetSampleDurationMS( int index ) const;
// Returns the duration in milliseconds
const WAVEFORMATEX* __cdecl GetFormat( int index, _Out_writes_bytes_(maxsize) WAVEFORMATEX* wfx, size_t maxsize ) const;
int __cdecl Find( _In_z_ const char* name ) const;
#if defined(_XBOX_ONE) || (_WIN32_WINNT < _WIN32_WINNT_WIN8) || (_WIN32_WINNT >= 0x0A00 /*_WIN32_WINNT_WIN10*/ )
bool __cdecl FillSubmitBuffer( int index, _Out_ XAUDIO2_BUFFER& buffer, _Out_ XAUDIO2_BUFFER_WMA& wmaBuffer ) const;
#else
void __cdecl FillSubmitBuffer( int index, _Out_ XAUDIO2_BUFFER& buffer ) const;
#endif
private:
// Private implementation.
class Impl;
std::unique_ptr<Impl> pImpl;
// Prevent copying.
WaveBank(WaveBank const&) DIRECTX_CTOR_DELETE
WaveBank& operator= (WaveBank const&) DIRECTX_CTOR_DELETE
// Private interface
void __cdecl UnregisterInstance( _In_ SoundEffectInstance* instance );
friend class SoundEffectInstance;
};
//----------------------------------------------------------------------------------
class SoundEffect
{
public:
SoundEffect( _In_ AudioEngine* engine, _In_z_ const wchar_t* waveFileName );
SoundEffect( _In_ AudioEngine* engine, _Inout_ std::unique_ptr<uint8_t[]>& wavData,
_In_ const WAVEFORMATEX* wfx, _In_reads_bytes_(audioBytes) const uint8_t* startAudio, size_t audioBytes );
SoundEffect( _In_ AudioEngine* engine, _Inout_ std::unique_ptr<uint8_t[]>& wavData,
_In_ const WAVEFORMATEX* wfx, _In_reads_bytes_(audioBytes) const uint8_t* startAudio, size_t audioBytes,
uint32_t loopStart, uint32_t loopLength );
#if defined(_XBOX_ONE) || (_WIN32_WINNT < _WIN32_WINNT_WIN8) || (_WIN32_WINNT >= 0x0A00 /*_WIN32_WINNT_WIN10*/)
SoundEffect( _In_ AudioEngine* engine, _Inout_ std::unique_ptr<uint8_t[]>& wavData,
_In_ const WAVEFORMATEX* wfx, _In_reads_bytes_(audioBytes) const uint8_t* startAudio, size_t audioBytes,
_In_reads_(seekCount) const uint32_t* seekTable, size_t seekCount );
#endif
SoundEffect(SoundEffect&& moveFrom);
SoundEffect& operator= (SoundEffect&& moveFrom);
virtual ~SoundEffect();
void __cdecl Play();
void __cdecl Play(float volume, float pitch, float pan);
std::unique_ptr<SoundEffectInstance> __cdecl CreateInstance( SOUND_EFFECT_INSTANCE_FLAGS flags = SoundEffectInstance_Default );
bool __cdecl IsInUse() const;
size_t __cdecl GetSampleSizeInBytes() const;
// Returns size of wave audio data
size_t __cdecl GetSampleDuration() const;
// Returns the duration in samples
size_t __cdecl GetSampleDurationMS() const;
// Returns the duration in milliseconds
const WAVEFORMATEX* __cdecl GetFormat() const;
#if defined(_XBOX_ONE) || (_WIN32_WINNT < _WIN32_WINNT_WIN8) || (_WIN32_WINNT >= 0x0A00 /*_WIN32_WINNT_WIN10*/)
bool __cdecl FillSubmitBuffer( _Out_ XAUDIO2_BUFFER& buffer, _Out_ XAUDIO2_BUFFER_WMA& wmaBuffer ) const;
#else
void __cdecl FillSubmitBuffer( _Out_ XAUDIO2_BUFFER& buffer ) const;
#endif
private:
// Private implementation.
class Impl;
std::unique_ptr<Impl> pImpl;
// Prevent copying.
SoundEffect(SoundEffect const&) DIRECTX_CTOR_DELETE
SoundEffect& operator= (SoundEffect const&) DIRECTX_CTOR_DELETE
// Private interface
void __cdecl UnregisterInstance( _In_ SoundEffectInstance* instance );
friend class SoundEffectInstance;
};
//----------------------------------------------------------------------------------
struct AudioListener : public X3DAUDIO_LISTENER
{
AudioListener()
{
memset( this, 0, sizeof(X3DAUDIO_LISTENER) );
OrientFront.z =
OrientTop.y = 1.f;
}
void XM_CALLCONV SetPosition( FXMVECTOR v )
{
XMStoreFloat3( reinterpret_cast<XMFLOAT3*>( &Position ), v );
}
void __cdecl SetPosition( const XMFLOAT3& pos )
{
Position.x = pos.x;
Position.y = pos.y;
Position.z = pos.z;
}
void XM_CALLCONV SetVelocity( FXMVECTOR v )
{
XMStoreFloat3( reinterpret_cast<XMFLOAT3*>( &Velocity ), v );
}
void __cdecl SetVelocity( const XMFLOAT3& vel )
{
Velocity.x = vel.x;
Velocity.y = vel.y;
Velocity.z = vel.z;
}
void XM_CALLCONV SetOrientation( FXMVECTOR forward, FXMVECTOR up )
{
XMStoreFloat3( reinterpret_cast<XMFLOAT3*>( &OrientFront ), forward );
XMStoreFloat3( reinterpret_cast<XMFLOAT3*>( &OrientTop ), up );
}
void __cdecl SetOrientation( const XMFLOAT3& forward, const XMFLOAT3& up )
{
OrientFront.x = forward.x; OrientTop.x = up.x;
OrientFront.y = forward.y; OrientTop.y = up.y;
OrientFront.z = forward.z; OrientTop.z = up.z;
}
void XM_CALLCONV SetOrientationFromQuaternion( FXMVECTOR quat )
{
XMVECTOR forward = XMVector3Rotate( g_XMIdentityR2, quat );
XMStoreFloat3( reinterpret_cast<XMFLOAT3*>( &OrientFront ), forward );
XMVECTOR up = XMVector3Rotate( g_XMIdentityR1, quat );
XMStoreFloat3( reinterpret_cast<XMFLOAT3*>( &OrientTop ), up );
}
void XM_CALLCONV Update( FXMVECTOR newPos, XMVECTOR upDir, float dt )
// Updates velocity and orientation by tracking changes in position over time...
{
if ( dt > 0.f )
{
XMVECTOR lastPos = XMLoadFloat3( reinterpret_cast<const XMFLOAT3*>( &Position ) );
XMVECTOR vDelta = ( newPos - lastPos );
XMVECTOR v = vDelta / dt;
XMStoreFloat3( reinterpret_cast<XMFLOAT3*>( &Velocity ), v );
vDelta = XMVector3Normalize( vDelta );
XMStoreFloat3( reinterpret_cast<XMFLOAT3*>( &OrientFront ), vDelta );
v = XMVector3Cross( upDir, vDelta );
v = XMVector3Normalize( v );
v = XMVector3Cross( vDelta, v );
v = XMVector3Normalize( v );
XMStoreFloat3( reinterpret_cast<XMFLOAT3*>( &OrientTop ), v );
XMStoreFloat3( reinterpret_cast<XMFLOAT3*>( &Position ), newPos );
}
}
};
//----------------------------------------------------------------------------------
struct AudioEmitter : public X3DAUDIO_EMITTER
{
float EmitterAzimuths[XAUDIO2_MAX_AUDIO_CHANNELS];
AudioEmitter()
{
memset( this, 0, sizeof(X3DAUDIO_EMITTER) );
memset( EmitterAzimuths, 0, sizeof(EmitterAzimuths) );
OrientFront.z =
OrientTop.y =
ChannelRadius =
CurveDistanceScaler =
DopplerScaler = 1.f;
ChannelCount = 1;
pChannelAzimuths = EmitterAzimuths;
InnerRadiusAngle = X3DAUDIO_PI / 4.0f;
}
void XM_CALLCONV SetPosition( FXMVECTOR v )
{
XMStoreFloat3( reinterpret_cast<XMFLOAT3*>( &Position ), v );
}
void __cdecl SetPosition( const XMFLOAT3& pos )
{
Position.x = pos.x;
Position.y = pos.y;
Position.z = pos.z;
}
void XM_CALLCONV SetVelocity( FXMVECTOR v )
{
XMStoreFloat3( reinterpret_cast<XMFLOAT3*>( &Velocity ), v );
}
void __cdecl SetVelocity( const XMFLOAT3& vel )
{
Velocity.x = vel.x;
Velocity.y = vel.y;
Velocity.z = vel.z;
}
void XM_CALLCONV SetOrientation( FXMVECTOR forward, FXMVECTOR up )
{
XMStoreFloat3( reinterpret_cast<XMFLOAT3*>( &OrientFront ), forward );
XMStoreFloat3( reinterpret_cast<XMFLOAT3*>( &OrientTop ), up );
}
void __cdecl SetOrientation( const XMFLOAT3& forward, const XMFLOAT3& up )
{
OrientFront.x = forward.x; OrientTop.x = up.x;
OrientFront.y = forward.y; OrientTop.y = up.y;
OrientFront.z = forward.z; OrientTop.z = up.z;
}
void XM_CALLCONV SetOrientationFromQuaternion( FXMVECTOR quat )
{
XMVECTOR forward = XMVector3Rotate( g_XMIdentityR2, quat );
XMStoreFloat3( reinterpret_cast<XMFLOAT3*>( &OrientFront ), forward );
XMVECTOR up = XMVector3Rotate( g_XMIdentityR1, quat );
XMStoreFloat3( reinterpret_cast<XMFLOAT3*>( &OrientTop ), up );
}
void XM_CALLCONV Update( FXMVECTOR newPos, XMVECTOR upDir, float dt )
// Updates velocity and orientation by tracking changes in position over time...
{
if ( dt > 0.f )
{
XMVECTOR lastPos = XMLoadFloat3( reinterpret_cast<const XMFLOAT3*>( &Position ) );
XMVECTOR vDelta = ( newPos - lastPos );
XMVECTOR v = vDelta / dt;
XMStoreFloat3( reinterpret_cast<XMFLOAT3*>( &Velocity ), v );
vDelta = XMVector3Normalize( vDelta );
XMStoreFloat3( reinterpret_cast<XMFLOAT3*>( &OrientFront ), vDelta );
v = XMVector3Cross( upDir, vDelta );
v = XMVector3Normalize( v );
v = XMVector3Cross( vDelta, v );
v = XMVector3Normalize( v );
XMStoreFloat3( reinterpret_cast<XMFLOAT3*>( &OrientTop ), v );
XMStoreFloat3( reinterpret_cast<XMFLOAT3*>( &Position ), newPos );
}
}
};
//----------------------------------------------------------------------------------
class SoundEffectInstance
{
public:
SoundEffectInstance(SoundEffectInstance&& moveFrom);
SoundEffectInstance& operator= (SoundEffectInstance&& moveFrom);
virtual ~SoundEffectInstance();
void __cdecl Play( bool loop = false );
void __cdecl Stop( bool immediate = true );
void __cdecl Pause();
void __cdecl Resume();
void __cdecl SetVolume( float volume );
void __cdecl SetPitch( float pitch );
void __cdecl SetPan( float pan );
void __cdecl Apply3D( const AudioListener& listener, const AudioEmitter& emitter );
bool __cdecl IsLooped() const;
SoundState __cdecl GetState();
// Notifications.
void __cdecl OnDestroyParent();
private:
// Private implementation.
class Impl;
std::unique_ptr<Impl> pImpl;
// Private constructors
SoundEffectInstance( _In_ AudioEngine* engine, _In_ SoundEffect* effect, SOUND_EFFECT_INSTANCE_FLAGS flags );
SoundEffectInstance( _In_ AudioEngine* engine, _In_ WaveBank* effect, int index, SOUND_EFFECT_INSTANCE_FLAGS flags );
friend std::unique_ptr<SoundEffectInstance> __cdecl SoundEffect::CreateInstance( SOUND_EFFECT_INSTANCE_FLAGS );
friend std::unique_ptr<SoundEffectInstance> __cdecl WaveBank::CreateInstance( int, SOUND_EFFECT_INSTANCE_FLAGS );
// Prevent copying.
SoundEffectInstance(SoundEffectInstance const&) DIRECTX_CTOR_DELETE
SoundEffectInstance& operator= (SoundEffectInstance const&) DIRECTX_CTOR_DELETE
};
//----------------------------------------------------------------------------------
class DynamicSoundEffectInstance
{
public:
DynamicSoundEffectInstance( _In_ AudioEngine* engine,
_In_opt_ std::function<void DIRECTX_STD_CALLCONV(DynamicSoundEffectInstance*)> bufferNeeded,
int sampleRate, int channels, int sampleBits = 16,
SOUND_EFFECT_INSTANCE_FLAGS flags = SoundEffectInstance_Default );
DynamicSoundEffectInstance(DynamicSoundEffectInstance&& moveFrom);
DynamicSoundEffectInstance& operator= (DynamicSoundEffectInstance&& moveFrom);
virtual ~DynamicSoundEffectInstance();
void __cdecl Play();
void __cdecl Stop( bool immediate = true );
void __cdecl Pause();
void __cdecl Resume();
void __cdecl SetVolume( float volume );
void __cdecl SetPitch( float pitch );
void __cdecl SetPan( float pan );
void __cdecl Apply3D( const AudioListener& listener, const AudioEmitter& emitter );
void __cdecl SubmitBuffer( _In_reads_bytes_(audioBytes) const uint8_t* pAudioData, size_t audioBytes );
void __cdecl SubmitBuffer( _In_reads_bytes_(audioBytes) const uint8_t* pAudioData, uint32_t offset, size_t audioBytes );
SoundState __cdecl GetState();
size_t __cdecl GetSampleDuration( size_t bytes ) const;
// Returns duration in samples of a buffer of a given size
size_t __cdecl GetSampleDurationMS( size_t bytes ) const;
// Returns duration in milliseconds of a buffer of a given size
size_t __cdecl GetSampleSizeInBytes( uint64_t duration ) const;
// Returns size of a buffer for a duration given in milliseconds
int __cdecl GetPendingBufferCount() const;
const WAVEFORMATEX* __cdecl GetFormat() const;
private:
// Private implementation.
class Impl;
std::unique_ptr<Impl> pImpl;
// Prevent copying.
DynamicSoundEffectInstance(DynamicSoundEffectInstance const&) DIRECTX_CTOR_DELETE
DynamicSoundEffectInstance& operator= (DynamicSoundEffectInstance const&) DIRECTX_CTOR_DELETE
};
}
#pragma warning(pop)
+81
View File
@@ -0,0 +1,81 @@
//--------------------------------------------------------------------------------------
// File: CommonStates.h
//
// THIS CODE AND INFORMATION IS PROVIDED "AS IS" WITHOUT WARRANTY OF
// ANY KIND, EITHER EXPRESSED OR IMPLIED, INCLUDING BUT NOT LIMITED TO
// THE IMPLIED WARRANTIES OF MERCHANTABILITY AND/OR FITNESS FOR A
// PARTICULAR PURPOSE.
//
// Copyright (c) Microsoft Corporation. All rights reserved.
//
// http://go.microsoft.com/fwlink/?LinkId=248929
//--------------------------------------------------------------------------------------
#pragma once
#if defined(_XBOX_ONE) && defined(_TITLE)
#include <d3d11_x.h>
#else
#include <d3d11_1.h>
#endif
// VS 2010/2012 do not support =default =delete
#ifndef DIRECTX_CTOR_DEFAULT
#if defined(_MSC_VER) && (_MSC_VER < 1800)
#define DIRECTX_CTOR_DEFAULT {}
#define DIRECTX_CTOR_DELETE ;
#else
#define DIRECTX_CTOR_DEFAULT =default;
#define DIRECTX_CTOR_DELETE =delete;
#endif
#endif
#include <memory>
namespace DirectX
{
class CommonStates
{
public:
explicit CommonStates(_In_ ID3D11Device* device);
CommonStates(CommonStates&& moveFrom);
CommonStates& operator= (CommonStates&& moveFrom);
virtual ~CommonStates();
// Blend states.
ID3D11BlendState* __cdecl Opaque() const;
ID3D11BlendState* __cdecl AlphaBlend() const;
ID3D11BlendState* __cdecl Additive() const;
ID3D11BlendState* __cdecl NonPremultiplied() const;
// Depth stencil states.
ID3D11DepthStencilState* __cdecl DepthNone() const;
ID3D11DepthStencilState* __cdecl DepthDefault() const;
ID3D11DepthStencilState* __cdecl DepthRead() const;
// Rasterizer states.
ID3D11RasterizerState* __cdecl CullNone() const;
ID3D11RasterizerState* __cdecl CullClockwise() const;
ID3D11RasterizerState* __cdecl CullCounterClockwise() const;
ID3D11RasterizerState* __cdecl Wireframe() const;
// Sampler states.
ID3D11SamplerState* __cdecl PointWrap() const;
ID3D11SamplerState* __cdecl PointClamp() const;
ID3D11SamplerState* __cdecl LinearWrap() const;
ID3D11SamplerState* __cdecl LinearClamp() const;
ID3D11SamplerState* __cdecl AnisotropicWrap() const;
ID3D11SamplerState* __cdecl AnisotropicClamp() const;
private:
// Private implementation.
class Impl;
std::shared_ptr<Impl> pImpl;
// Prevent copying.
CommonStates(CommonStates const&) DIRECTX_CTOR_DELETE
CommonStates& operator= (CommonStates const&) DIRECTX_CTOR_DELETE
};
}
+160
View File
@@ -0,0 +1,160 @@
//--------------------------------------------------------------------------------------
// File: DDSTextureLoader.h
//
// Functions for loading a DDS texture and creating a Direct3D 11 runtime resource for it
//
// Note these functions are useful as a light-weight runtime loader for DDS files. For
// a full-featured DDS file reader, writer, and texture processing pipeline see
// the 'Texconv' sample and the 'DirectXTex' library.
//
// THIS CODE AND INFORMATION IS PROVIDED "AS IS" WITHOUT WARRANTY OF
// ANY KIND, EITHER EXPRESSED OR IMPLIED, INCLUDING BUT NOT LIMITED TO
// THE IMPLIED WARRANTIES OF MERCHANTABILITY AND/OR FITNESS FOR A
// PARTICULAR PURPOSE.
//
// Copyright (c) Microsoft Corporation. All rights reserved.
//
// http://go.microsoft.com/fwlink/?LinkId=248926
// http://go.microsoft.com/fwlink/?LinkId=248929
//--------------------------------------------------------------------------------------
#pragma once
#if defined(_XBOX_ONE) && defined(_TITLE)
#include <d3d11_x.h>
#else
#include <d3d11_1.h>
#endif
#pragma warning(push)
#pragma warning(disable : 4005)
#include <stdint.h>
#pragma warning(pop)
namespace DirectX
{
enum DDS_ALPHA_MODE
{
DDS_ALPHA_MODE_UNKNOWN = 0,
DDS_ALPHA_MODE_STRAIGHT = 1,
DDS_ALPHA_MODE_PREMULTIPLIED = 2,
DDS_ALPHA_MODE_OPAQUE = 3,
DDS_ALPHA_MODE_CUSTOM = 4,
};
// Standard version
HRESULT __cdecl CreateDDSTextureFromMemory( _In_ ID3D11Device* d3dDevice,
_In_reads_bytes_(ddsDataSize) const uint8_t* ddsData,
_In_ size_t ddsDataSize,
_Outptr_opt_ ID3D11Resource** texture,
_Outptr_opt_ ID3D11ShaderResourceView** textureView,
_In_ size_t maxsize = 0,
_Out_opt_ DDS_ALPHA_MODE* alphaMode = nullptr
);
HRESULT __cdecl CreateDDSTextureFromFile( _In_ ID3D11Device* d3dDevice,
_In_z_ const wchar_t* szFileName,
_Outptr_opt_ ID3D11Resource** texture,
_Outptr_opt_ ID3D11ShaderResourceView** textureView,
_In_ size_t maxsize = 0,
_Out_opt_ DDS_ALPHA_MODE* alphaMode = nullptr
);
// Standard version with optional auto-gen mipmap support
#if defined(_XBOX_ONE) && defined(_TITLE)
HRESULT __cdecl CreateDDSTextureFromMemory( _In_ ID3D11DeviceX* d3dDevice,
_In_opt_ ID3D11DeviceContextX* d3dContext,
#else
HRESULT __cdecl CreateDDSTextureFromMemory( _In_ ID3D11Device* d3dDevice,
_In_opt_ ID3D11DeviceContext* d3dContext,
#endif
_In_reads_bytes_(ddsDataSize) const uint8_t* ddsData,
_In_ size_t ddsDataSize,
_Outptr_opt_ ID3D11Resource** texture,
_Outptr_opt_ ID3D11ShaderResourceView** textureView,
_In_ size_t maxsize = 0,
_Out_opt_ DDS_ALPHA_MODE* alphaMode = nullptr
);
#if defined(_XBOX_ONE) && defined(_TITLE)
HRESULT __cdecl CreateDDSTextureFromFile( _In_ ID3D11DeviceX* d3dDevice,
_In_opt_ ID3D11DeviceContextX* d3dContext,
#else
HRESULT __cdecl CreateDDSTextureFromFile( _In_ ID3D11Device* d3dDevice,
_In_opt_ ID3D11DeviceContext* d3dContext,
#endif
_In_z_ const wchar_t* szFileName,
_Outptr_opt_ ID3D11Resource** texture,
_Outptr_opt_ ID3D11ShaderResourceView** textureView,
_In_ size_t maxsize = 0,
_Out_opt_ DDS_ALPHA_MODE* alphaMode = nullptr
);
// Extended version
HRESULT __cdecl CreateDDSTextureFromMemoryEx( _In_ ID3D11Device* d3dDevice,
_In_reads_bytes_(ddsDataSize) const uint8_t* ddsData,
_In_ size_t ddsDataSize,
_In_ size_t maxsize,
_In_ D3D11_USAGE usage,
_In_ unsigned int bindFlags,
_In_ unsigned int cpuAccessFlags,
_In_ unsigned int miscFlags,
_In_ bool forceSRGB,
_Outptr_opt_ ID3D11Resource** texture,
_Outptr_opt_ ID3D11ShaderResourceView** textureView,
_Out_opt_ DDS_ALPHA_MODE* alphaMode = nullptr
);
HRESULT __cdecl CreateDDSTextureFromFileEx( _In_ ID3D11Device* d3dDevice,
_In_z_ const wchar_t* szFileName,
_In_ size_t maxsize,
_In_ D3D11_USAGE usage,
_In_ unsigned int bindFlags,
_In_ unsigned int cpuAccessFlags,
_In_ unsigned int miscFlags,
_In_ bool forceSRGB,
_Outptr_opt_ ID3D11Resource** texture,
_Outptr_opt_ ID3D11ShaderResourceView** textureView,
_Out_opt_ DDS_ALPHA_MODE* alphaMode = nullptr
);
// Extended version with optional auto-gen mipmap support
#if defined(_XBOX_ONE) && defined(_TITLE)
HRESULT __cdecl CreateDDSTextureFromMemoryEx( _In_ ID3D11DeviceX* d3dDevice,
_In_opt_ ID3D11DeviceContextX* d3dContext,
#else
HRESULT __cdecl CreateDDSTextureFromMemoryEx( _In_ ID3D11Device* d3dDevice,
_In_opt_ ID3D11DeviceContext* d3dContext,
#endif
_In_reads_bytes_(ddsDataSize) const uint8_t* ddsData,
_In_ size_t ddsDataSize,
_In_ size_t maxsize,
_In_ D3D11_USAGE usage,
_In_ unsigned int bindFlags,
_In_ unsigned int cpuAccessFlags,
_In_ unsigned int miscFlags,
_In_ bool forceSRGB,
_Outptr_opt_ ID3D11Resource** texture,
_Outptr_opt_ ID3D11ShaderResourceView** textureView,
_Out_opt_ DDS_ALPHA_MODE* alphaMode = nullptr
);
#if defined(_XBOX_ONE) && defined(_TITLE)
HRESULT __cdecl CreateDDSTextureFromFileEx( _In_ ID3D11DeviceX* d3dDevice,
_In_opt_ ID3D11DeviceContextX* d3dContext,
#else
HRESULT __cdecl CreateDDSTextureFromFileEx( _In_ ID3D11Device* d3dDevice,
_In_opt_ ID3D11DeviceContext* d3dContext,
#endif
_In_z_ const wchar_t* szFileName,
_In_ size_t maxsize,
_In_ D3D11_USAGE usage,
_In_ unsigned int bindFlags,
_In_ unsigned int cpuAccessFlags,
_In_ unsigned int miscFlags,
_In_ bool forceSRGB,
_Outptr_opt_ ID3D11Resource** texture,
_Outptr_opt_ ID3D11ShaderResourceView** textureView,
_Out_opt_ DDS_ALPHA_MODE* alphaMode = nullptr
);
}
+130
View File
@@ -0,0 +1,130 @@
//--------------------------------------------------------------------------------------
// File: DirectXHelpers.h
//
// THIS CODE AND INFORMATION IS PROVIDED "AS IS" WITHOUT WARRANTY OF
// ANY KIND, EITHER EXPRESSED OR IMPLIED, INCLUDING BUT NOT LIMITED TO
// THE IMPLIED WARRANTIES OF MERCHANTABILITY AND/OR FITNESS FOR A
// PARTICULAR PURPOSE.
//
// Copyright (c) Microsoft Corporation. All rights reserved.
//
// http://go.microsoft.com/fwlink/?LinkId=248929
//--------------------------------------------------------------------------------------
#pragma once
#if defined(_XBOX_ONE) && defined(_TITLE)
#include <d3d11_x.h>
#else
#include <d3d11_1.h>
#endif
#if !defined(NO_D3D11_DEBUG_NAME) && ( defined(_DEBUG) || defined(PROFILE) )
#if !defined(_XBOX_ONE) || !defined(_TITLE)
#pragma comment(lib,"dxguid.lib")
#endif
#endif
#include <exception>
#pragma warning(push)
#pragma warning(disable : 4005)
#include <stdint.h>
#pragma warning(pop)
//
// The core Direct3D headers provide the following helper C++ classes
// CD3D11_RECT
// CD3D11_BOX
// CD3D11_DEPTH_STENCIL_DESC
// CD3D11_BLEND_DESC, CD3D11_BLEND_DESC1
// CD3D11_RASTERIZER_DESC, CD3D11_RASTERIZER_DESC1
// CD3D11_BUFFER_DESC
// CD3D11_TEXTURE1D_DESC
// CD3D11_TEXTURE2D_DESC
// CD3D11_TEXTURE3D_DESC
// CD3D11_SHADER_RESOURCE_VIEW_DESC
// CD3D11_RENDER_TARGET_VIEW_DESC
// CD3D11_VIEWPORT
// CD3D11_DEPTH_STENCIL_VIEW_DESC
// CD3D11_UNORDERED_ACCESS_VIEW_DESC
// CD3D11_SAMPLER_DESC
// CD3D11_QUERY_DESC
// CD3D11_COUNTER_DESC
//
namespace DirectX
{
// simliar to std::lock_guard for exception-safe Direct3D 11 resource locking
class MapGuard : public D3D11_MAPPED_SUBRESOURCE
{
public:
MapGuard( _In_ ID3D11DeviceContext* context,
_In_ ID3D11Resource *resource,
_In_ UINT subresource,
_In_ D3D11_MAP mapType,
_In_ UINT mapFlags )
: mContext(context), mResource(resource), mSubresource(subresource)
{
HRESULT hr = mContext->Map( resource, subresource, mapType, mapFlags, this );
if (FAILED(hr))
{
throw std::exception();
}
}
~MapGuard()
{
mContext->Unmap( mResource, mSubresource );
}
uint8_t* get() const
{
return reinterpret_cast<uint8_t*>( pData );
}
uint8_t* get(size_t slice) const
{
return reinterpret_cast<uint8_t*>( pData ) + ( slice * DepthPitch );
}
uint8_t* scanline(size_t row) const
{
return reinterpret_cast<uint8_t*>( pData ) + ( row * RowPitch );
}
uint8_t* scanline(size_t slice, size_t row) const
{
return reinterpret_cast<uint8_t*>( pData ) + ( slice * DepthPitch ) + ( row * RowPitch );
}
private:
ID3D11DeviceContext* mContext;
ID3D11Resource* mResource;
UINT mSubresource;
MapGuard(MapGuard const&);
MapGuard& operator= (MapGuard const&);
};
// Helper sets a D3D resource name string (used by PIX and debug layer leak reporting).
template<UINT TNameLength>
inline void SetDebugObjectName(_In_ ID3D11DeviceChild* resource, _In_z_ const char (&name)[TNameLength])
{
#if !defined(NO_D3D11_DEBUG_NAME) && ( defined(_DEBUG) || defined(PROFILE) )
#if defined(_XBOX_ONE) && defined(_TITLE)
WCHAR wname[MAX_PATH];
int result = MultiByteToWideChar( CP_ACP, MB_PRECOMPOSED, name, TNameLength, wname, MAX_PATH );
if ( result > 0 )
{
resource->SetName( wname );
}
#else
resource->SetPrivateData(WKPDID_D3DDebugObjectName, TNameLength - 1, name);
#endif
#else
UNREFERENCED_PARAMETER(resource);
UNREFERENCED_PARAMETER(name);
#endif
}
}
+612
View File
@@ -0,0 +1,612 @@
//--------------------------------------------------------------------------------------
// File: Effects.h
//
// THIS CODE AND INFORMATION IS PROVIDED "AS IS" WITHOUT WARRANTY OF
// ANY KIND, EITHER EXPRESSED OR IMPLIED, INCLUDING BUT NOT LIMITED TO
// THE IMPLIED WARRANTIES OF MERCHANTABILITY AND/OR FITNESS FOR A
// PARTICULAR PURPOSE.
//
// Copyright (c) Microsoft Corporation. All rights reserved.
//
// http://go.microsoft.com/fwlink/?LinkId=248929
//--------------------------------------------------------------------------------------
#pragma once
#if defined(_XBOX_ONE) && defined(_TITLE)
#include <d3d11_x.h>
#else
#include <d3d11_1.h>
#endif
// VS 2010/2012 do not support =default =delete
#ifndef DIRECTX_CTOR_DEFAULT
#if defined(_MSC_VER) && (_MSC_VER < 1800)
#define DIRECTX_CTOR_DEFAULT {}
#define DIRECTX_CTOR_DELETE ;
#else
#define DIRECTX_CTOR_DEFAULT =default;
#define DIRECTX_CTOR_DELETE =delete;
#endif
#endif
#include <DirectXMath.h>
#include <memory>
#pragma warning(push)
#pragma warning(disable : 4481)
// VS 2010 considers 'override' to be a extension, but it's part of C++11 as of VS 2012
namespace DirectX
{
#if (DIRECTX_MATH_VERSION < 305) && !defined(XM_CALLCONV)
#define XM_CALLCONV __fastcall
typedef const XMVECTOR& HXMVECTOR;
typedef const XMMATRIX& FXMMATRIX;
#endif
//----------------------------------------------------------------------------------
// Abstract interface representing any effect which can be applied onto a D3D device context.
class IEffect
{
public:
virtual ~IEffect() { }
virtual void __cdecl Apply(_In_ ID3D11DeviceContext* deviceContext) = 0;
virtual void __cdecl GetVertexShaderBytecode(_Out_ void const** pShaderByteCode, _Out_ size_t* pByteCodeLength) = 0;
};
// Abstract interface for effects with world, view, and projection matrices.
class IEffectMatrices
{
public:
virtual ~IEffectMatrices() { }
virtual void XM_CALLCONV SetWorld(FXMMATRIX value) = 0;
virtual void XM_CALLCONV SetView(FXMMATRIX value) = 0;
virtual void XM_CALLCONV SetProjection(FXMMATRIX value) = 0;
};
// Abstract interface for effects which support directional lighting.
class IEffectLights
{
public:
virtual ~IEffectLights() { }
virtual void __cdecl SetLightingEnabled(bool value) = 0;
virtual void __cdecl SetPerPixelLighting(bool value) = 0;
virtual void XM_CALLCONV SetAmbientLightColor(FXMVECTOR value) = 0;
virtual void __cdecl SetLightEnabled(int whichLight, bool value) = 0;
virtual void XM_CALLCONV SetLightDirection(int whichLight, FXMVECTOR value) = 0;
virtual void XM_CALLCONV SetLightDiffuseColor(int whichLight, FXMVECTOR value) = 0;
virtual void XM_CALLCONV SetLightSpecularColor(int whichLight, FXMVECTOR value) = 0;
virtual void __cdecl EnableDefaultLighting() = 0;
static const int MaxDirectionalLights = 3;
};
// Abstract interface for effects which support fog.
class IEffectFog
{
public:
virtual ~IEffectFog() { }
virtual void __cdecl SetFogEnabled(bool value) = 0;
virtual void __cdecl SetFogStart(float value) = 0;
virtual void __cdecl SetFogEnd(float value) = 0;
virtual void XM_CALLCONV SetFogColor(FXMVECTOR value) = 0;
};
// Abstract interface for effects which support skinning
class IEffectSkinning
{
public:
virtual ~IEffectSkinning() { }
virtual void __cdecl SetWeightsPerVertex(int value) = 0;
virtual void __cdecl SetBoneTransforms(_In_reads_(count) XMMATRIX const* value, size_t count) = 0;
virtual void __cdecl ResetBoneTransforms() = 0;
static const int MaxBones = 72;
};
//----------------------------------------------------------------------------------
// Built-in shader supports optional texture mapping, vertex coloring, directional lighting, and fog.
class BasicEffect : public IEffect, public IEffectMatrices, public IEffectLights, public IEffectFog
{
public:
explicit BasicEffect(_In_ ID3D11Device* device);
BasicEffect(BasicEffect&& moveFrom);
BasicEffect& operator= (BasicEffect&& moveFrom);
virtual ~BasicEffect();
// IEffect methods.
void __cdecl Apply(_In_ ID3D11DeviceContext* deviceContext) override;
void __cdecl GetVertexShaderBytecode(_Out_ void const** pShaderByteCode, _Out_ size_t* pByteCodeLength) override;
// Camera settings.
void XM_CALLCONV SetWorld(FXMMATRIX value) override;
void XM_CALLCONV SetView(FXMMATRIX value) override;
void XM_CALLCONV SetProjection(FXMMATRIX value) override;
// Material settings.
void XM_CALLCONV SetDiffuseColor(FXMVECTOR value);
void XM_CALLCONV SetEmissiveColor(FXMVECTOR value);
void XM_CALLCONV SetSpecularColor(FXMVECTOR value);
void __cdecl SetSpecularPower(float value);
void __cdecl DisableSpecular();
void __cdecl SetAlpha(float value);
// Light settings.
void __cdecl SetLightingEnabled(bool value) override;
void __cdecl SetPerPixelLighting(bool value) override;
void XM_CALLCONV SetAmbientLightColor(FXMVECTOR value) override;
void __cdecl SetLightEnabled(int whichLight, bool value) override;
void XM_CALLCONV SetLightDirection(int whichLight, FXMVECTOR value) override;
void XM_CALLCONV SetLightDiffuseColor(int whichLight, FXMVECTOR value) override;
void XM_CALLCONV SetLightSpecularColor(int whichLight, FXMVECTOR value) override;
void __cdecl EnableDefaultLighting() override;
// Fog settings.
void __cdecl SetFogEnabled(bool value) override;
void __cdecl SetFogStart(float value) override;
void __cdecl SetFogEnd(float value) override;
void XM_CALLCONV SetFogColor(FXMVECTOR value) override;
// Vertex color setting.
void __cdecl SetVertexColorEnabled(bool value);
// Texture setting.
void __cdecl SetTextureEnabled(bool value);
void __cdecl SetTexture(_In_opt_ ID3D11ShaderResourceView* value);
private:
// Private implementation.
class Impl;
std::unique_ptr<Impl> pImpl;
// Prevent copying.
BasicEffect(BasicEffect const&) DIRECTX_CTOR_DELETE
BasicEffect& operator= (BasicEffect const&) DIRECTX_CTOR_DELETE
};
// Built-in shader supports per-pixel alpha testing.
class AlphaTestEffect : public IEffect, public IEffectMatrices, public IEffectFog
{
public:
explicit AlphaTestEffect(_In_ ID3D11Device* device);
AlphaTestEffect(AlphaTestEffect&& moveFrom);
AlphaTestEffect& operator= (AlphaTestEffect&& moveFrom);
virtual ~AlphaTestEffect();
// IEffect methods.
void __cdecl Apply(_In_ ID3D11DeviceContext* deviceContext) override;
void __cdecl GetVertexShaderBytecode(_Out_ void const** pShaderByteCode, _Out_ size_t* pByteCodeLength) override;
// Camera settings.
void XM_CALLCONV SetWorld(FXMMATRIX value) override;
void XM_CALLCONV SetView(FXMMATRIX value) override;
void XM_CALLCONV SetProjection(FXMMATRIX value) override;
// Material settings.
void XM_CALLCONV SetDiffuseColor(FXMVECTOR value);
void __cdecl SetAlpha(float value);
// Fog settings.
void __cdecl SetFogEnabled(bool value) override;
void __cdecl SetFogStart(float value) override;
void __cdecl SetFogEnd(float value) override;
void XM_CALLCONV SetFogColor(FXMVECTOR value) override;
// Vertex color setting.
void __cdecl SetVertexColorEnabled(bool value);
// Texture setting.
void __cdecl SetTexture(_In_opt_ ID3D11ShaderResourceView* value);
// Alpha test settings.
void __cdecl SetAlphaFunction(D3D11_COMPARISON_FUNC value);
void __cdecl SetReferenceAlpha(int value);
private:
// Private implementation.
class Impl;
std::unique_ptr<Impl> pImpl;
// Prevent copying.
AlphaTestEffect(AlphaTestEffect const&) DIRECTX_CTOR_DELETE
AlphaTestEffect& operator= (AlphaTestEffect const&) DIRECTX_CTOR_DELETE
};
// Built-in shader supports two layer multitexturing (eg. for lightmaps or detail textures).
class DualTextureEffect : public IEffect, public IEffectMatrices, public IEffectFog
{
public:
explicit DualTextureEffect(_In_ ID3D11Device* device);
DualTextureEffect(DualTextureEffect&& moveFrom);
DualTextureEffect& operator= (DualTextureEffect&& moveFrom);
~DualTextureEffect();
// IEffect methods.
void __cdecl Apply(_In_ ID3D11DeviceContext* deviceContext) override;
void __cdecl GetVertexShaderBytecode(_Out_ void const** pShaderByteCode, _Out_ size_t* pByteCodeLength) override;
// Camera settings.
void XM_CALLCONV SetWorld(FXMMATRIX value) override;
void XM_CALLCONV SetView(FXMMATRIX value) override;
void XM_CALLCONV SetProjection(FXMMATRIX value) override;
// Material settings.
void XM_CALLCONV SetDiffuseColor(FXMVECTOR value);
void __cdecl SetAlpha(float value);
// Fog settings.
void __cdecl SetFogEnabled(bool value) override;
void __cdecl SetFogStart(float value) override;
void __cdecl SetFogEnd(float value) override;
void XM_CALLCONV SetFogColor(FXMVECTOR value) override;
// Vertex color setting.
void __cdecl SetVertexColorEnabled(bool value);
// Texture settings.
void __cdecl SetTexture(_In_opt_ ID3D11ShaderResourceView* value);
void __cdecl SetTexture2(_In_opt_ ID3D11ShaderResourceView* value);
private:
// Private implementation.
class Impl;
std::unique_ptr<Impl> pImpl;
// Prevent copying.
DualTextureEffect(DualTextureEffect const&) DIRECTX_CTOR_DELETE
DualTextureEffect& operator= (DualTextureEffect const&) DIRECTX_CTOR_DELETE
};
// Built-in shader supports cubic environment mapping.
class EnvironmentMapEffect : public IEffect, public IEffectMatrices, public IEffectLights, public IEffectFog
{
public:
explicit EnvironmentMapEffect(_In_ ID3D11Device* device);
EnvironmentMapEffect(EnvironmentMapEffect&& moveFrom);
EnvironmentMapEffect& operator= (EnvironmentMapEffect&& moveFrom);
virtual ~EnvironmentMapEffect();
// IEffect methods.
void __cdecl Apply(_In_ ID3D11DeviceContext* deviceContext) override;
void __cdecl GetVertexShaderBytecode(_Out_ void const** pShaderByteCode, _Out_ size_t* pByteCodeLength) override;
// Camera settings.
void XM_CALLCONV SetWorld(FXMMATRIX value) override;
void XM_CALLCONV SetView(FXMMATRIX value) override;
void XM_CALLCONV SetProjection(FXMMATRIX value) override;
// Material settings.
void XM_CALLCONV SetDiffuseColor(FXMVECTOR value);
void XM_CALLCONV SetEmissiveColor(FXMVECTOR value);
void __cdecl SetAlpha(float value);
// Light settings.
void XM_CALLCONV SetAmbientLightColor(FXMVECTOR value) override;
void __cdecl SetLightEnabled(int whichLight, bool value) override;
void XM_CALLCONV SetLightDirection(int whichLight, FXMVECTOR value) override;
void XM_CALLCONV SetLightDiffuseColor(int whichLight, FXMVECTOR value) override;
void __cdecl EnableDefaultLighting() override;
// Fog settings.
void __cdecl SetFogEnabled(bool value) override;
void __cdecl SetFogStart(float value) override;
void __cdecl SetFogEnd(float value) override;
void XM_CALLCONV SetFogColor(FXMVECTOR value) override;
// Texture setting.
void __cdecl SetTexture(_In_opt_ ID3D11ShaderResourceView* value);
// Environment map settings.
void __cdecl SetEnvironmentMap(_In_opt_ ID3D11ShaderResourceView* value);
void __cdecl SetEnvironmentMapAmount(float value);
void XM_CALLCONV SetEnvironmentMapSpecular(FXMVECTOR value);
void __cdecl SetFresnelFactor(float value);
private:
// Private implementation.
class Impl;
std::unique_ptr<Impl> pImpl;
// Unsupported interface methods.
void __cdecl SetLightingEnabled(bool value) override;
void __cdecl SetPerPixelLighting(bool value) override;
void XM_CALLCONV SetLightSpecularColor(int whichLight, FXMVECTOR value) override;
// Prevent copying.
EnvironmentMapEffect(EnvironmentMapEffect const&) DIRECTX_CTOR_DELETE
EnvironmentMapEffect& operator= (EnvironmentMapEffect const&) DIRECTX_CTOR_DELETE
};
// Built-in shader supports skinned animation.
class SkinnedEffect : public IEffect, public IEffectMatrices, public IEffectLights, public IEffectFog, public IEffectSkinning
{
public:
explicit SkinnedEffect(_In_ ID3D11Device* device);
SkinnedEffect(SkinnedEffect&& moveFrom);
SkinnedEffect& operator= (SkinnedEffect&& moveFrom);
virtual ~SkinnedEffect();
// IEffect methods.
void __cdecl Apply(_In_ ID3D11DeviceContext* deviceContext) override;
void __cdecl GetVertexShaderBytecode(_Out_ void const** pShaderByteCode, _Out_ size_t* pByteCodeLength) override;
// Camera settings.
void XM_CALLCONV SetWorld(FXMMATRIX value) override;
void XM_CALLCONV SetView(FXMMATRIX value) override;
void XM_CALLCONV SetProjection(FXMMATRIX value) override;
// Material settings.
void XM_CALLCONV SetDiffuseColor(FXMVECTOR value);
void XM_CALLCONV SetEmissiveColor(FXMVECTOR value);
void XM_CALLCONV SetSpecularColor(FXMVECTOR value);
void __cdecl SetSpecularPower(float value);
void __cdecl DisableSpecular();
void __cdecl SetAlpha(float value);
// Light settings.
void __cdecl SetPerPixelLighting(bool value) override;
void XM_CALLCONV SetAmbientLightColor(FXMVECTOR value) override;
void __cdecl SetLightEnabled(int whichLight, bool value) override;
void XM_CALLCONV SetLightDirection(int whichLight, FXMVECTOR value) override;
void XM_CALLCONV SetLightDiffuseColor(int whichLight, FXMVECTOR value) override;
void XM_CALLCONV SetLightSpecularColor(int whichLight, FXMVECTOR value) override;
void __cdecl EnableDefaultLighting() override;
// Fog settings.
void __cdecl SetFogEnabled(bool value) override;
void __cdecl SetFogStart(float value) override;
void __cdecl SetFogEnd(float value) override;
void XM_CALLCONV SetFogColor(FXMVECTOR value) override;
// Texture setting.
void __cdecl SetTexture(_In_opt_ ID3D11ShaderResourceView* value);
// Animation settings.
void __cdecl SetWeightsPerVertex(int value) override;
void __cdecl SetBoneTransforms(_In_reads_(count) XMMATRIX const* value, size_t count) override;
void __cdecl ResetBoneTransforms() override;
private:
// Private implementation.
class Impl;
std::unique_ptr<Impl> pImpl;
// Unsupported interface method.
void __cdecl SetLightingEnabled(bool value) override;
// Prevent copying.
SkinnedEffect(SkinnedEffect const&) DIRECTX_CTOR_DELETE
SkinnedEffect& operator= (SkinnedEffect const&) DIRECTX_CTOR_DELETE
};
//----------------------------------------------------------------------------------
// Built-in effect for Visual Studio Shader Designer (DGSL) shaders
class DGSLEffect : public IEffect, public IEffectMatrices, public IEffectLights, public IEffectSkinning
{
public:
explicit DGSLEffect( _In_ ID3D11Device* device, _In_opt_ ID3D11PixelShader* pixelShader = nullptr,
_In_ bool enableSkinning = false );
DGSLEffect(DGSLEffect&& moveFrom);
DGSLEffect& operator= (DGSLEffect&& moveFrom);
virtual ~DGSLEffect();
// IEffect methods.
void __cdecl Apply(_In_ ID3D11DeviceContext* deviceContext) override;
void __cdecl GetVertexShaderBytecode(_Out_ void const** pShaderByteCode, _Out_ size_t* pByteCodeLength) override;
// Camera settings.
void XM_CALLCONV SetWorld(FXMMATRIX value) override;
void XM_CALLCONV SetView(FXMMATRIX value) override;
void XM_CALLCONV SetProjection(FXMMATRIX value) override;
// Material settings.
void XM_CALLCONV SetAmbientColor(FXMVECTOR value);
void XM_CALLCONV SetDiffuseColor(FXMVECTOR value);
void XM_CALLCONV SetEmissiveColor(FXMVECTOR value);
void XM_CALLCONV SetSpecularColor(FXMVECTOR value);
void __cdecl SetSpecularPower(float value);
void __cdecl DisableSpecular();
void __cdecl SetAlpha(float value);
// Additional settings.
void XM_CALLCONV SetUVTransform(FXMMATRIX value);
void __cdecl SetViewport( float width, float height );
void __cdecl SetTime( float time );
void __cdecl SetAlphaDiscardEnable(bool value);
// Light settings.
void __cdecl SetLightingEnabled(bool value) override;
void XM_CALLCONV SetAmbientLightColor(FXMVECTOR value) override;
void __cdecl SetLightEnabled(int whichLight, bool value) override;
void XM_CALLCONV SetLightDirection(int whichLight, FXMVECTOR value) override;
void XM_CALLCONV SetLightDiffuseColor(int whichLight, FXMVECTOR value) override;
void XM_CALLCONV SetLightSpecularColor(int whichLight, FXMVECTOR value) override;
void __cdecl EnableDefaultLighting() override;
static const int MaxDirectionalLights = 4;
// Vertex color setting.
void __cdecl SetVertexColorEnabled(bool value);
// Texture settings.
void __cdecl SetTextureEnabled(bool value);
void __cdecl SetTexture(_In_opt_ ID3D11ShaderResourceView* value);
void __cdecl SetTexture2(_In_opt_ ID3D11ShaderResourceView* value);
void __cdecl SetTexture(int whichTexture, _In_opt_ ID3D11ShaderResourceView* value);
static const int MaxTextures = 8;
// Animation setting.
void __cdecl SetWeightsPerVertex(int value) override;
void __cdecl SetBoneTransforms(_In_reads_(count) XMMATRIX const* value, size_t count) override;
void __cdecl ResetBoneTransforms() override;
private:
// Private implementation.
class Impl;
std::unique_ptr<Impl> pImpl;
// Unsupported interface methods.
void __cdecl SetPerPixelLighting(bool value) override;
// Prevent copying.
DGSLEffect(DGSLEffect const&) DIRECTX_CTOR_DELETE
DGSLEffect& operator= (DGSLEffect const&) DIRECTX_CTOR_DELETE
};
//----------------------------------------------------------------------------------
// Abstract interface to factory for sharing effects and texture resources
class IEffectFactory
{
public:
virtual ~IEffectFactory() {}
struct EffectInfo
{
const WCHAR* name;
bool perVertexColor;
bool enableSkinning;
bool enableDualTexture;
float specularPower;
float alpha;
DirectX::XMFLOAT3 ambientColor;
DirectX::XMFLOAT3 diffuseColor;
DirectX::XMFLOAT3 specularColor;
DirectX::XMFLOAT3 emissiveColor;
const WCHAR* texture;
const WCHAR* texture2;
EffectInfo() { memset( this, 0, sizeof(EffectInfo) ); };
};
virtual std::shared_ptr<IEffect> __cdecl CreateEffect( _In_ const EffectInfo& info, _In_opt_ ID3D11DeviceContext* deviceContext ) = 0;
virtual void __cdecl CreateTexture( _In_z_ const WCHAR* name, _In_opt_ ID3D11DeviceContext* deviceContext, _Outptr_ ID3D11ShaderResourceView** textureView ) = 0;
};
// Factory for sharing effects and texture resources
class EffectFactory : public IEffectFactory
{
public:
explicit EffectFactory(_In_ ID3D11Device* device);
EffectFactory(EffectFactory&& moveFrom);
EffectFactory& operator= (EffectFactory&& moveFrom);
virtual ~EffectFactory();
// IEffectFactory methods.
virtual std::shared_ptr<IEffect> __cdecl CreateEffect( _In_ const EffectInfo& info, _In_opt_ ID3D11DeviceContext* deviceContext ) override;
virtual void __cdecl CreateTexture( _In_z_ const WCHAR* name, _In_opt_ ID3D11DeviceContext* deviceContext, _Outptr_ ID3D11ShaderResourceView** textureView ) override;
// Settings.
void __cdecl ReleaseCache();
void __cdecl SetSharing( bool enabled );
void __cdecl SetDirectory( _In_opt_z_ const WCHAR* path );
private:
// Private implementation.
class Impl;
std::shared_ptr<Impl> pImpl;
// Prevent copying.
EffectFactory(EffectFactory const&) DIRECTX_CTOR_DELETE
EffectFactory& operator= (EffectFactory const&) DIRECTX_CTOR_DELETE
};
// Factory for sharing Visual Studio Shader Designer (DGSL) shaders and texture resources
class DGSLEffectFactory : public IEffectFactory
{
public:
explicit DGSLEffectFactory(_In_ ID3D11Device* device);
DGSLEffectFactory(DGSLEffectFactory&& moveFrom);
DGSLEffectFactory& operator= (DGSLEffectFactory&& moveFrom);
virtual ~DGSLEffectFactory();
// IEffectFactory methods.
virtual std::shared_ptr<IEffect> __cdecl CreateEffect( _In_ const EffectInfo& info, _In_opt_ ID3D11DeviceContext* deviceContext ) override;
virtual void __cdecl CreateTexture( _In_z_ const WCHAR* name, _In_opt_ ID3D11DeviceContext* deviceContext, _Outptr_ ID3D11ShaderResourceView** textureView ) override;
// DGSL methods.
struct DGSLEffectInfo : public EffectInfo
{
const WCHAR* textures[6];
const WCHAR* pixelShader;
DGSLEffectInfo() { memset( this, 0, sizeof(DGSLEffectInfo) ); };
};
virtual std::shared_ptr<IEffect> __cdecl CreateDGSLEffect( _In_ const DGSLEffectInfo& info, _In_opt_ ID3D11DeviceContext* deviceContext );
virtual void __cdecl CreatePixelShader( _In_z_ const WCHAR* shader, _Outptr_ ID3D11PixelShader** pixelShader );
// Settings.
void __cdecl ReleaseCache();
void __cdecl SetSharing( bool enabled );
void __cdecl SetDirectory( _In_opt_z_ const WCHAR* path );
private:
// Private implementation.
class Impl;
std::shared_ptr<Impl> pImpl;
// Prevent copying.
DGSLEffectFactory(DGSLEffectFactory const&) DIRECTX_CTOR_DELETE
DGSLEffectFactory& operator= (DGSLEffectFactory const&) DIRECTX_CTOR_DELETE
};
}
#pragma warning(pop)
+244
View File
@@ -0,0 +1,244 @@
//--------------------------------------------------------------------------------------
// File: GamePad.h
//
// THIS CODE AND INFORMATION IS PROVIDED "AS IS" WITHOUT WARRANTY OF
// ANY KIND, EITHER EXPRESSED OR IMPLIED, INCLUDING BUT NOT LIMITED TO
// THE IMPLIED WARRANTIES OF MERCHANTABILITY AND/OR FITNESS FOR A
// PARTICULAR PURPOSE.
//
// Copyright (c) Microsoft Corporation. All rights reserved.
//
// http://go.microsoft.com/fwlink/?LinkId=248929
//--------------------------------------------------------------------------------------
#pragma once
#if (_WIN32_WINNT < 0x0A00 /*_WIN32_WINNT_WIN10*/)
#ifndef _XBOX_ONE
#if !defined(WINAPI_FAMILY) || (WINAPI_FAMILY != WINAPI_FAMILY_PHONE_APP)
#if (_WIN32_WINNT >= 0x0602 /*_WIN32_WINNT_WIN8*/ )
#pragma comment(lib,"xinput.lib")
#else
#pragma comment(lib,"xinput9_1_0.lib")
#endif
#endif
#endif
#endif
// VS 2010/2012 do not support =default =delete
#ifndef DIRECTX_CTOR_DEFAULT
#if defined(_MSC_VER) && (_MSC_VER < 1800)
#define DIRECTX_CTOR_DEFAULT {}
#define DIRECTX_CTOR_DELETE ;
#else
#define DIRECTX_CTOR_DEFAULT =default;
#define DIRECTX_CTOR_DELETE =delete;
#endif
#endif
#include <memory>
#pragma warning(push)
#pragma warning(disable : 4005)
#include <stdint.h>
#include <intsafe.h>
#pragma warning(pop)
namespace DirectX
{
class GamePad
{
public:
GamePad();
GamePad(GamePad&& moveFrom);
GamePad& operator= (GamePad&& moveFrom);
virtual ~GamePad();
#if (_WIN32_WINNT >= 0x0A00 /*_WIN32_WINNT_WIN10*/ ) || defined(_XBOX_ONE)
static const int MAX_PLAYER_COUNT = 8;
#else
static const int MAX_PLAYER_COUNT = 4;
#endif
enum DeadZone
{
DEAD_ZONE_INDEPENDENT_AXES = 0,
DEAD_ZONE_CIRCULAR,
DEAD_ZONE_NONE,
};
struct Buttons
{
bool a;
bool b;
bool x;
bool y;
bool leftStick;
bool rightStick;
bool leftShoulder;
bool rightShoulder;
bool back;
bool start;
};
struct DPad
{
bool up;
bool down;
bool right;
bool left;
};
struct ThumbSticks
{
float leftX;
float leftY;
float rightX;
float rightY;
};
struct Triggers
{
float left;
float right;
};
struct State
{
bool connected;
uint64_t packet;
Buttons buttons;
DPad dpad;
ThumbSticks thumbSticks;
Triggers triggers;
bool __cdecl IsConnected() const { return connected; }
// Is the button pressed currently?
bool __cdecl IsAPressed() const { return buttons.a; }
bool __cdecl IsBPressed() const { return buttons.b; }
bool __cdecl IsXPressed() const { return buttons.x; }
bool __cdecl IsYPressed() const { return buttons.y; }
bool __cdecl IsLeftStickPressed() const { return buttons.leftStick; }
bool __cdecl IsRightStickPressed() const { return buttons.rightStick; }
bool __cdecl IsLeftShoulderPressed() const { return buttons.leftShoulder; }
bool __cdecl IsRightShoulderPressed() const { return buttons.rightShoulder; }
bool __cdecl IsBackPressed() const { return buttons.back; }
bool __cdecl IsViewPressed() const { return buttons.back; }
bool __cdecl IsStartPressed() const { return buttons.start; }
bool __cdecl IsMenuPressed() const { return buttons.start; }
bool __cdecl IsDPadDownPressed() const { return dpad.down; };
bool __cdecl IsDPadUpPressed() const { return dpad.up; };
bool __cdecl IsDPadLeftPressed() const { return dpad.left; };
bool __cdecl IsDPadRightPressed() const { return dpad.right; };
bool __cdecl IsLeftThumbStickUp() const { return (thumbSticks.leftY > 0.5f) != 0; }
bool __cdecl IsLeftThumbStickDown() const { return (thumbSticks.leftY < -0.5f) != 0; }
bool __cdecl IsLeftThumbStickLeft() const { return (thumbSticks.leftX < -0.5f) != 0; }
bool __cdecl IsLeftThumbStickRight() const { return (thumbSticks.leftX > 0.5f) != 0; }
bool __cdecl IsRightThumbStickUp() const { return (thumbSticks.rightY > 0.5f ) != 0; }
bool __cdecl IsRightThumbStickDown() const { return (thumbSticks.rightY < -0.5f) != 0; }
bool __cdecl IsRightThumbStickLeft() const { return (thumbSticks.rightX < -0.5f) != 0; }
bool __cdecl IsRightThumbStickRight() const { return (thumbSticks.rightX > 0.5f) != 0; }
bool __cdecl IsLeftTriggerPressed() const { return (triggers.left > 0.5f) != 0; }
bool __cdecl IsRightTriggerPressed() const { return (triggers.right > 0.5f) != 0; }
};
struct Capabilities
{
enum Type
{
UNKNOWN = 0,
GAMEPAD,
WHEEL,
ARCADE_STICK,
FLIGHT_STICK,
DANCE_PAD,
GUITAR,
GUITAR_ALTERNATE,
DRUM_KIT,
GUITAR_BASS = 11,
ARCADE_PAD = 19,
};
bool connected;
Type gamepadType;
uint64_t id;
bool __cdecl IsConnected() const { return connected; }
};
class ButtonStateTracker
{
public:
enum ButtonState
{
UP = 0, // Button is up
HELD = 1, // Button is held down
RELEASED = 2, // Button was just released
PRESSED = 3, // Buton was just pressed
};
ButtonState a;
ButtonState b;
ButtonState x;
ButtonState y;
ButtonState leftStick;
ButtonState rightStick;
ButtonState leftShoulder;
ButtonState rightShoulder;
ButtonState back;
ButtonState start;
ButtonState dpadUp;
ButtonState dpadDown;
ButtonState dpadLeft;
ButtonState dpadRight;
ButtonStateTracker() { Reset(); }
void __cdecl Update( const State& state );
void __cdecl Reset();
private:
State lastState;
};
// Retrieve the current state of the gamepad of the associated player index
State __cdecl GetState(int player, DeadZone deadZoneMode = DEAD_ZONE_INDEPENDENT_AXES);
// Retrieve the current capabilities of the gamepad of the associated player index
Capabilities __cdecl GetCapabilities(int player);
// Set the vibration motor speeds of the gamepad
bool __cdecl SetVibration( int player, float leftMotor, float rightMotor, float leftTrigger = 0.f, float rightTrigger = 0.f );
// Handle suspending/resuming
void __cdecl Suspend();
void __cdecl Resume();
// Singleton
static GamePad& __cdecl Get();
private:
// Private implementation.
class Impl;
std::unique_ptr<Impl> pImpl;
// Prevent copying.
GamePad(GamePad const&) DIRECTX_CTOR_DELETE
GamePad& operator=(GamePad const&) DIRECTX_CTOR_DELETE
};
}
+100
View File
@@ -0,0 +1,100 @@
//--------------------------------------------------------------------------------------
// File: GeometricPrimitive.h
//
// THIS CODE AND INFORMATION IS PROVIDED "AS IS" WITHOUT WARRANTY OF
// ANY KIND, EITHER EXPRESSED OR IMPLIED, INCLUDING BUT NOT LIMITED TO
// THE IMPLIED WARRANTIES OF MERCHANTABILITY AND/OR FITNESS FOR A
// PARTICULAR PURPOSE.
//
// Copyright (c) Microsoft Corporation. All rights reserved.
//
// http://go.microsoft.com/fwlink/?LinkId=248929
//--------------------------------------------------------------------------------------
#pragma once
#if defined(_XBOX_ONE) && defined(_TITLE)
#include <d3d11_x.h>
#else
#include <d3d11_1.h>
#endif
#include <DirectXMath.h>
#include <DirectXColors.h>
#include <functional>
#include <memory>
// VS 2010 doesn't support explicit calling convention for std::function
#ifndef DIRECTX_STD_CALLCONV
#if defined(_MSC_VER) && (_MSC_VER < 1700)
#define DIRECTX_STD_CALLCONV
#else
#define DIRECTX_STD_CALLCONV __cdecl
#endif
#endif
// VS 2010/2012 do not support =default =delete
#ifndef DIRECTX_CTOR_DEFAULT
#if defined(_MSC_VER) && (_MSC_VER < 1800)
#define DIRECTX_CTOR_DEFAULT {}
#define DIRECTX_CTOR_DELETE ;
#else
#define DIRECTX_CTOR_DEFAULT =default;
#define DIRECTX_CTOR_DELETE =delete;
#endif
#endif
namespace DirectX
{
#if (DIRECTX_MATH_VERSION < 305) && !defined(XM_CALLCONV)
#define XM_CALLCONV __fastcall
typedef const XMVECTOR& HXMVECTOR;
typedef const XMMATRIX& FXMMATRIX;
#endif
class IEffect;
class GeometricPrimitive
{
public:
virtual ~GeometricPrimitive();
// Factory methods.
static std::unique_ptr<GeometricPrimitive> __cdecl CreateCube (_In_ ID3D11DeviceContext* deviceContext, float size = 1, bool rhcoords = true);
static std::unique_ptr<GeometricPrimitive> __cdecl CreateBox (_In_ ID3D11DeviceContext* deviceContext, const XMFLOAT3& size, bool rhcoords = true, bool invertn = false);
static std::unique_ptr<GeometricPrimitive> __cdecl CreateSphere (_In_ ID3D11DeviceContext* deviceContext, float diameter = 1, size_t tessellation = 16, bool rhcoords = true, bool invertn = false);
static std::unique_ptr<GeometricPrimitive> __cdecl CreateGeoSphere (_In_ ID3D11DeviceContext* deviceContext, float diameter = 1, size_t tessellation = 3, bool rhcoords = true);
static std::unique_ptr<GeometricPrimitive> __cdecl CreateCylinder (_In_ ID3D11DeviceContext* deviceContext, float height = 1, float diameter = 1, size_t tessellation = 32, bool rhcoords = true);
static std::unique_ptr<GeometricPrimitive> __cdecl CreateCone (_In_ ID3D11DeviceContext* deviceContext, float diameter = 1, float height = 1, size_t tessellation = 32, bool rhcoords = true);
static std::unique_ptr<GeometricPrimitive> __cdecl CreateTorus (_In_ ID3D11DeviceContext* deviceContext, float diameter = 1, float thickness = 0.333f, size_t tessellation = 32, bool rhcoords = true);
static std::unique_ptr<GeometricPrimitive> __cdecl CreateTetrahedron (_In_ ID3D11DeviceContext* deviceContext, float size = 1, bool rhcoords = true);
static std::unique_ptr<GeometricPrimitive> __cdecl CreateOctahedron (_In_ ID3D11DeviceContext* deviceContext, float size = 1, bool rhcoords = true);
static std::unique_ptr<GeometricPrimitive> __cdecl CreateDodecahedron (_In_ ID3D11DeviceContext* deviceContext, float size = 1, bool rhcoords = true);
static std::unique_ptr<GeometricPrimitive> __cdecl CreateIcosahedron (_In_ ID3D11DeviceContext* deviceContext, float size = 1, bool rhcoords = true);
static std::unique_ptr<GeometricPrimitive> __cdecl CreateTeapot (_In_ ID3D11DeviceContext* deviceContext, float size = 1, size_t tessellation = 8, bool rhcoords = true);
// Draw the primitive.
void XM_CALLCONV Draw(FXMMATRIX world, CXMMATRIX view, CXMMATRIX projection, FXMVECTOR color = Colors::White, _In_opt_ ID3D11ShaderResourceView* texture = nullptr, bool wireframe = false,
_In_opt_ std::function<void DIRECTX_STD_CALLCONV()> setCustomState = nullptr );
// Draw the primitive using a custom effect.
void __cdecl Draw( _In_ IEffect* effect, _In_ ID3D11InputLayout* inputLayout, bool alpha = false, bool wireframe = false,
_In_opt_ std::function<void DIRECTX_STD_CALLCONV()> setCustomState = nullptr );
// Create input layout for drawing with a custom effect.
void __cdecl CreateInputLayout( _In_ IEffect* effect, _Outptr_ ID3D11InputLayout** inputLayout );
private:
GeometricPrimitive();
// Private implementation.
class Impl;
std::unique_ptr<Impl> pImpl;
// Prevent copying.
GeometricPrimitive(GeometricPrimitive const&) DIRECTX_CTOR_DELETE
GeometricPrimitive& operator= (GeometricPrimitive const&) DIRECTX_CTOR_DELETE
};
}
+490
View File
@@ -0,0 +1,490 @@
//--------------------------------------------------------------------------------------
// File: Keyboard.h
//
// THIS CODE AND INFORMATION IS PROVIDED "AS IS" WITHOUT WARRANTY OF
// ANY KIND, EITHER EXPRESSED OR IMPLIED, INCLUDING BUT NOT LIMITED TO
// THE IMPLIED WARRANTIES OF MERCHANTABILITY AND/OR FITNESS FOR A
// PARTICULAR PURPOSE.
//
// Copyright (c) Microsoft Corporation. All rights reserved.
//
// http://go.microsoft.com/fwlink/?LinkId=248929
//--------------------------------------------------------------------------------------
#pragma once
// VS 2010/2012 do not support =default =delete
#ifndef DIRECTX_CTOR_DEFAULT
#if defined(_MSC_VER) && (_MSC_VER < 1800)
#define DIRECTX_CTOR_DEFAULT {}
#define DIRECTX_CTOR_DELETE ;
#else
#define DIRECTX_CTOR_DEFAULT =default;
#define DIRECTX_CTOR_DELETE =delete;
#endif
#endif
#pragma warning(push)
#pragma warning(disable : 4005)
#include <stdint.h>
#pragma warning(pop)
#include <memory>
#if defined(WINAPI_FAMILY) && (WINAPI_FAMILY == WINAPI_FAMILY_APP)
namespace ABI { namespace Windows { namespace UI { namespace Core { struct ICoreWindow; } } } }
#endif
namespace DirectX
{
class Keyboard
{
public:
Keyboard();
Keyboard(Keyboard&& moveFrom);
Keyboard& operator= (Keyboard&& moveFrom);
virtual ~Keyboard();
enum Keys
{
None = 0,
Back = 0x8,
Tab = 0x9,
Enter = 0xd,
Pause = 0x13,
CapsLock = 0x14,
Kana = 0x15,
Kanji = 0x19,
Escape = 0x1b,
ImeConvert = 0x1c,
ImeNoConvert = 0x1d,
Space = 0x20,
PageUp = 0x21,
PageDown = 0x22,
End = 0x23,
Home = 0x24,
Left = 0x25,
Up = 0x26,
Right = 0x27,
Down = 0x28,
Select = 0x29,
Print = 0x2a,
Execute = 0x2b,
PrintScreen = 0x2c,
Insert = 0x2d,
Delete = 0x2e,
Help = 0x2f,
D0 = 0x30,
D1 = 0x31,
D2 = 0x32,
D3 = 0x33,
D4 = 0x34,
D5 = 0x35,
D6 = 0x36,
D7 = 0x37,
D8 = 0x38,
D9 = 0x39,
A = 0x41,
B = 0x42,
C = 0x43,
D = 0x44,
E = 0x45,
F = 0x46,
G = 0x47,
H = 0x48,
I = 0x49,
J = 0x4a,
K = 0x4b,
L = 0x4c,
M = 0x4d,
N = 0x4e,
O = 0x4f,
P = 0x50,
Q = 0x51,
R = 0x52,
S = 0x53,
T = 0x54,
U = 0x55,
V = 0x56,
W = 0x57,
X = 0x58,
Y = 0x59,
Z = 0x5a,
LeftWindows = 0x5b,
RightWindows = 0x5c,
Apps = 0x5d,
Sleep = 0x5f,
NumPad0 = 0x60,
NumPad1 = 0x61,
NumPad2 = 0x62,
NumPad3 = 0x63,
NumPad4 = 0x64,
NumPad5 = 0x65,
NumPad6 = 0x66,
NumPad7 = 0x67,
NumPad8 = 0x68,
NumPad9 = 0x69,
Multiply = 0x6a,
Add = 0x6b,
Separator = 0x6c,
Subtract = 0x6d,
Decimal = 0x6e,
Divide = 0x6f,
F1 = 0x70,
F2 = 0x71,
F3 = 0x72,
F4 = 0x73,
F5 = 0x74,
F6 = 0x75,
F7 = 0x76,
F8 = 0x77,
F9 = 0x78,
F10 = 0x79,
F11 = 0x7a,
F12 = 0x7b,
F13 = 0x7c,
F14 = 0x7d,
F15 = 0x7e,
F16 = 0x7f,
F17 = 0x80,
F18 = 0x81,
F19 = 0x82,
F20 = 0x83,
F21 = 0x84,
F22 = 0x85,
F23 = 0x86,
F24 = 0x87,
NumLock = 0x90,
Scroll = 0x91,
LeftShift = 0xa0,
RightShift = 0xa1,
LeftControl = 0xa2,
RightControl = 0xa3,
LeftAlt = 0xa4,
RightAlt = 0xa5,
BrowserBack = 0xa6,
BrowserForward = 0xa7,
BrowserRefresh = 0xa8,
BrowserStop = 0xa9,
BrowserSearch = 0xaa,
BrowserFavorites = 0xab,
BrowserHome = 0xac,
VolumeMute = 0xad,
VolumeDown = 0xae,
VolumeUp = 0xaf,
MediaNextTrack = 0xb0,
MediaPreviousTrack = 0xb1,
MediaStop = 0xb2,
MediaPlayPause = 0xb3,
LaunchMail = 0xb4,
SelectMedia = 0xb5,
LaunchApplication1 = 0xb6,
LaunchApplication2 = 0xb7,
OemSemicolon = 0xba,
OemPlus = 0xbb,
OemComma = 0xbc,
OemMinus = 0xbd,
OemPeriod = 0xbe,
OemQuestion = 0xbf,
OemTilde = 0xc0,
OemOpenBrackets = 0xdb,
OemPipe = 0xdc,
OemCloseBrackets = 0xdd,
OemQuotes = 0xde,
Oem8 = 0xdf,
OemBackslash = 0xe2,
ProcessKey = 0xe5,
OemCopy = 0xf2,
OemAuto = 0xf3,
OemEnlW = 0xf4,
Attn = 0xf6,
Crsel = 0xf7,
Exsel = 0xf8,
EraseEof = 0xf9,
Play = 0xfa,
Zoom = 0xfb,
Pa1 = 0xfd,
OemClear = 0xfe,
};
struct State
{
bool Reserved0 : 8;
bool Back : 1; // VK_BACK, 0x8
bool Tab : 1; // VK_TAB, 0x9
bool Reserved1 : 3;
bool Enter : 1; // VK_RETURN, 0xD
bool Reserved2 : 2;
bool Reserved3 : 3;
bool Pause : 1; // VK_PAUSE, 0x13
bool CapsLock : 1; // VK_CAPITAL, 0x14
bool Kana : 1; // VK_KANA, 0x15
bool Reserved4 : 2;
bool Reserved5 : 1;
bool Kanji : 1; // VK_KANJI, 0x19
bool Reserved6 : 1;
bool Escape : 1; // VK_ESCAPE, 0x1B
bool ImeConvert : 1; // VK_CONVERT, 0x1C
bool ImeNoConvert : 1; // VK_NONCONVERT, 0x1D
bool Reserved7 : 2;
bool Space : 1; // VK_SPACE, 0x20
bool PageUp : 1; // VK_PRIOR, 0x21
bool PageDown : 1; // VK_NEXT, 0x22
bool End : 1; // VK_END, 0x23
bool Home : 1; // VK_HOME, 0x24
bool Left : 1; // VK_LEFT, 0x25
bool Up : 1; // VK_UP, 0x26
bool Right : 1; // VK_RIGHT, 0x27
bool Down : 1; // VK_DOWN, 0x28
bool Select : 1; // VK_SELECT, 0x29
bool Print : 1; // VK_PRINT, 0x2A
bool Execute : 1; // VK_EXECUTE, 0x2B
bool PrintScreen : 1; // VK_SNAPSHOT, 0x2C
bool Insert : 1; // VK_INSERT, 0x2D
bool Delete : 1; // VK_DELETE, 0x2E
bool Help : 1; // VK_HELP, 0x2F
bool D0 : 1; // 0x30
bool D1 : 1; // 0x31
bool D2 : 1; // 0x32
bool D3 : 1; // 0x33
bool D4 : 1; // 0x34
bool D5 : 1; // 0x35
bool D6 : 1; // 0x36
bool D7 : 1; // 0x37
bool D8 : 1; // 0x38
bool D9 : 1; // 0x39
bool Reserved8 : 6;
bool Reserved9 : 1;
bool A : 1; // 0x41
bool B : 1; // 0x42
bool C : 1; // 0x43
bool D : 1; // 0x44
bool E : 1; // 0x45
bool F : 1; // 0x46
bool G : 1; // 0x47
bool H : 1; // 0x48
bool I : 1; // 0x49
bool J : 1; // 0x4A
bool K : 1; // 0x4B
bool L : 1; // 0x4C
bool M : 1; // 0x4D
bool N : 1; // 0x4E
bool O : 1; // 0x4F
bool P : 1; // 0x50
bool Q : 1; // 0x51
bool R : 1; // 0x52
bool S : 1; // 0x53
bool T : 1; // 0x54
bool U : 1; // 0x55
bool V : 1; // 0x56
bool W : 1; // 0x57
bool X : 1; // 0x58
bool Y : 1; // 0x59
bool Z : 1; // 0x5A
bool LeftWindows : 1; // VK_LWIN, 0x5B
bool RightWindows : 1; // VK_RWIN, 0x5C
bool Apps : 1; // VK_APPS, 0x5D
bool Reserved10 : 1;
bool Sleep : 1; // VK_SLEEP, 0x5F
bool NumPad0 : 1; // VK_NUMPAD0, 0x60
bool NumPad1 : 1; // VK_NUMPAD1, 0x61
bool NumPad2 : 1; // VK_NUMPAD2, 0x62
bool NumPad3 : 1; // VK_NUMPAD3, 0x63
bool NumPad4 : 1; // VK_NUMPAD4, 0x64
bool NumPad5 : 1; // VK_NUMPAD5, 0x65
bool NumPad6 : 1; // VK_NUMPAD6, 0x66
bool NumPad7 : 1; // VK_NUMPAD7, 0x67
bool NumPad8 : 1; // VK_NUMPAD8, 0x68
bool NumPad9 : 1; // VK_NUMPAD9, 0x69
bool Multiply : 1; // VK_MULTIPLY, 0x6A
bool Add : 1; // VK_ADD, 0x6B
bool Separator : 1; // VK_SEPARATOR, 0x6C
bool Subtract : 1; // VK_SUBTRACT, 0x6D
bool Decimal : 1; // VK_DECIMANL, 0x6E
bool Divide : 1; // VK_DIVIDE, 0x6F
bool F1 : 1; // VK_F1, 0x70
bool F2 : 1; // VK_F2, 0x71
bool F3 : 1; // VK_F3, 0x72
bool F4 : 1; // VK_F4, 0x73
bool F5 : 1; // VK_F5, 0x74
bool F6 : 1; // VK_F6, 0x75
bool F7 : 1; // VK_F7, 0x76
bool F8 : 1; // VK_F8, 0x77
bool F9 : 1; // VK_F9, 0x78
bool F10 : 1; // VK_F10, 0x79
bool F11 : 1; // VK_F11, 0x7A
bool F12 : 1; // VK_F12, 0x7B
bool F13 : 1; // VK_F13, 0x7C
bool F14 : 1; // VK_F14, 0x7D
bool F15 : 1; // VK_F15, 0x7E
bool F16 : 1; // VK_F16, 0x7F
bool F17 : 1; // VK_F17, 0x80
bool F18 : 1; // VK_F18, 0x81
bool F19 : 1; // VK_F19, 0x82
bool F20 : 1; // VK_F20, 0x83
bool F21 : 1; // VK_F21, 0x84
bool F22 : 1; // VK_F22, 0x85
bool F23 : 1; // VK_F23, 0x86
bool F24 : 1; // VK_F24, 0x87
bool Reserved11 : 8;
bool NumLock : 1; // VK_NUMLOCK, 0x90
bool Scroll : 1; // VK_SCROLL, 0x91
bool Reserved12 : 6;
bool Reserved13 : 8;
bool LeftShift : 1; // VK_LSHIFT, 0xA0
bool RightShift : 1; // VK_RSHIFT, 0xA1
bool LeftControl : 1; // VK_LCONTROL, 0xA2
bool RightControl : 1; // VK_RCONTROL, 0xA3
bool LeftAlt : 1; // VK_LMENU, 0xA4
bool RightAlt : 1; // VK_RMENU, 0xA5
bool BrowserBack : 1; // VK_BROWSER_BACK, 0xA6
bool BrowserForward : 1; // VK_BROWSER_FORWARD, 0xA7
bool BrowserRefresh : 1; // VK_BROWSER_REFRESH, 0xA8
bool BrowserStop : 1; // VK_BROWSER_STOP, 0xA9
bool BrowserSearch : 1; // VK_BROWSER_SEARCH, 0xAA
bool BrowserFavorites : 1; // VK_BROWSER_FAVORITES, 0xAB
bool BrowserHome : 1; // VK_BROWSER_HOME, 0xAC
bool VolumeMute : 1; // VK_VOLUME_MUTE, 0xAD
bool VolumeDown : 1; // VK_VOLUME_DOWN, 0xAE
bool VolumeUp : 1; // VK_VOLUME_UP, 0xAF
bool MediaNextTrack : 1; // VK_MEDIA_NEXT_TRACK, 0xB0
bool MediaPreviousTrack : 1;// VK_MEDIA_PREV_TRACK, 0xB1
bool MediaStop : 1; // VK_MEDIA_STOP, 0xB2
bool MediaPlayPause : 1; // VK_MEDIA_PLAY_PAUSE, 0xB3
bool LaunchMail : 1; // VK_LAUNCH_MAIL, 0xB4
bool SelectMedia : 1; // VK_LAUNCH_MEDIA_SELECT, 0xB5
bool LaunchApplication1 : 1;// VK_LAUNCH_APP1, 0xB6
bool LaunchApplication2 : 1;// VK_LAUNCH_APP2, 0xB7
bool Reserved14 : 2;
bool OemSemicolon : 1; // VK_OEM_1, 0xBA
bool OemPlus : 1; // VK_OEM_PLUS, 0xBB
bool OemComma : 1; // VK_OEM_COMMA, 0xBC
bool OemMinus : 1; // VK_OEM_MINUS, 0xBD
bool OemPeriod : 1; // VK_OEM_PERIOD, 0xBE
bool OemQuestion : 1; // VK_OEM_2, 0xBF
bool OemTilde : 1; // VK_OEM_3, 0xC0
bool Reserved15 : 7;
bool Reserved16 : 8;
bool Reserved17 : 8;
bool Reserved18 : 1;
bool OemOpenBrackets : 1; // VK_OEM_4, 0xDB
bool OemPipe : 1; // VK_OEM_5, 0xDC
bool OemCloseBrackets : 1; // VK_OEM_6, 0xDD
bool OemQuotes : 1; // VK_OEM_7, 0xDE
bool Oem8 : 1; // VK_OEM_8, 0xDF
bool Reserved19 : 2;
bool OemBackslash : 1; // VK_OEM_102, 0xE2
bool Reserved20 : 2;
bool ProcessKey : 1; // VK_PROCESSKEY, 0xE5
bool Reserved21 : 4;
bool Reserved22 : 8;
bool OemCopy : 1; // 0XF2
bool OemAuto : 1; // 0xF3
bool OemEnlW : 1; // 0xF4
bool Reserved23 : 1;
bool Attn : 1; // VK_ATTN, 0xF6
bool Crsel : 1; // VK_CRSEL, 0xF7
bool Exsel : 1; // VK_EXSEL, 0xF8
bool EraseEof : 1; // VK_EREOF, 0xF9
bool Play : 1; // VK_PLAY, 0xFA
bool Zoom : 1; // VK_ZOOM, 0xFB
bool Reserved24 : 1;
bool Pa1 : 1; // VK_PA1, 0xFD
bool OemClear : 1; // VK_OEM_CLEAR, 0xFE
bool __cdecl IsKeyDown(Keys key) const
{
if (key >= 0 && key <= 0xff)
{
auto ptr = reinterpret_cast<const uint32_t*>(this);
unsigned int bf = 1u << (key & 0x1f);
return (ptr[(key >> 5)] & bf) != 0;
}
return false;
}
bool __cdecl IsKeyUp(Keys key) const
{
if (key >= 0 && key <= 0xfe)
{
auto ptr = reinterpret_cast<const uint32_t*>(this);
unsigned int bf = 1u << (key & 0x1f);
return (ptr[(key >> 5)] & bf) == 0;
}
return false;
}
};
class KeyboardStateTracker
{
public:
State released;
State pressed;
KeyboardStateTracker() { Reset(); }
void __cdecl Update(const State& state);
void __cdecl Reset();
bool __cdecl IsKeyPressed(Keys key) const { return pressed.IsKeyDown(key); }
bool __cdecl IsKeyReleased(Keys key) const { return released.IsKeyDown(key); }
public:
State lastState;
};
// Retrieve the current state of the keyboard
State __cdecl GetState() const;
// Reset the keyboard state
void __cdecl Reset();
#if !defined(WINAPI_FAMILY) || (WINAPI_FAMILY == WINAPI_FAMILY_DESKTOP_APP) && defined(WM_USER)
static void __cdecl ProcessMessage(UINT message, WPARAM wParam, LPARAM lParam);
#endif
#if defined(WINAPI_FAMILY) && (WINAPI_FAMILY == WINAPI_FAMILY_APP)
void __cdecl SetWindow(ABI::Windows::UI::Core::ICoreWindow* window);
#ifdef __cplusplus_winrt
void __cdecl SetWindow(Windows::UI::Core::CoreWindow^ window)
{
// See https://msdn.microsoft.com/en-us/library/hh755802.aspx
SetWindow(reinterpret_cast<ABI::Windows::UI::Core::ICoreWindow*>(window));
}
#endif
#endif
// Singleton
static Keyboard& __cdecl Get();
private:
// Private implementation.
class Impl;
std::unique_ptr<Impl> pImpl;
// Prevent copying.
Keyboard(Keyboard const&) DIRECTX_CTOR_DELETE
Keyboard& operator=(Keyboard const&) DIRECTX_CTOR_DELETE
};
}
+163
View File
@@ -0,0 +1,163 @@
//--------------------------------------------------------------------------------------
// File: Model.h
//
// THIS CODE AND INFORMATION IS PROVIDED "AS IS" WITHOUT WARRANTY OF
// ANY KIND, EITHER EXPRESSED OR IMPLIED, INCLUDING BUT NOT LIMITED TO
// THE IMPLIED WARRANTIES OF MERCHANTABILITY AND/OR FITNESS FOR A
// PARTICULAR PURPOSE.
//
// Copyright (c) Microsoft Corporation. All rights reserved.
//
// http://go.microsoft.com/fwlink/?LinkId=248929
//--------------------------------------------------------------------------------------
#pragma once
#if defined(_XBOX_ONE) && defined(_TITLE)
#include <d3d11_x.h>
#else
#include <d3d11_1.h>
#endif
#include <DirectXMath.h>
#include <DirectXCollision.h>
#include <memory>
#include <functional>
#include <set>
#include <string>
#include <vector>
#pragma warning(push)
#pragma warning(disable : 4005)
#include <stdint.h>
#include <intsafe.h>
#pragma warning(pop)
#include <wrl\client.h>
// VS 2010 doesn't support explicit calling convention for std::function
#ifndef DIRECTX_STD_CALLCONV
#if defined(_MSC_VER) && (_MSC_VER < 1700)
#define DIRECTX_STD_CALLCONV
#else
#define DIRECTX_STD_CALLCONV __cdecl
#endif
#endif
namespace DirectX
{
#if (DIRECTX_MATH_VERSION < 305) && !defined(XM_CALLCONV)
#define XM_CALLCONV __fastcall
typedef const XMVECTOR& HXMVECTOR;
typedef const XMMATRIX& FXMMATRIX;
#endif
class IEffect;
class IEffectFactory;
class CommonStates;
class ModelMesh;
//----------------------------------------------------------------------------------
// Each mesh part is a submesh with a single effect
class ModelMeshPart
{
public:
ModelMeshPart();
virtual ~ModelMeshPart();
uint32_t indexCount;
uint32_t startIndex;
uint32_t vertexOffset;
uint32_t vertexStride;
D3D_PRIMITIVE_TOPOLOGY primitiveType;
DXGI_FORMAT indexFormat;
Microsoft::WRL::ComPtr<ID3D11InputLayout> inputLayout;
Microsoft::WRL::ComPtr<ID3D11Buffer> indexBuffer;
Microsoft::WRL::ComPtr<ID3D11Buffer> vertexBuffer;
std::shared_ptr<IEffect> effect;
std::shared_ptr<std::vector<D3D11_INPUT_ELEMENT_DESC>> vbDecl;
bool isAlpha;
typedef std::vector<std::unique_ptr<ModelMeshPart>> Collection;
// Draw mesh part with custom effect
void __cdecl Draw( _In_ ID3D11DeviceContext* deviceContext, _In_ IEffect* ieffect, _In_ ID3D11InputLayout* iinputLayout,
_In_opt_ std::function<void DIRECTX_STD_CALLCONV()> setCustomState = nullptr ) const;
// Create input layout for drawing with a custom effect.
void __cdecl CreateInputLayout( _In_ ID3D11Device* d3dDevice, _In_ IEffect* ieffect, _Outptr_ ID3D11InputLayout** iinputLayout );
// Change effect used by part and regenerate input layout (be sure to call Model::Modified as well)
void __cdecl ModifyEffect( _In_ ID3D11Device* d3dDevice, _In_ std::shared_ptr<IEffect>& ieffect, bool isalpha = false );
};
//----------------------------------------------------------------------------------
// A mesh consists of one or more model mesh parts
class ModelMesh
{
public:
ModelMesh();
virtual ~ModelMesh();
BoundingSphere boundingSphere;
BoundingBox boundingBox;
ModelMeshPart::Collection meshParts;
std::wstring name;
bool ccw;
bool pmalpha;
typedef std::vector<std::shared_ptr<ModelMesh>> Collection;
// Setup states for drawing mesh
void __cdecl PrepareForRendering( _In_ ID3D11DeviceContext* deviceContext, CommonStates& states, bool alpha = false, bool wireframe = false ) const;
// Draw the mesh
void XM_CALLCONV Draw( _In_ ID3D11DeviceContext* deviceContext, FXMMATRIX world, CXMMATRIX view, CXMMATRIX projection,
bool alpha = false, _In_opt_ std::function<void DIRECTX_STD_CALLCONV()> setCustomState = nullptr ) const;
};
//----------------------------------------------------------------------------------
// A model consists of one or more meshes
class Model
{
public:
virtual ~Model();
ModelMesh::Collection meshes;
std::wstring name;
// Draw all the meshes in the model
void XM_CALLCONV Draw( _In_ ID3D11DeviceContext* deviceContext, CommonStates& states, FXMMATRIX world, CXMMATRIX view, CXMMATRIX projection,
bool wireframe = false, _In_opt_ std::function<void DIRECTX_STD_CALLCONV()> setCustomState = nullptr ) const;
// Notify model that effects, parts list, or mesh list has changed
void __cdecl Modified() { mEffectCache.clear(); }
// Update all effects used by the model
void __cdecl UpdateEffects( _In_ std::function<void DIRECTX_STD_CALLCONV(IEffect*)> setEffect );
// Loads a model from a Visual Studio Starter Kit .CMO file
static std::unique_ptr<Model> __cdecl CreateFromCMO( _In_ ID3D11Device* d3dDevice, _In_reads_bytes_(dataSize) const uint8_t* meshData, size_t dataSize,
_In_ IEffectFactory& fxFactory, bool ccw = true, bool pmalpha = false );
static std::unique_ptr<Model> __cdecl CreateFromCMO( _In_ ID3D11Device* d3dDevice, _In_z_ const wchar_t* szFileName,
_In_ IEffectFactory& fxFactory, bool ccw = true, bool pmalpha = false );
// Loads a model from a DirectX SDK .SDKMESH file
static std::unique_ptr<Model> __cdecl CreateFromSDKMESH( _In_ ID3D11Device* d3dDevice, _In_reads_bytes_(dataSize) const uint8_t* meshData, _In_ size_t dataSize,
_In_ IEffectFactory& fxFactory, bool ccw = false, bool pmalpha = false );
static std::unique_ptr<Model> __cdecl CreateFromSDKMESH( _In_ ID3D11Device* d3dDevice, _In_z_ const wchar_t* szFileName,
_In_ IEffectFactory& fxFactory, bool ccw = false, bool pmalpha = false );
// Loads a model from a .VBO file
static std::unique_ptr<Model> __cdecl CreateFromVBO( _In_ ID3D11Device* d3dDevice, _In_reads_bytes_(dataSize) const uint8_t* meshData, _In_ size_t dataSize,
_In_opt_ std::shared_ptr<IEffect> ieffect = nullptr, bool ccw = false, bool pmalpha = false );
static std::unique_ptr<Model> __cdecl CreateFromVBO( _In_ ID3D11Device* d3dDevice, _In_z_ const wchar_t* szFileName,
_In_opt_ std::shared_ptr<IEffect> ieffect = nullptr, bool ccw = false, bool pmalpha = false );
private:
std::set<IEffect*> mEffectCache;
};
}
+129
View File
@@ -0,0 +1,129 @@
//--------------------------------------------------------------------------------------
// File: Mouse.h
//
// THIS CODE AND INFORMATION IS PROVIDED "AS IS" WITHOUT WARRANTY OF
// ANY KIND, EITHER EXPRESSED OR IMPLIED, INCLUDING BUT NOT LIMITED TO
// THE IMPLIED WARRANTIES OF MERCHANTABILITY AND/OR FITNESS FOR A
// PARTICULAR PURPOSE.
//
// Copyright (c) Microsoft Corporation. All rights reserved.
//
// http://go.microsoft.com/fwlink/?LinkId=248929
//--------------------------------------------------------------------------------------
#pragma once
// VS 2010/2012 do not support =default =delete
#ifndef DIRECTX_CTOR_DEFAULT
#if defined(_MSC_VER) && (_MSC_VER < 1800)
#define DIRECTX_CTOR_DEFAULT {}
#define DIRECTX_CTOR_DELETE ;
#else
#define DIRECTX_CTOR_DEFAULT =default;
#define DIRECTX_CTOR_DELETE =delete;
#endif
#endif
#include <memory>
#if defined(WINAPI_FAMILY) && (WINAPI_FAMILY == WINAPI_FAMILY_APP)
namespace ABI { namespace Windows { namespace UI { namespace Core { struct ICoreWindow; } } } }
#endif
namespace DirectX
{
class Mouse
{
public:
Mouse();
Mouse(Mouse&& moveFrom);
Mouse& operator= (Mouse&& moveFrom);
virtual ~Mouse();
enum Mode
{
MODE_ABSOLUTE = 0,
MODE_RELATIVE,
};
struct State
{
bool leftButton;
bool middleButton;
bool rightButton;
bool xButton1;
bool xButton2;
int x;
int y;
int scrollWheelValue;
Mode positionMode;
};
class ButtonStateTracker
{
public:
enum ButtonState
{
UP = 0, // Button is up
HELD = 1, // Button is held down
RELEASED = 2, // Button was just released
PRESSED = 3, // Buton was just pressed
};
ButtonState leftButton;
ButtonState middleButton;
ButtonState rightButton;
ButtonState xButton1;
ButtonState xButton2;
ButtonStateTracker() { Reset(); }
void __cdecl Update( const State& state );
void __cdecl Reset();
private:
State lastState;
};
// Retrieve the current state of the mouse
State __cdecl GetState() const;
// Resets the accumulated scroll wheel value
void __cdecl ResetScrollWheelValue();
// Sets mouse mode (defaults to absolute)
void __cdecl SetMode(Mode mode);
#if !defined(WINAPI_FAMILY) || (WINAPI_FAMILY == WINAPI_FAMILY_DESKTOP_APP) && defined(WM_USER)
void __cdecl SetWindow(HWND window);
static void __cdecl ProcessMessage(UINT message, WPARAM wParam, LPARAM lParam);
#endif
#if defined(WINAPI_FAMILY) && (WINAPI_FAMILY == WINAPI_FAMILY_APP)
void __cdecl SetWindow(ABI::Windows::UI::Core::ICoreWindow* window);
#ifdef __cplusplus_winrt
void __cdecl SetWindow(Windows::UI::Core::CoreWindow^ window)
{
// See https://msdn.microsoft.com/en-us/library/hh755802.aspx
SetWindow(reinterpret_cast<ABI::Windows::UI::Core::ICoreWindow*>(window));
}
#endif
static void __cdecl SetDpi(float dpi);
#endif
// Singleton
static Mouse& __cdecl Get();
private:
// Private implementation.
class Impl;
std::unique_ptr<Impl> pImpl;
// Prevent copying.
Mouse(Mouse const&) DIRECTX_CTOR_DELETE
Mouse& operator=(Mouse const&) DIRECTX_CTOR_DELETE
};
}
+158
View File
@@ -0,0 +1,158 @@
//--------------------------------------------------------------------------------------
// File: PrimitiveBatch.h
//
// THIS CODE AND INFORMATION IS PROVIDED "AS IS" WITHOUT WARRANTY OF
// ANY KIND, EITHER EXPRESSED OR IMPLIED, INCLUDING BUT NOT LIMITED TO
// THE IMPLIED WARRANTIES OF MERCHANTABILITY AND/OR FITNESS FOR A
// PARTICULAR PURPOSE.
//
// Copyright (c) Microsoft Corporation. All rights reserved.
//
// http://go.microsoft.com/fwlink/?LinkId=248929
//--------------------------------------------------------------------------------------
#pragma once
#if defined(_XBOX_ONE) && defined(_TITLE)
#include <d3d11_x.h>
#else
#include <d3d11_1.h>
#endif
// VS 2010/2012 do not support =default =delete
#ifndef DIRECTX_CTOR_DEFAULT
#if defined(_MSC_VER) && (_MSC_VER < 1800)
#define DIRECTX_CTOR_DEFAULT {}
#define DIRECTX_CTOR_DELETE ;
#else
#define DIRECTX_CTOR_DEFAULT =default;
#define DIRECTX_CTOR_DELETE =delete;
#endif
#endif
#include <memory.h>
#include <memory>
#pragma warning(push)
#pragma warning(disable: 4005)
#include <stdint.h>
#pragma warning(pop)
namespace DirectX
{
namespace Internal
{
// Base class, not to be used directly: clients should access this via the derived PrimitiveBatch<T>.
class PrimitiveBatchBase
{
protected:
PrimitiveBatchBase(_In_ ID3D11DeviceContext* deviceContext, size_t maxIndices, size_t maxVertices, size_t vertexSize);
PrimitiveBatchBase(PrimitiveBatchBase&& moveFrom);
PrimitiveBatchBase& operator= (PrimitiveBatchBase&& moveFrom);
virtual ~PrimitiveBatchBase();
public:
// Begin/End a batch of primitive drawing operations.
void __cdecl Begin();
void __cdecl End();
protected:
// Internal, untyped drawing method.
void __cdecl Draw(D3D11_PRIMITIVE_TOPOLOGY topology, bool isIndexed, _In_opt_count_(indexCount) uint16_t const* indices, size_t indexCount, size_t vertexCount, _Out_ void** pMappedVertices);
private:
// Private implementation.
class Impl;
std::unique_ptr<Impl> pImpl;
// Prevent copying.
PrimitiveBatchBase(PrimitiveBatchBase const&) DIRECTX_CTOR_DELETE
PrimitiveBatchBase& operator= (PrimitiveBatchBase const&) DIRECTX_CTOR_DELETE
};
}
// Template makes the API typesafe, eg. PrimitiveBatch<VertexPositionColor>.
template<typename TVertex>
class PrimitiveBatch : public Internal::PrimitiveBatchBase
{
static const size_t DefaultBatchSize = 2048;
public:
PrimitiveBatch(_In_ ID3D11DeviceContext* deviceContext, size_t maxIndices = DefaultBatchSize * 3, size_t maxVertices = DefaultBatchSize)
: PrimitiveBatchBase(deviceContext, maxIndices, maxVertices, sizeof(TVertex))
{ }
PrimitiveBatch(PrimitiveBatch&& moveFrom)
: PrimitiveBatchBase(std::move(moveFrom))
{ }
PrimitiveBatch& __cdecl operator= (PrimitiveBatch&& moveFrom)
{
PrimitiveBatchBase::operator=(std::move(moveFrom));
return *this;
}
// Similar to the D3D9 API DrawPrimitiveUP.
void __cdecl Draw(D3D11_PRIMITIVE_TOPOLOGY topology, _In_reads_(vertexCount) TVertex const* vertices, size_t vertexCount)
{
void* mappedVertices;
PrimitiveBatchBase::Draw(topology, false, nullptr, 0, vertexCount, &mappedVertices);
memcpy(mappedVertices, vertices, vertexCount * sizeof(TVertex));
}
// Similar to the D3D9 API DrawIndexedPrimitiveUP.
void __cdecl DrawIndexed(D3D11_PRIMITIVE_TOPOLOGY topology, _In_reads_(indexCount) uint16_t const* indices, size_t indexCount, _In_reads_(vertexCount) TVertex const* vertices, size_t vertexCount)
{
void* mappedVertices;
PrimitiveBatchBase::Draw(topology, true, indices, indexCount, vertexCount, &mappedVertices);
memcpy(mappedVertices, vertices, vertexCount * sizeof(TVertex));
}
void __cdecl DrawLine(TVertex const& v1, TVertex const& v2)
{
TVertex* mappedVertices;
PrimitiveBatchBase::Draw(D3D11_PRIMITIVE_TOPOLOGY_LINELIST, false, nullptr, 0, 2, reinterpret_cast<void**>(&mappedVertices));
mappedVertices[0] = v1;
mappedVertices[1] = v2;
}
void __cdecl DrawTriangle(TVertex const& v1, TVertex const& v2, TVertex const& v3)
{
TVertex* mappedVertices;
PrimitiveBatchBase::Draw(D3D11_PRIMITIVE_TOPOLOGY_TRIANGLELIST, false, nullptr, 0, 3, reinterpret_cast<void**>(&mappedVertices));
mappedVertices[0] = v1;
mappedVertices[1] = v2;
mappedVertices[2] = v3;
}
void __cdecl DrawQuad(TVertex const& v1, TVertex const& v2, TVertex const& v3, TVertex const& v4)
{
static const uint16_t quadIndices[] = { 0, 1, 2, 0, 2, 3 };
TVertex* mappedVertices;
PrimitiveBatchBase::Draw(D3D11_PRIMITIVE_TOPOLOGY_TRIANGLELIST, true, quadIndices, 6, 4, reinterpret_cast<void**>(&mappedVertices));
mappedVertices[0] = v1;
mappedVertices[1] = v2;
mappedVertices[2] = v3;
mappedVertices[3] = v4;
}
};
}
+64
View File
@@ -0,0 +1,64 @@
//--------------------------------------------------------------------------------------
// File: ScreenGrab.h
//
// Function for capturing a 2D texture and saving it to a file (aka a 'screenshot'
// when used on a Direct3D 11 Render Target).
//
// Note these functions are useful as a light-weight runtime screen grabber. For
// full-featured texture capture, DDS writer, and texture processing pipeline,
// see the 'Texconv' sample and the 'DirectXTex' library.
//
// THIS CODE AND INFORMATION IS PROVIDED "AS IS" WITHOUT WARRANTY OF
// ANY KIND, EITHER EXPRESSED OR IMPLIED, INCLUDING BUT NOT LIMITED TO
// THE IMPLIED WARRANTIES OF MERCHANTABILITY AND/OR FITNESS FOR A
// PARTICULAR PURPOSE.
//
// Copyright (c) Microsoft Corporation. All rights reserved.
//
// http://go.microsoft.com/fwlink/?LinkId=248926
// http://go.microsoft.com/fwlink/?LinkId=248929
//--------------------------------------------------------------------------------------
#pragma once
#if defined(_XBOX_ONE) && defined(_TITLE)
#include <d3d11_x.h>
#else
#include <d3d11_1.h>
#endif
#include <ocidl.h>
#pragma warning(push)
#pragma warning(disable : 4005)
#include <stdint.h>
#pragma warning(pop)
#include <functional>
// VS 2010 doesn't support explicit calling convention for std::function
#ifndef DIRECTX_STD_CALLCONV
#if defined(_MSC_VER) && (_MSC_VER < 1700)
#define DIRECTX_STD_CALLCONV
#else
#define DIRECTX_STD_CALLCONV __cdecl
#endif
#endif
namespace DirectX
{
HRESULT __cdecl SaveDDSTextureToFile( _In_ ID3D11DeviceContext* pContext,
_In_ ID3D11Resource* pSource,
_In_z_ LPCWSTR fileName );
#if !defined(WINAPI_FAMILY) || (WINAPI_FAMILY != WINAPI_FAMILY_PHONE_APP) || (_WIN32_WINNT > _WIN32_WINNT_WIN8)
HRESULT __cdecl SaveWICTextureToFile( _In_ ID3D11DeviceContext* pContext,
_In_ ID3D11Resource* pSource,
_In_ REFGUID guidContainerFormat,
_In_z_ LPCWSTR fileName,
_In_opt_ const GUID* targetFormat = nullptr,
_In_opt_ std::function<void DIRECTX_STD_CALLCONV(IPropertyBag2*)> setCustomProps = nullptr );
#endif
}
+845
View File
@@ -0,0 +1,845 @@
//-------------------------------------------------------------------------------------
// SimpleMath.h -- Simplified C++ Math wrapper for DirectXMath
//
// THIS CODE AND INFORMATION IS PROVIDED "AS IS" WITHOUT WARRANTY OF
// ANY KIND, EITHER EXPRESSED OR IMPLIED, INCLUDING BUT NOT LIMITED TO
// THE IMPLIED WARRANTIES OF MERCHANTABILITY AND/OR FITNESS FOR A
// PARTICULAR PURPOSE.
//
// Copyright (c) Microsoft Corporation. All rights reserved.
//
// http://go.microsoft.com/fwlink/?LinkId=248929
//-------------------------------------------------------------------------------------
#pragma once
#include <functional>
#include <memory.h>
#include <DirectXMath.h>
#include <DirectXPackedVector.h>
#include <DirectXCollision.h>
namespace DirectX
{
namespace SimpleMath
{
struct Vector4;
struct Matrix;
struct Quaternion;
struct Plane;
//------------------------------------------------------------------------------
// 2D vector
struct Vector2 : public XMFLOAT2
{
Vector2() : XMFLOAT2(0.f, 0.f) {}
explicit Vector2(float x) : XMFLOAT2( x, x ) {}
Vector2(float _x, float _y) : XMFLOAT2(_x, _y) {}
explicit Vector2(_In_reads_(2) const float *pArray) : XMFLOAT2(pArray) {}
Vector2(FXMVECTOR V) { XMStoreFloat2( this, V ); }
Vector2(const XMFLOAT2& V) { this->x = V.x; this->y = V.y; }
operator XMVECTOR() const { return XMLoadFloat2( this ); }
// Comparision operators
bool operator == ( const Vector2& V ) const;
bool operator != ( const Vector2& V ) const;
// Assignment operators
Vector2& operator= (const Vector2& V) { x = V.x; y = V.y; return *this; }
Vector2& operator= (const XMFLOAT2& V) { x = V.x; y = V.y; return *this; }
Vector2& operator+= (const Vector2& V);
Vector2& operator-= (const Vector2& V);
Vector2& operator*= (const Vector2& V);
Vector2& operator*= (float S);
Vector2& operator/= (float S);
// Urnary operators
Vector2 operator+ () const { return *this; }
Vector2 operator- () const { return Vector2(-x, -y); }
// Vector operations
bool InBounds( const Vector2& Bounds ) const;
float Length() const;
float LengthSquared() const;
float Dot( const Vector2& V ) const;
void Cross( const Vector2& V, Vector2& result ) const;
Vector2 Cross( const Vector2& V ) const;
void Normalize();
void Normalize( Vector2& result ) const;
void Clamp( const Vector2& vmin, const Vector2& vmax );
void Clamp( const Vector2& vmin, const Vector2& vmax, Vector2& result ) const;
// Static functions
static float Distance( const Vector2& v1, const Vector2& v2 );
static float DistanceSquared( const Vector2& v1, const Vector2& v2 );
static void Min( const Vector2& v1, const Vector2& v2, Vector2& result );
static Vector2 Min( const Vector2& v1, const Vector2& v2 );
static void Max( const Vector2& v1, const Vector2& v2, Vector2& result );
static Vector2 Max( const Vector2& v1, const Vector2& v2 );
static void Lerp( const Vector2& v1, const Vector2& v2, float t, Vector2& result );
static Vector2 Lerp( const Vector2& v1, const Vector2& v2, float t );
static void SmoothStep( const Vector2& v1, const Vector2& v2, float t, Vector2& result );
static Vector2 SmoothStep( const Vector2& v1, const Vector2& v2, float t );
static void Barycentric( const Vector2& v1, const Vector2& v2, const Vector2& v3, float f, float g, Vector2& result );
static Vector2 Barycentric( const Vector2& v1, const Vector2& v2, const Vector2& v3, float f, float g );
static void CatmullRom( const Vector2& v1, const Vector2& v2, const Vector2& v3, const Vector2& v4, float t, Vector2& result );
static Vector2 CatmullRom( const Vector2& v1, const Vector2& v2, const Vector2& v3, const Vector2& v4, float t );
static void Hermite( const Vector2& v1, const Vector2& t1, const Vector2& v2, const Vector2& t2, float t, Vector2& result );
static Vector2 Hermite( const Vector2& v1, const Vector2& t1, const Vector2& v2, const Vector2& t2, float t );
static void Reflect( const Vector2& ivec, const Vector2& nvec, Vector2& result );
static Vector2 Reflect( const Vector2& ivec, const Vector2& nvec );
static void Refract( const Vector2& ivec, const Vector2& nvec, float refractionIndex, Vector2& result );
static Vector2 Refract( const Vector2& ivec, const Vector2& nvec, float refractionIndex );
static void Transform( const Vector2& v, const Quaternion& quat, Vector2& result );
static Vector2 Transform( const Vector2& v, const Quaternion& quat );
static void Transform( const Vector2& v, const Matrix& m, Vector2& result );
static Vector2 Transform( const Vector2& v, const Matrix& m );
static void Transform( _In_reads_(count) const Vector2* varray, size_t count, const Matrix& m, _Out_writes_(count) Vector2* resultArray );
static void Transform( const Vector2& v, const Matrix& m, Vector4& result );
static void Transform( _In_reads_(count) const Vector2* varray, size_t count, const Matrix& m, _Out_writes_(count) Vector4* resultArray );
static void TransformNormal( const Vector2& v, const Matrix& m, Vector2& result );
static Vector2 TransformNormal( const Vector2& v, const Matrix& m );
static void TransformNormal( _In_reads_(count) const Vector2* varray, size_t count, const Matrix& m, _Out_writes_(count) Vector2* resultArray );
// Constants
static const Vector2 Zero;
static const Vector2 One;
static const Vector2 UnitX;
static const Vector2 UnitY;
};
// Binary operators
Vector2 operator+ (const Vector2& V1, const Vector2& V2);
Vector2 operator- (const Vector2& V1, const Vector2& V2);
Vector2 operator* (const Vector2& V1, const Vector2& V2);
Vector2 operator* (const Vector2& V, float S);
Vector2 operator/ (const Vector2& V1, const Vector2& V2);
Vector2 operator* (float S, const Vector2& V);
//------------------------------------------------------------------------------
// 3D vector
struct Vector3 : public XMFLOAT3
{
Vector3() : XMFLOAT3(0.f, 0.f, 0.f) {}
explicit Vector3(float x) : XMFLOAT3( x, x, x ) {}
Vector3(float _x, float _y, float _z) : XMFLOAT3(_x, _y, _z) {}
explicit Vector3(_In_reads_(3) const float *pArray) : XMFLOAT3(pArray) {}
Vector3(FXMVECTOR V) { XMStoreFloat3( this, V ); }
Vector3(const XMFLOAT3& V) { this->x = V.x; this->y = V.y; this->z = V.z; }
operator XMVECTOR() const { return XMLoadFloat3( this ); }
// Comparision operators
bool operator == ( const Vector3& V ) const;
bool operator != ( const Vector3& V ) const;
// Assignment operators
Vector3& operator= (const Vector3& V) { x = V.x; y = V.y; z = V.z; return *this; }
Vector3& operator= (const XMFLOAT3& V) { x = V.x; y = V.y; z = V.z; return *this; }
Vector3& operator+= (const Vector3& V);
Vector3& operator-= (const Vector3& V);
Vector3& operator*= (const Vector3& V);
Vector3& operator*= (float S);
Vector3& operator/= (float S);
// Urnary operators
Vector3 operator+ () const { return *this; }
Vector3 operator- () const;
// Vector operations
bool InBounds( const Vector3& Bounds ) const;
float Length() const;
float LengthSquared() const;
float Dot( const Vector3& V ) const;
void Cross( const Vector3& V, Vector3& result ) const;
Vector3 Cross( const Vector3& V ) const;
void Normalize();
void Normalize( Vector3& result ) const;
void Clamp( const Vector3& vmin, const Vector3& vmax );
void Clamp( const Vector3& vmin, const Vector3& vmax, Vector3& result ) const;
// Static functions
static float Distance( const Vector3& v1, const Vector3& v2 );
static float DistanceSquared( const Vector3& v1, const Vector3& v2 );
static void Min( const Vector3& v1, const Vector3& v2, Vector3& result );
static Vector3 Min( const Vector3& v1, const Vector3& v2 );
static void Max( const Vector3& v1, const Vector3& v2, Vector3& result );
static Vector3 Max( const Vector3& v1, const Vector3& v2 );
static void Lerp( const Vector3& v1, const Vector3& v2, float t, Vector3& result );
static Vector3 Lerp( const Vector3& v1, const Vector3& v2, float t );
static void SmoothStep( const Vector3& v1, const Vector3& v2, float t, Vector3& result );
static Vector3 SmoothStep( const Vector3& v1, const Vector3& v2, float t );
static void Barycentric( const Vector3& v1, const Vector3& v2, const Vector3& v3, float f, float g, Vector3& result );
static Vector3 Barycentric( const Vector3& v1, const Vector3& v2, const Vector3& v3, float f, float g );
static void CatmullRom( const Vector3& v1, const Vector3& v2, const Vector3& v3, const Vector3& v4, float t, Vector3& result );
static Vector3 CatmullRom( const Vector3& v1, const Vector3& v2, const Vector3& v3, const Vector3& v4, float t );
static void Hermite( const Vector3& v1, const Vector3& t1, const Vector3& v2, const Vector3& t2, float t, Vector3& result );
static Vector3 Hermite( const Vector3& v1, const Vector3& t1, const Vector3& v2, const Vector3& t2, float t );
static void Reflect( const Vector3& ivec, const Vector3& nvec, Vector3& result );
static Vector3 Reflect( const Vector3& ivec, const Vector3& nvec );
static void Refract( const Vector3& ivec, const Vector3& nvec, float refractionIndex, Vector3& result );
static Vector3 Refract( const Vector3& ivec, const Vector3& nvec, float refractionIndex );
static void Transform( const Vector3& v, const Quaternion& quat, Vector3& result );
static Vector3 Transform( const Vector3& v, const Quaternion& quat );
static void Transform( const Vector3& v, const Matrix& m, Vector3& result );
static Vector3 Transform( const Vector3& v, const Matrix& m );
static void Transform( _In_reads_(count) const Vector3* varray, size_t count, const Matrix& m, _Out_writes_(count) Vector3* resultArray );
static void Transform( const Vector3& v, const Matrix& m, Vector4& result );
static void Transform( _In_reads_(count) const Vector3* varray, size_t count, const Matrix& m, _Out_writes_(count) Vector4* resultArray );
static void TransformNormal( const Vector3& v, const Matrix& m, Vector3& result );
static Vector3 TransformNormal( const Vector3& v, const Matrix& m );
static void TransformNormal( _In_reads_(count) const Vector3* varray, size_t count, const Matrix& m, _Out_writes_(count) Vector3* resultArray );
// Constants
static const Vector3 Zero;
static const Vector3 One;
static const Vector3 UnitX;
static const Vector3 UnitY;
static const Vector3 UnitZ;
static const Vector3 Up;
static const Vector3 Down;
static const Vector3 Right;
static const Vector3 Left;
static const Vector3 Forward;
static const Vector3 Backward;
};
// Binary operators
Vector3 operator+ (const Vector3& V1, const Vector3& V2);
Vector3 operator- (const Vector3& V1, const Vector3& V2);
Vector3 operator* (const Vector3& V1, const Vector3& V2);
Vector3 operator* (const Vector3& V, float S);
Vector3 operator/ (const Vector3& V1, const Vector3& V2);
Vector3 operator* (float S, const Vector3& V);
//------------------------------------------------------------------------------
// 4D vector
struct Vector4 : public XMFLOAT4
{
Vector4() : XMFLOAT4(0.f, 0.f, 0.f, 0.f) {}
explicit Vector4(float x) : XMFLOAT4( x, x, x, x ) {}
Vector4(float _x, float _y, float _z, float _w) : XMFLOAT4(_x, _y, _z, _w) {}
explicit Vector4(_In_reads_(4) const float *pArray) : XMFLOAT4(pArray) {}
Vector4(FXMVECTOR V) { XMStoreFloat4( this, V ); }
Vector4(const XMFLOAT4& V) { this->x = V.x; this->y = V.y; this->z = V.z; this->w = V.w; }
operator XMVECTOR() const { return XMLoadFloat4( this ); }
// Comparision operators
bool operator == ( const Vector4& V ) const;
bool operator != ( const Vector4& V ) const;
// Assignment operators
Vector4& operator= (const Vector4& V) { x = V.x; y = V.y; z = V.z; w = V.w; return *this; }
Vector4& operator= (const XMFLOAT4& V) { x = V.x; y = V.y; z = V.z; w = V.w; return *this; }
Vector4& operator+= (const Vector4& V);
Vector4& operator-= (const Vector4& V);
Vector4& operator*= (const Vector4& V);
Vector4& operator*= (float S);
Vector4& operator/= (float S);
// Urnary operators
Vector4 operator+ () const { return *this; }
Vector4 operator- () const;
// Vector operations
bool InBounds( const Vector4& Bounds ) const;
float Length() const;
float LengthSquared() const;
float Dot( const Vector4& V ) const;
void Cross( const Vector4& v1, const Vector4& v2, Vector4& result ) const;
Vector4 Cross( const Vector4& v1, const Vector4& v2 ) const;
void Normalize();
void Normalize( Vector4& result ) const;
void Clamp( const Vector4& vmin, const Vector4& vmax );
void Clamp( const Vector4& vmin, const Vector4& vmax, Vector4& result ) const;
// Static functions
static float Distance( const Vector4& v1, const Vector4& v2 );
static float DistanceSquared( const Vector4& v1, const Vector4& v2 );
static void Min( const Vector4& v1, const Vector4& v2, Vector4& result );
static Vector4 Min( const Vector4& v1, const Vector4& v2 );
static void Max( const Vector4& v1, const Vector4& v2, Vector4& result );
static Vector4 Max( const Vector4& v1, const Vector4& v2 );
static void Lerp( const Vector4& v1, const Vector4& v2, float t, Vector4& result );
static Vector4 Lerp( const Vector4& v1, const Vector4& v2, float t );
static void SmoothStep( const Vector4& v1, const Vector4& v2, float t, Vector4& result );
static Vector4 SmoothStep( const Vector4& v1, const Vector4& v2, float t );
static void Barycentric( const Vector4& v1, const Vector4& v2, const Vector4& v3, float f, float g, Vector4& result );
static Vector4 Barycentric( const Vector4& v1, const Vector4& v2, const Vector4& v3, float f, float g );
static void CatmullRom( const Vector4& v1, const Vector4& v2, const Vector4& v3, const Vector4& v4, float t, Vector4& result );
static Vector4 CatmullRom( const Vector4& v1, const Vector4& v2, const Vector4& v3, const Vector4& v4, float t );
static void Hermite( const Vector4& v1, const Vector4& t1, const Vector4& v2, const Vector4& t2, float t, Vector4& result );
static Vector4 Hermite( const Vector4& v1, const Vector4& t1, const Vector4& v2, const Vector4& t2, float t );
static void Reflect( const Vector4& ivec, const Vector4& nvec, Vector4& result );
static Vector4 Reflect( const Vector4& ivec, const Vector4& nvec );
static void Refract( const Vector4& ivec, const Vector4& nvec, float refractionIndex, Vector4& result );
static Vector4 Refract( const Vector4& ivec, const Vector4& nvec, float refractionIndex );
static void Transform( const Vector2& v, const Quaternion& quat, Vector4& result );
static Vector4 Transform( const Vector2& v, const Quaternion& quat );
static void Transform( const Vector3& v, const Quaternion& quat, Vector4& result );
static Vector4 Transform( const Vector3& v, const Quaternion& quat );
static void Transform( const Vector4& v, const Quaternion& quat, Vector4& result );
static Vector4 Transform( const Vector4& v, const Quaternion& quat );
static void Transform( const Vector4& v, const Matrix& m, Vector4& result );
static Vector4 Transform( const Vector4& v, const Matrix& m );
static void Transform( _In_reads_(count) const Vector4* varray, size_t count, const Matrix& m, _Out_writes_(count) Vector4* resultArray );
// Constants
static const Vector4 Zero;
static const Vector4 One;
static const Vector4 UnitX;
static const Vector4 UnitY;
static const Vector4 UnitZ;
static const Vector4 UnitW;
};
// Binary operators
Vector4 operator+ (const Vector4& V1, const Vector4& V2);
Vector4 operator- (const Vector4& V1, const Vector4& V2);
Vector4 operator* (const Vector4& V1, const Vector4& V2);
Vector4 operator* (const Vector4& V, float S);
Vector4 operator/ (const Vector4& V1, const Vector4& V2);
Vector4 operator* (float S, const Vector4& V);
//------------------------------------------------------------------------------
// 4x4 Matrix (assumes right-handed cooordinates)
struct Matrix : public XMFLOAT4X4
{
Matrix() : XMFLOAT4X4( 1.f, 0, 0, 0,
0, 1.f, 0, 0,
0, 0, 1.f, 0,
0, 0, 0, 1.f ) {}
Matrix(float m00, float m01, float m02, float m03,
float m10, float m11, float m12, float m13,
float m20, float m21, float m22, float m23,
float m30, float m31, float m32, float m33) : XMFLOAT4X4(m00, m01, m02, m03,
m10, m11, m12, m13,
m20, m21, m22, m23,
m30, m31, m32, m33) {}
explicit Matrix( const Vector3& r0, const Vector3& r1, const Vector3& r2 ) : XMFLOAT4X4( r0.x, r0.y, r0.z, 0,
r1.x, r1.y, r1.z, 0,
r2.x, r2.y, r2.z, 0,
0, 0, 0, 1.f ) {}
explicit Matrix( const Vector4& r0, const Vector4& r1, const Vector4& r2, const Vector4& r3 ) : XMFLOAT4X4( r0.x, r0.y, r0.z, r0.w,
r1.x, r1.y, r1.z, r1.w,
r2.x, r2.y, r2.z, r2.w,
r3.x, r3.y, r3.z, r3.w ) {}
Matrix(const XMFLOAT4X4& M) { memcpy_s(this, sizeof(float)*16, &M, sizeof(XMFLOAT4X4)); }
explicit Matrix(_In_reads_(16) const float *pArray) : XMFLOAT4X4(pArray) {}
Matrix( CXMMATRIX M ) { XMStoreFloat4x4( this, M ); }
operator XMMATRIX() const { return XMLoadFloat4x4( this ); }
// Comparision operators
bool operator == ( const Matrix& M ) const;
bool operator != ( const Matrix& M ) const;
// Assignment operators
Matrix& operator= (const Matrix& M) { memcpy_s( this, sizeof(float)*16, &M, sizeof(float)*16 ); return *this; }
Matrix& operator= (const XMFLOAT4X4& M) { memcpy_s( this, sizeof(float)*16, &M, sizeof(XMFLOAT4X4) ); return *this; }
Matrix& operator+= (const Matrix& M);
Matrix& operator-= (const Matrix& M);
Matrix& operator*= (const Matrix& M);
Matrix& operator*= (float S);
Matrix& operator/= (float S);
Matrix& operator/= (const Matrix& M);
// Element-wise divide
// Urnary operators
Matrix operator+ () const { return *this; }
Matrix operator- () const;
// Properties
Vector3 Up() const { return Vector3( _21, _22, _23); }
void Up( const Vector3& v ) { _21 = v.x; _22 = v.y; _23 = v.z; }
Vector3 Down() const { return Vector3( -_21, -_22, -_23); }
void Down( const Vector3& v ) { _21 = -v.x; _22 = -v.y; _23 = -v.z; }
Vector3 Right() const { return Vector3( _11, _12, _13 ); }
void Right( const Vector3& v ) { _11 = v.x; _12 = v.y; _13 = v.z; }
Vector3 Left() const { return Vector3( -_11, -_12, -_13 ); }
void Left( const Vector3& v ) { _11 = -v.x; _12 = -v.y; _13 = -v.z; }
Vector3 Forward() const { return Vector3( -_31, -_32, -_33 ); }
void Forward( const Vector3& v ) { _31 = -v.x; _32 = -v.y; _33 = -v.z; }
Vector3 Backward() const { return Vector3( _31, _32, _33 ); }
void Backward( const Vector3& v ) { _31 = v.x; _32 = v.y; _33 = v.z; }
Vector3 Translation() const { return Vector3( _41, _42, _43 ); }
void Translation( const Vector3& v ) { _41 = v.x; _42 = v.y; _43 = v.z; }
// Matrix operations
bool Decompose( Vector3& scale, Quaternion& rotation, Vector3& translation );
Matrix Transpose() const;
void Transpose( Matrix& result ) const;
Matrix Invert() const;
void Invert( Matrix& result ) const;
float Determinant() const;
// Static functions
static Matrix CreateBillboard( const Vector3& object, const Vector3& cameraPosition, const Vector3& cameraUp, _In_opt_ const Vector3* cameraForward = nullptr );
static Matrix CreateConstrainedBillboard( const Vector3& object, const Vector3& cameraPosition, const Vector3& rotateAxis,
_In_opt_ const Vector3* cameraForward = nullptr, _In_opt_ const Vector3* objectForward = nullptr);
static Matrix CreateTranslation( const Vector3& position );
static Matrix CreateTranslation( float x, float y, float z );
static Matrix CreateScale( const Vector3& scales );
static Matrix CreateScale( float xs, float ys, float zs );
static Matrix CreateScale( float scale );
static Matrix CreateRotationX( float radians );
static Matrix CreateRotationY( float radians );
static Matrix CreateRotationZ( float radians );
static Matrix CreateFromAxisAngle( const Vector3& axis, float angle );
static Matrix CreatePerspectiveFieldOfView( float fov, float aspectRatio, float nearPlane, float farPlane );
static Matrix CreatePerspective( float width, float height, float nearPlane, float farPlane );
static Matrix CreatePerspectiveOffCenter( float left, float right, float bottom, float top, float nearPlane, float farPlane );
static Matrix CreateOrthographic( float width, float height, float zNearPlane, float zFarPlane );
static Matrix CreateOrthographicOffCenter( float left, float right, float bottom, float top, float zNearPlane, float zFarPlane );
static Matrix CreateLookAt( const Vector3& position, const Vector3& target, const Vector3& up );
static Matrix CreateWorld( const Vector3& position, const Vector3& forward, const Vector3& up );
static Matrix CreateFromQuaternion( const Quaternion& quat );
static Matrix CreateFromYawPitchRoll( float yaw, float pitch, float roll );
static Matrix CreateShadow( const Vector3& lightDir, const Plane& plane );
static Matrix CreateReflection( const Plane& plane );
static void Lerp( const Matrix& M1, const Matrix& M2, float t, Matrix& result );
static Matrix Lerp( const Matrix& M1, const Matrix& M2, float t );
static void Transform( const Matrix& M, const Quaternion& rotation, Matrix& result );
static Matrix Transform( const Matrix& M, const Quaternion& rotation );
// Constants
static const Matrix Identity;
};
// Binary operators
Matrix operator+ (const Matrix& M1, const Matrix& M2);
Matrix operator- (const Matrix& M1, const Matrix& M2);
Matrix operator* (const Matrix& M1, const Matrix& M2);
Matrix operator* (const Matrix& M, float S);
Matrix operator/ (const Matrix& M, float S);
Matrix operator/ (const Matrix& M1, const Matrix& M2);
// Element-wise divide
Matrix operator* (float S, const Matrix& M);
//-----------------------------------------------------------------------------
// Plane
struct Plane : public XMFLOAT4
{
Plane() : XMFLOAT4(0.f, 1.f, 0.f, 0.f) {}
Plane(float _x, float _y, float _z, float _w) : XMFLOAT4(_x, _y, _z, _w) {}
Plane(const Vector3& normal, float d) : XMFLOAT4(normal.x, normal.y, normal.z, d) {}
Plane(const Vector3& point1, const Vector3& point2, const Vector3& point3 );
Plane(const Vector3& point, const Vector3& normal);
explicit Plane(const Vector4& v) : XMFLOAT4(v.x, v.y, v.z, v.w) {}
explicit Plane(_In_reads_(4) const float *pArray) : XMFLOAT4(pArray) {}
Plane(FXMVECTOR V) { XMStoreFloat4( this, V ); }
Plane(const XMFLOAT4& p) { this->x = p.x; this->y = p.y; this->z = p.z; this->w = p.w; }
operator XMVECTOR() const { return XMLoadFloat4( this ); }
// Comparision operators
bool operator == ( const Plane& p ) const;
bool operator != ( const Plane& p ) const;
// Assignment operators
Plane& operator= (const Plane& p) { x = p.x; y = p.y; z = p.z; w = p.w; return *this; }
Plane& operator= (const XMFLOAT4& p) { x = p.x; y = p.y; z = p.z; w = p.w; return *this; }
// Properties
Vector3 Normal() const { return Vector3( x, y, z ); }
void Normal( const Vector3& normal ) { x = normal.x; y = normal.y; z = normal.z; }
float D() const { return w; }
void D(float d) { w = d; }
// Plane operations
void Normalize();
void Normalize( Plane& result ) const;
float Dot( const Vector4& v ) const;
float DotCoordinate( const Vector3& position ) const;
float DotNormal( const Vector3& normal ) const;
// Static functions
static void Transform( const Plane& plane, const Matrix& M, Plane& result );
static Plane Transform( const Plane& plane, const Matrix& M );
static void Transform( const Plane& plane, const Quaternion& rotation, Plane& result );
static Plane Transform( const Plane& plane, const Quaternion& rotation );
// Input quaternion must be the inverse transpose of the transformation
};
//------------------------------------------------------------------------------
// Quaternion
struct Quaternion : public XMFLOAT4
{
Quaternion() : XMFLOAT4(0, 0, 0, 1.f) {}
Quaternion( float _x, float _y, float _z, float _w ) : XMFLOAT4(_x, _y, _z, _w) {}
Quaternion( const Vector3& v, float scalar ) : XMFLOAT4( v.x, v.y, v.z, scalar ) {}
explicit Quaternion( const Vector4& v ) : XMFLOAT4( v.x, v.y, v.z, v.w ) {}
explicit Quaternion(_In_reads_(4) const float *pArray) : XMFLOAT4(pArray) {}
Quaternion(FXMVECTOR V) { XMStoreFloat4( this, V ); }
Quaternion(const XMFLOAT4& q) { this->x = q.x; this->y = q.y; this->z = q.z; this->w = q.w; }
operator XMVECTOR() const { return XMLoadFloat4( this ); }
// Comparision operators
bool operator == ( const Quaternion& q ) const;
bool operator != ( const Quaternion& q ) const;
// Assignment operators
Quaternion& operator= (const Quaternion& q) { x = q.x; y = q.y; z = q.z; w = q.w; return *this; }
Quaternion& operator= (const XMFLOAT4& q) { x = q.x; y = q.y; z = q.z; w = q.w; return *this; }
Quaternion& operator+= (const Quaternion& q);
Quaternion& operator-= (const Quaternion& q);
Quaternion& operator*= (const Quaternion& q);
Quaternion& operator*= (float S);
Quaternion& operator/= (const Quaternion& q);
// Urnary operators
Quaternion operator+ () const { return *this; }
Quaternion operator- () const;
// Quaternion operations
float Length() const;
float LengthSquared() const;
void Normalize();
void Normalize( Quaternion& result ) const;
void Conjugate();
void Conjugate( Quaternion& result ) const;
void Inverse( Quaternion& result ) const;
float Dot( const Quaternion& Q ) const;
// Static functions
static Quaternion CreateFromAxisAngle( const Vector3& axis, float angle );
static Quaternion CreateFromYawPitchRoll( float yaw, float pitch, float roll );
static Quaternion CreateFromRotationMatrix( const Matrix& M );
static void Lerp( const Quaternion& q1, const Quaternion& q2, float t, Quaternion& result );
static Quaternion Lerp( const Quaternion& q1, const Quaternion& q2, float t );
static void Slerp( const Quaternion& q1, const Quaternion& q2, float t, Quaternion& result );
static Quaternion Slerp( const Quaternion& q1, const Quaternion& q2, float t );
static void Concatenate( const Quaternion& q1, const Quaternion& q2, Quaternion& result );
static Quaternion Concatenate( const Quaternion& q1, const Quaternion& q2 );
// Constants
static const Quaternion Identity;
};
// Binary operators
Quaternion operator+ (const Quaternion& Q1, const Quaternion& Q2);
Quaternion operator- (const Quaternion& Q1, const Quaternion& Q2);
Quaternion operator* (const Quaternion& Q1, const Quaternion& Q2);
Quaternion operator* (const Quaternion& Q, float S);
Quaternion operator/ (const Quaternion& Q1, const Quaternion& Q2);
Quaternion operator* (float S, const Quaternion& Q);
//------------------------------------------------------------------------------
// Color
struct Color : public XMFLOAT4
{
Color() : XMFLOAT4(0, 0, 0, 1.f) {}
Color( float _r, float _g, float _b ) : XMFLOAT4(_r, _g, _b, 1.f) {}
Color( float _r, float _g, float _b, float _a ) : XMFLOAT4(_r, _g, _b, _a) {}
explicit Color( const Vector3& clr ) : XMFLOAT4( clr.x, clr.y, clr.z, 1.f ) {}
explicit Color( const Vector4& clr ) : XMFLOAT4( clr.x, clr.y, clr.z, clr.w ) {}
explicit Color(_In_reads_(4) const float *pArray) : XMFLOAT4(pArray) {}
Color(FXMVECTOR V) { XMStoreFloat4( this, V ); }
Color(const XMFLOAT4& c) { this->x = c.x; this->y = c.y; this->z = c.z; this->w = c.w; }
explicit Color( const DirectX::PackedVector::XMCOLOR& Packed );
// BGRA Direct3D 9 D3DCOLOR packed color
explicit Color( const DirectX::PackedVector::XMUBYTEN4& Packed );
// RGBA XNA Game Studio packed color
operator XMVECTOR() const { return XMLoadFloat4( this ); }
operator const float*() const { return reinterpret_cast<const float*>(this); }
// Comparision operators
bool operator == ( const Color& c ) const;
bool operator != ( const Color& c ) const;
// Assignment operators
Color& operator= (const Color& c) { x = c.x; y = c.y; z = c.z; w = c.w; return *this; }
Color& operator= (const XMFLOAT4& c) { x = c.x; y = c.y; z = c.z; w = c.w; return *this; }
Color& operator+= (const Color& c);
Color& operator-= (const Color& c);
Color& operator*= (const Color& c);
Color& operator*= (float S);
Color& operator/= (const Color& c);
// Urnary operators
Color operator+ () const { return *this; }
Color operator- () const;
// Properties
float R() const { return x; }
void R(float r) { x = r; }
float G() const { return y; }
void G(float g) { y = g; }
float B() const { return z; }
void B(float b) { z = b; }
float A() const { return w; }
void A(float a) { w = a; }
// Color operations
DirectX::PackedVector::XMCOLOR BGRA() const;
DirectX::PackedVector::XMUBYTEN4 RGBA() const;
Vector3 ToVector3() const;
Vector4 ToVector4() const;
void Negate();
void Negate( Color& result ) const;
void Saturate();
void Saturate( Color& result ) const;
void Premultiply();
void Premultiply( Color& result ) const;
void AdjustSaturation( float sat );
void AdjustSaturation( float sat, Color& result ) const;
void AdjustContrast( float contrast );
void AdjustContrast( float contrast, Color& result ) const;
// Static functions
static void Modulate( const Color& c1, const Color& c2, Color& result );
static Color Modulate( const Color& c1, const Color& c2 );
static void Lerp( const Color& c1, const Color& c2, float t, Color& result );
static Color Lerp( const Color& c1, const Color& c2, float t );
};
// Binary operators
Color operator+ (const Color& C1, const Color& C2);
Color operator- (const Color& C1, const Color& C2);
Color operator* (const Color& C1, const Color& C2);
Color operator* (const Color& C, float S);
Color operator/ (const Color& C1, const Color& C2);
Color operator* (float S, const Color& C);
//------------------------------------------------------------------------------
// Ray
class Ray
{
public:
Vector3 position;
Vector3 direction;
Ray() : position(0,0,0), direction(0,0,1) {}
Ray( const Vector3& pos, const Vector3& dir ) : position(pos), direction(dir) {}
// Comparision operators
bool operator == ( const Ray& r ) const;
bool operator != ( const Ray& r ) const;
// Ray operations
bool Intersects( const BoundingSphere& sphere, _Out_ float& Dist ) const;
bool Intersects( const BoundingBox& box, _Out_ float& Dist ) const;
bool Intersects( const Vector3& tri0, const Vector3& tri1, const Vector3& tri2, _Out_ float& Dist ) const;
bool Intersects( const Plane& plane, _Out_ float& Dist ) const;
};
#include "SimpleMath.inl"
}; // namespace SimpleMath
}; // namespace DirectX
//------------------------------------------------------------------------------
// Support for SimpleMath and Standard C++ Library containers
namespace std
{
template<> struct less<DirectX::SimpleMath::Vector2>
{
bool operator()(const DirectX::SimpleMath::Vector2& V1, const DirectX::SimpleMath::Vector2& V2) const
{
return ( (V1.x < V2.x) || ((V1.x == V2.x) && (V1.y < V2.y)) );
}
};
template<> struct less<DirectX::SimpleMath::Vector3>
{
bool operator()(const DirectX::SimpleMath::Vector3& V1, const DirectX::SimpleMath::Vector3& V2) const
{
return ( (V1.x < V2.x)
|| ((V1.x == V2.x) && (V1.y < V2.y))
|| ((V1.x == V2.x) && (V1.y == V2.y) && (V1.z < V2.z)) );
}
};
template<> struct less<DirectX::SimpleMath::Vector4>
{
bool operator()(const DirectX::SimpleMath::Vector4& V1, const DirectX::SimpleMath::Vector4& V2) const
{
return ( (V1.x < V2.x)
|| ((V1.x == V2.x) && (V1.y < V2.y))
|| ((V1.x == V2.x) && (V1.y == V2.y) && (V1.z < V2.z))
|| ((V1.x == V2.x) && (V1.y == V2.y) && (V1.z == V2.z) && (V1.w < V2.w)) );
}
};
template<> struct less<DirectX::SimpleMath::Matrix>
{
bool operator()(const DirectX::SimpleMath::Matrix& M1, const DirectX::SimpleMath::Matrix& M2) const
{
if (M1._11 != M2._11) return M1._11 < M2._11;
if (M1._12 != M2._12) return M1._12 < M2._12;
if (M1._13 != M2._13) return M1._13 < M2._13;
if (M1._14 != M2._14) return M1._14 < M2._14;
if (M1._21 != M2._21) return M1._21 < M2._21;
if (M1._22 != M2._22) return M1._22 < M2._22;
if (M1._23 != M2._23) return M1._23 < M2._23;
if (M1._24 != M2._24) return M1._24 < M2._24;
if (M1._31 != M2._31) return M1._31 < M2._31;
if (M1._32 != M2._32) return M1._32 < M2._32;
if (M1._33 != M2._33) return M1._33 < M2._33;
if (M1._34 != M2._34) return M1._34 < M2._34;
if (M1._41 != M2._41) return M1._41 < M2._41;
if (M1._42 != M2._42) return M1._42 < M2._42;
if (M1._43 != M2._43) return M1._43 < M2._43;
if (M1._44 != M2._44) return M1._44 < M2._44;
return false;
}
};
template<> struct less<DirectX::SimpleMath::Plane>
{
bool operator()(const DirectX::SimpleMath::Plane& P1, const DirectX::SimpleMath::Plane& P2) const
{
return ( (P1.x < P2.x)
|| ((P1.x == P2.x) && (P1.y < P2.y))
|| ((P1.x == P2.x) && (P1.y == P2.y) && (P1.z < P2.z))
|| ((P1.x == P2.x) && (P1.y == P2.y) && (P1.z == P2.z) && (P1.w < P2.w)) );
}
};
template<> struct less<DirectX::SimpleMath::Quaternion>
{
bool operator()(const DirectX::SimpleMath::Quaternion& Q1, const DirectX::SimpleMath::Quaternion& Q2) const
{
return ( (Q1.x < Q2.x)
|| ((Q1.x == Q2.x) && (Q1.y < Q2.y))
|| ((Q1.x == Q2.x) && (Q1.y == Q2.y) && (Q1.z < Q2.z))
|| ((Q1.x == Q2.x) && (Q1.y == Q2.y) && (Q1.z == Q2.z) && (Q1.w < Q2.w)) );
}
};
template<> struct less<DirectX::SimpleMath::Color>
{
bool operator()(const DirectX::SimpleMath::Color& C1, const DirectX::SimpleMath::Color& C2) const
{
return ( (C1.x < C2.x)
|| ((C1.x == C2.x) && (C1.y < C2.y))
|| ((C1.x == C2.x) && (C1.y == C2.y) && (C1.z < C2.z))
|| ((C1.x == C2.x) && (C1.y == C2.y) && (C1.z == C2.z) && (C1.w < C2.w)) );
}
};
template<> struct less<DirectX::SimpleMath::Ray>
{
bool operator()(const DirectX::SimpleMath::Ray& R1, const DirectX::SimpleMath::Ray& R2) const
{
if (R1.position.x != R2.position.x) return R1.position.x < R2.position.x;
if (R1.position.y != R2.position.y) return R1.position.y < R2.position.y;
if (R1.position.z != R2.position.z) return R1.position.z < R2.position.z;
if (R1.direction.x != R2.direction.x) return R1.direction.x < R2.direction.x;
if (R1.direction.y != R2.direction.y) return R1.direction.y < R2.direction.y;
if (R1.direction.z != R2.direction.z) return R1.direction.z < R2.direction.z;
return false;
}
};
} // namespace std
File diff suppressed because it is too large Load Diff
+121
View File
@@ -0,0 +1,121 @@
//--------------------------------------------------------------------------------------
// File: SpriteBatch.h
//
// THIS CODE AND INFORMATION IS PROVIDED "AS IS" WITHOUT WARRANTY OF
// ANY KIND, EITHER EXPRESSED OR IMPLIED, INCLUDING BUT NOT LIMITED TO
// THE IMPLIED WARRANTIES OF MERCHANTABILITY AND/OR FITNESS FOR A
// PARTICULAR PURPOSE.
//
// Copyright (c) Microsoft Corporation. All rights reserved.
//
// http://go.microsoft.com/fwlink/?LinkId=248929
//--------------------------------------------------------------------------------------
#pragma once
#if defined(_XBOX_ONE) && defined(_TITLE)
#include <d3d11_x.h>
#else
#include <d3d11_1.h>
#endif
// VS 2010/2012 do not support =default =delete
#ifndef DIRECTX_CTOR_DEFAULT
#if defined(_MSC_VER) && (_MSC_VER < 1800)
#define DIRECTX_CTOR_DEFAULT {}
#define DIRECTX_CTOR_DELETE ;
#else
#define DIRECTX_CTOR_DEFAULT =default;
#define DIRECTX_CTOR_DELETE =delete;
#endif
#endif
#include <DirectXMath.h>
#include <DirectXColors.h>
#include <functional>
#include <memory>
// VS 2010 doesn't support explicit calling convention for std::function
#ifndef DIRECTX_STD_CALLCONV
#if defined(_MSC_VER) && (_MSC_VER < 1700)
#define DIRECTX_STD_CALLCONV
#else
#define DIRECTX_STD_CALLCONV __cdecl
#endif
#endif
namespace DirectX
{
#if (DIRECTX_MATH_VERSION < 305) && !defined(XM_CALLCONV)
#define XM_CALLCONV __fastcall
typedef const XMVECTOR& HXMVECTOR;
typedef const XMMATRIX& FXMMATRIX;
#endif
enum SpriteSortMode
{
SpriteSortMode_Deferred,
SpriteSortMode_Immediate,
SpriteSortMode_Texture,
SpriteSortMode_BackToFront,
SpriteSortMode_FrontToBack,
};
enum SpriteEffects
{
SpriteEffects_None = 0,
SpriteEffects_FlipHorizontally = 1,
SpriteEffects_FlipVertically = 2,
SpriteEffects_FlipBoth = SpriteEffects_FlipHorizontally | SpriteEffects_FlipVertically,
};
class SpriteBatch
{
public:
explicit SpriteBatch(_In_ ID3D11DeviceContext* deviceContext);
SpriteBatch(SpriteBatch&& moveFrom);
SpriteBatch& operator= (SpriteBatch&& moveFrom);
virtual ~SpriteBatch();
// Begin/End a batch of sprite drawing operations.
void XM_CALLCONV Begin(SpriteSortMode sortMode = SpriteSortMode_Deferred, _In_opt_ ID3D11BlendState* blendState = nullptr, _In_opt_ ID3D11SamplerState* samplerState = nullptr, _In_opt_ ID3D11DepthStencilState* depthStencilState = nullptr, _In_opt_ ID3D11RasterizerState* rasterizerState = nullptr,
_In_opt_ std::function<void DIRECTX_STD_CALLCONV()> setCustomShaders = nullptr, FXMMATRIX transformMatrix = MatrixIdentity);
void __cdecl End();
// Draw overloads specifying position, origin and scale as XMFLOAT2.
void XM_CALLCONV Draw(_In_ ID3D11ShaderResourceView* texture, XMFLOAT2 const& position, FXMVECTOR color = Colors::White);
void XM_CALLCONV Draw(_In_ ID3D11ShaderResourceView* texture, XMFLOAT2 const& position, _In_opt_ RECT const* sourceRectangle, FXMVECTOR color = Colors::White, float rotation = 0, XMFLOAT2 const& origin = Float2Zero, float scale = 1, SpriteEffects effects = SpriteEffects_None, float layerDepth = 0);
void XM_CALLCONV Draw(_In_ ID3D11ShaderResourceView* texture, XMFLOAT2 const& position, _In_opt_ RECT const* sourceRectangle, FXMVECTOR color, float rotation, XMFLOAT2 const& origin, XMFLOAT2 const& scale, SpriteEffects effects = SpriteEffects_None, float layerDepth = 0);
// Draw overloads specifying position, origin and scale via the first two components of an XMVECTOR.
void XM_CALLCONV Draw(_In_ ID3D11ShaderResourceView* texture, FXMVECTOR position, FXMVECTOR color = Colors::White);
void XM_CALLCONV Draw(_In_ ID3D11ShaderResourceView* texture, FXMVECTOR position, _In_opt_ RECT const* sourceRectangle, FXMVECTOR color = Colors::White, float rotation = 0, FXMVECTOR origin = g_XMZero, float scale = 1, SpriteEffects effects = SpriteEffects_None, float layerDepth = 0);
void XM_CALLCONV Draw(_In_ ID3D11ShaderResourceView* texture, FXMVECTOR position, _In_opt_ RECT const* sourceRectangle, FXMVECTOR color, float rotation, FXMVECTOR origin, GXMVECTOR scale, SpriteEffects effects = SpriteEffects_None, float layerDepth = 0);
// Draw overloads specifying position as a RECT.
void XM_CALLCONV Draw(_In_ ID3D11ShaderResourceView* texture, RECT const& destinationRectangle, FXMVECTOR color = Colors::White);
void XM_CALLCONV Draw(_In_ ID3D11ShaderResourceView* texture, RECT const& destinationRectangle, _In_opt_ RECT const* sourceRectangle, FXMVECTOR color = Colors::White, float rotation = 0, XMFLOAT2 const& origin = Float2Zero, SpriteEffects effects = SpriteEffects_None, float layerDepth = 0);
// Rotation mode to be applied to the sprite transformation
void __cdecl SetRotation( DXGI_MODE_ROTATION mode );
DXGI_MODE_ROTATION __cdecl GetRotation() const;
// Set viewport for sprite transformation
void __cdecl SetViewport( const D3D11_VIEWPORT& viewPort );
private:
// Private implementation.
class Impl;
std::unique_ptr<Impl> pImpl;
static const XMMATRIX MatrixIdentity;
static const XMFLOAT2 Float2Zero;
// Prevent copying.
SpriteBatch(SpriteBatch const&) DIRECTX_CTOR_DELETE
SpriteBatch& operator= (SpriteBatch const&) DIRECTX_CTOR_DELETE
};
}
+89
View File
@@ -0,0 +1,89 @@
//--------------------------------------------------------------------------------------
// File: SpriteFont.h
//
// THIS CODE AND INFORMATION IS PROVIDED "AS IS" WITHOUT WARRANTY OF
// ANY KIND, EITHER EXPRESSED OR IMPLIED, INCLUDING BUT NOT LIMITED TO
// THE IMPLIED WARRANTIES OF MERCHANTABILITY AND/OR FITNESS FOR A
// PARTICULAR PURPOSE.
//
// Copyright (c) Microsoft Corporation. All rights reserved.
//
// http://go.microsoft.com/fwlink/?LinkId=248929
//--------------------------------------------------------------------------------------
#pragma once
#include "SpriteBatch.h"
// VS 2010/2012 do not support =default =delete
#ifndef DIRECTX_CTOR_DEFAULT
#if defined(_MSC_VER) && (_MSC_VER < 1800)
#define DIRECTX_CTOR_DEFAULT {}
#define DIRECTX_CTOR_DELETE ;
#else
#define DIRECTX_CTOR_DEFAULT =default;
#define DIRECTX_CTOR_DELETE =delete;
#endif
#endif
namespace DirectX
{
class SpriteFont
{
public:
struct Glyph;
SpriteFont(_In_ ID3D11Device* device, _In_z_ wchar_t const* fileName);
SpriteFont(_In_ ID3D11Device* device, _In_reads_bytes_(dataSize) uint8_t const* dataBlob, _In_ size_t dataSize);
SpriteFont(_In_ ID3D11ShaderResourceView* texture, _In_reads_(glyphCount) Glyph const* glyphs, _In_ size_t glyphCount, _In_ float lineSpacing);
SpriteFont(SpriteFont&& moveFrom);
SpriteFont& operator= (SpriteFont&& moveFrom);
virtual ~SpriteFont();
void XM_CALLCONV DrawString(_In_ SpriteBatch* spriteBatch, _In_z_ wchar_t const* text, XMFLOAT2 const& position, FXMVECTOR color = Colors::White, float rotation = 0, XMFLOAT2 const& origin = Float2Zero, float scale = 1, SpriteEffects effects = SpriteEffects_None, float layerDepth = 0);
void XM_CALLCONV DrawString(_In_ SpriteBatch* spriteBatch, _In_z_ wchar_t const* text, XMFLOAT2 const& position, FXMVECTOR color, float rotation, XMFLOAT2 const& origin, XMFLOAT2 const& scale, SpriteEffects effects = SpriteEffects_None, float layerDepth = 0);
void XM_CALLCONV DrawString(_In_ SpriteBatch* spriteBatch, _In_z_ wchar_t const* text, FXMVECTOR position, FXMVECTOR color = Colors::White, float rotation = 0, FXMVECTOR origin = g_XMZero, float scale = 1, SpriteEffects effects = SpriteEffects_None, float layerDepth = 0);
void XM_CALLCONV DrawString(_In_ SpriteBatch* spriteBatch, _In_z_ wchar_t const* text, FXMVECTOR position, FXMVECTOR color, float rotation, FXMVECTOR origin, GXMVECTOR scale, SpriteEffects effects = SpriteEffects_None, float layerDepth = 0);
XMVECTOR XM_CALLCONV MeasureString(_In_z_ wchar_t const* text) const;
// Spacing properties
float __cdecl GetLineSpacing() const;
void __cdecl SetLineSpacing(float spacing);
// Font properties
wchar_t __cdecl GetDefaultCharacter() const;
void __cdecl SetDefaultCharacter(wchar_t character);
bool __cdecl ContainsCharacter(wchar_t character) const;
// Custom layout/rendering
Glyph const* __cdecl FindGlyph(wchar_t character) const;
void GetSpriteSheet( ID3D11ShaderResourceView** texture ) const;
// Describes a single character glyph.
struct Glyph
{
uint32_t Character;
RECT Subrect;
float XOffset;
float YOffset;
float XAdvance;
};
private:
// Private implementation.
class Impl;
std::unique_ptr<Impl> pImpl;
static const XMFLOAT2 Float2Zero;
// Prevent copying.
SpriteFont(SpriteFont const&) DIRECTX_CTOR_DELETE
SpriteFont& operator= (SpriteFont const&) DIRECTX_CTOR_DELETE
};
}
+333
View File
@@ -0,0 +1,333 @@
//--------------------------------------------------------------------------------------
// File: VertexTypes.h
//
// THIS CODE AND INFORMATION IS PROVIDED "AS IS" WITHOUT WARRANTY OF
// ANY KIND, EITHER EXPRESSED OR IMPLIED, INCLUDING BUT NOT LIMITED TO
// THE IMPLIED WARRANTIES OF MERCHANTABILITY AND/OR FITNESS FOR A
// PARTICULAR PURPOSE.
//
// Copyright (c) Microsoft Corporation. All rights reserved.
//
// http://go.microsoft.com/fwlink/?LinkId=248929
//--------------------------------------------------------------------------------------
#pragma once
#if defined(_XBOX_ONE) && defined(_TITLE)
#include <d3d11_x.h>
#else
#include <d3d11_1.h>
#endif
// VS 2010/2012 do not support =default =delete
#ifndef DIRECTX_CTOR_DEFAULT
#if defined(_MSC_VER) && (_MSC_VER < 1800)
#define DIRECTX_CTOR_DEFAULT {}
#define DIRECTX_CTOR_DELETE ;
#else
#define DIRECTX_CTOR_DEFAULT =default;
#define DIRECTX_CTOR_DELETE =delete;
#endif
#endif
#include <DirectXMath.h>
namespace DirectX
{
#if (DIRECTX_MATH_VERSION < 305) && !defined(XM_CALLCONV)
#define XM_CALLCONV __fastcall
typedef const XMVECTOR& HXMVECTOR;
typedef const XMMATRIX& FXMMATRIX;
#endif
// Vertex struct holding position and color information.
struct VertexPositionColor
{
VertexPositionColor() DIRECTX_CTOR_DEFAULT
VertexPositionColor(XMFLOAT3 const& position, XMFLOAT4 const& color)
: position(position),
color(color)
{ }
VertexPositionColor(FXMVECTOR position, FXMVECTOR color)
{
XMStoreFloat3(&this->position, position);
XMStoreFloat4(&this->color, color);
}
XMFLOAT3 position;
XMFLOAT4 color;
static const int InputElementCount = 2;
static const D3D11_INPUT_ELEMENT_DESC InputElements[InputElementCount];
};
// Vertex struct holding position and texture mapping information.
struct VertexPositionTexture
{
VertexPositionTexture() DIRECTX_CTOR_DEFAULT
VertexPositionTexture(XMFLOAT3 const& position, XMFLOAT2 const& textureCoordinate)
: position(position),
textureCoordinate(textureCoordinate)
{ }
VertexPositionTexture(FXMVECTOR position, FXMVECTOR textureCoordinate)
{
XMStoreFloat3(&this->position, position);
XMStoreFloat2(&this->textureCoordinate, textureCoordinate);
}
XMFLOAT3 position;
XMFLOAT2 textureCoordinate;
static const int InputElementCount = 2;
static const D3D11_INPUT_ELEMENT_DESC InputElements[InputElementCount];
};
// Vertex struct holding position and normal vector.
struct VertexPositionNormal
{
VertexPositionNormal() DIRECTX_CTOR_DEFAULT
VertexPositionNormal(XMFLOAT3 const& position, XMFLOAT3 const& normal)
: position(position),
normal(normal)
{ }
VertexPositionNormal(FXMVECTOR position, FXMVECTOR normal)
{
XMStoreFloat3(&this->position, position);
XMStoreFloat3(&this->normal, normal);
}
XMFLOAT3 position;
XMFLOAT3 normal;
static const int InputElementCount = 2;
static const D3D11_INPUT_ELEMENT_DESC InputElements[InputElementCount];
};
// Vertex struct holding position, color, and texture mapping information.
struct VertexPositionColorTexture
{
VertexPositionColorTexture() DIRECTX_CTOR_DEFAULT
VertexPositionColorTexture(XMFLOAT3 const& position, XMFLOAT4 const& color, XMFLOAT2 const& textureCoordinate)
: position(position),
color(color),
textureCoordinate(textureCoordinate)
{ }
VertexPositionColorTexture(FXMVECTOR position, FXMVECTOR color, FXMVECTOR textureCoordinate)
{
XMStoreFloat3(&this->position, position);
XMStoreFloat4(&this->color, color);
XMStoreFloat2(&this->textureCoordinate, textureCoordinate);
}
XMFLOAT3 position;
XMFLOAT4 color;
XMFLOAT2 textureCoordinate;
static const int InputElementCount = 3;
static const D3D11_INPUT_ELEMENT_DESC InputElements[InputElementCount];
};
// Vertex struct holding position, normal vector, and color information.
struct VertexPositionNormalColor
{
VertexPositionNormalColor() DIRECTX_CTOR_DEFAULT
VertexPositionNormalColor(XMFLOAT3 const& position, XMFLOAT3 const& normal, XMFLOAT4 const& color)
: position(position),
normal(normal),
color(color)
{ }
VertexPositionNormalColor(FXMVECTOR position, FXMVECTOR normal, FXMVECTOR color)
{
XMStoreFloat3(&this->position, position);
XMStoreFloat3(&this->normal, normal);
XMStoreFloat4(&this->color, color);
}
XMFLOAT3 position;
XMFLOAT3 normal;
XMFLOAT4 color;
static const int InputElementCount = 3;
static const D3D11_INPUT_ELEMENT_DESC InputElements[InputElementCount];
};
// Vertex struct holding position, normal vector, and texture mapping information.
struct VertexPositionNormalTexture
{
VertexPositionNormalTexture() DIRECTX_CTOR_DEFAULT
VertexPositionNormalTexture(XMFLOAT3 const& position, XMFLOAT3 const& normal, XMFLOAT2 const& textureCoordinate)
: position(position),
normal(normal),
textureCoordinate(textureCoordinate)
{ }
VertexPositionNormalTexture(FXMVECTOR position, FXMVECTOR normal, FXMVECTOR textureCoordinate)
{
XMStoreFloat3(&this->position, position);
XMStoreFloat3(&this->normal, normal);
XMStoreFloat2(&this->textureCoordinate, textureCoordinate);
}
XMFLOAT3 position;
XMFLOAT3 normal;
XMFLOAT2 textureCoordinate;
static const int InputElementCount = 3;
static const D3D11_INPUT_ELEMENT_DESC InputElements[InputElementCount];
};
// Vertex struct holding position, normal vector, color, and texture mapping information.
struct VertexPositionNormalColorTexture
{
VertexPositionNormalColorTexture() DIRECTX_CTOR_DEFAULT
VertexPositionNormalColorTexture(XMFLOAT3 const& position, XMFLOAT3 const& normal, XMFLOAT4 const& color, XMFLOAT2 const& textureCoordinate)
: position(position),
normal(normal),
color(color),
textureCoordinate(textureCoordinate)
{ }
VertexPositionNormalColorTexture(FXMVECTOR position, FXMVECTOR normal, FXMVECTOR color, CXMVECTOR textureCoordinate)
{
XMStoreFloat3(&this->position, position);
XMStoreFloat3(&this->normal, normal);
XMStoreFloat4(&this->color, color);
XMStoreFloat2(&this->textureCoordinate, textureCoordinate);
}
XMFLOAT3 position;
XMFLOAT3 normal;
XMFLOAT4 color;
XMFLOAT2 textureCoordinate;
static const int InputElementCount = 4;
static const D3D11_INPUT_ELEMENT_DESC InputElements[InputElementCount];
};
// Vertex struct for Visual Studio Shader Designer (DGSL) holding position, normal,
// tangent, color (RGBA), and texture mapping information
struct VertexPositionNormalTangentColorTexture
{
VertexPositionNormalTangentColorTexture() DIRECTX_CTOR_DEFAULT
XMFLOAT3 position;
XMFLOAT3 normal;
XMFLOAT4 tangent;
uint32_t color;
XMFLOAT2 textureCoordinate;
VertexPositionNormalTangentColorTexture(XMFLOAT3 const& position, XMFLOAT3 const& normal, XMFLOAT4 const& tangent, uint32_t rgba, XMFLOAT2 const& textureCoordinate)
: position(position),
normal(normal),
tangent(tangent),
color(rgba),
textureCoordinate(textureCoordinate)
{
}
VertexPositionNormalTangentColorTexture(FXMVECTOR position, FXMVECTOR normal, FXMVECTOR tangent, uint32_t rgba, CXMVECTOR textureCoordinate)
: color(rgba)
{
XMStoreFloat3(&this->position, position);
XMStoreFloat3(&this->normal, normal);
XMStoreFloat4(&this->tangent, tangent);
XMStoreFloat2(&this->textureCoordinate, textureCoordinate);
}
VertexPositionNormalTangentColorTexture(XMFLOAT3 const& position, XMFLOAT3 const& normal, XMFLOAT4 const& tangent, XMFLOAT4 const& color, XMFLOAT2 const& textureCoordinate)
: position(position),
normal(normal),
tangent(tangent),
textureCoordinate(textureCoordinate)
{
SetColor( color );
}
VertexPositionNormalTangentColorTexture(FXMVECTOR position, FXMVECTOR normal, FXMVECTOR tangent, CXMVECTOR color, CXMVECTOR textureCoordinate)
{
XMStoreFloat3(&this->position, position);
XMStoreFloat3(&this->normal, normal);
XMStoreFloat4(&this->tangent, tangent);
XMStoreFloat2(&this->textureCoordinate, textureCoordinate);
SetColor( color );
}
void __cdecl SetColor( XMFLOAT4 const& icolor ) { SetColor( XMLoadFloat4( &icolor ) ); }
void XM_CALLCONV SetColor( FXMVECTOR icolor );
static const int InputElementCount = 5;
static const D3D11_INPUT_ELEMENT_DESC InputElements[InputElementCount];
};
// Vertex struct for Visual Studio Shader Designer (DGSL) holding position, normal,
// tangent, color (RGBA), texture mapping information, and skinning weights
struct VertexPositionNormalTangentColorTextureSkinning : public VertexPositionNormalTangentColorTexture
{
VertexPositionNormalTangentColorTextureSkinning() DIRECTX_CTOR_DEFAULT
uint32_t indices;
uint32_t weights;
VertexPositionNormalTangentColorTextureSkinning(XMFLOAT3 const& position, XMFLOAT3 const& normal, XMFLOAT4 const& tangent, uint32_t rgba,
XMFLOAT2 const& textureCoordinate, XMUINT4 const& indices, XMFLOAT4 const& weights)
: VertexPositionNormalTangentColorTexture(position,normal,tangent,rgba,textureCoordinate)
{
SetBlendIndices( indices );
SetBlendWeights( weights );
}
VertexPositionNormalTangentColorTextureSkinning(FXMVECTOR position, FXMVECTOR normal, FXMVECTOR tangent, uint32_t rgba, CXMVECTOR textureCoordinate,
XMUINT4 const& indices, CXMVECTOR weights)
: VertexPositionNormalTangentColorTexture(position,normal,tangent,rgba,textureCoordinate)
{
SetBlendIndices( indices );
SetBlendWeights( weights );
}
VertexPositionNormalTangentColorTextureSkinning(XMFLOAT3 const& position, XMFLOAT3 const& normal, XMFLOAT4 const& tangent, XMFLOAT4 const& color,
XMFLOAT2 const& textureCoordinate, XMUINT4 const& indices, XMFLOAT4 const& weights)
: VertexPositionNormalTangentColorTexture(position,normal,tangent,color,textureCoordinate)
{
SetBlendIndices( indices );
SetBlendWeights( weights );
}
VertexPositionNormalTangentColorTextureSkinning(FXMVECTOR position, FXMVECTOR normal, FXMVECTOR tangent, CXMVECTOR color, CXMVECTOR textureCoordinate,
XMUINT4 const& indices, CXMVECTOR weights)
: VertexPositionNormalTangentColorTexture(position,normal,tangent,color,textureCoordinate)
{
SetBlendIndices( indices );
SetBlendWeights( weights );
}
void __cdecl SetBlendIndices( XMUINT4 const& iindices );
void __cdecl SetBlendWeights( XMFLOAT4 const& iweights ) { SetBlendWeights( XMLoadFloat4( &iweights ) ); }
void XM_CALLCONV SetBlendWeights( FXMVECTOR iweights );
static const int InputElementCount = 7;
static const D3D11_INPUT_ELEMENT_DESC InputElements[InputElementCount];
};
}
+154
View File
@@ -0,0 +1,154 @@
//--------------------------------------------------------------------------------------
// File: WICTextureLoader.h
//
// Function for loading a WIC image and creating a Direct3D 11 runtime texture for it
// (auto-generating mipmaps if possible)
//
// Note: Assumes application has already called CoInitializeEx
//
// Warning: CreateWICTexture* functions are not thread-safe if given a d3dContext instance for
// auto-gen mipmap support.
//
// Note these functions are useful for images created as simple 2D textures. For
// more complex resources, DDSTextureLoader is an excellent light-weight runtime loader.
// For a full-featured DDS file reader, writer, and texture processing pipeline see
// the 'Texconv' sample and the 'DirectXTex' library.
//
// THIS CODE AND INFORMATION IS PROVIDED "AS IS" WITHOUT WARRANTY OF
// ANY KIND, EITHER EXPRESSED OR IMPLIED, INCLUDING BUT NOT LIMITED TO
// THE IMPLIED WARRANTIES OF MERCHANTABILITY AND/OR FITNESS FOR A
// PARTICULAR PURPOSE.
//
// Copyright (c) Microsoft Corporation. All rights reserved.
//
// http://go.microsoft.com/fwlink/?LinkId=248926
// http://go.microsoft.com/fwlink/?LinkId=248929
//--------------------------------------------------------------------------------------
#pragma once
#if defined(WINAPI_FAMILY) && (WINAPI_FAMILY == WINAPI_FAMILY_PHONE_APP) && (_WIN32_WINNT <= _WIN32_WINNT_WIN8)
#error WIC is not supported on Windows Phone 8.0
#endif
#if defined(_XBOX_ONE) && defined(_TITLE)
#include <d3d11_x.h>
#else
#include <d3d11_1.h>
#endif
#pragma warning(push)
#pragma warning(disable : 4005)
#include <stdint.h>
#pragma warning(pop)
namespace DirectX
{
// Standard version
HRESULT __cdecl CreateWICTextureFromMemory( _In_ ID3D11Device* d3dDevice,
_In_reads_bytes_(wicDataSize) const uint8_t* wicData,
_In_ size_t wicDataSize,
_Out_opt_ ID3D11Resource** texture,
_Out_opt_ ID3D11ShaderResourceView** textureView,
_In_ size_t maxsize = 0
);
HRESULT __cdecl CreateWICTextureFromFile( _In_ ID3D11Device* d3dDevice,
_In_z_ const wchar_t* szFileName,
_Out_opt_ ID3D11Resource** texture,
_Out_opt_ ID3D11ShaderResourceView** textureView,
_In_ size_t maxsize = 0
);
// Standard version with optional auto-gen mipmap support
#if defined(_XBOX_ONE) && defined(_TITLE)
HRESULT __cdecl CreateWICTextureFromMemory( _In_ ID3D11DeviceX* d3dDevice,
_In_opt_ ID3D11DeviceContextX* d3dContext,
#else
HRESULT __cdecl CreateWICTextureFromMemory( _In_ ID3D11Device* d3dDevice,
_In_opt_ ID3D11DeviceContext* d3dContext,
#endif
_In_reads_bytes_(wicDataSize) const uint8_t* wicData,
_In_ size_t wicDataSize,
_Out_opt_ ID3D11Resource** texture,
_Out_opt_ ID3D11ShaderResourceView** textureView,
_In_ size_t maxsize = 0
);
#if defined(_XBOX_ONE) && defined(_TITLE)
HRESULT __cdecl CreateWICTextureFromFile( _In_ ID3D11DeviceX* d3dDevice,
_In_opt_ ID3D11DeviceContextX* d3dContext,
#else
HRESULT __cdecl CreateWICTextureFromFile( _In_ ID3D11Device* d3dDevice,
_In_opt_ ID3D11DeviceContext* d3dContext,
#endif
_In_z_ const wchar_t* szFileName,
_Out_opt_ ID3D11Resource** texture,
_Out_opt_ ID3D11ShaderResourceView** textureView,
_In_ size_t maxsize = 0
);
// Extended version
HRESULT __cdecl CreateWICTextureFromMemoryEx( _In_ ID3D11Device* d3dDevice,
_In_reads_bytes_(wicDataSize) const uint8_t* wicData,
_In_ size_t wicDataSize,
_In_ size_t maxsize,
_In_ D3D11_USAGE usage,
_In_ unsigned int bindFlags,
_In_ unsigned int cpuAccessFlags,
_In_ unsigned int miscFlags,
_In_ bool forceSRGB,
_Out_opt_ ID3D11Resource** texture,
_Out_opt_ ID3D11ShaderResourceView** textureView
);
HRESULT __cdecl CreateWICTextureFromFileEx( _In_ ID3D11Device* d3dDevice,
_In_z_ const wchar_t* szFileName,
_In_ size_t maxsize,
_In_ D3D11_USAGE usage,
_In_ unsigned int bindFlags,
_In_ unsigned int cpuAccessFlags,
_In_ unsigned int miscFlags,
_In_ bool forceSRGB,
_Out_opt_ ID3D11Resource** texture,
_Out_opt_ ID3D11ShaderResourceView** textureView
);
// Extended version with optional auto-gen mipmap support
#if defined(_XBOX_ONE) && defined(_TITLE)
HRESULT __cdecl CreateWICTextureFromMemoryEx( _In_ ID3D11DeviceX* d3dDevice,
_In_opt_ ID3D11DeviceContextX* d3dContext,
#else
HRESULT __cdecl CreateWICTextureFromMemoryEx( _In_ ID3D11Device* d3dDevice,
_In_opt_ ID3D11DeviceContext* d3dContext,
#endif
_In_reads_bytes_(wicDataSize) const uint8_t* wicData,
_In_ size_t wicDataSize,
_In_ size_t maxsize,
_In_ D3D11_USAGE usage,
_In_ unsigned int bindFlags,
_In_ unsigned int cpuAccessFlags,
_In_ unsigned int miscFlags,
_In_ bool forceSRGB,
_Out_opt_ ID3D11Resource** texture,
_Out_opt_ ID3D11ShaderResourceView** textureView
);
#if defined(_XBOX_ONE) && defined(_TITLE)
HRESULT __cdecl CreateWICTextureFromFileEx( _In_ ID3D11DeviceX* d3dDevice,
_In_opt_ ID3D11DeviceContextX* d3dContext,
#else
HRESULT __cdecl CreateWICTextureFromFileEx( _In_ ID3D11Device* d3dDevice,
_In_opt_ ID3D11DeviceContext* d3dContext,
#endif
_In_z_ const wchar_t* szFileName,
_In_ size_t maxsize,
_In_ D3D11_USAGE usage,
_In_ unsigned int bindFlags,
_In_ unsigned int cpuAccessFlags,
_In_ unsigned int miscFlags,
_In_ bool forceSRGB,
_Out_opt_ ID3D11Resource** texture,
_Out_opt_ ID3D11ShaderResourceView** textureView
);
}
+61
View File
@@ -0,0 +1,61 @@
//--------------------------------------------------------------------------------------
// File: XboxDDSTextureLoader.h
//
// Functions for loading a DDS texture using the XBOX extended header and creating a
// Direct3D11.X runtime resource for it via the CreatePlacement APIs
//
// Note these functions will not load standard DDS files. Use the DDSTextureLoader
// module in the DirectXTex package or as part of the DirectXTK library to load
// these files which use standard Direct3D 11 resource creation APIs.
//
// THIS CODE AND INFORMATION IS PROVIDED "AS IS" WITHOUT WARRANTY OF
// ANY KIND, EITHER EXPRESSED OR IMPLIED, INCLUDING BUT NOT LIMITED TO
// THE IMPLIED WARRANTIES OF MERCHANTABILITY AND/OR FITNESS FOR A
// PARTICULAR PURPOSE.
//
// Copyright (c) Microsoft Corporation. All rights reserved.
//
// http://go.microsoft.com/fwlink/?LinkId=248926
// http://go.microsoft.com/fwlink/?LinkId=248929
//--------------------------------------------------------------------------------------
#pragma once
#if !defined(_XBOX_ONE) || !defined(_TITLE)
#error This module only supports Xbox One exclusive apps
#endif
#include <d3d11_x.h>
#include <stdint.h>
namespace Xbox
{
enum DDS_ALPHA_MODE
{
DDS_ALPHA_MODE_UNKNOWN = 0,
DDS_ALPHA_MODE_STRAIGHT = 1,
DDS_ALPHA_MODE_PREMULTIPLIED = 2,
DDS_ALPHA_MODE_OPAQUE = 3,
DDS_ALPHA_MODE_CUSTOM = 4,
};
HRESULT __cdecl CreateDDSTextureFromMemory( _In_ ID3D11DeviceX* d3dDevice,
_In_reads_bytes_(ddsDataSize) const uint8_t* ddsData,
_In_ size_t ddsDataSize,
_Outptr_opt_ ID3D11Resource** texture,
_Outptr_opt_ ID3D11ShaderResourceView** textureView,
_Outptr_ void** grfxMemory,
_Out_opt_ DDS_ALPHA_MODE* alphaMode = nullptr,
_In_ bool forceSRGB = false
);
HRESULT __cdecl CreateDDSTextureFromFile( _In_ ID3D11DeviceX* d3dDevice,
_In_z_ const wchar_t* szFileName,
_Outptr_opt_ ID3D11Resource** texture,
_Outptr_opt_ ID3D11ShaderResourceView** textureView,
_Outptr_ void** grfxMemory,
_Out_opt_ DDS_ALPHA_MODE* alphaMode = nullptr,
_In_ bool forceSRGB = false
);
}
Binary file not shown.
Binary file not shown.
-102
View File
@@ -1,102 +0,0 @@
#ifndef BGFXRenderer_h__
#define BGFXRenderer_h__
#include <bgfx.h>
#include <bgfxplatform.h>
#include "Util/Rectangle.h"
#include "Core/Camera.h"
#include "Core/RenderQueue.h"
namespace dd
{
class BGFXRenderer
{
public:
GLFWwindow* Window() const { return m_Window; }
Rectangle Resolution() const { return m_Resolution; }
void SetResolution(const Rectangle& resolution) { m_Resolution = resolution; }
bool Fullscreen() { return m_Fullscreen; }
void SetFullscreen(bool fullscreen) { m_Fullscreen = fullscreen; }
bool VSYNC() const { return m_VSYNC; }
void SetVSYNC(bool vsync) { m_VSYNC = vsync; }
//void SetViewport(const Rectangle& viewport) { m_Viewport = viewport; }
//void SetScissor(const Rectangle& scissor) { m_Scissor = scissor; }
const dd::Camera* Camera() const { return m_Camera; }
void SetCamera(const dd::Camera* camera)
{
if (camera == nullptr) {
m_Camera = m_DefaultCamera.get();
} else {
m_Camera = camera;
}
}
void Initialize()
{
// Initialize GLFW
if (!glfwInit()) {
LOG_ERROR("GLFW: Initialization failed");
exit(EXIT_FAILURE);
}
// Create a window
GLFWmonitor* monitor = nullptr;
if (m_Fullscreen) {
monitor = glfwGetPrimaryMonitor();
}
glfwWindowHint(GLFW_SAMPLES, 8);
m_Window = glfwCreateWindow(m_Resolution.Width, m_Resolution.Height, "daydream", monitor, nullptr);
if (!m_Window) {
LOG_ERROR("GLFW: Failed to create window");
exit(EXIT_FAILURE);
}
//glfwMakeContextCurrent(m_Window);
// Initialize GLEW
// if (glewInit() != GLEW_OK) {
// LOG_ERROR("GLEW: Initialization failed");
// exit(EXIT_FAILURE);
// }
//LOG_ERROR("STUFF");
// Initialize bgfx
bgfx::glfwSetWindow(m_Window);
bgfx::init(bgfx::RendererType::OpenGL, BGFX_PCI_ID_NONE, 0, nullptr, nullptr);
bgfx::reset(m_Resolution.Width, m_Resolution.Height, BGFX_RESET_NONE);
bgfx::setDebug(BGFX_DEBUG_TEXT);
bgfx::setViewClear(0, BGFX_CLEAR_COLOR | BGFX_CLEAR_DEPTH, 0x303030ff, 1.0f, 0);
std::stringstream ss;
ss << bgfx::getRendererName(bgfx::getRendererType());
#ifdef DEBUG
ss << " DEBUG";
#endif
LOG_INFO(ss.str().c_str());
glfwSetWindowTitle(m_Window, ss.str().c_str());
}
void Draw(RenderQueueCollection& rq)
{
bgfx::touch(0);
bgfx::dbgTextClear();
bgfx::dbgTextPrintf(0, 1, 0x4f, "daydream");
bgfx::frame();
}
private:
Rectangle m_Resolution = Rectangle(1280, 720);
bool m_Fullscreen = false;
bool m_VSYNC = false;
std::unique_ptr<dd::Camera> m_DefaultCamera = nullptr;
const dd::Camera* m_Camera = nullptr;
GLFWwindow* m_Window = nullptr;
};
}
#endif
+17 -15
View File
@@ -21,12 +21,12 @@
#include <Sound/CCollisionSound.h>
#include "ResourceManager.h"
#include "OBJ.h"
#include "Model.h"
#include "Texture.h"
#include "Rendering/OBJ.h"
#include "Rendering/Model.h"
#include "Rendering/Texture.h"
#include "EventBroker.h"
#include "RenderQueue.h"
#include "Renderer.h"
#include "Rendering/RenderQueue.h"
#include "Rendering/Renderer.h"
#include "InputManager.h"
//TODO: Remove includes that are only here for the temporary draw solution.
#include "World.h"
@@ -59,6 +59,7 @@
#include "Game/LifebuoySystem.h"
#include "Game/ProjectileSystem.h"
#include "Game/KrakenSystem.h"
#include "Game/WaterSystem.h"
#include "Game/Bricks/CPowerUpBrick.h"
#include "Game/BrickComponents.h"
@@ -164,7 +165,7 @@ public:
m_World->ComponentFactory.Register<Components::KrakenAttackBrick>();
m_World->SystemFactory.Register<Systems::LevelSystem>(
[this]() { return new Systems::LevelSystem(m_World.get(), m_EventBroker); });
[this]() { return new Systems::LevelSystem(m_World.get(), m_EventBroker); });
m_World->AddSystem<Systems::LevelSystem>();
m_World->SystemFactory.Register<Systems::PadSystem>(
[this]() { return new Systems::PadSystem(m_World.get(), m_EventBroker); });
@@ -193,6 +194,9 @@ public:
m_World->SystemFactory.Register<Systems::KrakenSystem>(
[this]() { return new Systems::KrakenSystem(m_World.get(), m_EventBroker); });
m_World->AddSystem<Systems::KrakenSystem>();
m_World->SystemFactory.Register<Systems::WaterSystem>(
[this]() { return new Systems::WaterSystem(m_World.get(), m_EventBroker); });
m_World->AddSystem<Systems::WaterSystem>();
m_World->ComponentFactory.Register<Components::Model>();
m_World->ComponentFactory.Register<Components::Template>();
@@ -351,11 +355,10 @@ public:
{
ModelJob job;
job.TextureID = (texGroup.Texture) ? texGroup.Texture->ResourceID : 0;
job.DiffuseTexture = (texGroup.Texture) ? *texGroup.Texture : 0;
job.NormalTexture = (texGroup.NormalMap) ? *texGroup.NormalMap : 0;
job.SpecularTexture = (texGroup.SpecularMap) ? *texGroup.SpecularMap : 0;
job.VAO = model->VAO;
job.ElementBuffer = model->ElementBuffer;
job.DiffuseTexture = texGroup.Texture.get();
job.NormalTexture = texGroup.NormalMap.get();
job.SpecularTexture = texGroup.SpecularMap.get();
job.Model = model;
job.StartIndex = texGroup.StartIndex;
job.EndIndex = texGroup.EndIndex;
job.ModelMatrix = modelMatrix * model->m_Matrix;
@@ -379,14 +382,13 @@ public:
{
SpriteJob job;
job.TextureID = texture->ResourceID;
job.DiffuseTexture = *texture;
job.NormalTexture = *normalTexture;
job.SpecularTexture = *specularTexture;
job.DiffuseTexture = texture;
job.NormalTexture = normalTexture;
job.SpecularTexture = specularTexture;
job.ModelMatrix = modelMatrix;
job.Color = color;
job.Depth = depth;
m_RendererQueue.Forward.Add(job);
}
+2 -16
View File
@@ -23,8 +23,8 @@
#include <forward_list>
#include "Core/Util/Rectangle.h"
#include "Core/Texture.h"
#include "Core/Model.h"
#include "Rendering/Texture.h"
#include "Rendering/Model.h"
namespace dd
{
@@ -78,20 +78,6 @@ struct ModelJob : RenderJob
}
};
struct BlendMapModelJob : ModelJob
{
GLuint BlendMapTextureRed;
GLuint BlendMapTextureRedNormal;
GLuint BlendMapTextureRedSpecular;
GLuint BlendMapTextureGreen;
GLuint BlendMapTextureGreenNormal;
GLuint BlendMapTextureGreenSpecular;
GLuint BlendMapTextureBlue;
GLuint BlendMapTextureBlueNormal;
GLuint BlendMapTextureBlueSpecular;
float TextureRepeat;
};
struct SpriteJob : RenderJob
{
unsigned int ShaderID;
+34
View File
@@ -0,0 +1,34 @@
#ifndef DD_STATICSYSTEM_H__
#define DD_STATICSYSTEM_H__
#include <unordered_map>
namespace dd
{
class StaticSystem
{
private:
StaticSystem();
public:
template <typename T>
static T* Get()
{
return static_cast<T*>(Instances.at(typeid(T).hash_code()));
}
template <typename T>
static void Set(T* ptr)
{
Instances[typeid(T).hash_code()] = static_cast<void*>(ptr);
}
private:
static std::unordered_map<size_t, void*> Instances;
};
}
#endif
+3 -3
View File
@@ -9,9 +9,9 @@
#include "Core/EKeyDown.h"
#include "Core/EKeyUp.h"
#include "Core/ResourceManager.h"
#include "Core/Renderer.h"
#include "Core/RenderQueue.h"
#include "Core/Texture.h"
#include "Rendering/Renderer.h"
#include "Rendering/RenderQueue.h"
#include "Rendering/Texture.h"
#include "Input/EInputCommand.h"
namespace dd
+3 -3
View File
@@ -2,7 +2,7 @@
#define GUI_TextureFrame_h__
#include "GUI/Frame.h"
#include "Core/Texture.h"
#include "Rendering/Texture.h"
namespace dd
{
@@ -29,7 +29,7 @@ public:
job.Scissor = (m_ScissorEnabled) ? m_Parent->AbsoluteRectangle() : Rectangle();
job.Viewport = Rectangle(Left(), Top(), Width, Height);
job.TextureID = m_FadeTexture->ResourceID;
job.DiffuseTexture = *m_FadeTexture;
job.DiffuseTexture = m_FadeTexture;
job.Color = glm::vec4(m_Color.r, m_Color.g, m_Color.b, m_Color.a);
job.Name = Name();
rq.GUI.Add(job);
@@ -41,7 +41,7 @@ public:
job.Scissor = (m_ScissorEnabled) ? m_Parent->AbsoluteRectangle() : Rectangle();
job.Viewport = Rectangle(Left(), Top(), Width, Height);
job.TextureID = m_Texture->ResourceID;
job.DiffuseTexture = *m_Texture;
job.DiffuseTexture = m_Texture;
job.Color = glm::vec4(m_Color.r, m_Color.g, m_Color.b, m_Color.a * m_CurrentFade);
job.Name = Name();
rq.GUI.Add(job);
+1 -1
View File
@@ -15,7 +15,7 @@ namespace Components
struct Projectile : Component
{
float Speed = 5;
};
}
+1 -1
View File
@@ -12,7 +12,7 @@ namespace Events
struct ClusterClear : Event
{
int ClusterCleared;
};
}
+1
View File
@@ -17,6 +17,7 @@ struct InkBlaster : Event
{
Components::Transform* Transform;
int Shots;
float Speed = 5;
};
}
+26
View File
@@ -0,0 +1,26 @@
//
// Created by Adniklastrator on 2015-10-19.
//
#ifndef DAYDREAM_EKRAKENDEFEATED_H
#define DAYDREAM_EKRAKENDEFEATED_H
#include "Core/EventBroker.h"
namespace dd
{
namespace Events
{
struct KrakenDefeated : Event
{
EntityID Kraken;
EntityID Hitter;
};
}
}
#endif //DAYDREAM_EKRAKENDEFEATED_H
+26
View File
@@ -0,0 +1,26 @@
//
// Created by Adniklastrator on 2015-10-19.
//
#ifndef DAYDREAM_EKRAKENHIT_H
#define DAYDREAM_EKRAKENHIT_H
#include "Core/EventBroker.h"
namespace dd
{
namespace Events
{
struct KrakenHit : Event
{
EntityID Kraken;
EntityID Hitter;
};
}
}
#endif //DAYDREAM_EKRAKENHIT_H
+1
View File
@@ -16,6 +16,7 @@ namespace Events
struct RaiseWater : Event
{
float Amount;
float Speed;
};
}
+26
View File
@@ -0,0 +1,26 @@
//
// Created by Administrator on 2015-10-20.
//
#ifndef DAYDREAM_ERAISEWATERWALL_H
#define DAYDREAM_ERAISEWATERWALL_H
#include "Core/EventBroker.h"
namespace dd
{
namespace Events
{
struct RaiseWaterWall : Event
{
float Amount;
float Speed;
};
}
}
#endif //DAYDREAM_ERAISEWATERWALL_H
+27
View File
@@ -0,0 +1,27 @@
//
// Created by Administrator on 2015-10-20.
//
#ifndef DAYDREAM_ERELEVANTOBJECTCREATED_H
#define DAYDREAM_ERELEVANTOBJECTCREATED_H
#include "Core/EventBroker.h"
#include "Core/Entity.h"
namespace dd
{
namespace Events
{
struct RelevantObjectCreated : Event
{
std::string ObjectName;
EntityID ObjectID;
};
}
}
#endif //DAYDREAM_ERELEVANTOBJECTCREATED_H
+1
View File
@@ -17,6 +17,7 @@ struct StageCleared : Event
{
int ClearedStage = 0;
int StageCluster = 0;
int StagesInCluster = 6;
};
}
+22
View File
@@ -0,0 +1,22 @@
//
// Created by Administrator on 2015-10-19.
//
#ifndef DAYDREAM_ESTARTEDNEWLEVEL_H
#define DAYDREAM_ESTARTEDNEWLEVEL_H
#include "Core/EventBroker.h"
#include "Core/Entity.h"
namespace dd
{
namespace Events
{
struct StartedNewLevel : Event
{
};
}
}
#endif //DAYDREAM_ESTARTEDNEWLEVEL_H
+9
View File
@@ -17,13 +17,18 @@
#include "Physics/CCircleShape.h"
#include "Physics/CPhysics.h"
#include "Physics/EContact.h"
#include "Physics/ESetImpulse.h"
#include "Physics/ECreateParticleSequence.h"
#include "Game/EPause.h"
#include "Game/EResume.h"
#include "Game/EKrakenAppear.h"
#include "Game/EKrakenAttack.h"
#include "Game/EKrakenHit.h"
#include "Game/EKrakenDefeated.h"
#include "Game/EBrickGenerating.h"
#include "Game/CTravels.h"
#include "Game/CKraken.h"
#include "Game/CBall.h"
#include "Sound/CCollisionSound.h"
//#include "Core/Camera.h" Camera Component
@@ -69,12 +74,16 @@ private:
dd::EventRelay<KrakenSystem, dd::Events::Contact> m_EContact;
dd::EventRelay<KrakenSystem, dd::Events::KrakenAppear> m_EKrakenAppear;
dd::EventRelay<KrakenSystem, dd::Events::KrakenAttack> m_EKrakenAttack;
dd::EventRelay<KrakenSystem, dd::Events::KrakenHit> m_EKrakenHit;
dd::EventRelay<KrakenSystem, dd::Events::KrakenDefeated> m_EKrakenDefeated;
dd::EventRelay<KrakenSystem, dd::Events::BrickGenerating> m_EBrickGenerating;
bool OnPause(const dd::Events::Pause &event);
bool OnResume(const dd::Events::Resume &event);
bool OnContact(const dd::Events::Contact &event);
bool OnKrakenAppear(const dd::Events::KrakenAppear &event);
bool OnKrakenAttack(const dd::Events::KrakenAttack &event);
bool OnKrakenHit(const dd::Events::KrakenHit &event);
bool OnKrakenDefeated(const dd::Events::KrakenDefeated &event);
bool OnBrickGenerating(const dd::Events::BrickGenerating &event);
void GetBrickSet();
};
+9
View File
@@ -33,7 +33,9 @@
#include "Game/BrickComponents.h"
#include "Game/ERelevantObjectCreated.h"
#include "Game/EStageCleared.h"
#include "Game/EArrivedAtNewStage.h"
#include "Game/ELifeLost.h"
#include "Game/EResetBall.h"
#include "Game/EScoreEvent.h"
@@ -52,7 +54,9 @@
#include "Game/ECreatePowerUp.h"
#include "Game/EPowerUpTaken.h"
#include "Game/CKraken.h"
#include "Game/EKrakenAppear.h"
#include "Game/EKrakenDefeated.h"
#include "Game/EBrickGenerating.h"
#include "Physics/CPhysics.h"
@@ -147,6 +151,7 @@ private:
int m_NumberOfBricks;
int m_Rows = 6;
int m_Lines = 7;
int m_StagesInCluster = 6;
float m_SpaceToEdge = 0.25f;
glm::vec2 m_SpaceBetweenBricks = glm::vec2(1, 0.4);
float m_NotResettingTheStage = 5.f;
@@ -177,10 +182,12 @@ private:
dd::EventRelay<LevelSystem, dd::Events::CreatePowerUp> m_ECreatePowerUp;
dd::EventRelay<LevelSystem, dd::Events::PowerUpTaken> m_EPowerUpTaken;
dd::EventRelay<LevelSystem, dd::Events::StageCleared> m_EStageCleared;
dd::EventRelay<LevelSystem, dd::Events::ArrivedAtNewStage> m_EArrivedAtNewStage;
dd::EventRelay<LevelSystem, dd::Events::Pause> m_EPause;
dd::EventRelay<LevelSystem, dd::Events::Resume> m_EResume;
dd::EventRelay<LevelSystem, dd::Events::HitPad> m_EHitPad;
dd::EventRelay<LevelSystem, dd::Events::BrickGenerating> m_EBrickGenerating;
dd::EventRelay<LevelSystem, dd::Events::KrakenDefeated> m_EKrakenDefeated;
bool OnContact(const dd::Events::Contact &event);
bool OnScoreEvent(const dd::Events::ScoreEvent &event);
@@ -189,11 +196,13 @@ private:
bool OnCreatePowerUp(const dd::Events::CreatePowerUp &event);
bool OnPowerUpTaken(const dd::Events::PowerUpTaken &event);
bool OnStageCleared(const dd::Events::StageCleared &event);
bool OnArrivedAtNewStage(const dd::Events::ArrivedAtNewStage &event);
bool OnPause(const dd::Events::Pause &event);
bool OnResume(const dd::Events::Resume &event);
bool OnHitPad(const dd::Events::HitPad &event);
bool OnBrickGenerating(const dd::Events::BrickGenerating &event);
void GetBrickSet(int Set);
bool OnKrakenDefeated(const dd::Events::KrakenDefeated &event);
void GetNextLevel();
void SetBrokenModel(EntityID entity);
+4
View File
@@ -36,6 +36,7 @@
#include "Game/EResetBall.h"
#include "Game/EResetAll.h"
#include "Game/ERaiseWater.h"
#include "Game/ERaiseWaterWall.h"
#include "Game/EMultiBall.h"
#include "Game/ELifebuoy.h"
#include "Game/EStickyPad.h"
@@ -120,6 +121,7 @@ private:
dd::EventRelay<PadSystem, dd::Events::ResetBall> m_EResetBall;
dd::EventRelay<PadSystem, dd::Events::ResetAll> m_EResetAll;
dd::EventRelay<PadSystem, dd::Events::RaiseWater> m_ERaiseWater;
dd::EventRelay<PadSystem, dd::Events::RaiseWaterWall> m_ERaiseWaterWall;
dd::EventRelay<PadSystem, dd::Events::Pause> m_EPause;
dd::EventRelay<PadSystem, dd::Events::Resume> m_EResume;
dd::EventRelay<PadSystem, dd::Events::KrakenAttack> m_EKrakenAttack;
@@ -135,6 +137,8 @@ private:
bool OnResetBall(const dd::Events::ResetBall &event);
bool OnResetAll(const dd::Events::ResetAll &event);
bool OnRaiseWater(const dd::Events::RaiseWater &event);
bool OnRaiseWaterWall(const dd::Events::RaiseWaterWall &event);
bool RaisePad(float amount, float speed);
bool OnPause(const dd::Events::Pause &event);
bool OnResume(const dd::Events::Resume &event);
bool OnKrakenAttack(const dd::Events::KrakenAttack &event);
+1
View File
@@ -53,6 +53,7 @@ private:
bool m_InkBlaster = false;
bool m_SquidLoaded = false;
int m_Shots = 0;
float m_InkBlasterSpeed = 5;
EntityID m_InkBlastTemplate;
EntityID m_AttachedSquid;
+72
View File
@@ -0,0 +1,72 @@
//
// Created by Adniklastrator on 2015-10-20.
//
#ifndef DAYDREAM_WATERSYSTEM_H
#define DAYDREAM_WATERSYSTEM_H
#include "Core/System.h"
#include "Core/CTransform.h"
#include "Core/CTemplate.h"
#include "Core/EventBroker.h"
#include "Core/World.h"
#include "Transform/EMove.h"
#include "Physics/CWaterVolume.h"
#include "Physics/CRectangleShape.h"
#include "Game/EPause.h"
#include "Game/EResume.h"
#include "Game/ERelevantObjectCreated.h"
#include "Game/ERaiseWater.h"
#include "Game/ERaiseWaterWall.h"
#include "Game/EArrivedAtNewStage.h"
#include "Game/EStageCleared.h"
namespace dd
{
namespace Systems
{
class WaterSystem : public System
{
public:
WaterSystem(World* world, std::shared_ptr<dd::EventBroker> eventBroker)
: System(world, eventBroker)
{ }
void Initialize() override;
void Update(double dt) override;
void UpdateEntity(double dt, EntityID entity, EntityID parent) override;
bool IsPaused() const { return m_Pause; }
void SetPause(const bool& pause) { m_Pause = pause; }
private:
bool m_Pause = false;
EntityID m_BottomWall = 0;
dd::EventRelay<WaterSystem, dd::Events::Pause> m_EPause;
dd::EventRelay<WaterSystem, dd::Events::Resume> m_EResume;
dd::EventRelay<WaterSystem, dd::Events::RelevantObjectCreated> m_ERelevantObjectCreated;
dd::EventRelay<WaterSystem, dd::Events::StageCleared> m_EStageCleared;
dd::EventRelay<WaterSystem, dd::Events::ArrivedAtNewStage> m_EArrivedAtNewStage;
dd::EventRelay<WaterSystem, dd::Events::RaiseWater> m_ERaiseWater;
dd::EventRelay<WaterSystem, dd::Events::RaiseWaterWall> m_ERaiseWaterWall;
bool OnPause(const dd::Events::Pause &event);
bool OnResume(const dd::Events::Resume &event);
bool OnRelevantObjectCreated(const dd::Events::RelevantObjectCreated &event);
bool OnStageCleared(const dd::Events::StageCleared &event);
bool OnArrivedAtNewStage(const dd::Events::ArrivedAtNewStage &event);
bool OnRaiseWater(const dd::Events::RaiseWater &event);
bool OnRaiseWaterWall(const dd::Events::RaiseWaterWall &event);
};
}
}
#endif //DAYDREAM_WATERSYSTEM_H
+6
View File
@@ -27,7 +27,13 @@
// OpenGL
#include <GL/glew.h>
#define GLFW_INCLUDE_GLU
#define NOMINMAX
#include <GLFW/glfw3.h>
#ifdef BUILD_RENDERER_DIRECTX
#define GLFW_EXPOSE_NATIVE_WIN32
#define GLFW_EXPOSE_NATIVE_WGL
#include <GLFW/glfw3native.h>
#endif
#include <glext.h>
#include "Core/Util/GLError.h"
+64
View File
@@ -0,0 +1,64 @@
/*
This file is part of Daydream Engine.
Copyright 2014 Adam Byléhn, Tobias Dahl, Simon Holmberg, Viktor Ljung
Daydream Engine is free software: you can redistribute it and/or modify
it under the terms of the GNU Lesser General Public License as published by
the Free Software Foundation, either version 3 of the License, or
(at your option) any later version.
Daydream Engine is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU Lesser General Public License for more details.
You should have received a copy of the GNU Lesser General Public License
along with Daydream Engine. If not, see <http://www.gnu.org/licenses/>.
*/
#ifndef DD_BASERENDERER_H__
#define DD_BASERENDERER_H__
#include "Core/Util/Rectangle.h"
#include "Core/ResourceManager.h"
#include "Rendering/Camera.h"
#include "Rendering/RenderQueue.h"
namespace dd
{
class BaseRenderer
{
public:
GLFWwindow* Window() const { return m_Window; }
Rectangle Resolution() const { return m_Resolution; }
void SetResolution(const Rectangle& resolution) { m_Resolution = resolution; }
bool Fullscreen() { return m_Fullscreen; }
void SetFullscreen(bool fullscreen) { m_Fullscreen = fullscreen; }
bool VSYNC() const { return m_VSYNC; }
void SetVSYNC(bool vsync) { m_VSYNC = vsync; }
const dd::Camera* Camera() const { return m_Camera; }
void SetCamera(const dd::Camera* camera)
{
if (camera == nullptr) {
m_Camera = m_DefaultCamera.get();
} else {
m_Camera = camera;
}
}
virtual void Initialize() = 0;
virtual void Draw(RenderQueueCollection& rq) = 0;
protected:
Rectangle m_Resolution = Rectangle(1280, 720);
bool m_Fullscreen = false;
bool m_VSYNC = false;
std::unique_ptr<dd::Camera> m_DefaultCamera = nullptr;
const dd::Camera* m_Camera = nullptr;
GLFWwindow* m_Window = nullptr;
};
}
#endif // Renderer_h__
+45
View File
@@ -0,0 +1,45 @@
/*
This file is part of Daydream Engine.
Copyright 2014 Adam Byléhn, Tobias Dahl, Simon Holmberg, Viktor Ljung
Daydream Engine is free software: you can redistribute it and/or modify
it under the terms of the GNU Lesser General Public License as published by
the Free Software Foundation, either version 3 of the License, or
(at your option) any later version.
Daydream Engine is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU Lesser General Public License for more details.
You should have received a copy of the GNU Lesser General Public License
along with Daydream Engine. If not, see <http://www.gnu.org/licenses/>.
*/
#ifndef BaseTexture_h__
#define BaseTexture_h__
#include <string>
#include <unordered_map>
#include <cstdio>
#include "Core/ResourceManager.h"
#include "Rendering/PNG.h"
namespace dd
{
class BaseTexture : public Resource
{
friend class ResourceManager;
public:
unsigned int Width = 0;
unsigned int Height = 0;
};
}
#endif
+1 -1
View File
@@ -20,7 +20,7 @@
#define Components_PointLight_h__
#include "Core/Component.h"
#include "Core/Color.h"
#include "Rendering/Color.h"
namespace dd
{
@@ -65,15 +65,15 @@ public:
float FarClip() const { return m_FarClip; }
void SetFarClip(float val);
private:
void UpdateViewMatrix();
void UpdateProjectionMatrix();
float m_AspectRatio;
float m_FOV;
float m_NearClip;
float m_FarClip;
private:
void UpdateViewMatrix();
void UpdateProjectionMatrix();
glm::vec3 m_Position;
glm::quat m_Orientation;
@@ -0,0 +1,32 @@
#ifndef Model_h__
#define Model_h__
#include <string>
#include <d3d11.h>
#include "Rendering/RawModel.h"
#include "Core/StaticSystem.h"
#include "Rendering/Renderer.h"
namespace dd
{
class Model : public RawModel
{
friend class ResourceManager;
private:
Model(std::string fileName);
public:
~Model();
ID3D11Buffer* VertexBuffer = nullptr;
ID3D11Buffer* IndexBuffer = nullptr;
unsigned int NumVertices;
};
}
#endif // Model_h__
@@ -0,0 +1,86 @@
/*
This file is part of Daydream Engine.
Copyright 2014 Adam Byléhn, Tobias Dahl, Simon Holmberg, Viktor Ljung
Daydream Engine is free software: you can redistribute it and/or modify
it under the terms of the GNU Lesser General Public License as published by
the Free Software Foundation, either version 3 of the License, or
(at your option) any later version.
Daydream Engine is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU Lesser General Public License for more details.
You should have received a copy of the GNU Lesser General Public License
along with Daydream Engine. If not, see <http://www.gnu.org/licenses/>.
*/
#ifndef DD_RENDERER_H__
#define DD_RENDERER_H__
#include <d3d11.h>
#pragma comment (lib, "d3d11.lib")
#include <DirectXTK/SimpleMath.h>
using namespace DirectX::SimpleMath;
//#pragma comment (lib, "DirectXTK.lib")
#include "Rendering/BaseRenderer.h"
namespace dd
{
class Model;
class ShaderProgram;
class Renderer : public BaseRenderer
{
public:
~Renderer();
void Initialize() override;
void Draw(RenderQueueCollection& rq) override;
D3D11_RASTERIZER_DESC m_RasterDesc;
IDXGISwapChain* m_SwapChain = nullptr;
ID3D11Device* m_Device = nullptr;
ID3D11RasterizerState* m_RasterState = nullptr;
ID3D11DeviceContext* m_DeviceContext = nullptr;
ID3D11RenderTargetView* m_BackBuffer = nullptr;
ID3D11DepthStencilView* m_DepthBuffer = nullptr;
ID3D11SamplerState* m_SamplerState = nullptr;
private:
struct ConstantBufferStruct
{
Matrix MVP;
Matrix ModelMatrix;
Matrix ViewMatrix;
Matrix ProjectionMatrix;
Matrix InverseTransposeViewModel;
Vector4 Color;
Vector4 LightPositions[10];
Vector4 LightColors[10];
float LightRadii[10];
unsigned int NumLights;
float paddingBitch;
} constantBufferStruct;
ShaderProgram* m_ForwardShaderProgram = nullptr;
ShaderProgram* m_GUIShaderProgram = nullptr;
ID3D11Buffer* constantBuffer = nullptr;
Model* m_UnitQuad = nullptr;
Texture* m_WhiteSphereTexture = nullptr;
static DirectX::SimpleMath::Matrix GLMtoDXModelView(glm::mat4 m);
static DirectX::SimpleMath::Matrix GLMtoDXProjection(glm::mat4 m);
void setDefaultRasterState();
void setGUIRasterState();
static bool DepthSort(const std::shared_ptr<RenderJob> &i, const std::shared_ptr<RenderJob> &j) { return (i->Depth < j->Depth); }
};
}
#endif // Renderer_h__
@@ -0,0 +1,42 @@
#ifndef ShaderProgram_h__
#define ShaderProgram_h__
#include <string>
#include <d3d11.h>
#include <d3dcompiler.h>
#pragma comment (lib, "D3DCompiler.lib")
#include "Core/StaticSystem.h"
#include "Rendering/Renderer.h"
namespace dd
{
class ShaderProgram
{
public:
ShaderProgram();
~ShaderProgram();
void CompileVertexShader(std::wstring filename);
void CompilePixelShader(std::wstring filename);
HRESULT CreateInputLayout(D3D11_INPUT_ELEMENT_DESC* ied, UINT numElements);
ID3D11InputLayout* GetInputLayout() const { return m_InputLayout; }
void Bind();
void Unbind();
private:
ID3D10Blob* m_VertexShaderBlob;
ID3D11VertexShader* m_VertexShader;
ID3D10Blob* m_PixelShaderBlob;
ID3D11PixelShader* m_PixelShader;
ID3D11InputLayout* m_InputLayout;
};
}
#endif // ShaderProgram_h__
@@ -0,0 +1,50 @@
/*
This file is part of Daydream Engine.
Copyright 2014 Adam Byléhn, Tobias Dahl, Simon Holmberg, Viktor Ljung
Daydream Engine is free software: you can redistribute it and/or modify
it under the terms of the GNU Lesser General Public License as published by
the Free Software Foundation, either version 3 of the License, or
(at your option) any later version.
Daydream Engine is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU Lesser General Public License for more details.
You should have received a copy of the GNU Lesser General Public License
along with Daydream Engine. If not, see <http://www.gnu.org/licenses/>.
*/
#ifndef Texture_h__
#define Texture_h__
#include <d3d11.h>
#include "Rendering/BaseTexture.h"
#include "Core/StaticSystem.h"
#include "Rendering/Renderer.h"
namespace dd
{
class Texture : public BaseTexture
{
friend class ResourceManager;
private:
Texture(std::string path);
public:
~Texture();
operator ID3D11Texture2D*() { return m_Texture; }
ID3D11Texture2D* m_Texture = nullptr;
ID3D11ShaderResourceView* m_ShaderResourceView = nullptr;
private:
};
}
#endif
View File
@@ -30,7 +30,7 @@
#include <boost/filesystem/path.hpp>
#include <boost/program_options.hpp>
#include "ResourceManager.h"
#include "Core/ResourceManager.h"
namespace dd
{
@@ -0,0 +1,52 @@
/*
This file is part of Daydream Engine.
Copyright 2014 Adam Byléhn, Tobias Dahl, Simon Holmberg, Viktor Ljung
Daydream Engine is free software: you can redistribute it and/or modify
it under the terms of the GNU Lesser General Public License as published by
the Free Software Foundation, either version 3 of the License, or
(at your option) any later version.
Daydream Engine is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU Lesser General Public License for more details.
You should have received a copy of the GNU Lesser General Public License
along with Daydream Engine. If not, see <http://www.gnu.org/licenses/>.
*/
#ifndef Model_h__
#define Model_h__
#include "Rendering/RawModel.h"
namespace dd
{
class Model : public RawModel
{
friend class ResourceManager;
private:
Model(std::string fileName);
public:
~Model();
GLuint VAO;
GLuint ElementBuffer;
private:
GLuint VertexBuffer;
GLuint DiffuseVertexColorBuffer;
GLuint SpecularVertexColorBuffer;
GLuint NormalBuffer;
GLuint TangentNormalsBuffer;
GLuint BiTangentNormalsBuffer;
GLuint TextureCoordBuffer;
};
}
#endif // Model_h__
@@ -19,7 +19,11 @@
#ifndef DD_RENDERER_H__
#define DD_RENDERER_H__
#include "Util/Rectangle.h"
#include "Rendering/BaseRenderer.h"
#include "Core/Util/Rectangle.h"
#include "Rendering/Camera.h"
#include "Rendering/RenderQueue.h"
#include "Rendering/ShaderProgram.h"
#include "Core/System.h"
#include "Core/CTransform.h"
#include "Core/CTemplate.h"
@@ -28,46 +32,22 @@
#include "Core/ResourceManager.h"
#include "Core/ConfigFile.h"
#include "Game/EScreenShake.h"
#include "Camera.h"
#include "RenderQueue.h"
#include "ShaderProgram.h"
#include "Rendering/Model.h"
#include "Rendering/Texture.h"
namespace dd
{
class Renderer
class Renderer : public BaseRenderer
{
public:
GLFWwindow* Window() const { return m_Window; }
Rectangle Resolution() const { return m_Resolution; }
void SetResolution(const Rectangle& resolution) { m_Resolution = resolution; }
bool Fullscreen() { return m_Fullscreen; }
void SetFullscreen(bool fullscreen) { m_Fullscreen = fullscreen; }
bool VSYNC() const { return m_VSYNC; }
void SetVSYNC(bool vsync) { m_VSYNC = vsync; }
const dd::Camera* Camera() const { return m_Camera; }
void SetCamera(const dd::Camera* camera)
{
if (camera == nullptr) {
m_Camera = m_DefaultCamera.get();
} else {
m_Camera = camera;
}
}
void Initialize();
void Draw(RenderQueueCollection& rq);
void Initialize() override;
void Draw(RenderQueueCollection& rq) override;
void PlaceCamera(glm::vec3 position);
private:
Rectangle m_Resolution = Rectangle(1280, 720);
bool m_Fullscreen = false;
bool m_VSYNC = false;
std::unique_ptr<dd::Camera> m_DefaultCamera = nullptr;
const dd::Camera* m_Camera = nullptr;
int m_GLVersion[2];
std::string m_GLVendor;
GLFWwindow* m_Window = nullptr;
ShaderProgram* m_SpDeferred1;
ShaderProgram* m_SpDeferred2;
@@ -80,6 +60,7 @@ private:
GLuint m_ScreenQuad = 0;
Model* m_UnitSphere = nullptr;
Model* m_UnitQuad = nullptr;
Texture* m_ErrorTexture;
Texture* m_StandardNormal;
Texture* m_StandardSpecular;
Texture* m_WhiteSphereTexture;
@@ -27,7 +27,7 @@
#include <boost/filesystem.hpp>
#include <boost/filesystem/path.hpp>
#include "ResourceManager.h"
#include "Core/ResourceManager.h"
namespace dd
{
@@ -19,17 +19,12 @@
#ifndef Texture_h__
#define Texture_h__
#include <string>
#include <unordered_map>
#include <cstdio>
#include "ResourceManager.h"
#include "PNG.h"
#include "Rendering/BaseTexture.h"
namespace dd
{
class Texture : public Resource
class Texture : public BaseTexture
{
friend class ResourceManager;
@@ -41,16 +36,9 @@ public:
void Bind(GLenum textureUnit = GL_TEXTURE0);
operator GLuint() const { return m_Texture; }
unsigned int Width = 0;
unsigned int Height = 0;
private:
GLuint m_Texture = 0;
};
}
#endif // Texture_h__
@@ -16,8 +16,8 @@
along with Daydream Engine. If not, see <http://www.gnu.org/licenses/>.
*/
#ifndef Model_h__
#define Model_h__
#ifndef RawModel_h__
#define RawModel_h__
#include <string>
#include <fstream>
@@ -34,21 +34,21 @@
#include <boost/filesystem/path.hpp>
#include "Core/ResourceManager.h"
#include "Core/Texture.h"
#include "Core/Skeleton.h"
#include "Rendering/Texture.h"
#include "Rendering/Skeleton.h"
namespace dd
{
class Model : public Resource
class RawModel : public Resource
{
friend class ResourceManager;
private:
Model(std::string fileName);
protected:
RawModel(std::string fileName);
public:
~Model();
~RawModel();
struct Vertex
{
@@ -75,17 +75,11 @@ public:
unsigned int EndIndex;
};
GLuint VAO;
GLuint ElementBuffer;
std::vector<MaterialGroup> TextureGroups;
std::vector<std::shared_ptr<Texture>> texture;
glm::mat4 GetMatrix();
std::vector<glm::vec3> Vertices;
std::vector<Vertex> m_Vertices;
std::vector<unsigned int> m_Indices;
Skeleton* m_Skeleton = nullptr;
glm::mat4 m_Matrix;
private:
@@ -98,17 +92,9 @@ private:
std::vector<glm::vec3> BiTangentNormals;
std::vector<glm::vec2> TextureCoords;
GLuint VertexBuffer;
GLuint DiffuseVertexColorBuffer;
GLuint SpecularVertexColorBuffer;
GLuint NormalBuffer;
GLuint TangentNormalsBuffer;
GLuint BiTangentNormalsBuffer;
GLuint TextureCoordBuffer;
void CreateSkeleton(std::vector<std::tuple<std::string, glm::mat4>> &boneInfo, std::map<std::string, int> &boneNameMapping, aiNode* node, int parentID);
};
}
#endif // Model_h__
#endif
+198
View File
@@ -0,0 +1,198 @@
/*
This file is part of Daydream Engine.
Copyright 2014 Adam Byléhn, Tobias Dahl, Simon Holmberg, Viktor Ljung
Daydream Engine is free software: you can redistribute it and/or modify
it under the terms of the GNU Lesser General Public License as published by
the Free Software Foundation, either version 3 of the License, or
(at your option) any later version.
Daydream Engine is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU Lesser General Public License for more details.
You should have received a copy of the GNU Lesser General Public License
along with Daydream Engine. If not, see <http://www.gnu.org/licenses/>.
*/
#ifndef RenderQueue_h__
#define RenderQueue_h__
#include <cstdint>
#include <forward_list>
#include "Core/Util/Rectangle.h"
namespace dd
{
class Model;
class Skeleton;
class Texture;
class RenderQueue;
struct RenderJob
{
friend class RenderQueue;
float Depth;
protected:
uint64_t Hash;
virtual void CalculateHash() = 0;
bool operator<(const RenderJob& rhs)
{
return this->Hash < rhs.Hash;
}
};
struct ModelJob : RenderJob
{
unsigned int ShaderID = 0;
unsigned int TextureID = 0;
glm::mat4 ModelMatrix;
const Texture* DiffuseTexture;
const Texture* NormalTexture;
const Texture* SpecularTexture;
float Shininess = 0.f;
glm::vec4 Color;
const dd::Model* Model = nullptr;
unsigned int StartIndex = 0;
unsigned int EndIndex = 0;
// Animation
dd::Skeleton* Skeleton = nullptr;
bool NoRootMotion = true;
std::string AnimationName;
double AnimationTime = 0;
void CalculateHash() override
{
Hash = TextureID;
}
};
struct SpriteJob : RenderJob
{
unsigned int ShaderID = 0;
unsigned int TextureID = 0;
glm::mat4 ModelMatrix;
const Texture* DiffuseTexture = nullptr;
const Texture* NormalTexture = nullptr;
const Texture* SpecularTexture = nullptr;
glm::vec4 Color;
void CalculateHash() override
{
Hash = TextureID;
}
};
struct PointLightJob : RenderJob
{
glm::vec3 Position;
glm::vec3 SpecularColor = glm::vec3(1, 1, 1);
glm::vec3 DiffuseColor = glm::vec3(1, 1, 1);
float Radius = 1.f;
void CalculateHash() override
{
Hash = 0;
}
};
struct FrameJob : SpriteJob
{
Rectangle Scissor;
Rectangle Viewport;
std::string Name;
void CalculateHash() override
{
Hash = 0;
}
};
struct WaterParticleJob : RenderJob
{
glm::vec3 Position;
glm::vec4 Color;
glm::mat4 ModelMatrix;
void CalculateHash() override
{
Hash = 0;
}
};
class RenderQueue
{
public:
template <typename T>
void Add(T &job)
{
job.CalculateHash();
Jobs.push_back(std::shared_ptr<T>(new T(job)));
m_Size++;
}
void Sort()
{
Jobs.sort();
}
void Clear()
{
Jobs.clear();
m_Size = 0;
}
int Size() const { return m_Size; }
std::list<std::shared_ptr<RenderJob>>::const_iterator begin()
{
return Jobs.begin();
}
std::list<std::shared_ptr<RenderJob>>::const_iterator end()
{
return Jobs.end();
}
std::list<std::shared_ptr<RenderJob>> Jobs;
private:
int m_Size = 0;
};
struct RenderQueueCollection
{
RenderQueue Deferred;
RenderQueue Forward;
RenderQueue Lights;
RenderQueue GUI;
void Clear()
{
Deferred.Clear();
Forward.Clear();
Lights.Clear();
GUI.Clear();
}
void Sort()
{
Deferred.Sort();
Forward.Sort();
Lights.Sort();
GUI.Sort();
}
};
}
#endif // RenderQueue_h__
+41 -20
View File
@@ -53,6 +53,16 @@ file(GLOB SOURCE_FILES_Rendering
"Rendering/*.cpp"
)
source_group(Rendering FILES ${SOURCE_FILES_Rendering})
file(GLOB SOURCE_FILES_Rendering_OpenGL
"${INCLUDE_PATH}/Rendering/OpenGL/Rendering/*.h"
"Rendering/OpenGL/*.cpp"
)
source_group(Rendering\\OpenGL FILES ${SOURCE_FILES_Rendering_OpenGL})
file(GLOB SOURCE_FILES_Rendering_DirectX
"${INCLUDE_PATH}/Rendering/DirectX/Rendering/*.h"
"Rendering/DirectX/*.cpp"
)
source_group(Rendering\\DirectX FILES ${SOURCE_FILES_Rendering_DirectX})
file(GLOB SOURCE_FILES_Transform
"${INCLUDE_PATH}/Transform/*.h"
@@ -61,8 +71,8 @@ file(GLOB SOURCE_FILES_Transform
source_group(Transform FILES ${SOURCE_FILES_Transform})
file(GLOB SOURCE_FILES_Physics
"${INCLUDE_PATH}/Physics/*.h"
"Physics/*.cpp"
"${INCLUDE_PATH}/Physics/*.h"
"Physics/*.cpp"
)
source_group(Physics FILES ${SOURCE_FILES_Physics})
@@ -102,14 +112,7 @@ set(SOURCE_FILES
${SOURCE_FILES_GUI}
)
if(CMAKE_COMPILER_IS_GNUCXX)
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -pthread")
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -w")
set(STATIC_LIBRARY_FLAGS "${STATIC_LIBRARY_FLAGS}")
endif()
add_library(game ${SOURCE_FILES})
target_link_libraries(game
set(LIBRARIES
${OPENGL_LIBRARIES}
${GLEW_LIBRARIES}
${GLFW_LIBRARIES}
@@ -118,7 +121,33 @@ target_link_libraries(game
${PNG_LIBRARIES}
${X11_LIBRARIES}
${OPENAL_LIBRARY}
${liquidfun_LIBRARIES}
${liquidfun_LIBRARIES}
)
if(BUILD_RENDERER_OPENGL)
set(SOURCE_FILES ${SOURCE_FILES}
${SOURCE_FILES_Rendering_OpenGL}
)
endif()
# Compiling for DirectX target
if(BUILD_RENDERER_DIRECTX)
set(SOURCE_FILES ${SOURCE_FILES}
${SOURCE_FILES_Rendering_DirectX}
)
set(LIBRARIES ${LIBRARIES}
${CMAKE_LIBRARY_PATH}/DirectXTK.lib
)
endif()
if(CMAKE_COMPILER_IS_GNUCXX)
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -pthread")
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -w")
set(STATIC_LIBRARY_FLAGS "${STATIC_LIBRARY_FLAGS}")
endif()
add_library(game ${SOURCE_FILES})
target_link_libraries(game
${LIBRARIES}
)
add_executable(breakout
@@ -126,14 +155,6 @@ add_executable(breakout
)
target_link_libraries(breakout
game
${OPENGL_LIBRARIES}
${GLEW_LIBRARIES}
${GLFW_LIBRARIES}
${Boost_LIBRARIES}
${assimp_LIBRARIES}
${PNG_LIBRARIES}
${X11_LIBRARIES}
${OPENAL_LIBRARY}
${liquidfun_LIBRARIES}
${LIBRARIES}
)
-3
View File
@@ -1,3 +0,0 @@
#include "PrecompiledHeader.h"
#include "Core/BGFXRenderer.h"
+22
View File
@@ -0,0 +1,22 @@
/*
This file is part of Daydream Engine.
Copyright 2014 Adam Byléhn, Tobias Dahl, Simon Holmberg, Viktor Ljung
Daydream Engine is free software: you can redistribute it and/or modify
it under the terms of the GNU Lesser General Public License as published by
the Free Software Foundation, either version 3 of the License, or
(at your option) any later version.
Daydream Engine is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU Lesser General Public License for more details.
You should have received a copy of the GNU Lesser General Public License
along with Daydream Engine. If not, see <http://www.gnu.org/licenses/>.
*/
#include "PrecompiledHeader.h"
#include "Core/StaticSystem.h"
std::unordered_map<size_t, void*> dd::StaticSystem::Instances;
+144 -3
View File
@@ -11,8 +11,11 @@ void dd::Systems::KrakenSystem::Initialize()
m_RandomGenerator = std::mt19937(rd());
EVENT_SUBSCRIBE_MEMBER(m_EPause, &KrakenSystem::OnPause);
EVENT_SUBSCRIBE_MEMBER(m_EResume, &KrakenSystem::OnResume);
EVENT_SUBSCRIBE_MEMBER(m_EContact, &KrakenSystem::OnContact);
EVENT_SUBSCRIBE_MEMBER(m_EKrakenAppear, &KrakenSystem::OnKrakenAppear);
EVENT_SUBSCRIBE_MEMBER(m_EKrakenAttack, &KrakenSystem::OnKrakenAttack);
EVENT_SUBSCRIBE_MEMBER(m_EKrakenHit, &KrakenSystem::OnKrakenHit);
EVENT_SUBSCRIBE_MEMBER(m_EKrakenDefeated, &KrakenSystem::OnKrakenDefeated);
EVENT_SUBSCRIBE_MEMBER(m_EBrickGenerating, &KrakenSystem::OnBrickGenerating);
EntityID ent = m_World->CreateEntity();
@@ -59,7 +62,7 @@ void dd::Systems::KrakenSystem::Update(double dt)
void dd::Systems::KrakenSystem::UpdateEntity(double dt, EntityID entity, EntityID parent)
{
if (IsPaused()) {
if (IsPaused() || !m_KrakenBattle) {
return;
}
@@ -68,6 +71,11 @@ void dd::Systems::KrakenSystem::UpdateEntity(double dt, EntityID entity, EntityI
auto kraken = m_World->GetComponent<Components::Kraken>(entity);
if (kraken != nullptr) {
auto transform = m_World->GetComponent<Components::Transform>(entity);
if (transform->Position.y < -10) {
m_World->RemoveEntity(entity);
return;
}
Events::KrakenAttack krakenAttack;
switch (kraken->CurrentAction)
{
@@ -77,9 +85,9 @@ void dd::Systems::KrakenSystem::UpdateEntity(double dt, EntityID entity, EntityI
m_KrakenTimer = 0;
std::uniform_real_distribution<float> dist(1, 2.999f);
float random = dist(m_RandomGenerator);
std::cout << random << std::endl;
//std::cout << random << std::endl;
kraken->CurrentAction = random;
std::cout << kraken->CurrentAction << std::endl;
//std::cout << kraken->CurrentAction << std::endl;
}
break;
case 2: // Grabbing
@@ -126,6 +134,42 @@ bool dd::Systems::KrakenSystem::OnResume(const dd::Events::Resume &event)
return true;
}
bool dd::Systems::KrakenSystem::OnContact(const dd::Events::Contact &event)
{
Components::Kraken* kraken1 = m_World->GetComponent<Components::Kraken>(event.Entity1);
Components::Kraken* kraken2 = m_World->GetComponent<Components::Kraken>(event.Entity2);
Components::Kraken* kraken;
if (kraken1 != nullptr && kraken2 != nullptr) {
return false;
}
EntityID krakenEntity, otherEntitiy;
//Which is the ball?
if (kraken1 != nullptr) {
krakenEntity = event.Entity1;
otherEntitiy = event.Entity2;
kraken = kraken1;
}
else if (kraken2 != nullptr) {
krakenEntity = event.Entity2;
otherEntitiy = event.Entity1;
kraken = kraken2;
}
else {
return false;
}
auto ball = m_World->GetComponent<Components::Ball>(otherEntitiy);
if (ball != nullptr) {
Events::KrakenHit e;
e.Kraken = krakenEntity;
e.Hitter = otherEntitiy;
EventBroker->Publish(e);
}
}
bool dd::Systems::KrakenSystem::OnKrakenAppear(const dd::Events::KrakenAppear &event)
{
auto ent = m_World->CloneEntity(m_KrakenTemplate);
@@ -144,6 +188,103 @@ bool dd::Systems::KrakenSystem::OnKrakenAttack(const dd::Events::KrakenAttack &e
return true;
}
bool dd::Systems::KrakenSystem::OnKrakenHit(const dd::Events::KrakenHit &event)
{
auto kraken = m_World->GetComponent<Components::Kraken>(event.Kraken);
//kraken->Health--;
//std::cout << kraken->Health << std::endl;
kraken->Health = -1;
if (kraken->Health < 0) {
Events::KrakenDefeated e;
e.Kraken = event.Kraken;
e.Hitter = event.Hitter;
EventBroker->Publish(e);
}
return false;
}
bool dd::Systems::KrakenSystem::OnKrakenDefeated(const dd::Events::KrakenDefeated &event)
{
m_KrakenBattle = false;
auto kraken = m_World->GetComponent<Components::Kraken>(event.Kraken);
auto physicsComponent = m_World->GetComponent<Components::Physics>(event.Kraken);
/*physicsComponent->CollisionType = CollisionType::Type::Dynamic;
physicsComponent->GravityScale = 1.f;
physicsComponent->Mask = static_cast<CollisionLayer::Type>(CollisionLayer::Water | CollisionLayer::Wall);
physicsComponent->Calculate = false;*/
auto transformComponentBrick = m_World->GetComponent<Components::Transform>(event.Kraken);
auto transformComponentHitter = m_World->GetComponent<Components::Transform>(event.Hitter);
auto brickModel = m_World->GetComponent<Components::Model>(event.Kraken);
auto cTransform = m_World->GetComponent<Components::Transform>(event.Kraken);
/*cTransform->Position = cTransform->Position + transformComponentBrick->Position;
glm::vec2 ballToBrick = 4.f * glm::normalize(glm::vec2(cTransform->Position.x - transformComponentHitter->Position.x, cTransform->Position.y - transformComponentHitter->Position.y));
cTransform->Velocity = glm::vec3(ballToBrick.x, ballToBrick.y, 0.f);
std::uniform_real_distribution<float> dist(-1.5f, 1.5f);
int impulseStrength = dist(m_RandomGenerator);
Events::SetImpulse i;
i.Entity = event.Kraken;
i.Impulse = glm::vec2(impulseStrength, 0.f);
i.Point = glm::vec2(cTransform->Position.x, cTransform->Position.y + 0.5f);
EventBroker->Publish(i);*/
auto cModel = m_World->GetComponent<Components::Model>(event.Kraken);
cModel->Color = brickModel->Color;
cModel->Color *= 0.5f;
/*m_World->RemoveComponent<Components::Template>(event.Kraken);
m_World->SetEntityParent(event.Kraken, 0);
m_World->CommitEntity(event.Kraken);*/
//Particle trail
Events::CreateParticleSequence trail;
trail.parent = event.Kraken;
trail.AlphaValues.push_back(1.f);
trail.AlphaValues.push_back(0.f);
trail.ScaleValues.push_back(glm::vec3(0.08f));
trail.ScaleValues.push_back(glm::vec3(0.f));
trail.RadiusDistribution = 1;
trail.EmitterLifeTime = 2.f;
trail.ParticleLifeTime = 1.f;
trail.ParticlesPerTick = 1;
trail.SpawnRate = 0.1f;
trail.Speed = 10.f;
trail.EmittingAngle = glm::half_pi<float>();
trail.SpriteFile = "Textures/Particles/FadeBall.png";
trail.Color = brickModel->Color;
//p.Spread = ...
EventBroker->Publish(trail);
//ParticlePoof
Events::CreateParticleSequence poof;
poof.EmitterLifeTime = 4;
poof.EmittingAngle = glm::half_pi<float>();
poof.Spread = 0.5f;
poof.NumberOfTicks = 1;
poof.ParticleLifeTime = 1.5f;
poof.ParticlesPerTick = 1;
poof.Position = cTransform->Position;
poof.ScaleValues.clear();
poof.ScaleValues.push_back(glm::vec3(0.5f));
poof.ScaleValues.push_back(glm::vec3(2.f, 2.f, 0.2f));
poof.SpriteFile = "Textures/Particles/Cloud_Particle.png";
poof.Color = brickModel->Color;
poof.AlphaValues.clear();
poof.AlphaValues.push_back(1.f);
poof.AlphaValues.push_back(0.f);
poof.Speed = 10;
EventBroker->Publish(poof);
return true;
}
bool dd::Systems::KrakenSystem::OnBrickGenerating(const dd::Events::BrickGenerating &event)
{
return true;
+48 -35
View File
@@ -18,10 +18,12 @@ void dd::Systems::LevelSystem::Initialize()
EVENT_SUBSCRIBE_MEMBER(m_EMultiBallLost, &LevelSystem::OnMultiBallLost);
EVENT_SUBSCRIBE_MEMBER(m_EPowerUpTaken, &LevelSystem::OnPowerUpTaken);
EVENT_SUBSCRIBE_MEMBER(m_EStageCleared, &LevelSystem::OnStageCleared);
EVENT_SUBSCRIBE_MEMBER(m_EArrivedAtNewStage, &LevelSystem::OnArrivedAtNewStage);
EVENT_SUBSCRIBE_MEMBER(m_EPause, &LevelSystem::OnPause);
EVENT_SUBSCRIBE_MEMBER(m_EResume, &LevelSystem::OnResume);
EVENT_SUBSCRIBE_MEMBER(m_EHitPad, &LevelSystem::OnHitPad);
EVENT_SUBSCRIBE_MEMBER(m_EBrickGenerating, &LevelSystem::OnBrickGenerating);
EVENT_SUBSCRIBE_MEMBER(m_EKrakenDefeated, &LevelSystem::OnKrakenDefeated);
m_GodMode = ResourceManager::Load<ConfigFile>("Config.ini")->GetValue("Cheat.GodMode", false);
@@ -60,7 +62,7 @@ void dd::Systems::LevelSystem::Initialize()
travels->CurrentlyTraveling = false;
auto model = m_World->AddComponent<Components::Model>(t_halfPipe);
model->ModelFile = "Models/Test/halfpipe/Halfpipe.obj";
model->Color = glm::vec4(0.8f, 0.8f, 0.8f, 0.3f);
model->Color = glm::vec4(0.8f, 0.8f, 0.8f, 1.f);
m_World->CommitEntity(t_halfPipe);
auto t_halfPipe2 = m_World->CloneEntity(t_halfPipe);
@@ -84,16 +86,7 @@ void dd::Systems::LevelSystem::Initialize()
}*/
// auto particleEmitter= m_World->AddComponent<Components::Emitter>(Pe);
//Water test
{
auto t_waterBody = m_World->CreateEntity();
auto transform = m_World->AddComponent<Components::Transform>(t_waterBody);
transform->Position = glm::vec3(0.f, -3.5f, -10.f);
transform->Scale = glm::vec3(7.0f, 1.5f, 1.f);
auto water = m_World->AddComponent<Components::WaterVolume>(t_waterBody);
auto body = m_World->AddComponent<Components::RectangleShape>(t_waterBody);
m_World->CommitEntity(t_waterBody);
}
//ParticleTest
@@ -114,7 +107,7 @@ void dd::Systems::LevelSystem::Initialize()
particleEmitter->Spread = glm::pi<float>()*2;
particleEmitter->EmittingAngle = glm::pi<float>();
particleEmitter->LifeTime = 50;
{
auto Pt = m_World->CreateEntity(Pe);
auto PtTransform = m_World->AddComponent<Components::Transform>(Pt);
@@ -134,13 +127,13 @@ void dd::Systems::LevelSystem::Initialize()
//TODO: Why does the ball not collide with these bricks?
//BottomBox
{
auto BottomWall = m_World->CreateEntity();
EntityID BottomWall = m_World->CreateEntity();
auto transform = m_World->AddComponent<Components::Transform>(BottomWall);
auto wall = m_World->AddComponent<Components::Wall>(BottomWall);
transform->Position = glm::vec3(0.f, -6.f, -10.f);
transform->Scale = glm::vec3(20.f, 0.5f, 1.f);
//std::shared_ptr<Components::Sprite> sprite = m_World->AddComponent<Components::Sprite>(BottomWall);
//sprite->SpriteFile = "Textures/Core/ErrorTexture.png";
std::shared_ptr<Components::Sprite> sprite = m_World->AddComponent<Components::Sprite>(BottomWall);
sprite->SpriteFile = "Textures/Core/ErrorTexture.png";
std::shared_ptr<Components::RectangleShape> rectangleShape = m_World->AddComponent<Components::RectangleShape>(BottomWall);
rectangleShape->Dimensions = glm::vec2(20.f, 0.5f);
std::shared_ptr<Components::Physics> physics = m_World->AddComponent<Components::Physics>(BottomWall);
@@ -152,6 +145,8 @@ void dd::Systems::LevelSystem::Initialize()
physics->Mask = static_cast<CollisionLayer::Type>(CollisionLayer::LifeBuoy);
}
m_World->CommitEntity(BottomWall);
m_World->SetProperty(BottomWall, "Name", "BottomWall");
}
{
@@ -301,6 +296,7 @@ void dd::Systems::LevelSystem::UpdateEntity(double dt, EntityID entity, EntityID
} else if (brick->Type == InkBlasterBrick) {
Events::InkBlaster e;
e.Shots = 5;
e.Speed = 7;
EventBroker->Publish(e);
} else if(brick->Type == KrakenAttackBrick) {
Events::KrakenAttack e;
@@ -321,6 +317,7 @@ void dd::Systems::LevelSystem::UpdateEntity(double dt, EntityID entity, EntityID
Events::StageCleared ec;
ec.ClearedStage = m_CurrentLevel;
ec.StageCluster = m_CurrentCluster;
ec.StagesInCluster = m_StagesInCluster;
EventBroker->Publish(ec);
} else {
if (ball != nullptr && MultiBalls() > 0) {
@@ -443,7 +440,7 @@ EntityID dd::Systems::LevelSystem::CreateBrick(int row, int line, glm::vec2 spac
} else if (typeInt == KrakenAttackBrick) {
cBrick->Type = KrakenAttackBrick;
auto type = m_World->AddComponent<Components::KrakenAttackBrick>(brick);
model->Color = glm::vec4(0.f, 0.5f, 1.0f, .0f);
model->Color = glm::vec4(0.f, 0.5f, 1.0f, 1.0f);
} else if (typeInt == Kraken) {
Events::KrakenAppear e;
e.Position = transform->Position;
@@ -509,14 +506,14 @@ void dd::Systems::LevelSystem::GetBrickSet(int set)
// m is magenta.
// d is dark.
// Feel free to make your own.
glm::vec4 w = glm::vec4(1, 1, 1, 0);
glm::vec4 r = glm::vec4(1, 0, 0, 0);
glm::vec4 g = glm::vec4(0, 1, 0, 0);
glm::vec4 b = glm::vec4(0, 0, 1, 0);
glm::vec4 y = glm::vec4(1, 1, 0, 0);
glm::vec4 c = glm::vec4(0, 1, 1, 0);
glm::vec4 m = glm::vec4(1, 0, 1, 0);
glm::vec4 d = glm::vec4(0, 0, 0, 0);
glm::vec4 w = glm::vec4(1, 1, 1, 1);
glm::vec4 r = glm::vec4(1, 0, 0, 1);
glm::vec4 g = glm::vec4(0, 1, 0, 1);
glm::vec4 b = glm::vec4(0, 0, 1, 1);
glm::vec4 y = glm::vec4(1, 1, 0, 1);
glm::vec4 c = glm::vec4(0, 1, 1, 1);
glm::vec4 m = glm::vec4(1, 0, 1, 1);
glm::vec4 d = glm::vec4(0, 0, 0, 1);
if (set == 1) {
level =
@@ -688,6 +685,7 @@ void dd::Systems::LevelSystem::BrickHit(EntityID entityHitter, EntityID entityBr
Events::InkBlaster e;
e.Transform = transformComponentBrick;
e.Shots = 5;
e.Speed = 7;
EventBroker->Publish(e);
}
else {
@@ -710,8 +708,6 @@ void dd::Systems::LevelSystem::BrickHit(EntityID entityHitter, EntityID entityBr
auto brickChildren = m_World->GetEntityChildren(entityBrick);
for (auto b : brickChildren)
{
auto cTransform = m_World->GetComponent<Components::Transform>(b);
cTransform->Position = cTransform->Position + transformComponentBrick->Position;
glm::vec2 ballToBrick = 4.f * glm::normalize(glm::vec2(cTransform->Position.x - transformComponentHitter->Position.x, cTransform->Position.y - transformComponentHitter->Position.y));
@@ -837,6 +833,16 @@ bool dd::Systems::LevelSystem::OnPowerUpTaken(const dd::Events::PowerUpTaken &ev
return true;
}
bool dd::Systems::LevelSystem::OnKrakenDefeated(const dd::Events::KrakenDefeated &event)
{
SetNumberOfBricks(NumberOfBricks() - 1);
m_LooseBricks--;
std::cout << m_LooseBricks << std::endl;
return true;
}
bool dd::Systems::LevelSystem::OnStageCleared(const dd::Events::StageCleared &event)
{
if (!m_Cleared) {
@@ -848,12 +854,13 @@ bool dd::Systems::LevelSystem::OnStageCleared(const dd::Events::StageCleared &ev
es.Score = 500;
EventBroker->Publish(es);
m_CurrentLevel++;
if (m_CurrentLevel < 6) {
if (m_CurrentLevel <= event.StagesInCluster) {
GetNextLevel();
CreateLevel(12); //NextLevelDistance
} else {
// Win
Events::ClusterClear e;
e.ClusterCleared = m_CurrentCluster;
EventBroker->Publish(e);
Events::Pause p;
@@ -864,6 +871,12 @@ bool dd::Systems::LevelSystem::OnStageCleared(const dd::Events::StageCleared &ev
return true;
}
bool dd::Systems::LevelSystem::OnArrivedAtNewStage(const dd::Events::ArrivedAtNewStage &event)
{
m_Cleared = false;
return true;
}
void dd::Systems::LevelSystem::GetNextLevel()
{
std::array<int, 42> level;
@@ -889,14 +902,14 @@ void dd::Systems::LevelSystem::GetNextLevel()
// m is magenta.
// d is dark.
// Feel free to make your own.
glm::vec4 w = glm::vec4(1, 1, 1, 0);
glm::vec4 r = glm::vec4(1, 0, 0, 0);
glm::vec4 g = glm::vec4(0, 1, 0, 0);
glm::vec4 b = glm::vec4(0, 0, 1, 0);
glm::vec4 y = glm::vec4(1, 1, 0, 0);
glm::vec4 c = glm::vec4(0, 1, 1, 0);
glm::vec4 m = glm::vec4(1, 0, 1, 0);
glm::vec4 d = glm::vec4(0, 0, 0, 0);
glm::vec4 w = glm::vec4(1, 1, 1, 1);
glm::vec4 r = glm::vec4(1, 0, 0, 1);
glm::vec4 g = glm::vec4(0, 1, 0, 1);
glm::vec4 b = glm::vec4(0, 0, 1, 1);
glm::vec4 y = glm::vec4(1, 1, 0, 1);
glm::vec4 c = glm::vec4(0, 1, 1, 1);
glm::vec4 m = glm::vec4(1, 0, 1, 1);
glm::vec4 d = glm::vec4(0, 0, 0, 1);
//glm::vec4 p4 = glm::vec4(asd.f / 255.f, asd.f / 255.f, sad.f / 255.f, 1.f);
glm::vec4 br = glm::vec4(143.f / 255.f, 98.f / 255.f, 0.f / 255.f, 1.f);
File diff suppressed because it is too large Load Diff
+41 -14
View File
@@ -30,6 +30,7 @@ void dd::Systems::PadSystem::Initialize()
EVENT_SUBSCRIBE_MEMBER(m_EResetBall, &PadSystem::OnResetBall);
EVENT_SUBSCRIBE_MEMBER(m_EResetAll, &PadSystem::OnResetAll);
EVENT_SUBSCRIBE_MEMBER(m_ERaiseWater, &PadSystem::OnRaiseWater);
EVENT_SUBSCRIBE_MEMBER(m_ERaiseWaterWall, &PadSystem::OnRaiseWaterWall);
EVENT_SUBSCRIBE_MEMBER(m_EPause, &PadSystem::OnPause);
EVENT_SUBSCRIBE_MEMBER(m_EResume, &PadSystem::OnResume);
EVENT_SUBSCRIBE_MEMBER(m_EKrakenAttack, &PadSystem::OnKrakenAttack);
@@ -74,6 +75,17 @@ void dd::Systems::PadSystem::Initialize()
m_StickTransform = transform;
m_StickyAim = sticky;
/*{
auto entChild = m_World->CreateEntity(ent);
std::shared_ptr<Components::Transform> transform = m_World->AddComponent<Components::Transform>(entChild);
transform->Position = glm::vec3(0.f, 12.5f, 0.f);
transform->Scale = glm::vec3(0.1f, 25.f, 0.1f);
std::shared_ptr<Components::Sprite> sprite = m_World->AddComponent<Components::Sprite>(entChild);
sprite->SpriteFile = "Models/Brick/White.png";
sprite->Color = glm::vec4(0.f, 0.5f, 0.f, 0.5f);
}*/
}
m_ResetBall = true;
@@ -218,8 +230,14 @@ bool dd::Systems::PadSystem::OnKeyDown(const dd::Events::KeyDown &event) {
} else if (val == GLFW_KEY_W) {
Events::RaiseWater e;
e.Amount = 0.2;
e.Speed = 0.2;
EventBroker->Publish(e);
} else if (val == GLFW_KEY_A) {
} else if (val == GLFW_KEY_Q) {
Events::RaiseWaterWall e;
e.Amount = 0.2;
e.Speed = 0.2;
EventBroker->Publish(e);
} else if (val == GLFW_KEY_A) {
Events::ResetAll e;
EventBroker->Publish(e);
} else if (val == GLFW_KEY_M) {
@@ -266,6 +284,7 @@ bool dd::Systems::PadSystem::OnKeyDown(const dd::Events::KeyDown &event) {
} else if (val == GLFW_KEY_I) {
Events::InkBlaster e;
e.Shots = 5;
e.Speed = 7;
EventBroker->Publish(e);
} else if (val == GLFW_KEY_K) {
Events::KrakenAttack e;
@@ -415,21 +434,29 @@ bool dd::Systems::PadSystem::OnResetAll(const dd::Events::ResetAll &event)
}
bool dd::Systems::PadSystem::OnRaiseWater(const dd::Events::RaiseWater &event)
{
RaisePad(event.Amount, event.Speed);
return true;
}
bool dd::Systems::PadSystem::OnRaiseWaterWall(const dd::Events::RaiseWaterWall &event)
{
RaisePad(event.Amount, event.Speed);
return true;
}
bool dd::Systems::PadSystem::RaisePad(float amount, float speed)
{
auto transform = Transform();
glm::vec3 raise = glm::vec3(0, event.Amount, 0);
transform->Position += raise;
{
auto t_waterBody = m_World->CreateEntity();
auto transform = m_World->AddComponent<Components::Transform>(t_waterBody);
transform->Position = glm::vec3(0.f, -3.5f, -10.f);
transform->Scale = glm::vec3(7.0f, event.Amount * 1.6f, 1.f);
auto water = m_World->AddComponent<Components::WaterVolume>(t_waterBody);
auto body = m_World->AddComponent<Components::RectangleShape>(t_waterBody);
m_World->CommitEntity(t_waterBody);
}
glm::vec3 raise = glm::vec3(0, amount, 0);
Events::Move e;
e.Entity = m_Entity;
e.GoalPosition = transform->Position + raise;
e.Speed = speed;
e.Queue = true;
EventBroker->Publish(e);
return true;
}
+4 -1
View File
@@ -100,6 +100,7 @@ bool dd::Systems::ProjectileSystem::OnInkBlaster(const dd::Events::InkBlaster &e
{
m_InkBlaster = true;
m_Shots = event.Shots;
m_InkBlasterSpeed = event.Speed;
return true;
}
@@ -117,9 +118,11 @@ bool dd::Systems::ProjectileSystem::OnActionButton(const dd::Events::ActionButto
if (m_InkBlaster && m_SquidLoaded) {
auto ent = m_World->CloneEntity(m_InkBlastTemplate);
m_World->RemoveComponent<Components::Template>(ent);
auto projectile = m_World->GetComponent<Components::Projectile>(ent);
projectile->Speed = m_InkBlasterSpeed;
auto transform = m_World->GetComponent<Components::Transform>(ent);
transform->Position = event.Position;
transform->Velocity = glm::vec3(0, 7, 0);
transform->Velocity = glm::vec3(0, projectile->Speed, 0);
m_Shots--;
if (m_Shots <= 0) {
auto ball = m_World->GetComponent<Components::Ball>(m_AttachedSquid);
+151
View File
@@ -0,0 +1,151 @@
//
// Created by Adniklastrator on 2015-10-08.
//
#include "PrecompiledHeader.h"
#include "Game/ProjectileSystem.h"
void dd::Systems::ProjectileSystem::Initialize()
{
EVENT_SUBSCRIBE_MEMBER(m_EContact, &ProjectileSystem::OnContact);
EVENT_SUBSCRIBE_MEMBER(m_EPause, &ProjectileSystem::OnPause);
EVENT_SUBSCRIBE_MEMBER(m_EResume, &ProjectileSystem::OnResume);
EVENT_SUBSCRIBE_MEMBER(m_EInkBlaster, &ProjectileSystem::OnInkBlaster);
EVENT_SUBSCRIBE_MEMBER(m_EHitPad, &ProjectileSystem::OnHitPad);
EVENT_SUBSCRIBE_MEMBER(m_EActionButton, &ProjectileSystem::OnActionButton);
//Ink Blast
{
auto ent = m_World->CreateEntity();
m_World->SetProperty(ent, "Name", "Projectile");
std::shared_ptr<Components::Transform> ctransform = m_World->AddComponent<Components::Transform>(ent);
auto circleShape = m_World->AddComponent<Components::CircleShape>(ent);
auto inkBlastTemplate = m_World->AddComponent<Components::Template>(ent);
circleShape->Radius = 0.1f;
auto physics = m_World->AddComponent<Components::Physics>(ent);
physics->CollisionType = CollisionType::Type::Dynamic;
physics->Category = CollisionLayer::Type::Projectile;
physics->Mask = static_cast<CollisionLayer::Type>(CollisionLayer::Type::Pad | CollisionLayer::Type::Brick | CollisionLayer::Type::Wall);
physics->Calculate = true;
ctransform->Position = glm::vec3(0.f, 0.f, -10.f);
ctransform->Scale = glm::vec3(0.6f, 0.6f, 0.6f);
// auto cModel = m_World->AddComponent<Components::Model>(ent);
// cModel->ModelFile = "Models/Test/Ball/Sid.obj";
auto cSprite = m_World->AddComponent<Components::Sprite>(ent);
cSprite->SpriteFile = "Textures/Particles/OilShot.png";
auto projectile = m_World->AddComponent<Components::Projectile>(ent);
m_World->CommitEntity(ent);
m_InkBlastTemplate = ent;
}
return;
}
void dd::Systems::ProjectileSystem::Update(double dt)
{
if (m_Pause) {
return;
}
}
void dd::Systems::ProjectileSystem::UpdateEntity(double dt, EntityID entity, EntityID parent)
{
if (IsPaused()) {
return;
}
auto templateCheck = m_World->GetComponent<Components::Template>(entity);
if (templateCheck != nullptr){ return; }
auto shot = m_World->GetComponent<Components::Projectile>(entity);
if (shot != nullptr) {
auto transform = m_World->GetComponent<Components::Transform>(entity);
if (transform->Position.y > 8) {
m_World->RemoveEntity(entity);
}
}
}
bool dd::Systems::ProjectileSystem::OnPause(const dd::Events::Pause &event)
{
/*if (event.Type != "ProjectileSystem" && event.Type != "All") {
return false;
}*/
m_Pause = true;
return true;
}
bool dd::Systems::ProjectileSystem::OnResume(const dd::Events::Resume &event)
{
/*if (event.Type != "ProjectileSystem" && event.Type != "All") {
return false;
}*/
m_Pause = false;
return true;
}
bool dd::Systems::ProjectileSystem::OnContact(const dd::Events::Contact &event)
{
return true;
}
bool dd::Systems::ProjectileSystem::OnInkBlaster(const dd::Events::InkBlaster &event)
{
m_InkBlaster = true;
m_Shots = event.Shots;
m_InkBlasterSpeed = event.Speed;
return true;
}
bool dd::Systems::ProjectileSystem::OnHitPad(const dd::Events::HitPad &event)
{
if (m_InkBlaster) {
m_SquidLoaded = true;
m_AttachedSquid = event.Ball;
}
return true;
}
bool dd::Systems::ProjectileSystem::OnActionButton(const dd::Events::ActionButton &event)
{
if (m_InkBlaster && m_SquidLoaded) {
auto ent = m_World->CloneEntity(m_InkBlastTemplate);
m_World->RemoveComponent<Components::Template>(ent);
auto projectile = m_World->GetComponent<Components::Projectile>(ent);
projectile->Speed = m_InkBlasterSpeed;
auto transform = m_World->GetComponent<Components::Transform>(ent);
transform->Position = event.Position;
<<<<<<< HEAD
transform->Velocity = glm::vec3(0, projectile->Speed, 0);
=======
transform->Velocity = glm::vec3(0, 7, 0);
>>>>>>> origin/master
m_Shots--;
if (m_Shots <= 0) {
auto ball = m_World->GetComponent<Components::Ball>(m_AttachedSquid);
m_InkBlaster = false;
m_SquidLoaded = false;
ball->InkBlaster = false;
ball->Sticky = false;
ball->Waiting = true;
{
Events::InkBlasterOver e;
e.Ball = m_AttachedSquid;
EventBroker->Publish(e);
}
{
Events::ActionButton e;
EventBroker->Publish(e);
}
}
}
return true;
}
+1 -1
View File
@@ -97,7 +97,7 @@ bool dd::Systems::TravellingSystem::OnResume(const dd::Events::Resume &event)
bool dd::Systems::TravellingSystem::OnStageCleared(const dd::Events::StageCleared &event)
{
if (event.ClearedStage < 5) {
if (event.ClearedStage < event.StagesInCluster) {
m_Travelling = true;
}
return true;
+124
View File
@@ -0,0 +1,124 @@
//
// Created by Adniklastrator on 2015-10-20.
//
#include "PrecompiledHeader.h"
#include "Game/WaterSystem.h"
void dd::Systems::WaterSystem::Initialize()
{
EVENT_SUBSCRIBE_MEMBER(m_EPause, &WaterSystem::OnPause);
EVENT_SUBSCRIBE_MEMBER(m_EResume, &WaterSystem::OnResume);
EVENT_SUBSCRIBE_MEMBER(m_ERelevantObjectCreated, &WaterSystem::OnRelevantObjectCreated);
EVENT_SUBSCRIBE_MEMBER(m_EStageCleared, &WaterSystem::OnStageCleared);
EVENT_SUBSCRIBE_MEMBER(m_ERaiseWater, &WaterSystem::OnRaiseWater);
EVENT_SUBSCRIBE_MEMBER(m_ERaiseWaterWall, &WaterSystem::OnRaiseWaterWall);
//Water test
{
auto t_waterBody = m_World->CreateEntity();
auto transform = m_World->AddComponent<Components::Transform>(t_waterBody);
transform->Position = glm::vec3(0.f, -3.5f, -10.f);
transform->Scale = glm::vec3(7.0f, 1.5f, 1.f);
auto water = m_World->AddComponent<Components::WaterVolume>(t_waterBody);
auto body = m_World->AddComponent<Components::RectangleShape>(t_waterBody);
m_World->CommitEntity(t_waterBody);
}
}
void dd::Systems::WaterSystem::Update(double dt)
{
if (m_Pause) {
return;
}
}
void dd::Systems::WaterSystem::UpdateEntity(double dt, EntityID entity, EntityID parent)
{
if (m_Pause) {
return;
}
auto templateCheck = m_World->GetComponent<Components::Template>(entity);
if (templateCheck != nullptr){ return; }
if (m_BottomWall == 0) {
for (auto it = m_World->GetEntities()->begin(); it != m_World->GetEntities()->end(); it++) {
if (m_World->GetProperty<std::string>(it->first, "Name") == "BottomWall") {
m_BottomWall = entity;
break;
}
}
}
}
bool dd::Systems::WaterSystem::OnPause(const dd::Events::Pause &event)
{
/*if (event.Type != "WaterSystem" && event.Type != "All") {
return false;
}*/
m_Pause = true;
return true;
}
bool dd::Systems::WaterSystem::OnResume(const dd::Events::Resume &event)
{
/*if (event.Type != "WaterSystem" && event.Type != "All") {
return false;
}*/
m_Pause = false;
return true;
}
bool dd::Systems::WaterSystem::OnRelevantObjectCreated(const dd::Events::RelevantObjectCreated &event)
{
if (event.ObjectName == "BottomWall") {
m_BottomWall = event.ObjectID;
}
return true;
}
bool dd::Systems::WaterSystem::OnStageCleared(const dd::Events::StageCleared &event)
{
return true;
}
bool dd::Systems::WaterSystem::OnArrivedAtNewStage(const dd::Events::ArrivedAtNewStage &event)
{
return true;
}
bool dd::Systems::WaterSystem::OnRaiseWater(const dd::Events::RaiseWater &event)
{
{
auto t_waterBody = m_World->CreateEntity();
auto transform = m_World->AddComponent<Components::Transform>(t_waterBody);
transform->Position = glm::vec3(0.f, -3.5f, -10.f);
transform->Scale = glm::vec3(7.0f, event.Amount * 1.6f, 1.f);
auto water = m_World->AddComponent<Components::WaterVolume>(t_waterBody);
auto body = m_World->AddComponent<Components::RectangleShape>(t_waterBody);
m_World->CommitEntity(t_waterBody);
}
return true;
}
bool dd::Systems::WaterSystem::OnRaiseWaterWall(const dd::Events::RaiseWaterWall &event)
{
auto transform = m_World->GetComponent<Components::Transform>(m_BottomWall);
if (transform != nullptr) {
glm::vec3 raise = glm::vec3(0, event.Amount, 0);
Events::Move e;
e.Entity = m_BottomWall;
e.GoalPosition = transform->Position + raise;
e.Queue = true;
e.Speed = 0.2;
EventBroker->Publish(e);
} else {
LOG_ERROR("There is no BottomWall in WaterSystem");
}
return true;
}
+3 -7
View File
@@ -17,7 +17,7 @@
*/
#include "PrecompiledHeader.h"
#include "Core/Camera.h"
#include "Rendering/Camera.h"
dd::Camera::Camera(float aspectRatio, float yFOV, float nearClip, float farClip)
{
@@ -85,12 +85,8 @@ void dd::Camera::UpdateProjectionMatrix()
// m_NearClip,
// m_FarClip
// );
m_ProjectionMatrix = glm::perspective(
m_FOV,
m_AspectRatio,
m_NearClip,
m_FarClip
);
m_ProjectionMatrix = glm::perspective(m_FOV, m_AspectRatio, m_NearClip, m_FarClip);
}
void dd::Camera::UpdateViewMatrix()
+20
View File
@@ -0,0 +1,20 @@
#include "PrecompiledHeader.h"
#include "Rendering/Model.h"
dd::Model::Model(std::string fileName)
: dd::RawModel(fileName)
{
D3D11_BUFFER_DESC vbd = { 0 };
vbd.ByteWidth = sizeof(RawModel::Vertex) * m_Vertices.size();
vbd.BindFlags = D3D11_BIND_VERTEX_BUFFER;
D3D11_SUBRESOURCE_DATA vsrd = { m_Vertices.data(), 0, 0 };
StaticSystem::Get<Renderer>()->m_Device->CreateBuffer(&vbd, &vsrd, &VertexBuffer);
D3D11_BUFFER_DESC ibd = { 0 };
ibd.ByteWidth = sizeof(unsigned int) * m_Indices.size();
ibd.BindFlags = D3D11_BIND_INDEX_BUFFER;
D3D11_SUBRESOURCE_DATA idata = { 0 };
idata.pSysMem = m_Indices.data();
StaticSystem::Get<Renderer>()->m_Device->CreateBuffer(&ibd, &idata, &IndexBuffer);
}
+429
View File
@@ -0,0 +1,429 @@
#include "PrecompiledHeader.h"
#include "Rendering/Renderer.h"
#include "Rendering/Model.h"
#include "Rendering/Skeleton.h"
#include "Rendering/ShaderProgram.h"
void dd::Renderer::Initialize()
{
StaticSystem::Set(this);
// Initialize GLFW
if (!glfwInit()) {
LOG_ERROR("GLFW: Initialization failed");
exit(EXIT_FAILURE);
}
// Create a window
GLFWmonitor* monitor = nullptr;
if (m_Fullscreen) {
monitor = glfwGetPrimaryMonitor();
}
glfwWindowHint(GLFW_SAMPLES, 8);
m_Window = glfwCreateWindow(m_Resolution.Width, m_Resolution.Height, "Squidout! (DirectX 11)", monitor, nullptr);
if (!m_Window) {
LOG_ERROR("GLFW: Failed to create window");
exit(EXIT_FAILURE);
}
//glfwMakeContextCurrent(m_Window);
// Create default camera
m_DefaultCamera = std::unique_ptr<dd::Camera>(new dd::Camera((float)m_Resolution.Width / m_Resolution.Height, 45.f, 0.01f, 5000.f));
m_DefaultCamera->SetPosition(glm::vec3(0, 0, 0));
if (m_Camera == nullptr) {
m_Camera = m_DefaultCamera.get();
}
DXGI_SWAP_CHAIN_DESC scd = { 0 };
scd.BufferCount = 1;
scd.BufferDesc.Format = DXGI_FORMAT_R8G8B8A8_UNORM;
scd.BufferUsage = DXGI_USAGE_RENDER_TARGET_OUTPUT;
scd.OutputWindow = glfwGetWin32Window(m_Window);
scd.SampleDesc.Count = 4;
scd.Windowed = TRUE;
scd.Flags = DXGI_SWAP_CHAIN_FLAG_ALLOW_MODE_SWITCH;
D3D11CreateDeviceAndSwapChain(
NULL,
D3D_DRIVER_TYPE_HARDWARE,
NULL,
NULL,
NULL,
NULL,
D3D11_SDK_VERSION,
&scd,
&m_SwapChain,
&m_Device,
NULL,
&m_DeviceContext);
// Set the back buffer render target
ID3D11Texture2D* pBackBuffer;
m_SwapChain->GetBuffer(0, __uuidof(ID3D11Texture2D), (void**)&pBackBuffer);
m_Device->CreateRenderTargetView(pBackBuffer, NULL, &m_BackBuffer);
pBackBuffer->Release();
// Depth buffer
D3D11_TEXTURE2D_DESC texd = { };
texd.Width = m_Resolution.Width;
texd.Height = m_Resolution.Height;
texd.ArraySize = 1;
texd.MipLevels = 1;
texd.SampleDesc.Count = 4;
texd.Format = DXGI_FORMAT_D32_FLOAT;
texd.BindFlags = D3D11_BIND_DEPTH_STENCIL;
ID3D11Texture2D* pDepthBuffer;
m_Device->CreateTexture2D(&texd, NULL, &pDepthBuffer);
D3D11_DEPTH_STENCIL_VIEW_DESC dsvd = { };
dsvd.Format = DXGI_FORMAT_D32_FLOAT;
dsvd.ViewDimension = D3D11_DSV_DIMENSION_TEXTURE2DMS;
m_Device->CreateDepthStencilView(pDepthBuffer, &dsvd, &m_DepthBuffer);
pDepthBuffer->Release();
// Set back and depth buffer
m_DeviceContext->OMSetRenderTargets(1, &m_BackBuffer, m_DepthBuffer);
// Rasterizer settings
setDefaultRasterState();
D3D11_BLEND_DESC blend = { 0 };
for (int i = 0; i < 1; i++) {
blend.RenderTarget[i].BlendEnable = true;
blend.RenderTarget[i].BlendOp = D3D11_BLEND_OP_ADD;
blend.RenderTarget[i].SrcBlend = D3D11_BLEND_SRC_ALPHA;
blend.RenderTarget[i].DestBlend = D3D11_BLEND_INV_SRC_ALPHA;
blend.RenderTarget[i].BlendOpAlpha = D3D11_BLEND_OP_ADD;
blend.RenderTarget[i].SrcBlendAlpha = D3D11_BLEND_ONE;
blend.RenderTarget[i].DestBlendAlpha = D3D11_BLEND_ZERO;
blend.RenderTarget[i].RenderTargetWriteMask = D3D11_COLOR_WRITE_ENABLE_ALL;
}
ID3D11BlendState* blendState;
m_Device->CreateBlendState(&blend, &blendState);
m_DeviceContext->OMSetBlendState(blendState, nullptr, 0xffffffff);
D3D11_INPUT_ELEMENT_DESC VertexIED[] = {
{"POSITION", 0, DXGI_FORMAT_R32G32B32_FLOAT, 0, 0, D3D11_INPUT_PER_VERTEX_DATA, 0},
{"NORMAL", 0, DXGI_FORMAT_R32G32B32_FLOAT, 0, D3D11_APPEND_ALIGNED_ELEMENT, D3D11_INPUT_PER_VERTEX_DATA, 0},
{"TANGENT", 0, DXGI_FORMAT_R32G32B32_FLOAT, 0, D3D11_APPEND_ALIGNED_ELEMENT, D3D11_INPUT_PER_VERTEX_DATA, 0},
{"TANGENT", 1, DXGI_FORMAT_R32G32B32_FLOAT, 0, D3D11_APPEND_ALIGNED_ELEMENT, D3D11_INPUT_PER_VERTEX_DATA, 0},
{"TEXCOORD", 0, DXGI_FORMAT_R32G32_FLOAT, 0, D3D11_APPEND_ALIGNED_ELEMENT, D3D11_INPUT_PER_VERTEX_DATA, 0},
{"COLOR", 0, DXGI_FORMAT_R32G32B32A32_FLOAT, 0, D3D11_APPEND_ALIGNED_ELEMENT, D3D11_INPUT_PER_VERTEX_DATA, 0},
{"COLOR", 1, DXGI_FORMAT_R32G32B32A32_FLOAT, 0, D3D11_APPEND_ALIGNED_ELEMENT, D3D11_INPUT_PER_VERTEX_DATA, 0},
{"BLENDINDICES", 0, DXGI_FORMAT_R32G32B32A32_FLOAT, 0, D3D11_APPEND_ALIGNED_ELEMENT, D3D11_INPUT_PER_VERTEX_DATA, 0},
{"BLENDINDICES", 1, DXGI_FORMAT_R32G32B32A32_FLOAT, 0, D3D11_APPEND_ALIGNED_ELEMENT, D3D11_INPUT_PER_VERTEX_DATA, 0},
{"BLENDWEIGHT", 0, DXGI_FORMAT_R32G32B32A32_FLOAT, 0, D3D11_APPEND_ALIGNED_ELEMENT, D3D11_INPUT_PER_VERTEX_DATA, 0},
{"BLENDWEIGHT", 1, DXGI_FORMAT_R32G32B32A32_FLOAT, 0, D3D11_APPEND_ALIGNED_ELEMENT, D3D11_INPUT_PER_VERTEX_DATA, 0},
};
m_ForwardShaderProgram = new ShaderProgram();
m_ForwardShaderProgram->CompileVertexShader(L"Shaders/DirectX/vertex.hlsl");
m_ForwardShaderProgram->CompilePixelShader(L"Shaders/DirectX/pixel.hlsl");
m_ForwardShaderProgram->CreateInputLayout(VertexIED, sizeof(VertexIED) / sizeof(VertexIED[0]));
m_GUIShaderProgram = new ShaderProgram();
m_GUIShaderProgram->CompileVertexShader(L"Shaders/DirectX/vertex.hlsl");
m_GUIShaderProgram->CompilePixelShader(L"Shaders/DirectX/Flat.pixel.hlsl");
m_GUIShaderProgram->CreateInputLayout(VertexIED, sizeof(VertexIED) / sizeof(VertexIED[0]));
// Create constant buffer
// TODO: Put this in shader
D3D11_BUFFER_DESC bd = { };
bd.ByteWidth = sizeof(ConstantBufferStruct);
bd.BindFlags = D3D11_BIND_CONSTANT_BUFFER;
m_Device->CreateBuffer(&bd, NULL, &constantBuffer);
m_DeviceContext->VSSetConstantBuffers(0, 1, &constantBuffer);
m_DeviceContext->PSSetConstantBuffers(0, 1, &constantBuffer);
D3D11_SAMPLER_DESC samplerDesc;
samplerDesc.Filter = D3D11_FILTER_MIN_MAG_MIP_LINEAR;
samplerDesc.AddressU = D3D11_TEXTURE_ADDRESS_WRAP;
samplerDesc.AddressV = D3D11_TEXTURE_ADDRESS_WRAP;
samplerDesc.AddressW = D3D11_TEXTURE_ADDRESS_WRAP;
samplerDesc.MipLODBias = 0.0f;
samplerDesc.MaxAnisotropy = 1;
samplerDesc.ComparisonFunc = D3D11_COMPARISON_ALWAYS;
samplerDesc.BorderColor[0] = 1.f;
samplerDesc.BorderColor[1] = 0;
samplerDesc.BorderColor[2] = 1.f;
samplerDesc.BorderColor[3] = 0;
samplerDesc.MinLOD = 0;
samplerDesc.MaxLOD = D3D11_FLOAT32_MAX;
m_Device->CreateSamplerState(&samplerDesc, &m_SamplerState);
m_UnitQuad = ResourceManager::Load<Model>("Models/Core/UnitQuad.obj");
m_WhiteSphereTexture = ResourceManager::Load<Texture>("Textures/Test/Water.png");
}
void dd::Renderer::Draw(RenderQueueCollection& rq)
{
using namespace DirectX::SimpleMath;
rq.Forward.Jobs.sort(dd::Renderer::DepthSort);
m_DeviceContext->OMSetRenderTargets(1, &m_BackBuffer, m_DepthBuffer);
float color[] = { 0.f, 0.f, 0.f, 1.f };
m_DeviceContext->ClearRenderTargetView(m_BackBuffer, color);
m_DeviceContext->ClearDepthStencilView(m_DepthBuffer, D3D11_CLEAR_DEPTH, 1.0f, 0);
// Set the viewport
D3D11_VIEWPORT viewport = { 0 };
viewport.TopLeftX = 0;
viewport.TopLeftY = 0;
viewport.Width = m_Resolution.Width;
viewport.Height = m_Resolution.Height;
viewport.MinDepth = 0;
viewport.MaxDepth = 1;
m_DeviceContext->RSSetViewports(1, &viewport);
m_ForwardShaderProgram->Bind();
Matrix proj = DirectX::SimpleMath::Matrix::CreatePerspectiveFieldOfView(m_Camera->m_FOV, m_Camera->m_AspectRatio, m_Camera->m_NearClip, m_Camera->m_FarClip); // Right-handed
Matrix view = Matrix::CreateTranslation(Vector3(m_Camera->Position().x, m_Camera->Position().y, -m_Camera->Position().z));
int i = 0;
constantBufferStruct.NumLights = 0;
for (auto &job : rq.Lights) {
auto pointLightJob = std::dynamic_pointer_cast<PointLightJob>(job);
if (pointLightJob) {
glm::vec3 p = pointLightJob->Position;
constantBufferStruct.LightPositions[i] = Vector4(p.r, p.g, p.b, 0.f);
glm::vec3 c = pointLightJob->DiffuseColor;
constantBufferStruct.LightColors[i] = Vector4(c.r, c.g, c.b, 1.f);
constantBufferStruct.LightRadii[i] = pointLightJob->Radius;
constantBufferStruct.NumLights++;
i++;
}
}
for (auto &job : rq.Deferred) {
auto modelJob = std::dynamic_pointer_cast<ModelJob>(job);
if (modelJob) {
constantBufferStruct.MVP = Matrix(glm::value_ptr(modelJob->ModelMatrix)) * view * proj;
constantBufferStruct.InverseTransposeViewModel = (Matrix(glm::value_ptr(modelJob->ModelMatrix)) * view).Transpose().Invert();
constantBufferStruct.Color = Vector4(modelJob->Color.r, modelJob->Color.g, modelJob->Color.b, modelJob->Color.a);
m_DeviceContext->UpdateSubresource(constantBuffer, 0, 0, &constantBufferStruct, 0, 0);
m_DeviceContext->PSSetSamplers(0, 1, &m_SamplerState);
m_DeviceContext->IASetPrimitiveTopology(D3D11_PRIMITIVE_TOPOLOGY_TRIANGLELIST);
UINT stride = sizeof(Model::Vertex);
UINT offset = 0;
m_DeviceContext->IASetVertexBuffers(0, 1, &modelJob->Model->VertexBuffer, &stride, &offset);
m_DeviceContext->IASetIndexBuffer(modelJob->Model->IndexBuffer, DXGI_FORMAT_R32_UINT, 0);
if (modelJob->DiffuseTexture != nullptr) {
m_DeviceContext->PSSetShaderResources(0, 1, &modelJob->DiffuseTexture->m_ShaderResourceView);
}
//m_DeviceContext->Draw(modelJob->EndIndex - modelJob->StartIndex + 1, modelJob->StartIndex);
m_DeviceContext->DrawIndexed(modelJob->EndIndex - modelJob->StartIndex + 1, modelJob->StartIndex, 0);
continue;
}
}
for (auto &job : rq.Forward) {
auto spriteJob = std::dynamic_pointer_cast<SpriteJob>(job);
if (spriteJob) {
constantBufferStruct.MVP = Matrix(glm::value_ptr(spriteJob->ModelMatrix)) * view * proj;
constantBufferStruct.InverseTransposeViewModel = (Matrix(glm::value_ptr(spriteJob->ModelMatrix)) * view).Transpose().Invert();
constantBufferStruct.Color = Vector4(glm::value_ptr(spriteJob->Color));
m_DeviceContext->UpdateSubresource(constantBuffer, 0, 0, &constantBufferStruct, 0, 0);
m_DeviceContext->PSSetSamplers(0, 1, &m_SamplerState);
m_DeviceContext->IASetPrimitiveTopology(D3D11_PRIMITIVE_TOPOLOGY_TRIANGLELIST);
UINT stride = sizeof(Model::Vertex);
UINT offset = 0;
m_DeviceContext->IASetVertexBuffers(0, 1, &m_UnitQuad->VertexBuffer, &stride, &offset);
m_DeviceContext->IASetIndexBuffer(m_UnitQuad->IndexBuffer, DXGI_FORMAT_R32_UINT, 0);
if (spriteJob->DiffuseTexture != nullptr) {
m_DeviceContext->PSSetShaderResources(0, 1, &spriteJob->DiffuseTexture->m_ShaderResourceView);
}
//m_DeviceContext->Draw(modelJob->EndIndex - modelJob->StartIndex + 1, modelJob->StartIndex);
m_DeviceContext->DrawIndexed(m_UnitQuad->m_Indices.size(), 0, 0);
continue;
}
auto waterJob = std::dynamic_pointer_cast<WaterParticleJob>(job);
if (waterJob) {
constantBufferStruct.MVP = Matrix(glm::value_ptr(waterJob->ModelMatrix)) * view * proj;
constantBufferStruct.InverseTransposeViewModel = (Matrix(glm::value_ptr(waterJob->ModelMatrix)) * view).Transpose().Invert();
constantBufferStruct.Color = Vector4(glm::value_ptr(waterJob->Color));
m_DeviceContext->UpdateSubresource(constantBuffer, 0, 0, &constantBufferStruct, 0, 0);
m_DeviceContext->PSSetSamplers(0, 1, &m_SamplerState);
m_DeviceContext->IASetPrimitiveTopology(D3D11_PRIMITIVE_TOPOLOGY_TRIANGLELIST);
UINT stride = sizeof(Model::Vertex);
UINT offset = 0;
m_DeviceContext->IASetVertexBuffers(0, 1, &m_UnitQuad->VertexBuffer, &stride, &offset);
m_DeviceContext->IASetIndexBuffer(m_UnitQuad->IndexBuffer, DXGI_FORMAT_R32_UINT, 0);
m_DeviceContext->PSSetShaderResources(0, 1, &m_WhiteSphereTexture->m_ShaderResourceView);
//m_DeviceContext->Draw(modelJob->EndIndex - modelJob->StartIndex + 1, modelJob->StartIndex);
m_DeviceContext->DrawIndexed(m_UnitQuad->m_Indices.size(), 0, 0);
continue;
}
}
m_DeviceContext->OMSetRenderTargets(1, &m_BackBuffer, nullptr);
m_GUIShaderProgram->Bind();
for (auto &job : rq.GUI) {
auto frameJob = std::dynamic_pointer_cast<FrameJob>(job);
if (frameJob) {
Rectangle& vp = frameJob->Viewport;
glViewport(vp.X, m_Resolution.Height - vp.Y - vp.Height, vp.Width, vp.Height);
Rectangle& sc = frameJob->Scissor;
if (sc == Rectangle()) {
glDisable(GL_SCISSOR_TEST);
} else {
glEnable(GL_SCISSOR_TEST);
glScissor(sc.X, m_Resolution.Height - sc.Y - sc.Height, sc.Width, sc.Height);
}
D3D11_VIEWPORT viewport = { 0 };
viewport.TopLeftX = vp.X;
viewport.TopLeftY = vp.Y;
viewport.Width = vp.Width;
viewport.Height = vp.Height;
viewport.MinDepth = 0;
viewport.MaxDepth = 1;
m_DeviceContext->RSSetViewports(1, &viewport);
proj = Matrix::Identity;
view = Matrix::Identity;
Matrix model = Matrix::CreateScale(2.f);
constantBufferStruct.MVP = model * view * proj;
constantBufferStruct.InverseTransposeViewModel = (model * view).Transpose().Invert();
constantBufferStruct.Color = Vector4(glm::value_ptr(frameJob->Color));
m_DeviceContext->UpdateSubresource(constantBuffer, 0, 0, &constantBufferStruct, 0, 0);
m_DeviceContext->PSSetSamplers(0, 1, &m_SamplerState);
m_DeviceContext->IASetPrimitiveTopology(D3D11_PRIMITIVE_TOPOLOGY_TRIANGLELIST);
UINT stride = sizeof(Model::Vertex);
UINT offset = 0;
m_DeviceContext->IASetVertexBuffers(0, 1, &m_UnitQuad->VertexBuffer, &stride, &offset);
m_DeviceContext->IASetIndexBuffer(m_UnitQuad->IndexBuffer, DXGI_FORMAT_R32_UINT, 0);
if (frameJob->DiffuseTexture != nullptr) {
m_DeviceContext->PSSetShaderResources(0, 1, &frameJob->DiffuseTexture->m_ShaderResourceView);
}
//m_DeviceContext->Draw(modelJob->EndIndex - modelJob->StartIndex + 1, modelJob->StartIndex);
m_DeviceContext->DrawIndexed(m_UnitQuad->m_Indices.size(), 0, 0);
continue;
}
}
//constantBufferStruct.ModelMatrix = GLMtoDX(glm::mat4(1.f));
//constantBufferStruct.ViewMatrix = GLMtoDX(m_Camera->ViewMatrix());
//constantBufferStruct.ProjectionMatrix = proj;
//constantBufferStruct.InverseTransposeViewModel = GLMtoDX(glm::mat4(1.f));
m_SwapChain->Present(0, 0);
//glfwSwapBuffers(m_Window);
}
//void dd::Renderer::Resize(int width, int height)
//{
// m_DeviceContext->OMSetRenderTargets(0, 0, 0);
// m_BackBuffer->Release();
//
// HRESULT hr; // TODO: Error handling
// // Preserve the existing buffer count and format.
// hr = m_SwapChain->ResizeBuffers(0, width, height, DXGI_FORMAT_UNKNOWN, 0);
//
// ID3D11Texture2D* pBuffer;
// hr = m_SwapChain->GetBuffer(0, __uuidof(ID3D11Texture2D), (void**)&pBuffer);
// hr = m_Device->CreateRenderTargetView(pBuffer, NULL, &m_BackBuffer);
// pBuffer->Release();
// m_DeviceContext->OMSetRenderTargets(1, &BackBuffer, NULL);
//
// // Set the viewport
// D3D11_VIEWPORT viewport = { 0 };
// viewport.TopLeftX = 0;
// viewport.TopLeftY = 0;
// viewport.Width = width;
// viewport.Height = height;
// m_DeviceContext->RSSetViewports(1, &viewport);
//}
dd::Renderer::~Renderer()
{
m_SwapChain->Release();
m_BackBuffer->Release();
m_Device->Release();
m_DeviceContext->Release();
}
DirectX::SimpleMath::Matrix dd::Renderer::GLMtoDXModelView(glm::mat4 gm)
{
gm = glm::transpose(gm);
DirectX::SimpleMath::Matrix dm(
gm[0][0], gm[0][1], -gm[0][2], gm[0][3],
gm[1][0], gm[1][1], -gm[1][2], gm[1][3],
-gm[2][0], -gm[2][1], gm[2][2], gm[2][3],
gm[3][0], gm[3][1], -gm[3][2], gm[3][3]
);
return dm;
}
DirectX::SimpleMath::Matrix dd::Renderer::GLMtoDXProjection(glm::mat4 gm)
{
gm = glm::transpose(gm);
DirectX::SimpleMath::Matrix dm(
gm[0][0], gm[0][1], gm[0][2], gm[0][3],
gm[1][0], gm[1][1], gm[1][2], gm[1][3],
-gm[2][0], -gm[2][1], -gm[2][2], -gm[2][3],
gm[3][0], gm[3][1], gm[3][2], gm[3][3]
);
return dm;
}
void dd::Renderer::setDefaultRasterState()
{
if (m_RasterState != nullptr) {
m_RasterState->Release();
m_RasterState = nullptr;
}
D3D11_RASTERIZER_DESC rd;
memset(&rd, 0, sizeof(D3D11_RASTERIZER_DESC));
rd.AntialiasedLineEnable = false;
rd.CullMode = D3D11_CULL_BACK;
rd.DepthBias = 0;
rd.DepthBiasClamp = 0.0f;
rd.DepthClipEnable = true;
rd.FillMode = D3D11_FILL_SOLID;
rd.FrontCounterClockwise = true;
rd.MultisampleEnable = false;
rd.ScissorEnable = false;
rd.SlopeScaledDepthBias = 0.0f;
m_Device->CreateRasterizerState(&rd, &m_RasterState);
m_DeviceContext->RSSetState(m_RasterState);
}
void dd::Renderer::setGUIRasterState()
{
if (m_RasterState != nullptr) {
m_RasterState->Release();
m_RasterState = nullptr;
}
D3D11_RASTERIZER_DESC rd;
memset(&rd, 0, sizeof(D3D11_RASTERIZER_DESC));
rd.AntialiasedLineEnable = false;
rd.CullMode = D3D11_CULL_BACK;
rd.DepthBias = 0;
rd.DepthBiasClamp = 0.0f;
rd.DepthClipEnable = false;
rd.FillMode = D3D11_FILL_SOLID;
rd.FrontCounterClockwise = true;
rd.MultisampleEnable = false;
rd.ScissorEnable = false;
rd.SlopeScaledDepthBias = 0.0f;
m_Device->CreateRasterizerState(&rd, &m_RasterState);
m_DeviceContext->RSSetState(m_RasterState);
}
@@ -0,0 +1,78 @@
#include "PrecompiledHeader.h"
#include "Rendering/ShaderProgram.h"
dd::ShaderProgram::ShaderProgram()
{
m_VertexShaderBlob = nullptr;
m_VertexShader = nullptr;
m_PixelShaderBlob = nullptr;
m_PixelShader = nullptr;
m_InputLayout = nullptr;
}
dd::ShaderProgram::~ShaderProgram()
{
if (m_VertexShader != nullptr)
m_VertexShader->Release();
if (m_VertexShaderBlob != nullptr)
m_VertexShaderBlob->Release();
if (m_PixelShader != nullptr)
m_PixelShader->Release();
if (m_PixelShaderBlob != nullptr)
m_PixelShaderBlob->Release();
if (m_InputLayout != nullptr)
m_InputLayout->Release();
}
void dd::ShaderProgram::CompileVertexShader(std::wstring filename)
{
//D3DX11CompileFromFile(filename.c_str(), 0, 0, "main", "vs_5_0", 0, 0, 0, &m_VertexShaderBlob, 0, 0);
ID3DBlob* blob = nullptr;
HRESULT result = D3DCompileFromFile(filename.c_str(), nullptr, nullptr, "main", "vs_5_0", 0, 0, &m_VertexShaderBlob, &blob);
if (result != S_OK) {
std::wstring blobString((wchar_t*)blob->GetBufferPointer(), blob->GetBufferSize());
LOG_ERROR("Failed to compile vertex shader!\n\n%s", blobString.c_str());
return;
}
StaticSystem::Get<Renderer>()->m_Device->CreateVertexShader(m_VertexShaderBlob->GetBufferPointer(), m_VertexShaderBlob->GetBufferSize(), NULL, &m_VertexShader);
}
void dd::ShaderProgram::CompilePixelShader(std::wstring filename)
{
//D3DX11CompileFromFile(filename.c_str(), 0, 0, "main", "ps_5_0", 0, 0, 0, &m_PixelShaderBlob, 0, 0);
ID3DBlob* blob = nullptr;
HRESULT result = D3DCompileFromFile(filename.c_str(), nullptr, nullptr, "main", "ps_5_0", 0, 0, &m_PixelShaderBlob, &blob);
if (result != S_OK) {
std::wstring blobString((wchar_t*)blob->GetBufferPointer(), blob->GetBufferSize());
LOG_ERROR("Failed to compile pixel shader!\n\n%s", blobString.c_str());
return;
}
StaticSystem::Get<Renderer>()->m_Device->CreatePixelShader(m_PixelShaderBlob->GetBufferPointer(), m_PixelShaderBlob->GetBufferSize(), NULL, &m_PixelShader);
}
void dd::ShaderProgram::Bind()
{
if (m_VertexShader != nullptr)
StaticSystem::Get<Renderer>()->m_DeviceContext->VSSetShader(m_VertexShader, 0, 0);
if (m_PixelShader != nullptr)
StaticSystem::Get<Renderer>()->m_DeviceContext->PSSetShader(m_PixelShader, 0, 0);
if (m_InputLayout != nullptr)
StaticSystem::Get<Renderer>()->m_DeviceContext->IASetInputLayout(m_InputLayout);
}
void dd::ShaderProgram::Unbind()
{
if (m_VertexShader != nullptr) {
StaticSystem::Get<Renderer>()->m_DeviceContext->VSSetShader(NULL, 0, 0);
}
if (m_PixelShader != nullptr) {
StaticSystem::Get<Renderer>()->m_DeviceContext->PSSetShader(NULL, 0, 0);
}
//if (m_InputLayout != nullptr)
// dd::RENDERER->DeviceContext->IASetInputLayout(NULL);
}
HRESULT dd::ShaderProgram::CreateInputLayout(D3D11_INPUT_ELEMENT_DESC* ied, UINT numElements)
{
return StaticSystem::Get<Renderer>()->m_Device->CreateInputLayout(ied, numElements, m_VertexShaderBlob->GetBufferPointer(), m_VertexShaderBlob->GetBufferSize(), &m_InputLayout);
}
@@ -0,0 +1,38 @@
cbuffer ConstantBuffer
{
float4x4 MVP;
float4x4 ModelMatrix;
float4x4 ViewMatrix;
float4x4 ProjectionMatrix;
float4x4 InverseTransposeViewModel;
float4 Color;
float4 LightPositions[10];
float4 LightColors[10];
float LightRadii[10];
uint NumLights;
}
Texture2D Texture;
SamplerState samplerState;
struct VOut
{
float4 PixelPosition : SV_POSITION;
float4 Position : POSITION;
float4 Normal : NORMAL;
float4 Tangent : TANGENT0;
float4 BiTangent : TANGENT1;
float2 TextureCoord : TEXCOORD;
float4 DiffuseColor : COLOR0;
float4 SpecularColor : COLOR1;
float4 BoneIndices1 : BLENDINDICES0;
float4 BoneIndices2 : BLENDINDICES1;
float4 BoneWeights1 : BLENDWEIGHT0;
float4 BoneWeights2 : BLENDWEIGHT1;
};
float4 main(VOut input) : SV_TARGET
{
float4 diffuseTexture = Texture.Sample(samplerState, input.TextureCoord) * Color;
return diffuseTexture;
}
@@ -0,0 +1,76 @@
cbuffer ConstantBuffer
{
float4x4 MVP;
float4x4 ModelMatrix;
float4x4 ViewMatrix;
float4x4 ProjectionMatrix;
float4x4 InverseTransposeViewModel;
float4 Color;
float4 LightPositions[10];
float4 LightColors[10];
float LightRadii[10];
uint NumLights;
}
Texture2D Texture;
SamplerState samplerState;
struct VOut
{
float4 PixelPosition : SV_POSITION;
float4 Position : POSITION;
float4 Normal : NORMAL;
float4 Tangent : TANGENT0;
float4 BiTangent : TANGENT1;
float2 TextureCoord : TEXCOORD;
float4 DiffuseColor : COLOR0;
float4 SpecularColor : COLOR1;
float4 BoneIndices1 : BLENDINDICES0;
float4 BoneIndices2 : BLENDINDICES1;
float4 BoneWeights1 : BLENDWEIGHT0;
float4 BoneWeights2 : BLENDWEIGHT1;
};
float4 phong(float3 lightPos, float lightRadius, float3 lightColor, float3 position, float3 normal, float3 specular, float specularExponent)
{
float3 LightSpecular = float3(1.0f, 1.0f, 1.0f) * 0.5f;
// Diffuse
lightPos = mul(ViewMatrix, float4(lightPos, 1.0f)).xyz;
float3 distanceToLight = lightPos - position;
float3 directionToLight = normalize(distanceToLight);
float dotProd = dot(directionToLight, normal);
float3 Idiffuse = lightColor * dotProd;
// Specular
float3 surfaceToViewer = normalize(-position);
float3 halfWay = normalize(surfaceToViewer + directionToLight);
float dotSpecular = max(dot(halfWay, normal), 0.0f);
float specularFactor = pow(dotSpecular, specularExponent);
float3 Ispecular = specular * LightSpecular * specularFactor;
// Attenuation
float dist = distance(lightPos, position);
float attenuation = pow(max(0.0f, 1.0f - (dist / lightRadius)), 2.0f);
return float4((Idiffuse + Ispecular) * attenuation, 1.0f);
}
float4 main(VOut input) : SV_TARGET
{
//float4 ambientLight = float4(1.0f, 1.0f, 1.0f, 1.0f) * 0.1f;
//float4 lightColor = float4(1.0f, 1.0f, 1.0f, 1.0f);
//float3 lightToPixel = normalize(LightPosition - mul(input.Position, transpose(ModelMatrix)));
//float diffuseBrightness = saturate(dot(lightToPixel, normalize(mul(input.Normal, transpose(ModelMatrix)))));
float4 diffuseTexture = Texture.Sample(samplerState, input.TextureCoord) * Color;
float4 lights = float4(1.f, 1.f, 1.f, 1.f);
for (uint i = 0; i < NumLights; i++) {
float4 light = phong(LightPositions[i], LightRadii[i], LightColors[i].rgb, input.Position, normalize(input.Normal.xyz), float3(1.0f, 1.0f, 1.0f), 1.0f);
lights = lights + light;
}
//return float4(1.f, 0.f, 0.f, 1.f);
return float4(diffuseTexture.rgb * 0.8f, diffuseTexture.a) * lights;
}
@@ -0,0 +1,67 @@
cbuffer ConstantBuffer
{
float4x4 MVP;
float4x4 ModelMatrix;
float4x4 ViewMatrix;
float4x4 ProjectionMatrix;
float4x4 InverseTransposeViewModel;
float4 Color;
float4 LightPositions[2];
}
struct VIn
{
float4 Position : POSITION;
float4 Normal : NORMAL;
float4 Tangent : TANGENT0;
float4 BiTangent : TANGENT1;
float2 TextureCoord : TEXCOORD;
float4 DiffuseColor : COLOR0;
float4 SpecularColor : COLOR1;
float4 BoneIndices1 : BLENDINDICES0;
float4 BoneIndices2 : BLENDINDICES1;
float4 BoneWeights1 : BLENDWEIGHT0;
float4 BoneWeights2 : BLENDWEIGHT1;
};
struct VOut
{
float4 PixelPosition : SV_POSITION;
float4 Position : POSITION;
float4 Normal : NORMAL;
float4 Tangent : TANGENT0;
float4 BiTangent : TANGENT1;
float2 TextureCoord : TEXCOORD;
float4 DiffuseColor : COLOR0;
float4 SpecularColor : COLOR1;
float4 BoneIndices1 : BLENDINDICES0;
float4 BoneIndices2 : BLENDINDICES1;
float4 BoneWeights1 : BLENDWEIGHT0;
float4 BoneWeights2 : BLENDWEIGHT1;
};
VOut main(VIn input)
{
/*float4 ambientLight = float4(1.0f, 1.0f, 1.0f, 1.0f) * 0.1f;
float4 lightPos = float4(0.0f, 0.0f, 8.0f, 0.0f);
float4 lightColor = float4(1.0f, 1.0f, 1.0f, 1.0f);
float diffuseBrightness = saturate(dot(normal, lightPos));*/
VOut output;
output.PixelPosition = mul(MVP, input.Position);
//TODO: Make sure that boneTransform works here.
output.Position = mul(ModelMatrix * ViewMatrix, float4(input.Position.xyz, 1.0f));
output.Normal = mul(InverseTransposeViewModel, float4(input.Normal.xyz, 0.0f));
output.Tangent = input.Tangent;
output.BiTangent = input.BiTangent;
output.TextureCoord = input.TextureCoord;
output.DiffuseColor = input.DiffuseColor;
output.SpecularColor = input.SpecularColor;
output.BoneIndices1 = input.BoneIndices1;
output.BoneIndices2 = input.BoneIndices2;
output.BoneWeights1 = input.BoneWeights1;
output.BoneWeights2 = input.BoneWeights2;
return output;
}
+68
View File
@@ -0,0 +1,68 @@
/*
This file is part of Daydream Engine.
Copyright 2014 Adam Byléhn, Tobias Dahl, Simon Holmberg, Viktor Ljung
Daydream Engine is free software: you can redistribute it and/or modify
it under the terms of the GNU Lesser General Public License as published by
the Free Software Foundation, either version 3 of the License, or
(at your option) any later version.
Daydream Engine is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU Lesser General Public License for more details.
You should have received a copy of the GNU Lesser General Public License
along with Daydream Engine. If not, see <http://www.gnu.org/licenses/>.
*/
#include "PrecompiledHeader.h"
#include "Rendering/Texture.h"
dd::Texture::Texture(std::string path)
{
std::unique_ptr<Image> image = std::make_unique<PNG>(path);
if (image->Width == 0 && image->Height == 0 || image->Format == Image::ImageFormat::Unknown) {
image = std::make_unique<PNG>("Textures/Core/ErrorTexture.png");
if (image->Width == 0 && image->Height == 0 || image->Format == Image::ImageFormat::Unknown) {
LOG_ERROR("Couldn't even load the error texture. This is a dark day indeed.");
return;
}
}
this->Width = image->Width;
this->Height = image->Height;
D3D11_TEXTURE2D_DESC desc;
desc.Width = this->Width;
desc.Height = this->Height;
desc.MipLevels = 1;
desc.ArraySize = 1;
desc.Format = DXGI_FORMAT_R8G8B8A8_UNORM;
desc.SampleDesc.Count = 1;
desc.SampleDesc.Quality = 0;
desc.Usage = D3D11_USAGE_DEFAULT;
desc.BindFlags = D3D11_BIND_SHADER_RESOURCE;
desc.CPUAccessFlags = 0;
desc.MiscFlags = 0;
D3D11_SUBRESOURCE_DATA data;
data.pSysMem = image->Data;
data.SysMemPitch = image->Width * 4;
data.SysMemSlicePitch = image->Width * image->Height * 4;
HRESULT result;
result = StaticSystem::Get<Renderer>()->m_Device->CreateTexture2D(&desc, &data, &m_Texture);
if (result != S_OK) {
LOG_ERROR("DirectX failed to create texture \"%s\"", path.c_str());
}
result = StaticSystem::Get<Renderer>()->m_Device->CreateShaderResourceView(m_Texture, nullptr, &m_ShaderResourceView);
if (result != S_OK) {
LOG_ERROR("DirectX failed to create shader resource view for texture \"%s\"", path.c_str());
}
}
dd::Texture::~Texture()
{
}
@@ -17,7 +17,7 @@
*/
#include "PrecompiledHeader.h"
#include "Core/OBJ.h"
#include "Rendering/OBJ.h"
bool dd::OBJ::LoadFromFile(std::string filename)
{
+81
View File
@@ -0,0 +1,81 @@
/*
This file is part of Daydream Engine.
Copyright 2014 Adam Byléhn, Tobias Dahl, Simon Holmberg, Viktor Ljung
Daydream Engine is free software: you can redistribute it and/or modify
it under the terms of the GNU Lesser General Public License as published by
the Free Software Foundation, either version 3 of the License, or
(at your option) any later version.
Daydream Engine is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU Lesser General Public License for more details.
You should have received a copy of the GNU Lesser General Public License
along with Daydream Engine. If not, see <http://www.gnu.org/licenses/>.
*/
#include "PrecompiledHeader.h"
#include "Rendering/Model.h"
dd::Model::Model(std::string fileName)
: RawModel(fileName)
{
// Generate GL buffers
GLuint buffer;
glGenBuffers(1, &buffer);
glBindBuffer(GL_ARRAY_BUFFER, buffer);
glBufferData(GL_ARRAY_BUFFER, m_Vertices.size() * sizeof(Vertex), &m_Vertices[0], GL_STATIC_DRAW);
glGenBuffers(1, &ElementBuffer);
glBindBuffer(GL_ELEMENT_ARRAY_BUFFER, ElementBuffer);
glBufferData(GL_ELEMENT_ARRAY_BUFFER, m_Indices.size() * sizeof(unsigned int), &m_Indices[0], GL_STATIC_DRAW);
glGenVertexArrays(1, &VAO);
glBindVertexArray(VAO);
GLERROR("GLEW: BufferFail4");
glBindBuffer(GL_ARRAY_BUFFER, buffer);
std::vector<int> structSizes = { 3, 3, 3, 3, 2, 4, 4, 4, 4, 4, 4 };
int stride = 0;
for (int size : structSizes)
stride += size;
stride *= sizeof(GLfloat);
int offset = 0;
{
int element = 0;
glVertexAttribPointer(element, structSizes[element], GL_FLOAT, GL_FALSE, stride, (GLvoid*)(sizeof(GLfloat) * offset)); element++;
glVertexAttribPointer(element, structSizes[element], GL_FLOAT, GL_FALSE, stride, (GLvoid*)(sizeof(GLfloat) * (offset += structSizes[element - 1]))); element++;
glVertexAttribPointer(element, structSizes[element], GL_FLOAT, GL_FALSE, stride, (GLvoid*)(sizeof(GLfloat) * (offset += structSizes[element - 1]))); element++;
glVertexAttribPointer(element, structSizes[element], GL_FLOAT, GL_FALSE, stride, (GLvoid*)(sizeof(GLfloat) * (offset += structSizes[element - 1]))); element++;
glVertexAttribPointer(element, structSizes[element], GL_FLOAT, GL_FALSE, stride, (GLvoid*)(sizeof(GLfloat) * (offset += structSizes[element - 1]))); element++;
glVertexAttribPointer(element, structSizes[element], GL_FLOAT, GL_FALSE, stride, (GLvoid*)(sizeof(GLfloat) * (offset += structSizes[element - 1]))); element++;
glVertexAttribPointer(element, structSizes[element], GL_FLOAT, GL_FALSE, stride, (GLvoid*)(sizeof(GLfloat) * (offset += structSizes[element - 1]))); element++;
glVertexAttribPointer(element, structSizes[element], GL_FLOAT, GL_FALSE, stride, (GLvoid*)(sizeof(GLfloat) * (offset += structSizes[element - 1]))); element++;
glVertexAttribPointer(element, structSizes[element], GL_FLOAT, GL_FALSE, stride, (GLvoid*)(sizeof(GLfloat) * (offset += structSizes[element - 1]))); element++;
glVertexAttribPointer(element, structSizes[element], GL_FLOAT, GL_FALSE, stride, (GLvoid*)(sizeof(GLfloat) * (offset += structSizes[element - 1]))); element++;
glVertexAttribPointer(element, structSizes[element], GL_FLOAT, GL_FALSE, stride, (GLvoid*)(sizeof(GLfloat) * (offset += structSizes[element - 1]))); element++;
}
GLERROR("GLEW: BufferFail5");
glEnableVertexAttribArray(0);
glEnableVertexAttribArray(1);
glEnableVertexAttribArray(2);
glEnableVertexAttribArray(3);
glEnableVertexAttribArray(4);
glEnableVertexAttribArray(5);
glEnableVertexAttribArray(6);
glEnableVertexAttribArray(7);
glEnableVertexAttribArray(8);
glEnableVertexAttribArray(9);
glEnableVertexAttribArray(10);
GLERROR("GLEW: BufferFail5");
//CreateBuffers();
}
dd::Model::~Model()
{
}
+33 -26
View File
@@ -17,7 +17,7 @@
*/
#include "PrecompiledHeader.h"
#include "Core/Renderer.h"
#include "Rendering/Renderer.h"
void dd::Renderer::Initialize()
{
@@ -45,7 +45,7 @@ void dd::Renderer::Initialize()
glGetIntegerv(GL_MINOR_VERSION, &m_GLVersion[1]);
m_GLVendor = (GLchar*)glGetString(GL_VENDOR);
std::stringstream ss;
ss << m_GLVendor << " OpenGL " << m_GLVersion[0] << "." << m_GLVersion[1];
ss << "Squidout! (" << m_GLVendor << " OpenGL " << m_GLVersion[0] << "." << m_GLVersion[1] << ")";
#ifdef DEBUG
ss << " DEBUG";
#endif
@@ -80,7 +80,7 @@ void dd::Renderer::LoadShaders()
*/
// Pass #1: Fill G-buffers
m_SpDeferred1 = ResourceManager::Load<ShaderProgram>("Shaders/Deferred/1/");
m_SpDeferred1 = ResourceManager::Load<ShaderProgram>("Shaders/OpenGL/Deferred/1/");
m_SpDeferred1->BindFragDataLocation(0, "GDiffuse");
m_SpDeferred1->BindFragDataLocation(1, "GPosition");
m_SpDeferred1->BindFragDataLocation(2, "GNormal");
@@ -88,30 +88,30 @@ void dd::Renderer::LoadShaders()
m_SpDeferred1->Link();
// Pass #2: Lighting
m_SpDeferred2 = ResourceManager::Load<ShaderProgram>("Shaders/Deferred/2/");
m_SpDeferred2 = ResourceManager::Load<ShaderProgram>("Shaders/OpenGL/Deferred/2/");
//glBindFragDataLocation(m_SPDeferred2, 0, "FragmentLighting");
m_SpDeferred2->Link();
//Water Pass
m_SpWater = ResourceManager::Load<ShaderProgram>("Shaders/Deferred/water/");
m_SpWater = ResourceManager::Load<ShaderProgram>("Shaders/OpenGL/Deferred/water/");
m_SpWater->Link();
m_SpWater2 = ResourceManager::Load<ShaderProgram>("Shaders/Deferred/water2/");
m_SpWater2 = ResourceManager::Load<ShaderProgram>("Shaders/OpenGL/Deferred/water2/");
m_SpWater2->Link();
// Pass #3: Combining into final image
m_SpDeferred3 = ResourceManager::Load<ShaderProgram>("Shaders/Deferred/3/");
m_SpDeferred3 = ResourceManager::Load<ShaderProgram>("Shaders/OpenGL/Deferred/3/");
m_SpDeferred3->Link();
/*
Forward rendering
*/
m_SpForward = ResourceManager::Load<ShaderProgram>("Shaders/Forward/");
m_SpForward = ResourceManager::Load<ShaderProgram>("Shaders/OpenGL/Forward/");
m_SpForward->Link();
/*
Screen draw
*/
m_SpScreen = ResourceManager::Load<ShaderProgram>("Shaders/Screen/");
m_SpScreen = ResourceManager::Load<ShaderProgram>("Shaders/OpenGL/Screen/");
m_SpScreen->Link();
}
@@ -121,6 +121,7 @@ void dd::Renderer::CreateBuffers()
m_ScreenQuad = CreateQuad();
m_UnitQuad = ResourceManager::Load<Model>("Models/Core/UnitQuad.obj");
m_UnitSphere = ResourceManager::Load<Model>("Models/Core/UnitSphere.obj");
m_ErrorTexture = ResourceManager::Load<Texture>("Textures/Core/ErrorTexture.png");
m_StandardNormal = ResourceManager::Load<Texture>("Textures/Core/NeutralNormalMap.png");
m_StandardSpecular = ResourceManager::Load<Texture>("Textures/Core/NeutralSpecularMap.png");
//m_WhiteSphereTexture = ResourceManager::Load<Texture>("Textures/Test/Water.png");
@@ -414,22 +415,28 @@ void dd::Renderer::DrawScene(RenderQueue &objects, ShaderProgram &program)
glUniform1f(glGetUniformLocation(shaderProgramHandle, "LightRadius"), 40.0f);
glUniform1f(glGetUniformLocation(shaderProgramHandle, "MaterialShininess"), modelJob->Shininess);
glActiveTexture(GL_TEXTURE0);
glBindTexture(GL_TEXTURE_2D, modelJob->DiffuseTexture);
if (modelJob->NormalTexture != 0) {
glActiveTexture(GL_TEXTURE1);
glBindTexture(GL_TEXTURE_2D, modelJob->NormalTexture);
if (modelJob->DiffuseTexture != nullptr) {
glActiveTexture(GL_TEXTURE0);
glBindTexture(GL_TEXTURE_2D, modelJob->DiffuseTexture->m_Texture);
} else {
glActiveTexture(GL_TEXTURE1);
glBindTexture(GL_TEXTURE_2D, *m_StandardNormal);
glActiveTexture(GL_TEXTURE0);
glBindTexture(GL_TEXTURE_2D, m_ErrorTexture->m_Texture);
}
if (modelJob->SpecularTexture != 0) {
if (modelJob->NormalTexture != nullptr) {
glActiveTexture(GL_TEXTURE1);
glBindTexture(GL_TEXTURE_2D, modelJob->NormalTexture->m_Texture);
} else {
glActiveTexture(GL_TEXTURE1);
glBindTexture(GL_TEXTURE_2D, m_StandardNormal->m_Texture);
}
if (modelJob->SpecularTexture != nullptr) {
glActiveTexture(GL_TEXTURE2);
glBindTexture(GL_TEXTURE_2D, modelJob->SpecularTexture);
glBindTexture(GL_TEXTURE_2D, modelJob->SpecularTexture->m_Texture);
} else {
glActiveTexture(GL_TEXTURE2);
glBindTexture(GL_TEXTURE_2D, *m_StandardSpecular);
glBindTexture(GL_TEXTURE_2D, m_StandardSpecular->m_Texture);
}
if (modelJob->Skeleton != nullptr) {
@@ -446,8 +453,8 @@ void dd::Renderer::DrawScene(RenderQueue &objects, ShaderProgram &program)
}
}
glBindVertexArray(modelJob->VAO);
glBindBuffer(GL_ELEMENT_ARRAY_BUFFER, modelJob->ElementBuffer);
glBindVertexArray(modelJob->Model->VAO);
glBindBuffer(GL_ELEMENT_ARRAY_BUFFER, modelJob->Model->ElementBuffer);
glDrawElementsBaseVertex(GL_TRIANGLES, modelJob->EndIndex - modelJob->StartIndex + 1, GL_UNSIGNED_INT, 0, modelJob->StartIndex);
continue;
@@ -464,11 +471,11 @@ void dd::Renderer::DrawScene(RenderQueue &objects, ShaderProgram &program)
glUniform4fv(glGetUniformLocation(shaderProgramHandle, "Color"), 1, glm::value_ptr(spriteJob->Color));
glActiveTexture(GL_TEXTURE0);
glBindTexture(GL_TEXTURE_2D, spriteJob->DiffuseTexture);
glBindTexture(GL_TEXTURE_2D, spriteJob->DiffuseTexture->m_Texture);
glActiveTexture(GL_TEXTURE1);
glBindTexture(GL_TEXTURE_2D, spriteJob->NormalTexture);
glBindTexture(GL_TEXTURE_2D, spriteJob->NormalTexture->m_Texture);
glActiveTexture(GL_TEXTURE2);
glBindTexture(GL_TEXTURE_2D, spriteJob->SpecularTexture);
glBindTexture(GL_TEXTURE_2D, spriteJob->SpecularTexture->m_Texture);
glBindVertexArray(m_UnitQuad->VAO);
glBindBuffer(GL_ELEMENT_ARRAY_BUFFER, m_UnitQuad->ElementBuffer);
@@ -536,7 +543,7 @@ void dd::Renderer::DrawWater(RenderQueue &rq)
glm::value_ptr(viewMatrix));
glActiveTexture(GL_TEXTURE0);
glBindTexture(GL_TEXTURE_2D, *m_WhiteSphereTexture);
glBindTexture(GL_TEXTURE_2D, m_WhiteSphereTexture->m_Texture);
glBindVertexArray(m_UnitQuad->VAO);
glBindBuffer(GL_ELEMENT_ARRAY_BUFFER, m_UnitQuad->ElementBuffer);
@@ -691,7 +698,7 @@ void dd::Renderer::DrawGUI(dd::RenderQueue& rq)
glUniform4fv(glGetUniformLocation(*m_SpScreen, "Color"), 1, glm::value_ptr(frameJob->Color));
glActiveTexture(GL_TEXTURE0);
glBindTexture(GL_TEXTURE_2D, frameJob->DiffuseTexture);
glBindTexture(GL_TEXTURE_2D, frameJob->DiffuseTexture->m_Texture);
//glActiveTexture(GL_TEXTURE1);
//glBindTexture(GL_TEXTURE_2D, frameJob->NormalTexture);
//glActiveTexture(GL_TEXTURE2);
@@ -17,7 +17,7 @@
*/
#include "PrecompiledHeader.h"
#include "Core/ShaderProgram.h"
#include "Rendering/ShaderProgram.h"
void dd::Shader::Compile()
{

Some files were not shown because too many files have changed in this diff Show More