mirror of
https://github.com/celisej567/source-engine.git
synced 2026-01-13 10:09:54 +03:00
Compare commits
16 Commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
b9cf6b2c7e | ||
|
|
f4e00c3159 | ||
|
|
82d805508c | ||
|
|
b7bd94c52e | ||
|
|
1d4f7fb2cc | ||
|
|
b5d6051d98 | ||
|
|
b73f3b70fa | ||
|
|
2d3f31d37e | ||
|
|
5ea9937457 | ||
|
|
601cfff164 | ||
|
|
4f10928299 | ||
|
|
02a3c641a6 | ||
|
|
7f267853f4 | ||
|
|
3d0025b594 | ||
|
|
b6cb0c2696 | ||
|
|
8acf608b4d |
@@ -404,6 +404,9 @@ private:
|
||||
int m_MouseButtonDownX;
|
||||
int m_MouseButtonDownY;
|
||||
|
||||
bool m_bResetVsync;
|
||||
int m_nFramesToSkip;
|
||||
|
||||
double m_flPrevGLSwapWindowTime;
|
||||
};
|
||||
|
||||
@@ -584,6 +587,9 @@ InitReturnVal_t CSDLMgr::Init()
|
||||
m_nWarpDelta = 0;
|
||||
m_bRawInput = false;
|
||||
|
||||
m_nFramesToSkip = 0;
|
||||
m_bResetVsync = false;
|
||||
|
||||
m_flPrevGLSwapWindowTime = 0.0f;
|
||||
|
||||
memset(m_pixelFormatAttribs, '\0', sizeof (m_pixelFormatAttribs));
|
||||
@@ -1431,7 +1437,20 @@ void CSDLMgr::ShowPixels( CShowPixelsParams *params )
|
||||
|
||||
m_flPrevGLSwapWindowTime = tm.GetDurationInProgress().GetMillisecondsF();
|
||||
|
||||
|
||||
#ifdef ANDROID
|
||||
// ADRENO GPU MOMENT, SKIP 5 FRAMES
|
||||
if( m_bResetVsync )
|
||||
{
|
||||
if( m_nFramesToSkip <= 0 )
|
||||
{
|
||||
SDL_GL_SetSwapInterval(swapInterval);
|
||||
m_bResetVsync = false;
|
||||
}
|
||||
else
|
||||
m_nFramesToSkip--;
|
||||
}
|
||||
#endif
|
||||
|
||||
CheckGLError( __LINE__ );
|
||||
}
|
||||
#endif // DX_TO_GL_ABSTRACTION
|
||||
@@ -1887,6 +1906,7 @@ void CSDLMgr::PumpWindowsMessageLoop()
|
||||
}
|
||||
case SDL_WINDOWEVENT_FOCUS_GAINED:
|
||||
{
|
||||
m_bResetVsync = true; m_nFramesToSkip = 3;
|
||||
m_bHasFocus = true;
|
||||
SDL_ShowCursor( m_bCursorVisible ? 1 : 0 );
|
||||
CCocoaEvent theEvent;
|
||||
|
||||
599
engine/audio/snd_dev_mac_audioqueue.cpp
Normal file
599
engine/audio/snd_dev_mac_audioqueue.cpp
Normal file
@@ -0,0 +1,599 @@
|
||||
//========= Copyright Valve Corporation, All rights reserved. ============//
|
||||
//
|
||||
// Purpose:
|
||||
//
|
||||
//===========================================================================//
|
||||
|
||||
#include "audio_pch.h"
|
||||
#include <AudioToolbox/AudioQueue.h>
|
||||
#include <AudioToolbox/AudioFile.h>
|
||||
#include <AudioToolbox/AudioFormat.h>
|
||||
|
||||
// memdbgon must be the last include file in a .cpp file!!!
|
||||
#include "tier0/memdbgon.h"
|
||||
|
||||
extern bool snd_firsttime;
|
||||
extern bool MIX_ScaleChannelVolume( paintbuffer_t *ppaint, channel_t *pChannel, int volume[CCHANVOLUMES], int mixchans );
|
||||
extern void S_SpatializeChannel( int volume[6], int master_vol, const Vector *psourceDir, float gain, float mono );
|
||||
|
||||
#define NUM_BUFFERS_SOURCES 128
|
||||
#define BUFF_MASK (NUM_BUFFERS_SOURCES - 1 )
|
||||
#define BUFFER_SIZE 0x0400
|
||||
|
||||
|
||||
//-----------------------------------------------------------------------------
|
||||
//
|
||||
// NOTE: This only allows 16-bit, stereo wave out
|
||||
//
|
||||
//-----------------------------------------------------------------------------
|
||||
class CAudioDeviceAudioQueue : public CAudioDeviceBase
|
||||
{
|
||||
public:
|
||||
bool IsActive( void );
|
||||
bool Init( void );
|
||||
void Shutdown( void );
|
||||
void PaintEnd( void );
|
||||
int GetOutputPosition( void );
|
||||
void ChannelReset( int entnum, int channelIndex, float distanceMod );
|
||||
void Pause( void );
|
||||
void UnPause( void );
|
||||
float MixDryVolume( void );
|
||||
bool Should3DMix( void );
|
||||
void StopAllSounds( void );
|
||||
|
||||
int PaintBegin( float mixAheadTime, int soundtime, int paintedtime );
|
||||
void ClearBuffer( void );
|
||||
void UpdateListener( const Vector& position, const Vector& forward, const Vector& right, const Vector& up );
|
||||
void MixBegin( int sampleCount );
|
||||
void MixUpsample( int sampleCount, int filtertype );
|
||||
void Mix8Mono( channel_t *pChannel, char *pData, int outputOffset, int inputOffset, fixedint rateScaleFix, int outCount, int timecompress );
|
||||
void Mix8Stereo( channel_t *pChannel, char *pData, int outputOffset, int inputOffset, fixedint rateScaleFix, int outCount, int timecompress );
|
||||
void Mix16Mono( channel_t *pChannel, short *pData, int outputOffset, int inputOffset, fixedint rateScaleFix, int outCount, int timecompress );
|
||||
void Mix16Stereo( channel_t *pChannel, short *pData, int outputOffset, int inputOffset, fixedint rateScaleFix, int outCount, int timecompress );
|
||||
|
||||
void TransferSamples( int end );
|
||||
void SpatializeChannel( int volume[CCHANVOLUMES/2], int master_vol, const Vector& sourceDir, float gain, float mono);
|
||||
void ApplyDSPEffects( int idsp, portable_samplepair_t *pbuffront, portable_samplepair_t *pbufrear, portable_samplepair_t *pbufcenter, int samplecount );
|
||||
|
||||
const char *DeviceName( void ) { return "AudioQueue"; }
|
||||
int DeviceChannels( void ) { return 2; }
|
||||
int DeviceSampleBits( void ) { return 16; }
|
||||
int DeviceSampleBytes( void ) { return 2; }
|
||||
int DeviceDmaSpeed( void ) { return SOUND_DMA_SPEED; }
|
||||
int DeviceSampleCount( void ) { return m_deviceSampleCount; }
|
||||
|
||||
void BufferCompleted() { m_buffersCompleted++; }
|
||||
void SetRunning( bool bState ) { m_bRunning = bState; }
|
||||
|
||||
private:
|
||||
void OpenWaveOut( void );
|
||||
void CloseWaveOut( void );
|
||||
bool ValidWaveOut( void ) const;
|
||||
bool BIsPlaying();
|
||||
|
||||
AudioStreamBasicDescription m_DataFormat;
|
||||
AudioQueueRef m_Queue;
|
||||
AudioQueueBufferRef m_Buffers[NUM_BUFFERS_SOURCES];
|
||||
|
||||
int m_SndBufSize;
|
||||
|
||||
void *m_sndBuffers;
|
||||
|
||||
CInterlockedInt m_deviceSampleCount;
|
||||
|
||||
int m_buffersSent;
|
||||
int m_buffersCompleted;
|
||||
int m_pauseCount;
|
||||
bool m_bSoundsShutdown;
|
||||
|
||||
bool m_bFailed;
|
||||
bool m_bRunning;
|
||||
|
||||
|
||||
};
|
||||
|
||||
CAudioDeviceAudioQueue *wave = NULL;
|
||||
|
||||
|
||||
static void AudioCallback(void *pContext, AudioQueueRef pQueue, AudioQueueBufferRef pBuffer)
|
||||
{
|
||||
if ( wave )
|
||||
wave->BufferCompleted();
|
||||
}
|
||||
|
||||
|
||||
IAudioDevice *Audio_CreateMacAudioQueueDevice( void )
|
||||
{
|
||||
wave = new CAudioDeviceAudioQueue;
|
||||
if ( wave->Init() )
|
||||
return wave;
|
||||
|
||||
delete wave;
|
||||
wave = NULL;
|
||||
|
||||
return NULL;
|
||||
}
|
||||
|
||||
|
||||
void OnSndSurroundCvarChanged2( IConVar *pVar, const char *pOldString, float flOldValue );
|
||||
void OnSndSurroundLegacyChanged2( IConVar *pVar, const char *pOldString, float flOldValue );
|
||||
|
||||
//-----------------------------------------------------------------------------
|
||||
// Init, shutdown
|
||||
//-----------------------------------------------------------------------------
|
||||
bool CAudioDeviceAudioQueue::Init( void )
|
||||
{
|
||||
m_SndBufSize = 0;
|
||||
m_sndBuffers = NULL;
|
||||
m_pauseCount = 0;
|
||||
|
||||
m_bSurround = false;
|
||||
m_bSurroundCenter = false;
|
||||
m_bHeadphone = false;
|
||||
m_buffersSent = 0;
|
||||
m_buffersCompleted = 0;
|
||||
m_pauseCount = 0;
|
||||
m_bSoundsShutdown = false;
|
||||
m_bFailed = false;
|
||||
m_bRunning = false;
|
||||
|
||||
m_Queue = NULL;
|
||||
|
||||
static bool first = true;
|
||||
if ( first )
|
||||
{
|
||||
snd_surround.SetValue( 2 );
|
||||
snd_surround.InstallChangeCallback( &OnSndSurroundCvarChanged2 );
|
||||
snd_legacy_surround.InstallChangeCallback( &OnSndSurroundLegacyChanged2 );
|
||||
first = false;
|
||||
}
|
||||
|
||||
OpenWaveOut();
|
||||
|
||||
if ( snd_firsttime )
|
||||
{
|
||||
DevMsg( "Wave sound initialized\n" );
|
||||
}
|
||||
return ValidWaveOut() && !m_bFailed;
|
||||
}
|
||||
|
||||
void CAudioDeviceAudioQueue::Shutdown( void )
|
||||
{
|
||||
CloseWaveOut();
|
||||
}
|
||||
|
||||
|
||||
//-----------------------------------------------------------------------------
|
||||
// WAV out device
|
||||
//-----------------------------------------------------------------------------
|
||||
inline bool CAudioDeviceAudioQueue::ValidWaveOut( void ) const
|
||||
{
|
||||
return m_sndBuffers != 0 && m_Queue;
|
||||
}
|
||||
|
||||
|
||||
//-----------------------------------------------------------------------------
|
||||
// called by the mac audioqueue code when we run out of playback buffers
|
||||
//-----------------------------------------------------------------------------
|
||||
void AudioQueueIsRunningCallback( void* inClientData, AudioQueueRef inAQ, AudioQueuePropertyID inID)
|
||||
{
|
||||
CAudioDeviceAudioQueue* audioqueue = (CAudioDeviceAudioQueue*)inClientData;
|
||||
|
||||
UInt32 running = 0;
|
||||
UInt32 size;
|
||||
OSStatus err = AudioQueueGetProperty(inAQ, kAudioQueueProperty_IsRunning, &running, &size);
|
||||
audioqueue->SetRunning( running != 0 );
|
||||
//DevWarning( "AudioQueueStart %d\n", running );
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
//-----------------------------------------------------------------------------
|
||||
// Opens the windows wave out device
|
||||
//-----------------------------------------------------------------------------
|
||||
void CAudioDeviceAudioQueue::OpenWaveOut( void )
|
||||
{
|
||||
if ( m_Queue )
|
||||
return;
|
||||
|
||||
m_buffersSent = 0;
|
||||
m_buffersCompleted = 0;
|
||||
|
||||
m_DataFormat.mSampleRate = 44100;
|
||||
m_DataFormat.mFormatID = kAudioFormatLinearPCM;
|
||||
m_DataFormat.mFormatFlags = kAudioFormatFlagIsSignedInteger|kAudioFormatFlagIsPacked;
|
||||
m_DataFormat.mBytesPerPacket = 4; // 16-bit samples * 2 channels
|
||||
m_DataFormat.mFramesPerPacket = 1;
|
||||
m_DataFormat.mBytesPerFrame = 4; // 16-bit samples * 2 channels
|
||||
m_DataFormat.mChannelsPerFrame = 2;
|
||||
m_DataFormat.mBitsPerChannel = 16;
|
||||
m_DataFormat.mReserved = 0;
|
||||
|
||||
// Create the audio queue that will be used to manage the array of audio
|
||||
// buffers used to queue samples.
|
||||
OSStatus err = AudioQueueNewOutput(&m_DataFormat, AudioCallback, this, NULL, NULL, 0, &m_Queue);
|
||||
if ( err != noErr)
|
||||
{
|
||||
DevMsg( "Failed to create AudioQueue output %d\n", (int)err );
|
||||
m_bFailed = true;
|
||||
return;
|
||||
}
|
||||
|
||||
for ( int i = 0; i < NUM_BUFFERS_SOURCES; ++i)
|
||||
{
|
||||
err = AudioQueueAllocateBuffer( m_Queue, BUFFER_SIZE,&(m_Buffers[i]));
|
||||
if ( err != noErr)
|
||||
{
|
||||
DevMsg( "Failed to AudioQueueAllocateBuffer output %d (%i)\n",(int)err,i );
|
||||
m_bFailed = true;
|
||||
}
|
||||
|
||||
m_Buffers[i]->mAudioDataByteSize = BUFFER_SIZE;
|
||||
Q_memset( m_Buffers[i]->mAudioData, 0, BUFFER_SIZE );
|
||||
}
|
||||
|
||||
err = AudioQueuePrime( m_Queue, 0, NULL);
|
||||
if ( err != noErr)
|
||||
{
|
||||
DevMsg( "Failed to create AudioQueue output %d\n", (int)err );
|
||||
m_bFailed = true;
|
||||
return;
|
||||
}
|
||||
|
||||
AudioQueueSetParameter( m_Queue, kAudioQueueParam_Volume, 1.0);
|
||||
|
||||
err = AudioQueueAddPropertyListener( m_Queue, kAudioQueueProperty_IsRunning, AudioQueueIsRunningCallback, this );
|
||||
if ( err != noErr)
|
||||
{
|
||||
DevMsg( "Failed to create AudioQueue output %d\n", (int)err );
|
||||
m_bFailed = true;
|
||||
return;
|
||||
}
|
||||
|
||||
m_SndBufSize = NUM_BUFFERS_SOURCES*BUFFER_SIZE;
|
||||
m_deviceSampleCount = m_SndBufSize / DeviceSampleBytes();
|
||||
|
||||
if ( !m_sndBuffers )
|
||||
{
|
||||
m_sndBuffers = malloc( m_SndBufSize );
|
||||
memset( m_sndBuffers, 0x0, m_SndBufSize );
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
//-----------------------------------------------------------------------------
|
||||
// Closes the windows wave out device
|
||||
//-----------------------------------------------------------------------------
|
||||
void CAudioDeviceAudioQueue::CloseWaveOut( void )
|
||||
{
|
||||
if ( ValidWaveOut() )
|
||||
{
|
||||
AudioQueueStop(m_Queue, true);
|
||||
m_bRunning = false;
|
||||
|
||||
AudioQueueRemovePropertyListener( m_Queue, kAudioQueueProperty_IsRunning, AudioQueueIsRunningCallback, this );
|
||||
|
||||
for ( int i = 0; i < NUM_BUFFERS_SOURCES; i++ )
|
||||
AudioQueueFreeBuffer( m_Queue, m_Buffers[i]);
|
||||
|
||||
AudioQueueDispose( m_Queue, true);
|
||||
|
||||
m_Queue = NULL;
|
||||
}
|
||||
|
||||
if ( m_sndBuffers )
|
||||
{
|
||||
free( m_sndBuffers );
|
||||
m_sndBuffers = NULL;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
||||
//-----------------------------------------------------------------------------
|
||||
// Mixing setup
|
||||
//-----------------------------------------------------------------------------
|
||||
int CAudioDeviceAudioQueue::PaintBegin( float mixAheadTime, int soundtime, int paintedtime )
|
||||
{
|
||||
// soundtime - total samples that have been played out to hardware at dmaspeed
|
||||
// paintedtime - total samples that have been mixed at speed
|
||||
// endtime - target for samples in mixahead buffer at speed
|
||||
|
||||
unsigned int endtime = soundtime + mixAheadTime * DeviceDmaSpeed();
|
||||
|
||||
int samps = DeviceSampleCount() >> (DeviceChannels()-1);
|
||||
|
||||
if ((int)(endtime - soundtime) > samps)
|
||||
endtime = soundtime + samps;
|
||||
|
||||
if ((endtime - paintedtime) & 0x3)
|
||||
{
|
||||
// The difference between endtime and painted time should align on
|
||||
// boundaries of 4 samples. This is important when upsampling from 11khz -> 44khz.
|
||||
endtime -= (endtime - paintedtime) & 0x3;
|
||||
}
|
||||
|
||||
return endtime;
|
||||
}
|
||||
|
||||
|
||||
//-----------------------------------------------------------------------------
|
||||
// Actually performs the mixing
|
||||
//-----------------------------------------------------------------------------
|
||||
void CAudioDeviceAudioQueue::PaintEnd( void )
|
||||
{
|
||||
int cblocks = 4 << 1;
|
||||
|
||||
if ( m_bRunning && m_buffersSent == m_buffersCompleted )
|
||||
{
|
||||
// We are running the audio queue but have become starved of buffers.
|
||||
// Stop the audio queue so we force a restart of it.
|
||||
AudioQueueStop( m_Queue, true );
|
||||
}
|
||||
|
||||
//
|
||||
// submit a few new sound blocks
|
||||
//
|
||||
// 44K sound support
|
||||
while (((m_buffersSent - m_buffersCompleted) >> SAMPLE_16BIT_SHIFT) < cblocks)
|
||||
{
|
||||
int iBuf = m_buffersSent&BUFF_MASK;
|
||||
|
||||
m_Buffers[iBuf]->mAudioDataByteSize = BUFFER_SIZE;
|
||||
Q_memcpy( m_Buffers[iBuf]->mAudioData, (char *)m_sndBuffers + iBuf*BUFFER_SIZE, BUFFER_SIZE);
|
||||
|
||||
// Queue the buffer for playback.
|
||||
OSStatus err = AudioQueueEnqueueBuffer( m_Queue, m_Buffers[iBuf], 0, NULL);
|
||||
if ( err != noErr)
|
||||
{
|
||||
DevMsg( "Failed to AudioQueueEnqueueBuffer output %d\n", (int)err );
|
||||
}
|
||||
|
||||
m_buffersSent++;
|
||||
}
|
||||
|
||||
|
||||
if ( !m_bRunning )
|
||||
{
|
||||
DevMsg( "Restarting sound playback\n" );
|
||||
m_bRunning = true;
|
||||
AudioQueueStart( m_Queue, NULL);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
int CAudioDeviceAudioQueue::GetOutputPosition( void )
|
||||
{
|
||||
int s = m_buffersSent * BUFFER_SIZE;
|
||||
|
||||
s >>= SAMPLE_16BIT_SHIFT;
|
||||
|
||||
s &= (DeviceSampleCount()-1);
|
||||
|
||||
return s / DeviceChannels();
|
||||
}
|
||||
|
||||
|
||||
//-----------------------------------------------------------------------------
|
||||
// Pausing
|
||||
//-----------------------------------------------------------------------------
|
||||
void CAudioDeviceAudioQueue::Pause( void )
|
||||
{
|
||||
m_pauseCount++;
|
||||
if (m_pauseCount == 1)
|
||||
{
|
||||
m_bRunning = false;
|
||||
AudioQueueStop(m_Queue, true);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
void CAudioDeviceAudioQueue::UnPause( void )
|
||||
{
|
||||
if ( m_pauseCount > 0 )
|
||||
{
|
||||
m_pauseCount--;
|
||||
}
|
||||
|
||||
if ( m_pauseCount == 0 )
|
||||
{
|
||||
m_bRunning = true;
|
||||
AudioQueueStart( m_Queue, NULL);
|
||||
}
|
||||
}
|
||||
|
||||
bool CAudioDeviceAudioQueue::IsActive( void )
|
||||
{
|
||||
return ( m_pauseCount == 0 );
|
||||
}
|
||||
|
||||
float CAudioDeviceAudioQueue::MixDryVolume( void )
|
||||
{
|
||||
return 0;
|
||||
}
|
||||
|
||||
|
||||
bool CAudioDeviceAudioQueue::Should3DMix( void )
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
|
||||
void CAudioDeviceAudioQueue::ClearBuffer( void )
|
||||
{
|
||||
if ( !m_sndBuffers )
|
||||
return;
|
||||
|
||||
Q_memset( m_sndBuffers, 0x0, DeviceSampleCount() * DeviceSampleBytes() );
|
||||
}
|
||||
|
||||
void CAudioDeviceAudioQueue::UpdateListener( const Vector& position, const Vector& forward, const Vector& right, const Vector& up )
|
||||
{
|
||||
}
|
||||
|
||||
|
||||
bool CAudioDeviceAudioQueue::BIsPlaying()
|
||||
{
|
||||
UInt32 isRunning;
|
||||
UInt32 propSize = sizeof(isRunning);
|
||||
|
||||
OSStatus result = AudioQueueGetProperty( m_Queue, kAudioQueueProperty_IsRunning, &isRunning, &propSize);
|
||||
return isRunning != 0;
|
||||
}
|
||||
|
||||
|
||||
void CAudioDeviceAudioQueue::MixBegin( int sampleCount )
|
||||
{
|
||||
MIX_ClearAllPaintBuffers( sampleCount, false );
|
||||
}
|
||||
|
||||
|
||||
void CAudioDeviceAudioQueue::MixUpsample( int sampleCount, int filtertype )
|
||||
{
|
||||
paintbuffer_t *ppaint = MIX_GetCurrentPaintbufferPtr();
|
||||
int ifilter = ppaint->ifilter;
|
||||
|
||||
Assert (ifilter < CPAINTFILTERS);
|
||||
|
||||
S_MixBufferUpsample2x( sampleCount, ppaint->pbuf, &(ppaint->fltmem[ifilter][0]), CPAINTFILTERMEM, filtertype );
|
||||
|
||||
ppaint->ifilter++;
|
||||
}
|
||||
|
||||
void CAudioDeviceAudioQueue::Mix8Mono( channel_t *pChannel, char *pData, int outputOffset, int inputOffset, fixedint rateScaleFix, int outCount, int timecompress )
|
||||
{
|
||||
int volume[CCHANVOLUMES];
|
||||
paintbuffer_t *ppaint = MIX_GetCurrentPaintbufferPtr();
|
||||
|
||||
if (!MIX_ScaleChannelVolume( ppaint, pChannel, volume, 1))
|
||||
return;
|
||||
|
||||
Mix8MonoWavtype( pChannel, ppaint->pbuf + outputOffset, volume, (byte *)pData, inputOffset, rateScaleFix, outCount );
|
||||
}
|
||||
|
||||
|
||||
void CAudioDeviceAudioQueue::Mix8Stereo( channel_t *pChannel, char *pData, int outputOffset, int inputOffset, fixedint rateScaleFix, int outCount, int timecompress )
|
||||
{
|
||||
int volume[CCHANVOLUMES];
|
||||
paintbuffer_t *ppaint = MIX_GetCurrentPaintbufferPtr();
|
||||
|
||||
if (!MIX_ScaleChannelVolume( ppaint, pChannel, volume, 2 ))
|
||||
return;
|
||||
|
||||
Mix8StereoWavtype( pChannel, ppaint->pbuf + outputOffset, volume, (byte *)pData, inputOffset, rateScaleFix, outCount );
|
||||
}
|
||||
|
||||
|
||||
void CAudioDeviceAudioQueue::Mix16Mono( channel_t *pChannel, short *pData, int outputOffset, int inputOffset, fixedint rateScaleFix, int outCount, int timecompress )
|
||||
{
|
||||
int volume[CCHANVOLUMES];
|
||||
paintbuffer_t *ppaint = MIX_GetCurrentPaintbufferPtr();
|
||||
|
||||
if (!MIX_ScaleChannelVolume( ppaint, pChannel, volume, 1 ))
|
||||
return;
|
||||
|
||||
Mix16MonoWavtype( pChannel, ppaint->pbuf + outputOffset, volume, pData, inputOffset, rateScaleFix, outCount );
|
||||
}
|
||||
|
||||
|
||||
void CAudioDeviceAudioQueue::Mix16Stereo( channel_t *pChannel, short *pData, int outputOffset, int inputOffset, fixedint rateScaleFix, int outCount, int timecompress )
|
||||
{
|
||||
int volume[CCHANVOLUMES];
|
||||
paintbuffer_t *ppaint = MIX_GetCurrentPaintbufferPtr();
|
||||
|
||||
if (!MIX_ScaleChannelVolume( ppaint, pChannel, volume, 2 ))
|
||||
return;
|
||||
|
||||
Mix16StereoWavtype( pChannel, ppaint->pbuf + outputOffset, volume, pData, inputOffset, rateScaleFix, outCount );
|
||||
}
|
||||
|
||||
|
||||
void CAudioDeviceAudioQueue::ChannelReset( int entnum, int channelIndex, float distanceMod )
|
||||
{
|
||||
}
|
||||
|
||||
|
||||
void CAudioDeviceAudioQueue::TransferSamples( int end )
|
||||
{
|
||||
int lpaintedtime = g_paintedtime;
|
||||
int endtime = end;
|
||||
|
||||
// resumes playback...
|
||||
|
||||
if ( m_sndBuffers )
|
||||
{
|
||||
S_TransferStereo16( m_sndBuffers, PAINTBUFFER, lpaintedtime, endtime );
|
||||
}
|
||||
}
|
||||
|
||||
void CAudioDeviceAudioQueue::SpatializeChannel( int volume[CCHANVOLUMES/2], int master_vol, const Vector& sourceDir, float gain, float mono )
|
||||
{
|
||||
VPROF("CAudioDeviceAudioQueue::SpatializeChannel");
|
||||
S_SpatializeChannel( volume, master_vol, &sourceDir, gain, mono );
|
||||
}
|
||||
|
||||
void CAudioDeviceAudioQueue::StopAllSounds( void )
|
||||
{
|
||||
m_bSoundsShutdown = true;
|
||||
m_bRunning = false;
|
||||
AudioQueueStop(m_Queue, true);
|
||||
}
|
||||
|
||||
|
||||
|
||||
void CAudioDeviceAudioQueue::ApplyDSPEffects( int idsp, portable_samplepair_t *pbuffront, portable_samplepair_t *pbufrear, portable_samplepair_t *pbufcenter, int samplecount )
|
||||
{
|
||||
//SX_RoomFX( endtime, filter, timefx );
|
||||
DSP_Process( idsp, pbuffront, pbufrear, pbufcenter, samplecount );
|
||||
}
|
||||
|
||||
|
||||
static uint32 GetOSXSpeakerConfig()
|
||||
{
|
||||
return 2;
|
||||
}
|
||||
|
||||
static uint32 GetSpeakerConfigForSurroundMode( int surroundMode, const char **pConfigDesc )
|
||||
{
|
||||
uint32 newSpeakerConfig = 2;
|
||||
*pConfigDesc = "stereo speaker";
|
||||
return newSpeakerConfig;
|
||||
}
|
||||
|
||||
|
||||
|
||||
void OnSndSurroundCvarChanged2( IConVar *pVar, const char *pOldString, float flOldValue )
|
||||
{
|
||||
// if the old value is -1, we're setting this from the detect routine for the first time
|
||||
// no need to reset the device
|
||||
if ( flOldValue == -1 )
|
||||
return;
|
||||
|
||||
// get the user's previous speaker config
|
||||
uint32 speaker_config = GetOSXSpeakerConfig();
|
||||
|
||||
// get the new config
|
||||
uint32 newSpeakerConfig = 0;
|
||||
const char *speakerConfigDesc = "";
|
||||
|
||||
ConVarRef var( pVar );
|
||||
newSpeakerConfig = GetSpeakerConfigForSurroundMode( var.GetInt(), &speakerConfigDesc );
|
||||
// make sure the config has changed
|
||||
if (newSpeakerConfig == speaker_config)
|
||||
return;
|
||||
|
||||
// set new configuration
|
||||
//SetWindowsSpeakerConfig(newSpeakerConfig);
|
||||
|
||||
Msg("Speaker configuration has been changed to %s.\n", speakerConfigDesc);
|
||||
|
||||
// restart sound system so it takes effect
|
||||
//g_pSoundServices->RestartSoundSystem();
|
||||
}
|
||||
|
||||
void OnSndSurroundLegacyChanged2( IConVar *pVar, const char *pOldString, float flOldValue )
|
||||
{
|
||||
}
|
||||
|
||||
|
||||
@@ -11,6 +11,10 @@
|
||||
#endif
|
||||
#ifdef OSX
|
||||
#include "snd_dev_openal.h"
|
||||
#include "snd_dev_mac_audioqueue.h"
|
||||
|
||||
ConVar snd_audioqueue( "snd_audioqueue", "1" );
|
||||
|
||||
#endif
|
||||
|
||||
// memdbgon must be the last include file in a .cpp file!!!
|
||||
@@ -90,6 +94,11 @@ IAudioDevice *IAudioDevice::AutoDetectInit( bool waveOnly )
|
||||
pDevice = Audio_CreateWaveDevice();
|
||||
}
|
||||
#elif defined(OSX)
|
||||
if ( !CommandLine()->CheckParm( "-snd_openal" ) )
|
||||
{
|
||||
DevMsg( "Using AudioQueue Interface\n" );
|
||||
pDevice = Audio_CreateMacAudioQueueDevice();
|
||||
}
|
||||
if ( !pDevice )
|
||||
{
|
||||
DevMsg( "Using OpenAL Interface\n" );
|
||||
|
||||
@@ -189,6 +189,8 @@ bool g_bUsingSteamVoice = false;
|
||||
|
||||
#ifdef WIN32
|
||||
extern IVoiceRecord* CreateVoiceRecord_DSound(int nSamplesPerSec);
|
||||
#elif defined( OSX )
|
||||
extern IVoiceRecord* CreateVoiceRecord_AudioQueue(int sampleRate);
|
||||
#endif
|
||||
|
||||
#ifdef POSIX
|
||||
@@ -641,8 +643,13 @@ bool Voice_Init( const char *pCodecName, int nSampleRate )
|
||||
return false;
|
||||
|
||||
// Get the voice input device.
|
||||
#if defined( OSX )
|
||||
g_pVoiceRecord = CreateVoiceRecord_OpenAL( Voice_SamplesPerSec() );
|
||||
#ifdef OSX
|
||||
g_pVoiceRecord = CreateVoiceRecord_AudioQueue( Voice_SamplesPerSec() );
|
||||
if ( !g_pVoiceRecord )
|
||||
{
|
||||
// Fall back to OpenAL
|
||||
g_pVoiceRecord = CreateVoiceRecord_OpenAL( Voice_SamplesPerSec() );
|
||||
}
|
||||
#elif defined( WIN32 )
|
||||
g_pVoiceRecord = CreateVoiceRecord_DSound( Voice_SamplesPerSec() );
|
||||
#elif defined( USE_SDL )
|
||||
|
||||
528
engine/audio/voice_record_mac_audioqueue.cpp
Normal file
528
engine/audio/voice_record_mac_audioqueue.cpp
Normal file
@@ -0,0 +1,528 @@
|
||||
//========= Copyright 1996-2009, Valve Corporation, All rights reserved. ============//
|
||||
//
|
||||
// Purpose:
|
||||
//
|
||||
// $NoKeywords: $
|
||||
//
|
||||
//=============================================================================//
|
||||
// This module implements the voice record and compression functions
|
||||
|
||||
#include <Carbon/Carbon.h>
|
||||
#include <AudioUnit/AudioUnit.h>
|
||||
#include <AudioToolbox/AudioToolbox.h>
|
||||
|
||||
#include "tier0/platform.h"
|
||||
#include "tier0/threadtools.h"
|
||||
//#include "tier0/vcrmode.h"
|
||||
#include "ivoicerecord.h"
|
||||
|
||||
|
||||
#define kNumSecAudioBuffer 1.0f
|
||||
|
||||
// ------------------------------------------------------------------------------
|
||||
// VoiceRecord_AudioQueue
|
||||
// ------------------------------------------------------------------------------
|
||||
|
||||
class VoiceRecord_AudioQueue : public IVoiceRecord
|
||||
{
|
||||
public:
|
||||
|
||||
VoiceRecord_AudioQueue();
|
||||
virtual ~VoiceRecord_AudioQueue();
|
||||
|
||||
// IVoiceRecord.
|
||||
virtual void Release();
|
||||
|
||||
virtual bool RecordStart();
|
||||
virtual void RecordStop();
|
||||
|
||||
// Initialize. The format of the data we expect from the provider is
|
||||
// 8-bit signed mono at the specified sample rate.
|
||||
virtual bool Init( int nSampleRate );
|
||||
|
||||
virtual void Idle();
|
||||
|
||||
// Get the most recent N samples.
|
||||
virtual int GetRecordedData(short *pOut, int nSamplesWanted );
|
||||
|
||||
AudioUnit GetAudioUnit() { return m_AudioUnit; }
|
||||
AudioConverterRef GetConverter() { return m_Converter; }
|
||||
void RenderBuffer( const short *pszBuf, int nSamples );
|
||||
bool BRecording() { return m_bRecordingAudio; }
|
||||
void ClearThreadHandle() { m_hThread = NULL; m_bFirstInit = false; }
|
||||
|
||||
AudioBufferList m_MicInputBuffer;
|
||||
AudioBufferList m_ConverterBuffer;
|
||||
void *m_pMicInputBuffer;
|
||||
|
||||
int m_nMicInputSamplesAvaialble;
|
||||
float m_flSampleRateConversion;
|
||||
int m_nBufferFrameSize;
|
||||
int m_ConverterBufferSize;
|
||||
int m_MicInputBufferSize;
|
||||
int m_InputBytesPerPacket;
|
||||
|
||||
private:
|
||||
bool InitalizeInterfaces(); // Initialize the openal capture buffers and other interfaces
|
||||
void ReleaseInterfaces(); // Release openal buffers and other interfaces
|
||||
void ClearInterfaces(); // Clear members.
|
||||
|
||||
|
||||
private:
|
||||
AudioUnit m_AudioUnit;
|
||||
char *m_SampleBuffer;
|
||||
int m_SampleBufferSize;
|
||||
int m_nSampleRate;
|
||||
bool m_bRecordingAudio;
|
||||
bool m_bFirstInit;
|
||||
ThreadHandle_t m_hThread;
|
||||
AudioConverterRef m_Converter;
|
||||
|
||||
CInterlockedUInt m_SampleBufferReadPos;
|
||||
CInterlockedUInt m_SampleBufferWritePos;
|
||||
|
||||
//UInt32 nPackets = 0;
|
||||
//bool bHaveListData = false;
|
||||
|
||||
|
||||
};
|
||||
|
||||
|
||||
VoiceRecord_AudioQueue::VoiceRecord_AudioQueue() :
|
||||
m_nSampleRate( 0 ), m_AudioUnit( NULL ), m_SampleBufferSize(0), m_SampleBuffer(NULL),
|
||||
m_SampleBufferReadPos(0), m_SampleBufferWritePos(0), m_bRecordingAudio(false), m_hThread( NULL ), m_bFirstInit( true )
|
||||
{
|
||||
ClearInterfaces();
|
||||
}
|
||||
|
||||
|
||||
VoiceRecord_AudioQueue::~VoiceRecord_AudioQueue()
|
||||
{
|
||||
ReleaseInterfaces();
|
||||
if ( m_hThread )
|
||||
ReleaseThreadHandle( m_hThread );
|
||||
m_hThread = NULL;
|
||||
}
|
||||
|
||||
|
||||
void VoiceRecord_AudioQueue::Release()
|
||||
{
|
||||
ReleaseInterfaces();
|
||||
}
|
||||
|
||||
uintp StartAudio( void *pRecorder )
|
||||
{
|
||||
VoiceRecord_AudioQueue *vr = (VoiceRecord_AudioQueue *)pRecorder;
|
||||
if ( vr )
|
||||
{
|
||||
//printf( "AudioOutputUnitStart\n" );
|
||||
AudioOutputUnitStart( vr->GetAudioUnit() );
|
||||
vr->ClearThreadHandle();
|
||||
}
|
||||
//printf( "StartAudio thread done\n" );
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
bool VoiceRecord_AudioQueue::RecordStart()
|
||||
{
|
||||
if ( !m_AudioUnit )
|
||||
return false;
|
||||
|
||||
if ( m_bFirstInit )
|
||||
m_hThread = CreateSimpleThread( StartAudio, this );
|
||||
else
|
||||
AudioOutputUnitStart( m_AudioUnit );
|
||||
|
||||
m_SampleBufferReadPos = m_SampleBufferWritePos = 0;
|
||||
|
||||
m_bRecordingAudio = true;
|
||||
//printf( "VoiceRecord_AudioQueue::RecordStart\n" );
|
||||
return ( !m_bFirstInit || m_hThread != NULL );
|
||||
}
|
||||
|
||||
|
||||
void VoiceRecord_AudioQueue::RecordStop()
|
||||
{
|
||||
// Stop capturing.
|
||||
if ( m_AudioUnit && m_bRecordingAudio )
|
||||
{
|
||||
AudioOutputUnitStop( m_AudioUnit );
|
||||
//printf( "AudioOutputUnitStop\n" );
|
||||
}
|
||||
|
||||
m_SampleBufferReadPos = m_SampleBufferWritePos = 0;
|
||||
m_bRecordingAudio = false;
|
||||
|
||||
if ( m_hThread )
|
||||
ReleaseThreadHandle( m_hThread );
|
||||
m_hThread = NULL;
|
||||
}
|
||||
|
||||
|
||||
|
||||
OSStatus ComplexBufferFillPlayback( AudioConverterRef inAudioConverter,
|
||||
UInt32 *ioNumberDataPackets,
|
||||
AudioBufferList *ioData,
|
||||
AudioStreamPacketDescription **outDataPacketDesc,
|
||||
void *inUserData)
|
||||
{
|
||||
VoiceRecord_AudioQueue *vr = (VoiceRecord_AudioQueue *)inUserData;
|
||||
if ( !vr->BRecording() )
|
||||
return noErr;
|
||||
|
||||
if ( vr->m_nMicInputSamplesAvaialble )
|
||||
{
|
||||
int nBytesRequired = *ioNumberDataPackets * vr->m_InputBytesPerPacket;
|
||||
int nBytesAvailable = vr->m_nMicInputSamplesAvaialble*vr->m_InputBytesPerPacket;
|
||||
|
||||
if ( nBytesRequired < nBytesAvailable )
|
||||
{
|
||||
ioData->mBuffers[0].mData = vr->m_MicInputBuffer.mBuffers[0].mData;
|
||||
ioData->mBuffers[0].mDataByteSize = nBytesRequired;
|
||||
vr->m_MicInputBuffer.mBuffers[0].mData = (char *)vr->m_MicInputBuffer.mBuffers[0].mData+nBytesRequired;
|
||||
vr->m_MicInputBuffer.mBuffers[0].mDataByteSize = nBytesAvailable - nBytesRequired;
|
||||
}
|
||||
else
|
||||
{
|
||||
ioData->mBuffers[0].mData = vr->m_MicInputBuffer.mBuffers[0].mData;
|
||||
ioData->mBuffers[0].mDataByteSize = nBytesAvailable;
|
||||
vr->m_MicInputBuffer.mBuffers[0].mData = vr->m_pMicInputBuffer;
|
||||
vr->m_MicInputBuffer.mBuffers[0].mDataByteSize = vr->m_MicInputBufferSize;
|
||||
}
|
||||
|
||||
*ioNumberDataPackets = ioData->mBuffers[0].mDataByteSize / vr->m_InputBytesPerPacket;
|
||||
vr->m_nMicInputSamplesAvaialble = nBytesAvailable / vr->m_InputBytesPerPacket - *ioNumberDataPackets;
|
||||
}
|
||||
else
|
||||
{
|
||||
*ioNumberDataPackets = 0;
|
||||
return -1;
|
||||
}
|
||||
|
||||
return noErr;
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
static OSStatus recordingCallback(void *inRefCon, AudioUnitRenderActionFlags *ioActionFlags, const AudioTimeStamp *inTimeStamp,
|
||||
UInt32 inBusNumber, UInt32 inNumberFrames, AudioBufferList *ioData)
|
||||
{
|
||||
VoiceRecord_AudioQueue *vr = (VoiceRecord_AudioQueue *)inRefCon;
|
||||
if ( !vr->BRecording() )
|
||||
return noErr;
|
||||
|
||||
OSStatus err = noErr;
|
||||
if ( vr->m_nMicInputSamplesAvaialble == 0 )
|
||||
{
|
||||
err = AudioUnitRender( vr->GetAudioUnit(), ioActionFlags, inTimeStamp, 1, inNumberFrames, &vr->m_MicInputBuffer );
|
||||
if ( err == noErr )
|
||||
vr->m_nMicInputSamplesAvaialble = vr->m_MicInputBuffer.mBuffers[0].mDataByteSize / vr->m_InputBytesPerPacket;
|
||||
}
|
||||
|
||||
if ( vr->m_nMicInputSamplesAvaialble > 0 )
|
||||
{
|
||||
UInt32 nConverterSamples = ceil(vr->m_nMicInputSamplesAvaialble/vr->m_flSampleRateConversion);
|
||||
vr->m_ConverterBuffer.mBuffers[0].mDataByteSize = vr->m_ConverterBufferSize;
|
||||
OSStatus err = AudioConverterFillComplexBuffer( vr->GetConverter(),
|
||||
ComplexBufferFillPlayback,
|
||||
vr,
|
||||
&nConverterSamples,
|
||||
&vr->m_ConverterBuffer,
|
||||
NULL );
|
||||
if ( err == noErr || err == -1 )
|
||||
vr->RenderBuffer( (short *)vr->m_ConverterBuffer.mBuffers[0].mData, vr->m_ConverterBuffer.mBuffers[0].mDataByteSize/sizeof(short) );
|
||||
}
|
||||
|
||||
return err;
|
||||
}
|
||||
|
||||
|
||||
void VoiceRecord_AudioQueue::RenderBuffer( const short *pszBuf, int nSamples )
|
||||
{
|
||||
int samplePos = m_SampleBufferWritePos;
|
||||
int samplePosBefore = samplePos;
|
||||
int readPos = m_SampleBufferReadPos;
|
||||
bool bBeforeRead = false;
|
||||
if ( samplePos < readPos )
|
||||
bBeforeRead = true;
|
||||
char *pOut = (char *)(m_SampleBuffer + samplePos);
|
||||
int nFirstCopy = MIN( nSamples*sizeof(short), m_SampleBufferSize - samplePos );
|
||||
memcpy( pOut, pszBuf, nFirstCopy );
|
||||
samplePos += nFirstCopy;
|
||||
if ( nSamples*sizeof(short) > nFirstCopy )
|
||||
{
|
||||
nSamples -= ( nFirstCopy / sizeof(short) );
|
||||
samplePos = 0;
|
||||
memcpy( m_SampleBuffer, pszBuf + nFirstCopy, nSamples * sizeof(short) );
|
||||
samplePos += nSamples * sizeof(short);
|
||||
}
|
||||
|
||||
m_SampleBufferWritePos = samplePos%m_SampleBufferSize;
|
||||
if ( (bBeforeRead && samplePos > readPos) )
|
||||
{
|
||||
m_SampleBufferReadPos = (readPos+m_SampleBufferSize/2)%m_SampleBufferSize; // if we crossed the read pointer then bump it forward
|
||||
//printf( "Crossed %d %d (%d)\n", (int)samplePosBefore, (int)samplePos, readPos );
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
bool VoiceRecord_AudioQueue::InitalizeInterfaces()
|
||||
{
|
||||
//printf( "Initializing audio queue recorder\n" );
|
||||
// Describe audio component
|
||||
ComponentDescription desc;
|
||||
desc.componentType = kAudioUnitType_Output;
|
||||
desc.componentSubType = kAudioUnitSubType_HALOutput;
|
||||
desc.componentManufacturer = kAudioUnitManufacturer_Apple;
|
||||
desc.componentFlags = 0;
|
||||
desc.componentFlagsMask = 0;
|
||||
|
||||
Component comp = FindNextComponent(NULL, &desc);
|
||||
if (comp == NULL)
|
||||
return false;
|
||||
|
||||
OSStatus status = OpenAComponent(comp, &m_AudioUnit);
|
||||
if ( status != noErr )
|
||||
return false;
|
||||
|
||||
// Enable IO for recording
|
||||
UInt32 flag = 1;
|
||||
status = AudioUnitSetProperty( m_AudioUnit, kAudioOutputUnitProperty_EnableIO, kAudioUnitScope_Input,
|
||||
1, &flag, sizeof(flag));
|
||||
if ( status != noErr )
|
||||
return false;
|
||||
|
||||
// disable output on the device
|
||||
flag = 0;
|
||||
status = AudioUnitSetProperty( m_AudioUnit,kAudioOutputUnitProperty_EnableIO, kAudioUnitScope_Output,
|
||||
0, &flag,sizeof(flag));
|
||||
if ( status != noErr )
|
||||
return false;
|
||||
|
||||
UInt32 size = sizeof(AudioDeviceID);
|
||||
AudioDeviceID inputDevice;
|
||||
status = AudioHardwareGetProperty(kAudioHardwarePropertyDefaultInputDevice,&size, &inputDevice);
|
||||
if ( status != noErr )
|
||||
return false;
|
||||
|
||||
status =AudioUnitSetProperty( m_AudioUnit, kAudioOutputUnitProperty_CurrentDevice, kAudioUnitScope_Global,
|
||||
0, &inputDevice, sizeof(inputDevice));
|
||||
if ( status != noErr )
|
||||
return false;
|
||||
|
||||
// Describe format
|
||||
AudioStreamBasicDescription audioDeviceFormat;
|
||||
size = sizeof(AudioStreamBasicDescription);
|
||||
status = AudioUnitGetProperty( m_AudioUnit,
|
||||
kAudioUnitProperty_StreamFormat,
|
||||
kAudioUnitScope_Input,
|
||||
1, // input bus
|
||||
&audioDeviceFormat,
|
||||
&size);
|
||||
|
||||
if ( status != noErr )
|
||||
return false;
|
||||
|
||||
// we only want mono audio, so if they have a stero input ask for mono
|
||||
if ( audioDeviceFormat.mChannelsPerFrame == 2 )
|
||||
{
|
||||
audioDeviceFormat.mChannelsPerFrame = 1;
|
||||
audioDeviceFormat.mBytesPerPacket /= 2;
|
||||
audioDeviceFormat.mBytesPerFrame /= 2;
|
||||
}
|
||||
|
||||
// Apply format
|
||||
status = AudioUnitSetProperty( m_AudioUnit, kAudioUnitProperty_StreamFormat, kAudioUnitScope_Output,
|
||||
1, &audioDeviceFormat, sizeof(audioDeviceFormat) );
|
||||
if ( status != noErr )
|
||||
return false;
|
||||
|
||||
AudioStreamBasicDescription audioOutputFormat;
|
||||
audioOutputFormat = audioDeviceFormat;
|
||||
audioOutputFormat.mFormatID = kAudioFormatLinearPCM;
|
||||
audioOutputFormat.mFormatFlags = kAudioFormatFlagIsSignedInteger | kAudioFormatFlagIsPacked;
|
||||
audioOutputFormat.mBytesPerPacket = 2; // 16-bit samples * 1 channels
|
||||
audioOutputFormat.mFramesPerPacket = 1;
|
||||
audioOutputFormat.mBytesPerFrame = 2; // 16-bit samples * 1 channels
|
||||
audioOutputFormat.mChannelsPerFrame = 1;
|
||||
audioOutputFormat.mBitsPerChannel = 16;
|
||||
audioOutputFormat.mReserved = 0;
|
||||
|
||||
audioOutputFormat.mSampleRate = m_nSampleRate;
|
||||
|
||||
m_flSampleRateConversion = audioDeviceFormat.mSampleRate / audioOutputFormat.mSampleRate;
|
||||
|
||||
// setup sample rate conversion
|
||||
status = AudioConverterNew( &audioDeviceFormat, &audioOutputFormat, &m_Converter );
|
||||
if ( status != noErr )
|
||||
return false;
|
||||
|
||||
|
||||
UInt32 primeMethod = kConverterPrimeMethod_None;
|
||||
status = AudioConverterSetProperty( m_Converter, kAudioConverterPrimeMethod, sizeof(UInt32), &primeMethod);
|
||||
if ( status != noErr )
|
||||
return false;
|
||||
|
||||
UInt32 quality = kAudioConverterQuality_Medium;
|
||||
status = AudioConverterSetProperty( m_Converter, kAudioConverterSampleRateConverterQuality, sizeof(UInt32), &quality);
|
||||
if ( status != noErr )
|
||||
return false;
|
||||
|
||||
// Set input callback
|
||||
AURenderCallbackStruct callbackStruct;
|
||||
callbackStruct.inputProc = recordingCallback;
|
||||
callbackStruct.inputProcRefCon = this;
|
||||
status = AudioUnitSetProperty( m_AudioUnit, kAudioOutputUnitProperty_SetInputCallback, kAudioUnitScope_Global,
|
||||
0, &callbackStruct, sizeof(callbackStruct) );
|
||||
if ( status != noErr )
|
||||
return false;
|
||||
|
||||
UInt32 bufferFrameSize;
|
||||
size = sizeof(bufferFrameSize);
|
||||
status = AudioDeviceGetProperty( inputDevice, 1, 1, kAudioDevicePropertyBufferFrameSize, &size, &bufferFrameSize );
|
||||
if ( status != noErr )
|
||||
return false;
|
||||
|
||||
m_nBufferFrameSize = bufferFrameSize;
|
||||
|
||||
// allocate the input and conversion sound storage buffers
|
||||
m_MicInputBuffer.mNumberBuffers = 1;
|
||||
m_MicInputBuffer.mBuffers[0].mDataByteSize = m_nBufferFrameSize*audioDeviceFormat.mBitsPerChannel/8*audioDeviceFormat.mChannelsPerFrame;
|
||||
m_MicInputBuffer.mBuffers[0].mData = malloc( m_MicInputBuffer.mBuffers[0].mDataByteSize );
|
||||
m_MicInputBuffer.mBuffers[0].mNumberChannels = audioDeviceFormat.mChannelsPerFrame;
|
||||
m_pMicInputBuffer = m_MicInputBuffer.mBuffers[0].mData;
|
||||
m_MicInputBufferSize = m_MicInputBuffer.mBuffers[0].mDataByteSize;
|
||||
|
||||
m_InputBytesPerPacket = audioDeviceFormat.mBytesPerPacket;
|
||||
|
||||
m_ConverterBuffer.mNumberBuffers = 1;
|
||||
m_ConverterBuffer.mBuffers[0].mDataByteSize = m_nBufferFrameSize*audioOutputFormat.mBitsPerChannel/8*audioOutputFormat.mChannelsPerFrame;
|
||||
m_ConverterBuffer.mBuffers[0].mData = malloc( m_MicInputBuffer.mBuffers[0].mDataByteSize );
|
||||
m_ConverterBuffer.mBuffers[0].mNumberChannels = 1;
|
||||
|
||||
m_ConverterBufferSize = m_ConverterBuffer.mBuffers[0].mDataByteSize;
|
||||
|
||||
m_nMicInputSamplesAvaialble = 0;
|
||||
|
||||
|
||||
m_SampleBufferReadPos = m_SampleBufferWritePos = 0;
|
||||
m_SampleBufferSize = ceil( kNumSecAudioBuffer * m_nSampleRate * audioOutputFormat.mBytesPerPacket );
|
||||
m_SampleBuffer = (char *)malloc( m_SampleBufferSize );
|
||||
memset( m_SampleBuffer, 0x0, m_SampleBufferSize );
|
||||
|
||||
DevMsg( "Initialized AudioQueue record interface\n" );
|
||||
return true;
|
||||
}
|
||||
|
||||
bool VoiceRecord_AudioQueue::Init( int nSampleRate )
|
||||
{
|
||||
if ( m_AudioUnit && m_nSampleRate != nSampleRate )
|
||||
{
|
||||
// Need to recreate interfaces with different sample rate
|
||||
ReleaseInterfaces();
|
||||
ClearInterfaces();
|
||||
}
|
||||
m_nSampleRate = nSampleRate;
|
||||
|
||||
// Re-initialize the capture buffer if neccesary
|
||||
if ( !m_AudioUnit )
|
||||
{
|
||||
InitalizeInterfaces();
|
||||
}
|
||||
|
||||
m_SampleBufferReadPos = m_SampleBufferWritePos = 0;
|
||||
|
||||
//printf( "VoiceRecord_AudioQueue::Init()\n" );
|
||||
// Initialise
|
||||
OSStatus status = AudioUnitInitialize( m_AudioUnit );
|
||||
if ( status != noErr )
|
||||
return false;
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
|
||||
void VoiceRecord_AudioQueue::ReleaseInterfaces()
|
||||
{
|
||||
AudioOutputUnitStop( m_AudioUnit );
|
||||
AudioConverterDispose( m_Converter );
|
||||
AudioUnitUninitialize( m_AudioUnit );
|
||||
m_AudioUnit = NULL;
|
||||
m_Converter = NULL;
|
||||
}
|
||||
|
||||
|
||||
void VoiceRecord_AudioQueue::ClearInterfaces()
|
||||
{
|
||||
m_AudioUnit = NULL;
|
||||
m_Converter = NULL;
|
||||
m_SampleBufferReadPos = m_SampleBufferWritePos = 0;
|
||||
if ( m_SampleBuffer )
|
||||
free( m_SampleBuffer );
|
||||
m_SampleBuffer = NULL;
|
||||
|
||||
if ( m_MicInputBuffer.mBuffers[0].mData )
|
||||
free( m_MicInputBuffer.mBuffers[0].mData );
|
||||
if ( m_ConverterBuffer.mBuffers[0].mData )
|
||||
free( m_ConverterBuffer.mBuffers[0].mData );
|
||||
m_MicInputBuffer.mBuffers[0].mData = NULL;
|
||||
m_ConverterBuffer.mBuffers[0].mData = NULL;
|
||||
}
|
||||
|
||||
|
||||
void VoiceRecord_AudioQueue::Idle()
|
||||
{
|
||||
}
|
||||
|
||||
|
||||
int VoiceRecord_AudioQueue::GetRecordedData(short *pOut, int nSamples )
|
||||
{
|
||||
if ( !m_SampleBuffer )
|
||||
return 0;
|
||||
|
||||
int cbSamples = nSamples*2; // convert to bytes
|
||||
int writePos = m_SampleBufferWritePos;
|
||||
int readPos = m_SampleBufferReadPos;
|
||||
|
||||
int nOutstandingSamples = ( writePos - readPos );
|
||||
if ( readPos > writePos ) // writing has wrapped around
|
||||
{
|
||||
nOutstandingSamples = writePos + ( m_SampleBufferSize - readPos );
|
||||
}
|
||||
|
||||
if ( !nOutstandingSamples )
|
||||
return 0;
|
||||
|
||||
if ( nOutstandingSamples < cbSamples )
|
||||
cbSamples = nOutstandingSamples; // clamp to the number of samples we have available
|
||||
|
||||
memcpy( (char *)pOut, m_SampleBuffer + readPos, MIN( cbSamples, m_SampleBufferSize - readPos ) );
|
||||
if ( cbSamples > ( m_SampleBufferSize - readPos ) )
|
||||
{
|
||||
int offset = m_SampleBufferSize - readPos;
|
||||
cbSamples -= offset;
|
||||
readPos = 0;
|
||||
memcpy( (char *)pOut + offset, m_SampleBuffer, cbSamples );
|
||||
}
|
||||
readPos+=cbSamples;
|
||||
m_SampleBufferReadPos = readPos%m_SampleBufferSize;
|
||||
//printf( "Returning %d samples, %d %d (%d)\n", cbSamples/2, (int)m_SampleBufferReadPos, (int)m_SampleBufferWritePos, m_SampleBufferSize );
|
||||
return cbSamples/2;
|
||||
}
|
||||
|
||||
|
||||
VoiceRecord_AudioQueue g_AudioQueueVoiceRecord;
|
||||
IVoiceRecord* CreateVoiceRecord_AudioQueue( int sampleRate )
|
||||
{
|
||||
if ( g_AudioQueueVoiceRecord.Init( sampleRate ) )
|
||||
{
|
||||
return &g_AudioQueueVoiceRecord;
|
||||
}
|
||||
else
|
||||
{
|
||||
g_AudioQueueVoiceRecord.Release();
|
||||
return NULL;
|
||||
}
|
||||
}
|
||||
@@ -873,9 +873,9 @@ bool IntersectRayWithBoxBrush( TraceInfo_t *pTraceInfo, const cbrush_t *pBrush,
|
||||
FPExceptionDisabler hideExceptions;
|
||||
|
||||
// Load the unaligned ray/box parameters into SIMD registers
|
||||
fltx4 start = LoadUnaligned3SIMD(pTraceInfo->m_start.Base());
|
||||
fltx4 extents = LoadUnaligned3SIMD(pTraceInfo->m_extents.Base());
|
||||
fltx4 delta = LoadUnaligned3SIMD(pTraceInfo->m_delta.Base());
|
||||
fltx4 start = LoadAlignedSIMD(pTraceInfo->m_start.Base());
|
||||
fltx4 extents = LoadAlignedSIMD(pTraceInfo->m_extents.Base());
|
||||
fltx4 delta = LoadAlignedSIMD(pTraceInfo->m_delta.Base());
|
||||
fltx4 boxMins = LoadAlignedSIMD( pBox->mins.Base() );
|
||||
fltx4 boxMaxs = LoadAlignedSIMD( pBox->maxs.Base() );
|
||||
|
||||
@@ -899,7 +899,7 @@ bool IntersectRayWithBoxBrush( TraceInfo_t *pTraceInfo, const cbrush_t *pBrush,
|
||||
|
||||
fltx4 crossPlane = OrSIMD(XorSIMD(startOutMins,endOutMins), XorSIMD(startOutMaxs,endOutMaxs));
|
||||
// now build the per-axis interval of t for intersections
|
||||
fltx4 invDelta = LoadUnaligned3SIMD(pTraceInfo->m_invDelta.Base());
|
||||
fltx4 invDelta = LoadAlignedSIMD(pTraceInfo->m_invDelta.Base());
|
||||
fltx4 tmins = MulSIMD( offsetMinsExpanded, invDelta );
|
||||
fltx4 tmaxs = MulSIMD( offsetMaxsExpanded, invDelta );
|
||||
// now sort the interval per axis
|
||||
@@ -1037,9 +1037,9 @@ bool IntersectRayWithBox( const Ray_t &ray, const VectorAligned &inInvDelta, con
|
||||
pTrace->fraction = 1.0f;
|
||||
|
||||
// Load the unaligned ray/box parameters into SIMD registers
|
||||
fltx4 start = LoadUnaligned3SIMD(ray.m_Start.Base());
|
||||
fltx4 extents = LoadUnaligned3SIMD(ray.m_Extents.Base());
|
||||
fltx4 delta = LoadUnaligned3SIMD(ray.m_Delta.Base());
|
||||
fltx4 start = LoadAlignedSIMD(ray.m_Start.Base());
|
||||
fltx4 extents = LoadAlignedSIMD(ray.m_Extents.Base());
|
||||
fltx4 delta = LoadAlignedSIMD(ray.m_Delta.Base());
|
||||
fltx4 boxMins = LoadAlignedSIMD( inBoxMins.Base() );
|
||||
fltx4 boxMaxs = LoadAlignedSIMD( inBoxMaxs.Base() );
|
||||
|
||||
@@ -1372,9 +1372,9 @@ void FASTCALL CM_ClipBoxToBrush( TraceInfo_t * RESTRICT pTraceInfo, const cbrush
|
||||
|
||||
inline bool IsTraceBoxIntersectingBoxBrush( TraceInfo_t *pTraceInfo, cboxbrush_t *pBox )
|
||||
{
|
||||
fltx4 start = LoadUnaligned3SIMD(pTraceInfo->m_start.Base());
|
||||
fltx4 mins = LoadUnaligned3SIMD(pTraceInfo->m_mins.Base());
|
||||
fltx4 maxs = LoadUnaligned3SIMD(pTraceInfo->m_maxs.Base());
|
||||
fltx4 start = LoadAlignedSIMD(pTraceInfo->m_start.Base());
|
||||
fltx4 mins = LoadAlignedSIMD(pTraceInfo->m_mins.Base());
|
||||
fltx4 maxs = LoadAlignedSIMD(pTraceInfo->m_maxs.Base());
|
||||
|
||||
fltx4 boxMins = LoadAlignedSIMD( pBox->mins.Base() );
|
||||
fltx4 boxMaxs = LoadAlignedSIMD( pBox->maxs.Base() );
|
||||
@@ -1569,15 +1569,15 @@ void FASTCALL CM_TraceToLeaf( TraceInfo_t * RESTRICT pTraceInfo, int ndxLeaf, fl
|
||||
if (IsX360())
|
||||
{
|
||||
// set up some relatively constant variables we'll use in the loop below
|
||||
fltx4 traceStart = LoadUnaligned3SIMD(pTraceInfo->m_start.Base());
|
||||
fltx4 traceDelta = LoadUnaligned3SIMD(pTraceInfo->m_delta.Base());
|
||||
fltx4 traceInvDelta = LoadUnaligned3SIMD(pTraceInfo->m_invDelta.Base());
|
||||
fltx4 traceStart = LoadAlignedSIMD(pTraceInfo->m_start.Base());
|
||||
fltx4 traceDelta = LoadAlignedSIMD(pTraceInfo->m_delta.Base());
|
||||
fltx4 traceInvDelta = LoadAlignedSIMD(pTraceInfo->m_invDelta.Base());
|
||||
static const fltx4 vecEpsilon = {DISPCOLL_DIST_EPSILON,DISPCOLL_DIST_EPSILON,DISPCOLL_DIST_EPSILON,DISPCOLL_DIST_EPSILON};
|
||||
// only used in !IS_POINT version:
|
||||
fltx4 extents;
|
||||
if (!IS_POINT)
|
||||
{
|
||||
extents = LoadUnaligned3SIMD(pTraceInfo->m_extents.Base());
|
||||
extents = LoadAlignedSIMD(pTraceInfo->m_extents.Base());
|
||||
}
|
||||
|
||||
// TODO: this loop probably ought to be unrolled so that we can make a more efficient
|
||||
|
||||
@@ -42,13 +42,13 @@ struct TraceInfo_t
|
||||
m_nCheckDepth = -1;
|
||||
}
|
||||
|
||||
Vector m_start;
|
||||
Vector m_end;
|
||||
Vector m_mins;
|
||||
Vector m_maxs;
|
||||
Vector m_extents;
|
||||
Vector m_delta;
|
||||
Vector m_invDelta;
|
||||
VectorAligned m_start;
|
||||
VectorAligned m_end;
|
||||
VectorAligned m_mins;
|
||||
VectorAligned m_maxs;
|
||||
VectorAligned m_extents;
|
||||
VectorAligned m_delta;
|
||||
VectorAligned m_invDelta;
|
||||
|
||||
trace_t m_trace;
|
||||
trace_t m_stabTrace;
|
||||
|
||||
@@ -4934,7 +4934,7 @@ static bool EnumerateLeafInBox_R(mnode_t * RESTRICT node, const EnumLeafBoxInfo_
|
||||
*/
|
||||
|
||||
// take advantage of high throughput/high latency
|
||||
fltx4 planeNormal = LoadUnaligned3SIMD( plane->normal.Base() );
|
||||
fltx4 planeNormal = LoadAlignedSIMD( plane->normal.Base() );
|
||||
fltx4 vecBoxMin = LoadAlignedSIMD(pInfo->m_vecBoxMin);
|
||||
fltx4 vecBoxMax = LoadAlignedSIMD(pInfo->m_vecBoxMax);
|
||||
fltx4 cornermin, cornermax;
|
||||
|
||||
@@ -987,7 +987,7 @@ private:
|
||||
int m_iTree;
|
||||
};
|
||||
|
||||
|
||||
/*
|
||||
class CIntersectPoint : public CPartitionVisitor
|
||||
{
|
||||
public:
|
||||
@@ -1009,7 +1009,7 @@ public:
|
||||
private:
|
||||
fltx4 m_f4Point;
|
||||
};
|
||||
|
||||
*/
|
||||
|
||||
class CIntersectBox : public CPartitionVisitor
|
||||
{
|
||||
@@ -1040,8 +1040,8 @@ class CIntersectRay : public CPartitionVisitor
|
||||
public:
|
||||
CIntersectRay( CVoxelTree *pPartition, const Ray_t &ray, const Vector &vecInvDelta ) : CPartitionVisitor( pPartition )
|
||||
{
|
||||
m_f4Start = LoadUnaligned3SIMD( ray.m_Start.Base() );
|
||||
m_f4Delta = LoadUnaligned3SIMD( ray.m_Delta.Base() );
|
||||
m_f4Start = LoadAlignedSIMD( ray.m_Start.Base() );
|
||||
m_f4Delta = LoadAlignedSIMD( ray.m_Delta.Base() );
|
||||
m_f4InvDelta = LoadUnaligned3SIMD( vecInvDelta.Base() );
|
||||
}
|
||||
|
||||
@@ -1069,10 +1069,10 @@ class CIntersectSweptBox : public CPartitionVisitor
|
||||
public:
|
||||
CIntersectSweptBox( CVoxelTree *pPartition, const Ray_t &ray, const Vector &vecInvDelta ) : CPartitionVisitor( pPartition )
|
||||
{
|
||||
m_f4Start = LoadUnaligned3SIMD( ray.m_Start.Base() );
|
||||
m_f4Delta = LoadUnaligned3SIMD( ray.m_Delta.Base() );
|
||||
m_f4Start = LoadAlignedSIMD( ray.m_Start.Base() );
|
||||
m_f4Delta = LoadAlignedSIMD( ray.m_Delta.Base() );
|
||||
m_f4Extents = LoadAlignedSIMD( ray.m_Extents.Base() );
|
||||
m_f4InvDelta = LoadUnaligned3SIMD( vecInvDelta.Base() );
|
||||
m_f4Extents = LoadUnaligned3SIMD( ray.m_Extents.Base() );
|
||||
}
|
||||
|
||||
bool Intersects( const float *pMins, const float *pMaxs ) const
|
||||
|
||||
@@ -1339,7 +1339,6 @@ void CStaticPropMgr::UnserializeModels( CUtlBuffer& buf )
|
||||
case 5: UnserializeLump<StaticPropLumpV5_t>(&lump, buf); break;
|
||||
case 6: UnserializeLump<StaticPropLumpV6_t>(&lump, buf); break;
|
||||
case 7: // Falls down to version 10. We promoted TF to version 10 to deal with SFM.
|
||||
case 9: UnserializeLump<StaticPropLumpV9_t>(&lump, buf); break;
|
||||
case 10:
|
||||
{
|
||||
if( s_MapVersion == 21 )
|
||||
@@ -1348,7 +1347,8 @@ void CStaticPropMgr::UnserializeModels( CUtlBuffer& buf )
|
||||
UnserializeLump<StaticPropLumpV10_t>(&lump, buf);
|
||||
break;
|
||||
}
|
||||
case 11: UnserializeLump<StaticPropLumpV11_t>(&lump, buf);
|
||||
case 9: UnserializeLump<StaticPropLumpV9_t>(&lump, buf); break;
|
||||
case 11: UnserializeLump<StaticPropLumpV11_t>(&lump, buf); break;
|
||||
default:
|
||||
Assert("Unexpected version while deserializing lumps.");
|
||||
}
|
||||
|
||||
@@ -263,7 +263,6 @@ GameMessageHandler_t g_GameMessageHandlers[] =
|
||||
{ IE_Quit, &CGame::HandleMsg_Close },
|
||||
};
|
||||
|
||||
|
||||
void CGame::AppActivate( bool fActive )
|
||||
{
|
||||
// If text mode, force it to be active.
|
||||
@@ -299,8 +298,18 @@ void CGame::AppActivate( bool fActive )
|
||||
// Clear keyboard states (should be cleared already but...)
|
||||
// VGui_ActivateMouse will reactivate the mouse soon.
|
||||
ClearIOStates();
|
||||
|
||||
UpdateMaterialSystemConfig();
|
||||
|
||||
#ifdef ANDROID
|
||||
ConVarRef mat_queue_mode( "mat_queue_mode" );
|
||||
|
||||
// Hack to reset internal queue buffers
|
||||
int nSavedQueueMode = mat_queue_mode.GetInt();
|
||||
mat_queue_mode.SetValue( 0 );
|
||||
materials->BeginFrame( host_frametime );
|
||||
materials->EndFrame();
|
||||
mat_queue_mode.SetValue( nSavedQueueMode );
|
||||
#endif
|
||||
}
|
||||
else
|
||||
{
|
||||
@@ -355,7 +364,7 @@ void CGame::HandleMsg_Close( const InputEvent_t &event )
|
||||
|
||||
void CGame::DispatchInputEvent( const InputEvent_t &event )
|
||||
{
|
||||
switch( event.m_nType & 0xFFFF )
|
||||
switch( event.m_nType )
|
||||
{
|
||||
// Handle button events specially,
|
||||
// since we have all manner of crazy filtering going on when dealing with them
|
||||
|
||||
@@ -341,7 +341,8 @@ def build(bld):
|
||||
if bld.env.DEST_OS == 'darwin':
|
||||
source += [
|
||||
'audio/snd_dev_openal.cpp', # [$OSXALL]
|
||||
'audio/snd_dev_mac_audioqueue.cpp', # [$OSXALL]
|
||||
'audio/snd_dev_mac_audioqueue.cpp',# [$OSXALL]
|
||||
'audio/voice_record_mac_audioqueue.cpp', #[$OSXALL]
|
||||
]
|
||||
|
||||
includes = [
|
||||
|
||||
@@ -729,7 +729,7 @@ public:
|
||||
void PrecacheMaterial( const char *pMaterialName );
|
||||
|
||||
virtual bool IsConnectedUserInfoChangeAllowed( IConVar *pCvar );
|
||||
virtual void IN_TouchEvent( uint data, uint data2, uint data3, uint data4 );
|
||||
virtual void IN_TouchEvent( int type, int fingerId, int x, int y );
|
||||
|
||||
private:
|
||||
void UncacheAllMaterials( );
|
||||
@@ -1631,6 +1631,7 @@ void CHLClient::LevelInitPreEntity( char const* pMapName )
|
||||
g_RagdollLVManager.SetLowViolence( pMapName );
|
||||
|
||||
gHUD.LevelInit();
|
||||
gTouch.LevelInit();
|
||||
|
||||
#if defined( REPLAY_ENABLED )
|
||||
// Initialize replay ragdoll recorder
|
||||
@@ -2637,24 +2638,20 @@ CSteamID GetSteamIDForPlayerIndex( int iPlayerIndex )
|
||||
#endif
|
||||
|
||||
|
||||
void CHLClient::IN_TouchEvent( uint data, uint data2, uint data3, uint data4 )
|
||||
void CHLClient::IN_TouchEvent( int type, int fingerId, int x, int y )
|
||||
{
|
||||
if( enginevgui->IsGameUIVisible() )
|
||||
return;
|
||||
|
||||
touch_event_t ev;
|
||||
|
||||
ev.type = data & 0xFFFF;
|
||||
ev.fingerid = (data >> 16) & 0xFFFF;
|
||||
ev.x = (double)((data2 >> 16) & 0xFFFF) / 0xFFFF;
|
||||
ev.y = (double)(data2 & 0xFFFF) / 0xFFFF;
|
||||
ev.type = type;
|
||||
ev.fingerid = fingerId;
|
||||
memcpy( &ev.x, &x, sizeof(ev.x) );
|
||||
memcpy( &ev.y, &y, sizeof(ev.y) );
|
||||
|
||||
union{uint i;float f;} ifconv;
|
||||
ifconv.i = data3;
|
||||
ev.dx = ifconv.f;
|
||||
|
||||
ifconv.i = data4;
|
||||
ev.dy = ifconv.f;
|
||||
if( type == IE_FingerMotion )
|
||||
inputsystem->GetTouchAccumulators( fingerId, ev.dx, ev.dy );
|
||||
|
||||
gTouch.ProcessEvent( &ev );
|
||||
}
|
||||
|
||||
@@ -72,7 +72,7 @@ DECLARE_HUDELEMENT( CHudHealth );
|
||||
//-----------------------------------------------------------------------------
|
||||
// Purpose: Constructor
|
||||
//-----------------------------------------------------------------------------
|
||||
CHudHealth::CHudHealth( const char *pElementName ) : CHudElement( pElementName ), CHudNumericDisplay(NULL, "HudHealth")
|
||||
CHudHealth::CHudHealth( const char *pElementName ) : CHudElement( pElementName ), CHudNumericDisplay(NULL, "HudHealth"), m_pHealthIcon( NULL )
|
||||
{
|
||||
SetHiddenBits( HIDEHUD_HEALTH | HIDEHUD_PLAYERDEAD );
|
||||
}
|
||||
@@ -172,4 +172,4 @@ void CHudHealth::Paint( void )
|
||||
|
||||
//draw the health icon
|
||||
BaseClass::Paint();
|
||||
}
|
||||
}
|
||||
|
||||
@@ -152,13 +152,13 @@ void CCSViewRender::PerformNightVisionEffect( const CViewSetup &view )
|
||||
render->ViewDrawFade( overlaycolor, pMaterial );
|
||||
|
||||
// Only one pass in DX7.
|
||||
if ( g_pMaterialSystemHardwareConfig->GetDXSupportLevel() >= 80 )
|
||||
/* if ( g_pMaterialSystemHardwareConfig->GetDXSupportLevel() >= 80 )
|
||||
{
|
||||
CMatRenderContextPtr pRenderContext( materials );
|
||||
pRenderContext->DrawScreenSpaceQuad( pMaterial );
|
||||
render->ViewDrawFade( overlaycolor, pMaterial );
|
||||
pRenderContext->DrawScreenSpaceQuad( pMaterial );
|
||||
}
|
||||
}*/
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -211,6 +211,7 @@ void CCSViewRender::PerformFlashbangEffect( const CViewSetup &view )
|
||||
render->ViewDrawFade( overlaycolor, pMaterial );
|
||||
|
||||
// just do one pass for dxlevel < 80.
|
||||
/*
|
||||
if (g_pMaterialSystemHardwareConfig->GetDXSupportLevel() >= 80)
|
||||
{
|
||||
pRenderContext->DrawScreenSpaceRectangle( pMaterial, view.x, view.y, view.width, view.height,
|
||||
@@ -221,6 +222,7 @@ void CCSViewRender::PerformFlashbangEffect( const CViewSetup &view )
|
||||
0, 0, m_pFlashTexture->GetActualWidth()-1, m_pFlashTexture->GetActualHeight()-1,
|
||||
m_pFlashTexture->GetActualWidth(), m_pFlashTexture->GetActualHeight() );
|
||||
}
|
||||
*/
|
||||
}
|
||||
else if ( m_pFlashTexture )
|
||||
{
|
||||
@@ -233,7 +235,7 @@ void CCSViewRender::PerformFlashbangEffect( const CViewSetup &view )
|
||||
render->ViewDrawFade( overlaycolor, pMaterial );
|
||||
|
||||
// just do one pass for dxlevel < 80.
|
||||
if (g_pMaterialSystemHardwareConfig->GetDXSupportLevel() >= 80)
|
||||
/* if (g_pMaterialSystemHardwareConfig->GetDXSupportLevel() >= 80)
|
||||
{
|
||||
pRenderContext->DrawScreenSpaceRectangle( pMaterial, view.x, view.y, view.width, view.height,
|
||||
0, 0, m_pFlashTexture->GetActualWidth()-1, m_pFlashTexture->GetActualHeight()-1,
|
||||
@@ -242,7 +244,7 @@ void CCSViewRender::PerformFlashbangEffect( const CViewSetup &view )
|
||||
pRenderContext->DrawScreenSpaceRectangle( pMaterial, view.x, view.y, view.width, view.height,
|
||||
0, 0, m_pFlashTexture->GetActualWidth()-1, m_pFlashTexture->GetActualHeight()-1,
|
||||
m_pFlashTexture->GetActualWidth(), m_pFlashTexture->GetActualHeight() );
|
||||
}
|
||||
}*/
|
||||
}
|
||||
|
||||
// this does the pure white overlay part of the flashbang effect.
|
||||
|
||||
@@ -47,7 +47,7 @@ private:
|
||||
DECLARE_HUDELEMENT( CHudArmor );
|
||||
|
||||
|
||||
CHudArmor::CHudArmor( const char *pName ) : CHudNumericDisplay( NULL, "HudArmor" ), CHudElement( pName )
|
||||
CHudArmor::CHudArmor( const char *pName ) : CHudNumericDisplay( NULL, "HudArmor" ), CHudElement( pName ), m_pArmorIcon( NULL )
|
||||
{
|
||||
SetHiddenBits( HIDEHUD_HEALTH | HIDEHUD_PLAYERDEAD );
|
||||
}
|
||||
|
||||
@@ -313,7 +313,7 @@ void CTouchControls::ResetToDefaults()
|
||||
{
|
||||
rgba_t color(255, 255, 255, 155);
|
||||
char buf[MAX_PATH];
|
||||
gridcolor = rgba_t(255, 0, 0, 50);
|
||||
gridcolor = rgba_t(255, 0, 0, 30);
|
||||
|
||||
RemoveButtons();
|
||||
|
||||
@@ -372,7 +372,7 @@ void CTouchControls::Init()
|
||||
mouse_events = 0;
|
||||
move_start_x = move_start_y = 0.0f;
|
||||
m_flPreviousYaw = m_flPreviousPitch = 0.f;
|
||||
gridcolor = rgba_t(255, 0, 0, 50);
|
||||
gridcolor = rgba_t(255, 0, 0, 30);
|
||||
|
||||
m_bCutScene = false;
|
||||
showtexture = hidetexture = resettexture = closetexture = joytexture = 0;
|
||||
@@ -425,6 +425,13 @@ void CTouchControls::Init()
|
||||
initialized = true;
|
||||
}
|
||||
|
||||
void CTouchControls::LevelInit()
|
||||
{
|
||||
m_bCutScene = false;
|
||||
m_AlphaDiff = 0;
|
||||
m_flHideTouch = 0;
|
||||
}
|
||||
|
||||
int nextPowerOfTwo(int x)
|
||||
{
|
||||
if( (x & (x - 1)) == 0)
|
||||
@@ -652,6 +659,8 @@ void CTouchControls::Paint()
|
||||
|
||||
CUtlLinkedList<CTouchButton*>::iterator it;
|
||||
|
||||
const rgba_t buttonEditClr = rgba_t( 61, 153, 0, 40 );
|
||||
|
||||
if( state == state_edit )
|
||||
{
|
||||
vgui::surface()->DrawSetColor(gridcolor.r, gridcolor.g, gridcolor.b, gridcolor.a*3); // 255, 0, 0, 200 <- default here
|
||||
@@ -678,7 +687,7 @@ void CTouchControls::Paint()
|
||||
g_pMatSystemSurface->DrawColoredText( 2, btn->x1*screen_w, btn->y1*screen_h+40, 255, 255, 255, 255, "RGBA: %d %d %d %d", btn->color.r, btn->color.g, btn->color.b, btn->color.a );// color
|
||||
}
|
||||
|
||||
vgui::surface()->DrawSetColor(gridcolor.r, gridcolor.g, gridcolor.b, gridcolor.a); // 255, 0, 0, 50 <- default here
|
||||
vgui::surface()->DrawSetColor(buttonEditClr.r, buttonEditClr.g, buttonEditClr.b, buttonEditClr.a); // 255, 0, 0, 50 <- default here
|
||||
vgui::surface()->DrawFilledRect( btn->x1*screen_w, btn->y1*screen_h, btn->x2*screen_w, btn->y2*screen_h );
|
||||
}
|
||||
}
|
||||
|
||||
@@ -161,6 +161,7 @@ class CTouchControls
|
||||
{
|
||||
public:
|
||||
void Init( );
|
||||
void LevelInit( );
|
||||
void Shutdown( );
|
||||
|
||||
void Paint( );
|
||||
|
||||
@@ -28,7 +28,7 @@ extern bool g_bMovementOptimizations;
|
||||
|
||||
ConVar sv_timebetweenducks( "sv_timebetweenducks", "0", FCVAR_REPLICATED, "Minimum time before recognizing consecutive duck key", true, 0.0, true, 2.0 );
|
||||
ConVar sv_enableboost( "sv_enableboost", "0", FCVAR_REPLICATED | FCVAR_NOTIFY, "Allow boost exploits");
|
||||
|
||||
ConVar cs_autojump( "cs_autojump", "0", FCVAR_REPLICATED | FCVAR_NOTIFY );
|
||||
|
||||
class CCSGameMovement : public CGameMovement
|
||||
{
|
||||
@@ -691,8 +691,11 @@ bool CCSGameMovement::CheckJumpButton( void )
|
||||
return false; // in air, so no effect
|
||||
}
|
||||
|
||||
if ( mv->m_nOldButtons & IN_JUMP )
|
||||
if ( (mv->m_nOldButtons & IN_JUMP) &&
|
||||
(!cs_autojump.GetBool() && m_pCSPlayer->GetGroundEntity()) )
|
||||
{
|
||||
return false; // don't pogo stick
|
||||
}
|
||||
|
||||
if ( !sv_enablebunnyhopping.GetBool() )
|
||||
{
|
||||
|
||||
@@ -1151,12 +1151,14 @@ ConVarRef suitcharger( "sk_suitcharger" );
|
||||
|
||||
void StripChar(char *szBuffer, const char cWhiteSpace )
|
||||
{
|
||||
char *src, *dst;
|
||||
|
||||
while ( char *pSpace = strchr( szBuffer, cWhiteSpace ) )
|
||||
for (src = dst = szBuffer; *src != '\0'; src++)
|
||||
{
|
||||
char *pNextChar = pSpace + sizeof(char);
|
||||
V_strcpy( pSpace, pNextChar );
|
||||
*dst = *src;
|
||||
if (*dst != cWhiteSpace) dst++;
|
||||
}
|
||||
*dst = '\0';
|
||||
}
|
||||
|
||||
void CMultiplayRules::GetNextLevelName( char *pszNextMap, int bufsize, bool bRandom /* = false */ )
|
||||
|
||||
@@ -1530,16 +1530,6 @@ bool CInputSystem::GetRawMouseAccumulators( int& accumX, int& accumY )
|
||||
#endif
|
||||
}
|
||||
|
||||
bool CInputSystem::GetTouchAccumulators( InputEventType_t &event, int &fingerId, int& accumX, int& accumY )
|
||||
{
|
||||
event = m_touchAccumEvent;
|
||||
fingerId = m_touchAccumFingerId;
|
||||
accumX = m_touchAccumX;
|
||||
accumY = m_touchAccumY;
|
||||
|
||||
return m_bJoystickInitialized;
|
||||
}
|
||||
|
||||
void CInputSystem::SetConsoleTextMode( bool bConsoleTextMode )
|
||||
{
|
||||
/* If someone calls this after init, shut it down. */
|
||||
|
||||
@@ -44,6 +44,8 @@
|
||||
|
||||
#include "steam/steam_api.h"
|
||||
|
||||
#define TOUCH_FINGER_MAX_COUNT 10
|
||||
|
||||
//-----------------------------------------------------------------------------
|
||||
// Implementation of the input system
|
||||
//-----------------------------------------------------------------------------
|
||||
@@ -101,7 +103,7 @@ public:
|
||||
virtual void *GetHapticsInterfaceAddress() const { return NULL;}
|
||||
#endif
|
||||
bool GetRawMouseAccumulators( int& accumX, int& accumY );
|
||||
bool GetTouchAccumulators( InputEventType_t &event, int &fingerId, int& accumX, int& accumY );
|
||||
virtual bool GetTouchAccumulators( int fingerId, float &dx, float &dy );
|
||||
|
||||
virtual void SetConsoleTextMode( bool bConsoleTextMode );
|
||||
|
||||
@@ -458,8 +460,7 @@ public:
|
||||
bool m_bRawInputSupported;
|
||||
int m_mouseRawAccumX, m_mouseRawAccumY;
|
||||
|
||||
InputEventType_t m_touchAccumEvent;
|
||||
int m_touchAccumFingerId, m_touchAccumX, m_touchAccumY;
|
||||
float m_touchAccumX[TOUCH_FINGER_MAX_COUNT], m_touchAccumY[TOUCH_FINGER_MAX_COUNT];
|
||||
|
||||
// For the 'SleepUntilInput' feature
|
||||
HANDLE m_hEvent;
|
||||
|
||||
@@ -48,6 +48,9 @@ void CInputSystem::InitializeTouch( void )
|
||||
// abort startup if user requests no touch
|
||||
if ( CommandLine()->FindParm("-notouch") ) return;
|
||||
|
||||
memset( m_touchAccumX, 0, sizeof(m_touchAccumX) );
|
||||
memset( m_touchAccumY, 0, sizeof(m_touchAccumY) );
|
||||
|
||||
m_bJoystickInitialized = true;
|
||||
SDL_AddEventWatch(TouchSDLWatcher, this);
|
||||
}
|
||||
@@ -61,20 +64,35 @@ void CInputSystem::ShutdownTouch()
|
||||
m_bTouchInitialized = false;
|
||||
}
|
||||
|
||||
bool CInputSystem::GetTouchAccumulators( int fingerId, float &dx, float &dy )
|
||||
{
|
||||
dx = m_touchAccumX[fingerId];
|
||||
dy = m_touchAccumY[fingerId];
|
||||
|
||||
m_touchAccumX[fingerId] = m_touchAccumY[fingerId] = 0.f;
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
void CInputSystem::FingerEvent(int eventType, int fingerId, float x, float y, float dx, float dy)
|
||||
{
|
||||
// Shit, but should work with arm/x86
|
||||
if( fingerId >= TOUCH_FINGER_MAX_COUNT )
|
||||
return;
|
||||
|
||||
int data0 = fingerId << 16 | eventType;
|
||||
int _x = (int)((double)x*0xFFFF);
|
||||
int _y = (int)((double)y*0xFFFF);
|
||||
int data1 = _x << 16 | (_y & 0xFFFF);
|
||||
if( eventType == IE_FingerUp )
|
||||
{
|
||||
m_touchAccumX[fingerId] = 0.f;
|
||||
m_touchAccumY[fingerId] = 0.f;
|
||||
}
|
||||
else
|
||||
{
|
||||
m_touchAccumX[fingerId] += dx;
|
||||
m_touchAccumY[fingerId] += dy;
|
||||
}
|
||||
|
||||
union{int i;float f;} ifconv;
|
||||
ifconv.f = dx;
|
||||
int _dx = ifconv.i;
|
||||
ifconv.f = dy;
|
||||
int _dy = ifconv.i;
|
||||
|
||||
PostEvent(data0, m_nLastSampleTick, data1, _dx, _dy);
|
||||
int _x,_y;
|
||||
memcpy( &_x, &x, sizeof(float) );
|
||||
memcpy( &_y, &y, sizeof(float) );
|
||||
PostEvent(eventType, m_nLastSampleTick, fingerId, _x, _y);
|
||||
}
|
||||
|
||||
|
||||
@@ -501,6 +501,7 @@ public:
|
||||
DELEGATE_TO_OBJECT_0( bool, OnFlushBufferedPrimitives, GetRenderContextInternal() );
|
||||
void OnThreadEvent( uint32 threadEvent );
|
||||
ShaderAPITextureHandle_t GetShaderAPITextureBindHandle( ITexture *pTexture, int nFrame, int nTextureChannel ); // JasonM ????
|
||||
uint32_t GetShaderAPIGLTexture( ITexture *pTexture, int nFrame, int nTextureChannel ); // fuck
|
||||
|
||||
|
||||
|
||||
|
||||
53
materialsystem/gltexturehack.cpp
Normal file
53
materialsystem/gltexturehack.cpp
Normal file
@@ -0,0 +1,53 @@
|
||||
#include "pch_materialsystem.h"
|
||||
#include "togl/rendermechanism.h"
|
||||
|
||||
#define MATSYS_INTERNAL
|
||||
|
||||
#include "cmaterialsystem.h"
|
||||
//-----------------------------------------------------------------------------
|
||||
// The Base implementation of the shader rendering interface
|
||||
//-----------------------------------------------------------------------------
|
||||
class CShaderAPIBase : public IShaderAPI
|
||||
{
|
||||
public:
|
||||
// constructor, destructor
|
||||
CShaderAPIBase();
|
||||
virtual ~CShaderAPIBase();
|
||||
|
||||
// Called when the device is initializing or shutting down
|
||||
virtual bool OnDeviceInit() = 0;
|
||||
virtual void OnDeviceShutdown() = 0;
|
||||
|
||||
// Pix events
|
||||
virtual void BeginPIXEvent( unsigned long color, const char *szName ) = 0;
|
||||
virtual void EndPIXEvent() = 0;
|
||||
virtual void AdvancePIXFrame() = 0;
|
||||
|
||||
// Release, reacquire objects
|
||||
virtual void ReleaseShaderObjects() = 0;
|
||||
virtual void RestoreShaderObjects() = 0;
|
||||
|
||||
// Resets the render state to its well defined initial value
|
||||
virtual void ResetRenderState( bool bFullReset = true ) = 0;
|
||||
|
||||
// Returns a d3d texture associated with a texture handle
|
||||
virtual IDirect3DBaseTexture9* GetD3DTexture( ShaderAPITextureHandle_t hTexture ) = 0;
|
||||
|
||||
// Queues a non-full reset of render state next BeginFrame.
|
||||
virtual void QueueResetRenderState() = 0;
|
||||
|
||||
// Methods of IShaderDynamicAPI
|
||||
public:
|
||||
virtual void GetCurrentColorCorrection( ShaderColorCorrectionInfo_t* pInfo );
|
||||
|
||||
protected:
|
||||
};
|
||||
|
||||
uint32_t CMaterialSystem::GetShaderAPIGLTexture( ITexture *pTexture, int nFrame, int nTextureChannel )
|
||||
{
|
||||
ShaderAPITextureHandle_t handle = ShaderSystem()->GetShaderAPITextureBindHandle( pTexture, nFrame, nTextureChannel );
|
||||
IDirect3DTexture9* pTex = ((CShaderAPIBase*)g_pShaderAPI)->GetD3DTexture(handle);
|
||||
IDirect3DSurface9* surf = pTex->m_surfZero;
|
||||
CGLMTex *tex = surf->m_tex;
|
||||
return tex->GetTexName();
|
||||
}
|
||||
@@ -2276,7 +2276,7 @@ public:
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
virtual uint32_t GetShaderAPIGLTexture(ITexture*, int, int) {return 0;}
|
||||
};
|
||||
|
||||
|
||||
|
||||
@@ -45,6 +45,7 @@ def build(bld):
|
||||
'cmatrendercontext.cpp',
|
||||
'cmatqueuedrendercontext.cpp',
|
||||
'ctexturecompositor.cpp',
|
||||
'gltexturehack.cpp',
|
||||
'../public/tier0/memoverride.cpp'
|
||||
]
|
||||
|
||||
|
||||
@@ -790,7 +790,7 @@ public:
|
||||
|
||||
virtual bool IsConnectedUserInfoChangeAllowed( IConVar *pCvar ) = 0;
|
||||
|
||||
virtual void IN_TouchEvent( uint data, uint data2, uint data3, uint data4 ) = 0;
|
||||
virtual void IN_TouchEvent( int type, int fingerId, int x, int y ) = 0;
|
||||
};
|
||||
|
||||
#define CLIENT_DLL_INTERFACE_VERSION "VClient017"
|
||||
|
||||
@@ -119,6 +119,7 @@ public:
|
||||
|
||||
// read and clear accumulated raw input values
|
||||
virtual bool GetRawMouseAccumulators( int& accumX, int& accumY ) = 0;
|
||||
virtual bool GetTouchAccumulators( int fingerId, float &dx, float &dy ) = 0;
|
||||
|
||||
// tell the input system that we're not a game, we're console text mode.
|
||||
// this is used for dedicated servers to not initialize joystick system.
|
||||
|
||||
@@ -1093,6 +1093,7 @@ public:
|
||||
|
||||
// Performs final verification of all compositor templates (after they've all been initially loaded).
|
||||
virtual bool VerifyTextureCompositorTemplates( ) = 0;
|
||||
virtual uint32_t GetShaderAPIGLTexture( ITexture *pTexture, int nFrame, int nTextureChannel ) = 0;
|
||||
};
|
||||
|
||||
|
||||
|
||||
@@ -114,7 +114,7 @@ inline T clamp( T const &val, T const &minVal, T const &maxVal )
|
||||
// FIXME: this should move to a different file
|
||||
struct cplane_t
|
||||
{
|
||||
Vector normal;
|
||||
VectorAligned normal;
|
||||
float dist;
|
||||
byte type; // for fast side tests
|
||||
byte signbits; // signx + (signy<<1) + (signz<<1)
|
||||
|
||||
File diff suppressed because it is too large
Load Diff
@@ -1,130 +0,0 @@
|
||||
//====== Copyright (c) 1996-2014, Valve Corporation, All rights reserved. =======
|
||||
//
|
||||
// Purpose: Header for flatted SteamAPI. Use this for binding to other languages.
|
||||
// This file is auto-generated, do not edit it.
|
||||
//
|
||||
//=============================================================================
|
||||
|
||||
#ifndef __OPENVR_API_FLAT_H__
|
||||
#define __OPENVR_API_FLAT_H__
|
||||
#ifdef _WIN32
|
||||
#pragma once
|
||||
#endif
|
||||
|
||||
// OPENVR API export macro
|
||||
#if defined( _WIN32 ) && !defined( _X360 )
|
||||
#if defined( OPENVR_API_EXPORTS )
|
||||
#define S_API extern "C" __declspec( dllexport )
|
||||
#elif defined( OPENVR_API_NODLL )
|
||||
#define S_API extern "C"
|
||||
#else
|
||||
#define S_API extern "C" __declspec( dllimport )
|
||||
#endif // OPENVR_API_EXPORTS
|
||||
#elif defined( GNUC )
|
||||
#if defined( OPENVR_API_EXPORTS )
|
||||
#define S_API extern "C" __attribute__ ((visibility("default")))
|
||||
#else
|
||||
#define S_API extern "C"
|
||||
#endif // OPENVR_API_EXPORTS
|
||||
#else // !WIN32
|
||||
#if defined( OPENVR_API_EXPORTS )
|
||||
#define S_API extern "C"
|
||||
#else
|
||||
#define S_API extern "C"
|
||||
#endif // OPENVR_API_EXPORTS
|
||||
#endif
|
||||
|
||||
|
||||
#include <stdint.h>
|
||||
#include "openvr.h"
|
||||
#include "ivrsystem.h"
|
||||
#include "ivrcameraaccess.h"
|
||||
#include "ivrchaperone.h"
|
||||
#include "ivrchaperonesetup.h"
|
||||
#include "ivrcompositor.h"
|
||||
|
||||
|
||||
S_API void VR_IVRSystem_GetWindowBounds(intptr_t instancePtr, int32_t * pnX, int32_t * pnY, uint32_t * pnWidth, uint32_t * pnHeight);
|
||||
S_API void VR_IVRSystem_GetRecommendedRenderTargetSize(intptr_t instancePtr, uint32_t * pnWidth, uint32_t * pnHeight);
|
||||
S_API void VR_IVRSystem_GetEyeOutputViewport(intptr_t instancePtr, vr::Hmd_Eye eEye, uint32_t * pnX, uint32_t * pnY, uint32_t * pnWidth, uint32_t * pnHeight);
|
||||
S_API struct vr::HmdMatrix44_t VR_IVRSystem_GetProjectionMatrix(intptr_t instancePtr, vr::Hmd_Eye eEye, float fNearZ, float fFarZ, vr::GraphicsAPIConvention eProjType);
|
||||
S_API void VR_IVRSystem_GetProjectionRaw(intptr_t instancePtr, vr::Hmd_Eye eEye, float * pfLeft, float * pfRight, float * pfTop, float * pfBottom);
|
||||
S_API struct vr::DistortionCoordinates_t VR_IVRSystem_ComputeDistortion(intptr_t instancePtr, vr::Hmd_Eye eEye, float fU, float fV);
|
||||
S_API struct vr::HmdMatrix34_t VR_IVRSystem_GetEyeToHeadTransform(intptr_t instancePtr, vr::Hmd_Eye eEye);
|
||||
S_API bool VR_IVRSystem_GetTimeSinceLastVsync(intptr_t instancePtr, float * pfSecondsSinceLastVsync, uint64_t * pulFrameCounter);
|
||||
S_API int32_t VR_IVRSystem_GetD3D9AdapterIndex(intptr_t instancePtr);
|
||||
S_API void VR_IVRSystem_GetDXGIOutputInfo(intptr_t instancePtr, int32_t * pnAdapterIndex, int32_t * pnAdapterOutputIndex);
|
||||
S_API bool VR_IVRSystem_AttachToWindow(intptr_t instancePtr, void * hWnd);
|
||||
S_API void VR_IVRSystem_GetDeviceToAbsoluteTrackingPose(intptr_t instancePtr, vr::TrackingUniverseOrigin eOrigin, float fPredictedSecondsToPhotonsFromNow, struct vr::TrackedDevicePose_t * pTrackedDevicePoseArray, uint32_t unTrackedDevicePoseArrayCount);
|
||||
S_API void VR_IVRSystem_ResetSeatedZeroPose(intptr_t instancePtr);
|
||||
S_API struct vr::HmdMatrix34_t VR_IVRSystem_GetSeatedZeroPoseToStandingAbsoluteTrackingPose(intptr_t instancePtr);
|
||||
S_API bool VR_IVRSystem_LoadRenderModel(intptr_t instancePtr, const char * pchRenderModelName, struct vr::RenderModel_t * pRenderModel);
|
||||
S_API void VR_IVRSystem_FreeRenderModel(intptr_t instancePtr, struct vr::RenderModel_t * pRenderModel);
|
||||
S_API vr::TrackedDeviceClass VR_IVRSystem_GetTrackedDeviceClass(intptr_t instancePtr, vr::TrackedDeviceIndex_t unDeviceIndex);
|
||||
S_API bool VR_IVRSystem_IsTrackedDeviceConnected(intptr_t instancePtr, vr::TrackedDeviceIndex_t unDeviceIndex);
|
||||
S_API bool VR_IVRSystem_GetBoolTrackedDeviceProperty(intptr_t instancePtr, vr::TrackedDeviceIndex_t unDeviceIndex, vr::TrackedDeviceProperty prop, vr::TrackedPropertyError * pError);
|
||||
S_API float VR_IVRSystem_GetFloatTrackedDeviceProperty(intptr_t instancePtr, vr::TrackedDeviceIndex_t unDeviceIndex, vr::TrackedDeviceProperty prop, vr::TrackedPropertyError * pError);
|
||||
S_API int32_t VR_IVRSystem_GetInt32TrackedDeviceProperty(intptr_t instancePtr, vr::TrackedDeviceIndex_t unDeviceIndex, vr::TrackedDeviceProperty prop, vr::TrackedPropertyError * pError);
|
||||
S_API uint64_t VR_IVRSystem_GetUint64TrackedDeviceProperty(intptr_t instancePtr, vr::TrackedDeviceIndex_t unDeviceIndex, vr::TrackedDeviceProperty prop, vr::TrackedPropertyError * pError);
|
||||
S_API struct vr::HmdMatrix34_t VR_IVRSystem_GetMatrix34TrackedDeviceProperty(intptr_t instancePtr, vr::TrackedDeviceIndex_t unDeviceIndex, vr::TrackedDeviceProperty prop, vr::TrackedPropertyError * pError);
|
||||
S_API uint32_t VR_IVRSystem_GetStringTrackedDeviceProperty(intptr_t instancePtr, vr::TrackedDeviceIndex_t unDeviceIndex, vr::TrackedDeviceProperty prop, char * pchValue, uint32_t unBufferSize, vr::TrackedPropertyError * pError);
|
||||
S_API const char * VR_IVRSystem_GetPropErrorNameFromEnum(intptr_t instancePtr, vr::TrackedPropertyError error);
|
||||
S_API bool VR_IVRSystem_PollNextEvent(intptr_t instancePtr, struct vr::VREvent_t * pEvent);
|
||||
S_API bool VR_IVRSystem_PollNextEventWithPose(intptr_t instancePtr, vr::TrackingUniverseOrigin eOrigin, vr::VREvent_t * pEvent, vr::TrackedDevicePose_t * pTrackedDevicePose);
|
||||
S_API const char * VR_IVRSystem_GetEventTypeNameFromEnum(intptr_t instancePtr, vr::EVREventType eType);
|
||||
S_API struct vr::HiddenAreaMesh_t VR_IVRSystem_GetHiddenAreaMesh(intptr_t instancePtr, vr::Hmd_Eye eEye);
|
||||
S_API bool VR_IVRSystem_GetControllerState(intptr_t instancePtr, vr::TrackedDeviceIndex_t unControllerDeviceIndex, vr::VRControllerState_t * pControllerState);
|
||||
S_API bool VR_IVRSystem_GetControllerStateWithPose(intptr_t instancePtr, vr::TrackingUniverseOrigin eOrigin, vr::TrackedDeviceIndex_t unControllerDeviceIndex, vr::VRControllerState_t * pControllerState, struct vr::TrackedDevicePose_t * pTrackedDevicePose);
|
||||
S_API void VR_IVRSystem_TriggerHapticPulse(intptr_t instancePtr, vr::TrackedDeviceIndex_t unControllerDeviceIndex, uint32_t unAxisId, unsigned short usDurationMicroSec);
|
||||
S_API const char * VR_IVRSystem_GetButtonIdNameFromEnum(intptr_t instancePtr, vr::EVRButtonId eButtonId);
|
||||
S_API const char * VR_IVRSystem_GetControllerAxisTypeNameFromEnum(intptr_t instancePtr, vr::EVRControllerAxisType eAxisType);
|
||||
S_API bool VR_IVRSystem_HandleControllerOverlayInteractionAsMouse(intptr_t instancePtr, const vr::Compositor_OverlaySettings & overlaySettings, vr::HmdVector2_t vecWindowClientPositionOnScreen, vr::HmdVector2_t vecWindowClientSize, vr::TrackedDeviceIndex_t unControllerDeviceIndex, vr::EVRControllerEventOutputType eOutputType);
|
||||
S_API bool VR_IVRSystem_CaptureInputFocus(intptr_t instancePtr);
|
||||
S_API void VR_IVRSystem_ReleaseInputFocus(intptr_t instancePtr);
|
||||
S_API bool VR_IVRSystem_IsInputFocusCapturedByAnotherProcess(intptr_t instancePtr);
|
||||
S_API uint32_t VR_IVRCameraAccess_GetCameraCount(intptr_t instancePtr);
|
||||
S_API uint32_t VR_IVRCameraAccess_GetCameraId(intptr_t instancePtr, uint32_t unCameraIndex, char * pchBuffer, uint32_t unBufferLen);
|
||||
S_API bool VR_IVRCameraAccess_EnableCamera(intptr_t instancePtr, uint32_t unCameraIndex, bool bEnabled);
|
||||
S_API bool VR_IVRCameraAccess_GetCameraInfo(intptr_t instancePtr, uint32_t unCameraIndex, struct vr::CameraInfo_t * pCameraInfo);
|
||||
S_API bool VR_IVRCameraAccess_GetCameraImage(intptr_t instancePtr, uint32_t unCameraIndex, struct vr::CameraImage_t * pCameraImage);
|
||||
S_API vr::ChaperoneCalibrationState VR_IVRChaperone_GetCalibrationState(intptr_t instancePtr);
|
||||
S_API bool VR_IVRChaperone_GetSoftBoundsInfo(intptr_t instancePtr, struct vr::ChaperoneSoftBoundsInfo_t * pInfo);
|
||||
S_API bool VR_IVRChaperone_GetHardBoundsInfo(intptr_t instancePtr, struct vr::HmdQuad_t * pQuadsBuffer, uint32_t * punQuadsCount);
|
||||
S_API bool VR_IVRChaperone_GetSeatedBoundsInfo(intptr_t instancePtr, struct vr::ChaperoneSeatedBoundsInfo_t * pInfo);
|
||||
S_API bool VR_IVRChaperoneSetup_CommitWorkingCopy(intptr_t instancePtr, const char * pchCalibrationName);
|
||||
S_API void VR_IVRChaperoneSetup_RevertWorkingCopy(intptr_t instancePtr);
|
||||
S_API bool VR_IVRChaperoneSetup_GetWorkingSoftBoundsInfo(intptr_t instancePtr, struct vr::ChaperoneSoftBoundsInfo_t * pInfo);
|
||||
S_API bool VR_IVRChaperoneSetup_GetWorkingHardBoundsInfo(intptr_t instancePtr, struct vr::HmdQuad_t * pQuadsBuffer, uint32_t * punQuadsCount);
|
||||
S_API bool VR_IVRChaperoneSetup_GetWorkingSeatedZeroPoseToRawTrackingPose(intptr_t instancePtr, struct vr::HmdMatrix34_t * pmatSeatedZeroPoseToRawTrackingPose);
|
||||
S_API bool VR_IVRChaperoneSetup_GetWorkingStandingZeroPoseToRawTrackingPose(intptr_t instancePtr, struct vr::HmdMatrix34_t * pmatStandingZeroPoseToRawTrackingPose);
|
||||
S_API void VR_IVRChaperoneSetup_SetWorkingSoftBoundsInfo(intptr_t instancePtr, const struct vr::ChaperoneSoftBoundsInfo_t * pInfo);
|
||||
S_API void VR_IVRChaperoneSetup_SetWorkingHardBoundsInfo(intptr_t instancePtr, struct vr::HmdQuad_t * pQuadsBuffer, uint32_t unQuadsCount);
|
||||
S_API void VR_IVRChaperoneSetup_SetWorkingSeatedZeroPoseToRawTrackingPose(intptr_t instancePtr, const struct vr::HmdMatrix34_t & matSeatedZeroPoseToRawTrackingPose);
|
||||
S_API void VR_IVRChaperoneSetup_SetWorkingStandingZeroPoseToRawTrackingPose(intptr_t instancePtr, const struct vr::HmdMatrix34_t & matStandingZeroPoseToRawTrackingPose);
|
||||
S_API uint32_t VR_IVRCompositor_GetLastError(intptr_t instancePtr, char * pchBuffer, uint32_t unBufferSize);
|
||||
S_API void VR_IVRCompositor_SetVSync(intptr_t instancePtr, bool bVSync);
|
||||
S_API bool VR_IVRCompositor_GetVSync(intptr_t instancePtr);
|
||||
S_API void VR_IVRCompositor_SetGamma(intptr_t instancePtr, float fGamma);
|
||||
S_API float VR_IVRCompositor_GetGamma(intptr_t instancePtr);
|
||||
S_API void VR_IVRCompositor_SetGraphicsDevice(intptr_t instancePtr, vr::Compositor_DeviceType eType, void * pDevice);
|
||||
S_API void VR_IVRCompositor_WaitGetPoses(intptr_t instancePtr, struct vr::TrackedDevicePose_t * pPoseArray, uint32_t unPoseArrayCount);
|
||||
S_API void VR_IVRCompositor_Submit(intptr_t instancePtr, vr::Hmd_Eye eEye, void * pTexture, struct vr::Compositor_TextureBounds * pBounds);
|
||||
S_API void VR_IVRCompositor_ClearLastSubmittedFrame(intptr_t instancePtr);
|
||||
S_API void VR_IVRCompositor_GetOverlayDefaults(intptr_t instancePtr, struct vr::Compositor_OverlaySettings * pSettings);
|
||||
S_API void VR_IVRCompositor_SetOverlay(intptr_t instancePtr, void * pTexture, struct vr::Compositor_OverlaySettings * pSettings);
|
||||
S_API void VR_IVRCompositor_SetOverlayRaw(intptr_t instancePtr, void * buffer, uint32_t width, uint32_t height, uint32_t depth, struct vr::Compositor_OverlaySettings * pSettings);
|
||||
S_API void VR_IVRCompositor_SetOverlayFromFile(intptr_t instancePtr, const char * pchFilePath, struct vr::Compositor_OverlaySettings * pSettings);
|
||||
S_API void VR_IVRCompositor_ClearOverlay(intptr_t instancePtr);
|
||||
S_API bool VR_IVRCompositor_GetFrameTiming(intptr_t instancePtr, struct vr::Compositor_FrameTiming * pTiming, uint32_t unFramesAgo);
|
||||
S_API void VR_IVRCompositor_FadeToColor(intptr_t instancePtr, float fSeconds, float fRed, float fGreen, float fBlue, float fAlpha, bool bBackground);
|
||||
S_API void VR_IVRCompositor_FadeGrid(intptr_t instancePtr, float fSeconds, bool bFadeIn);
|
||||
S_API void VR_IVRCompositor_CompositorBringToFront(intptr_t instancePtr);
|
||||
S_API void VR_IVRCompositor_CompositorGoToBack(intptr_t instancePtr);
|
||||
S_API void VR_IVRCompositor_CompositorQuit(intptr_t instancePtr);
|
||||
S_API bool VR_IVRCompositor_IsFullscreen(intptr_t instancePtr);
|
||||
S_API bool VR_IVRCompositor_ComputeOverlayIntersection(intptr_t instancePtr, const struct vr::Compositor_OverlaySettings * pSettings, float fAspectRatio, vr::TrackingUniverseOrigin eOrigin, vr::HmdVector3_t vSource, vr::HmdVector3_t vDirection, vr::HmdVector2_t * pvecIntersectionUV, vr::HmdVector3_t * pvecIntersectionTrackingSpace);
|
||||
S_API void VR_IVRCompositor_SetTrackingSpace(intptr_t instancePtr, vr::TrackingUniverseOrigin eOrigin);
|
||||
S_API vr::TrackingUniverseOrigin VR_IVRCompositor_GetTrackingSpace(intptr_t instancePtr);
|
||||
#endif // __OPENVR_API_FLAT_H__
|
||||
|
||||
|
||||
@@ -455,7 +455,9 @@ bool GetVTFPreload360Data( const char *pDebugName, CUtlBuffer &fileBufferIn, CUt
|
||||
// compiler pads, the 360 compiler does NOT.
|
||||
//-----------------------------------------------------------------------------
|
||||
|
||||
struct VTFFileBaseHeader_t
|
||||
// nillerusr: try to avoid problems with pragma pack, remove c++ inheritance to make this structs platform-independent
|
||||
|
||||
struct alignas(16) VTFFileBaseHeader_t
|
||||
{
|
||||
DECLARE_BYTESWAP_DATADESC();
|
||||
char fileTypeString[4]; // "VTF" Valve texture file
|
||||
@@ -463,22 +465,23 @@ struct VTFFileBaseHeader_t
|
||||
int headerSize;
|
||||
};
|
||||
|
||||
struct VTFFileHeaderV7_1_t : public VTFFileBaseHeader_t
|
||||
struct alignas(16) VTFFileHeaderV7_1_t
|
||||
{
|
||||
DECLARE_BYTESWAP_DATADESC();
|
||||
char fileTypeString[4]; // "VTF" Valve texture file
|
||||
int version[2]; // version[0].version[1]
|
||||
int headerSize;
|
||||
|
||||
unsigned short width;
|
||||
unsigned short height;
|
||||
unsigned int flags;
|
||||
unsigned short numFrames;
|
||||
unsigned short startFrame;
|
||||
#if !defined( POSIX ) && !defined( _X360 )
|
||||
VectorAligned reflectivity;
|
||||
#else
|
||||
|
||||
// must manually align in order to maintain pack(1) expected layout with existing binaries
|
||||
char pad1[4];
|
||||
Vector reflectivity;
|
||||
char pad2[4];
|
||||
#endif
|
||||
char pad1[4];
|
||||
VectorAligned reflectivity;
|
||||
|
||||
float bumpScale;
|
||||
ImageFormat imageFormat;
|
||||
unsigned char numMipLevels;
|
||||
@@ -487,13 +490,65 @@ struct VTFFileHeaderV7_1_t : public VTFFileBaseHeader_t
|
||||
unsigned char lowResImageHeight;
|
||||
};
|
||||
|
||||
struct VTFFileHeaderV7_2_t : public VTFFileHeaderV7_1_t
|
||||
struct alignas(16) VTFFileHeaderV7_2_t
|
||||
{
|
||||
DECLARE_BYTESWAP_DATADESC();
|
||||
|
||||
char fileTypeString[4]; // "VTF" Valve texture file
|
||||
int version[2]; // version[0].version[1]
|
||||
int headerSize;
|
||||
|
||||
unsigned short width;
|
||||
unsigned short height;
|
||||
unsigned int flags;
|
||||
unsigned short numFrames;
|
||||
unsigned short startFrame;
|
||||
|
||||
// must manually align in order to maintain pack(1) expected layout with existing binaries
|
||||
char pad1[4];
|
||||
VectorAligned reflectivity;
|
||||
|
||||
float bumpScale;
|
||||
ImageFormat imageFormat;
|
||||
unsigned char numMipLevels;
|
||||
ImageFormat lowResImageFormat;
|
||||
unsigned char lowResImageWidth;
|
||||
unsigned char lowResImageHeight;
|
||||
unsigned short depth;
|
||||
};
|
||||
|
||||
struct alignas(16) VTFFileHeaderV7_3_t
|
||||
{
|
||||
DECLARE_BYTESWAP_DATADESC();
|
||||
|
||||
char fileTypeString[4]; // "VTF" Valve texture file
|
||||
int version[2]; // version[0].version[1]
|
||||
int headerSize;
|
||||
|
||||
unsigned short width;
|
||||
unsigned short height;
|
||||
unsigned int flags;
|
||||
unsigned short numFrames;
|
||||
unsigned short startFrame;
|
||||
|
||||
// must manually align in order to maintain pack(1) expected layout with existing binaries
|
||||
char pad1[4];
|
||||
VectorAligned reflectivity;
|
||||
|
||||
float bumpScale;
|
||||
ImageFormat imageFormat;
|
||||
unsigned char numMipLevels;
|
||||
ImageFormat lowResImageFormat;
|
||||
unsigned char lowResImageWidth;
|
||||
unsigned char lowResImageHeight;
|
||||
unsigned short depth;
|
||||
|
||||
char pad4[3];
|
||||
unsigned int numResources;
|
||||
};
|
||||
|
||||
typedef VTFFileHeaderV7_3_t VTFFileHeader_t;
|
||||
|
||||
#define BYTE_POS( byteVal, shft ) uint32( uint32(uint8(byteVal)) << uint8(shft * 8) )
|
||||
#if !defined( _X360 )
|
||||
#define MK_VTF_RSRC_ID(a, b, c) uint32( BYTE_POS(a, 0) | BYTE_POS(b, 1) | BYTE_POS(c, 2) )
|
||||
@@ -538,28 +593,6 @@ struct ResourceEntryInfo
|
||||
unsigned int resData; // Resource data or offset from the beginning of the file
|
||||
};
|
||||
|
||||
struct VTFFileHeaderV7_3_t : public VTFFileHeaderV7_2_t
|
||||
{
|
||||
DECLARE_BYTESWAP_DATADESC();
|
||||
|
||||
char pad4[3];
|
||||
unsigned int numResources;
|
||||
|
||||
#if defined( _X360 ) || defined( POSIX )
|
||||
// must manually align in order to maintain pack(1) expected layout with existing binaries
|
||||
char pad5[8];
|
||||
#endif
|
||||
|
||||
// AFTER THE IMPLICIT PADDING CAUSED BY THE COMPILER....
|
||||
// *** followed by *** ResourceEntryInfo resources[0];
|
||||
// Array of resource entry infos sorted ascending by type
|
||||
};
|
||||
|
||||
struct VTFFileHeader_t : public VTFFileHeaderV7_3_t
|
||||
{
|
||||
DECLARE_BYTESWAP_DATADESC();
|
||||
};
|
||||
|
||||
#define VTF_X360_MAJOR_VERSION 0x0360
|
||||
#define VTF_X360_MINOR_VERSION 8
|
||||
struct VTFFileHeaderX360_t : public VTFFileBaseHeader_t
|
||||
|
||||
@@ -80,7 +80,7 @@ CSourceVirtualReality::CSourceVirtualReality()
|
||||
m_textureGeneratorRight( vr::Eye_Right )
|
||||
{
|
||||
m_bActive = false;
|
||||
m_bUsingOffscreenRenderTarget = false;
|
||||
m_bUsingOffscreenRenderTarget = true;
|
||||
m_pHmd = NULL;
|
||||
}
|
||||
|
||||
@@ -207,7 +207,11 @@ void CDistortionTextureRegen::RegenerateTextureBits( ITexture *pTexture, IVTFTex
|
||||
float u = ( (float)x + 0.5f) / fWidth;
|
||||
float v = ( (float)y + 0.5f) / fHeight;
|
||||
|
||||
DistortionCoordinates_t coords = g_SourceVirtualReality.GetHmd()->ComputeDistortion( m_eEye, u, v );
|
||||
DistortionCoordinates_t coords;
|
||||
if(!g_SourceVirtualReality.GetHmd()->ComputeDistortion( m_eEye, u, v, &coords ))
|
||||
{
|
||||
Warning("ComputeDistortion failed");
|
||||
}
|
||||
|
||||
coords.rfRed[0] = Clamp( coords.rfRed[0], 0.f, 1.f ) * fUScale + fUOffset;
|
||||
coords.rfGreen[0] = Clamp( coords.rfGreen[0], 0.f, 1.f ) * fUScale + fUOffset;
|
||||
@@ -277,9 +281,9 @@ bool CSourceVirtualReality::GetDisplayBounds( VRRect_t *pRect )
|
||||
{
|
||||
if( m_pHmd )
|
||||
{
|
||||
int32_t x, y;
|
||||
uint32_t width, height;
|
||||
m_pHmd->GetWindowBounds( &x, &y, &width, &height );
|
||||
int32_t x = 0, y = 0;
|
||||
uint32_t width = 1024, height = 1024;
|
||||
m_pExtDisplay->GetWindowBounds( &x, &y, &width, &height );
|
||||
pRect->nX = x;
|
||||
pRect->nY = y;
|
||||
pRect->nWidth = width;
|
||||
@@ -420,8 +424,9 @@ void CSourceVirtualReality::GetViewportBounds( VREye eEye, int *pnX, int *pnY, i
|
||||
}
|
||||
else
|
||||
{
|
||||
uint32_t x, y, w, h;
|
||||
m_pHmd->GetEyeOutputViewport( SourceEyeToHmdEye( eEye ), &x, &y, &w, &h );
|
||||
uint32_t x = 0, y = 0, w = 640, h = 480;
|
||||
// m_pHmd->GetEyeOutputViewport( SourceEyeToHmdEye( eEye ), &x, &y, &w, &h );
|
||||
m_pExtDisplay->GetEyeOutputViewport( SourceEyeToHmdEye( eEye ), &x, &y, &w, &h );
|
||||
if( pnX && pnY )
|
||||
{
|
||||
*pnX = x;
|
||||
@@ -446,14 +451,14 @@ VMatrix CSourceVirtualReality::GetMideyePose()
|
||||
// ----------------------------------------------------------------------
|
||||
inline static void ComposeProjectionTransform(float fLeft, float fRight, float fTop, float fBottom, float zNear, float zFar, float fovScale, VMatrix *pmProj )
|
||||
{
|
||||
if( fovScale != 1.0f && fovScale > 0.f )
|
||||
/*if( fovScale != 1.0f && fovScale > 0.f )
|
||||
{
|
||||
float fFovScaleAdjusted = tan( atan( fTop ) / fovScale ) / fTop;
|
||||
fRight *= fFovScaleAdjusted;
|
||||
fLeft *= fFovScaleAdjusted;
|
||||
fTop *= fFovScaleAdjusted;
|
||||
fBottom *= fFovScaleAdjusted;
|
||||
}
|
||||
}*/
|
||||
|
||||
float idx = 1.0f / (fRight - fLeft);
|
||||
float idy = 1.0f / (fBottom - fTop);
|
||||
@@ -530,15 +535,21 @@ bool CSourceVirtualReality::WillDriftInYaw()
|
||||
void CSourceVirtualReality::AcquireNewZeroPose()
|
||||
{
|
||||
// just let the next tracker update re-zero us
|
||||
if( m_pHmd )
|
||||
m_pHmd->ResetSeatedZeroPose();
|
||||
if( m_pChap )
|
||||
m_pChap->ResetZeroPose(TrackingUniverseSeated);
|
||||
}
|
||||
|
||||
bool CSourceVirtualReality::SampleTrackingState ( float PlayerGameFov, float fPredictionSeconds )
|
||||
{
|
||||
if( !m_pHmd || !m_bActive )
|
||||
return false;
|
||||
|
||||
vr::VREvent_t event;
|
||||
while( m_pHmd->PollNextEvent( &event, sizeof( event ) ) )
|
||||
{
|
||||
//ProcessVREvent( event );
|
||||
}
|
||||
vr::TrackedDevicePose_t m_rTrackedDevicePose[ vr::k_unMaxTrackedDeviceCount ];
|
||||
vr::VRCompositor()->WaitGetPoses(m_rTrackedDevicePose, vr::k_unMaxTrackedDeviceCount, NULL, 0 );
|
||||
// If tracker can't return a pose (it's possibly recalibrating itself)
|
||||
// then we will freeze tracking at its current state, rather than
|
||||
// snapping it back to the zero position
|
||||
@@ -572,6 +583,7 @@ bool CSourceVirtualReality::SampleTrackingState ( float PlayerGameFov, float fPr
|
||||
|
||||
return true;
|
||||
}
|
||||
#include "togl/rendermechanism.h"
|
||||
|
||||
|
||||
// ----------------------------------------------------------------------
|
||||
@@ -589,10 +601,16 @@ bool CSourceVirtualReality::DoDistortionProcessing ( VREye eEye )
|
||||
CMatRenderContextPtr pRenderContext( materials );
|
||||
|
||||
IMaterial *pDistortMaterial;
|
||||
ITexture *pDistortTexture;
|
||||
|
||||
if( eEye == VREye_Left )
|
||||
pDistortMaterial = m_DistortLeftMaterial;
|
||||
else
|
||||
pDistortMaterial = m_DistortRightMaterial;
|
||||
if( eEye == VREye_Left )
|
||||
pDistortTexture = m_pDistortionTextureLeft;
|
||||
else
|
||||
pDistortTexture = m_pDistortionTextureRight;
|
||||
|
||||
if( !UsingOffscreenRenderTarget() )
|
||||
{
|
||||
@@ -602,17 +620,48 @@ bool CSourceVirtualReality::DoDistortionProcessing ( VREye eEye )
|
||||
return false;
|
||||
|
||||
Rect_t r;
|
||||
r.x = !eEye?0:640;
|
||||
r.y = 0;
|
||||
r.width = 640;
|
||||
r.height = 480;
|
||||
this->GetViewportBounds( eEye, &r.x, &r.y, &r.width, &r.height );
|
||||
pRenderContext->CopyRenderTargetToTextureEx( pFullFrameFB1, 0, &r, &r );
|
||||
}
|
||||
|
||||
// This is where we are rendering to
|
||||
uint32_t x, y, w, h;
|
||||
m_pHmd->GetEyeOutputViewport( SourceEyeToHmdEye( eEye ), &x, &y, &w, &h );
|
||||
x = !eEye?0:640;
|
||||
y = 0;
|
||||
w = 640;
|
||||
h = 480;
|
||||
//m_pExtDisplay->GetEyeOutputViewport( SourceEyeToHmdEye( eEye ), &x, &y, &w, &h );
|
||||
|
||||
pRenderContext->DrawScreenSpaceRectangle ( pDistortMaterial,
|
||||
x, y, w, h,
|
||||
0, 0, distortionTextureSize-1,distortionTextureSize-1,distortionTextureSize,distortionTextureSize);
|
||||
// pRenderContext->DrawScreenSpaceRectangle ( pDistortMaterial,
|
||||
// x, y, w, h,
|
||||
// 0, 0, distortionTextureSize-1,distortionTextureSize-1,distortionTextureSize,distortionTextureSize);
|
||||
|
||||
static int id = -1;
|
||||
//static CDynamicFunctionOpenGL< true, GLvoid ( APIENTRY *)(GLenum pname, GLint *params), GLvoid > glGetIntegerv("glGetIntegerv");
|
||||
// pRenderContext->Bind(pDistortMaterial);
|
||||
// pRenderContext->Flush( true );
|
||||
// ShaderAPITextureHandle_t hndl = materials->GetShaderAPITextureBindHandle(pDistortTexture,0,0);
|
||||
//if(id < 0)
|
||||
id = materials->GetShaderAPIGLTexture(m_pPredistortRT,0,0);
|
||||
|
||||
static int last_tex[2] = {-1, -1};
|
||||
// glGetIntegerv(GL_TEXTURE_BINDING_2D, &id);
|
||||
if(id > 0)
|
||||
last_tex[eEye != VREye_Left] = id;
|
||||
// Msg("tex %d\n", id);
|
||||
const vr::VRTextureBounds_t bounds = { 0.0f, 1.0f, 1.0f, 0.0f };
|
||||
vr::Texture_t eyeTexture = {(void*)(uintptr_t)last_tex[eEye != VREye_Left], vr::TextureType_OpenGL, vr::ColorSpace_Gamma };
|
||||
if(last_tex[eEye != VREye_Left] <= 0)
|
||||
return true;
|
||||
materials->Flush();
|
||||
// if(eEye != VREye_Left)
|
||||
// return 0;
|
||||
glFinish();
|
||||
vr::VRCompositor()->Submit(SourceEyeToHmdEye( eEye ), &eyeTexture, &bounds );
|
||||
|
||||
return true;
|
||||
}
|
||||
@@ -682,11 +731,20 @@ bool CSourceVirtualReality::CompositeHud ( VREye eEye, float ndcHudBounds[4], bo
|
||||
CMatRenderContextPtr pRenderContext( materials );
|
||||
|
||||
uint32_t x, y, w, h;
|
||||
m_pHmd->GetEyeOutputViewport( SourceEyeToHmdEye( eEye ), &x, &y, &w, &h );
|
||||
x = !eEye?0:640;
|
||||
y = 0;
|
||||
w = 640;
|
||||
h = 480;
|
||||
m_pExtDisplay->GetEyeOutputViewport( SourceEyeToHmdEye( eEye ), &x, &y, &w, &h );
|
||||
int id = materials->GetShaderAPIGLTexture(g_StereoGuiTexture,0,0);
|
||||
vr::Texture_t guiTexture = {(void*)(uintptr_t)id, vr::TextureType_OpenGL, vr::ColorSpace_Gamma };
|
||||
const vr::VRTextureBounds_t bounds = { 0.0f, 1.0f, 1.0f, 0.0f };
|
||||
vr::VROverlay()->SetOverlayTextureBounds(m_GuiOverlay, &bounds);
|
||||
vr::VROverlay()->SetOverlayTexture(m_GuiOverlay, &guiTexture);
|
||||
|
||||
pRenderContext->DrawScreenSpaceRectangle ( pDistortHUDMaterial,
|
||||
x, y, w, h,
|
||||
0, 0, distortionTextureSize-1,distortionTextureSize-1,distortionTextureSize,distortionTextureSize);
|
||||
// pRenderContext->DrawScreenSpaceRectangle ( pDistortHUDMaterial,
|
||||
// x, y, w, h,
|
||||
// 0, 0, distortionTextureSize-1,distortionTextureSize-1,distortionTextureSize,distortionTextureSize);
|
||||
|
||||
return true;
|
||||
}
|
||||
@@ -706,14 +764,22 @@ bool CSourceVirtualReality::StartTracker()
|
||||
|
||||
// Initialize SteamVR
|
||||
vr::HmdError err;
|
||||
m_pHmd = vr::VR_Init( &err );
|
||||
if( err != HmdError_None )
|
||||
m_pHmd = vr::VR_Init( &err, vr::VRApplication_Scene );
|
||||
m_pExtDisplay = vr::VRExtendedDisplay();
|
||||
m_pChap = vr::VRChaperone();
|
||||
if( err != vr::VRInitError_None )
|
||||
{
|
||||
Msg( "Unable to initialize HMD tracker. Error code %d\n", err );
|
||||
return false;
|
||||
}
|
||||
|
||||
m_pHmd->ResetSeatedZeroPose();
|
||||
if( !vr::VRCompositor() )
|
||||
{
|
||||
Msg("Compositor initialization failed. See log file for details");
|
||||
}
|
||||
vr::VROverlay()->CreateOverlay("GuiOverlayKey", "GuiOverlay", &m_GuiOverlay);
|
||||
vr::VROverlay()->ShowOverlay(m_GuiOverlay);
|
||||
m_pChap->ResetZeroPose(TrackingUniverseSeated);
|
||||
|
||||
m_bHaveValidPose = false;
|
||||
m_ZeroFromHeadPose.Identity();
|
||||
|
||||
@@ -124,6 +124,8 @@ private:
|
||||
CMaterialReference m_blackMaterial;
|
||||
|
||||
vr::IVRSystem *m_pHmd;
|
||||
vr::IVRExtendedDisplay *m_pExtDisplay;
|
||||
vr::IVRChaperone *m_pChap;
|
||||
|
||||
bool m_bHaveValidPose;
|
||||
VMatrix m_ZeroFromHeadPose;
|
||||
|
||||
50
sourcevr/wscript
Executable file
50
sourcevr/wscript
Executable file
@@ -0,0 +1,50 @@
|
||||
#! /usr/bin/env python
|
||||
# encoding: utf-8
|
||||
|
||||
from waflib import Utils
|
||||
import os
|
||||
|
||||
top = '.'
|
||||
PROJECT_NAME = 'sourcevr'
|
||||
|
||||
def options(opt):
|
||||
# stub
|
||||
return
|
||||
|
||||
def configure(conf):
|
||||
conf.env.append_unique('DEFINES',['strncpy=use_Q_strncpy_instead',
|
||||
'_snprintf=use_Q_snprintf_instead','SOURCEVR_DLL'])
|
||||
conf.check_cfg(package='openvr', uselib_store='OPENVR', args=['--cflags', '--libs'])
|
||||
conf.check(lib='GL', uselib_store='GL')
|
||||
|
||||
def build(bld):
|
||||
source = [
|
||||
"sourcevirtualreality.cpp"
|
||||
]
|
||||
|
||||
includes = [
|
||||
'.',
|
||||
'../public',
|
||||
'../public/tier0',
|
||||
'../public/tier1'
|
||||
] + bld.env.INCLUDES_SDL2
|
||||
|
||||
defines = []
|
||||
|
||||
libs = ['tier0','tier1','tier2', 'tier3','vstdlib','mathlib','OPENVR', 'GL']
|
||||
|
||||
install_path = bld.env.LIBDIR
|
||||
|
||||
bld.shlib(
|
||||
source = source,
|
||||
target = PROJECT_NAME,
|
||||
name = PROJECT_NAME,
|
||||
features = 'c cxx',
|
||||
includes = includes,
|
||||
defines = defines,
|
||||
use = libs,
|
||||
install_path = install_path,
|
||||
subsystem = bld.env.MSVC_SUBSYSTEM,
|
||||
idx = bld.get_taskgen_count()
|
||||
)
|
||||
|
||||
@@ -376,7 +376,7 @@ static vgui::MouseCode ButtonCodeToMouseCode( ButtonCode_t buttonCode )
|
||||
//-----------------------------------------------------------------------------
|
||||
bool InputHandleInputEvent( const InputEvent_t &event )
|
||||
{
|
||||
switch( event.m_nType & 0xFFFF )
|
||||
switch( event.m_nType )
|
||||
{
|
||||
case IE_ButtonPressed:
|
||||
{
|
||||
@@ -428,9 +428,10 @@ bool InputHandleInputEvent( const InputEvent_t &event )
|
||||
case IE_FingerDown:
|
||||
{
|
||||
int w,h,x,y; g_MatSystemSurface.GetScreenSize(w, h);
|
||||
uint data = (uint)event.m_nData;
|
||||
x = w*((double)((data >> 16) & 0xFFFF) / 0xFFFF);
|
||||
y = h*((double)(data & 0xFFFF) / 0xFFFF);
|
||||
float _x, _y;
|
||||
memcpy( &_x, &event.m_nData2, sizeof(_x) );
|
||||
memcpy( &_y, &event.m_nData3, sizeof(_y) );
|
||||
x = w*_x; y = h*_y;
|
||||
g_pIInput->UpdateCursorPosInternal( x, y );
|
||||
g_pIInput->SetMouseCodeState( MOUSE_LEFT, vgui::BUTTON_PRESSED );
|
||||
g_pIInput->InternalMousePressed( MOUSE_LEFT );
|
||||
@@ -439,9 +440,10 @@ bool InputHandleInputEvent( const InputEvent_t &event )
|
||||
case IE_FingerUp:
|
||||
{
|
||||
int w,h,x,y; g_MatSystemSurface.GetScreenSize(w, h);
|
||||
uint data = (uint)event.m_nData;
|
||||
x = w*((double)((data >> 16) & 0xFFFF) / 0xFFFF);
|
||||
y = h*((double)(data & 0xFFFF) / 0xFFFF);
|
||||
float _x, _y;
|
||||
memcpy( &_x, &event.m_nData2, sizeof(_x) );
|
||||
memcpy( &_y, &event.m_nData3, sizeof(_y) );
|
||||
x = w*_x; y = h*_y;
|
||||
g_pIInput->UpdateCursorPosInternal( x, y );
|
||||
g_pIInput->SetMouseCodeState( MOUSE_LEFT, vgui::BUTTON_RELEASED );
|
||||
g_pIInput->InternalMouseReleased( MOUSE_LEFT );
|
||||
@@ -450,9 +452,10 @@ bool InputHandleInputEvent( const InputEvent_t &event )
|
||||
case IE_FingerMotion:
|
||||
{
|
||||
int w,h,x,y; g_MatSystemSurface.GetScreenSize(w, h);
|
||||
uint data = (uint)event.m_nData;
|
||||
x = w*((double)((data >> 16) & 0xFFFF) / 0xFFFF);
|
||||
y = h*((double)(data & 0xFFFF) / 0xFFFF);
|
||||
float _x, _y;
|
||||
memcpy( &_x, &event.m_nData2, sizeof(_x) );
|
||||
memcpy( &_y, &event.m_nData3, sizeof(_y) );
|
||||
x = w*_x; y = h*_y;
|
||||
g_pIInput->InternalCursorMoved( x, y );
|
||||
}
|
||||
return true;
|
||||
|
||||
55
vtf/vtf.cpp
55
vtf/vtf.cpp
@@ -27,7 +27,10 @@ BEGIN_BYTESWAP_DATADESC( VTFFileBaseHeader_t )
|
||||
DEFINE_FIELD( headerSize, FIELD_INTEGER ),
|
||||
END_DATADESC()
|
||||
|
||||
BEGIN_BYTESWAP_DATADESC_( VTFFileHeaderV7_1_t, VTFFileBaseHeader_t )
|
||||
BEGIN_BYTESWAP_DATADESC( VTFFileHeaderV7_1_t )
|
||||
DEFINE_ARRAY( fileTypeString, FIELD_CHARACTER, 4 ),
|
||||
DEFINE_ARRAY( version, FIELD_INTEGER, 2 ),
|
||||
DEFINE_FIELD( headerSize, FIELD_INTEGER ),
|
||||
DEFINE_FIELD( width, FIELD_SHORT ),
|
||||
DEFINE_FIELD( height, FIELD_SHORT ),
|
||||
DEFINE_FIELD( flags, FIELD_INTEGER ),
|
||||
@@ -42,17 +45,45 @@ BEGIN_BYTESWAP_DATADESC_( VTFFileHeaderV7_1_t, VTFFileBaseHeader_t )
|
||||
DEFINE_FIELD( lowResImageHeight, FIELD_CHARACTER ),
|
||||
END_DATADESC()
|
||||
|
||||
BEGIN_BYTESWAP_DATADESC_( VTFFileHeaderV7_2_t, VTFFileHeaderV7_1_t )
|
||||
BEGIN_BYTESWAP_DATADESC( VTFFileHeaderV7_2_t )
|
||||
DEFINE_ARRAY( fileTypeString, FIELD_CHARACTER, 4 ),
|
||||
DEFINE_ARRAY( version, FIELD_INTEGER, 2 ),
|
||||
DEFINE_FIELD( headerSize, FIELD_INTEGER ),
|
||||
DEFINE_FIELD( width, FIELD_SHORT ),
|
||||
DEFINE_FIELD( height, FIELD_SHORT ),
|
||||
DEFINE_FIELD( flags, FIELD_INTEGER ),
|
||||
DEFINE_FIELD( numFrames, FIELD_SHORT ),
|
||||
DEFINE_FIELD( startFrame, FIELD_SHORT ),
|
||||
DEFINE_FIELD( reflectivity, FIELD_VECTOR ),
|
||||
DEFINE_FIELD( bumpScale, FIELD_FLOAT ),
|
||||
DEFINE_FIELD( imageFormat, FIELD_INTEGER ),
|
||||
DEFINE_FIELD( numMipLevels, FIELD_CHARACTER ),
|
||||
DEFINE_FIELD( lowResImageFormat, FIELD_INTEGER ),
|
||||
DEFINE_FIELD( lowResImageWidth, FIELD_CHARACTER ),
|
||||
DEFINE_FIELD( lowResImageHeight, FIELD_CHARACTER ),
|
||||
DEFINE_FIELD( depth, FIELD_SHORT ),
|
||||
END_DATADESC()
|
||||
|
||||
BEGIN_BYTESWAP_DATADESC_( VTFFileHeaderV7_3_t, VTFFileHeaderV7_2_t )
|
||||
BEGIN_BYTESWAP_DATADESC( VTFFileHeaderV7_3_t )
|
||||
DEFINE_ARRAY( fileTypeString, FIELD_CHARACTER, 4 ),
|
||||
DEFINE_ARRAY( version, FIELD_INTEGER, 2 ),
|
||||
DEFINE_FIELD( headerSize, FIELD_INTEGER ),
|
||||
DEFINE_FIELD( width, FIELD_SHORT ),
|
||||
DEFINE_FIELD( height, FIELD_SHORT ),
|
||||
DEFINE_FIELD( flags, FIELD_INTEGER ),
|
||||
DEFINE_FIELD( numFrames, FIELD_SHORT ),
|
||||
DEFINE_FIELD( startFrame, FIELD_SHORT ),
|
||||
DEFINE_FIELD( reflectivity, FIELD_VECTOR ),
|
||||
DEFINE_FIELD( bumpScale, FIELD_FLOAT ),
|
||||
DEFINE_FIELD( imageFormat, FIELD_INTEGER ),
|
||||
DEFINE_FIELD( numMipLevels, FIELD_CHARACTER ),
|
||||
DEFINE_FIELD( lowResImageFormat, FIELD_INTEGER ),
|
||||
DEFINE_FIELD( lowResImageWidth, FIELD_CHARACTER ),
|
||||
DEFINE_FIELD( lowResImageHeight, FIELD_CHARACTER ),
|
||||
DEFINE_FIELD( depth, FIELD_SHORT ),
|
||||
DEFINE_FIELD( numResources, FIELD_INTEGER ),
|
||||
END_DATADESC()
|
||||
|
||||
BEGIN_BYTESWAP_DATADESC_( VTFFileHeader_t, VTFFileHeaderV7_2_t )
|
||||
END_DATADESC()
|
||||
|
||||
BEGIN_BYTESWAP_DATADESC_( VTFFileHeaderX360_t, VTFFileBaseHeader_t )
|
||||
DEFINE_FIELD( flags, FIELD_INTEGER ),
|
||||
DEFINE_FIELD( width, FIELD_SHORT ),
|
||||
@@ -903,23 +934,11 @@ static bool ReadHeaderFromBufferPastBaseHeader( CUtlBuffer &buf, VTFFileHeader_t
|
||||
else if ( header.version[1] == 2 )
|
||||
{
|
||||
buf.Get( pBuf, sizeof(VTFFileHeaderV7_2_t) - sizeof(VTFFileBaseHeader_t) );
|
||||
|
||||
#if defined( _X360 ) || defined (POSIX)
|
||||
// read 15 dummy bytes to be properly positioned with 7.2 PC data
|
||||
byte dummy[15];
|
||||
buf.Get( dummy, 15 );
|
||||
#endif
|
||||
}
|
||||
else if ( header.version[1] == 1 || header.version[1] == 0 )
|
||||
{
|
||||
// previous version 7.0 or 7.1
|
||||
buf.Get( pBuf, sizeof(VTFFileHeaderV7_1_t) - sizeof(VTFFileBaseHeader_t) );
|
||||
|
||||
#if defined( _X360 ) || defined (POSIX)
|
||||
// read a dummy byte to be properly positioned with 7.0/1 PC data
|
||||
byte dummy;
|
||||
buf.Get( &dummy, 1 );
|
||||
#endif
|
||||
}
|
||||
else
|
||||
{
|
||||
|
||||
9
wscript
9
wscript
@@ -79,6 +79,7 @@ projects={
|
||||
'utils/vtex',
|
||||
'unicode',
|
||||
'video',
|
||||
'sourcevr'
|
||||
],
|
||||
'tests': [
|
||||
'appframework',
|
||||
@@ -358,10 +359,10 @@ def check_deps(conf):
|
||||
else:
|
||||
conf.check_pkg('freetype2', 'FT2', FT2_CHECK)
|
||||
conf.check_pkg('fontconfig', 'FC', FC_CHECK)
|
||||
if conf.env.DEST_OS == "darwin":
|
||||
conf.env.FRAMEWORK_OPENAL = "OpenAL"
|
||||
else:
|
||||
conf.check_cfg(package='openal', uselib_store='OPENAL', args=['--cflags', '--libs'])
|
||||
# if conf.env.DEST_OS == "darwin":
|
||||
# conf.env.FRAMEWORK_OPENAL = "OpenAL"
|
||||
# else:
|
||||
# conf.check_cfg(package='openal', uselib_store='OPENAL', args=['--cflags', '--libs'])
|
||||
conf.check_cfg(package='libjpeg', uselib_store='JPEG', args=['--cflags', '--libs'])
|
||||
conf.check_cfg(package='libpng', uselib_store='PNG', args=['--cflags', '--libs'])
|
||||
conf.check_cfg(package='libcurl', uselib_store='CURL', args=['--cflags', '--libs'])
|
||||
|
||||
Reference in New Issue
Block a user