remove dublicated GL queries

This commit is contained in:
Jupeyy 2017-11-04 05:38:48 +01:00
parent 78a9fbb9b5
commit 78c06e180f
2 changed files with 14 additions and 10 deletions

View file

@ -263,8 +263,9 @@ void CCommandProcessorFragment_OpenGL::Cmd_Texture_Create(const CCommandBuffer::
// resample if needed
if(pCommand->m_Format == CCommandBuffer::TEXFORMAT_RGBA || pCommand->m_Format == CCommandBuffer::TEXFORMAT_RGB)
{
int MaxTexSize;
glGetIntegerv(GL_MAX_TEXTURE_SIZE, &MaxTexSize);
static int MaxTexSize = -1;
if(MaxTexSize == -1)
glGetIntegerv(GL_MAX_TEXTURE_SIZE, &MaxTexSize);
if(Width > MaxTexSize || Height > MaxTexSize)
{
do
@ -752,7 +753,10 @@ void CCommandProcessorFragment_OpenGL3_3::Cmd_Init(const SCommand_Init *pCommand
if(m_UsePreinitializedVertexBuffer)
glBufferData(GL_ARRAY_BUFFER, sizeof(CCommandBuffer::SVertex) * CCommandBuffer::MAX_VERTICES, NULL, GL_STREAM_DRAW);
//query the image max size only once
glGetIntegerv(GL_MAX_TEXTURE_SIZE, &m_MaxTexSize);
//query maximum of allowed textures
glGetIntegerv(GL_MAX_COMBINED_TEXTURE_IMAGE_UNITS, &m_MaxTextureUnits);
m_TextureSlotBoundToUnit.resize(m_MaxTextureUnits);
@ -785,6 +789,9 @@ void CCommandProcessorFragment_OpenGL3_3::Cmd_Init(const SCommand_Init *pCommand
mem_zero(m_aTextures, sizeof(m_aTextures));
m_ClearColor.r = m_ClearColor.g = m_ClearColor.b = -1.f;
//fix the alignment to allow even 1byte changes, e.g. for alpha components
glPixelStorei(GL_UNPACK_ALIGNMENT, 1);
}
void CCommandProcessorFragment_OpenGL3_3::Cmd_Shutdown(const SCommand_Shutdown *pCommand)
@ -827,9 +834,7 @@ void CCommandProcessorFragment_OpenGL3_3::Cmd_Texture_Update(const CCommandBuffe
glActiveTexture(GL_TEXTURE0 + Slot);
glBindSampler(Slot, m_aTextures[pCommand->m_Slot].m_Sampler);
}
//fix the alignment to allow even 1byte changes, e.g. for alpha components
glPixelStorei(GL_UNPACK_ALIGNMENT, 1);
glBindTexture(GL_TEXTURE_2D, m_aTextures[pCommand->m_Slot].m_Tex);
glTexSubImage2D(GL_TEXTURE_2D, 0, pCommand->m_X, pCommand->m_Y, pCommand->m_Width, pCommand->m_Height,
TexFormatToOpenGLFormat(pCommand->m_Format), GL_UNSIGNED_BYTE, pCommand->m_pData);
@ -860,16 +865,14 @@ void CCommandProcessorFragment_OpenGL3_3::Cmd_Texture_Create(const CCommandBuffe
// resample if needed
if(pCommand->m_Format == CCommandBuffer::TEXFORMAT_RGBA || pCommand->m_Format == CCommandBuffer::TEXFORMAT_RGB)
{
int MaxTexSize;
glGetIntegerv(GL_MAX_TEXTURE_SIZE, &MaxTexSize);
if(Width > MaxTexSize || Height > MaxTexSize)
if(Width > m_MaxTexSize || Height > m_MaxTexSize)
{
do
{
Width>>=1;
Height>>=1;
}
while(Width > MaxTexSize || Height > MaxTexSize);
while(Width > m_MaxTexSize || Height > m_MaxTexSize);
void *pTmpData = Rescale(pCommand->m_Width, pCommand->m_Height, Width, Height, pCommand->m_Format, static_cast<const unsigned char *>(pCommand->m_pData));
mem_free(pTexData);

View file

@ -156,6 +156,7 @@ class CCommandProcessorFragment_OpenGL3_3
unsigned int m_CurrentIndicesInBuffer;
GLint m_MaxTextureUnits;
GLint m_MaxTexSize;
int m_LastBlendMode; //avoid all possible opengl state changes
bool m_LastClipEnable;