| 1 |
/* |
| 2 |
* This file is part of the DXX-Rebirth project <https://www.dxx-rebirth.com/>. |
| 3 |
* It is copyright by its individual contributors, as recorded in the |
| 4 |
* project's Git history. See COPYING.txt at the top level for license |
| 5 |
* terms and a link to the Git history. |
| 6 |
*/ |
| 7 |
/* interface to OpenGL functions |
| 8 |
* Added 9/15/99 Matthew Mueller |
| 9 |
* Got rid of OpenGL-internal stuff 2004-5-16 Martin Schaffner |
| 10 |
*/ |
| 11 |
|
| 12 |
#ifndef _OGL_INIT_H_ |
| 13 |
#define _OGL_INIT_H_ |
| 14 |
|
| 15 |
#include "dxxsconf.h" |
| 16 |
|
| 17 |
#if !DXX_USE_OGL |
| 18 |
#error "This file can only be included in OpenGL enabled builds." |
| 19 |
#endif |
| 20 |
|
| 21 |
#ifdef _MSC_VER |
| 22 |
#include <windows.h> |
| 23 |
#include <stddef.h> |
| 24 |
#endif |
| 25 |
|
| 26 |
#include "d_gl.h" |
| 27 |
#include "dsx-ns.h" |
| 28 |
#include "fwd-gr.h" |
| 29 |
#include "fwd-segment.h" |
| 30 |
#include "palette.h" |
| 31 |
#include "pstypes.h" |
| 32 |
#include "3d.h" |
| 33 |
#include <array> |
| 34 |
|
| 35 |
namespace dcx { |
| 36 |
|
| 37 |
/* we need to export ogl_texture for 2d/font.c */ |
| 38 |
struct ogl_texture |
| 39 |
{ |
| 40 |
GLuint handle; |
| 41 |
GLint internalformat; |
| 42 |
GLenum format; |
| 43 |
unsigned w, h, tw, th; |
| 44 |
int lw; |
| 45 |
int bytesu; |
| 46 |
int bytes; |
| 47 |
GLfloat u,v; |
| 48 |
GLfloat prio; |
| 49 |
int wrapstate; |
| 50 |
unsigned long numrend; |
| 51 |
}; |
| 52 |
|
| 53 |
extern ogl_texture* ogl_get_free_texture(); |
| 54 |
void ogl_init_texture(ogl_texture &t, int w, int h, int flags); |
| 55 |
|
| 56 |
void ogl_init_shared_palette(void); |
| 57 |
|
| 58 |
/* These values are written to a file as integers, so they must not be |
| 59 |
* renumbered. |
| 60 |
*/ |
| 61 |
enum class opengl_texture_filter : uint8_t |
| 62 |
{ |
| 63 |
classic, |
| 64 |
upscale, |
| 65 |
trilinear, |
| 66 |
}; |
| 67 |
|
| 68 |
#define OGL_FLAG_MIPMAP (1 << 0) |
| 69 |
#define OGL_FLAG_NOCOLOR (1 << 1) |
| 70 |
#define OGL_FLAG_ALPHA (1 << 31) // not required for ogl_loadbmtexture, since it uses the BM_FLAG_TRANSPARENT, but is needed for ogl_init_texture. |
| 71 |
void ogl_loadbmtexture_f(grs_bitmap &bm, opengl_texture_filter texfilt, bool texanis, bool edgepad); |
| 72 |
void ogl_freebmtexture(grs_bitmap &bm); |
| 73 |
|
| 74 |
void ogl_start_frame(grs_canvas &); |
| 75 |
#if DXX_USE_STEREOSCOPIC_RENDER |
| 76 |
void ogl_stereo_frame(bool left_eye, int xoff); |
| 77 |
#endif |
| 78 |
void ogl_end_frame(void); |
| 79 |
void ogl_set_screen_mode(void); |
| 80 |
|
| 81 |
struct ogl_colors |
| 82 |
{ |
| 83 |
using array_type = std::array<GLfloat, 16>; |
| 84 |
static const array_type white; |
| 85 |
const array_type &init(int c) |
| 86 |
{ |
| 87 |
return |
| 88 |
#ifdef DXX_CONSTANT_TRUE |
| 89 |
DXX_CONSTANT_TRUE(c == -1) |
| 90 |
? white |
| 91 |
: DXX_CONSTANT_TRUE(c != -1) |
| 92 |
? init_palette(c) |
| 93 |
: |
| 94 |
#endif |
| 95 |
init_maybe_white(c); |
| 96 |
} |
| 97 |
const array_type &init_maybe_white(int c); |
| 98 |
const array_type &init_palette(unsigned c); |
| 99 |
private: |
| 100 |
array_type a; |
| 101 |
}; |
| 102 |
|
| 103 |
void ogl_urect(grs_canvas &, int left, int top, int right, int bot, color_palette_index color); |
| 104 |
constexpr int opengl_bitmap_use_src_bitmap = 0; |
| 105 |
constexpr int opengl_bitmap_use_dst_canvas = -1; |
| 106 |
bool ogl_ubitmapm_cs(grs_canvas &, int x, int y,int dw, int dh, grs_bitmap &bm, int c); |
| 107 |
bool ogl_ubitmapm_cs(grs_canvas &, int x, int y,int dw, int dh, grs_bitmap &bm, const ogl_colors::array_type &c); |
| 108 |
bool ogl_ubitblt_i(unsigned dw, unsigned dh, unsigned dx, unsigned dy, unsigned sw, unsigned sh, unsigned sx, unsigned sy, const grs_bitmap &src, grs_bitmap &dest, opengl_texture_filter texfilt); |
| 109 |
bool ogl_ubitblt(unsigned w, unsigned h, unsigned dx, unsigned dy, unsigned sx, unsigned sy, const grs_bitmap &src, grs_bitmap &dest); |
| 110 |
void ogl_upixelc(const grs_bitmap &, unsigned x, unsigned y, color_palette_index c); |
| 111 |
color_palette_index ogl_ugpixel(const grs_bitmap &bitmap, unsigned x, unsigned y); |
| 112 |
void ogl_ulinec(grs_canvas &, int left, int top, int right, int bot, int c); |
| 113 |
void _g3_draw_tmap_2(grs_canvas &, std::span<g3_draw_tmap_point *const> pointlist, std::span<const g3s_uvl, 4> uvl_list, std::span<const g3s_lrgb, 4> light_rgb, grs_bitmap &bmbot, grs_bitmap &bm, texture2_rotation_low orient, tmap_drawer_type tmap_drawer_ptr); |
| 114 |
|
| 115 |
} |
| 116 |
#ifdef DXX_BUILD_DESCENT |
| 117 |
namespace dsx { |
| 118 |
void ogl_cache_level_textures(); |
| 119 |
} |
| 120 |
#endif |
| 121 |
|
| 122 |
template <std::size_t N> |
| 123 |
static inline void g3_draw_tmap_2(grs_canvas &canvas, const unsigned nv, const std::array<g3_draw_tmap_point *, N> &pointlist, const std::array<g3s_uvl, N> &uvl_list, const std::array<g3s_lrgb, N> &light_rgb, grs_bitmap &bmbot, grs_bitmap &bm, const texture2_rotation_low orient, const tmap_drawer_type tmap_drawer_ptr) |
| 124 |
{ |
| 125 |
static_assert(N <= MAX_POINTS_PER_POLY, "too many points in tmap"); |
| 126 |
#ifdef DXX_CONSTANT_TRUE |
| 127 |
if (DXX_CONSTANT_TRUE(nv > N)) |
| 128 |
DXX_ALWAYS_ERROR_FUNCTION("reading beyond array"); |
| 129 |
#endif |
| 130 |
if (nv > N) |
| 131 |
return; |
| 132 |
_g3_draw_tmap_2(canvas, std::span(pointlist).first(nv), uvl_list, light_rgb, bmbot, bm, orient, tmap_drawer_ptr); |
| 133 |
} |
| 134 |
|
| 135 |
namespace dcx { |
| 136 |
void ogl_draw_vertex_reticle(grs_canvas &, int cross, int primary, int secondary, int color, int alpha, int size_offs); |
| 137 |
void ogl_toggle_depth_test(int enable); |
| 138 |
void ogl_set_blending(gr_blend); |
| 139 |
} |
| 140 |
|
| 141 |
#endif /* _OGL_INIT_H_ */ |