Skip to content

Commit

Permalink
Fix water rendering
Browse files Browse the repository at this point in the history
Other rendering fixes
Misc bugfixes
  • Loading branch information
Temtaime committed Jun 20, 2021
1 parent aed70ae commit b9b0405
Show file tree
Hide file tree
Showing 25 changed files with 88 additions and 202 deletions.
9 changes: 4 additions & 5 deletions source/perfontain/managers/gui/package.d
Original file line number Diff line number Diff line change
Expand Up @@ -182,13 +182,16 @@ private:

void draw(SubMeshData data)
{
PEstate.culling = false; // TODO: FIX GUI
scope (exit)
PEstate.culling = true;

auto mh = asRC(new MeshHolder(RENDER_GUI, data));
//mh.texs = (cast(Texture) ftex).sliceOne;

{
uint offset;
short n;
glDisable(GL_CULL_FACE);

for (auto cmd = nk__draw_begin(_ctx.ctx, &cmds); (cmd); (cmd) = nk__draw_next(cmd, &cmds, _ctx.ctx))
{
Expand Down Expand Up @@ -235,11 +238,7 @@ private:

}

//logger(`gui draw`);

PE.render.doDraw(_prog, RENDER_GUI, _proj, null, false);
glEnable(GL_CULL_FACE);
//logger(`gui draw 2`);
}

void drawPopups()
Expand Down
6 changes: 2 additions & 4 deletions source/perfontain/managers/render/drawinfo.d
Original file line number Diff line number Diff line change
Expand Up @@ -14,17 +14,15 @@ struct DrawInfo
Matrix4 matrix;
Vector4s scissor;

uint lightStart, lightEnd;

Color color = colorWhite;
ushort id;

ubyte flags, blendingMode = noBlending;
package:
static diff(string val, string cmp = `<`, string as = ``)
{
return `if(` ~ as ~ `(a.` ~ val ~ `) != ` ~ as ~ `(b.` ~ val ~ `)) return `
~ as ~ `(a.` ~ val ~ `) ` ~ cmp ~ as ~ `(b.` ~ val ~ `);`;
return `if(` ~ as ~ `(a.` ~ val ~ `) != ` ~ as ~ `(b.` ~ val ~ `)) return ` ~ as ~ `(a.` ~ val ~ `) ` ~ cmp ~ as ~ `(b.` ~ val
~ `);`;
}

static cmp(ref in DrawInfo a, ref in DrawInfo b)
Expand Down
7 changes: 0 additions & 7 deletions source/perfontain/managers/render/package.d
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
module perfontain.managers.render;

import std, perfontain, perfontain.opengl, perfontain.misc.draw;

public import perfontain.managers.render.drawinfo;
Expand Down Expand Up @@ -128,12 +127,6 @@ private:
if (flags & PROG_DATA_SCISSOR)
add(di.scissor.Vector4i);

if (flags & PROG_DATA_LIGHTS)
{
add(di.lightStart);
add(di.lightEnd);
}

arr[p .. $] = 0;

assert(arr.length == (p + 15) / 16 * 16);
Expand Down
4 changes: 2 additions & 2 deletions source/perfontain/managers/scene/package.d
Original file line number Diff line number Diff line change
Expand Up @@ -174,7 +174,7 @@ package(perfontain):

void computeLights(Texture tex, Program compute, ushort bs)
{
tex.imageBind(0, GL_WRITE_ONLY);
tex.imageBind(0, GL_READ_WRITE);

compute.send(`proj_view_inversed`, _vp.inversed);
compute.bind;
Expand All @@ -189,7 +189,7 @@ package(perfontain):
glDispatchCompute(sz.x, sz.y, 1);
}

glMemoryBarrier(GL_TEXTURE_FETCH_BARRIER_BIT);
glMemoryBarrier(GL_SHADER_IMAGE_ACCESS_BARRIER_BIT);
}

void clear(Vector2s size, uint flags)
Expand Down
10 changes: 3 additions & 7 deletions source/perfontain/managers/scene/renderdata.d
Original file line number Diff line number Diff line change
Expand Up @@ -57,15 +57,14 @@ class SceneRenderData : RCounted
}

if (texShadowsDepth)
_draw.add(ShaderTexture.shadows, texShadowsDepth);

{
_compute = ProgramCreator(ProgramSource.light_compute).create;
_draw.add(ShaderTexture.shadows_depth, texShadowsDepth);
}

if (lightsFull)
{
_depth = ProgramCreator(ProgramSource.depth).create;
_compute = ProgramCreator(ProgramSource.light_compute).create;

VertexBuffer vbo = new VertexBuffer;
{
Expand All @@ -92,12 +91,10 @@ class SceneRenderData : RCounted
auto tex = new Texture(TEX_SHADOW_MAP, PEwindow._size, s);
_lightsDepth = new RenderTarget(tex, null);

_compute.add(ShaderTexture.depth, tex);
_compute.add(ShaderTexture.lights_depth, tex);
}

_ind = new Texture(TEX_RED_UINT, PEwindow._size, s);

_draw.add(ShaderTexture.lights, _ind);
}
}
}
Expand Down Expand Up @@ -140,6 +137,5 @@ private:

RC!Texture _ind;
RC!RenderTarget _lightsDepth, _shadowsDepth;

RC!Program _draw, _compute, _depth, _shadowsDepthProg;
}
4 changes: 2 additions & 2 deletions source/perfontain/managers/settings/package.d
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ final class SettingsManager
}
catch (Exception e)
{
logger.error!`cannot parse setting %s: %s`(name, e.msg);
logger.error!`cannot parse setting %s: %s`(name, e.msg);
}
}
}
Expand Down Expand Up @@ -56,7 +56,7 @@ final class SettingsManager
mixin Setting!(bool, `fullscreen`, false);

mixin Setting!(Lights, `lights`, Lights.global);
mixin Setting!(Shadows, `shadows`, Shadows.high);
mixin Setting!(Shadows, `shadows`, Shadows.medium);

Tuple!(string, `user`, string, `pass`)[] accounts;
private:
Expand Down
33 changes: 13 additions & 20 deletions source/perfontain/managers/state.d
Original file line number Diff line number Diff line change
@@ -1,16 +1,16 @@
module perfontain.managers.state;

import std.array, core.bitop, perfontain, perfontain.opengl, perfontain.config,
perfontain.math.matrix, perfontain.misc;
import std.array, core.bitop, perfontain, perfontain.opengl, perfontain.config, perfontain.math.matrix, perfontain.misc;

final class StateManager
{
this()
{
culling = false; // TODO GUI TEST
culling = true;

if (PE._msaaLevel > 0)
{
msaa = true;
}
}

@property
Expand All @@ -32,6 +32,14 @@ final class StateManager
}
}

void culling(bool b)
{
if (_culling != b)
{
disableEnable(GL_CULL_FACE, _culling = b);
}
}

bool msaa()
{
return _msaa;
Expand Down Expand Up @@ -95,8 +103,7 @@ package(perfontain):
if (_blending && _blendingMode != m)
{
auto modes = unpackModes(_blendingMode = m);
glBlendFuncSeparate(modes.front.blendingModeGL,
modes.back.blendingModeGL, GL_ONE, GL_ONE);
glBlendFuncSeparate(modes.front.blendingModeGL, modes.back.blendingModeGL, GL_ONE, GL_ONE);
}
}

Expand All @@ -109,12 +116,6 @@ package(perfontain):
}
}

struct LayerInfo
{
uint tex, samp;
}

LayerInfo[MAX_LAYERS] _texLayers;
uint _pipeline, _vao, _prog;
private:
static disableEnable(uint v, bool b)
Expand All @@ -133,14 +134,6 @@ private:
}
}

void culling(bool b)
{
if (_culling != b)
{
disableEnable(GL_CULL_FACE, _culling = b);
}
}

Vector2s _viewPort;

ubyte _blendingMode;
Expand Down
4 changes: 1 addition & 3 deletions source/perfontain/managers/texture/texture.d
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ final class Texture : RCounted
{
PE.textures.remove(this);

PEstate._texLayers.each!((ref a) => cas(a.tex, id, 0));
//PEstate._texLayers.each!((ref a) => cas(a.tex, id, 0));

glDeleteTextures(1, &id);
}
Expand Down Expand Up @@ -100,8 +100,6 @@ final class Texture : RCounted

const bind(ubyte idx)
{
auto p = &PEstate._texLayers[idx];

//if (set(p.samp, _samp._id))
{
glBindSampler(idx, _samp._id);
Expand Down
22 changes: 5 additions & 17 deletions source/perfontain/misc/dxt.d
Original file line number Diff line number Diff line change
@@ -1,21 +1,11 @@
module perfontain.misc.dxt;

import
std.range,
std.algorithm,
std.parallelism,

stb.dxt,
stb.image,

perfontain;

import std.range, std.algorithm, std.parallelism, stb.dxt, stb.image, perfontain;

auto dxtTranspType(in Image im)
{
enum D = 10;

return im[].any!(a => a.a > D && a.a < 255 - D) ? TEX_DXT_5 : TEX_DXT_5;
return im[].any!(a => a.a > D && a.a < 255 - D) ? TEX_DXT_5 : TEX_DXT_5; // FIXME: ??????
}

auto makeTexInfo(in Image im, bool mipmaps = true)
Expand All @@ -25,14 +15,12 @@ auto makeTexInfo(in Image im, bool mipmaps = true)

auto makeTexInfo(in Image im, ubyte t, bool mipmaps = true)
{
TextureInfo res = { t };
TextureInfo res = {t};

auto useDXT = t <= TEX_DXT_5;
auto arr = mipmaps ? im.toMipmaps : (&im)[0..1];
auto arr = mipmaps ? im.toMipmaps : (&im)[0 .. 1];

res.levels = arr
.map!(a => TextureData(Vector2s(a.w, a.h), useDXT ? a.dxtCompress(t == TEX_DXT_5) : a[].toByte))
.array;
res.levels = arr.map!(a => TextureData(Vector2s(a.w, a.h), useDXT ? a.dxtCompress(t == TEX_DXT_5) : a[].toByte)).array;

return res;
}
30 changes: 5 additions & 25 deletions source/perfontain/nodes/package.d
Original file line number Diff line number Diff line change
@@ -1,21 +1,6 @@
module perfontain.nodes;

import

std.stdio,
std.range,
std.algorithm,

perfontain,
perfontain.vbo,
perfontain.mesh,
perfontain.misc,
perfontain.math.bbox,
perfontain.config,
perfontain.opengl,
perfontain.math.matrix,
perfontain.shader;

import std.stdio, std.range, std.algorithm, perfontain, perfontain.vbo, perfontain.mesh, perfontain.misc,
perfontain.math.bbox, perfontain.config, perfontain.opengl, perfontain.math.matrix, perfontain.shader;

class Node : RCounted
{
Expand All @@ -29,7 +14,7 @@ class Node : RCounted
//const transBBox() { return bbox * matrix; }
}

void draw(in DrawInfo *di)
void draw(in DrawInfo* di)
{
childs.each!(a => a.draw(di));
}
Expand All @@ -48,11 +33,11 @@ struct FrameOrientation

final class ObjecterNode : Node
{
override void draw(in DrawInfo *di)
override void draw(in DrawInfo* di)
{
DrawInfo m;

if(oris.length)
if (oris.length)
{
auto step = (PE._tick * 2) % oris.back.time;

Expand All @@ -73,9 +58,6 @@ final class ObjecterNode : Node
}

m.mh = mh;

m.lightStart = lightStart;
m.lightEnd = lightEnd;
m.id = id;
m.flags = di.flags;

Expand All @@ -90,7 +72,5 @@ final class ObjecterNode : Node
RC!MeshHolder mh;

Matrix4 matrix;

uint lightStart, lightEnd;
ushort id;
}
4 changes: 3 additions & 1 deletion source/perfontain/opengl/package.d
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,9 @@ string dumpArgs(A...)(A args)
dump ~= dump ? `, ` : null;

static if (isPointer!(typeof(e)))
{
dump ~= format(`0x%X`, cast(size_t)e);
}
else
dump ~= e.to!string;
}
Expand All @@ -31,7 +33,7 @@ string dumpArgs(A...)(A args)

void traceGL(A...)(string func, string file, uint line, A args)
{
//logger.info3(`[trace] %s(%s)`, func, dumpArgs(args));
//logger.info3!`[%s:%u] %s(%s)`(file, line, func, dumpArgs(args));
}

void checkError(A...)(string func, string file, uint line, A args)
Expand Down
2 changes: 0 additions & 2 deletions source/perfontain/program/package.d
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@ enum
PROG_DATA_MODEL = 1,
PROG_DATA_COLOR = 2,
PROG_DATA_NORMAL = 4,
PROG_DATA_LIGHTS = 8,
PROG_DATA_SM_MAT = 16,
PROG_DATA_SCISSOR = 32,
}
Expand All @@ -30,7 +29,6 @@ final class Program : RCounted
tuple(`pe_transforms.transforms[0].color`, PROG_DATA_COLOR),
tuple(`pe_transforms.transforms[0].normal`, PROG_DATA_NORMAL),
tuple(`pe_transforms.transforms[0].scissor`, PROG_DATA_SCISSOR),
tuple(`pe_transforms.transforms[0].lightStart`, PROG_DATA_LIGHTS),
];

foreach (a; Attrs)
Expand Down
5 changes: 2 additions & 3 deletions source/perfontain/program/props.d
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,8 @@ import std;
enum ShaderTexture : ubyte
{
main,
depth,
lights,
shadows,
lights_depth,
shadows_depth,

max
}
Expand Down
Loading

0 comments on commit b9b0405

Please sign in to comment.