mirror of
https://github.com/celisej567/source-engine.git
synced 2026-01-03 05:49:41 +03:00
Compare commits
1 Commits
ios
...
shaderapig
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
b5a0314f33 |
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
|
#endif
|
||||||
#ifdef OSX
|
#ifdef OSX
|
||||||
#include "snd_dev_openal.h"
|
#include "snd_dev_openal.h"
|
||||||
|
#include "snd_dev_mac_audioqueue.h"
|
||||||
|
|
||||||
|
ConVar snd_audioqueue( "snd_audioqueue", "1" );
|
||||||
|
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
// memdbgon must be the last include file in a .cpp file!!!
|
// memdbgon must be the last include file in a .cpp file!!!
|
||||||
@@ -90,6 +94,11 @@ IAudioDevice *IAudioDevice::AutoDetectInit( bool waveOnly )
|
|||||||
pDevice = Audio_CreateWaveDevice();
|
pDevice = Audio_CreateWaveDevice();
|
||||||
}
|
}
|
||||||
#elif defined(OSX)
|
#elif defined(OSX)
|
||||||
|
if ( !CommandLine()->CheckParm( "-snd_openal" ) )
|
||||||
|
{
|
||||||
|
DevMsg( "Using AudioQueue Interface\n" );
|
||||||
|
pDevice = Audio_CreateMacAudioQueueDevice();
|
||||||
|
}
|
||||||
if ( !pDevice )
|
if ( !pDevice )
|
||||||
{
|
{
|
||||||
DevMsg( "Using OpenAL Interface\n" );
|
DevMsg( "Using OpenAL Interface\n" );
|
||||||
|
|||||||
@@ -189,6 +189,8 @@ bool g_bUsingSteamVoice = false;
|
|||||||
|
|
||||||
#ifdef WIN32
|
#ifdef WIN32
|
||||||
extern IVoiceRecord* CreateVoiceRecord_DSound(int nSamplesPerSec);
|
extern IVoiceRecord* CreateVoiceRecord_DSound(int nSamplesPerSec);
|
||||||
|
#elif defined( OSX )
|
||||||
|
extern IVoiceRecord* CreateVoiceRecord_AudioQueue(int sampleRate);
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
#ifdef POSIX
|
#ifdef POSIX
|
||||||
@@ -641,8 +643,13 @@ bool Voice_Init( const char *pCodecName, int nSampleRate )
|
|||||||
return false;
|
return false;
|
||||||
|
|
||||||
// Get the voice input device.
|
// Get the voice input device.
|
||||||
#if defined( OSX )
|
#ifdef OSX
|
||||||
g_pVoiceRecord = CreateVoiceRecord_OpenAL( Voice_SamplesPerSec() );
|
g_pVoiceRecord = CreateVoiceRecord_AudioQueue( Voice_SamplesPerSec() );
|
||||||
|
if ( !g_pVoiceRecord )
|
||||||
|
{
|
||||||
|
// Fall back to OpenAL
|
||||||
|
g_pVoiceRecord = CreateVoiceRecord_OpenAL( Voice_SamplesPerSec() );
|
||||||
|
}
|
||||||
#elif defined( WIN32 )
|
#elif defined( WIN32 )
|
||||||
g_pVoiceRecord = CreateVoiceRecord_DSound( Voice_SamplesPerSec() );
|
g_pVoiceRecord = CreateVoiceRecord_DSound( Voice_SamplesPerSec() );
|
||||||
#elif defined( USE_SDL )
|
#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;
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -341,7 +341,8 @@ def build(bld):
|
|||||||
if bld.env.DEST_OS == 'darwin':
|
if bld.env.DEST_OS == 'darwin':
|
||||||
source += [
|
source += [
|
||||||
'audio/snd_dev_openal.cpp', # [$OSXALL]
|
'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 = [
|
includes = [
|
||||||
|
|||||||
@@ -696,7 +696,6 @@ int CFileSystem_Stdio::FS_stat( const char *pathT, struct _stat *buf, bool *pbLo
|
|||||||
int rt = _stat( path, buf );
|
int rt = _stat( path, buf );
|
||||||
|
|
||||||
// Workaround bug wherein stat() randomly fails on Windows XP. See comment on function.
|
// Workaround bug wherein stat() randomly fails on Windows XP. See comment on function.
|
||||||
/*
|
|
||||||
#if defined(_WIN32) && defined(FILESYSTEM_MSVC2015_STAT_BUG_WORKAROUND)
|
#if defined(_WIN32) && defined(FILESYSTEM_MSVC2015_STAT_BUG_WORKAROUND)
|
||||||
if ( rt == -1 )
|
if ( rt == -1 )
|
||||||
{
|
{
|
||||||
@@ -707,7 +706,6 @@ int CFileSystem_Stdio::FS_stat( const char *pathT, struct _stat *buf, bool *pbLo
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
#endif // defined(_WIN32) && defined(FILESYSTEM_MSVC2015_STAT_BUG_WORKAROUND)
|
#endif // defined(_WIN32) && defined(FILESYSTEM_MSVC2015_STAT_BUG_WORKAROUND)
|
||||||
*/
|
|
||||||
|
|
||||||
#if defined(LINUX) || defined(PLATFORM_BSD)
|
#if defined(LINUX) || defined(PLATFORM_BSD)
|
||||||
if ( rt == -1 )
|
if ( rt == -1 )
|
||||||
|
|||||||
@@ -752,6 +752,12 @@ bool CSourceAppSystemGroup::Create()
|
|||||||
// Load up the appropriate shader DLL
|
// Load up the appropriate shader DLL
|
||||||
// This has to be done before connection.
|
// This has to be done before connection.
|
||||||
char const* pDLLName = "shaderapidx9" DLL_EXT_STRING;
|
char const* pDLLName = "shaderapidx9" DLL_EXT_STRING;
|
||||||
|
|
||||||
|
if ( CommandLine()->FindParm( "-gl" ) )
|
||||||
|
{
|
||||||
|
pDLLName = "shaderapigl" DLL_EXT_STRING;
|
||||||
|
}
|
||||||
|
|
||||||
if ( CommandLine()->FindParm( "-noshaderapi" ) )
|
if ( CommandLine()->FindParm( "-noshaderapi" ) )
|
||||||
{
|
{
|
||||||
pDLLName = "shaderapiempty" DLL_EXT_STRING;
|
pDLLName = "shaderapiempty" DLL_EXT_STRING;
|
||||||
|
|||||||
171
materialsystem/shaderapigl/meshgl.cpp
Normal file
171
materialsystem/shaderapigl/meshgl.cpp
Normal file
@@ -0,0 +1,171 @@
|
|||||||
|
#include "meshgl.h"
|
||||||
|
|
||||||
|
//-----------------------------------------------------------------------------
|
||||||
|
//
|
||||||
|
// The empty mesh...
|
||||||
|
//
|
||||||
|
//-----------------------------------------------------------------------------
|
||||||
|
CGLMesh::CGLMesh( bool bIsDynamic ) : m_bIsDynamic( bIsDynamic )
|
||||||
|
{
|
||||||
|
m_pVertexMemory = new unsigned char[VERTEX_BUFFER_SIZE];
|
||||||
|
}
|
||||||
|
|
||||||
|
CGLMesh::~CGLMesh()
|
||||||
|
{
|
||||||
|
delete[] m_pVertexMemory;
|
||||||
|
}
|
||||||
|
|
||||||
|
bool CGLMesh::Lock( int nMaxIndexCount, bool bAppend, IndexDesc_t& desc )
|
||||||
|
{
|
||||||
|
static int s_BogusIndex;
|
||||||
|
desc.m_pIndices = (unsigned short*)&s_BogusIndex;
|
||||||
|
desc.m_nIndexSize = 0;
|
||||||
|
desc.m_nFirstIndex = 0;
|
||||||
|
desc.m_nOffset = 0;
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
void CGLMesh::Unlock( int nWrittenIndexCount, IndexDesc_t& desc )
|
||||||
|
{
|
||||||
|
}
|
||||||
|
|
||||||
|
void CGLMesh::ModifyBegin( bool bReadOnly, int nFirstIndex, int nIndexCount, IndexDesc_t& desc )
|
||||||
|
{
|
||||||
|
Lock( nIndexCount, false, desc );
|
||||||
|
}
|
||||||
|
|
||||||
|
void CGLMesh::ModifyEnd( IndexDesc_t& desc )
|
||||||
|
{
|
||||||
|
}
|
||||||
|
|
||||||
|
void CGLMesh::Spew( int nIndexCount, const IndexDesc_t & desc )
|
||||||
|
{
|
||||||
|
}
|
||||||
|
|
||||||
|
void CGLMesh::ValidateData( int nIndexCount, const IndexDesc_t &desc )
|
||||||
|
{
|
||||||
|
}
|
||||||
|
|
||||||
|
bool CGLMesh::Lock( int nVertexCount, bool bAppend, VertexDesc_t &desc )
|
||||||
|
{
|
||||||
|
// Who cares about the data?
|
||||||
|
desc.m_pPosition = (float*)m_pVertexMemory;
|
||||||
|
desc.m_pNormal = (float*)m_pVertexMemory;
|
||||||
|
desc.m_pColor = m_pVertexMemory;
|
||||||
|
|
||||||
|
int i;
|
||||||
|
for ( i = 0; i < VERTEX_MAX_TEXTURE_COORDINATES; ++i)
|
||||||
|
{
|
||||||
|
desc.m_pTexCoord[i] = (float*)m_pVertexMemory;
|
||||||
|
}
|
||||||
|
|
||||||
|
desc.m_pBoneWeight = (float*)m_pVertexMemory;
|
||||||
|
desc.m_pBoneMatrixIndex = (unsigned char*)m_pVertexMemory;
|
||||||
|
desc.m_pTangentS = (float*)m_pVertexMemory;
|
||||||
|
desc.m_pTangentT = (float*)m_pVertexMemory;
|
||||||
|
desc.m_pUserData = (float*)m_pVertexMemory;
|
||||||
|
desc.m_NumBoneWeights = 2;
|
||||||
|
|
||||||
|
desc.m_VertexSize_Position = 0;
|
||||||
|
desc.m_VertexSize_BoneWeight = 0;
|
||||||
|
desc.m_VertexSize_BoneMatrixIndex = 0;
|
||||||
|
desc.m_VertexSize_Normal = 0;
|
||||||
|
desc.m_VertexSize_Color = 0;
|
||||||
|
for( i=0; i < VERTEX_MAX_TEXTURE_COORDINATES; i++ )
|
||||||
|
{
|
||||||
|
desc.m_VertexSize_TexCoord[i] = 0;
|
||||||
|
}
|
||||||
|
desc.m_VertexSize_TangentS = 0;
|
||||||
|
desc.m_VertexSize_TangentT = 0;
|
||||||
|
desc.m_VertexSize_UserData = 0;
|
||||||
|
desc.m_ActualVertexSize = 0; // Size of the vertices.. Some of the m_VertexSize_ elements above
|
||||||
|
|
||||||
|
desc.m_nFirstVertex = 0;
|
||||||
|
desc.m_nOffset = 0;
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
void CGLMesh::Unlock( int nVertexCount, VertexDesc_t &desc )
|
||||||
|
{
|
||||||
|
}
|
||||||
|
|
||||||
|
void CGLMesh::Spew( int nVertexCount, const VertexDesc_t &desc )
|
||||||
|
{
|
||||||
|
}
|
||||||
|
|
||||||
|
void CGLMesh::ValidateData( int nVertexCount, const VertexDesc_t & desc )
|
||||||
|
{
|
||||||
|
}
|
||||||
|
|
||||||
|
void CGLMesh::LockMesh( int numVerts, int numIndices, MeshDesc_t& desc )
|
||||||
|
{
|
||||||
|
Lock( numVerts, false, *static_cast<VertexDesc_t*>( &desc ) );
|
||||||
|
Lock( numIndices, false, *static_cast<IndexDesc_t*>( &desc ) );
|
||||||
|
}
|
||||||
|
|
||||||
|
void CGLMesh::UnlockMesh( int numVerts, int numIndices, MeshDesc_t& desc )
|
||||||
|
{
|
||||||
|
}
|
||||||
|
|
||||||
|
void CGLMesh::ModifyBeginEx( bool bReadOnly, int firstVertex, int numVerts, int firstIndex, int numIndices, MeshDesc_t& desc )
|
||||||
|
{
|
||||||
|
Lock( numVerts, false, *static_cast<VertexDesc_t*>( &desc ) );
|
||||||
|
Lock( numIndices, false, *static_cast<IndexDesc_t*>( &desc ) );
|
||||||
|
}
|
||||||
|
|
||||||
|
void CGLMesh::ModifyBegin( int firstVertex, int numVerts, int firstIndex, int numIndices, MeshDesc_t& desc )
|
||||||
|
{
|
||||||
|
ModifyBeginEx( false, firstVertex, numVerts, firstIndex, numIndices, desc );
|
||||||
|
}
|
||||||
|
|
||||||
|
void CGLMesh::ModifyEnd( MeshDesc_t& desc )
|
||||||
|
{
|
||||||
|
}
|
||||||
|
|
||||||
|
// returns the # of vertices (static meshes only)
|
||||||
|
int CGLMesh::VertexCount() const
|
||||||
|
{
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
// Sets the primitive type
|
||||||
|
void CGLMesh::SetPrimitiveType( MaterialPrimitiveType_t type )
|
||||||
|
{
|
||||||
|
}
|
||||||
|
|
||||||
|
// Draws the entire mesh
|
||||||
|
void CGLMesh::Draw( int firstIndex, int numIndices )
|
||||||
|
{
|
||||||
|
}
|
||||||
|
|
||||||
|
void CGLMesh::Draw(CPrimList *pPrims, int nPrims)
|
||||||
|
{
|
||||||
|
}
|
||||||
|
|
||||||
|
// Copy verts and/or indices to a mesh builder. This only works for temp meshes!
|
||||||
|
void CGLMesh::CopyToMeshBuilder(
|
||||||
|
int iStartVert, // Which vertices to copy.
|
||||||
|
int nVerts,
|
||||||
|
int iStartIndex, // Which indices to copy.
|
||||||
|
int nIndices,
|
||||||
|
int indexOffset, // This is added to each index.
|
||||||
|
CMeshBuilder &builder )
|
||||||
|
{
|
||||||
|
}
|
||||||
|
|
||||||
|
// Spews the mesh data
|
||||||
|
void CGLMesh::Spew( int numVerts, int numIndices, const MeshDesc_t & desc )
|
||||||
|
{
|
||||||
|
}
|
||||||
|
|
||||||
|
void CGLMesh::ValidateData( int numVerts, int numIndices, const MeshDesc_t & desc )
|
||||||
|
{
|
||||||
|
}
|
||||||
|
|
||||||
|
// gets the associated material
|
||||||
|
IMaterial* CGLMesh::GetMaterial()
|
||||||
|
{
|
||||||
|
// umm. this don't work none
|
||||||
|
Assert(0);
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
109
materialsystem/shaderapigl/meshgl.h
Normal file
109
materialsystem/shaderapigl/meshgl.h
Normal file
@@ -0,0 +1,109 @@
|
|||||||
|
#ifndef MESHGL_H
|
||||||
|
#define MESHGL_H
|
||||||
|
|
||||||
|
#include "utlvector.h"
|
||||||
|
#include "materialsystem/imaterialsystem.h"
|
||||||
|
#include "shaderapi/ishaderutil.h"
|
||||||
|
#include "shaderapi/ishaderapi.h"
|
||||||
|
#include "materialsystem/imesh.h"
|
||||||
|
#include "materialsystem/idebugtextureinfo.h"
|
||||||
|
#include "materialsystem/deformations.h"
|
||||||
|
|
||||||
|
//-----------------------------------------------------------------------------
|
||||||
|
// The empty mesh
|
||||||
|
//-----------------------------------------------------------------------------
|
||||||
|
class CGLMesh : public IMesh
|
||||||
|
{
|
||||||
|
public:
|
||||||
|
CGLMesh( bool bIsDynamic );
|
||||||
|
virtual ~CGLMesh();
|
||||||
|
|
||||||
|
// FIXME: Make this work! Unsupported methods of IIndexBuffer + IVertexBuffer
|
||||||
|
virtual bool Lock( int nMaxIndexCount, bool bAppend, IndexDesc_t& desc );
|
||||||
|
virtual void Unlock( int nWrittenIndexCount, IndexDesc_t& desc );
|
||||||
|
virtual void ModifyBegin( bool bReadOnly, int nFirstIndex, int nIndexCount, IndexDesc_t& desc );
|
||||||
|
virtual void ModifyEnd( IndexDesc_t& desc );
|
||||||
|
virtual void Spew( int nIndexCount, const IndexDesc_t & desc );
|
||||||
|
virtual void ValidateData( int nIndexCount, const IndexDesc_t &desc );
|
||||||
|
virtual bool Lock( int nVertexCount, bool bAppend, VertexDesc_t &desc );
|
||||||
|
virtual void Unlock( int nVertexCount, VertexDesc_t &desc );
|
||||||
|
virtual void Spew( int nVertexCount, const VertexDesc_t &desc );
|
||||||
|
virtual void ValidateData( int nVertexCount, const VertexDesc_t & desc );
|
||||||
|
virtual bool IsDynamic() const { return m_bIsDynamic; }
|
||||||
|
virtual void BeginCastBuffer( VertexFormat_t format ) {}
|
||||||
|
virtual void BeginCastBuffer( MaterialIndexFormat_t format ) {}
|
||||||
|
virtual void EndCastBuffer( ) {}
|
||||||
|
virtual int GetRoomRemaining() const { return 0; }
|
||||||
|
virtual MaterialIndexFormat_t IndexFormat() const { return MATERIAL_INDEX_FORMAT_UNKNOWN; }
|
||||||
|
|
||||||
|
void LockMesh( int numVerts, int numIndices, MeshDesc_t& desc );
|
||||||
|
void UnlockMesh( int numVerts, int numIndices, MeshDesc_t& desc );
|
||||||
|
|
||||||
|
void ModifyBeginEx( bool bReadOnly, int firstVertex, int numVerts, int firstIndex, int numIndices, MeshDesc_t& desc );
|
||||||
|
void ModifyBegin( int firstVertex, int numVerts, int firstIndex, int numIndices, MeshDesc_t& desc );
|
||||||
|
void ModifyEnd( MeshDesc_t& desc );
|
||||||
|
|
||||||
|
// returns the # of vertices (static meshes only)
|
||||||
|
int VertexCount() const;
|
||||||
|
|
||||||
|
// Sets the primitive type
|
||||||
|
void SetPrimitiveType( MaterialPrimitiveType_t type );
|
||||||
|
|
||||||
|
// Draws the entire mesh
|
||||||
|
void Draw(int firstIndex, int numIndices);
|
||||||
|
|
||||||
|
void Draw(CPrimList *pPrims, int nPrims);
|
||||||
|
|
||||||
|
// Copy verts and/or indices to a mesh builder. This only works for temp meshes!
|
||||||
|
virtual void CopyToMeshBuilder(
|
||||||
|
int iStartVert, // Which vertices to copy.
|
||||||
|
int nVerts,
|
||||||
|
int iStartIndex, // Which indices to copy.
|
||||||
|
int nIndices,
|
||||||
|
int indexOffset, // This is added to each index.
|
||||||
|
CMeshBuilder &builder );
|
||||||
|
|
||||||
|
// Spews the mesh data
|
||||||
|
void Spew( int numVerts, int numIndices, const MeshDesc_t & desc );
|
||||||
|
|
||||||
|
void ValidateData( int numVerts, int numIndices, const MeshDesc_t & desc );
|
||||||
|
|
||||||
|
// gets the associated material
|
||||||
|
IMaterial* GetMaterial();
|
||||||
|
|
||||||
|
void SetColorMesh( IMesh *pColorMesh, int nVertexOffset )
|
||||||
|
{
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
virtual int IndexCount() const
|
||||||
|
{
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
virtual void SetFlexMesh( IMesh *pMesh, int nVertexOffset ) {}
|
||||||
|
|
||||||
|
virtual void DisableFlexMesh() {}
|
||||||
|
|
||||||
|
virtual void MarkAsDrawn() {}
|
||||||
|
|
||||||
|
virtual unsigned ComputeMemoryUsed() { return 0; }
|
||||||
|
|
||||||
|
virtual VertexFormat_t GetVertexFormat() const { return VERTEX_POSITION; }
|
||||||
|
|
||||||
|
virtual IMesh *GetMesh()
|
||||||
|
{
|
||||||
|
return this;
|
||||||
|
}
|
||||||
|
|
||||||
|
private:
|
||||||
|
enum
|
||||||
|
{
|
||||||
|
VERTEX_BUFFER_SIZE = 1024 * 1024
|
||||||
|
};
|
||||||
|
|
||||||
|
unsigned char* m_pVertexMemory;
|
||||||
|
bool m_bIsDynamic;
|
||||||
|
};
|
||||||
|
|
||||||
|
#endif
|
||||||
0
materialsystem/shaderapigl/shaderapidevicegl.cp
Normal file
0
materialsystem/shaderapigl/shaderapidevicegl.cp
Normal file
223
materialsystem/shaderapigl/shaderapidevicegl.cpp
Normal file
223
materialsystem/shaderapigl/shaderapidevicegl.cpp
Normal file
@@ -0,0 +1,223 @@
|
|||||||
|
#include "utlvector.h"
|
||||||
|
#include "materialsystem/imaterialsystem.h"
|
||||||
|
#include "shaderapi/ishaderutil.h"
|
||||||
|
#include "shaderapi/ishaderapi.h"
|
||||||
|
#include "materialsystem/imesh.h"
|
||||||
|
#include "materialsystem/idebugtextureinfo.h"
|
||||||
|
#include "materialsystem/deformations.h"
|
||||||
|
#include "meshgl.h"
|
||||||
|
#include "shaderapigl.h"
|
||||||
|
#include "shaderapidevicegl.h"
|
||||||
|
#include "shadershadowgl.h"
|
||||||
|
|
||||||
|
//-----------------------------------------------------------------------------
|
||||||
|
// The main GL Shader util interface
|
||||||
|
//-----------------------------------------------------------------------------
|
||||||
|
IShaderUtil* g_pShaderUtil;
|
||||||
|
|
||||||
|
//-----------------------------------------------------------------------------
|
||||||
|
// Factory to return from SetMode
|
||||||
|
//-----------------------------------------------------------------------------
|
||||||
|
static void* ShaderInterfaceFactory( const char *pInterfaceName, int *pReturnCode )
|
||||||
|
{
|
||||||
|
if ( pReturnCode )
|
||||||
|
{
|
||||||
|
*pReturnCode = IFACE_OK;
|
||||||
|
}
|
||||||
|
if ( !Q_stricmp( pInterfaceName, SHADER_DEVICE_INTERFACE_VERSION ) )
|
||||||
|
return static_cast< IShaderDevice* >( &s_ShaderDeviceGL );
|
||||||
|
if ( !Q_stricmp( pInterfaceName, SHADERAPI_INTERFACE_VERSION ) )
|
||||||
|
return static_cast< IShaderAPI* >( &g_ShaderAPIGL );
|
||||||
|
if ( !Q_stricmp( pInterfaceName, SHADERSHADOW_INTERFACE_VERSION ) )
|
||||||
|
return static_cast< IShaderShadow* >( &g_ShaderShadow );
|
||||||
|
|
||||||
|
if ( pReturnCode )
|
||||||
|
{
|
||||||
|
*pReturnCode = IFACE_FAILED;
|
||||||
|
}
|
||||||
|
return NULL;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
//-----------------------------------------------------------------------------
|
||||||
|
//
|
||||||
|
// Shader device empty
|
||||||
|
//
|
||||||
|
//-----------------------------------------------------------------------------
|
||||||
|
void CShaderDeviceGL::GetWindowSize( int &width, int &height ) const
|
||||||
|
{
|
||||||
|
width = 0;
|
||||||
|
height = 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
void CShaderDeviceGL::GetBackBufferDimensions( int& width, int& height ) const
|
||||||
|
{
|
||||||
|
width = 1600;
|
||||||
|
height = 900;
|
||||||
|
}
|
||||||
|
|
||||||
|
// Use this to spew information about the 3D layer
|
||||||
|
void CShaderDeviceGL::SpewDriverInfo() const
|
||||||
|
{
|
||||||
|
Warning("GL shader\n");
|
||||||
|
}
|
||||||
|
|
||||||
|
// Creates/ destroys a child window
|
||||||
|
bool CShaderDeviceGL::AddView( void* hwnd )
|
||||||
|
{
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
void CShaderDeviceGL::RemoveView( void* hwnd )
|
||||||
|
{
|
||||||
|
}
|
||||||
|
|
||||||
|
// Activates a view
|
||||||
|
void CShaderDeviceGL::SetView( void* hwnd )
|
||||||
|
{
|
||||||
|
}
|
||||||
|
|
||||||
|
void CShaderDeviceGL::ReleaseResources()
|
||||||
|
{
|
||||||
|
}
|
||||||
|
|
||||||
|
void CShaderDeviceGL::ReacquireResources()
|
||||||
|
{
|
||||||
|
}
|
||||||
|
|
||||||
|
// Creates/destroys Mesh
|
||||||
|
IMesh* CShaderDeviceGL::CreateStaticMesh( VertexFormat_t fmt, const char *pTextureBudgetGroup, IMaterial * pMaterial )
|
||||||
|
{
|
||||||
|
return &m_Mesh;
|
||||||
|
}
|
||||||
|
|
||||||
|
void CShaderDeviceGL::DestroyStaticMesh( IMesh* mesh )
|
||||||
|
{
|
||||||
|
}
|
||||||
|
|
||||||
|
// Creates/destroys static vertex + index buffers
|
||||||
|
IVertexBuffer *CShaderDeviceGL::CreateVertexBuffer( ShaderBufferType_t type, VertexFormat_t fmt, int nVertexCount, const char *pTextureBudgetGroup )
|
||||||
|
{
|
||||||
|
return ( type == SHADER_BUFFER_TYPE_STATIC || type == SHADER_BUFFER_TYPE_STATIC_TEMP ) ? &m_Mesh : &m_DynamicMesh;
|
||||||
|
}
|
||||||
|
|
||||||
|
void CShaderDeviceGL::DestroyVertexBuffer( IVertexBuffer *pVertexBuffer )
|
||||||
|
{
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
IIndexBuffer *CShaderDeviceGL::CreateIndexBuffer( ShaderBufferType_t bufferType, MaterialIndexFormat_t fmt, int nIndexCount, const char *pTextureBudgetGroup )
|
||||||
|
{
|
||||||
|
switch( bufferType )
|
||||||
|
{
|
||||||
|
case SHADER_BUFFER_TYPE_STATIC:
|
||||||
|
case SHADER_BUFFER_TYPE_STATIC_TEMP:
|
||||||
|
return &m_Mesh;
|
||||||
|
default:
|
||||||
|
Assert( 0 );
|
||||||
|
case SHADER_BUFFER_TYPE_DYNAMIC:
|
||||||
|
case SHADER_BUFFER_TYPE_DYNAMIC_TEMP:
|
||||||
|
return &m_DynamicMesh;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
void CShaderDeviceGL::DestroyIndexBuffer( IIndexBuffer *pIndexBuffer )
|
||||||
|
{
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
IVertexBuffer *CShaderDeviceGL::GetDynamicVertexBuffer( int streamID, VertexFormat_t vertexFormat, bool bBuffered )
|
||||||
|
{
|
||||||
|
return &m_DynamicMesh;
|
||||||
|
}
|
||||||
|
|
||||||
|
IIndexBuffer *CShaderDeviceGL::GetDynamicIndexBuffer( MaterialIndexFormat_t fmt, bool bBuffered )
|
||||||
|
{
|
||||||
|
return &m_Mesh;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
//-----------------------------------------------------------------------------
|
||||||
|
//
|
||||||
|
// CShaderDeviceMgrGL
|
||||||
|
//
|
||||||
|
//-----------------------------------------------------------------------------
|
||||||
|
bool CShaderDeviceMgrGL::Connect( CreateInterfaceFn factory )
|
||||||
|
{
|
||||||
|
// So others can access it
|
||||||
|
g_pShaderUtil = (IShaderUtil*)factory( SHADER_UTIL_INTERFACE_VERSION, NULL );
|
||||||
|
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
void CShaderDeviceMgrGL::Disconnect()
|
||||||
|
{
|
||||||
|
g_pShaderUtil = NULL;
|
||||||
|
}
|
||||||
|
|
||||||
|
void *CShaderDeviceMgrGL::QueryInterface( const char *pInterfaceName )
|
||||||
|
{
|
||||||
|
if ( !Q_stricmp( pInterfaceName, SHADER_DEVICE_MGR_INTERFACE_VERSION ) )
|
||||||
|
return static_cast< IShaderDeviceMgr* >( this );
|
||||||
|
if ( !Q_stricmp( pInterfaceName, MATERIALSYSTEM_HARDWARECONFIG_INTERFACE_VERSION ) )
|
||||||
|
return static_cast< IMaterialSystemHardwareConfig* >( &g_ShaderAPIGL );
|
||||||
|
return NULL;
|
||||||
|
}
|
||||||
|
|
||||||
|
InitReturnVal_t CShaderDeviceMgrGL::Init()
|
||||||
|
{
|
||||||
|
return INIT_OK;
|
||||||
|
}
|
||||||
|
|
||||||
|
void CShaderDeviceMgrGL::Shutdown()
|
||||||
|
{
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
// Sets the adapter
|
||||||
|
bool CShaderDeviceMgrGL::SetAdapter( int nAdapter, int nFlags )
|
||||||
|
{
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
// FIXME: Is this a public interface? Might only need to be private to shaderapi
|
||||||
|
CreateInterfaceFn CShaderDeviceMgrGL::SetMode( void *hWnd, int nAdapter, const ShaderDeviceInfo_t& mode )
|
||||||
|
{
|
||||||
|
return ShaderInterfaceFactory;
|
||||||
|
}
|
||||||
|
|
||||||
|
// Gets the number of adapters...
|
||||||
|
int CShaderDeviceMgrGL::GetAdapterCount() const
|
||||||
|
{
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
bool CShaderDeviceMgrGL::GetRecommendedConfigurationInfo( int nAdapter, int nDXLevel, KeyValues *pKeyValues )
|
||||||
|
{
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
// Returns info about each adapter
|
||||||
|
void CShaderDeviceMgrGL::GetAdapterInfo( int adapter, MaterialAdapterInfo_t& info ) const
|
||||||
|
{
|
||||||
|
memset( &info, 0, sizeof( info ) );
|
||||||
|
info.m_nDXSupportLevel = 90;
|
||||||
|
}
|
||||||
|
|
||||||
|
// Returns the number of modes
|
||||||
|
int CShaderDeviceMgrGL::GetModeCount( int nAdapter ) const
|
||||||
|
{
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
// Returns mode information..
|
||||||
|
void CShaderDeviceMgrGL::GetModeInfo( ShaderDisplayMode_t *pInfo, int nAdapter, int nMode ) const
|
||||||
|
{
|
||||||
|
}
|
||||||
|
|
||||||
|
void CShaderDeviceMgrGL::GetCurrentModeInfo( ShaderDisplayMode_t* pInfo, int nAdapter ) const
|
||||||
|
{
|
||||||
|
}
|
||||||
99
materialsystem/shaderapigl/shaderapidevicegl.h
Normal file
99
materialsystem/shaderapigl/shaderapidevicegl.h
Normal file
@@ -0,0 +1,99 @@
|
|||||||
|
#ifndef SHADERAPIDEVICEGL_H
|
||||||
|
#define SHADERAPIDEVICEGL_H
|
||||||
|
|
||||||
|
extern IShaderUtil* g_pShaderUtil;
|
||||||
|
|
||||||
|
//-----------------------------------------------------------------------------
|
||||||
|
// The GL implementation of the shader device
|
||||||
|
//-----------------------------------------------------------------------------
|
||||||
|
class CShaderDeviceGL : public IShaderDevice
|
||||||
|
{
|
||||||
|
public:
|
||||||
|
CShaderDeviceGL() : m_DynamicMesh( true ), m_Mesh( false ) {}
|
||||||
|
|
||||||
|
// Methods of IShaderDevice
|
||||||
|
virtual int GetCurrentAdapter() const { return 0; }
|
||||||
|
virtual bool IsUsingGraphics() const { return false; }
|
||||||
|
virtual void SpewDriverInfo() const;
|
||||||
|
virtual ImageFormat GetBackBufferFormat() const { return IMAGE_FORMAT_RGB888; }
|
||||||
|
virtual void GetBackBufferDimensions( int& width, int& height ) const;
|
||||||
|
virtual int StencilBufferBits() const { return 0; }
|
||||||
|
virtual bool IsAAEnabled() const { return false; }
|
||||||
|
virtual void Present( ) {}
|
||||||
|
virtual void GetWindowSize( int &width, int &height ) const;
|
||||||
|
virtual bool AddView( void* hwnd );
|
||||||
|
virtual void RemoveView( void* hwnd );
|
||||||
|
virtual void SetView( void* hwnd );
|
||||||
|
virtual void ReleaseResources();
|
||||||
|
virtual void ReacquireResources();
|
||||||
|
virtual IMesh* CreateStaticMesh( VertexFormat_t fmt, const char *pTextureBudgetGroup, IMaterial * pMaterial = NULL );
|
||||||
|
virtual void DestroyStaticMesh( IMesh* mesh );
|
||||||
|
virtual IShaderBuffer* CompileShader( const char *pProgram, size_t nBufLen, const char *pShaderVersion ) { return NULL; }
|
||||||
|
virtual VertexShaderHandle_t CreateVertexShader( IShaderBuffer* pShaderBuffer ) { return VERTEX_SHADER_HANDLE_INVALID; }
|
||||||
|
virtual void DestroyVertexShader( VertexShaderHandle_t hShader ) {}
|
||||||
|
virtual GeometryShaderHandle_t CreateGeometryShader( IShaderBuffer* pShaderBuffer ) { return GEOMETRY_SHADER_HANDLE_INVALID; }
|
||||||
|
virtual void DestroyGeometryShader( GeometryShaderHandle_t hShader ) {}
|
||||||
|
virtual PixelShaderHandle_t CreatePixelShader( IShaderBuffer* pShaderBuffer ) { return PIXEL_SHADER_HANDLE_INVALID; }
|
||||||
|
virtual void DestroyPixelShader( PixelShaderHandle_t hShader ) {}
|
||||||
|
virtual IVertexBuffer *CreateVertexBuffer( ShaderBufferType_t type, VertexFormat_t fmt, int nVertexCount, const char *pBudgetGroup );
|
||||||
|
virtual void DestroyVertexBuffer( IVertexBuffer *pVertexBuffer );
|
||||||
|
virtual IIndexBuffer *CreateIndexBuffer( ShaderBufferType_t bufferType, MaterialIndexFormat_t fmt, int nIndexCount, const char *pBudgetGroup );
|
||||||
|
virtual void DestroyIndexBuffer( IIndexBuffer *pIndexBuffer );
|
||||||
|
virtual IVertexBuffer *GetDynamicVertexBuffer( int streamID, VertexFormat_t vertexFormat, bool bBuffered );
|
||||||
|
virtual IIndexBuffer *GetDynamicIndexBuffer( MaterialIndexFormat_t fmt, bool bBuffered );
|
||||||
|
virtual void SetHardwareGammaRamp( float fGamma, float fGammaTVRangeMin, float fGammaTVRangeMax, float fGammaTVExponent, bool bTVEnabled ) {}
|
||||||
|
virtual void EnableNonInteractiveMode( MaterialNonInteractiveMode_t mode, ShaderNonInteractiveInfo_t *pInfo ) {}
|
||||||
|
virtual void RefreshFrontBufferNonInteractive( ) {}
|
||||||
|
virtual void HandleThreadEvent( uint32 threadEvent ) {}
|
||||||
|
|
||||||
|
#ifdef DX_TO_GL_ABSTRACTION
|
||||||
|
virtual void DoStartupShaderPreloading( void ) {}
|
||||||
|
#endif
|
||||||
|
|
||||||
|
virtual char *GetDisplayDeviceName() OVERRIDE { return ""; }
|
||||||
|
|
||||||
|
private:
|
||||||
|
CGLMesh m_Mesh;
|
||||||
|
CGLMesh m_DynamicMesh;
|
||||||
|
};
|
||||||
|
|
||||||
|
static CShaderDeviceGL s_ShaderDeviceGL;
|
||||||
|
|
||||||
|
// FIXME: Remove; it's for backward compat with the materialsystem only for now
|
||||||
|
EXPOSE_SINGLE_INTERFACE_GLOBALVAR( CShaderDeviceGL, IShaderDevice,
|
||||||
|
SHADER_DEVICE_INTERFACE_VERSION, s_ShaderDeviceGL )
|
||||||
|
|
||||||
|
//-----------------------------------------------------------------------------
|
||||||
|
// The DX8 implementation of the shader device
|
||||||
|
//-----------------------------------------------------------------------------
|
||||||
|
class CShaderDeviceMgrGL : public IShaderDeviceMgr
|
||||||
|
{
|
||||||
|
public:
|
||||||
|
// Methods of IAppSystem
|
||||||
|
virtual bool Connect( CreateInterfaceFn factory );
|
||||||
|
virtual void Disconnect();
|
||||||
|
virtual void *QueryInterface( const char *pInterfaceName );
|
||||||
|
virtual InitReturnVal_t Init();
|
||||||
|
virtual void Shutdown();
|
||||||
|
|
||||||
|
public:
|
||||||
|
// Methods of IShaderDeviceMgr
|
||||||
|
virtual int GetAdapterCount() const;
|
||||||
|
virtual void GetAdapterInfo( int adapter, MaterialAdapterInfo_t& info ) const;
|
||||||
|
virtual bool GetRecommendedConfigurationInfo( int nAdapter, int nDXLevel, KeyValues *pKeyValues );
|
||||||
|
virtual int GetModeCount( int adapter ) const;
|
||||||
|
virtual void GetModeInfo( ShaderDisplayMode_t *pInfo, int nAdapter, int mode ) const;
|
||||||
|
virtual void GetCurrentModeInfo( ShaderDisplayMode_t* pInfo, int nAdapter ) const;
|
||||||
|
virtual bool SetAdapter( int nAdapter, int nFlags );
|
||||||
|
virtual CreateInterfaceFn SetMode( void *hWnd, int nAdapter, const ShaderDeviceInfo_t& mode );
|
||||||
|
virtual void AddModeChangeCallback( ShaderModeChangeCallbackFunc_t func ) {}
|
||||||
|
virtual void RemoveModeChangeCallback( ShaderModeChangeCallbackFunc_t func ) {}
|
||||||
|
};
|
||||||
|
|
||||||
|
static CShaderDeviceMgrGL s_ShaderDeviceMgrGL;
|
||||||
|
|
||||||
|
EXPOSE_SINGLE_INTERFACE_GLOBALVAR( CShaderDeviceMgrGL, IShaderDeviceMgr,
|
||||||
|
SHADER_DEVICE_MGR_INTERFACE_VERSION, s_ShaderDeviceMgrGL )
|
||||||
|
|
||||||
|
|
||||||
|
#endif
|
||||||
1142
materialsystem/shaderapigl/shaderapigl.cpp
Normal file
1142
materialsystem/shaderapigl/shaderapigl.cpp
Normal file
File diff suppressed because it is too large
Load Diff
887
materialsystem/shaderapigl/shaderapigl.h
Normal file
887
materialsystem/shaderapigl/shaderapigl.h
Normal file
@@ -0,0 +1,887 @@
|
|||||||
|
#ifndef SHADERAPIGL_H
|
||||||
|
#define SHADERAPIGL_H
|
||||||
|
|
||||||
|
#include "IHardwareConfigInternal.h"
|
||||||
|
|
||||||
|
//-----------------------------------------------------------------------------
|
||||||
|
// The DX8 implementation of the shader API
|
||||||
|
//-----------------------------------------------------------------------------
|
||||||
|
class CShaderAPIGL : public IShaderAPI, public IHardwareConfigInternal, public IDebugTextureInfo
|
||||||
|
{
|
||||||
|
public:
|
||||||
|
// constructor, destructor
|
||||||
|
CShaderAPIGL( );
|
||||||
|
virtual ~CShaderAPIGL();
|
||||||
|
|
||||||
|
// IDebugTextureInfo implementation.
|
||||||
|
public:
|
||||||
|
|
||||||
|
virtual bool IsDebugTextureListFresh( int numFramesAllowed = 1 ) { return false; }
|
||||||
|
virtual bool SetDebugTextureRendering( bool bEnable ) { return false; }
|
||||||
|
virtual void EnableDebugTextureList( bool bEnable ) {}
|
||||||
|
virtual void EnableGetAllTextures( bool bEnable ) {}
|
||||||
|
virtual KeyValues* GetDebugTextureList() { return NULL; }
|
||||||
|
virtual int GetTextureMemoryUsed( TextureMemoryType eTextureMemory ) { return 0; }
|
||||||
|
|
||||||
|
// Methods of IShaderDynamicAPI
|
||||||
|
virtual void GetBackBufferDimensions( int& width, int& height ) const;
|
||||||
|
virtual void GetCurrentColorCorrection( ShaderColorCorrectionInfo_t* pInfo );
|
||||||
|
|
||||||
|
// Methods of IShaderAPI
|
||||||
|
public:
|
||||||
|
virtual void SetViewports( int nCount, const ShaderViewport_t* pViewports );
|
||||||
|
virtual int GetViewports( ShaderViewport_t* pViewports, int nMax ) const;
|
||||||
|
virtual void ClearBuffers( bool bClearColor, bool bClearDepth, bool bClearStencil, int renderTargetWidth, int renderTargetHeight );
|
||||||
|
virtual void ClearColor3ub( unsigned char r, unsigned char g, unsigned char b );
|
||||||
|
virtual void ClearColor4ub( unsigned char r, unsigned char g, unsigned char b, unsigned char a );
|
||||||
|
virtual void BindVertexShader( VertexShaderHandle_t hVertexShader ) {}
|
||||||
|
virtual void BindGeometryShader( GeometryShaderHandle_t hGeometryShader ) {}
|
||||||
|
virtual void BindPixelShader( PixelShaderHandle_t hPixelShader ) {}
|
||||||
|
virtual void SetRasterState( const ShaderRasterState_t& state ) {}
|
||||||
|
virtual void MarkUnusedVertexFields( unsigned int nFlags, int nTexCoordCount, bool *pUnusedTexCoords ) {}
|
||||||
|
virtual bool OwnGPUResources( bool bEnable ) { return false; }
|
||||||
|
|
||||||
|
virtual bool DoRenderTargetsNeedSeparateDepthBuffer() const;
|
||||||
|
|
||||||
|
// Used to clear the transition table when we know it's become invalid.
|
||||||
|
void ClearSnapshots();
|
||||||
|
|
||||||
|
// Sets the mode...
|
||||||
|
bool SetMode( void* hwnd, int nAdapter, const ShaderDeviceInfo_t &info )
|
||||||
|
{
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
void ChangeVideoMode( const ShaderDeviceInfo_t &info )
|
||||||
|
{
|
||||||
|
}
|
||||||
|
|
||||||
|
// Called when the dx support level has changed
|
||||||
|
virtual void DXSupportLevelChanged() {}
|
||||||
|
|
||||||
|
virtual void EnableUserClipTransformOverride( bool bEnable ) {}
|
||||||
|
virtual void UserClipTransform( const VMatrix &worldToView ) {}
|
||||||
|
|
||||||
|
// Sets the default *dynamic* state
|
||||||
|
void SetDefaultState( );
|
||||||
|
|
||||||
|
// Returns the snapshot id for the shader state
|
||||||
|
StateSnapshot_t TakeSnapshot( );
|
||||||
|
|
||||||
|
// Returns true if the state snapshot is transparent
|
||||||
|
bool IsTranslucent( StateSnapshot_t id ) const;
|
||||||
|
bool IsAlphaTested( StateSnapshot_t id ) const;
|
||||||
|
bool UsesVertexAndPixelShaders( StateSnapshot_t id ) const;
|
||||||
|
virtual bool IsDepthWriteEnabled( StateSnapshot_t id ) const;
|
||||||
|
|
||||||
|
// Gets the vertex format for a set of snapshot ids
|
||||||
|
VertexFormat_t ComputeVertexFormat( int numSnapshots, StateSnapshot_t* pIds ) const;
|
||||||
|
|
||||||
|
// Gets the vertex format for a set of snapshot ids
|
||||||
|
VertexFormat_t ComputeVertexUsage( int numSnapshots, StateSnapshot_t* pIds ) const;
|
||||||
|
|
||||||
|
// Begins a rendering pass that uses a state snapshot
|
||||||
|
void BeginPass( StateSnapshot_t snapshot );
|
||||||
|
|
||||||
|
// Uses a state snapshot
|
||||||
|
void UseSnapshot( StateSnapshot_t snapshot );
|
||||||
|
|
||||||
|
// Use this to get the mesh builder that allows us to modify vertex data
|
||||||
|
CMeshBuilder* GetVertexModifyBuilder();
|
||||||
|
|
||||||
|
// Sets the color to modulate by
|
||||||
|
void Color3f( float r, float g, float b );
|
||||||
|
void Color3fv( float const* pColor );
|
||||||
|
void Color4f( float r, float g, float b, float a );
|
||||||
|
void Color4fv( float const* pColor );
|
||||||
|
|
||||||
|
// Faster versions of color
|
||||||
|
void Color3ub( unsigned char r, unsigned char g, unsigned char b );
|
||||||
|
void Color3ubv( unsigned char const* rgb );
|
||||||
|
void Color4ub( unsigned char r, unsigned char g, unsigned char b, unsigned char a );
|
||||||
|
void Color4ubv( unsigned char const* rgba );
|
||||||
|
|
||||||
|
// Sets the lights
|
||||||
|
void SetLight( int lightNum, const LightDesc_t& desc );
|
||||||
|
void SetLightingOrigin( Vector vLightingOrigin );
|
||||||
|
void SetAmbientLight( float r, float g, float b );
|
||||||
|
void SetAmbientLightCube( Vector4D cube[6] );
|
||||||
|
|
||||||
|
// Get the lights
|
||||||
|
int GetMaxLights( void ) const;
|
||||||
|
const LightDesc_t& GetLight( int lightNum ) const;
|
||||||
|
|
||||||
|
// Render state for the ambient light cube (vertex shaders)
|
||||||
|
void SetVertexShaderStateAmbientLightCube();
|
||||||
|
void SetPixelShaderStateAmbientLightCube( int pshReg, bool bForceToBlack = false )
|
||||||
|
{
|
||||||
|
}
|
||||||
|
|
||||||
|
float GetAmbientLightCubeLuminance(void)
|
||||||
|
{
|
||||||
|
return 0.0f;
|
||||||
|
}
|
||||||
|
|
||||||
|
void SetSkinningMatrices();
|
||||||
|
|
||||||
|
// Lightmap texture binding
|
||||||
|
void BindLightmap( TextureStage_t stage );
|
||||||
|
void BindLightmapAlpha( TextureStage_t stage )
|
||||||
|
{
|
||||||
|
}
|
||||||
|
void BindBumpLightmap( TextureStage_t stage );
|
||||||
|
void BindFullbrightLightmap( TextureStage_t stage );
|
||||||
|
void BindWhite( TextureStage_t stage );
|
||||||
|
void BindBlack( TextureStage_t stage );
|
||||||
|
void BindGrey( TextureStage_t stage );
|
||||||
|
void BindFBTexture( TextureStage_t stage, int textureIdex );
|
||||||
|
void CopyRenderTargetToTexture( ShaderAPITextureHandle_t texID )
|
||||||
|
{
|
||||||
|
}
|
||||||
|
|
||||||
|
void CopyRenderTargetToTextureEx( ShaderAPITextureHandle_t texID, int nRenderTargetID, Rect_t *pSrcRect, Rect_t *pDstRect )
|
||||||
|
{
|
||||||
|
}
|
||||||
|
|
||||||
|
void CopyTextureToRenderTargetEx( int nRenderTargetID, ShaderAPITextureHandle_t textureHandle, Rect_t *pSrcRect, Rect_t *pDstRect )
|
||||||
|
{
|
||||||
|
}
|
||||||
|
|
||||||
|
// Special system flat normal map binding.
|
||||||
|
void BindFlatNormalMap( TextureStage_t stage );
|
||||||
|
void BindNormalizationCubeMap( TextureStage_t stage );
|
||||||
|
void BindSignedNormalizationCubeMap( TextureStage_t stage );
|
||||||
|
|
||||||
|
// Set the number of bone weights
|
||||||
|
void SetNumBoneWeights( int numBones );
|
||||||
|
void EnableHWMorphing( bool bEnable );
|
||||||
|
|
||||||
|
// Flushes any primitives that are buffered
|
||||||
|
void FlushBufferedPrimitives();
|
||||||
|
|
||||||
|
// Gets the dynamic mesh; note that you've got to render the mesh
|
||||||
|
// before calling this function a second time. Clients should *not*
|
||||||
|
// call DestroyStaticMesh on the mesh returned by this call.
|
||||||
|
IMesh* GetDynamicMesh( IMaterial* pMaterial, int nHWSkinBoneCount, bool buffered, IMesh* pVertexOverride, IMesh* pIndexOverride );
|
||||||
|
IMesh* GetDynamicMeshEx( IMaterial* pMaterial, VertexFormat_t fmt, int nHWSkinBoneCount, bool buffered, IMesh* pVertexOverride, IMesh* pIndexOverride );
|
||||||
|
|
||||||
|
IMesh* GetFlexMesh();
|
||||||
|
|
||||||
|
// Renders a single pass of a material
|
||||||
|
void RenderPass( int nPass, int nPassCount );
|
||||||
|
|
||||||
|
// stuff related to matrix stacks
|
||||||
|
void MatrixMode( MaterialMatrixMode_t matrixMode );
|
||||||
|
void PushMatrix();
|
||||||
|
void PopMatrix();
|
||||||
|
void LoadMatrix( float *m );
|
||||||
|
void LoadBoneMatrix( int boneIndex, const float *m ) {}
|
||||||
|
void MultMatrix( float *m );
|
||||||
|
void MultMatrixLocal( float *m );
|
||||||
|
void GetMatrix( MaterialMatrixMode_t matrixMode, float *dst );
|
||||||
|
void LoadIdentity( void );
|
||||||
|
void LoadCameraToWorld( void );
|
||||||
|
void Ortho( double left, double top, double right, double bottom, double zNear, double zFar );
|
||||||
|
void PerspectiveX( double fovx, double aspect, double zNear, double zFar );
|
||||||
|
void PerspectiveOffCenterX( double fovx, double aspect, double zNear, double zFar, double bottom, double top, double left, double right );
|
||||||
|
void PickMatrix( int x, int y, int width, int height );
|
||||||
|
void Rotate( float angle, float x, float y, float z );
|
||||||
|
void Translate( float x, float y, float z );
|
||||||
|
void Scale( float x, float y, float z );
|
||||||
|
void ScaleXY( float x, float y );
|
||||||
|
|
||||||
|
// Fog methods...
|
||||||
|
void FogMode( MaterialFogMode_t fogMode );
|
||||||
|
void FogStart( float fStart );
|
||||||
|
void FogEnd( float fEnd );
|
||||||
|
void SetFogZ( float fogZ );
|
||||||
|
void FogMaxDensity( float flMaxDensity );
|
||||||
|
void GetFogDistances( float *fStart, float *fEnd, float *fFogZ );
|
||||||
|
void FogColor3f( float r, float g, float b );
|
||||||
|
void FogColor3fv( float const* rgb );
|
||||||
|
void FogColor3ub( unsigned char r, unsigned char g, unsigned char b );
|
||||||
|
void FogColor3ubv( unsigned char const* rgb );
|
||||||
|
|
||||||
|
virtual void SceneFogColor3ub( unsigned char r, unsigned char g, unsigned char b );
|
||||||
|
virtual void SceneFogMode( MaterialFogMode_t fogMode );
|
||||||
|
virtual void GetSceneFogColor( unsigned char *rgb );
|
||||||
|
virtual MaterialFogMode_t GetSceneFogMode( );
|
||||||
|
virtual int GetPixelFogCombo( );
|
||||||
|
|
||||||
|
void SetHeightClipZ( float z );
|
||||||
|
void SetHeightClipMode( enum MaterialHeightClipMode_t heightClipMode );
|
||||||
|
|
||||||
|
void SetClipPlane( int index, const float *pPlane );
|
||||||
|
void EnableClipPlane( int index, bool bEnable );
|
||||||
|
|
||||||
|
void SetFastClipPlane( const float *pPlane );
|
||||||
|
void EnableFastClip( bool bEnable );
|
||||||
|
|
||||||
|
// We use smaller dynamic VBs during level transitions, to free up memory
|
||||||
|
virtual int GetCurrentDynamicVBSize( void );
|
||||||
|
virtual void DestroyVertexBuffers( bool bExitingLevel = false );
|
||||||
|
|
||||||
|
// Sets the vertex and pixel shaders
|
||||||
|
void SetVertexShaderIndex( int vshIndex );
|
||||||
|
void SetPixelShaderIndex( int pshIndex );
|
||||||
|
|
||||||
|
// Sets the constant register for vertex and pixel shaders
|
||||||
|
void SetVertexShaderConstant( int var, float const* pVec, int numConst = 1, bool bForce = false );
|
||||||
|
void SetBooleanVertexShaderConstant( int var, BOOL const* pVec, int numConst = 1, bool bForce = false );
|
||||||
|
void SetIntegerVertexShaderConstant( int var, int const* pVec, int numConst = 1, bool bForce = false );
|
||||||
|
void SetPixelShaderConstant( int var, float const* pVec, int numConst = 1, bool bForce = false );
|
||||||
|
void SetBooleanPixelShaderConstant( int var, BOOL const* pVec, int numBools = 1, bool bForce = false );
|
||||||
|
void SetIntegerPixelShaderConstant( int var, int const* pVec, int numIntVecs = 1, bool bForce = false );
|
||||||
|
|
||||||
|
void InvalidateDelayedShaderConstants( void );
|
||||||
|
|
||||||
|
// Gamma<->Linear conversions according to the video hardware we're running on
|
||||||
|
float GammaToLinear_HardwareSpecific( float fGamma ) const;
|
||||||
|
float LinearToGamma_HardwareSpecific( float fLinear ) const;
|
||||||
|
|
||||||
|
//Set's the linear->gamma conversion textures to use for this hardware for both srgb writes enabled and disabled(identity)
|
||||||
|
void SetLinearToGammaConversionTextures( ShaderAPITextureHandle_t hSRGBWriteEnabledTexture, ShaderAPITextureHandle_t hIdentityTexture );
|
||||||
|
|
||||||
|
// Cull mode
|
||||||
|
void CullMode( MaterialCullMode_t cullMode );
|
||||||
|
|
||||||
|
// Force writes only when z matches. . . useful for stenciling things out
|
||||||
|
// by rendering the desired Z values ahead of time.
|
||||||
|
void ForceDepthFuncEquals( bool bEnable );
|
||||||
|
|
||||||
|
// Forces Z buffering on or off
|
||||||
|
void OverrideDepthEnable( bool bEnable, bool bDepthEnable );
|
||||||
|
void OverrideAlphaWriteEnable( bool bOverrideEnable, bool bAlphaWriteEnable );
|
||||||
|
void OverrideColorWriteEnable( bool bOverrideEnable, bool bColorWriteEnable );
|
||||||
|
|
||||||
|
// Sets the shade mode
|
||||||
|
void ShadeMode( ShaderShadeMode_t mode );
|
||||||
|
|
||||||
|
// Binds a particular material to render with
|
||||||
|
void Bind( IMaterial* pMaterial );
|
||||||
|
|
||||||
|
// Returns the nearest supported format
|
||||||
|
ImageFormat GetNearestSupportedFormat( ImageFormat fmt, bool bFilteringRequired = true ) const;
|
||||||
|
ImageFormat GetNearestRenderTargetFormat( ImageFormat fmt ) const;
|
||||||
|
|
||||||
|
// Sets the texture state
|
||||||
|
void BindTexture( Sampler_t stage, ShaderAPITextureHandle_t textureHandle );
|
||||||
|
|
||||||
|
void SetRenderTarget( ShaderAPITextureHandle_t colorTextureHandle, ShaderAPITextureHandle_t depthTextureHandle )
|
||||||
|
{
|
||||||
|
}
|
||||||
|
|
||||||
|
void SetRenderTargetEx( int nRenderTargetID, ShaderAPITextureHandle_t colorTextureHandle, ShaderAPITextureHandle_t depthTextureHandle )
|
||||||
|
{
|
||||||
|
}
|
||||||
|
|
||||||
|
// Indicates we're going to be modifying this texture
|
||||||
|
// TexImage2D, TexSubImage2D, TexWrap, TexMinFilter, and TexMagFilter
|
||||||
|
// all use the texture specified by this function.
|
||||||
|
void ModifyTexture( ShaderAPITextureHandle_t textureHandle );
|
||||||
|
|
||||||
|
// Texture management methods
|
||||||
|
void TexImage2D( int level, int cubeFace, ImageFormat dstFormat, int zOffset, int width, int height,
|
||||||
|
ImageFormat srcFormat, bool bSrcIsTiled, void *imageData );
|
||||||
|
void TexSubImage2D( int level, int cubeFace, int xOffset, int yOffset, int zOffset, int width, int height,
|
||||||
|
ImageFormat srcFormat, int srcStride, bool bSrcIsTiled, void *imageData );
|
||||||
|
|
||||||
|
void TexImageFromVTF( IVTFTexture *pVTF, int iVTFFrame );
|
||||||
|
|
||||||
|
bool TexLock( int level, int cubeFaceID, int xOffset, int yOffset,
|
||||||
|
int width, int height, CPixelWriter& writer );
|
||||||
|
void TexUnlock( );
|
||||||
|
|
||||||
|
// These are bound to the texture, not the texture environment
|
||||||
|
void TexMinFilter( ShaderTexFilterMode_t texFilterMode );
|
||||||
|
void TexMagFilter( ShaderTexFilterMode_t texFilterMode );
|
||||||
|
void TexWrap( ShaderTexCoordComponent_t coord, ShaderTexWrapMode_t wrapMode );
|
||||||
|
void TexSetPriority( int priority );
|
||||||
|
|
||||||
|
ShaderAPITextureHandle_t CreateTexture(
|
||||||
|
int width,
|
||||||
|
int height,
|
||||||
|
int depth,
|
||||||
|
ImageFormat dstImageFormat,
|
||||||
|
int numMipLevels,
|
||||||
|
int numCopies,
|
||||||
|
int flags,
|
||||||
|
const char *pDebugName,
|
||||||
|
const char *pTextureGroupName );
|
||||||
|
// Create a multi-frame texture (equivalent to calling "CreateTexture" multiple times, but more efficient)
|
||||||
|
void CreateTextures(
|
||||||
|
ShaderAPITextureHandle_t *pHandles,
|
||||||
|
int count,
|
||||||
|
int width,
|
||||||
|
int height,
|
||||||
|
int depth,
|
||||||
|
ImageFormat dstImageFormat,
|
||||||
|
int numMipLevels,
|
||||||
|
int numCopies,
|
||||||
|
int flags,
|
||||||
|
const char *pDebugName,
|
||||||
|
const char *pTextureGroupName );
|
||||||
|
ShaderAPITextureHandle_t CreateDepthTexture( ImageFormat renderFormat, int width, int height, const char *pDebugName, bool bTexture );
|
||||||
|
void DeleteTexture( ShaderAPITextureHandle_t textureHandle );
|
||||||
|
bool IsTexture( ShaderAPITextureHandle_t textureHandle );
|
||||||
|
bool IsTextureResident( ShaderAPITextureHandle_t textureHandle );
|
||||||
|
|
||||||
|
// stuff that isn't to be used from within a shader
|
||||||
|
void ClearBuffersObeyStencil( bool bClearColor, bool bClearDepth );
|
||||||
|
void ClearBuffersObeyStencilEx( bool bClearColor, bool bClearAlpha, bool bClearDepth );
|
||||||
|
void PerformFullScreenStencilOperation( void );
|
||||||
|
void ReadPixels( int x, int y, int width, int height, unsigned char *data, ImageFormat dstFormat );
|
||||||
|
virtual void ReadPixels( Rect_t *pSrcRect, Rect_t *pDstRect, unsigned char *data, ImageFormat dstFormat, int nDstStride );
|
||||||
|
|
||||||
|
// Selection mode methods
|
||||||
|
int SelectionMode( bool selectionMode );
|
||||||
|
void SelectionBuffer( unsigned int* pBuffer, int size );
|
||||||
|
void ClearSelectionNames( );
|
||||||
|
void LoadSelectionName( int name );
|
||||||
|
void PushSelectionName( int name );
|
||||||
|
void PopSelectionName();
|
||||||
|
|
||||||
|
void FlushHardware();
|
||||||
|
void ResetRenderState( bool bFullReset = true );
|
||||||
|
|
||||||
|
void SetScissorRect( const int nLeft, const int nTop, const int nRight, const int nBottom, const bool bEnableScissor );
|
||||||
|
|
||||||
|
// Can we download textures?
|
||||||
|
virtual bool CanDownloadTextures() const;
|
||||||
|
|
||||||
|
// Board-independent calls, here to unify how shaders set state
|
||||||
|
// Implementations should chain back to IShaderUtil->BindTexture(), etc.
|
||||||
|
|
||||||
|
// Use this to begin and end the frame
|
||||||
|
void BeginFrame();
|
||||||
|
void EndFrame();
|
||||||
|
|
||||||
|
// returns current time
|
||||||
|
double CurrentTime() const;
|
||||||
|
|
||||||
|
// Get the current camera position in world space.
|
||||||
|
void GetWorldSpaceCameraPosition( float * pPos ) const;
|
||||||
|
|
||||||
|
// Members of IMaterialSystemHardwareConfig
|
||||||
|
bool HasDestAlphaBuffer() const;
|
||||||
|
bool HasStencilBuffer() const;
|
||||||
|
virtual int MaxViewports() const;
|
||||||
|
virtual void OverrideStreamOffsetSupport( bool bOverrideEnabled, bool bEnableSupport ) {}
|
||||||
|
virtual int GetShadowFilterMode() const;
|
||||||
|
int StencilBufferBits() const;
|
||||||
|
int GetFrameBufferColorDepth() const;
|
||||||
|
int GetSamplerCount() const;
|
||||||
|
bool HasSetDeviceGammaRamp() const;
|
||||||
|
bool SupportsCompressedTextures() const;
|
||||||
|
VertexCompressionType_t SupportsCompressedVertices() const;
|
||||||
|
bool SupportsVertexAndPixelShaders() const;
|
||||||
|
bool SupportsPixelShaders_1_4() const;
|
||||||
|
bool SupportsPixelShaders_2_0() const;
|
||||||
|
bool SupportsPixelShaders_2_b() const;
|
||||||
|
bool ActuallySupportsPixelShaders_2_b() const;
|
||||||
|
bool SupportsStaticControlFlow() const;
|
||||||
|
bool SupportsVertexShaders_2_0() const;
|
||||||
|
bool SupportsShaderModel_3_0() const;
|
||||||
|
int MaximumAnisotropicLevel() const;
|
||||||
|
int MaxTextureWidth() const;
|
||||||
|
int MaxTextureHeight() const;
|
||||||
|
int MaxTextureAspectRatio() const;
|
||||||
|
int GetDXSupportLevel() const;
|
||||||
|
const char *GetShaderDLLName() const
|
||||||
|
{
|
||||||
|
return "GL";
|
||||||
|
}
|
||||||
|
int TextureMemorySize() const;
|
||||||
|
bool SupportsOverbright() const;
|
||||||
|
bool SupportsCubeMaps() const;
|
||||||
|
bool SupportsMipmappedCubemaps() const;
|
||||||
|
bool SupportsNonPow2Textures() const;
|
||||||
|
int GetTextureStageCount() const;
|
||||||
|
int NumVertexShaderConstants() const;
|
||||||
|
int NumBooleanVertexShaderConstants() const;
|
||||||
|
int NumIntegerVertexShaderConstants() const;
|
||||||
|
int NumPixelShaderConstants() const;
|
||||||
|
int MaxNumLights() const;
|
||||||
|
bool SupportsHardwareLighting() const;
|
||||||
|
int MaxBlendMatrices() const;
|
||||||
|
int MaxBlendMatrixIndices() const;
|
||||||
|
int MaxVertexShaderBlendMatrices() const;
|
||||||
|
int MaxUserClipPlanes() const;
|
||||||
|
bool UseFastClipping() const
|
||||||
|
{
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
bool SpecifiesFogColorInLinearSpace() const;
|
||||||
|
virtual bool SupportsSRGB() const;
|
||||||
|
virtual bool FakeSRGBWrite() const;
|
||||||
|
virtual bool CanDoSRGBReadFromRTs() const;
|
||||||
|
virtual bool SupportsGLMixedSizeTargets() const;
|
||||||
|
|
||||||
|
const char *GetHWSpecificShaderDLLName() const;
|
||||||
|
bool NeedsAAClamp() const
|
||||||
|
{
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
bool SupportsSpheremapping() const;
|
||||||
|
virtual int MaxHWMorphBatchCount() const { return 0; }
|
||||||
|
|
||||||
|
// This is the max dx support level supported by the card
|
||||||
|
virtual int GetMaxDXSupportLevel() const;
|
||||||
|
|
||||||
|
bool ReadPixelsFromFrontBuffer() const;
|
||||||
|
bool PreferDynamicTextures() const;
|
||||||
|
virtual bool PreferReducedFillrate() const;
|
||||||
|
bool HasProjectedBumpEnv() const;
|
||||||
|
void ForceHardwareSync( void );
|
||||||
|
|
||||||
|
int GetCurrentNumBones( void ) const;
|
||||||
|
bool IsHWMorphingEnabled( void ) const;
|
||||||
|
int GetCurrentLightCombo( void ) const;
|
||||||
|
void GetDX9LightState( LightState_t *state ) const;
|
||||||
|
MaterialFogMode_t GetCurrentFogType( void ) const;
|
||||||
|
|
||||||
|
void RecordString( const char *pStr );
|
||||||
|
|
||||||
|
void EvictManagedResources();
|
||||||
|
|
||||||
|
void SetTextureTransformDimension( TextureStage_t textureStage, int dimension, bool projected );
|
||||||
|
void DisableTextureTransform( TextureStage_t textureStage )
|
||||||
|
{
|
||||||
|
}
|
||||||
|
void SetBumpEnvMatrix( TextureStage_t textureStage, float m00, float m01, float m10, float m11 );
|
||||||
|
|
||||||
|
// Gets the lightmap dimensions
|
||||||
|
virtual void GetLightmapDimensions( int *w, int *h );
|
||||||
|
|
||||||
|
virtual void SyncToken( const char *pToken );
|
||||||
|
|
||||||
|
// Setup standard vertex shader constants (that don't change)
|
||||||
|
// This needs to be called anytime that overbright changes.
|
||||||
|
virtual void SetStandardVertexShaderConstants( float fOverbright )
|
||||||
|
{
|
||||||
|
}
|
||||||
|
|
||||||
|
// Level of anisotropic filtering
|
||||||
|
virtual void SetAnisotropicLevel( int nAnisotropyLevel );
|
||||||
|
|
||||||
|
bool SupportsHDR() const
|
||||||
|
{
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
HDRType_t GetHDRType() const
|
||||||
|
{
|
||||||
|
return HDR_TYPE_NONE;
|
||||||
|
}
|
||||||
|
HDRType_t GetHardwareHDRType() const
|
||||||
|
{
|
||||||
|
return HDR_TYPE_NONE;
|
||||||
|
}
|
||||||
|
virtual bool NeedsATICentroidHack() const
|
||||||
|
{
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
virtual bool SupportsColorOnSecondStream() const
|
||||||
|
{
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
virtual bool SupportsStaticPlusDynamicLighting() const
|
||||||
|
{
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
virtual bool SupportsStreamOffset() const
|
||||||
|
{
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
void SetDefaultDynamicState()
|
||||||
|
{
|
||||||
|
}
|
||||||
|
virtual void CommitPixelShaderLighting( int pshReg )
|
||||||
|
{
|
||||||
|
}
|
||||||
|
|
||||||
|
ShaderAPIOcclusionQuery_t CreateOcclusionQueryObject( void )
|
||||||
|
{
|
||||||
|
return INVALID_SHADERAPI_OCCLUSION_QUERY_HANDLE;
|
||||||
|
}
|
||||||
|
|
||||||
|
void DestroyOcclusionQueryObject( ShaderAPIOcclusionQuery_t handle )
|
||||||
|
{
|
||||||
|
}
|
||||||
|
|
||||||
|
void BeginOcclusionQueryDrawing( ShaderAPIOcclusionQuery_t handle )
|
||||||
|
{
|
||||||
|
}
|
||||||
|
|
||||||
|
void EndOcclusionQueryDrawing( ShaderAPIOcclusionQuery_t handle )
|
||||||
|
{
|
||||||
|
}
|
||||||
|
|
||||||
|
int OcclusionQuery_GetNumPixelsRendered( ShaderAPIOcclusionQuery_t handle, bool bFlush )
|
||||||
|
{
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
virtual void AcquireThreadOwnership() {}
|
||||||
|
virtual void ReleaseThreadOwnership() {}
|
||||||
|
|
||||||
|
virtual bool SupportsBorderColor() const { return false; }
|
||||||
|
virtual bool SupportsFetch4() const { return false; }
|
||||||
|
virtual bool CanStretchRectFromTextures( void ) const { return false; }
|
||||||
|
virtual void EnableBuffer2FramesAhead( bool bEnable ) {}
|
||||||
|
|
||||||
|
virtual void SetPSNearAndFarZ( int pshReg ) { }
|
||||||
|
|
||||||
|
virtual void SetDepthFeatheringPixelShaderConstant( int iConstant, float fDepthBlendScale ) {}
|
||||||
|
|
||||||
|
void SetPixelShaderFogParams( int reg )
|
||||||
|
{
|
||||||
|
}
|
||||||
|
|
||||||
|
virtual bool InFlashlightMode() const
|
||||||
|
{
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
virtual bool InEditorMode() const
|
||||||
|
{
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
// What fields in the morph do we actually use?
|
||||||
|
virtual MorphFormat_t ComputeMorphFormat( int numSnapshots, StateSnapshot_t* pIds ) const
|
||||||
|
{
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
// Gets the bound morph's vertex format; returns 0 if no morph is bound
|
||||||
|
virtual MorphFormat_t GetBoundMorphFormat()
|
||||||
|
{
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
// Binds a standard texture
|
||||||
|
virtual void BindStandardTexture( Sampler_t stage, StandardTextureId_t id )
|
||||||
|
{
|
||||||
|
}
|
||||||
|
|
||||||
|
virtual void BindStandardVertexTexture( VertexTextureSampler_t stage, StandardTextureId_t id )
|
||||||
|
{
|
||||||
|
}
|
||||||
|
|
||||||
|
virtual void GetStandardTextureDimensions( int *pWidth, int *pHeight, StandardTextureId_t id )
|
||||||
|
{
|
||||||
|
*pWidth = *pHeight = 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
virtual void SetFlashlightState( const FlashlightState_t &state, const VMatrix &worldToTexture )
|
||||||
|
{
|
||||||
|
}
|
||||||
|
|
||||||
|
virtual void SetFlashlightStateEx( const FlashlightState_t &state, const VMatrix &worldToTexture, ITexture *pFlashlightDepthTexture )
|
||||||
|
{
|
||||||
|
}
|
||||||
|
|
||||||
|
virtual const FlashlightState_t &GetFlashlightState( VMatrix &worldToTexture ) const
|
||||||
|
{
|
||||||
|
static FlashlightState_t blah;
|
||||||
|
return blah;
|
||||||
|
}
|
||||||
|
|
||||||
|
virtual const FlashlightState_t &GetFlashlightStateEx( VMatrix &worldToTexture, ITexture **pFlashlightDepthTexture ) const
|
||||||
|
{
|
||||||
|
static FlashlightState_t blah;
|
||||||
|
return blah;
|
||||||
|
}
|
||||||
|
|
||||||
|
virtual void ClearVertexAndPixelShaderRefCounts()
|
||||||
|
{
|
||||||
|
}
|
||||||
|
|
||||||
|
virtual void PurgeUnusedVertexAndPixelShaders()
|
||||||
|
{
|
||||||
|
}
|
||||||
|
|
||||||
|
virtual bool IsAAEnabled() const
|
||||||
|
{
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
virtual int GetVertexTextureCount() const
|
||||||
|
{
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
virtual int GetMaxVertexTextureDimension() const
|
||||||
|
{
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
virtual int MaxTextureDepth() const
|
||||||
|
{
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
// Binds a vertex texture to a particular texture stage in the vertex pipe
|
||||||
|
virtual void BindVertexTexture( VertexTextureSampler_t nSampler, ShaderAPITextureHandle_t hTexture )
|
||||||
|
{
|
||||||
|
}
|
||||||
|
|
||||||
|
// Sets morph target factors
|
||||||
|
virtual void SetFlexWeights( int nFirstWeight, int nCount, const MorphWeight_t* pWeights )
|
||||||
|
{
|
||||||
|
}
|
||||||
|
|
||||||
|
// NOTE: Stuff after this is added after shipping HL2.
|
||||||
|
ITexture *GetRenderTargetEx( int nRenderTargetID )
|
||||||
|
{
|
||||||
|
return NULL;
|
||||||
|
}
|
||||||
|
|
||||||
|
void SetToneMappingScaleLinear( const Vector &scale )
|
||||||
|
{
|
||||||
|
}
|
||||||
|
|
||||||
|
const Vector &GetToneMappingScaleLinear( void ) const
|
||||||
|
{
|
||||||
|
static Vector dummy;
|
||||||
|
return dummy;
|
||||||
|
}
|
||||||
|
|
||||||
|
virtual float GetLightMapScaleFactor( void ) const
|
||||||
|
{
|
||||||
|
return 1.0;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
// For dealing with device lost in cases where SwapBuffers isn't called all the time (Hammer)
|
||||||
|
virtual void HandleDeviceLost()
|
||||||
|
{
|
||||||
|
}
|
||||||
|
|
||||||
|
virtual void EnableLinearColorSpaceFrameBuffer( bool bEnable )
|
||||||
|
{
|
||||||
|
}
|
||||||
|
|
||||||
|
// Lets the shader know about the full-screen texture so it can
|
||||||
|
virtual void SetFullScreenTextureHandle( ShaderAPITextureHandle_t h )
|
||||||
|
{
|
||||||
|
}
|
||||||
|
|
||||||
|
void SetFloatRenderingParameter(int parm_number, float value)
|
||||||
|
{
|
||||||
|
}
|
||||||
|
|
||||||
|
void SetIntRenderingParameter(int parm_number, int value)
|
||||||
|
{
|
||||||
|
}
|
||||||
|
void SetVectorRenderingParameter(int parm_number, Vector const &value)
|
||||||
|
{
|
||||||
|
}
|
||||||
|
|
||||||
|
float GetFloatRenderingParameter(int parm_number) const
|
||||||
|
{
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
int GetIntRenderingParameter(int parm_number) const
|
||||||
|
{
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
Vector GetVectorRenderingParameter(int parm_number) const
|
||||||
|
{
|
||||||
|
return Vector(0,0,0);
|
||||||
|
}
|
||||||
|
|
||||||
|
// Methods related to stencil
|
||||||
|
void SetStencilEnable(bool onoff)
|
||||||
|
{
|
||||||
|
}
|
||||||
|
|
||||||
|
void SetStencilFailOperation(StencilOperation_t op)
|
||||||
|
{
|
||||||
|
}
|
||||||
|
|
||||||
|
void SetStencilZFailOperation(StencilOperation_t op)
|
||||||
|
{
|
||||||
|
}
|
||||||
|
|
||||||
|
void SetStencilPassOperation(StencilOperation_t op)
|
||||||
|
{
|
||||||
|
}
|
||||||
|
|
||||||
|
void SetStencilCompareFunction(StencilComparisonFunction_t cmpfn)
|
||||||
|
{
|
||||||
|
}
|
||||||
|
|
||||||
|
void SetStencilReferenceValue(int ref)
|
||||||
|
{
|
||||||
|
}
|
||||||
|
|
||||||
|
void SetStencilTestMask(uint32 msk)
|
||||||
|
{
|
||||||
|
}
|
||||||
|
|
||||||
|
void SetStencilWriteMask(uint32 msk)
|
||||||
|
{
|
||||||
|
}
|
||||||
|
|
||||||
|
void ClearStencilBufferRectangle( int xmin, int ymin, int xmax, int ymax,int value)
|
||||||
|
{
|
||||||
|
}
|
||||||
|
|
||||||
|
virtual void GetDXLevelDefaults(uint &max_dxlevel,uint &recommended_dxlevel)
|
||||||
|
{
|
||||||
|
max_dxlevel=recommended_dxlevel=90;
|
||||||
|
}
|
||||||
|
|
||||||
|
virtual void GetMaxToRender( IMesh *pMesh, bool bMaxUntilFlush, int *pMaxVerts, int *pMaxIndices )
|
||||||
|
{
|
||||||
|
*pMaxVerts = 32768;
|
||||||
|
*pMaxIndices = 32768;
|
||||||
|
}
|
||||||
|
|
||||||
|
// Returns the max possible vertices + indices to render in a single draw call
|
||||||
|
virtual int GetMaxVerticesToRender( IMaterial *pMaterial )
|
||||||
|
{
|
||||||
|
return 32768;
|
||||||
|
}
|
||||||
|
|
||||||
|
virtual int GetMaxIndicesToRender( )
|
||||||
|
{
|
||||||
|
return 32768;
|
||||||
|
}
|
||||||
|
virtual int CompareSnapshots( StateSnapshot_t snapshot0, StateSnapshot_t snapshot1 ) { return 0; }
|
||||||
|
|
||||||
|
virtual void DisableAllLocalLights() {}
|
||||||
|
|
||||||
|
virtual bool SupportsMSAAMode( int nMSAAMode ) { return false; }
|
||||||
|
|
||||||
|
virtual bool SupportsCSAAMode( int nNumSamples, int nQualityLevel ) { return false; }
|
||||||
|
|
||||||
|
// Hooks for firing PIX events from outside the Material System...
|
||||||
|
virtual void BeginPIXEvent( unsigned long color, const char *szName ) {}
|
||||||
|
virtual void EndPIXEvent() {}
|
||||||
|
virtual void SetPIXMarker( unsigned long color, const char *szName ) {}
|
||||||
|
|
||||||
|
virtual void ComputeVertexDescription( unsigned char* pBuffer, VertexFormat_t vertexFormat, MeshDesc_t& desc ) const {}
|
||||||
|
|
||||||
|
virtual bool SupportsShadowDepthTextures() { return false; }
|
||||||
|
|
||||||
|
virtual bool SupportsFetch4() { return false; }
|
||||||
|
|
||||||
|
virtual int NeedsShaderSRGBConversion(void) const { return 0; }
|
||||||
|
virtual bool UsesSRGBCorrectBlending() const { return false; }
|
||||||
|
|
||||||
|
virtual bool HasFastVertexTextures() const { return false; }
|
||||||
|
|
||||||
|
virtual void SetShadowDepthBiasFactors( float fShadowSlopeScaleDepthBias, float fShadowDepthBias ) {}
|
||||||
|
|
||||||
|
virtual void SetDisallowAccess( bool ) {}
|
||||||
|
virtual void EnableShaderShaderMutex( bool ) {}
|
||||||
|
virtual void ShaderLock() {}
|
||||||
|
virtual void ShaderUnlock() {}
|
||||||
|
|
||||||
|
// ------------ New Vertex/Index Buffer interface ----------------------------
|
||||||
|
void BindVertexBuffer( int streamID, IVertexBuffer *pVertexBuffer, int nOffsetInBytes, int nFirstVertex, int nVertexCount, VertexFormat_t fmt, int nRepetitions1 )
|
||||||
|
{
|
||||||
|
}
|
||||||
|
void BindIndexBuffer( IIndexBuffer *pIndexBuffer, int nOffsetInBytes )
|
||||||
|
{
|
||||||
|
}
|
||||||
|
void Draw( MaterialPrimitiveType_t primitiveType, int firstIndex, int numIndices )
|
||||||
|
{
|
||||||
|
}
|
||||||
|
// ------------ End ----------------------------
|
||||||
|
|
||||||
|
virtual int GetVertexBufferCompression( void ) const { return 0; };
|
||||||
|
|
||||||
|
virtual bool ShouldWriteDepthToDestAlpha( void ) const { return false; };
|
||||||
|
virtual bool SupportsHDRMode( HDRType_t nHDRMode ) const { return false; };
|
||||||
|
virtual bool IsDX10Card() const { return false; };
|
||||||
|
|
||||||
|
void PushDeformation( const DeformationBase_t *pDeformation )
|
||||||
|
{
|
||||||
|
}
|
||||||
|
|
||||||
|
virtual void PopDeformation( )
|
||||||
|
{
|
||||||
|
}
|
||||||
|
|
||||||
|
int GetNumActiveDeformations( ) const
|
||||||
|
{
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
// for shaders to set vertex shader constants. returns a packed state which can be used to set the dynamic combo
|
||||||
|
int GetPackedDeformationInformation( int nMaskOfUnderstoodDeformations,
|
||||||
|
float *pConstantValuesOut,
|
||||||
|
int nBufferSize,
|
||||||
|
int nMaximumDeformations,
|
||||||
|
int *pNumDefsOut ) const
|
||||||
|
{
|
||||||
|
*pNumDefsOut = 0;
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
void SetStandardTextureHandle(StandardTextureId_t,ShaderAPITextureHandle_t)
|
||||||
|
{
|
||||||
|
}
|
||||||
|
|
||||||
|
virtual void ExecuteCommandBuffer( uint8 *pData )
|
||||||
|
{
|
||||||
|
}
|
||||||
|
virtual bool GetHDREnabled( void ) const { return true; }
|
||||||
|
virtual void SetHDREnabled( bool bEnable ) {}
|
||||||
|
|
||||||
|
virtual void CopyRenderTargetToScratchTexture( ShaderAPITextureHandle_t srcRt, ShaderAPITextureHandle_t dstTex, Rect_t *pSrcRect = NULL, Rect_t *pDstRect = NULL )
|
||||||
|
{
|
||||||
|
}
|
||||||
|
|
||||||
|
// Allows locking and unlocking of very specific surface types.
|
||||||
|
virtual void LockRect( void** pOutBits, int* pOutPitch, ShaderAPITextureHandle_t texHandle, int mipmap, int x, int y, int w, int h, bool bWrite, bool bRead )
|
||||||
|
{
|
||||||
|
}
|
||||||
|
|
||||||
|
virtual void UnlockRect( ShaderAPITextureHandle_t texHandle, int mipmap )
|
||||||
|
{
|
||||||
|
}
|
||||||
|
|
||||||
|
virtual void TexLodClamp( int finest ) {}
|
||||||
|
|
||||||
|
virtual void TexLodBias( float bias ) {}
|
||||||
|
|
||||||
|
virtual void CopyTextureToTexture( ShaderAPITextureHandle_t srcTex, ShaderAPITextureHandle_t dstTex ) {}
|
||||||
|
|
||||||
|
void PrintfVA( char *fmt, va_list vargs ) {}
|
||||||
|
void Printf( const char *fmt, ... ) {}
|
||||||
|
float Knob( char *knobname, float *setvalue = NULL ) { return 0.0f; };
|
||||||
|
|
||||||
|
private:
|
||||||
|
enum
|
||||||
|
{
|
||||||
|
TRANSLUCENT = 0x1,
|
||||||
|
ALPHATESTED = 0x2,
|
||||||
|
VERTEX_AND_PIXEL_SHADERS = 0x4,
|
||||||
|
DEPTHWRITE = 0x8,
|
||||||
|
};
|
||||||
|
|
||||||
|
CGLMesh m_Mesh;
|
||||||
|
|
||||||
|
void EnableAlphaToCoverage() {} ;
|
||||||
|
void DisableAlphaToCoverage() {} ;
|
||||||
|
|
||||||
|
ImageFormat GetShadowDepthTextureFormat() { return IMAGE_FORMAT_UNKNOWN; };
|
||||||
|
ImageFormat GetNullTextureFormat() { return IMAGE_FORMAT_UNKNOWN; };
|
||||||
|
};
|
||||||
|
|
||||||
|
static CShaderAPIGL g_ShaderAPIGL;
|
||||||
|
|
||||||
|
EXPOSE_SINGLE_INTERFACE_GLOBALVAR( CShaderAPIGL, IMaterialSystemHardwareConfig,
|
||||||
|
MATERIALSYSTEM_HARDWARECONFIG_INTERFACE_VERSION, g_ShaderAPIGL )
|
||||||
|
|
||||||
|
EXPOSE_SINGLE_INTERFACE_GLOBALVAR( CShaderAPIGL, IDebugTextureInfo,
|
||||||
|
DEBUG_TEXTURE_INFO_VERSION, g_ShaderAPIGL )
|
||||||
|
|
||||||
|
#endif
|
||||||
0
materialsystem/shaderapigl/shaderdevicebase.cpp
Normal file
0
materialsystem/shaderapigl/shaderdevicebase.cpp
Normal file
0
materialsystem/shaderapigl/shaderdevicebase.h
Normal file
0
materialsystem/shaderapigl/shaderdevicebase.h
Normal file
205
materialsystem/shaderapigl/shadershadowgl.cpp
Normal file
205
materialsystem/shaderapigl/shadershadowgl.cpp
Normal file
@@ -0,0 +1,205 @@
|
|||||||
|
#include "utlvector.h"
|
||||||
|
#include "materialsystem/imaterialsystem.h"
|
||||||
|
#include "shaderapi/ishaderutil.h"
|
||||||
|
#include "shaderapi/ishaderapi.h"
|
||||||
|
#include "materialsystem/imesh.h"
|
||||||
|
#include "materialsystem/idebugtextureinfo.h"
|
||||||
|
#include "materialsystem/deformations.h"
|
||||||
|
#include "meshgl.h"
|
||||||
|
#include "shaderapigl.h"
|
||||||
|
#include "shaderapidevicegl.h"
|
||||||
|
#include "shadershadowgl.h"
|
||||||
|
|
||||||
|
|
||||||
|
//-----------------------------------------------------------------------------
|
||||||
|
// The shader shadow interface
|
||||||
|
//-----------------------------------------------------------------------------
|
||||||
|
CShaderShadowGL::CShaderShadowGL()
|
||||||
|
{
|
||||||
|
m_IsTranslucent = false;
|
||||||
|
m_IsAlphaTested = false;
|
||||||
|
m_bIsDepthWriteEnabled = true;
|
||||||
|
m_bUsesVertexAndPixelShaders = false;
|
||||||
|
}
|
||||||
|
|
||||||
|
CShaderShadowGL::~CShaderShadowGL()
|
||||||
|
{
|
||||||
|
}
|
||||||
|
|
||||||
|
// Sets the default *shadow* state
|
||||||
|
void CShaderShadowGL::SetDefaultState()
|
||||||
|
{
|
||||||
|
m_IsTranslucent = false;
|
||||||
|
m_IsAlphaTested = false;
|
||||||
|
m_bIsDepthWriteEnabled = true;
|
||||||
|
m_bUsesVertexAndPixelShaders = false;
|
||||||
|
}
|
||||||
|
|
||||||
|
// Methods related to depth buffering
|
||||||
|
void CShaderShadowGL::DepthFunc( ShaderDepthFunc_t depthFunc )
|
||||||
|
{
|
||||||
|
}
|
||||||
|
|
||||||
|
void CShaderShadowGL::EnableDepthWrites( bool bEnable )
|
||||||
|
{
|
||||||
|
m_bIsDepthWriteEnabled = bEnable;
|
||||||
|
}
|
||||||
|
|
||||||
|
void CShaderShadowGL::EnableDepthTest( bool bEnable )
|
||||||
|
{
|
||||||
|
}
|
||||||
|
|
||||||
|
void CShaderShadowGL::EnablePolyOffset( PolygonOffsetMode_t nOffsetMode )
|
||||||
|
{
|
||||||
|
}
|
||||||
|
|
||||||
|
// Suppresses/activates color writing
|
||||||
|
void CShaderShadowGL::EnableColorWrites( bool bEnable )
|
||||||
|
{
|
||||||
|
}
|
||||||
|
|
||||||
|
// Suppresses/activates alpha writing
|
||||||
|
void CShaderShadowGL::EnableAlphaWrites( bool bEnable )
|
||||||
|
{
|
||||||
|
}
|
||||||
|
|
||||||
|
// Methods related to alpha blending
|
||||||
|
void CShaderShadowGL::EnableBlending( bool bEnable )
|
||||||
|
{
|
||||||
|
m_IsTranslucent = bEnable;
|
||||||
|
}
|
||||||
|
|
||||||
|
void CShaderShadowGL::BlendFunc( ShaderBlendFactor_t srcFactor, ShaderBlendFactor_t dstFactor )
|
||||||
|
{
|
||||||
|
}
|
||||||
|
|
||||||
|
// A simpler method of dealing with alpha modulation
|
||||||
|
void CShaderShadowGL::EnableAlphaPipe( bool bEnable )
|
||||||
|
{
|
||||||
|
}
|
||||||
|
|
||||||
|
void CShaderShadowGL::EnableConstantAlpha( bool bEnable )
|
||||||
|
{
|
||||||
|
}
|
||||||
|
|
||||||
|
void CShaderShadowGL::EnableVertexAlpha( bool bEnable )
|
||||||
|
{
|
||||||
|
}
|
||||||
|
|
||||||
|
void CShaderShadowGL::EnableTextureAlpha( TextureStage_t stage, bool bEnable )
|
||||||
|
{
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
// Alpha testing
|
||||||
|
void CShaderShadowGL::EnableAlphaTest( bool bEnable )
|
||||||
|
{
|
||||||
|
m_IsAlphaTested = bEnable;
|
||||||
|
}
|
||||||
|
|
||||||
|
void CShaderShadowGL::AlphaFunc( ShaderAlphaFunc_t alphaFunc, float alphaRef /* [0-1] */ )
|
||||||
|
{
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
// Wireframe/filled polygons
|
||||||
|
void CShaderShadowGL::PolyMode( ShaderPolyModeFace_t face, ShaderPolyMode_t polyMode )
|
||||||
|
{
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
// Back face culling
|
||||||
|
void CShaderShadowGL::EnableCulling( bool bEnable )
|
||||||
|
{
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
// Alpha to coverage
|
||||||
|
void CShaderShadowGL::EnableAlphaToCoverage( bool bEnable )
|
||||||
|
{
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
// constant color + transparency
|
||||||
|
void CShaderShadowGL::EnableConstantColor( bool bEnable )
|
||||||
|
{
|
||||||
|
}
|
||||||
|
|
||||||
|
// Indicates the vertex format for use with a vertex shader
|
||||||
|
// The flags to pass in here come from the VertexFormatFlags_t enum
|
||||||
|
// If pTexCoordDimensions is *not* specified, we assume all coordinates
|
||||||
|
// are 2-dimensional
|
||||||
|
void CShaderShadowGL::VertexShaderVertexFormat( unsigned int nFlags,
|
||||||
|
int nTexCoordCount,
|
||||||
|
int* pTexCoordDimensions,
|
||||||
|
int nUserDataSize )
|
||||||
|
{
|
||||||
|
}
|
||||||
|
|
||||||
|
// Indicates we're going to light the model
|
||||||
|
void CShaderShadowGL::EnableLighting( bool bEnable )
|
||||||
|
{
|
||||||
|
}
|
||||||
|
|
||||||
|
void CShaderShadowGL::EnableSpecular( bool bEnable )
|
||||||
|
{
|
||||||
|
}
|
||||||
|
|
||||||
|
// Activate/deactivate skinning
|
||||||
|
void CShaderShadowGL::EnableVertexBlend( bool bEnable )
|
||||||
|
{
|
||||||
|
}
|
||||||
|
|
||||||
|
// per texture unit stuff
|
||||||
|
void CShaderShadowGL::OverbrightValue( TextureStage_t stage, float value )
|
||||||
|
{
|
||||||
|
}
|
||||||
|
|
||||||
|
void CShaderShadowGL::EnableTexture( Sampler_t stage, bool bEnable )
|
||||||
|
{
|
||||||
|
}
|
||||||
|
|
||||||
|
void CShaderShadowGL::EnableCustomPixelPipe( bool bEnable )
|
||||||
|
{
|
||||||
|
}
|
||||||
|
|
||||||
|
void CShaderShadowGL::CustomTextureStages( int stageCount )
|
||||||
|
{
|
||||||
|
}
|
||||||
|
|
||||||
|
void CShaderShadowGL::CustomTextureOperation( TextureStage_t stage, ShaderTexChannel_t channel,
|
||||||
|
ShaderTexOp_t op, ShaderTexArg_t arg1, ShaderTexArg_t arg2 )
|
||||||
|
{
|
||||||
|
}
|
||||||
|
|
||||||
|
void CShaderShadowGL::EnableTexGen( TextureStage_t stage, bool bEnable )
|
||||||
|
{
|
||||||
|
}
|
||||||
|
|
||||||
|
void CShaderShadowGL::TexGen( TextureStage_t stage, ShaderTexGenParam_t param )
|
||||||
|
{
|
||||||
|
}
|
||||||
|
|
||||||
|
// Sets the vertex and pixel shaders
|
||||||
|
void CShaderShadowGL::SetVertexShader( const char *pShaderName, int vshIndex )
|
||||||
|
{
|
||||||
|
m_bUsesVertexAndPixelShaders = ( pShaderName != NULL );
|
||||||
|
}
|
||||||
|
|
||||||
|
void CShaderShadowGL::EnableBlendingSeparateAlpha( bool bEnable )
|
||||||
|
{
|
||||||
|
}
|
||||||
|
void CShaderShadowGL::SetPixelShader( const char *pShaderName, int pshIndex )
|
||||||
|
{
|
||||||
|
m_bUsesVertexAndPixelShaders = ( pShaderName != NULL );
|
||||||
|
}
|
||||||
|
|
||||||
|
void CShaderShadowGL::BlendFuncSeparateAlpha( ShaderBlendFactor_t srcFactor, ShaderBlendFactor_t dstFactor )
|
||||||
|
{
|
||||||
|
}
|
||||||
|
// indicates what per-vertex data we're providing
|
||||||
|
void CShaderShadowGL::DrawFlags( unsigned int drawFlags )
|
||||||
|
{
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
172
materialsystem/shaderapigl/shadershadowgl.h
Normal file
172
materialsystem/shaderapigl/shadershadowgl.h
Normal file
@@ -0,0 +1,172 @@
|
|||||||
|
#ifndef SHADERSHADOWGL_H
|
||||||
|
#define SHADERSHADOWGL_H
|
||||||
|
|
||||||
|
#include "shaderapi/ishadershadow.h"
|
||||||
|
|
||||||
|
//-----------------------------------------------------------------------------
|
||||||
|
// The empty shader shadow
|
||||||
|
//-----------------------------------------------------------------------------
|
||||||
|
class CShaderShadowGL : public IShaderShadow
|
||||||
|
{
|
||||||
|
public:
|
||||||
|
CShaderShadowGL();
|
||||||
|
virtual ~CShaderShadowGL();
|
||||||
|
|
||||||
|
// Sets the default *shadow* state
|
||||||
|
void SetDefaultState();
|
||||||
|
|
||||||
|
// Methods related to depth buffering
|
||||||
|
void DepthFunc( ShaderDepthFunc_t depthFunc );
|
||||||
|
void EnableDepthWrites( bool bEnable );
|
||||||
|
void EnableDepthTest( bool bEnable );
|
||||||
|
void EnablePolyOffset( PolygonOffsetMode_t nOffsetMode );
|
||||||
|
|
||||||
|
// Suppresses/activates color writing
|
||||||
|
void EnableColorWrites( bool bEnable );
|
||||||
|
void EnableAlphaWrites( bool bEnable );
|
||||||
|
|
||||||
|
// Methods related to alpha blending
|
||||||
|
void EnableBlending( bool bEnable );
|
||||||
|
void BlendFunc( ShaderBlendFactor_t srcFactor, ShaderBlendFactor_t dstFactor );
|
||||||
|
|
||||||
|
// Alpha testing
|
||||||
|
void EnableAlphaTest( bool bEnable );
|
||||||
|
void AlphaFunc( ShaderAlphaFunc_t alphaFunc, float alphaRef /* [0-1] */ );
|
||||||
|
|
||||||
|
// Wireframe/filled polygons
|
||||||
|
void PolyMode( ShaderPolyModeFace_t face, ShaderPolyMode_t polyMode );
|
||||||
|
|
||||||
|
// Back face culling
|
||||||
|
void EnableCulling( bool bEnable );
|
||||||
|
|
||||||
|
// constant color + transparency
|
||||||
|
void EnableConstantColor( bool bEnable );
|
||||||
|
|
||||||
|
// Indicates the vertex format for use with a vertex shader
|
||||||
|
// The flags to pass in here come from the VertexFormatFlags_t enum
|
||||||
|
// If pTexCoordDimensions is *not* specified, we assume all coordinates
|
||||||
|
// are 2-dimensional
|
||||||
|
void VertexShaderVertexFormat( unsigned int nFlags,
|
||||||
|
int nTexCoordCount, int* pTexCoordDimensions, int nUserDataSize );
|
||||||
|
|
||||||
|
// Indicates we're going to light the model
|
||||||
|
void EnableLighting( bool bEnable );
|
||||||
|
void EnableSpecular( bool bEnable );
|
||||||
|
|
||||||
|
// vertex blending
|
||||||
|
void EnableVertexBlend( bool bEnable );
|
||||||
|
|
||||||
|
// per texture unit stuff
|
||||||
|
void OverbrightValue( TextureStage_t stage, float value );
|
||||||
|
void EnableTexture( Sampler_t stage, bool bEnable );
|
||||||
|
void EnableTexGen( TextureStage_t stage, bool bEnable );
|
||||||
|
void TexGen( TextureStage_t stage, ShaderTexGenParam_t param );
|
||||||
|
|
||||||
|
// alternate method of specifying per-texture unit stuff, more flexible and more complicated
|
||||||
|
// Can be used to specify different operation per channel (alpha/color)...
|
||||||
|
void EnableCustomPixelPipe( bool bEnable );
|
||||||
|
void CustomTextureStages( int stageCount );
|
||||||
|
void CustomTextureOperation( TextureStage_t stage, ShaderTexChannel_t channel,
|
||||||
|
ShaderTexOp_t op, ShaderTexArg_t arg1, ShaderTexArg_t arg2 );
|
||||||
|
|
||||||
|
// indicates what per-vertex data we're providing
|
||||||
|
void DrawFlags( unsigned int drawFlags );
|
||||||
|
|
||||||
|
// A simpler method of dealing with alpha modulation
|
||||||
|
void EnableAlphaPipe( bool bEnable );
|
||||||
|
void EnableConstantAlpha( bool bEnable );
|
||||||
|
void EnableVertexAlpha( bool bEnable );
|
||||||
|
void EnableTextureAlpha( TextureStage_t stage, bool bEnable );
|
||||||
|
|
||||||
|
// GR - Separate alpha blending
|
||||||
|
void EnableBlendingSeparateAlpha( bool bEnable );
|
||||||
|
void BlendFuncSeparateAlpha( ShaderBlendFactor_t srcFactor, ShaderBlendFactor_t dstFactor );
|
||||||
|
|
||||||
|
// Sets the vertex and pixel shaders
|
||||||
|
void SetVertexShader( const char *pFileName, int vshIndex );
|
||||||
|
void SetPixelShader( const char *pFileName, int pshIndex );
|
||||||
|
|
||||||
|
// Convert from linear to gamma color space on writes to frame buffer.
|
||||||
|
void EnableSRGBWrite( bool bEnable )
|
||||||
|
{
|
||||||
|
}
|
||||||
|
|
||||||
|
void EnableSRGBRead( Sampler_t stage, bool bEnable )
|
||||||
|
{
|
||||||
|
}
|
||||||
|
|
||||||
|
virtual void FogMode( ShaderFogMode_t fogMode )
|
||||||
|
{
|
||||||
|
}
|
||||||
|
|
||||||
|
virtual void DisableFogGammaCorrection( bool bDisable )
|
||||||
|
{
|
||||||
|
}
|
||||||
|
|
||||||
|
virtual void SetDiffuseMaterialSource( ShaderMaterialSource_t materialSource )
|
||||||
|
{
|
||||||
|
}
|
||||||
|
|
||||||
|
virtual void SetMorphFormat( MorphFormat_t flags )
|
||||||
|
{
|
||||||
|
}
|
||||||
|
|
||||||
|
virtual void EnableStencil( bool bEnable )
|
||||||
|
{
|
||||||
|
}
|
||||||
|
virtual void StencilFunc( ShaderStencilFunc_t stencilFunc )
|
||||||
|
{
|
||||||
|
}
|
||||||
|
virtual void StencilPassOp( ShaderStencilOp_t stencilOp )
|
||||||
|
{
|
||||||
|
}
|
||||||
|
virtual void StencilFailOp( ShaderStencilOp_t stencilOp )
|
||||||
|
{
|
||||||
|
}
|
||||||
|
virtual void StencilDepthFailOp( ShaderStencilOp_t stencilOp )
|
||||||
|
{
|
||||||
|
}
|
||||||
|
virtual void StencilReference( int nReference )
|
||||||
|
{
|
||||||
|
}
|
||||||
|
virtual void StencilMask( int nMask )
|
||||||
|
{
|
||||||
|
}
|
||||||
|
virtual void StencilWriteMask( int nMask )
|
||||||
|
{
|
||||||
|
}
|
||||||
|
|
||||||
|
virtual void ExecuteCommandBuffer( uint8 *pBuf )
|
||||||
|
{
|
||||||
|
}
|
||||||
|
// Alpha to coverage
|
||||||
|
void EnableAlphaToCoverage( bool bEnable );
|
||||||
|
|
||||||
|
virtual void SetShadowDepthFiltering( Sampler_t stage )
|
||||||
|
{
|
||||||
|
}
|
||||||
|
|
||||||
|
virtual void BlendOp( ShaderBlendOp_t blendOp ) {}
|
||||||
|
virtual void BlendOpSeparateAlpha( ShaderBlendOp_t blendOp ) {}
|
||||||
|
|
||||||
|
bool m_IsTranslucent;
|
||||||
|
bool m_IsAlphaTested;
|
||||||
|
bool m_bIsDepthWriteEnabled;
|
||||||
|
bool m_bUsesVertexAndPixelShaders;
|
||||||
|
};
|
||||||
|
|
||||||
|
//-----------------------------------------------------------------------------
|
||||||
|
// Class Factory
|
||||||
|
//-----------------------------------------------------------------------------
|
||||||
|
|
||||||
|
static CShaderShadowGL g_ShaderShadow;
|
||||||
|
|
||||||
|
// FIXME: Remove; it's for backward compat with the materialsystem only for now
|
||||||
|
EXPOSE_SINGLE_INTERFACE_GLOBALVAR( CShaderAPIGL, IShaderAPI,
|
||||||
|
SHADERAPI_INTERFACE_VERSION, g_ShaderAPIGL )
|
||||||
|
|
||||||
|
EXPOSE_SINGLE_INTERFACE_GLOBALVAR( CShaderShadowGL, IShaderShadow,
|
||||||
|
SHADERSHADOW_INTERFACE_VERSION, g_ShaderShadow )
|
||||||
|
|
||||||
|
|
||||||
|
#endif
|
||||||
@@ -5,31 +5,41 @@ from waflib import Utils
|
|||||||
import os
|
import os
|
||||||
|
|
||||||
top = '.'
|
top = '.'
|
||||||
PROJECT_NAME = 'steam_api'
|
PROJECT_NAME = 'shaderapigl'
|
||||||
|
|
||||||
def options(opt):
|
def options(opt):
|
||||||
# stub
|
# stub
|
||||||
return
|
return
|
||||||
|
|
||||||
def configure(conf):
|
def configure(conf):
|
||||||
return
|
conf.env.append_unique('DEFINES',[
|
||||||
|
'SHADER_DLL_EXPORT',
|
||||||
|
'PROTECTED_THINGS_ENABLE'
|
||||||
|
])
|
||||||
|
|
||||||
def build(bld):
|
def build(bld):
|
||||||
source = [
|
source = [
|
||||||
'steam_api.cpp'
|
'shaderapigl.cpp',
|
||||||
|
'shaderapidevicegl.cpp',
|
||||||
|
'shadershadowgl.cpp',
|
||||||
|
'meshgl.cpp',
|
||||||
|
'../../public/tier0/memoverride.cpp'
|
||||||
]
|
]
|
||||||
|
|
||||||
includes = [
|
includes = [
|
||||||
'.',
|
'.',
|
||||||
'../public',
|
'../../public',
|
||||||
'../public/tier0',
|
'../../public/tier0',
|
||||||
|
'../../public/tier1',
|
||||||
|
'../../common',
|
||||||
|
'../'
|
||||||
] + bld.env.INCLUDES_SDL2
|
] + bld.env.INCLUDES_SDL2
|
||||||
|
|
||||||
defines = []
|
defines = []
|
||||||
|
|
||||||
libs = []
|
libs = ['tier0','tier1']
|
||||||
|
|
||||||
install_path = None if bld.env.BUILD_SDK else bld.env.LIBDIR
|
install_path = bld.env.LIBDIR
|
||||||
|
|
||||||
bld.shlib(
|
bld.shlib(
|
||||||
source = source,
|
source = source,
|
||||||
@@ -38,8 +48,8 @@ def build(bld):
|
|||||||
features = 'c cxx',
|
features = 'c cxx',
|
||||||
includes = includes,
|
includes = includes,
|
||||||
defines = defines,
|
defines = defines,
|
||||||
install_path = install_path,
|
|
||||||
use = libs,
|
use = libs,
|
||||||
|
install_path = install_path,
|
||||||
subsystem = bld.env.MSVC_SUBSYSTEM,
|
subsystem = bld.env.MSVC_SUBSYSTEM,
|
||||||
idx = bld.get_taskgen_count()
|
idx = bld.get_taskgen_count()
|
||||||
)
|
)
|
||||||
@@ -90,9 +90,6 @@ def fix_dos_path( path ):
|
|||||||
if find_path == '': find_path = './'
|
if find_path == '': find_path = './'
|
||||||
else: find_path += '/'
|
else: find_path += '/'
|
||||||
|
|
||||||
if not os.path.exists(find_path):
|
|
||||||
return find_path+filename
|
|
||||||
|
|
||||||
dirlist = os.listdir(find_path)
|
dirlist = os.listdir(find_path)
|
||||||
for file in dirlist:
|
for file in dirlist:
|
||||||
if file == filename:
|
if file == filename:
|
||||||
|
|||||||
@@ -215,6 +215,7 @@ class Android:
|
|||||||
# TODO: proper STL support
|
# TODO: proper STL support
|
||||||
return [
|
return [
|
||||||
#os.path.abspath(os.path.join(self.ndk_home, 'sources', 'cxx-stl', 'system', 'include')),
|
#os.path.abspath(os.path.join(self.ndk_home, 'sources', 'cxx-stl', 'system', 'include')),
|
||||||
|
os.path.abspath(os.path.join(self.ndk_home, 'sources', 'cxx-stl', 'stlport', 'stlport')),
|
||||||
os.path.abspath(os.path.join(self.ndk_home, 'sources', 'android', 'support', 'include'))
|
os.path.abspath(os.path.join(self.ndk_home, 'sources', 'android', 'support', 'include'))
|
||||||
]
|
]
|
||||||
|
|
||||||
@@ -345,12 +346,8 @@ def configure(conf):
|
|||||||
conf.env.CXXFLAGS += android.cflags(True)
|
conf.env.CXXFLAGS += android.cflags(True)
|
||||||
conf.env.LINKFLAGS += android.linkflags()
|
conf.env.LINKFLAGS += android.linkflags()
|
||||||
conf.env.LDFLAGS += android.ldflags()
|
conf.env.LDFLAGS += android.ldflags()
|
||||||
conf.env.INCLUDES += [
|
conf.env.STLIBPATH += [os.path.abspath(os.path.join(android.ndk_home, 'sources','cxx-stl','stlport','libs',stlarch))]
|
||||||
os.path.abspath(os.path.join(android.ndk_home, 'sources', 'cxx-stl', 'gnu-libstdc++', '4.9', 'include')),
|
conf.env.LDFLAGS += ['-lstlport_static']
|
||||||
os.path.abspath(os.path.join(android.ndk_home, 'sources', 'cxx-stl', 'gnu-libstdc++', '4.9', 'libs', stlarch, 'include'))
|
|
||||||
]
|
|
||||||
conf.env.STLIBPATH += [os.path.abspath(os.path.join(android.ndk_home, 'sources','cxx-stl','gnu-libstdc++','4.9','libs',stlarch))]
|
|
||||||
conf.env.LDFLAGS += ['-lgnustl_static']
|
|
||||||
|
|
||||||
conf.env.HAVE_M = True
|
conf.env.HAVE_M = True
|
||||||
if android.is_hardfp():
|
if android.is_hardfp():
|
||||||
|
|||||||
@@ -1,185 +0,0 @@
|
|||||||
#define _CRT_SECURE_NO_WARNINGS
|
|
||||||
#define STEAM_API_EXPORTS
|
|
||||||
|
|
||||||
#if defined __GNUC__
|
|
||||||
#define S_API extern "C" __attribute__ ((visibility("default")))
|
|
||||||
#elif defined _MSC_VER
|
|
||||||
#define S_API extern "C" __declspec(dllexport)
|
|
||||||
#endif
|
|
||||||
#define NULL 0
|
|
||||||
|
|
||||||
S_API void *g_pSteamClientGameServer;
|
|
||||||
void *g_pSteamClientGameServer = NULL;
|
|
||||||
|
|
||||||
//steam_api.h
|
|
||||||
S_API bool SteamAPI_Init() {
|
|
||||||
return true;
|
|
||||||
}
|
|
||||||
|
|
||||||
S_API bool SteamAPI_InitSafe() {
|
|
||||||
return true;
|
|
||||||
}
|
|
||||||
|
|
||||||
S_API void SteamAPI_Shutdown() {
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
S_API bool SteamAPI_RestartAppIfNecessary() {
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
|
|
||||||
S_API void SteamAPI_ReleaseCurrentThreadMemory() {
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
S_API void SteamAPI_WriteMiniDump() {
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
S_API void SteamAPI_SetMiniDumpComment() {
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
S_API void SteamAPI_RunCallbacks() {
|
|
||||||
}
|
|
||||||
|
|
||||||
S_API void SteamAPI_RegisterCallback() {
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
S_API void SteamAPI_UnregisterCallback() {
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
S_API void SteamAPI_RegisterCallResult() {
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
S_API void SteamAPI_UnregisterCallResult() {
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
S_API bool SteamAPI_IsSteamRunning() {
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
|
|
||||||
S_API void Steam_RunCallbacks() {
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
S_API void Steam_RegisterInterfaceFuncs() {
|
|
||||||
}
|
|
||||||
|
|
||||||
S_API int Steam_GetHSteamUserCurrent() {
|
|
||||||
return 0;
|
|
||||||
}
|
|
||||||
|
|
||||||
S_API const char *SteamAPI_GetSteamInstallPath() {
|
|
||||||
return NULL;
|
|
||||||
}
|
|
||||||
|
|
||||||
S_API int SteamAPI_GetHSteamPipe() {
|
|
||||||
return 0;
|
|
||||||
}
|
|
||||||
|
|
||||||
S_API void SteamAPI_SetTryCatchCallbacks() {
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
S_API void SteamAPI_SetBreakpadAppID() {
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
S_API void SteamAPI_UseBreakpadCrashHandler() {
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
S_API int GetHSteamPipe() {
|
|
||||||
return 0;
|
|
||||||
}
|
|
||||||
|
|
||||||
S_API int GetHSteamUser() {
|
|
||||||
return 0;
|
|
||||||
}
|
|
||||||
|
|
||||||
S_API int SteamAPI_GetHSteamUser() {
|
|
||||||
return 0;
|
|
||||||
}
|
|
||||||
|
|
||||||
S_API void *SteamInternal_ContextInit() {
|
|
||||||
return NULL;
|
|
||||||
}
|
|
||||||
|
|
||||||
S_API void *SteamInternal_CreateInterface() {
|
|
||||||
return NULL;
|
|
||||||
}
|
|
||||||
|
|
||||||
S_API void *SteamApps() {
|
|
||||||
return NULL;
|
|
||||||
}
|
|
||||||
|
|
||||||
S_API void *SteamClient() {
|
|
||||||
return NULL;
|
|
||||||
}
|
|
||||||
|
|
||||||
S_API void *SteamFriends() {
|
|
||||||
return NULL;
|
|
||||||
}
|
|
||||||
|
|
||||||
S_API void *SteamHTTP() {
|
|
||||||
return NULL;
|
|
||||||
}
|
|
||||||
|
|
||||||
S_API void *SteamMatchmaking() {
|
|
||||||
return NULL;
|
|
||||||
}
|
|
||||||
|
|
||||||
S_API void *SteamMatchmakingServers() {
|
|
||||||
return NULL;
|
|
||||||
}
|
|
||||||
|
|
||||||
S_API void *SteamNetworking() {
|
|
||||||
return NULL;
|
|
||||||
}
|
|
||||||
|
|
||||||
S_API void *SteamRemoteStorage() {
|
|
||||||
return NULL;
|
|
||||||
}
|
|
||||||
|
|
||||||
S_API void *SteamScreenshots() {
|
|
||||||
return NULL;
|
|
||||||
}
|
|
||||||
|
|
||||||
S_API void *SteamUser() {
|
|
||||||
return NULL;
|
|
||||||
}
|
|
||||||
|
|
||||||
S_API void *SteamUserStats() {
|
|
||||||
return NULL;
|
|
||||||
}
|
|
||||||
|
|
||||||
S_API void *SteamUtils() {
|
|
||||||
return NULL;
|
|
||||||
}
|
|
||||||
|
|
||||||
S_API int SteamGameServer_GetHSteamPipe() {
|
|
||||||
return 0;
|
|
||||||
}
|
|
||||||
|
|
||||||
S_API int SteamGameServer_GetHSteamUser() {
|
|
||||||
return 0;
|
|
||||||
}
|
|
||||||
|
|
||||||
S_API int SteamGameServer_GetIPCCallCount() {
|
|
||||||
return 0;
|
|
||||||
}
|
|
||||||
|
|
||||||
S_API int SteamGameServer_InitSafe() {
|
|
||||||
return 0;
|
|
||||||
}
|
|
||||||
|
|
||||||
S_API void SteamGameServer_RunCallbacks() {
|
|
||||||
}
|
|
||||||
|
|
||||||
S_API void SteamGameServer_Shutdown() {
|
|
||||||
}
|
|
||||||
Submodule thirdparty updated: c5b901ecef...aac07c7205
@@ -83,7 +83,7 @@ def build(bld):
|
|||||||
else:
|
else:
|
||||||
libs = ['DL', 'M', 'LOG']
|
libs = ['DL', 'M', 'LOG']
|
||||||
|
|
||||||
install_path = None if bld.env.BUILD_SDK else bld.env.LIBDIR
|
install_path = bld.env.LIBDIR
|
||||||
|
|
||||||
bld.shlib(
|
bld.shlib(
|
||||||
source = source,
|
source = source,
|
||||||
|
|||||||
427
vstdlib/osversion.cpp
Normal file
427
vstdlib/osversion.cpp
Normal file
@@ -0,0 +1,427 @@
|
|||||||
|
//========= Copyright Valve Corporation, All rights reserved. ============//
|
||||||
|
//
|
||||||
|
// Purpose:
|
||||||
|
//
|
||||||
|
// $NoKeywords: $
|
||||||
|
//
|
||||||
|
//=============================================================================//
|
||||||
|
|
||||||
|
#include "vstdlib/osversion.h"
|
||||||
|
#include "winlite.h"
|
||||||
|
#include "strtools.h"
|
||||||
|
#include "tier0/dbg.h"
|
||||||
|
|
||||||
|
#ifdef OSX
|
||||||
|
#include <CoreServices/CoreServices.h>
|
||||||
|
#endif
|
||||||
|
|
||||||
|
//-----------------------------------------------------------------------------
|
||||||
|
// Purpose: return the OS type for this machine
|
||||||
|
//-----------------------------------------------------------------------------
|
||||||
|
EOSType GetOSType()
|
||||||
|
{
|
||||||
|
static EOSType eOSVersion = k_eOSUnknown;
|
||||||
|
|
||||||
|
#if defined( _WIN32 ) && !defined( _X360 )
|
||||||
|
if ( eOSVersion == k_eOSUnknown || eOSVersion == k_eWinUnknown )
|
||||||
|
{
|
||||||
|
eOSVersion = k_eWinUnknown;
|
||||||
|
OSVERSIONINFOEX osvi;
|
||||||
|
Q_memset( &osvi, 0x00, sizeof(osvi) );
|
||||||
|
osvi.dwOSVersionInfoSize = sizeof(osvi);
|
||||||
|
|
||||||
|
if ( GetVersionEx( (OSVERSIONINFO *) &osvi ) )
|
||||||
|
{
|
||||||
|
switch ( osvi.dwPlatformId )
|
||||||
|
{
|
||||||
|
case VER_PLATFORM_WIN32_NT:
|
||||||
|
if ( osvi.dwMajorVersion <= 4 )
|
||||||
|
{
|
||||||
|
eOSVersion = k_eWinNT;
|
||||||
|
}
|
||||||
|
else if ( osvi.dwMajorVersion == 5 )
|
||||||
|
{
|
||||||
|
switch( osvi.dwMinorVersion )
|
||||||
|
{
|
||||||
|
case 0:
|
||||||
|
eOSVersion = k_eWin2000;
|
||||||
|
break;
|
||||||
|
case 1:
|
||||||
|
eOSVersion = k_eWinXP;
|
||||||
|
break;
|
||||||
|
case 2:
|
||||||
|
eOSVersion = k_eWin2003;
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
else if ( osvi.dwMajorVersion >= 6 )
|
||||||
|
{
|
||||||
|
if ( osvi.wProductType == VER_NT_WORKSTATION )
|
||||||
|
{
|
||||||
|
switch ( osvi.dwMinorVersion )
|
||||||
|
{
|
||||||
|
case 0:
|
||||||
|
eOSVersion = k_eWinVista;
|
||||||
|
break;
|
||||||
|
case 1:
|
||||||
|
eOSVersion = k_eWindows7;
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
else /* ( osvi.wProductType != VER_NT_WORKSTATION ) */
|
||||||
|
{
|
||||||
|
switch ( osvi.dwMinorVersion )
|
||||||
|
{
|
||||||
|
case 0:
|
||||||
|
eOSVersion = k_eWin2008; // Windows 2008, not R2
|
||||||
|
break;
|
||||||
|
case 1:
|
||||||
|
eOSVersion = k_eWin2008; // Windows 2008 R2
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
break;
|
||||||
|
case VER_PLATFORM_WIN32_WINDOWS:
|
||||||
|
switch ( osvi.dwMinorVersion )
|
||||||
|
{
|
||||||
|
case 0:
|
||||||
|
eOSVersion = k_eWin95;
|
||||||
|
break;
|
||||||
|
case 10:
|
||||||
|
eOSVersion = k_eWin98;
|
||||||
|
break;
|
||||||
|
case 90:
|
||||||
|
eOSVersion = k_eWinME;
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
break;
|
||||||
|
case VER_PLATFORM_WIN32s:
|
||||||
|
eOSVersion = k_eWin311;
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
#elif defined(OSX)
|
||||||
|
if ( eOSVersion == k_eOSUnknown )
|
||||||
|
{
|
||||||
|
SInt32 MajorVer = 0;
|
||||||
|
SInt32 MinorVer = 0;
|
||||||
|
SInt32 PatchVer = 0;
|
||||||
|
OSErr err = noErr;
|
||||||
|
err = Gestalt( gestaltSystemVersionMajor, &MajorVer );
|
||||||
|
if ( err != noErr )
|
||||||
|
return k_eOSUnknown;
|
||||||
|
err = Gestalt( gestaltSystemVersionMinor, &MinorVer );
|
||||||
|
if ( err != noErr )
|
||||||
|
return k_eOSUnknown;
|
||||||
|
err = Gestalt( gestaltSystemVersionBugFix, &PatchVer );
|
||||||
|
if ( err != noErr )
|
||||||
|
return k_eOSUnknown;
|
||||||
|
|
||||||
|
switch ( MajorVer )
|
||||||
|
{
|
||||||
|
case 10:
|
||||||
|
{
|
||||||
|
switch( MinorVer )
|
||||||
|
{
|
||||||
|
case 4:
|
||||||
|
eOSVersion = k_eMacOS104;
|
||||||
|
break;
|
||||||
|
case 5:
|
||||||
|
eOSVersion = k_eMacOS105;
|
||||||
|
switch ( PatchVer )
|
||||||
|
{
|
||||||
|
case 8:
|
||||||
|
eOSVersion = k_eMacOS1058;
|
||||||
|
default:
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
break;
|
||||||
|
case 6:
|
||||||
|
eOSVersion = k_eMacOS106;
|
||||||
|
switch ( PatchVer )
|
||||||
|
{
|
||||||
|
case 1:
|
||||||
|
case 2:
|
||||||
|
break;
|
||||||
|
case 3:
|
||||||
|
default:
|
||||||
|
// note the default here - 10.6.4 (5,6...) >= 10.6.3, so we want to
|
||||||
|
// identify as 10.6.3 for sysreqs purposes
|
||||||
|
eOSVersion = k_eMacOS1063;
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
break;
|
||||||
|
case 7:
|
||||||
|
eOSVersion = k_eMacOS107;
|
||||||
|
break;
|
||||||
|
default:
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
default:
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
#elif defined(LINUX)
|
||||||
|
if ( eOSVersion == k_eOSUnknown )
|
||||||
|
{
|
||||||
|
|
||||||
|
FILE *fpKernelVer = fopen( "/proc/version", "r" );
|
||||||
|
|
||||||
|
if ( !fpKernelVer )
|
||||||
|
return k_eLinuxUnknown;
|
||||||
|
|
||||||
|
char rgchVersionLine[1024];
|
||||||
|
char *pchRet = fgets( rgchVersionLine, sizeof(rgchVersionLine), fpKernelVer );
|
||||||
|
fclose( fpKernelVer );
|
||||||
|
|
||||||
|
eOSVersion = k_eLinuxUnknown;
|
||||||
|
|
||||||
|
// move past "Linux version "
|
||||||
|
const char *pchVersion = rgchVersionLine + Q_strlen( "Linux version " );
|
||||||
|
if ( pchRet && *pchVersion == '2' && *(pchVersion+1) == '.' )
|
||||||
|
{
|
||||||
|
pchVersion += 2; // move past "2."
|
||||||
|
if ( *pchVersion == '2' && *(pchVersion+1) == '.' )
|
||||||
|
eOSVersion = k_eLinux22;
|
||||||
|
else if ( *pchVersion == '4' && *(pchVersion+1) == '.' )
|
||||||
|
eOSVersion = k_eLinux24;
|
||||||
|
else if ( *pchVersion == '6' && *(pchVersion+1) == '.' )
|
||||||
|
eOSVersion = k_eLinux26;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
#endif
|
||||||
|
return eOSVersion;
|
||||||
|
}
|
||||||
|
|
||||||
|
//-----------------------------------------------------------------------------
|
||||||
|
// Purpose: get platform-specific OS details (distro, on linux)
|
||||||
|
// returns a pointer to the input buffer on success (for convenience),
|
||||||
|
// NULL on failure.
|
||||||
|
//-----------------------------------------------------------------------------
|
||||||
|
const char *GetOSDetailString( char *pchOutBuf, int cchOutBuf )
|
||||||
|
{
|
||||||
|
#if defined WIN32
|
||||||
|
(void)( pchOutBuf );
|
||||||
|
(void)( cchOutBuf );
|
||||||
|
// no interesting details
|
||||||
|
return NULL;
|
||||||
|
#else
|
||||||
|
#if defined LINUX
|
||||||
|
// we're about to go poking around to see if we can figure out distribution
|
||||||
|
// looking @ any /etc file is fragile (people can change 'em),
|
||||||
|
// but since this is just hardware survey data, we're not super concerned.
|
||||||
|
// a bunch of OS-specific issue files
|
||||||
|
const char *pszIssueFile[] =
|
||||||
|
{
|
||||||
|
"/etc/redhat-release",
|
||||||
|
"/etc/fedora-release",
|
||||||
|
"/etc/slackware-release",
|
||||||
|
"/etc/debian_release",
|
||||||
|
"/etc/mandrake-release",
|
||||||
|
"/etc/yellowdog-release",
|
||||||
|
"/etc/gentoo-release",
|
||||||
|
"/etc/lsb-release",
|
||||||
|
"/etc/SUSE-release",
|
||||||
|
};
|
||||||
|
if ( !pchOutBuf )
|
||||||
|
return NULL;
|
||||||
|
|
||||||
|
for (int i = 0; i < Q_ARRAYSIZE( pszIssueFile ); i++ )
|
||||||
|
{
|
||||||
|
FILE *fdInfo = fopen( pszIssueFile[i], "r" );
|
||||||
|
if ( !fdInfo )
|
||||||
|
continue;
|
||||||
|
|
||||||
|
// prepend the buffer with the name of the file we found for easier grouping
|
||||||
|
snprintf( pchOutBuf, cchOutBuf, "%s\n", pszIssueFile[i] );
|
||||||
|
int cchIssueFile = strlen( pszIssueFile[i] ) + 1;
|
||||||
|
ssize_t cubRead = fread( (void*) (pchOutBuf + cchIssueFile) , sizeof(char), cchOutBuf - cchIssueFile, fdInfo );
|
||||||
|
fclose( fdInfo );
|
||||||
|
|
||||||
|
if ( cubRead < 0 )
|
||||||
|
return NULL;
|
||||||
|
|
||||||
|
// null terminate
|
||||||
|
pchOutBuf[ MIN( cubRead, cchOutBuf-1 ) ] = '\0';
|
||||||
|
return pchOutBuf;
|
||||||
|
}
|
||||||
|
#endif
|
||||||
|
// if all else fails, just send back uname -a
|
||||||
|
if ( !pchOutBuf )
|
||||||
|
return NULL;
|
||||||
|
FILE *fpUname = popen( "uname -mrsv", "r" );
|
||||||
|
if ( !fpUname )
|
||||||
|
return NULL;
|
||||||
|
size_t cchRead = fread( pchOutBuf, sizeof(char), cchOutBuf, fpUname );
|
||||||
|
pclose( fpUname );
|
||||||
|
|
||||||
|
pchOutBuf[ MIN( cchRead, (size_t)cchOutBuf-1 ) ] = '\0';
|
||||||
|
return pchOutBuf;
|
||||||
|
#endif
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
//-----------------------------------------------------------------------------
|
||||||
|
// Purpose: get a friendly name for an OS type
|
||||||
|
//-----------------------------------------------------------------------------
|
||||||
|
const char *GetNameFromOSType( EOSType eOSType )
|
||||||
|
{
|
||||||
|
switch ( eOSType )
|
||||||
|
{
|
||||||
|
case k_eWinUnknown:
|
||||||
|
return "Windows";
|
||||||
|
case k_eWin311:
|
||||||
|
return "Windows 3.11";
|
||||||
|
case k_eWin95:
|
||||||
|
return "Windows 95";
|
||||||
|
case k_eWin98:
|
||||||
|
return "Windows 98";
|
||||||
|
case k_eWinME:
|
||||||
|
return "Windows ME";
|
||||||
|
case k_eWinNT:
|
||||||
|
return "Windows NT";
|
||||||
|
case k_eWin2000:
|
||||||
|
return "Windows 2000";
|
||||||
|
case k_eWinXP:
|
||||||
|
return "Windows XP";
|
||||||
|
case k_eWin2003:
|
||||||
|
return "Windows 2003";
|
||||||
|
case k_eWinVista:
|
||||||
|
return "Windows Vista";
|
||||||
|
case k_eWindows7:
|
||||||
|
return "Windows 7";
|
||||||
|
case k_eWin2008:
|
||||||
|
return "Windows 2008";
|
||||||
|
#ifdef POSIX
|
||||||
|
case k_eMacOSUnknown:
|
||||||
|
return "Mac OS";
|
||||||
|
case k_eMacOS104:
|
||||||
|
return "MacOS 10.4";
|
||||||
|
case k_eMacOS105:
|
||||||
|
return "MacOS 10.5";
|
||||||
|
case k_eMacOS1058:
|
||||||
|
return "MacOS 10.5.8";
|
||||||
|
case k_eMacOS106:
|
||||||
|
return "MacOS 10.6";
|
||||||
|
case k_eMacOS1063:
|
||||||
|
return "MacOS 10.6.3";
|
||||||
|
case k_eMacOS107:
|
||||||
|
return "MacOS 10.7";
|
||||||
|
case k_eLinuxUnknown:
|
||||||
|
return "Linux";
|
||||||
|
case k_eLinux22:
|
||||||
|
return "Linux 2.2";
|
||||||
|
case k_eLinux24:
|
||||||
|
return "Linux 2.4";
|
||||||
|
case k_eLinux26:
|
||||||
|
return "Linux 2.6";
|
||||||
|
#endif
|
||||||
|
default:
|
||||||
|
case k_eOSUnknown:
|
||||||
|
return "Unknown";
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
// friendly name to OS type, MUST be same size as EOSType enum
|
||||||
|
struct OSTypeNameTuple
|
||||||
|
{
|
||||||
|
EOSType m_OSType;
|
||||||
|
const char *m_pchOSName;
|
||||||
|
|
||||||
|
};
|
||||||
|
|
||||||
|
const OSTypeNameTuple k_rgOSTypeToName[] =
|
||||||
|
{
|
||||||
|
{ k_eOSUnknown, "unknown" },
|
||||||
|
{ k_eMacOSUnknown, "macos" },
|
||||||
|
{ k_eMacOS104, "macos104" },
|
||||||
|
{ k_eMacOS105, "macos105" },
|
||||||
|
{ k_eMacOS1058, "macos1058" },
|
||||||
|
{ k_eMacOS106, "macos106" },
|
||||||
|
{ k_eMacOS1063, "macos1063" },
|
||||||
|
{ k_eMacOS107, "macos107" },
|
||||||
|
{ k_eLinuxUnknown, "linux" },
|
||||||
|
{ k_eLinux22, "linux22" },
|
||||||
|
{ k_eLinux24, "linux24" },
|
||||||
|
{ k_eLinux26, "linux26" },
|
||||||
|
{ k_eWinUnknown, "windows" },
|
||||||
|
{ k_eWin311, "win311" },
|
||||||
|
{ k_eWin95, "win95" },
|
||||||
|
{ k_eWin98, "win98" },
|
||||||
|
{ k_eWinME, "winME" },
|
||||||
|
{ k_eWinNT, "winNT" },
|
||||||
|
{ k_eWin2000, "win200" },
|
||||||
|
{ k_eWinXP, "winXP" },
|
||||||
|
{ k_eWin2003, "win2003" },
|
||||||
|
{ k_eWinVista, "winVista" },
|
||||||
|
{ k_eWindows7, "win7" },
|
||||||
|
{ k_eWin2008, "win2008" },
|
||||||
|
};
|
||||||
|
|
||||||
|
//-----------------------------------------------------------------------------
|
||||||
|
// Purpose: convert a friendly OS name to a eostype
|
||||||
|
//-----------------------------------------------------------------------------
|
||||||
|
EOSType GetOSTypeFromString_Deprecated( const char *pchName )
|
||||||
|
{
|
||||||
|
EOSType eOSType;
|
||||||
|
#ifdef WIN32
|
||||||
|
eOSType = k_eWinUnknown;
|
||||||
|
#else
|
||||||
|
eOSType = k_eOSUnknown;
|
||||||
|
#endif
|
||||||
|
|
||||||
|
// if this fires, make sure all OS types are in the map
|
||||||
|
Assert( Q_ARRAYSIZE( k_rgOSTypeToName ) == k_eOSTypeMax );
|
||||||
|
if ( !pchName || Q_strlen( pchName ) == 0 )
|
||||||
|
return eOSType;
|
||||||
|
|
||||||
|
for ( int iOS = 0; iOS < Q_ARRAYSIZE( k_rgOSTypeToName ) ; iOS++ )
|
||||||
|
{
|
||||||
|
if ( !Q_stricmp( k_rgOSTypeToName[iOS].m_pchOSName, pchName ) )
|
||||||
|
return k_rgOSTypeToName[iOS].m_OSType;
|
||||||
|
}
|
||||||
|
return eOSType;
|
||||||
|
}
|
||||||
|
|
||||||
|
bool OSTypesAreCompatible( EOSType eOSTypeDetected, EOSType eOSTypeRequired )
|
||||||
|
{
|
||||||
|
// check windows (on the positive side of the number line)
|
||||||
|
if ( eOSTypeRequired >= k_eWinUnknown )
|
||||||
|
return ( eOSTypeDetected >= eOSTypeRequired );
|
||||||
|
|
||||||
|
if ( eOSTypeRequired == k_eOSUnknown )
|
||||||
|
return true;
|
||||||
|
|
||||||
|
// osx
|
||||||
|
if ( eOSTypeRequired >= k_eMacOSUnknown && eOSTypeRequired < k_eOSUnknown )
|
||||||
|
return ( eOSTypeDetected >= eOSTypeRequired && eOSTypeDetected < k_eOSUnknown );
|
||||||
|
|
||||||
|
// and linux
|
||||||
|
if ( eOSTypeRequired >= k_eLinuxUnknown && eOSTypeRequired < k_eMacOSUnknown )
|
||||||
|
return ( eOSTypeDetected >= eOSTypeRequired && eOSTypeDetected < k_eMacOSUnknown );
|
||||||
|
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
// these strings "windows", "macos", "linux" are part of the
|
||||||
|
// interface, which is why they're hard-coded here, rather than using
|
||||||
|
// the strings in k_rgOSTypeToName
|
||||||
|
const char *GetPlatformName( bool *pbIs64Bit )
|
||||||
|
{
|
||||||
|
if ( pbIs64Bit )
|
||||||
|
*pbIs64Bit = Is64BitOS();
|
||||||
|
|
||||||
|
EOSType eType = GetOSType();
|
||||||
|
if ( OSTypesAreCompatible( eType, k_eWinUnknown ) )
|
||||||
|
return "windows";
|
||||||
|
if ( OSTypesAreCompatible( eType, k_eMacOSUnknown ) )
|
||||||
|
return "macos";
|
||||||
|
if ( OSTypesAreCompatible( eType, k_eLinuxUnknown ) )
|
||||||
|
return "linux";
|
||||||
|
return "unknown";
|
||||||
|
}
|
||||||
|
|
||||||
@@ -21,6 +21,7 @@ def build(bld):
|
|||||||
'cvar.cpp',
|
'cvar.cpp',
|
||||||
'jobthread.cpp',
|
'jobthread.cpp',
|
||||||
'KeyValuesSystem.cpp',
|
'KeyValuesSystem.cpp',
|
||||||
|
'osversion.cpp',
|
||||||
'random.cpp',
|
'random.cpp',
|
||||||
'vcover.cpp',
|
'vcover.cpp',
|
||||||
'../public/tier0/memoverride.cpp'
|
'../public/tier0/memoverride.cpp'
|
||||||
@@ -54,7 +55,7 @@ def build(bld):
|
|||||||
elif bld.env.DEST_OS == 'darwin':
|
elif bld.env.DEST_OS == 'darwin':
|
||||||
linkflags += ['-framework', 'CoreServices']
|
linkflags += ['-framework', 'CoreServices']
|
||||||
|
|
||||||
install_path = None if bld.env.BUILD_SDK else bld.env.LIBDIR
|
install_path = bld.env.LIBDIR
|
||||||
|
|
||||||
bld.shlib(
|
bld.shlib(
|
||||||
source = source,
|
source = source,
|
||||||
|
|||||||
6
wscript
6
wscript
@@ -51,7 +51,7 @@ projects={
|
|||||||
'launcher',
|
'launcher',
|
||||||
'launcher_main',
|
'launcher_main',
|
||||||
'materialsystem',
|
'materialsystem',
|
||||||
# 'materialsystem/shaderapiempty',
|
'materialsystem/shaderapigl',
|
||||||
'materialsystem/shaderapidx9',
|
'materialsystem/shaderapidx9',
|
||||||
'materialsystem/shaderlib',
|
'materialsystem/shaderlib',
|
||||||
'materialsystem/stdshaders',
|
'materialsystem/stdshaders',
|
||||||
@@ -61,7 +61,7 @@ projects={
|
|||||||
'serverbrowser',
|
'serverbrowser',
|
||||||
'soundemittersystem',
|
'soundemittersystem',
|
||||||
'studiorender',
|
'studiorender',
|
||||||
'stub_steam',
|
'thirdparty/StubSteamAPI',
|
||||||
'tier0',
|
'tier0',
|
||||||
'tier1',
|
'tier1',
|
||||||
'tier2',
|
'tier2',
|
||||||
@@ -129,7 +129,7 @@ projects={
|
|||||||
'vpklib',
|
'vpklib',
|
||||||
'vstdlib',
|
'vstdlib',
|
||||||
'vtf',
|
'vtf',
|
||||||
'stub_steam'
|
'thirdparty/StubSteamAPI'
|
||||||
]
|
]
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user