src/render/SDL_sysrender.h
author Sam Lantinga <slouken@libsdl.org>
Fri, 14 Jun 2019 13:56:42 -0700
changeset 12860 0f52dd40abe5
parent 12503 806492103856
child 13019 ecad0a0684ad
permissions -rw-r--r--
Worked around "Undefined symbol: ___isPlatformVersionAtLeast()" link error on Xcode 11 beta
slouken@5154
     1
/*
slouken@5535
     2
  Simple DirectMedia Layer
slouken@12503
     3
  Copyright (C) 1997-2019 Sam Lantinga <slouken@libsdl.org>
slouken@5154
     4
slouken@5535
     5
  This software is provided 'as-is', without any express or implied
slouken@5535
     6
  warranty.  In no event will the authors be held liable for any damages
slouken@5535
     7
  arising from the use of this software.
slouken@5154
     8
slouken@5535
     9
  Permission is granted to anyone to use this software for any purpose,
slouken@5535
    10
  including commercial applications, and to alter it and redistribute it
slouken@5535
    11
  freely, subject to the following restrictions:
slouken@5154
    12
slouken@5535
    13
  1. The origin of this software must not be misrepresented; you must not
slouken@5535
    14
     claim that you wrote the original software. If you use this software
slouken@5535
    15
     in a product, an acknowledgment in the product documentation would be
slouken@5535
    16
     appreciated but is not required.
slouken@5535
    17
  2. Altered source versions must be plainly marked as such, and must not be
slouken@5535
    18
     misrepresented as being the original software.
slouken@5535
    19
  3. This notice may not be removed or altered from any source distribution.
slouken@5154
    20
*/
icculus@8093
    21
#include "../SDL_internal.h"
slouken@5154
    22
slouken@10638
    23
#ifndef SDL_sysrender_h_
slouken@10638
    24
#define SDL_sysrender_h_
slouken@5154
    25
slouken@5154
    26
#include "SDL_render.h"
slouken@5154
    27
#include "SDL_events.h"
slouken@12021
    28
#include "SDL_mutex.h"
slouken@5156
    29
#include "SDL_yuv_sw_c.h"
slouken@5154
    30
slouken@5154
    31
/* The SDL 2D rendering system */
slouken@5154
    32
slouken@5154
    33
typedef struct SDL_RenderDriver SDL_RenderDriver;
slouken@5154
    34
slouken@11958
    35
typedef enum
slouken@11958
    36
{
slouken@11958
    37
    SDL_ScaleModeNearest,
slouken@11958
    38
    SDL_ScaleModeLinear,
slouken@11958
    39
    SDL_ScaleModeBest
slouken@11958
    40
} SDL_ScaleMode;
slouken@11958
    41
slouken@5154
    42
/* Define the SDL texture structure */
slouken@5154
    43
struct SDL_Texture
slouken@5154
    44
{
slouken@5154
    45
    const void *magic;
slouken@5154
    46
    Uint32 format;              /**< The pixel format of the texture */
slouken@5154
    47
    int access;                 /**< SDL_TextureAccess */
slouken@5154
    48
    int w;                      /**< The width of the texture */
slouken@5154
    49
    int h;                      /**< The height of the texture */
slouken@5154
    50
    int modMode;                /**< The texture modulation mode */
slouken@5154
    51
    SDL_BlendMode blendMode;    /**< The texture blend mode */
slouken@11958
    52
    SDL_ScaleMode scaleMode;    /**< The texture scale mode */
slouken@5154
    53
    Uint8 r, g, b, a;           /**< Texture modulation values */
slouken@5154
    54
slouken@5154
    55
    SDL_Renderer *renderer;
slouken@5154
    56
slouken@5156
    57
    /* Support for formats not supported directly by the renderer */
slouken@5156
    58
    SDL_Texture *native;
slouken@5156
    59
    SDL_SW_YUVTexture *yuv;
slouken@5156
    60
    void *pixels;
slouken@5156
    61
    int pitch;
slouken@5156
    62
    SDL_Rect locked_rect;
slouken@5156
    63
icculus@12211
    64
    Uint32 last_command_generation; /* last command queue generation this texture was in. */
icculus@12211
    65
slouken@5154
    66
    void *driverdata;           /**< Driver specific texture representation */
slouken@5154
    67
slouken@5154
    68
    SDL_Texture *prev;
slouken@5154
    69
    SDL_Texture *next;
slouken@5154
    70
};
slouken@5154
    71
icculus@12211
    72
typedef enum
icculus@12211
    73
{
icculus@12211
    74
    SDL_RENDERCMD_NO_OP,
icculus@12211
    75
    SDL_RENDERCMD_SETVIEWPORT,
icculus@12211
    76
    SDL_RENDERCMD_SETCLIPRECT,
icculus@12214
    77
    SDL_RENDERCMD_SETDRAWCOLOR,
icculus@12211
    78
    SDL_RENDERCMD_CLEAR,
icculus@12211
    79
    SDL_RENDERCMD_DRAW_POINTS,
icculus@12211
    80
    SDL_RENDERCMD_DRAW_LINES,
icculus@12211
    81
    SDL_RENDERCMD_FILL_RECTS,
icculus@12211
    82
    SDL_RENDERCMD_COPY,
icculus@12211
    83
    SDL_RENDERCMD_COPY_EX
icculus@12211
    84
} SDL_RenderCommandType;
icculus@12211
    85
icculus@12211
    86
typedef struct SDL_RenderCommand
icculus@12211
    87
{
icculus@12211
    88
    SDL_RenderCommandType command;
icculus@12211
    89
    union {
icculus@12214
    90
        struct {
icculus@12214
    91
            size_t first;
icculus@12214
    92
            SDL_Rect rect;
icculus@12214
    93
        } viewport;
icculus@12211
    94
        struct {
icculus@12211
    95
            SDL_bool enabled;
icculus@12211
    96
            SDL_Rect rect;
icculus@12211
    97
        } cliprect;
icculus@12211
    98
        struct {
icculus@12211
    99
            size_t first;
icculus@12211
   100
            size_t count;
icculus@12211
   101
            Uint8 r, g, b, a;
icculus@12211
   102
            SDL_BlendMode blend;
icculus@12211
   103
            SDL_Texture *texture;
icculus@12211
   104
        } draw;
icculus@12211
   105
        struct {
icculus@12214
   106
            size_t first;
icculus@12211
   107
            Uint8 r, g, b, a;
icculus@12211
   108
        } color;
icculus@12211
   109
    } data;
icculus@12211
   110
    struct SDL_RenderCommand *next;
icculus@12211
   111
} SDL_RenderCommand;
icculus@12211
   112
icculus@12214
   113
typedef struct SDL_AllocVertGap
icculus@12214
   114
{
icculus@12214
   115
    size_t offset;
icculus@12214
   116
    size_t len;
icculus@12214
   117
    struct SDL_AllocVertGap *next;
icculus@12214
   118
} SDL_AllocVertGap;
icculus@12214
   119
icculus@12211
   120
slouken@5154
   121
/* Define the SDL renderer structure */
slouken@5154
   122
struct SDL_Renderer
slouken@5154
   123
{
slouken@5154
   124
    const void *magic;
slouken@5154
   125
slouken@5154
   126
    void (*WindowEvent) (SDL_Renderer * renderer, const SDL_WindowEvent *event);
slouken@7239
   127
    int (*GetOutputSize) (SDL_Renderer * renderer, int *w, int *h);
slouken@11282
   128
    SDL_bool (*SupportsBlendMode)(SDL_Renderer * renderer, SDL_BlendMode blendMode);
slouken@5154
   129
    int (*CreateTexture) (SDL_Renderer * renderer, SDL_Texture * texture);
icculus@12214
   130
    int (*QueueSetViewport) (SDL_Renderer * renderer, SDL_RenderCommand *cmd);
icculus@12214
   131
    int (*QueueSetDrawColor) (SDL_Renderer * renderer, SDL_RenderCommand *cmd);
icculus@12211
   132
    int (*QueueDrawPoints) (SDL_Renderer * renderer, SDL_RenderCommand *cmd, const SDL_FPoint * points,
icculus@12211
   133
                             int count);
icculus@12211
   134
    int (*QueueDrawLines) (SDL_Renderer * renderer, SDL_RenderCommand *cmd, const SDL_FPoint * points,
icculus@12211
   135
                            int count);
icculus@12211
   136
    int (*QueueFillRects) (SDL_Renderer * renderer, SDL_RenderCommand *cmd, const SDL_FRect * rects,
icculus@12211
   137
                            int count);
icculus@12211
   138
    int (*QueueCopy) (SDL_Renderer * renderer, SDL_RenderCommand *cmd, SDL_Texture * texture,
icculus@12211
   139
                       const SDL_Rect * srcrect, const SDL_FRect * dstrect);
icculus@12211
   140
    int (*QueueCopyEx) (SDL_Renderer * renderer, SDL_RenderCommand *cmd, SDL_Texture * texture,
icculus@12211
   141
                        const SDL_Rect * srcquad, const SDL_FRect * dstrect,
icculus@12211
   142
                        const double angle, const SDL_FPoint *center, const SDL_RendererFlip flip);
icculus@12211
   143
    int (*RunCommandQueue) (SDL_Renderer * renderer, SDL_RenderCommand *cmd, void *vertices, size_t vertsize);
slouken@5154
   144
    int (*UpdateTexture) (SDL_Renderer * renderer, SDL_Texture * texture,
slouken@5154
   145
                          const SDL_Rect * rect, const void *pixels,
slouken@5154
   146
                          int pitch);
slouken@7759
   147
    int (*UpdateTextureYUV) (SDL_Renderer * renderer, SDL_Texture * texture,
slouken@7759
   148
                            const SDL_Rect * rect,
slouken@7759
   149
                            const Uint8 *Yplane, int Ypitch,
slouken@7759
   150
                            const Uint8 *Uplane, int Upitch,
slouken@7759
   151
                            const Uint8 *Vplane, int Vpitch);
slouken@5154
   152
    int (*LockTexture) (SDL_Renderer * renderer, SDL_Texture * texture,
slouken@5156
   153
                        const SDL_Rect * rect, void **pixels, int *pitch);
slouken@5154
   154
    void (*UnlockTexture) (SDL_Renderer * renderer, SDL_Texture * texture);
slouken@6247
   155
    int (*SetRenderTarget) (SDL_Renderer * renderer, SDL_Texture * texture);
slouken@5154
   156
    int (*RenderReadPixels) (SDL_Renderer * renderer, const SDL_Rect * rect,
slouken@5154
   157
                             Uint32 format, void * pixels, int pitch);
slouken@5154
   158
    void (*RenderPresent) (SDL_Renderer * renderer);
slouken@5154
   159
    void (*DestroyTexture) (SDL_Renderer * renderer, SDL_Texture * texture);
slouken@5154
   160
slouken@5154
   161
    void (*DestroyRenderer) (SDL_Renderer * renderer);
slouken@5154
   162
gabomdq@6414
   163
    int (*GL_BindTexture) (SDL_Renderer * renderer, SDL_Texture *texture, float *texw, float *texh);
gabomdq@6414
   164
    int (*GL_UnbindTexture) (SDL_Renderer * renderer, SDL_Texture *texture);
gabomdq@6414
   165
slouken@11744
   166
    void *(*GetMetalLayer) (SDL_Renderer * renderer);
slouken@11744
   167
    void *(*GetMetalCommandEncoder) (SDL_Renderer * renderer);
slouken@11744
   168
slouken@5154
   169
    /* The current renderer info */
slouken@5154
   170
    SDL_RendererInfo info;
slouken@5154
   171
slouken@5154
   172
    /* The window associated with the renderer */
slouken@5154
   173
    SDL_Window *window;
slouken@6260
   174
    SDL_bool hidden;
slouken@5154
   175
slouken@6530
   176
    /* The logical resolution for rendering */
slouken@6530
   177
    int logical_w;
slouken@6530
   178
    int logical_h;
slouken@6581
   179
    int logical_w_backup;
slouken@6581
   180
    int logical_h_backup;
slouken@6530
   181
flibitijibibo@10039
   182
    /* Whether or not to force the viewport to even integer intervals */
flibitijibibo@10039
   183
    SDL_bool integer_scale;
flibitijibibo@10039
   184
slouken@5297
   185
    /* The drawable area within the window */
slouken@5297
   186
    SDL_Rect viewport;
slouken@6246
   187
    SDL_Rect viewport_backup;
slouken@5297
   188
slouken@7141
   189
    /* The clip rectangle within the window */
slouken@7141
   190
    SDL_Rect clip_rect;
slouken@7141
   191
    SDL_Rect clip_rect_backup;
slouken@7141
   192
jorgenpt@8728
   193
    /* Wether or not the clipping rectangle is used. */
jorgenpt@8728
   194
    SDL_bool clipping_enabled;
jorgenpt@8728
   195
    SDL_bool clipping_enabled_backup;
jorgenpt@8728
   196
slouken@6528
   197
    /* The render output coordinate scale */
slouken@6528
   198
    SDL_FPoint scale;
slouken@6528
   199
    SDL_FPoint scale_backup;
slouken@6528
   200
slouken@11178
   201
    /* The pixel to point coordinate scale */
slouken@11178
   202
    SDL_FPoint dpi_scale;
slouken@11178
   203
slouken@5154
   204
    /* The list of textures */
slouken@5154
   205
    SDL_Texture *textures;
slouken@6246
   206
    SDL_Texture *target;
slouken@12021
   207
    SDL_mutex *target_mutex;
slouken@5154
   208
slouken@5154
   209
    Uint8 r, g, b, a;                   /**< Color for drawing operations values */
slouken@5154
   210
    SDL_BlendMode blendMode;            /**< The drawing blend mode */
slouken@5154
   211
icculus@12214
   212
    SDL_bool always_batch;
icculus@12211
   213
    SDL_bool batching;
icculus@12211
   214
    SDL_RenderCommand *render_commands;
icculus@12211
   215
    SDL_RenderCommand *render_commands_tail;
icculus@12211
   216
    SDL_RenderCommand *render_commands_pool;
icculus@12211
   217
    Uint32 render_command_generation;
icculus@12214
   218
    Uint32 last_queued_color;
icculus@12214
   219
    SDL_Rect last_queued_viewport;
icculus@12214
   220
    SDL_Rect last_queued_cliprect;
icculus@12214
   221
    SDL_bool last_queued_cliprect_enabled;
icculus@12214
   222
    SDL_bool color_queued;
icculus@12214
   223
    SDL_bool viewport_queued;
icculus@12214
   224
    SDL_bool cliprect_queued;
icculus@12211
   225
icculus@12211
   226
    void *vertex_data;
icculus@12211
   227
    size_t vertex_data_used;
icculus@12211
   228
    size_t vertex_data_allocation;
icculus@12214
   229
    SDL_AllocVertGap vertex_data_gaps;
icculus@12214
   230
    SDL_AllocVertGap *vertex_data_gaps_pool;
icculus@12211
   231
slouken@5154
   232
    void *driverdata;
slouken@5154
   233
};
slouken@5154
   234
slouken@5154
   235
/* Define the SDL render driver structure */
slouken@5154
   236
struct SDL_RenderDriver
slouken@5154
   237
{
slouken@5154
   238
    SDL_Renderer *(*CreateRenderer) (SDL_Window * window, Uint32 flags);
slouken@5154
   239
slouken@5154
   240
    /* Info about the renderer capabilities */
slouken@5154
   241
    SDL_RendererInfo info;
slouken@5154
   242
};
slouken@5154
   243
icculus@10914
   244
/* Not all of these are available in a given build. Use #ifdefs, etc. */
slouken@5154
   245
extern SDL_RenderDriver D3D_RenderDriver;
dludwig@8400
   246
extern SDL_RenderDriver D3D11_RenderDriver;
slouken@5154
   247
extern SDL_RenderDriver GL_RenderDriver;
slouken@5209
   248
extern SDL_RenderDriver GLES2_RenderDriver;
slouken@5201
   249
extern SDL_RenderDriver GLES_RenderDriver;
slouken@5199
   250
extern SDL_RenderDriver DirectFB_RenderDriver;
icculus@11729
   251
extern SDL_RenderDriver METAL_RenderDriver;
kimonline@7009
   252
extern SDL_RenderDriver PSP_RenderDriver;
slouken@5154
   253
extern SDL_RenderDriver SW_RenderDriver;
slouken@5154
   254
slouken@11282
   255
/* Blend mode functions */
slouken@11282
   256
extern SDL_BlendFactor SDL_GetBlendModeSrcColorFactor(SDL_BlendMode blendMode);
slouken@11282
   257
extern SDL_BlendFactor SDL_GetBlendModeDstColorFactor(SDL_BlendMode blendMode);
slouken@11282
   258
extern SDL_BlendOperation SDL_GetBlendModeColorOperation(SDL_BlendMode blendMode);
slouken@11282
   259
extern SDL_BlendFactor SDL_GetBlendModeSrcAlphaFactor(SDL_BlendMode blendMode);
slouken@11282
   260
extern SDL_BlendFactor SDL_GetBlendModeDstAlphaFactor(SDL_BlendMode blendMode);
slouken@11282
   261
extern SDL_BlendOperation SDL_GetBlendModeAlphaOperation(SDL_BlendMode blendMode);
slouken@11282
   262
icculus@12211
   263
/* drivers call this during their Queue*() methods to make space in a array that are used
icculus@12211
   264
   for a vertex buffer during RunCommandQueue(). Pointers returned here are only valid until
icculus@12211
   265
   the next call, because it might be in an array that gets realloc()'d. */
icculus@12214
   266
extern void *SDL_AllocateRenderVertices(SDL_Renderer *renderer, const size_t numbytes, const size_t alignment, size_t *offset);
icculus@12211
   267
slouken@10638
   268
#endif /* SDL_sysrender_h_ */
slouken@5154
   269
slouken@5154
   270
/* vi: set ts=4 sw=4 expandtab: */