Loads in vertex program as well.

This commit is contained in:
Themaister 2010-11-13 03:13:10 +01:00
parent 43660dad6d
commit 42dc761cac
2 changed files with 43 additions and 15 deletions

33
gl.c
View File

@ -45,14 +45,15 @@ static const GLfloat tex_coords[] = {
}; };
static bool keep_aspect = true; static bool keep_aspect = true;
static CGparameter cg_mvp_matrix;
typedef struct gl typedef struct gl
{ {
bool vsync; bool vsync;
unsigned real_x;
unsigned real_y;
#ifdef HAVE_CG #ifdef HAVE_CG
CGcontext cgCtx; CGcontext cgCtx;
CGprogram cgPrg; CGprogram cgFPrg;
CGprogram cgVPrg;
CGprofile cgFProf;
CGprofile cgVProf; CGprofile cgVProf;
CGparameter cg_video_size, cg_texture_size; CGparameter cg_video_size, cg_texture_size;
#endif #endif
@ -188,6 +189,7 @@ static void GLFWCALL resize(int width, int height)
glOrtho(0, 1, 0, 1, -1, 1); glOrtho(0, 1, 0, 1, -1, 1);
glMatrixMode(GL_MODELVIEW); glMatrixMode(GL_MODELVIEW);
glLoadIdentity(); glLoadIdentity();
cgGLSetStateMatrixParameter(cg_mvp_matrix, CG_GL_MODELVIEW_PROJECTION_MATRIX, CG_GL_MATRIX_IDENTITY);
} }
static float tv_to_fps(const struct timeval *tv, const struct timeval *new_tv, int frames) static float tv_to_fps(const struct timeval *tv, const struct timeval *new_tv, int frames)
@ -334,27 +336,34 @@ static void* gl_init(video_info_t *video, const input_driver_t **input)
fprintf(stderr, "Failed to create Cg context\n"); fprintf(stderr, "Failed to create Cg context\n");
goto error; goto error;
} }
gl->cgVProf = cgGLGetLatestProfile(CG_GL_FRAGMENT); gl->cgFProf = cgGLGetLatestProfile(CG_GL_FRAGMENT);
if (gl->cgVProf == CG_PROFILE_UNKNOWN) gl->cgVProf = cgGLGetLatestProfile(CG_GL_VERTEX);
if (gl->cgFProf == CG_PROFILE_UNKNOWN || gl->cgVProf == CG_PROFILE_UNKNOWN)
{ {
fprintf(stderr, "Invalid profile type\n"); fprintf(stderr, "Invalid profile type\n");
goto error; goto error;
} }
cgGLSetOptimalOptions(gl->cgFProf);
cgGLSetOptimalOptions(gl->cgVProf); cgGLSetOptimalOptions(gl->cgVProf);
gl->cgPrg = cgCreateProgramFromFile(gl->cgCtx, CG_SOURCE, cg_shader_path, gl->cgVProf, "main", 0); gl->cgFPrg = cgCreateProgramFromFile(gl->cgCtx, CG_SOURCE, cg_shader_path, gl->cgFProf, "main_fragment", 0);
if (gl->cgPrg == NULL) gl->cgVPrg = cgCreateProgramFromFile(gl->cgCtx, CG_SOURCE, cg_shader_path, gl->cgVProf, "main_vertex", 0);
if (gl->cgFPrg == NULL || gl->cgVPrg == NULL)
{ {
CGerror err = cgGetError(); CGerror err = cgGetError();
fprintf(stderr, "CG error: %s\n", cgGetErrorString(err)); fprintf(stderr, "CG error: %s\n", cgGetErrorString(err));
goto error; goto error;
} }
cgGLLoadProgram(gl->cgPrg); cgGLLoadProgram(gl->cgFPrg);
cgGLLoadProgram(gl->cgVPrg);
cgGLEnableProfile(gl->cgFProf);
cgGLEnableProfile(gl->cgVProf); cgGLEnableProfile(gl->cgVProf);
cgGLBindProgram(gl->cgPrg); cgGLBindProgram(gl->cgFPrg);
cgGLBindProgram(gl->cgVPrg);
gl->cg_video_size = cgGetNamedParameter(gl->cgPrg, "IN.video_size");
gl->cg_texture_size = cgGetNamedParameter(gl->cgPrg, "IN.texture_size");
gl->cg_video_size = cgGetNamedParameter(gl->cgFPrg, "IN.video_size");
gl->cg_texture_size = cgGetNamedParameter(gl->cgFPrg, "IN.texture_size");
cg_mvp_matrix = cgGetNamedParameter(gl->cgVPrg, "modelViewProj");
cgGLSetStateMatrixParameter(cg_mvp_matrix, CG_GL_MODELVIEW_PROJECTION_MATRIX, CG_GL_MATRIX_IDENTITY);
#endif #endif
*input = &input_glfw; *input = &input_glfw;

View File

@ -1,9 +1,27 @@
/* Default Vertex shader */
void main_vertex
(
float4 position : POSITION,
float4 color : COLOR,
float2 texCoord : TEXCOORD0,
uniform float4x4 modelViewProj,
out float4 oPosition : POSITION,
out float4 oColor : COLOR,
out float2 otexCoord : TEXCOORD
)
{
oPosition = mul(modelViewProj, position);
oColor = color;
otexCoord = texCoord;
}
#define TEX2D(c) tex2D(decal,(c)) #define TEX2D(c) tex2D(decal,(c))
#define PI 3.141592653589 #define PI 3.141592653589
#define phase 0.0 #define phase 0.0
#define gamma 2.5 #define gamma 2.5
#define distortion 0.2 #define distortion 0.2
struct output struct output
@ -28,13 +46,14 @@ float2 fract(float2 v)
return ret; return ret;
} }
float2 barrelDistortion(float2 coord) { float2 barrelDistortion(float2 coord)
{
float2 cc = coord - 0.5; float2 cc = coord - 0.5;
float dist = dot(cc, cc); float dist = dot(cc, cc);
return coord + cc * (dist + distortion * dist * dist) * distortion; return coord + cc * (dist + distortion * dist * dist) * distortion;
} }
output main(float2 texCoord : TEXCOORD0, uniform sampler2D decal : TEXUNIT0, uniform input IN) output main_fragment(float2 texCoord : TEXCOORD0, uniform sampler2D decal : TEXUNIT0, uniform input IN)
{ {
output OUT; output OUT;