Skip to content

Commit

Permalink
ViewPort UI object
Browse files Browse the repository at this point in the history
  • Loading branch information
qreeves committed Feb 11, 2024
1 parent 4e18776 commit 09ab534
Show file tree
Hide file tree
Showing 17 changed files with 465 additions and 248 deletions.
28 changes: 0 additions & 28 deletions config/glsl/hud.cfg
Original file line number Diff line number Diff line change
Expand Up @@ -33,34 +33,6 @@ shader $SHADER_DEFAULT "hudrgb" [
}
]

shader $SHADER_DEFAULT "hudrect" [
attribute vec4 vvertex, vcolor;
attribute vec2 vtexcoord0;
uniform mat4 hudmatrix;
varying vec2 texcoord0;
varying vec4 colorscale;

void main(void)
{
gl_Position = hudmatrix * vvertex;
texcoord0 = vtexcoord0;
colorscale = vcolor;
}
] [
uniform sampler2DRect tex0;
varying vec2 texcoord0;
varying vec4 colorscale;

fragdata(0) vec4 fragcolor;

void main(void)
{
vec4 color = colorscale * texture2DRect(tex0, texcoord0);
if(color.a <= 0.0) discard;
fragcolor = color;
}
]

shader $SHADER_DEFAULT "hudrectrgb" [
attribute vec4 vvertex, vcolor;
attribute vec2 vtexcoord0;
Expand Down
50 changes: 32 additions & 18 deletions config/glsl/init.cfg
Original file line number Diff line number Diff line change
Expand Up @@ -18,36 +18,57 @@ shader $SHADER_DEFAULT "null" [

shader $SHADER_DEFAULT "hud" [
attribute vec4 vvertex, vcolor;
attribute vec3 vhintcolor;
attribute vec2 vtexcoord0, vhintblend;
attribute vec2 vtexcoord0;
uniform mat4 hudmatrix;
varying vec2 texcoord0;
varying vec4 colorscale;
varying vec3 hintcolor;
varying vec2 hintblend;

void main(void)
{
gl_Position = hudmatrix * vvertex;
texcoord0 = vtexcoord0;
colorscale = vcolor;
hintcolor = vhintcolor;
hintblend = vhintblend;
}
] [
uniform sampler2D tex0;
varying vec2 texcoord0;
varying vec4 colorscale;
varying vec3 hintcolor;
varying vec2 hintblend;

fragdata(0) vec4 fragcolor;

void main(void)
{
vec4 diffuse = texture2D(tex0, texcoord0), color = diffuse * colorscale;
if(color.a <= 0.0) discard;
fragcolor = hintblend.x > 0.0 && diffuse.a < hintblend.x ? vec4(mix(color.rgb, hintcolor.rgb, diffuse.a * hintblend.y), color.a) : color;
fragcolor = color;
}
]

shader $SHADER_DEFAULT "hudrect" [
attribute vec4 vvertex, vcolor;
attribute vec2 vtexcoord0;
uniform mat4 hudmatrix;
varying vec2 texcoord0;
varying vec4 colorscale;

void main(void)
{
gl_Position = hudmatrix * vvertex;
texcoord0 = vtexcoord0;
colorscale = vcolor;
}
] [
uniform sampler2DRect tex0;
varying vec2 texcoord0;
varying vec4 colorscale;

fragdata(0) vec4 fragcolor;

void main(void)
{
vec4 color = colorscale * texture2DRect(tex0, texcoord0);
if(color.a <= 0.0) discard;
fragcolor = color;
}
]

Expand Down Expand Up @@ -166,23 +187,18 @@ shader $SHADER_DEFAULT "hudnotexture" [

shader $SHADER_DEFAULT "hudminimap" [
attribute vec4 vvertex, vcolor;
attribute vec3 vhintcolor;
attribute vec2 vtexcoord0, vhintblend;
attribute vec2 vtexcoord0;
uniform mat4 hudmatrix;
varying vec2 screenpos;
varying vec2 texcoord0;
varying vec4 colorscale;
varying vec3 hintcolor;
varying vec2 hintblend;

void main(void)
{
gl_Position = hudmatrix * vvertex;
screenpos = (hudmatrix * vvertex).xy;
texcoord0 = vtexcoord0;
colorscale = vcolor;
hintcolor = vhintcolor;
hintblend = vhintblend;
}
] [
uniform float millis;
Expand All @@ -191,8 +207,6 @@ shader $SHADER_DEFAULT "hudminimap" [
varying vec2 screenpos;
varying vec2 texcoord0;
varying vec4 colorscale;
varying vec3 hintcolor;
varying vec2 hintblend;

fragdata(0) vec4 fragcolor;

Expand Down Expand Up @@ -233,7 +247,7 @@ shader $SHADER_DEFAULT "hudminimap" [
scanlineIntensity += abs(fract(screenpos.y * 120.0) * 2.0 - 1.0);
color.rgb *= 1.0 - (scanlineIntensity * 0.4);

fragcolor = hintblend.x > 0.0 && diffuse.a < hintblend.x ? vec4(mix(color.rgb, hintcolor.rgb, diffuse.a * hintblend.y), color.a) : color;
fragcolor = color;
}
]

Expand Down
4 changes: 3 additions & 1 deletion config/ui/dyn/entity.cfg
Original file line number Diff line number Diff line change
Expand Up @@ -172,7 +172,9 @@ ui_entityedit_dynui = [
uiborderedimageclamped (? $_selected $skinalphatex $skinshadowtex) 0xff000000 0 $ui_texborder $ui_screenborder 0 0 [
uispace $ui_padnormal $ui_padsmall [
uivlist $ui_padsmall [

if (&& (= $_group 0) (=s $_name "Camera")) [
uiviewport $uiname (getentity $uiarg1 4 1) (getentity $uiarg1 4 2) (getentity $uiarg1 4 3) (getentity $uiarg1 4 4) (getentity $uiarg1 4 5) 0.05 0.05
]
uihlist $ui_padsmall [
uiimage (? $_selected "<grey>textures/icons/star" "<grey>textures/icons/dot") 0xFFFFFFFF 0 0.0075 0.0075
uifont $textfontoutline [
Expand Down
5 changes: 3 additions & 2 deletions config/ui/hud/package.cfg
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,6 @@ ui_hud_lastinit = 0

ui_hud_init = [
uistyle clampxy
uiallowinput $arg1
uimenu 0 // not a menu

if (!= $ui_hud_lastinit $totalmillis) [
Expand Down Expand Up @@ -695,7 +694,9 @@ ui_hud_progress = [
]

newui "hud" $SURFACE_VISOR [
ui_hud_init (? $ui_hud_input 2 0)
ui_hud_init
uiallowinput (? $ui_hud_input 2 0)

if $ui_hud_showhud [
uigroup [
uistyle clampxy
Expand Down
43 changes: 21 additions & 22 deletions src/engine/engine.h
Original file line number Diff line number Diff line change
Expand Up @@ -357,7 +357,7 @@ extern float calcfogcull();
namespace modelpreview
{
extern void start(int x, int y, int w, int h, float pitch = -15, float roll = 0, float fov = 0, bool background = true, bool scissor = false, vec translate = vec(0, 0, 0));
extern void end(int outfbo, const vec &skycol = vec(0.1f, 0.1f, 0.1f), const vec &suncol = vec(0.6f, 0.6f, 0.6f), const vec &sundir = vec(0, -1, 2), const vec &excol_ = vec(0.f, 0.f, 0.f), const vec &exdir_ = vec(0, 0, 0));
extern void end(GLuint outfbo, const vec &skycol = vec(0.1f, 0.1f, 0.1f), const vec &suncol = vec(0.6f, 0.6f, 0.6f), const vec &sundir = vec(0, -1, 2), const vec &excol_ = vec(0.f, 0.f, 0.f), const vec &exdir_ = vec(0, 0, 0));
}

struct timer;
Expand Down Expand Up @@ -537,7 +537,7 @@ extern void rendergbuffer(bool depthclear = true);
extern void shadesky();
extern void shadegbuffer();
extern void shademinimap(const vec &color = vec(-1, -1, -1));
extern void shademodelpreview(int outfbo, int x, int y, int w, int h, bool background = true, bool scissor = false, const vec &skycol = vec(0.1f, 0.1f, 0.1f), const vec &suncol = vec(0.6f, 0.6f, 0.6f), const vec &sundir = vec(0, -1, 2), const vec &excol_ = vec(0.f, 0.f, 0.f), const vec &exdir_ = vec(0, 0, 0));
extern void shademodelpreview(GLuint outfbo, int x, int y, int w, int h, bool background = true, bool scissor = false, const vec &skycol = vec(0.1f, 0.1f, 0.1f), const vec &suncol = vec(0.6f, 0.6f, 0.6f), const vec &sundir = vec(0, -1, 2), const vec &excol_ = vec(0.f, 0.f, 0.f), const vec &exdir_ = vec(0, 0, 0));
extern void rendertransparent();
extern void renderao();
extern void loadhdrshaders(int aa = AA_UNUSED);
Expand Down Expand Up @@ -1098,31 +1098,34 @@ extern bvec halocolour;

struct RenderSurface
{
int tclamp = 3, filter = 1, width = 0, height = 0;
GLenum format = GL_RGBA, target = GL_TEXTURE_RECTANGLE;
GLuint origfbo = 0;
int tclamp = 3, filter = 1, width = 0, height = 0, origvieww = 0, origviewh = 0, blitsize = 0;
GLenum format = GL_RGBA, target = GL_TEXTURE_RECTANGLE, blittarget = 0;
GLuint origfbo = 0, blittex = 0, blitfbo = 0;
vector<GLuint> texs, fbos;

RenderSurface() { reset(); }
~RenderSurface() { destroy(); }

void reset();
bool cleanup();
int genbuffers(int wanttex = 1, int wantfbo = -1);
int genbuffers(int wanttex = 1, int wantfbo = -1, GLenum b = 0);

virtual void checkformat(int &w, int &h, GLenum &f, GLenum &t, int &n, int &o);
virtual int setup(int w = 0, int h = 0, GLenum f = GL_RGBA, GLenum t = GL_TEXTURE_RECTANGLE, int wanttex = 1, int wantfbo = -1);
virtual int init(int w = 0, int h = 0, GLenum f = GL_RGBA, GLenum t = GL_TEXTURE_RECTANGLE, int wanttex = 1, int wantfbo = -1);
virtual bool bindtex(int wanttex = 0, int tmu = 0);
virtual bool savefbo(int wantfbo = 0);
virtual int setup(int w = 0, int h = 0, GLenum f = GL_RGBA, GLenum t = GL_TEXTURE_RECTANGLE, int wanttex = 1, int wantfbo = -1, GLenum b = 0);
virtual int init(int w = 0, int h = 0, GLenum f = GL_RGBA, GLenum t = GL_TEXTURE_RECTANGLE, int wanttex = 1, int wantfbo = -1, GLenum b = 0);
virtual bool bindtex(int wanttex = 0, int tmu = -1);
virtual void savefbo();
virtual bool bindfbo(int wantfbo = 0);
virtual int create(int w = 0, int h = 0, GLenum f = GL_RGBA, GLenum t = GL_TEXTURE_RECTANGLE, int wanttex = 1, int wantfbo = -1);
virtual int create(int w = 0, int h = 0, GLenum f = GL_RGBA, GLenum t = GL_TEXTURE_RECTANGLE, int wanttex = 1, int wantfbo = -1, GLenum b = 0);
virtual bool destroy();
virtual bool render();
virtual bool render(int w = 0, int h = 0, GLenum f = GL_RGBA, GLenum t = GL_TEXTURE_RECTANGLE, int wanttex = 1, int wantfbo = -1, GLenum b = 0);
virtual bool swap(int wantfbo = 0);
virtual bool draw(int x = 0, int y = 0, int w = 0, int h = 0);
virtual bool blit(int index = 0, bool restore = false);
virtual bool setblit(int tmu = -1);
virtual void debug(int w, int h, int wanttex = 0, bool large = false);
virtual bool save(const char *name, int w, int h);
virtual bool saveblit(const char *name, int w, int h);
virtual void restorefbo();
};

Expand All @@ -1138,9 +1141,9 @@ struct HaloSurface : RenderSurface
bool check(bool check, bool val);

void checkformat(int &w, int &h, GLenum &f, GLenum &t, int &n, int &o) override;
int create(int w = 0, int h = 0, GLenum f = GL_RGBA, GLenum t = GL_TEXTURE_RECTANGLE, int wanttex = 1, int wantfbo = -1) override;
int create(int w = 0, int h = 0, GLenum f = GL_RGBA, GLenum t = GL_TEXTURE_RECTANGLE, int wanttex = 1, int wantfbo = -1, GLenum b = 0) override;
bool destroy() override;
bool render() override;
bool render(int w = 0, int h = 0, GLenum f = GL_RGBA, GLenum t = GL_TEXTURE_RECTANGLE, int wanttex = 1, int wantfbo = -1, GLenum b = 0) override;
bool swap(int wantfbo = 0) override;
bool draw(int x = 0, int y = 0, int w = 0, int h = 0) override;
};
Expand All @@ -1166,8 +1169,8 @@ struct HazeSurface : RenderSurface
bool check();

void checkformat(int &w, int &h, GLenum &f, GLenum &t, int &n, int &o) override;
int create(int w = 0, int h = 0, GLenum f = GL_RGBA, GLenum t = GL_TEXTURE_RECTANGLE, int wanttex = 1, int wantfbo = -1) override;
bool render() override;
int create(int w = 0, int h = 0, GLenum f = GL_RGBA, GLenum t = GL_TEXTURE_RECTANGLE, int wanttex = 1, int wantfbo = -1, GLenum b = 0) override;
bool render(int w = 0, int h = 0, GLenum f = GL_RGBA, GLenum t = GL_TEXTURE_RECTANGLE, int wanttex = 1, int wantfbo = -1, GLenum b = 0) override;
};
extern HazeSurface hazesurf;

Expand All @@ -1189,7 +1192,7 @@ struct VisorSurface : RenderSurface
void coords(float cx, float cy, float &vx, float &vy, bool back = false);

void checkformat(int &w, int &h, GLenum &f, GLenum &t, int &n, int &o) override;
bool render() override;
bool render(int w = 0, int h = 0, GLenum f = GL_RGBA, GLenum t = GL_TEXTURE_RECTANGLE, int wanttex = MAX, int wantfbo = -1, GLenum b = 0) override;
};
extern VisorSurface visorsurf;

Expand All @@ -1199,13 +1202,9 @@ struct ViewSurface : RenderSurface
float yaw = 0.0f, pitch = 0.0f, roll = 0.0f, fov = 90.0f, ratio = 1.0f, nearpoint = 0.54f, farscale = 1.0f;

ViewSurface() { reset(); }
ViewSurface(const vec &o, float y = 0.0f, float p = 0.0f, float r = 0.0f, float f = 90.0f, float t = 1.0f, float n = 0.54f, float s = 1.0f) : worldpos(o), yaw(y), pitch(p), roll(r), fov(f), ratio(t), nearpoint(n), farscale(s) { reset(); }
~ViewSurface() { destroy(); }

void checkformat(int &w, int &h, GLenum &f, GLenum &t, int &n, int &o) override;
int create(int w = 0, int h = 0, GLenum f = GL_RGBA, GLenum t = GL_TEXTURE_RECTANGLE, int wanttex = 1, int wantfbo = -1) override;
bool destroy() override;
bool render() override;
bool render(int w = 0, int h = 0, GLenum f = GL_RGB, GLenum t = GL_TEXTURE_RECTANGLE, int wanttex = 1, int wantfbo = 1, GLenum b = 0) override;
};

#endif // STANDALONE
Expand Down
2 changes: 1 addition & 1 deletion src/engine/main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1288,8 +1288,8 @@ int main(int argc, char **argv)
curtextscale = textscale;
int elapsed = updatetimer(true);
updatefps(frameloops, elapsed);
UI::poke();
cdpi::runframe();
UI::poke(true);
checkinput();
tryedit();

Expand Down
Loading

0 comments on commit 09ab534

Please sign in to comment.