mirror of
https://github.com/ZDoom/raze-gles.git
synced 2024-12-27 04:00:42 +00:00
- transitioned matrix setup to use the backend's uniform buffer implementation.
This commit is contained in:
parent
40f085adea
commit
b15cc31a38
10 changed files with 52 additions and 36 deletions
|
@ -210,6 +210,8 @@ public:
|
|||
{
|
||||
Base->CopySize(BaseTexture->Base.get());
|
||||
SetDisplaySize(BaseTexture->GetDisplayWidth(), BaseTexture->GetDisplayHeight());
|
||||
SetOffsets(0, BaseTexture->GetTexelLeftOffset(0), BaseTexture->GetTexelTopOffset(0));
|
||||
SetOffsets(1, BaseTexture->GetTexelLeftOffset(1), BaseTexture->GetTexelTopOffset(1));
|
||||
}
|
||||
|
||||
// Glowing is a pure material property that should not filter down to the actual texture objects.
|
||||
|
|
|
@ -141,7 +141,7 @@ void FMultipatchTextureBuilder::MakeTexture(BuildInfo &buildinfo, ETextureType u
|
|||
buildinfo.texture->SetSize(buildinfo.Width, buildinfo.Height);
|
||||
buildinfo.texture->SetOffsets(0, buildinfo.LeftOffset[0], buildinfo.TopOffset[0]); // These are needed for construction of other multipatch textures.
|
||||
buildinfo.texture->SetOffsets(1, buildinfo.LeftOffset[1], buildinfo.TopOffset[1]);
|
||||
buildinfo.texture->SetScale((float)buildinfo.Scale.X, (float)buildinfo.Scale.X);
|
||||
buildinfo.texture->SetScale((float)buildinfo.Scale.X, (float)buildinfo.Scale.Y);
|
||||
buildinfo.texture->SetWorldPanning(buildinfo.bWorldPanning);
|
||||
buildinfo.texture->SetNoDecals(buildinfo.bNoDecals);
|
||||
TexMan.AddGameTexture(buildinfo.texture);
|
||||
|
@ -923,7 +923,10 @@ void FMultipatchTextureBuilder::ResolveAllPatches()
|
|||
for (auto &b : BuiltTextures)
|
||||
{
|
||||
Printf("%s\n", b.Name.GetChars());
|
||||
// make it hard to find but also ensure that it references valid backing data.
|
||||
b.texture->SetUseType(ETextureType::Null);
|
||||
b.texture->SetBase(TexMan.GameByIndex(0)->GetTexture());
|
||||
b.texture->SetName("");
|
||||
}
|
||||
break;
|
||||
}
|
||||
|
|
|
@ -37,6 +37,7 @@
|
|||
#include "glbackend.h"
|
||||
#include "gl_shader.h"
|
||||
#include "zstring.h"
|
||||
#include "shaderuniforms.h"
|
||||
|
||||
#include "baselayer.h"
|
||||
|
||||
|
@ -134,10 +135,12 @@ bool PolymostShader::Load(const char * name, const char * vert_prog, const char
|
|||
{
|
||||
if (!FShader::Load(name, vert_prog, frag_prog)) return false;
|
||||
|
||||
int tempindex = glGetUniformBlockIndex(hShader, "ViewpointUBO");
|
||||
if (tempindex != -1) glUniformBlockBinding(hShader, tempindex, VIEWPOINT_BINDINGPOINT);
|
||||
|
||||
Flags.Init(hShader, "u_flags");
|
||||
Shade.Init(hShader, "u_shade");
|
||||
ShadeDiv.Init(hShader, "u_shadeDiv");
|
||||
NumShades.Init(hShader, "u_numShades");
|
||||
VisFactor.Init(hShader, "u_visFactor");
|
||||
NPOTEmulationFactor.Init(hShader, "u_npotEmulationFactor");
|
||||
NPOTEmulationXOffset.Init(hShader, "u_npotEmulationXOffset");
|
||||
|
@ -150,9 +153,7 @@ bool PolymostShader::Load(const char * name, const char * vert_prog, const char
|
|||
TintFlags.Init(hShader, "u_tintFlags");
|
||||
DetailParms.Init(hShader, "u_detailParms");
|
||||
|
||||
RotMatrix.Init(hShader, "u_rotMatrix");
|
||||
ModelMatrix.Init(hShader, "u_modelMatrix");
|
||||
ProjectionMatrix.Init(hShader, "u_projectionMatrix");
|
||||
TextureMatrix.Init(hShader, "u_textureMatrix");
|
||||
|
||||
|
||||
|
|
|
@ -37,7 +37,6 @@ class PolymostShader : public FShader
|
|||
public:
|
||||
FBufferedUniform1i Flags;
|
||||
FBufferedUniform1f Shade;
|
||||
FBufferedUniform1f NumShades;
|
||||
FBufferedUniform1f ShadeDiv;
|
||||
FBufferedUniform1f VisFactor;
|
||||
FBufferedUniform1f NPOTEmulationFactor;
|
||||
|
@ -52,9 +51,7 @@ public:
|
|||
FBufferedUniform2f DetailParms;
|
||||
|
||||
|
||||
FUniformMatrix4f RotMatrix;
|
||||
FUniformMatrix4f ModelMatrix;
|
||||
FUniformMatrix4f ProjectionMatrix;
|
||||
FUniformMatrix4f TextureMatrix;
|
||||
|
||||
public:
|
||||
|
|
|
@ -54,6 +54,8 @@
|
|||
#include "v_draw.h"
|
||||
#include "v_font.h"
|
||||
#include "hw_viewpointuniforms.h"
|
||||
#include "hw_viewpointbuffer.h"
|
||||
#include "gl_renderstate.h"
|
||||
|
||||
F2DDrawer twodpsp;
|
||||
static int BufferLock = 0;
|
||||
|
@ -98,6 +100,26 @@ void GLInstance::Init(int ydim)
|
|||
LoadPolymostShader();
|
||||
}
|
||||
|
||||
FString i_data = R"(
|
||||
#version 330
|
||||
// This must match the HWViewpointUniforms struct
|
||||
layout(std140) uniform ViewpointUBO {
|
||||
mat4 ProjectionMatrix;
|
||||
mat4 ViewMatrix;
|
||||
mat4 NormalViewMatrix;
|
||||
|
||||
vec4 uCameraPos;
|
||||
vec4 uClipLine;
|
||||
|
||||
float uGlobVis; // uGlobVis = R_GetGlobVis(r_visibility) / 32.0
|
||||
int uPalLightLevels;
|
||||
int uViewHeight; // Software fuzz scaling
|
||||
float uClipHeight;
|
||||
float uClipHeightDirection;
|
||||
int uShadowmapFilter;
|
||||
};
|
||||
)";
|
||||
|
||||
void GLInstance::LoadPolymostShader()
|
||||
{
|
||||
auto fr1 = GetResource("engine/shaders/glsl/polymost.vp");
|
||||
|
@ -107,8 +129,10 @@ void GLInstance::LoadPolymostShader()
|
|||
// Zero-terminate both strings.
|
||||
Vert.Push(0);
|
||||
Frag.Push(0);
|
||||
FStringf VertS("%s\n%s", i_data, Vert.Data());
|
||||
FStringf FragS("%s\n%s", i_data, Frag.Data());
|
||||
polymostShader = new PolymostShader();
|
||||
polymostShader->Load("PolymostShader", (const char*)Vert.Data(), (const char*)Frag.Data());
|
||||
polymostShader->Load("PolymostShader", (const char*)VertS.GetChars(), (const char*)FragS.GetChars());
|
||||
SetPolymostShader();
|
||||
}
|
||||
|
||||
|
@ -268,7 +292,7 @@ void GLInstance::SetPalette(int index)
|
|||
void GLInstance::SetPalswap(int index)
|
||||
{
|
||||
palmanager.BindPalswap(index);
|
||||
renderState.ShadeDiv = shadediv[index] == 0 ? 1.f / (renderState.NumShades - 2) : shadediv[index];
|
||||
renderState.ShadeDiv = shadediv[index] == 0 ? 1.f / (numshades - 2) : shadediv[index];
|
||||
}
|
||||
|
||||
void GLInstance::DrawImGui(ImDrawData* data)
|
||||
|
@ -486,7 +510,6 @@ void PolymostRenderState::Apply(PolymostShader* shader, GLState &oldState)
|
|||
if (!(Flags & RF_FogDisabled) && !FogColor.isBlack()) Flags &= ~RF_Brightmapping;
|
||||
shader->Flags.Set(Flags);
|
||||
shader->Shade.Set(Shade);
|
||||
shader->NumShades.Set(NumShades);
|
||||
shader->ShadeDiv.Set(ShadeDiv);
|
||||
shader->VisFactor.Set(VisFactor);
|
||||
shader->Flags.Set(Flags);
|
||||
|
@ -503,6 +526,7 @@ void PolymostRenderState::Apply(PolymostShader* shader, GLState &oldState)
|
|||
shader->ModelMatrix.Set(matrixArray[matrixIndex[Matrix_Model]].get());
|
||||
if (matrixIndex[Matrix_Texture] != -1)
|
||||
shader->TextureMatrix.Set(matrixArray[matrixIndex[Matrix_Texture]].get());
|
||||
|
||||
memset(matrixIndex, -1, sizeof(matrixIndex));
|
||||
}
|
||||
|
||||
|
@ -595,8 +619,8 @@ void renderBeginScene()
|
|||
if (videoGetRenderMode() < REND_POLYMOST) return;
|
||||
assert(BufferLock == 0);
|
||||
|
||||
GLInterface.polymostShader->ProjectionMatrix.Set(vp.mProjectionMatrix.get());
|
||||
GLInterface.polymostShader->RotMatrix.Set(vp.mViewMatrix.get());
|
||||
vp.mPalLightLevels = numshades;
|
||||
screen->mViewpoints->SetViewpoint(OpenGLRenderer::gl_RenderState, &vp);
|
||||
|
||||
if (BufferLock++ == 0)
|
||||
{
|
||||
|
|
|
@ -200,7 +200,6 @@ public:
|
|||
void SetShade(int32_t shade, int numshades)
|
||||
{
|
||||
renderState.Shade = shade;
|
||||
renderState.NumShades = numshades;
|
||||
}
|
||||
|
||||
void SetVisibility(float visibility, float fviewingrange)
|
||||
|
|
|
@ -33,6 +33,7 @@
|
|||
*/
|
||||
|
||||
|
||||
#include "gl_load.h"
|
||||
#include "cmdlib.h"
|
||||
#include "gl_buffers.h"
|
||||
#include "v_2ddrawer.h"
|
||||
|
@ -44,6 +45,8 @@
|
|||
#include "build.h"
|
||||
#include "v_video.h"
|
||||
#include "hw_renderstate.h"
|
||||
#include "hw_viewpointbuffer.h"
|
||||
#include "gl_renderstate.h"
|
||||
|
||||
extern int16_t numshades;
|
||||
extern TArray<VSMatrix> matrixArray;
|
||||
|
@ -102,15 +105,8 @@ void polymost_dorotatesprite(int32_t sx, int32_t sy, int32_t z, int16_t a, int16
|
|||
void GLInstance::Draw2D(F2DDrawer *drawer)
|
||||
{
|
||||
VSMatrix mat(0);
|
||||
renderSetViewMatrix(nullptr);
|
||||
mat.ortho(0, xdim, ydim, 0, -1, 1);
|
||||
renderSetProjectionMatrix(mat.get());
|
||||
screen->mViewpoints->Set2D(OpenGLRenderer::gl_RenderState, xdim, ydim);
|
||||
SetIdentityMatrix(Matrix_Model);
|
||||
|
||||
// Temporary hack to set the matrices.
|
||||
renderBeginScene();
|
||||
renderFinishScene();
|
||||
|
||||
SetViewport(0, 0, xdim, ydim);
|
||||
EnableDepthTest(false);
|
||||
EnableMultisampling(false);
|
||||
|
|
|
@ -58,7 +58,6 @@ struct PolymostRenderState
|
|||
{
|
||||
int vindex, vcount, primtype;
|
||||
float Shade;
|
||||
float NumShades = 64.f;
|
||||
float ShadeDiv = 62.f;
|
||||
float VisFactor = 128.f;
|
||||
int Flags = 0;
|
||||
|
|
|
@ -1,5 +1,3 @@
|
|||
#version 330
|
||||
|
||||
const int RF_ColorOnly = 1;
|
||||
const int RF_UsePalette = 2;
|
||||
const int RF_DetailMapping = 4;
|
||||
|
@ -40,6 +38,7 @@ uniform float u_alphaThreshold;
|
|||
uniform vec4 u_tintOverlay, u_tintModulate;
|
||||
uniform int u_tintFlags;
|
||||
uniform vec4 u_fullscreenTint;
|
||||
uniform vec2 u_detailParms;
|
||||
|
||||
uniform float u_npotEmulationFactor;
|
||||
uniform float u_npotEmulationXOffset;
|
||||
|
@ -171,13 +170,14 @@ void main()
|
|||
vec4 detailColor = vec4(1.0);
|
||||
if ((u_flags & RF_DetailMapping) != 0)
|
||||
{
|
||||
detailColor = texture(s_detail, v_detailCoord.xy);
|
||||
detailColor = texture(s_detail, newCoord * u_detailParms);
|
||||
detailColor = mix(vec4(1.0), 2.0 * detailColor, detailColor.a);
|
||||
// Application of this differs based on render mode because for paletted rendering with palettized shade tables it can only be done after processing the shade table. We only have a palette index before.
|
||||
}
|
||||
|
||||
float visibility = max(u_visFactor * v_distance - ((u_flags & RF_ShadeInterpolate) != 0.0? 0.5 : 0.0), 0.0);
|
||||
float shade = clamp((u_shade + visibility), 0.0, u_numShades - 1.0);
|
||||
float numShades = float(uPalLightLevels & 255);
|
||||
float shade = clamp((u_shade + visibility), 0.0, numShades - 1.0);
|
||||
|
||||
|
||||
if ((u_flags & RF_UsePalette) != 0)
|
||||
|
@ -223,7 +223,7 @@ void main()
|
|||
}
|
||||
if ((u_flags & RF_MapFog) != 0) // fog hack for RRRA E2L1. Needs to be done better, this is gross, but still preferable to the broken original implementation.
|
||||
{
|
||||
float fogfactor = 0.55 + 0.3 * exp2 ((-5.0 / 1024.0)*v_distance);
|
||||
float fogfactor = 0.55 + 0.3 * exp2 (-5.0*v_fogCoord);
|
||||
color.rgb = vec3(0.6*(1.0-fogfactor)) + color.rgb * fogfactor;// mix(vec3(0.6), color.rgb, fogfactor);
|
||||
}
|
||||
if (color.a < u_alphaThreshold) discard; // it's only here that we have the alpha value available to be able to perform the alpha test.
|
||||
|
|
|
@ -1,17 +1,12 @@
|
|||
#version 330
|
||||
|
||||
out vec4 v_color;
|
||||
out float v_distance;
|
||||
out vec4 v_texCoord;
|
||||
out vec4 v_detailCoord;
|
||||
out float v_fogCoord;
|
||||
out vec4 v_eyeCoordPosition;
|
||||
|
||||
uniform float u_usePalette;
|
||||
uniform mat4 u_rotMatrix;
|
||||
uniform mat4 u_modelMatrix;
|
||||
uniform mat4 u_projectionMatrix;
|
||||
uniform mat4 u_textureMatrix;
|
||||
uniform vec2 u_detailParms;
|
||||
|
||||
in vec4 i_vertPos;
|
||||
in vec4 i_texCoord;
|
||||
|
@ -22,15 +17,15 @@ in vec4 i_color;
|
|||
void main()
|
||||
{
|
||||
vec4 vertex = u_modelMatrix * i_vertPos;
|
||||
vec4 eyeCoordPosition = u_rotMatrix * vertex;
|
||||
vec4 eyeCoordPosition = ViewMatrix * vertex;
|
||||
v_eyeCoordPosition = eyeCoordPosition;
|
||||
gl_Position = u_projectionMatrix * eyeCoordPosition;
|
||||
gl_Position = ProjectionMatrix * eyeCoordPosition;
|
||||
|
||||
eyeCoordPosition.xyz /= eyeCoordPosition.w;
|
||||
|
||||
v_texCoord = u_textureMatrix * i_texCoord;
|
||||
v_detailCoord = vec4(i_texCoord.x * u_detailParms.x, i_texCoord.y * u_detailParms.y, 0.0, 0.0);
|
||||
|
||||
v_fogCoord = abs(eyeCoordPosition.z);
|
||||
|
||||
v_color = i_color;
|
||||
v_distance = eyeCoordPosition.z;
|
||||
|
|
Loading…
Reference in a new issue