1
0
mirror of https://github.com/alliedmodders/hl2sdk.git synced 2025-09-19 03:56:10 +08:00

* Added support for building shaders in your mod

* Added nav mesh support
* fixed many warnings and misc bugs
* Fixed the create*projects scripts in mp
* Added a bunch of stuff to .gitignore
This commit is contained in:
Joe Ludwig
2013-07-17 18:26:59 -07:00
parent 64f3b0abed
commit 0e42951d44
210 changed files with 27490 additions and 1351 deletions

View File

@ -0,0 +1,190 @@
//========= Copyright Valve Corporation, All rights reserved. ============//
//
// cglmprogram.h
// GLMgr buffers (index / vertex)
// ... maybe add PBO later as well
//===============================================================================
#ifndef CGLMBUFFER_H
#define CGLMBUFFER_H
#pragma once
//===============================================================================
extern bool g_bUsePseudoBufs;
// forward declarations
class GLMContext;
enum EGLMBufferType
{
kGLMVertexBuffer,
kGLMIndexBuffer,
kGLMUniformBuffer, // for bindable uniform
kGLMPixelBuffer, // for PBO
kGLMNumBufferTypes
};
// pass this in "options" to constructor to make a dynamic buffer
#define GLMBufferOptionDynamic 0x00000001
struct GLMBuffLockParams
{
uint m_nOffset;
uint m_nSize;
bool m_bNoOverwrite;
bool m_bDiscard;
};
#define GL_STATIC_BUFFER_SIZE ( 2048 * 1024 )
#define GL_MAX_STATIC_BUFFERS 2
extern void glBufferSubDataMaxSize( GLenum target, GLintptr offset, GLsizeiptr size, const GLvoid *data, uint nMaxSizePerCall = 128 * 1024 );
//===============================================================================
#if GL_ENABLE_INDEX_VERIFICATION
struct GLDynamicBuf_t
{
GLenum m_nGLType;
uint m_nHandle;
uint m_nActualBufSize;
uint m_nSize;
uint m_nLockOffset;
uint m_nLockSize;
};
class CGLMBufferSpanManager
{
CGLMBufferSpanManager( const CGLMBufferSpanManager& );
CGLMBufferSpanManager& operator= ( const CGLMBufferSpanManager& );
public:
CGLMBufferSpanManager();
~CGLMBufferSpanManager();
void Init( GLMContext *pContext, EGLMBufferType nBufType, uint nInitialCapacity, uint nBufSize, bool bDynamic );
void Deinit();
inline GLMContext *GetContext() const { return m_pCtx; }
inline GLenum GetGLBufType() const { return ( m_nBufType == kGLMVertexBuffer ) ? GL_ARRAY_BUFFER_ARB : GL_ELEMENT_ARRAY_BUFFER_ARB; }
struct ActiveSpan_t
{
uint m_nStart;
uint m_nEnd;
GLDynamicBuf_t m_buf;
bool m_bOriginalAlloc;
inline ActiveSpan_t() { }
inline ActiveSpan_t( uint nStart, uint nEnd, GLDynamicBuf_t &buf, bool bOriginalAlloc ) : m_nStart( nStart ), m_nEnd( nEnd ), m_buf( buf ), m_bOriginalAlloc( bOriginalAlloc ) { Assert( nStart <= nEnd ); }
};
ActiveSpan_t *AddSpan( uint nOffset, uint nMaxSize, uint nActualSize, bool bDiscard, bool bNoOverwrite );
void DiscardAllSpans();
bool IsValid( uint nOffset, uint nSize ) const;
private:
bool AllocDynamicBuf( uint nSize, GLDynamicBuf_t &buf );
void ReleaseDynamicBuf( GLDynamicBuf_t &buf );
GLMContext *m_pCtx;
EGLMBufferType m_nBufType;
uint m_nBufSize;
bool m_bDynamic;
CUtlVector<ActiveSpan_t> m_ActiveSpans;
CUtlVector<ActiveSpan_t> m_DeletedSpans;
int m_nSpanEndMax;
int m_nNumAllocatedBufs;
int m_nTotalBytesAllocated;
};
#endif // GL_ENABLE_INDEX_VERIFICATION
class CGLMBuffer
{
public:
void Lock( GLMBuffLockParams *pParams, char **pAddressOut );
void Unlock( int nActualSize = -1, const void *pActualData = NULL );
friend class GLMContext; // only GLMContext can make CGLMBuffer objects
friend class GLMTester;
friend struct IDirect3D9;
friend struct IDirect3DDevice9;
CGLMBuffer( GLMContext *pCtx, EGLMBufferType type, uint size, uint options );
~CGLMBuffer();
void SetModes( bool bAsyncMap, bool bExplicitFlush, bool bForce = false );
void FlushRange( uint offset, uint size );
#if GL_ENABLE_INDEX_VERIFICATION
bool IsSpanValid( uint nOffset, uint nSize ) const;
#endif
GLMContext *m_pCtx; // link back to parent context
EGLMBufferType m_type;
uint m_nSize;
uint m_nActualSize;
bool m_bDynamic;
GLenum m_buffGLTarget; // GL_ARRAY_BUFFER_ARB / GL_ELEMENT_BUFFER_ARB
GLuint m_nHandle; // name of this program in the context
uint m_nRevision; // bump anytime the size changes or buffer is orphaned
bool m_bEnableAsyncMap; // mirror of the buffer state
bool m_bEnableExplicitFlush; // mirror of the buffer state
bool m_bMapped; // is it currently mapped
uint m_dirtyMinOffset; // when equal, range is empty
uint m_dirtyMaxOffset;
float *m_pLastMappedAddress;
int m_nPinnedMemoryOfs;
bool m_bPseudo; // true if the m_name is 0, and the backing is plain RAM
// in pseudo mode, there is just one RAM buffer that acts as the backing.
// expectation is that this mode would only be used for dynamic indices.
// since indices have to be consumed (copied to command stream) prior to return from a drawing call,
// there's no need to do any fencing or multibuffering. orphaning in particular becomes a no-op.
char *m_pActualPseudoBuf; // storage for pseudo buffer
char *m_pPseudoBuf; // storage for pseudo buffer
char *m_pStaticBuffer;
GLMBuffLockParams m_LockParams;
static char ALIGN16 m_StaticBuffers[ GL_MAX_STATIC_BUFFERS ][ GL_STATIC_BUFFER_SIZE ] ALIGN16_POST;
static bool m_bStaticBufferUsed[ GL_MAX_STATIC_BUFFERS ];
#if GL_ENABLE_INDEX_VERIFICATION
CGLMBufferSpanManager m_BufferSpanManager;
#endif
#if GL_ENABLE_UNLOCK_BUFFER_OVERWRITE_DETECTION
uint m_nDirtyRangeStart;
uint m_nDirtyRangeEnd;
#endif
};
#endif // CGLMBUFFER_H

View File

@ -0,0 +1,82 @@
//========= Copyright Valve Corporation, All rights reserved. ============//
//
// cglmfbo.h
// GLMgr FBO's (render targets)
//
//===============================================================================
#ifndef CGLMFBO_H
#define CGLMFBO_H
#pragma once
// good FBO references / recaps
// http://www.songho.ca/opengl/gl_fbo.html
// http://www.gamedev.net/reference/articles/article2331.asp
// ext links
// http://www.opengl.org/registry/specs/EXT/framebuffer_object.txt
// http://www.opengl.org/registry/specs/EXT/framebuffer_multisample.txt
//===============================================================================
// tokens not in the SDK headers
#ifndef GL_DEPTH_STENCIL_ATTACHMENT_EXT
#define GL_DEPTH_STENCIL_ATTACHMENT_EXT 0x84F9
#endif
//===============================================================================
// forward declarations
class GLMContext;
enum EGLMFBOAttachment
{
kAttColor0, kAttColor1, kAttColor2, kAttColor3,
kAttDepth, kAttStencil, kAttDepthStencil,
kAttCount
};
struct GLMFBOTexAttachParams
{
CGLMTex *m_tex;
int m_face; // keep zero if not cube map
int m_mip; // keep zero if notmip mapped
int m_zslice; // keep zero if not a 3D tex
};
class CGLMFBO
{
friend class GLMContext;
friend class GLMTester;
friend class CGLMTex;
friend struct IDirect3D9;
friend struct IDirect3DDevice9;
public:
CGLMFBO( GLMContext *ctx );
~CGLMFBO( );
protected:
void TexAttach( GLMFBOTexAttachParams *params, EGLMFBOAttachment attachIndex, GLenum fboBindPoint = GL_FRAMEBUFFER_EXT );
void TexDetach( EGLMFBOAttachment attachIndex, GLenum fboBindPoint = GL_FRAMEBUFFER_EXT );
// you can also pass GL_READ_FRAMEBUFFER_EXT or GL_DRAW_FRAMEBUFFER_EXT to selectively bind the receiving FBO to one or the other.
void TexScrub( CGLMTex *tex );
// search and destroy any attachment for the named texture
bool IsReady( void ); // aka FBO completeness check - ready to draw
GLMContext *m_ctx; // link back to parent context
GLuint m_name; // name of this FBO in the context
GLMFBOTexAttachParams m_attach[ kAttCount ]; // indexed by EGLMFBOAttachment
};
#endif

View File

@ -0,0 +1,420 @@
//========= Copyright Valve Corporation, All rights reserved. ============//
//
// cglmprogram.h
// GLMgr programs (ARBVP/ARBfp)
//
//===============================================================================
#ifndef CGLMPROGRAM_H
#define CGLMPROGRAM_H
#include <sys/stat.h>
#pragma once
// good ARB program references
// http://petewarden.com/notes/archives/2005/05/fragment_progra_2.html
// http://petewarden.com/notes/archives/2005/06/fragment_progra_3.html
// ext links
// http://www.opengl.org/registry/specs/ARB/vertex_program.txt
// http://www.opengl.org/registry/specs/ARB/fragment_program.txt
// http://www.opengl.org/registry/specs/EXT/gpu_program_parameters.txt
//===============================================================================
// tokens not in the SDK headers
//#ifndef GL_DEPTH_STENCIL_ATTACHMENT_EXT
// #define GL_DEPTH_STENCIL_ATTACHMENT_EXT 0x84F9
//#endif
//===============================================================================
// forward declarations
class GLMContext;
class CGLMShaderPair;
class CGLMShaderPairCache;
// CGLMProgram can contain two flavors of the same program, one in assembler, one in GLSL.
// these flavors are pretty different in terms of the API's that are used to activate them -
// for example, assembler programs can just get bound to the context, whereas GLSL programs
// have to be linked. To some extent we try to hide that detail inside GLM.
// for now, make CGLMProgram a container, it does not set policy or hold a preference as to which
// flavor you want to use. GLMContext has to handle that.
enum EGLMProgramType
{
kGLMVertexProgram,
kGLMFragmentProgram,
kGLMNumProgramTypes
};
enum EGLMProgramLang
{
kGLMARB,
kGLMGLSL,
kGLMNumProgramLangs
};
struct GLMShaderDesc
{
union
{
GLuint arb; // ARB program object name
GLhandleARB glsl; // GLSL shader object handle (void*)
} m_object;
// these can change if shader text is edited
bool m_textPresent; // is this flavor(lang) of text present in the buffer?
int m_textOffset; // where is it
int m_textLength; // how big
bool m_compiled; // has this text been through a compile attempt
bool m_valid; // and if so, was the compile successful
int m_slowMark; // has it been flagged during a non native draw batch before. increment every time it's slow.
int m_highWater; // count of vec4's in the major uniform array ("vc" on vs, "pc" on ps)
// written by dxabstract.... gross!
int m_VSHighWaterBone; // count of vec4's in the bone-specific uniform array (only valid for vertex shaders)
};
GLenum GLMProgTypeToARBEnum( EGLMProgramType type ); // map vert/frag to ARB asm bind target
GLenum GLMProgTypeToGLSLEnum( EGLMProgramType type ); // map vert/frag to ARB asm bind target
#define GL_SHADER_PAIR_CACHE_STATS 0
class CGLMProgram
{
public:
friend class CGLMShaderPairCache;
friend class CGLMShaderPair;
friend class GLMContext; // only GLMContext can make CGLMProgram objects
friend class GLMTester;
friend struct IDirect3D9;
friend struct IDirect3DDevice9;
//===============================
// constructor is very light, it just makes one empty program object per flavor.
CGLMProgram( GLMContext *ctx, EGLMProgramType type );
~CGLMProgram( );
void SetProgramText ( char *text ); // import text to GLM object - invalidate any prev compiled program
void SetShaderName ( const char *name ); // only used for debugging/telemetry markup
bool CompileActiveSources ( void ); // compile only the flavors that were provided.
bool Compile ( EGLMProgramLang lang );
bool CheckValidity ( EGLMProgramLang lang );
void LogSlow ( EGLMProgramLang lang ); // detailed spew when called for first time; one liner or perhaps silence after that
void GetLabelIndexCombo ( char *labelOut, int labelOutMaxChars, int *indexOut, int *comboOut );
void GetComboIndexNameString ( char *stringOut, int stringOutMaxChars ); // mmmmmmmm-nnnnnnnn-filename
#if GLMDEBUG
bool PollForChanges( void ); // check mirror for changes.
void ReloadStringFromEditable( void ); // populate m_string from editable item (react to change)
bool SyncWithEditable( void );
#endif
//===============================
// common stuff
GLMContext *m_ctx; // link back to parent context
EGLMProgramType m_type; // vertex or pixel
uint m_nHashTag; // serial number for hashing
char *m_text; // copy of text passed into constructor. Can change if editable shaders is enabled.
// note - it can contain multiple flavors, so use CGLMTextSectioner to scan it and locate them
#if GLMDEBUG
CGLMEditableTextItem *m_editable; // editable text item for debugging
#endif
GLMShaderDesc m_descs[ kGLMNumProgramLangs ];
uint m_samplerMask; // (1<<n) mask of sampler active locs, if this is a fragment shader (dxabstract sets this field)
uint m_samplerTypes; // SAMPLER_2D, etc.
uint m_nNumUsedSamplers;
uint m_maxSamplers;
uint m_maxVertexAttrs;
uint m_nCentroidMask;
uint m_nShadowDepthSamplerMask;
bool m_bTranslatedProgram;
char m_shaderName[64];
};
//===============================================================================
struct GLMShaderPairInfo
{
int m_status; // -1 means req'd index was out of bounds (loop stop..) 0 means not present. 1 means present/active.
char m_vsName[ 128 ];
int m_vsStaticIndex;
int m_vsDynamicIndex;
char m_psName[ 128 ];
int m_psStaticIndex;
int m_psDynamicIndex;
};
class CGLMShaderPair // a container for a linked GLSL shader pair, and metadata obtained post-link
{
public:
friend class CGLMProgram;
friend class GLMContext;
friend class CGLMShaderPairCache;
//===============================
// constructor just sets up a GLSL program object and leaves it empty.
CGLMShaderPair( GLMContext *ctx );
~CGLMShaderPair( );
bool SetProgramPair ( CGLMProgram *vp, CGLMProgram *fp );
// true result means successful link and query
bool RefreshProgramPair ( void );
// re-link and re-query the uniforms
FORCEINLINE void UpdateScreenUniform( uint nWidthHeight )
{
if ( m_nScreenWidthHeight == nWidthHeight )
return;
m_nScreenWidthHeight = nWidthHeight;
uint nWidth = nWidthHeight & 0xFFFF, nHeight = nWidthHeight >> 16;
// Apply half pixel offset to output vertices to account for the pixel center difference between D3D9 and OpenGL.
// We output vertices in clip space, which ranges from [-1,1], so 1.0/width in clip space transforms into .5/width in screenspace, see: "Viewports and Clipping (Direct3D 9)" in the DXSDK
float v[4] = { 1.0f / nWidth, 1.0f / nHeight, nWidth, nHeight };
if ( m_locVertexScreenParams >= 0 )
gGL->glUniform4fv( m_locVertexScreenParams, 1, v );
}
//===============================
// common stuff
GLMContext *m_ctx; // link back to parent context
CGLMProgram *m_vertexProg;
CGLMProgram *m_fragmentProg;
GLhandleARB m_program; // linked program object
// need meta data for attribs / samplers / params
// actually we only need it for samplers and params.
// attributes are hardwired.
// vertex stage uniforms
GLint m_locVertexParams; // "vc" per dx9asmtogl2 convention
GLint m_locVertexBoneParams; // "vcbones"
GLint m_locVertexInteger0; // "i0"
GLint m_locVertexBool0; // "b0"
GLint m_locVertexBool1; // "b1"
GLint m_locVertexBool2; // "b2"
GLint m_locVertexBool3; // "b3"
bool m_bHasBoolOrIntUniforms;
// fragment stage uniforms
GLint m_locFragmentParams; // "pc" per dx9asmtogl2 convention
int m_NumUniformBufferParams[kGLMNumProgramTypes];
GLint m_UniformBufferParams[kGLMNumProgramTypes][256];
GLint m_locFragmentFakeSRGBEnable; // "flSRGBWrite" - set to 1.0 to effect sRGB encoding on output
float m_fakeSRGBEnableValue; // shadow to avoid redundant sets of the m_locFragmentFakeSRGBEnable uniform
// init it to -1.0 at link or relink, so it will trip on any legit incoming value (0.0 or 1.0)
GLint m_locSamplers[ 16 ]; // "sampler0 ... sampler1..."
// other stuff
bool m_valid; // true on successful link
uint m_revision; // if this pair is relinked, bump this number.
GLint m_locVertexScreenParams; // vcscreen
uint m_nScreenWidthHeight;
};
//===============================================================================
// N-row, M-way associative cache with LRU per row.
// still needs some metric dump ability and some parameter tuning.
// extra credit would be to make an auto-tuner.
struct CGLMPairCacheEntry
{
long long m_lastMark; // a mark of zero means an empty entry
CGLMProgram *m_vertexProg;
CGLMProgram *m_fragmentProg;
uint m_extraKeyBits;
CGLMShaderPair *m_pair;
};
class CGLMShaderPairCache // cache for linked GLSL shader pairs
{
public:
protected:
friend class CGLMShaderPair;
friend class CGLMProgram;
friend class GLMContext;
//===============================
CGLMShaderPairCache( GLMContext *ctx );
~CGLMShaderPairCache( );
FORCEINLINE CGLMShaderPair *SelectShaderPair ( CGLMProgram *vp, CGLMProgram *fp, uint extraKeyBits );
void QueryShaderPair ( int index, GLMShaderPairInfo *infoOut );
// shoot down linked pairs that use the program in the arg
// return true if any had to be skipped due to conflict with currently bound pair
bool PurgePairsWithShader( CGLMProgram *prog );
// purge everything (when would GLM know how to do this ? at context destroy time, but any other times?)
// return true if any had to be skipped due to conflict with currently bound pair
bool Purge ( void );
// stats
void DumpStats ( void );
//===============================
FORCEINLINE uint HashRowIndex( CGLMProgram *vp, CGLMProgram *fp, uint extraKeyBits ) const;
FORCEINLINE CGLMPairCacheEntry* HashRowPtr( uint hashRowIndex ) const;
FORCEINLINE void HashRowProbe( CGLMPairCacheEntry *row, CGLMProgram *vp, CGLMProgram *fp, uint extraKeyBits, int &hitway, int &emptyway, int &oldestway );
CGLMShaderPair *SelectShaderPairInternal( CGLMProgram *vp, CGLMProgram *fp, uint extraKeyBits, int rowIndex );
//===============================
// common stuff
GLMContext *m_ctx; // link back to parent context
long long m_mark;
uint m_rowsLg2;
uint m_rows;
uint m_rowsMask;
uint m_waysLg2;
uint m_ways;
uint m_entryCount;
CGLMPairCacheEntry *m_entries; // array[ m_rows ][ m_ways ]
uint *m_evictions; // array[ m_rows ];
#if GL_SHADER_PAIR_CACHE_STATS
uint *m_hits; // array[ m_rows ];
#endif
};
FORCEINLINE uint CGLMShaderPairCache::HashRowIndex( CGLMProgram *vp, CGLMProgram *fp, uint extraKeyBits ) const
{
return ( vp->m_nHashTag + fp->m_nHashTag + extraKeyBits * 7 ) & m_rowsMask;
}
FORCEINLINE CGLMPairCacheEntry* CGLMShaderPairCache::HashRowPtr( uint hashRowIndex ) const
{
return &m_entries[ hashRowIndex * m_ways ];
}
FORCEINLINE void CGLMShaderPairCache::HashRowProbe( CGLMPairCacheEntry *row, CGLMProgram *vp, CGLMProgram *fp, uint extraKeyBits, int& hitway, int& emptyway, int& oldestway )
{
hitway = -1;
emptyway = -1;
oldestway = -1;
// scan this row to see if the desired pair is present
CGLMPairCacheEntry *cursor = row;
long long oldestmark = 0xFFFFFFFFFFFFFFFFLL;
for( uint way = 0; way < m_ways; ++way )
{
if ( cursor->m_lastMark != 0 ) // occupied slot
{
// check if this is the oldest one on the row - only occupied slots are checked
if ( cursor->m_lastMark < oldestmark )
{
oldestway = way;
oldestmark = cursor->m_lastMark;
}
if ( ( cursor->m_vertexProg == vp ) && ( cursor->m_fragmentProg == fp ) && ( cursor->m_extraKeyBits == extraKeyBits ) ) // match?
{
// found it
hitway = way;
break;
}
}
else
{
// empty way, log it if first one seen
if (emptyway<0)
{
emptyway = way;
}
}
cursor++;
}
}
FORCEINLINE CGLMShaderPair *CGLMShaderPairCache::SelectShaderPair( CGLMProgram *vp, CGLMProgram *fp, uint extraKeyBits )
{
// select row where pair would be found if it exists
uint rowIndex = HashRowIndex( vp, fp, extraKeyBits );
CGLMPairCacheEntry *pCursor = HashRowPtr( rowIndex );
if ( ( pCursor->m_fragmentProg != fp ) || ( pCursor->m_vertexProg != vp ) || ( pCursor->m_extraKeyBits != extraKeyBits ) )
{
CGLMPairCacheEntry *pLastCursor = pCursor + m_ways;
++pCursor;
while ( pCursor != pLastCursor )
{
if ( ( pCursor->m_fragmentProg == fp ) && ( pCursor->m_vertexProg == vp ) && ( pCursor->m_extraKeyBits == extraKeyBits ) ) // match?
break;
++pCursor;
};
if ( pCursor == pLastCursor )
return SelectShaderPairInternal( vp, fp, extraKeyBits, rowIndex );
}
// found it. mark it and return
pCursor->m_lastMark = m_mark++;
#if GL_SHADER_PAIR_CACHE_STATS
// count the hit
m_hits[ rowIndex ] ++;
#endif
return pCursor->m_pair;
}
#endif

View File

@ -0,0 +1,90 @@
//========= Copyright Valve Corporation, All rights reserved. ============//
//
// cglmquery.h
// GLMgr queries
//
//===============================================================================
#ifndef CGLMQUERY_H
#define CGLMQUERY_H
#pragma once
#ifdef OSX
#include "glmgr/glmgrbasics.h"
#endif
//===============================================================================
// forward declarations
class GLMContext;
class CGLMQuery;
//===============================================================================
enum EGLMQueryType
{
EOcclusion,
EFence,
EGLMQueryCount
};
struct GLMQueryParams
{
EGLMQueryType m_type;
};
class CGLMQuery
{
// leave everything public til it's running
public:
friend class GLMContext; // only GLMContext can make CGLMTex objects
friend struct IDirect3DDevice9;
friend struct IDirect3DQuery9;
GLMContext *m_ctx; // link back to parent context
GLMQueryParams m_params; // params created with
GLuint m_name; // name of the query object per se - could be fence, could be query object ... NOT USED WITH GL_ARB_sync!
#ifdef HAVE_GL_ARB_SYNC
GLsync m_syncobj; // GL_ARB_sync object. NOT USED WITH GL_NV_fence or GL_APPLE_fence!
#else
GLuint m_syncobj;
#endif
bool m_started;
bool m_stopped;
bool m_done;
bool m_nullQuery; // was gl_nullqueries true at Start time - if so, continue to act like a null query through Stop/IsDone/Complete time
// restated - only Start should examine the convar.
static uint s_nTotalOcclusionQueryCreatesOrDeletes;
CGLMQuery( GLMContext *ctx, GLMQueryParams *params );
~CGLMQuery( );
// for an occlusion query:
// Start = BeginQuery query-start goes into stream
// Stop = EndQuery query-end goes into stream - a fence is also set so we can probe for completion
// IsDone = TestFence use the added fence to ask if query-end has passed (i.e. will Complete block?)
// Complete = GetQueryObjectuivARB(uint id, enum pname, uint *params) - extract the sample count
// for a fence query:
// Start = SetFence fence goes into command stream
// Stop = NOP fences are self finishing - no need to call Stop on a fence
// IsDone = TestFence ask if fence passed
// Complete = FinishFence
void Start ( void );
void Stop ( void );
bool IsDone ( void );
void Complete ( uint *result );
// accessors for the started/stopped state
bool IsStarted ( void );
bool IsStopped ( void );
};
#endif

View File

@ -0,0 +1,502 @@
//========= Copyright Valve Corporation, All rights reserved. ============//
//
// cglmtex.h
// GLMgr textures
//
//===============================================================================
#ifndef CGLMTEX_H
#define CGLMTEX_H
#pragma once
#ifdef OSX
#include "glmgr/glmgrbasics.h"
#endif
#include "tier1/utlhash.h"
#include "tier1/utlmap.h"
//===============================================================================
// forward declarations
class GLMContext;
class GLMTester;
class CGLMTexLayoutTable;
class CGLMTex;
class CGLMFBO;
struct IDirect3DSurface9;
#if GLMDEBUG
extern CGLMTex *g_pFirstCGMLTex;
#endif
// For GL_EXT_texture_sRGB_decode
#ifndef GL_TEXTURE_SRGB_DECODE_EXT
#define GL_TEXTURE_SRGB_DECODE_EXT 0x8A48
#endif
#ifndef GL_DECODE_EXT
#define GL_DECODE_EXT 0x8A49
#endif
#ifndef GL_SKIP_DECODE_EXT
#define GL_SKIP_DECODE_EXT 0x8A4A
#endif
//===============================================================================
struct GLMTexFormatDesc
{
const char *m_formatSummary; // for debug visibility
D3DFORMAT m_d3dFormat; // what D3D knows it as; see public/bitmap/imageformat.h
GLenum m_glIntFormat; // GL internal format
GLenum m_glIntFormatSRGB; // internal format if SRGB flavor
GLenum m_glDataFormat; // GL data format
GLenum m_glDataType; // GL data type
int m_chunkSize; // 1 or 4 - 4 is used for compressed textures
int m_bytesPerSquareChunk; // how many bytes for the smallest quantum (m_chunkSize x m_chunkSize)
// this description lets us calculate size cleanly without conditional logic for compression
};
const GLMTexFormatDesc *GetFormatDesc( D3DFORMAT format );
//===============================================================================
// utility function for generating slabs of texels. mostly for test.
typedef struct
{
// in
D3DFORMAT m_format;
void *m_dest; // dest address
int m_chunkCount; // square chunk count (single texels or compressed blocks)
int m_byteCountLimit; // caller expectation of max number of bytes to write out
float r,g,b,a; // color desired
// out
int m_bytesWritten;
} GLMGenTexelParams;
// return true if successful
bool GLMGenTexels( GLMGenTexelParams *params );
//===============================================================================
struct GLMTexLayoutSlice
{
int m_xSize,m_ySize,m_zSize; //texel dimensions of this slice
int m_storageOffset; //where in the storage slab does this slice live
int m_storageSize; //how much storage does this slice occupy
};
enum EGLMTexFlags
{
kGLMTexMipped = 0x01,
kGLMTexMippedAuto = 0x02,
kGLMTexRenderable = 0x04,
kGLMTexIsStencil = 0x08,
kGLMTexIsDepth = 0x10,
kGLMTexSRGB = 0x20,
kGLMTexMultisampled = 0x40, // has an RBO backing it. Cannot combine with Mipped, MippedAuto. One slice maximum, only targeting GL_TEXTURE_2D.
// actually not 100% positive on the mipmapping, the RBO itself can't be mipped, but the resulting texture could
// have mipmaps generated.
};
//===============================================================================
struct GLMTexLayoutKey
{
// input values: held const, these are the hash key for the form map
GLenum m_texGLTarget; // flavor of texture: GL_TEXTURE_2D, GL_TEXTURE_3D, GLTEXTURE_CUBE_MAP
D3DFORMAT m_texFormat; // D3D texel format
unsigned long m_texFlags; // mipped, autogen mips, render target, ... ?
unsigned long m_texSamples; // zero for a plain tex, 2/4/6/8 for "MSAA tex" (RBO backed)
int m_xSize,m_ySize,m_zSize; // size of base mip
};
bool LessFunc_GLMTexLayoutKey( const GLMTexLayoutKey &a, const GLMTexLayoutKey &b );
#define GLM_TEX_MAX_MIPS 14
#define GLM_TEX_MAX_FACES 6
#define GLM_TEX_MAX_SLICES (GLM_TEX_MAX_MIPS * GLM_TEX_MAX_FACES)
#pragma warning( push )
#pragma warning( disable : 4200 )
struct GLMTexLayout
{
char *m_layoutSummary; // for debug visibility
// const inputs used for hashing
GLMTexLayoutKey m_key;
// refcount
int m_refCount;
// derived values:
GLMTexFormatDesc *m_format; // format specific info
int m_mipCount; // derived by starying at base size and working down towards 1x1
int m_faceCount; // 1 for 2d/3d, 6 for cubemap
int m_sliceCount; // product of faces and mips
int m_storageTotalSize; // size of storage slab required
// slice array
GLMTexLayoutSlice m_slices[0]; // dynamically allocated 2-d array [faces][mips]
};
#pragma warning( pop )
class CGLMTexLayoutTable
{
public:
CGLMTexLayoutTable();
GLMTexLayout *NewLayoutRef( GLMTexLayoutKey *pDesiredKey ); // pass in a pointer to layout key - receive ptr to completed layout
void DelLayoutRef( GLMTexLayout *layout ); // pass in pointer to completed layout. refcount is dropped.
void DumpStats( void );
protected:
CUtlMap< GLMTexLayoutKey, GLMTexLayout* > m_layoutMap;
};
//===============================================================================
// a sampler specifies desired state for drawing on a given sampler index
// this is the combination of a texture choice and a set of sampler parameters
// see http://msdn.microsoft.com/en-us/library/bb172602(VS.85).aspx
struct GLMTexLockParams
{
// input params which identify the slice of interest
CGLMTex *m_tex;
int m_face;
int m_mip;
// identifies the region of the slice
GLMRegion m_region;
// tells GLM to force re-read of the texels back from GL
// i.e. "I know I stepped on those texels with a draw or blit - the GLM copy is stale"
bool m_readback;
};
struct GLMTexLockDesc
{
GLMTexLockParams m_req; // form of the lock request
bool m_active; // set true at lock time. cleared at unlock time.
int m_sliceIndex; // which slice in the layout
int m_sliceBaseOffset; // where is that in the texture data
int m_sliceRegionOffset; // offset to the start (lowest address corner) of the region requested
};
//===============================================================================
#define GLM_SAMPLER_COUNT 16
typedef CBitVec<GLM_SAMPLER_COUNT> CTexBindMask;
enum EGLMTexSliceFlag
{
kSliceValid = 0x01, // slice has been teximage'd in whole at least once - set to 0 initially
kSliceStorageValid = 0x02, // if backing store is available, this slice's data is a valid copy - set to 0 initially
kSliceLocked = 0x04, // are one or more locks outstanding on this slice
kSliceFullyDirty = 0x08, // does the slice need to be fully downloaded at unlock time (disregard dirty rects)
};
//===============================================================================
#define GLM_PACKED_SAMPLER_PARAMS_ADDRESS_BITS (2)
#define GLM_PACKED_SAMPLER_PARAMS_MIN_FILTER_BITS (2)
#define GLM_PACKED_SAMPLER_PARAMS_MAG_FILTER_BITS (2)
#define GLM_PACKED_SAMPLER_PARAMS_MIP_FILTER_BITS (2)
#define GLM_PACKED_SAMPLER_PARAMS_MIN_LOD_BITS (4)
#define GLM_PACKED_SAMPLER_PARAMS_MAX_ANISO_BITS (5)
#define GLM_PACKED_SAMPLER_PARAMS_COMPARE_MODE_BITS (1)
#define GLM_PACKED_SAMPLER_PARAMS_SRGB_BITS (1)
struct GLMTexPackedSamplingParams
{
uint32 m_addressU : GLM_PACKED_SAMPLER_PARAMS_ADDRESS_BITS;
uint32 m_addressV : GLM_PACKED_SAMPLER_PARAMS_ADDRESS_BITS;
uint32 m_addressW : GLM_PACKED_SAMPLER_PARAMS_ADDRESS_BITS;
uint32 m_minFilter : GLM_PACKED_SAMPLER_PARAMS_MIN_FILTER_BITS;
uint32 m_magFilter : GLM_PACKED_SAMPLER_PARAMS_MAG_FILTER_BITS;
uint32 m_mipFilter : GLM_PACKED_SAMPLER_PARAMS_MIP_FILTER_BITS;
uint32 m_minLOD : GLM_PACKED_SAMPLER_PARAMS_MIN_LOD_BITS;
uint32 m_maxAniso : GLM_PACKED_SAMPLER_PARAMS_MAX_ANISO_BITS;
uint32 m_compareMode : GLM_PACKED_SAMPLER_PARAMS_COMPARE_MODE_BITS;
uint32 m_srgb : GLM_PACKED_SAMPLER_PARAMS_SRGB_BITS;
uint32 m_isValid : 1;
};
struct GLMTexSamplingParams
{
union
{
GLMTexPackedSamplingParams m_packed;
uint32 m_bits;
};
uint32 m_borderColor;
FORCEINLINE bool operator== (const GLMTexSamplingParams& rhs ) const
{
return ( m_bits == rhs.m_bits ) && ( m_borderColor == rhs.m_borderColor );
}
FORCEINLINE void SetToDefaults()
{
m_bits = 0;
m_borderColor = 0;
m_packed.m_addressU = D3DTADDRESS_WRAP;
m_packed.m_addressV = D3DTADDRESS_WRAP;
m_packed.m_addressW = D3DTADDRESS_WRAP;
m_packed.m_minFilter = D3DTEXF_POINT;
m_packed.m_magFilter = D3DTEXF_POINT;
m_packed.m_mipFilter = D3DTEXF_NONE;
m_packed.m_maxAniso = 1;
m_packed.m_isValid = true;
}
FORCEINLINE void SetToSamplerObject( GLuint nSamplerObject ) const
{
static const GLenum dxtogl_addressMode[] = { GL_REPEAT, GL_CLAMP_TO_EDGE, GL_CLAMP_TO_BORDER, (GLenum)-1 };
static const GLenum dxtogl_magFilter[4] = { GL_NEAREST, GL_NEAREST, GL_LINEAR, GL_LINEAR };
static const GLenum dxtogl_minFilter[4][4] = // indexed by _D3DTEXTUREFILTERTYPE on both axes: [row is min filter][col is mip filter].
{
/* min = D3DTEXF_NONE */ { GL_NEAREST, GL_NEAREST_MIPMAP_NEAREST, GL_NEAREST_MIPMAP_LINEAR, (GLenum)-1 }, // D3DTEXF_NONE we just treat like POINT
/* min = D3DTEXF_POINT */ { GL_NEAREST, GL_NEAREST_MIPMAP_NEAREST, GL_NEAREST_MIPMAP_LINEAR, (GLenum)-1 },
/* min = D3DTEXF_LINEAR */ { GL_LINEAR, GL_LINEAR_MIPMAP_NEAREST, GL_LINEAR_MIPMAP_LINEAR, (GLenum)-1 },
/* min = D3DTEXF_ANISOTROPIC */ { GL_LINEAR, GL_LINEAR_MIPMAP_NEAREST, GL_LINEAR_MIPMAP_LINEAR, (GLenum)-1 }, // no diff from prior row, set maxAniso to effect the sampling
};
gGL->glSamplerParameteri( nSamplerObject, GL_TEXTURE_WRAP_S, dxtogl_addressMode[m_packed.m_addressU] );
gGL->glSamplerParameteri( nSamplerObject, GL_TEXTURE_WRAP_T, dxtogl_addressMode[m_packed.m_addressV] );
gGL->glSamplerParameteri( nSamplerObject, GL_TEXTURE_WRAP_R, dxtogl_addressMode[m_packed.m_addressW] );
gGL->glSamplerParameteri( nSamplerObject, GL_TEXTURE_MIN_FILTER, dxtogl_minFilter[m_packed.m_minFilter][m_packed.m_mipFilter] );
gGL->glSamplerParameteri( nSamplerObject, GL_TEXTURE_MAG_FILTER, dxtogl_magFilter[m_packed.m_magFilter] );
gGL->glSamplerParameteri( nSamplerObject, GL_TEXTURE_MAX_ANISOTROPY_EXT, m_packed.m_maxAniso );
float flBorderColor[4] = { 0, 0, 0, 0 };
if ( m_borderColor )
{
flBorderColor[0] = ((m_borderColor >> 16) & 0xFF) * (1.0f/255.0f); //R
flBorderColor[1] = ((m_borderColor >> 8) & 0xFF) * (1.0f/255.0f); //G
flBorderColor[2] = ((m_borderColor ) & 0xFF) * (1.0f/255.0f); //B
flBorderColor[3] = ((m_borderColor >> 24) & 0xFF) * (1.0f/255.0f); //A
}
gGL->glSamplerParameterfv( nSamplerObject, GL_TEXTURE_BORDER_COLOR, flBorderColor ); // <-- this crashes ATI's driver, remark it out
gGL->glSamplerParameteri( nSamplerObject, GL_TEXTURE_MIN_LOD, m_packed.m_minLOD );
gGL->glSamplerParameteri( nSamplerObject, GL_TEXTURE_COMPARE_MODE_ARB, m_packed.m_compareMode ? GL_COMPARE_R_TO_TEXTURE_ARB : GL_NONE );
if ( m_packed.m_compareMode )
{
gGL->glSamplerParameteri( nSamplerObject, GL_TEXTURE_COMPARE_FUNC_ARB, GL_LEQUAL );
}
if ( gGL->m_bHave_GL_EXT_texture_sRGB_decode )
{
gGL->glSamplerParameteri( nSamplerObject, GL_TEXTURE_SRGB_DECODE_EXT, m_packed.m_srgb ? GL_DECODE_EXT : GL_SKIP_DECODE_EXT );
}
}
inline void DeltaSetToTarget( GLenum target, const GLMTexSamplingParams &curState )
{
static const GLenum dxtogl_addressMode[] = { GL_REPEAT, GL_CLAMP_TO_EDGE, GL_CLAMP_TO_BORDER, (GLenum)-1 };
static const GLenum dxtogl_magFilter[4] = { GL_NEAREST, GL_NEAREST, GL_LINEAR, GL_LINEAR };
static const GLenum dxtogl_minFilter[4][4] = // indexed by _D3DTEXTUREFILTERTYPE on both axes: [row is min filter][col is mip filter].
{
/* min = D3DTEXF_NONE */ { GL_NEAREST, GL_NEAREST_MIPMAP_NEAREST, GL_NEAREST_MIPMAP_LINEAR, (GLenum)-1 }, // D3DTEXF_NONE we just treat like POINT
/* min = D3DTEXF_POINT */ { GL_NEAREST, GL_NEAREST_MIPMAP_NEAREST, GL_NEAREST_MIPMAP_LINEAR, (GLenum)-1 },
/* min = D3DTEXF_LINEAR */ { GL_LINEAR, GL_LINEAR_MIPMAP_NEAREST, GL_LINEAR_MIPMAP_LINEAR, (GLenum)-1 },
/* min = D3DTEXF_ANISOTROPIC */ { GL_LINEAR, GL_LINEAR_MIPMAP_NEAREST, GL_LINEAR_MIPMAP_LINEAR, (GLenum)-1 }, // no diff from prior row, set maxAniso to effect the sampling
};
if ( m_packed.m_addressU != curState.m_packed.m_addressU )
{
gGL->glTexParameteri( target, GL_TEXTURE_WRAP_S, dxtogl_addressMode[m_packed.m_addressU] );
}
if ( m_packed.m_addressV != curState.m_packed.m_addressV )
{
gGL->glTexParameteri( target, GL_TEXTURE_WRAP_T, dxtogl_addressMode[m_packed.m_addressV] );
}
if ( m_packed.m_addressW != curState.m_packed.m_addressW )
{
gGL->glTexParameteri( target, GL_TEXTURE_WRAP_R, dxtogl_addressMode[m_packed.m_addressW] );
}
if ( ( m_packed.m_minFilter != curState.m_packed.m_minFilter ) ||
( m_packed.m_magFilter != curState.m_packed.m_magFilter ) ||
( m_packed.m_mipFilter != curState.m_packed.m_mipFilter ) ||
( m_packed.m_maxAniso != curState.m_packed.m_maxAniso ) )
{
gGL->glTexParameteri( target, GL_TEXTURE_MIN_FILTER, dxtogl_minFilter[m_packed.m_minFilter][m_packed.m_mipFilter] );
gGL->glTexParameteri( target, GL_TEXTURE_MAG_FILTER, dxtogl_magFilter[m_packed.m_magFilter] );
gGL->glTexParameteri( target, GL_TEXTURE_MAX_ANISOTROPY_EXT, m_packed.m_maxAniso );
}
if ( m_borderColor != curState.m_borderColor )
{
float flBorderColor[4] = { 0, 0, 0, 0 };
if ( m_borderColor )
{
flBorderColor[0] = ((m_borderColor >> 16) & 0xFF) * (1.0f/255.0f); //R
flBorderColor[1] = ((m_borderColor >> 8) & 0xFF) * (1.0f/255.0f); //G
flBorderColor[2] = ((m_borderColor ) & 0xFF) * (1.0f/255.0f); //B
flBorderColor[3] = ((m_borderColor >> 24) & 0xFF) * (1.0f/255.0f); //A
}
gGL->glTexParameterfv( target, GL_TEXTURE_BORDER_COLOR, flBorderColor ); // <-- this crashes ATI's driver, remark it out
}
if ( m_packed.m_minLOD != curState.m_packed.m_minLOD )
{
gGL->glTexParameteri( target, GL_TEXTURE_MIN_LOD, m_packed.m_minLOD );
}
if ( m_packed.m_compareMode != curState.m_packed.m_compareMode )
{
gGL->glTexParameteri( target, GL_TEXTURE_COMPARE_MODE_ARB, m_packed.m_compareMode ? GL_COMPARE_R_TO_TEXTURE_ARB : GL_NONE );
if ( m_packed.m_compareMode )
{
gGL->glTexParameteri( target, GL_TEXTURE_COMPARE_FUNC_ARB, GL_LEQUAL );
}
}
if ( ( gGL->m_bHave_GL_EXT_texture_sRGB_decode ) && ( m_packed.m_srgb != curState.m_packed.m_srgb ) )
{
gGL->glTexParameteri( target, GL_TEXTURE_SRGB_DECODE_EXT, m_packed.m_srgb ? GL_DECODE_EXT : GL_SKIP_DECODE_EXT );
}
}
inline void SetToTargetTexture( GLenum target )
{
static const GLenum dxtogl_addressMode[] = { GL_REPEAT, GL_CLAMP_TO_EDGE, GL_CLAMP_TO_BORDER, (GLenum)-1 };
static const GLenum dxtogl_magFilter[4] = { GL_NEAREST, GL_NEAREST, GL_LINEAR, GL_LINEAR };
static const GLenum dxtogl_minFilter[4][4] = // indexed by _D3DTEXTUREFILTERTYPE on both axes: [row is min filter][col is mip filter].
{
/* min = D3DTEXF_NONE */ { GL_NEAREST, GL_NEAREST_MIPMAP_NEAREST, GL_NEAREST_MIPMAP_LINEAR, (GLenum)-1 }, // D3DTEXF_NONE we just treat like POINT
/* min = D3DTEXF_POINT */ { GL_NEAREST, GL_NEAREST_MIPMAP_NEAREST, GL_NEAREST_MIPMAP_LINEAR, (GLenum)-1 },
/* min = D3DTEXF_LINEAR */ { GL_LINEAR, GL_LINEAR_MIPMAP_NEAREST, GL_LINEAR_MIPMAP_LINEAR, (GLenum)-1 },
/* min = D3DTEXF_ANISOTROPIC */ { GL_LINEAR, GL_LINEAR_MIPMAP_NEAREST, GL_LINEAR_MIPMAP_LINEAR, (GLenum)-1 }, // no diff from prior row, set maxAniso to effect the sampling
};
gGL->glTexParameteri( target, GL_TEXTURE_WRAP_S, dxtogl_addressMode[m_packed.m_addressU] );
gGL->glTexParameteri( target, GL_TEXTURE_WRAP_T, dxtogl_addressMode[m_packed.m_addressV] );
gGL->glTexParameteri( target, GL_TEXTURE_WRAP_R, dxtogl_addressMode[m_packed.m_addressW] );
gGL->glTexParameteri( target, GL_TEXTURE_MIN_FILTER, dxtogl_minFilter[m_packed.m_minFilter][m_packed.m_mipFilter] );
gGL->glTexParameteri( target, GL_TEXTURE_MAG_FILTER, dxtogl_magFilter[m_packed.m_magFilter] );
gGL->glTexParameteri( target, GL_TEXTURE_MAX_ANISOTROPY_EXT, m_packed.m_maxAniso );
float flBorderColor[4] = { 0, 0, 0, 0 };
if ( m_borderColor )
{
flBorderColor[0] = ((m_borderColor >> 16) & 0xFF) * (1.0f/255.0f); //R
flBorderColor[1] = ((m_borderColor >> 8) & 0xFF) * (1.0f/255.0f); //G
flBorderColor[2] = ((m_borderColor ) & 0xFF) * (1.0f/255.0f); //B
flBorderColor[3] = ((m_borderColor >> 24) & 0xFF) * (1.0f/255.0f); //A
}
gGL->glTexParameterfv( target, GL_TEXTURE_BORDER_COLOR, flBorderColor ); // <-- this crashes ATI's driver, remark it out
gGL->glTexParameteri( target, GL_TEXTURE_MIN_LOD, m_packed.m_minLOD );
gGL->glTexParameteri( target, GL_TEXTURE_COMPARE_MODE_ARB, m_packed.m_compareMode ? GL_COMPARE_R_TO_TEXTURE_ARB : GL_NONE );
if ( m_packed.m_compareMode )
{
gGL->glTexParameteri( target, GL_TEXTURE_COMPARE_FUNC_ARB, GL_LEQUAL );
}
if ( gGL->m_bHave_GL_EXT_texture_sRGB_decode )
{
gGL->glTexParameteri( target, GL_TEXTURE_SRGB_DECODE_EXT, m_packed.m_srgb ? GL_DECODE_EXT : GL_SKIP_DECODE_EXT );
}
}
};
//===============================================================================
class CGLMTex
{
public:
void Lock( GLMTexLockParams *params, char** addressOut, int* yStrideOut, int *zStrideOut );
void Unlock( GLMTexLockParams *params );
protected:
friend class GLMContext; // only GLMContext can make CGLMTex objects
friend class GLMTester;
friend class CGLMFBO;
friend struct IDirect3DDevice9;
friend struct IDirect3DBaseTexture9;
friend struct IDirect3DTexture9;
friend struct IDirect3DSurface9;
friend struct IDirect3DCubeTexture9;
friend struct IDirect3DVolumeTexture9;
CGLMTex( GLMContext *ctx, GLMTexLayout *layout, const char *debugLabel = NULL );
~CGLMTex( );
int CalcSliceIndex( int face, int mip );
void CalcTexelDataOffsetAndStrides( int sliceIndex, int x, int y, int z, int *offsetOut, int *yStrideOut, int *zStrideOut );
void ReadTexels( GLMTexLockDesc *desc, bool readWholeSlice=true );
void WriteTexels( GLMTexLockDesc *desc, bool writeWholeSlice=true, bool noDataWrite=false );
// last param lets us send NULL data ptr (only legal with uncompressed formats, beware)
// this helps out ResetSRGB.
bool IsRBODirty() const;
void ForceRBONonDirty();
void ForceRBODirty();
void AllocBacking();
void ReleaseBacking();
// re-specify texture format to match desired sRGB form
// noWrite means send NULL for texel source addresses instead of actual data - ideal for RT's
GLuint m_texName; // name of this texture in the context
GLenum m_texGLTarget;
uint m_nSamplerType; // SAMPLER_2D, etc.
GLMTexSamplingParams m_SamplingParams;
GLMTexLayout *m_layout; // layout of texture (shared across all tex with same layout)
uint m_nLastResolvedBatchCounter;
int m_minActiveMip;//index of lowest mip that has been written. used to drive setting of GL_TEXTURE_MAX_LEVEL.
int m_maxActiveMip;//index of highest mip that has been written. used to drive setting of GL_TEXTURE_MAX_LEVEL.
int m_mipCount;
GLMContext *m_ctx; // link back to parent context
CGLMFBO *m_pBlitSrcFBO;
CGLMFBO *m_pBlitDstFBO;
GLuint m_rboName; // name of MSAA RBO backing the tex if MSAA enabled (or zero)
int m_rtAttachCount; // how many RT's have this texture attached somewhere
char *m_pBacking; // backing storage if available
int m_lockCount; // lock reqs are stored in the GLMContext for tracking
CUtlVector<unsigned char> m_sliceFlags;
char *m_debugLabel; // strdup() of debugLabel passed in, or NULL
bool m_texClientStorage; // was CS selected for texture
bool m_texPreloaded; // has it been kicked into VRAM with GLMContext::PreloadTex yet
#if GLMDEBUG
CGLMTex *m_pPrevTex;
CGLMTex *m_pNextTex;
#endif
};
#endif

File diff suppressed because it is too large Load Diff

File diff suppressed because it is too large Load Diff

View File

@ -0,0 +1,104 @@
//========= Copyright Valve Corporation, All rights reserved. ============//
//
// glbase.h
//
//===============================================================================
#ifndef GLBASE_H
#define GLBASE_H
#ifdef DX_TO_GL_ABSTRACTION
#undef HAVE_GL_ARB_SYNC
#ifndef OSX
#define HAVE_GL_ARB_SYNC 1
#endif
#ifdef OSX
#include <OpenGL/OpenGL.h>
#include <OpenGL/gl.h>
#include <OpenGL/glext.h>
#include <OpenGL/CGLTypes.h>
#include <OpenGL/CGLRenderers.h>
#include <OpenGL/CGLCurrent.h>
#include <OpenGL/CGLProfiler.h>
#include <ApplicationServices/ApplicationServices.h>
#elif defined(DX_TO_GL_ABSTRACTION)
#include <GL/gl.h>
#include <GL/glext.h>
#else
#error
#endif
#ifdef DX_TO_GL_ABSTRACTION
#ifndef WIN32
#define Debugger DebuggerBreak
#endif
#undef CurrentTime
// prevent some conflicts in SDL headers...
#undef M_PI
#include <stdint.h>
#ifndef _STDINT_H_
#define _STDINT_H_ 1
#endif
#endif
//===============================================================================
// glue to call out to Obj-C land (these are in glmgrcocoa.mm)
#ifdef OSX
bool NewNSGLContext( unsigned long *attribs, PseudoNSGLContextPtr nsglShareCtx, PseudoNSGLContextPtr *nsglCtxOut, CGLContextObj *cglCtxOut );
CGLContextObj GetCGLContextFromNSGL( PseudoNSGLContextPtr nsglCtx );
void DelNSGLContext( PseudoNSGLContextPtr nsglCtx );
#endif
// Set TOGL_SUPPORT_NULL_DEVICE to 1 to support the NULL ref device
#define TOGL_SUPPORT_NULL_DEVICE 0
#if TOGL_SUPPORT_NULL_DEVICE
#define TOGL_NULL_DEVICE_CHECK if( m_params.m_deviceType == D3DDEVTYPE_NULLREF ) return S_OK;
#define TOGL_NULL_DEVICE_CHECK_RET_VOID if( m_params.m_deviceType == D3DDEVTYPE_NULLREF ) return;
#else
#define TOGL_NULL_DEVICE_CHECK
#define TOGL_NULL_DEVICE_CHECK_RET_VOID
#endif
// GL_ENABLE_INDEX_VERIFICATION enables index range verification on all dynamic IB/VB's (obviously slow)
#define GL_ENABLE_INDEX_VERIFICATION 0
// GL_ENABLE_UNLOCK_BUFFER_OVERWRITE_DETECTION (currently win32 only) - If 1, VirtualAlloc/VirtualProtect is used to detect cases where the app locks a buffer, copies the ptr away, unlocks, then tries to later write to the buffer.
#define GL_ENABLE_UNLOCK_BUFFER_OVERWRITE_DETECTION 0
#define GL_BATCH_TELEMETRY_ZONES 0
// GL_BATCH_PERF_ANALYSIS - Enables gl_batch_vis, and various per-batch telemetry statistics messages.
#define GL_BATCH_PERF_ANALYSIS 0
#define GL_BATCH_PERF_ANALYSIS_WRITE_PNGS 0
// GL_TELEMETRY_ZONES - Causes every single OpenGL call to generate a telemetry event
#define GL_TELEMETRY_ZONES 0
// GL_DUMP_ALL_API_CALLS - Causes a debug message to be printed for every API call if s_bDumpCalls bool is set to 1
#define GL_DUMP_ALL_API_CALLS 0
// Must also enable PIX_ENABLE to use GL_TELEMETRY_GPU_ZONES.
#define GL_TELEMETRY_GPU_ZONES 0
// Records global # of OpenGL calls/total cycles spent inside GL
#define GL_TRACK_API_TIME GL_BATCH_PERF_ANALYSIS
#define GL_USE_EXECUTE_HELPER_FOR_ALL_API_CALLS ( GL_TELEMETRY_ZONES || GL_TRACK_API_TIME || GL_DUMP_ALL_API_CALLS )
#if GL_BATCH_PERF_ANALYSIS
#define GL_BATCH_PERF(...) __VA_ARGS__
#else
#define GL_BATCH_PERF(...)
#endif
#define kGLMUserClipPlanes 2
#define kGLMScratchFBOCount 4
#endif // DX_TO_GL_ABSTRACTION
#endif // GLBASE_H

View File

@ -0,0 +1,378 @@
//========= Copyright Valve Corporation, All rights reserved. ============//
//
// glentrypoints.h
//
//===============================================================================
#ifndef GLENTRYPOINTS_H
#define GLENTRYPOINTS_H
#pragma once
#ifdef DX_TO_GL_ABSTRACTION
#include "tier0/platform.h"
#include "tier0/dynfunction.h"
#include "tier0/vprof_telemetry.h"
#include "interface.h"
#include "togl/rendermechanism.h"
void *VoidFnPtrLookup_GlMgr(const char *fn, bool &okay, const bool bRequired, void *fallback=NULL);
#if GL_USE_EXECUTE_HELPER_FOR_ALL_API_CALLS
class CGLExecuteHelperBase
{
public:
inline void StartCall(const char *pName);
inline void StopCall(const char *pName);
#if GL_TRACK_API_TIME
TmU64 m_nStartTime;
#endif
};
template < class FunctionType, typename Result >
class CGLExecuteHelper : public CGLExecuteHelperBase
{
public:
inline CGLExecuteHelper(FunctionType pFn, const char *pName ) : m_pFn( pFn ) { StartCall(pName); m_Result = (*m_pFn)(); StopCall(pName); }
template<typename A> inline CGLExecuteHelper(FunctionType pFn, const char *pName, A a) : m_pFn( pFn ) { StartCall(pName); m_Result = (*m_pFn)(a); StopCall(pName); }
template<typename A, typename B> inline CGLExecuteHelper(FunctionType pFn, const char *pName, A a, B b) : m_pFn( pFn ) { StartCall(pName); m_Result = (*m_pFn)(a, b); StopCall(pName); }
template<typename A, typename B, typename C> inline CGLExecuteHelper(FunctionType pFn, const char *pName, A a, B b, C c) : m_pFn( pFn ) { StartCall(pName); m_Result = (*m_pFn)(a, b, c); StopCall(pName); }
template<typename A, typename B, typename C, typename D> inline CGLExecuteHelper(FunctionType pFn, const char *pName, A a, B b, C c, D d) : m_pFn( pFn ) { StartCall(pName); m_Result = (*m_pFn)(a, b, c, d); StopCall(pName); }
template<typename A, typename B, typename C, typename D, typename E> inline CGLExecuteHelper(FunctionType pFn, const char *pName, A a, B b, C c, D d, E e) : m_pFn( pFn ) { StartCall(pName); m_Result = (*m_pFn)(a, b, c, d, e); StopCall(pName); }
template<typename A, typename B, typename C, typename D, typename E, typename F> inline CGLExecuteHelper(FunctionType pFn, const char *pName, A a, B b, C c, D d, E e, F f) : m_pFn( pFn ) { StartCall(pName); m_Result = (*m_pFn)(a, b, c, d, e, f); StopCall(pName); }
template<typename A, typename B, typename C, typename D, typename E, typename F, typename G> inline CGLExecuteHelper(FunctionType pFn, const char *pName, A a, B b, C c, D d, E e, F f, G g) : m_pFn( pFn ) { StartCall(pName); m_Result = (*m_pFn)(a, b, c, d, e, f, g); StopCall(pName); }
template<typename A, typename B, typename C, typename D, typename E, typename F, typename G, typename H> inline CGLExecuteHelper(FunctionType pFn, const char *pName, A a, B b, C c, D d, E e, F f, G g, H h) : m_pFn( pFn ) { StartCall(pName); m_Result = (*m_pFn)(a, b, c, d, e, f, g, h); StopCall(pName); }
template<typename A, typename B, typename C, typename D, typename E, typename F, typename G, typename H, typename I> inline CGLExecuteHelper(FunctionType pFn, const char *pName, A a, B b, C c, D d, E e, F f, G g, H h, I i) : m_pFn( pFn ) { StartCall(pName); m_Result = (*m_pFn)(a, b, c, d, e, f, g, h, i); StopCall(pName); }
template<typename A, typename B, typename C, typename D, typename E, typename F, typename G, typename H, typename I, typename J> inline CGLExecuteHelper(FunctionType pFn, const char *pName, A a, B b, C c, D d, E e, F f, G g, H h, I i, J j) : m_pFn( pFn ) { StartCall(pName); m_Result = (*m_pFn)(a, b, c, d, e, f, g, h, i, j); StopCall(pName); }
inline operator Result() const { return m_Result; }
inline operator char*() const { return (char*)m_Result; }
FunctionType m_pFn;
Result m_Result;
};
template < class FunctionType>
class CGLExecuteHelper<FunctionType, void> : public CGLExecuteHelperBase
{
public:
inline CGLExecuteHelper(FunctionType pFn, const char *pName ) : m_pFn( pFn ) { StartCall(pName); (*m_pFn)(); StopCall(pName); }
template<typename A> inline CGLExecuteHelper(FunctionType pFn, const char *pName, A a) : m_pFn( pFn ) { StartCall(pName); (*m_pFn)(a); StopCall(pName); }
template<typename A, typename B> inline CGLExecuteHelper(FunctionType pFn, const char *pName, A a, B b) : m_pFn( pFn ) { StartCall(pName); (*m_pFn)(a, b); StopCall(pName); }
template<typename A, typename B, typename C> inline CGLExecuteHelper(FunctionType pFn, const char *pName, A a, B b, C c) : m_pFn( pFn ) { StartCall(pName); (*m_pFn)(a, b, c); StopCall(pName); }
template<typename A, typename B, typename C, typename D> inline CGLExecuteHelper(FunctionType pFn, const char *pName, A a, B b, C c, D d) : m_pFn( pFn ) { StartCall(pName); (*m_pFn)(a, b, c, d); StopCall(pName); }
template<typename A, typename B, typename C, typename D, typename E> inline CGLExecuteHelper(FunctionType pFn, const char *pName, A a, B b, C c, D d, E e) : m_pFn( pFn ) { StartCall(pName); (*m_pFn)(a, b, c, d, e); StopCall(pName); }
template<typename A, typename B, typename C, typename D, typename E, typename F> inline CGLExecuteHelper(FunctionType pFn, const char *pName, A a, B b, C c, D d, E e, F f) : m_pFn( pFn ) { StartCall(pName); (*m_pFn)(a, b, c, d, e, f); StopCall(pName); }
template<typename A, typename B, typename C, typename D, typename E, typename F, typename G> inline CGLExecuteHelper(FunctionType pFn, const char *pName, A a, B b, C c, D d, E e, F f, G g) : m_pFn( pFn ) { StartCall(pName); (*m_pFn)(a, b, c, d, e, f, g); StopCall(pName); }
template<typename A, typename B, typename C, typename D, typename E, typename F, typename G, typename H> inline CGLExecuteHelper(FunctionType pFn, const char *pName, A a, B b, C c, D d, E e, F f, G g, H h) : m_pFn( pFn ) { StartCall(pName); (*m_pFn)(a, b, c, d, e, f, g, h); StopCall(pName); }
template<typename A, typename B, typename C, typename D, typename E, typename F, typename G, typename H, typename I> inline CGLExecuteHelper(FunctionType pFn, const char *pName, A a, B b, C c, D d, E e, F f, G g, H h, I i) : m_pFn( pFn ) { StartCall(pName); (*m_pFn)(a, b, c, d, e, f, g, h, i); StopCall(pName); }
template<typename A, typename B, typename C, typename D, typename E, typename F, typename G, typename H, typename I, typename J> inline CGLExecuteHelper(FunctionType pFn, const char *pName, A a, B b, C c, D d, E e, F f, G g, H h, I i, J j) : m_pFn( pFn ) { StartCall(pName); (*m_pFn)(a, b, c, d, e, f, g, h, i, j); StopCall(pName); }
FunctionType m_pFn;
};
#endif
template < class FunctionType, typename Result >
class CDynamicFunctionOpenGLBase
{
public:
// Construct with a NULL function pointer. You must manually call
// Lookup() before you can call a dynamic function through this interface.
CDynamicFunctionOpenGLBase() : m_pFn(NULL) {}
// Construct and do a lookup right away. You will need to make sure that
// the lookup actually succeeded, as the gl library might have failed to load
// or (fn) might not exist in it.
CDynamicFunctionOpenGLBase(const char *fn, FunctionType fallback=NULL) : m_pFn(NULL)
{
Lookup(fn, fallback);
}
// Construct and do a lookup right away. See comments in Lookup() about what (okay) does.
CDynamicFunctionOpenGLBase(const char *fn, bool &okay, FunctionType fallback=NULL) : m_pFn(NULL)
{
Lookup(fn, okay, fallback);
}
// Load library if necessary, look up symbol. Returns true and sets
// m_pFn on successful lookup, returns false otherwise. If the
// function pointer is already looked up, this return true immediately.
// Use Reset() first if you want to look up the symbol again.
// This function will return false immediately unless (okay) is true.
// This allows you to chain lookups like this:
// bool okay = true;
// x.Lookup(lib, "x", okay);
// y.Lookup(lib, "y", okay);
// z.Lookup(lib, "z", okay);
// if (okay) { printf("All functions were loaded successfully!\n"); }
// If you supply a fallback, it'll be used if the lookup fails (and if
// non-NULL, means this will always return (okay)).
bool Lookup(const char *fn, bool &okay, FunctionType fallback=NULL)
{
if (!okay)
return false;
else if (this->m_pFn == NULL)
{
this->m_pFn = (FunctionType) VoidFnPtrLookup_GlMgr(fn, okay, false, (void *) fallback);
this->SetFuncName( fn );
}
okay = m_pFn != NULL;
return okay;
}
// Load library if necessary, look up symbol. Returns true and sets
// m_pFn on successful lookup, returns false otherwise. If the
// function pointer is already looked up, this return true immediately.
// Use Reset() first if you want to look up the symbol again.
// This function will return false immediately unless (okay) is true.
// If you supply a fallback, it'll be used if the lookup fails (and if
// non-NULL, means this will always return true).
bool Lookup(const char *fn, FunctionType fallback=NULL)
{
bool okay = true;
return Lookup(fn, okay, fallback);
}
// Invalidates the current lookup. Makes the function pointer NULL. You
// will need to call Lookup() before you can call a dynamic function
// through this interface again.
void Reset() { m_pFn = NULL; }
// Force this to be a specific function pointer.
void Force(FunctionType ptr) { m_pFn = ptr; }
// Retrieve the actual function pointer.
FunctionType Pointer() const { return m_pFn; }
#if GL_USE_EXECUTE_HELPER_FOR_ALL_API_CALLS
#if GL_TELEMETRY_ZONES || GL_DUMP_ALL_API_CALLS
#define GL_FUNC_NAME m_szName
#else
#define GL_FUNC_NAME ""
#endif
inline CGLExecuteHelper<FunctionType, Result> operator() () const { return CGLExecuteHelper<FunctionType, Result>(m_pFn, GL_FUNC_NAME ); }
template<typename T>
inline CGLExecuteHelper<FunctionType, Result> operator() (T a) const { return CGLExecuteHelper<FunctionType, Result>(m_pFn, GL_FUNC_NAME, a); }
template<typename T, typename U>
inline CGLExecuteHelper<FunctionType, Result> operator() (T a, U b) const { return CGLExecuteHelper<FunctionType, Result>(m_pFn, GL_FUNC_NAME, a, b); }
template<typename T, typename U, typename V>
inline CGLExecuteHelper<FunctionType, Result> operator() (T a, U b, V c ) const { return CGLExecuteHelper<FunctionType, Result>(m_pFn, GL_FUNC_NAME, a, b, c); }
template<typename T, typename U, typename V, typename W>
inline CGLExecuteHelper<FunctionType, Result> operator() (T a, U b, V c, W d) const { return CGLExecuteHelper<FunctionType, Result>(m_pFn, GL_FUNC_NAME, a, b, c, d); }
template<typename T, typename U, typename V, typename W, typename X>
inline CGLExecuteHelper<FunctionType, Result> operator() (T a, U b, V c, W d, X e) const { return CGLExecuteHelper<FunctionType, Result>(m_pFn, GL_FUNC_NAME, a, b, c, d, e); }
template<typename T, typename U, typename V, typename W, typename X, typename Y>
inline CGLExecuteHelper<FunctionType, Result> operator() (T a, U b, V c, W d, X e, Y f) const { return CGLExecuteHelper<FunctionType, Result>(m_pFn, GL_FUNC_NAME, a, b, c, d, e, f); }
template<typename T, typename U, typename V, typename W, typename X, typename Y, typename Z>
inline CGLExecuteHelper<FunctionType, Result> operator() (T a, U b, V c, W d, X e, Y f, Z g) const { return CGLExecuteHelper<FunctionType, Result>(m_pFn, GL_FUNC_NAME, a, b, c, d, e, f, g); }
template<typename T, typename U, typename V, typename W, typename X, typename Y, typename Z, typename A>
inline CGLExecuteHelper<FunctionType, Result> operator() (T a, U b, V c, W d, X e, Y f, Z g, A h) const { return CGLExecuteHelper<FunctionType, Result>(m_pFn, GL_FUNC_NAME, a, b, c, d, e, f, g, h); }
template<typename T, typename U, typename V, typename W, typename X, typename Y, typename Z, typename A, typename B>
inline CGLExecuteHelper<FunctionType, Result> operator() (T a, U b, V c, W d, X e, Y f, Z g, A h, B i) const { return CGLExecuteHelper<FunctionType, Result>(m_pFn, GL_FUNC_NAME, a, b, c, d, e, f, g, h, i); }
template<typename T, typename U, typename V, typename W, typename X, typename Y, typename Z, typename A, typename B, typename C>
inline CGLExecuteHelper<FunctionType, Result> operator() (T a, U b, V c, W d, X e, Y f, Z g, A h, B i, C j) const { return CGLExecuteHelper<FunctionType, Result>(m_pFn, GL_FUNC_NAME, a, b, c, d, e, f, g, h, i, j); }
#else
operator FunctionType() const { return m_pFn; }
#endif
// Can be used to verify that we have an actual function looked up and
// ready to call: if (!MyDynFunc) { printf("Function not found!\n"); }
operator bool () const { return m_pFn != NULL; }
bool operator !() const { return m_pFn == NULL; }
protected:
FunctionType m_pFn;
#if GL_TELEMETRY_ZONES || GL_DUMP_ALL_API_CALLS
char m_szName[32];
inline void SetFuncName(const char *pFn) { V_strncpy( m_szName, pFn, sizeof( m_szName ) ); }
#else
inline void SetFuncName(const char *pFn) { (void)pFn; }
#endif
};
// This works a lot like CDynamicFunctionMustInit, but we use SDL_GL_GetProcAddress().
template < const bool bRequired, class FunctionType, typename Result >
class CDynamicFunctionOpenGL : public CDynamicFunctionOpenGLBase< FunctionType, Result >
{
private: // forbid default constructor.
CDynamicFunctionOpenGL() {}
public:
CDynamicFunctionOpenGL(const char *fn, FunctionType fallback=NULL)
{
bool okay = true;
Lookup(fn, okay, fallback);
this->SetFuncName( fn );
}
CDynamicFunctionOpenGL(const char *fn, bool &okay, FunctionType fallback=NULL)
{
Lookup(fn, okay, fallback);
this->SetFuncName( fn );
}
// Please note this is not virtual.
// !!! FIXME: we might want to fall back and try "EXT" or "ARB" versions in some case.
bool Lookup(const char *fn, bool &okay, FunctionType fallback=NULL)
{
if (this->m_pFn == NULL)
{
this->m_pFn = (FunctionType) VoidFnPtrLookup_GlMgr(fn, okay, bRequired, (void *) fallback);
this->SetFuncName( fn );
}
return okay;
}
};
enum GLDriverStrings_t
{
cGLVendorString,
cGLRendererString,
cGLVersionString,
cGLExtensionsString,
cGLTotalDriverStrings
};
enum GLDriverProvider_t
{
cGLDriverProviderUnknown,
cGLDriverProviderNVIDIA,
cGLDriverProviderAMD,
cGLDriverProviderIntel,
cGLDriverProviderIntelOpenSource,
cGLDriverProviderApple,
cGLTotalDriverProviders
};
// This provides all the entry points for a given OpenGL context.
// ENTRY POINTS ARE ONLY VALID FOR THE CONTEXT THAT WAS CURRENT WHEN
// YOU LOOKED THEM UP. 99% of the time, this is not a problem, but
// that 1% is really hard to track down. Always access the GL
// through this class!
class COpenGLEntryPoints
{
COpenGLEntryPoints( const COpenGLEntryPoints & );
COpenGLEntryPoints &operator= ( const COpenGLEntryPoints & );
public:
// The GL context you are looking up entry points for must be current when you construct this object!
COpenGLEntryPoints();
~COpenGLEntryPoints();
void ClearEntryPoints();
uint64 m_nTotalGLCycles, m_nTotalGLCalls;
int m_nOpenGLVersionMajor; // if GL_VERSION is 2.1.0, this will be set to 2.
int m_nOpenGLVersionMinor; // if GL_VERSION is 2.1.0, this will be set to 1.
int m_nOpenGLVersionPatch; // if GL_VERSION is 2.1.0, this will be set to 0.
bool m_bHave_OpenGL;
char *m_pGLDriverStrings[cGLTotalDriverStrings];
GLDriverProvider_t m_nDriverProvider;
#define GL_EXT(x,glmajor,glminor) bool m_bHave_##x;
#define GL_FUNC(ext,req,ret,fn,arg,call) CDynamicFunctionOpenGL< req, ret (APIENTRY *) arg, ret > fn;
#define GL_FUNC_VOID(ext,req,fn,arg,call) CDynamicFunctionOpenGL< req, void (APIENTRY *) arg, void > fn;
#include "togl/glfuncs.inl"
#undef GL_FUNC_VOID
#undef GL_FUNC
#undef GL_EXT
bool HasSwapTearExtension() const
{
#ifdef _WIN32
return m_bHave_WGL_EXT_swap_control_tear;
#else
return m_bHave_GLX_EXT_swap_control_tear;
#endif
}
};
// This will be set to the current OpenGL context's entry points.
extern COpenGLEntryPoints *gGL;
typedef void * (*GL_GetProcAddressCallbackFunc_t)(const char *, bool &, const bool, void *);
#ifdef TOGL_DLL_EXPORT
DLL_EXPORT COpenGLEntryPoints *ToGLConnectLibraries( CreateInterfaceFn factory );
DLL_EXPORT void ToGLDisconnectLibraries();
DLL_EXPORT COpenGLEntryPoints *GetOpenGLEntryPoints(GL_GetProcAddressCallbackFunc_t callback);
DLL_EXPORT void ClearOpenGLEntryPoints();
#else
DLL_IMPORT COpenGLEntryPoints *ToGLConnectLibraries( CreateInterfaceFn factory );
DLL_IMPORT void ToGLDisconnectLibraries();
DLL_IMPORT COpenGLEntryPoints *GetOpenGLEntryPoints(GL_GetProcAddressCallbackFunc_t callback);
DLL_IMPORT void ClearOpenGLEntryPoints();
#endif
#if GL_USE_EXECUTE_HELPER_FOR_ALL_API_CALLS
inline void CGLExecuteHelperBase::StartCall(const char *pName)
{
(void)pName;
#if GL_TELEMETRY_ZONES
tmEnter( TELEMETRY_LEVEL3, TMZF_NONE, pName );
#endif
#if GL_TRACK_API_TIME
m_nStartTime = tmFastTime();
#endif
#if GL_DUMP_ALL_API_CALLS
static bool s_bDumpCalls;
if ( s_bDumpCalls )
{
char buf[128];
buf[0] = 'G';
buf[1] = 'L';
buf[2] = ':';
size_t l = strlen( pName );
memcpy( buf + 3, pName, l );
buf[3 + l] = '\n';
buf[4 + l] = '\0';
Plat_DebugString( buf );
}
#endif
}
inline void CGLExecuteHelperBase::StopCall(const char *pName)
{
#if GL_TRACK_API_TIME
uint64 nTotalCycles = tmFastTime() - m_nStartTime;
#endif
#if GL_TELEMETRY_ZONES
tmLeave( TELEMETRY_LEVEL3 );
#endif
#if GL_TRACK_API_TIME
//double flMilliseconds = g_Telemetry.flRDTSCToMilliSeconds * nTotalCycles;
if (gGL)
{
gGL->m_nTotalGLCycles += nTotalCycles;
gGL->m_nTotalGLCalls++;
}
#endif
}
#endif
#endif // DX_TO_GL_ABSTRACTION
#endif // GLENTRYPOINTS_H

View File

@ -0,0 +1,236 @@
//========= Copyright Valve Corporation, All rights reserved. ============//
// !!! FIXME: Some of these aren't base OpenGL...pick out the extensions.
// !!! FIXME: Also, look up these -1, -1 versions numbers.
GL_FUNC(OpenGL,true,GLenum,glGetError,(void),())
GL_FUNC_VOID(OpenGL,true,glActiveTexture,(GLenum a),(a))
GL_FUNC_VOID(OpenGL,true,glAlphaFunc,(GLenum a,GLclampf b),(a,b))
GL_FUNC_VOID(OpenGL,true,glAttachObjectARB,(GLhandleARB a,GLhandleARB b),(a,b))
GL_FUNC_VOID(OpenGL,true,glBegin,(GLenum a),(a))
GL_FUNC_VOID(OpenGL,true,glBindAttribLocationARB,(GLhandleARB a,GLuint b,const GLcharARB *c),(a,b,c))
GL_FUNC_VOID(OpenGL,true,glBindBufferARB,(GLenum a,GLuint b),(a,b))
GL_FUNC_VOID(OpenGL,true,glBindProgramARB,(GLenum a,GLuint b),(a,b))
GL_FUNC_VOID(OpenGL,true,glBindTexture,(GLenum a,GLuint b),(a,b))
GL_FUNC_VOID(OpenGL,true,glBlendColor,(GLclampf a,GLclampf b,GLclampf c,GLclampf d),(a,b,c,d))
GL_FUNC_VOID(OpenGL,true,glBlendEquation,(GLenum a),(a))
GL_FUNC_VOID(OpenGL,true,glBlendFunc,(GLenum a,GLenum b),(a,b))
GL_FUNC_VOID(OpenGL,true,glBufferDataARB,(GLenum a,GLsizeiptrARB b,const GLvoid *c,GLenum d),(a,b,c,d))
GL_FUNC_VOID(OpenGL,true,glClear,(GLbitfield a),(a))
GL_FUNC_VOID(OpenGL,true,glClearColor,(GLclampf a,GLclampf b,GLclampf c,GLclampf d),(a,b,c,d))
GL_FUNC_VOID(OpenGL,true,glClearDepth,(GLclampd a),(a))
GL_FUNC_VOID(OpenGL,true,glClearStencil,(GLint a),(a))
GL_FUNC_VOID(OpenGL,true,glClipPlane,(GLenum a,const GLdouble *b),(a,b))
GL_FUNC_VOID(OpenGL,true,glColorMask,(GLboolean a,GLboolean b,GLboolean c,GLboolean d),(a,b,c,d))
GL_FUNC_VOID(OpenGL,true,glCompileShaderARB,(GLhandleARB a),(a))
GL_FUNC_VOID(OpenGL,true,glCompressedTexImage2D,(GLenum a,GLint b,GLenum c,GLsizei d,GLsizei e,GLint f,GLsizei g,const GLvoid *h),(a,b,c,d,e,f,g,h))
GL_FUNC_VOID(OpenGL,true,glCompressedTexImage3D,(GLenum a,GLint b,GLenum c,GLsizei d,GLsizei e,GLsizei f,GLint g,GLsizei h,const GLvoid *i),(a,b,c,d,e,f,g,h,i))
GL_FUNC(OpenGL,true,GLhandleARB,glCreateProgramObjectARB,(void),())
GL_FUNC(OpenGL,true,GLhandleARB,glCreateShaderObjectARB,(GLenum a),(a))
GL_FUNC_VOID(OpenGL,true,glDeleteBuffersARB,(GLsizei a,const GLuint *b),(a,b))
GL_FUNC_VOID(OpenGL,true,glDeleteObjectARB,(GLhandleARB a),(a))
GL_FUNC_VOID(OpenGL,true,glDeleteProgramsARB,(GLsizei a,const GLuint *b),(a,b))
GL_FUNC_VOID(OpenGL,true,glDeleteQueriesARB,(GLsizei a,const GLuint *b),(a,b))
GL_FUNC_VOID(OpenGL,true,glDeleteShader,(GLuint a),(a))
GL_FUNC_VOID(OpenGL,true,glDeleteTextures,(GLsizei a,const GLuint *b),(a,b))
GL_FUNC_VOID(OpenGL,true,glDepthFunc,(GLenum a),(a))
GL_FUNC_VOID(OpenGL,true,glDepthMask,(GLboolean a),(a))
GL_FUNC_VOID(OpenGL,true,glDepthRange,(GLclampd a,GLclampd b),(a,b))
GL_FUNC_VOID(OpenGL,true,glDetachObjectARB,(GLhandleARB a,GLhandleARB b),(a,b))
GL_FUNC_VOID(OpenGL,true,glDisable,(GLenum a),(a))
GL_FUNC_VOID(OpenGL,true,glDisableVertexAttribArray,(GLuint a),(a))
GL_FUNC_VOID(OpenGL,true,glDrawArrays,(GLenum a,GLint b,GLsizei c),(a,b,c))
GL_FUNC_VOID(OpenGL,true,glDrawBuffer,(GLenum a),(a))
GL_FUNC_VOID(OpenGL,true,glDrawRangeElements,(GLenum a,GLuint b,GLuint c,GLsizei d,GLenum e,const GLvoid *f),(a,b,c,d,e,f))
GL_FUNC_VOID(OpenGL,true,glDrawRangeElementsBaseVertex,(GLenum a,GLuint b,GLuint c,GLsizei d,GLenum e,const GLvoid *f, GLenum g),(a,b,c,d,e,f,g))
GL_FUNC_VOID(OpenGL,true,glEnable,(GLenum a),(a))
GL_FUNC_VOID(OpenGL,true,glEnableVertexAttribArray,(GLuint a),(a))
GL_FUNC_VOID(OpenGL,true,glEnd,(void),())
GL_FUNC_VOID(OpenGL,true,glFinish,(void),())
GL_FUNC_VOID(OpenGL,true,glFlush,(void),())
GL_FUNC_VOID(OpenGL,true,glFrontFace,(GLenum a),(a))
GL_FUNC_VOID(OpenGL,true,glGenBuffersARB,(GLsizei a,GLuint *b),(a,b))
GL_FUNC_VOID(OpenGL,true,glGenProgramsARB,(GLsizei a,GLuint *b),(a,b))
GL_FUNC_VOID(OpenGL,true,glGenQueriesARB,(GLsizei a,GLuint *b),(a,b))
GL_FUNC_VOID(OpenGL,true,glGenTextures,(GLsizei a,GLuint *b),(a,b))
GL_FUNC_VOID(OpenGL,true,glGetBooleanv,(GLenum a,GLboolean *b),(a,b))
GL_FUNC_VOID(OpenGL,true,glGetCompressedTexImage,(GLenum a,GLint b,GLvoid *c),(a,b,c))
GL_FUNC_VOID(OpenGL,true,glGetDoublev,(GLenum a,GLdouble *b),(a,b))
GL_FUNC_VOID(OpenGL,true,glGetFloatv,(GLenum a,GLfloat *b),(a,b))
GL_FUNC_VOID(OpenGL,true,glGetInfoLogARB,(GLhandleARB a,GLsizei b,GLsizei *c,GLcharARB *d),(a,b,c,d))
GL_FUNC_VOID(OpenGL,true,glGetIntegerv,(GLenum a,GLint *b),(a,b))
GL_FUNC_VOID(OpenGL,true,glGetObjectParameterivARB,(GLhandleARB a,GLenum b,GLint *c),(a,b,c))
GL_FUNC_VOID(OpenGL,true,glGetProgramivARB,(GLenum a,GLenum b,GLint *c),(a,b,c))
GL_FUNC(OpenGL,true,const GLubyte *,glGetString,(GLenum a),(a))
GL_FUNC_VOID(OpenGL,true,glGetTexImage,(GLenum a,GLint b,GLenum c,GLenum d,GLvoid *e),(a,b,c,d,e))
GL_FUNC(OpenGL,true,GLint,glGetUniformLocationARB,(GLhandleARB a,const GLcharARB *b),(a,b))
GL_FUNC(OpenGL,true,GLboolean,glIsEnabled,(GLenum a),(a))
GL_FUNC(OpenGL,true,GLboolean,glIsTexture,(GLuint a),(a))
GL_FUNC_VOID(OpenGL,true,glLinkProgramARB,(GLhandleARB a),(a))
GL_FUNC(OpenGL,true,GLvoid*,glMapBufferARB,(GLenum a,GLenum b),(a,b))
GL_FUNC_VOID(OpenGL,true,glOrtho,(GLdouble a,GLdouble b,GLdouble c,GLdouble d,GLdouble e,GLdouble f),(a,b,c,d,e,f))
GL_FUNC_VOID(OpenGL,true,glPixelStorei,(GLenum a,GLint b),(a,b))
GL_FUNC_VOID(OpenGL,true,glPolygonMode,(GLenum a,GLenum b),(a,b))
GL_FUNC_VOID(OpenGL,true,glPolygonOffset,(GLfloat a,GLfloat b),(a,b))
GL_FUNC_VOID(OpenGL,true,glPopAttrib,(void),())
GL_FUNC_VOID(OpenGL,true,glProgramStringARB,(GLenum a,GLenum b,GLsizei c,const GLvoid *d),(a,b,c,d))
GL_FUNC_VOID(OpenGL,true,glPushAttrib,(GLbitfield a),(a))
GL_FUNC_VOID(OpenGL,true,glReadBuffer,(GLenum a),(a))
GL_FUNC_VOID(OpenGL,true,glScissor,(GLint a,GLint b,GLsizei c,GLsizei d),(a,b,c,d))
GL_FUNC_VOID(OpenGL,true,glShaderSourceARB,(GLhandleARB a,GLsizei b,const GLcharARB **c,const GLint *d),(a,b,c,d))
GL_FUNC_VOID(OpenGL,true,glStencilFunc,(GLenum a,GLint b,GLuint c),(a,b,c))
GL_FUNC_VOID(OpenGL,true,glStencilMask,(GLuint a),(a))
GL_FUNC_VOID(OpenGL,true,glStencilOp,(GLenum a,GLenum b,GLenum c),(a,b,c))
GL_FUNC_VOID(OpenGL,true,glTexCoord2f,(GLfloat a,GLfloat b),(a,b))
GL_FUNC_VOID(OpenGL,true,glTexImage2D,(GLenum a,GLint b,GLint c,GLsizei d,GLsizei e,GLint f,GLenum g,GLenum h,const GLvoid *i),(a,b,c,d,e,f,g,h,i))
GL_FUNC_VOID(OpenGL,true,glTexImage3D,(GLenum a,GLint b,GLint c,GLsizei d,GLsizei e,GLsizei f,GLint g,GLenum h,GLenum i,const GLvoid *j),(a,b,c,d,e,f,g,h,i,j))
GL_FUNC_VOID(OpenGL,true,glTexParameterfv,(GLenum a,GLenum b,const GLfloat *c),(a,b,c))
GL_FUNC_VOID(OpenGL,true,glTexParameteri,(GLenum a,GLenum b,GLint c),(a,b,c))
GL_FUNC_VOID(OpenGL,true,glTexSubImage2D,(GLenum a,GLint b,GLint c,GLint d,GLsizei e,GLsizei f,GLenum g,GLenum h,const GLvoid *i),(a,b,c,d,e,f,g,h,i))
GL_FUNC_VOID(OpenGL,true,glUniform1f,(GLint a,GLfloat b),(a,b))
GL_FUNC_VOID(OpenGL,true,glUniform1i,(GLint a,GLint b),(a,b))
GL_FUNC_VOID(OpenGL,true,glUniform1iARB,(GLint a,GLint b),(a,b))
GL_FUNC_VOID(OpenGL,true,glUniform4fv,(GLint a,GLsizei b,const GLfloat *c),(a,b,c))
GL_FUNC(OpenGL,true,GLboolean,glUnmapBuffer,(GLenum a),(a))
GL_FUNC_VOID(OpenGL,true,glUseProgram,(GLuint a),(a))
GL_FUNC_VOID(OpenGL,true,glVertex3f,(GLfloat a,GLfloat b,GLfloat c),(a,b,c))
GL_FUNC_VOID(OpenGL,true,glVertexAttribPointer,(GLuint a,GLint b,GLenum c,GLboolean d,GLsizei e,const GLvoid *f),(a,b,c,d,e,f))
GL_FUNC_VOID(OpenGL,true,glViewport,(GLint a,GLint b,GLsizei c,GLsizei d),(a,b,c,d))
GL_FUNC_VOID(OpenGL,true,glEnableClientState,(GLenum a),(a))
GL_FUNC_VOID(OpenGL,true,glDisableClientState,(GLenum a),(a))
GL_FUNC_VOID(OpenGL,true,glClientActiveTexture,(GLenum a),(a))
GL_FUNC_VOID(OpenGL,true,glVertexPointer,(GLint a,GLenum b,GLsizei c,const GLvoid *d),(a,b,c,d))
GL_FUNC_VOID(OpenGL,true,glTexCoordPointer,(GLint a,GLenum b,GLsizei c,const GLvoid *d),(a,b,c,d))
GL_FUNC_VOID(OpenGL,true,glProgramEnvParameters4fvEXT,(GLenum a,GLuint b,GLsizei c,const GLfloat *d),(a,b,c,d))
GL_FUNC_VOID(OpenGL,true,glColor4sv,(const GLshort *a),(a))
GL_FUNC_VOID(OpenGL,true,glStencilOpSeparate,(GLenum a,GLenum b,GLenum c,GLenum d),(a,b,c,d))
GL_FUNC_VOID(OpenGL,true,glStencilFuncSeparate,(GLenum a,GLenum b,GLint c,GLuint d),(a,b,c,d))
GL_FUNC_VOID(OpenGL,true,glGetTexLevelParameteriv,(GLenum a,GLint b,GLenum c,GLint *d),(a,b,c,d))
GL_FUNC_VOID(OpenGL,true,glColor4f,(GLfloat a,GLfloat b,GLfloat c,GLfloat d),(a,b,c,d))
GL_EXT(GL_EXT_framebuffer_object,-1,-1)
GL_FUNC_VOID(GL_EXT_framebuffer_object,false,glBindFramebufferEXT,(GLenum a,GLuint b),(a,b))
GL_FUNC_VOID(GL_EXT_framebuffer_object,false,glBindRenderbufferEXT,(GLenum a,GLuint b),(a,b))
GL_FUNC(GL_EXT_framebuffer_object,false,GLenum,glCheckFramebufferStatusEXT,(GLenum a),(a))
GL_FUNC_VOID(GL_EXT_framebuffer_object,false,glDeleteRenderbuffersEXT,(GLsizei a,const GLuint *b),(a,b))
GL_FUNC_VOID(GL_EXT_framebuffer_object,false,glFramebufferRenderbufferEXT,(GLenum a,GLenum b,GLenum c,GLuint d),(a,b,c,d))
GL_FUNC_VOID(GL_EXT_framebuffer_object,false,glFramebufferTexture2DEXT,(GLenum a,GLenum b,GLenum c,GLuint d,GLint e),(a,b,c,d,e))
GL_FUNC_VOID(GL_EXT_framebuffer_object,false,glFramebufferTexture3DEXT,(GLenum a,GLenum b,GLenum c,GLuint d,GLint e,GLint f),(a,b,c,d,e,f))
GL_FUNC_VOID(GL_EXT_framebuffer_object,false,glGenFramebuffersEXT,(GLsizei a,GLuint *b),(a,b))
GL_FUNC_VOID(GL_EXT_framebuffer_object,false,glGenRenderbuffersEXT,(GLsizei a,GLuint *b),(a,b))
GL_FUNC_VOID(GL_EXT_framebuffer_object,false,glDeleteFramebuffersEXT,(GLsizei a,const GLuint *b),(a,b))
GL_EXT(GL_EXT_framebuffer_blit,-1,-1)
GL_FUNC_VOID(GL_EXT_framebuffer_blit,false,glBlitFramebufferEXT,(GLint a,GLint b,GLint c,GLint d,GLint e,GLint f,GLint g,GLint h,GLbitfield i,GLenum j),(a,b,c,d,e,f,g,h,i,j))
GL_EXT(GL_EXT_framebuffer_multisample,-1,-1)
GL_FUNC_VOID(GL_EXT_framebuffer_multisample,false,glRenderbufferStorageMultisampleEXT,(GLenum a,GLsizei b,GLenum c,GLsizei d,GLsizei e),(a,b,c,d,e))
GL_EXT(GL_APPLE_fence,-1,-1)
GL_FUNC(GL_APPLE_fence,false,GLboolean,glTestFenceAPPLE,(GLuint a),(a))
GL_FUNC_VOID(GL_APPLE_fence,false,glSetFenceAPPLE,(GLuint a),(a))
GL_FUNC_VOID(GL_APPLE_fence,false,glFinishFenceAPPLE,(GLuint a),(a))
GL_FUNC_VOID(GL_APPLE_fence,false,glDeleteFencesAPPLE,(GLsizei a,const GLuint *b),(a,b))
GL_FUNC_VOID(GL_APPLE_fence,false,glGenFencesAPPLE,(GLsizei a,GLuint *b),(a,b))
GL_EXT(GL_NV_fence,-1,-1)
GL_FUNC(GL_NV_fence,false,GLboolean,glTestFenceNV,(GLuint a),(a))
GL_FUNC_VOID(GL_NV_fence,false,glSetFenceNV,(GLuint a,GLenum b),(a,b))
GL_FUNC_VOID(GL_NV_fence,false,glFinishFenceNV,(GLuint a),(a))
GL_FUNC_VOID(GL_NV_fence,false,glDeleteFencesNV,(GLsizei a,const GLuint *b),(a,b))
GL_FUNC_VOID(GL_NV_fence,false,glGenFencesNV,(GLsizei a,GLuint *b),(a,b))
GL_EXT(GL_ARB_sync,3,2)
#ifdef HAVE_GL_ARB_SYNC
GL_FUNC_VOID(GL_ARB_sync,false,glGetSynciv,(GLsync a, GLenum b, GLsizei c, GLsizei *d, GLint *e),(a,b,c,d,e))
GL_FUNC(GL_ARB_sync,false,GLenum,glClientWaitSync,(GLsync a, GLbitfield b, GLuint64 c),(a,b,c))
GL_FUNC_VOID(GL_ARB_sync,false,glWaitSync,(GLsync a, GLbitfield b, GLuint64 c),(a,b,c))
GL_FUNC_VOID(GL_ARB_sync,false,glDeleteSync,(GLsync a),(a))
GL_FUNC(GL_ARB_sync,false,GLsync,glFenceSync,(GLenum a, GLbitfield b),(a,b))
#endif
GL_EXT(GL_EXT_draw_buffers2,-1,-1)
GL_FUNC_VOID(GL_EXT_draw_buffers2,true,glColorMaskIndexedEXT,(GLuint a,GLboolean b,GLboolean c,GLboolean d,GLboolean e),(a,b,c,d,e))
GL_FUNC_VOID(GL_EXT_draw_buffers2,true,glEnableIndexedEXT,(GLenum a,GLuint b),(a,b))
GL_FUNC_VOID(GL_EXT_draw_buffers2,true,glDisableIndexedEXT,(GLenum a,GLuint b),(a,b))
GL_FUNC_VOID(GL_EXT_draw_buffers2,true,glGetBooleanIndexedvEXT,(GLenum a,GLuint b,GLboolean *c),(a,b,c))
GL_EXT(GL_EXT_bindable_uniform,-1,-1)
GL_FUNC_VOID(GL_EXT_bindable_uniform,false,glUniformBufferEXT,(GLuint a,GLint b,GLuint c),(a,b,c))
GL_FUNC(GL_EXT_bindable_uniform,false,int,glGetUniformBufferSizeEXT,(GLenum a, GLenum b),(a,b))
GL_FUNC(GL_EXT_bindable_uniform,false,GLintptr,glGetUniformOffsetEXT,(GLenum a, GLenum b),(a,b))
GL_EXT(GL_APPLE_flush_buffer_range,-1,-1)
GL_FUNC_VOID(GL_APPLE_flush_buffer_range,false,glBufferParameteriAPPLE,(GLenum a,GLenum b,GLint c),(a,b,c))
GL_FUNC_VOID(GL_APPLE_flush_buffer_range,false,glFlushMappedBufferRangeAPPLE,(GLenum a,GLintptr b,GLsizeiptr c),(a,b,c))
GL_EXT(GL_ARB_map_buffer_range,-1,-1)
GL_FUNC(GL_ARB_map_buffer_range,false,void*,glMapBufferRange,(GLenum a,GLintptr b,GLsizeiptr c,GLbitfield d),(a,b,c,d))
GL_FUNC_VOID(GL_ARB_map_buffer_range,false,glFlushMappedBufferRange,(GLenum a,GLintptr b,GLsizeiptr c),(a,b,c))
GL_EXT(GL_ARB_vertex_buffer_object,-1,-1)
GL_FUNC_VOID(GL_ARB_vertex_buffer_object,true,glBufferSubData,(GLenum a,GLintptr b,GLsizeiptr c,const GLvoid *d),(a,b,c,d))
GL_EXT(GL_ARB_occlusion_query,-1,-1)
GL_FUNC_VOID(GL_ARB_occlusion_query,false,glBeginQueryARB,(GLenum a,GLuint b),(a,b))
GL_FUNC_VOID(GL_ARB_occlusion_query,false,glEndQueryARB,(GLenum a),(a))
GL_FUNC_VOID(GL_ARB_occlusion_query,false,glGetQueryObjectivARB,(GLuint a,GLenum b,GLint *c),(a,b,c))
GL_FUNC_VOID(GL_ARB_occlusion_query,false,glGetQueryObjectuivARB,(GLuint a,GLenum b,GLuint *c),(a,b,c))
GL_EXT(GL_APPLE_texture_range,-1,-1)
GL_FUNC_VOID(GL_APPLE_texture_range,false,glTextureRangeAPPLE,(GLenum a,GLsizei b,void *c),(a,b,c))
GL_FUNC_VOID(GL_APPLE_texture_range,false,glGetTexParameterPointervAPPLE,(GLenum a,GLenum b,void* *c),(a,b,c))
GL_EXT(GL_APPLE_client_storage,-1,-1)
GL_EXT(GL_ARB_uniform_buffer,-1,-1)
GL_EXT(GL_ARB_vertex_array_bgra,-1,-1)
GL_EXT(GL_EXT_vertex_array_bgra,-1,-1)
GL_EXT(GL_ARB_framebuffer_object,3,0)
GL_FUNC_VOID(GL_ARB_framebuffer_object,false,glBindFramebuffer,(GLenum a,GLuint b),(a,b))
GL_FUNC_VOID(GL_ARB_framebuffer_object,false,glBindRenderbuffer,(GLenum a,GLuint b),(a,b))
GL_FUNC(GL_ARB_framebuffer_object,false,GLenum,glCheckFramebufferStatus,(GLenum a),(a))
GL_FUNC_VOID(GL_ARB_framebuffer_object,false,glDeleteRenderbuffers,(GLsizei a,const GLuint *b),(a,b))
GL_FUNC_VOID(GL_ARB_framebuffer_object,false,glFramebufferRenderbuffer,(GLenum a,GLenum b,GLenum c,GLuint d),(a,b,c,d))
GL_FUNC_VOID(GL_ARB_framebuffer_object,false,glFramebufferTexture2D,(GLenum a,GLenum b,GLenum c,GLuint d,GLint e),(a,b,c,d,e))
GL_FUNC_VOID(GL_ARB_framebuffer_object,false,glFramebufferTexture3D,(GLenum a,GLenum b,GLenum c,GLuint d,GLint e,GLint f),(a,b,c,d,e,f))
GL_FUNC_VOID(GL_ARB_framebuffer_object,false,glGenFramebuffers,(GLsizei a,GLuint *b),(a,b))
GL_FUNC_VOID(GL_ARB_framebuffer_object,false,glGenRenderbuffers,(GLsizei a,GLuint *b),(a,b))
GL_FUNC_VOID(GL_ARB_framebuffer_object,false,glDeleteFramebuffers,(GLsizei a,const GLuint *b),(a,b))
GL_FUNC_VOID(GL_ARB_framebuffer_object,false,glBlitFramebuffer,(GLint a,GLint b,GLint c,GLint d,GLint e,GLint f,GLint g,GLint h,GLbitfield i,GLenum j),(a,b,c,d,e,f,g,h,i,j))
GL_FUNC_VOID(GL_ARB_framebuffer_object,false,glRenderbufferStorageMultisample,(GLenum a,GLsizei b,GLenum c,GLsizei d,GLsizei e),(a,b,c,d,e))
GL_EXT(GL_GREMEDY_string_marker,-1,-1)
GL_FUNC_VOID(GL_GREMEDY_string_marker,false,glStringMarkerGREMEDY,(GLsizei a,const void *b),(a,b))
GL_EXT(GL_ARB_debug_output,-1,-1)
GL_FUNC_VOID(GL_ARB_debug_output,false,glDebugMessageCallbackARB,(void (APIENTRY *a)(GLenum, GLenum , GLuint , GLenum , GLsizei , const GLchar* , GLvoid*) ,void* b),(a,b))
GL_FUNC_VOID(GL_ARB_debug_output,false,glDebugMessageControlARB,(GLenum a, GLenum b, GLenum c, GLsizei d, const GLuint* e, GLboolean f),(a,b,c,d,e,f))
GL_EXT(GL_EXT_direct_state_access,-1,-1)
GL_FUNC_VOID(GL_EXT_direct_state_access,false,glBindMultiTextureEXT,(GLenum a,GLuint b, GLuint c),(a,b,c))
GL_FUNC_VOID(OpenGL,true,glGenSamplers,(GLuint a,GLuint *b),(a,b))
GL_FUNC_VOID(OpenGL,true,glDeleteSamplers,(GLsizei a,const GLuint *b),(a,b))
GL_FUNC_VOID(OpenGL,true,glBindSampler,(GLuint a, GLuint b),(a,b))
GL_FUNC_VOID(OpenGL,true,glSamplerParameteri,(GLuint a, GLenum b, GLint c),(a,b,c))
GL_FUNC_VOID(OpenGL,true,glSamplerParameterf,(GLuint a, GLenum b, GLfloat c),(a,b,c))
GL_FUNC_VOID(OpenGL,true,glSamplerParameterfv,(GLuint a, GLenum b, const GLfloat *c),(a,b,c))
GL_EXT(GL_NV_bindless_texture,-1,-1)
GL_FUNC(GL_NV_bindless_texture, false, GLuint64, glGetTextureHandleNV, (GLuint texture), (texture))
GL_FUNC(GL_NV_bindless_texture, false, GLuint64, glGetTextureSamplerHandleNV, (GLuint texture, GLuint sampler), (texture, sampler))
GL_FUNC_VOID(GL_NV_bindless_texture, false, glMakeTextureHandleResidentNV, (GLuint64 handle), (handle))
GL_FUNC_VOID(GL_NV_bindless_texture, false, glMakeTextureHandleNonResidentNV, (GLuint64 handle), (handle))
GL_FUNC_VOID(GL_NV_bindless_texture, false, glUniformHandleui64NV, (GLint location, GLuint64 value), (location, value))
GL_FUNC_VOID(GL_NV_bindless_texture, false, glUniformHandleui64vNV, (int location, GLsizei count, const GLuint64 *value), (location count, value))
GL_FUNC_VOID(GL_NV_bindless_texture, false, glProgramUniformHandleui64NV, (GLuint program, GLint location, GLuint64 value), (program, location, value))
GL_FUNC_VOID(GL_NV_bindless_texture, false, glProgramUniformHandleui64vNV, (GLuint program, GLint location, GLsizei count, const GLuint64 *values), (program, location, count, values))
GL_FUNC(GL_NV_bindless_texture, false, GLboolean, glIsTextureHandleResidentNV, (GLuint64 handle), (handle))
GL_FUNC_VOID(OpenGL,true,glGenQueries,(GLsizei n, GLuint *ids), (n, ids))
GL_FUNC_VOID(OpenGL,true,glDeleteQueries,(GLsizei n, const GLuint *ids),(n, ids))
GL_FUNC_VOID(OpenGL,true,glBeginQuery,(GLenum target, GLuint id), (target, id))
GL_FUNC_VOID(OpenGL,true,glEndQuery,(GLenum target), (target))
GL_FUNC_VOID(OpenGL,true,glQueryCounter,(GLuint id, GLenum target), (id, target))
GL_FUNC_VOID(OpenGL,true,glGetQueryObjectiv,(GLuint id, GLenum pname, GLint *params), (id, pname, params))
GL_FUNC_VOID(OpenGL,true,glGetQueryObjectui64v,(GLuint id, GLenum pname, GLuint64 *params), (id, pname, params))
GL_FUNC_VOID(OpenGL,true,glCopyBufferSubData,(GLenum readtarget, GLenum writetarget, GLintptr readoffset, GLintptr writeoffset, GLsizeiptr size),(readtarget, writetarget, readoffset, writeoffset, size))
GL_EXT(GL_AMD_pinned_memory,-1,-1)
GL_EXT(GL_EXT_framebuffer_multisample_blit_scaled,-1,-1)
GL_FUNC_VOID(OpenGL,true,glGenVertexArrays,(GLsizei n, GLuint *arrays),(n, arrays))
GL_FUNC_VOID(OpenGL,true,glDeleteVertexArrays,(GLsizei n, GLuint *arrays),(n, arrays))
GL_FUNC_VOID(OpenGL,true,glBindVertexArray,(GLuint a),(a))
GL_EXT(GL_EXT_texture_sRGB_decode,-1,-1)
GL_FUNC_VOID(OpenGL,true,glPushClientAttrib,(GLbitfield a),(a))
GL_FUNC_VOID(OpenGL,true,glPopClientAttrib,(void),())
GL_EXT(GL_NVX_gpu_memory_info,-1,-1)
GL_EXT(GL_ATI_meminfo,-1,-1)
GL_EXT(GL_EXT_texture_compression_s3tc,-1,-1)
GL_EXT(GL_EXT_texture_compression_dxt1,-1,-1)
GL_EXT(GL_ANGLE_texture_compression_dxt3,-1,-1)
GL_EXT(GL_ANGLE_texture_compression_dxt5,-1,-1)
// This one is an OS extension. We'll add a little helper function to look for it.
#ifdef _WIN32
GL_EXT(WGL_EXT_swap_control_tear,-1,-1)
#else
GL_EXT(GLX_EXT_swap_control_tear,-1,-1)
#endif

View File

@ -0,0 +1,160 @@
//========= Copyright Valve Corporation, All rights reserved. ============//
#ifndef GLMDEBUG_H
#define GLMDEBUG_H
#include "tier0/platform.h"
// include this anywhere you need to be able to compile-out code related specifically to GLM debugging.
// we expect DEBUG to be driven by the build system so you can include this header anywhere.
// when we come out, GLMDEBUG will be defined to a value - 0, 1, or 2
// 0 means no GLM debugging is possible
// 1 means it's possible and resulted from being a debug build
// 2 means it's possible and resulted from being manually forced on for a release build
#ifdef POSIX
#ifndef GLMDEBUG
#ifdef DEBUG
#define GLMDEBUG 1 // normally 1 here, testing
#else
// #define GLMDEBUG 2 // don't check this in enabled..
#endif
#ifndef GLMDEBUG
#define GLMDEBUG 0
#endif
#endif
#else
#ifndef GLMDEBUG
#define GLMDEBUG 0
#endif
#endif
//===============================================================================
// debug channels
enum EGLMDebugChannel
{
ePrintf,
eDebugger,
eGLProfiler
};
#if GLMDEBUG
// make all these prototypes disappear in non GLMDEBUG
void GLMDebugInitialize( bool forceReinit=false );
bool GLMDetectOGLP( void );
bool GLMDetectGDB( void );
uint GLMDetectAvailableChannels( void );
uint GLMDebugChannelMask( uint *newValue = NULL );
// note that GDB and OGLP can both come and go during run - forceCheck will allow that to be detected.
// mask returned is in form of 1<<n, n from EGLMDebugChannel
#endif
//===============================================================================
// debug message flavors
enum EGLMDebugFlavor
{
eAllFlavors, // 0
eDebugDump, // 1 debug dump flavor -D-
eTenure, // 2 code tenures > <
eComment, // 3 one off messages ---
eMatrixData, // 4 matrix data -M-
eShaderData, // 5 shader data (params) -S-
eFrameBufData, // 6 FBO data (attachments) -F-
eDXStuff, // 7 dxabstract spew -X-
eAllocations, // 8 tracking allocs and frees -A-
eSlowness, // 9 slow things happening (srgb flips..) -Z-
eDefaultFlavor, // not specified (no marker)
eFlavorCount
};
uint GLMDebugFlavorMask( uint *newValue = NULL );
// make all these prototypes disappear in non GLMDEBUG
#if GLMDEBUG
// these are unconditional outputs, they don't interrogate the string
void GLMStringOut( const char *string );
void GLMStringOutIndented( const char *string, int indentColumns );
#ifdef TOGL_DLL_EXPORT
// these will look at the string to guess its flavor: <, >, ---, -M-, -S-
DLL_EXPORT void GLMPrintfVA( const char *fmt, va_list vargs );
DLL_EXPORT void GLMPrintf( const char *fmt, ... );
#else
DLL_IMPORT void GLMPrintfVA( const char *fmt, va_list vargs );
DLL_IMPORT void GLMPrintf( const char *fmt, ... );
#endif
// these take an explicit flavor with a default value
void GLMPrintStr( const char *str, EGLMDebugFlavor flavor = eDefaultFlavor );
#define GLMPRINTTEXT_NUMBEREDLINES 0x80000000
void GLMPrintText( const char *str, EGLMDebugFlavor flavor = eDefaultFlavor, uint options=0 ); // indent each newline
int GLMIncIndent( int indentDelta );
int GLMGetIndent( void );
void GLMSetIndent( int indent );
#endif
// helpful macro if you are in a position to call GLM functions directly (i.e. you live in materialsystem / shaderapidx9)
#if GLMDEBUG
#define GLMPRINTF(args) GLMPrintf args
#define GLMPRINTSTR(args) GLMPrintStr args
#define GLMPRINTTEXT(args) GLMPrintText args
#else
#define GLMPRINTF(args)
#define GLMPRINTSTR(args)
#define GLMPRINTTEXT(args)
#endif
//===============================================================================
// knob twiddling
#ifdef TOGL_DLL_EXPORT
DLL_EXPORT float GLMKnob( char *knobname, float *setvalue ); // Pass NULL to not-set the knob value
DLL_EXPORT float GLMKnobToggle( char *knobname );
#else
DLL_IMPORT float GLMKnob( char *knobname, float *setvalue ); // Pass NULL to not-set the knob value
DLL_IMPORT float GLMKnobToggle( char *knobname );
#endif
//===============================================================================
// other stuff
#if GLMDEBUG
void GLMTriggerDebuggerBreak();
inline void GLMDebugger( void )
{
if (GLMDebugChannelMask() & (1<<eDebugger))
{
#ifdef OSX
asm {int 3 };
#else
DebuggerBreak();
#endif
}
if (GLMDebugChannelMask() & (1<<eGLProfiler))
{
GLMTriggerDebuggerBreak();
}
}
#else
#define GLMDebugger() do { } while(0)
#endif
// helpers for CGLSetOption - no op if no profiler
void GLMProfilerClearTrace( void );
void GLMProfilerEnableTrace( bool enable );
// helpers for CGLSetParameter - no op if no profiler
void GLMProfilerDumpState( void );
void CheckGLError( int line );
#endif // GLMDEBUG_H

View File

@ -0,0 +1,176 @@
//========= Copyright Valve Corporation, All rights reserved. ============//
//
// glmdisplay.h
// display related stuff - used by both GLMgr and the CocoaMgr
//
//===============================================================================
#ifndef GLMDISPLAY_H
#define GLMDISPLAY_H
#pragma once
#ifdef OSX
#include <OpenGL/OpenGL.h>
#include <OpenGL/gl.h>
#include <OpenGL/glext.h>
#include <OpenGL/CGLTypes.h>
#include <OpenGL/CGLRenderers.h>
#include <OpenGL/CGLCurrent.h>
#include <ApplicationServices/ApplicationServices.h>
#elif defined(DX_TO_GL_ABSTRACTION)
#include <GL/gl.h>
#include <GL/glext.h>
#include "tier0/platform.h"
#else
#error
#endif
typedef void _PseudoNSGLContext; // aka NSOpenGLContext
typedef _PseudoNSGLContext *PseudoNSGLContextPtr;
struct GLMDisplayModeInfoFields
{
uint m_modePixelWidth;
uint m_modePixelHeight;
uint m_modeRefreshHz;
// are we even going to talk about bit depth... not yet
};
struct GLMDisplayInfoFields
{
#ifdef OSX
CGDirectDisplayID m_cgDisplayID;
CGOpenGLDisplayMask m_glDisplayMask; // result of CGDisplayIDToOpenGLDisplayMask on the cg_displayID.
#endif
uint m_displayPixelWidth;
uint m_displayPixelHeight;
};
struct GLMRendererInfoFields
{
/*properties of interest and their desired values.
kCGLRPFullScreen = 54, true
kCGLRPAccelerated = 73, true
kCGLRPWindow = 80, true
kCGLRPRendererID = 70, informational
kCGLRPDisplayMask = 84, informational
kCGLRPBufferModes = 100, informational
kCGLRPColorModes = 103, informational
kCGLRPAccumModes = 104, informational
kCGLRPDepthModes = 105, informational
kCGLRPStencilModes = 106, informational
kCGLRPMaxAuxBuffers = 107, informational
kCGLRPMaxSampleBuffers = 108, informational
kCGLRPMaxSamples = 109, informational
kCGLRPSampleModes = 110, informational
kCGLRPSampleAlpha = 111, informational
kCGLRPVideoMemory = 120, informational
kCGLRPTextureMemory = 121, informational
kCGLRPRendererCount = 128 number of renderers in the CGLRendererInfoObj under examination
kCGLRPOffScreen = 53, D/C
kCGLRPRobust = 75, FALSE or D/C - aka we're asking for no-fallback
kCGLRPBackingStore = 76, D/C
kCGLRPMPSafe = 78, D/C
kCGLRPMultiScreen = 81, D/C
kCGLRPCompliant = 83, D/C
*/
//--------------------------- info we have from CGL renderer queries, IOKit, Gestalt
//--------------------------- these are set up in the displayDB by CocoaMgr
GLint m_fullscreen;
GLint m_accelerated;
GLint m_windowed;
GLint m_rendererID;
GLint m_displayMask;
GLint m_bufferModes;
GLint m_colorModes;
GLint m_accumModes;
GLint m_depthModes;
GLint m_stencilModes;
GLint m_maxAuxBuffers;
GLint m_maxSampleBuffers;
GLint m_maxSamples;
GLint m_sampleModes;
GLint m_sampleAlpha;
GLint m_vidMemory;
GLint m_texMemory;
uint m_pciVendorID;
uint m_pciDeviceID;
char m_pciModelString[64];
char m_driverInfoString[64];
//--------------------------- OS version related - set up by CocoaMgr
// OS version found
uint m_osComboVersion; // 0x00XXYYZZ : XX major, YY minor, ZZ minor minor : 10.6.3 --> 0x000A0603. 10.5.8 --> 0x000A0508.
//--------------------------- shorthands - also set up by CocoaMgr - driven by vendorid / deviceid
bool m_ati;
bool m_atiR5xx;
bool m_atiR6xx;
bool m_atiR7xx;
bool m_atiR8xx;
bool m_atiNewer;
bool m_intel;
bool m_intel95x;
bool m_intel3100;
bool m_intelNewer;
bool m_nv;
bool m_nvG7x;
bool m_nvG8x;
bool m_nvNewer;
//--------------------------- context query results - left blank in the display DB - but valid in a GLMContext (call ctx->Caps() to get a const ref)
// booleans
bool m_hasGammaWrites; // aka glGetBooleanv(GL_FRAMEBUFFER_SRGB_CAPABLE_EXT) / glEnable(GL_FRAMEBUFFER_SRGB_EXT)
bool m_hasMixedAttachmentSizes; // aka ARB_fbo in 10.6.3 - test for min OS vers, then exported ext string
bool m_hasBGRA; // aka GL_BGRA vertex attribs in 10.6.3 - - test for min OS vers, then exported ext string
bool m_hasNewFullscreenMode; // aka 10.6.x "big window" fullscreen mode
bool m_hasNativeClipVertexMode; // aka GLSL gl_ClipVertex does not fall back to SW- OS version and folklore-based
bool m_hasOcclusionQuery; // occlusion query: do you speak it ?!
bool m_hasFramebufferBlit; // framebuffer blit: know what I'm sayin?!
bool m_hasPerfPackage1; // means new MTGL, fast OQ, fast uniform upload, NV can resolve flipped (late summer 2010 post 10.6.4 update)
// counts
int m_maxAniso; // aniso limit - context query
// other exts
bool m_hasBindableUniforms;
int m_maxVertexBindableUniforms;
int m_maxFragmentBindableUniforms;
int m_maxBindableUniformSize;
bool m_hasUniformBuffers;
// runtime options that aren't negotiable once set
bool m_hasDualShaders; // must supply CLI arg "-glmdualshaders" or we go GLSL only
//--------------------------- " can'ts " - specific problems that need to be worked around
bool m_cantBlitReliably; // Intel chipsets have problems blitting sRGB sometimes
bool m_cantAttachSRGB; // NV G8x on 10.5.8 can't have srgb tex on FBO color - separate issue from hasGammaWrites
bool m_cantResolveFlipped; // happens on NV in 10.6.4 and prior - console variable "gl_can_resolve_flipped" can overrule
bool m_cantResolveScaled; // happens everywhere per GL spec but may be relaxed some day - console variable "gl_can_resolve_scaled" can overrule
bool m_costlyGammaFlips; // this means that sRGB sampling state affects shader code gen, resulting in state-dependent code regen
//--------------------------- " bads " - known bad drivers
bool m_badDriver1064NV; // this is the bad NVIDIA driver on 10.6.4 - stutter, tex corruption, black screen issues
};
#endif

View File

@ -0,0 +1,92 @@
//========= Copyright Valve Corporation, All rights reserved. ============//
#ifndef GLMDISPLAYDB_H
#define GLMDISPLAYDB_H
#include "tier1/utlvector.h"
//===============================================================================
// modes, displays, and renderers
//===============================================================================
// GLMDisplayModeInfoFields is in glmdisplay.h
class GLMDisplayMode
{
public:
GLMDisplayModeInfoFields m_info;
GLMDisplayMode( uint width, uint height, uint refreshHz );
GLMDisplayMode() { };
~GLMDisplayMode( void );
void Init( uint width, uint height, uint refreshHz );
void Dump( int which );
};
//===============================================================================
// GLMDisplayInfoFields is in glmdisplay.h
class GLMDisplayInfo
{
public:
GLMDisplayInfoFields m_info;
CUtlVector< GLMDisplayMode* > *m_modes; // starts out NULL, set by PopulateModes
GLMDisplayInfo( void );
~GLMDisplayInfo( void );
void PopulateModes( void );
void Dump( int which );
};
//===============================================================================
// GLMRendererInfoFields is in glmdisplay.h
class GLMRendererInfo
{
public:
GLMRendererInfoFields m_info;
GLMDisplayInfo *m_display;
GLMRendererInfo ();
~GLMRendererInfo ( void );
void Init( GLMRendererInfoFields *info );
void PopulateDisplays();
void Dump( int which );
};
//===============================================================================
class GLMDisplayDB
{
public:
GLMRendererInfo m_renderer;
GLMDisplayDB ( void );
~GLMDisplayDB ( void );
virtual void PopulateRenderers( void );
virtual void PopulateFakeAdapters( uint realRendererIndex ); // fake adapters = one real adapter times however many displays are on it
virtual void Populate( void );
// The info-get functions return false on success.
virtual int GetFakeAdapterCount( void );
virtual bool GetFakeAdapterInfo( int fakeAdapterIndex, int *rendererOut, int *displayOut, GLMRendererInfoFields *rendererInfoOut, GLMDisplayInfoFields *displayInfoOut );
virtual int GetRendererCount( void );
virtual bool GetRendererInfo( int rendererIndex, GLMRendererInfoFields *infoOut );
virtual int GetDisplayCount( int rendererIndex );
virtual bool GetDisplayInfo( int rendererIndex, int displayIndex, GLMDisplayInfoFields *infoOut );
virtual int GetModeCount( int rendererIndex, int displayIndex );
virtual bool GetModeInfo( int rendererIndex, int displayIndex, int modeIndex, GLMDisplayModeInfoFields *infoOut );
virtual void Dump( void );
};
#endif // GLMDISPLAYDB_H

2259
public/togl/linuxwin/glmgr.h Normal file

File diff suppressed because it is too large Load Diff

View File

@ -0,0 +1,308 @@
//========= Copyright Valve Corporation, All rights reserved. ============//
//
// glmgrbasics.h
// types, common headers, forward declarations, utilities
//
//===============================================================================
#ifndef GLMBASICS_H
#define GLMBASICS_H
#pragma once
#ifdef OSX
#include <OpenGL/OpenGL.h>
#include <OpenGL/gl.h>
#include <OpenGL/glext.h>
#include <OpenGL/CGLTypes.h>
#include <OpenGL/CGLRenderers.h>
#include <OpenGL/CGLCurrent.h>
#include <OpenGL/CGLProfiler.h>
#include <ApplicationServices/ApplicationServices.h>
#elif defined(DX_TO_GL_ABSTRACTION)
#include <GL/gl.h>
#include <GL/glext.h>
#else
#error
#endif
#include "tier0/platform.h"
#include "bitmap/imageformat.h"
#include "bitvec.h"
#include "tier1/checksum_md5.h"
#include "tier1/utlvector.h"
#include "tier1/convar.h"
#include <sys/stat.h>
#include "dxabstract_types.h"
struct GLMRect;
typedef void *PseudoGLContextPtr;
// types
// 3-d integer box (used for texture lock/unlock etc)
struct GLMRegion
{
int xmin,xmax;
int ymin,ymax;
int zmin,zmax;
};
struct GLMRect // follows GL convention - if coming from the D3D rect you will need to fiddle the Y's
{
int xmin; // left
int ymin; // bottom
int xmax; // right
int ymax; // top
};
// macros
//#define GLMassert(x) assert(x)
// forward decls
class GLMgr; // singleton
class GLMContext; // GL context
class CGLMContextTester; // testing class
class CGLMTex;
class CGLMFBO;
class CGLMProgram;
class CGLMBuffer;
// utilities
typedef enum
{
// D3D codes
eD3D_DEVTYPE,
eD3D_FORMAT,
eD3D_RTYPE,
eD3D_USAGE,
eD3D_RSTATE, // render state
eD3D_SIO, // D3D shader bytecode
eD3D_VTXDECLUSAGE,
// CGL codes
eCGL_RENDID,
// OpenGL error codes
eGL_ERROR,
// OpenGL enums
eGL_ENUM,
eGL_RENDERER
} GLMThing_t;
// these will look at the string to guess its flavor: <, >, ---, -M-, -S-
#ifdef TOGL_DLL_EXPORT
DLL_EXPORT const char* GLMDecode( GLMThing_t type, unsigned long value ); // decode a numeric const
#else
DLL_IMPORT const char* GLMDecode( GLMThing_t type, unsigned long value ); // decode a numeric const
#endif
const char* GLMDecodeMask( GLMThing_t type, unsigned long value ); // decode a bitmask
FORCEINLINE void GLMStop( void ) { DXABSTRACT_BREAK_ON_ERROR(); }
void GLMEnableTrace( bool on );
//===============================================================================
// output functions
// expose these in release now
// Mimic PIX events so we can decorate debug spew
DLL_EXPORT void GLMBeginPIXEvent( const char *str );
DLL_EXPORT void GLMEndPIXEvent( void );
class CScopedGLMPIXEvent
{
CScopedGLMPIXEvent( const CScopedGLMPIXEvent & );
CScopedGLMPIXEvent& operator= ( const CScopedGLMPIXEvent & );
public:
inline CScopedGLMPIXEvent( const char *pName ) { GLMBeginPIXEvent( pName ); }
inline ~CScopedGLMPIXEvent() { GLMEndPIXEvent( ); }
};
#if GLMDEBUG
//===============================================================================
// classes
// helper class making function tracking easier to wire up
class GLMFuncLogger
{
public:
// simple function log
GLMFuncLogger( const char *funcName )
{
m_funcName = funcName;
m_earlyOut = false;
GLMPrintf( ">%s", m_funcName );
};
// more advanced version lets you pass args (i.e. called parameters or anything else of interest)
// no macro for this one, since no easy way to pass through the args as well as the funcname
GLMFuncLogger( const char *funcName, char *fmt, ... )
{
m_funcName = funcName;
m_earlyOut = false;
// this acts like GLMPrintf here
// all the indent policy is down in GLMPrintfVA
// which means we need to inject a ">" at the front of the format string to make this work... sigh.
char modifiedFmt[2000];
modifiedFmt[0] = '>';
strcpy( modifiedFmt+1, fmt );
va_list vargs;
va_start(vargs, fmt);
GLMPrintfVA( modifiedFmt, vargs );
va_end( vargs );
}
~GLMFuncLogger( )
{
if (m_earlyOut)
{
GLMPrintf( "<%s (early out)", m_funcName );
}
else
{
GLMPrintf( "<%s", m_funcName );
}
};
void EarlyOut( void )
{
m_earlyOut = true;
};
const char *m_funcName; // set at construction time
bool m_earlyOut;
};
// handy macro to go with the function tracking class
#define GLM_FUNC GLMFuncLogger _logger_ ( __FUNCTION__ )
#else
#define GLM_FUNC tmZone( TELEMETRY_LEVEL1, TMZF_NONE, "%s", __FUNCTION__ )
#endif
// class to keep an in-memory mirror of a file which may be getting edited during run
class CGLMFileMirror
{
public:
CGLMFileMirror( char *fullpath ); // just associates mirror with file. if file exists it will be read.
//if non existent it will be created with size zero
~CGLMFileMirror( );
bool HasData( void ); // see if data avail
void GetData( char **dataPtr, uint *dataSizePtr ); // read it out
void SetData( char *data, uint dataSize ); // put data in (and write it to disk)
bool PollForChanges( void ); // check disk copy. If different, read it back in and return true.
void UpdateStatInfo( void ); // make sure stat info is current for our file
void ReadFile( void );
void WriteFile( void );
void OpenInEditor( bool foreground=false ); // pass TRUE if you would like the editor to pop to foreground
/// how about a "wait for change" method..
char *m_path; // fullpath to file
bool m_exists;
struct stat m_stat; // stat results for the file (last time checked)
char *m_data; // content of file
uint m_size; // length of content
};
// class based on the file mirror, that makes it easy to edit them outside the app.
// it receives an initial block of text from the engine, and hashes it. ("orig")
// it munges it by duplicating all the text after the "!!" line, and appending it in commented form. ("munged")
// a mirror file is activated, using a filename based on the hash from the orig text.
// if there is already content on disk matching that filename, use that content *unless* the 'blitz' parameter is set.
// (i.e. engine is instructing this subsystem to wipe out any old/modified variants of the text)
class CGLMEditableTextItem
{
public:
CGLMEditableTextItem( char *text, uint size, bool forceOverwrite, char *prefix, char *suffix = NULL ); // create a text blob from text source, optional filename suffix
~CGLMEditableTextItem( );
bool HasData( void );
bool PollForChanges( void ); // return true if stale i.e. you need to get a new edition
void GetCurrentText( char **textOut, uint *sizeOut ); // query for read access to the active blob (could be the original, could be external edited copy)
void OpenInEditor( bool foreground=false ); // call user attention to this text
// internal methods
void GenHashOfOrigText( void );
void GenBaseNameAndFullPath( char *prefix, char *suffix );
void GenMungedText( bool fromMirror );
// members
// orig
uint m_origSize;
char *m_origText; // what was submitted
unsigned char m_origDigest[MD5_DIGEST_LENGTH]; // digest of what was submitted
// munged
uint m_mungedSize;
char *m_mungedText; // re-processed edition, initial content submission to the file mirror
// mirror
char *m_mirrorBaseName; // generated from the hash of the orig text, plus the label / prefix
char *m_mirrorFullPath; // base name
CGLMFileMirror *m_mirror; // file mirror itself. holds "official" copy for GetCurrentText to return.
};
// debug font
extern unsigned char g_glmDebugFontMap[16384];
// class for cracking multi-part text blobs
// sections are demarcated by beginning-of-line markers submitted in a table by the caller
struct GLMTextSection
{
int m_markerIndex; // based on table of markers passed in to constructor
uint m_textOffset; // where is the text - offset
int m_textLength; // how big is the section
};
class CGLMTextSectioner
{
public:
CGLMTextSectioner( char *text, int textSize, const char **markers ); // constructor finds all the sections
~CGLMTextSectioner( );
int Count( void ); // how many sections found
void GetSection( int index, uint *offsetOut, uint *lengthOut, int *markerIndexOut );
// find section, size, what marker
// note that more than one section can be marked similarly.
// so policy isn't made here, you walk the sections and decide what to do if there are dupes.
//members
//section table
CUtlVector< GLMTextSection > m_sectionTable;
};
void GLMGPUTimestampManagerInit();
void GLMGPUTimestampManagerDeinit();
void GLMGPUTimestampManagerTick();
#endif // GLMBASICS_H

View File

@ -0,0 +1,93 @@
//========= Copyright Valve Corporation, All rights reserved. ============//
//
// glmgrext.h
// helper file for extension testing and runtime importing of entry points
//
//===============================================================================
#pragma once
#ifdef OSX
#include <OpenGL/gl.h>
#include <OpenGL/glext.h>
#elif defined(DX_TO_GL_ABSTRACTION)
#include <GL/gl.h>
#include <GL/glext.h>
#else
#error
#endif
#ifndef GL_EXT_framebuffer_sRGB
#define GL_FRAMEBUFFER_SRGB_EXT 0x8DB9
#define GL_FRAMEBUFFER_SRGB_CAPABLE_EXT 0x8DBA
#endif
#ifndef ARB_texture_rg
#define GL_COMPRESSED_RED 0x8225
#define GL_COMPRESSED_RG 0x8226
#define GL_RG 0x8227
#define GL_RG_INTEGER 0x8228
#define GL_R8 0x8229
#define GL_R16 0x822A
#define GL_RG8 0x822B
#define GL_RG16 0x822C
#define GL_R16F 0x822D
#define GL_R32F 0x822E
#define GL_RG16F 0x822F
#define GL_RG32F 0x8230
#define GL_R8I 0x8231
#define GL_R8UI 0x8232
#define GL_R16I 0x8233
#define GL_R16UI 0x8234
#define GL_R32I 0x8235
#define GL_R32UI 0x8236
#define GL_RG8I 0x8237
#define GL_RG8UI 0x8238
#define GL_RG16I 0x8239
#define GL_RG16UI 0x823A
#define GL_RG32I 0x823B
#define GL_RG32UI 0x823C
#endif
#ifndef GL_EXT_bindable_uniform
#define GL_UNIFORM_BUFFER_EXT 0x8DEE
#endif
// unpublished extension enums (thus the "X")
// from EXT_framebuffer_multisample_blit_scaled..
#define XGL_SCALED_RESOLVE_FASTEST_EXT 0x90BA
#define XGL_SCALED_RESOLVE_NICEST_EXT 0x90BB
#ifndef GL_TEXTURE_MINIMIZE_STORAGE_APPLE
#define GL_TEXTURE_MINIMIZE_STORAGE_APPLE 0x85B6
#endif
#ifndef GL_ALL_COMPLETED_NV
#define GL_ALL_COMPLETED_NV 0x84F2
#endif
#ifndef GL_MAP_READ_BIT
#define GL_MAP_READ_BIT 0x0001
#endif
#ifndef GL_MAP_WRITE_BIT
#define GL_MAP_WRITE_BIT 0x0002
#endif
#ifndef GL_MAP_INVALIDATE_RANGE_BIT
#define GL_MAP_INVALIDATE_RANGE_BIT 0x0004
#endif
#ifndef GL_MAP_INVALIDATE_BUFFER_BIT
#define GL_MAP_INVALIDATE_BUFFER_BIT 0x0008
#endif
#ifndef GL_MAP_FLUSH_EXPLICIT_BIT
#define GL_MAP_FLUSH_EXPLICIT_BIT 0x0010
#endif
#ifndef GL_MAP_UNSYNCHRONIZED_BIT
#define GL_MAP_UNSYNCHRONIZED_BIT 0x0020
#endif