zzogl: plug vertex array object and remove most deprecated variable from shader. Only remains gl_FragData

git-svn-id: http://pcsx2.googlecode.com/svn/trunk@5210 96395faa-99c1-11dd-bbfe-3dabce05a288
This commit is contained in:
gregory.hainaut 2012-05-13 20:22:15 +00:00
parent 7d7ca41187
commit e7de58c3e2
5 changed files with 56 additions and 36 deletions

View File

@ -87,10 +87,12 @@ static __forceinline void GL_STENCILFUNC_SET()
// sets the data stream // sets the data stream
static __forceinline void SET_STREAM() static __forceinline void SET_STREAM()
{ {
#ifndef GLSL4_API
glColorPointer(4, GL_UNSIGNED_BYTE, sizeof(VertexGPU), (void*)8); glColorPointer(4, GL_UNSIGNED_BYTE, sizeof(VertexGPU), (void*)8);
glSecondaryColorPointerEXT(4, GL_UNSIGNED_BYTE, sizeof(VertexGPU), (void*)12); glSecondaryColorPointerEXT(4, GL_UNSIGNED_BYTE, sizeof(VertexGPU), (void*)12);
glTexCoordPointer(3, GL_FLOAT, sizeof(VertexGPU), (void*)16); glTexCoordPointer(3, GL_FLOAT, sizeof(VertexGPU), (void*)16);
glVertexPointer(4, GL_SHORT, sizeof(VertexGPU), (void*)0); glVertexPointer(4, GL_SHORT, sizeof(VertexGPU), (void*)0);
#endif
} }
// global alpha blending settings // global alpha blending settings

View File

@ -682,6 +682,9 @@ bool ZZCreate(int _width, int _height)
glBufferDataARB(GL_ARRAY_BUFFER, 4*sizeof(VertexGPU), &verts[0], GL_STATIC_DRAW); glBufferDataARB(GL_ARRAY_BUFFER, 4*sizeof(VertexGPU), &verts[0], GL_STATIC_DRAW);
// FIXME Done inside ZZoglShadersGLSL4 for the moment
// Move it later
#ifndef GLSL4_API
// setup the default vertex declaration // setup the default vertex declaration
glEnableClientState(GL_VERTEX_ARRAY); glEnableClientState(GL_VERTEX_ARRAY);
glClientActiveTexture(GL_TEXTURE0); glClientActiveTexture(GL_TEXTURE0);
@ -689,6 +692,7 @@ bool ZZCreate(int _width, int _height)
glEnableClientState(GL_SECONDARY_COLOR_ARRAY); glEnableClientState(GL_SECONDARY_COLOR_ARRAY);
glEnableClientState(GL_COLOR_ARRAY); glEnableClientState(GL_COLOR_ARRAY);
GL_REPORT_ERROR(); GL_REPORT_ERROR();
#endif
// some cards don't support this // some cards don't support this
// glClientActiveTexture(GL_TEXTURE0); // glClientActiveTexture(GL_TEXTURE0);

View File

@ -61,6 +61,7 @@ inline bool ZZshActiveParameter(ZZshParameter param) {return (param !=NULL); }
#ifdef GLSL4_API #ifdef GLSL4_API
#include "GSUniformBufferOGL.h" #include "GSUniformBufferOGL.h"
#include "GSVertexArrayOGL.h"
#endif #endif
#ifdef GLSL_API #ifdef GLSL_API
@ -363,7 +364,6 @@ struct SamplerParam {
struct FRAGMENTSHADER struct FRAGMENTSHADER
{ {
FRAGMENTSHADER() : prog(sZero) FRAGMENTSHADER() : prog(sZero)
, Shader(0)
, program(0) , program(0)
, sFinal(2) , sFinal(2)
, sBitwiseANDX(3) , sBitwiseANDX(3)
@ -403,7 +403,6 @@ struct FRAGMENTSHADER
} }
ZZshShaderLink prog; // it link to FRAGMENTSHADER structure, for compability between GLSL and CG ZZshShaderLink prog; // it link to FRAGMENTSHADER structure, for compability between GLSL and CG
ZZshShader Shader; // useless with separate build
ZZshProgram program; ZZshProgram program;
ZZshShaderType ShaderType; // Not every PS and VS are used together, only compatible ones. ZZshShaderType ShaderType; // Not every PS and VS are used together, only compatible ones.
@ -705,6 +704,7 @@ extern GSUniformBufferOGL *constant_buffer;
extern GSUniformBufferOGL *common_buffer; extern GSUniformBufferOGL *common_buffer;
extern GSUniformBufferOGL *vertex_buffer; extern GSUniformBufferOGL *vertex_buffer;
extern GSUniformBufferOGL *fragment_buffer; extern GSUniformBufferOGL *fragment_buffer;
extern GSVertexBufferStateOGL *vertex_array;
static void init_shader(); static void init_shader();
static void PutParametersInProgram(VERTEXSHADER* vs, FRAGMENTSHADER* ps, int context); static void PutParametersInProgram(VERTEXSHADER* vs, FRAGMENTSHADER* ps, int context);

View File

@ -118,6 +118,7 @@ GSUniformBufferOGL *constant_buffer;
GSUniformBufferOGL *common_buffer; GSUniformBufferOGL *common_buffer;
GSUniformBufferOGL *vertex_buffer; GSUniformBufferOGL *vertex_buffer;
GSUniformBufferOGL *fragment_buffer; GSUniformBufferOGL *fragment_buffer;
GSVertexBufferStateOGL *vertex_array;
COMMONSHADER g_cs; COMMONSHADER g_cs;
static GLuint s_pipeline = 0; static GLuint s_pipeline = 0;
@ -168,8 +169,6 @@ bool ZZshStartUsingShaders() {
g_nPixelShaderVer = SHADER_ACCURATE|SHADER_REDUCED; g_nPixelShaderVer = SHADER_ACCURATE|SHADER_REDUCED;
pfrag = ZZshLoadShadeEffect(0, 0, 1, 1, 0, temp, 0, &bFailed); pfrag = ZZshLoadShadeEffect(0, 0, 1, 1, 0, temp, 0, &bFailed);
if( pfrag != NULL )
glLinkProgram(pfrag->Shader);
if( bFailed || pfrag == NULL || glGetError() != GL_NO_ERROR) { if( bFailed || pfrag == NULL || glGetError() != GL_NO_ERROR) {
g_nPixelShaderVer = SHADER_REDUCED; g_nPixelShaderVer = SHADER_REDUCED;
ZZLog::Error_Log("Basic shader test failed."); ZZLog::Error_Log("Basic shader test failed.");
@ -222,6 +221,8 @@ void ZZshExitCleaning() {
delete vertex_buffer; delete vertex_buffer;
delete fragment_buffer; delete fragment_buffer;
delete vertex_array;
glDeleteProgramPipelines(1, &s_pipeline); glDeleteProgramPipelines(1, &s_pipeline);
} }
@ -405,17 +406,20 @@ static void PutParametersAndRun(VERTEXSHADER* vs, FRAGMENTSHADER* ps) {
} }
inline bool ZZshCheckShaderCompatibility(VERTEXSHADER* vs, FRAGMENTSHADER* ps) { inline bool ZZshCheckShaderCompatibility(VERTEXSHADER* vs, FRAGMENTSHADER* ps) {
if (vs == NULL) return false;
if (vs->ShaderType == ZZ_SH_ZERO) return true; // ZeroPS is compatible with everything if (vs->ShaderType == ZZ_SH_ZERO) return true; // ZeroPS is compatible with everything
if (ps == NULL) return false;
return (vs->ShaderType == ps->ShaderType); return (vs->ShaderType == ps->ShaderType);
} }
static void ZZshSetShader(VERTEXSHADER* vs, FRAGMENTSHADER* ps) { static void ZZshSetShader(VERTEXSHADER* vs, FRAGMENTSHADER* ps) {
if (vs == NULL || ps == NULL) return; if (vs == NULL || ps == NULL) {
// if (vs == NULL) fprintf(stderr, "VS is null !!! \n");
// if (ps == NULL) fprintf(stderr, "PS is null !!! \n");
return;
}
UNIFORM_ERROR_LOG("SHADER: %s(%d) \t+\t%s(%d)", ShaderNames[vs->program], vs->program, ShaderNames[ps->program], ps->program); // FIXME all Shader are compatible now
// I keep for the moment to avoid useless running of the program
if (!ZZshCheckShaderCompatibility(vs, ps)) { // We don't need to link uncompatible shaders if (!ZZshCheckShaderCompatibility(vs, ps)) { // We don't need to link uncompatible shaders
return; return;
} }
@ -461,10 +465,21 @@ static void init_shader() {
constant_buffer->bind(); constant_buffer->bind();
constant_buffer->upload((void*)&g_cs.uniform_buffer_constant); constant_buffer->upload((void*)&g_cs.uniform_buffer_constant);
glGenProgramPipelines(1, &s_pipeline); glGenProgramPipelines(1, &s_pipeline);
glBindProgramPipeline(s_pipeline); glBindProgramPipeline(s_pipeline);
// FIXME maybe GL_UNSIGNED_SHORT could be better than GL_SHORT
GSInputLayoutOGL vert_format[] =
{
{0 , 4 , GL_SHORT , GL_FALSE , sizeof(VertexGPU) , (const GLvoid*)(0) } , // vertex
{1 , 4 , GL_UNSIGNED_BYTE , GL_TRUE , sizeof(VertexGPU) , (const GLvoid*)(8) } , // color
{2 , 4 , GL_UNSIGNED_BYTE , GL_TRUE , sizeof(VertexGPU) , (const GLvoid*)(12) } , // z value. FIXME WTF 4 unsigned byte, why not a full integer
{3 , 3 , GL_FLOAT , GL_FALSE , sizeof(VertexGPU) , (const GLvoid*)(16) } , // tex coord
};
vertex_array = new GSVertexBufferStateOGL(sizeof(VertexGPU), vert_format, 4);
} }
static void PutParametersInProgram(VERTEXSHADER* vs, FRAGMENTSHADER* ps, int context) { static void PutParametersInProgram(VERTEXSHADER* vs, FRAGMENTSHADER* ps, int context) {
@ -487,7 +502,7 @@ static void SetupFragmentProgramParameters(FRAGMENTSHADER* pf, int context, int
// uniform parameters // uniform parameters
pf->prog.link = (void*)pf; // Setting autolink pf->prog.link = (void*)pf; // Setting autolink
pf->prog.isFragment = true; // Setting autolink pf->prog.isFragment = true; // Setting autolink
pf->ShaderType = ShaderTypes[pf->Shader]; pf->ShaderType = ShaderTypes[pf->program];
g_cs.set_texture(g_cs.sBlocks, ptexBlocks); g_cs.set_texture(g_cs.sBlocks, ptexBlocks);
g_cs.set_texture(g_cs.sConv16to32, ptexConv16to32); g_cs.set_texture(g_cs.sConv16to32, ptexConv16to32);

View File

@ -103,17 +103,16 @@ struct vertex
#ifdef VERTEX_SHADER #ifdef VERTEX_SHADER
// The standard GL3 core interface
out gl_PerVertex { out gl_PerVertex {
invariant vec4 gl_Position; invariant vec4 gl_Position;
float gl_PointSize; float gl_PointSize;
float gl_ClipDistance[]; float gl_ClipDistance[];
}; };
// FIXME: deprecated variable layout(location = 0) in uvec2 Vert;
// not supported in VS layout(location = 1) in vec4 Color;
// in vec4 gl_Color; layout(location = 2) in vec4 SecondaryColor;
// in vec4 gl_SecondaryColor; layout(location = 3) in vec3 TexCoord;
layout(location = 0) out vertex VSout; layout(location = 0) out vertex VSout;
@ -866,65 +865,65 @@ void Convert32to16PS() {
#ifdef VERTEX_SHADER #ifdef VERTEX_SHADER
float4 OutPosition(float4 vertex) { float4 OutPosition() {
float4 Position; float4 Position;
Position.xy = gl_Vertex.xy * g_fPosXY.xy + g_fPosXY.zw; Position.xy = Vert.xy * g_fPosXY.xy + g_fPosXY.zw;
Position.z = (log(g_fc0.y + dot(g_fZ, gl_SecondaryColor.zyxw)) * g_fZNorm.x + g_fZNorm.y) * g_fZMin.y + dot(g_fZ, gl_SecondaryColor.zyxw) * g_fZMin.x ; Position.z = (log(g_fc0.y + dot(g_fZ, SecondaryColor.zyxw)) * g_fZNorm.x + g_fZNorm.y) * g_fZMin.y + dot(g_fZ, SecondaryColor.zyxw) * g_fZMin.x ;
Position.w = g_fc0.y; Position.w = g_fc0.y;
return Position; return Position;
} }
// just smooth shadering // just smooth shadering
void RegularVS() { void RegularVS() {
gl_Position = OutPosition(gl_Vertex); gl_Position = OutPosition();
VSout.color = gl_Color; VSout.color = Color;
DOZWRITE(VSout.z = gl_SecondaryColor * g_fZBias.x + g_fZBias.y;) DOZWRITE(VSout.z = SecondaryColor * g_fZBias.x + g_fZBias.y;)
DOZWRITE(VSout.z.w = g_fc0.y;) DOZWRITE(VSout.z.w = g_fc0.y;)
} }
// diffuse texture mapping // diffuse texture mapping
void TextureVS() { void TextureVS() {
gl_Position = OutPosition(gl_Vertex); gl_Position = OutPosition();
VSout.color = gl_Color; VSout.color = Color;
#ifdef PERSPECTIVE_CORRECT_TEX #ifdef PERSPECTIVE_CORRECT_TEX
VSout.tex.xyz = gl_MultiTexCoord0.xyz; VSout.tex.xyz = TexCoord.xyz;
#else #else
VSout.tex.xy = gl_MultiTexCoord0.xy/gl_MultiTexCoord0.z; VSout.tex.xy = TexCoord.xy/TexCoord.z;
#endif #endif
DOZWRITE(VSout.z = gl_SecondaryColor * g_fZBias.x + g_fZBias.y;) DOZWRITE(VSout.z = SecondaryColor * g_fZBias.x + g_fZBias.y;)
DOZWRITE(VSout.z.w = g_fc0.y;) DOZWRITE(VSout.z.w = g_fc0.y;)
} }
void RegularFogVS() { void RegularFogVS() {
float4 position = OutPosition(gl_Vertex); float4 position = OutPosition();
gl_Position = position; gl_Position = position;
VSout.color = gl_Color; VSout.color = Color;
VSout.fog = position.z * g_fBilinear.w; VSout.fog = position.z * g_fBilinear.w;
DOZWRITE(VSout.z = gl_SecondaryColor * g_fZBias.x + g_fZBias.y;) DOZWRITE(VSout.z = SecondaryColor * g_fZBias.x + g_fZBias.y;)
DOZWRITE(VSout.z.w = g_fc0.y;) DOZWRITE(VSout.z.w = g_fc0.y;)
} }
void TextureFogVS() { void TextureFogVS() {
float4 position = OutPosition(gl_Vertex); float4 position = OutPosition();
gl_Position = position; gl_Position = position;
VSout.color = gl_Color; VSout.color = Color;
#ifdef PERSPECTIVE_CORRECT_TEX #ifdef PERSPECTIVE_CORRECT_TEX
VSout.tex.xyz = gl_MultiTexCoord0.xyz; VSout.tex.xyz = TexCoord.xyz;
#else #else
VSout.tex.xy = gl_MultiTexCoord0.xy/gl_MultiTexCoord0.z; VSout.tex.xy = TexCoord.xy/TexCoord.z;
#endif #endif
VSout.fog = position.z * g_fBilinear.w; VSout.fog = position.z * g_fBilinear.w;
DOZWRITE(VSout.z = gl_SecondaryColor * g_fZBias.x + g_fZBias.y;) DOZWRITE(VSout.z = SecondaryColor * g_fZBias.x + g_fZBias.y;)
DOZWRITE(VSout.z.w = g_fc0.y;) DOZWRITE(VSout.z.w = g_fc0.y;)
} }
void BitBltVS() { void BitBltVS() {
vec4 position; vec4 position;
position.xy = gl_Vertex.xy * g_fBitBltPos.xy + g_fBitBltPos.zw; position.xy = Vert.xy * g_fBitBltPos.xy + g_fBitBltPos.zw;
position.zw = g_fc0.xy; position.zw = g_fc0.xy;
gl_Position = position; gl_Position = position;
VSout.tex.xy = gl_MultiTexCoord0.xy * g_fBitBltTex.xy + g_fBitBltTex.zw; VSout.tex.xy = TexCoord.xy * g_fBitBltTex.xy + g_fBitBltTex.zw;
VSout.z.xy = position.xy * g_fBitBltTrans.xy + g_fBitBltTrans.zw; VSout.z.xy = position.xy * g_fBitBltTrans.xy + g_fBitBltTrans.zw;
} }