1 #ifndef GFX_H 2 #define GFX_H 3 4 /* 5 Copyright (c) 2009-2010 Tero Lindeman (kometbomb) 6 7 Permission is hereby granted, free of charge, to any person 8 obtaining a copy of this software and associated documentation 9 files (the "Software"), to deal in the Software without 10 restriction, including without limitation the rights to use, 11 copy, modify, merge, publish, distribute, sublicense, and/or sell 12 copies of the Software, and to permit persons to whom the 13 Software is furnished to do so, subject to the following 14 conditions: 15 16 The above copyright notice and this permission notice shall be 17 included in all copies or substantial portions of the Software. 18 19 THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, 20 EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES 21 OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND 22 NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT 23 HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, 24 WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING 25 FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR 26 OTHER DEALINGS IN THE SOFTWARE. 27 */ 28 29 30 #include "SDL.h" 31 #include "SDL_rwops.h" 32 #include "tiledescriptor.h" 33 #include "gfxsurf.h" 34 #include <stdbool.h> 35 36 #ifdef USESDL_GPU 37 #include "SDL_gpu.h" 38 #endif 39 40 enum 41 { 42 GFX_KEYED = 1, 43 GFX_ALPHA = 2, 44 GFX_TRANS_HALF = 4, 45 GFX_COL_MASK = 8 46 }; 47 48 enum 49 { 50 GFX_DOMAIN_DISABLE_RENDER_TO_TEXTURE = 1 51 }; 52 53 typedef enum 54 { 55 GFX_SCALE_NEAREST, 56 GFX_SCALE_SCANLINES 57 } GfxScaleType; 58 59 #ifdef WIN32 60 typedef Uint64 FramerateTimer; 61 #else 62 typedef Uint32 FramerateTimer; 63 #endif 64 65 struct GfxDomain_t 66 { 67 #ifdef USESDL_GPU 68 GPU_Target *screen; 69 SDL_Rect clip; 70 #else 71 SDL_Window *window; 72 SDL_Renderer *renderer; 73 SDL_Texture *scale_texture, *scanlines_texture; 74 bool render_to_texture; 75 #endif 76 int screen_w, screen_h; 77 int window_w, window_h, window_min_w, window_min_h; 78 int scale, fullscreen, fps; 79 GfxScaleType scale_type; 80 FramerateTimer start_time, dt, clock_resolution, accumulator; 81 int flags; 82 Uint8 texmod_r, texmod_g, texmod_b; 83 #ifdef DEBUG 84 int calls_per_frame; 85 #endif 86 }; 87 88 typedef struct GfxDomain_t GfxDomain; 89 90 GfxSurface* gfx_load_surface(GfxDomain *domain, const char* filename, const int flags); 91 GfxSurface* gfx_load_surface_RW(GfxDomain *domain, SDL_RWops *rw, const int flags); 92 int * gfx_build_collision_mask(SDL_Surface *s); 93 GfxSurface * gfx_create_surface(GfxDomain *domain, int w, int h); 94 void gfx_free_surface(GfxSurface *surface); 95 void gfx_blit_2x(SDL_Surface *dest, SDL_Surface *src); 96 void gfx_blit_2x_resample(SDL_Surface *dest, SDL_Surface *src); 97 void gfx_blit_3x(SDL_Surface *dest, SDL_Surface *src); 98 void gfx_blit_3x_resample(SDL_Surface *dest, SDL_Surface *src); 99 void gfx_blit_4x(SDL_Surface *dest, SDL_Surface *src); 100 void gfx_raster(SDL_Surface *dest, const SDL_Rect *rect, const Uint32 *colors, int len); 101 void gfx_generate_raster(Uint32 *dest, const Uint32 from, const Uint32 to, int len); 102 TileDescriptor *gfx_build_tiledescriptor(GfxSurface *tiles, const int cellwidth, const int cellheight, int *out_n_tiles); 103 void gfx_line(GfxDomain *dest, int x0, int y0, int x1, int y1, Uint32 color); 104 void gfx_circle_inverted(SDL_Surface *dest, const int xc, const int yc, const int r, const Uint32 color); 105 void gfx_circle(SDL_Surface *dest, const int xc, const int yc, const int r, const Uint32 color); 106 void gfx_clear(GfxDomain *domain, Uint32 color); 107 void gfx_blit(GfxSurface *src, SDL_Rect *srcrect, GfxDomain *domain, SDL_Rect *dest); 108 void gfx_rect(GfxDomain *domain, SDL_Rect *dest, Uint32 rgb); 109 void gfx_surface_set_color(GfxSurface *surf, Uint32 color); 110 void gfx_update_texture(GfxDomain *domain, GfxSurface *surface); 111 void gfx_convert_mouse_coordinates(GfxDomain *domain, int *x, int *y); 112 113 GfxDomain * gfx_create_domain(const char *title, Uint32 window_flags, int window_w, int window_h, int scale); 114 void gfx_domain_update(GfxDomain *domain, bool resize_window); 115 void gfx_domain_flip(GfxDomain *domain); 116 void gfx_domain_free(GfxDomain *domain); 117 int gfx_domain_is_next_frame(GfxDomain *domain); 118 119 void gfx_domain_set_clip(GfxDomain *domain, const SDL_Rect *rect); 120 void gfx_domain_get_clip(GfxDomain *domain, SDL_Rect *rect); 121 122 // 123 void my_BlitSurface(GfxSurface *src, SDL_Rect *src_rect, GfxDomain *dest, SDL_Rect *dest_rect); 124 125 #endif 126