2013-12-19 17:10:14 +00:00
|
|
|
#pragma once
|
|
|
|
#include "rend/rend.h"
|
|
|
|
|
2014-01-21 22:12:04 +00:00
|
|
|
|
|
|
|
#ifdef GLES
|
2015-07-28 11:09:27 +00:00
|
|
|
#if defined(TARGET_IPHONE) //apple-specific ogles2 headers
|
2014-12-17 18:13:05 +00:00
|
|
|
//#include <APPLE/egl.h>
|
2014-05-20 22:58:41 +00:00
|
|
|
#include <OpenGLES/ES2/gl.h>
|
|
|
|
#include <OpenGLES/ES2/glext.h>
|
|
|
|
#else
|
2015-07-28 11:09:27 +00:00
|
|
|
#if !defined(TARGET_NACL32)
|
2014-05-20 23:00:54 +00:00
|
|
|
#include <EGL/egl.h>
|
2015-07-28 11:09:27 +00:00
|
|
|
#endif
|
2013-12-19 17:10:14 +00:00
|
|
|
#include <GLES2/gl2.h>
|
|
|
|
#include <GLES2/gl2ext.h>
|
2014-05-20 22:58:41 +00:00
|
|
|
#endif
|
2013-12-19 17:10:14 +00:00
|
|
|
|
|
|
|
#ifndef GL_NV_draw_path
|
|
|
|
//IMGTEC GLES emulation
|
|
|
|
#pragma comment(lib,"libEGL.lib")
|
|
|
|
#pragma comment(lib,"libGLESv2.lib")
|
|
|
|
#else /* NV gles emulation*/
|
|
|
|
#pragma comment(lib,"libGLES20.lib")
|
2014-01-21 22:12:04 +00:00
|
|
|
#endif
|
2013-12-19 17:10:14 +00:00
|
|
|
|
2015-08-05 19:04:17 +00:00
|
|
|
#else
|
|
|
|
#if HOST_OS == OS_DARWIN
|
|
|
|
#include <OpenGL/gl3.h>
|
2014-01-21 22:12:04 +00:00
|
|
|
#else
|
2014-12-30 11:20:51 +00:00
|
|
|
#include <GL3/gl3w.h>
|
2013-12-19 17:10:14 +00:00
|
|
|
#endif
|
2015-08-05 19:04:17 +00:00
|
|
|
#endif
|
2014-01-21 22:12:04 +00:00
|
|
|
|
2018-07-18 14:01:40 +00:00
|
|
|
#ifndef GL_UNSIGNED_INT_8_8_8_8
|
|
|
|
#define GL_UNSIGNED_INT_8_8_8_8 0x8035
|
|
|
|
#endif
|
2014-01-21 22:12:04 +00:00
|
|
|
|
2018-05-15 09:54:14 +00:00
|
|
|
#define glCheck() do { if (unlikely(settings.validate.OpenGlChecks)) { verify(glGetError()==GL_NO_ERROR); } } while(0)
|
2015-05-07 23:06:40 +00:00
|
|
|
#define eglCheck() false
|
2013-12-19 17:10:14 +00:00
|
|
|
|
|
|
|
#define VERTEX_POS_ARRAY 0
|
|
|
|
#define VERTEX_COL_BASE_ARRAY 1
|
|
|
|
#define VERTEX_COL_OFFS_ARRAY 2
|
|
|
|
#define VERTEX_UV_ARRAY 3
|
2018-10-04 08:29:23 +00:00
|
|
|
// OIT only
|
|
|
|
#define VERTEX_COL_BASE1_ARRAY 4
|
|
|
|
#define VERTEX_COL_OFFS1_ARRAY 5
|
|
|
|
#define VERTEX_UV1_ARRAY 6
|
2013-12-19 17:10:14 +00:00
|
|
|
|
2018-08-01 17:43:01 +00:00
|
|
|
#ifndef GL_UNSIGNED_INT_8_8_8_8
|
|
|
|
#define GL_UNSIGNED_INT_8_8_8_8 0x8035
|
|
|
|
#endif
|
2013-12-19 17:10:14 +00:00
|
|
|
|
|
|
|
//vertex types
|
|
|
|
extern u32 gcflip;
|
2018-05-04 16:18:04 +00:00
|
|
|
extern float scale_x, scale_y;
|
2013-12-19 17:10:14 +00:00
|
|
|
|
|
|
|
|
|
|
|
void DrawStrips();
|
|
|
|
|
|
|
|
struct PipelineShader
|
|
|
|
{
|
|
|
|
GLuint program;
|
|
|
|
|
|
|
|
GLuint scale,depth_scale;
|
2018-09-04 16:37:59 +00:00
|
|
|
GLuint extra_depth_scale;
|
2013-12-19 17:10:14 +00:00
|
|
|
GLuint pp_ClipTest,cp_AlphaTestValue;
|
2018-06-05 10:18:09 +00:00
|
|
|
GLuint sp_FOG_COL_RAM,sp_FOG_COL_VERT,sp_FOG_DENSITY;
|
2018-07-03 18:36:13 +00:00
|
|
|
GLuint trilinear_alpha;
|
2018-09-01 10:56:37 +00:00
|
|
|
GLuint fog_clamp_min, fog_clamp_max;
|
2013-12-19 17:10:14 +00:00
|
|
|
|
|
|
|
//
|
|
|
|
u32 cp_AlphaTest; s32 pp_ClipTestMode;
|
|
|
|
u32 pp_Texture, pp_UseAlpha, pp_IgnoreTexA, pp_ShadInstr, pp_Offset, pp_FogCtrl;
|
2018-07-02 13:23:47 +00:00
|
|
|
bool pp_Gouraud, pp_BumpMap;
|
2018-09-01 10:56:37 +00:00
|
|
|
bool fog_clamping;
|
2018-11-23 21:33:51 +00:00
|
|
|
bool trilinear;
|
2013-12-19 17:10:14 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
|
|
|
|
struct gl_ctx
|
|
|
|
{
|
2015-07-28 21:45:16 +00:00
|
|
|
#if defined(GLES) && HOST_OS != OS_DARWIN && !defined(TARGET_NACL32)
|
2013-12-19 17:10:14 +00:00
|
|
|
struct
|
|
|
|
{
|
|
|
|
EGLNativeWindowType native_wind;
|
|
|
|
EGLNativeDisplayType native_disp;
|
|
|
|
EGLDisplay display;
|
|
|
|
EGLSurface surface;
|
|
|
|
EGLContext context;
|
|
|
|
} setup;
|
2014-01-21 22:12:04 +00:00
|
|
|
#endif
|
2013-12-19 17:10:14 +00:00
|
|
|
|
|
|
|
struct
|
|
|
|
{
|
|
|
|
GLuint program;
|
|
|
|
|
2018-05-12 12:39:06 +00:00
|
|
|
GLuint scale,depth_scale;
|
2018-09-04 16:37:59 +00:00
|
|
|
GLuint extra_depth_scale;
|
2013-12-19 17:10:14 +00:00
|
|
|
GLuint sp_ShaderColor;
|
|
|
|
|
|
|
|
} modvol_shader;
|
|
|
|
|
2018-11-23 21:33:51 +00:00
|
|
|
PipelineShader pogram_table[24576];
|
2013-12-19 17:10:14 +00:00
|
|
|
struct
|
|
|
|
{
|
2018-05-12 12:39:06 +00:00
|
|
|
GLuint program,scale,depth_scale;
|
2018-09-04 16:37:59 +00:00
|
|
|
GLuint extra_depth_scale;
|
2013-12-19 17:10:14 +00:00
|
|
|
} OSD_SHADER;
|
|
|
|
|
|
|
|
struct
|
|
|
|
{
|
|
|
|
GLuint geometry,modvols,idxs,idxs2;
|
2014-06-26 21:51:57 +00:00
|
|
|
#ifndef GLES
|
|
|
|
GLuint vao;
|
|
|
|
#endif
|
2013-12-19 17:10:14 +00:00
|
|
|
} vbo;
|
|
|
|
|
2018-08-07 07:44:52 +00:00
|
|
|
const char *gl_version;
|
|
|
|
const char *glsl_version_header;
|
|
|
|
int gl_major;
|
|
|
|
bool is_gles;
|
|
|
|
GLuint fog_image_format;
|
2018-12-13 21:26:25 +00:00
|
|
|
GLenum index_type;
|
2019-02-14 11:40:17 +00:00
|
|
|
bool swap_buffer_not_preserved;
|
2018-12-13 21:26:25 +00:00
|
|
|
|
|
|
|
size_t get_index_size() { return index_type == GL_UNSIGNED_INT ? sizeof(u32) : sizeof(u16); }
|
2013-12-19 17:10:14 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
extern gl_ctx gl;
|
2018-08-26 14:58:10 +00:00
|
|
|
extern GLuint fbTextureId;
|
2018-10-04 08:29:23 +00:00
|
|
|
extern float fb_scale_x, fb_scale_y;
|
2013-12-19 17:10:14 +00:00
|
|
|
|
2015-08-05 00:43:40 +00:00
|
|
|
GLuint gl_GetTexture(TSP tsp,TCW tcw);
|
2015-08-05 15:02:34 +00:00
|
|
|
struct text_info {
|
|
|
|
u16* pdata;
|
|
|
|
u32 width;
|
|
|
|
u32 height;
|
|
|
|
u32 textype; // 0 565, 1 1555, 2 4444
|
|
|
|
};
|
2018-10-04 12:04:15 +00:00
|
|
|
enum ModifierVolumeMode { Xor, Or, Inclusion, Exclusion, ModeCount };
|
2015-08-05 15:02:34 +00:00
|
|
|
|
2018-10-04 08:29:23 +00:00
|
|
|
bool gl_init(void* wind, void* disp);
|
2018-10-04 12:49:20 +00:00
|
|
|
void gl_load_osd_resources();
|
2018-10-04 08:29:23 +00:00
|
|
|
void gl_swap();
|
2018-10-04 10:32:26 +00:00
|
|
|
bool ProcessFrame(TA_context* ctx);
|
2018-10-04 12:49:20 +00:00
|
|
|
void UpdateFogTexture(u8 *fog_table, GLenum texture_slot, GLint fog_image_format);
|
2019-02-14 11:40:17 +00:00
|
|
|
void save_current_frame();
|
|
|
|
bool render_last_frame();
|
2018-10-04 08:29:23 +00:00
|
|
|
|
2015-08-05 15:02:34 +00:00
|
|
|
text_info raw_GetTexture(TSP tsp, TCW tcw);
|
2018-10-29 17:02:47 +00:00
|
|
|
void killtex();
|
2014-05-08 01:29:14 +00:00
|
|
|
void CollectCleanup();
|
|
|
|
void DoCleanup();
|
2018-05-10 19:28:20 +00:00
|
|
|
void SortPParams(int first, int count);
|
2018-10-04 08:29:23 +00:00
|
|
|
void SetCull(u32 CullMode);
|
2018-10-04 10:32:26 +00:00
|
|
|
s32 SetTileClip(u32 val, GLint uniform);
|
2018-10-04 12:04:15 +00:00
|
|
|
void SetMVS_Mode(ModifierVolumeMode mv_mode, ISP_Modvol ispc);
|
2014-05-08 01:29:14 +00:00
|
|
|
|
2013-12-19 17:10:14 +00:00
|
|
|
void BindRTT(u32 addy, u32 fbw, u32 fbh, u32 channels, u32 fmt);
|
2018-05-08 16:47:00 +00:00
|
|
|
void ReadRTTBuffer();
|
2018-08-26 14:58:10 +00:00
|
|
|
void RenderFramebuffer();
|
|
|
|
void DrawFramebuffer(float w, float h);
|
|
|
|
|
2019-02-13 19:29:49 +00:00
|
|
|
void HideOSD();
|
2018-10-04 08:29:23 +00:00
|
|
|
void OSD_HOOK();
|
2018-10-04 12:49:20 +00:00
|
|
|
void OSD_DRAW(GLuint shader_program);
|
2013-12-19 17:10:14 +00:00
|
|
|
int GetProgramID(u32 cp_AlphaTest, u32 pp_ClipTestMode,
|
|
|
|
u32 pp_Texture, u32 pp_UseAlpha, u32 pp_IgnoreTexA, u32 pp_ShadInstr, u32 pp_Offset,
|
2018-11-23 21:33:51 +00:00
|
|
|
u32 pp_FogCtrl, bool pp_Gouraud, bool pp_BumpMap, bool fog_clamping, bool trilinear);
|
2013-12-19 17:10:14 +00:00
|
|
|
|
2018-10-04 08:29:23 +00:00
|
|
|
GLuint gl_CompileShader(const char* shader, GLuint type);
|
|
|
|
GLuint gl_CompileAndLink(const char* VertexShader, const char* FragmentShader);
|
2013-12-24 00:56:44 +00:00
|
|
|
bool CompilePipelineShader(PipelineShader* s);
|
2013-12-19 17:10:14 +00:00
|
|
|
#define TEXTURE_LOAD_ERROR 0
|
2018-12-30 17:42:55 +00:00
|
|
|
u8* loadPNGData(const string& subpath, int &width, int &height, bool bottom_to_top = true);
|
|
|
|
GLuint loadPNG(const string& subpath, int &width, int &height, bool bottom_to_top = true);
|
2018-06-26 12:24:45 +00:00
|
|
|
|
2018-07-03 18:36:13 +00:00
|
|
|
extern struct ShaderUniforms_t
|
|
|
|
{
|
|
|
|
float PT_ALPHA;
|
|
|
|
float scale_coefs[4];
|
|
|
|
float depth_coefs[4];
|
2018-09-04 16:37:59 +00:00
|
|
|
float extra_depth_scale;
|
2018-07-03 18:36:13 +00:00
|
|
|
float fog_den_float;
|
|
|
|
float ps_FOG_COL_RAM[3];
|
|
|
|
float ps_FOG_COL_VERT[3];
|
|
|
|
float trilinear_alpha;
|
2018-09-01 10:56:37 +00:00
|
|
|
float fog_clamp_min[4];
|
|
|
|
float fog_clamp_max[4];
|
2018-07-03 18:36:13 +00:00
|
|
|
|
|
|
|
void Set(PipelineShader* s)
|
|
|
|
{
|
|
|
|
if (s->cp_AlphaTestValue!=-1)
|
|
|
|
glUniform1f(s->cp_AlphaTestValue,PT_ALPHA);
|
|
|
|
|
|
|
|
if (s->scale!=-1)
|
|
|
|
glUniform4fv( s->scale, 1, scale_coefs);
|
|
|
|
|
|
|
|
if (s->depth_scale!=-1)
|
|
|
|
glUniform4fv( s->depth_scale, 1, depth_coefs);
|
|
|
|
|
2018-09-04 16:37:59 +00:00
|
|
|
if (s->extra_depth_scale != -1)
|
|
|
|
glUniform1f(s->extra_depth_scale, extra_depth_scale);
|
|
|
|
|
2018-07-03 18:36:13 +00:00
|
|
|
if (s->sp_FOG_DENSITY!=-1)
|
|
|
|
glUniform1f( s->sp_FOG_DENSITY,fog_den_float);
|
|
|
|
|
|
|
|
if (s->sp_FOG_COL_RAM!=-1)
|
|
|
|
glUniform3fv( s->sp_FOG_COL_RAM, 1, ps_FOG_COL_RAM);
|
|
|
|
|
|
|
|
if (s->sp_FOG_COL_VERT!=-1)
|
|
|
|
glUniform3fv( s->sp_FOG_COL_VERT, 1, ps_FOG_COL_VERT);
|
|
|
|
|
|
|
|
if (s->trilinear_alpha != -1)
|
|
|
|
glUniform1f(s->trilinear_alpha, trilinear_alpha);
|
2018-09-01 10:56:37 +00:00
|
|
|
|
|
|
|
if (s->fog_clamp_min != -1)
|
|
|
|
glUniform4fv(s->fog_clamp_min, 1, fog_clamp_min);
|
|
|
|
if (s->fog_clamp_max != -1)
|
|
|
|
glUniform4fv(s->fog_clamp_max, 1, fog_clamp_max);
|
2018-07-03 18:36:13 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
} ShaderUniforms;
|
|
|
|
|
2018-10-04 08:29:23 +00:00
|
|
|
// Render to texture
|
|
|
|
struct FBT
|
|
|
|
{
|
|
|
|
u32 TexAddr;
|
|
|
|
GLuint depthb,stencilb;
|
|
|
|
GLuint tex;
|
|
|
|
GLuint fbo;
|
|
|
|
};
|
|
|
|
|
|
|
|
extern FBT fb_rtt;
|
2018-12-30 17:42:55 +00:00
|
|
|
|
|
|
|
struct PvrTexInfo;
|
|
|
|
template <class pixel_type> class PixelBuffer;
|
|
|
|
typedef void TexConvFP(PixelBuffer<u16>* pb,u8* p_in,u32 Width,u32 Height);
|
|
|
|
typedef void TexConvFP32(PixelBuffer<u32>* pb,u8* p_in,u32 Width,u32 Height);
|
|
|
|
|
|
|
|
struct TextureCacheData
|
|
|
|
{
|
|
|
|
TSP tsp; //dreamcast texture parameters
|
|
|
|
TCW tcw;
|
|
|
|
|
|
|
|
GLuint texID; //gl texture
|
|
|
|
u16* pData;
|
|
|
|
int tex_type;
|
|
|
|
|
|
|
|
u32 Lookups;
|
|
|
|
|
|
|
|
//decoded texture info
|
|
|
|
u32 sa; //pixel data start address in vram (might be offset for mipmaps/etc)
|
|
|
|
u32 sa_tex; //texture data start address in vram
|
|
|
|
u32 w,h; //width & height of the texture
|
|
|
|
u32 size; //size, in bytes, in vram
|
|
|
|
|
|
|
|
PvrTexInfo* tex;
|
|
|
|
TexConvFP* texconv;
|
|
|
|
TexConvFP32* texconv32;
|
|
|
|
|
|
|
|
u32 dirty;
|
|
|
|
vram_block* lock_block;
|
|
|
|
|
|
|
|
u32 Updates;
|
|
|
|
|
|
|
|
//used for palette updates
|
|
|
|
u32 palette_hash; // Palette hash at time of last update
|
|
|
|
u32 indirect_color_ptr; //palette color table index for pal. tex
|
|
|
|
//VQ quantizers table for VQ tex
|
|
|
|
//a texture can't be both VQ and PAL at the same time
|
|
|
|
u32 texture_hash; // xxhash of texture data, used for custom textures
|
|
|
|
u8* custom_image_data; // loaded custom image data
|
|
|
|
u32 custom_width;
|
|
|
|
u32 custom_height;
|
2018-12-30 18:19:27 +00:00
|
|
|
bool custom_load_in_progress;
|
2018-12-30 17:42:55 +00:00
|
|
|
|
|
|
|
void PrintTextureName();
|
|
|
|
|
|
|
|
bool IsPaletted()
|
|
|
|
{
|
|
|
|
return tcw.PixelFmt == PixelPal4 || tcw.PixelFmt == PixelPal8;
|
|
|
|
}
|
|
|
|
|
|
|
|
void Create(bool isGL);
|
|
|
|
void ComputeHash();
|
|
|
|
void Update();
|
|
|
|
void UploadToGPU(GLuint textype, int width, int height, u8 *temp_tex_buffer);
|
|
|
|
void CheckCustomTexture();
|
|
|
|
//true if : dirty or paletted texture and hashes don't match
|
|
|
|
bool NeedsUpdate();
|
2018-12-30 18:19:27 +00:00
|
|
|
bool Delete();
|
2018-12-30 17:42:55 +00:00
|
|
|
};
|