get gl display method working, at least, minimally, with the scanlines shader. someone else can fix up the others if they need to or make me a bug. at least the hard part is past

This commit is contained in:
zeromus 2020-06-20 00:42:25 -04:00
parent d4cb18aff8
commit 1b4a6f6415
3 changed files with 59 additions and 51 deletions

View File

@ -0,0 +1,31 @@
//Yeah, I'm sorry this uses really old non-generic attributes
//that's just how old this code is; support on ancient graphics cards is helpful
#ifdef VERTEX
uniform mat4 modelViewProj;
void main()
{
gl_Position = modelViewProj * gl_Vertex;
gl_TexCoord[0] = gl_MultiTexCoord0;
}
#endif
#ifdef FRAGMENT
uniform float uIntensity;
uniform sampler2D s_p;
uniform vec2 output_size;
void main()
{
vec2 vTex = gl_TexCoord[0].xy;
vec4 temp = texture2D(s_p,vTex);
vec2 wpos = gl_FragCoord.xy;
if(floor(wpos.y/2.0) != floor(wpos.y)/2.0) temp.rgb *= uIntensity;
gl_FragColor = temp;
}
#endif

View File

@ -0,0 +1,16 @@
Despite using the "cgp" derived "retro shader" approach, we're doing things a bit different than retroarch.
A single .cgp file is used for any graphics backend. The shader references inside it can be written extensionless, or with .cg (or with .hlsl or .glsl for reasons, read on)
In case you have shaders that work only GLSL or HLSL -- well, they simply won't work in the wrong mode.
In that case, try something like bizhawkdir/Shaders/myshaders/glsl/mybadshader.cgp
In this case, the .cgp can reference .glsl shaders internally.
An important point, which you will perceive by checking out the bizhawk shaders, is that a .cgp is now portable due to the extension-ignorant behaviour AND the separate .glsl and .hlsl extensions.
(For instance, BizScanlines.cgp+BizScanlines.hlsl+BizScanlines.glsl).
The separate extensions let there be separate shaders for each backend, each referenced by the same cgp which references .cg (arbitrarily; it could be blank)
However if the .cgp referenced a .glsl, it wouldn't work on D3D.
In case you haven't pieced it together yet, this means there is no automatic mechanism for transpiling shaders. It isn't reliable and created an unmaintainable, slow, mess.
Porting shaders from retroarch will require touching them extensively, probably.

View File

@ -6,9 +6,6 @@
// etc
// glBindAttribLocation (programID, 0, "vertexPosition_modelspace");
// for future reference: c# tesselators
// http://www.opentk.com/node/437 (AGG#, codes on Tao forums)
using System;
using System.IO;
using System.Collections.Generic;
@ -198,8 +195,6 @@ namespace BizHawk.Client.EmuHawk
var fsw = fragmentShader.Opaque as ShaderWrapper;
var sws = new[] { vsw,fsw };
bool mapVariables = vsw.MapCodeToNative != null || fsw.MapCodeToNative != null;
ErrorCode errcode;
int pid = GL.CreateProgram();
GL.AttachShader(pid, vsw.sid);
@ -207,53 +202,27 @@ namespace BizHawk.Client.EmuHawk
GL.AttachShader(pid, fsw.sid);
errcode = GL.GetError();
//NOT BEING USED NOW: USING SEMANTICS INSTEAD
////bind the attribute locations from the vertex layout
////as we go, look for attribute mappings (CGC will happily reorder and rename our attribute mappings)
////what's more it will _RESIZE_ them but this seems benign..somehow..
////WELLLLLLL we wish we could do that by names
////but the shaders don't seem to be adequate quality (oddly named attributes.. texCoord vs texCoord1). need to use semantics instead.
//foreach (var kvp in vertexLayout.Items)
//{
// string name = kvp.Value.Name;
// //if (mapVariables)
// //{
// // foreach (var sw in sws)
// // {
// // if (sw.MapNativeToCode.ContainsKey(name))
// // {
// // name = sw.MapNativeToCode[name];
// // break;
// // }
// // }
// //}
// if(mapVariables) {
// ////proxy for came-from-cgc
// //switch (kvp.Value.Usage)
// //{
// // case AttributeUsage.Position:
// //}
// }
// //GL.BindAttribLocation(pid, kvp.Key, name);
//}
GL.LinkProgram(pid);
errcode = GL.GetError();
string resultLog = GL.GetProgramInfoLog(pid);
if (errcode != ErrorCode.NoError)
{
if (required)
throw new InvalidOperationException($"Error creating pipeline (error returned from glLinkProgram): {errcode}\r\n\r\n{resultLog}");
else success = false;
}
GL.GetProgram(pid, GetProgramParameterName.LinkStatus, out var linkStatus);
if (linkStatus == 0)
{
if (required)
throw new InvalidOperationException($"Error creating pipeline (link status false returned from glLinkProgram): \r\n\r\n{resultLog}");
else success = false;
resultLog = GL.GetProgramInfoLog(pid);
Console.WriteLine(resultLog);
}
//need to work on validation. apparently there are some weird caveats to glValidate which make it complicated and possibly excuses (barely) the intel drivers' dysfunctional operation
//"A sampler points to a texture unit used by fixed function with an incompatible target"
@ -304,14 +273,6 @@ namespace BizHawk.Client.EmuHawk
errcode = GL.GetError();
int loc = GL.GetUniformLocation(pid, name);
//translate name if appropriate
//not sure how effective this approach will be, due to confusion of vertex and fragment uniforms
if (mapVariables)
{
if (vsw.MapCodeToNative.ContainsKey(name)) name = vsw.MapCodeToNative[name];
if (fsw.MapCodeToNative.ContainsKey(name)) name = fsw.MapCodeToNative[name];
}
var ui = new UniformInfo { Name = name, Opaque = loc };
if (type == ActiveUniformType.Sampler2D)
@ -425,11 +386,7 @@ namespace BizHawk.Client.EmuHawk
public unsafe void SetPipelineUniformMatrix(PipelineUniform uniform, Matrix4 mat, bool transpose)
{
//GL.UniformMatrix4((int)uniform.Opaque, 1, transpose, (float*)&mat);
GL.Uniform4((int)uniform.Sole.Opaque + 0, 1, (float*)&mat.Row0);
GL.Uniform4((int)uniform.Sole.Opaque + 1, 1, (float*)&mat.Row1);
GL.Uniform4((int)uniform.Sole.Opaque + 2, 1, (float*)&mat.Row2);
GL.Uniform4((int)uniform.Sole.Opaque + 3, 1, (float*)&mat.Row3);
GL.UniformMatrix4((int)uniform.Sole.Opaque, 1, transpose, (float*)&mat);
}
public unsafe void SetPipelineUniformMatrix(PipelineUniform uniform, ref Matrix4 mat, bool transpose)
@ -694,18 +651,22 @@ namespace BizHawk.Client.EmuHawk
Shader CreateShader(ShaderType type, string source, string entry, bool required)
{
var sw = new ShaderWrapper();
string info = "";
int sid = GL.CreateShader(type);
bool ok = CompileShaderSimple(sid, source, required);
if(!ok)
{
GL.GetShaderInfoLog(sid, out info);
GL.DeleteShader(sid);
sid = 0;
}
Shader ret = new Shader(this, sw, ok);
ret.Errors = info;
sw.sid = sid;
return new Shader(this, sw, ok);
return ret;
}
bool CompileShaderSimple(int sid, string source, bool required)