forked from organicmaps/organicmaps
Add imGui shaders
Signed-off-by: renderexpert <expert@renderconsulting.co.uk>
This commit is contained in:
parent
466b9365f6
commit
a54f5268cd
16 changed files with 114 additions and 1 deletions
File diff suppressed because one or more lines are too long
Binary file not shown.
10
shaders/GL/imgui.fsh.glsl
Normal file
10
shaders/GL/imgui.fsh.glsl
Normal file
|
@ -0,0 +1,10 @@
|
|||
varying vec2 v_texCoords;
|
||||
varying vec4 v_color;
|
||||
|
||||
uniform sampler2D u_colorTex;
|
||||
|
||||
void main()
|
||||
{
|
||||
LOW_P vec4 color = texture2D(u_colorTex, v_texCoords);
|
||||
gl_FragColor = color * v_color;
|
||||
}
|
19
shaders/GL/imgui.vsh.glsl
Normal file
19
shaders/GL/imgui.vsh.glsl
Normal file
|
@ -0,0 +1,19 @@
|
|||
attribute vec2 a_position;
|
||||
attribute vec2 a_texCoords;
|
||||
attribute vec4 a_color;
|
||||
|
||||
varying vec2 v_texCoords;
|
||||
varying vec4 v_color;
|
||||
|
||||
uniform mat4 u_projection;
|
||||
|
||||
void main()
|
||||
{
|
||||
v_texCoords = a_texCoords;
|
||||
v_color = a_color;
|
||||
gl_Position = vec4(a_position, 0, 1) * u_projection;
|
||||
#ifdef VULKAN
|
||||
gl_Position.y = -gl_Position.y;
|
||||
gl_Position.z = (gl_Position.z + gl_Position.w) * 0.5;
|
||||
#endif
|
||||
}
|
|
@ -53,3 +53,4 @@ TrafficCircle traffic_circle.vsh.glsl traffic_circle.fsh.glsl
|
|||
SmaaEdges smaa_edges.vsh.glsl smaa_edges.fsh.glsl
|
||||
SmaaBlendingWeight smaa_blending_weight.vsh.glsl smaa_blending_weight.fsh.glsl
|
||||
SmaaFinal smaa_final.vsh.glsl smaa_final.fsh.glsl
|
||||
ImGui imgui.vsh.glsl imgui.fsh.glsl
|
||||
|
|
39
shaders/Metal/imgui.metal
Normal file
39
shaders/Metal/imgui.metal
Normal file
|
@ -0,0 +1,39 @@
|
|||
#include <metal_stdlib>
|
||||
#include <simd/simd.h>
|
||||
using namespace metal;
|
||||
|
||||
typedef struct
|
||||
{
|
||||
float2 a_position [[attribute(0)]];
|
||||
float2 a_texCoords [[attribute(1)]];
|
||||
float4 a_color [[attribute(2)]];
|
||||
} Vertex_T;
|
||||
|
||||
typedef struct
|
||||
{
|
||||
float4 position [[position]];
|
||||
float2 texCoords;
|
||||
float4 color;
|
||||
} Fragment_T;
|
||||
|
||||
typedef struct
|
||||
{
|
||||
float4x4 u_projection;
|
||||
} Uniforms_T;
|
||||
|
||||
vertex Fragment_T vsImGui(const Vertex_T in [[stage_in]],
|
||||
constant Uniforms_T & uniforms [[buffer(1)]])
|
||||
{
|
||||
Fragment_T out;
|
||||
out.position = float4(in.a_position, 0.0, 1.0) * uniforms.u_projection;
|
||||
out.texCoords = in.a_texCoords;
|
||||
out.color = in.a_color;
|
||||
return out;
|
||||
}
|
||||
|
||||
fragment float4 fsImGui(const Fragment_T in [[stage_in]],
|
||||
texture2d<float> u_colorTex [[texture(0)]],
|
||||
sampler u_colorTexSampler [[sampler(0)]])
|
||||
{
|
||||
return in.color * u_colorTex.sample(u_colorTexSampler, in.texCoords);
|
||||
}
|
|
@ -230,4 +230,14 @@ void GLProgramParamsSetter::Apply(ref_ptr<dp::GraphicsContext> context,
|
|||
|
||||
Parameter::CheckApply(guard, "u_framebufferMetrics", params.m_framebufferMetrics);
|
||||
}
|
||||
|
||||
void GLProgramParamsSetter::Apply(ref_ptr<dp::GraphicsContext> context,
|
||||
ref_ptr<dp::GpuProgram> program,
|
||||
ImGuiProgramParams const & params)
|
||||
{
|
||||
UNUSED_VALUE(context);
|
||||
UniformsGuard guard(program, params);
|
||||
|
||||
Parameter::CheckApply(guard, "u_projection", params.m_projection);
|
||||
}
|
||||
} // namespace gpu
|
||||
|
|
|
@ -29,5 +29,7 @@ public:
|
|||
ref_ptr<dp::GpuProgram> program, ScreenQuadProgramParams const & params) override;
|
||||
void Apply(ref_ptr<dp::GraphicsContext> context,
|
||||
ref_ptr<dp::GpuProgram> program, SMAAProgramParams const & params) override;
|
||||
void Apply(ref_ptr<dp::GraphicsContext> context,
|
||||
ref_ptr<dp::GpuProgram> program, ImGuiProgramParams const & params) override;
|
||||
};
|
||||
} // namespace gpu
|
||||
|
|
|
@ -31,6 +31,8 @@ public:
|
|||
ScreenQuadProgramParams const & params) override;
|
||||
void Apply(ref_ptr<dp::GraphicsContext> context, ref_ptr<dp::GpuProgram> program,
|
||||
SMAAProgramParams const & params) override;
|
||||
void Apply(ref_ptr<dp::GraphicsContext> context, ref_ptr<dp::GpuProgram> program,
|
||||
ImGuiProgramParams const & params) override;
|
||||
};
|
||||
} // namespace metal
|
||||
} // namespace gpu
|
||||
|
|
|
@ -101,5 +101,12 @@ void MetalProgramParamsSetter::Apply(ref_ptr<dp::GraphicsContext> context,
|
|||
{
|
||||
ApplyBytes(context, program, params);
|
||||
}
|
||||
|
||||
void MetalProgramParamsSetter::Apply(ref_ptr<dp::GraphicsContext> context,
|
||||
ref_ptr<dp::GpuProgram> program,
|
||||
ImGuiProgramParams const & params)
|
||||
{
|
||||
ApplyBytes(context, program, params);
|
||||
}
|
||||
} // namespace metal
|
||||
} // namespace gpu
|
||||
|
|
|
@ -102,6 +102,7 @@ std::array<ProgramInfo, static_cast<size_t>(Program::ProgramsCount)> const kMeta
|
|||
ProgramInfo("vsSmaaEdges", "fsSmaaEdges", {{0, 1}}), // SmaaEdges
|
||||
ProgramInfo("vsSmaaBlendingWeight", "fsSmaaBlendingWeight", {{0, 1}}), // SmaaBlendingWeight
|
||||
ProgramInfo("vsSmaaFinal", "fsSmaaFinal", {{0, 1}}), // SmaaFinal
|
||||
ProgramInfo("vsImGui", "fsImGui", {{0, 2}}), // ImGui
|
||||
}};
|
||||
|
||||
MTLVertexFormat GetFormatByDataType(MTLDataType dataType)
|
||||
|
|
|
@ -18,6 +18,7 @@ void ProgramParams::Init()
|
|||
DebugRectProgramParams::BindPrograms(m_boundParams);
|
||||
ScreenQuadProgramParams::BindPrograms(m_boundParams);
|
||||
SMAAProgramParams::BindPrograms(m_boundParams);
|
||||
ImGuiProgramParams::BindPrograms(m_boundParams);
|
||||
}
|
||||
|
||||
// static
|
||||
|
|
|
@ -222,6 +222,14 @@ struct ALIGNMENT SMAAProgramParams
|
|||
Program::SmaaFinal)
|
||||
};
|
||||
|
||||
struct ALIGNMENT ImGuiProgramParams
|
||||
{
|
||||
glsl::mat4 m_projection;
|
||||
|
||||
BIND_PROGRAMS(ImGuiProgramParams,
|
||||
Program::ImGui)
|
||||
};
|
||||
|
||||
#undef ALIGNMENT
|
||||
|
||||
class ProgramParamsSetter
|
||||
|
@ -248,5 +256,7 @@ public:
|
|||
ref_ptr<dp::GpuProgram> program, ScreenQuadProgramParams const & params) = 0;
|
||||
virtual void Apply(ref_ptr<dp::GraphicsContext> context,
|
||||
ref_ptr<dp::GpuProgram> program, SMAAProgramParams const & params) = 0;
|
||||
virtual void Apply(ref_ptr<dp::GraphicsContext> context,
|
||||
ref_ptr<dp::GpuProgram> program, ImGuiProgramParams const & params) = 0;
|
||||
};
|
||||
} // namespace gpu
|
||||
|
|
|
@ -65,6 +65,7 @@ enum class Program
|
|||
SmaaEdges,
|
||||
SmaaBlendingWeight,
|
||||
SmaaFinal,
|
||||
ImGui,
|
||||
|
||||
ProgramsCount
|
||||
};
|
||||
|
@ -128,6 +129,7 @@ inline std::string DebugPrint(Program p)
|
|||
case Program::SmaaEdges: return "SmaaEdges";
|
||||
case Program::SmaaBlendingWeight: return "SmaaBlendingWeight";
|
||||
case Program::SmaaFinal: return "SmaaFinal";
|
||||
case Program::ImGui: return "ImGui";
|
||||
|
||||
case Program::ProgramsCount:
|
||||
CHECK(false, ("Try to output ProgramsCount"));
|
||||
|
|
|
@ -229,5 +229,12 @@ void VulkanProgramParamsSetter::Apply(ref_ptr<dp::GraphicsContext> context,
|
|||
{
|
||||
ApplyImpl(context, program, params);
|
||||
}
|
||||
|
||||
void VulkanProgramParamsSetter::Apply(ref_ptr<dp::GraphicsContext> context,
|
||||
ref_ptr<dp::GpuProgram> program,
|
||||
ImGuiProgramParams const & params)
|
||||
{
|
||||
ApplyImpl(context, program, params);
|
||||
}
|
||||
} // namespace vulkan
|
||||
} // namespace gpu
|
||||
|
|
|
@ -55,6 +55,8 @@ public:
|
|||
ScreenQuadProgramParams const & params) override;
|
||||
void Apply(ref_ptr<dp::GraphicsContext> context, ref_ptr<dp::GpuProgram> program,
|
||||
SMAAProgramParams const & params) override;
|
||||
void Apply(ref_ptr<dp::GraphicsContext> context, ref_ptr<dp::GpuProgram> program,
|
||||
ImGuiProgramParams const & params) override;
|
||||
|
||||
private:
|
||||
template<typename T>
|
||||
|
|
Loading…
Add table
Reference in a new issue