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

Sync with upstream (Issue #30).

Recompiled tier1 and mathlib  for all platforms will come in next commit.
This commit is contained in:
Nicholas Hastings
2016-11-30 10:01:15 -05:00
parent 98fe5b5a34
commit 3957adff10
491 changed files with 29846 additions and 10698 deletions

View File

@ -1,4 +1,26 @@
//========= Copyright Valve Corporation, All rights reserved. ============//
// TOGL CODE LICENSE
//
// Copyright 2011-2014 Valve Corporation
// All Rights Reserved.
//
// Permission is hereby granted, free of charge, to any person obtaining a copy
// of this software and associated documentation files (the "Software"), to deal
// in the Software without restriction, including without limitation the rights
// to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
// copies of the Software, and to permit persons to whom the Software is
// furnished to do so, subject to the following conditions:
//
// The above copyright notice and this permission notice shall be included in
// all copies or substantial portions of the Software.
//
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
// THE SOFTWARE.
//
// cglmprogram.h
// GLMgr buffers (index / vertex)
@ -44,6 +66,51 @@ struct GLMBuffLockParams
extern void glBufferSubDataMaxSize( GLenum target, GLintptr offset, GLsizeiptr size, const GLvoid *data, uint nMaxSizePerCall = 128 * 1024 );
//===========================================================================//
// Creates an immutable storage for a buffer object
// https://www.opengl.org/registry/specs/ARB/buffer_storage.txt
class CPersistentBuffer
{
public:
CPersistentBuffer();
~CPersistentBuffer();
void Init( EGLMBufferType type,uint nSize );
void Deinit();
void InsertFence();
void BlockUntilNotBusy();
void Append( uint nSize );
inline uint GetBytesRemaining() const { return m_nSize - m_nOffset; }
inline uint GetOffset() const { return m_nOffset; }
inline void *GetPtr() const { return m_pImmutablePersistentBuf; }
inline GLuint GetHandle() const { return m_nHandle; }
private:
CPersistentBuffer( const CPersistentBuffer & );
CPersistentBuffer & operator= (const CPersistentBuffer &);
uint m_nSize;
EGLMBufferType m_type;
GLenum m_buffGLTarget; // GL_ARRAY_BUFFER_ARB / GL_ELEMENT_BUFFER_ARB
GLuint m_nHandle; // handle of this program in the GL context
// Holds a pointer to the persistently mapped buffer
void* m_pImmutablePersistentBuf;
uint m_nOffset;
#ifdef HAVE_GL_ARB_SYNC
GLsync m_nSyncObj;
#endif
};
//===============================================================================
#if GL_ENABLE_INDEX_VERIFICATION
@ -92,7 +159,7 @@ public:
void DiscardAllSpans();
bool IsValid( uint nOffset, uint nSize ) const;
private:
bool AllocDynamicBuf( uint nSize, GLDynamicBuf_t &buf );
void ReleaseDynamicBuf( GLDynamicBuf_t &buf );
@ -120,6 +187,8 @@ class CGLMBuffer
public:
void Lock( GLMBuffLockParams *pParams, char **pAddressOut );
void Unlock( int nActualSize = -1, const void *pActualData = NULL );
GLuint GetHandle() const;
friend class GLMContext; // only GLMContext can make CGLMBuffer objects
friend class GLMTester;
@ -159,6 +228,9 @@ public:
float *m_pLastMappedAddress;
int m_nPinnedMemoryOfs;
uint m_nPersistentBufferStartOffset;
bool m_bUsingPersistentBuffer;
bool m_bPseudo; // true if the m_name is 0, and the backing is plain RAM

View File

@ -1,4 +1,26 @@
//========= Copyright Valve Corporation, All rights reserved. ============//
// TOGL CODE LICENSE
//
// Copyright 2011-2014 Valve Corporation
// All Rights Reserved.
//
// Permission is hereby granted, free of charge, to any person obtaining a copy
// of this software and associated documentation files (the "Software"), to deal
// in the Software without restriction, including without limitation the rights
// to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
// copies of the Software, and to permit persons to whom the Software is
// furnished to do so, subject to the following conditions:
//
// The above copyright notice and this permission notice shall be included in
// all copies or substantial portions of the Software.
//
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
// THE SOFTWARE.
//
// cglmfbo.h
// GLMgr FBO's (render targets)

View File

@ -1,4 +1,26 @@
//========= Copyright Valve Corporation, All rights reserved. ============//
// TOGL CODE LICENSE
//
// Copyright 2011-2014 Valve Corporation
// All Rights Reserved.
//
// Permission is hereby granted, free of charge, to any person obtaining a copy
// of this software and associated documentation files (the "Software"), to deal
// in the Software without restriction, including without limitation the rights
// to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
// copies of the Software, and to permit persons to whom the Software is
// furnished to do so, subject to the following conditions:
//
// The above copyright notice and this permission notice shall be included in
// all copies or substantial portions of the Software.
//
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
// THE SOFTWARE.
//
// cglmprogram.h
// GLMgr programs (ARBVP/ARBfp)
@ -110,8 +132,8 @@ public:
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 );
void CompileActiveSources ( void ); // compile only the flavors that were provided.
void 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
@ -145,6 +167,9 @@ public:
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_fragDataMask; // (1<<n) mask of gl_FragData[n] outputs referenced, if this is a fragment shader (dxabstract sets this field)
uint m_numDrawBuffers; // number of draw buffers used
GLenum m_drawBuffers[4]; // GL_COLOR_ATTACHMENT0_EXT1, etc
uint m_nNumUsedSamplers;
uint m_maxSamplers;
uint m_maxVertexAttrs;
@ -154,6 +179,13 @@ public:
bool m_bTranslatedProgram;
char m_shaderName[64];
// Cache label string from the shader text
// example:
// trans#2871 label:vs-file vertexlit_and_unlit_generic_vs20 vs-index 294912 vs-combo 1234
char m_labelName[1024];
int m_labelIndex;
int m_labelCombo;
};
//===============================================================================
@ -188,10 +220,15 @@ public:
bool SetProgramPair ( CGLMProgram *vp, CGLMProgram *fp );
// true result means successful link and query
// Note that checking the link status and querying the uniform can be optionally
// deferred to take advantage of multi-threaded compilation in the driver
bool RefreshProgramPair ( void );
// re-link and re-query the uniforms
bool ValidateProgramPair( void );
// true result means successful link and query
FORCEINLINE void UpdateScreenUniform( uint nWidthHeight )
{
if ( m_nScreenWidthHeight == nWidthHeight )
@ -199,10 +236,10 @@ public:
m_nScreenWidthHeight = nWidthHeight;
uint nWidth = nWidthHeight & 0xFFFF, nHeight = nWidthHeight >> 16;
float fWidth = (float)( nWidthHeight & 0xFFFF ), fHeight = (float)( 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 / (float)nWidth, 1.0f / (float)nHeight, (float)nWidth, (float)nHeight };
float v[4] = { 1.0f / fWidth, 1.0f / fHeight, fWidth, fHeight };
if ( m_locVertexScreenParams >= 0 )
gGL->glUniform4fv( m_locVertexScreenParams, 1, v );
}
@ -227,10 +264,10 @@ public:
GLint m_locVertexBoneParams; // "vcbones"
GLint m_locVertexInteger0; // "i0"
GLint m_locVertexBool0; // "b0"
GLint m_locVertexBool1; // "b1"
GLint m_locVertexBool2; // "b2"
GLint m_locVertexBool3; // "b3"
enum { cMaxVertexShaderBoolUniforms = 4, cMaxFragmentShaderBoolUniforms = 1 };
GLint m_locVertexBool[cMaxVertexShaderBoolUniforms]; // "b0", etc.
GLint m_locFragmentBool[cMaxFragmentShaderBoolUniforms]; // "fb0", etc.
bool m_bHasBoolOrIntUniforms;
// fragment stage uniforms
@ -243,10 +280,11 @@ public:
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..."
GLint m_locSamplers[ GLM_SAMPLER_COUNT ]; // "sampler0 ... sampler1..."
// other stuff
bool m_valid; // true on successful link
bool m_bCheckLinkStatus;
uint m_revision; // if this pair is relinked, bump this number.
GLint m_locVertexScreenParams; // vcscreen

View File

@ -1,4 +1,26 @@
//========= Copyright Valve Corporation, All rights reserved. ============//
// TOGL CODE LICENSE
//
// Copyright 2011-2014 Valve Corporation
// All Rights Reserved.
//
// Permission is hereby granted, free of charge, to any person obtaining a copy
// of this software and associated documentation files (the "Software"), to deal
// in the Software without restriction, including without limitation the rights
// to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
// copies of the Software, and to permit persons to whom the Software is
// furnished to do so, subject to the following conditions:
//
// The above copyright notice and this permission notice shall be included in
// all copies or substantial portions of the Software.
//
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
// THE SOFTWARE.
//
// cglmquery.h
// GLMgr queries
@ -10,10 +32,6 @@
#pragma once
#ifdef OSX
#include "glmgr/glmgrbasics.h"
#endif
//===============================================================================
// forward declarations

View File

@ -1,4 +1,26 @@
//========= Copyright Valve Corporation, All rights reserved. ============//
// TOGL CODE LICENSE
//
// Copyright 2011-2014 Valve Corporation
// All Rights Reserved.
//
// Permission is hereby granted, free of charge, to any person obtaining a copy
// of this software and associated documentation files (the "Software"), to deal
// in the Software without restriction, including without limitation the rights
// to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
// copies of the Software, and to permit persons to whom the Software is
// furnished to do so, subject to the following conditions:
//
// The above copyright notice and this permission notice shall be included in
// all copies or substantial portions of the Software.
//
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
// THE SOFTWARE.
//
// cglmtex.h
// GLMgr textures
@ -11,7 +33,7 @@
#pragma once
#ifdef OSX
#include "glmgr/glmgrbasics.h"
#include "glmgrbasics.h"
#endif
#include "tier1/utlhash.h"
#include "tier1/utlmap.h"
@ -203,6 +225,8 @@ struct GLMTexLockDesc
#define GLM_SAMPLER_COUNT 16
#define GLM_MAX_PIXEL_TEX_SAMPLERS 16
#define GLM_MAX_VERTEX_TEX_SAMPLERS 0
typedef CBitVec<GLM_SAMPLER_COUNT> CTexBindMask;
enum EGLMTexSliceFlag
@ -267,9 +291,11 @@ struct GLMTexSamplingParams
m_packed.m_magFilter = D3DTEXF_POINT;
m_packed.m_mipFilter = D3DTEXF_NONE;
m_packed.m_maxAniso = 1;
m_packed.m_compareMode = 0;
m_packed.m_isValid = true;
}
#ifndef OSX
FORCEINLINE void SetToSamplerObject( GLuint nSamplerObject ) const
{
static const GLenum dxtogl_addressMode[] = { GL_REPEAT, GL_CLAMP_TO_EDGE, GL_CLAMP_TO_BORDER, (GLenum)-1 };
@ -309,6 +335,7 @@ struct GLMTexSamplingParams
gGL->glSamplerParameteri( nSamplerObject, GL_TEXTURE_SRGB_DECODE_EXT, m_packed.m_srgb ? GL_DECODE_EXT : GL_SKIP_DECODE_EXT );
}
}
#endif // !OSX
inline void DeltaSetToTarget( GLenum target, const GLMTexSamplingParams &curState )
{
@ -381,7 +408,7 @@ struct GLMTexSamplingParams
}
}
inline void SetToTargetTexture( GLenum target )
inline void SetToTarget( 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 };
@ -431,6 +458,7 @@ public:
void Lock( GLMTexLockParams *params, char** addressOut, int* yStrideOut, int *zStrideOut );
void Unlock( GLMTexLockParams *params );
GLuint GetTexName() { return m_texName; }
protected:
friend class GLMContext; // only GLMContext can make CGLMTex objects
@ -444,7 +472,7 @@ protected:
friend struct IDirect3DCubeTexture9;
friend struct IDirect3DVolumeTexture9;
CGLMTex( GLMContext *ctx, GLMTexLayout *layout, const char *debugLabel = NULL );
CGLMTex( GLMContext *ctx, GLMTexLayout *layout, uint levels, const char *debugLabel = NULL );
~CGLMTex( );
int CalcSliceIndex( int face, int mip );
@ -454,13 +482,17 @@ protected:
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.
#if defined( OSX )
void HandleSRGBMismatch( bool srgb, int &srgbFlipCount );
void ResetSRGB( bool srgb, bool noDataWrite );
// 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
#endif
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
@ -468,25 +500,26 @@ protected:
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
char *m_backing; // backing storage if available
int m_lockCount; // lock reqs are stored in the GLMContext for tracking
@ -497,6 +530,7 @@ protected:
bool m_texClientStorage; // was CS selected for texture
bool m_texPreloaded; // has it been kicked into VRAM with GLMContext::PreloadTex yet
int m_srgbFlipCount;
#if GLMDEBUG
CGLMTex *m_pPrevTex;
CGLMTex *m_pNextTex;

View File

@ -1,4 +1,26 @@
//========= Copyright Valve Corporation, All rights reserved. ============//
// TOGL CODE LICENSE
//
// Copyright 2011-2014 Valve Corporation
// All Rights Reserved.
//
// Permission is hereby granted, free of charge, to any person obtaining a copy
// of this software and associated documentation files (the "Software"), to deal
// in the Software without restriction, including without limitation the rights
// to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
// copies of the Software, and to permit persons to whom the Software is
// furnished to do so, subject to the following conditions:
//
// The above copyright notice and this permission notice shall be included in
// all copies or substantial portions of the Software.
//
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
// THE SOFTWARE.
//
// dxabstract.h
//
@ -18,8 +40,10 @@
#define IUNKNOWN_ALLOC_SPEW 0
#define IUNKNOWN_ALLOC_SPEW_MARK_ALL 0
TOGL_INTERFACE void toglGetClientRect( VD3DHWND hWnd, RECT *destRect );
struct TOGL_CLASS IUnknown
{
int m_refcount[2];
@ -138,7 +162,6 @@ struct TOGL_CLASS IDirect3DBaseTexture9 : public IDirect3DResource9 // "A T
{
D3DSURFACE_DESC m_descZero; // desc of top level.
CGLMTex *m_tex; // a CGLMTex can represent all forms of tex
int m_srgbFlipCount;
virtual ~IDirect3DBaseTexture9();
D3DRESOURCETYPE TOGLMETHODCALLTYPE GetType();
@ -270,7 +293,8 @@ struct TOGL_CLASS IDirect3DPixelShader9 : public IDirect3DResource9 //was IUnkno
uint m_pixHighWater; // count of active constant slots referenced by shader.
uint m_pixSamplerMask; // (1<<n) mask of samplers referemnced by this pixel shader
// this can help FlushSamplers avoid SRGB flipping on textures not being referenced...
uint m_pixSamplerTypes; // SAMPLER_TYPE_2D, etc.
uint m_pixSamplerTypes; // SAMPLER_TYPE_2D, etc.
uint m_pixFragDataMask; // (1<<n) mask of gl_FragData[n] referenced by this pixel shader
virtual ~IDirect3DPixelShader9();
};
@ -404,6 +428,7 @@ struct TOGL_CLASS IDirect3DDevice9 : public IUnknown
//
HRESULT TOGLMETHODCALLTYPE Reset(D3DPRESENT_PARAMETERS* pPresentationParameters);
HRESULT TOGLMETHODCALLTYPE SetViewport(CONST D3DVIEWPORT9* pViewport);
HRESULT TOGLMETHODCALLTYPE GetViewport(D3DVIEWPORT9* pViewport);
HRESULT TOGLMETHODCALLTYPE BeginScene();
HRESULT TOGLMETHODCALLTYPE Clear(DWORD Count,CONST D3DRECT* pRects,DWORD Flags,D3DCOLOR Color,float Z,DWORD Stencil);
HRESULT TOGLMETHODCALLTYPE EndScene();
@ -463,6 +488,7 @@ struct TOGL_CLASS IDirect3DDevice9 : public IUnknown
// POSIX only - preheating for a specific vertex/pixel shader pair - trigger GLSL link inside GLM
HRESULT TOGLMETHODCALLTYPE LinkShaderPair( IDirect3DVertexShader9* vs, IDirect3DPixelShader9* ps );
HRESULT TOGLMETHODCALLTYPE ValidateShaderPair( IDirect3DVertexShader9* vs, IDirect3DPixelShader9* ps );
HRESULT TOGLMETHODCALLTYPE QueryShaderPair( int index, GLMShaderPairInfo *infoOut );
// vertex buffers
@ -484,7 +510,7 @@ struct TOGL_CLASS IDirect3DDevice9 : public IUnknown
FORCEINLINE HRESULT TOGLMETHODCALLTYPE SetIndices(IDirect3DIndexBuffer9* pIndexData);
HRESULT TOGLMETHODCALLTYPE SetIndicesNonInline(IDirect3DIndexBuffer9* pIndexData);
// State management.
FORCEINLINE HRESULT TOGLMETHODCALLTYPE SetRenderStateInline(D3DRENDERSTATETYPE State,DWORD Value);
FORCEINLINE HRESULT TOGLMETHODCALLTYPE SetRenderStateConstInline(D3DRENDERSTATETYPE State,DWORD Value);
@ -495,7 +521,13 @@ struct TOGL_CLASS IDirect3DDevice9 : public IUnknown
FORCEINLINE void TOGLMETHODCALLTYPE SetSamplerStates(DWORD Sampler, DWORD AddressU, DWORD AddressV, DWORD AddressW, DWORD MinFilter, DWORD MagFilter, DWORD MipFilter );
void TOGLMETHODCALLTYPE SetSamplerStatesNonInline(DWORD Sampler, DWORD AddressU, DWORD AddressV, DWORD AddressW, DWORD MinFilter, DWORD MagFilter, DWORD MipFilter );
#ifdef OSX
// required for 10.6 support
HRESULT TOGLMETHODCALLTYPE FlushIndexBindings(void); // push index buffer (set index ptr)
HRESULT TOGLMETHODCALLTYPE FlushVertexBindings(uint baseVertexIndex); // push vertex streams (set attrib ptrs)
#endif
// Draw.
HRESULT TOGLMETHODCALLTYPE DrawPrimitive(D3DPRIMITIVETYPE PrimitiveType,UINT StartVertex,UINT PrimitiveCount);
HRESULT TOGLMETHODCALLTYPE DrawIndexedPrimitive(D3DPRIMITIVETYPE PrimitiveType,INT BaseVertexIndex,UINT MinVertexIndex,UINT NumVertices,UINT startIndex,UINT primCount);
@ -514,6 +546,7 @@ struct TOGL_CLASS IDirect3DDevice9 : public IUnknown
HRESULT TOGLMETHODCALLTYPE SetLight(DWORD Index,CONST D3DLIGHT9*);
void TOGLMETHODCALLTYPE SetGammaRamp(UINT iSwapChain,DWORD Flags,CONST D3DGAMMARAMP* pRamp);
void TOGLMETHODCALLTYPE SaveGLState();
void TOGLMETHODCALLTYPE RestoreGLState();
@ -544,7 +577,6 @@ struct TOGL_CLASS IDirect3DDevice9 : public IUnknown
private:
IDirect3DDevice9( const IDirect3DDevice9& );
IDirect3DDevice9& operator= ( const IDirect3DDevice9& );
// Flushing changes to GL
void FlushClipPlaneEquation();
void InitStates();
@ -567,8 +599,9 @@ private:
// Member variables
DWORD m_nValidMarker;
IDirect3DDevice9Params m_params; // mirror of the creation inputs
public:
IDirect3DDevice9Params m_params; // mirror of the creation inputs
private:
// D3D flavor stuff
IDirect3DSurface9 *m_pRenderTargets[4];
@ -586,8 +619,8 @@ private:
IDirect3DVertexShader9 *m_vertexShader; // Set by SetVertexShader...
IDirect3DPixelShader9 *m_pixelShader; // Set by SetPixelShader...
IDirect3DBaseTexture9 *m_textures[16]; // set by SetTexture... NULL if stage inactive
D3DSamplerDesc m_samplers[16]; // set by SetSamplerState..
IDirect3DBaseTexture9 *m_textures[GLM_SAMPLER_COUNT]; // set by SetTexture... NULL if stage inactive
// GLM flavor stuff
GLMContext *m_ctx;
CGLMFBOMap *m_pFBOs;
@ -673,7 +706,7 @@ private:
bool m_FogEnable; // not really pushed to GL, just latched here
// samplers
GLMTexSamplingParams m_samplers[ 16 ];
//GLMTexSamplingParams m_samplers[GLM_SAMPLER_COUNT];
} gl;
#if GL_BATCH_PERF_ANALYSIS
@ -710,7 +743,7 @@ FORCEINLINE HRESULT TOGLMETHODCALLTYPE IDirect3DDevice9::SetSamplerState( DWORD
return SetSamplerStateNonInline( Sampler, Type, Value );
#else
Assert( GetCurrentOwnerThreadId() == ThreadGetCurrentId() );
Assert( Sampler < 16 );
Assert( Sampler < GLM_SAMPLER_COUNT );
m_ctx->SetSamplerDirty( Sampler );
@ -747,7 +780,7 @@ FORCEINLINE HRESULT TOGLMETHODCALLTYPE IDirect3DDevice9::SetSamplerState( DWORD
m_ctx->SetSamplerMaxAnisotropy( Sampler, Value);
break;
case D3DSAMP_SRGBTEXTURE:
m_samplers[ Sampler ].m_srgb = Value;
//m_samplers[ Sampler ].m_srgb = Value;
m_ctx->SetSamplerSRGBTexture(Sampler, Value);
break;
case D3DSAMP_SHADOWFILTER:
@ -768,7 +801,7 @@ FORCEINLINE void TOGLMETHODCALLTYPE IDirect3DDevice9::SetSamplerStates(
SetSamplerStatesNonInline( Sampler, AddressU, AddressV, AddressW, MinFilter, MagFilter, MipFilter );
#else
Assert( GetCurrentOwnerThreadId() == ThreadGetCurrentId() );
Assert( Sampler < 16);
Assert( Sampler < GLM_SAMPLER_COUNT);
m_ctx->SetSamplerDirty( Sampler );
@ -782,6 +815,7 @@ FORCEINLINE HRESULT TOGLMETHODCALLTYPE IDirect3DDevice9::SetTexture(DWORD Stage,
return SetTextureNonInline( Stage, pTexture );
#else
Assert( GetCurrentOwnerThreadId() == ThreadGetCurrentId() );
Assert( Stage < GLM_SAMPLER_COUNT );
m_textures[Stage] = pTexture;
m_ctx->SetSamplerTex( Stage, pTexture ? pTexture->m_tex : NULL );
return S_OK;
@ -809,13 +843,10 @@ FORCEINLINE GLenum D3DBlendOperationToGL( DWORD operation )
switch (operation)
{
case D3DBLENDOP_ADD : return GL_FUNC_ADD; // The result is the destination added to the source. Result = Source + Destination
/* not covered by dxabstract.h..
case D3DBLENDOP_SUBTRACT : return GL_FUNC_SUBTRACT; // The result is the destination subtracted from to the source. Result = Source - Destination
case D3DBLENDOP_REVSUBTRACT : return GL_FUNC_REVERSE_SUBTRACT; // The result is the source subtracted from the destination. Result = Destination - Source
case D3DBLENDOP_MIN : return GL_MIN; // The result is the minimum of the source and destination. Result = MIN(Source, Destination)
case D3DBLENDOP_MAX : return GL_MAX; // The result is the maximum of the source and destination. Result = MAX(Source, Destination)
*/
case D3DBLENDOP_SUBTRACT : return GL_FUNC_SUBTRACT; // The result is the destination subtracted from to the source. Result = Source - Destination
case D3DBLENDOP_REVSUBTRACT : return GL_FUNC_REVERSE_SUBTRACT; // The result is the source subtracted from the destination. Result = Destination - Source
case D3DBLENDOP_MIN : return GL_MIN; // The result is the minimum of the source and destination. Result = MIN(Source, Destination)
case D3DBLENDOP_MAX : return GL_MAX; // The result is the maximum of the source and destination. Result = MAX(Source, Destination)
default:
DXABSTRACT_BREAK_ON_ERROR();
return 0xFFFFFFFF;
@ -1174,7 +1205,7 @@ FORCEINLINE HRESULT TOGLMETHODCALLTYPE IDirect3DDevice9::SetStreamSource(UINT St
// OK, we are being given the stride, we don't need to calc it..
GLMPRINTF(("-X- IDirect3DDevice9::SetStreamSource setting stream #%d to D3D buf %p (GL name %d); offset %d, stride %d", StreamNumber, pStreamData, (pStreamData) ? pStreamData->m_vtxBuffer->m_name: -1, OffsetInBytes, Stride));
if ( !pStreamData )
{
OffsetInBytes = 0;

View File

@ -1,4 +1,26 @@
//========= Copyright Valve Corporation, All rights reserved. ============//
// TOGL CODE LICENSE
//
// Copyright 2011-2014 Valve Corporation
// All Rights Reserved.
//
// Permission is hereby granted, free of charge, to any person obtaining a copy
// of this software and associated documentation files (the "Software"), to deal
// in the Software without restriction, including without limitation the rights
// to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
// copies of the Software, and to permit persons to whom the Software is
// furnished to do so, subject to the following conditions:
//
// The above copyright notice and this permission notice shall be included in
// all copies or substantial portions of the Software.
//
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
// THE SOFTWARE.
//
// dxabstract_types.h
//
@ -50,10 +72,6 @@ class CGLMFBO;
#define TOGL_GLOBAL DLL_GLOBAL_IMPORT
#endif
#ifdef OSX
#error "Do not use this header's types on OSX until togo is ported to Mac!"
#endif
#define TOGLMETHODCALLTYPE __stdcall
//#define TOGLMETHODCALLTYPE
@ -176,6 +194,25 @@ typedef enum _D3DFORMAT D3DFORMAT;
#define D3DSP_OPCODESPECIFICCONTROL_MASK 0x00ff0000
#define D3DSP_OPCODESPECIFICCONTROL_SHIFT 16
// Comparison for dynamic conditional instruction opcodes (i.e. if, breakc)
typedef enum _D3DSHADER_COMPARISON
{
// < = >
D3DSPC_RESERVED0= 0, // 0 0 0
D3DSPC_GT = 1, // 0 0 1
D3DSPC_EQ = 2, // 0 1 0
D3DSPC_GE = 3, // 0 1 1
D3DSPC_LT = 4, // 1 0 0
D3DSPC_NE = 5, // 1 0 1
D3DSPC_LE = 6, // 1 1 0
D3DSPC_RESERVED1= 7 // 1 1 1
} D3DSHADER_COMPARISON;
// Comparison is part of instruction opcode token:
#define D3DSHADER_COMPARISON_SHIFT D3DSP_OPCODESPECIFICCONTROL_SHIFT
#define D3DSHADER_COMPARISON_MASK (0x7<<D3DSHADER_COMPARISON_SHIFT)
/* Flags to construct D3DRS_COLORWRITEENABLE */
#define D3DCOLORWRITEENABLE_RED (1L<<0)
@ -1004,12 +1041,7 @@ typedef enum _D3DSHADER_PARAM_REGISTER_TYPE
D3DSPR_FORCE_DWORD = 0x7fffffff, // force 32-bit size enum
} D3DSHADER_PARAM_REGISTER_TYPE;
#ifdef _MSC_VER
#pragma warning(push)
#pragma warning(disable:4201) // warning C4201: nonstandard extension used : nameless struct/union
#endif
typedef struct _D3DMATRIX
struct D3DMATRIX
{
union
{
@ -1021,12 +1053,15 @@ typedef struct _D3DMATRIX
float _41, _42, _43, _44;
};
float m[4][4];
};
} D3DMATRIX;
#ifdef _MSC_VER
#pragma warning(pop)
};
#if defined( WIN32 )
operator void* ();
bool operator == ( CONST D3DMATRIX& src ) const;
#endif
};
typedef struct _D3DVERTEXBUFFER_DESC
{
@ -1047,6 +1082,7 @@ public:
operator FLOAT* ();
float& operator()( int row, int column );
const float& operator()( int row, int column ) const;
bool operator != ( CONST D3DXMATRIX& src ) const;
};
typedef DWORD D3DCOLOR;
@ -1681,7 +1717,7 @@ struct IDirect3DDevice9Params
D3DPRESENT_PARAMETERS m_presentationParameters;
};
#define D3D_MAX_STREAMS 4
#define D3D_MAX_STREAMS 5 //9
struct D3DStreamDesc
{
IDirect3DVertexBuffer9 *m_vtxBuffer;

View File

@ -1,4 +1,26 @@
//========= Copyright Valve Corporation, All rights reserved. ============//
// TOGL CODE LICENSE
//
// Copyright 2011-2014 Valve Corporation
// All Rights Reserved.
//
// Permission is hereby granted, free of charge, to any person obtaining a copy
// of this software and associated documentation files (the "Software"), to deal
// in the Software without restriction, including without limitation the rights
// to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
// copies of the Software, and to permit persons to whom the Software is
// furnished to do so, subject to the following conditions:
//
// The above copyright notice and this permission notice shall be included in
// all copies or substantial portions of the Software.
//
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
// THE SOFTWARE.
//
// glbase.h
//
@ -12,23 +34,16 @@
#undef HAVE_GL_ARB_SYNC
#ifndef OSX
#define HAVE_GL_ARB_SYNC 1
#define HAVE_GL_ARB_SYNC 1
#endif
#ifdef USE_SDL
#include "SDL_opengl.h"
#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
#include <OpenGL/CGLCurrent.h>
#include <ApplicationServices/ApplicationServices.h>
#endif
#ifdef DX_TO_GL_ABSTRACTION
@ -37,20 +52,18 @@
#endif
#undef CurrentTime
// prevent some conflicts in SDL headers...
#undef M_PI
#include <stdint.h>
#ifndef _STDINT_H_
#define _STDINT_H_ 1
#if defined( USE_SDL )
#include "SDL.h"
#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 );
typedef void _PseudoNSGLContext; // aka NSOpenGLContext
typedef _PseudoNSGLContext *PseudoNSGLContextPtr;
CGLContextObj GetCGLContextFromNSGL( PseudoNSGLContextPtr nsglCtx );
void DelNSGLContext( PseudoNSGLContextPtr nsglCtx );
#endif
// Set TOGL_SUPPORT_NULL_DEVICE to 1 to support the NULL ref device

View File

@ -1,4 +1,26 @@
//========= Copyright Valve Corporation, All rights reserved. ============//
// TOGL CODE LICENSE
//
// Copyright 2011-2014 Valve Corporation
// All Rights Reserved.
//
// Permission is hereby granted, free of charge, to any person obtaining a copy
// of this software and associated documentation files (the "Software"), to deal
// in the Software without restriction, including without limitation the rights
// to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
// copies of the Software, and to permit persons to whom the Software is
// furnished to do so, subject to the following conditions:
//
// The above copyright notice and this permission notice shall be included in
// all copies or substantial portions of the Software.
//
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
// THE SOFTWARE.
//
// glentrypoints.h
//
@ -12,10 +34,8 @@
#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);
@ -277,7 +297,6 @@ public:
~COpenGLEntryPoints();
void ClearEntryPoints();
uint64 m_nTotalGLCycles, m_nTotalGLCalls;
int m_nOpenGLVersionMajor; // if GL_VERSION is 2.1.0, this will be set to 2.
@ -288,20 +307,26 @@ public:
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;
#ifdef OSX
#define GL_EXT(x,glmajor,glminor) bool m_bHave_##x;
#define GL_FUNC(ext,req,ret,fn,arg,call) CDynamicFunctionOpenGL< req, ret (*) arg, ret > fn;
#define GL_FUNC_VOID(ext,req,fn,arg,call) CDynamicFunctionOpenGL< req, void (*) arg, void > fn;
#else
#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;
#endif
#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;
return m_bHave_WGL_EXT_swap_control_tear;
#else
return m_bHave_GLX_EXT_swap_control_tear;
return m_bHave_GLX_EXT_swap_control_tear;
#endif
}
};

View File

@ -1,4 +1,26 @@
//========= Copyright Valve Corporation, All rights reserved. ============//
// TOGL CODE LICENSE
//
// Copyright 2011-2014 Valve Corporation
// All Rights Reserved.
//
// Permission is hereby granted, free of charge, to any person obtaining a copy
// of this software and associated documentation files (the "Software"), to deal
// in the Software without restriction, including without limitation the rights
// to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
// copies of the Software, and to permit persons to whom the Software is
// furnished to do so, subject to the following conditions:
//
// The above copyright notice and this permission notice shall be included in
// all copies or substantial portions of the Software.
//
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
// THE SOFTWARE.
// !!! 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),())
@ -39,8 +61,11 @@ 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,glDrawBuffers,(GLsizei a,const GLenum *b),(a,b))
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))
#ifndef OSX // 10.6/GL 2.1 compatability
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))
#endif
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),())
@ -185,17 +210,24 @@ GL_FUNC_VOID(GL_ARB_framebuffer_object,false,glRenderbufferStorageMultisample,(G
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)
#ifdef OSX
GL_FUNC_VOID(GL_ARB_debug_output,false,glDebugMessageCallbackARB,(void ( *a)(GLenum, GLenum , GLuint , GLenum , GLsizei , const GLchar* , GLvoid*) ,void* b),(a,b))
#else
GL_FUNC_VOID(GL_ARB_debug_output,false,glDebugMessageCallbackARB,(void (APIENTRY *a)(GLenum, GLenum , GLuint , GLenum , GLsizei , const GLchar* , GLvoid*) ,void* b),(a,b))
#endif
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)
#ifndef OSX
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_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))
@ -213,11 +245,17 @@ 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))
#endif // !OSX
GL_EXT(GL_AMD_pinned_memory,-1,-1)
GL_EXT(GL_EXT_framebuffer_multisample_blit_scaled,-1,-1)
#ifndef OSX
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))
#endif // !OSX
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),())
@ -228,6 +266,9 @@ 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)
GL_EXT( GL_ARB_buffer_storage, 4, 4 )
GL_FUNC_VOID( GL_ARB_buffer_storage, false, glBufferStorage, (GLenum target, GLsizeiptr size, const void *data, GLbitfield flags), (target, size, data, flags) )
// 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)

View File

@ -1,8 +1,33 @@
//========= Copyright Valve Corporation, All rights reserved. ============//
// TOGL CODE LICENSE
//
// Copyright 2011-2014 Valve Corporation
// All Rights Reserved.
//
// Permission is hereby granted, free of charge, to any person obtaining a copy
// of this software and associated documentation files (the "Software"), to deal
// in the Software without restriction, including without limitation the rights
// to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
// copies of the Software, and to permit persons to whom the Software is
// furnished to do so, subject to the following conditions:
//
// The above copyright notice and this permission notice shall be included in
// all copies or substantial portions of the Software.
//
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
// THE SOFTWARE.
#ifndef GLMDEBUG_H
#define GLMDEBUG_H
#include "tier0/platform.h"
#if defined( OSX )
#include <stdarg.h>
#endif
// include this anywhere you need to be able to compile-out code related specifically to GLM debugging.
@ -132,11 +157,7 @@ inline void GLMDebugger( void )
{
if (GLMDebugChannelMask() & (1<<eDebugger))
{
#ifdef OSX
asm {int 3 };
#else
DebuggerBreak();
#endif
}
if (GLMDebugChannelMask() & (1<<eGLProfiler))

View File

@ -1,4 +1,26 @@
//========= Copyright Valve Corporation, All rights reserved. ============//
// TOGL CODE LICENSE
//
// Copyright 2011-2014 Valve Corporation
// All Rights Reserved.
//
// Permission is hereby granted, free of charge, to any person obtaining a copy
// of this software and associated documentation files (the "Software"), to deal
// in the Software without restriction, including without limitation the rights
// to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
// copies of the Software, and to permit persons to whom the Software is
// furnished to do so, subject to the following conditions:
//
// The above copyright notice and this permission notice shall be included in
// all copies or substantial portions of the Software.
//
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
// THE SOFTWARE.
//
// glmdisplay.h
// display related stuff - used by both GLMgr and the CocoaMgr
@ -10,20 +32,22 @@
#pragma once
#ifdef USE_SDL
#include "SDL_opengl.h"
#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 <ApplicationServices/ApplicationServices.h>
#elif defined(DX_TO_GL_ABSTRACTION)
#include <GL/gl.h>
#include <GL/glext.h>
#include "tier0/platform.h"
#else
#error
#endif
#ifdef MAC_OS_X_VERSION_10_9
typedef uint32_t CGDirectDisplayID;
typedef uint32_t CGOpenGLDisplayMask;
typedef double CGRefreshRate;
#endif
typedef void _PseudoNSGLContext; // aka NSOpenGLContext
@ -125,7 +149,7 @@ struct GLMRendererInfoFields
bool m_intel;
bool m_intel95x;
bool m_intel3100;
bool m_intelNewer;
bool m_intelHD4000;
bool m_nv;
bool m_nvG7x;
@ -169,6 +193,7 @@ struct GLMRendererInfoFields
//--------------------------- " bads " - known bad drivers
bool m_badDriver1064NV; // this is the bad NVIDIA driver on 10.6.4 - stutter, tex corruption, black screen issues
bool m_badDriver108Intel; // this is the bad Intel HD4000 driver on 10.8 - intermittent crash on GLSL compilation.
};

View File

@ -1,4 +1,26 @@
//========= Copyright Valve Corporation, All rights reserved. ============//
// TOGL CODE LICENSE
//
// Copyright 2011-2014 Valve Corporation
// All Rights Reserved.
//
// Permission is hereby granted, free of charge, to any person obtaining a copy
// of this software and associated documentation files (the "Software"), to deal
// in the Software without restriction, including without limitation the rights
// to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
// copies of the Software, and to permit persons to whom the Software is
// furnished to do so, subject to the following conditions:
//
// The above copyright notice and this permission notice shall be included in
// all copies or substantial portions of the Software.
//
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
// THE SOFTWARE.
#ifndef GLMDISPLAYDB_H
#define GLMDISPLAYDB_H
@ -32,13 +54,24 @@ class GLMDisplayInfo
public:
GLMDisplayInfoFields m_info;
CUtlVector< GLMDisplayMode* > *m_modes; // starts out NULL, set by PopulateModes
GLMDisplayMode m_DesktopMode;
#ifdef OSX
GLMDisplayInfo( CGDirectDisplayID displayID, CGOpenGLDisplayMask displayMask );
#else
GLMDisplayInfo( void );
#endif
~GLMDisplayInfo( void );
void PopulateModes( void );
void Dump( int which );
#ifdef OSX
private:
int m_display;
#endif
};
//===============================================================================
@ -48,23 +81,55 @@ public:
class GLMRendererInfo
{
public:
GLMRendererInfoFields m_info;
GLMDisplayInfo *m_display;
GLMRendererInfoFields m_info;
#ifdef OSX
CUtlVector< GLMDisplayInfo* > *m_displays; // starts out NULL, set by PopulateDisplays
#else
GLMDisplayInfo *m_display;
#endif
#ifdef OSX
GLMRendererInfo ( GLMRendererInfoFields *info );
#else
GLMRendererInfo ();
#endif
~GLMRendererInfo ( void );
#ifndef OSX
void Init( GLMRendererInfoFields *info );
#endif
void PopulateDisplays();
void Dump( int which );
};
//===============================================================================
#ifdef OSX
// this is just a tuple describing fake adapters which are really renderer/display pairings.
// dxabstract bridges the gap between the d3d adapter-centric world and the GL renderer+display world.
// this makes it straightforward to handle cases like two video cards with two displays on one, and one on the other -
// you get three fake adapters which represent each useful screen.
// the constraint that dxa will have to follow though, is that if the user wants to change their
// display selection for full screen, they would only be able to pick on that has the same underlying renderer.
// can't change fakeAdapter from one to another with different GL renderer under it. Screen hop but no card hop.
struct GLMFakeAdapter
{
int m_rendererIndex;
int m_displayIndex;
};
#endif
class GLMDisplayDB
{
public:
#ifdef OSX
CUtlVector< GLMRendererInfo* > *m_renderers; // starts out NULL, set by PopulateRenderers
CUtlVector< GLMFakeAdapter > m_fakeAdapters;
#else
GLMRendererInfo m_renderer;
#endif
GLMDisplayDB ( void );
~GLMDisplayDB ( void );

View File

@ -1,4 +1,26 @@
//========= Copyright Valve Corporation, All rights reserved. ============//
// TOGL CODE LICENSE
//
// Copyright 2011-2014 Valve Corporation
// All Rights Reserved.
//
// Permission is hereby granted, free of charge, to any person obtaining a copy
// of this software and associated documentation files (the "Software"), to deal
// in the Software without restriction, including without limitation the rights
// to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
// copies of the Software, and to permit persons to whom the Software is
// furnished to do so, subject to the following conditions:
//
// The above copyright notice and this permission notice shall be included in
// all copies or substantial portions of the Software.
//
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
// THE SOFTWARE.
//
// glmgr.h
// singleton class, common basis for managing GL contexts
@ -11,6 +33,11 @@
#pragma once
#undef HAVE_GL_ARB_SYNC
#ifndef OSX
#define HAVE_GL_ARB_SYNC 1
#endif
#include "glbase.h"
#include "glentrypoints.h"
#include "glmdebug.h"
@ -28,6 +55,9 @@
#include "dxabstract_types.h"
#include "tier0/icommandline.h"
#undef FORCEINLINE
#define FORCEINLINE inline
//===============================================================================
#define GLM_OPENGL_VENDOR_ID 1
@ -1066,7 +1096,7 @@ struct GLMVertexSetup
#define kGLMProgramParamInt4Limit 16
#define kGLMVertexProgramParamFloat4Limit 256
#define kGLMFragmentProgramParamFloat4Limit 32
#define kGLMFragmentProgramParamFloat4Limit 256
struct GLMProgramParamsF
{
@ -1174,6 +1204,7 @@ public:
};
//===========================================================================//
#ifndef OSX
#ifndef GL_EXTERNAL_VIRTUAL_MEMORY_BUFFER_AMD
#define GL_EXTERNAL_VIRTUAL_MEMORY_BUFFER_AMD 0x9160
@ -1187,7 +1218,16 @@ class CPinnedMemoryBuffer
CPinnedMemoryBuffer & operator= ( const CPinnedMemoryBuffer & );
public:
CPinnedMemoryBuffer() : m_pRawBuf( NULL ), m_pBuf( NULL ), m_nSize( 0 ), m_nOfs( 0 ), m_nBufferObj( 0 ), m_nSyncObj( 0 )
CPinnedMemoryBuffer()
:
m_pRawBuf( NULL )
, m_pBuf( NULL )
, m_nSize( 0 )
, m_nOfs( 0 )
, m_nBufferObj( 0 )
#ifdef HAVE_GL_ARB_SYNC
, m_nSyncObj( 0 )
#endif
{
}
@ -1199,7 +1239,7 @@ public:
bool Init( uint nSize )
{
Deinit();
// Guarantee 64KB alignment
m_pRawBuf = malloc( nSize + 65535 );
m_pBuf = reinterpret_cast<void *>((reinterpret_cast<uint64>(m_pRawBuf) + 65535) & (~65535));
@ -1210,7 +1250,7 @@ public:
gGL->glBindBufferARB( GL_EXTERNAL_VIRTUAL_MEMORY_BUFFER_AMD, m_nBufferObj );
gGL->glBufferDataARB( GL_EXTERNAL_VIRTUAL_MEMORY_BUFFER_AMD, m_nSize, m_pBuf, GL_STREAM_COPY );
return true;
}
@ -1218,22 +1258,22 @@ public:
{
if ( !m_pRawBuf )
return;
BlockUntilNotBusy();
gGL->glBindBufferARB(GL_EXTERNAL_VIRTUAL_MEMORY_BUFFER_AMD, m_nBufferObj );
gGL->glBufferDataARB( GL_EXTERNAL_VIRTUAL_MEMORY_BUFFER_AMD, 0, (void*)NULL, GL_STREAM_COPY );
gGL->glBindBufferARB( GL_EXTERNAL_VIRTUAL_MEMORY_BUFFER_AMD, 0 );
gGL->glDeleteBuffersARB( 1, &m_nBufferObj );
m_nBufferObj = 0;
free( m_pRawBuf );
m_pRawBuf = NULL;
m_pBuf = NULL;
m_nSize = 0;
m_nOfs = 0;
}
@ -1246,43 +1286,49 @@ public:
void InsertFence()
{
#ifdef HAVE_GL_ARB_SYNC
if ( m_nSyncObj )
{
gGL->glDeleteSync( m_nSyncObj );
}
m_nSyncObj = gGL->glFenceSync( GL_SYNC_GPU_COMMANDS_COMPLETE, 0 );
#endif
}
void BlockUntilNotBusy()
{
#ifdef HAVE_GL_ARB_SYNC
if ( m_nSyncObj )
{
gGL->glClientWaitSync( m_nSyncObj, GL_SYNC_FLUSH_COMMANDS_BIT, 3000000000000ULL );
gGL->glDeleteSync( m_nSyncObj );
gGL->glDeleteSync( m_nSyncObj );
m_nSyncObj = 0;
}
#endif
m_nOfs = 0;
}
void Append( uint nSize )
{
m_nOfs += nSize;
Assert( m_nOfs <= m_nSize );
}
private:
void *m_pRawBuf;
void *m_pBuf;
uint m_nSize;
uint m_nOfs;
GLuint m_nBufferObj;
GLuint m_nBufferObj;
#ifdef HAVE_GL_ARB_SYNC
GLsync m_nSyncObj;
#endif
};
#endif // !OSX
//===========================================================================//
@ -1310,7 +1356,7 @@ class GLMContext
// textures
// Lock and Unlock reqs go directly to the tex object
CGLMTex *NewTex( GLMTexLayoutKey *key, const char *debugLabel=NULL );
CGLMTex *NewTex( GLMTexLayoutKey *key, uint levels=1, const char *debugLabel=NULL );
void DelTex( CGLMTex *tex );
// options for Blit (replacement for ResolveTex and BlitTex)
@ -1347,7 +1393,7 @@ class GLMContext
// render targets (FBO's)
CGLMFBO *NewFBO( void );
void DelFBO( CGLMFBO *fbo );
// programs
CGLMProgram *NewProgram( EGLMProgramType type, char *progString, const char *pShaderName );
void DelProgram( CGLMProgram *pProg );
@ -1360,6 +1406,7 @@ class GLMContext
void SetDrawingLang( EGLMProgramLang lang, bool immediate=false ); // choose ARB or GLSL. immediate=false defers lang change to top of frame
void LinkShaderPair( CGLMProgram *vp, CGLMProgram *fp ); // ensure this combo has been linked and is in the GLSL pair cache
void ValidateShaderPair( CGLMProgram *vp, CGLMProgram *fp );
void ClearShaderPairCache( void ); // call this to shoot down all the linked pairs
void QueryShaderPair( int index, GLMShaderPairInfo *infoOut ); // this lets you query the shader pair cache for saving its state
@ -1403,8 +1450,12 @@ class GLMContext
void FlushDrawStatesNoShaders();
// drawing
#ifndef OSX
FORCEINLINE void DrawRangeElements( GLenum mode, GLuint start, GLuint end, GLsizei count, GLenum type, const GLvoid *indices, uint baseVertex, CGLMBuffer *pIndexBuf );
void DrawRangeElementsNonInline( GLenum mode, GLuint start, GLuint end, GLsizei count, GLenum type, const GLvoid *indices, uint baseVertex, CGLMBuffer *pIndexBuf );
#else
void DrawRangeElements( GLenum mode, GLuint start, GLuint end, GLsizei count, GLenum type, const GLvoid *indices, CGLMBuffer *pIndexBuf );
#endif
void CheckNative( void );
@ -1421,7 +1472,7 @@ class GLMContext
// Called when IDirect3DDevice9::Reset() is called.
void Reset();
// writers for the state block inputs
FORCEINLINE void WriteAlphaTestEnable( GLAlphaTestEnable_t *src ) { m_AlphaTestEnable.Write( src ); }
@ -1482,7 +1533,6 @@ class GLMContext
#endif
FORCEINLINE void SetMaxUsedVertexShaderConstantsHint( uint nMaxConstants );
FORCEINLINE DWORD GetCurrentOwnerThreadId() const { return m_nCurOwnerThreadId; }
protected:
@ -1507,8 +1557,10 @@ class GLMContext
GLMContext( IDirect3DDevice9 *pDevice, GLMDisplayParams *params );
~GLMContext();
#ifndef OSX
FORCEINLINE GLuint FindSamplerObject( const GLMTexSamplingParams &desiredParams );
#endif
FORCEINLINE void SetBufAndVertexAttribPointer( uint nIndex, GLuint nGLName, GLuint stride, GLuint datatype, GLboolean normalized, GLuint nCompCount, const void *pBuf, uint nRevision )
{
VertexAttribs_t &curAttribs = m_boundVertexAttribs[nIndex];
@ -1518,7 +1570,7 @@ class GLMContext
gGL->glBindBufferARB( GL_ARRAY_BUFFER_ARB, nGLName );
}
else if ( ( curAttribs.m_pPtr == pBuf ) &&
( curAttribs.m_revision == nRevision ) &&
( curAttribs.m_revision == nRevision ) &&
( curAttribs.m_stride == stride ) &&
( curAttribs.m_datatype == datatype ) &&
( curAttribs.m_normalized == normalized ) &&
@ -1533,7 +1585,7 @@ class GLMContext
curAttribs.m_stride = stride;
curAttribs.m_pPtr = pBuf;
curAttribs.m_revision = nRevision;
gGL->glVertexAttribPointer( nIndex, nCompCount, datatype, normalized, stride, pBuf );
}
@ -1555,7 +1607,7 @@ class GLMContext
m_CurAttribs.m_vtxAttribMap[0] = 0xBBBBBBBBBBBBBBBBULL;
m_CurAttribs.m_vtxAttribMap[1] = 0xBBBBBBBBBBBBBBBBULL;
}
FORCEINLINE void ReleasedShader() { NullProgram(); }
// textures
@ -1572,7 +1624,7 @@ class GLMContext
// render targets / FBO's
void BindFBOToCtx( CGLMFBO *fbo, GLenum bindPoint = GL_FRAMEBUFFER_EXT ); // you can also choose GL_READ_FRAMEBUFFER_EXT / GL_DRAW_FRAMEBUFFER_EXT
// buffers
FORCEINLINE void BindGLBufferToCtx( GLenum nGLBufType, GLuint nGLName, bool bForce = false )
{
@ -1585,40 +1637,48 @@ class GLMContext
gGL->glBindBufferARB( nGLBufType, nGLName );
}
}
void BindBufferToCtx( EGLMBufferType type, CGLMBuffer *buff, bool force = false ); // does not twiddle any enables.
FORCEINLINE void BindIndexBufferToCtx( CGLMBuffer *buff );
FORCEINLINE void BindVertexBufferToCtx( CGLMBuffer *buff );
CPinnedMemoryBuffer *GetCurPinnedMemoryBuffer( ) { return &m_PinnedMemoryBuffers[m_nCurPinnedMemoryBuffer]; }
// members------------------------------------------
GLuint CreateTex( GLenum texBind, GLenum internalFormat );
void CleanupTex( GLenum texBind, GLMTexLayout* pLayout, GLuint tex );
void DestroyTex( GLenum texBind, GLMTexLayout* pLayout, GLuint tex );
GLuint FillTexCache( bool holdOne, int newTextures );
void PurgeTexCache( );
// debug font
void GenDebugFontTex( void );
void DrawDebugText( float x, float y, float z, float drawCharWidth, float drawCharHeight, char *string );
#ifndef OSX
CPinnedMemoryBuffer *GetCurPinnedMemoryBuffer( ) { return &m_PinnedMemoryBuffers[m_nCurPinnedMemoryBuffer]; }
#endif
CPersistentBuffer* GetCurPersistentBuffer( EGLMBufferType type ) { return &( m_persistentBuffer[m_nCurPersistentBuffer][type] ); }
// members------------------------------------------
// context
DWORD m_nCurOwnerThreadId;
uint m_nThreadOwnershipReleaseCounter;
bool m_bUseSamplerObjects;
bool m_bPreferMapBufferRange;
bool m_bTexClientStorage;
IDirect3DDevice9 *m_pDevice;
GLMRendererInfoFields m_caps;
bool m_displayParamsValid; // is there a param block copied in yet
GLMDisplayParams m_displayParams; // last known display config, either via constructor, or by SetDisplayParams...
#ifdef OSX
CGLPixelFormatAttribute m_pixelFormatAttribs[100]; // more than enough
PseudoNSGLContextPtr m_nsctx;
CGLContextObj m_ctx;
#elif defined( USE_SDL )
#if defined( USE_SDL )
int m_pixelFormatAttribs[100]; // more than enough
PseudoNSGLContextPtr m_nsctx;
void * m_ctx;
#endif
bool m_oneCtxEnable; // true if we use the window's context directly instead of making a second one shared against it
bool m_bUseBoneUniformBuffers; // if true, we use two uniform buffers for vertex shader constants vs. one
// texture form table
@ -1712,15 +1772,17 @@ class GLMContext
CGLMFBO *m_scratchFBO[ kGLMScratchFBOCount ]; // general purpose FBO's for internal use
CUtlVector< CGLMFBO* > m_fboTable; // each live FBO goes in the table
uint m_fragDataMask;
// program bindings
EGLMProgramLang m_drawingLangAtFrameStart; // selector for start of frame (spills into m_drawingLang)
EGLMProgramLang m_drawingLang; // selector for which language we desire to draw with on the next batch
CGLMProgram *m_drawingProgram[ kGLMNumProgramTypes ];
bool m_bDirtyPrograms;
GLMProgramParamsF m_programParamsF[ kGLMNumProgramTypes ];
GLMProgramParamsB m_programParamsB[ kGLMNumProgramTypes ]; // two banks, but only the vertex one is used
GLMProgramParamsB m_programParamsB[ kGLMNumProgramTypes ];
GLMProgramParamsI m_programParamsI[ kGLMNumProgramTypes ]; // two banks, but only the vertex one is used
EGLMParamWriteMode m_paramWriteMode;
@ -1730,7 +1792,11 @@ class GLMContext
CGLMProgram *m_preload2DTexFragmentProgram;
CGLMProgram *m_preload3DTexFragmentProgram;
CGLMProgram *m_preloadCubeTexFragmentProgram;
#if defined( OSX ) && defined( GLMDEBUG )
CGLMProgram *m_boundProgram[ kGLMNumProgramTypes ];
#endif
CGLMShaderPairCache *m_pairCache; // GLSL only
CGLMShaderPair *m_pBoundPair; // GLSL only
@ -1741,7 +1807,7 @@ class GLMContext
// buffer bindings
GLuint m_nBoundGLBuffer[kGLMNumBufferTypes];
struct VertexAttribs_t
{
GLuint m_nCompCount;
@ -1773,23 +1839,39 @@ class GLMContext
// batch/frame debugging support
int m_debugFrameIndex; // init to -1. Increment at BeginFrame
int m_nMaxUsedVertexProgramConstantsHint;
uint32 m_dwRenderThreadId;
volatile bool m_bIsThreading;
uint m_nCurFrame;
uint m_nBatchCounter;
struct TextureEntry_t
{
GLenum m_nTexBind;
GLenum m_nInternalFormat;
GLuint m_nTexName;
};
GLuint m_destroyPBO;
CUtlVector< TextureEntry_t > m_availableTextures;
#ifndef OSX
enum { cNumPinnedMemoryBuffers = 4 };
CPinnedMemoryBuffer m_PinnedMemoryBuffers[cNumPinnedMemoryBuffers];
uint m_nCurPinnedMemoryBuffer;
#endif
enum { cNumPersistentBuffers = 3 };
CPersistentBuffer m_persistentBuffer[cNumPersistentBuffers][kGLMNumBufferTypes];
uint m_nCurPersistentBuffer;
void SaveColorMaskAndSetToDefault();
void RestoreSavedColorMask();
GLColorMaskSingle_t m_SavedColorMask;
#if GLMDEBUG
// interactive (DebugHook) debug support
@ -1825,6 +1907,8 @@ class GLMContext
#endif
};
#ifndef OSX
FORCEINLINE void GLMContext::DrawRangeElements( GLenum mode, GLuint start, GLuint end, GLsizei count, GLenum type, const GLvoid *indices, uint baseVertex, CGLMBuffer *pIndexBuf )
{
#if GL_ENABLE_INDEX_VERIFICATION
@ -1836,20 +1920,25 @@ FORCEINLINE void GLMContext::DrawRangeElements( GLenum mode, GLuint start, GLuin
#else
//tmZone( TELEMETRY_LEVEL0, TMZF_NONE, "%s %d-%d count:%d mode:%d type:%d", __FUNCTION__, start, end, count, mode, type );
#endif
++m_nBatchCounter;
SetIndexBuffer( pIndexBuf );
void *indicesActual = (void*)indices;
if ( pIndexBuf->m_bPseudo )
{
// you have to pass actual address, not offset
indicesActual = (void*)( (int)indicesActual + (int)pIndexBuf->m_pPseudoBuf );
}
if (pIndexBuf->m_bUsingPersistentBuffer)
{
indicesActual = (void*)( (int)indicesActual + (int)pIndexBuf->m_nPersistentBufferStartOffset );
}
#if GLMDEBUG
//#if GLMDEBUG
#if 0
bool hasVP = m_drawingProgram[ kGLMVertexProgram ] != NULL;
bool hasFP = m_drawingProgram[ kGLMFragmentProgram ] != NULL;
@ -1931,6 +2020,8 @@ FORCEINLINE void GLMContext::DrawRangeElements( GLenum mode, GLuint start, GLuin
#endif // GL_ENABLE_INDEX_VERIFICATION
}
#endif // #ifndef OSX
FORCEINLINE void GLMContext::SetVertexProgram( CGLMProgram *pProg )
{
m_drawingProgram[kGLMVertexProgram] = pProg;
@ -1969,23 +2060,53 @@ FORCEINLINE void GLMContext::SetProgramParametersF( EGLMProgramType type, uint b
if ( ( type == kGLMVertexProgram ) && ( m_bUseBoneUniformBuffers ) )
{
if ( ( baseSlot + slotCount ) > DXABSTRACT_VS_FIRST_BONE_SLOT )
// changes here to handle vertex shaders which use constants before and after the bone array i.e. before c58 and after c216
// a better change may be to modify the shaders and place the bone consts at either start or end - would simplify this and the flush code
// the current supporting code (shader translator(dx9asmtogl2), param setting(here) and flushing(glmgr_flush.inl) should work unchanged, even if the const mapping is changed.
int firstDirty = (int)baseSlot;
int highWater = (int)(baseSlot + slotCount);
if ( highWater <= DXABSTRACT_VS_FIRST_BONE_SLOT )
{
if ( baseSlot < DXABSTRACT_VS_FIRST_BONE_SLOT )
m_programParamsF[kGLMVertexProgram].m_firstDirtySlotNonBone = MIN( m_programParamsF[kGLMVertexProgram].m_firstDirtySlotNonBone, firstDirty );
m_programParamsF[kGLMVertexProgram].m_dirtySlotHighWaterNonBone = MAX( m_programParamsF[kGLMVertexProgram].m_dirtySlotHighWaterNonBone, highWater );
}
else if ( highWater <= (DXABSTRACT_VS_LAST_BONE_SLOT+1) )
{
if ( firstDirty < DXABSTRACT_VS_FIRST_BONE_SLOT )
{
// The register set crosses between the constant buffers - should only happen at startup during init.
m_programParamsF[kGLMVertexProgram].m_firstDirtySlotNonBone = MIN( m_programParamsF[kGLMVertexProgram].m_firstDirtySlotNonBone, (int)baseSlot );
m_programParamsF[kGLMVertexProgram].m_dirtySlotHighWaterNonBone = MAX( m_programParamsF[kGLMVertexProgram].m_dirtySlotHighWaterNonBone, (int)MIN( baseSlot + slotCount, DXABSTRACT_VS_FIRST_BONE_SLOT ) );
baseSlot = DXABSTRACT_VS_FIRST_BONE_SLOT;
m_programParamsF[kGLMVertexProgram].m_firstDirtySlotNonBone = MIN( m_programParamsF[kGLMVertexProgram].m_firstDirtySlotNonBone, firstDirty );
m_programParamsF[kGLMVertexProgram].m_dirtySlotHighWaterNonBone = MAX( m_programParamsF[kGLMVertexProgram].m_dirtySlotHighWaterNonBone, MIN( DXABSTRACT_VS_FIRST_BONE_SLOT, highWater ) );
firstDirty = DXABSTRACT_VS_FIRST_BONE_SLOT;
}
int nNumActualBones = ( baseSlot + slotCount ) - DXABSTRACT_VS_FIRST_BONE_SLOT;
int nNumActualBones = ( firstDirty + slotCount ) - DXABSTRACT_VS_FIRST_BONE_SLOT;
m_programParamsF[kGLMVertexProgram].m_dirtySlotHighWaterBone = MAX( m_programParamsF[kGLMVertexProgram].m_dirtySlotHighWaterBone, nNumActualBones );
}
else
{
m_programParamsF[kGLMVertexProgram].m_firstDirtySlotNonBone = MIN( m_programParamsF[kGLMVertexProgram].m_firstDirtySlotNonBone, (int)baseSlot );
m_programParamsF[kGLMVertexProgram].m_dirtySlotHighWaterNonBone = MAX( m_programParamsF[kGLMVertexProgram].m_dirtySlotHighWaterNonBone, (int)(baseSlot + slotCount) );
const int maxBoneSlots = ( DXABSTRACT_VS_LAST_BONE_SLOT + 1 ) - DXABSTRACT_VS_FIRST_BONE_SLOT;
if ( firstDirty > DXABSTRACT_VS_LAST_BONE_SLOT )
{
m_programParamsF[kGLMVertexProgram].m_firstDirtySlotNonBone = MIN( m_programParamsF[kGLMVertexProgram].m_firstDirtySlotNonBone, firstDirty - maxBoneSlots );
m_programParamsF[kGLMVertexProgram].m_dirtySlotHighWaterNonBone = MAX( m_programParamsF[kGLMVertexProgram].m_dirtySlotHighWaterNonBone, highWater - maxBoneSlots );
}
else if ( firstDirty >= DXABSTRACT_VS_FIRST_BONE_SLOT )
{
m_programParamsF[kGLMVertexProgram].m_dirtySlotHighWaterBone = DXABSTRACT_VS_LAST_BONE_SLOT + 1;
m_programParamsF[kGLMVertexProgram].m_firstDirtySlotNonBone = MIN( m_programParamsF[kGLMVertexProgram].m_firstDirtySlotNonBone, DXABSTRACT_VS_FIRST_BONE_SLOT );
m_programParamsF[kGLMVertexProgram].m_dirtySlotHighWaterNonBone = MAX( m_programParamsF[kGLMVertexProgram].m_dirtySlotHighWaterNonBone, highWater - maxBoneSlots );
}
else
{
int nNumActualBones = ( DXABSTRACT_VS_LAST_BONE_SLOT + 1 ) - DXABSTRACT_VS_FIRST_BONE_SLOT;
m_programParamsF[kGLMVertexProgram].m_dirtySlotHighWaterBone = MAX( m_programParamsF[kGLMVertexProgram].m_dirtySlotHighWaterBone, nNumActualBones );
m_programParamsF[kGLMVertexProgram].m_firstDirtySlotNonBone = MIN( m_programParamsF[kGLMVertexProgram].m_firstDirtySlotNonBone, firstDirty );
m_programParamsF[kGLMVertexProgram].m_dirtySlotHighWaterNonBone = MAX( m_programParamsF[kGLMVertexProgram].m_dirtySlotHighWaterNonBone, highWater - maxBoneSlots );
}
}
}
else
@ -2002,7 +2123,7 @@ FORCEINLINE void GLMContext::SetProgramParametersB( EGLMProgramType type, uint b
#endif
Assert( m_drawingLang == kGLMGLSL );
Assert( type==kGLMVertexProgram );
Assert( type==kGLMVertexProgram || type==kGLMFragmentProgram );
Assert( baseSlot < kGLMProgramParamBoolLimit );
Assert( baseSlot+boolCount <= kGLMProgramParamBoolLimit );
@ -2069,21 +2190,21 @@ FORCEINLINE void GLMContext::SetSamplerTex( int sampler, CGLMTex *tex )
m_samplers[sampler].m_pBoundTex = tex;
if ( tex )
{
if ( !gGL->m_bHave_GL_EXT_direct_state_access )
{
if ( sampler != m_activeTexture )
if ( !gGL->m_bHave_GL_EXT_direct_state_access )
{
gGL->glActiveTexture( GL_TEXTURE0 + sampler );
m_activeTexture = sampler;
}
if ( sampler != m_activeTexture )
{
gGL->glActiveTexture( GL_TEXTURE0 + sampler );
m_activeTexture = sampler;
}
gGL->glBindTexture( tex->m_texGLTarget, tex->m_texName );
gGL->glBindTexture( tex->m_texGLTarget, tex->m_texName );
}
else
{
gGL->glBindMultiTextureEXT( GL_TEXTURE0 + sampler, tex->m_texGLTarget, tex->m_texName );
}
}
else
{
gGL->glBindMultiTextureEXT( GL_TEXTURE0 + sampler, tex->m_texGLTarget, tex->m_texName );
}
}
if ( !m_bUseSamplerObjects )
{
@ -2184,8 +2305,8 @@ FORCEINLINE void GLMContext::BindIndexBufferToCtx( CGLMBuffer *buff )
GLMPRINTF(( "--- GLMContext::BindIndexBufferToCtx buff %p, GL name %d", buff, (buff) ? buff->m_nHandle : -1 ));
Assert( !buff || ( buff->m_buffGLTarget == GL_ELEMENT_ARRAY_BUFFER_ARB ) );
GLuint nGLName = buff ? buff->m_nHandle : 0;
GLuint nGLName = buff ? buff->GetHandle() : 0;
if ( m_nBoundGLBuffer[ kGLMIndexBuffer] == nGLName )
return;
@ -2199,8 +2320,8 @@ FORCEINLINE void GLMContext::BindVertexBufferToCtx( CGLMBuffer *buff )
GLMPRINTF(( "--- GLMContext::BindVertexBufferToCtx buff %p, GL name %d", buff, (buff) ? buff->m_nHandle : -1 ));
Assert( !buff || ( buff->m_buffGLTarget == GL_ARRAY_BUFFER_ARB ) );
GLuint nGLName = buff ? buff->m_nHandle : 0;
GLuint nGLName = buff ? buff->GetHandle() : 0;
if ( m_nBoundGLBuffer[ kGLMVertexBuffer] == nGLName )
return;
@ -2232,6 +2353,45 @@ struct GLMTestParams
int m_frameCount; // how many frames to test.
};
class GLMTester
{
public:
GLMTester(GLMTestParams *params);
~GLMTester();
// optionally callable by test routines to get basic drawables wired up
void StdSetup( void );
void StdCleanup( void );
// callable by test routines to clear the frame or present it
void Clear( void );
void Present( int seed );
// error reporting
void CheckGLError( const char *comment ); // obey m_params setting for console / debugger response
void InternalError( int errcode, char *comment ); // if errcode!=0, obey m_params setting for console / debugger response
void RunTests();
void RunOneTest( int testindex );
// test routines themselves
void Test0();
void Test1();
void Test2();
void Test3();
GLMTestParams m_params; // copy of caller's params, do not mutate...
// std-setup stuff
int m_drawWidth, m_drawHeight;
CGLMFBO *m_drawFBO;
CGLMTex *m_drawColorTex;
CGLMTex *m_drawDepthTex;
};
class CShowPixelsParams
{
public:

View File

@ -1,4 +1,26 @@
//========= Copyright Valve Corporation, All rights reserved. ============//
// TOGL CODE LICENSE
//
// Copyright 2011-2014 Valve Corporation
// All Rights Reserved.
//
// Permission is hereby granted, free of charge, to any person obtaining a copy
// of this software and associated documentation files (the "Software"), to deal
// in the Software without restriction, including without limitation the rights
// to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
// copies of the Software, and to permit persons to whom the Software is
// furnished to do so, subject to the following conditions:
//
// The above copyright notice and this permission notice shall be included in
// all copies or substantial portions of the Software.
//
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
// THE SOFTWARE.
//
// glmgrbasics.h
// types, common headers, forward declarations, utilities
@ -10,20 +32,20 @@
#pragma once
#ifdef USE_SDL
#include "SDL_opengl.h"
#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 <AvailabilityMacros.h>
#ifndef MAC_OS_X_VERSION_10_9
#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
#endif
#include "tier0/platform.h"
@ -301,8 +323,10 @@ public:
CUtlVector< GLMTextSection > m_sectionTable;
};
#ifndef OSX
void GLMGPUTimestampManagerInit();
void GLMGPUTimestampManagerDeinit();
void GLMGPUTimestampManagerTick();
#endif
#endif // GLMBASICS_H

View File

@ -1,4 +1,26 @@
//========= Copyright Valve Corporation, All rights reserved. ============//
// TOGL CODE LICENSE
//
// Copyright 2011-2014 Valve Corporation
// All Rights Reserved.
//
// Permission is hereby granted, free of charge, to any person obtaining a copy
// of this software and associated documentation files (the "Software"), to deal
// in the Software without restriction, including without limitation the rights
// to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
// copies of the Software, and to permit persons to whom the Software is
// furnished to do so, subject to the following conditions:
//
// The above copyright notice and this permission notice shall be included in
// all copies or substantial portions of the Software.
//
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
// THE SOFTWARE.
//
// glmgrext.h
// helper file for extension testing and runtime importing of entry points
@ -91,3 +113,11 @@
#define GL_MAP_UNSYNCHRONIZED_BIT 0x0020
#endif
#ifndef GL_MAP_PERSISTENT_BIT
#define GL_MAP_PERSISTENT_BIT 0x0040
#endif
#ifndef GL_MAP_COHERENT_BIT
#define GL_MAP_COHERENT_BIT 0x0080
#endif