diff options
author | Juan Linietsky <reduzio@gmail.com> | 2017-06-11 15:52:03 -0300 |
---|---|---|
committer | Juan Linietsky <reduzio@gmail.com> | 2017-06-11 15:52:03 -0300 |
commit | 4d50c7ad8c77efd304d343edf81a81c596958d7d (patch) | |
tree | 8dd9483ff3f09f5c420f241755c0a49ee42b8edc /drivers | |
parent | ec015a32ae4fed154ed6d0bd002c1e653d74a2c3 (diff) |
Restored multiple viewport function, as well as view modes.
Diffstat (limited to 'drivers')
-rw-r--r-- | drivers/gles3/rasterizer_scene_gles3.cpp | 243 | ||||
-rw-r--r-- | drivers/gles3/rasterizer_scene_gles3.h | 9 | ||||
-rw-r--r-- | drivers/gles3/rasterizer_storage_gles3.cpp | 118 | ||||
-rw-r--r-- | drivers/gles3/rasterizer_storage_gles3.h | 14 |
4 files changed, 246 insertions, 138 deletions
diff --git a/drivers/gles3/rasterizer_scene_gles3.cpp b/drivers/gles3/rasterizer_scene_gles3.cpp index 7152b49d27..8d8c5e556b 100644 --- a/drivers/gles3/rasterizer_scene_gles3.cpp +++ b/drivers/gles3/rasterizer_scene_gles3.cpp @@ -1290,8 +1290,11 @@ void RasterizerSceneGLES3::_setup_geometry(RenderList::Element *e, const Transfo storage->mesh_render_blend_shapes(s, e->instance->blend_values.ptr()); //rebind shader state.scene_shader.bind(); +#ifdef DEBUG_ENABLED + } else if (state.debug_draw == VS::VIEWPORT_DEBUG_DRAW_WIREFRAME && s->array_wireframe_id) { + glBindVertexArray(s->array_wireframe_id); // everything is so easy nowadays +#endif } else { - glBindVertexArray(s->array_id); // everything is so easy nowadays } @@ -1301,7 +1304,16 @@ void RasterizerSceneGLES3::_setup_geometry(RenderList::Element *e, const Transfo RasterizerStorageGLES3::MultiMesh *multi_mesh = static_cast<RasterizerStorageGLES3::MultiMesh *>(e->owner); RasterizerStorageGLES3::Surface *s = static_cast<RasterizerStorageGLES3::Surface *>(e->geometry); - glBindVertexArray(s->instancing_array_id); // use the instancing array ID +#ifdef DEBUG_ENABLED + if (state.debug_draw == VS::VIEWPORT_DEBUG_DRAW_WIREFRAME && s->instancing_array_wireframe_id) { + + glBindVertexArray(s->instancing_array_wireframe_id); // use the instancing array ID + } else +#endif + { + glBindVertexArray(s->instancing_array_id); // use the instancing array ID + } + glBindBuffer(GL_ARRAY_BUFFER, multi_mesh->buffer); //modify the buffer int stride = (multi_mesh->xform_floats + multi_mesh->color_floats) * 4; @@ -1366,13 +1378,26 @@ void RasterizerSceneGLES3::_setup_geometry(RenderList::Element *e, const Transfo sorter.sort(particle_array, particles->amount); glUnmapBuffer(GL_ARRAY_BUFFER); +#ifdef DEBUG_ENABLED + if (state.debug_draw == VS::VIEWPORT_DEBUG_DRAW_WIREFRAME && s->instancing_array_wireframe_id) { + glBindVertexArray(s->instancing_array_wireframe_id); // use the wireframe instancing array ID + } else +#endif + { - glBindVertexArray(s->instancing_array_id); // use the instancing array ID + glBindVertexArray(s->instancing_array_id); // use the instancing array ID + } glBindBuffer(GL_ARRAY_BUFFER, particles->particle_buffer_histories[1]); //modify the buffer } else { - - glBindVertexArray(s->instancing_array_id); // use the instancing array ID +#ifdef DEBUG_ENABLED + if (state.debug_draw == VS::VIEWPORT_DEBUG_DRAW_WIREFRAME && s->instancing_array_wireframe_id) { + glBindVertexArray(s->instancing_array_wireframe_id); // use the wireframe instancing array ID + } else +#endif + { + glBindVertexArray(s->instancing_array_id); // use the instancing array ID + } glBindBuffer(GL_ARRAY_BUFFER, particles->particle_buffers[0]); //modify the buffer } @@ -1421,7 +1446,15 @@ void RasterizerSceneGLES3::_render_geometry(RenderList::Element *e) { RasterizerStorageGLES3::Surface *s = static_cast<RasterizerStorageGLES3::Surface *>(e->geometry); - if (s->index_array_len > 0) { +#ifdef DEBUG_ENABLED + + if (state.debug_draw == VS::VIEWPORT_DEBUG_DRAW_WIREFRAME && s->array_wireframe_id) { + + glDrawElements(GL_LINES, s->index_wireframe_len, GL_UNSIGNED_INT, 0); + storage->info.render_vertices_count += s->index_array_len; + } else +#endif + if (s->index_array_len > 0) { glDrawElements(gl_primitive[s->primitive], s->index_array_len, (s->array_len >= (1 << 16)) ? GL_UNSIGNED_INT : GL_UNSIGNED_SHORT, 0); @@ -1442,7 +1475,15 @@ void RasterizerSceneGLES3::_render_geometry(RenderList::Element *e) { int amount = MAX(multi_mesh->size, multi_mesh->visible_instances); - if (s->index_array_len > 0) { +#ifdef DEBUG_ENABLED + + if (state.debug_draw == VS::VIEWPORT_DEBUG_DRAW_WIREFRAME && s->array_wireframe_id) { + + glDrawElementsInstanced(GL_LINES, s->index_wireframe_len, GL_UNSIGNED_INT, 0, amount); + storage->info.render_vertices_count += s->index_array_len * amount; + } else +#endif + if (s->index_array_len > 0) { glDrawElementsInstanced(gl_primitive[s->primitive], s->index_array_len, (s->array_len >= (1 << 16)) ? GL_UNSIGNED_INT : GL_UNSIGNED_SHORT, 0, amount); @@ -1600,8 +1641,15 @@ void RasterizerSceneGLES3::_render_geometry(RenderList::Element *e) { glEnableVertexAttribArray(12); //custom glVertexAttribPointer(12, 4, GL_FLOAT, GL_FALSE, stride, ((uint8_t *)NULL) + stride * split + sizeof(float) * 4 * 2); glVertexAttribDivisor(12, 1); +#ifdef DEBUG_ENABLED - if (s->index_array_len > 0) { + if (state.debug_draw == VS::VIEWPORT_DEBUG_DRAW_WIREFRAME && s->array_wireframe_id) { + + glDrawElementsInstanced(GL_LINES, s->index_wireframe_len, GL_UNSIGNED_INT, 0, amount - split); + storage->info.render_vertices_count += s->index_array_len * (amount - split); + } else +#endif + if (s->index_array_len > 0) { glDrawElementsInstanced(gl_primitive[s->primitive], s->index_array_len, (s->array_len >= (1 << 16)) ? GL_UNSIGNED_INT : GL_UNSIGNED_SHORT, 0, amount - split); @@ -1631,8 +1679,15 @@ void RasterizerSceneGLES3::_render_geometry(RenderList::Element *e) { glEnableVertexAttribArray(12); //custom glVertexAttribPointer(12, 4, GL_FLOAT, GL_FALSE, stride, ((uint8_t *)NULL) + sizeof(float) * 4 * 2); glVertexAttribDivisor(12, 1); +#ifdef DEBUG_ENABLED - if (s->index_array_len > 0) { + if (state.debug_draw == VS::VIEWPORT_DEBUG_DRAW_WIREFRAME && s->array_wireframe_id) { + + glDrawElementsInstanced(GL_LINES, s->index_wireframe_len, GL_UNSIGNED_INT, 0, split); + storage->info.render_vertices_count += s->index_array_len * split; + } else +#endif + if (s->index_array_len > 0) { glDrawElementsInstanced(gl_primitive[s->primitive], s->index_array_len, (s->array_len >= (1 << 16)) ? GL_UNSIGNED_INT : GL_UNSIGNED_SHORT, 0, split); @@ -1648,7 +1703,15 @@ void RasterizerSceneGLES3::_render_geometry(RenderList::Element *e) { } else { - if (s->index_array_len > 0) { +#ifdef DEBUG_ENABLED + + if (state.debug_draw == VS::VIEWPORT_DEBUG_DRAW_WIREFRAME && s->array_wireframe_id) { + + glDrawElementsInstanced(GL_LINES, s->index_wireframe_len, GL_UNSIGNED_INT, 0, amount); + storage->info.render_vertices_count += s->index_array_len * amount; + } else +#endif + if (s->index_array_len > 0) { glDrawElementsInstanced(gl_primitive[s->primitive], s->index_array_len, (s->array_len >= (1 << 16)) ? GL_UNSIGNED_INT : GL_UNSIGNED_SHORT, 0, amount); @@ -2034,6 +2097,10 @@ void RasterizerSceneGLES3::_add_geometry(RasterizerStorageGLES3::Geometry *p_geo RasterizerStorageGLES3::Material *m = NULL; RID m_src = p_instance->material_override.is_valid() ? p_instance->material_override : (p_material >= 0 ? p_instance->materials[p_material] : p_geometry->material); + if (state.debug_draw == VS::VIEWPORT_DEBUG_DRAW_OVERDRAW) { + m_src = default_overdraw_material; + } + /* #ifdef DEBUG_ENABLED if (current_debug==VS::SCENARIO_DEBUG_OVERDRAW) { @@ -2152,7 +2219,7 @@ void RasterizerSceneGLES3::_add_geometry(RasterizerStorageGLES3::Geometry *p_geo //e->light_type=0xFF; // no lights! - if (shadow || m->shader->spatial.unshaded /*|| current_debug==VS::SCENARIO_DEBUG_SHADELESS*/) { + if (shadow || m->shader->spatial.unshaded || state.debug_draw == VS::VIEWPORT_DEBUG_DRAW_UNSHADED) { e->sort_key |= RenderList::SORT_KEY_UNSHADED_FLAG; } @@ -3789,7 +3856,7 @@ void RasterizerSceneGLES3::render_scene(const Transform &p_cam_transform, const state.used_contact_shadows = true; - if (storage->frame.current_rt && true) { //detect with state.used_contact_shadows too + if (storage->frame.current_rt && state.debug_draw != VS::VIEWPORT_DEBUG_DRAW_OVERDRAW) { //detect with state.used_contact_shadows too //pre z pass glDisable(GL_BLEND); @@ -3880,6 +3947,7 @@ void RasterizerSceneGLES3::render_scene(const Transform &p_cam_transform, const //effects disabled and transparency also prevent using MRTs use_mrt = use_mrt && !storage->frame.current_rt->flags[RasterizerStorage::RENDER_TARGET_TRANSPARENT]; use_mrt = use_mrt && !storage->frame.current_rt->flags[RasterizerStorage::RENDER_TARGET_NO_3D_EFFECTS]; + use_mrt = use_mrt && state.debug_draw != VS::VIEWPORT_DEBUG_DRAW_OVERDRAW; glViewport(0, 0, storage->frame.current_rt->width, storage->frame.current_rt->height); @@ -3928,7 +3996,10 @@ void RasterizerSceneGLES3::render_scene(const Transform &p_cam_transform, const RasterizerStorageGLES3::Sky *sky = NULL; GLuint env_radiance_tex = 0; - if (storage->frame.current_rt->flags[RasterizerStorage::RENDER_TARGET_TRANSPARENT]) { + if (state.debug_draw == VS::VIEWPORT_DEBUG_DRAW_OVERDRAW) { + clear_color = Color(0, 0, 0, 0); + storage->frame.clear_request = false; + } else if (storage->frame.current_rt->flags[RasterizerStorage::RENDER_TARGET_TRANSPARENT]) { clear_color = Color(0, 0, 0, 0); } else if (!env || env->bg_mode == VS::ENV_BG_CLEAR_COLOR) { @@ -3992,7 +4063,7 @@ void RasterizerSceneGLES3::render_scene(const Transform &p_cam_transform, const glDrawBuffers(1, &gldb); } - if (env && env->bg_mode == VS::ENV_BG_SKY && !storage->frame.current_rt->flags[RasterizerStorage::RENDER_TARGET_TRANSPARENT]) { + if (env && env->bg_mode == VS::ENV_BG_SKY && !storage->frame.current_rt->flags[RasterizerStorage::RENDER_TARGET_TRANSPARENT] && state.debug_draw != VS::VIEWPORT_DEBUG_DRAW_OVERDRAW) { /* if (use_mrt) { @@ -4554,136 +4625,39 @@ bool RasterizerSceneGLES3::free(RID p_rid) { return true; } -// http://holger.dammertz.org/stuff/notes_HammersleyOnHemisphere.html -static _FORCE_INLINE_ float radicalInverse_VdC(uint32_t bits) { - bits = (bits << 16u) | (bits >> 16u); - bits = ((bits & 0x55555555u) << 1u) | ((bits & 0xAAAAAAAAu) >> 1u); - bits = ((bits & 0x33333333u) << 2u) | ((bits & 0xCCCCCCCCu) >> 2u); - bits = ((bits & 0x0F0F0F0Fu) << 4u) | ((bits & 0xF0F0F0F0u) >> 4u); - bits = ((bits & 0x00FF00FFu) << 8u) | ((bits & 0xFF00FF00u) >> 8u); - return float(bits) * 2.3283064365386963e-10f; // / 0x100000000 -} - -static _FORCE_INLINE_ Vector2 Hammersley(uint32_t i, uint32_t N) { - return Vector2(float(i) / float(N), radicalInverse_VdC(i)); -} - -static _FORCE_INLINE_ Vector3 ImportanceSampleGGX(Vector2 Xi, float Roughness, Vector3 N) { - float a = Roughness * Roughness; // DISNEY'S ROUGHNESS [see Burley'12 siggraph] - - // Compute distribution direction - float Phi = 2.0f * Math_PI * Xi.x; - float CosTheta = Math::sqrt((float)(1.0f - Xi.y) / (1.0f + (a * a - 1.0f) * Xi.y)); - float SinTheta = Math::sqrt((float)Math::abs(1.0f - CosTheta * CosTheta)); - - // Convert to spherical direction - Vector3 H; - H.x = SinTheta * Math::cos(Phi); - H.y = SinTheta * Math::sin(Phi); - H.z = CosTheta; - - Vector3 UpVector = Math::abs(N.z) < 0.999 ? Vector3(0.0, 0.0, 1.0) : Vector3(1.0, 0.0, 0.0); - Vector3 TangentX = UpVector.cross(N); - TangentX.normalize(); - Vector3 TangentY = N.cross(TangentX); - - // Tangent to world space - return TangentX * H.x + TangentY * H.y + N * H.z; -} +void RasterizerSceneGLES3::set_debug_draw_mode(VS::ViewportDebugDraw p_debug_draw) { -static _FORCE_INLINE_ float GGX(float NdotV, float a) { - float k = a / 2.0; - return NdotV / (NdotV * (1.0 - k) + k); + state.debug_draw = p_debug_draw; } -// http://graphicrants.blogspot.com.au/2013/08/specular-brdf-reference.html -float _FORCE_INLINE_ G_Smith(float a, float nDotV, float nDotL) { - return GGX(nDotL, a * a) * GGX(nDotV, a * a); -} - -void RasterizerSceneGLES3::_generate_brdf() { - - int brdf_size = GLOBAL_DEF("rendering/gles3/brdf_texture_size", 64); - - PoolVector<uint8_t> brdf; - brdf.resize(brdf_size * brdf_size * 2); - - PoolVector<uint8_t>::Write w = brdf.write(); - - for (int i = 0; i < brdf_size; i++) { - for (int j = 0; j < brdf_size; j++) { - - float Roughness = float(j) / (brdf_size - 1); - float NoV = float(i + 1) / (brdf_size); //avoid storing nov0 - - Vector3 V; - V.x = Math::sqrt(1.0f - NoV * NoV); - V.y = 0.0; - V.z = NoV; - - Vector3 N = Vector3(0.0, 0.0, 1.0); - - float A = 0; - float B = 0; - - for (int s = 0; s < 512; s++) { - - Vector2 xi = Hammersley(s, 512); - Vector3 H = ImportanceSampleGGX(xi, Roughness, N); - Vector3 L = 2.0 * V.dot(H) * H - V; +void RasterizerSceneGLES3::initialize() { - float NoL = CLAMP(L.z, 0.0, 1.0); - float NoH = CLAMP(H.z, 0.0, 1.0); - float VoH = CLAMP(V.dot(H), 0.0, 1.0); + render_pass = 0; - if (NoL > 0.0) { - float G = G_Smith(Roughness, NoV, NoL); - float G_Vis = G * VoH / (NoH * NoV); - float Fc = pow(1.0 - VoH, 5.0); + state.scene_shader.init(); - A += (1.0 - Fc) * G_Vis; - B += Fc * G_Vis; - } - } + { + //default material and shader - A /= 512.0; - B /= 512.0; + default_shader = storage->shader_create(); + storage->shader_set_code(default_shader, "shader_type spatial;\n"); + default_material = storage->material_create(); + storage->material_set_shader(default_material, default_shader); - int tofs = ((brdf_size - j - 1) * brdf_size + i) * 2; - w[tofs + 0] = CLAMP(A * 255, 0, 255); - w[tofs + 1] = CLAMP(B * 255, 0, 255); - } + default_shader_twosided = storage->shader_create(); + default_material_twosided = storage->material_create(); + storage->shader_set_code(default_shader_twosided, "shader_type spatial; render_mode cull_disabled;\n"); + storage->material_set_shader(default_material_twosided, default_shader_twosided); } - //set up brdf texture - - glGenTextures(1, &state.brdf_texture); - - glActiveTexture(GL_TEXTURE0); - glBindTexture(GL_TEXTURE_2D, state.brdf_texture); - glTexImage2D(GL_TEXTURE_2D, 0, GL_RG8, brdf_size, brdf_size, 0, GL_RG, GL_UNSIGNED_BYTE, w.ptr()); - glTexParameterf(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR); - glTexParameterf(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR); - glTexParameterf(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_CLAMP_TO_EDGE); - glTexParameterf(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_CLAMP_TO_EDGE); - glBindTexture(GL_TEXTURE_2D, 0); -} - -void RasterizerSceneGLES3::initialize() { - - render_pass = 0; - - state.scene_shader.init(); - - default_shader = storage->shader_create(); - storage->shader_set_code(default_shader, "shader_type spatial;\n"); - default_material = storage->material_create(); - storage->material_set_shader(default_material, default_shader); + { + //default material and shader - default_shader_twosided = storage->shader_create(); - default_material_twosided = storage->material_create(); - storage->shader_set_code(default_shader_twosided, "shader_type spatial; render_mode cull_disabled;\n"); - storage->material_set_shader(default_material_twosided, default_shader_twosided); + default_overdraw_shader = storage->shader_create(); + storage->shader_set_code(default_overdraw_shader, "shader_type spatial;\nrender_mode blend_add,unshaded;\n void fragment() { ALBEDO=vec3(0.4,0.8,0.8); ALPHA=0.2; }"); + default_overdraw_material = storage->material_create(); + storage->material_set_shader(default_overdraw_material, default_overdraw_shader); + } glGenBuffers(1, &state.scene_ubo); glBindBuffer(GL_UNIFORM_BUFFER, state.scene_ubo); @@ -4721,7 +4695,6 @@ void RasterizerSceneGLES3::initialize() { } render_list.init(); state.cube_to_dp_shader.init(); - _generate_brdf(); shadow_atlas_realloc_tolerance_msec = 500; @@ -4968,6 +4941,8 @@ void RasterizerSceneGLES3::initialize() { GLenum status = glCheckFramebufferStatus(GL_FRAMEBUFFER); ERR_CONTINUE(status != GL_FRAMEBUFFER_COMPLETE); } + + state.debug_draw = VS::VIEWPORT_DEBUG_DRAW_DISABLED; } void RasterizerSceneGLES3::iteration() { diff --git a/drivers/gles3/rasterizer_scene_gles3.h b/drivers/gles3/rasterizer_scene_gles3.h index 55d314a800..59b8e3fb35 100644 --- a/drivers/gles3/rasterizer_scene_gles3.h +++ b/drivers/gles3/rasterizer_scene_gles3.h @@ -77,6 +77,9 @@ public: RID default_shader; RID default_shader_twosided; + RID default_overdraw_material; + RID default_overdraw_shader; + RasterizerStorageGLES3 *storage; Vector<RasterizerStorageGLES3::RenderTarget::Exposure> exposure_shrink; @@ -152,8 +155,6 @@ public: GLuint env_radiance_ubo; - GLuint brdf_texture; - GLuint sky_verts; GLuint sky_array; @@ -187,6 +188,7 @@ public: bool used_sss; bool used_screen_texture; + VS::ViewportDebugDraw debug_draw; } state; /* SHADOW ATLAS API */ @@ -783,9 +785,8 @@ public: virtual void render_shadow(RID p_light, RID p_shadow_atlas, int p_pass, InstanceBase **p_cull_result, int p_cull_count); virtual bool free(RID p_rid); - void _generate_brdf(); - virtual void set_scene_pass(uint64_t p_pass); + virtual void set_debug_draw_mode(VS::ViewportDebugDraw p_debug_draw); void iteration(); void initialize(); diff --git a/drivers/gles3/rasterizer_storage_gles3.cpp b/drivers/gles3/rasterizer_storage_gles3.cpp index 1801260146..1250e55748 100644 --- a/drivers/gles3/rasterizer_storage_gles3.cpp +++ b/drivers/gles3/rasterizer_storage_gles3.cpp @@ -2727,6 +2727,112 @@ void RasterizerStorageGLES3::mesh_add_surface(RID p_mesh, uint32_t p_format, VS: glBindBuffer(GL_ARRAY_BUFFER, 0); //unbind glBindBuffer(GL_ELEMENT_ARRAY_BUFFER, 0); } + +#ifdef DEBUG_ENABLED + + if (config.generate_wireframes && p_primitive == VS::PRIMITIVE_TRIANGLES) { + //generate wireframes, this is used mostly by editor + PoolVector<uint32_t> wf_indices; + int index_count; + + if (p_format & VS::ARRAY_FORMAT_INDEX) { + + index_count = p_index_count * 2; + wf_indices.resize(index_count); + + PoolVector<uint8_t>::Read ir = p_index_array.read(); + PoolVector<uint32_t>::Write wr = wf_indices.write(); + + if (p_vertex_count < (1 << 16)) { + //read 16 bit indices + const uint16_t *src_idx = (const uint16_t *)ir.ptr(); + for (int i = 0; i < index_count; i += 6) { + + wr[i + 0] = src_idx[i / 2]; + wr[i + 1] = src_idx[i / 2 + 1]; + wr[i + 2] = src_idx[i / 2 + 1]; + wr[i + 3] = src_idx[i / 2 + 2]; + wr[i + 4] = src_idx[i / 2 + 2]; + wr[i + 5] = src_idx[i / 2]; + } + + } else { + + //read 16 bit indices + const uint32_t *src_idx = (const uint32_t *)ir.ptr(); + for (int i = 0; i < index_count; i += 6) { + + wr[i + 0] = src_idx[i / 2]; + wr[i + 1] = src_idx[i / 2 + 1]; + wr[i + 2] = src_idx[i / 2 + 1]; + wr[i + 3] = src_idx[i / 2 + 2]; + wr[i + 4] = src_idx[i / 2 + 2]; + wr[i + 5] = src_idx[i / 2]; + } + } + + } else { + + index_count = p_vertex_count * 2; + wf_indices.resize(index_count); + PoolVector<uint32_t>::Write wr = wf_indices.write(); + for (int i = 0; i < index_count; i += 6) { + + wr[i + 0] = i / 2; + wr[i + 1] = i / 2 + 1; + wr[i + 2] = i / 2 + 1; + wr[i + 3] = i / 2 + 2; + wr[i + 4] = i / 2 + 2; + wr[i + 5] = i / 2; + } + } + { + PoolVector<uint32_t>::Read ir = wf_indices.read(); + + glGenBuffers(1, &surface->index_wireframe_id); + glBindBuffer(GL_ELEMENT_ARRAY_BUFFER, surface->index_wireframe_id); + glBufferData(GL_ELEMENT_ARRAY_BUFFER, index_count * sizeof(uint32_t), ir.ptr(), GL_STATIC_DRAW); + glBindBuffer(GL_ELEMENT_ARRAY_BUFFER, 0); //unbind + + surface->index_wireframe_len = index_count; + } + + for (int ai = 0; ai < 2; ai++) { + + if (ai == 0) { + //for normal draw + glGenVertexArrays(1, &surface->array_wireframe_id); + glBindVertexArray(surface->array_wireframe_id); + glBindBuffer(GL_ARRAY_BUFFER, surface->vertex_id); + } else if (ai == 1) { + //for instancing draw (can be changed and no one cares) + glGenVertexArrays(1, &surface->instancing_array_wireframe_id); + glBindVertexArray(surface->instancing_array_wireframe_id); + glBindBuffer(GL_ARRAY_BUFFER, surface->vertex_id); + } + + for (int i = 0; i < VS::ARRAY_MAX - 1; i++) { + + if (!attribs[i].enabled) + continue; + + if (attribs[i].integer) { + glVertexAttribIPointer(attribs[i].index, attribs[i].size, attribs[i].type, attribs[i].stride, ((uint8_t *)0) + attribs[i].offset); + } else { + glVertexAttribPointer(attribs[i].index, attribs[i].size, attribs[i].type, attribs[i].normalized, attribs[i].stride, ((uint8_t *)0) + attribs[i].offset); + } + glEnableVertexAttribArray(attribs[i].index); + } + + glBindBuffer(GL_ELEMENT_ARRAY_BUFFER, surface->index_wireframe_id); + + glBindVertexArray(0); + glBindBuffer(GL_ARRAY_BUFFER, 0); //unbind + glBindBuffer(GL_ELEMENT_ARRAY_BUFFER, 0); + } + } + +#endif } { @@ -2998,6 +3104,12 @@ void RasterizerStorageGLES3::mesh_remove_surface(RID p_mesh, int p_surface) { glDeleteVertexArrays(1, &surface->blend_shapes[i].array_id); } + if (surface->index_wireframe_id) { + glDeleteBuffers(1, &surface->index_wireframe_id); + glDeleteVertexArrays(1, &surface->array_wireframe_id); + glDeleteVertexArrays(1, &surface->instancing_array_wireframe_id); + } + mesh->instance_material_change_notify(); memdelete(surface); @@ -6345,6 +6457,11 @@ bool RasterizerStorageGLES3::has_os_feature(const String &p_feature) const { //////////////////////////////////////////// +void RasterizerStorageGLES3::set_debug_generate_wireframes(bool p_generate) { + + config.generate_wireframes = p_generate; +} + void RasterizerStorageGLES3::initialize() { RasterizerStorageGLES3::system_fbo = 0; @@ -6526,6 +6643,7 @@ void RasterizerStorageGLES3::initialize() { frame.delta = 0; frame.current_rt = NULL; config.keep_original_textures = false; + config.generate_wireframes = false; } void RasterizerStorageGLES3::finalize() { diff --git a/drivers/gles3/rasterizer_storage_gles3.h b/drivers/gles3/rasterizer_storage_gles3.h index 9af342301c..d16fa99c2a 100644 --- a/drivers/gles3/rasterizer_storage_gles3.h +++ b/drivers/gles3/rasterizer_storage_gles3.h @@ -84,6 +84,8 @@ public: int max_texture_image_units; int max_texture_size; + bool generate_wireframes; + Set<String> extensions; bool keep_original_textures; @@ -537,6 +539,11 @@ public: GLuint vertex_id; GLuint index_id; + GLuint index_wireframe_id; + GLuint array_wireframe_id; + GLuint instancing_array_wireframe_id; + int index_wireframe_len; + Vector<Rect3> skeleton_bone_aabb; Vector<bool> skeleton_bone_used; @@ -581,6 +588,11 @@ public: primitive = VS::PRIMITIVE_POINTS; index_array_len = 0; active = false; + + index_wireframe_id = 0; + array_wireframe_id = 0; + instancing_array_wireframe_id = 0; + index_wireframe_len = 0; } ~Surface() { @@ -1283,6 +1295,8 @@ public: virtual void update_dirty_resources(); + virtual void set_debug_generate_wireframes(bool p_generate); + RasterizerStorageGLES3(); }; |