2016-11-01 20:44:33 +00:00
|
|
|
/*
|
|
|
|
** LLVM code generated drawers
|
|
|
|
** Copyright (c) 2016 Magnus Norddahl
|
|
|
|
**
|
|
|
|
** This software is provided 'as-is', without any express or implied
|
|
|
|
** warranty. In no event will the authors be held liable for any damages
|
|
|
|
** arising from the use of this software.
|
|
|
|
**
|
|
|
|
** Permission is granted to anyone to use this software for any purpose,
|
|
|
|
** including commercial applications, and to alter it and redistribute it
|
|
|
|
** freely, subject to the following restrictions:
|
|
|
|
**
|
|
|
|
** 1. The origin of this software must not be misrepresented; you must not
|
|
|
|
** claim that you wrote the original software. If you use this software
|
|
|
|
** in a product, an acknowledgment in the product documentation would be
|
|
|
|
** appreciated but is not required.
|
|
|
|
** 2. Altered source versions must be plainly marked as such, and must not be
|
|
|
|
** misrepresented as being the original software.
|
|
|
|
** 3. This notice may not be removed or altered from any source distribution.
|
|
|
|
**
|
|
|
|
*/
|
2016-09-29 00:10:14 +00:00
|
|
|
|
|
|
|
#pragma once
|
|
|
|
|
2016-11-28 16:31:56 +00:00
|
|
|
#include <cstdint>
|
|
|
|
#include <vector>
|
|
|
|
|
|
|
|
class FString;
|
2016-12-13 18:26:13 +00:00
|
|
|
|
|
|
|
struct TriFullSpan
|
|
|
|
{
|
|
|
|
uint16_t X;
|
|
|
|
uint16_t Y;
|
|
|
|
uint32_t Length;
|
|
|
|
};
|
|
|
|
|
|
|
|
struct TriPartialBlock
|
|
|
|
{
|
|
|
|
uint16_t X;
|
|
|
|
uint16_t Y;
|
|
|
|
uint32_t Mask0;
|
|
|
|
uint32_t Mask1;
|
|
|
|
};
|
2016-11-28 16:31:56 +00:00
|
|
|
|
2016-09-30 05:27:25 +00:00
|
|
|
struct WorkerThreadData
|
|
|
|
{
|
|
|
|
int32_t core;
|
|
|
|
int32_t num_cores;
|
|
|
|
int32_t pass_start_y;
|
|
|
|
int32_t pass_end_y;
|
2016-10-07 04:40:29 +00:00
|
|
|
uint32_t *temp;
|
2016-12-13 18:26:13 +00:00
|
|
|
|
|
|
|
// Triangle working data:
|
|
|
|
TriFullSpan *FullSpans;
|
|
|
|
TriPartialBlock *PartialBlocks;
|
|
|
|
uint32_t NumFullSpans;
|
|
|
|
uint32_t NumPartialBlocks;
|
|
|
|
int32_t StartX;
|
|
|
|
int32_t StartY;
|
2016-09-30 05:27:25 +00:00
|
|
|
};
|
|
|
|
|
2016-12-20 22:21:34 +00:00
|
|
|
struct TriLight
|
|
|
|
{
|
|
|
|
uint32_t color;
|
|
|
|
float x, y, z;
|
|
|
|
float radius;
|
|
|
|
};
|
|
|
|
|
2016-09-29 05:38:33 +00:00
|
|
|
struct DrawWallArgs
|
|
|
|
{
|
|
|
|
uint32_t *dest;
|
|
|
|
const uint32_t *source[4];
|
|
|
|
const uint32_t *source2[4];
|
|
|
|
int32_t pitch;
|
|
|
|
int32_t count;
|
|
|
|
int32_t dest_y;
|
|
|
|
uint32_t texturefrac[4];
|
|
|
|
uint32_t texturefracx[4];
|
|
|
|
uint32_t iscale[4];
|
|
|
|
uint32_t textureheight[4];
|
|
|
|
uint32_t light[4];
|
|
|
|
uint32_t srcalpha;
|
|
|
|
uint32_t destalpha;
|
|
|
|
|
|
|
|
uint16_t light_alpha;
|
|
|
|
uint16_t light_red;
|
|
|
|
uint16_t light_green;
|
|
|
|
uint16_t light_blue;
|
|
|
|
uint16_t fade_alpha;
|
|
|
|
uint16_t fade_red;
|
|
|
|
uint16_t fade_green;
|
|
|
|
uint16_t fade_blue;
|
|
|
|
uint16_t desaturate;
|
|
|
|
uint32_t flags;
|
|
|
|
enum Flags
|
|
|
|
{
|
|
|
|
simple_shade = 1,
|
|
|
|
nearest_filter = 2
|
|
|
|
};
|
2016-10-12 11:25:05 +00:00
|
|
|
|
2016-12-20 22:21:34 +00:00
|
|
|
float z, step_z;
|
|
|
|
TriLight *dynlights;
|
|
|
|
uint32_t num_dynlights;
|
|
|
|
|
2016-11-28 16:31:56 +00:00
|
|
|
FString ToString();
|
2016-09-29 05:38:33 +00:00
|
|
|
};
|
|
|
|
|
2016-09-29 02:01:42 +00:00
|
|
|
struct DrawSpanArgs
|
2016-09-29 00:10:14 +00:00
|
|
|
{
|
|
|
|
uint32_t *destorg;
|
|
|
|
const uint32_t *source;
|
|
|
|
int32_t destpitch;
|
|
|
|
int32_t xfrac;
|
|
|
|
int32_t yfrac;
|
|
|
|
int32_t xstep;
|
|
|
|
int32_t ystep;
|
|
|
|
int32_t x1;
|
|
|
|
int32_t x2;
|
|
|
|
int32_t y;
|
|
|
|
int32_t xbits;
|
|
|
|
int32_t ybits;
|
|
|
|
uint32_t light;
|
|
|
|
uint32_t srcalpha;
|
|
|
|
uint32_t destalpha;
|
|
|
|
|
|
|
|
uint16_t light_alpha;
|
|
|
|
uint16_t light_red;
|
|
|
|
uint16_t light_green;
|
|
|
|
uint16_t light_blue;
|
|
|
|
uint16_t fade_alpha;
|
|
|
|
uint16_t fade_red;
|
|
|
|
uint16_t fade_green;
|
|
|
|
uint16_t fade_blue;
|
|
|
|
uint16_t desaturate;
|
|
|
|
uint32_t flags;
|
|
|
|
enum Flags
|
|
|
|
{
|
|
|
|
simple_shade = 1,
|
|
|
|
nearest_filter = 2
|
|
|
|
};
|
2016-10-12 11:49:12 +00:00
|
|
|
|
2016-12-22 07:42:21 +00:00
|
|
|
float viewpos_x, step_viewpos_x;
|
|
|
|
TriLight *dynlights;
|
|
|
|
uint32_t num_dynlights;
|
|
|
|
|
2016-11-28 16:31:56 +00:00
|
|
|
FString ToString();
|
2016-09-29 00:10:14 +00:00
|
|
|
};
|
|
|
|
|
2016-10-07 01:38:43 +00:00
|
|
|
struct DrawColumnArgs
|
|
|
|
{
|
|
|
|
uint32_t *dest;
|
|
|
|
const uint8_t *source;
|
2016-11-05 10:29:50 +00:00
|
|
|
const uint8_t *source2;
|
2016-10-07 01:38:43 +00:00
|
|
|
uint8_t *colormap;
|
|
|
|
uint8_t *translation;
|
|
|
|
const uint32_t *basecolors;
|
|
|
|
int32_t pitch;
|
|
|
|
int32_t count;
|
|
|
|
int32_t dest_y;
|
|
|
|
uint32_t iscale;
|
2016-11-05 10:29:50 +00:00
|
|
|
uint32_t texturefracx;
|
|
|
|
uint32_t textureheight;
|
2016-10-07 01:38:43 +00:00
|
|
|
uint32_t texturefrac;
|
|
|
|
uint32_t light;
|
|
|
|
uint32_t color;
|
|
|
|
uint32_t srccolor;
|
|
|
|
uint32_t srcalpha;
|
|
|
|
uint32_t destalpha;
|
|
|
|
|
|
|
|
uint16_t light_alpha;
|
|
|
|
uint16_t light_red;
|
|
|
|
uint16_t light_green;
|
|
|
|
uint16_t light_blue;
|
|
|
|
uint16_t fade_alpha;
|
|
|
|
uint16_t fade_red;
|
|
|
|
uint16_t fade_green;
|
|
|
|
uint16_t fade_blue;
|
|
|
|
uint16_t desaturate;
|
|
|
|
uint32_t flags;
|
|
|
|
enum Flags
|
|
|
|
{
|
2016-11-05 10:29:50 +00:00
|
|
|
simple_shade = 1,
|
|
|
|
nearest_filter = 2
|
2016-10-07 01:38:43 +00:00
|
|
|
};
|
2016-10-12 11:49:12 +00:00
|
|
|
|
2016-11-28 16:31:56 +00:00
|
|
|
FString ToString();
|
2016-10-07 01:38:43 +00:00
|
|
|
};
|
|
|
|
|
2016-10-15 13:04:14 +00:00
|
|
|
struct DrawSkyArgs
|
|
|
|
{
|
|
|
|
uint32_t *dest;
|
|
|
|
const uint32_t *source0[4];
|
|
|
|
const uint32_t *source1[4];
|
|
|
|
int32_t pitch;
|
|
|
|
int32_t count;
|
|
|
|
int32_t dest_y;
|
|
|
|
uint32_t texturefrac[4];
|
|
|
|
uint32_t iscale[4];
|
|
|
|
uint32_t textureheight0;
|
|
|
|
uint32_t textureheight1;
|
|
|
|
uint32_t top_color;
|
|
|
|
uint32_t bottom_color;
|
|
|
|
|
2016-11-28 16:31:56 +00:00
|
|
|
FString ToString();
|
2016-10-15 13:04:14 +00:00
|
|
|
};
|
|
|
|
|
2016-11-11 18:54:27 +00:00
|
|
|
struct TriVertex
|
|
|
|
{
|
|
|
|
TriVertex() { }
|
|
|
|
TriVertex(float x, float y, float z, float w, float u, float v) : x(x), y(y), z(z), w(w) { varying[0] = u; varying[1] = v; }
|
|
|
|
|
|
|
|
enum { NumVarying = 2 };
|
|
|
|
float x, y, z, w;
|
|
|
|
float varying[NumVarying];
|
|
|
|
};
|
|
|
|
|
|
|
|
struct TriUniforms
|
|
|
|
{
|
|
|
|
uint32_t light;
|
|
|
|
uint32_t subsectorDepth;
|
2016-11-19 01:53:32 +00:00
|
|
|
uint32_t color;
|
|
|
|
uint32_t srcalpha;
|
|
|
|
uint32_t destalpha;
|
2016-11-11 18:54:27 +00:00
|
|
|
uint16_t light_alpha;
|
|
|
|
uint16_t light_red;
|
|
|
|
uint16_t light_green;
|
|
|
|
uint16_t light_blue;
|
|
|
|
uint16_t fade_alpha;
|
|
|
|
uint16_t fade_red;
|
|
|
|
uint16_t fade_green;
|
|
|
|
uint16_t fade_blue;
|
|
|
|
uint16_t desaturate;
|
|
|
|
uint32_t flags;
|
|
|
|
enum Flags
|
|
|
|
{
|
|
|
|
simple_shade = 1,
|
|
|
|
nearest_filter = 2,
|
2016-11-15 22:30:42 +00:00
|
|
|
fixed_light = 4
|
2016-11-11 18:54:27 +00:00
|
|
|
};
|
|
|
|
};
|
|
|
|
|
2016-11-11 19:12:09 +00:00
|
|
|
struct TriDrawTriangleArgs
|
2016-11-11 18:54:27 +00:00
|
|
|
{
|
|
|
|
uint8_t *dest;
|
2016-11-11 19:12:09 +00:00
|
|
|
int32_t pitch;
|
2016-11-11 18:54:27 +00:00
|
|
|
TriVertex *v1;
|
|
|
|
TriVertex *v2;
|
|
|
|
TriVertex *v3;
|
2016-11-11 19:12:09 +00:00
|
|
|
int32_t clipleft;
|
|
|
|
int32_t clipright;
|
|
|
|
int32_t cliptop;
|
|
|
|
int32_t clipbottom;
|
2016-11-11 18:54:27 +00:00
|
|
|
const uint8_t *texturePixels;
|
2016-11-11 19:12:09 +00:00
|
|
|
uint32_t textureWidth;
|
|
|
|
uint32_t textureHeight;
|
2016-11-19 01:53:32 +00:00
|
|
|
const uint8_t *translation;
|
2016-11-11 18:54:27 +00:00
|
|
|
const TriUniforms *uniforms;
|
|
|
|
uint8_t *stencilValues;
|
|
|
|
uint32_t *stencilMasks;
|
2016-11-11 19:12:09 +00:00
|
|
|
int32_t stencilPitch;
|
2016-11-11 18:54:27 +00:00
|
|
|
uint8_t stencilTestValue;
|
|
|
|
uint8_t stencilWriteValue;
|
|
|
|
uint32_t *subsectorGBuffer;
|
2016-11-20 03:06:21 +00:00
|
|
|
const uint8_t *colormaps;
|
2016-12-19 16:27:46 +00:00
|
|
|
const uint8_t *RGB256k;
|
2016-11-20 15:42:53 +00:00
|
|
|
const uint8_t *BaseColors;
|
2016-11-11 18:54:27 +00:00
|
|
|
};
|
|
|
|
|
2016-11-19 01:53:32 +00:00
|
|
|
enum class TriBlendMode
|
|
|
|
{
|
|
|
|
Copy, // blend_copy(shade(fg))
|
|
|
|
AlphaBlend, // blend_alpha_blend(shade(fg), bg)
|
|
|
|
AddSolid, // blend_add(shade(fg), bg, srcalpha, destalpha)
|
|
|
|
Add, // blend_add(shade(fg), bg, srcalpha, calc_blend_bgalpha(fg, destalpha))
|
|
|
|
Sub, // blend_sub(shade(fg), bg, srcalpha, calc_blend_bgalpha(fg, destalpha))
|
|
|
|
RevSub, // blend_revsub(shade(fg), bg, srcalpha, calc_blend_bgalpha(fg, destalpha))
|
2016-11-21 04:52:02 +00:00
|
|
|
Stencil, // blend_stencil(shade(color), fg.a, bg, srcalpha, calc_blend_bgalpha(fg, destalpha))
|
|
|
|
Shaded, // blend_stencil(shade(color), fg.index, bg, srcalpha, calc_blend_bgalpha(fg, destalpha))
|
2016-11-19 01:53:32 +00:00
|
|
|
TranslateCopy, // blend_copy(shade(translate(fg)))
|
2016-11-19 12:32:57 +00:00
|
|
|
TranslateAlphaBlend, // blend_alpha_blend(shade(translate(fg)), bg)
|
2016-11-19 01:53:32 +00:00
|
|
|
TranslateAdd, // blend_add(shade(translate(fg)), bg, srcalpha, calc_blend_bgalpha(fg, destalpha))
|
|
|
|
TranslateSub, // blend_sub(shade(translate(fg)), bg, srcalpha, calc_blend_bgalpha(fg, destalpha))
|
2016-11-30 06:49:04 +00:00
|
|
|
TranslateRevSub,// blend_revsub(shade(translate(fg)), bg, srcalpha, calc_blend_bgalpha(fg, destalpha))
|
2016-12-03 05:58:06 +00:00
|
|
|
AddSrcColorOneMinusSrcColor, // glBlendMode(GL_SRC_COLOR, GL_ONE_MINUS_SRC_COLOR) used by GZDoom's fullbright additive sprites
|
|
|
|
Skycap // Fade to sky color when the V texture coordinate go beyond the [-1, 1] range
|
2016-11-19 01:53:32 +00:00
|
|
|
};
|
|
|
|
|
2016-12-03 05:58:06 +00:00
|
|
|
inline int NumTriBlendModes() { return (int)TriBlendMode::Skycap + 1; }
|
2016-11-19 01:53:32 +00:00
|
|
|
|
2016-11-28 16:31:56 +00:00
|
|
|
class Drawers
|
2016-09-29 00:10:14 +00:00
|
|
|
{
|
|
|
|
public:
|
2016-11-28 16:31:56 +00:00
|
|
|
static Drawers *Instance();
|
2016-09-29 00:10:14 +00:00
|
|
|
|
2016-10-07 01:38:43 +00:00
|
|
|
void(*DrawColumn)(const DrawColumnArgs *, const WorkerThreadData *) = nullptr;
|
|
|
|
void(*DrawColumnAdd)(const DrawColumnArgs *, const WorkerThreadData *) = nullptr;
|
|
|
|
void(*DrawColumnShaded)(const DrawColumnArgs *, const WorkerThreadData *) = nullptr;
|
|
|
|
void(*DrawColumnAddClamp)(const DrawColumnArgs *, const WorkerThreadData *) = nullptr;
|
|
|
|
void(*DrawColumnSubClamp)(const DrawColumnArgs *, const WorkerThreadData *) = nullptr;
|
|
|
|
void(*DrawColumnRevSubClamp)(const DrawColumnArgs *, const WorkerThreadData *) = nullptr;
|
2016-10-07 04:40:29 +00:00
|
|
|
void(*DrawColumnTranslated)(const DrawColumnArgs *, const WorkerThreadData *) = nullptr;
|
|
|
|
void(*DrawColumnTlatedAdd)(const DrawColumnArgs *, const WorkerThreadData *) = nullptr;
|
|
|
|
void(*DrawColumnAddClampTranslated)(const DrawColumnArgs *, const WorkerThreadData *) = nullptr;
|
|
|
|
void(*DrawColumnSubClampTranslated)(const DrawColumnArgs *, const WorkerThreadData *) = nullptr;
|
2016-10-07 01:38:43 +00:00
|
|
|
void(*DrawColumnRevSubClampTranslated)(const DrawColumnArgs *, const WorkerThreadData *) = nullptr;
|
|
|
|
void(*FillColumn)(const DrawColumnArgs *, const WorkerThreadData *) = nullptr;
|
|
|
|
void(*FillColumnAdd)(const DrawColumnArgs *, const WorkerThreadData *) = nullptr;
|
|
|
|
void(*FillColumnAddClamp)(const DrawColumnArgs *, const WorkerThreadData *) = nullptr;
|
|
|
|
void(*FillColumnSubClamp)(const DrawColumnArgs *, const WorkerThreadData *) = nullptr;
|
|
|
|
void(*FillColumnRevSubClamp)(const DrawColumnArgs *, const WorkerThreadData *) = nullptr;
|
|
|
|
|
2016-09-29 02:01:42 +00:00
|
|
|
void(*DrawSpan)(const DrawSpanArgs *) = nullptr;
|
|
|
|
void(*DrawSpanMasked)(const DrawSpanArgs *) = nullptr;
|
|
|
|
void(*DrawSpanTranslucent)(const DrawSpanArgs *) = nullptr;
|
|
|
|
void(*DrawSpanMaskedTranslucent)(const DrawSpanArgs *) = nullptr;
|
|
|
|
void(*DrawSpanAddClamp)(const DrawSpanArgs *) = nullptr;
|
|
|
|
void(*DrawSpanMaskedAddClamp)(const DrawSpanArgs *) = nullptr;
|
2016-09-29 00:10:14 +00:00
|
|
|
|
2016-09-30 05:27:25 +00:00
|
|
|
void(*vlinec1)(const DrawWallArgs *, const WorkerThreadData *) = nullptr;
|
|
|
|
void(*mvlinec1)(const DrawWallArgs *, const WorkerThreadData *) = nullptr;
|
|
|
|
void(*tmvline1_add)(const DrawWallArgs *, const WorkerThreadData *) = nullptr;
|
|
|
|
void(*tmvline1_addclamp)(const DrawWallArgs *, const WorkerThreadData *) = nullptr;
|
|
|
|
void(*tmvline1_subclamp)(const DrawWallArgs *, const WorkerThreadData *) = nullptr;
|
|
|
|
void(*tmvline1_revsubclamp)(const DrawWallArgs *, const WorkerThreadData *) = nullptr;
|
2016-09-29 05:38:33 +00:00
|
|
|
|
2016-10-15 13:04:14 +00:00
|
|
|
void(*DrawSky1)(const DrawSkyArgs *, const WorkerThreadData *) = nullptr;
|
|
|
|
void(*DrawDoubleSky1)(const DrawSkyArgs *, const WorkerThreadData *) = nullptr;
|
|
|
|
|
2016-12-15 22:29:31 +00:00
|
|
|
std::vector<void(*)(const TriDrawTriangleArgs *, WorkerThreadData *)> TriDraw8;
|
|
|
|
std::vector<void(*)(const TriDrawTriangleArgs *, WorkerThreadData *)> TriDraw32;
|
|
|
|
std::vector<void(*)(const TriDrawTriangleArgs *, WorkerThreadData *)> TriFill8;
|
|
|
|
std::vector<void(*)(const TriDrawTriangleArgs *, WorkerThreadData *)> TriFill32;
|
2016-11-30 07:32:05 +00:00
|
|
|
|
|
|
|
private:
|
|
|
|
Drawers();
|
2016-09-29 00:10:14 +00:00
|
|
|
};
|