2016-11-08 13:28:58 +00:00
|
|
|
/*
|
|
|
|
** Triangle 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-11-20 00:51:08 +00:00
|
|
|
#pragma once
|
2016-11-08 13:28:58 +00:00
|
|
|
|
2016-12-27 05:31:55 +00:00
|
|
|
#include "swrenderer/drawers/r_draw.h"
|
|
|
|
#include "swrenderer/drawers/r_thread.h"
|
2017-02-23 08:02:13 +00:00
|
|
|
#include "polyrenderer/drawers/screen_triangle.h"
|
2016-12-30 01:20:24 +00:00
|
|
|
#include "polyrenderer/math/tri_matrix.h"
|
|
|
|
#include "polyrenderer/drawers/poly_buffer.h"
|
|
|
|
#include "polyrenderer/drawers/poly_draw_args.h"
|
2016-11-11 17:24:59 +00:00
|
|
|
|
2016-11-26 09:49:29 +00:00
|
|
|
struct ShadedTriVertex : public TriVertex
|
|
|
|
{
|
|
|
|
float clipDistance0;
|
|
|
|
};
|
|
|
|
|
2016-12-15 00:33:26 +00:00
|
|
|
typedef void(*PolyDrawFuncPtr)(const TriDrawTriangleArgs *, WorkerThreadData *);
|
|
|
|
|
2016-11-08 13:28:58 +00:00
|
|
|
class PolyTriangleDrawer
|
|
|
|
{
|
|
|
|
public:
|
2016-11-18 00:58:39 +00:00
|
|
|
static void set_viewport(int x, int y, int width, int height, DCanvas *canvas);
|
2016-12-07 21:26:18 +00:00
|
|
|
static void toggle_mirror();
|
2017-03-26 08:10:55 +00:00
|
|
|
static bool is_mirror();
|
2016-11-08 13:28:58 +00:00
|
|
|
|
|
|
|
private:
|
2016-11-26 09:49:29 +00:00
|
|
|
static ShadedTriVertex shade_vertex(const TriMatrix &objectToClip, const float *clipPlane, const TriVertex &v);
|
2016-12-15 23:35:45 +00:00
|
|
|
static void draw_arrays(const PolyDrawArgs &args, WorkerThreadData *thread);
|
2016-12-15 22:29:31 +00:00
|
|
|
static void draw_shaded_triangle(const ShadedTriVertex *vertices, bool ccw, TriDrawTriangleArgs *args, WorkerThreadData *thread, PolyDrawFuncPtr *drawfuncs, int num_drawfuncs);
|
2017-03-24 12:04:02 +00:00
|
|
|
|
|
|
|
static int clipedge(const ShadedTriVertex *verts, TriVertex *clippedvert);
|
2016-11-08 13:28:58 +00:00
|
|
|
|
2016-11-18 00:58:39 +00:00
|
|
|
static int viewport_x, viewport_y, viewport_width, viewport_height, dest_pitch, dest_width, dest_height;
|
|
|
|
static bool dest_bgra;
|
|
|
|
static uint8_t *dest;
|
2016-12-07 21:26:18 +00:00
|
|
|
static bool mirror;
|
2016-11-18 00:58:39 +00:00
|
|
|
|
2016-11-10 04:30:33 +00:00
|
|
|
enum { max_additional_vertices = 16 };
|
|
|
|
|
2016-11-08 13:28:58 +00:00
|
|
|
friend class DrawPolyTrianglesCommand;
|
|
|
|
};
|
|
|
|
|
|
|
|
class DrawPolyTrianglesCommand : public DrawerCommand
|
|
|
|
{
|
|
|
|
public:
|
2016-12-15 23:35:45 +00:00
|
|
|
DrawPolyTrianglesCommand(const PolyDrawArgs &args, bool mirror);
|
2016-11-08 13:28:58 +00:00
|
|
|
|
|
|
|
void Execute(DrawerThread *thread) override;
|
2017-03-26 08:10:55 +00:00
|
|
|
FString DebugInfo() override { return "DrawPolyTriangles"; }
|
2016-11-08 13:28:58 +00:00
|
|
|
|
|
|
|
private:
|
2016-11-11 17:24:59 +00:00
|
|
|
PolyDrawArgs args;
|
2016-11-08 13:28:58 +00:00
|
|
|
};
|