From 7b54c0078640584b82d93ad445537a9b069dfeb0 Mon Sep 17 00:00:00 2001 From: "coadde [Márcio Alexandre Silva Delgado]" Date: Wed, 7 Oct 2015 03:14:31 -0300 Subject: pcr/reicast-git: update pkg --- pcr/reicast-git/refactor-rend-stuff.patch | 1244 +++++++++++++++++++++++++++++ 1 file changed, 1244 insertions(+) create mode 100644 pcr/reicast-git/refactor-rend-stuff.patch (limited to 'pcr/reicast-git/refactor-rend-stuff.patch') diff --git a/pcr/reicast-git/refactor-rend-stuff.patch b/pcr/reicast-git/refactor-rend-stuff.patch new file mode 100644 index 000000000..187ccb8d0 --- /dev/null +++ b/pcr/reicast-git/refactor-rend-stuff.patch @@ -0,0 +1,1244 @@ +diff -Nur a/core/rend/gles/gles.cpp b/core/rend/gles/gles.cpp +--- a/core/rend/gles/gles.cpp 2015-10-06 21:43:53.047336437 -0300 ++++ b/core/rend/gles/gles.cpp 2015-10-06 21:51:21.723570329 -0300 +@@ -1,27 +1,3 @@ +-#include +-#include "gles.h" +-#include "rend/TexCache.h" +-#include "cfg/cfg.h" +- +-#ifdef TARGET_PANDORA +-#include +-#include +-#include +-#include +- +-#ifndef FBIO_WAITFORVSYNC +- #define FBIO_WAITFORVSYNC _IOW('F', 0x20, __u32) +-#endif +-int fbdev = -1; +-#endif +- +-#ifndef GLES +-#if HOST_OS != OS_DARWIN +-#include +-#pragma comment(lib,"Opengl32.lib") +-#endif +-#endif +- + /* + GL|ES 2 + Slower, smaller subset of gl2 +@@ -54,305 +30,126 @@ + + */ + ++#include ++#include "cfg/cfg.h" + #include "oslib/oslib.h" + #include "rend/rend.h" ++#include "rend/TexCache.h" + #include "hw/pvr/Renderer_if.h" ++#include "deps/libpng/png.h" ++#include "gles.h" ++#include "glshaders.h" + +-void GenSorted(); +- +-float fb_scale_x,fb_scale_y; +- +-#ifndef GLES +-#define attr "in" +-#define vary "out" +-#else +-#define attr "attribute" +-#define vary "varying" ++#ifdef TARGET_PANDORA ++ #include ++ #include ++ #include ++ #include + #endif +-#if 1 + +-//Fragment and vertex shaders code +-//pretty much 1:1 copy of the d3d ones for now +-const char* VertexShaderSource = +-#ifndef GLES +- "#version 140 \n" ++#if !defined(GLES) && HOST_OS != OS_DARWIN ++ #include ++ #pragma comment(lib,"Opengl32.lib") + #endif +-"\ +-/* Vertex constants*/ \n\ +-uniform highp vec4 scale; \n\ +-uniform highp vec4 depth_scale; \n\ +-uniform highp float sp_FOG_DENSITY; \n\ +-/* Vertex input */ \n\ +-" attr " highp vec4 in_pos; \n\ +-" attr " lowp vec4 in_base; \n\ +-" attr " lowp vec4 in_offs; \n\ +-" attr " mediump vec2 in_uv; \n\ +-/* output */ \n\ +-" vary " lowp vec4 vtx_base; \n\ +-" vary " lowp vec4 vtx_offs; \n\ +-" vary " mediump vec2 vtx_uv; \n\ +-" vary " highp vec3 vtx_xyz; \n\ +-void main() \n\ +-{ \n\ +- vtx_base=in_base; \n\ +- vtx_offs=in_offs; \n\ +- vtx_uv=in_uv; \n\ +- vec4 vpos=in_pos; \n\ +- vtx_xyz.xy = vpos.xy; \n\ +- vtx_xyz.z = vpos.z*sp_FOG_DENSITY; \n\ +- vpos.w=1.0/vpos.z; \n\ +- vpos.xy=vpos.xy*scale.xy-scale.zw; \n\ +- vpos.xy*=vpos.w; \n\ +- vpos.z=depth_scale.x+depth_scale.y*vpos.w; \n\ +- gl_Position = vpos; \n\ +-}"; +- + +-#else +- +- +- +-const char* VertexShaderSource = +- "" +- "/* Test Projection Matrix */" +- "" +- "uniform highp mat4 Projection;" +- "" +- "" +- "/* Vertex constants */" +- "" +- "uniform highp float sp_FOG_DENSITY;" +- "uniform highp vec4 scale;" +- "" +- "/* Vertex output */" +- "" +- "attribute highp vec4 in_pos;" +- "attribute lowp vec4 in_base;" +- "attribute lowp vec4 in_offs;" +- "attribute mediump vec2 in_uv;" +- "" +- "/* Transformed input */" +- "" +- "varying lowp vec4 vtx_base;" +- "varying lowp vec4 vtx_offs;" +- "varying mediump vec2 vtx_uv;" +- "varying highp vec3 vtx_xyz;" +- "" +- "void main()" +- "{" +- " vtx_base = in_base;" +- " vtx_offs = in_offs;" +- " vtx_uv = in_uv;" +- "" +- " vec4 vpos = in_pos;" +- " vtx_xyz.xy = vpos.xy; " +- " vtx_xyz.z = vpos.z*sp_FOG_DENSITY; " +- "" +- " vpos.w = 1.0/vpos.z; " +- " vpos.z *= -scale.w; " +- " vpos.xy = vpos.xy*scale.xy-sign(scale.xy); " +- " vpos.xy *= vpos.w; " +- "" +- " gl_Position = vpos;" +- // " gl_Position = vpos * Projection;" +- "}" +- ; ++#define OSD_TEX_W 512 ++#define OSD_TEX_H 256 + ++#define key_CONT_C (1 << 0) ++#define key_CONT_B (1 << 1) ++#define key_CONT_A (1 << 2) ++#define key_CONT_START (1 << 3) ++#define key_CONT_DPAD_UP (1 << 4) ++#define key_CONT_DPAD_DOWN (1 << 5) ++#define key_CONT_DPAD_LEFT (1 << 6) ++#define key_CONT_DPAD_RIGHT (1 << 7) ++#define key_CONT_Z (1 << 8) ++#define key_CONT_Y (1 << 9) ++#define key_CONT_X (1 << 10) ++#define key_CONT_D (1 << 11) ++#define key_CONT_DPAD2_UP (1 << 12) ++#define key_CONT_DPAD2_DOWN (1 << 13) ++#define key_CONT_DPAD2_LEFT (1 << 14) ++#define key_CONT_DPAD2_RIGHT (1 << 15) + +-#endif ++gl_ctx gl; + ++float fb_scale_x; ++float fb_scale_y; ++int screen_width; ++int screen_height; + ++GLuint osd_tex; + ++extern u16 kcode[4]; ++extern u8 rt[4]; ++extern u8 lt[4]; + ++u32 osd_base; ++u32 osd_count; + ++#if defined(_ANDROID) ++ extern float vjoy_pos[14][8]; ++#else ++ float vjoy_pos[14][8]= ++ { ++ {24+0,24+64,64,64}, //LEFT ++ {24+64,24+0,64,64}, //UP ++ {24+128,24+64,64,64}, //RIGHT ++ {24+64,24+128,64,64}, //DOWN ++ ++ {440+0,280+64,64,64}, //X ++ {440+64,280+0,64,64}, //Y ++ {440+128,280+64,64,64}, //B ++ {440+64,280+128,64,64}, //A ++ ++ {320-32,360+32,64,64}, //Start ++ ++ {440,200,90,64}, //RT ++ {542,200,90,64}, //LT ++ ++ {-24,128+224,128,128}, //ANALOG_RING ++ {96,320,64,64}, //ANALOG_POINT ++ {1} ++ }; ++#endif // !_ANDROID + +-/* ++float vjoy_sz[2][14] = { ++ { 64,64,64,64, 64,64,64,64, 64, 90,90, 128, 64 }, ++ { 64,64,64,64, 64,64,64,64, 64, 64,64, 128, 64 }, ++}; + +-cp_AlphaTest 0 1 2 2 +-pp_ClipTestMode -1 0 1 3 6 +-pp_UseAlpha 0 1 2 12 +-pp_Texture 1 +- pp_IgnoreTexA 0 1 2 2 +- pp_ShadInstr 0 1 2 3 4 8 +- pp_Offset 0 1 2 16 +- pp_FogCtrl 0 1 2 3 4 64 +-pp_Texture 0 +- pp_FogCtrl 0 2 3 4 4 +- +-pp_Texture: off -> 12*4=48 shaders +-pp_Texture: on -> 12*64=768 shaders +-Total: 816 shaders +- +-highp float fdecp(highp float flt,out highp float e) \n\ +-{ \n\ +- highp float lg2=log2(flt); //ie , 2.5 \n\ +- highp float frc=fract(lg2); //ie , 0.5 \n\ +- e=lg2-frc; //ie , 2.5-0.5=2 (exp) \n\ +- return pow(2.0,frc); //2^0.5 (manitsa) \n\ +-} \n\ +-lowp float fog_mode2(highp float invW) \n\ +-{ \n\ +- highp float foginvW=invW; \n\ +- foginvW=clamp(foginvW,1.0,255.0); \n\ +- \n\ +- highp float fogexp; //0 ... 7 \n\ +- highp float fogman=fdecp(foginvW, fogexp); //[1,2) mantissa bits. that is 1.m \n\ +- \n\ +- highp float fogman_hi=fogman*16.0-16.0; //[16,32) -16 -> [0,16) \n\ +- highp float fogman_idx=floor(fogman_hi); //[0,15] \n\ +- highp float fogman_blend=fract(fogman_hi); //[0,1) -- can also be fogman_idx-fogman_idx ! \n\ +- highp float fog_idx_fr=fogexp*16.0+fogman_idx; //[0,127] \n\ +- \n\ +- highp float fog_idx_pixel_fr=fog_idx_fr+0.5; \n\ +- highp float fog_idx_pixel_n=fog_idx_pixel_fr/128.0;//normalise to [0.5/128,127.5/128) coordinates \n\ +- \n\ +- //fog is 128x1 texure \n\ +- lowp vec2 fog_coefs=texture2D(fog_table,vec2(fog_idx_pixel_n)).rg; \n\ +- \n\ +- lowp float fog_coef=mix(fog_coefs.r,fog_coefs.g,fogman_blend); \n\ +- \n\ +- return fog_coef; \n\ +-} \n\ +-*/ ++#ifdef TARGET_PANDORA ++ #ifndef FBIO_WAITFORVSYNC ++ #define FBIO_WAITFORVSYNC _IOW('F', 0x20, __u32) ++ #endif + +-#ifndef GLES +-#define FRAGCOL "FragColor" +-#define TEXLOOKUP "texture" +-#define vary "in" +-#else +-#define FRAGCOL "gl_FragColor" +-#define TEXLOOKUP "texture2D" ++ int fbdev = -1; ++ char OSD_Info[128]; ++ int OSD_Delay = 0; ++ char OSD_Counters[256]; ++ int OSD_Counter = 0; ++ GLuint osd_font; + #endif + +- +-const char* PixelPipelineShader = +-#ifndef GLES +- "#version 140 \n" +- "out vec4 FragColor; \n" ++#if !defined(_ANDROID) && !defined(TARGET_NACL32) && HOST_OS==OS_LINUX ++ #define SET_AFNT 1 + #endif +-"\ +-\ +-#define cp_AlphaTest %d \n\ +-#define pp_ClipTestMode %d.0 \n\ +-#define pp_UseAlpha %d \n\ +-#define pp_Texture %d \n\ +-#define pp_IgnoreTexA %d \n\ +-#define pp_ShadInstr %d \n\ +-#define pp_Offset %d \n\ +-#define pp_FogCtrl %d \n\ +-/* Shader program params*/ \n\ +-/* gles has no alpha test stage, so its emulated on the shader */ \n\ +-uniform lowp float cp_AlphaTestValue; \n\ +-uniform lowp vec4 pp_ClipTest; \n\ +-uniform lowp vec3 sp_FOG_COL_RAM,sp_FOG_COL_VERT; \n\ +-uniform highp vec2 sp_LOG_FOG_COEFS; \n\ +-uniform sampler2D tex,fog_table; \n\ +-/* Vertex input*/ \n\ +-" vary " lowp vec4 vtx_base; \n\ +-" vary " lowp vec4 vtx_offs; \n\ +-" vary " mediump vec2 vtx_uv; \n\ +-" vary " highp vec3 vtx_xyz; \n\ +-lowp float fog_mode2(highp float val) \n\ +-{ \n\ +- highp float fog_idx=clamp(val,0.0,127.99); \n\ +- return clamp(sp_LOG_FOG_COEFS.y*log2(fog_idx)+sp_LOG_FOG_COEFS.x,0.001,1.0); //the clamp is required due to yet another bug !\n\ +-} \n\ +-void main() \n\ +-{ \n\ +- lowp vec4 color=vtx_base; \n\ +- #if pp_UseAlpha==0 \n\ +- color.a=1.0; \n\ +- #endif\n\ +- #if pp_FogCtrl==3 \n\ +- color=vec4(sp_FOG_COL_RAM.rgb,fog_mode2(vtx_xyz.z)); \n\ +- #endif\n\ +- #if pp_Texture==1 \n\ +- { \n\ +- lowp vec4 texcol=" TEXLOOKUP "(tex,vtx_uv); \n\ +- \n\ +- #if pp_IgnoreTexA==1 \n\ +- texcol.a=1.0; \n\ +- #endif\n\ +- \n\ +- #if pp_ShadInstr==0 \n\ +- { \n\ +- color.rgb=texcol.rgb; \n\ +- color.a=texcol.a; \n\ +- } \n\ +- #endif\n\ +- #if pp_ShadInstr==1 \n\ +- { \n\ +- color.rgb*=texcol.rgb; \n\ +- color.a=texcol.a; \n\ +- } \n\ +- #endif\n\ +- #if pp_ShadInstr==2 \n\ +- { \n\ +- color.rgb=mix(color.rgb,texcol.rgb,texcol.a); \n\ +- } \n\ +- #endif\n\ +- #if pp_ShadInstr==3 \n\ +- { \n\ +- color*=texcol; \n\ +- } \n\ +- #endif\n\ +- \n\ +- #if pp_Offset==1 \n\ +- { \n\ +- color.rgb+=vtx_offs.rgb; \n\ +- if (pp_FogCtrl==1) \n\ +- color.rgb=mix(color.rgb,sp_FOG_COL_VERT.rgb,vtx_offs.a); \n\ +- } \n\ +- #endif\n\ +- } \n\ +- #endif\n\ +- #if pp_FogCtrl==0 \n\ +- { \n\ +- color.rgb=mix(color.rgb,sp_FOG_COL_RAM.rgb,fog_mode2(vtx_xyz.z)); \n\ +- } \n\ +- #endif\n\ +- #if cp_AlphaTest == 1 \n\ +- if (cp_AlphaTestValue>color.a) discard;\n\ +- #endif \n\ +- //color.rgb=vec3(vtx_xyz.z/255.0);\n\ +- " FRAGCOL "=color; \n\ +-}"; + +-const char* ModifierVolumeShader = +-#ifndef GLES +- "#version 140 \n" +- "out vec4 FragColor; \n" +-#endif +-" \ +-uniform lowp float sp_ShaderColor; \n\ +-/* Vertex input*/ \n\ +-void main() \n\ +-{ \n\ +- " FRAGCOL "=vec4(0.0, 0.0, 0.0, sp_ShaderColor); \n\ +-}"; ++FILE* pngfile; + +-const char* OSD_Shader = +-#ifndef GLES +- "#version 140 \n" +- "out vec4 FragColor; \n" +-#endif +-" \ +-" vary " lowp vec4 vtx_base; \n\ +-" vary " mediump vec2 vtx_uv; \n\ +-/* Vertex input*/ \n\ +-uniform sampler2D tex; \n\ +-void main() \n\ +-{ \n\ +- mediump vec2 uv=vtx_uv; \n\ +- uv.y=1.0-uv.y; \n\ +- " FRAGCOL "=vtx_base*" TEXLOOKUP "(tex,uv.st); \n\n\ +-}"; ++void GenSorted(); + ++bool gl_init(void* wind, void* disp); + +-gl_ctx gl; ++//swap buffers ++void gl_swap(); ++//destroy the gles context and free resources ++void gl_term(); + +-int screen_width; +-int screen_height; ++GLuint gl_CompileShader(const char* shader,GLuint type); ++ ++bool gl_create_resources(); + + #if (HOST_OS != OS_DARWIN) && !defined(TARGET_NACL32) + #ifdef GLES +@@ -843,11 +640,6 @@ + return glIsProgram(s->program)==GL_TRUE; + } + +-GLuint osd_tex; +-#ifdef TARGET_PANDORA +-GLuint osd_font; +-#endif +- + bool gl_create_resources() + { + +@@ -938,51 +730,8 @@ + return true; + } + +-bool gl_init(void* wind, void* disp); +- +-//swap buffers +-void gl_swap(); +-//destroy the gles context and free resources +-void gl_term(); +- +-GLuint gl_CompileShader(const char* shader,GLuint type); +- +-bool gl_create_resources(); +- + //setup + +- +-bool gles_init() +-{ +- +- if (!gl_init((void*)libPvr_GetRenderTarget(), +- (void*)libPvr_GetRenderSurface())) +- return false; +- +- if (!gl_create_resources()) +- return false; +- +-#if defined(GLES) && HOST_OS != OS_DARWIN && !defined(TARGET_NACL32) +- #ifdef TARGET_PANDORA +- fbdev=open("/dev/fb0", O_RDONLY); +- #else +- eglSwapInterval(gl.setup.display,1); +- #endif +-#endif +- +- //clean up all buffers ... +- for (int i=0;i<10;i++) +- { +- glClearColor(0.f, 0.f, 0.f, 0.f); +- glClear(GL_COLOR_BUFFER_BIT); +- gl_swap(); +- } +- +- return true; +-} +- +- +- + float fog_coefs[]={0,0}; + void tryfit(float* x,float* y) + { +@@ -1043,64 +792,6 @@ + //printf("%f\n",B*log(maxdev)/log(2.0)+A); + } + +- +- +-extern u16 kcode[4]; +-extern u8 rt[4],lt[4]; +- +-#define key_CONT_C (1 << 0) +-#define key_CONT_B (1 << 1) +-#define key_CONT_A (1 << 2) +-#define key_CONT_START (1 << 3) +-#define key_CONT_DPAD_UP (1 << 4) +-#define key_CONT_DPAD_DOWN (1 << 5) +-#define key_CONT_DPAD_LEFT (1 << 6) +-#define key_CONT_DPAD_RIGHT (1 << 7) +-#define key_CONT_Z (1 << 8) +-#define key_CONT_Y (1 << 9) +-#define key_CONT_X (1 << 10) +-#define key_CONT_D (1 << 11) +-#define key_CONT_DPAD2_UP (1 << 12) +-#define key_CONT_DPAD2_DOWN (1 << 13) +-#define key_CONT_DPAD2_LEFT (1 << 14) +-#define key_CONT_DPAD2_RIGHT (1 << 15) +- +-u32 osd_base; +-u32 osd_count; +- +- +-#if defined(_ANDROID) +-extern float vjoy_pos[14][8]; +-#else +- +-float vjoy_pos[14][8]= +-{ +- {24+0,24+64,64,64}, //LEFT +- {24+64,24+0,64,64}, //UP +- {24+128,24+64,64,64}, //RIGHT +- {24+64,24+128,64,64}, //DOWN +- +- {440+0,280+64,64,64}, //X +- {440+64,280+0,64,64}, //Y +- {440+128,280+64,64,64}, //B +- {440+64,280+128,64,64}, //A +- +- {320-32,360+32,64,64}, //Start +- +- {440,200,90,64}, //RT +- {542,200,90,64}, //LT +- +- {-24,128+224,128,128}, //ANALOG_RING +- {96,320,64,64}, //ANALOG_POINT +- {1} +-}; +-#endif // !_ANDROID +- +-float vjoy_sz[2][14] = { +- { 64,64,64,64, 64,64,64,64, 64, 90,90, 128, 64 }, +- { 64,64,64,64, 64,64,64,64, 64, 64,64, 128, 64 }, +-}; +- + static void DrawButton(float* xy, u32 state) + { + Vertex vtx; +@@ -1139,12 +830,6 @@ + osd_count+=4; + } + +-static void ClearBG() +-{ +- +-} +- +- + void DrawButton2(float* xy, bool state) { DrawButton(xy,state?0:255); } + #ifdef TARGET_PANDORA + static void DrawCenteredText(float yy, float scale, int transparency, const char* text) +@@ -1247,13 +932,6 @@ + } + #endif + +-#ifdef TARGET_PANDORA +-char OSD_Info[128]; +-int OSD_Delay=0; +-char OSD_Counters[256]; +-int OSD_Counter=0; +-#endif +- + static void OSD_HOOK() + { + osd_base=pvrrc.verts.used(); +@@ -1290,128 +968,95 @@ + #endif + } + +-extern GLuint osd_tex; +-#ifdef TARGET_PANDORA +-extern GLuint osd_font; +-#endif +- +-#define OSD_TEX_W 512 +-#define OSD_TEX_H 256 +- +-void OSD_DRAW() ++/* ++bool rend_single_frame() + { +- #ifndef TARGET_PANDORA +- if (osd_tex) +- { +- float u=0; +- float v=0; +- +- for (int i=0;i<13;i++) +- { +- //umin,vmin,umax,vmax +- vjoy_pos[i][4]=(u+1)/OSD_TEX_W; +- vjoy_pos[i][5]=(v+1)/OSD_TEX_H; +- +- vjoy_pos[i][6]=((u+vjoy_sz[0][i]-1))/OSD_TEX_W; +- vjoy_pos[i][7]=((v+vjoy_sz[1][i]-1))/OSD_TEX_H; +- +- u+=vjoy_sz[0][i]; +- if (u>=OSD_TEX_W) +- { +- u-=OSD_TEX_W; +- v+=vjoy_sz[1][i]; +- } +- //v+=vjoy_pos[i][3]; +- } +- +- verify(glIsProgram(gl.OSD_SHADER.program)); ++ //wait render start only if no frame pending ++ _pvrrc = DequeueRender(); + +- glBindTexture(GL_TEXTURE_2D,osd_tex); +- glUseProgram(gl.OSD_SHADER.program); ++ while (!_pvrrc) ++ { ++ rs.Wait(); ++ _pvrrc = DequeueRender(); ++ } + +- //reset rendering scale +-/* +- float dc_width=640; +- float dc_height=480; ++ bool do_swp=false; ++ //if (kcode[0]&(1<<9)) ++ { + +- float dc2s_scale_h=screen_height/480.0f; +- float ds2s_offs_x=(screen_width-dc2s_scale_h*640)/2; + +- //-1 -> too much to left +- ShaderUniforms.scale_coefs[0]=2.0f/(screen_width/dc2s_scale_h); +- ShaderUniforms.scale_coefs[1]=-2/dc_height; +- ShaderUniforms.scale_coefs[2]=1-2*ds2s_offs_x/(screen_width); +- ShaderUniforms.scale_coefs[3]=-1; ++ //clear up & free data .. ++ tactx_Recycle(_pvrrc); ++ _pvrrc=0; + +- glUniform4fv( gl.OSD_SHADER.scale, 1, ShaderUniforms.scale_coefs); ++ return do_swp; ++} + */ + +- glEnable(GL_BLEND); +- glDisable(GL_DEPTH_TEST); +- glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA); +- +- glDepthMask(false); +- glDepthFunc(GL_ALWAYS); +- +- glDisable(GL_CULL_FACE); +- glDisable(GL_SCISSOR_TEST); +- +- int dfa=osd_count/4; +- +- for (int i=0;i too much to left +- ShaderUniforms.scale_coefs[0]=2.0f/(screen_width/dc2s_scale_h); +- ShaderUniforms.scale_coefs[1]=-2/dc_height; +- ShaderUniforms.scale_coefs[2]=1-2*ds2s_offs_x/(screen_width); +- ShaderUniforms.scale_coefs[3]=-1; ++ bool Process(TA_context* ctx); ++ bool Render(); + +- glUniform4fv( gl.OSD_SHADER.scale, 1, ShaderUniforms.scale_coefs); +-*/ ++ void Present(); + +- glEnable(GL_BLEND); +- glDisable(GL_DEPTH_TEST); +- glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA); ++ void DrawOSD(); + ++ virtual u32 GetTexture(TSP tsp, TCW tcw); ++}; + +- glDepthMask(false); +- glDepthFunc(GL_ALWAYS); ++bool glesrend::Init() ++{ ++ ++ if (!gl_init((void*)libPvr_GetRenderTarget(), (void*)libPvr_GetRenderSurface())) ++ { ++ return false; ++ } + ++ if (!gl_create_resources()) ++ { ++ return false; ++ } + +- glDisable(GL_CULL_FACE); +- glDisable(GL_SCISSOR_TEST); ++ #if defined(GLES) && HOST_OS != OS_DARWIN && !defined(TARGET_NACL32) ++ #ifdef TARGET_PANDORA ++ fbdev = open("/dev/fb0", O_RDONLY); ++ #else ++ eglSwapInterval(gl.setup.display,1); ++ #endif ++ #endif + ++ //clean up all buffers ... ++ for (int i=0;i<10;i++) ++ { ++ glClearColor(0.f, 0.f, 0.f, 0.f); ++ glClear(GL_COLOR_BUFFER_BIT); ++ gl_swap(); ++ } + +- int dfa=osd_count/4; ++ return true; ++} + +- for (int i=0;irend.isRTT) +@@ -1435,7 +1080,7 @@ + return true; + } + +-bool RenderFrame() ++bool glesrend::Render() + { + DoCleanup(); + +@@ -1737,10 +1382,10 @@ + } + else + { +-#if HOST_OS != OS_DARWIN +- //Fix this in a proper way +- glBindFramebuffer(GL_FRAMEBUFFER,0); +-#endif ++ #if HOST_OS != OS_DARWIN ++ //Fix this in a proper way ++ glBindFramebuffer(GL_FRAMEBUFFER,0); ++ #endif + } + + //Clear depth +@@ -1812,68 +1457,93 @@ + return !is_rtt; + } + +-#if !defined(_ANDROID) && !defined(TARGET_NACL32) +-#if HOST_OS==OS_LINUX +-#define SET_AFNT 1 +-#endif +-#endif +- +-extern u16 kcode[4]; ++void glesrend::Present() ++{ ++ gl_swap(); ++ glViewport(0, 0, screen_width, screen_height); ++} + +-/* +-bool rend_single_frame() ++void glesrend::DrawOSD() + { +- //wait render start only if no frame pending +- _pvrrc = DequeueRender(); ++ #ifdef TARGET_PANDORA ++ GLuint osd_texture = osd_font; ++ #else ++ GLuint osd_texture = osd_tex; ++ #endif + +- while (!_pvrrc) ++ if (!osd_texture) + { +- rs.Wait(); +- _pvrrc = DequeueRender(); ++ return; + } + +- bool do_swp=false; +- //if (kcode[0]&(1<<9)) +- { ++ verify(glIsProgram(gl.OSD_SHADER.program)); + ++ #ifndef TARGET_PANDORA ++ float u = 0; ++ float v = 0; ++ ++ for (int i = 0; i < 13; i++) ++ { ++ //umin,vmin,umax,vmax ++ vjoy_pos[i][4]=(u+1)/OSD_TEX_W; ++ vjoy_pos[i][5]=(v+1)/OSD_TEX_H; + +- //clear up & free data .. +- tactx_Recycle(_pvrrc); +- _pvrrc=0; ++ vjoy_pos[i][6]=((u+vjoy_sz[0][i]-1))/OSD_TEX_W; ++ vjoy_pos[i][7]=((v+vjoy_sz[1][i]-1))/OSD_TEX_H; + +- return do_swp; +-} +-*/ ++ u+=vjoy_sz[0][i]; ++ if (u>=OSD_TEX_W) ++ { ++ u-=OSD_TEX_W; ++ v+=vjoy_sz[1][i]; ++ } ++ //v+=vjoy_pos[i][3]; ++ } ++ #endif + ++ glBindTexture(GL_TEXTURE_2D, osd_texture); ++ glUseProgram(gl.OSD_SHADER.program); + +-void rend_set_fb_scale(float x,float y) +-{ +- fb_scale_x=x; +- fb_scale_y=y; +-} ++ /* ++ //reset rendering scale + +-struct glesrend : Renderer +-{ +- bool Init() { return gles_init(); } +- void Resize(int w, int h) { screen_width=w; screen_height=h; } +- void Term() { } ++ float dc_width=640; ++ float dc_height=480; + +- bool Process(TA_context* ctx) { return ProcessFrame(ctx); } +- bool Render() { return RenderFrame(); } ++ float dc2s_scale_h=screen_height/480.0f; ++ float ds2s_offs_x=(screen_width-dc2s_scale_h*640)/2; + +- void Present() { gl_swap(); glViewport(0, 0, screen_width, screen_height); } ++ //-1 -> too much to left ++ ShaderUniforms.scale_coefs[0]=2.0f/(screen_width/dc2s_scale_h); ++ ShaderUniforms.scale_coefs[1]=-2/dc_height; ++ ShaderUniforms.scale_coefs[2]=1-2*ds2s_offs_x/(screen_width); ++ ShaderUniforms.scale_coefs[3]=-1; + +- void DrawOSD() { OSD_DRAW(); } ++ glUniform4fv( gl.OSD_SHADER.scale, 1, ShaderUniforms.scale_coefs); ++ */ + +- virtual u32 GetTexture(TSP tsp, TCW tcw) { +- return gl_GetTexture(tsp, tcw); +- } +-}; ++ glEnable(GL_BLEND); ++ glDisable(GL_DEPTH_TEST); ++ glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA); + ++ glDepthMask(false); ++ glDepthFunc(GL_ALWAYS); + +-#include "deps/libpng/png.h" ++ glDisable(GL_CULL_FACE); ++ glDisable(GL_SCISSOR_TEST); + +-FILE* pngfile; ++ int dfa = osd_count/4; ++ ++ for (int i = 0; i < dfa; i++) ++ { ++ glDrawArrays(GL_TRIANGLE_STRIP, osd_base + i*4, 4); ++ } ++} ++ ++u32 glesrend::GetTexture(TSP tsp, TCW tcw) ++{ ++ return gl_GetTexture(tsp, tcw); ++} + + void png_cstd_read(png_structp png_ptr, png_bytep data, png_size_t length) + { +@@ -2021,5 +1691,4 @@ + return texture; + } + +- + Renderer* rend_GLES2() { return new glesrend(); } +diff -Nur a/core/rend/gles/glshaders.cpp b/core/rend/gles/glshaders.cpp +--- a/core/rend/gles/glshaders.cpp 1969-12-31 21:00:00.000000000 -0300 ++++ b/core/rend/gles/glshaders.cpp 2015-10-06 21:51:21.723570329 -0300 +@@ -0,0 +1,280 @@ ++#ifndef GLES ++#define attr "in" ++#define vary "out" ++#else ++#define attr "attribute" ++#define vary "varying" ++#endif ++#if 1 ++ ++//Fragment and vertex shaders code ++//pretty much 1:1 copy of the d3d ones for now ++const char* VertexShaderSource = ++#ifndef GLES ++ "#version 140 \n" ++#endif ++"\ ++/* Vertex constants*/ \n\ ++uniform highp vec4 scale; \n\ ++uniform highp vec4 depth_scale; \n\ ++uniform highp float sp_FOG_DENSITY; \n\ ++/* Vertex input */ \n\ ++" attr " highp vec4 in_pos; \n\ ++" attr " lowp vec4 in_base; \n\ ++" attr " lowp vec4 in_offs; \n\ ++" attr " mediump vec2 in_uv; \n\ ++/* output */ \n\ ++" vary " lowp vec4 vtx_base; \n\ ++" vary " lowp vec4 vtx_offs; \n\ ++" vary " mediump vec2 vtx_uv; \n\ ++" vary " highp vec3 vtx_xyz; \n\ ++void main() \n\ ++{ \n\ ++ vtx_base=in_base; \n\ ++ vtx_offs=in_offs; \n\ ++ vtx_uv=in_uv; \n\ ++ vec4 vpos=in_pos; \n\ ++ vtx_xyz.xy = vpos.xy; \n\ ++ vtx_xyz.z = vpos.z*sp_FOG_DENSITY; \n\ ++ vpos.w=1.0/vpos.z; \n\ ++ vpos.xy=vpos.xy*scale.xy-scale.zw; \n\ ++ vpos.xy*=vpos.w; \n\ ++ vpos.z=depth_scale.x+depth_scale.y*vpos.w; \n\ ++ gl_Position = vpos; \n\ ++}"; ++ ++ ++#else ++ ++ ++ ++const char* VertexShaderSource = ++ "" ++ "/* Test Projection Matrix */" ++ "" ++ "uniform highp mat4 Projection;" ++ "" ++ "" ++ "/* Vertex constants */" ++ "" ++ "uniform highp float sp_FOG_DENSITY;" ++ "uniform highp vec4 scale;" ++ "" ++ "/* Vertex output */" ++ "" ++ "attribute highp vec4 in_pos;" ++ "attribute lowp vec4 in_base;" ++ "attribute lowp vec4 in_offs;" ++ "attribute mediump vec2 in_uv;" ++ "" ++ "/* Transformed input */" ++ "" ++ "varying lowp vec4 vtx_base;" ++ "varying lowp vec4 vtx_offs;" ++ "varying mediump vec2 vtx_uv;" ++ "varying highp vec3 vtx_xyz;" ++ "" ++ "void main()" ++ "{" ++ " vtx_base = in_base;" ++ " vtx_offs = in_offs;" ++ " vtx_uv = in_uv;" ++ "" ++ " vec4 vpos = in_pos;" ++ " vtx_xyz.xy = vpos.xy; " ++ " vtx_xyz.z = vpos.z*sp_FOG_DENSITY; " ++ "" ++ " vpos.w = 1.0/vpos.z; " ++ " vpos.z *= -scale.w; " ++ " vpos.xy = vpos.xy*scale.xy-sign(scale.xy); " ++ " vpos.xy *= vpos.w; " ++ "" ++ " gl_Position = vpos;" ++ // " gl_Position = vpos * Projection;" ++ "}" ++ ; ++ ++ ++#endif ++ ++/* ++ ++cp_AlphaTest 0 1 2 2 ++pp_ClipTestMode -1 0 1 3 6 ++pp_UseAlpha 0 1 2 12 ++pp_Texture 1 ++ pp_IgnoreTexA 0 1 2 2 ++ pp_ShadInstr 0 1 2 3 4 8 ++ pp_Offset 0 1 2 16 ++ pp_FogCtrl 0 1 2 3 4 64 ++pp_Texture 0 ++ pp_FogCtrl 0 2 3 4 4 ++ ++pp_Texture: off -> 12*4=48 shaders ++pp_Texture: on -> 12*64=768 shaders ++Total: 816 shaders ++ ++highp float fdecp(highp float flt,out highp float e) \n\ ++{ \n\ ++ highp float lg2=log2(flt); //ie , 2.5 \n\ ++ highp float frc=fract(lg2); //ie , 0.5 \n\ ++ e=lg2-frc; //ie , 2.5-0.5=2 (exp) \n\ ++ return pow(2.0,frc); //2^0.5 (manitsa) \n\ ++} \n\ ++lowp float fog_mode2(highp float invW) \n\ ++{ \n\ ++ highp float foginvW=invW; \n\ ++ foginvW=clamp(foginvW,1.0,255.0); \n\ ++ \n\ ++ highp float fogexp; //0 ... 7 \n\ ++ highp float fogman=fdecp(foginvW, fogexp); //[1,2) mantissa bits. that is 1.m \n\ ++ \n\ ++ highp float fogman_hi=fogman*16.0-16.0; //[16,32) -16 -> [0,16) \n\ ++ highp float fogman_idx=floor(fogman_hi); //[0,15] \n\ ++ highp float fogman_blend=fract(fogman_hi); //[0,1) -- can also be fogman_idx-fogman_idx ! \n\ ++ highp float fog_idx_fr=fogexp*16.0+fogman_idx; //[0,127] \n\ ++ \n\ ++ highp float fog_idx_pixel_fr=fog_idx_fr+0.5; \n\ ++ highp float fog_idx_pixel_n=fog_idx_pixel_fr/128.0;//normalise to [0.5/128,127.5/128) coordinates \n\ ++ \n\ ++ //fog is 128x1 texure \n\ ++ lowp vec2 fog_coefs=texture2D(fog_table,vec2(fog_idx_pixel_n)).rg; \n\ ++ \n\ ++ lowp float fog_coef=mix(fog_coefs.r,fog_coefs.g,fogman_blend); \n\ ++ \n\ ++ return fog_coef; \n\ ++} \n\ ++*/ ++ ++#ifndef GLES ++#define FRAGCOL "FragColor" ++#define TEXLOOKUP "texture" ++#define vary "in" ++#else ++#define FRAGCOL "gl_FragColor" ++#define TEXLOOKUP "texture2D" ++#endif ++ ++ ++const char* PixelPipelineShader = ++#ifndef GLES ++ "#version 140 \n" ++ "out vec4 FragColor; \n" ++#endif ++"\ ++\ ++#define cp_AlphaTest %d \n\ ++#define pp_ClipTestMode %d.0 \n\ ++#define pp_UseAlpha %d \n\ ++#define pp_Texture %d \n\ ++#define pp_IgnoreTexA %d \n\ ++#define pp_ShadInstr %d \n\ ++#define pp_Offset %d \n\ ++#define pp_FogCtrl %d \n\ ++/* Shader program params*/ \n\ ++/* gles has no alpha test stage, so its emulated on the shader */ \n\ ++uniform lowp float cp_AlphaTestValue; \n\ ++uniform lowp vec4 pp_ClipTest; \n\ ++uniform lowp vec3 sp_FOG_COL_RAM,sp_FOG_COL_VERT; \n\ ++uniform highp vec2 sp_LOG_FOG_COEFS; \n\ ++uniform sampler2D tex,fog_table; \n\ ++/* Vertex input*/ \n\ ++" vary " lowp vec4 vtx_base; \n\ ++" vary " lowp vec4 vtx_offs; \n\ ++" vary " mediump vec2 vtx_uv; \n\ ++" vary " highp vec3 vtx_xyz; \n\ ++lowp float fog_mode2(highp float val) \n\ ++{ \n\ ++ highp float fog_idx=clamp(val,0.0,127.99); \n\ ++ return clamp(sp_LOG_FOG_COEFS.y*log2(fog_idx)+sp_LOG_FOG_COEFS.x,0.001,1.0); //the clamp is required due to yet another bug !\n\ ++} \n\ ++void main() \n\ ++{ \n\ ++ lowp vec4 color=vtx_base; \n\ ++ #if pp_UseAlpha==0 \n\ ++ color.a=1.0; \n\ ++ #endif\n\ ++ #if pp_FogCtrl==3 \n\ ++ color=vec4(sp_FOG_COL_RAM.rgb,fog_mode2(vtx_xyz.z)); \n\ ++ #endif\n\ ++ #if pp_Texture==1 \n\ ++ { \n\ ++ lowp vec4 texcol=" TEXLOOKUP "(tex,vtx_uv); \n\ ++ \n\ ++ #if pp_IgnoreTexA==1 \n\ ++ texcol.a=1.0; \n\ ++ #endif\n\ ++ \n\ ++ #if pp_ShadInstr==0 \n\ ++ { \n\ ++ color.rgb=texcol.rgb; \n\ ++ color.a=texcol.a; \n\ ++ } \n\ ++ #endif\n\ ++ #if pp_ShadInstr==1 \n\ ++ { \n\ ++ color.rgb*=texcol.rgb; \n\ ++ color.a=texcol.a; \n\ ++ } \n\ ++ #endif\n\ ++ #if pp_ShadInstr==2 \n\ ++ { \n\ ++ color.rgb=mix(color.rgb,texcol.rgb,texcol.a); \n\ ++ } \n\ ++ #endif\n\ ++ #if pp_ShadInstr==3 \n\ ++ { \n\ ++ color*=texcol; \n\ ++ } \n\ ++ #endif\n\ ++ \n\ ++ #if pp_Offset==1 \n\ ++ { \n\ ++ color.rgb+=vtx_offs.rgb; \n\ ++ if (pp_FogCtrl==1) \n\ ++ color.rgb=mix(color.rgb,sp_FOG_COL_VERT.rgb,vtx_offs.a); \n\ ++ } \n\ ++ #endif\n\ ++ } \n\ ++ #endif\n\ ++ #if pp_FogCtrl==0 \n\ ++ { \n\ ++ color.rgb=mix(color.rgb,sp_FOG_COL_RAM.rgb,fog_mode2(vtx_xyz.z)); \n\ ++ } \n\ ++ #endif\n\ ++ #if cp_AlphaTest == 1 \n\ ++ if (cp_AlphaTestValue>color.a) discard;\n\ ++ #endif \n\ ++ //color.rgb=vec3(vtx_xyz.z/255.0);\n\ ++ " FRAGCOL "=color; \n\ ++}"; ++ ++const char* ModifierVolumeShader = ++#ifndef GLES ++ "#version 140 \n" ++ "out vec4 FragColor; \n" ++#endif ++" \ ++uniform lowp float sp_ShaderColor; \n\ ++/* Vertex input*/ \n\ ++void main() \n\ ++{ \n\ ++ " FRAGCOL "=vec4(0.0, 0.0, 0.0, sp_ShaderColor); \n\ ++}"; ++ ++const char* OSD_Shader = ++#ifndef GLES ++ "#version 140 \n" ++ "out vec4 FragColor; \n" ++#endif ++" \ ++" vary " lowp vec4 vtx_base; \n\ ++" vary " mediump vec2 vtx_uv; \n\ ++/* Vertex input*/ \n\ ++uniform sampler2D tex; \n\ ++void main() \n\ ++{ \n\ ++ mediump vec2 uv=vtx_uv; \n\ ++ uv.y=1.0-uv.y; \n\ ++ " FRAGCOL "=vtx_base*" TEXLOOKUP "(tex,uv.st); \n\n\ ++}"; +diff -Nur a/core/rend/gles/glshaders.h b/core/rend/gles/glshaders.h +--- a/core/rend/gles/glshaders.h 1969-12-31 21:00:00.000000000 -0300 ++++ b/core/rend/gles/glshaders.h 2015-10-06 21:51:21.723570329 -0300 +@@ -0,0 +1,5 @@ ++#pragma once ++extern const char* VertexShaderSource; ++extern const char* PixelPipelineShader; ++extern const char* ModifierVolumeShader; ++extern const char* OSD_Shader; +\ No newline at end of file -- cgit v1.2.3-54-g00ecf