mirror of
https://github.com/ZDoom/gzdoom-gles.git
synced 2025-02-23 03:41:03 +00:00
Update to uniforms and shader.
This commit is contained in:
parent
e4c7003bb9
commit
68988df681
8 changed files with 54 additions and 51 deletions
|
@ -142,12 +142,6 @@ void *GLBuffer::Lock(unsigned int size)
|
|||
SetData(size, nullptr, true);
|
||||
|
||||
return map;
|
||||
/*
|
||||
else
|
||||
{
|
||||
return glMapBufferRange(mUseType, 0, size, GL_MAP_WRITE_BIT | GL_MAP_INVALIDATE_BUFFER_BIT | GL_MAP_UNSYNCHRONIZED_BIT);
|
||||
}
|
||||
*/
|
||||
}
|
||||
|
||||
void GLBuffer::Unlock()
|
||||
|
|
|
@ -127,8 +127,9 @@ unsigned int FHardwareTexture::CreateTexture(unsigned char * buffer, int w, int
|
|||
// store the physical size.
|
||||
|
||||
int sourcetype;
|
||||
|
||||
#define GL_BGRA 0x80E1
|
||||
//sourcetype = GL_BGRA;
|
||||
|
||||
#if USE_GLES2
|
||||
sourcetype = GL_BGRA;
|
||||
texformat = GL_BGRA;
|
||||
|
|
|
@ -120,15 +120,18 @@ bool FGLRenderState::ApplyShader()
|
|||
int texFlags = mTextureModeFlags; if (!mBrightmapEnabled) texFlags &= ~(TEXF_Brightmap | TEXF_Glowmap);
|
||||
|
||||
activeShader->Bind(textureMode, texFlags, 0);
|
||||
|
||||
}
|
||||
|
||||
|
||||
if (mHwUniforms)
|
||||
{
|
||||
matrixToGL(mHwUniforms->mProjectionMatrix, activeShader->cur->ProjectionMatrix_index);
|
||||
matrixToGL(mHwUniforms->mViewMatrix, activeShader->cur->ViewMatrix_index);
|
||||
matrixToGL(mHwUniforms->mNormalViewMatrix, activeShader->cur->NormalViewMatrix_index);
|
||||
//matrixToGL(mHwUniforms->mProjectionMatrix, activeShader->cur->ProjectionMatrix_index);
|
||||
activeShader->cur->muProjectionMatrix.Set(&mHwUniforms->mProjectionMatrix);
|
||||
activeShader->cur->muViewMatrix.Set(&mHwUniforms->mViewMatrix);
|
||||
activeShader->cur->muNormalViewMatrix.Set(&mHwUniforms->mNormalViewMatrix);
|
||||
|
||||
//matrixToGL(mHwUniforms->mViewMatrix, activeShader->cur->ViewMatrix_index);
|
||||
//matrixToGL(mHwUniforms->mNormalViewMatrix, activeShader->cur->NormalViewMatrix_index);
|
||||
|
||||
activeShader->cur->muCameraPos.Set(&mHwUniforms->mCameraPos.X);
|
||||
activeShader->cur->muClipLine.Set(&mHwUniforms->mClipLine.X);
|
||||
|
@ -139,7 +142,7 @@ bool FGLRenderState::ApplyShader()
|
|||
activeShader->cur->muViewHeight.Set(mHwUniforms->mViewHeight);
|
||||
activeShader->cur->muClipHeight.Set(mHwUniforms->mClipHeight);
|
||||
activeShader->cur->muClipHeightDirection.Set(mHwUniforms->mClipHeightDirection);
|
||||
activeShader->cur->muShadowmapFilter.Set(mHwUniforms->mShadowmapFilter);
|
||||
//activeShader->cur->muShadowmapFilter.Set(mHwUniforms->mShadowmapFilter);
|
||||
}
|
||||
|
||||
glVertexAttrib4fv(VATTR_COLOR, &mStreamData.uVertexColor.X);
|
||||
|
@ -150,7 +153,7 @@ bool FGLRenderState::ApplyShader()
|
|||
|
||||
int f = mTextureModeFlags;
|
||||
if (!mBrightmapEnabled) f &= ~(TEXF_Brightmap | TEXF_Glowmap);
|
||||
activeShader->cur->muTextureMode.Set((mTextureMode == TM_NORMAL && mTempTM == TM_OPAQUE ? TM_OPAQUE : mTextureMode) | f);
|
||||
//activeShader->cur->muTextureMode.Set((mTextureMode == TM_NORMAL && mTempTM == TM_OPAQUE ? TM_OPAQUE : mTextureMode) | f);
|
||||
activeShader->cur->muLightParms.Set(mLightParms);
|
||||
activeShader->cur->muFogColor.Set(mStreamData.uFogColor);
|
||||
activeShader->cur->muObjectColor.Set(mStreamData.uObjectColor);
|
||||
|
@ -235,7 +238,7 @@ bool FGLRenderState::ApplyShader()
|
|||
}
|
||||
}
|
||||
|
||||
activeShader->cur->muLightIndex.Set(index);
|
||||
//activeShader->cur->muLightIndex.Set(index);
|
||||
return true;
|
||||
}
|
||||
|
||||
|
|
|
@ -244,8 +244,8 @@ bool FShader::Load(const char * name, const char * vert_prog_lump_, const char *
|
|||
|
||||
FString i_data = R"(
|
||||
// these settings are actually pointless but there seem to be some old ATI drivers that fail to compile the shader without setting the precision here.
|
||||
precision highp int;
|
||||
precision highp float;
|
||||
precision mediump int;
|
||||
precision mediump float;
|
||||
|
||||
// This must match the HWViewpointUniforms struct
|
||||
|
||||
|
@ -563,10 +563,13 @@ bool FShader::Load(const char * name, const char * vert_prog_lump_, const char *
|
|||
shaderData->hFragProg = 0;
|
||||
}
|
||||
|
||||
|
||||
shaderData->ProjectionMatrix_index = glGetUniformLocation(shaderData->hShader, "ProjectionMatrix");
|
||||
shaderData->ViewMatrix_index = glGetUniformLocation(shaderData->hShader, "ViewMatrix");
|
||||
shaderData->NormalViewMatrix_index = glGetUniformLocation(shaderData->hShader, "NormalViewMatrix");
|
||||
shaderData->muProjectionMatrix.Init(shaderData->hShader, "ProjectionMatrix");
|
||||
shaderData->muViewMatrix.Init(shaderData->hShader, "ViewMatrix");
|
||||
shaderData->muNormalViewMatrix.Init(shaderData->hShader, "NormalViewMatrix");
|
||||
|
||||
//shaderData->ProjectionMatrix_index = glGetUniformLocation(shaderData->hShader, "ProjectionMatrix");
|
||||
//shaderData->ViewMatrix_index = glGetUniformLocation(shaderData->hShader, "ViewMatrix");
|
||||
//shaderData->NormalViewMatrix_index = glGetUniformLocation(shaderData->hShader, "NormalViewMatrix");
|
||||
|
||||
shaderData->muCameraPos.Init(shaderData->hShader, "uCameraPos");
|
||||
shaderData->muClipLine.Init(shaderData->hShader, "uClipLine");
|
||||
|
@ -734,7 +737,7 @@ FShaderManager::~FShaderManager()
|
|||
|
||||
void FShaderManager::SetActiveShader(FShader::ShaderVariantData *sh)
|
||||
{
|
||||
//if (mActiveShader != sh)
|
||||
if (mActiveShader != sh)
|
||||
{
|
||||
glUseProgram(sh!= NULL? sh->GetHandle() : 0);
|
||||
mActiveShader = sh;
|
||||
|
|
|
@ -227,6 +227,28 @@ public:
|
|||
}
|
||||
};
|
||||
|
||||
class FBufferedUniformMat4fv
|
||||
{
|
||||
VSMatrix mBuffer;
|
||||
int mIndex;
|
||||
|
||||
public:
|
||||
void Init(GLuint hShader, const GLchar* name)
|
||||
{
|
||||
mIndex = glGetUniformLocation(hShader, name);
|
||||
mBuffer = 0;
|
||||
}
|
||||
|
||||
void Set(const VSMatrix* newvalue)
|
||||
{
|
||||
if (memcmp(newvalue, &mBuffer, sizeof(mBuffer)))
|
||||
{
|
||||
mBuffer = *newvalue;
|
||||
glUniformMatrix4fv(mIndex, 1, false, (float*)newvalue);
|
||||
}
|
||||
}
|
||||
};
|
||||
|
||||
class FShader
|
||||
{
|
||||
friend class FShaderCollection;
|
||||
|
@ -249,9 +271,13 @@ public: class ShaderVariantData
|
|||
unsigned int hVertProg = 0;
|
||||
unsigned int hFragProg = 0;
|
||||
|
||||
int ProjectionMatrix_index = 0;
|
||||
int ViewMatrix_index = 0;
|
||||
int NormalViewMatrix_index = 0;
|
||||
//int ProjectionMatrix_index = 0;
|
||||
//int ViewMatrix_index = 0;
|
||||
//int NormalViewMatrix_index = 0;
|
||||
|
||||
FBufferedUniformMat4fv muProjectionMatrix;
|
||||
FBufferedUniformMat4fv muViewMatrix;
|
||||
FBufferedUniformMat4fv muNormalViewMatrix;
|
||||
|
||||
FUniform4f muCameraPos;
|
||||
FUniform4f muClipLine;
|
||||
|
|
|
@ -236,8 +236,8 @@ FString FShaderProgram::PatchShader(ShaderType type, const FString &code, const
|
|||
|
||||
patchedCode.AppendFormat("#version %d\n", 100); // Set to GLES2
|
||||
|
||||
patchedCode << "precision highp int;\n";
|
||||
patchedCode << "precision highp float;\n";
|
||||
patchedCode << "precision mediump int;\n";
|
||||
patchedCode << "precision mediump float;\n";
|
||||
|
||||
if (defines)
|
||||
patchedCode << defines;
|
||||
|
|
|
@ -19,12 +19,6 @@ struct Material
|
|||
vec4 Bright;
|
||||
vec4 Glow;
|
||||
vec3 Normal;
|
||||
vec3 Specular;
|
||||
float Glossiness;
|
||||
float SpecularLevel;
|
||||
float Metallic;
|
||||
float Roughness;
|
||||
float AO;
|
||||
};
|
||||
|
||||
vec4 Process(vec4 color);
|
||||
|
@ -459,12 +453,6 @@ void main()
|
|||
material.Bright = vec4(0.0);
|
||||
material.Glow = vec4(0.0);
|
||||
material.Normal = vec3(0.0);
|
||||
material.Specular = vec3(0.0);
|
||||
material.Glossiness = 0.0;
|
||||
material.SpecularLevel = 0.0;
|
||||
material.Metallic = 0.0;
|
||||
material.Roughness = 0.0;
|
||||
material.AO = 0.0;
|
||||
SetupMaterial(material);
|
||||
#else
|
||||
Material material = ProcessMaterial();
|
||||
|
|
|
@ -101,11 +101,6 @@ void main()
|
|||
#endif
|
||||
|
||||
|
||||
|
||||
#ifdef VULKAN_COORDINATE_SYSTEM
|
||||
gl_Position.z = (gl_Position.z + gl_Position.w) / 2.0;
|
||||
#endif
|
||||
|
||||
if (uClipHeightDirection != 0.0) // clip planes used for reflective flats
|
||||
{
|
||||
ClipDistance0 = (worldcoord.y - uClipHeight) * uClipHeightDirection;
|
||||
|
@ -129,16 +124,9 @@ void main()
|
|||
ClipDistance4 = 1.0;
|
||||
}
|
||||
|
||||
#ifdef NO_CLIPDISTANCE_SUPPORT
|
||||
ClipDistanceA = vec4(ClipDistance0, ClipDistance1, ClipDistance2, ClipDistance3);
|
||||
ClipDistanceB = vec4(ClipDistance4, 0.0, 0.0, 0.0);
|
||||
#else
|
||||
gl_ClipDistance[0] = ClipDistance0;
|
||||
gl_ClipDistance[1] = ClipDistance1;
|
||||
gl_ClipDistance[2] = ClipDistance2;
|
||||
gl_ClipDistance[3] = ClipDistance3;
|
||||
gl_ClipDistance[4] = ClipDistance4;
|
||||
#endif
|
||||
|
||||
|
||||
//gl_PointSize = 1.0;
|
||||
|
||||
|
|
Loading…
Reference in a new issue