comparison include/SDL_render.h @ 5148:2f44e6969a59

Split the rendering API out into a separate header file.
author Sam Lantinga <slouken@libsdl.org>
date Tue, 01 Feb 2011 15:02:21 -0800
parents
children ad50b3db78bd
comparison
equal deleted inserted replaced
5147:a1345acf7b3d 5148:2f44e6969a59
1 /*
2 SDL - Simple DirectMedia Layer
3 Copyright (C) 1997-2010 Sam Lantinga
4
5 This library is free software; you can redistribute it and/or
6 modify it under the terms of the GNU Lesser General Public
7 License as published by the Free Software Foundation; either
8 version 2.1 of the License, or (at your option) any later version.
9
10 This library is distributed in the hope that it will be useful,
11 but WITHOUT ANY WARRANTY; without even the implied warranty of
12 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13 Lesser General Public License for more details.
14
15 You should have received a copy of the GNU Lesser General Public
16 License along with this library; if not, write to the Free Software
17 Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
18
19 Sam Lantinga
20 slouken@libsdl.org
21 */
22
23 /**
24 * \file SDL_render.h
25 *
26 * Header file for SDL 2D rendering functions.
27 */
28
29 #ifndef _SDL_render_h
30 #define _SDL_render_h
31
32 #include "SDL_stdinc.h"
33 //#include "SDL_pixels.h"
34 #include "SDL_rect.h"
35 #include "SDL_video.h"
36
37 #include "begin_code.h"
38 /* Set up for C function definitions, even when using C++ */
39 #ifdef __cplusplus
40 /* *INDENT-OFF* */
41 extern "C" {
42 /* *INDENT-ON* */
43 #endif
44
45 /**
46 * \brief Flags used when creating a rendering context
47 */
48 typedef enum
49 {
50 SDL_RENDERER_ACCELERATED = 0x00000001, /**< The renderer uses hardware
51 acceleration */
52 SDL_RENDERER_PRESENTVSYNC = 0x00000002 /**< Present is synchronized
53 with the refresh rate */
54 } SDL_RendererFlags;
55
56 /**
57 * \brief Information on the capabilities of a render driver or context.
58 */
59 typedef struct SDL_RendererInfo
60 {
61 const char *name; /**< The name of the renderer */
62 Uint32 flags; /**< Supported ::SDL_RendererFlags */
63 Uint32 num_texture_formats; /**< The number of available texture formats */
64 Uint32 texture_formats[50]; /**< The available texture formats */
65 int max_texture_width; /**< The maximimum texture width */
66 int max_texture_height; /**< The maximimum texture height */
67 } SDL_RendererInfo;
68
69 /**
70 * \brief The access pattern allowed for a texture.
71 */
72 typedef enum
73 {
74 SDL_TEXTUREACCESS_STATIC, /**< Changes rarely, not lockable */
75 SDL_TEXTUREACCESS_STREAMING /**< Changes frequently, lockable */
76 } SDL_TextureAccess;
77
78 /**
79 * \brief The texture channel modulation used in SDL_RenderCopy().
80 */
81 typedef enum
82 {
83 SDL_TEXTUREMODULATE_NONE = 0x00000000, /**< No modulation */
84 SDL_TEXTUREMODULATE_COLOR = 0x00000001, /**< srcC = srcC * color */
85 SDL_TEXTUREMODULATE_ALPHA = 0x00000002 /**< srcA = srcA * alpha */
86 } SDL_TextureModulate;
87
88 /**
89 * \brief An efficient driver-specific representation of pixel data
90 */
91 struct SDL_Texture;
92 typedef struct SDL_Texture SDL_Texture;
93
94
95 /* Function prototypes */
96
97 /**
98 * \brief Get the number of 2D rendering drivers available for the current
99 * display.
100 *
101 * A render driver is a set of code that handles rendering and texture
102 * management on a particular display. Normally there is only one, but
103 * some drivers may have several available with different capabilities.
104 *
105 * \sa SDL_GetRenderDriverInfo()
106 * \sa SDL_CreateRenderer()
107 */
108 extern DECLSPEC int SDLCALL SDL_GetNumRenderDrivers(void);
109
110 /**
111 * \brief Get information about a specific 2D rendering driver for the current
112 * display.
113 *
114 * \param index The index of the driver to query information about.
115 * \param info A pointer to an SDL_RendererInfo struct to be filled with
116 * information on the rendering driver.
117 *
118 * \return 0 on success, -1 if the index was out of range.
119 *
120 * \sa SDL_CreateRenderer()
121 */
122 extern DECLSPEC int SDLCALL SDL_GetRenderDriverInfo(int index,
123 SDL_RendererInfo * info);
124
125 /**
126 * \brief Create and make active a 2D rendering context for a window.
127 *
128 * \param window The window where rendering is displayed.
129 * \param index The index of the rendering driver to initialize, or -1 to
130 * initialize the first one supporting the requested flags.
131 * \param flags ::SDL_RendererFlags.
132 *
133 * \return 0 on success, -1 if there was an error creating the renderer.
134 *
135 * \sa SDL_SelectRenderer()
136 * \sa SDL_GetRendererInfo()
137 * \sa SDL_DestroyRenderer()
138 */
139 extern DECLSPEC int SDLCALL SDL_CreateRenderer(SDL_Window * window,
140 int index, Uint32 flags);
141
142 /**
143 * \brief Select the rendering context for a particular window.
144 *
145 * \return 0 on success, -1 if the selected window doesn't have a
146 * rendering context.
147 */
148 extern DECLSPEC int SDLCALL SDL_SelectRenderer(SDL_Window * window);
149
150 /**
151 * \brief Get information about the current rendering context.
152 */
153 extern DECLSPEC int SDLCALL SDL_GetRendererInfo(SDL_RendererInfo * info);
154
155 /**
156 * \brief Create a texture for the current rendering context.
157 *
158 * \param format The format of the texture.
159 * \param access One of the enumerated values in ::SDL_TextureAccess.
160 * \param w The width of the texture in pixels.
161 * \param h The height of the texture in pixels.
162 *
163 * \return The created texture is returned, or 0 if no rendering context was
164 * active, the format was unsupported, or the width or height were out
165 * of range.
166 *
167 * \sa SDL_QueryTexture()
168 * \sa SDL_DestroyTexture()
169 */
170 extern DECLSPEC SDL_Texture * SDLCALL SDL_CreateTexture(Uint32 format,
171 int access, int w,
172 int h);
173
174 /**
175 * \brief Create a texture from an existing surface.
176 *
177 * \param format The format of the texture, or 0 to pick an appropriate format.
178 * \param surface The surface containing pixel data used to fill the texture.
179 *
180 * \return The created texture is returned, or 0 if no rendering context was
181 * active, the format was unsupported, or the surface width or height
182 * were out of range.
183 *
184 * \note The surface is not modified or freed by this function.
185 *
186 * \sa SDL_QueryTexture()
187 * \sa SDL_DestroyTexture()
188 */
189 extern DECLSPEC SDL_Texture * SDLCALL SDL_CreateTextureFromSurface(Uint32
190 format,
191 SDL_Surface
192 * surface);
193
194 /**
195 * \brief Query the attributes of a texture
196 *
197 * \param texture A texture to be queried.
198 * \param format A pointer filled in with the raw format of the texture. The
199 * actual format may differ, but pixel transfers will use this
200 * format.
201 * \param access A pointer filled in with the actual access to the texture.
202 * \param w A pointer filled in with the width of the texture in pixels.
203 * \param h A pointer filled in with the height of the texture in pixels.
204 *
205 * \return 0 on success, or -1 if the texture is not valid.
206 */
207 extern DECLSPEC int SDLCALL SDL_QueryTexture(SDL_Texture * texture,
208 Uint32 * format, int *access,
209 int *w, int *h);
210
211 /**
212 * \brief Query the pixels of a texture, if the texture does not need to be
213 * locked for pixel access.
214 *
215 * \param texture A texture to be queried, which was created with
216 * ::SDL_TEXTUREACCESS_STREAMING.
217 * \param pixels A pointer filled with a pointer to the pixels for the
218 * texture.
219 * \param pitch A pointer filled in with the pitch of the pixel data.
220 *
221 * \return 0 on success, or -1 if the texture is not valid, or must be locked
222 * for pixel access.
223 */
224 extern DECLSPEC int SDLCALL SDL_QueryTexturePixels(SDL_Texture * texture,
225 void **pixels, int *pitch);
226
227 /**
228 * \brief Set the color palette of an indexed texture.
229 *
230 * \param texture The texture to update.
231 * \param colors The array of RGB color data.
232 * \param firstcolor The first index to update.
233 * \param ncolors The number of palette entries to fill with the color data.
234 *
235 * \return 0 on success, or -1 if the texture is not valid or not an indexed
236 * texture.
237 */
238 extern DECLSPEC int SDLCALL SDL_SetTexturePalette(SDL_Texture * texture,
239 const SDL_Color * colors,
240 int firstcolor,
241 int ncolors);
242
243 /**
244 * \brief Get the color palette from an indexed texture if it has one.
245 *
246 * \param texture The texture to update.
247 * \param colors The array to fill with RGB color data.
248 * \param firstcolor The first index to retrieve.
249 * \param ncolors The number of palette entries to retrieve.
250 *
251 * \return 0 on success, or -1 if the texture is not valid or not an indexed
252 * texture.
253 */
254 extern DECLSPEC int SDLCALL SDL_GetTexturePalette(SDL_Texture * texture,
255 SDL_Color * colors,
256 int firstcolor,
257 int ncolors);
258
259 /**
260 * \brief Set an additional color value used in render copy operations.
261 *
262 * \param texture The texture to update.
263 * \param r The red color value multiplied into copy operations.
264 * \param g The green color value multiplied into copy operations.
265 * \param b The blue color value multiplied into copy operations.
266 *
267 * \return 0 on success, or -1 if the texture is not valid or color modulation
268 * is not supported.
269 *
270 * \sa SDL_GetTextureColorMod()
271 */
272 extern DECLSPEC int SDLCALL SDL_SetTextureColorMod(SDL_Texture * texture,
273 Uint8 r, Uint8 g, Uint8 b);
274
275
276 /**
277 * \brief Get the additional color value used in render copy operations.
278 *
279 * \param texture The texture to query.
280 * \param r A pointer filled in with the current red color value.
281 * \param g A pointer filled in with the current green color value.
282 * \param b A pointer filled in with the current blue color value.
283 *
284 * \return 0 on success, or -1 if the texture is not valid.
285 *
286 * \sa SDL_SetTextureColorMod()
287 */
288 extern DECLSPEC int SDLCALL SDL_GetTextureColorMod(SDL_Texture * texture,
289 Uint8 * r, Uint8 * g,
290 Uint8 * b);
291
292 /**
293 * \brief Set an additional alpha value used in render copy operations.
294 *
295 * \param texture The texture to update.
296 * \param alpha The alpha value multiplied into copy operations.
297 *
298 * \return 0 on success, or -1 if the texture is not valid or alpha modulation
299 * is not supported.
300 *
301 * \sa SDL_GetTextureAlphaMod()
302 */
303 extern DECLSPEC int SDLCALL SDL_SetTextureAlphaMod(SDL_Texture * texture,
304 Uint8 alpha);
305
306 /**
307 * \brief Get the additional alpha value used in render copy operations.
308 *
309 * \param texture The texture to query.
310 * \param alpha A pointer filled in with the current alpha value.
311 *
312 * \return 0 on success, or -1 if the texture is not valid.
313 *
314 * \sa SDL_SetTextureAlphaMod()
315 */
316 extern DECLSPEC int SDLCALL SDL_GetTextureAlphaMod(SDL_Texture * texture,
317 Uint8 * alpha);
318
319 /**
320 * \brief Set the blend mode used for texture copy operations.
321 *
322 * \param texture The texture to update.
323 * \param blendMode ::SDL_BlendMode to use for texture blending.
324 *
325 * \return 0 on success, or -1 if the texture is not valid or the blend mode is
326 * not supported.
327 *
328 * \note If the blend mode is not supported, the closest supported mode is
329 * chosen.
330 *
331 * \sa SDL_GetTextureBlendMode()
332 */
333 extern DECLSPEC int SDLCALL SDL_SetTextureBlendMode(SDL_Texture * texture,
334 SDL_BlendMode blendMode);
335
336 /**
337 * \brief Get the blend mode used for texture copy operations.
338 *
339 * \param texture The texture to query.
340 * \param blendMode A pointer filled in with the current blend mode.
341 *
342 * \return 0 on success, or -1 if the texture is not valid.
343 *
344 * \sa SDL_SetTextureBlendMode()
345 */
346 extern DECLSPEC int SDLCALL SDL_GetTextureBlendMode(SDL_Texture * texture,
347 SDL_BlendMode *blendMode);
348
349 /**
350 * \brief Update the given texture rectangle with new pixel data.
351 *
352 * \param texture The texture to update
353 * \param rect A pointer to the rectangle of pixels to update, or NULL to
354 * update the entire texture.
355 * \param pixels The raw pixel data.
356 * \param pitch The number of bytes between rows of pixel data.
357 *
358 * \return 0 on success, or -1 if the texture is not valid.
359 *
360 * \note This is a fairly slow function.
361 */
362 extern DECLSPEC int SDLCALL SDL_UpdateTexture(SDL_Texture * texture,
363 const SDL_Rect * rect,
364 const void *pixels, int pitch);
365
366 /**
367 * \brief Lock a portion of the texture for pixel access.
368 *
369 * \param texture The texture to lock for access, which was created with
370 * ::SDL_TEXTUREACCESS_STREAMING.
371 * \param rect A pointer to the rectangle to lock for access. If the rect
372 * is NULL, the entire texture will be locked.
373 * \param markDirty If this is nonzero, the locked area will be marked dirty
374 * when the texture is unlocked.
375 * \param pixels This is filled in with a pointer to the locked pixels,
376 * appropriately offset by the locked area.
377 * \param pitch This is filled in with the pitch of the locked pixels.
378 *
379 * \return 0 on success, or -1 if the texture is not valid or was created with
380 * ::SDL_TEXTUREACCESS_STATIC.
381 *
382 * \sa SDL_DirtyTexture()
383 * \sa SDL_UnlockTexture()
384 */
385 extern DECLSPEC int SDLCALL SDL_LockTexture(SDL_Texture * texture,
386 const SDL_Rect * rect,
387 int markDirty, void **pixels,
388 int *pitch);
389
390 /**
391 * \brief Unlock a texture, uploading the changes to renderer memory, if needed.
392 *
393 * \sa SDL_LockTexture()
394 * \sa SDL_DirtyTexture()
395 */
396 extern DECLSPEC void SDLCALL SDL_UnlockTexture(SDL_Texture * texture);
397
398 /**
399 * \brief Mark the specified rectangles of the texture as dirty.
400 *
401 * \param texture The texture to mark dirty, which was created with
402 * ::SDL_TEXTUREACCESS_STREAMING.
403 * \param numrects The number of rectangles pointed to by rects.
404 * \param rects The pointer to an array of dirty rectangles.
405 *
406 * \sa SDL_LockTexture()
407 * \sa SDL_UnlockTexture()
408 */
409 extern DECLSPEC void SDLCALL SDL_DirtyTexture(SDL_Texture * texture,
410 int numrects,
411 const SDL_Rect * rects);
412
413 /**
414 * \brief Set the color used for drawing operations (Fill and Line).
415 *
416 * \param r The red value used to draw on the rendering target.
417 * \param g The green value used to draw on the rendering target.
418 * \param b The blue value used to draw on the rendering target.
419 * \param a The alpha value used to draw on the rendering target, usually
420 * ::SDL_ALPHA_OPAQUE (255).
421 *
422 * \return 0 on success, or -1 if there is no rendering context current.
423 */
424 extern DECLSPEC int SDL_SetRenderDrawColor(Uint8 r, Uint8 g, Uint8 b,
425 Uint8 a);
426
427 /**
428 * \brief Get the color used for drawing operations (Fill and Line).
429 *
430 * \param r A pointer to the red value used to draw on the rendering target.
431 * \param g A pointer to the green value used to draw on the rendering target.
432 * \param b A pointer to the blue value used to draw on the rendering target.
433 * \param a A pointer to the alpha value used to draw on the rendering target,
434 * usually ::SDL_ALPHA_OPAQUE (255).
435 *
436 * \return 0 on success, or -1 if there is no rendering context current.
437 */
438 extern DECLSPEC int SDL_GetRenderDrawColor(Uint8 * r, Uint8 * g, Uint8 * b,
439 Uint8 * a);
440
441 /**
442 * \brief Set the blend mode used for drawing operations (Fill and Line).
443 *
444 * \param blendMode ::SDL_BlendMode to use for blending.
445 *
446 * \return 0 on success, or -1 if there is no rendering context current.
447 *
448 * \note If the blend mode is not supported, the closest supported mode is
449 * chosen.
450 *
451 * \sa SDL_GetRenderDrawBlendMode()
452 */
453 extern DECLSPEC int SDLCALL SDL_SetRenderDrawBlendMode(SDL_BlendMode blendMode);
454
455 /**
456 * \brief Get the blend mode used for drawing operations.
457 *
458 * \param blendMode A pointer filled in with the current blend mode.
459 *
460 * \return 0 on success, or -1 if there is no rendering context current.
461 *
462 * \sa SDL_SetRenderDrawBlendMode()
463 */
464 extern DECLSPEC int SDLCALL SDL_GetRenderDrawBlendMode(SDL_BlendMode *blendMode);
465
466 /**
467 * \brief Clear the current rendering target with the drawing color
468 */
469 extern DECLSPEC int SDLCALL SDL_RenderClear(void);
470
471 /**
472 * \brief Draw a point on the current rendering target.
473 *
474 * \param x The x coordinate of the point.
475 * \param y The y coordinate of the point.
476 *
477 * \return 0 on success, or -1 if there is no rendering context current.
478 */
479 extern DECLSPEC int SDLCALL SDL_RenderDrawPoint(int x, int y);
480
481 /**
482 * \brief Draw multiple points on the current rendering target.
483 *
484 * \param points The points to draw
485 * \param count The number of points to draw
486 *
487 * \return 0 on success, or -1 if there is no rendering context current.
488 */
489 extern DECLSPEC int SDLCALL SDL_RenderDrawPoints(const SDL_Point * points,
490 int count);
491
492 /**
493 * \brief Draw a line on the current rendering target.
494 *
495 * \param x1 The x coordinate of the start point.
496 * \param y1 The y coordinate of the start point.
497 * \param x2 The x coordinate of the end point.
498 * \param y2 The y coordinate of the end point.
499 *
500 * \return 0 on success, or -1 if there is no rendering context current.
501 */
502 extern DECLSPEC int SDLCALL SDL_RenderDrawLine(int x1, int y1, int x2, int y2);
503
504 /**
505 * \brief Draw a series of connected lines on the current rendering target.
506 *
507 * \param points The points along the lines
508 * \param count The number of points, drawing count-1 lines
509 *
510 * \return 0 on success, or -1 if there is no rendering context current.
511 */
512 extern DECLSPEC int SDLCALL SDL_RenderDrawLines(const SDL_Point * points,
513 int count);
514
515 /**
516 * \brief Draw a rectangle on the current rendering target.
517 *
518 * \param rect A pointer to the destination rectangle, or NULL to outline the entire rendering target.
519 *
520 * \return 0 on success, or -1 if there is no rendering context current.
521 */
522 extern DECLSPEC int SDLCALL SDL_RenderDrawRect(const SDL_Rect * rect);
523
524 /**
525 * \brief Draw some number of rectangles on the current rendering target.
526 *
527 * \param rects A pointer to an array of destination rectangles.
528 * \param count The number of rectangles.
529 *
530 * \return 0 on success, or -1 if there is no rendering context current.
531 */
532 extern DECLSPEC int SDLCALL SDL_RenderDrawRects(const SDL_Rect ** rects, int count);
533
534 /**
535 * \brief Fill a rectangle on the current rendering target with the drawing color.
536 *
537 * \param rect A pointer to the destination rectangle, or NULL for the entire
538 * rendering target.
539 *
540 * \return 0 on success, or -1 if there is no rendering context current.
541 */
542 extern DECLSPEC int SDLCALL SDL_RenderFillRect(const SDL_Rect * rect);
543
544 /**
545 * \brief Fill some number of rectangles on the current rendering target with the drawing color.
546 *
547 * \param rects A pointer to an array of destination rectangles.
548 * \param count The number of rectangles.
549 *
550 * \return 0 on success, or -1 if there is no rendering context current.
551 */
552 extern DECLSPEC int SDLCALL SDL_RenderFillRects(const SDL_Rect ** rect, int count);
553
554 /**
555 * \brief Copy a portion of the texture to the current rendering target.
556 *
557 * \param texture The source texture.
558 * \param srcrect A pointer to the source rectangle, or NULL for the entire
559 * texture.
560 * \param dstrect A pointer to the destination rectangle, or NULL for the
561 * entire rendering target.
562 *
563 * \return 0 on success, or -1 if there is no rendering context current, or the
564 * driver doesn't support the requested operation.
565 */
566 extern DECLSPEC int SDLCALL SDL_RenderCopy(SDL_Texture * texture,
567 const SDL_Rect * srcrect,
568 const SDL_Rect * dstrect);
569
570 /**
571 * \brief Read pixels from the current rendering target.
572 *
573 * \param rect A pointer to the rectangle to read, or NULL for the entire
574 * render target.
575 * \param format The desired format of the pixel data, or 0 to use the format
576 * of the rendering target
577 * \param pixels A pointer to be filled in with the pixel data
578 * \param pitch The pitch of the pixels parameter.
579 *
580 * \return 0 on success, or -1 if pixel reading is not supported.
581 *
582 * \warning This is a very slow operation, and should not be used frequently.
583 */
584 extern DECLSPEC int SDLCALL SDL_RenderReadPixels(const SDL_Rect * rect,
585 Uint32 format,
586 void *pixels, int pitch);
587
588 /**
589 * \brief Write pixels to the current rendering target.
590 *
591 * \param rect A pointer to the rectangle to write, or NULL for the entire
592 * render target.
593 * \param format The format of the pixel data, or 0 to use the format
594 * of the rendering target
595 * \param pixels A pointer to the pixel data to write.
596 * \param pitch The pitch of the pixels parameter.
597 *
598 * \return 0 on success, or -1 if pixel writing is not supported.
599 *
600 * \warning This is a very slow operation, and should not be used frequently.
601 */
602 extern DECLSPEC int SDLCALL SDL_RenderWritePixels(const SDL_Rect * rect,
603 Uint32 format,
604 const void *pixels,
605 int pitch);
606
607 /**
608 * \brief Update the screen with rendering performed.
609 */
610 extern DECLSPEC void SDLCALL SDL_RenderPresent(void);
611
612 /**
613 * \brief Destroy the specified texture.
614 *
615 * \sa SDL_CreateTexture()
616 * \sa SDL_CreateTextureFromSurface()
617 */
618 extern DECLSPEC void SDLCALL SDL_DestroyTexture(SDL_Texture * texture);
619
620 /**
621 * \brief Destroy the rendering context for a window and free associated
622 * textures.
623 *
624 * \sa SDL_CreateRenderer()
625 */
626 extern DECLSPEC void SDLCALL SDL_DestroyRenderer(SDL_Window * window);
627
628
629 /* Ends C function definitions when using C++ */
630 #ifdef __cplusplus
631 /* *INDENT-OFF* */
632 }
633 /* *INDENT-ON* */
634 #endif
635 #include "close_code.h"
636
637 #endif /* _SDL_render_h */
638
639 /* vi: set ts=4 sw=4 expandtab: */