mirror of
https://github.com/ZDoom/raze-gles.git
synced 2024-11-10 23:02:03 +00:00
- moved the animvpx shader to the backend code.
This removes the final access to OpenGL from the rest of the source, with the exception of the glFinish call in the swap code.
This commit is contained in:
parent
0ee80628a2
commit
3c193bb243
8 changed files with 73 additions and 68 deletions
|
@ -675,6 +675,8 @@ file( GLOB HEADER_FILES
|
|||
libxmp-lite/src/*.h
|
||||
mact/include/*.h
|
||||
mact/src/*.h
|
||||
common/*.h
|
||||
common/utility/*.h
|
||||
|
||||
build/src/*.h
|
||||
duke3d/src/*.h
|
||||
|
@ -1018,6 +1020,7 @@ include_directories(
|
|||
libxmp-lite/include/libxmp-lite
|
||||
libsmackerdec/include
|
||||
thirdparty/include
|
||||
common
|
||||
common/utility
|
||||
common/console
|
||||
platform
|
||||
|
|
|
@ -89,7 +89,7 @@ static FORCE_INLINE int32_t eligible_for_tileshades(int32_t const picnum, int32_
|
|||
static inline float getshadefactor(int32_t const shade)
|
||||
{
|
||||
// 8-bit tiles, i.e. non-hightiles and non-models, don't get additional
|
||||
// glColor() shading with r_usetileshades!
|
||||
// shading with r_usetileshades!
|
||||
if (videoGetRenderMode() == REND_POLYMOST && !(globalflags & GLOBAL_NO_GL_TILESHADES) && eligible_for_tileshades(globalpicnum, globalpal))
|
||||
return 1.f;
|
||||
|
||||
|
|
|
@ -344,69 +344,11 @@ static FHardwareTexture* texture;
|
|||
static int sampler;
|
||||
static int32_t texuploaded;
|
||||
|
||||
#ifdef USE_GLEXT
|
||||
// YUV->RGB conversion fragment shader adapted from
|
||||
// http://www.fourcc.org/fccyvrgb.php: "Want some sample code?"
|
||||
// direct link: http://www.fourcc.org/source/YUV420P-OpenGL-GLSLang.c
|
||||
static const char *fragprog_src =
|
||||
"#version 120\n"
|
||||
|
||||
"uniform sampler2D tex;\n"
|
||||
|
||||
"void main(void) {\n"
|
||||
|
||||
" float r,g,b,y,u,v;\n"
|
||||
" vec3 yuv;\n"
|
||||
|
||||
" yuv = texture2D(tex, gl_TexCoord[0].st).rgb;\n"
|
||||
" y = yuv.r;\n"
|
||||
" u = yuv.g;\n"
|
||||
" v = yuv.b;\n"
|
||||
|
||||
" y = 1.1643*(y-0.0625);\n"
|
||||
" u = u-0.5;\n"
|
||||
" v = v-0.5;\n"
|
||||
|
||||
" r = y + 1.5958*v;\n"
|
||||
" g = y - 0.39173*u - 0.81290*v;\n"
|
||||
" b = y + 2.017*u;\n"
|
||||
|
||||
" gl_FragColor = vec4(r,g,b,1.0);\n"
|
||||
"}\n";
|
||||
#endif
|
||||
|
||||
void animvpx_setup_glstate(int32_t animvpx_flags)
|
||||
{
|
||||
GLint gli;
|
||||
GLuint FSHandle, PHandle;
|
||||
static char logbuf[512];
|
||||
static char logbuf[512];
|
||||
|
||||
// first, compile the fragment shader
|
||||
/* Set up program objects. */
|
||||
PHandle = glCreateProgram();
|
||||
FSHandle = glCreateShader(GL_FRAGMENT_SHADER);
|
||||
|
||||
/* Compile the shader. */
|
||||
glShaderSource(FSHandle, 1, (const GLchar **)&fragprog_src, NULL);
|
||||
glCompileShader(FSHandle);
|
||||
|
||||
/* Print the compilation log. */
|
||||
glGetShaderiv(FSHandle, GL_COMPILE_STATUS, &gli);
|
||||
glGetShaderInfoLog(FSHandle, sizeof(logbuf), NULL, logbuf);
|
||||
if (logbuf[0])
|
||||
OSD_Printf("animvpx compile log: %s\n", logbuf);
|
||||
|
||||
/* Create a complete program object. */
|
||||
glAttachShader(PHandle, FSHandle);
|
||||
glLinkProgram(PHandle);
|
||||
|
||||
/* And print the link log. */
|
||||
glGetProgramInfoLog(PHandle, sizeof(logbuf), NULL, logbuf);
|
||||
if (logbuf[0])
|
||||
OSD_Printf("animvpx link log: %s\n", logbuf);
|
||||
|
||||
/* Finally, use the program. */
|
||||
glUseProgram(PHandle);
|
||||
GLInterface.SetVPXShader();
|
||||
|
||||
|
||||
////////// GL STATE //////////
|
||||
|
@ -444,7 +386,6 @@ void animvpx_setup_glstate(int32_t animvpx_flags)
|
|||
void animvpx_restore_glstate(void)
|
||||
{
|
||||
GLInterface.SetPolymostShader();
|
||||
|
||||
delete texture;
|
||||
texture = nullptr;
|
||||
texuploaded = 0;
|
||||
|
|
|
@ -65,4 +65,4 @@ public:
|
|||
SurfaceShader() = default;
|
||||
virtual bool Load(const char* name, const char* vert_prog_lump, const char* fragprog); //, const char * fragprog2, const char *defines);
|
||||
|
||||
};
|
||||
};
|
||||
|
|
|
@ -63,6 +63,7 @@ void GLInstance::Init()
|
|||
}
|
||||
new(&renderState) PolymostRenderState; // reset to defaults.
|
||||
LoadSurfaceShader();
|
||||
LoadVPXShader();
|
||||
LoadPolymostShader();
|
||||
|
||||
}
|
||||
|
@ -70,20 +71,36 @@ void GLInstance::Init()
|
|||
void GLInstance::LoadPolymostShader()
|
||||
{
|
||||
auto fr1 = GetBaseResource("demolition/shaders/glsl/polymost.vp");
|
||||
TArray<uint8_t> polymost1Vert = fr1.Read();
|
||||
TArray<uint8_t> Vert = fr1.Read();
|
||||
fr1 = GetBaseResource("demolition/shaders/glsl/polymost.fp");
|
||||
TArray<uint8_t> polymost1Frag = fr1.Read();
|
||||
TArray<uint8_t> Frag = fr1.Read();
|
||||
// Zero-terminate both strings.
|
||||
polymost1Vert.Push(0);
|
||||
polymost1Frag.Push(0);
|
||||
Vert.Push(0);
|
||||
Frag.Push(0);
|
||||
polymostShader = new PolymostShader();
|
||||
if (!polymostShader->Load("PolymostShader", (const char*)polymost1Vert.Data(), (const char*)polymost1Frag.Data()))
|
||||
if (!polymostShader->Load("PolymostShader", (const char*)Vert.Data(), (const char*)Frag.Data()))
|
||||
{
|
||||
exit(1);
|
||||
}
|
||||
SetPolymostShader();
|
||||
}
|
||||
|
||||
void GLInstance::LoadVPXShader()
|
||||
{
|
||||
auto fr1 = GetBaseResource("demolition/shaders/glsl/animvpx.vp");
|
||||
TArray<uint8_t> Vert = fr1.Read();
|
||||
fr1 = GetBaseResource("demolition/shaders/glsl/animvpx.fp");
|
||||
TArray<uint8_t> Frag = fr1.Read();
|
||||
// Zero-terminate both strings.
|
||||
Vert.Push(0);
|
||||
Frag.Push(0);
|
||||
vpxShader = new FShader();
|
||||
if (!vpxShader->Load("VPXShader", (const char*)Vert.Data(), (const char*)Frag.Data()))
|
||||
{
|
||||
exit(1);
|
||||
}
|
||||
}
|
||||
|
||||
void GLInstance::LoadSurfaceShader()
|
||||
{
|
||||
auto fr1 = GetBaseResource("demolition/shaders/glsl/surface.vp");
|
||||
|
@ -399,6 +416,14 @@ void GLInstance::SetSurfaceShader()
|
|||
}
|
||||
}
|
||||
|
||||
void GLInstance::SetVPXShader()
|
||||
{
|
||||
if (activeShader != vpxShader)
|
||||
{
|
||||
vpxShader->Bind();
|
||||
activeShader = vpxShader;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
void PolymostRenderState::Apply(PolymostShader* shader)
|
||||
|
|
|
@ -132,6 +132,7 @@ class GLInstance
|
|||
FShader* activeShader;
|
||||
PolymostShader* polymostShader;
|
||||
SurfaceShader* surfaceShader;
|
||||
FShader* vpxShader;
|
||||
|
||||
|
||||
public:
|
||||
|
@ -197,6 +198,7 @@ public:
|
|||
void SetWireframe(bool on);
|
||||
void SetPolymostShader();
|
||||
void SetSurfaceShader();
|
||||
void SetVPXShader();
|
||||
|
||||
void ReadPixels(int w, int h, uint8_t* buffer);
|
||||
|
||||
|
|
27
wadsrc/static/demolition/shaders/glsl/animvpx.fp
Normal file
27
wadsrc/static/demolition/shaders/glsl/animvpx.fp
Normal file
|
@ -0,0 +1,27 @@
|
|||
// YUV->RGB conversion fragment shader adapted from
|
||||
// http://www.fourcc.org/fccyvrgb.php: Want some sample code?
|
||||
// direct link: http://www.fourcc.org/source/YUV420P-OpenGL-GLSLang.c
|
||||
#version 120
|
||||
|
||||
uniform sampler2D tex;
|
||||
|
||||
void main(void) {
|
||||
|
||||
float r,g,b,y,u,v;
|
||||
vec3 yuv;
|
||||
|
||||
yuv = texture2D(tex, gl_TexCoord[0].st).rgb;
|
||||
y = yuv.r;
|
||||
u = yuv.g;
|
||||
v = yuv.b;
|
||||
|
||||
y = 1.1643*(y-0.0625);
|
||||
u = u-0.5;
|
||||
v = v-0.5;
|
||||
|
||||
r = y + 1.5958*v;
|
||||
g = y - 0.39173*u - 0.81290*v;
|
||||
b = y + 2.017*u;
|
||||
|
||||
gl_FragColor = vec4(r,g,b,1.0);
|
||||
};
|
7
wadsrc/static/demolition/shaders/glsl/animvpx.vp
Normal file
7
wadsrc/static/demolition/shaders/glsl/animvpx.vp
Normal file
|
@ -0,0 +1,7 @@
|
|||
#version 110
|
||||
|
||||
void main()
|
||||
{
|
||||
gl_Position = gl_Vertex;
|
||||
gl_TexCoord[0] = gl_MultiTexCoord0;
|
||||
}
|
Loading…
Reference in a new issue