This commit is contained in:
Mikulas Florek 2020-11-26 20:25:14 +01:00
parent e7116590df
commit 0c6415dc45
14 changed files with 241 additions and 215 deletions

View file

@ -915,8 +915,8 @@ inline void getOptionalFlagField(lua_State* L, int idx, const char* field_name,
value = toType<bool>(L, -1);
}
lua_pop(L, 1);
if (value) *out |= flag;
else *out &= ~flag;
if (value) *out = *out | flag;
else *out = *out & ~flag;
}
inline bool getOptionalStringField(lua_State* L, int idx, const char* field_name, Span<char> out)

View file

@ -953,9 +953,9 @@ struct CaptureImpostorJob : Renderer::RenderJob {
gpu::BufferHandle pass_buf = gpu::allocBufferHandle();
gpu::BufferHandle ub = gpu::allocBufferHandle();
gpu::createBuffer(ub, (u32)gpu::BufferFlags::UNIFORM_BUFFER, 512, nullptr);
gpu::createBuffer(ub, gpu::BufferFlags::UNIFORM_BUFFER, 512, nullptr);
const u32 pass_buf_size = (sizeof(PassState) + 255) & ~255;
gpu::createBuffer(pass_buf, (u32)gpu::BufferFlags::UNIFORM_BUFFER, pass_buf_size, nullptr);
gpu::createBuffer(pass_buf, gpu::BufferFlags::UNIFORM_BUFFER, pass_buf_size, nullptr);
gpu::bindUniformBuffer(1, pass_buf, 0, pass_buf_size);
gpu::bindUniformBuffer(4, ub, 0, 512);
@ -968,13 +968,13 @@ struct CaptureImpostorJob : Renderer::RenderJob {
m_tile_size->x = (m_tile_size->x + 3) & ~3;
m_tile_size->y = (m_tile_size->y + 3) & ~3;
const IVec2 texture_size = m_tile_size.value * IMPOSTOR_COLS;
gpu::createTexture(gbs[0], texture_size.x, texture_size.y, 1, gpu::TextureFormat::RGBA8, (u32)gpu::TextureFlags::NO_MIPS, nullptr, "impostor_gb0");
gpu::createTexture(gbs[1], texture_size.x, texture_size.y, 1, gpu::TextureFormat::RGBA8, (u32)gpu::TextureFlags::NO_MIPS, nullptr, "impostor_gb1");
gpu::createTexture(gbs[2], texture_size.x, texture_size.y, 1, gpu::TextureFormat::D32, (u32)gpu::TextureFlags::NO_MIPS | (u32)gpu::TextureFlags::POINT_FILTER, nullptr, "impostor_gbd");
gpu::createTexture(gbs[0], texture_size.x, texture_size.y, 1, gpu::TextureFormat::RGBA8, gpu::TextureFlags::NO_MIPS, nullptr, "impostor_gb0");
gpu::createTexture(gbs[1], texture_size.x, texture_size.y, 1, gpu::TextureFormat::RGBA8, gpu::TextureFlags::NO_MIPS, nullptr, "impostor_gb1");
gpu::createTexture(gbs[2], texture_size.x, texture_size.y, 1, gpu::TextureFormat::D32, gpu::TextureFlags::NO_MIPS | gpu::TextureFlags::POINT_FILTER, nullptr, "impostor_gbd");
gpu::setFramebuffer(gbs, 2, gbs[2], 0);
gpu::setFramebuffer(gbs, 2, gbs[2], gpu::FramebufferFlags::NONE);
const float color[] = {0, 0, 0, 0};
gpu::clear((u32)gpu::ClearFlags::COLOR | (u32)gpu::ClearFlags::DEPTH | (u32)gpu::ClearFlags::STENCIL, color, 0);
gpu::clear(gpu::ClearFlags::COLOR | gpu::ClearFlags::DEPTH | gpu::ClearFlags::STENCIL, color, 0);
for (u32 j = 0; j < IMPOSTOR_COLS; ++j) {
for (u32 i = 0; i < IMPOSTOR_COLS; ++i) {
@ -1007,20 +1007,20 @@ struct CaptureImpostorJob : Renderer::RenderJob {
gpu::bindIndexBuffer(rd->index_buffer_handle);
gpu::bindVertexBuffer(0, rd->vertex_buffer_handle, 0, rd->vb_stride);
gpu::bindVertexBuffer(1, gpu::INVALID_BUFFER, 0, 0);
gpu::setState(u64(gpu::StateFlags::DEPTH_TEST) | u64(gpu::StateFlags::DEPTH_WRITE) | dc.material->render_states);
gpu::setState(gpu::StateFlags::DEPTH_TEST | gpu::StateFlags::DEPTH_WRITE | dc.material->render_states);
gpu::drawTriangles(0, rd->indices_count, rd->index_type);
}
}
}
gpu::setFramebuffer(nullptr, 0, gpu::INVALID_TEXTURE, 0);
gpu::setFramebuffer(nullptr, 0, gpu::INVALID_TEXTURE, gpu::FramebufferFlags::NONE);
m_gb0->resize(texture_size.x * texture_size.y);
m_gb1->resize(m_gb0->size());
m_shadow->resize(m_gb0->size());
gpu::TextureHandle shadow = gpu::allocTextureHandle();
gpu::createTexture(shadow, texture_size.x, texture_size.y, 1, gpu::TextureFormat::RGBA8, (u32)gpu::TextureFlags::NO_MIPS | (u32)gpu::TextureFlags::COMPUTE_WRITE, nullptr, "impostor_shadow");
gpu::createTexture(shadow, texture_size.x, texture_size.y, 1, gpu::TextureFormat::RGBA8, gpu::TextureFlags::NO_MIPS | gpu::TextureFlags::COMPUTE_WRITE, nullptr, "impostor_shadow");
gpu::useProgram(m_shadow_program);
gpu::bindImageTexture(shadow, 0);
gpu::bindTextures(&gbs[2], 1, 1);
@ -1054,7 +1054,7 @@ struct CaptureImpostorJob : Renderer::RenderJob {
}
gpu::TextureHandle staging = gpu::allocTextureHandle();
const u32 flags = u32(gpu::TextureFlags::NO_MIPS) | u32(gpu::TextureFlags::READBACK);
const gpu::TextureFlags flags = gpu::TextureFlags::NO_MIPS | gpu::TextureFlags::READBACK;
gpu::createTexture(staging, texture_size.x, texture_size.y, 1, gpu::TextureFormat::RGBA8, flags, nullptr, "staging_buffer");
gpu::copy(staging, gbs[0], 0, 0);
gpu::readTexture(staging, 0, Span((u8*)m_gb0->begin(), m_gb0->byte_size()));

View file

@ -2958,16 +2958,16 @@ struct EnvironmentProbePlugin final : PropertyGrid::IPlugin
gpu::pushDebugGroup("radiance_filter");
gpu::TextureHandle src = gpu::allocTextureHandle();
gpu::TextureHandle dst = gpu::allocTextureHandle();
bool created = gpu::createTexture(src, size, size, 1, gpu::TextureFormat::RGBA32F, (u32)gpu::TextureFlags::IS_CUBE, nullptr, "env");
bool created = gpu::createTexture(src, size, size, 1, gpu::TextureFormat::RGBA32F, gpu::TextureFlags::IS_CUBE, nullptr, "env");
ASSERT(created);
for (u32 face = 0; face < 6; ++face) {
gpu::update(src, 0, face, 0, 0, size, size, gpu::TextureFormat::RGBA32F, (void*)(data + size * size * face));
}
gpu::generateMipmaps(src);
created = gpu::createTexture(dst, size, size, 1, gpu::TextureFormat::RGBA32F, (u32)gpu::TextureFlags::IS_CUBE, nullptr, "env_filtered");
created = gpu::createTexture(dst, size, size, 1, gpu::TextureFormat::RGBA32F, gpu::TextureFlags::IS_CUBE, nullptr, "env_filtered");
ASSERT(created);
gpu::BufferHandle buf = gpu::allocBufferHandle();
gpu::createBuffer(buf, (u32)gpu::BufferFlags::UNIFORM_BUFFER, 256, nullptr);
gpu::createBuffer(buf, gpu::BufferFlags::UNIFORM_BUFFER, 256, nullptr);
const u32 roughness_levels = 5;
@ -2984,17 +2984,17 @@ struct EnvironmentProbePlugin final : PropertyGrid::IPlugin
u32 face;
u32 mip;
} drawcall = {roughness, face, mip};
gpu::setState(0);
gpu::setState(gpu::StateFlags::NONE);
gpu::viewport(0, 0, size >> mip, size >> mip);
gpu::update(buf, &drawcall, sizeof(drawcall));
gpu::drawArrays(0, 4, gpu::PrimitiveType::TRIANGLE_STRIP);
}
}
gpu::setFramebuffer(nullptr, 0, gpu::INVALID_TEXTURE, 0);
gpu::setFramebuffer(nullptr, 0, gpu::INVALID_TEXTURE, gpu::FramebufferFlags::NONE);
gpu::TextureHandle staging = gpu::allocTextureHandle();
const u32 flags = u32(gpu::TextureFlags::IS_CUBE) | u32(gpu::TextureFlags::READBACK);
const gpu::TextureFlags flags = gpu::TextureFlags::IS_CUBE | gpu::TextureFlags::READBACK;
gpu::createTexture(staging, size, size, 1, gpu::TextureFormat::RGBA32F, flags, nullptr, "staging_buffer");
u32 data_size = 0;
@ -3356,8 +3356,8 @@ struct EditorUIRenderPlugin final : StudioApp::GUIPlugin
if (use_big_buffers) {
big_vb = gpu::allocBufferHandle();
big_ib = gpu::allocBufferHandle();
gpu::createBuffer(big_vb, (u32)gpu::BufferFlags::IMMUTABLE, num_vertices * sizeof(ImDrawVert), cmd_list.vtx_buffer.data);
gpu::createBuffer(big_ib, (u32)gpu::BufferFlags::IMMUTABLE, num_indices * sizeof(ImDrawIdx), cmd_list.idx_buffer.data);
gpu::createBuffer(big_vb, gpu::BufferFlags::IMMUTABLE, num_vertices * sizeof(ImDrawVert), cmd_list.vtx_buffer.data);
gpu::createBuffer(big_ib, gpu::BufferFlags::IMMUTABLE, num_indices * sizeof(ImDrawIdx), cmd_list.idx_buffer.data);
gpu::bindIndexBuffer(big_ib);
gpu::bindVertexBuffer(0, big_vb, 0, sizeof(ImDrawVert));
gpu::bindVertexBuffer(1, gpu::INVALID_BUFFER, 0, 0);
@ -3376,8 +3376,8 @@ struct EditorUIRenderPlugin final : StudioApp::GUIPlugin
const ImDrawCmd* pcmd_begin = cmd_list.commands.begin();
const ImDrawCmd* pcmd_end = cmd_list.commands.end();
const u64 blend_state = gpu::getBlendStateBits(gpu::BlendFactors::SRC_ALPHA, gpu::BlendFactors::ONE_MINUS_SRC_ALPHA, gpu::BlendFactors::SRC_ALPHA, gpu::BlendFactors::ONE_MINUS_SRC_ALPHA);
gpu::setState((u64)gpu::StateFlags::SCISSOR_TEST | blend_state);
const gpu::StateFlags blend_state = gpu::getBlendStateBits(gpu::BlendFactors::SRC_ALPHA, gpu::BlendFactors::ONE_MINUS_SRC_ALPHA, gpu::BlendFactors::SRC_ALPHA, gpu::BlendFactors::ONE_MINUS_SRC_ALPHA);
gpu::setState(gpu::StateFlags::SCISSOR_TEST | blend_state);
for (const ImDrawCmd* pcmd = pcmd_begin; pcmd != pcmd_end; pcmd++)
{
ASSERT(!pcmd->UserCallback);
@ -3422,9 +3422,9 @@ struct EditorUIRenderPlugin final : StudioApp::GUIPlugin
PROFILE_FUNCTION();
if (init_render) {
gpu::createBuffer(ub, (u32)gpu::BufferFlags::UNIFORM_BUFFER, 256, nullptr);
gpu::createBuffer(ib, 0, 256 * 1024, nullptr);
gpu::createBuffer(vb, 0, 256 * 1024, nullptr);
gpu::createBuffer(ub, gpu::BufferFlags::UNIFORM_BUFFER, 256, nullptr);
gpu::createBuffer(ib, gpu::BufferFlags::NONE, 256 * 1024, nullptr);
gpu::createBuffer(vb, gpu::BufferFlags::NONE, 256 * 1024, nullptr);
}
gpu::pushDebugGroup("imgui");
@ -3433,7 +3433,7 @@ struct EditorUIRenderPlugin final : StudioApp::GUIPlugin
ib_offset = 0;
for (WindowDrawData& dd : window_draw_data) {
gpu::setCurrentWindow(dd.window);
gpu::setFramebuffer(nullptr, 0, gpu::INVALID_TEXTURE, 0);
gpu::setFramebuffer(nullptr, 0, gpu::INVALID_TEXTURE, gpu::FramebufferFlags::NONE);
gpu::viewport(0, 0, dd.w, dd.h);
Vec4 canvas_mtx[] = {
@ -3444,7 +3444,7 @@ struct EditorUIRenderPlugin final : StudioApp::GUIPlugin
gpu::bindUniformBuffer(4, ub, 0, sizeof(canvas_mtx));
Vec4 cc = {1, 0, 1, 1};
const float clear_color[] = {0.2f, 0.2f, 0.2f, 1.f};
gpu::clear((u32)gpu::ClearFlags::COLOR | (u32)gpu::ClearFlags::DEPTH, clear_color, 1.0);
gpu::clear(gpu::ClearFlags::COLOR | gpu::ClearFlags::DEPTH, clear_color, 1.0);
if (dd.new_program) {
const char* vs =
R"#(
@ -3523,7 +3523,7 @@ struct EditorUIRenderPlugin final : StudioApp::GUIPlugin
ImGui::GetIO().Fonts->GetTexDataAsRGBA32(&pixels, &width, &height);
const Renderer::MemRef mem = renderer->copy(pixels, width * height * 4);
m_texture = renderer->createTexture(width, height, 1, gpu::TextureFormat::RGBA8, (u32)gpu::TextureFlags::NO_MIPS, mem, "editor_font_atlas");
m_texture = renderer->createTexture(width, height, 1, gpu::TextureFormat::RGBA8, gpu::TextureFlags::NO_MIPS, mem, "editor_font_atlas");
ImGui::GetIO().Fonts->TexID = m_texture;
WorldEditor& editor = app.getWorldEditor();

View file

@ -983,7 +983,7 @@ void SceneView::renderGizmos()
renderer->beginProfileBlock("gizmos", 0);
gpu::pushDebugGroup("gizmos");
gpu::setState(u64(gpu::StateFlags::DEPTH_TEST) | u64(gpu::StateFlags::DEPTH_WRITE));
gpu::setState(gpu::StateFlags::DEPTH_TEST | gpu::StateFlags::DEPTH_WRITE);
u32 offset = 0;
const gpu::BufferHandle drawcall_ub = view->getPipeline()->getDrawcallUniformBuffer();
const Matrix mtx = Matrix::IDENTITY;

View file

@ -39,7 +39,7 @@ struct Buffer {
}
GLuint gl_handle;
u32 flags;
BufferFlags flags;
};
struct Texture {
@ -53,7 +53,7 @@ struct Texture {
u32 width;
u32 height;
u32 depth;
u32 flags;
TextureFlags flags;
#ifdef LUMIX_DEBUG
StaticString<64> name;
#endif
@ -89,7 +89,7 @@ struct GL {
int instance_attributes = 0;
int max_vertex_attributes = 16;
ProgramHandle last_program = INVALID_PROGRAM;
u64 last_state = 0;
StateFlags last_state = StateFlags::NONE;
GLuint framebuffer = 0;
ProgramHandle default_program = INVALID_PROGRAM;
bool has_gpu_mem_info_ext = false;
@ -335,10 +335,10 @@ static bool load_gl_linux(void* wnd){
}
#endif
static bool load_gl(void* platform_handle, u32 init_flags)
static bool load_gl(void* platform_handle, InitFlags init_flags)
{
#ifdef _WIN32
const bool vsync = init_flags & (u32)InitFlags::VSYNC;
const bool vsync = u32(init_flags & InitFlags::VSYNC);
HDC hdc = (HDC)platform_handle;
const PIXELFORMATDESCRIPTOR pfd =
{
@ -563,7 +563,7 @@ void bindTextures(const TextureHandle* handles, u32 offset, u32 count)
glBindTextures(offset, count, gl_handles);
}
void bindShaderBuffer(BufferHandle buffer, u32 binding_idx, u32 flags)
void bindShaderBuffer(BufferHandle buffer, u32 binding_idx, BindShaderBufferFlags flags)
{
checkThread();
glBindBufferBase(GL_SHADER_STORAGE_BUFFER, binding_idx, buffer ? buffer->gl_handle : 0);
@ -576,26 +576,26 @@ void bindVertexBuffer(u32 binding_idx, BufferHandle buffer, u32 buffer_offset, u
}
void setState(u64 state)
void setState(StateFlags state)
{
checkThread();
if(state == gl->last_state) return;
gl->last_state = state;
if (state & u64(StateFlags::DEPTH_TEST)) glEnable(GL_DEPTH_TEST);
if (u64(state & StateFlags::DEPTH_TEST)) glEnable(GL_DEPTH_TEST);
else glDisable(GL_DEPTH_TEST);
glDepthMask((state & u64(StateFlags::DEPTH_WRITE)) != 0);
glDepthMask(u64(state & StateFlags::DEPTH_WRITE) != 0);
if (state & u64(StateFlags::SCISSOR_TEST)) glEnable(GL_SCISSOR_TEST);
if (u64(state & StateFlags::SCISSOR_TEST)) glEnable(GL_SCISSOR_TEST);
else glDisable(GL_SCISSOR_TEST);
if (state & u64(StateFlags::CULL_BACK)) {
if (u64(state & StateFlags::CULL_BACK)) {
glEnable(GL_CULL_FACE);
glCullFace(GL_BACK);
}
else if(state & u64(StateFlags::CULL_FRONT)) {
else if(u64(state & StateFlags::CULL_FRONT)) {
glEnable(GL_CULL_FACE);
glCullFace(GL_FRONT);
}
@ -603,7 +603,7 @@ void setState(u64 state)
glDisable(GL_CULL_FACE);
}
glPolygonMode(GL_FRONT_AND_BACK, state & u64(StateFlags::WIREFRAME) ? GL_LINE : GL_FILL);
glPolygonMode(GL_FRONT_AND_BACK, u64(state & StateFlags::WIREFRAME) ? GL_LINE : GL_FILL);
auto to_gl = [&](BlendFactors factor) -> GLenum{
static const GLenum table[] = {
@ -625,7 +625,7 @@ void setState(u64 state)
return table[(int)factor];
};
u16 blend_bits = u16(state >> 6);
u16 blend_bits = u16(u64(state) >> 6);
if (blend_bits) {
const BlendFactors src_rgb = (BlendFactors)(blend_bits & 0xf);
@ -639,14 +639,14 @@ void setState(u64 state)
glDisable(GL_BLEND);
}
glStencilMask(u8(state >> 22));
const StencilFuncs func = (StencilFuncs)((state >> 30) & 0xf);
glStencilMask(u8(u64(state) >> 22));
const StencilFuncs func = (StencilFuncs)((u64(state) >> 30) & 0xf);
if (func == StencilFuncs::DISABLE) {
glDisable(GL_STENCIL_TEST);
}
else {
const u8 ref = u8(state >> 34);
const u8 mask = u8(state >> 42);
const u8 ref = u8(u64(state) >> 34);
const u8 mask = u8(u64(state) >> 42);
glEnable(GL_STENCIL_TEST);
GLenum gl_func;
switch(func) {
@ -669,9 +669,9 @@ void setState(u64 state)
};
return table[(int)op];
};
const StencilOps sfail = StencilOps((state >> 50) & 0xf);
const StencilOps zfail = StencilOps((state >> 54) & 0xf);
const StencilOps zpass = StencilOps((state >> 58) & 0xf);
const StencilOps sfail = StencilOps((u64(state) >> 50) & 0xf);
const StencilOps zfail = StencilOps((u64(state) >> 54) & 0xf);
const StencilOps zpass = StencilOps((u64(state) >> 58) & 0xf);
glStencilOp(toGLOp(sfail), toGLOp(zfail), toGLOp(zpass));
}
}
@ -788,7 +788,7 @@ void* map(BufferHandle buffer, size_t size)
{
checkThread();
ASSERT(buffer);
ASSERT((buffer->flags & (u32)BufferFlags::IMMUTABLE) == 0);
ASSERT(u32(buffer->flags & BufferFlags::IMMUTABLE) == 0);
const GLbitfield gl_flags = GL_MAP_INVALIDATE_BUFFER_BIT | GL_MAP_UNSYNCHRONIZED_BIT | GL_MAP_WRITE_BIT;
return glMapNamedBufferRange(buffer->gl_handle, 0, size, gl_flags);
}
@ -806,7 +806,7 @@ void update(BufferHandle buffer, const void* data, size_t size)
{
checkThread();
ASSERT(buffer);
ASSERT((buffer->flags & (u32)BufferFlags::IMMUTABLE) == 0);
ASSERT(u32(buffer->flags & BufferFlags::IMMUTABLE) == 0);
const GLuint buf = buffer->gl_handle;
glNamedBufferSubData(buf, 0, size, data);
}
@ -816,7 +816,7 @@ void copy(BufferHandle dst, BufferHandle src, u32 dst_offset, u32 size)
checkThread();
ASSERT(src);
ASSERT(dst);
ASSERT((dst->flags & (u32)BufferFlags::IMMUTABLE) == 0);
ASSERT(u32(dst->flags & BufferFlags::IMMUTABLE) == 0);
glCopyNamedBufferSubData(src->gl_handle, dst->gl_handle, 0, dst_offset, size);
}
@ -986,7 +986,7 @@ u32 swapBuffers()
bool frameFinished(u32 frame) { return true; }
void waitFrame(u32 frame) {}
void createBuffer(BufferHandle buffer, u32 flags, size_t size, const void* data)
void createBuffer(BufferHandle buffer, BufferFlags flags, size_t size, const void* data)
{
checkThread();
ASSERT(buffer);
@ -994,7 +994,7 @@ void createBuffer(BufferHandle buffer, u32 flags, size_t size, const void* data)
glCreateBuffers(1, &buf);
GLbitfield gl_flags = 0;
if ((flags & (u32)BufferFlags::IMMUTABLE) == 0) gl_flags |= GL_DYNAMIC_STORAGE_BIT | GL_MAP_WRITE_BIT | GL_MAP_READ_BIT;
if (u64(flags & BufferFlags::IMMUTABLE) == 0) gl_flags |= GL_DYNAMIC_STORAGE_BIT | GL_MAP_WRITE_BIT | GL_MAP_READ_BIT;
glNamedBufferStorage(buf, size, data, gl_flags);
buffer->gl_handle = buf;
@ -1064,7 +1064,7 @@ void update(TextureHandle texture, u32 level, u32 slice, u32 x, u32 y, u32 w, u3
if (s_texture_formats[i].format == format) {
const auto& f = s_texture_formats[i];
glPixelStorei(GL_UNPACK_ALIGNMENT, 1);
if (texture->flags & (u32)TextureFlags::IS_CUBE || texture->depth > 1) {
if (u32(texture->flags & TextureFlags::IS_CUBE) || texture->depth > 1) {
glTextureSubImage3D(handle, level, x, y, slice, w, h, 1, f.gl_format, f.type, buf);
}
else {
@ -1077,7 +1077,7 @@ void update(TextureHandle texture, u32 level, u32 slice, u32 x, u32 y, u32 w, u3
}
bool loadTexture(TextureHandle handle, const void* input, int input_size, u32 flags, const char* debug_name)
bool loadTexture(TextureHandle handle, const void* input, int input_size, TextureFlags flags, const char* debug_name)
{
ASSERT(debug_name && debug_name[0]);
ASSERT(handle);
@ -1143,7 +1143,7 @@ bool loadTexture(TextureHandle handle, const void* input, int input_size, u32 fl
const bool is_cubemap = (hdr.caps2.dwCaps2 & DDS::DDSCAPS2_CUBEMAP) != 0;
const GLenum texture_target = is_cubemap ? GL_TEXTURE_CUBE_MAP : layers > 1 ? GL_TEXTURE_2D_ARRAY : GL_TEXTURE_2D;
const bool is_srgb = flags & (u32)TextureFlags::SRGB;
const bool is_srgb = u32(flags & TextureFlags::SRGB);
const GLenum internal_format = is_srgb ? li->internalSRGBFormat : li->internalFormat;
const u32 mipMapCount = (hdr.dwFlags & DDS::DDSD_MIPMAPCOUNT) ? hdr.dwMipMapCount : 1;
@ -1249,9 +1249,9 @@ bool loadTexture(TextureHandle handle, const void* input, int input_size, u32 fl
}
}
const GLint wrap_u = (flags & (u32)TextureFlags::CLAMP_U) ? GL_CLAMP : GL_REPEAT;
const GLint wrap_v = (flags & (u32)TextureFlags::CLAMP_V) ? GL_CLAMP : GL_REPEAT;
const GLint wrap_w = (flags & (u32)TextureFlags::CLAMP_W) ? GL_CLAMP : GL_REPEAT;
const GLint wrap_u = u32(flags & TextureFlags::CLAMP_U) ? GL_CLAMP : GL_REPEAT;
const GLint wrap_v = u32(flags & TextureFlags::CLAMP_V) ? GL_CLAMP : GL_REPEAT;
const GLint wrap_w = u32(flags & TextureFlags::CLAMP_W) ? GL_CLAMP : GL_REPEAT;
glTextureParameteri(texture, GL_TEXTURE_WRAP_S, wrap_u);
glTextureParameteri(texture, GL_TEXTURE_WRAP_T, wrap_v);
glTextureParameteri(texture, GL_TEXTURE_WRAP_R, wrap_w);
@ -1313,14 +1313,14 @@ void createTextureView(TextureHandle view, TextureHandle texture)
}
bool createTexture(TextureHandle handle, u32 w, u32 h, u32 depth, TextureFormat format, u32 flags, const void* data, const char* debug_name)
bool createTexture(TextureHandle handle, u32 w, u32 h, u32 depth, TextureFormat format, TextureFlags flags, const void* data, const char* debug_name)
{
checkThread();
ASSERT(handle);
const bool is_srgb = flags & (u32)TextureFlags::SRGB;
const bool no_mips = flags & (u32)TextureFlags::NO_MIPS;
const bool is_3d = depth > 1 && (flags & (u32)TextureFlags::IS_3D);
const bool is_cubemap = flags & (u32)TextureFlags::IS_CUBE;
const bool is_srgb = u32(flags & TextureFlags::SRGB);
const bool no_mips = u32(flags & TextureFlags::NO_MIPS);
const bool is_3d = depth > 1 && u32(flags & TextureFlags::IS_3D);
const bool is_cubemap = u32(flags & TextureFlags::IS_CUBE);
ASSERT(!is_cubemap || depth == 1);
ASSERT(!is_cubemap || !is_3d);
@ -1404,13 +1404,13 @@ bool createTexture(TextureHandle handle, u32 w, u32 h, u32 depth, TextureFormat
}
glGenerateTextureMipmap(texture);
const GLint wrap_u = (flags & (u32)TextureFlags::CLAMP_U) ? GL_CLAMP_TO_EDGE : GL_REPEAT;
const GLint wrap_v = (flags & (u32)TextureFlags::CLAMP_V) ? GL_CLAMP_TO_EDGE : GL_REPEAT;
const GLint wrap_w = (flags & (u32)TextureFlags::CLAMP_W) ? GL_CLAMP_TO_EDGE : GL_REPEAT;
const GLint wrap_u = u32(flags & TextureFlags::CLAMP_U) ? GL_CLAMP_TO_EDGE : GL_REPEAT;
const GLint wrap_v = u32(flags & TextureFlags::CLAMP_V) ? GL_CLAMP_TO_EDGE : GL_REPEAT;
const GLint wrap_w = u32(flags & TextureFlags::CLAMP_W) ? GL_CLAMP_TO_EDGE : GL_REPEAT;
glTextureParameteri(texture, GL_TEXTURE_WRAP_S, wrap_u);
glTextureParameteri(texture, GL_TEXTURE_WRAP_T, wrap_v);
glTextureParameteri(texture, GL_TEXTURE_WRAP_R, wrap_w);
if (flags & (u32)TextureFlags::POINT_FILTER) {
if (u32(flags & TextureFlags::POINT_FILTER)) {
glTextureParameteri(texture, GL_TEXTURE_MAG_FILTER, GL_NEAREST);
glTextureParameteri(texture, GL_TEXTURE_MIN_FILTER, GL_NEAREST);
}
@ -1449,27 +1449,27 @@ void destroy(BufferHandle buffer) {
LUMIX_DELETE(gl->allocator, buffer);
}
void clear(u32 flags, const float* color, float depth)
void clear(ClearFlags flags, const float* color, float depth)
{
glUseProgram(0);
gl->last_program = INVALID_PROGRAM;
glDisable(GL_SCISSOR_TEST);
glDisable(GL_BLEND);
gl->last_state &= ~u64(0xffFF << 6);
gl->last_state = gl->last_state & ~StateFlags(0xffFF << 6);
checkThread();
GLbitfield gl_flags = 0;
if (flags & (u32)ClearFlags::COLOR) {
if (u32(flags & ClearFlags::COLOR)) {
glClearColor(color[0], color[1], color[2], color[3]);
gl_flags |= GL_COLOR_BUFFER_BIT;
}
if (flags & (u32)ClearFlags::DEPTH) {
if (u32(flags & ClearFlags::DEPTH)) {
glDepthMask(GL_TRUE);
glClearDepth(depth);
gl_flags |= GL_DEPTH_BUFFER_BIT;
}
if (flags & (u32)ClearFlags::STENCIL) {
if (u32(flags & ClearFlags::STENCIL)) {
glStencilMask(0xff);
gl->last_state = gl->last_state | (0xff << 22);
gl->last_state = gl->last_state | StateFlags(0xff << 22);
glClearStencil(0);
gl_flags |= GL_STENCIL_BUFFER_BIT;
}
@ -1645,12 +1645,12 @@ bool getMemoryStats(Ref<MemoryStats> stats) {
}
bool init(void* window_handle, u32 init_flags)
bool init(void* window_handle, InitFlags init_flags)
{
#ifdef LUMIX_DEBUG
const bool debug = true;
#else
const bool debug = init_flags & (u32)InitFlags::DEBUG_OUTPUT;
const bool debug = u32(init_flags & InitFlags::DEBUG_OUTPUT);
#endif
gl->thread = OS::getCurrentThreadID();
@ -1710,8 +1710,8 @@ bool init(void* window_handle, u32 init_flags)
glLinkProgram(p.gl_handle);
glDeleteShader(vs);
gl->last_state = 1;
setState(0);
gl->last_state = StateFlags(1);
setState(StateFlags::NONE);
return true;
}
@ -1739,8 +1739,8 @@ void copy(TextureHandle dst, TextureHandle src, u32 dst_x, u32 dst_y) {
glCopyImageSubData(src->gl_handle, src->target, mip, 0, 0, 0, dst->gl_handle, dst->target, mip, dst_x, dst_y, 0, w, h, 1);
}
++mip;
if (src->flags & (u32)TextureFlags::NO_MIPS) break;
if (dst->flags & (u32)TextureFlags::NO_MIPS) break;
if (u32(src->flags & TextureFlags::NO_MIPS)) break;
if (u32(dst->flags & TextureFlags::NO_MIPS)) break;
}
}
@ -1839,11 +1839,11 @@ void setFramebufferCube(TextureHandle cube, u32 face, u32 mip)
glDrawBuffers(1, &db);
}
void setFramebuffer(TextureHandle* attachments, u32 num, TextureHandle ds, u32 flags)
void setFramebuffer(TextureHandle* attachments, u32 num, TextureHandle ds, FramebufferFlags flags)
{
checkThread();
if (flags & (u32)FramebufferFlags::SRGB) {
if (u32(flags & FramebufferFlags::SRGB)) {
glEnable(GL_FRAMEBUFFER_SRGB);
}
else {

View file

@ -19,17 +19,19 @@ const TextureHandle INVALID_TEXTURE = nullptr;
const QueryHandle INVALID_QUERY = nullptr;
enum class InitFlags : u32 {
DEBUG_OUTPUT,
VSYNC,
RENDERDOC
NONE = 0,
DEBUG_OUTPUT = 1 << 0,
VSYNC = 1 << 1
};
enum class FramebufferFlags : u32 {
NONE = 0,
SRGB = 1 << 0,
READONLY_DEPTH_STENCIL = 1 << 1
};
enum class StateFlags : u64 {
NONE = 0,
WIREFRAME = 1 << 0,
DEPTH_TEST = 1 << 1,
CULL_FRONT = 1 << 2,
@ -127,10 +129,12 @@ enum class TextureFormat : u32 {
};
enum class BindShaderBufferFlags : u32 {
NONE = 0,
OUTPUT = 1 << 0,
};
enum class TextureFlags : u32 {
NONE = 0,
POINT_FILTER = 1 << 0,
CLAMP_U = 1 << 1,
CLAMP_V = 1 << 2,
@ -145,6 +149,7 @@ enum class TextureFlags : u32 {
};
enum class BufferFlags : u32 {
NONE = 0,
IMMUTABLE = 1 << 0,
UNIFORM_BUFFER = 1 << 1,
SHADER_BUFFER = 1 << 2,
@ -201,7 +206,7 @@ struct MemoryStats {
void preinit(IAllocator& allocator, bool load_renderdoc);
bool init(void* window_handle, u32 flags);
bool init(void* window_handle, InitFlags flags);
void launchRenderDoc();
void setCurrentWindow(void* window_handle);
bool getMemoryStats(Ref<MemoryStats> stats);
@ -216,42 +221,42 @@ void stopCapture();
int getSize(AttributeType type);
void clear(u32 flags, const float* color, float depth);
void clear(ClearFlags flags, const float* color, float depth);
void scissor(u32 x, u32 y, u32 w, u32 h);
void viewport(u32 x, u32 y, u32 w, u32 h);
inline u64 getBlendStateBits(BlendFactors src_rgb, BlendFactors dst_rgb, BlendFactors src_a, BlendFactors dst_a)
inline StateFlags getBlendStateBits(BlendFactors src_rgb, BlendFactors dst_rgb, BlendFactors src_a, BlendFactors dst_a)
{
return (((u64)src_rgb & 15) << 6) | (((u64)dst_rgb & 15) << 10) | (((u64)src_a & 15) << 14) | (((u64)dst_a & 15) << 18);
return StateFlags((((u64)src_rgb & 15) << 6) | (((u64)dst_rgb & 15) << 10) | (((u64)src_a & 15) << 14) | (((u64)dst_a & 15) << 18));
}
inline u64 getStencilStateBits(u8 write_mask, StencilFuncs func, u8 ref, u8 mask, StencilOps sfail, StencilOps dpfail, StencilOps dppass)
inline StateFlags getStencilStateBits(u8 write_mask, StencilFuncs func, u8 ref, u8 mask, StencilOps sfail, StencilOps dpfail, StencilOps dppass)
{
return ((u64)write_mask << 22) | ((u64)func << 30) | ((u64)ref << 34) | ((u64)mask << 42) | ((u64)sfail << 50) | ((u64)dpfail << 54) | ((u64)dppass << 58);
return StateFlags(((u64)write_mask << 22) | ((u64)func << 30) | ((u64)ref << 34) | ((u64)mask << 42) | ((u64)sfail << 50) | ((u64)dpfail << 54) | ((u64)dppass << 58));
}
TextureHandle allocTextureHandle();
BufferHandle allocBufferHandle();
ProgramHandle allocProgramHandle();
void setState(u64 state);
void setState(StateFlags state);
bool createProgram(ProgramHandle program, const VertexDecl& decl, const char** srcs, const ShaderType* types, u32 num, const char** prefixes, u32 prefixes_count, const char* name);
void useProgram(ProgramHandle prg);
void dispatch(u32 num_groups_x, u32 num_groups_y, u32 num_groups_z);
void createBuffer(BufferHandle handle, u32 flags, size_t size, const void* data);
bool createTexture(TextureHandle handle, u32 w, u32 h, u32 depth, TextureFormat format, u32 flags, const void* data, const char* debug_name);
void createBuffer(BufferHandle handle, BufferFlags flags, size_t size, const void* data);
bool createTexture(TextureHandle handle, u32 w, u32 h, u32 depth, TextureFormat format, TextureFlags flags, const void* data, const char* debug_name);
void createTextureView(TextureHandle view, TextureHandle texture);
void generateMipmaps(TextureHandle handle);
bool loadTexture(TextureHandle handle, const void* data, int size, u32 flags, const char* debug_name);
bool loadTexture(TextureHandle handle, const void* data, int size, TextureFlags flags, const char* debug_name);
void update(TextureHandle texture, u32 level, u32 slice, u32 x, u32 y, u32 w, u32 h, TextureFormat format, void* buf);
QueryHandle createQuery();
void bindVertexBuffer(u32 binding_idx, BufferHandle buffer, u32 buffer_offset, u32 stride_offset);
void bindImageTexture(TextureHandle texture, u32 unit);
void bindTextures(const TextureHandle* handles, u32 offset, u32 count);
void bindShaderBuffer(BufferHandle buffer, u32 binding_point, u32 flags);
void bindShaderBuffer(BufferHandle buffer, u32 binding_point, BindShaderBufferFlags flags);
void update(BufferHandle buffer, const void* data, size_t size);
void* map(BufferHandle buffer, size_t size);
void unmap(BufferHandle buffer);
@ -283,7 +288,7 @@ void pushDebugGroup(const char* msg);
void popDebugGroup();
void setFramebufferCube(TextureHandle cube, u32 face, u32 mip);
void setFramebuffer(TextureHandle* attachments, u32 num, TextureHandle depth_stencil, u32 flags);
void setFramebuffer(TextureHandle* attachments, u32 num, TextureHandle depth_stencil, FramebufferFlags flags);
inline u32 getBytesPerPixel(gpu::TextureFormat format) {
switch (format) {
@ -310,6 +315,27 @@ inline u32 getBytesPerPixel(gpu::TextureFormat format) {
}
}
constexpr StateFlags operator ~(StateFlags a) { return StateFlags(~(u64)a); }
constexpr StateFlags operator | (StateFlags a, StateFlags b) { return StateFlags((u64)a | (u64)b); }
constexpr StateFlags operator & (StateFlags a, StateFlags b) { return StateFlags((u64)a & (u64)b); }
constexpr ClearFlags operator | (ClearFlags a, ClearFlags b) { return ClearFlags((u32)a | (u32)b); }
constexpr ClearFlags operator & (ClearFlags a, ClearFlags b) { return ClearFlags((u32)a & (u32)b); }
constexpr FramebufferFlags operator | (FramebufferFlags a, FramebufferFlags b) { return FramebufferFlags((u32)a | (u32)b); }
constexpr FramebufferFlags operator & (FramebufferFlags a, FramebufferFlags b) { return FramebufferFlags((u32)a & (u32)b); }
constexpr TextureFlags operator ~(TextureFlags a) { return TextureFlags(~(u64)a); }
constexpr TextureFlags operator | (TextureFlags a, TextureFlags b) { return TextureFlags((u32)a | (u32)b); }
constexpr TextureFlags operator & (TextureFlags a, TextureFlags b) { return TextureFlags((u32)a & (u32)b); }
constexpr BufferFlags operator | (BufferFlags a, BufferFlags b) { return BufferFlags((u32)a | (u32)b); }
constexpr BufferFlags operator & (BufferFlags a, BufferFlags b) { return BufferFlags((u32)a & (u32)b); }
constexpr InitFlags operator ~(InitFlags a) { return InitFlags(~(u32)a); }
constexpr InitFlags operator | (InitFlags a, InitFlags b) { return InitFlags((u32)a | (u32)b); }
constexpr InitFlags operator & (InitFlags a, InitFlags b) { return InitFlags((u32)a & (u32)b); }
} // namespace gpu
} // namespace Lumix

View file

@ -36,7 +36,7 @@ Material::Material(const Path& path, ResourceManager& resource_manager, Renderer
, m_uniforms(allocator)
, m_texture_count(0)
, m_renderer(renderer)
, m_render_states(u64(gpu::StateFlags::CULL_BACK))
, m_render_states(gpu::StateFlags::CULL_BACK)
, m_color(1, 1, 1, 1)
, m_metallic(0.f)
, m_roughness(1.f)
@ -152,7 +152,7 @@ void Material::unload()
m_metallic = 0.0f;
m_roughness = 1.0f;
m_emission = 0.0f;
m_render_states = u64(gpu::StateFlags::CULL_BACK);
m_render_states = gpu::StateFlags::CULL_BACK;
}
@ -472,17 +472,17 @@ bool Material::isTextureDefine(u8 define_idx) const
void Material::enableBackfaceCulling(bool enable)
{
if (enable) {
m_render_states |= (u64)gpu::StateFlags::CULL_BACK;
m_render_states = m_render_states | gpu::StateFlags::CULL_BACK;
}
else {
m_render_states &= ~(u64)gpu::StateFlags::CULL_BACK;
m_render_states = m_render_states & ~gpu::StateFlags::CULL_BACK;
}
}
bool Material::isBackfaceCulling() const
{
return (m_render_states & (u64)gpu::StateFlags::CULL_BACK) != 0;
return u64(m_render_states & gpu::StateFlags::CULL_BACK);
}
@ -688,7 +688,7 @@ bool Material::load(u64 size, const u8* mem)
lua_State* L = mng.getState(*this);
m_uniforms.clear();
m_render_states = u64(gpu::StateFlags::CULL_BACK);
m_render_states = gpu::StateFlags::CULL_BACK;
m_custom_flags = 0;
setAlphaRef(DEFAULT_ALPHA_REF_VALUE);

View file

@ -51,7 +51,7 @@ public:
struct RenderData {
gpu::TextureHandle textures[MAX_TEXTURE_COUNT];
int textures_count;
u64 render_states;
gpu::StateFlags render_states;
u32 material_constants;
u32 define_mask;
};
@ -90,7 +90,7 @@ public:
void setColor(const Vec4& color) { m_color = color; updateRenderData(false); }
float getAlphaRef() const { return m_alpha_ref; }
void setAlphaRef(float value) { m_alpha_ref = value; updateRenderData(false); }
u64 getRenderStates() const { return m_render_states; }
gpu::StateFlags getRenderStates() const { return m_render_states; }
void enableBackfaceCulling(bool enable);
bool isBackfaceCulling() const;
@ -145,7 +145,7 @@ private:
Texture* m_textures[MAX_TEXTURE_COUNT];
u32 m_texture_count;
u32 m_define_mask;
u64 m_render_states;
gpu::StateFlags m_render_states;
RenderData* m_render_data;
u8 m_layer;
u32 m_sort_key;

View file

@ -486,7 +486,7 @@ bool Model::parseMeshes(InputMemoryStream& file, FileVersion version)
if (index_size == 2) mesh.flags.set(Mesh::Flags::INDICES_16_BIT);
const Renderer::MemRef mem = m_renderer.copy(mesh.indices.data(), (u32)mesh.indices.size());
mesh.render_data->index_buffer_handle = m_renderer.createBuffer(mem, (u32)gpu::BufferFlags::IMMUTABLE);
mesh.render_data->index_buffer_handle = m_renderer.createBuffer(mem, gpu::BufferFlags::IMMUTABLE);
mesh.render_data->index_type = index_size == 2 ? gpu::DataType::U16 : gpu::DataType::U32;
if (!mesh.render_data->index_buffer_handle) return false;
}
@ -521,7 +521,7 @@ bool Model::parseMeshes(InputMemoryStream& file, FileVersion version)
}
mesh.vertices[j] = *(const Vec3*)&vertices[offset + position_attribute_offset];
}
mesh.render_data->vertex_buffer_handle = m_renderer.createBuffer(vertices_mem, (u32)gpu::BufferFlags::IMMUTABLE);
mesh.render_data->vertex_buffer_handle = m_renderer.createBuffer(vertices_mem, gpu::BufferFlags::IMMUTABLE);
if (!mesh.render_data->vertex_buffer_handle) return false;
}
file.read(m_origin_bounding_radius);

View file

@ -47,7 +47,7 @@ struct CameraParams
};
struct RenderState {
u64 value;
gpu::StateFlags value;
};
using LuaTextureHandle = gpu::TextureHandle;
@ -66,19 +66,19 @@ namespace LuaWrapper {
gpu::StencilOps stencil_zpass = gpu::StencilOps::KEEP;
char tmp[64];
u64 rs = (u64)gpu::StateFlags::DEPTH_TEST | (u64)gpu::StateFlags::DEPTH_WRITE;
gpu::StateFlags rs = gpu::StateFlags::DEPTH_TEST | gpu::StateFlags::DEPTH_WRITE;
if (LuaWrapper::getOptionalStringField(L, idx, "blending", Span(tmp))) {
if(equalIStrings(tmp, "add")) {
rs |= gpu::getBlendStateBits(gpu::BlendFactors::ONE, gpu::BlendFactors::ONE, gpu::BlendFactors::ONE, gpu::BlendFactors::ONE);
rs = rs | gpu::getBlendStateBits(gpu::BlendFactors::ONE, gpu::BlendFactors::ONE, gpu::BlendFactors::ONE, gpu::BlendFactors::ONE);
}
else if(equalIStrings(tmp, "alpha")) {
rs |= gpu::getBlendStateBits(gpu::BlendFactors::SRC_ALPHA, gpu::BlendFactors::ONE_MINUS_SRC_ALPHA, gpu::BlendFactors::SRC_ALPHA, gpu::BlendFactors::ONE_MINUS_SRC_ALPHA);
rs = rs | gpu::getBlendStateBits(gpu::BlendFactors::SRC_ALPHA, gpu::BlendFactors::ONE_MINUS_SRC_ALPHA, gpu::BlendFactors::SRC_ALPHA, gpu::BlendFactors::ONE_MINUS_SRC_ALPHA);
}
else if(equalIStrings(tmp, "multiply")) {
rs |= gpu::getBlendStateBits(gpu::BlendFactors::DST_COLOR, gpu::BlendFactors::ZERO, gpu::BlendFactors::ONE, gpu::BlendFactors::ZERO);
rs = rs | gpu::getBlendStateBits(gpu::BlendFactors::DST_COLOR, gpu::BlendFactors::ZERO, gpu::BlendFactors::ONE, gpu::BlendFactors::ZERO);
}
else if(equalIStrings(tmp, "dual")) {
rs |= gpu::getBlendStateBits(gpu::BlendFactors::ONE, gpu::BlendFactors::SRC1_COLOR, gpu::BlendFactors::ONE, gpu::BlendFactors::ONE);
rs = rs | gpu::getBlendStateBits(gpu::BlendFactors::ONE, gpu::BlendFactors::SRC1_COLOR, gpu::BlendFactors::ONE, gpu::BlendFactors::ONE);
}
else if(equalIStrings(tmp, "")) {
}
@ -87,9 +87,9 @@ namespace LuaWrapper {
}
}
LuaWrapper::getOptionalFlagField(L, idx, "depth_test", &rs, (u64)gpu::StateFlags::DEPTH_TEST, true);
LuaWrapper::getOptionalFlagField(L, idx, "wireframe", &rs, (u64)gpu::StateFlags::WIREFRAME, false);
LuaWrapper::getOptionalFlagField(L, idx, "depth_write", &rs, (u64)gpu::StateFlags::DEPTH_WRITE, true);
LuaWrapper::getOptionalFlagField(L, idx, "depth_test", &rs, gpu::StateFlags::DEPTH_TEST, true);
LuaWrapper::getOptionalFlagField(L, idx, "wireframe", &rs, gpu::StateFlags::WIREFRAME, false);
LuaWrapper::getOptionalFlagField(L, idx, "depth_write", &rs, gpu::StateFlags::DEPTH_WRITE, true);
LuaWrapper::getOptionalField(L, idx, "stencil_func", reinterpret_cast<u8*>(&stencil_func));
LuaWrapper::getOptionalField(L, idx, "stencil_write_mask", &stencil_write_mask);
LuaWrapper::getOptionalField(L, idx, "stencil_ref", &stencil_ref);
@ -98,7 +98,7 @@ namespace LuaWrapper {
LuaWrapper::getOptionalField(L, idx, "stencil_zfail", reinterpret_cast<u8*>(&stencil_zfail));
LuaWrapper::getOptionalField(L, idx, "stencil_zpass", reinterpret_cast<u8*>(&stencil_zpass));
rs |= gpu::getStencilStateBits(stencil_write_mask, stencil_func, stencil_ref, stencil_mask, stencil_sfail, stencil_zfail, stencil_zpass);
rs = rs | gpu::getStencilStateBits(stencil_write_mask, stencil_func, stencil_ref, stencil_mask, stencil_sfail, stencil_zfail, stencil_zpass);
return {rs};
}
@ -635,11 +635,11 @@ struct PipelineImpl final : Pipeline
-1, 1, 1
};
const Renderer::MemRef vb_mem = m_renderer.copy(cube_verts, sizeof(cube_verts));
m_cube_vb = m_renderer.createBuffer(vb_mem, (u32)gpu::BufferFlags::IMMUTABLE);
m_cube_vb = m_renderer.createBuffer(vb_mem, gpu::BufferFlags::IMMUTABLE);
Renderer::MemRef no_mem;
no_mem.size = sizeof(Matrix) * 128;
m_shadow_atlas.uniform_buffer = m_renderer.createBuffer(no_mem, (u32)gpu::BufferFlags::UNIFORM_BUFFER);
m_shadow_atlas.uniform_buffer = m_renderer.createBuffer(no_mem, gpu::BufferFlags::UNIFORM_BUFFER);
u16 cube_indices[] = {
0, 1, 2,
@ -657,20 +657,20 @@ struct PipelineImpl final : Pipeline
};
const Renderer::MemRef ib_mem = m_renderer.copy(cube_indices, sizeof(cube_indices));
m_cube_ib = m_renderer.createBuffer(ib_mem, (u32)gpu::BufferFlags::IMMUTABLE);
m_cube_ib = m_renderer.createBuffer(ib_mem, gpu::BufferFlags::IMMUTABLE);
m_resource->onLoaded<&PipelineImpl::onStateChanged>(this);
GlobalState global_state;
const Renderer::MemRef global_state_mem = m_renderer.copy(&global_state, sizeof(global_state));
m_global_state_buffer = m_renderer.createBuffer(global_state_mem, (u32)gpu::BufferFlags::UNIFORM_BUFFER);
m_global_state_buffer = m_renderer.createBuffer(global_state_mem, gpu::BufferFlags::UNIFORM_BUFFER);
PassState pass_state;
const Renderer::MemRef pass_state_mem = m_renderer.copy(&pass_state, sizeof(pass_state));
m_pass_state_buffer = m_renderer.createBuffer(pass_state_mem, (u32)gpu::BufferFlags::UNIFORM_BUFFER);
m_pass_state_buffer = m_renderer.createBuffer(pass_state_mem, gpu::BufferFlags::UNIFORM_BUFFER);
const Renderer::MemRef dc_mem = { DRAWCALL_UB_SIZE, nullptr, false };
const u32 dc_ub_flags = (u32)gpu::BufferFlags::UNIFORM_BUFFER;
const gpu::BufferFlags dc_ub_flags = gpu::BufferFlags::UNIFORM_BUFFER;
m_drawcall_ub = m_renderer.createBuffer(dc_mem, dc_ub_flags);
m_base_vertex_decl.addAttribute(0, 0, 3, gpu::AttributeType::FLOAT, 0);
@ -1228,7 +1228,7 @@ struct PipelineImpl final : Pipeline
gpu::update(pipeline->m_drawcall_ub, &Matrix::IDENTITY.columns[0].x, sizeof(Matrix));
gpu::setState(u64(gpu::StateFlags::DEPTH_TEST) | u64(gpu::StateFlags::DEPTH_WRITE) | u64(gpu::StateFlags::CULL_BACK));
gpu::setState(gpu::StateFlags::DEPTH_TEST | gpu::StateFlags::DEPTH_WRITE | gpu::StateFlags::CULL_BACK);
gpu::useProgram(program);
gpu::bindIndexBuffer(gpu::INVALID_BUFFER);
@ -1290,7 +1290,7 @@ struct PipelineImpl final : Pipeline
gpu::update(pipeline->m_drawcall_ub, &Matrix::IDENTITY.columns[0].x, sizeof(Matrix));
gpu::setState(u64(gpu::StateFlags::DEPTH_TEST) | u64(gpu::StateFlags::DEPTH_WRITE));
gpu::setState(gpu::StateFlags::DEPTH_TEST | gpu::StateFlags::DEPTH_WRITE);
gpu::useProgram(program);
gpu::bindIndexBuffer(gpu::INVALID_BUFFER);
@ -1372,8 +1372,8 @@ struct PipelineImpl final : Pipeline
gpu::update(pipeline->m_drawcall_ub, &size.x, sizeof(size));
u32 elem_offset = 0;
u64 state = gpu::getBlendStateBits(gpu::BlendFactors::SRC_ALPHA, gpu::BlendFactors::ONE_MINUS_SRC_ALPHA, gpu::BlendFactors::ONE, gpu::BlendFactors::ONE);
state |= (u64)gpu::StateFlags::SCISSOR_TEST;
gpu::StateFlags state = gpu::getBlendStateBits(gpu::BlendFactors::SRC_ALPHA, gpu::BlendFactors::ONE_MINUS_SRC_ALPHA, gpu::BlendFactors::ONE, gpu::BlendFactors::ONE);
state = state | gpu::StateFlags::SCISSOR_TEST;
gpu::setState(state);
gpu::useProgram(program);
gpu::bindIndexBuffer(idx_buffer_mem.buffer);
@ -1501,10 +1501,10 @@ struct PipelineImpl final : Pipeline
PROFILE_FUNCTION();
const gpu::TextureFormat format = getFormat(format_str);
const u32 flags = (u32)gpu::TextureFlags::RENDER_TARGET
| (u32)gpu::TextureFlags::NO_MIPS
| (u32)gpu::TextureFlags::CLAMP_U
| (u32)gpu::TextureFlags::CLAMP_V;
const gpu::TextureFlags flags = gpu::TextureFlags::RENDER_TARGET
| gpu::TextureFlags::NO_MIPS
| gpu::TextureFlags::CLAMP_U
| gpu::TextureFlags::CLAMP_V;
for (int i = 0, n = m_renderbuffers.size(); i < n; ++i)
{
Renderbuffer& rb = m_renderbuffers[i];
@ -1577,7 +1577,7 @@ struct PipelineImpl final : Pipeline
LuaWrapper::getOptionalField<const char*>(L, 2, "define", &define);
cmd.m_define_mask = define[0] ? 1 << m_renderer.getShaderDefineIdx(define) : 0;
}
cmd.m_render_state = state.get({0}).value;
cmd.m_render_state = state.get({gpu::StateFlags::NONE}).value;
cmd.m_pipeline = this;
cmd.m_camera_params = cp;
cmd.m_compute_shader = m_place_grass_shader->getProgram(gpu::VertexDecl(), 0);
@ -1640,8 +1640,8 @@ struct PipelineImpl final : Pipeline
gpu::pushDebugGroup("particles");
const u64 blend_state = gpu::getBlendStateBits(gpu::BlendFactors::SRC_ALPHA, gpu::BlendFactors::ONE_MINUS_SRC_ALPHA, gpu::BlendFactors::SRC_ALPHA, gpu::BlendFactors::ONE_MINUS_SRC_ALPHA);
gpu::setState(blend_state | (u32)gpu::StateFlags::DEPTH_TEST);
const gpu::StateFlags blend_state = gpu::getBlendStateBits(gpu::BlendFactors::SRC_ALPHA, gpu::BlendFactors::ONE_MINUS_SRC_ALPHA, gpu::BlendFactors::SRC_ALPHA, gpu::BlendFactors::ONE_MINUS_SRC_ALPHA);
gpu::setState(blend_state | gpu::StateFlags::DEPTH_TEST);
for (const Drawcall& dc : m_drawcalls) {
Matrix mtx = dc.rot.toMatrix();
mtx.setTranslation(dc.pos);
@ -1765,7 +1765,7 @@ struct PipelineImpl final : Pipeline
void setup() override {}
void execute() override {
PROFILE_FUNCTION();
gpu::bindShaderBuffer(buffer, binding_point, writable ? (u32)gpu::BindShaderBufferFlags::OUTPUT : 0);
gpu::bindShaderBuffer(buffer, binding_point, writable ? gpu::BindShaderBufferFlags::OUTPUT : gpu::BindShaderBufferFlags::NONE);
}
u32 binding_point;
bool writable;
@ -1803,7 +1803,7 @@ struct PipelineImpl final : Pipeline
mem.own = false;
mem.data = nullptr;
mem.size = size;
const gpu::BufferHandle buffer = m_renderer.createBuffer(mem, (u32)gpu::BufferFlags::COMPUTE_WRITE | (u32)gpu::BufferFlags::SHADER_BUFFER);
const gpu::BufferHandle buffer = m_renderer.createBuffer(mem, gpu::BufferFlags::COMPUTE_WRITE | gpu::BufferFlags::SHADER_BUFFER);
m_buffers.push(buffer);
return buffer;
}
@ -1816,7 +1816,7 @@ struct PipelineImpl final : Pipeline
, height
, 1
, format
, (u32)gpu::TextureFlags::CLAMP_U | (u32)gpu::TextureFlags::CLAMP_V | (u32)gpu::TextureFlags::NO_MIPS | (u32)gpu::TextureFlags::COMPUTE_WRITE
, gpu::TextureFlags::CLAMP_U | gpu::TextureFlags::CLAMP_V | gpu::TextureFlags::NO_MIPS | gpu::TextureFlags::COMPUTE_WRITE
, mem
, debug_name.get("lua_texture"));
m_textures.push(texture);
@ -1831,7 +1831,7 @@ struct PipelineImpl final : Pipeline
, height
, depth
, format
, (u32)gpu::TextureFlags::IS_3D | (u32)gpu::TextureFlags::COMPUTE_WRITE | (u32)gpu::TextureFlags::NO_MIPS
, gpu::TextureFlags::IS_3D | gpu::TextureFlags::COMPUTE_WRITE | gpu::TextureFlags::NO_MIPS
, mem
, debug_name.get("lua_texture"));
m_textures.push(texture);
@ -2084,7 +2084,7 @@ struct PipelineImpl final : Pipeline
int m_indices_count;
int m_indices_offset;
u32 m_define_mask = 0;
u64 m_render_state;
gpu::StateFlags m_render_state;
gpu::ProgramHandle m_program;
};
@ -2093,12 +2093,12 @@ struct PipelineImpl final : Pipeline
if (lua_gettop(L) > 3) LuaWrapper::checkTableArg(L, 4);
const u64 rs = [&](){
const gpu::StateFlags rs = [&](){
if(lua_gettop(L) > 4) {
LuaWrapper::checkTableArg(L, 5);
return getState(L, 5);
}
return (u64)gpu::StateFlags::DEPTH_WRITE | (u64)gpu::StateFlags::DEPTH_TEST;
return gpu::StateFlags::DEPTH_WRITE | gpu::StateFlags::DEPTH_TEST;
}();
Shader* shader = nullptr;
@ -2267,8 +2267,8 @@ struct PipelineImpl final : Pipeline
if (vb.size == 0) return;
gpu::useProgram(m_program);
const u64 blend_state = gpu::getBlendStateBits(gpu::BlendFactors::SRC_ALPHA, gpu::BlendFactors::ONE_MINUS_SRC_ALPHA, gpu::BlendFactors::SRC_ALPHA, gpu::BlendFactors::ONE_MINUS_SRC_ALPHA);
gpu::setState((u64)gpu::StateFlags::DEPTH_WRITE | (u64)gpu::StateFlags::DEPTH_TEST | blend_state);
const gpu::StateFlags blend_state = gpu::getBlendStateBits(gpu::BlendFactors::SRC_ALPHA, gpu::BlendFactors::ONE_MINUS_SRC_ALPHA, gpu::BlendFactors::SRC_ALPHA, gpu::BlendFactors::ONE_MINUS_SRC_ALPHA);
gpu::setState(gpu::StateFlags::DEPTH_WRITE | gpu::StateFlags::DEPTH_TEST | blend_state);
gpu::bindTextures(&m_atlas, 0, 1);
gpu::bindIndexBuffer(gpu::INVALID_BUFFER);
gpu::bindVertexBuffer(0, vb.buffer, vb.offset, 24);
@ -2312,7 +2312,7 @@ struct PipelineImpl final : Pipeline
return;
}
const u64 blend_state = gpu::getBlendStateBits(gpu::BlendFactors::ONE, gpu::BlendFactors::ONE, gpu::BlendFactors::ONE, gpu::BlendFactors::ONE);
const gpu::StateFlags blend_state = gpu::getBlendStateBits(gpu::BlendFactors::ONE, gpu::BlendFactors::ONE, gpu::BlendFactors::ONE, gpu::BlendFactors::ONE);
CmdPage* page = m_cmds;
while (page) {
const u8* cmd = page->data;
@ -2329,7 +2329,7 @@ struct PipelineImpl final : Pipeline
gpu::useProgram(m_program);
if(total_count - nonintersecting_count) {
gpu::setState(blend_state | (u64)gpu::StateFlags::CULL_FRONT);
gpu::setState(blend_state | gpu::StateFlags::CULL_FRONT);
const u32 offs = offset + sizeof(float) * 16 * nonintersecting_count;
gpu::bindIndexBuffer(m_pipeline->m_cube_ib);
gpu::bindVertexBuffer(0, m_pipeline->m_cube_vb, 0, 12);
@ -2338,7 +2338,7 @@ struct PipelineImpl final : Pipeline
}
if (nonintersecting_count) {
gpu::setState(blend_state | (u64)gpu::StateFlags::DEPTH_TEST | (u64)gpu::StateFlags::CULL_BACK);
gpu::setState(blend_state | gpu::StateFlags::DEPTH_TEST | gpu::StateFlags::CULL_BACK);
gpu::bindIndexBuffer(m_pipeline->m_cube_ib);
gpu::bindVertexBuffer(0, m_pipeline->m_cube_vb, 0, 12);
gpu::bindVertexBuffer(1, buffer, offset, 64);
@ -2376,7 +2376,7 @@ struct PipelineImpl final : Pipeline
m_renderer.queue(job, m_profiler_link);
}
static u64 getState(lua_State* L, int idx)
static gpu::StateFlags getState(lua_State* L, int idx)
{
gpu::StencilFuncs stencil_func = gpu::StencilFuncs::DISABLE;
u8 stencil_write_mask = 0xff;
@ -2387,19 +2387,19 @@ struct PipelineImpl final : Pipeline
gpu::StencilOps stencil_zpass = gpu::StencilOps::KEEP;
char tmp[64];
u64 rs = (u64)gpu::StateFlags::DEPTH_TEST | (u64)gpu::StateFlags::DEPTH_WRITE;
gpu::StateFlags rs = gpu::StateFlags::DEPTH_TEST | gpu::StateFlags::DEPTH_WRITE;
if (LuaWrapper::getOptionalStringField(L, idx, "blending", Span(tmp))) {
if(equalIStrings(tmp, "add")) {
rs |= gpu::getBlendStateBits(gpu::BlendFactors::ONE, gpu::BlendFactors::ONE, gpu::BlendFactors::ONE, gpu::BlendFactors::ONE);
rs = rs | gpu::getBlendStateBits(gpu::BlendFactors::ONE, gpu::BlendFactors::ONE, gpu::BlendFactors::ONE, gpu::BlendFactors::ONE);
}
else if(equalIStrings(tmp, "alpha")) {
rs |= gpu::getBlendStateBits(gpu::BlendFactors::SRC_ALPHA, gpu::BlendFactors::ONE_MINUS_SRC_ALPHA, gpu::BlendFactors::SRC_ALPHA, gpu::BlendFactors::ONE_MINUS_SRC_ALPHA);
rs = rs | gpu::getBlendStateBits(gpu::BlendFactors::SRC_ALPHA, gpu::BlendFactors::ONE_MINUS_SRC_ALPHA, gpu::BlendFactors::SRC_ALPHA, gpu::BlendFactors::ONE_MINUS_SRC_ALPHA);
}
else if(equalIStrings(tmp, "multiply")) {
rs |= gpu::getBlendStateBits(gpu::BlendFactors::DST_COLOR, gpu::BlendFactors::ZERO, gpu::BlendFactors::ONE, gpu::BlendFactors::ZERO);
rs = rs | gpu::getBlendStateBits(gpu::BlendFactors::DST_COLOR, gpu::BlendFactors::ZERO, gpu::BlendFactors::ONE, gpu::BlendFactors::ZERO);
}
else if(equalIStrings(tmp, "dual")) {
rs |= gpu::getBlendStateBits(gpu::BlendFactors::ONE, gpu::BlendFactors::SRC1_COLOR, gpu::BlendFactors::ONE, gpu::BlendFactors::ONE);
rs = rs | gpu::getBlendStateBits(gpu::BlendFactors::ONE, gpu::BlendFactors::SRC1_COLOR, gpu::BlendFactors::ONE, gpu::BlendFactors::ONE);
}
else if(equalIStrings(tmp, "")) {
}
@ -2408,9 +2408,9 @@ struct PipelineImpl final : Pipeline
}
}
LuaWrapper::getOptionalFlagField(L, idx, "depth_test", &rs, (u64)gpu::StateFlags::DEPTH_TEST, true);
LuaWrapper::getOptionalFlagField(L, idx, "wireframe", &rs, (u64)gpu::StateFlags::WIREFRAME, false);
LuaWrapper::getOptionalFlagField(L, idx, "depth_write", &rs, (u64)gpu::StateFlags::DEPTH_WRITE, true);
LuaWrapper::getOptionalFlagField(L, idx, "depth_test", &rs, gpu::StateFlags::DEPTH_TEST, true);
LuaWrapper::getOptionalFlagField(L, idx, "wireframe", &rs, gpu::StateFlags::WIREFRAME, false);
LuaWrapper::getOptionalFlagField(L, idx, "depth_write", &rs, gpu::StateFlags::DEPTH_WRITE, true);
LuaWrapper::getOptionalField(L, idx, "stencil_func", reinterpret_cast<u8*>(&stencil_func));
LuaWrapper::getOptionalField(L, idx, "stencil_write_mask", &stencil_write_mask);
LuaWrapper::getOptionalField(L, idx, "stencil_ref", &stencil_ref);
@ -2419,7 +2419,7 @@ struct PipelineImpl final : Pipeline
LuaWrapper::getOptionalField(L, idx, "stencil_zfail", reinterpret_cast<u8*>(&stencil_zfail));
LuaWrapper::getOptionalField(L, idx, "stencil_zpass", reinterpret_cast<u8*>(&stencil_zpass));
rs |= gpu::getStencilStateBits(stencil_write_mask, stencil_func, stencil_ref, stencil_mask, stencil_sfail, stencil_zfail, stencil_zpass);
rs = rs | gpu::getStencilStateBits(stencil_write_mask, stencil_func, stencil_ref, stencil_mask, stencil_sfail, stencil_zfail, stencil_zpass);
return rs;
}
@ -2483,10 +2483,10 @@ struct PipelineImpl final : Pipeline
gpu::bindTextures(&p.texture, m_texture_offset, 1);
u64 blend_state = gpu::getBlendStateBits(gpu::BlendFactors::ONE_MINUS_DST_ALPHA, gpu::BlendFactors::ONE, gpu::BlendFactors::ONE_MINUS_DST_ALPHA, gpu::BlendFactors::ONE);
const u64 state = p.intersecting
? (u64)gpu::StateFlags::CULL_FRONT
: (u64)gpu::StateFlags::DEPTH_TEST | (u64)gpu::StateFlags::CULL_BACK;
gpu::StateFlags blend_state = gpu::getBlendStateBits(gpu::BlendFactors::ONE_MINUS_DST_ALPHA, gpu::BlendFactors::ONE, gpu::BlendFactors::ONE_MINUS_DST_ALPHA, gpu::BlendFactors::ONE);
const gpu::StateFlags state = p.intersecting
? gpu::StateFlags::CULL_FRONT
: gpu::StateFlags::DEPTH_TEST | gpu::StateFlags::CULL_BACK;
gpu::setState(state | blend_state);
gpu::drawTriangles(0, 36, gpu::DataType::U16);
}
@ -2712,12 +2712,12 @@ struct PipelineImpl final : Pipeline
if (buffer.capacity < capacity) {
if (buffer.buffer) gpu::destroy(buffer.buffer);
buffer.buffer = gpu::allocBufferHandle();
gpu::createBuffer(buffer.buffer, (u32)gpu::BufferFlags::SHADER_BUFFER, capacity, nullptr);
gpu::createBuffer(buffer.buffer, gpu::BufferFlags::SHADER_BUFFER, capacity, nullptr);
buffer.capacity = capacity;
}
if (!data.empty()) {
gpu::update(buffer.buffer, data.begin(), data.byte_size());
gpu::bindShaderBuffer(buffer.buffer, idx, 0);
gpu::bindShaderBuffer(buffer.buffer, idx, gpu::BindShaderBufferFlags::NONE);
}
};
@ -2882,7 +2882,7 @@ struct PipelineImpl final : Pipeline
Stats stats = {};
const u64 render_states = m_render_state;
const gpu::StateFlags render_states = m_render_state;
gpu::bindUniformBuffer(4, m_pipeline->m_drawcall_ub, 0, DRAWCALL_UB_SIZE);
const gpu::BufferHandle material_ub = renderer.getMaterialUniformBuffer();
u32 material_ub_idx = 0xffFFffFF;
@ -3024,7 +3024,7 @@ struct PipelineImpl final : Pipeline
CmdPage* m_cmds;
PipelineImpl* m_pipeline;
u32 m_bucket_id;
u64 m_render_state;
gpu::StateFlags m_render_state;
};
void createCommands(const View& view
@ -3547,7 +3547,7 @@ struct PipelineImpl final : Pipeline
if (!m_shadow_atlas.texture) {
Renderer::MemRef mem;
m_shadow_atlas.texture = m_renderer.createTexture(ShadowAtlas::SIZE, ShadowAtlas::SIZE, 1, gpu::TextureFormat::D32, (u32)gpu::TextureFlags::NO_MIPS, mem, "shadow_atlas");
m_shadow_atlas.texture = m_renderer.createTexture(ShadowAtlas::SIZE, ShadowAtlas::SIZE, 1, gpu::TextureFormat::D32, gpu::TextureFlags::NO_MIPS, mem, "shadow_atlas");
}
for (u32 i = 0; i < atlas_sorter.count; ++i) {
@ -3591,7 +3591,7 @@ struct PipelineImpl final : Pipeline
PipelineImpl* pipeline;
gpu::TextureHandle rbs[8];
gpu::TextureHandle ds;
u32 flags;
gpu::FramebufferFlags flags;
u32 count;
u32 w;
u32 h;
@ -3607,9 +3607,9 @@ struct PipelineImpl final : Pipeline
cmd.pipeline = this;
cmd.ds = ds;
cmd.count = renderbuffers.length();
cmd.flags = srgb ? (u32)gpu::FramebufferFlags::SRGB : 0;
cmd.flags = srgb ? gpu::FramebufferFlags::SRGB : gpu::FramebufferFlags::NONE;
if (readonly_ds) {
cmd.flags |= (u32)gpu::FramebufferFlags::READONLY_DEPTH_STENCIL;
cmd.flags = cmd.flags | gpu::FramebufferFlags::READONLY_DEPTH_STENCIL;
}
cmd.w = m_viewport.w;
cmd.h = m_viewport.h;
@ -3718,7 +3718,7 @@ struct PipelineImpl final : Pipeline
// TODO reuse
gpu::BufferHandle data = gpu::allocBufferHandle();
gpu::BufferHandle indirect = gpu::allocBufferHandle();
gpu::createBuffer(data, (u32)gpu::BufferFlags::SHADER_BUFFER | (u32)gpu::BufferFlags::COMPUTE_WRITE, 1024 * 256 * 8, nullptr);
gpu::createBuffer(data, gpu::BufferFlags::SHADER_BUFFER | gpu::BufferFlags::COMPUTE_WRITE, 1024 * 256 * 8, nullptr);
struct Indirect {
u32 vertex_count;
u32 instance_count;
@ -3726,7 +3726,7 @@ struct PipelineImpl final : Pipeline
u32 base_vertex;
u32 base_instance;
};
gpu::createBuffer(indirect, (u32)gpu::BufferFlags::SHADER_BUFFER | (u32)gpu::BufferFlags::COMPUTE_WRITE, sizeof(Indirect), nullptr);
gpu::createBuffer(indirect, gpu::BufferFlags::SHADER_BUFFER | gpu::BufferFlags::COMPUTE_WRITE, sizeof(Indirect), nullptr);
for (const Grass& grass : m_grass) {
struct {
@ -3765,8 +3765,8 @@ struct PipelineImpl final : Pipeline
indirect_dc.instance_count = 0;
gpu::update(indirect, &indirect_dc, sizeof(indirect_dc));
gpu::bindShaderBuffer(data, 0, (u32)gpu::BindShaderBufferFlags::OUTPUT);
gpu::bindShaderBuffer(indirect, 1, (u32)gpu::BindShaderBufferFlags::OUTPUT);
gpu::bindShaderBuffer(data, 0, gpu::BindShaderBufferFlags::OUTPUT);
gpu::bindShaderBuffer(indirect, 1, gpu::BindShaderBufferFlags::OUTPUT);
gpu::bindTextures(&grass.heightmap, 2, 1);
gpu::bindTextures(&grass.splatmap, 3, 1);
gpu::bindUniformBuffer(4, m_pipeline->m_drawcall_ub, 0, sizeof(dc));
@ -3776,8 +3776,8 @@ struct PipelineImpl final : Pipeline
gpu::dispatch((size.x + 15) / 16, (size.y + 15) / 16, 1);
renderer.endProfileBlock();
gpu::bindShaderBuffer(gpu::INVALID_BUFFER, 0, 0);
gpu::bindShaderBuffer(gpu::INVALID_BUFFER, 1, 0);
gpu::bindShaderBuffer(gpu::INVALID_BUFFER, 0, gpu::BindShaderBufferFlags::NONE);
gpu::bindShaderBuffer(gpu::INVALID_BUFFER, 1, gpu::BindShaderBufferFlags::NONE);
gpu::useProgram(grass.program);
gpu::bindTextures(grass.material->textures, 0, grass.material->textures_count);
@ -3789,7 +3789,7 @@ struct PipelineImpl final : Pipeline
material_ub_idx = grass.material->material_constants;
}
gpu::setState(u64(gpu::StateFlags::DEPTH_TEST) | u64(gpu::StateFlags::DEPTH_WRITE) | m_render_state);
gpu::setState(gpu::StateFlags::DEPTH_TEST | gpu::StateFlags::DEPTH_WRITE | m_render_state);
gpu::bindIndirectBuffer(indirect);
gpu::drawIndirect(grass.mesh->index_type);
@ -3827,7 +3827,7 @@ struct PipelineImpl final : Pipeline
Array<Grass> m_grass;
PipelineImpl* m_pipeline;
CameraParams m_camera_params;
u64 m_render_state;
gpu::StateFlags m_render_state;
u32 m_define_mask = 0;
};
@ -3868,7 +3868,7 @@ struct PipelineImpl final : Pipeline
const gpu::BufferHandle material_ub = m_pipeline->m_renderer.getMaterialUniformBuffer();
u64 state = m_render_state;
gpu::StateFlags state = m_render_state;
for (Instance& inst : m_instances) {
Renderer& renderer = m_pipeline->m_renderer;
renderer.beginProfileBlock("terrain", 0);
@ -3962,7 +3962,7 @@ struct PipelineImpl final : Pipeline
IAllocator& m_allocator;
PipelineImpl* m_pipeline;
CameraParams m_camera_params;
u64 m_render_state;
gpu::StateFlags m_render_state;
Array<Instance> m_instances;
gpu::TextureHandle m_global_textures[16];
int m_global_textures_count = 0;
@ -4217,12 +4217,12 @@ struct PipelineImpl final : Pipeline
}
Vec4 color;
float depth;
u32 flags;
gpu::ClearFlags flags;
};
Cmd& cmd = m_renderer.createJob<Cmd>();
cmd.color.set(r, g, b, a);
cmd.flags = flags;
cmd.flags = (gpu::ClearFlags)flags;
cmd.depth = depth;
m_renderer.queue(cmd, m_profiler_link);
}
@ -4348,7 +4348,7 @@ struct PipelineImpl final : Pipeline
Array<u32> pixels(allocator);
pixels.resize(w * h);
gpu::TextureHandle staging = gpu::allocTextureHandle();
const u32 flags = u32(gpu::TextureFlags::NO_MIPS) | u32(gpu::TextureFlags::READBACK);
const gpu::TextureFlags flags = gpu::TextureFlags::NO_MIPS | gpu::TextureFlags::READBACK;
gpu::createTexture(staging, w, h, 1, gpu::TextureFormat::RGBA8, flags, nullptr, "staging_buffer");
gpu::copy(staging, handle, 0, 0);
gpu::readTexture(staging, 0, Span((u8*)pixels.begin(), pixels.byte_size()));

View file

@ -40,7 +40,7 @@ struct TransientBuffer {
void init() {
m_buffer = gpu::allocBufferHandle();
m_offset = 0;
gpu::createBuffer(m_buffer, (u32)gpu::BufferFlags::MAPPABLE, INIT_SIZE, nullptr);
gpu::createBuffer(m_buffer, gpu::BufferFlags::MAPPABLE, INIT_SIZE, nullptr);
m_size = INIT_SIZE;
m_ptr = (u8*)gpu::map(m_buffer, INIT_SIZE);
}
@ -80,7 +80,7 @@ struct TransientBuffer {
m_ptr = nullptr;
if (m_overflow.buffer) {
gpu::createBuffer(m_overflow.buffer, 0, nextPow2(m_overflow.size + m_size), nullptr);
gpu::createBuffer(m_overflow.buffer, gpu::BufferFlags::NONE, nextPow2(m_overflow.size + m_size), nullptr);
gpu::update(m_overflow.buffer, m_overflow.data, m_overflow.size);
OS::memRelease(m_overflow.data);
m_overflow.data = nullptr;
@ -551,7 +551,7 @@ struct RendererImpl final : Renderer
registerProperties(m_engine.getAllocator());
struct InitData {
u32 flags = (u32)gpu::InitFlags::VSYNC;
gpu::InitFlags flags = gpu::InitFlags::VSYNC;
RendererImpl* renderer;
} init_data;
init_data.renderer = this;
@ -561,10 +561,10 @@ struct RendererImpl final : Renderer
CommandLineParser cmd_line_parser(cmd_line);
while (cmd_line_parser.next()) {
if (cmd_line_parser.currentEquals("-no_vsync")) {
init_data.flags &= ~(u32)gpu::InitFlags::VSYNC;
init_data.flags = init_data.flags & ~gpu::InitFlags::VSYNC;
}
else if (cmd_line_parser.currentEquals("-debug_opengl")) {
init_data.flags |= (u32)gpu::InitFlags::DEBUG_OUTPUT;
init_data.flags = init_data.flags | gpu::InitFlags::DEBUG_OUTPUT;
}
}
@ -610,12 +610,12 @@ struct RendererImpl final : Renderer
}
mb.data.back().next_free = -1;
gpu::createBuffer(mb.buffer
, (u32)gpu::BufferFlags::UNIFORM_BUFFER
, gpu::BufferFlags::UNIFORM_BUFFER
, sizeof(MaterialConsts) * 400
, nullptr
);
gpu::createBuffer(mb.staging_buffer
, (u32)gpu::BufferFlags::UNIFORM_BUFFER
, gpu::BufferFlags::UNIFORM_BUFFER
, sizeof(MaterialConsts)
, nullptr
);
@ -695,7 +695,7 @@ struct RendererImpl final : Renderer
PROFILE_FUNCTION();
gpu::pushDebugGroup("get image data");
gpu::TextureHandle staging = gpu::allocTextureHandle();
const u32 flags = u32(gpu::TextureFlags::NO_MIPS) | u32(gpu::TextureFlags::READBACK);
const gpu::TextureFlags flags = gpu::TextureFlags::NO_MIPS | gpu::TextureFlags::READBACK;
gpu::createTexture(staging, w, h, 1, out_format, flags, nullptr, "staging_buffer");
gpu::copy(staging, handle, 0, 0);
gpu::readTexture(staging, 0, buf);
@ -758,7 +758,7 @@ struct RendererImpl final : Renderer
}
gpu::TextureHandle loadTexture(const MemRef& memory, u32 flags, gpu::TextureInfo* info, const char* debug_name) override
gpu::TextureHandle loadTexture(const MemRef& memory, gpu::TextureFlags flags, gpu::TextureInfo* info, const char* debug_name) override
{
ASSERT(memory.size > 0);
@ -782,7 +782,7 @@ struct RendererImpl final : Renderer
StaticString<MAX_PATH_LENGTH> debug_name;
gpu::TextureHandle handle;
MemRef memory;
u32 flags;
gpu::TextureFlags flags;
RendererImpl* renderer;
};
@ -842,7 +842,7 @@ struct RendererImpl final : Renderer
}
gpu::BufferHandle createBuffer(const MemRef& memory, u32 flags) override
gpu::BufferHandle createBuffer(const MemRef& memory, gpu::BufferFlags flags) override
{
gpu::BufferHandle handle = gpu::allocBufferHandle();
if(!handle) return handle;
@ -859,7 +859,7 @@ struct RendererImpl final : Renderer
gpu::BufferHandle handle;
MemRef memory;
u32 flags;
gpu::BufferFlags flags;
gpu::TextureFormat format;
Renderer* renderer;
};
@ -961,7 +961,7 @@ struct RendererImpl final : Renderer
}
gpu::TextureHandle createTexture(u32 w, u32 h, u32 depth, gpu::TextureFormat format, u32 flags, const MemRef& memory, const char* debug_name) override
gpu::TextureHandle createTexture(u32 w, u32 h, u32 depth, gpu::TextureFormat format, gpu::TextureFlags flags, const MemRef& memory, const char* debug_name) override
{
gpu::TextureHandle handle = gpu::allocTextureHandle();
if(!handle) return handle;
@ -983,7 +983,7 @@ struct RendererImpl final : Renderer
u32 depth;
gpu::TextureFormat format;
Renderer* renderer;
u32 flags;
gpu::TextureFlags flags;
};
Cmd& cmd = createJob<Cmd>();

View file

@ -82,12 +82,12 @@ struct LUMIX_RENDERER_API Renderer : IPlugin
virtual void free(const MemRef& memory) = 0;
virtual TransientSlice allocTransient(u32 size) = 0;
virtual gpu::BufferHandle createBuffer(const MemRef& memory, u32 flags) = 0;
virtual gpu::BufferHandle createBuffer(const MemRef& memory, gpu::BufferFlags flags) = 0;
virtual void destroy(gpu::BufferHandle buffer) = 0;
virtual void destroy(gpu::ProgramHandle program) = 0;
virtual gpu::TextureHandle createTexture(u32 w, u32 h, u32 depth, gpu::TextureFormat format, u32 flags, const MemRef& memory, const char* debug_name) = 0;
virtual gpu::TextureHandle loadTexture(const MemRef& memory, u32 flags, gpu::TextureInfo* info, const char* debug_name) = 0;
virtual gpu::TextureHandle createTexture(u32 w, u32 h, u32 depth, gpu::TextureFormat format, gpu::TextureFlags flags, const MemRef& memory, const char* debug_name) = 0;
virtual gpu::TextureHandle loadTexture(const MemRef& memory, gpu::TextureFlags flags, gpu::TextureInfo* info, const char* debug_name) = 0;
virtual void updateTexture(gpu::TextureHandle handle, u32 slice, u32 x, u32 y, u32 w, u32 h, gpu::TextureFormat format, const MemRef& memory) = 0;
virtual void getTextureImage(gpu::TextureHandle texture, u32 w, u32 h, gpu::TextureFormat out_format, Span<u8> data) = 0;
virtual void destroy(gpu::TextureHandle tex) = 0;

View file

@ -76,7 +76,7 @@ void Texture::destroy()
bool Texture::create(u32 w, u32 h, gpu::TextureFormat format, const void* data, u32 size)
{
Renderer::MemRef memory = renderer.copy(data, size);
handle = renderer.createTexture(w, h, 1, format, getGPUFlags() | (u32)gpu::TextureFlags::NO_MIPS, memory, getPath().c_str());
handle = renderer.createTexture(w, h, 1, format, getGPUFlags() | gpu::TextureFlags::NO_MIPS, memory, getPath().c_str());
mips = 1;
width = w;
height = h;
@ -323,13 +323,13 @@ static bool loadRaw(Texture& texture, InputMemoryStream& file, IAllocator& alloc
const Renderer::MemRef dst_mem = texture.renderer.copy(data, (u32)size);
const u32 flag_3d = header.depth > 1 && !header.is_array ? (u32)gpu::TextureFlags::IS_3D : 0;
const gpu::TextureFlags flag_3d = header.depth > 1 && !header.is_array ? gpu::TextureFlags::IS_3D : gpu::TextureFlags::NONE;
texture.handle = texture.renderer.createTexture(texture.width
, texture.height
, texture.depth
, texture.format
, (texture.getGPUFlags() & ~(u32)gpu::TextureFlags::SRGB) | flag_3d | (u32)gpu::TextureFlags::NO_MIPS
, (texture.getGPUFlags() & ~gpu::TextureFlags::SRGB) | flag_3d | gpu::TextureFlags::NO_MIPS
, dst_mem
, texture.getPath().c_str());
texture.mips = 1;
@ -390,7 +390,7 @@ bool Texture::loadTGA(IInputStream& file)
, header.height
, 1
, format
, getGPUFlags() & ~(u32)gpu::TextureFlags::SRGB
, getGPUFlags() & ~gpu::TextureFlags::SRGB
, mem
, getPath().c_str());
depth = 1;
@ -506,7 +506,7 @@ bool Texture::loadTGA(IInputStream& file)
, header.height
, 1
, format
, getGPUFlags() & ~(u32)gpu::TextureFlags::SRGB
, getGPUFlags() & ~gpu::TextureFlags::SRGB
, mem
, getPath().c_str());
depth = 1;
@ -559,23 +559,23 @@ static bool loadDDS(Texture& texture, IInputStream& file)
}
u32 Texture::getGPUFlags() const
gpu::TextureFlags Texture::getGPUFlags() const
{
u32 gpu_flags = 0;
gpu::TextureFlags gpu_flags = gpu::TextureFlags::NONE;
if(flags & (u32)Flags::SRGB) {
gpu_flags |= (u32)gpu::TextureFlags::SRGB;
gpu_flags = gpu_flags | gpu::TextureFlags::SRGB;
}
if(flags & (u32)Flags::POINT) {
gpu_flags |= (u32)gpu::TextureFlags::POINT_FILTER;
gpu_flags = gpu_flags | gpu::TextureFlags::POINT_FILTER;
}
if (flags & (u32)Flags::CLAMP_U) {
gpu_flags |= (u32)gpu::TextureFlags::CLAMP_U;
gpu_flags = gpu_flags | gpu::TextureFlags::CLAMP_U;
}
if (flags & (u32)Flags::CLAMP_V) {
gpu_flags |= (u32)gpu::TextureFlags::CLAMP_V;
gpu_flags = gpu_flags | gpu::TextureFlags::CLAMP_V;
}
if (flags & (u32)Flags::CLAMP_W) {
gpu_flags |= (u32)gpu::TextureFlags::CLAMP_W;
gpu_flags = gpu_flags | gpu::TextureFlags::CLAMP_W;
}
return gpu_flags;
}

View file

@ -83,7 +83,7 @@ public:
void setFlag(Flags flag, bool value);
u32 getPixelNearest(u32 x, u32 y) const;
u32 getPixel(float x, float y) const;
u32 getGPUFlags() const;
gpu::TextureFlags getGPUFlags() const;
static bool saveTGA(IOutputStream* file,
int width,