comparison src/video/SDL_renderer_gl.c @ 3596:f638ded38b8a

Added SDL_RenderClear() as a fast method of clearing the screen to the drawing color. Renamed SDL_RenderPoint() and SDL_RenderLine() to SDL_RenderDrawPoint() and SDL_RenderDrawLine(). Added API for rectangle drawing (as opposed to filling) Added placeholder API functions for circles and ellipses ... I'm not sure whether these will stay. Optimized software line drawing quite a bit. Added support for Wu's anti-aliased line drawing, currently disabled by default.
author Sam Lantinga <slouken@libsdl.org>
date Wed, 23 Dec 2009 01:55:00 +0000
parents 0267b8b1595c
children 0f958e527e5e
comparison
equal deleted inserted replaced
3595:b7c6828d4039 3596:f638ded38b8a
94 const SDL_Rect * rect, int markDirty, void **pixels, 94 const SDL_Rect * rect, int markDirty, void **pixels,
95 int *pitch); 95 int *pitch);
96 static void GL_UnlockTexture(SDL_Renderer * renderer, SDL_Texture * texture); 96 static void GL_UnlockTexture(SDL_Renderer * renderer, SDL_Texture * texture);
97 static void GL_DirtyTexture(SDL_Renderer * renderer, SDL_Texture * texture, 97 static void GL_DirtyTexture(SDL_Renderer * renderer, SDL_Texture * texture,
98 int numrects, const SDL_Rect * rects); 98 int numrects, const SDL_Rect * rects);
99 static int GL_RenderPoints(SDL_Renderer * renderer, const SDL_Point * points, 99 static int GL_RenderClear(SDL_Renderer * renderer);
100 int count); 100 static int GL_RenderDrawPoints(SDL_Renderer * renderer,
101 static int GL_RenderLines(SDL_Renderer * renderer, const SDL_Point * points, 101 const SDL_Point * points, int count);
102 int count); 102 static int GL_RenderDrawLines(SDL_Renderer * renderer,
103 static int GL_RenderRects(SDL_Renderer * renderer, const SDL_Rect ** rects, 103 const SDL_Point * points, int count);
104 int count); 104 static int GL_RenderDrawRects(SDL_Renderer * renderer,
105 const SDL_Rect ** rects, int count);
106 static int GL_RenderFillRects(SDL_Renderer * renderer,
107 const SDL_Rect ** rects, int count);
105 static int GL_RenderCopy(SDL_Renderer * renderer, SDL_Texture * texture, 108 static int GL_RenderCopy(SDL_Renderer * renderer, SDL_Texture * texture,
106 const SDL_Rect * srcrect, const SDL_Rect * dstrect); 109 const SDL_Rect * srcrect, const SDL_Rect * dstrect);
107 static int GL_RenderReadPixels(SDL_Renderer * renderer, const SDL_Rect * rect, 110 static int GL_RenderReadPixels(SDL_Renderer * renderer, const SDL_Rect * rect,
108 Uint32 pixel_format, void * pixels, int pitch); 111 Uint32 pixel_format, void * pixels, int pitch);
109 static int GL_RenderWritePixels(SDL_Renderer * renderer, const SDL_Rect * rect, 112 static int GL_RenderWritePixels(SDL_Renderer * renderer, const SDL_Rect * rect,
304 renderer->SetTextureScaleMode = GL_SetTextureScaleMode; 307 renderer->SetTextureScaleMode = GL_SetTextureScaleMode;
305 renderer->UpdateTexture = GL_UpdateTexture; 308 renderer->UpdateTexture = GL_UpdateTexture;
306 renderer->LockTexture = GL_LockTexture; 309 renderer->LockTexture = GL_LockTexture;
307 renderer->UnlockTexture = GL_UnlockTexture; 310 renderer->UnlockTexture = GL_UnlockTexture;
308 renderer->DirtyTexture = GL_DirtyTexture; 311 renderer->DirtyTexture = GL_DirtyTexture;
309 renderer->RenderPoints = GL_RenderPoints; 312 renderer->RenderClear = GL_RenderClear;
310 renderer->RenderLines = GL_RenderLines; 313 renderer->RenderDrawPoints = GL_RenderDrawPoints;
311 renderer->RenderRects = GL_RenderRects; 314 renderer->RenderDrawLines = GL_RenderDrawLines;
315 renderer->RenderDrawRects = GL_RenderDrawRects;
316 renderer->RenderFillRects = GL_RenderFillRects;
312 renderer->RenderCopy = GL_RenderCopy; 317 renderer->RenderCopy = GL_RenderCopy;
313 renderer->RenderReadPixels = GL_RenderReadPixels; 318 renderer->RenderReadPixels = GL_RenderReadPixels;
314 renderer->RenderWritePixels = GL_RenderWritePixels; 319 renderer->RenderWritePixels = GL_RenderWritePixels;
315 renderer->RenderPresent = GL_RenderPresent; 320 renderer->RenderPresent = GL_RenderPresent;
316 renderer->DestroyTexture = GL_DestroyTexture; 321 renderer->DestroyTexture = GL_DestroyTexture;
1112 data->blendMode = blendMode; 1117 data->blendMode = blendMode;
1113 } 1118 }
1114 } 1119 }
1115 1120
1116 static int 1121 static int
1117 GL_RenderPoints(SDL_Renderer * renderer, const SDL_Point * points, int count) 1122 GL_RenderClear(SDL_Renderer * renderer)
1123 {
1124 GL_RenderData *data = (GL_RenderData *) renderer->driverdata;
1125
1126 data->glClearColor((GLfloat) renderer->r * inv255f,
1127 (GLfloat) renderer->g * inv255f,
1128 (GLfloat) renderer->b * inv255f,
1129 (GLfloat) renderer->a * inv255f);
1130
1131 data->glClear(GL_COLOR_BUFFER_BIT);
1132
1133 return 0;
1134 }
1135
1136 static int
1137 GL_RenderDrawPoints(SDL_Renderer * renderer, const SDL_Point * points,
1138 int count)
1118 { 1139 {
1119 GL_RenderData *data = (GL_RenderData *) renderer->driverdata; 1140 GL_RenderData *data = (GL_RenderData *) renderer->driverdata;
1120 int i; 1141 int i;
1121 1142
1122 GL_SetBlendMode(data, renderer->blendMode, 1); 1143 GL_SetBlendMode(data, renderer->blendMode, 1);
1134 1155
1135 return 0; 1156 return 0;
1136 } 1157 }
1137 1158
1138 static int 1159 static int
1139 GL_RenderLines(SDL_Renderer * renderer, const SDL_Point * points, int count) 1160 GL_RenderDrawLines(SDL_Renderer * renderer, const SDL_Point * points,
1161 int count)
1140 { 1162 {
1141 GL_RenderData *data = (GL_RenderData *) renderer->driverdata; 1163 GL_RenderData *data = (GL_RenderData *) renderer->driverdata;
1142 int i; 1164 int i;
1143 1165
1144 GL_SetBlendMode(data, renderer->blendMode, 1); 1166 GL_SetBlendMode(data, renderer->blendMode, 1);
1197 1219
1198 return 0; 1220 return 0;
1199 } 1221 }
1200 1222
1201 static int 1223 static int
1202 GL_RenderRects(SDL_Renderer * renderer, const SDL_Rect ** rects, int count) 1224 GL_RenderDrawRects(SDL_Renderer * renderer, const SDL_Rect ** rects, int count)
1225 {
1226 GL_RenderData *data = (GL_RenderData *) renderer->driverdata;
1227 int i, x, y;
1228 SDL_Point points[4];
1229
1230 GL_SetBlendMode(data, renderer->blendMode, 1);
1231
1232 data->glColor4f((GLfloat) renderer->r * inv255f,
1233 (GLfloat) renderer->g * inv255f,
1234 (GLfloat) renderer->b * inv255f,
1235 (GLfloat) renderer->a * inv255f);
1236
1237 data->glBegin(GL_LINE_LOOP);
1238 for (i = 0; i < count; ++i) {
1239 const SDL_Rect *rect = rects[i];
1240
1241 x = rect->x;
1242 y = rect->y;
1243 data->glVertex2f(0.5f + x, 0.5f + y);
1244
1245 x = rect->x+rect->w-1;
1246 y = rect->y;
1247 data->glVertex2f(0.5f + x, 0.5f + y);
1248
1249 x = rect->x+rect->w-1;
1250 y = rect->y+rect->h-1;
1251 data->glVertex2f(0.5f + x, 0.5f + y);
1252
1253 x = rect->x;
1254 y = rect->y+rect->h-1;
1255 data->glVertex2f(0.5f + x, 0.5f + y);
1256 }
1257 data->glEnd();
1258
1259 return 0;
1260 }
1261
1262 static int
1263 GL_RenderFillRects(SDL_Renderer * renderer, const SDL_Rect ** rects, int count)
1203 { 1264 {
1204 GL_RenderData *data = (GL_RenderData *) renderer->driverdata; 1265 GL_RenderData *data = (GL_RenderData *) renderer->driverdata;
1205 int i; 1266 int i;
1206 1267
1207 GL_SetBlendMode(data, renderer->blendMode, 1); 1268 GL_SetBlendMode(data, renderer->blendMode, 1);