Go to the documentation of this file.
22 static int current_shader = 0;
35 const char *vert_source;
36 const char *frag_source;
44 "varying vec4 v_color;\n"
48 " gl_Position = gl_ModelViewProjectionMatrix * gl_Vertex;\n"
49 " v_color = gl_Color;\n"
52 "varying vec4 v_color;\n"
56 " gl_FragColor = v_color;\n"
63 "varying vec4 v_color;\n"
64 "varying vec2 v_texCoord;\n"
68 " gl_Position = gl_ModelViewProjectionMatrix * gl_Vertex;\n"
69 " v_color = gl_Color;\n"
70 " v_texCoord = vec2(gl_MultiTexCoord0);\n"
73 "varying vec4 v_color;\n"
74 "varying vec2 v_texCoord;\n"
75 "uniform sampler2D tex0;\n"
79 " gl_FragColor = texture2D(tex0, v_texCoord) * v_color;\n"
86 "varying vec2 v_texCoord;\n"
90 " gl_Position = gl_ModelViewProjectionMatrix * gl_Vertex;\n"
91 " v_texCoord = vec2(gl_MultiTexCoord0);\n"
94 "varying vec2 v_texCoord;\n"
102 " delta = vec2(0.5, 0.5) - v_texCoord;\n"
103 " dist = dot(delta, delta);\n"
105 " color.r = v_texCoord.x;\n"
106 " color.g = v_texCoord.x * v_texCoord.y;\n"
107 " color.b = v_texCoord.y;\n"
108 " color.a = 1.0 - (dist * 4.0);\n"
109 " gl_FragColor = color;\n"
114 static PFNGLATTACHOBJECTARBPROC glAttachObjectARB;
115 static PFNGLCOMPILESHADERARBPROC glCompileShaderARB;
116 static PFNGLCREATEPROGRAMOBJECTARBPROC glCreateProgramObjectARB;
117 static PFNGLCREATESHADEROBJECTARBPROC glCreateShaderObjectARB;
118 static PFNGLDELETEOBJECTARBPROC glDeleteObjectARB;
119 static PFNGLGETINFOLOGARBPROC glGetInfoLogARB;
120 static PFNGLGETOBJECTPARAMETERIVARBPROC glGetObjectParameterivARB;
121 static PFNGLGETUNIFORMLOCATIONARBPROC glGetUniformLocationARB;
122 static PFNGLLINKPROGRAMARBPROC glLinkProgramARB;
123 static PFNGLSHADERSOURCEARBPROC glShaderSourceARB;
124 static PFNGLUNIFORM1IARBPROC glUniform1iARB;
125 static PFNGLUSEPROGRAMOBJECTARBPROC glUseProgramObjectARB;
132 glCompileShaderARB(
shader);
152 const int num_tmus_bound = 4;
159 data->program = glCreateProgramObjectARB();
163 if (!CompileShader(
data->vert_shader,
data->vert_source)) {
169 if (!CompileShader(
data->frag_shader,
data->frag_source)) {
174 glAttachObjectARB(
data->program,
data->vert_shader);
175 glAttachObjectARB(
data->program,
data->frag_shader);
176 glLinkProgramARB(
data->program);
179 glUseProgramObjectARB(
data->program);
180 for (
i = 0;
i < num_tmus_bound; ++
i) {
183 location = glGetUniformLocationARB(
data->program, tex_name);
188 glUseProgramObjectARB(0);
193 static void DestroyShaderProgram(ShaderData *
data)
195 if (shaders_supported) {
196 glDeleteObjectARB(
data->vert_shader);
197 glDeleteObjectARB(
data->frag_shader);
198 glDeleteObjectARB(
data->program);
214 glCreateProgramObjectARB = (PFNGLCREATEPROGRAMOBJECTARBPROC)
SDL_GL_GetProcAddress(
"glCreateProgramObjectARB");
215 glCreateShaderObjectARB = (PFNGLCREATESHADEROBJECTARBPROC)
SDL_GL_GetProcAddress(
"glCreateShaderObjectARB");
218 glGetObjectParameterivARB = (PFNGLGETOBJECTPARAMETERIVARBPROC)
SDL_GL_GetProcAddress(
"glGetObjectParameterivARB");
219 glGetUniformLocationARB = (PFNGLGETUNIFORMLOCATIONARBPROC)
SDL_GL_GetProcAddress(
"glGetUniformLocationARB");
223 glUseProgramObjectARB = (PFNGLUSEPROGRAMOBJECTARBPROC)
SDL_GL_GetProcAddress(
"glUseProgramObjectARB");
224 if (glAttachObjectARB &&
225 glCompileShaderARB &&
226 glCreateProgramObjectARB &&
227 glCreateShaderObjectARB &&
230 glGetObjectParameterivARB &&
231 glGetUniformLocationARB &&
235 glUseProgramObjectARB) {
240 if (!shaders_supported) {
246 if (!CompileShaderProgram(&
shaders[
i])) {
256 static void QuitShaders()
267 power_of_two(
int input)
297 0x0000FF00, 0x00FF0000, 0xFF000000
300 0x00FF0000, 0x0000FF00, 0x000000FF
335 void InitGL(
int Width,
int Height)
350 glOrtho(-3.0, 3.0, -3.0 / aspect, 3.0 / aspect, 0.0, 1.0);
392 if (shaders_supported) {
407 if (shaders_supported) {
408 glUseProgramObjectARB(0);
416 int main(
int argc,
char **argv)
459 SDL_Log(
"Shaders supported, press SPACE to cycle them.\n");
475 current_shader = (current_shader + 1) %
NUM_SHADERS;
GLAPI void GLAPIENTRY glEnd(void)
A collection of pixels used in software blitting.
#define SDL_WINDOWPOS_CENTERED
GLsizei GLsizei GLchar * source
GLAPI void GLAPIENTRY glDepthFunc(GLenum func)
GLAPI GLenum GLAPIENTRY glGetError(void)
set set set set set set set macro pixldst1 abits if abits op else op endif endm macro pixldst2 abits if abits op else op endif endm macro pixldst4 abits if abits op else op endif endm macro pixldst0 abits op endm macro pixldst3 mem_operand op endm macro pixldst30 mem_operand op endm macro pixldst abits if abits elseif abits elseif abits elseif abits elseif abits pixldst0 abits else pixldst0 abits pixldst0 abits pixldst0 abits pixldst0 abits endif elseif abits else pixldst0 abits pixldst0 abits endif elseif abits else error unsupported bpp *numpix else pixst endif endm macro pixld1_s mem_operand if asr adds SRC_WIDTH_FIXED bpl add asl mov asr adds SRC_WIDTH_FIXED bpl add asl mov asr adds SRC_WIDTH_FIXED bpl add asl mov asr adds SRC_WIDTH_FIXED bpl add asl elseif asr adds SRC_WIDTH_FIXED bpl add asl mov asr adds SRC_WIDTH_FIXED bpl add asl else error unsupported endif endm macro pixld2_s mem_operand if mov asr add asl add asl mov asr sub UNIT_X add asl mov asr add asl add asl mov asr add UNIT_X add asl else pixld1_s mem_operand pixld1_s mem_operand endif endm macro pixld0_s mem_operand if asr adds SRC_WIDTH_FIXED bpl add asl elseif asr adds SRC_WIDTH_FIXED bpl add asl endif endm macro pixld_s_internal mem_operand if mem_operand pixld2_s mem_operand pixdeinterleave basereg elseif mem_operand elseif mem_operand elseif mem_operand elseif mem_operand pixld0_s mem_operand else pixld0_s mem_operand pixld0_s mem_operand pixld0_s mem_operand pixld0_s mem_operand endif elseif mem_operand else pixld0_s mem_operand pixld0_s mem_operand endif elseif mem_operand else error unsupported mem_operand if bpp mem_operand endif endm macro vuzp8 reg2 vuzp d d ®2 endm macro vzip8 reg2 vzip d d ®2 endm macro pixdeinterleave basereg basereg basereg basereg basereg endif endm macro pixinterleave basereg basereg basereg basereg basereg endif endm macro PF boost_increment endif if endif PF tst PF addne PF subne PF cmp ORIG_W if endif if endif if endif PF subge ORIG_W PF subges if endif if endif if endif endif endm macro cache_preload_simple endif if dst_r_bpp pld[DST_R, #(PREFETCH_DISTANCE_SIMPLE *dst_r_bpp/8)] endif if mask_bpp pld endif[MASK, #(PREFETCH_DISTANCE_SIMPLE *mask_bpp/8)] endif endif endm macro fetch_mask_pixblock pixld mask_basereg pixblock_size MASK endm macro ensure_destination_ptr_alignment process_pixblock_tail_head if beq irp skip1 beq endif SRC MASK if dst_r_bpp DST_R else add endif PF add sub src_basereg pixdeinterleave mask_basereg pixdeinterleave dst_r_basereg process_pixblock_head pixblock_size cache_preload_simple process_pixblock_tail pixinterleave dst_w_basereg irp beq endif process_pixblock_tail_head tst beq irp if pixblock_size chunk_size tst beq pixld_src SRC pixld MASK if DST_R else pixld DST_R endif if
GLAPI void GLAPIENTRY glClear(GLbitfield mask)
#define SDL_GL_CreateContext
GLAPI void GLAPIENTRY glVertex3f(GLfloat x, GLfloat y, GLfloat z)
GLAPI void GLAPIENTRY glBindTexture(GLenum target, GLuint texture)
#define GL_COLOR_BUFFER_BIT
GLAPI void GLAPIENTRY glTranslatef(GLfloat x, GLfloat y, GLfloat z)
GLsizei GLsizei GLuint * shaders
GLenum GLenum GLenum input
GLAPI void GLAPIENTRY glShadeModel(GLenum mode)
GLAPI void GLAPIENTRY glClearColor(GLclampf red, GLclampf green, GLclampf blue, GLclampf alpha)
GLfloat GLfloat GLfloat GLfloat h
GLuint GLsizei GLsizei * length
#define SDL_GetSurfaceBlendMode
GLAPI void GLAPIENTRY glDisable(GLenum cap)
GLAPI void GLAPIENTRY glTexParameteri(GLenum target, GLenum pname, GLint param)
GLint GLenum GLsizei GLsizei GLsizei GLint GLsizei const GLvoid * data
The type used to identify a window.
#define SDL_stack_alloc(type, count)
GLAPI void GLAPIENTRY glTexEnvf(GLenum target, GLenum pname, GLfloat param)
#define GL_FRAGMENT_SHADER_ARB
GLAPI void GLAPIENTRY glGenTextures(GLsizei n, GLuint *textures)
#define GL_TEXTURE_MIN_FILTER
#define GL_DEPTH_BUFFER_BIT
int main(int argc, char *argv[])
EGLSurface EGLNativeWindowType * window
GLAPI void GLAPIENTRY glLoadIdentity(void)
#define SDL_GL_GetProcAddress
@ SDL_LOG_CATEGORY_APPLICATION
#define GL_OBJECT_INFO_LOG_LENGTH_ARB
GLAPI void GLAPIENTRY glViewport(GLint x, GLint y, GLsizei width, GLsizei height)
#define GL_TEXTURE_ENV_MODE
#define GL_OBJECT_COMPILE_STATUS_ARB
const GLubyte GLuint GLuint GLuint GLuint alpha GLboolean GLboolean GLboolean GLboolean alpha GLint GLint GLsizei GLsizei GLenum type GLenum GLint GLenum GLint GLint GLsizei GLsizei GLint border GLenum GLint GLint GLint GLint GLint GLsizei GLsizei height GLsizei GLsizei GLenum GLenum const GLvoid *pixels GLenum GLint GLint GLint GLint j2 GLdouble GLdouble GLdouble GLdouble GLdouble GLdouble zFar GLenum GLenum GLint *params GLenum GLenum GLint *params GLenum GLenum GLint *params GLenum GLenum GLfloat *params GLenum GLint GLenum GLenum GLvoid *pixels GLenum GLint GLenum GLint *params GLenum GLenum GLint *params GLenum GLsizei const GLvoid *pointer GLenum GLenum const GLint *params GLenum GLfloat GLfloat GLint GLint const GLfloat *points GLenum GLfloat GLfloat GLint GLint GLfloat GLfloat GLint GLint const GLfloat *points GLint GLfloat GLfloat GLint GLfloat GLfloat v2 GLenum GLenum const GLint *params glOrtho
#define GL_TEXTURE_MAG_FILTER
#define SDL_LoadBMP(file)
GLAPI void GLAPIENTRY glBlendFunc(GLenum sfactor, GLenum dfactor)
#define SDL_CreateRGBSurface
#define SDL_arraysize(array)
GLAPI void GLAPIENTRY glBegin(GLenum mode)
GLAPI void GLAPIENTRY glColor3f(GLfloat red, GLfloat green, GLfloat blue)
#define SDL_stack_free(data)
#define SDL_LogSetPriority
GLsizei const GLfloat * value
A rectangle, with the origin at the upper left (integer).
GLAPI void GLAPIENTRY glMatrixMode(GLenum mode)
#define SDL_SetSurfaceBlendMode
const GLubyte GLuint GLuint GLuint GLuint alpha GLboolean GLboolean GLboolean GLboolean alpha GLint GLint GLsizei GLsizei GLenum type GLenum GLint GLenum GLint GLint GLsizei GLsizei GLint border GLenum GLint GLint GLint GLint GLint GLsizei GLsizei height GLsizei GLsizei GLenum GLenum const GLvoid *pixels GLenum GLint GLint GLint GLint j2 GLdouble GLdouble GLdouble GLdouble GLdouble GLdouble zFar GLenum GLenum GLint *params GLenum GLenum GLint *params GLenum GLenum GLint *params GLenum GLenum GLfloat *params GLenum GLint GLenum GLenum GLvoid *pixels GLenum GLint GLenum GLint *params GLenum GLenum GLint *params GLenum GLsizei const GLvoid *pointer GLenum GLenum const GLint *params GLenum GLfloat GLfloat GLint GLint const GLfloat *points GLenum GLfloat GLfloat GLint GLint GLfloat GLfloat GLint GLint const GLfloat *points GLint GLfloat GLfloat GLint GLfloat GLfloat v2 GLenum GLenum const GLint *params GLdouble GLdouble GLdouble GLdouble GLdouble GLdouble zFar GLenum GLsizei const GLuint *values GLsizei const GLuint const GLclampf *priorities GLfloat GLfloat GLfloat GLfloat w GLint GLint GLsizei GLsizei GLenum GLenum GLvoid *pixels GLfloat GLfloat GLfloat GLfloat y2 GLdouble GLdouble GLdouble GLdouble z GLdouble GLdouble GLdouble GLdouble q GLshort GLshort GLshort GLshort q GLenum GLenum const GLfloat *params GLenum GLenum const GLdouble *params GLenum GLenum const GLint *params glTexImage2D
GLbitfield GLuint program
#define SDL_GL_SwapWindow
#define GL_ONE_MINUS_SRC_ALPHA
GLenum GLenum GLuint texture
#define GL_VERTEX_SHADER_ARB
GLAPI void GLAPIENTRY glTexCoord2f(GLfloat s, GLfloat t)
GLAPI void GLAPIENTRY glClearDepth(GLclampd depth)
return Display return Display Bool Bool int int int return Display XEvent Bool(*) XPointer return Display return Display Drawable _Xconst char unsigned int unsigned int return Display Pixmap Pixmap XColor XColor unsigned int unsigned int return Display _Xconst char char int char return Display Visual unsigned int int int char unsigned int unsigned int in i)
SDL_BlendMode
The blend mode used in SDL_RenderCopy() and drawing operations.
GLAPI void GLAPIENTRY glEnable(GLenum cap)
GLubyte GLubyte GLubyte GLubyte w
#define SDL_GL_ExtensionSupported