comparison include/SDL_video.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 b52793134276
children be02be2ea897
comparison
equal deleted inserted replaced
5147:a1345acf7b3d 5148:2f44e6969a59
30 #define _SDL_video_h 30 #define _SDL_video_h
31 31
32 #include "SDL_stdinc.h" 32 #include "SDL_stdinc.h"
33 #include "SDL_pixels.h" 33 #include "SDL_pixels.h"
34 #include "SDL_rect.h" 34 #include "SDL_rect.h"
35 #include "SDL_blendmode.h"
36 #include "SDL_surface.h" 35 #include "SDL_surface.h"
37 36
38 #include "begin_code.h" 37 #include "begin_code.h"
39 /* Set up for C function definitions, even when using C++ */ 38 /* Set up for C function definitions, even when using C++ */
40 #ifdef __cplusplus 39 #ifdef __cplusplus
145 SDL_WINDOWEVENT_CLOSE /**< The window manager requests that the 144 SDL_WINDOWEVENT_CLOSE /**< The window manager requests that the
146 window be closed */ 145 window be closed */
147 } SDL_WindowEventID; 146 } SDL_WindowEventID;
148 147
149 /** 148 /**
150 * \brief Flags used when creating a rendering context
151 */
152 typedef enum
153 {
154 SDL_RENDERER_ACCELERATED = 0x00000001, /**< The renderer uses hardware
155 acceleration */
156 SDL_RENDERER_PRESENTVSYNC = 0x00000002 /**< Present is synchronized
157 with the refresh rate */
158 } SDL_RendererFlags;
159
160 /**
161 * \brief Information on the capabilities of a render driver or context.
162 */
163 typedef struct SDL_RendererInfo
164 {
165 const char *name; /**< The name of the renderer */
166 Uint32 flags; /**< Supported ::SDL_RendererFlags */
167 Uint32 num_texture_formats; /**< The number of available texture formats */
168 Uint32 texture_formats[50]; /**< The available texture formats */
169 int max_texture_width; /**< The maximimum texture width */
170 int max_texture_height; /**< The maximimum texture height */
171 } SDL_RendererInfo;
172
173 /**
174 * \brief The access pattern allowed for a texture.
175 */
176 typedef enum
177 {
178 SDL_TEXTUREACCESS_STATIC, /**< Changes rarely, not lockable */
179 SDL_TEXTUREACCESS_STREAMING /**< Changes frequently, lockable */
180 } SDL_TextureAccess;
181
182 /**
183 * \brief The texture channel modulation used in SDL_RenderCopy().
184 */
185 typedef enum
186 {
187 SDL_TEXTUREMODULATE_NONE = 0x00000000, /**< No modulation */
188 SDL_TEXTUREMODULATE_COLOR = 0x00000001, /**< srcC = srcC * color */
189 SDL_TEXTUREMODULATE_ALPHA = 0x00000002 /**< srcA = srcA * alpha */
190 } SDL_TextureModulate;
191
192 /**
193 * \brief An efficient driver-specific representation of pixel data
194 */
195 struct SDL_Texture;
196 typedef struct SDL_Texture SDL_Texture;
197
198 /**
199 * \brief An opaque handle to an OpenGL context. 149 * \brief An opaque handle to an OpenGL context.
200 */ 150 */
201 typedef void *SDL_GLContext; 151 typedef void *SDL_GLContext;
202 152
203 /** 153 /**
688 /** 638 /**
689 * \brief Destroy a window. 639 * \brief Destroy a window.
690 */ 640 */
691 extern DECLSPEC void SDLCALL SDL_DestroyWindow(SDL_Window * window); 641 extern DECLSPEC void SDLCALL SDL_DestroyWindow(SDL_Window * window);
692 642
693 /**
694 * \brief Get the number of 2D rendering drivers available for the current
695 * display.
696 *
697 * A render driver is a set of code that handles rendering and texture
698 * management on a particular display. Normally there is only one, but
699 * some drivers may have several available with different capabilities.
700 *
701 * \sa SDL_GetRenderDriverInfo()
702 * \sa SDL_CreateRenderer()
703 */
704 extern DECLSPEC int SDLCALL SDL_GetNumRenderDrivers(void);
705
706 /**
707 * \brief Get information about a specific 2D rendering driver for the current
708 * display.
709 *
710 * \param index The index of the driver to query information about.
711 * \param info A pointer to an SDL_RendererInfo struct to be filled with
712 * information on the rendering driver.
713 *
714 * \return 0 on success, -1 if the index was out of range.
715 *
716 * \sa SDL_CreateRenderer()
717 */
718 extern DECLSPEC int SDLCALL SDL_GetRenderDriverInfo(int index,
719 SDL_RendererInfo * info);
720
721 /**
722 * \brief Create and make active a 2D rendering context for a window.
723 *
724 * \param window The window where rendering is displayed.
725 * \param index The index of the rendering driver to initialize, or -1 to
726 * initialize the first one supporting the requested flags.
727 * \param flags ::SDL_RendererFlags.
728 *
729 * \return 0 on success, -1 if there was an error creating the renderer.
730 *
731 * \sa SDL_SelectRenderer()
732 * \sa SDL_GetRendererInfo()
733 * \sa SDL_DestroyRenderer()
734 */
735 extern DECLSPEC int SDLCALL SDL_CreateRenderer(SDL_Window * window,
736 int index, Uint32 flags);
737
738 /**
739 * \brief Select the rendering context for a particular window.
740 *
741 * \return 0 on success, -1 if the selected window doesn't have a
742 * rendering context.
743 */
744 extern DECLSPEC int SDLCALL SDL_SelectRenderer(SDL_Window * window);
745
746 /**
747 * \brief Get information about the current rendering context.
748 */
749 extern DECLSPEC int SDLCALL SDL_GetRendererInfo(SDL_RendererInfo * info);
750
751 /**
752 * \brief Create a texture for the current rendering context.
753 *
754 * \param format The format of the texture.
755 * \param access One of the enumerated values in ::SDL_TextureAccess.
756 * \param w The width of the texture in pixels.
757 * \param h The height of the texture in pixels.
758 *
759 * \return The created texture is returned, or 0 if no rendering context was
760 * active, the format was unsupported, or the width or height were out
761 * of range.
762 *
763 * \sa SDL_QueryTexture()
764 * \sa SDL_DestroyTexture()
765 */
766 extern DECLSPEC SDL_Texture * SDLCALL SDL_CreateTexture(Uint32 format,
767 int access, int w,
768 int h);
769
770 /**
771 * \brief Create a texture from an existing surface.
772 *
773 * \param format The format of the texture, or 0 to pick an appropriate format.
774 * \param surface The surface containing pixel data used to fill the texture.
775 *
776 * \return The created texture is returned, or 0 if no rendering context was
777 * active, the format was unsupported, or the surface width or height
778 * were out of range.
779 *
780 * \note The surface is not modified or freed by this function.
781 *
782 * \sa SDL_QueryTexture()
783 * \sa SDL_DestroyTexture()
784 */
785 extern DECLSPEC SDL_Texture * SDLCALL SDL_CreateTextureFromSurface(Uint32
786 format,
787 SDL_Surface
788 * surface);
789
790 /**
791 * \brief Query the attributes of a texture
792 *
793 * \param texture A texture to be queried.
794 * \param format A pointer filled in with the raw format of the texture. The
795 * actual format may differ, but pixel transfers will use this
796 * format.
797 * \param access A pointer filled in with the actual access to the texture.
798 * \param w A pointer filled in with the width of the texture in pixels.
799 * \param h A pointer filled in with the height of the texture in pixels.
800 *
801 * \return 0 on success, or -1 if the texture is not valid.
802 */
803 extern DECLSPEC int SDLCALL SDL_QueryTexture(SDL_Texture * texture,
804 Uint32 * format, int *access,
805 int *w, int *h);
806
807 /**
808 * \brief Query the pixels of a texture, if the texture does not need to be
809 * locked for pixel access.
810 *
811 * \param texture A texture to be queried, which was created with
812 * ::SDL_TEXTUREACCESS_STREAMING.
813 * \param pixels A pointer filled with a pointer to the pixels for the
814 * texture.
815 * \param pitch A pointer filled in with the pitch of the pixel data.
816 *
817 * \return 0 on success, or -1 if the texture is not valid, or must be locked
818 * for pixel access.
819 */
820 extern DECLSPEC int SDLCALL SDL_QueryTexturePixels(SDL_Texture * texture,
821 void **pixels, int *pitch);
822
823 /**
824 * \brief Set the color palette of an indexed texture.
825 *
826 * \param texture The texture to update.
827 * \param colors The array of RGB color data.
828 * \param firstcolor The first index to update.
829 * \param ncolors The number of palette entries to fill with the color data.
830 *
831 * \return 0 on success, or -1 if the texture is not valid or not an indexed
832 * texture.
833 */
834 extern DECLSPEC int SDLCALL SDL_SetTexturePalette(SDL_Texture * texture,
835 const SDL_Color * colors,
836 int firstcolor,
837 int ncolors);
838
839 /**
840 * \brief Get the color palette from an indexed texture if it has one.
841 *
842 * \param texture The texture to update.
843 * \param colors The array to fill with RGB color data.
844 * \param firstcolor The first index to retrieve.
845 * \param ncolors The number of palette entries to retrieve.
846 *
847 * \return 0 on success, or -1 if the texture is not valid or not an indexed
848 * texture.
849 */
850 extern DECLSPEC int SDLCALL SDL_GetTexturePalette(SDL_Texture * texture,
851 SDL_Color * colors,
852 int firstcolor,
853 int ncolors);
854
855 /**
856 * \brief Set an additional color value used in render copy operations.
857 *
858 * \param texture The texture to update.
859 * \param r The red color value multiplied into copy operations.
860 * \param g The green color value multiplied into copy operations.
861 * \param b The blue color value multiplied into copy operations.
862 *
863 * \return 0 on success, or -1 if the texture is not valid or color modulation
864 * is not supported.
865 *
866 * \sa SDL_GetTextureColorMod()
867 */
868 extern DECLSPEC int SDLCALL SDL_SetTextureColorMod(SDL_Texture * texture,
869 Uint8 r, Uint8 g, Uint8 b);
870
871
872 /**
873 * \brief Get the additional color value used in render copy operations.
874 *
875 * \param texture The texture to query.
876 * \param r A pointer filled in with the current red color value.
877 * \param g A pointer filled in with the current green color value.
878 * \param b A pointer filled in with the current blue color value.
879 *
880 * \return 0 on success, or -1 if the texture is not valid.
881 *
882 * \sa SDL_SetTextureColorMod()
883 */
884 extern DECLSPEC int SDLCALL SDL_GetTextureColorMod(SDL_Texture * texture,
885 Uint8 * r, Uint8 * g,
886 Uint8 * b);
887
888 /**
889 * \brief Set an additional alpha value used in render copy operations.
890 *
891 * \param texture The texture to update.
892 * \param alpha The alpha value multiplied into copy operations.
893 *
894 * \return 0 on success, or -1 if the texture is not valid or alpha modulation
895 * is not supported.
896 *
897 * \sa SDL_GetTextureAlphaMod()
898 */
899 extern DECLSPEC int SDLCALL SDL_SetTextureAlphaMod(SDL_Texture * texture,
900 Uint8 alpha);
901
902 /**
903 * \brief Get the additional alpha value used in render copy operations.
904 *
905 * \param texture The texture to query.
906 * \param alpha A pointer filled in with the current alpha value.
907 *
908 * \return 0 on success, or -1 if the texture is not valid.
909 *
910 * \sa SDL_SetTextureAlphaMod()
911 */
912 extern DECLSPEC int SDLCALL SDL_GetTextureAlphaMod(SDL_Texture * texture,
913 Uint8 * alpha);
914
915 /**
916 * \brief Set the blend mode used for texture copy operations.
917 *
918 * \param texture The texture to update.
919 * \param blendMode ::SDL_BlendMode to use for texture blending.
920 *
921 * \return 0 on success, or -1 if the texture is not valid or the blend mode is
922 * not supported.
923 *
924 * \note If the blend mode is not supported, the closest supported mode is
925 * chosen.
926 *
927 * \sa SDL_GetTextureBlendMode()
928 */
929 extern DECLSPEC int SDLCALL SDL_SetTextureBlendMode(SDL_Texture * texture,
930 SDL_BlendMode blendMode);
931
932 /**
933 * \brief Get the blend mode used for texture copy operations.
934 *
935 * \param texture The texture to query.
936 * \param blendMode A pointer filled in with the current blend mode.
937 *
938 * \return 0 on success, or -1 if the texture is not valid.
939 *
940 * \sa SDL_SetTextureBlendMode()
941 */
942 extern DECLSPEC int SDLCALL SDL_GetTextureBlendMode(SDL_Texture * texture,
943 SDL_BlendMode *blendMode);
944
945 /**
946 * \brief Update the given texture rectangle with new pixel data.
947 *
948 * \param texture The texture to update
949 * \param rect A pointer to the rectangle of pixels to update, or NULL to
950 * update the entire texture.
951 * \param pixels The raw pixel data.
952 * \param pitch The number of bytes between rows of pixel data.
953 *
954 * \return 0 on success, or -1 if the texture is not valid.
955 *
956 * \note This is a fairly slow function.
957 */
958 extern DECLSPEC int SDLCALL SDL_UpdateTexture(SDL_Texture * texture,
959 const SDL_Rect * rect,
960 const void *pixels, int pitch);
961
962 /**
963 * \brief Lock a portion of the texture for pixel access.
964 *
965 * \param texture The texture to lock for access, which was created with
966 * ::SDL_TEXTUREACCESS_STREAMING.
967 * \param rect A pointer to the rectangle to lock for access. If the rect
968 * is NULL, the entire texture will be locked.
969 * \param markDirty If this is nonzero, the locked area will be marked dirty
970 * when the texture is unlocked.
971 * \param pixels This is filled in with a pointer to the locked pixels,
972 * appropriately offset by the locked area.
973 * \param pitch This is filled in with the pitch of the locked pixels.
974 *
975 * \return 0 on success, or -1 if the texture is not valid or was created with
976 * ::SDL_TEXTUREACCESS_STATIC.
977 *
978 * \sa SDL_DirtyTexture()
979 * \sa SDL_UnlockTexture()
980 */
981 extern DECLSPEC int SDLCALL SDL_LockTexture(SDL_Texture * texture,
982 const SDL_Rect * rect,
983 int markDirty, void **pixels,
984 int *pitch);
985
986 /**
987 * \brief Unlock a texture, uploading the changes to video memory, if needed.
988 *
989 * \sa SDL_LockTexture()
990 * \sa SDL_DirtyTexture()
991 */
992 extern DECLSPEC void SDLCALL SDL_UnlockTexture(SDL_Texture * texture);
993
994 /**
995 * \brief Mark the specified rectangles of the texture as dirty.
996 *
997 * \param texture The texture to mark dirty, which was created with
998 * ::SDL_TEXTUREACCESS_STREAMING.
999 * \param numrects The number of rectangles pointed to by rects.
1000 * \param rects The pointer to an array of dirty rectangles.
1001 *
1002 * \sa SDL_LockTexture()
1003 * \sa SDL_UnlockTexture()
1004 */
1005 extern DECLSPEC void SDLCALL SDL_DirtyTexture(SDL_Texture * texture,
1006 int numrects,
1007 const SDL_Rect * rects);
1008
1009 /**
1010 * \brief Set the color used for drawing operations (Fill and Line).
1011 *
1012 * \param r The red value used to draw on the rendering target.
1013 * \param g The green value used to draw on the rendering target.
1014 * \param b The blue value used to draw on the rendering target.
1015 * \param a The alpha value used to draw on the rendering target, usually
1016 * ::SDL_ALPHA_OPAQUE (255).
1017 *
1018 * \return 0 on success, or -1 if there is no rendering context current.
1019 */
1020 extern DECLSPEC int SDL_SetRenderDrawColor(Uint8 r, Uint8 g, Uint8 b,
1021 Uint8 a);
1022
1023 /**
1024 * \brief Get the color used for drawing operations (Fill and Line).
1025 *
1026 * \param r A pointer to the red value used to draw on the rendering target.
1027 * \param g A pointer to the green value used to draw on the rendering target.
1028 * \param b A pointer to the blue value used to draw on the rendering target.
1029 * \param a A pointer to the alpha value used to draw on the rendering target,
1030 * usually ::SDL_ALPHA_OPAQUE (255).
1031 *
1032 * \return 0 on success, or -1 if there is no rendering context current.
1033 */
1034 extern DECLSPEC int SDL_GetRenderDrawColor(Uint8 * r, Uint8 * g, Uint8 * b,
1035 Uint8 * a);
1036
1037 /**
1038 * \brief Set the blend mode used for drawing operations (Fill and Line).
1039 *
1040 * \param blendMode ::SDL_BlendMode to use for blending.
1041 *
1042 * \return 0 on success, or -1 if there is no rendering context current.
1043 *
1044 * \note If the blend mode is not supported, the closest supported mode is
1045 * chosen.
1046 *
1047 * \sa SDL_GetRenderDrawBlendMode()
1048 */
1049 extern DECLSPEC int SDLCALL SDL_SetRenderDrawBlendMode(SDL_BlendMode blendMode);
1050
1051 /**
1052 * \brief Get the blend mode used for drawing operations.
1053 *
1054 * \param blendMode A pointer filled in with the current blend mode.
1055 *
1056 * \return 0 on success, or -1 if there is no rendering context current.
1057 *
1058 * \sa SDL_SetRenderDrawBlendMode()
1059 */
1060 extern DECLSPEC int SDLCALL SDL_GetRenderDrawBlendMode(SDL_BlendMode *blendMode);
1061
1062 /**
1063 * \brief Clear the current rendering target with the drawing color
1064 */
1065 extern DECLSPEC int SDLCALL SDL_RenderClear(void);
1066
1067 /**
1068 * \brief Draw a point on the current rendering target.
1069 *
1070 * \param x The x coordinate of the point.
1071 * \param y The y coordinate of the point.
1072 *
1073 * \return 0 on success, or -1 if there is no rendering context current.
1074 */
1075 extern DECLSPEC int SDLCALL SDL_RenderDrawPoint(int x, int y);
1076
1077 /**
1078 * \brief Draw multiple points on the current rendering target.
1079 *
1080 * \param points The points to draw
1081 * \param count The number of points to draw
1082 *
1083 * \return 0 on success, or -1 if there is no rendering context current.
1084 */
1085 extern DECLSPEC int SDLCALL SDL_RenderDrawPoints(const SDL_Point * points,
1086 int count);
1087
1088 /**
1089 * \brief Draw a line on the current rendering target.
1090 *
1091 * \param x1 The x coordinate of the start point.
1092 * \param y1 The y coordinate of the start point.
1093 * \param x2 The x coordinate of the end point.
1094 * \param y2 The y coordinate of the end point.
1095 *
1096 * \return 0 on success, or -1 if there is no rendering context current.
1097 */
1098 extern DECLSPEC int SDLCALL SDL_RenderDrawLine(int x1, int y1, int x2, int y2);
1099
1100 /**
1101 * \brief Draw a series of connected lines on the current rendering target.
1102 *
1103 * \param points The points along the lines
1104 * \param count The number of points, drawing count-1 lines
1105 *
1106 * \return 0 on success, or -1 if there is no rendering context current.
1107 */
1108 extern DECLSPEC int SDLCALL SDL_RenderDrawLines(const SDL_Point * points,
1109 int count);
1110
1111 /**
1112 * \brief Draw a rectangle on the current rendering target.
1113 *
1114 * \param rect A pointer to the destination rectangle, or NULL to outline the entire rendering target.
1115 *
1116 * \return 0 on success, or -1 if there is no rendering context current.
1117 */
1118 extern DECLSPEC int SDLCALL SDL_RenderDrawRect(const SDL_Rect * rect);
1119
1120 /**
1121 * \brief Draw some number of rectangles on the current rendering target.
1122 *
1123 * \param rects A pointer to an array of destination rectangles.
1124 * \param count The number of rectangles.
1125 *
1126 * \return 0 on success, or -1 if there is no rendering context current.
1127 */
1128 extern DECLSPEC int SDLCALL SDL_RenderDrawRects(const SDL_Rect ** rects, int count);
1129
1130 /**
1131 * \brief Fill a rectangle on the current rendering target with the drawing color.
1132 *
1133 * \param rect A pointer to the destination rectangle, or NULL for the entire
1134 * rendering target.
1135 *
1136 * \return 0 on success, or -1 if there is no rendering context current.
1137 */
1138 extern DECLSPEC int SDLCALL SDL_RenderFillRect(const SDL_Rect * rect);
1139
1140 /**
1141 * \brief Fill some number of rectangles on the current rendering target with the drawing color.
1142 *
1143 * \param rects A pointer to an array of destination rectangles.
1144 * \param count The number of rectangles.
1145 *
1146 * \return 0 on success, or -1 if there is no rendering context current.
1147 */
1148 extern DECLSPEC int SDLCALL SDL_RenderFillRects(const SDL_Rect ** rect, int count);
1149
1150 /**
1151 * \brief Copy a portion of the texture to the current rendering target.
1152 *
1153 * \param texture The source texture.
1154 * \param srcrect A pointer to the source rectangle, or NULL for the entire
1155 * texture.
1156 * \param dstrect A pointer to the destination rectangle, or NULL for the
1157 * entire rendering target.
1158 *
1159 * \return 0 on success, or -1 if there is no rendering context current, or the
1160 * driver doesn't support the requested operation.
1161 */
1162 extern DECLSPEC int SDLCALL SDL_RenderCopy(SDL_Texture * texture,
1163 const SDL_Rect * srcrect,
1164 const SDL_Rect * dstrect);
1165
1166 /**
1167 * \brief Read pixels from the current rendering target.
1168 *
1169 * \param rect A pointer to the rectangle to read, or NULL for the entire
1170 * render target.
1171 * \param format The desired format of the pixel data, or 0 to use the format
1172 * of the rendering target
1173 * \param pixels A pointer to be filled in with the pixel data
1174 * \param pitch The pitch of the pixels parameter.
1175 *
1176 * \return 0 on success, or -1 if pixel reading is not supported.
1177 *
1178 * \warning This is a very slow operation, and should not be used frequently.
1179 */
1180 extern DECLSPEC int SDLCALL SDL_RenderReadPixels(const SDL_Rect * rect,
1181 Uint32 format,
1182 void *pixels, int pitch);
1183
1184 /**
1185 * \brief Write pixels to the current rendering target.
1186 *
1187 * \param rect A pointer to the rectangle to write, or NULL for the entire
1188 * render target.
1189 * \param format The format of the pixel data, or 0 to use the format
1190 * of the rendering target
1191 * \param pixels A pointer to the pixel data to write.
1192 * \param pitch The pitch of the pixels parameter.
1193 *
1194 * \return 0 on success, or -1 if pixel writing is not supported.
1195 *
1196 * \warning This is a very slow operation, and should not be used frequently.
1197 */
1198 extern DECLSPEC int SDLCALL SDL_RenderWritePixels(const SDL_Rect * rect,
1199 Uint32 format,
1200 const void *pixels,
1201 int pitch);
1202
1203 /**
1204 * \brief Update the screen with rendering performed.
1205 */
1206 extern DECLSPEC void SDLCALL SDL_RenderPresent(void);
1207
1208 /**
1209 * \brief Destroy the specified texture.
1210 *
1211 * \sa SDL_CreateTexture()
1212 * \sa SDL_CreateTextureFromSurface()
1213 */
1214 extern DECLSPEC void SDLCALL SDL_DestroyTexture(SDL_Texture * texture);
1215
1216 /**
1217 * \brief Destroy the rendering context for a window and free associated
1218 * textures.
1219 *
1220 * \sa SDL_CreateRenderer()
1221 */
1222 extern DECLSPEC void SDLCALL SDL_DestroyRenderer(SDL_Window * window);
1223 643
1224 /** 644 /**
1225 * \brief Returns whether the screensaver is currently enabled (default on). 645 * \brief Returns whether the screensaver is currently enabled (default on).
1226 * 646 *
1227 * \sa SDL_EnableScreenSaver() 647 * \sa SDL_EnableScreenSaver()