src/render/SDL_sysrender.h
author Ryan C. Gordon <icculus@icculus.org>
Thu, 20 Sep 2018 15:46:02 -0400
branchSDL-ryan-batching-renderer
changeset 12211 0d8f33ad5fbb
parent 12021 3239c8ad2986
child 12214 d377f3ccade7
permissions -rw-r--r--
render: Move to a batching system for rendering (work in progress).
slouken@5154
     1
/*
slouken@5535
     2
  Simple DirectMedia Layer
slouken@11811
     3
  Copyright (C) 1997-2018 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@6528
    42
typedef struct
slouken@6528
    43
{
slouken@6528
    44
    float x;
slouken@6528
    45
    float y;
slouken@6528
    46
} SDL_FPoint;
slouken@6528
    47
slouken@6528
    48
typedef struct
slouken@6528
    49
{
slouken@6528
    50
    float x;
slouken@6528
    51
    float y;
slouken@6528
    52
    float w;
slouken@6528
    53
    float h;
slouken@6528
    54
} SDL_FRect;
slouken@6528
    55
slouken@5154
    56
/* Define the SDL texture structure */
slouken@5154
    57
struct SDL_Texture
slouken@5154
    58
{
slouken@5154
    59
    const void *magic;
slouken@5154
    60
    Uint32 format;              /**< The pixel format of the texture */
slouken@5154
    61
    int access;                 /**< SDL_TextureAccess */
slouken@5154
    62
    int w;                      /**< The width of the texture */
slouken@5154
    63
    int h;                      /**< The height of the texture */
slouken@5154
    64
    int modMode;                /**< The texture modulation mode */
slouken@5154
    65
    SDL_BlendMode blendMode;    /**< The texture blend mode */
slouken@11958
    66
    SDL_ScaleMode scaleMode;    /**< The texture scale mode */
slouken@5154
    67
    Uint8 r, g, b, a;           /**< Texture modulation values */
slouken@5154
    68
slouken@5154
    69
    SDL_Renderer *renderer;
slouken@5154
    70
slouken@5156
    71
    /* Support for formats not supported directly by the renderer */
slouken@5156
    72
    SDL_Texture *native;
slouken@5156
    73
    SDL_SW_YUVTexture *yuv;
slouken@5156
    74
    void *pixels;
slouken@5156
    75
    int pitch;
slouken@5156
    76
    SDL_Rect locked_rect;
slouken@5156
    77
icculus@12211
    78
    Uint32 last_command_generation; /* last command queue generation this texture was in. */
icculus@12211
    79
slouken@5154
    80
    void *driverdata;           /**< Driver specific texture representation */
slouken@5154
    81
slouken@5154
    82
    SDL_Texture *prev;
slouken@5154
    83
    SDL_Texture *next;
slouken@5154
    84
};
slouken@5154
    85
icculus@12211
    86
typedef enum
icculus@12211
    87
{
icculus@12211
    88
    SDL_RENDERCMD_NO_OP,
icculus@12211
    89
    SDL_RENDERCMD_SETVIEWPORT,
icculus@12211
    90
    SDL_RENDERCMD_SETCLIPRECT,
icculus@12211
    91
    SDL_RENDERCMD_CLEAR,
icculus@12211
    92
    SDL_RENDERCMD_DRAW_POINTS,
icculus@12211
    93
    SDL_RENDERCMD_DRAW_LINES,
icculus@12211
    94
    SDL_RENDERCMD_FILL_RECTS,
icculus@12211
    95
    SDL_RENDERCMD_COPY,
icculus@12211
    96
    SDL_RENDERCMD_COPY_EX
icculus@12211
    97
} SDL_RenderCommandType;
icculus@12211
    98
icculus@12211
    99
typedef struct SDL_RenderCommand
icculus@12211
   100
{
icculus@12211
   101
    SDL_RenderCommandType command;
icculus@12211
   102
    union {
icculus@12211
   103
        SDL_Rect viewport;
icculus@12211
   104
        struct {
icculus@12211
   105
            SDL_bool enabled;
icculus@12211
   106
            SDL_Rect rect;
icculus@12211
   107
        } cliprect;
icculus@12211
   108
        struct {
icculus@12211
   109
            size_t first;
icculus@12211
   110
            size_t count;
icculus@12211
   111
            Uint8 r, g, b, a;
icculus@12211
   112
            SDL_BlendMode blend;
icculus@12211
   113
            SDL_Texture *texture;
icculus@12211
   114
        } draw;
icculus@12211
   115
        struct {
icculus@12211
   116
            Uint8 r, g, b, a;
icculus@12211
   117
        } color;
icculus@12211
   118
    } data;
icculus@12211
   119
    struct SDL_RenderCommand *next;
icculus@12211
   120
} SDL_RenderCommand;
icculus@12211
   121
icculus@12211
   122
slouken@5154
   123
/* Define the SDL renderer structure */
slouken@5154
   124
struct SDL_Renderer
slouken@5154
   125
{
slouken@5154
   126
    const void *magic;
slouken@5154
   127
slouken@5154
   128
    void (*WindowEvent) (SDL_Renderer * renderer, const SDL_WindowEvent *event);
slouken@7239
   129
    int (*GetOutputSize) (SDL_Renderer * renderer, int *w, int *h);
slouken@11282
   130
    SDL_bool (*SupportsBlendMode)(SDL_Renderer * renderer, SDL_BlendMode blendMode);
slouken@5154
   131
    int (*CreateTexture) (SDL_Renderer * renderer, SDL_Texture * texture);
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@12211
   212
    SDL_bool batching;
icculus@12211
   213
    SDL_RenderCommand *render_commands;
icculus@12211
   214
    SDL_RenderCommand *render_commands_tail;
icculus@12211
   215
    SDL_RenderCommand *render_commands_pool;
icculus@12211
   216
    Uint32 render_command_generation;
icculus@12211
   217
icculus@12211
   218
    void *vertex_data;
icculus@12211
   219
    size_t vertex_data_used;
icculus@12211
   220
    size_t vertex_data_allocation;
icculus@12211
   221
slouken@5154
   222
    void *driverdata;
slouken@5154
   223
};
slouken@5154
   224
slouken@5154
   225
/* Define the SDL render driver structure */
slouken@5154
   226
struct SDL_RenderDriver
slouken@5154
   227
{
slouken@5154
   228
    SDL_Renderer *(*CreateRenderer) (SDL_Window * window, Uint32 flags);
slouken@5154
   229
slouken@5154
   230
    /* Info about the renderer capabilities */
slouken@5154
   231
    SDL_RendererInfo info;
slouken@5154
   232
};
slouken@5154
   233
icculus@10914
   234
/* Not all of these are available in a given build. Use #ifdefs, etc. */
slouken@5154
   235
extern SDL_RenderDriver D3D_RenderDriver;
dludwig@8400
   236
extern SDL_RenderDriver D3D11_RenderDriver;
slouken@5154
   237
extern SDL_RenderDriver GL_RenderDriver;
slouken@5209
   238
extern SDL_RenderDriver GLES2_RenderDriver;
slouken@5201
   239
extern SDL_RenderDriver GLES_RenderDriver;
slouken@5199
   240
extern SDL_RenderDriver DirectFB_RenderDriver;
icculus@11729
   241
extern SDL_RenderDriver METAL_RenderDriver;
kimonline@7009
   242
extern SDL_RenderDriver PSP_RenderDriver;
slouken@5154
   243
extern SDL_RenderDriver SW_RenderDriver;
slouken@5154
   244
slouken@11282
   245
/* Blend mode functions */
slouken@11282
   246
extern SDL_BlendFactor SDL_GetBlendModeSrcColorFactor(SDL_BlendMode blendMode);
slouken@11282
   247
extern SDL_BlendFactor SDL_GetBlendModeDstColorFactor(SDL_BlendMode blendMode);
slouken@11282
   248
extern SDL_BlendOperation SDL_GetBlendModeColorOperation(SDL_BlendMode blendMode);
slouken@11282
   249
extern SDL_BlendFactor SDL_GetBlendModeSrcAlphaFactor(SDL_BlendMode blendMode);
slouken@11282
   250
extern SDL_BlendFactor SDL_GetBlendModeDstAlphaFactor(SDL_BlendMode blendMode);
slouken@11282
   251
extern SDL_BlendOperation SDL_GetBlendModeAlphaOperation(SDL_BlendMode blendMode);
slouken@11282
   252
icculus@12211
   253
/* drivers call this during their Queue*() methods to make space in a array that are used
icculus@12211
   254
   for a vertex buffer during RunCommandQueue(). Pointers returned here are only valid until
icculus@12211
   255
   the next call, because it might be in an array that gets realloc()'d. */
icculus@12211
   256
extern void *SDL_AllocateRenderVertices(SDL_Renderer *renderer, const size_t numbytes, size_t *offset);
icculus@12211
   257
slouken@10638
   258
#endif /* SDL_sysrender_h_ */
slouken@5154
   259
slouken@5154
   260
/* vi: set ts=4 sw=4 expandtab: */