mirror of
https://github.com/celisej567/source-engine.git
synced 2026-01-04 18:09:53 +03:00
Update ToGLES( fix occlusion query and other small things )
This commit is contained in:
@@ -37,7 +37,7 @@ bool g_bUsePseudoBufs = false; //( Plat_GetCommandLineA() ) ? ( strstr( Plat_Get
|
||||
// Significant perf degradation on some OSX parts if static buffers not disabled
|
||||
bool g_bDisableStaticBuffer = true;
|
||||
#else
|
||||
bool g_bDisableStaticBuffer = false; //( Plat_GetCommandLineA() ) ? ( strstr( Plat_GetCommandLineA(), "-gl_disable_static_buffer" ) != NULL ) : false;
|
||||
bool g_bDisableStaticBuffer = true; //( Plat_GetCommandLineA() ) ? ( strstr( Plat_GetCommandLineA(), "-gl_disable_static_buffer" ) != NULL ) : false;
|
||||
#endif
|
||||
|
||||
// http://www.opengl.org/registry/specs/ARB/vertex_buffer_object.txt
|
||||
@@ -93,8 +93,8 @@ CPersistentBuffer::~CPersistentBuffer()
|
||||
|
||||
void CPersistentBuffer::Init( EGLMBufferType type,uint nSize )
|
||||
{
|
||||
Assert( gGL->m_bHave_GL_EXT_buffer_storage );
|
||||
Assert( gGL->m_bHave_GL_ARB_map_buffer_range );
|
||||
// Assert( gGL->m_bHave_GL_EXT_buffer_storage );
|
||||
// Assert( gGL->m_bHave_GL_ARB_map_buffer_range );
|
||||
|
||||
m_nSize = nSize;
|
||||
m_nOffset = 0;
|
||||
@@ -527,13 +527,13 @@ CGLMBuffer::CGLMBuffer( GLMContext *pCtx, EGLMBufferType type, uint size, uint o
|
||||
// buffers start out static, but if they get orphaned and gl_bufmode is non zero,
|
||||
// then they will get flipped to dynamic.
|
||||
|
||||
GLenum hint = GL_STATIC_DRAW;
|
||||
GLenum hint = GL_STREAM_DRAW;
|
||||
switch (m_type)
|
||||
{
|
||||
case kGLMVertexBuffer: hint = m_bDynamic ? GL_DYNAMIC_DRAW : GL_STATIC_DRAW; break;
|
||||
case kGLMIndexBuffer: hint = m_bDynamic ? GL_DYNAMIC_DRAW : GL_STATIC_DRAW; break;
|
||||
case kGLMVertexBuffer: hint = m_bDynamic ? GL_DYNAMIC_DRAW : GL_STREAM_DRAW; break;
|
||||
case kGLMIndexBuffer: hint = m_bDynamic ? GL_DYNAMIC_DRAW : GL_STREAM_DRAW; break;
|
||||
case kGLMUniformBuffer: hint = GL_DYNAMIC_DRAW; break;
|
||||
case kGLMPixelBuffer: hint = m_bDynamic ? GL_DYNAMIC_DRAW : GL_STATIC_DRAW; break;
|
||||
case kGLMPixelBuffer: hint = m_bDynamic ? GL_DYNAMIC_DRAW : GL_STREAM_DRAW; break;
|
||||
|
||||
default: Assert(!"Unknown buffer type" ); DXABSTRACT_BREAK_ON_ERROR();
|
||||
}
|
||||
@@ -786,7 +786,7 @@ void CGLMBuffer::Lock( GLMBuffLockParams *pParams, char **pAddressOut )
|
||||
|
||||
// observe gl_bufmode on any orphan event.
|
||||
// if orphaned and bufmode is nonzero, flip it to dynamic.
|
||||
GLenum hint = gl_bufmode.GetInt() ? GL_DYNAMIC_DRAW : GL_STATIC_DRAW;
|
||||
GLenum hint = gl_bufmode.GetInt() ? GL_DYNAMIC_DRAW : GL_STREAM_DRAW;
|
||||
gGL->glBufferData( m_buffGLTarget, m_nSize, (const GLvoid*)NULL, hint );
|
||||
|
||||
m_nRevision++; // revision grows on orphan event
|
||||
@@ -829,7 +829,7 @@ void CGLMBuffer::Lock( GLMBuffLockParams *pParams, char **pAddressOut )
|
||||
// if orphaned and bufmode is nonzero, flip it to dynamic.
|
||||
|
||||
// We always want to call glBufferData( ..., NULL ) on discards, even though we're using the GL_MAP_INVALIDATE_BUFFER_BIT flag, because this flag is actually only a hint according to AMD.
|
||||
GLenum hint = gl_bufmode.GetInt() ? GL_DYNAMIC_DRAW : GL_STATIC_DRAW;
|
||||
GLenum hint = gl_bufmode.GetInt() ? GL_DYNAMIC_DRAW : GL_STREAM_DRAW;
|
||||
gGL->glBufferData( m_buffGLTarget, m_nSize, (const GLvoid*)NULL, hint );
|
||||
|
||||
m_nRevision++; // revision grows on orphan event
|
||||
@@ -1047,7 +1047,7 @@ void CGLMBuffer::Unlock( int nActualSize, const void *pActualData )
|
||||
Assert( nActualSize <= (int)( m_dirtyMaxOffset - m_dirtyMinOffset ) );
|
||||
|
||||
glBufferSubDataMaxSize( m_buffGLTarget, m_dirtyMinOffset, nActualSize, pActualData ? pActualData : m_pStaticBuffer );
|
||||
|
||||
|
||||
#ifdef REPORT_LOCK_TIME
|
||||
double flEnd = Plat_FloatTime();
|
||||
if ( flEnd - flStart > 5.0 / 1000.0 )
|
||||
|
||||
@@ -362,8 +362,8 @@ void CGLMProgram::Compile( EGLMProgramLang lang )
|
||||
|
||||
GLchar log[4096];
|
||||
gGL->glGetShaderInfoLog( glslDesc->m_object.glsl, sizeof(log), &maxLength, log );
|
||||
printf("shader compile log: %s\n", log);
|
||||
printf("Shader %d source is:\n===============\n%s\nn===============\n", glslDesc->m_object.glsl, section);
|
||||
Msg("shader compile log: %s\n", log);
|
||||
Msg("Shader %d source is:\n===============\n%s\nn===============\n", glslDesc->m_object.glsl, section);
|
||||
}
|
||||
|
||||
#if 0 //GLM_FREE_SHADER_TEXT
|
||||
@@ -785,8 +785,6 @@ bool CGLMShaderPair::ValidateProgramPair()
|
||||
{
|
||||
gGL->glUseProgram( m_program );
|
||||
|
||||
printf("Sample text\n");
|
||||
|
||||
m_ctx->NewLinkedProgram();
|
||||
|
||||
m_locVertexParams = gGL->glGetUniformLocation( m_program, "vc" );
|
||||
|
||||
@@ -163,7 +163,7 @@ void CGLMQuery::Start( void ) // "start counting"
|
||||
}
|
||||
else
|
||||
{
|
||||
gGL->glBeginQuery( GL_SAMPLES_PASSED, m_name );
|
||||
gGL->glBeginQuery( GL_ANY_SAMPLES_PASSED, m_name );
|
||||
}
|
||||
}
|
||||
break;
|
||||
@@ -204,7 +204,7 @@ void CGLMQuery::Stop( void ) // "stop counting"
|
||||
}
|
||||
else
|
||||
{
|
||||
gGL->glEndQuery( GL_SAMPLES_PASSED ); // we are only putting the request-to-stop-counting into the cmd stream.
|
||||
gGL->glEndQuery( GL_ANY_SAMPLES_PASSED ); // we are only putting the request-to-stop-counting into the cmd stream.
|
||||
}
|
||||
}
|
||||
break;
|
||||
|
||||
@@ -114,7 +114,7 @@ const GLMTexFormatDesc g_formatDescTable[] =
|
||||
{ "_A8R8G8B8", D3DFMT_A8R8G8B8, GL_RGBA8, GL_SRGB8_ALPHA8_EXT, GL_BGRA, GL_UNSIGNED_INT_8_8_8_8_REV, 1, 4 },
|
||||
{ "_A4R4G4B4", D3DFMT_A4R4G4B4, GL_RGBA4, 0, GL_BGRA, GL_UNSIGNED_SHORT_4_4_4_4_REV, 1, 2 },
|
||||
{ "_X8R8G8B8", D3DFMT_X8R8G8B8, GL_RGB8, GL_SRGB8_EXT, GL_BGRA, GL_UNSIGNED_INT_8_8_8_8_REV, 1, 4 },
|
||||
|
||||
|
||||
{ "_X1R5G5B5", D3DFMT_X1R5G5B5, GL_RGB5, 0, GL_BGRA, GL_UNSIGNED_SHORT_1_5_5_5_REV, 1, 2 },
|
||||
{ "_A1R5G5B5", D3DFMT_A1R5G5B5, GL_RGB5_A1, 0, GL_BGRA, GL_UNSIGNED_SHORT_1_5_5_5_REV, 1, 2 },
|
||||
|
||||
@@ -1106,6 +1106,8 @@ void CGLMTex::CalcTexelDataOffsetAndStrides( int sliceIndex, int x, int y, int z
|
||||
*zStrideOut = zStride;
|
||||
}
|
||||
|
||||
extern void convert_texture( GLint &internalformat, GLsizei width, GLsizei height, GLenum &format, GLenum &type, void *data );
|
||||
|
||||
void CGLMTex::ReadTexels( GLMTexLockDesc *desc, bool readWholeSlice )
|
||||
{
|
||||
GLMRegion readBox;
|
||||
@@ -1177,26 +1179,24 @@ void CGLMTex::ReadTexels( GLMTexLockDesc *desc, bool readWholeSlice )
|
||||
gGL->glBindFramebuffer(GL_FRAMEBUFFER, fbo);
|
||||
gGL->glFramebufferTexture2D(GL_FRAMEBUFFER, GL_COLOR_ATTACHMENT0, GL_TEXTURE_2D, m_ctx->m_samplers[0].m_pBoundTex->m_texName, 0);
|
||||
|
||||
uint fmt = format->m_glDataFormat;
|
||||
GLenum fmt = format->m_glDataFormat;
|
||||
if( fmt == GL_BGR )
|
||||
fmt = GL_RGB;
|
||||
else if( fmt == GL_BGRA )
|
||||
fmt = GL_RGBA;
|
||||
|
||||
gGL->glReadPixels(0, 0, m_layout->m_slices[ desc->m_sliceIndex ].m_xSize, m_layout->m_slices[ desc->m_sliceIndex ].m_ySize, fmt , format->m_glDataType == GL_UNSIGNED_INT_8_8_8_8_REV ? GL_UNSIGNED_BYTE : format->m_glDataType, sliceAddress);
|
||||
|
||||
gGL->glReadPixels(0, 0, m_layout->m_slices[ desc->m_sliceIndex ].m_xSize, m_layout->m_slices[ desc->m_sliceIndex ].m_ySize, fmt, format->m_glDataType == GL_UNSIGNED_INT_8_8_8_8_REV ? GL_UNSIGNED_BYTE : format->m_glDataType, sliceAddress);
|
||||
GLint intformat = format->m_glDataFormat;
|
||||
GLenum _format = format->m_glDataFormat;
|
||||
GLenum _type = format->m_glDataType;
|
||||
|
||||
// TODO(nillerusr): Don't convert, should change m_format to another one
|
||||
convert_texture(intformat, m_layout->m_slices[ desc->m_sliceIndex ].m_xSize, m_layout->m_slices[ desc->m_sliceIndex ].m_ySize, _format, _type, sliceAddress);
|
||||
|
||||
gGL->glBindFramebuffer(GL_READ_FRAMEBUFFER, Rfbo);
|
||||
gGL->glBindFramebuffer(GL_DRAW_FRAMEBUFFER, Dfbo);
|
||||
|
||||
gGL->glDeleteFramebuffers(1, &fbo);
|
||||
|
||||
#if 0
|
||||
gGL->glGetTexImage( target, // target
|
||||
desc->m_req.m_mip, // level
|
||||
format->m_glDataFormat, // dataformat
|
||||
format->m_glDataType, // datatype
|
||||
sliceAddress ); // destination
|
||||
#endif
|
||||
}
|
||||
}
|
||||
break;
|
||||
@@ -3258,7 +3258,6 @@ const char *get_enum_str(uint val)
|
||||
if( g_glEnums[i].value == val )
|
||||
return g_glEnums[i].str;
|
||||
}
|
||||
|
||||
return "UNKNOWN";
|
||||
}
|
||||
|
||||
@@ -3301,6 +3300,148 @@ static inline float float_h2f(halffloat_t t)
|
||||
return tmp.f;
|
||||
}
|
||||
|
||||
static inline halffloat_t float_f2h(float f)
|
||||
{
|
||||
fullfloat_t tmp;
|
||||
halffloat_t ret;
|
||||
tmp.f = f;
|
||||
ret.x.sign = tmp.x.sign;
|
||||
if (tmp.x.exp == 0) {
|
||||
// O and denormal
|
||||
ret.bin = 0;
|
||||
} else if (tmp.x.exp==255) {
|
||||
// Inf / NaN
|
||||
ret.x.exp = 31;
|
||||
ret.x.mant = tmp.x.mant>>13;
|
||||
} else if(tmp.x.exp>0x71) {
|
||||
// flush to 0
|
||||
ret.x.exp = 0;
|
||||
ret.x.mant = 0;
|
||||
} else if(tmp.x.exp<0x8e) {
|
||||
// clamp to max
|
||||
ret.x.exp = 30;
|
||||
ret.x.mant = 1023;
|
||||
} else {
|
||||
ret.x.exp = tmp.x.exp - 38;
|
||||
ret.x.mant = tmp.x.mant>>13;
|
||||
}
|
||||
|
||||
return ret;
|
||||
}
|
||||
|
||||
static uint8_t srgb_table[256] = {0};
|
||||
void pixel_srgb_inplace(GLvoid* pixels, GLuint size, GLuint width, GLuint height)
|
||||
{
|
||||
// return;
|
||||
if(!srgb_table[255]) {
|
||||
// create table
|
||||
for (int i=1; i<256; ++i) {
|
||||
srgb_table[i] = floorf(255.f*powf(i/255.f, 2.2f)+0.5f);
|
||||
}
|
||||
}
|
||||
uint8_t *data = (uint8_t*)pixels;
|
||||
int sz = width*height*size;
|
||||
for (int i=0; i < sz; i += size)
|
||||
{
|
||||
data[i] = srgb_table[data[i]];
|
||||
data[i+1] = srgb_table[data[i+1]];
|
||||
data[i+2] = srgb_table[data[i+2]];
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
||||
void convert_texture( GLint &internalformat, GLsizei width, GLsizei height, GLenum &format, GLenum &type, void *data )
|
||||
{
|
||||
// printf("internalformat=%s format=%s type=%s\n", get_enum_str(internalformat), get_enum_str(format), get_enum_str(type));
|
||||
|
||||
if( internalformat == GL_SRGB8 && (format == GL_RGBA || format == GL_BGRA ))
|
||||
internalformat = GL_SRGB8_ALPHA8;
|
||||
|
||||
if( format == GL_LUMINANCE || format == GL_LUMINANCE_ALPHA )
|
||||
internalformat = format;
|
||||
|
||||
// if( internalformat == GL_SRGB8_ALPHA8 )
|
||||
// internalformat = GL_RGBA;
|
||||
|
||||
// if( internalformat == GL_SRGB8 )
|
||||
// internalformat = GL_RGB;
|
||||
|
||||
if( data )
|
||||
{
|
||||
uint8_t *_data = (uint8_t*)data;
|
||||
|
||||
if( format == GL_BGR )
|
||||
{
|
||||
for( int i = 0; i < width*height*3; i+=3 )
|
||||
{
|
||||
uint8_t tmp = _data[i];
|
||||
_data[i] = _data[i+2];
|
||||
_data[i+2] = tmp;
|
||||
}
|
||||
format = GL_RGB;
|
||||
}
|
||||
else if( format == GL_BGRA )
|
||||
{
|
||||
for( int i = 0; i < width*height*4; i+=4 )
|
||||
{
|
||||
uint8_t tmp = _data[i];
|
||||
_data[i] = _data[i+2];
|
||||
_data[i+2] = tmp;
|
||||
}
|
||||
format = GL_RGBA;
|
||||
}
|
||||
|
||||
if( internalformat == GL_RGBA16 && !gGL->m_bHave_GL_EXT_texture_norm16 )
|
||||
{
|
||||
uint16_t *_data = (uint16_t*)data;
|
||||
uint8_t *new_data = (uint8_t*)data;
|
||||
|
||||
for( int i = 0; i < width*height*4; i+=4 )
|
||||
{
|
||||
new_data[i] = _data[i] >> 8;
|
||||
new_data[i+1] = _data[i+1] >> 8;
|
||||
new_data[i+2] = _data[i+2] >> 8;
|
||||
new_data[i+3] = _data[i+3] >> 8;
|
||||
}
|
||||
|
||||
internalformat = GL_RGBA;
|
||||
format = GL_RGBA;
|
||||
type = GL_UNSIGNED_BYTE;
|
||||
}
|
||||
else if( internalformat == GL_SRGB8_ALPHA8 )
|
||||
{
|
||||
// pixel_srgb_inplace( data, 4, width, height );
|
||||
internalformat = GL_RGBA;
|
||||
}
|
||||
else if( internalformat == GL_SRGB8 )
|
||||
{
|
||||
// pixel_srgb_inplace( data, 3, width, height );
|
||||
internalformat = GL_RGB;
|
||||
}
|
||||
|
||||
}
|
||||
else
|
||||
{
|
||||
if( format == GL_BGR )
|
||||
format = GL_RGB;
|
||||
else if( format == GL_BGRA )
|
||||
format = GL_RGBA;
|
||||
|
||||
if( internalformat == GL_RGBA16 && !gGL->m_bHave_GL_EXT_texture_norm16 )
|
||||
{
|
||||
internalformat = GL_RGBA;
|
||||
format = GL_RGBA;
|
||||
type = GL_UNSIGNED_BYTE;
|
||||
}
|
||||
}
|
||||
|
||||
if( type == GL_UNSIGNED_INT_8_8_8_8_REV )
|
||||
type = GL_UNSIGNED_BYTE;
|
||||
|
||||
// printf("internalformat=%s format=%s type=%s\n==========================================\n", get_enum_str(internalformat), get_enum_str(format), get_enum_str(type));
|
||||
}
|
||||
|
||||
void TexImage2D(GLenum target,
|
||||
GLint level,
|
||||
GLint internalformat,
|
||||
@@ -3311,65 +3452,8 @@ void TexImage2D(GLenum target,
|
||||
GLenum type,
|
||||
const void * data)
|
||||
{
|
||||
if( type == GL_UNSIGNED_INT_8_8_8_8_REV )
|
||||
type = GL_UNSIGNED_BYTE;
|
||||
|
||||
if( format == GL_BGR )
|
||||
format = GL_RGB;
|
||||
convert_texture( internalformat, width, height, format, type, data );
|
||||
|
||||
if( format == GL_BGRA )
|
||||
format = GL_RGBA;
|
||||
|
||||
if( internalformat == GL_SRGB8 && format == GL_RGBA )
|
||||
internalformat = GL_SRGB8_ALPHA8;
|
||||
|
||||
if( format == GL_LUMINANCE || format == GL_LUMINANCE_ALPHA )
|
||||
internalformat = format;
|
||||
|
||||
#if 0
|
||||
if( internalformat == GL_SRGB8 )
|
||||
internalformat = GL_RGB;
|
||||
if( internalformat == GL_SRGB8_ALPHA8 )
|
||||
internalformat = GL_RGBA;*/
|
||||
|
||||
if( data )
|
||||
{
|
||||
if( internalformat == GL_RGBA16F )
|
||||
{
|
||||
uint16_t *_data = (uint16_t*)data;
|
||||
uint8_t *new_data = (uint8_t*)data;
|
||||
|
||||
for( int i = 0; i < width*height*4; i+=4 )
|
||||
{
|
||||
halffloat_t fl;
|
||||
fl.bin = _data[i]; new_data[i] = float_h2f(fl)*255;
|
||||
fl.bin = _data[i+1]; new_data[i+1] = float_h2f(fl)*255;
|
||||
fl.bin = _data[i+2]; new_data[i+2] = float_h2f(fl)*255;
|
||||
fl.bin = _data[i+3]; new_data[i+3] = float_h2f(fl)*255;
|
||||
}
|
||||
internalformat = GL_RGBA;
|
||||
type = GL_UNSIGNED_BYTE;
|
||||
}
|
||||
else if( internalformat == GL_RGBA16 )
|
||||
{
|
||||
uint16_t *_data = (uint16_t*)data;
|
||||
uint8_t *new_data = (uint8_t*)data;
|
||||
|
||||
for( int i = 0; i < width*height*4; i+=4 )
|
||||
{
|
||||
new_data[i] = _data[i] >> 8;
|
||||
new_data[i+1] = _data[i+1] >> 8;
|
||||
new_data[i+2] = _data[i+2] >> 8;
|
||||
new_data[i+3] = _data[i+3] >> 8;
|
||||
}
|
||||
|
||||
data = new_data;
|
||||
internalformat = GL_RGBA;
|
||||
type = GL_UNSIGNED_BYTE;
|
||||
}
|
||||
}
|
||||
#endif
|
||||
|
||||
gGL->glTexImage2D(target, level, internalformat, width, height, border, format, type, data);
|
||||
}
|
||||
|
||||
@@ -3501,10 +3585,28 @@ void CompressedTexImage2D(GLenum target, GLint level, GLenum internalformat,
|
||||
if( srgb )
|
||||
intformat = GL_SRGB8_ALPHA8;
|
||||
}
|
||||
//gGL->glTexImage2D(target, 0, internalformat, width, height, border, format, type, data);
|
||||
|
||||
TexImage2D( target, level, intformat, width, height, border, format, type, pixels );
|
||||
gGL->glTexImage2D(target, level, intformat, width, height, border, format, type, pixels);
|
||||
//TexImage2D( target, level, intformat, width, height, border, format, type, pixels );
|
||||
if( data != pixels )
|
||||
free(pixels);
|
||||
}
|
||||
|
||||
void TexSubImage2D( GLenum target,
|
||||
GLint level,
|
||||
GLint xoffset,
|
||||
GLint yoffset,
|
||||
GLsizei width,
|
||||
GLsizei height,
|
||||
GLenum format,
|
||||
GLint internalformat,
|
||||
GLenum type,
|
||||
const void * data)
|
||||
{
|
||||
convert_texture( internalformat, width, height, format, type, data );
|
||||
gGL->glTexSubImage2D( target, level, xoffset, yoffset, width, height, format, type, data);
|
||||
}
|
||||
|
||||
// TexSubImage should work properly on every driver stack and GPU--enabling by default.
|
||||
ConVar gl_enabletexsubimage( "gl_enabletexsubimage", "1" );
|
||||
|
||||
@@ -3562,11 +3664,11 @@ void CGLMTex::WriteTexels( GLMTexLockDesc *desc, bool writeWholeSlice, bool noDa
|
||||
|
||||
// allow use of subimage if the target is texture2D and it has already been teximage'd
|
||||
bool mayUseSubImage = false;
|
||||
//if ( (target==GL_TEXTURE_2D) && (m_sliceFlags[ desc->m_sliceIndex ] & kSliceValid) )
|
||||
//{
|
||||
// mayUseSubImage = gl_enabletexsubimage.GetInt() != 0;
|
||||
//}
|
||||
|
||||
if ( (target==GL_TEXTURE_2D) && (m_sliceFlags[ desc->m_sliceIndex ] & kSliceValid) )
|
||||
{
|
||||
// mayUseSubImage = gl_enabletexsubimage.GetInt() != 0;
|
||||
}
|
||||
|
||||
// check flavor, 2D, 3D, or cube map
|
||||
// we also have the choice to use subimage if this is a tex already created. (open question as to benefit)
|
||||
|
||||
@@ -3681,54 +3783,28 @@ void CGLMTex::WriteTexels( GLMTexLockDesc *desc, bool writeWholeSlice, bool noDa
|
||||
{
|
||||
// go subimage2D if it's a replacement, not a creation
|
||||
|
||||
|
||||
gGL->glPixelStorei( GL_UNPACK_ROW_LENGTH, slice->m_xSize ); // in pixels
|
||||
gGL->glPixelStorei( GL_UNPACK_SKIP_PIXELS, writeBox.xmin ); // in pixels
|
||||
gGL->glPixelStorei( GL_UNPACK_SKIP_ROWS, writeBox.ymin ); // in pixels
|
||||
|
||||
gGL->glTexSubImage2D( glDataFormat,
|
||||
|
||||
TexSubImage2D( target,
|
||||
desc->m_req.m_mip, // level
|
||||
writeBox.xmin, // xoffset into dest
|
||||
writeBox.ymin, // yoffset into dest
|
||||
writeBox.xmax - writeBox.xmin, // width (was slice->m_xSize)
|
||||
writeBox.ymax - writeBox.ymin, // height (was slice->m_ySize)
|
||||
glDataFormat, // format
|
||||
glDataType == GL_UNSIGNED_INT_8_8_8_8_REV ? GL_UNSIGNED_BYTE : glDataType, // type
|
||||
intformat,
|
||||
glDataType, // type
|
||||
sliceAddress // data (will be offsetted by the SKIP_PIXELS and SKIP_ROWS - let GL do the math to find the first source texel)
|
||||
);
|
||||
|
||||
gGL->glPixelStorei( GL_UNPACK_ROW_LENGTH, 0 );
|
||||
gGL->glPixelStorei( GL_UNPACK_SKIP_PIXELS, 0 );
|
||||
gGL->glPixelStorei( GL_UNPACK_SKIP_ROWS, 0 );
|
||||
|
||||
/*
|
||||
//http://www.opengl.org/sdk/docs/man/xhtml/glTexSubImage2D.xml
|
||||
glTexSubImage2D( target,
|
||||
desc->m_req.m_mip, // level
|
||||
0, // xoffset
|
||||
0, // yoffset
|
||||
slice->m_xSize, // width
|
||||
slice->m_ySize, // height
|
||||
glDataFormat, // format
|
||||
glDataType, // type
|
||||
sliceAddress // data
|
||||
);
|
||||
*/
|
||||
gGL->glPixelStorei( GL_UNPACK_SKIP_ROWS, 0 );
|
||||
}
|
||||
else
|
||||
{
|
||||
if (m_layout->m_key.m_texFlags & kGLMTexRenderable)
|
||||
{
|
||||
if (gl_rt_forcergba.GetInt())
|
||||
{
|
||||
if (glDataFormat == GL_BGRA)
|
||||
{
|
||||
// change it
|
||||
glDataFormat = GL_RGBA;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
{
|
||||
// uncompressed path
|
||||
// http://www.opengl.org/documentation/specs/man_pages/hardcopy/GL/html/gl/teximage2d.html
|
||||
TexImage2D( target, // target
|
||||
|
||||
@@ -1381,7 +1381,7 @@ void D3DToGL::PrintParameterToString ( uint32 dwToken, uint32 dwSourceOrDest, ch
|
||||
case D3DSRO_FOG:
|
||||
if( !m_bFogFragCoord )
|
||||
{
|
||||
StrcatToHeaderCode("varying mediump vec4 _gl_FogFragCoord;\n");
|
||||
StrcatToHeaderCode("varying highp vec4 _gl_FogFragCoord;\n");
|
||||
m_bFogFragCoord = true;
|
||||
}
|
||||
|
||||
@@ -1403,7 +1403,7 @@ void D3DToGL::PrintParameterToString ( uint32 dwToken, uint32 dwSourceOrDest, ch
|
||||
{
|
||||
if( !m_bFrontColor )
|
||||
{
|
||||
StrcatToHeaderCode("varying lowp vec4 _gl_FrontColor;\n");
|
||||
StrcatToHeaderCode("varying highp vec4 _gl_FrontColor;\n");
|
||||
m_bFrontColor = true;
|
||||
}
|
||||
|
||||
@@ -1413,7 +1413,7 @@ void D3DToGL::PrintParameterToString ( uint32 dwToken, uint32 dwSourceOrDest, ch
|
||||
{
|
||||
if( !m_bFrontSecondaryColor )
|
||||
{
|
||||
StrcatToHeaderCode("varying lowp vec4 _gl_FrontSecondaryColor;\n");
|
||||
StrcatToHeaderCode("varying highp vec4 _gl_FrontSecondaryColor;\n");
|
||||
m_bFrontSecondaryColor = true;
|
||||
}
|
||||
|
||||
@@ -2545,14 +2545,14 @@ void D3DToGL::Handle_TEX( uint32 dwToken, bool bIsTexLDL )
|
||||
V_snprintf( szExtra, sizeof( szExtra ), ".%c", GetSwizzleComponent( pSrc0Reg, 3 ) );
|
||||
V_strncat( szLOD, szExtra, sizeof( szLOD ) );
|
||||
|
||||
PrintToBufWithIndents( *m_pBufALUCode, "%s = %s( %s, %s, %s );\n", pDestReg, bIsShadowSampler ? "shadow2DLod" : "textureLod", pSrc1Reg, sCoordVar.String(), szLOD );
|
||||
PrintToBufWithIndents( *m_pBufALUCode, "%s = %s( %s, %s, %s );\n", pDestReg, "textureLod", pSrc1Reg, sCoordVar.String(), szLOD );
|
||||
}
|
||||
else if ( bIsShadowSampler )
|
||||
{
|
||||
// .z is meant to contain the object depth, while .xy contains the 2D tex coords
|
||||
CUtlString sCoordVar3D = EnsureNumSwizzleComponents( pSrc0Reg, 3 );
|
||||
|
||||
PrintToBufWithIndents( *m_pBufALUCode, "%s = shadow2D( %s, %s );\n", pDestReg, pSrc1Reg, sCoordVar3D.String() );
|
||||
PrintToBufWithIndents( *m_pBufALUCode, "%s = vec4(texture( %s, %s ));\n", pDestReg, pSrc1Reg, sCoordVar3D.String() );
|
||||
Assert( m_dwSamplerTypes[dwSrc1Token & D3DSP_REGNUM_MASK] == SAMPLER_TYPE_2D );
|
||||
}
|
||||
else if( ( OpcodeSpecificData( dwToken ) << D3DSP_OPCODESPECIFICCONTROL_SHIFT ) == D3DSI_TEXLD_PROJECT )
|
||||
@@ -2934,13 +2934,19 @@ void D3DToGL::WriteGLSLSamplerDefinitions()
|
||||
{
|
||||
int nSamplersWritten = 0;
|
||||
bool m_bSampler3d = false;
|
||||
bool m_bShadowSampler = false;
|
||||
for ( int i=0; i < ARRAYSIZE( m_dwSamplerTypes ); i++ )
|
||||
{
|
||||
if ( m_dwSamplerTypes[i] == SAMPLER_TYPE_2D )
|
||||
{
|
||||
if ( ( ( 1 << i ) & m_nShadowDepthSamplerMask ) != 0 )
|
||||
{
|
||||
PrintToBuf( *m_pBufHeaderCode, "uniform sampler2D sampler%d;\n", i );
|
||||
if( !m_bShadowSampler )
|
||||
{
|
||||
PrintToBuf( *m_pBufHeaderCode, "precision lowp sampler2DShadow;\n", i );
|
||||
m_bShadowSampler = true;
|
||||
}
|
||||
PrintToBuf( *m_pBufHeaderCode, "uniform sampler2DShadow sampler%d;\n", i );
|
||||
}
|
||||
else
|
||||
{
|
||||
@@ -2955,7 +2961,6 @@ void D3DToGL::WriteGLSLSamplerDefinitions()
|
||||
StrcatToHeaderCode( "precision mediump sampler3D;\n" );
|
||||
m_bSampler3d = true;
|
||||
}
|
||||
|
||||
PrintToBuf( *m_pBufHeaderCode, "uniform sampler3D sampler%d;\n", i );
|
||||
++nSamplersWritten;
|
||||
}
|
||||
@@ -3006,7 +3011,7 @@ void D3DToGL::WriteGLSLOutputVariableAssignments()
|
||||
{
|
||||
if( !m_bFrontColor )
|
||||
{
|
||||
StrcatToHeaderCode("varying lowp vec4 _gl_FrontColor;\n");
|
||||
StrcatToHeaderCode("varying highp vec4 _gl_FrontColor;\n");
|
||||
m_bFrontColor = true;
|
||||
}
|
||||
|
||||
@@ -3181,9 +3186,9 @@ int D3DToGL::TranslateShader( uint32* code, CUtlBuffer *pBufDisassembledCode, bo
|
||||
m_bPutHexCodesAfterLines = (options & D3DToGL_PutHexCommentsAfterLines) != 0;
|
||||
m_bGeneratingDebugText = (options & D3DToGL_GeneratingDebugText) != 0;
|
||||
m_bGenerateSRGBWriteSuffix = (options & D3DToGL_OptionSRGBWriteSuffix) != 0;
|
||||
// m_bGenerateSRGBWriteSuffix = true;
|
||||
m_bGenerateSRGBWriteSuffix = false;
|
||||
|
||||
if( debugLabel && ( V_strstr( debugLabel ,"vertexlit_and_unlit_generic_bump_ps") ))
|
||||
if( debugLabel && (V_strstr( debugLabel ,"vertexlit_and_unlit_generic_ps") || V_strstr( debugLabel ,"vertexlit_and_unlit_generic_bump_ps") ) )
|
||||
m_bGenerateSRGBWriteSuffix = true;
|
||||
|
||||
m_NumIndentTabs = 1; // start code indented one tab
|
||||
@@ -3277,13 +3282,13 @@ int D3DToGL::TranslateShader( uint32* code, CUtlBuffer *pBufDisassembledCode, bo
|
||||
if ( ( dwToken & 0xFFFF0000 ) == 0xFFFF0000 )
|
||||
{
|
||||
// must explicitly enable extensions if emitting GLSL
|
||||
V_snprintf( (char *)m_pBufHeaderCode->Base(), m_pBufHeaderCode->Size(), "#version 300 es\nprecision mediump float;\n#define varying in\n\n%s", glslExtText );
|
||||
V_snprintf( (char *)m_pBufHeaderCode->Base(), m_pBufHeaderCode->Size(), "#version 300 es\nprecision highp float;\n#define varying in\n\n%s", glslExtText );
|
||||
m_bVertexShader = false;
|
||||
}
|
||||
else // vertex shader
|
||||
{
|
||||
m_bGenerateSRGBWriteSuffix = false;
|
||||
V_snprintf( (char *)m_pBufHeaderCode->Base(), m_pBufHeaderCode->Size(), "#version 300 es\nprecision mediump float;\n#define attribute in\n#define varying out\n%s//ATTRIBMAP-xx-xx-xx-xx-xx-xx-xx-xx-xx-xx-xx-xx-xx-xx-xx-xx\n", glslExtText );
|
||||
V_snprintf( (char *)m_pBufHeaderCode->Base(), m_pBufHeaderCode->Size(), "#version 300 es\nprecision highp float;\n#define attribute in\n#define varying out\n%s//ATTRIBMAP-xx-xx-xx-xx-xx-xx-xx-xx-xx-xx-xx-xx-xx-xx-xx-xx\n", glslExtText );
|
||||
|
||||
// find that first '-xx' which is where the attrib map will be written later.
|
||||
pAttribMapStart = strstr( (char *)m_pBufHeaderCode->Base(), "-xx" ) + 1;
|
||||
@@ -3889,14 +3894,15 @@ int D3DToGL::TranslateShader( uint32* code, CUtlBuffer *pBufDisassembledCode, bo
|
||||
|
||||
#define FindSubcode(a) (V_strstr((char*)m_pBufALUCode->Base(), a) != 0 || V_strstr((char*)m_pBufHeaderCode->Base(), a) != 0 || V_strstr((char*)m_pBufParamCode->Base(), a) != 0 || V_strstr((char*)m_pBufAttribCode->Base(), a) != 0 )
|
||||
|
||||
/*
|
||||
if( FindSubcode("shadow2DProj") )
|
||||
{
|
||||
StrcatToHeaderCode( g_szShadow2D );
|
||||
StrcatToHeaderCode( g_szShadow2DProj );
|
||||
}
|
||||
else if( FindSubcode("shadow2D") )
|
||||
StrcatToHeaderCode( g_szShadow2D );
|
||||
|
||||
StrcatToHeaderCode( g_szShadow2D );*/
|
||||
|
||||
if( FindSubcode("_gl_FrontColor") && !m_bFrontColor )
|
||||
StrcatToHeaderCode( "in vec4 _gl_FrontColor;\n" );
|
||||
|
||||
|
||||
@@ -1201,8 +1201,8 @@ static void FillD3DCaps9( const GLMRendererInfoFields &glmRendererInfo, D3DCAPS9
|
||||
pCaps->MaxPixelShader30InstructionSlots = 0;
|
||||
|
||||
#if DX_TO_GL_ABSTRACTION
|
||||
pCaps->FakeSRGBWrite = true;//!glmRendererInfo.m_hasGammaWrites;
|
||||
pCaps->CanDoSRGBReadFromRTs = true;//!glmRendererInfo.m_cantAttachSRGB;
|
||||
pCaps->FakeSRGBWrite = !glmRendererInfo.m_hasGammaWrites;
|
||||
pCaps->CanDoSRGBReadFromRTs = !glmRendererInfo.m_cantAttachSRGB;
|
||||
pCaps->MixedSizeTargets = glmRendererInfo.m_hasMixedAttachmentSizes;
|
||||
#endif
|
||||
}
|
||||
@@ -1320,9 +1320,9 @@ HRESULT IDirect3D9::CheckDeviceFormat(UINT Adapter,D3DDEVTYPE DeviceType,D3DFORM
|
||||
| D3DUSAGE_QUERY_VERTEXTEXTURE;
|
||||
(void)knownUsageMask;
|
||||
|
||||
// FramebufferSRGB stuff.
|
||||
// basically a format is only allowed to have SRGB usage for writing, if you have the framebuffer SRGB extension.
|
||||
// so, check for that capability with GLM adapter db, and if it's not there, don't mark that bit as usable in any of our formats.
|
||||
// FramebufferSRGB stuff.
|
||||
// basically a format is only allowed to have SRGB usage for writing, if you have the framebuffer SRGB extension.
|
||||
// so, check for that capability with GLM adapter db, and if it's not there, don't mark that bit as usable in any of our formats.
|
||||
GLMDisplayDB *db = GetDisplayDB();
|
||||
int glmRendererIndex = -1;
|
||||
int glmDisplayIndex = -1;
|
||||
|
||||
@@ -333,6 +333,9 @@ static bool CheckOpenGLExtension(const char *ext, const int coremajor, const int
|
||||
return retval;
|
||||
}
|
||||
|
||||
extern bool g_bUsePseudoBufs;
|
||||
extern bool g_bDisableStaticBuffer;
|
||||
|
||||
// The GL context you want entry points for must be current when you hit this constructor!
|
||||
COpenGLEntryPoints::COpenGLEntryPoints()
|
||||
: m_nTotalGLCycles(0)
|
||||
@@ -387,17 +390,24 @@ COpenGLEntryPoints::COpenGLEntryPoints()
|
||||
{
|
||||
m_bHave_GL_EXT_framebuffer_object = true;
|
||||
m_bHave_GL_EXT_framebuffer_blit = true;
|
||||
m_bHave_GL_EXT_framebuffer_multisample = true;
|
||||
m_bHave_GL_ARB_occlusion_query = true;
|
||||
m_bHave_GL_ARB_map_buffer_range = true;
|
||||
m_bHave_GL_EXT_direct_state_access = false;
|
||||
m_bHave_GL_ARB_occlusion_query = true;
|
||||
m_bHave_GL_EXT_buffer_storage = false;
|
||||
m_bHave_GL_ARB_vertex_buffer_object = true;
|
||||
m_bHave_GL_ARB_vertex_array_bgra = true;
|
||||
m_bHave_GL_EXT_vertex_array_bgra = true;
|
||||
m_bHave_GL_ARB_debug_output = true;
|
||||
m_bHave_GL_EXT_direct_state_access = false;
|
||||
m_bHave_GL_EXT_framebuffer_multisample_blit_scaled = true;
|
||||
m_bHave_GL_EXT_texture_sRGB_decode = true;
|
||||
m_bHave_GL_ARB_sync = true;
|
||||
|
||||
// m_bHave_GL_EXT_texture_sRGB_decode = true;
|
||||
|
||||
if( CommandLine()->FindParm( "-gl_enable_pseudobufs" ) )
|
||||
g_bUsePseudoBufs = true;
|
||||
if( CommandLine()->FindParm( "-gl_enable_static_buffer" ) )
|
||||
g_bDisableStaticBuffer = false;
|
||||
if( CommandLine()->FindParm( "-gl_enable_buffer_storage" ) )
|
||||
m_bHave_GL_EXT_buffer_storage = true;
|
||||
|
||||
#if 0
|
||||
glBindFramebuffer.Force(glBindFramebuffer.Pointer());
|
||||
glBindRenderbuffer.Force(glBindRenderbuffer.Pointer());
|
||||
glCheckFramebufferStatus.Force(glCheckFramebufferStatus.Pointer());
|
||||
@@ -410,6 +420,7 @@ COpenGLEntryPoints::COpenGLEntryPoints()
|
||||
glDeleteFramebuffers.Force(glDeleteFramebuffers.Pointer());
|
||||
glBlitFramebuffer.Force(glBlitFramebuffer.Pointer());
|
||||
glRenderbufferStorageMultisample.Force(glRenderbufferStorageMultisample.Pointer());
|
||||
#endif
|
||||
}
|
||||
|
||||
#if DEBUG_ALL_GLCALLS
|
||||
@@ -417,10 +428,10 @@ COpenGLEntryPoints::COpenGLEntryPoints()
|
||||
#define GL_EXT(x,glmajor,glminor)
|
||||
#define GL_FUNC(ext,req,ret,fn,arg,call) \
|
||||
fn##_gldebugptr = this->fn; \
|
||||
this->fn.Force(fn##_gldebug);
|
||||
// this->fn.Force(fn##_gldebug);
|
||||
#define GL_FUNC_VOID(ext,req,fn,arg,call) \
|
||||
fn##_gldebugptr = this->fn; \
|
||||
this->fn.Force(fn##_gldebug);
|
||||
// this->fn.Force(fn##_gldebug);
|
||||
#include "togles/glfuncs.inl"
|
||||
#undef GL_FUNC_VOID
|
||||
#undef GL_FUNC
|
||||
@@ -434,6 +445,7 @@ COpenGLEntryPoints::COpenGLEntryPoints()
|
||||
if ( ( m_bHave_GL_NV_bindless_texture ) && ( !CommandLine()->CheckParm( "-gl_nv_bindless_texturing" ) ) )
|
||||
{
|
||||
m_bHave_GL_NV_bindless_texture = false;
|
||||
#if 0
|
||||
glGetTextureHandleNV.Force( NULL );
|
||||
glGetTextureSamplerHandleNV.Force( NULL );
|
||||
glMakeTextureHandleResidentNV.Force( NULL );
|
||||
@@ -443,6 +455,7 @@ COpenGLEntryPoints::COpenGLEntryPoints()
|
||||
glProgramUniformHandleui64NV.Force( NULL );
|
||||
glProgramUniformHandleui64vNV.Force( NULL );
|
||||
glIsTextureHandleResidentNV.Force( NULL );
|
||||
#endif
|
||||
}
|
||||
|
||||
if ( !CommandLine()->CheckParm( "-gl_amd_pinned_memory" ) )
|
||||
@@ -501,6 +514,3 @@ void COpenGLEntryPoints::ClearEntryPoints()
|
||||
}
|
||||
// Turn off memdbg macros (turned on up top) since this is included like a header
|
||||
#include "tier0/memdbgoff.h"
|
||||
|
||||
|
||||
|
||||
|
||||
@@ -229,7 +229,7 @@ void APIENTRY GL_Debug_Output_Callback(GLenum source, GLenum type, GLuint id, GL
|
||||
|
||||
if ( ( type == GL_DEBUG_TYPE_ERROR_ARB ) && ( g_bDebugOutputBreakpoints ) )
|
||||
{
|
||||
DebuggerBreak();
|
||||
// DebuggerBreak();
|
||||
}
|
||||
}
|
||||
|
||||
@@ -592,13 +592,13 @@ void GLMContext::ForceFlushStates()
|
||||
|
||||
m_DepthBias.Flush();
|
||||
|
||||
m_ScissorEnable.Flush();
|
||||
m_ScissorEnable.Flush();
|
||||
m_ScissorBox.Flush();
|
||||
|
||||
m_ViewportBox.Flush();
|
||||
m_ViewportBox.Flush();
|
||||
m_ViewportDepthRange.Flush();
|
||||
|
||||
m_ColorMaskSingle.Flush();
|
||||
m_ColorMaskSingle.Flush();
|
||||
|
||||
m_BlendEnable.Flush();
|
||||
m_BlendFactor.Flush();
|
||||
@@ -819,7 +819,7 @@ void GLMContext::ProcessTextureDeletes()
|
||||
}
|
||||
}
|
||||
|
||||
// push and pop attrib when blit has mixed srgb source and dest?
|
||||
// push and pop attrib when blit has mixed srgb source and dest?
|
||||
ConVar gl_radar7954721_workaround_mixed ( "gl_radar7954721_workaround_mixed", "1" );
|
||||
|
||||
// push and pop attrib on any blit?
|
||||
@@ -1323,7 +1323,7 @@ void GLMContext::BlitTex( CGLMTex *srcTex, GLMRect *srcRect, int srcFace, int sr
|
||||
attparams.m_zslice = 0;
|
||||
m_blitReadFBO->TexAttach( &attparams, attachIndex, GL_READ_FRAMEBUFFER );
|
||||
|
||||
gGL->glDrawBuffers( 1, &attachIndexGL );
|
||||
gGL->glReadBuffer( attachIndexGL );
|
||||
|
||||
// set the write fb and buffer, and attach write tex
|
||||
BindFBOToCtx( m_blitDrawFBO, GL_DRAW_FRAMEBUFFER );
|
||||
@@ -2648,7 +2648,7 @@ GLMContext::GLMContext( IDirect3DDevice9 *pDevice, GLMDisplayParams *params )
|
||||
|
||||
gGL->glGenBuffers( 1, &m_destroyPBO );
|
||||
gGL->glBindBuffer( GL_PIXEL_UNPACK_BUFFER, m_destroyPBO );
|
||||
gGL->glBufferData( GL_PIXEL_UNPACK_BUFFER, sizeof( g_garbageTextureBits ), g_garbageTextureBits, GL_STATIC_DRAW );
|
||||
gGL->glBufferData( GL_PIXEL_UNPACK_BUFFER, sizeof( g_garbageTextureBits ), g_garbageTextureBits, GL_STREAM_DRAW );
|
||||
gGL->glBindBuffer( GL_PIXEL_UNPACK_BUFFER, m_nBoundGLBuffer[ kGLMPixelBuffer ] );
|
||||
|
||||
// Create a bunch of texture names for us to use forever and ever ramen.
|
||||
|
||||
Reference in New Issue
Block a user