|
@@ -29,2376 +29,2271 @@
|
|
/*************************************************************************/
|
|
/*************************************************************************/
|
|
|
|
|
|
#include "rasterizer_canvas_gles3.h"
|
|
#include "rasterizer_canvas_gles3.h"
|
|
-
|
|
|
|
-#include "core/os/os.h"
|
|
|
|
-#include "core/project_settings.h"
|
|
|
|
-#include "rasterizer_scene_gles3.h"
|
|
|
|
#include "servers/visual/visual_server_raster.h"
|
|
#include "servers/visual/visual_server_raster.h"
|
|
|
|
|
|
-#ifndef GLES_OVER_GL
|
|
|
|
-#define glClearDepth glClearDepthf
|
|
|
|
-#endif
|
|
|
|
|
|
+static const GLenum gl_primitive[] = {
|
|
|
|
+ GL_POINTS,
|
|
|
|
+ GL_LINES,
|
|
|
|
+ GL_LINE_STRIP,
|
|
|
|
+ GL_LINE_LOOP,
|
|
|
|
+ GL_TRIANGLES,
|
|
|
|
+ GL_TRIANGLE_STRIP,
|
|
|
|
+ GL_TRIANGLE_FAN
|
|
|
|
+};
|
|
|
|
|
|
-static _FORCE_INLINE_ void store_transform2d(const Transform2D &p_mtx, float *p_array) {
|
|
|
|
-
|
|
|
|
- p_array[0] = p_mtx.elements[0][0];
|
|
|
|
- p_array[1] = p_mtx.elements[0][1];
|
|
|
|
- p_array[2] = 0;
|
|
|
|
- p_array[3] = 0;
|
|
|
|
- p_array[4] = p_mtx.elements[1][0];
|
|
|
|
- p_array[5] = p_mtx.elements[1][1];
|
|
|
|
- p_array[6] = 0;
|
|
|
|
- p_array[7] = 0;
|
|
|
|
- p_array[8] = 0;
|
|
|
|
- p_array[9] = 0;
|
|
|
|
- p_array[10] = 1;
|
|
|
|
- p_array[11] = 0;
|
|
|
|
- p_array[12] = p_mtx.elements[2][0];
|
|
|
|
- p_array[13] = p_mtx.elements[2][1];
|
|
|
|
- p_array[14] = 0;
|
|
|
|
- p_array[15] = 1;
|
|
|
|
|
|
+void RasterizerCanvasGLES3::canvas_end() {
|
|
|
|
+ batch_canvas_end();
|
|
|
|
+ RasterizerCanvasBaseGLES3::canvas_end();
|
|
}
|
|
}
|
|
|
|
|
|
-static _FORCE_INLINE_ void store_transform(const Transform &p_mtx, float *p_array) {
|
|
|
|
- p_array[0] = p_mtx.basis.elements[0][0];
|
|
|
|
- p_array[1] = p_mtx.basis.elements[1][0];
|
|
|
|
- p_array[2] = p_mtx.basis.elements[2][0];
|
|
|
|
- p_array[3] = 0;
|
|
|
|
- p_array[4] = p_mtx.basis.elements[0][1];
|
|
|
|
- p_array[5] = p_mtx.basis.elements[1][1];
|
|
|
|
- p_array[6] = p_mtx.basis.elements[2][1];
|
|
|
|
- p_array[7] = 0;
|
|
|
|
- p_array[8] = p_mtx.basis.elements[0][2];
|
|
|
|
- p_array[9] = p_mtx.basis.elements[1][2];
|
|
|
|
- p_array[10] = p_mtx.basis.elements[2][2];
|
|
|
|
- p_array[11] = 0;
|
|
|
|
- p_array[12] = p_mtx.origin.x;
|
|
|
|
- p_array[13] = p_mtx.origin.y;
|
|
|
|
- p_array[14] = p_mtx.origin.z;
|
|
|
|
- p_array[15] = 1;
|
|
|
|
|
|
+void RasterizerCanvasGLES3::canvas_begin() {
|
|
|
|
+ batch_canvas_begin();
|
|
|
|
+ RasterizerCanvasBaseGLES3::canvas_begin();
|
|
}
|
|
}
|
|
|
|
|
|
-static _FORCE_INLINE_ void store_camera(const CameraMatrix &p_mtx, float *p_array) {
|
|
|
|
-
|
|
|
|
- for (int i = 0; i < 4; i++) {
|
|
|
|
- for (int j = 0; j < 4; j++) {
|
|
|
|
-
|
|
|
|
- p_array[i * 4 + j] = p_mtx.matrix[i][j];
|
|
|
|
- }
|
|
|
|
- }
|
|
|
|
|
|
+void RasterizerCanvasGLES3::canvas_render_items_begin(const Color &p_modulate, Light *p_light, const Transform2D &p_base_transform) {
|
|
|
|
+ batch_canvas_render_items_begin(p_modulate, p_light, p_base_transform);
|
|
}
|
|
}
|
|
|
|
|
|
-RID RasterizerCanvasGLES3::light_internal_create() {
|
|
|
|
-
|
|
|
|
- LightInternal *li = memnew(LightInternal);
|
|
|
|
-
|
|
|
|
- glGenBuffers(1, &li->ubo);
|
|
|
|
- glBindBuffer(GL_UNIFORM_BUFFER, li->ubo);
|
|
|
|
- glBufferData(GL_UNIFORM_BUFFER, sizeof(LightInternal::UBOData), &state.canvas_item_ubo_data, GL_DYNAMIC_DRAW);
|
|
|
|
- glBindBuffer(GL_UNIFORM_BUFFER, 0);
|
|
|
|
-
|
|
|
|
- return light_internal_owner.make_rid(li);
|
|
|
|
|
|
+void RasterizerCanvasGLES3::canvas_render_items_end() {
|
|
|
|
+ batch_canvas_render_items_end();
|
|
}
|
|
}
|
|
|
|
|
|
-void RasterizerCanvasGLES3::light_internal_update(RID p_rid, Light *p_light) {
|
|
|
|
-
|
|
|
|
- LightInternal *li = light_internal_owner.getornull(p_rid);
|
|
|
|
- ERR_FAIL_COND(!li);
|
|
|
|
-
|
|
|
|
- store_transform2d(p_light->light_shader_xform, li->ubo_data.light_matrix);
|
|
|
|
- store_transform2d(p_light->xform_cache.affine_inverse(), li->ubo_data.local_matrix);
|
|
|
|
- store_camera(p_light->shadow_matrix_cache, li->ubo_data.shadow_matrix);
|
|
|
|
-
|
|
|
|
- for (int i = 0; i < 4; i++) {
|
|
|
|
-
|
|
|
|
- li->ubo_data.color[i] = p_light->color[i] * p_light->energy;
|
|
|
|
- li->ubo_data.shadow_color[i] = p_light->shadow_color[i];
|
|
|
|
- }
|
|
|
|
-
|
|
|
|
- li->ubo_data.light_pos[0] = p_light->light_shader_pos.x;
|
|
|
|
- li->ubo_data.light_pos[1] = p_light->light_shader_pos.y;
|
|
|
|
- li->ubo_data.shadowpixel_size = (1.0 / p_light->shadow_buffer_size) * (1.0 + p_light->shadow_smooth);
|
|
|
|
- li->ubo_data.light_outside_alpha = p_light->mode == VS::CANVAS_LIGHT_MODE_MASK ? 1.0 : 0.0;
|
|
|
|
- li->ubo_data.light_height = p_light->height;
|
|
|
|
- if (p_light->radius_cache == 0)
|
|
|
|
- li->ubo_data.shadow_gradient = 0;
|
|
|
|
- else
|
|
|
|
- li->ubo_data.shadow_gradient = p_light->shadow_gradient_length / (p_light->radius_cache * 1.1);
|
|
|
|
-
|
|
|
|
- li->ubo_data.shadow_distance_mult = (p_light->radius_cache * 1.1);
|
|
|
|
-
|
|
|
|
- glBindBuffer(GL_UNIFORM_BUFFER, li->ubo);
|
|
|
|
- glBufferData(GL_UNIFORM_BUFFER, sizeof(LightInternal::UBOData), &li->ubo_data, GL_DYNAMIC_DRAW);
|
|
|
|
- glBindBuffer(GL_UNIFORM_BUFFER, 0);
|
|
|
|
|
|
+void RasterizerCanvasGLES3::canvas_render_items(Item *p_item_list, int p_z, const Color &p_modulate, Light *p_light, const Transform2D &p_base_transform) {
|
|
|
|
+ batch_canvas_render_items(p_item_list, p_z, p_modulate, p_light, p_base_transform);
|
|
}
|
|
}
|
|
|
|
|
|
-void RasterizerCanvasGLES3::light_internal_free(RID p_rid) {
|
|
|
|
-
|
|
|
|
- LightInternal *li = light_internal_owner.getornull(p_rid);
|
|
|
|
- ERR_FAIL_COND(!li);
|
|
|
|
-
|
|
|
|
- glDeleteBuffers(1, &li->ubo);
|
|
|
|
- light_internal_owner.free(p_rid);
|
|
|
|
- memdelete(li);
|
|
|
|
|
|
+void RasterizerCanvasGLES3::gl_checkerror() {
|
|
|
|
+ GLenum e = glGetError();
|
|
|
|
+ CRASH_COND(e != GL_NO_ERROR);
|
|
}
|
|
}
|
|
|
|
|
|
-void RasterizerCanvasGLES3::canvas_begin() {
|
|
|
|
-
|
|
|
|
- if (storage->frame.current_rt && storage->frame.clear_request) {
|
|
|
|
- // a clear request may be pending, so do it
|
|
|
|
- bool transparent = storage->frame.current_rt->flags[RasterizerStorage::RENDER_TARGET_TRANSPARENT];
|
|
|
|
-
|
|
|
|
- glClearColor(storage->frame.clear_request_color.r,
|
|
|
|
- storage->frame.clear_request_color.g,
|
|
|
|
- storage->frame.clear_request_color.b,
|
|
|
|
- transparent ? storage->frame.clear_request_color.a : 1.0);
|
|
|
|
- glClear(GL_COLOR_BUFFER_BIT);
|
|
|
|
- storage->frame.clear_request = false;
|
|
|
|
- glColorMask(1, 1, 1, transparent ? 1 : 0);
|
|
|
|
- }
|
|
|
|
-
|
|
|
|
- reset_canvas();
|
|
|
|
-
|
|
|
|
- state.canvas_shader.set_conditional(CanvasShaderGLES3::USE_TEXTURE_RECT, true);
|
|
|
|
- state.canvas_shader.set_conditional(CanvasShaderGLES3::USE_LIGHTING, false);
|
|
|
|
- state.canvas_shader.set_conditional(CanvasShaderGLES3::USE_SHADOWS, false);
|
|
|
|
- state.canvas_shader.set_conditional(CanvasShaderGLES3::SHADOW_FILTER_NEAREST, false);
|
|
|
|
- state.canvas_shader.set_conditional(CanvasShaderGLES3::SHADOW_FILTER_PCF3, false);
|
|
|
|
- state.canvas_shader.set_conditional(CanvasShaderGLES3::SHADOW_FILTER_PCF5, false);
|
|
|
|
- state.canvas_shader.set_conditional(CanvasShaderGLES3::SHADOW_FILTER_PCF7, false);
|
|
|
|
- state.canvas_shader.set_conditional(CanvasShaderGLES3::SHADOW_FILTER_PCF9, false);
|
|
|
|
- state.canvas_shader.set_conditional(CanvasShaderGLES3::SHADOW_FILTER_PCF13, false);
|
|
|
|
- state.canvas_shader.set_conditional(CanvasShaderGLES3::USE_DISTANCE_FIELD, false);
|
|
|
|
- state.canvas_shader.set_conditional(CanvasShaderGLES3::USE_NINEPATCH, false);
|
|
|
|
- state.canvas_shader.set_conditional(CanvasShaderGLES3::USE_LIGHT_ANGLE, false);
|
|
|
|
- state.canvas_shader.set_conditional(CanvasShaderGLES3::USE_SKELETON, false);
|
|
|
|
-
|
|
|
|
- state.canvas_shader.set_custom_shader(0);
|
|
|
|
- state.canvas_shader.bind();
|
|
|
|
- state.canvas_shader.set_uniform(CanvasShaderGLES3::FINAL_MODULATE, Color(1, 1, 1, 1));
|
|
|
|
- state.canvas_shader.set_uniform(CanvasShaderGLES3::MODELVIEW_MATRIX, Transform2D());
|
|
|
|
- state.canvas_shader.set_uniform(CanvasShaderGLES3::EXTRA_MATRIX, Transform2D());
|
|
|
|
- if (storage->frame.current_rt) {
|
|
|
|
- state.canvas_shader.set_uniform(CanvasShaderGLES3::SCREEN_PIXEL_SIZE, Vector2(1.0 / storage->frame.current_rt->width, 1.0 / storage->frame.current_rt->height));
|
|
|
|
- } else {
|
|
|
|
- state.canvas_shader.set_uniform(CanvasShaderGLES3::SCREEN_PIXEL_SIZE, Vector2(1.0, 1.0));
|
|
|
|
- }
|
|
|
|
-
|
|
|
|
- //state.canvas_shader.set_uniform(CanvasShaderGLES3::PROJECTION_MATRIX,state.vp);
|
|
|
|
- //state.canvas_shader.set_uniform(CanvasShaderGLES3::MODELVIEW_MATRIX,Transform());
|
|
|
|
- //state.canvas_shader.set_uniform(CanvasShaderGLES3::EXTRA_MATRIX,Transform());
|
|
|
|
-
|
|
|
|
- glBindBufferBase(GL_UNIFORM_BUFFER, 0, state.canvas_item_ubo);
|
|
|
|
- glBindVertexArray(data.canvas_quad_array);
|
|
|
|
- state.using_texture_rect = true;
|
|
|
|
- state.using_ninepatch = false;
|
|
|
|
- state.using_light_angle = false;
|
|
|
|
- state.using_skeleton = false;
|
|
|
|
|
|
+void RasterizerCanvasGLES3::gl_enable_scissor(int p_x, int p_y, int p_width, int p_height) const {
|
|
|
|
+ glEnable(GL_SCISSOR_TEST);
|
|
|
|
+ glScissor(p_x, p_y, p_width, p_height);
|
|
}
|
|
}
|
|
|
|
|
|
-void RasterizerCanvasGLES3::canvas_end() {
|
|
|
|
-
|
|
|
|
- glBindVertexArray(0);
|
|
|
|
- glBindBufferBase(GL_UNIFORM_BUFFER, 0, 0);
|
|
|
|
- glColorMask(1, 1, 1, 1);
|
|
|
|
-
|
|
|
|
- glVertexAttrib4f(VS::ARRAY_COLOR, 1, 1, 1, 1);
|
|
|
|
-
|
|
|
|
- state.using_texture_rect = false;
|
|
|
|
- state.using_ninepatch = false;
|
|
|
|
- state.using_light_angle = false;
|
|
|
|
|
|
+void RasterizerCanvasGLES3::gl_disable_scissor() const {
|
|
|
|
+ glDisable(GL_SCISSOR_TEST);
|
|
}
|
|
}
|
|
|
|
|
|
-RasterizerStorageGLES3::Texture *RasterizerCanvasGLES3::_bind_canvas_texture(const RID &p_texture, const RID &p_normal_map, bool p_force) {
|
|
|
|
|
|
+// Legacy non-batched implementation for regression testing.
|
|
|
|
+// Should be removed after testing phase to avoid duplicate codepaths.
|
|
|
|
+void RasterizerCanvasGLES3::_legacy_canvas_render_item(Item *p_ci, RenderItemState &r_ris) {
|
|
|
|
+ storage->info.render._2d_item_count++;
|
|
|
|
|
|
- RasterizerStorageGLES3::Texture *tex_return = NULL;
|
|
|
|
|
|
+ if (r_ris.prev_distance_field != p_ci->distance_field) {
|
|
|
|
|
|
- if (p_texture == state.current_tex && !p_force) {
|
|
|
|
- tex_return = state.current_tex_ptr;
|
|
|
|
- } else if (p_texture.is_valid()) {
|
|
|
|
|
|
+ state.canvas_shader.set_conditional(CanvasShaderGLES3::USE_DISTANCE_FIELD, p_ci->distance_field);
|
|
|
|
+ r_ris.prev_distance_field = p_ci->distance_field;
|
|
|
|
+ r_ris.rebind_shader = true;
|
|
|
|
+ }
|
|
|
|
|
|
- RasterizerStorageGLES3::Texture *texture = storage->texture_owner.getornull(p_texture);
|
|
|
|
|
|
+ if (r_ris.current_clip != p_ci->final_clip_owner) {
|
|
|
|
|
|
- if (!texture) {
|
|
|
|
- state.current_tex = RID();
|
|
|
|
- state.current_tex_ptr = NULL;
|
|
|
|
- glActiveTexture(GL_TEXTURE0);
|
|
|
|
- glBindTexture(GL_TEXTURE_2D, storage->resources.white_tex);
|
|
|
|
|
|
+ r_ris.current_clip = p_ci->final_clip_owner;
|
|
|
|
|
|
- } else {
|
|
|
|
|
|
+ //setup clip
|
|
|
|
+ if (r_ris.current_clip) {
|
|
|
|
|
|
- if (texture->redraw_if_visible) { //check before proxy, because this is usually used with proxies
|
|
|
|
- VisualServerRaster::redraw_request();
|
|
|
|
- }
|
|
|
|
-
|
|
|
|
- texture = texture->get_ptr();
|
|
|
|
|
|
+ glEnable(GL_SCISSOR_TEST);
|
|
|
|
+ int y = storage->frame.current_rt->height - (r_ris.current_clip->final_clip_rect.position.y + r_ris.current_clip->final_clip_rect.size.y);
|
|
|
|
+ if (storage->frame.current_rt->flags[RasterizerStorage::RENDER_TARGET_VFLIP])
|
|
|
|
+ y = r_ris.current_clip->final_clip_rect.position.y;
|
|
|
|
|
|
- if (texture->render_target)
|
|
|
|
- texture->render_target->used_in_frame = true;
|
|
|
|
|
|
+ glScissor(r_ris.current_clip->final_clip_rect.position.x, y, r_ris.current_clip->final_clip_rect.size.x, r_ris.current_clip->final_clip_rect.size.y);
|
|
|
|
|
|
- glActiveTexture(GL_TEXTURE0);
|
|
|
|
- glBindTexture(GL_TEXTURE_2D, texture->tex_id);
|
|
|
|
- state.current_tex = p_texture;
|
|
|
|
- state.current_tex_ptr = texture;
|
|
|
|
|
|
+ } else {
|
|
|
|
|
|
- tex_return = texture;
|
|
|
|
|
|
+ glDisable(GL_SCISSOR_TEST);
|
|
}
|
|
}
|
|
-
|
|
|
|
- } else {
|
|
|
|
-
|
|
|
|
- glActiveTexture(GL_TEXTURE0);
|
|
|
|
- glBindTexture(GL_TEXTURE_2D, storage->resources.white_tex);
|
|
|
|
- state.current_tex = RID();
|
|
|
|
- state.current_tex_ptr = NULL;
|
|
|
|
}
|
|
}
|
|
|
|
|
|
- if (p_normal_map == state.current_normal && !p_force) {
|
|
|
|
- //do none
|
|
|
|
- state.canvas_shader.set_uniform(CanvasShaderGLES3::USE_DEFAULT_NORMAL, state.current_normal.is_valid());
|
|
|
|
-
|
|
|
|
- } else if (p_normal_map.is_valid()) {
|
|
|
|
|
|
+ if (p_ci->copy_back_buffer) {
|
|
|
|
|
|
- RasterizerStorageGLES3::Texture *normal_map = storage->texture_owner.getornull(p_normal_map);
|
|
|
|
-
|
|
|
|
- if (!normal_map) {
|
|
|
|
- state.current_normal = RID();
|
|
|
|
- glActiveTexture(GL_TEXTURE1);
|
|
|
|
- glBindTexture(GL_TEXTURE_2D, storage->resources.normal_tex);
|
|
|
|
- state.canvas_shader.set_uniform(CanvasShaderGLES3::USE_DEFAULT_NORMAL, false);
|
|
|
|
|
|
+ if (p_ci->copy_back_buffer->full) {
|
|
|
|
|
|
|
|
+ _copy_texscreen(Rect2());
|
|
} else {
|
|
} else {
|
|
-
|
|
|
|
- if (normal_map->redraw_if_visible) { //check before proxy, because this is usually used with proxies
|
|
|
|
- VisualServerRaster::redraw_request();
|
|
|
|
- }
|
|
|
|
-
|
|
|
|
- normal_map = normal_map->get_ptr();
|
|
|
|
-
|
|
|
|
- glActiveTexture(GL_TEXTURE1);
|
|
|
|
- glBindTexture(GL_TEXTURE_2D, normal_map->tex_id);
|
|
|
|
- state.current_normal = p_normal_map;
|
|
|
|
- state.canvas_shader.set_uniform(CanvasShaderGLES3::USE_DEFAULT_NORMAL, true);
|
|
|
|
|
|
+ _copy_texscreen(p_ci->copy_back_buffer->rect);
|
|
}
|
|
}
|
|
-
|
|
|
|
- } else {
|
|
|
|
-
|
|
|
|
- state.current_normal = RID();
|
|
|
|
- glActiveTexture(GL_TEXTURE1);
|
|
|
|
- glBindTexture(GL_TEXTURE_2D, storage->resources.normal_tex);
|
|
|
|
- state.canvas_shader.set_uniform(CanvasShaderGLES3::USE_DEFAULT_NORMAL, false);
|
|
|
|
}
|
|
}
|
|
|
|
|
|
- return tex_return;
|
|
|
|
-}
|
|
|
|
-
|
|
|
|
-void RasterizerCanvasGLES3::_set_texture_rect_mode(bool p_enable, bool p_ninepatch, bool p_light_angle) {
|
|
|
|
|
|
+ RasterizerStorageGLES3::Skeleton *skeleton = NULL;
|
|
|
|
|
|
- if (state.using_texture_rect == p_enable && state.using_ninepatch == p_ninepatch && state.using_light_angle == p_light_angle)
|
|
|
|
- return;
|
|
|
|
|
|
+ {
|
|
|
|
+ //skeleton handling
|
|
|
|
+ if (p_ci->skeleton.is_valid() && storage->skeleton_owner.owns(p_ci->skeleton)) {
|
|
|
|
+ skeleton = storage->skeleton_owner.get(p_ci->skeleton);
|
|
|
|
+ if (!skeleton->use_2d) {
|
|
|
|
+ skeleton = NULL;
|
|
|
|
+ } else {
|
|
|
|
+ state.skeleton_transform = r_ris.item_group_base_transform * skeleton->base_transform_2d;
|
|
|
|
+ state.skeleton_transform_inverse = state.skeleton_transform.affine_inverse();
|
|
|
|
+ }
|
|
|
|
+ }
|
|
|
|
|
|
- if (p_enable) {
|
|
|
|
- glBindVertexArray(data.canvas_quad_array);
|
|
|
|
|
|
+ bool use_skeleton = skeleton != NULL;
|
|
|
|
+ if (r_ris.prev_use_skeleton != use_skeleton) {
|
|
|
|
+ r_ris.rebind_shader = true;
|
|
|
|
+ state.canvas_shader.set_conditional(CanvasShaderGLES3::USE_SKELETON, use_skeleton);
|
|
|
|
+ r_ris.prev_use_skeleton = use_skeleton;
|
|
|
|
+ }
|
|
|
|
|
|
- } else {
|
|
|
|
- glBindVertexArray(0);
|
|
|
|
- glBindBuffer(GL_ARRAY_BUFFER, 0);
|
|
|
|
- glBindBuffer(GL_ELEMENT_ARRAY_BUFFER, 0);
|
|
|
|
|
|
+ if (skeleton) {
|
|
|
|
+ glActiveTexture(GL_TEXTURE0 + storage->config.max_texture_image_units - 4);
|
|
|
|
+ glBindTexture(GL_TEXTURE_2D, skeleton->texture);
|
|
|
|
+ state.using_skeleton = true;
|
|
|
|
+ } else {
|
|
|
|
+ state.using_skeleton = false;
|
|
|
|
+ }
|
|
}
|
|
}
|
|
|
|
|
|
- state.canvas_shader.set_conditional(CanvasShaderGLES3::USE_NINEPATCH, p_ninepatch && p_enable);
|
|
|
|
- state.canvas_shader.set_conditional(CanvasShaderGLES3::USE_TEXTURE_RECT, p_enable);
|
|
|
|
- state.canvas_shader.set_conditional(CanvasShaderGLES3::USE_LIGHT_ANGLE, p_light_angle);
|
|
|
|
- state.canvas_shader.bind();
|
|
|
|
- state.canvas_shader.set_uniform(CanvasShaderGLES3::FINAL_MODULATE, state.canvas_item_modulate);
|
|
|
|
- state.canvas_shader.set_uniform(CanvasShaderGLES3::MODELVIEW_MATRIX, state.final_transform);
|
|
|
|
- state.canvas_shader.set_uniform(CanvasShaderGLES3::EXTRA_MATRIX, state.extra_matrix);
|
|
|
|
- if (state.using_skeleton) {
|
|
|
|
- state.canvas_shader.set_uniform(CanvasShaderGLES3::SKELETON_TRANSFORM, state.skeleton_transform);
|
|
|
|
- state.canvas_shader.set_uniform(CanvasShaderGLES3::SKELETON_TRANSFORM_INVERSE, state.skeleton_transform_inverse);
|
|
|
|
- }
|
|
|
|
- if (storage->frame.current_rt) {
|
|
|
|
- state.canvas_shader.set_uniform(CanvasShaderGLES3::SCREEN_PIXEL_SIZE, Vector2(1.0 / storage->frame.current_rt->width, 1.0 / storage->frame.current_rt->height));
|
|
|
|
- } else {
|
|
|
|
- state.canvas_shader.set_uniform(CanvasShaderGLES3::SCREEN_PIXEL_SIZE, Vector2(1.0, 1.0));
|
|
|
|
- }
|
|
|
|
- state.using_texture_rect = p_enable;
|
|
|
|
- state.using_ninepatch = p_ninepatch;
|
|
|
|
- state.using_light_angle = p_light_angle;
|
|
|
|
-}
|
|
|
|
|
|
+ //begin rect
|
|
|
|
+ Item *material_owner = p_ci->material_owner ? p_ci->material_owner : p_ci;
|
|
|
|
|
|
-void RasterizerCanvasGLES3::_draw_polygon(const int *p_indices, int p_index_count, int p_vertex_count, const Vector2 *p_vertices, const Vector2 *p_uvs, const Color *p_colors, bool p_singlecolor, const int *p_bones, const float *p_weights) {
|
|
|
|
|
|
+ RID material = material_owner->material;
|
|
|
|
|
|
- glBindVertexArray(data.polygon_buffer_pointer_array);
|
|
|
|
- glBindBuffer(GL_ARRAY_BUFFER, data.polygon_buffer);
|
|
|
|
|
|
+ if (material != r_ris.canvas_last_material || r_ris.rebind_shader) {
|
|
|
|
|
|
- uint32_t buffer_ofs = 0;
|
|
|
|
- storage->buffer_orphan_and_upload(data.polygon_buffer_size, buffer_ofs, sizeof(Vector2) * p_vertex_count, p_vertices);
|
|
|
|
|
|
+ RasterizerStorageGLES3::Material *material_ptr = storage->material_owner.getornull(material);
|
|
|
|
+ RasterizerStorageGLES3::Shader *shader_ptr = NULL;
|
|
|
|
|
|
- glEnableVertexAttribArray(VS::ARRAY_VERTEX);
|
|
|
|
- glVertexAttribPointer(VS::ARRAY_VERTEX, 2, GL_FLOAT, false, sizeof(Vector2), CAST_INT_TO_UCHAR_PTR(buffer_ofs));
|
|
|
|
- buffer_ofs += sizeof(Vector2) * p_vertex_count;
|
|
|
|
- //color
|
|
|
|
-#ifdef DEBUG_ENABLED
|
|
|
|
- ERR_FAIL_COND(buffer_ofs > data.polygon_buffer_size);
|
|
|
|
-#endif
|
|
|
|
|
|
+ if (material_ptr) {
|
|
|
|
|
|
- if (p_singlecolor) {
|
|
|
|
- glDisableVertexAttribArray(VS::ARRAY_COLOR);
|
|
|
|
- Color m = *p_colors;
|
|
|
|
- glVertexAttrib4f(VS::ARRAY_COLOR, m.r, m.g, m.b, m.a);
|
|
|
|
- } else if (!p_colors) {
|
|
|
|
- glDisableVertexAttribArray(VS::ARRAY_COLOR);
|
|
|
|
- glVertexAttrib4f(VS::ARRAY_COLOR, 1, 1, 1, 1);
|
|
|
|
- } else {
|
|
|
|
|
|
+ shader_ptr = material_ptr->shader;
|
|
|
|
|
|
- glBufferSubData(GL_ARRAY_BUFFER, buffer_ofs, sizeof(Color) * p_vertex_count, p_colors);
|
|
|
|
- glEnableVertexAttribArray(VS::ARRAY_COLOR);
|
|
|
|
- glVertexAttribPointer(VS::ARRAY_COLOR, 4, GL_FLOAT, false, sizeof(Color), CAST_INT_TO_UCHAR_PTR(buffer_ofs));
|
|
|
|
- buffer_ofs += sizeof(Color) * p_vertex_count;
|
|
|
|
- }
|
|
|
|
|
|
+ if (shader_ptr && shader_ptr->mode != VS::SHADER_CANVAS_ITEM) {
|
|
|
|
+ shader_ptr = NULL; //do not use non canvasitem shader
|
|
|
|
+ }
|
|
|
|
+ }
|
|
|
|
|
|
-#ifdef DEBUG_ENABLED
|
|
|
|
- ERR_FAIL_COND(buffer_ofs > data.polygon_buffer_size);
|
|
|
|
-#endif
|
|
|
|
|
|
+ if (shader_ptr) {
|
|
|
|
|
|
- if (p_uvs) {
|
|
|
|
|
|
+ if (shader_ptr->canvas_item.uses_screen_texture && !state.canvas_texscreen_used) {
|
|
|
|
+ //copy if not copied before
|
|
|
|
+ _copy_texscreen(Rect2());
|
|
|
|
|
|
- glBufferSubData(GL_ARRAY_BUFFER, buffer_ofs, sizeof(Vector2) * p_vertex_count, p_uvs);
|
|
|
|
- glEnableVertexAttribArray(VS::ARRAY_TEX_UV);
|
|
|
|
- glVertexAttribPointer(VS::ARRAY_TEX_UV, 2, GL_FLOAT, false, sizeof(Vector2), CAST_INT_TO_UCHAR_PTR(buffer_ofs));
|
|
|
|
- buffer_ofs += sizeof(Vector2) * p_vertex_count;
|
|
|
|
|
|
+ // blend mode will have been enabled so make sure we disable it again later on
|
|
|
|
+ r_ris.last_blend_mode = r_ris.last_blend_mode != RasterizerStorageGLES3::Shader::CanvasItem::BLEND_MODE_DISABLED ? r_ris.last_blend_mode : -1;
|
|
|
|
+ }
|
|
|
|
|
|
- } else {
|
|
|
|
- glDisableVertexAttribArray(VS::ARRAY_TEX_UV);
|
|
|
|
- }
|
|
|
|
|
|
+ if (shader_ptr != r_ris.shader_cache || r_ris.rebind_shader) {
|
|
|
|
|
|
-#ifdef DEBUG_ENABLED
|
|
|
|
- ERR_FAIL_COND(buffer_ofs > data.polygon_buffer_size);
|
|
|
|
-#endif
|
|
|
|
|
|
+ if (shader_ptr->canvas_item.uses_time) {
|
|
|
|
+ VisualServerRaster::redraw_request();
|
|
|
|
+ }
|
|
|
|
|
|
- if (p_bones && p_weights) {
|
|
|
|
|
|
+ state.canvas_shader.set_custom_shader(shader_ptr->custom_code_id);
|
|
|
|
+ state.canvas_shader.bind();
|
|
|
|
+ }
|
|
|
|
|
|
- glBufferSubData(GL_ARRAY_BUFFER, buffer_ofs, sizeof(int) * 4 * p_vertex_count, p_bones);
|
|
|
|
- glEnableVertexAttribArray(VS::ARRAY_BONES);
|
|
|
|
- //glVertexAttribPointer(VS::ARRAY_BONES, 4, GL_UNSIGNED_INT, false, sizeof(int) * 4, ((uint8_t *)0) + buffer_ofs);
|
|
|
|
- glVertexAttribIPointer(VS::ARRAY_BONES, 4, GL_UNSIGNED_INT, sizeof(int) * 4, CAST_INT_TO_UCHAR_PTR(buffer_ofs));
|
|
|
|
- buffer_ofs += sizeof(int) * 4 * p_vertex_count;
|
|
|
|
|
|
+ if (material_ptr->ubo_id) {
|
|
|
|
+ glBindBufferBase(GL_UNIFORM_BUFFER, 2, material_ptr->ubo_id);
|
|
|
|
+ }
|
|
|
|
|
|
- glBufferSubData(GL_ARRAY_BUFFER, buffer_ofs, sizeof(float) * 4 * p_vertex_count, p_weights);
|
|
|
|
- glEnableVertexAttribArray(VS::ARRAY_WEIGHTS);
|
|
|
|
- glVertexAttribPointer(VS::ARRAY_WEIGHTS, 4, GL_FLOAT, false, sizeof(float) * 4, CAST_INT_TO_UCHAR_PTR(buffer_ofs));
|
|
|
|
- buffer_ofs += sizeof(float) * 4 * p_vertex_count;
|
|
|
|
|
|
+ int tc = material_ptr->textures.size();
|
|
|
|
+ RID *textures = material_ptr->textures.ptrw();
|
|
|
|
+ ShaderLanguage::ShaderNode::Uniform::Hint *texture_hints = shader_ptr->texture_hints.ptrw();
|
|
|
|
|
|
- } else if (state.using_skeleton) {
|
|
|
|
- glVertexAttribI4ui(VS::ARRAY_BONES, 0, 0, 0, 0);
|
|
|
|
- glVertexAttrib4f(VS::ARRAY_WEIGHTS, 0, 0, 0, 0);
|
|
|
|
- }
|
|
|
|
|
|
+ for (int i = 0; i < tc; i++) {
|
|
|
|
|
|
-#ifdef DEBUG_ENABLED
|
|
|
|
- ERR_FAIL_COND(buffer_ofs > data.polygon_buffer_size);
|
|
|
|
-#endif
|
|
|
|
|
|
+ glActiveTexture(GL_TEXTURE2 + i);
|
|
|
|
|
|
- //bind the indices buffer.
|
|
|
|
- glBindBuffer(GL_ELEMENT_ARRAY_BUFFER, data.polygon_index_buffer);
|
|
|
|
- storage->buffer_orphan_and_upload(data.polygon_index_buffer_size, 0, sizeof(int) * p_index_count, p_indices, GL_ELEMENT_ARRAY_BUFFER);
|
|
|
|
|
|
+ RasterizerStorageGLES3::Texture *t = storage->texture_owner.getornull(textures[i]);
|
|
|
|
+ if (!t) {
|
|
|
|
|
|
- //draw the triangles.
|
|
|
|
- glDrawElements(GL_TRIANGLES, p_index_count, GL_UNSIGNED_INT, 0);
|
|
|
|
|
|
+ switch (texture_hints[i]) {
|
|
|
|
+ case ShaderLanguage::ShaderNode::Uniform::HINT_BLACK_ALBEDO:
|
|
|
|
+ case ShaderLanguage::ShaderNode::Uniform::HINT_BLACK: {
|
|
|
|
+ glBindTexture(GL_TEXTURE_2D, storage->resources.black_tex);
|
|
|
|
+ } break;
|
|
|
|
+ case ShaderLanguage::ShaderNode::Uniform::HINT_ANISO: {
|
|
|
|
+ glBindTexture(GL_TEXTURE_2D, storage->resources.aniso_tex);
|
|
|
|
+ } break;
|
|
|
|
+ case ShaderLanguage::ShaderNode::Uniform::HINT_NORMAL: {
|
|
|
|
+ glBindTexture(GL_TEXTURE_2D, storage->resources.normal_tex);
|
|
|
|
+ } break;
|
|
|
|
+ default: {
|
|
|
|
+ glBindTexture(GL_TEXTURE_2D, storage->resources.white_tex);
|
|
|
|
+ } break;
|
|
|
|
+ }
|
|
|
|
|
|
- storage->info.render._2d_draw_call_count++;
|
|
|
|
|
|
+ //check hints
|
|
|
|
|
|
- if (p_bones && p_weights) {
|
|
|
|
- //not used so often, so disable when used
|
|
|
|
- glDisableVertexAttribArray(VS::ARRAY_BONES);
|
|
|
|
- glDisableVertexAttribArray(VS::ARRAY_WEIGHTS);
|
|
|
|
- }
|
|
|
|
|
|
+ continue;
|
|
|
|
+ }
|
|
|
|
|
|
- glBindVertexArray(0);
|
|
|
|
- glBindBuffer(GL_ARRAY_BUFFER, 0);
|
|
|
|
-}
|
|
|
|
|
|
+ if (t->redraw_if_visible) { //check before proxy, because this is usually used with proxies
|
|
|
|
+ VisualServerRaster::redraw_request();
|
|
|
|
+ }
|
|
|
|
|
|
-void RasterizerCanvasGLES3::_draw_generic(GLuint p_primitive, int p_vertex_count, const Vector2 *p_vertices, const Vector2 *p_uvs, const Color *p_colors, bool p_singlecolor) {
|
|
|
|
|
|
+ t = t->get_ptr();
|
|
|
|
|
|
- glBindVertexArray(data.polygon_buffer_pointer_array);
|
|
|
|
- glBindBuffer(GL_ARRAY_BUFFER, data.polygon_buffer);
|
|
|
|
|
|
+ if (storage->config.srgb_decode_supported && t->using_srgb) {
|
|
|
|
+ //no srgb in 2D
|
|
|
|
+ glTexParameteri(t->target, _TEXTURE_SRGB_DECODE_EXT, _SKIP_DECODE_EXT);
|
|
|
|
+ t->using_srgb = false;
|
|
|
|
+ }
|
|
|
|
|
|
- uint32_t buffer_ofs = 0;
|
|
|
|
- storage->buffer_orphan_and_upload(data.polygon_buffer_size, buffer_ofs, sizeof(Vector2) * p_vertex_count, p_vertices);
|
|
|
|
|
|
+ glBindTexture(t->target, t->tex_id);
|
|
|
|
+ }
|
|
|
|
|
|
- glEnableVertexAttribArray(VS::ARRAY_VERTEX);
|
|
|
|
- glVertexAttribPointer(VS::ARRAY_VERTEX, 2, GL_FLOAT, false, sizeof(Vector2), CAST_INT_TO_UCHAR_PTR(buffer_ofs));
|
|
|
|
- buffer_ofs += sizeof(Vector2) * p_vertex_count;
|
|
|
|
- //color
|
|
|
|
|
|
+ } else {
|
|
|
|
+ state.canvas_shader.set_custom_shader(0);
|
|
|
|
+ state.canvas_shader.bind();
|
|
|
|
+ }
|
|
|
|
|
|
- if (p_singlecolor) {
|
|
|
|
- glDisableVertexAttribArray(VS::ARRAY_COLOR);
|
|
|
|
- Color m = *p_colors;
|
|
|
|
- glVertexAttrib4f(VS::ARRAY_COLOR, m.r, m.g, m.b, m.a);
|
|
|
|
- } else if (!p_colors) {
|
|
|
|
- glDisableVertexAttribArray(VS::ARRAY_COLOR);
|
|
|
|
- glVertexAttrib4f(VS::ARRAY_COLOR, 1, 1, 1, 1);
|
|
|
|
- } else {
|
|
|
|
|
|
+ r_ris.shader_cache = shader_ptr;
|
|
|
|
|
|
- glBufferSubData(GL_ARRAY_BUFFER, buffer_ofs, sizeof(Color) * p_vertex_count, p_colors);
|
|
|
|
- glEnableVertexAttribArray(VS::ARRAY_COLOR);
|
|
|
|
- glVertexAttribPointer(VS::ARRAY_COLOR, 4, GL_FLOAT, false, sizeof(Color), CAST_INT_TO_UCHAR_PTR(buffer_ofs));
|
|
|
|
- buffer_ofs += sizeof(Color) * p_vertex_count;
|
|
|
|
|
|
+ r_ris.canvas_last_material = material;
|
|
|
|
+ r_ris.rebind_shader = false;
|
|
}
|
|
}
|
|
|
|
|
|
- if (p_uvs) {
|
|
|
|
-
|
|
|
|
- glBufferSubData(GL_ARRAY_BUFFER, buffer_ofs, sizeof(Vector2) * p_vertex_count, p_uvs);
|
|
|
|
- glEnableVertexAttribArray(VS::ARRAY_TEX_UV);
|
|
|
|
- glVertexAttribPointer(VS::ARRAY_TEX_UV, 2, GL_FLOAT, false, sizeof(Vector2), CAST_INT_TO_UCHAR_PTR(buffer_ofs));
|
|
|
|
- buffer_ofs += sizeof(Vector2) * p_vertex_count;
|
|
|
|
-
|
|
|
|
- } else {
|
|
|
|
- glDisableVertexAttribArray(VS::ARRAY_TEX_UV);
|
|
|
|
|
|
+ int blend_mode = r_ris.shader_cache ? r_ris.shader_cache->canvas_item.blend_mode : RasterizerStorageGLES3::Shader::CanvasItem::BLEND_MODE_MIX;
|
|
|
|
+ if (blend_mode == RasterizerStorageGLES3::Shader::CanvasItem::BLEND_MODE_DISABLED && (!storage->frame.current_rt || !storage->frame.current_rt->flags[RasterizerStorage::RENDER_TARGET_TRANSPARENT])) {
|
|
|
|
+ blend_mode = RasterizerStorageGLES3::Shader::CanvasItem::BLEND_MODE_MIX;
|
|
}
|
|
}
|
|
|
|
+ bool unshaded = r_ris.shader_cache && (r_ris.shader_cache->canvas_item.light_mode == RasterizerStorageGLES3::Shader::CanvasItem::LIGHT_MODE_UNSHADED || (blend_mode != RasterizerStorageGLES3::Shader::CanvasItem::BLEND_MODE_MIX && blend_mode != RasterizerStorageGLES3::Shader::CanvasItem::BLEND_MODE_PMALPHA));
|
|
|
|
+ bool reclip = false;
|
|
|
|
+
|
|
|
|
+ if (r_ris.last_blend_mode != blend_mode) {
|
|
|
|
+ if (r_ris.last_blend_mode == RasterizerStorageGLES3::Shader::CanvasItem::BLEND_MODE_DISABLED) {
|
|
|
|
+ // re-enable it
|
|
|
|
+ glEnable(GL_BLEND);
|
|
|
|
+ } else if (blend_mode == RasterizerStorageGLES3::Shader::CanvasItem::BLEND_MODE_DISABLED) {
|
|
|
|
+ // disable it
|
|
|
|
+ glDisable(GL_BLEND);
|
|
|
|
+ }
|
|
|
|
|
|
- glDrawArrays(p_primitive, 0, p_vertex_count);
|
|
|
|
|
|
+ switch (blend_mode) {
|
|
|
|
|
|
- storage->info.render._2d_draw_call_count++;
|
|
|
|
-
|
|
|
|
- glBindVertexArray(0);
|
|
|
|
- glBindBuffer(GL_ARRAY_BUFFER, 0);
|
|
|
|
-}
|
|
|
|
|
|
+ case RasterizerStorageGLES3::Shader::CanvasItem::BLEND_MODE_DISABLED: {
|
|
|
|
|
|
-void RasterizerCanvasGLES3::_draw_generic_indices(GLuint p_primitive, const int *p_indices, int p_index_count, int p_vertex_count, const Vector2 *p_vertices, const Vector2 *p_uvs, const Color *p_colors, bool p_singlecolor) {
|
|
|
|
|
|
+ // nothing to do here
|
|
|
|
|
|
- glBindVertexArray(data.polygon_buffer_pointer_array);
|
|
|
|
- glBindBuffer(GL_ARRAY_BUFFER, data.polygon_buffer);
|
|
|
|
|
|
+ } break;
|
|
|
|
+ case RasterizerStorageGLES3::Shader::CanvasItem::BLEND_MODE_MIX: {
|
|
|
|
|
|
- uint32_t buffer_ofs = 0;
|
|
|
|
- storage->buffer_orphan_and_upload(data.polygon_buffer_size, buffer_ofs, sizeof(Vector2) * p_vertex_count, p_vertices);
|
|
|
|
|
|
+ glBlendEquation(GL_FUNC_ADD);
|
|
|
|
+ if (storage->frame.current_rt && storage->frame.current_rt->flags[RasterizerStorage::RENDER_TARGET_TRANSPARENT]) {
|
|
|
|
+ glBlendFuncSeparate(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA, GL_ONE, GL_ONE_MINUS_SRC_ALPHA);
|
|
|
|
+ } else {
|
|
|
|
+ glBlendFuncSeparate(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA, GL_ZERO, GL_ONE);
|
|
|
|
+ }
|
|
|
|
|
|
- glEnableVertexAttribArray(VS::ARRAY_VERTEX);
|
|
|
|
- glVertexAttribPointer(VS::ARRAY_VERTEX, 2, GL_FLOAT, false, sizeof(Vector2), CAST_INT_TO_UCHAR_PTR(buffer_ofs));
|
|
|
|
- buffer_ofs += sizeof(Vector2) * p_vertex_count;
|
|
|
|
- //color
|
|
|
|
-#ifdef DEBUG_ENABLED
|
|
|
|
- ERR_FAIL_COND(buffer_ofs > data.polygon_buffer_size);
|
|
|
|
-#endif
|
|
|
|
|
|
+ } break;
|
|
|
|
+ case RasterizerStorageGLES3::Shader::CanvasItem::BLEND_MODE_ADD: {
|
|
|
|
|
|
- if (p_singlecolor) {
|
|
|
|
- glDisableVertexAttribArray(VS::ARRAY_COLOR);
|
|
|
|
- Color m = *p_colors;
|
|
|
|
- glVertexAttrib4f(VS::ARRAY_COLOR, m.r, m.g, m.b, m.a);
|
|
|
|
- } else if (!p_colors) {
|
|
|
|
- glDisableVertexAttribArray(VS::ARRAY_COLOR);
|
|
|
|
- glVertexAttrib4f(VS::ARRAY_COLOR, 1, 1, 1, 1);
|
|
|
|
- } else {
|
|
|
|
|
|
+ glBlendEquation(GL_FUNC_ADD);
|
|
|
|
+ if (storage->frame.current_rt && storage->frame.current_rt->flags[RasterizerStorage::RENDER_TARGET_TRANSPARENT]) {
|
|
|
|
+ glBlendFuncSeparate(GL_SRC_ALPHA, GL_ONE, GL_SRC_ALPHA, GL_ONE);
|
|
|
|
+ } else {
|
|
|
|
+ glBlendFuncSeparate(GL_SRC_ALPHA, GL_ONE, GL_ZERO, GL_ONE);
|
|
|
|
+ }
|
|
|
|
|
|
- glBufferSubData(GL_ARRAY_BUFFER, buffer_ofs, sizeof(Color) * p_vertex_count, p_colors);
|
|
|
|
- glEnableVertexAttribArray(VS::ARRAY_COLOR);
|
|
|
|
- glVertexAttribPointer(VS::ARRAY_COLOR, 4, GL_FLOAT, false, sizeof(Color), CAST_INT_TO_UCHAR_PTR(buffer_ofs));
|
|
|
|
- buffer_ofs += sizeof(Color) * p_vertex_count;
|
|
|
|
- }
|
|
|
|
|
|
+ } break;
|
|
|
|
+ case RasterizerStorageGLES3::Shader::CanvasItem::BLEND_MODE_SUB: {
|
|
|
|
|
|
-#ifdef DEBUG_ENABLED
|
|
|
|
- ERR_FAIL_COND(buffer_ofs > data.polygon_buffer_size);
|
|
|
|
-#endif
|
|
|
|
|
|
+ glBlendEquation(GL_FUNC_REVERSE_SUBTRACT);
|
|
|
|
+ if (storage->frame.current_rt && storage->frame.current_rt->flags[RasterizerStorage::RENDER_TARGET_TRANSPARENT]) {
|
|
|
|
+ glBlendFuncSeparate(GL_SRC_ALPHA, GL_ONE, GL_SRC_ALPHA, GL_ONE);
|
|
|
|
+ } else {
|
|
|
|
+ glBlendFuncSeparate(GL_SRC_ALPHA, GL_ONE, GL_ZERO, GL_ONE);
|
|
|
|
+ }
|
|
|
|
+ } break;
|
|
|
|
+ case RasterizerStorageGLES3::Shader::CanvasItem::BLEND_MODE_MUL: {
|
|
|
|
+ glBlendEquation(GL_FUNC_ADD);
|
|
|
|
+ if (storage->frame.current_rt && storage->frame.current_rt->flags[RasterizerStorage::RENDER_TARGET_TRANSPARENT]) {
|
|
|
|
+ glBlendFuncSeparate(GL_DST_COLOR, GL_ZERO, GL_DST_ALPHA, GL_ZERO);
|
|
|
|
+ } else {
|
|
|
|
+ glBlendFuncSeparate(GL_DST_COLOR, GL_ZERO, GL_ZERO, GL_ONE);
|
|
|
|
+ }
|
|
|
|
|
|
- if (p_uvs) {
|
|
|
|
|
|
+ } break;
|
|
|
|
+ case RasterizerStorageGLES3::Shader::CanvasItem::BLEND_MODE_PMALPHA: {
|
|
|
|
+ glBlendEquation(GL_FUNC_ADD);
|
|
|
|
+ if (storage->frame.current_rt && storage->frame.current_rt->flags[RasterizerStorage::RENDER_TARGET_TRANSPARENT]) {
|
|
|
|
+ glBlendFuncSeparate(GL_ONE, GL_ONE_MINUS_SRC_ALPHA, GL_ONE, GL_ONE_MINUS_SRC_ALPHA);
|
|
|
|
+ } else {
|
|
|
|
+ glBlendFuncSeparate(GL_ONE, GL_ONE_MINUS_SRC_ALPHA, GL_ZERO, GL_ONE);
|
|
|
|
+ }
|
|
|
|
|
|
- glBufferSubData(GL_ARRAY_BUFFER, buffer_ofs, sizeof(Vector2) * p_vertex_count, p_uvs);
|
|
|
|
- glEnableVertexAttribArray(VS::ARRAY_TEX_UV);
|
|
|
|
- glVertexAttribPointer(VS::ARRAY_TEX_UV, 2, GL_FLOAT, false, sizeof(Vector2), CAST_INT_TO_UCHAR_PTR(buffer_ofs));
|
|
|
|
- buffer_ofs += sizeof(Vector2) * p_vertex_count;
|
|
|
|
|
|
+ } break;
|
|
|
|
+ }
|
|
|
|
|
|
- } else {
|
|
|
|
- glDisableVertexAttribArray(VS::ARRAY_TEX_UV);
|
|
|
|
|
|
+ r_ris.last_blend_mode = blend_mode;
|
|
}
|
|
}
|
|
|
|
|
|
-#ifdef DEBUG_ENABLED
|
|
|
|
- ERR_FAIL_COND(buffer_ofs > data.polygon_buffer_size);
|
|
|
|
-#endif
|
|
|
|
-
|
|
|
|
- //bind the indices buffer.
|
|
|
|
- glBindBuffer(GL_ELEMENT_ARRAY_BUFFER, data.polygon_index_buffer);
|
|
|
|
-
|
|
|
|
- storage->buffer_orphan_and_upload(data.polygon_index_buffer_size, 0, sizeof(int) * p_index_count, p_indices, GL_ELEMENT_ARRAY_BUFFER);
|
|
|
|
-
|
|
|
|
- //draw the triangles.
|
|
|
|
- glDrawElements(p_primitive, p_index_count, GL_UNSIGNED_INT, 0);
|
|
|
|
-
|
|
|
|
- storage->info.render._2d_draw_call_count++;
|
|
|
|
-
|
|
|
|
- glBindVertexArray(0);
|
|
|
|
- glBindBuffer(GL_ARRAY_BUFFER, 0);
|
|
|
|
-}
|
|
|
|
-
|
|
|
|
-void RasterizerCanvasGLES3::_draw_gui_primitive(int p_points, const Vector2 *p_vertices, const Color *p_colors, const Vector2 *p_uvs, const float *p_light_angles) {
|
|
|
|
|
|
+ state.canvas_item_modulate = unshaded ? p_ci->final_modulate : Color(p_ci->final_modulate.r * r_ris.item_group_modulate.r, p_ci->final_modulate.g * r_ris.item_group_modulate.g, p_ci->final_modulate.b * r_ris.item_group_modulate.b, p_ci->final_modulate.a * r_ris.item_group_modulate.a);
|
|
|
|
|
|
- static const GLenum prim[5] = { GL_POINTS, GL_POINTS, GL_LINES, GL_TRIANGLES, GL_TRIANGLE_FAN };
|
|
|
|
|
|
+ state.final_transform = p_ci->final_transform;
|
|
|
|
+ state.extra_matrix = Transform2D();
|
|
|
|
|
|
- //#define GLES_USE_PRIMITIVE_BUFFER
|
|
|
|
-
|
|
|
|
- int version = 0;
|
|
|
|
- int color_ofs = 0;
|
|
|
|
- int uv_ofs = 0;
|
|
|
|
- int light_angle_ofs = 0;
|
|
|
|
- int stride = 2;
|
|
|
|
-
|
|
|
|
- if (p_colors) { //color
|
|
|
|
- version |= 1;
|
|
|
|
- color_ofs = stride;
|
|
|
|
- stride += 4;
|
|
|
|
|
|
+ if (state.using_skeleton) {
|
|
|
|
+ state.canvas_shader.set_uniform(CanvasShaderGLES3::SKELETON_TRANSFORM, state.skeleton_transform);
|
|
|
|
+ state.canvas_shader.set_uniform(CanvasShaderGLES3::SKELETON_TRANSFORM_INVERSE, state.skeleton_transform_inverse);
|
|
}
|
|
}
|
|
|
|
|
|
- if (p_uvs) { //uv
|
|
|
|
- version |= 2;
|
|
|
|
- uv_ofs = stride;
|
|
|
|
- stride += 2;
|
|
|
|
|
|
+ state.canvas_shader.set_uniform(CanvasShaderGLES3::FINAL_MODULATE, state.canvas_item_modulate);
|
|
|
|
+ state.canvas_shader.set_uniform(CanvasShaderGLES3::MODELVIEW_MATRIX, state.final_transform);
|
|
|
|
+ state.canvas_shader.set_uniform(CanvasShaderGLES3::EXTRA_MATRIX, state.extra_matrix);
|
|
|
|
+ if (storage->frame.current_rt) {
|
|
|
|
+ state.canvas_shader.set_uniform(CanvasShaderGLES3::SCREEN_PIXEL_SIZE, Vector2(1.0 / storage->frame.current_rt->width, 1.0 / storage->frame.current_rt->height));
|
|
|
|
+ } else {
|
|
|
|
+ state.canvas_shader.set_uniform(CanvasShaderGLES3::SCREEN_PIXEL_SIZE, Vector2(1.0, 1.0));
|
|
}
|
|
}
|
|
|
|
+ if (unshaded || (state.canvas_item_modulate.a > 0.001 && (!r_ris.shader_cache || r_ris.shader_cache->canvas_item.light_mode != RasterizerStorageGLES3::Shader::CanvasItem::LIGHT_MODE_LIGHT_ONLY) && !p_ci->light_masked))
|
|
|
|
+ _legacy_canvas_item_render_commands(p_ci, r_ris.current_clip, reclip, nullptr);
|
|
|
|
|
|
- if (p_light_angles) { //light_angles
|
|
|
|
- version |= 4;
|
|
|
|
- light_angle_ofs = stride;
|
|
|
|
- stride += 1;
|
|
|
|
- }
|
|
|
|
|
|
+ if ((blend_mode == RasterizerStorageGLES3::Shader::CanvasItem::BLEND_MODE_MIX || blend_mode == RasterizerStorageGLES3::Shader::CanvasItem::BLEND_MODE_PMALPHA) && r_ris.item_group_light && !unshaded) {
|
|
|
|
|
|
- float b[(2 + 2 + 4 + 1) * 4];
|
|
|
|
|
|
+ Light *light = r_ris.item_group_light;
|
|
|
|
+ bool light_used = false;
|
|
|
|
+ VS::CanvasLightMode mode = VS::CANVAS_LIGHT_MODE_ADD;
|
|
|
|
+ state.canvas_item_modulate = p_ci->final_modulate; // remove the canvas modulate
|
|
|
|
|
|
- for (int i = 0; i < p_points; i++) {
|
|
|
|
- b[stride * i + 0] = p_vertices[i].x;
|
|
|
|
- b[stride * i + 1] = p_vertices[i].y;
|
|
|
|
- }
|
|
|
|
|
|
+ while (light) {
|
|
|
|
|
|
- if (p_colors) {
|
|
|
|
|
|
+ if (p_ci->light_mask & light->item_mask && r_ris.item_group_z >= light->z_min && r_ris.item_group_z <= light->z_max && p_ci->global_rect_cache.intersects_transformed(light->xform_cache, light->rect_cache)) {
|
|
|
|
|
|
- for (int i = 0; i < p_points; i++) {
|
|
|
|
- b[stride * i + color_ofs + 0] = p_colors[i].r;
|
|
|
|
- b[stride * i + color_ofs + 1] = p_colors[i].g;
|
|
|
|
- b[stride * i + color_ofs + 2] = p_colors[i].b;
|
|
|
|
- b[stride * i + color_ofs + 3] = p_colors[i].a;
|
|
|
|
- }
|
|
|
|
- }
|
|
|
|
|
|
+ //intersects this light
|
|
|
|
|
|
- if (p_uvs) {
|
|
|
|
|
|
+ if (!light_used || mode != light->mode) {
|
|
|
|
|
|
- for (int i = 0; i < p_points; i++) {
|
|
|
|
- b[stride * i + uv_ofs + 0] = p_uvs[i].x;
|
|
|
|
- b[stride * i + uv_ofs + 1] = p_uvs[i].y;
|
|
|
|
- }
|
|
|
|
- }
|
|
|
|
|
|
+ mode = light->mode;
|
|
|
|
|
|
- if (p_light_angles) {
|
|
|
|
|
|
+ switch (mode) {
|
|
|
|
|
|
- for (int i = 0; i < p_points; i++) {
|
|
|
|
- b[stride * i + light_angle_ofs] = p_light_angles[i];
|
|
|
|
- }
|
|
|
|
- }
|
|
|
|
|
|
+ case VS::CANVAS_LIGHT_MODE_ADD: {
|
|
|
|
+ glBlendEquation(GL_FUNC_ADD);
|
|
|
|
+ glBlendFunc(GL_SRC_ALPHA, GL_ONE);
|
|
|
|
|
|
- glBindBuffer(GL_ARRAY_BUFFER, data.polygon_buffer);
|
|
|
|
- //TODO the below call may need to be replaced with: (p_points * stride * 4 * sizeof(float), &b[0]);
|
|
|
|
- storage->buffer_orphan_and_upload(data.polygon_buffer_size, 0, p_points * stride * 4, &b[0]);
|
|
|
|
|
|
+ } break;
|
|
|
|
+ case VS::CANVAS_LIGHT_MODE_SUB: {
|
|
|
|
+ glBlendEquation(GL_FUNC_REVERSE_SUBTRACT);
|
|
|
|
+ glBlendFunc(GL_SRC_ALPHA, GL_ONE);
|
|
|
|
+ } break;
|
|
|
|
+ case VS::CANVAS_LIGHT_MODE_MIX:
|
|
|
|
+ case VS::CANVAS_LIGHT_MODE_MASK: {
|
|
|
|
+ glBlendEquation(GL_FUNC_ADD);
|
|
|
|
+ glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA);
|
|
|
|
|
|
- glBindVertexArray(data.polygon_buffer_quad_arrays[version]);
|
|
|
|
- glDrawArrays(prim[p_points], 0, p_points);
|
|
|
|
- glBindVertexArray(0);
|
|
|
|
- glBindBuffer(GL_ARRAY_BUFFER, 0);
|
|
|
|
|
|
+ } break;
|
|
|
|
+ }
|
|
|
|
+ }
|
|
|
|
|
|
- storage->info.render._2d_draw_call_count++;
|
|
|
|
-}
|
|
|
|
|
|
+ if (!light_used) {
|
|
|
|
|
|
-static const GLenum gl_primitive[] = {
|
|
|
|
- GL_POINTS,
|
|
|
|
- GL_LINES,
|
|
|
|
- GL_LINE_STRIP,
|
|
|
|
- GL_LINE_LOOP,
|
|
|
|
- GL_TRIANGLES,
|
|
|
|
- GL_TRIANGLE_STRIP,
|
|
|
|
- GL_TRIANGLE_FAN
|
|
|
|
-};
|
|
|
|
|
|
+ state.canvas_shader.set_conditional(CanvasShaderGLES3::USE_LIGHTING, true);
|
|
|
|
+ light_used = true;
|
|
|
|
+ }
|
|
|
|
|
|
-void RasterizerCanvasGLES3::render_rect_nvidia_workaround(const Item::CommandRect *p_rect, const RasterizerStorageGLES3::Texture *p_texture) {
|
|
|
|
|
|
+ bool has_shadow = light->shadow_buffer.is_valid() && p_ci->light_mask & light->item_shadow_mask;
|
|
|
|
+
|
|
|
|
+ state.canvas_shader.set_conditional(CanvasShaderGLES3::USE_SHADOWS, has_shadow);
|
|
|
|
+ if (has_shadow) {
|
|
|
|
+ state.canvas_shader.set_conditional(CanvasShaderGLES3::SHADOW_USE_GRADIENT, light->shadow_gradient_length > 0);
|
|
|
|
+ state.canvas_shader.set_conditional(CanvasShaderGLES3::SHADOW_FILTER_NEAREST, light->shadow_filter == VS::CANVAS_LIGHT_FILTER_NONE);
|
|
|
|
+ state.canvas_shader.set_conditional(CanvasShaderGLES3::SHADOW_FILTER_PCF3, light->shadow_filter == VS::CANVAS_LIGHT_FILTER_PCF3);
|
|
|
|
+ state.canvas_shader.set_conditional(CanvasShaderGLES3::SHADOW_FILTER_PCF5, light->shadow_filter == VS::CANVAS_LIGHT_FILTER_PCF5);
|
|
|
|
+ state.canvas_shader.set_conditional(CanvasShaderGLES3::SHADOW_FILTER_PCF7, light->shadow_filter == VS::CANVAS_LIGHT_FILTER_PCF7);
|
|
|
|
+ state.canvas_shader.set_conditional(CanvasShaderGLES3::SHADOW_FILTER_PCF9, light->shadow_filter == VS::CANVAS_LIGHT_FILTER_PCF9);
|
|
|
|
+ state.canvas_shader.set_conditional(CanvasShaderGLES3::SHADOW_FILTER_PCF13, light->shadow_filter == VS::CANVAS_LIGHT_FILTER_PCF13);
|
|
|
|
+ }
|
|
|
|
|
|
- if (p_texture) {
|
|
|
|
|
|
+ bool light_rebind = state.canvas_shader.bind();
|
|
|
|
|
|
- bool send_light_angles = false;
|
|
|
|
|
|
+ if (light_rebind) {
|
|
|
|
+ state.canvas_shader.set_uniform(CanvasShaderGLES3::FINAL_MODULATE, state.canvas_item_modulate);
|
|
|
|
+ state.canvas_shader.set_uniform(CanvasShaderGLES3::MODELVIEW_MATRIX, state.final_transform);
|
|
|
|
+ state.canvas_shader.set_uniform(CanvasShaderGLES3::EXTRA_MATRIX, Transform2D());
|
|
|
|
+ if (storage->frame.current_rt) {
|
|
|
|
+ state.canvas_shader.set_uniform(CanvasShaderGLES3::SCREEN_PIXEL_SIZE, Vector2(1.0 / storage->frame.current_rt->width, 1.0 / storage->frame.current_rt->height));
|
|
|
|
+ } else {
|
|
|
|
+ state.canvas_shader.set_uniform(CanvasShaderGLES3::SCREEN_PIXEL_SIZE, Vector2(1.0, 1.0));
|
|
|
|
+ }
|
|
|
|
+ if (state.using_skeleton) {
|
|
|
|
+ state.canvas_shader.set_uniform(CanvasShaderGLES3::SKELETON_TRANSFORM, state.skeleton_transform);
|
|
|
|
+ state.canvas_shader.set_uniform(CanvasShaderGLES3::SKELETON_TRANSFORM_INVERSE, state.skeleton_transform_inverse);
|
|
|
|
+ }
|
|
|
|
+ }
|
|
|
|
|
|
- // only need to use light angles when normal mapping
|
|
|
|
- // otherwise we can use the default shader
|
|
|
|
- if (state.current_normal != RID()) {
|
|
|
|
- send_light_angles = true;
|
|
|
|
- }
|
|
|
|
|
|
+ glBindBufferBase(GL_UNIFORM_BUFFER, 1, static_cast<LightInternal *>(light->light_internal.get_data())->ubo);
|
|
|
|
|
|
- // we don't want to use texture rect, and we want to send light angles if we are using normal mapping
|
|
|
|
- _set_texture_rect_mode(false, false, send_light_angles);
|
|
|
|
|
|
+ if (has_shadow) {
|
|
|
|
|
|
- bool untile = false;
|
|
|
|
|
|
+ RasterizerStorageGLES3::CanvasLightShadow *cls = storage->canvas_light_shadow_owner.get(light->shadow_buffer);
|
|
|
|
+ glActiveTexture(GL_TEXTURE0 + storage->config.max_texture_image_units - 2);
|
|
|
|
+ glBindTexture(GL_TEXTURE_2D, cls->distance);
|
|
|
|
|
|
- if (p_rect->flags & CANVAS_RECT_TILE && !(p_texture->flags & VS::TEXTURE_FLAG_REPEAT)) {
|
|
|
|
- glTexParameterf(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_REPEAT);
|
|
|
|
- glTexParameterf(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_REPEAT);
|
|
|
|
- untile = true;
|
|
|
|
- }
|
|
|
|
|
|
+ /*canvas_shader.set_uniform(CanvasShaderGLES3::SHADOW_MATRIX,light->shadow_matrix_cache);
|
|
|
|
+ canvas_shader.set_uniform(CanvasShaderGLES3::SHADOW_ESM_MULTIPLIER,light->shadow_esm_mult);
|
|
|
|
+ canvas_shader.set_uniform(CanvasShaderGLES3::LIGHT_SHADOW_COLOR,light->shadow_color);*/
|
|
|
|
+ }
|
|
|
|
|
|
- Size2 texpixel_size(1.0 / p_texture->width, 1.0 / p_texture->height);
|
|
|
|
|
|
+ glActiveTexture(GL_TEXTURE0 + storage->config.max_texture_image_units - 1);
|
|
|
|
+ RasterizerStorageGLES3::Texture *t = storage->texture_owner.getornull(light->texture);
|
|
|
|
+ if (!t) {
|
|
|
|
+ glBindTexture(GL_TEXTURE_2D, storage->resources.white_tex);
|
|
|
|
+ } else {
|
|
|
|
+ t = t->get_ptr();
|
|
|
|
|
|
- state.canvas_shader.set_uniform(CanvasShaderGLES3::CLIP_RECT_UV, p_rect->flags & CANVAS_RECT_CLIP_UV);
|
|
|
|
|
|
+ glBindTexture(t->target, t->tex_id);
|
|
|
|
+ }
|
|
|
|
|
|
- Vector2 points[4] = {
|
|
|
|
- p_rect->rect.position,
|
|
|
|
- p_rect->rect.position + Vector2(p_rect->rect.size.x, 0.0),
|
|
|
|
- p_rect->rect.position + p_rect->rect.size,
|
|
|
|
- p_rect->rect.position + Vector2(0.0, p_rect->rect.size.y),
|
|
|
|
- };
|
|
|
|
|
|
+ glActiveTexture(GL_TEXTURE0);
|
|
|
|
+ _legacy_canvas_item_render_commands(p_ci, r_ris.current_clip, reclip, nullptr); //redraw using light
|
|
|
|
+ }
|
|
|
|
|
|
- if (p_rect->rect.size.x < 0) {
|
|
|
|
- SWAP(points[0], points[1]);
|
|
|
|
- SWAP(points[2], points[3]);
|
|
|
|
|
|
+ light = light->next_ptr;
|
|
}
|
|
}
|
|
- if (p_rect->rect.size.y < 0) {
|
|
|
|
- SWAP(points[0], points[3]);
|
|
|
|
- SWAP(points[1], points[2]);
|
|
|
|
- }
|
|
|
|
- Rect2 src_rect = (p_rect->flags & CANVAS_RECT_REGION) ? Rect2(p_rect->source.position * texpixel_size, p_rect->source.size * texpixel_size) : Rect2(0, 0, 1, 1);
|
|
|
|
|
|
|
|
- Vector2 uvs[4] = {
|
|
|
|
- src_rect.position,
|
|
|
|
- src_rect.position + Vector2(src_rect.size.x, 0.0),
|
|
|
|
- src_rect.position + src_rect.size,
|
|
|
|
- src_rect.position + Vector2(0.0, src_rect.size.y),
|
|
|
|
- };
|
|
|
|
|
|
+ if (light_used) {
|
|
|
|
|
|
- // for encoding in light angle
|
|
|
|
- bool flip_h = false;
|
|
|
|
- bool flip_v = false;
|
|
|
|
|
|
+ state.canvas_shader.set_conditional(CanvasShaderGLES3::USE_LIGHTING, false);
|
|
|
|
+ state.canvas_shader.set_conditional(CanvasShaderGLES3::USE_SHADOWS, false);
|
|
|
|
+ state.canvas_shader.set_conditional(CanvasShaderGLES3::SHADOW_FILTER_NEAREST, false);
|
|
|
|
+ state.canvas_shader.set_conditional(CanvasShaderGLES3::SHADOW_FILTER_PCF3, false);
|
|
|
|
+ state.canvas_shader.set_conditional(CanvasShaderGLES3::SHADOW_FILTER_PCF5, false);
|
|
|
|
+ state.canvas_shader.set_conditional(CanvasShaderGLES3::SHADOW_FILTER_PCF7, false);
|
|
|
|
+ state.canvas_shader.set_conditional(CanvasShaderGLES3::SHADOW_FILTER_PCF9, false);
|
|
|
|
+ state.canvas_shader.set_conditional(CanvasShaderGLES3::SHADOW_FILTER_PCF13, false);
|
|
|
|
|
|
- if (p_rect->flags & CANVAS_RECT_TRANSPOSE) {
|
|
|
|
- SWAP(uvs[1], uvs[3]);
|
|
|
|
- }
|
|
|
|
|
|
+ state.canvas_shader.bind();
|
|
|
|
|
|
- if (p_rect->flags & CANVAS_RECT_FLIP_H) {
|
|
|
|
- SWAP(uvs[0], uvs[1]);
|
|
|
|
- SWAP(uvs[2], uvs[3]);
|
|
|
|
- flip_h = true;
|
|
|
|
- flip_v = !flip_v;
|
|
|
|
- }
|
|
|
|
- if (p_rect->flags & CANVAS_RECT_FLIP_V) {
|
|
|
|
- SWAP(uvs[0], uvs[3]);
|
|
|
|
- SWAP(uvs[1], uvs[2]);
|
|
|
|
- flip_v = !flip_v;
|
|
|
|
- }
|
|
|
|
|
|
+ r_ris.last_blend_mode = -1;
|
|
|
|
|
|
- if (send_light_angles) {
|
|
|
|
- // for single rects, there is no need to fully utilize the light angle,
|
|
|
|
- // we only need it to encode flips (horz and vert). But the shader can be reused with
|
|
|
|
- // batching in which case the angle encodes the transform as well as
|
|
|
|
- // the flips.
|
|
|
|
- // Note transpose is NYI. I don't think it worked either with the non-nvidia method.
|
|
|
|
|
|
+ /*
|
|
|
|
+ //this is set again, so it should not be needed anyway?
|
|
|
|
+ state.canvas_item_modulate = unshaded ? ci->final_modulate : Color(
|
|
|
|
+ ci->final_modulate.r * p_modulate.r,
|
|
|
|
+ ci->final_modulate.g * p_modulate.g,
|
|
|
|
+ ci->final_modulate.b * p_modulate.b,
|
|
|
|
+ ci->final_modulate.a * p_modulate.a );
|
|
|
|
|
|
- // if horizontal flip, angle is 180
|
|
|
|
- float angle = 0.0f;
|
|
|
|
- if (flip_h)
|
|
|
|
- angle = Math_PI;
|
|
|
|
|
|
|
|
- // add 1 (to take care of zero floating point error with sign)
|
|
|
|
- angle += 1.0f;
|
|
|
|
|
|
+ state.canvas_shader.set_uniform(CanvasShaderGLES3::MODELVIEW_MATRIX,state.final_transform);
|
|
|
|
+ state.canvas_shader.set_uniform(CanvasShaderGLES3::EXTRA_MATRIX,Transform2D());
|
|
|
|
+ state.canvas_shader.set_uniform(CanvasShaderGLES3::FINAL_MODULATE,state.canvas_item_modulate);
|
|
|
|
|
|
- // flip if necessary
|
|
|
|
- if (flip_v)
|
|
|
|
- angle *= -1.0f;
|
|
|
|
|
|
+ glBlendEquation(GL_FUNC_ADD);
|
|
|
|
|
|
- // light angle must be sent for each vert, instead as a single uniform in the uniform draw method
|
|
|
|
- // this has the benefit of enabling batching with light angles.
|
|
|
|
- float light_angles[4] = { angle, angle, angle, angle };
|
|
|
|
|
|
+ if (storage->frame.current_rt->flags[RasterizerStorage::RENDER_TARGET_TRANSPARENT]) {
|
|
|
|
+ glBlendFuncSeparate(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA, GL_ONE, GL_ONE_MINUS_SRC_ALPHA);
|
|
|
|
+ } else {
|
|
|
|
+ glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA);
|
|
|
|
+ }
|
|
|
|
|
|
- _draw_gui_primitive(4, points, NULL, uvs, light_angles);
|
|
|
|
- } else {
|
|
|
|
- _draw_gui_primitive(4, points, NULL, uvs);
|
|
|
|
|
|
+ //@TODO RESET canvas_blend_mode
|
|
|
|
+ */
|
|
}
|
|
}
|
|
|
|
+ }
|
|
|
|
|
|
- if (untile) {
|
|
|
|
- glTexParameterf(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_CLAMP_TO_EDGE);
|
|
|
|
- glTexParameterf(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_CLAMP_TO_EDGE);
|
|
|
|
- }
|
|
|
|
|
|
+ if (reclip) {
|
|
|
|
|
|
- } else {
|
|
|
|
- _set_texture_rect_mode(false);
|
|
|
|
|
|
+ glEnable(GL_SCISSOR_TEST);
|
|
|
|
+ int y = storage->frame.current_rt->height - (r_ris.current_clip->final_clip_rect.position.y + r_ris.current_clip->final_clip_rect.size.y);
|
|
|
|
+ if (storage->frame.current_rt->flags[RasterizerStorage::RENDER_TARGET_VFLIP])
|
|
|
|
+ y = r_ris.current_clip->final_clip_rect.position.y;
|
|
|
|
+ glScissor(r_ris.current_clip->final_clip_rect.position.x, y, r_ris.current_clip->final_clip_rect.size.width, r_ris.current_clip->final_clip_rect.size.height);
|
|
|
|
+ }
|
|
|
|
+}
|
|
|
|
|
|
- state.canvas_shader.set_uniform(CanvasShaderGLES3::CLIP_RECT_UV, false);
|
|
|
|
|
|
+void RasterizerCanvasGLES3::render_batches(Item::Command *const *p_commands, Item *p_current_clip, bool &r_reclip, RasterizerStorageGLES3::Material *p_material) {
|
|
|
|
+ // bdata.reset_flush();
|
|
|
|
+ // return;
|
|
|
|
|
|
- Vector2 points[4] = {
|
|
|
|
- p_rect->rect.position,
|
|
|
|
- p_rect->rect.position + Vector2(p_rect->rect.size.x, 0.0),
|
|
|
|
- p_rect->rect.position + p_rect->rect.size,
|
|
|
|
- p_rect->rect.position + Vector2(0.0, p_rect->rect.size.y),
|
|
|
|
- };
|
|
|
|
|
|
+ int num_batches = bdata.batches.size();
|
|
|
|
|
|
- _draw_gui_primitive(4, points, NULL, nullptr);
|
|
|
|
- }
|
|
|
|
-}
|
|
|
|
|
|
+ for (int batch_num = 0; batch_num < num_batches; batch_num++) {
|
|
|
|
+ const Batch &batch = bdata.batches[batch_num];
|
|
|
|
|
|
-void RasterizerCanvasGLES3::_canvas_item_render_commands(Item *p_item, Item *current_clip, bool &reclip) {
|
|
|
|
|
|
+ switch (batch.type) {
|
|
|
|
+ case RasterizerStorageCommon::BT_RECT: {
|
|
|
|
+ _batch_render_rects(batch, p_material);
|
|
|
|
+ } break;
|
|
|
|
+ case RasterizerStorageCommon::BT_POLY: {
|
|
|
|
+ _batch_render_polys(batch, p_material);
|
|
|
|
+ } break;
|
|
|
|
+ case RasterizerStorageCommon::BT_LINE: {
|
|
|
|
+ _batch_render_lines(batch, p_material, false);
|
|
|
|
+ } break;
|
|
|
|
+ case RasterizerStorageCommon::BT_LINE_AA: {
|
|
|
|
+ _batch_render_lines(batch, p_material, true);
|
|
|
|
+ } break;
|
|
|
|
+ default: {
|
|
|
|
+ int end_command = batch.first_command + batch.num_commands;
|
|
|
|
|
|
- int cc = p_item->commands.size();
|
|
|
|
- Item::Command **commands = p_item->commands.ptrw();
|
|
|
|
|
|
+ for (int i = batch.first_command; i < end_command; i++) {
|
|
|
|
|
|
- for (int i = 0; i < cc; i++) {
|
|
|
|
|
|
+ Item::Command *c = p_commands[i];
|
|
|
|
|
|
- Item::Command *c = commands[i];
|
|
|
|
|
|
+ switch (c->type) {
|
|
|
|
|
|
- switch (c->type) {
|
|
|
|
- case Item::Command::TYPE_LINE: {
|
|
|
|
|
|
+ case Item::Command::TYPE_LINE: {
|
|
|
|
|
|
- Item::CommandLine *line = static_cast<Item::CommandLine *>(c);
|
|
|
|
- _set_texture_rect_mode(false);
|
|
|
|
|
|
+ Item::CommandLine *line = static_cast<Item::CommandLine *>(c);
|
|
|
|
+ _set_texture_rect_mode(false);
|
|
|
|
|
|
- _bind_canvas_texture(RID(), RID());
|
|
|
|
|
|
+ _bind_canvas_texture(RID(), RID());
|
|
|
|
|
|
- glVertexAttrib4f(VS::ARRAY_COLOR, line->color.r, line->color.g, line->color.b, line->color.a);
|
|
|
|
|
|
+ glVertexAttrib4f(VS::ARRAY_COLOR, line->color.r, line->color.g, line->color.b, line->color.a);
|
|
|
|
|
|
- if (line->width <= 1) {
|
|
|
|
- Vector2 verts[2] = {
|
|
|
|
- Vector2(line->from.x, line->from.y),
|
|
|
|
- Vector2(line->to.x, line->to.y)
|
|
|
|
- };
|
|
|
|
|
|
+ if (line->width <= 1) {
|
|
|
|
+ Vector2 verts[2] = {
|
|
|
|
+ Vector2(line->from.x, line->from.y),
|
|
|
|
+ Vector2(line->to.x, line->to.y)
|
|
|
|
+ };
|
|
|
|
|
|
#ifdef GLES_OVER_GL
|
|
#ifdef GLES_OVER_GL
|
|
- if (line->antialiased)
|
|
|
|
- glEnable(GL_LINE_SMOOTH);
|
|
|
|
|
|
+ if (line->antialiased)
|
|
|
|
+ glEnable(GL_LINE_SMOOTH);
|
|
#endif
|
|
#endif
|
|
- //glLineWidth(line->width);
|
|
|
|
- _draw_gui_primitive(2, verts, NULL, NULL);
|
|
|
|
|
|
+ //glLineWidth(line->width);
|
|
|
|
+ _draw_gui_primitive(2, verts, NULL, NULL);
|
|
|
|
|
|
#ifdef GLES_OVER_GL
|
|
#ifdef GLES_OVER_GL
|
|
- if (line->antialiased)
|
|
|
|
- glDisable(GL_LINE_SMOOTH);
|
|
|
|
|
|
+ if (line->antialiased)
|
|
|
|
+ glDisable(GL_LINE_SMOOTH);
|
|
#endif
|
|
#endif
|
|
- } else {
|
|
|
|
- //thicker line
|
|
|
|
|
|
+ } else {
|
|
|
|
+ //thicker line
|
|
|
|
|
|
- Vector2 t = (line->from - line->to).normalized().tangent() * line->width * 0.5;
|
|
|
|
|
|
+ Vector2 t = (line->from - line->to).normalized().tangent() * line->width * 0.5;
|
|
|
|
|
|
- Vector2 verts[4] = {
|
|
|
|
- line->from - t,
|
|
|
|
- line->from + t,
|
|
|
|
- line->to + t,
|
|
|
|
- line->to - t,
|
|
|
|
- };
|
|
|
|
|
|
+ Vector2 verts[4] = {
|
|
|
|
+ line->from - t,
|
|
|
|
+ line->from + t,
|
|
|
|
+ line->to + t,
|
|
|
|
+ line->to - t,
|
|
|
|
+ };
|
|
|
|
|
|
- //glLineWidth(line->width);
|
|
|
|
- _draw_gui_primitive(4, verts, NULL, NULL);
|
|
|
|
|
|
+ //glLineWidth(line->width);
|
|
|
|
+ _draw_gui_primitive(4, verts, NULL, NULL);
|
|
#ifdef GLES_OVER_GL
|
|
#ifdef GLES_OVER_GL
|
|
- if (line->antialiased) {
|
|
|
|
- glEnable(GL_LINE_SMOOTH);
|
|
|
|
- for (int j = 0; j < 4; j++) {
|
|
|
|
- Vector2 vertsl[2] = {
|
|
|
|
- verts[j],
|
|
|
|
- verts[(j + 1) % 4],
|
|
|
|
- };
|
|
|
|
- _draw_gui_primitive(2, vertsl, NULL, NULL);
|
|
|
|
- }
|
|
|
|
- glDisable(GL_LINE_SMOOTH);
|
|
|
|
- }
|
|
|
|
|
|
+ if (line->antialiased) {
|
|
|
|
+ glEnable(GL_LINE_SMOOTH);
|
|
|
|
+ for (int j = 0; j < 4; j++) {
|
|
|
|
+ Vector2 vertsl[2] = {
|
|
|
|
+ verts[j],
|
|
|
|
+ verts[(j + 1) % 4],
|
|
|
|
+ };
|
|
|
|
+ _draw_gui_primitive(2, vertsl, NULL, NULL);
|
|
|
|
+ }
|
|
|
|
+ glDisable(GL_LINE_SMOOTH);
|
|
|
|
+ }
|
|
#endif
|
|
#endif
|
|
- }
|
|
|
|
- } break;
|
|
|
|
- case Item::Command::TYPE_POLYLINE: {
|
|
|
|
|
|
+ }
|
|
|
|
+ } break;
|
|
|
|
+ case Item::Command::TYPE_POLYLINE: {
|
|
|
|
|
|
- Item::CommandPolyLine *pline = static_cast<Item::CommandPolyLine *>(c);
|
|
|
|
- _set_texture_rect_mode(false);
|
|
|
|
|
|
+ Item::CommandPolyLine *pline = static_cast<Item::CommandPolyLine *>(c);
|
|
|
|
+ _set_texture_rect_mode(false);
|
|
|
|
|
|
- _bind_canvas_texture(RID(), RID());
|
|
|
|
|
|
+ _bind_canvas_texture(RID(), RID());
|
|
|
|
|
|
- if (pline->triangles.size()) {
|
|
|
|
|
|
+ if (pline->triangles.size()) {
|
|
|
|
|
|
- _draw_generic(GL_TRIANGLE_STRIP, pline->triangles.size(), pline->triangles.ptr(), NULL, pline->triangle_colors.ptr(), pline->triangle_colors.size() == 1);
|
|
|
|
|
|
+ _draw_generic(GL_TRIANGLE_STRIP, pline->triangles.size(), pline->triangles.ptr(), NULL, pline->triangle_colors.ptr(), pline->triangle_colors.size() == 1);
|
|
#ifdef GLES_OVER_GL
|
|
#ifdef GLES_OVER_GL
|
|
- glEnable(GL_LINE_SMOOTH);
|
|
|
|
- if (pline->multiline) {
|
|
|
|
- //needs to be different
|
|
|
|
- } else {
|
|
|
|
- _draw_generic(GL_LINE_LOOP, pline->lines.size(), pline->lines.ptr(), NULL, pline->line_colors.ptr(), pline->line_colors.size() == 1);
|
|
|
|
- }
|
|
|
|
- glDisable(GL_LINE_SMOOTH);
|
|
|
|
|
|
+ glEnable(GL_LINE_SMOOTH);
|
|
|
|
+ if (pline->multiline) {
|
|
|
|
+ //needs to be different
|
|
|
|
+ } else {
|
|
|
|
+ _draw_generic(GL_LINE_LOOP, pline->lines.size(), pline->lines.ptr(), NULL, pline->line_colors.ptr(), pline->line_colors.size() == 1);
|
|
|
|
+ }
|
|
|
|
+ glDisable(GL_LINE_SMOOTH);
|
|
#endif
|
|
#endif
|
|
- } else {
|
|
|
|
|
|
+ } else {
|
|
|
|
|
|
#ifdef GLES_OVER_GL
|
|
#ifdef GLES_OVER_GL
|
|
- if (pline->antialiased)
|
|
|
|
- glEnable(GL_LINE_SMOOTH);
|
|
|
|
|
|
+ if (pline->antialiased)
|
|
|
|
+ glEnable(GL_LINE_SMOOTH);
|
|
#endif
|
|
#endif
|
|
|
|
|
|
- if (pline->multiline) {
|
|
|
|
- int todo = pline->lines.size() / 2;
|
|
|
|
- int max_per_call = data.polygon_buffer_size / (sizeof(real_t) * 4);
|
|
|
|
- int offset = 0;
|
|
|
|
|
|
+ if (pline->multiline) {
|
|
|
|
+ int todo = pline->lines.size() / 2;
|
|
|
|
+ int max_per_call = data.polygon_buffer_size / (sizeof(real_t) * 4);
|
|
|
|
+ int offset = 0;
|
|
|
|
|
|
- while (todo) {
|
|
|
|
- int to_draw = MIN(max_per_call, todo);
|
|
|
|
- _draw_generic(GL_LINES, to_draw * 2, &pline->lines.ptr()[offset], NULL, pline->line_colors.size() == 1 ? pline->line_colors.ptr() : &pline->line_colors.ptr()[offset], pline->line_colors.size() == 1);
|
|
|
|
- todo -= to_draw;
|
|
|
|
- offset += to_draw * 2;
|
|
|
|
- }
|
|
|
|
|
|
+ while (todo) {
|
|
|
|
+ int to_draw = MIN(max_per_call, todo);
|
|
|
|
+ _draw_generic(GL_LINES, to_draw * 2, &pline->lines.ptr()[offset], NULL, pline->line_colors.size() == 1 ? pline->line_colors.ptr() : &pline->line_colors.ptr()[offset], pline->line_colors.size() == 1);
|
|
|
|
+ todo -= to_draw;
|
|
|
|
+ offset += to_draw * 2;
|
|
|
|
+ }
|
|
|
|
|
|
- } else {
|
|
|
|
|
|
+ } else {
|
|
|
|
|
|
- _draw_generic(GL_LINE_STRIP, pline->lines.size(), pline->lines.ptr(), NULL, pline->line_colors.ptr(), pline->line_colors.size() == 1);
|
|
|
|
- }
|
|
|
|
|
|
+ _draw_generic(GL_LINE_STRIP, pline->lines.size(), pline->lines.ptr(), NULL, pline->line_colors.ptr(), pline->line_colors.size() == 1);
|
|
|
|
+ }
|
|
|
|
|
|
#ifdef GLES_OVER_GL
|
|
#ifdef GLES_OVER_GL
|
|
- if (pline->antialiased)
|
|
|
|
- glDisable(GL_LINE_SMOOTH);
|
|
|
|
|
|
+ if (pline->antialiased)
|
|
|
|
+ glDisable(GL_LINE_SMOOTH);
|
|
#endif
|
|
#endif
|
|
- }
|
|
|
|
|
|
+ }
|
|
|
|
|
|
- } break;
|
|
|
|
- case Item::Command::TYPE_RECT: {
|
|
|
|
|
|
+ } break;
|
|
|
|
+ case Item::Command::TYPE_RECT: {
|
|
|
|
|
|
- Item::CommandRect *rect = static_cast<Item::CommandRect *>(c);
|
|
|
|
|
|
+ Item::CommandRect *rect = static_cast<Item::CommandRect *>(c);
|
|
|
|
|
|
- //set color
|
|
|
|
- glVertexAttrib4f(VS::ARRAY_COLOR, rect->modulate.r, rect->modulate.g, rect->modulate.b, rect->modulate.a);
|
|
|
|
|
|
+ //set color
|
|
|
|
+ glVertexAttrib4f(VS::ARRAY_COLOR, rect->modulate.r, rect->modulate.g, rect->modulate.b, rect->modulate.a);
|
|
|
|
|
|
- RasterizerStorageGLES3::Texture *texture = _bind_canvas_texture(rect->texture, rect->normal_map);
|
|
|
|
|
|
+ RasterizerStorageGLES3::Texture *texture = _bind_canvas_texture(rect->texture, rect->normal_map);
|
|
|
|
|
|
- if (use_nvidia_rect_workaround) {
|
|
|
|
- render_rect_nvidia_workaround(rect, texture);
|
|
|
|
- } else {
|
|
|
|
|
|
+ if (use_nvidia_rect_workaround) {
|
|
|
|
+ render_rect_nvidia_workaround(rect, texture);
|
|
|
|
+ } else {
|
|
|
|
|
|
- _set_texture_rect_mode(true);
|
|
|
|
|
|
+ _set_texture_rect_mode(true);
|
|
|
|
|
|
- if (texture) {
|
|
|
|
|
|
+ if (texture) {
|
|
|
|
|
|
- bool untile = false;
|
|
|
|
|
|
+ bool untile = false;
|
|
|
|
|
|
- if (rect->flags & CANVAS_RECT_TILE && !(texture->flags & VS::TEXTURE_FLAG_REPEAT)) {
|
|
|
|
- glTexParameterf(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_REPEAT);
|
|
|
|
- glTexParameterf(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_REPEAT);
|
|
|
|
- untile = true;
|
|
|
|
- }
|
|
|
|
|
|
+ if (rect->flags & CANVAS_RECT_TILE && !(texture->flags & VS::TEXTURE_FLAG_REPEAT)) {
|
|
|
|
+ glTexParameterf(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_REPEAT);
|
|
|
|
+ glTexParameterf(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_REPEAT);
|
|
|
|
+ untile = true;
|
|
|
|
+ }
|
|
|
|
|
|
- Size2 texpixel_size(1.0 / texture->width, 1.0 / texture->height);
|
|
|
|
- Rect2 src_rect = (rect->flags & CANVAS_RECT_REGION) ? Rect2(rect->source.position * texpixel_size, rect->source.size * texpixel_size) : Rect2(0, 0, 1, 1);
|
|
|
|
- Rect2 dst_rect = Rect2(rect->rect.position, rect->rect.size);
|
|
|
|
|
|
+ Size2 texpixel_size(1.0 / texture->width, 1.0 / texture->height);
|
|
|
|
+ Rect2 src_rect = (rect->flags & CANVAS_RECT_REGION) ? Rect2(rect->source.position * texpixel_size, rect->source.size * texpixel_size) : Rect2(0, 0, 1, 1);
|
|
|
|
+ Rect2 dst_rect = Rect2(rect->rect.position, rect->rect.size);
|
|
|
|
|
|
- if (dst_rect.size.width < 0) {
|
|
|
|
- dst_rect.position.x += dst_rect.size.width;
|
|
|
|
- dst_rect.size.width *= -1;
|
|
|
|
- }
|
|
|
|
- if (dst_rect.size.height < 0) {
|
|
|
|
- dst_rect.position.y += dst_rect.size.height;
|
|
|
|
- dst_rect.size.height *= -1;
|
|
|
|
- }
|
|
|
|
|
|
+ if (dst_rect.size.width < 0) {
|
|
|
|
+ dst_rect.position.x += dst_rect.size.width;
|
|
|
|
+ dst_rect.size.width *= -1;
|
|
|
|
+ }
|
|
|
|
+ if (dst_rect.size.height < 0) {
|
|
|
|
+ dst_rect.position.y += dst_rect.size.height;
|
|
|
|
+ dst_rect.size.height *= -1;
|
|
|
|
+ }
|
|
|
|
|
|
- if (rect->flags & CANVAS_RECT_FLIP_H) {
|
|
|
|
- src_rect.size.x *= -1;
|
|
|
|
- }
|
|
|
|
|
|
+ if (rect->flags & CANVAS_RECT_FLIP_H) {
|
|
|
|
+ src_rect.size.x *= -1;
|
|
|
|
+ }
|
|
|
|
|
|
- if (rect->flags & CANVAS_RECT_FLIP_V) {
|
|
|
|
- src_rect.size.y *= -1;
|
|
|
|
- }
|
|
|
|
|
|
+ if (rect->flags & CANVAS_RECT_FLIP_V) {
|
|
|
|
+ src_rect.size.y *= -1;
|
|
|
|
+ }
|
|
|
|
|
|
- if (rect->flags & CANVAS_RECT_TRANSPOSE) {
|
|
|
|
- dst_rect.size.x *= -1; // Encoding in the dst_rect.z uniform
|
|
|
|
- }
|
|
|
|
|
|
+ if (rect->flags & CANVAS_RECT_TRANSPOSE) {
|
|
|
|
+ dst_rect.size.x *= -1; // Encoding in the dst_rect.z uniform
|
|
|
|
+ }
|
|
|
|
|
|
- state.canvas_shader.set_uniform(CanvasShaderGLES3::COLOR_TEXPIXEL_SIZE, texpixel_size);
|
|
|
|
|
|
+ state.canvas_shader.set_uniform(CanvasShaderGLES3::COLOR_TEXPIXEL_SIZE, texpixel_size);
|
|
|
|
|
|
- state.canvas_shader.set_uniform(CanvasShaderGLES3::DST_RECT, Color(dst_rect.position.x, dst_rect.position.y, dst_rect.size.x, dst_rect.size.y));
|
|
|
|
- state.canvas_shader.set_uniform(CanvasShaderGLES3::SRC_RECT, Color(src_rect.position.x, src_rect.position.y, src_rect.size.x, src_rect.size.y));
|
|
|
|
- state.canvas_shader.set_uniform(CanvasShaderGLES3::CLIP_RECT_UV, rect->flags & CANVAS_RECT_CLIP_UV);
|
|
|
|
|
|
+ state.canvas_shader.set_uniform(CanvasShaderGLES3::DST_RECT, Color(dst_rect.position.x, dst_rect.position.y, dst_rect.size.x, dst_rect.size.y));
|
|
|
|
+ state.canvas_shader.set_uniform(CanvasShaderGLES3::SRC_RECT, Color(src_rect.position.x, src_rect.position.y, src_rect.size.x, src_rect.size.y));
|
|
|
|
+ state.canvas_shader.set_uniform(CanvasShaderGLES3::CLIP_RECT_UV, rect->flags & CANVAS_RECT_CLIP_UV);
|
|
|
|
|
|
- glDrawArrays(GL_TRIANGLE_FAN, 0, 4);
|
|
|
|
- storage->info.render._2d_draw_call_count++;
|
|
|
|
|
|
+ glDrawArrays(GL_TRIANGLE_FAN, 0, 4);
|
|
|
|
+ storage->info.render._2d_draw_call_count++;
|
|
|
|
|
|
- if (untile) {
|
|
|
|
- glTexParameterf(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_CLAMP_TO_EDGE);
|
|
|
|
- glTexParameterf(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_CLAMP_TO_EDGE);
|
|
|
|
- }
|
|
|
|
|
|
+ if (untile) {
|
|
|
|
+ glTexParameterf(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_CLAMP_TO_EDGE);
|
|
|
|
+ glTexParameterf(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_CLAMP_TO_EDGE);
|
|
|
|
+ }
|
|
|
|
|
|
- } else {
|
|
|
|
- Rect2 dst_rect = Rect2(rect->rect.position, rect->rect.size);
|
|
|
|
|
|
+ } else {
|
|
|
|
+ Rect2 dst_rect = Rect2(rect->rect.position, rect->rect.size);
|
|
|
|
|
|
- if (dst_rect.size.width < 0) {
|
|
|
|
- dst_rect.position.x += dst_rect.size.width;
|
|
|
|
- dst_rect.size.width *= -1;
|
|
|
|
- }
|
|
|
|
- if (dst_rect.size.height < 0) {
|
|
|
|
- dst_rect.position.y += dst_rect.size.height;
|
|
|
|
- dst_rect.size.height *= -1;
|
|
|
|
- }
|
|
|
|
|
|
+ if (dst_rect.size.width < 0) {
|
|
|
|
+ dst_rect.position.x += dst_rect.size.width;
|
|
|
|
+ dst_rect.size.width *= -1;
|
|
|
|
+ }
|
|
|
|
+ if (dst_rect.size.height < 0) {
|
|
|
|
+ dst_rect.position.y += dst_rect.size.height;
|
|
|
|
+ dst_rect.size.height *= -1;
|
|
|
|
+ }
|
|
|
|
|
|
- state.canvas_shader.set_uniform(CanvasShaderGLES3::DST_RECT, Color(dst_rect.position.x, dst_rect.position.y, dst_rect.size.x, dst_rect.size.y));
|
|
|
|
- state.canvas_shader.set_uniform(CanvasShaderGLES3::SRC_RECT, Color(0, 0, 1, 1));
|
|
|
|
- state.canvas_shader.set_uniform(CanvasShaderGLES3::CLIP_RECT_UV, false);
|
|
|
|
- glDrawArrays(GL_TRIANGLE_FAN, 0, 4);
|
|
|
|
- storage->info.render._2d_draw_call_count++;
|
|
|
|
- }
|
|
|
|
- } // if not use nvidia workaround
|
|
|
|
- } break;
|
|
|
|
- case Item::Command::TYPE_NINEPATCH: {
|
|
|
|
|
|
+ state.canvas_shader.set_uniform(CanvasShaderGLES3::DST_RECT, Color(dst_rect.position.x, dst_rect.position.y, dst_rect.size.x, dst_rect.size.y));
|
|
|
|
+ state.canvas_shader.set_uniform(CanvasShaderGLES3::SRC_RECT, Color(0, 0, 1, 1));
|
|
|
|
+ state.canvas_shader.set_uniform(CanvasShaderGLES3::CLIP_RECT_UV, false);
|
|
|
|
+ glDrawArrays(GL_TRIANGLE_FAN, 0, 4);
|
|
|
|
+ storage->info.render._2d_draw_call_count++;
|
|
|
|
+ }
|
|
|
|
+ } // if not use nvidia workaround
|
|
|
|
+ } break;
|
|
|
|
+ case Item::Command::TYPE_NINEPATCH: {
|
|
|
|
|
|
- Item::CommandNinePatch *np = static_cast<Item::CommandNinePatch *>(c);
|
|
|
|
|
|
+ Item::CommandNinePatch *np = static_cast<Item::CommandNinePatch *>(c);
|
|
|
|
|
|
- _set_texture_rect_mode(true, true);
|
|
|
|
|
|
+ _set_texture_rect_mode(true, true);
|
|
|
|
|
|
- glVertexAttrib4f(VS::ARRAY_COLOR, np->color.r, np->color.g, np->color.b, np->color.a);
|
|
|
|
|
|
+ glVertexAttrib4f(VS::ARRAY_COLOR, np->color.r, np->color.g, np->color.b, np->color.a);
|
|
|
|
|
|
- RasterizerStorageGLES3::Texture *texture = _bind_canvas_texture(np->texture, np->normal_map);
|
|
|
|
|
|
+ RasterizerStorageGLES3::Texture *texture = _bind_canvas_texture(np->texture, np->normal_map);
|
|
|
|
|
|
- Size2 texpixel_size;
|
|
|
|
|
|
+ Size2 texpixel_size;
|
|
|
|
|
|
- if (!texture) {
|
|
|
|
|
|
+ if (!texture) {
|
|
|
|
|
|
- texpixel_size = Size2(1, 1);
|
|
|
|
|
|
+ texpixel_size = Size2(1, 1);
|
|
|
|
|
|
- state.canvas_shader.set_uniform(CanvasShaderGLES3::SRC_RECT, Color(0, 0, 1, 1));
|
|
|
|
|
|
+ state.canvas_shader.set_uniform(CanvasShaderGLES3::SRC_RECT, Color(0, 0, 1, 1));
|
|
|
|
|
|
- } else {
|
|
|
|
|
|
+ } else {
|
|
|
|
|
|
- if (np->source != Rect2()) {
|
|
|
|
- texpixel_size = Size2(1.0 / np->source.size.width, 1.0 / np->source.size.height);
|
|
|
|
- state.canvas_shader.set_uniform(CanvasShaderGLES3::SRC_RECT, Color(np->source.position.x / texture->width, np->source.position.y / texture->height, np->source.size.x / texture->width, np->source.size.y / texture->height));
|
|
|
|
- } else {
|
|
|
|
- texpixel_size = Size2(1.0 / texture->width, 1.0 / texture->height);
|
|
|
|
- state.canvas_shader.set_uniform(CanvasShaderGLES3::SRC_RECT, Color(0, 0, 1, 1));
|
|
|
|
- }
|
|
|
|
- }
|
|
|
|
|
|
+ if (np->source != Rect2()) {
|
|
|
|
+ texpixel_size = Size2(1.0 / np->source.size.width, 1.0 / np->source.size.height);
|
|
|
|
+ state.canvas_shader.set_uniform(CanvasShaderGLES3::SRC_RECT, Color(np->source.position.x / texture->width, np->source.position.y / texture->height, np->source.size.x / texture->width, np->source.size.y / texture->height));
|
|
|
|
+ } else {
|
|
|
|
+ texpixel_size = Size2(1.0 / texture->width, 1.0 / texture->height);
|
|
|
|
+ state.canvas_shader.set_uniform(CanvasShaderGLES3::SRC_RECT, Color(0, 0, 1, 1));
|
|
|
|
+ }
|
|
|
|
+ }
|
|
|
|
|
|
- state.canvas_shader.set_uniform(CanvasShaderGLES3::COLOR_TEXPIXEL_SIZE, texpixel_size);
|
|
|
|
- state.canvas_shader.set_uniform(CanvasShaderGLES3::CLIP_RECT_UV, false);
|
|
|
|
- state.canvas_shader.set_uniform(CanvasShaderGLES3::NP_REPEAT_H, int(np->axis_x));
|
|
|
|
- state.canvas_shader.set_uniform(CanvasShaderGLES3::NP_REPEAT_V, int(np->axis_y));
|
|
|
|
- state.canvas_shader.set_uniform(CanvasShaderGLES3::NP_DRAW_CENTER, np->draw_center);
|
|
|
|
- state.canvas_shader.set_uniform(CanvasShaderGLES3::NP_MARGINS, Color(np->margin[MARGIN_LEFT], np->margin[MARGIN_TOP], np->margin[MARGIN_RIGHT], np->margin[MARGIN_BOTTOM]));
|
|
|
|
- state.canvas_shader.set_uniform(CanvasShaderGLES3::DST_RECT, Color(np->rect.position.x, np->rect.position.y, np->rect.size.x, np->rect.size.y));
|
|
|
|
|
|
+ state.canvas_shader.set_uniform(CanvasShaderGLES3::COLOR_TEXPIXEL_SIZE, texpixel_size);
|
|
|
|
+ state.canvas_shader.set_uniform(CanvasShaderGLES3::CLIP_RECT_UV, false);
|
|
|
|
+ state.canvas_shader.set_uniform(CanvasShaderGLES3::NP_REPEAT_H, int(np->axis_x));
|
|
|
|
+ state.canvas_shader.set_uniform(CanvasShaderGLES3::NP_REPEAT_V, int(np->axis_y));
|
|
|
|
+ state.canvas_shader.set_uniform(CanvasShaderGLES3::NP_DRAW_CENTER, np->draw_center);
|
|
|
|
+ state.canvas_shader.set_uniform(CanvasShaderGLES3::NP_MARGINS, Color(np->margin[MARGIN_LEFT], np->margin[MARGIN_TOP], np->margin[MARGIN_RIGHT], np->margin[MARGIN_BOTTOM]));
|
|
|
|
+ state.canvas_shader.set_uniform(CanvasShaderGLES3::DST_RECT, Color(np->rect.position.x, np->rect.position.y, np->rect.size.x, np->rect.size.y));
|
|
|
|
|
|
- glDrawArrays(GL_TRIANGLE_FAN, 0, 4);
|
|
|
|
|
|
+ glDrawArrays(GL_TRIANGLE_FAN, 0, 4);
|
|
|
|
|
|
- storage->info.render._2d_draw_call_count++;
|
|
|
|
- } break;
|
|
|
|
- case Item::Command::TYPE_PRIMITIVE: {
|
|
|
|
|
|
+ storage->info.render._2d_draw_call_count++;
|
|
|
|
+ } break;
|
|
|
|
+ case Item::Command::TYPE_PRIMITIVE: {
|
|
|
|
|
|
- Item::CommandPrimitive *primitive = static_cast<Item::CommandPrimitive *>(c);
|
|
|
|
- _set_texture_rect_mode(false);
|
|
|
|
|
|
+ Item::CommandPrimitive *primitive = static_cast<Item::CommandPrimitive *>(c);
|
|
|
|
+ _set_texture_rect_mode(false);
|
|
|
|
|
|
- ERR_CONTINUE(primitive->points.size() < 1);
|
|
|
|
|
|
+ ERR_CONTINUE(primitive->points.size() < 1);
|
|
|
|
|
|
- RasterizerStorageGLES3::Texture *texture = _bind_canvas_texture(primitive->texture, primitive->normal_map);
|
|
|
|
|
|
+ RasterizerStorageGLES3::Texture *texture = _bind_canvas_texture(primitive->texture, primitive->normal_map);
|
|
|
|
|
|
- if (texture) {
|
|
|
|
- Size2 texpixel_size(1.0 / texture->width, 1.0 / texture->height);
|
|
|
|
- state.canvas_shader.set_uniform(CanvasShaderGLES3::COLOR_TEXPIXEL_SIZE, texpixel_size);
|
|
|
|
- }
|
|
|
|
- if (primitive->colors.size() == 1 && primitive->points.size() > 1) {
|
|
|
|
|
|
+ if (texture) {
|
|
|
|
+ Size2 texpixel_size(1.0 / texture->width, 1.0 / texture->height);
|
|
|
|
+ state.canvas_shader.set_uniform(CanvasShaderGLES3::COLOR_TEXPIXEL_SIZE, texpixel_size);
|
|
|
|
+ }
|
|
|
|
+ if (primitive->colors.size() == 1 && primitive->points.size() > 1) {
|
|
|
|
|
|
- Color col = primitive->colors[0];
|
|
|
|
- glVertexAttrib4f(VS::ARRAY_COLOR, col.r, col.g, col.b, col.a);
|
|
|
|
|
|
+ Color col = primitive->colors[0];
|
|
|
|
+ glVertexAttrib4f(VS::ARRAY_COLOR, col.r, col.g, col.b, col.a);
|
|
|
|
|
|
- } else if (primitive->colors.empty()) {
|
|
|
|
- glVertexAttrib4f(VS::ARRAY_COLOR, 1, 1, 1, 1);
|
|
|
|
- }
|
|
|
|
|
|
+ } else if (primitive->colors.empty()) {
|
|
|
|
+ glVertexAttrib4f(VS::ARRAY_COLOR, 1, 1, 1, 1);
|
|
|
|
+ }
|
|
|
|
|
|
- _draw_gui_primitive(primitive->points.size(), primitive->points.ptr(), primitive->colors.ptr(), primitive->uvs.ptr());
|
|
|
|
|
|
+ _draw_gui_primitive(primitive->points.size(), primitive->points.ptr(), primitive->colors.ptr(), primitive->uvs.ptr());
|
|
|
|
|
|
- } break;
|
|
|
|
- case Item::Command::TYPE_POLYGON: {
|
|
|
|
|
|
+ } break;
|
|
|
|
+ case Item::Command::TYPE_POLYGON: {
|
|
|
|
|
|
- Item::CommandPolygon *polygon = static_cast<Item::CommandPolygon *>(c);
|
|
|
|
- _set_texture_rect_mode(false);
|
|
|
|
|
|
+ Item::CommandPolygon *polygon = static_cast<Item::CommandPolygon *>(c);
|
|
|
|
+ _set_texture_rect_mode(false);
|
|
|
|
|
|
- RasterizerStorageGLES3::Texture *texture = _bind_canvas_texture(polygon->texture, polygon->normal_map);
|
|
|
|
|
|
+ RasterizerStorageGLES3::Texture *texture = _bind_canvas_texture(polygon->texture, polygon->normal_map);
|
|
|
|
|
|
- if (texture) {
|
|
|
|
- Size2 texpixel_size(1.0 / texture->width, 1.0 / texture->height);
|
|
|
|
- state.canvas_shader.set_uniform(CanvasShaderGLES3::COLOR_TEXPIXEL_SIZE, texpixel_size);
|
|
|
|
- }
|
|
|
|
|
|
+ if (texture) {
|
|
|
|
+ Size2 texpixel_size(1.0 / texture->width, 1.0 / texture->height);
|
|
|
|
+ state.canvas_shader.set_uniform(CanvasShaderGLES3::COLOR_TEXPIXEL_SIZE, texpixel_size);
|
|
|
|
+ }
|
|
|
|
|
|
- _draw_polygon(polygon->indices.ptr(), polygon->count, polygon->points.size(), polygon->points.ptr(), polygon->uvs.ptr(), polygon->colors.ptr(), polygon->colors.size() == 1, polygon->bones.ptr(), polygon->weights.ptr());
|
|
|
|
|
|
+ _draw_polygon(polygon->indices.ptr(), polygon->count, polygon->points.size(), polygon->points.ptr(), polygon->uvs.ptr(), polygon->colors.ptr(), polygon->colors.size() == 1, polygon->bones.ptr(), polygon->weights.ptr());
|
|
#ifdef GLES_OVER_GL
|
|
#ifdef GLES_OVER_GL
|
|
- if (polygon->antialiased) {
|
|
|
|
- glEnable(GL_LINE_SMOOTH);
|
|
|
|
- if (polygon->antialiasing_use_indices) {
|
|
|
|
- _draw_generic_indices(GL_LINE_STRIP, polygon->indices.ptr(), polygon->count, polygon->points.size(), polygon->points.ptr(), polygon->uvs.ptr(), polygon->colors.ptr(), polygon->colors.size() == 1);
|
|
|
|
- } else {
|
|
|
|
- _draw_generic(GL_LINE_LOOP, polygon->points.size(), polygon->points.ptr(), polygon->uvs.ptr(), polygon->colors.ptr(), polygon->colors.size() == 1);
|
|
|
|
- }
|
|
|
|
- glDisable(GL_LINE_SMOOTH);
|
|
|
|
- }
|
|
|
|
|
|
+ if (polygon->antialiased) {
|
|
|
|
+ glEnable(GL_LINE_SMOOTH);
|
|
|
|
+ if (polygon->antialiasing_use_indices) {
|
|
|
|
+ _draw_generic_indices(GL_LINE_STRIP, polygon->indices.ptr(), polygon->count, polygon->points.size(), polygon->points.ptr(), polygon->uvs.ptr(), polygon->colors.ptr(), polygon->colors.size() == 1);
|
|
|
|
+ } else {
|
|
|
|
+ _draw_generic(GL_LINE_LOOP, polygon->points.size(), polygon->points.ptr(), polygon->uvs.ptr(), polygon->colors.ptr(), polygon->colors.size() == 1);
|
|
|
|
+ }
|
|
|
|
+ glDisable(GL_LINE_SMOOTH);
|
|
|
|
+ }
|
|
#endif
|
|
#endif
|
|
|
|
|
|
- } break;
|
|
|
|
- case Item::Command::TYPE_MESH: {
|
|
|
|
-
|
|
|
|
- Item::CommandMesh *mesh = static_cast<Item::CommandMesh *>(c);
|
|
|
|
- _set_texture_rect_mode(false);
|
|
|
|
-
|
|
|
|
- RasterizerStorageGLES3::Texture *texture = _bind_canvas_texture(mesh->texture, mesh->normal_map);
|
|
|
|
-
|
|
|
|
- if (texture) {
|
|
|
|
- Size2 texpixel_size(1.0 / texture->width, 1.0 / texture->height);
|
|
|
|
- state.canvas_shader.set_uniform(CanvasShaderGLES3::COLOR_TEXPIXEL_SIZE, texpixel_size);
|
|
|
|
- }
|
|
|
|
-
|
|
|
|
- state.canvas_shader.set_uniform(CanvasShaderGLES3::MODELVIEW_MATRIX, state.final_transform * mesh->transform);
|
|
|
|
-
|
|
|
|
- RasterizerStorageGLES3::Mesh *mesh_data = storage->mesh_owner.getornull(mesh->mesh);
|
|
|
|
- if (mesh_data) {
|
|
|
|
-
|
|
|
|
- for (int j = 0; j < mesh_data->surfaces.size(); j++) {
|
|
|
|
- RasterizerStorageGLES3::Surface *s = mesh_data->surfaces[j];
|
|
|
|
- // materials are ignored in 2D meshes, could be added but many things (ie, lighting mode, reading from screen, etc) would break as they are not meant be set up at this point of drawing
|
|
|
|
- glBindVertexArray(s->array_id);
|
|
|
|
-
|
|
|
|
- glVertexAttrib4f(VS::ARRAY_COLOR, mesh->modulate.r, mesh->modulate.g, mesh->modulate.b, mesh->modulate.a);
|
|
|
|
-
|
|
|
|
- if (s->index_array_len) {
|
|
|
|
- glDrawElements(gl_primitive[s->primitive], s->index_array_len, (s->array_len >= (1 << 16)) ? GL_UNSIGNED_INT : GL_UNSIGNED_SHORT, 0);
|
|
|
|
- } else {
|
|
|
|
- glDrawArrays(gl_primitive[s->primitive], 0, s->array_len);
|
|
|
|
- }
|
|
|
|
- storage->info.render._2d_draw_call_count++;
|
|
|
|
-
|
|
|
|
- glBindVertexArray(0);
|
|
|
|
- }
|
|
|
|
- }
|
|
|
|
- state.canvas_shader.set_uniform(CanvasShaderGLES3::MODELVIEW_MATRIX, state.final_transform);
|
|
|
|
-
|
|
|
|
- } break;
|
|
|
|
- case Item::Command::TYPE_MULTIMESH: {
|
|
|
|
-
|
|
|
|
- Item::CommandMultiMesh *mmesh = static_cast<Item::CommandMultiMesh *>(c);
|
|
|
|
-
|
|
|
|
- RasterizerStorageGLES3::MultiMesh *multi_mesh = storage->multimesh_owner.getornull(mmesh->multimesh);
|
|
|
|
-
|
|
|
|
- if (!multi_mesh)
|
|
|
|
- break;
|
|
|
|
-
|
|
|
|
- RasterizerStorageGLES3::Mesh *mesh_data = storage->mesh_owner.getornull(multi_mesh->mesh);
|
|
|
|
-
|
|
|
|
- if (!mesh_data)
|
|
|
|
- break;
|
|
|
|
-
|
|
|
|
- RasterizerStorageGLES3::Texture *texture = _bind_canvas_texture(mmesh->texture, mmesh->normal_map);
|
|
|
|
-
|
|
|
|
- state.canvas_shader.set_conditional(CanvasShaderGLES3::USE_INSTANCE_CUSTOM, multi_mesh->custom_data_format != VS::MULTIMESH_CUSTOM_DATA_NONE);
|
|
|
|
- state.canvas_shader.set_conditional(CanvasShaderGLES3::USE_INSTANCING, true);
|
|
|
|
- //reset shader and force rebind
|
|
|
|
- state.using_texture_rect = true;
|
|
|
|
- _set_texture_rect_mode(false);
|
|
|
|
-
|
|
|
|
- if (texture) {
|
|
|
|
- Size2 texpixel_size(1.0 / texture->width, 1.0 / texture->height);
|
|
|
|
- state.canvas_shader.set_uniform(CanvasShaderGLES3::COLOR_TEXPIXEL_SIZE, texpixel_size);
|
|
|
|
- }
|
|
|
|
|
|
+ } break;
|
|
|
|
+ case Item::Command::TYPE_MESH: {
|
|
|
|
|
|
- int amount = MIN(multi_mesh->size, multi_mesh->visible_instances);
|
|
|
|
|
|
+ Item::CommandMesh *mesh = static_cast<Item::CommandMesh *>(c);
|
|
|
|
+ _set_texture_rect_mode(false);
|
|
|
|
|
|
- if (amount == -1) {
|
|
|
|
- amount = multi_mesh->size;
|
|
|
|
- }
|
|
|
|
|
|
+ RasterizerStorageGLES3::Texture *texture = _bind_canvas_texture(mesh->texture, mesh->normal_map);
|
|
|
|
|
|
- for (int j = 0; j < mesh_data->surfaces.size(); j++) {
|
|
|
|
- RasterizerStorageGLES3::Surface *s = mesh_data->surfaces[j];
|
|
|
|
- // materials are ignored in 2D meshes, could be added but many things (ie, lighting mode, reading from screen, etc) would break as they are not meant be set up at this point of drawing
|
|
|
|
- glBindVertexArray(s->instancing_array_id);
|
|
|
|
|
|
+ if (texture) {
|
|
|
|
+ Size2 texpixel_size(1.0 / texture->width, 1.0 / texture->height);
|
|
|
|
+ state.canvas_shader.set_uniform(CanvasShaderGLES3::COLOR_TEXPIXEL_SIZE, texpixel_size);
|
|
|
|
+ }
|
|
|
|
|
|
- glBindBuffer(GL_ARRAY_BUFFER, multi_mesh->buffer); //modify the buffer
|
|
|
|
|
|
+ state.canvas_shader.set_uniform(CanvasShaderGLES3::MODELVIEW_MATRIX, state.final_transform * mesh->transform);
|
|
|
|
|
|
- int stride = (multi_mesh->xform_floats + multi_mesh->color_floats + multi_mesh->custom_data_floats) * 4;
|
|
|
|
- glEnableVertexAttribArray(8);
|
|
|
|
- glVertexAttribPointer(8, 4, GL_FLOAT, GL_FALSE, stride, CAST_INT_TO_UCHAR_PTR(0));
|
|
|
|
- glVertexAttribDivisor(8, 1);
|
|
|
|
- glEnableVertexAttribArray(9);
|
|
|
|
- glVertexAttribPointer(9, 4, GL_FLOAT, GL_FALSE, stride, CAST_INT_TO_UCHAR_PTR(4 * 4));
|
|
|
|
- glVertexAttribDivisor(9, 1);
|
|
|
|
|
|
+ RasterizerStorageGLES3::Mesh *mesh_data = storage->mesh_owner.getornull(mesh->mesh);
|
|
|
|
+ if (mesh_data) {
|
|
|
|
|
|
- int color_ofs;
|
|
|
|
|
|
+ for (int j = 0; j < mesh_data->surfaces.size(); j++) {
|
|
|
|
+ RasterizerStorageGLES3::Surface *s = mesh_data->surfaces[j];
|
|
|
|
+ // materials are ignored in 2D meshes, could be added but many things (ie, lighting mode, reading from screen, etc) would break as they are not meant be set up at this point of drawing
|
|
|
|
+ glBindVertexArray(s->array_id);
|
|
|
|
|
|
- if (multi_mesh->transform_format == VS::MULTIMESH_TRANSFORM_3D) {
|
|
|
|
- glEnableVertexAttribArray(10);
|
|
|
|
- glVertexAttribPointer(10, 4, GL_FLOAT, GL_FALSE, stride, CAST_INT_TO_UCHAR_PTR(8 * 4));
|
|
|
|
- glVertexAttribDivisor(10, 1);
|
|
|
|
- color_ofs = 12 * 4;
|
|
|
|
- } else {
|
|
|
|
- glDisableVertexAttribArray(10);
|
|
|
|
- glVertexAttrib4f(10, 0, 0, 1, 0);
|
|
|
|
- color_ofs = 8 * 4;
|
|
|
|
- }
|
|
|
|
|
|
+ glVertexAttrib4f(VS::ARRAY_COLOR, mesh->modulate.r, mesh->modulate.g, mesh->modulate.b, mesh->modulate.a);
|
|
|
|
|
|
- int custom_data_ofs = color_ofs;
|
|
|
|
|
|
+ if (s->index_array_len) {
|
|
|
|
+ glDrawElements(gl_primitive[s->primitive], s->index_array_len, (s->array_len >= (1 << 16)) ? GL_UNSIGNED_INT : GL_UNSIGNED_SHORT, 0);
|
|
|
|
+ } else {
|
|
|
|
+ glDrawArrays(gl_primitive[s->primitive], 0, s->array_len);
|
|
|
|
+ }
|
|
|
|
+ storage->info.render._2d_draw_call_count++;
|
|
|
|
|
|
- switch (multi_mesh->color_format) {
|
|
|
|
|
|
+ glBindVertexArray(0);
|
|
|
|
+ }
|
|
|
|
+ }
|
|
|
|
+ state.canvas_shader.set_uniform(CanvasShaderGLES3::MODELVIEW_MATRIX, state.final_transform);
|
|
|
|
|
|
- case VS::MULTIMESH_COLOR_MAX:
|
|
|
|
- case VS::MULTIMESH_COLOR_NONE: {
|
|
|
|
- glDisableVertexAttribArray(11);
|
|
|
|
- glVertexAttrib4f(11, 1, 1, 1, 1);
|
|
|
|
} break;
|
|
} break;
|
|
- case VS::MULTIMESH_COLOR_8BIT: {
|
|
|
|
- glEnableVertexAttribArray(11);
|
|
|
|
- glVertexAttribPointer(11, 4, GL_UNSIGNED_BYTE, GL_TRUE, stride, CAST_INT_TO_UCHAR_PTR(color_ofs));
|
|
|
|
- glVertexAttribDivisor(11, 1);
|
|
|
|
- custom_data_ofs += 4;
|
|
|
|
|
|
+ case Item::Command::TYPE_MULTIMESH: {
|
|
|
|
+
|
|
|
|
+ Item::CommandMultiMesh *mmesh = static_cast<Item::CommandMultiMesh *>(c);
|
|
|
|
+
|
|
|
|
+ RasterizerStorageGLES3::MultiMesh *multi_mesh = storage->multimesh_owner.getornull(mmesh->multimesh);
|
|
|
|
+
|
|
|
|
+ if (!multi_mesh)
|
|
|
|
+ break;
|
|
|
|
+
|
|
|
|
+ RasterizerStorageGLES3::Mesh *mesh_data = storage->mesh_owner.getornull(multi_mesh->mesh);
|
|
|
|
+
|
|
|
|
+ if (!mesh_data)
|
|
|
|
+ break;
|
|
|
|
+
|
|
|
|
+ RasterizerStorageGLES3::Texture *texture = _bind_canvas_texture(mmesh->texture, mmesh->normal_map);
|
|
|
|
+
|
|
|
|
+ state.canvas_shader.set_conditional(CanvasShaderGLES3::USE_INSTANCE_CUSTOM, multi_mesh->custom_data_format != VS::MULTIMESH_CUSTOM_DATA_NONE);
|
|
|
|
+ state.canvas_shader.set_conditional(CanvasShaderGLES3::USE_INSTANCING, true);
|
|
|
|
+ //reset shader and force rebind
|
|
|
|
+ state.using_texture_rect = true;
|
|
|
|
+ _set_texture_rect_mode(false);
|
|
|
|
+
|
|
|
|
+ if (texture) {
|
|
|
|
+ Size2 texpixel_size(1.0 / texture->width, 1.0 / texture->height);
|
|
|
|
+ state.canvas_shader.set_uniform(CanvasShaderGLES3::COLOR_TEXPIXEL_SIZE, texpixel_size);
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ int amount = MIN(multi_mesh->size, multi_mesh->visible_instances);
|
|
|
|
+
|
|
|
|
+ if (amount == -1) {
|
|
|
|
+ amount = multi_mesh->size;
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ for (int j = 0; j < mesh_data->surfaces.size(); j++) {
|
|
|
|
+ RasterizerStorageGLES3::Surface *s = mesh_data->surfaces[j];
|
|
|
|
+ // materials are ignored in 2D meshes, could be added but many things (ie, lighting mode, reading from screen, etc) would break as they are not meant be set up at this point of drawing
|
|
|
|
+ glBindVertexArray(s->instancing_array_id);
|
|
|
|
+
|
|
|
|
+ glBindBuffer(GL_ARRAY_BUFFER, multi_mesh->buffer); //modify the buffer
|
|
|
|
+
|
|
|
|
+ int stride = (multi_mesh->xform_floats + multi_mesh->color_floats + multi_mesh->custom_data_floats) * 4;
|
|
|
|
+ glEnableVertexAttribArray(8);
|
|
|
|
+ glVertexAttribPointer(8, 4, GL_FLOAT, GL_FALSE, stride, CAST_INT_TO_UCHAR_PTR(0));
|
|
|
|
+ glVertexAttribDivisor(8, 1);
|
|
|
|
+ glEnableVertexAttribArray(9);
|
|
|
|
+ glVertexAttribPointer(9, 4, GL_FLOAT, GL_FALSE, stride, CAST_INT_TO_UCHAR_PTR(4 * 4));
|
|
|
|
+ glVertexAttribDivisor(9, 1);
|
|
|
|
+
|
|
|
|
+ int color_ofs;
|
|
|
|
+
|
|
|
|
+ if (multi_mesh->transform_format == VS::MULTIMESH_TRANSFORM_3D) {
|
|
|
|
+ glEnableVertexAttribArray(10);
|
|
|
|
+ glVertexAttribPointer(10, 4, GL_FLOAT, GL_FALSE, stride, CAST_INT_TO_UCHAR_PTR(8 * 4));
|
|
|
|
+ glVertexAttribDivisor(10, 1);
|
|
|
|
+ color_ofs = 12 * 4;
|
|
|
|
+ } else {
|
|
|
|
+ glDisableVertexAttribArray(10);
|
|
|
|
+ glVertexAttrib4f(10, 0, 0, 1, 0);
|
|
|
|
+ color_ofs = 8 * 4;
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ int custom_data_ofs = color_ofs;
|
|
|
|
+
|
|
|
|
+ switch (multi_mesh->color_format) {
|
|
|
|
+
|
|
|
|
+ case VS::MULTIMESH_COLOR_MAX:
|
|
|
|
+ case VS::MULTIMESH_COLOR_NONE: {
|
|
|
|
+ glDisableVertexAttribArray(11);
|
|
|
|
+ glVertexAttrib4f(11, 1, 1, 1, 1);
|
|
|
|
+ } break;
|
|
|
|
+ case VS::MULTIMESH_COLOR_8BIT: {
|
|
|
|
+ glEnableVertexAttribArray(11);
|
|
|
|
+ glVertexAttribPointer(11, 4, GL_UNSIGNED_BYTE, GL_TRUE, stride, CAST_INT_TO_UCHAR_PTR(color_ofs));
|
|
|
|
+ glVertexAttribDivisor(11, 1);
|
|
|
|
+ custom_data_ofs += 4;
|
|
|
|
+
|
|
|
|
+ } break;
|
|
|
|
+ case VS::MULTIMESH_COLOR_FLOAT: {
|
|
|
|
+ glEnableVertexAttribArray(11);
|
|
|
|
+ glVertexAttribPointer(11, 4, GL_FLOAT, GL_FALSE, stride, CAST_INT_TO_UCHAR_PTR(color_ofs));
|
|
|
|
+ glVertexAttribDivisor(11, 1);
|
|
|
|
+ custom_data_ofs += 4 * 4;
|
|
|
|
+ } break;
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ switch (multi_mesh->custom_data_format) {
|
|
|
|
+
|
|
|
|
+ case VS::MULTIMESH_CUSTOM_DATA_MAX:
|
|
|
|
+ case VS::MULTIMESH_CUSTOM_DATA_NONE: {
|
|
|
|
+ glDisableVertexAttribArray(12);
|
|
|
|
+ glVertexAttrib4f(12, 1, 1, 1, 1);
|
|
|
|
+ } break;
|
|
|
|
+ case VS::MULTIMESH_CUSTOM_DATA_8BIT: {
|
|
|
|
+ glEnableVertexAttribArray(12);
|
|
|
|
+ glVertexAttribPointer(12, 4, GL_UNSIGNED_BYTE, GL_TRUE, stride, CAST_INT_TO_UCHAR_PTR(custom_data_ofs));
|
|
|
|
+ glVertexAttribDivisor(12, 1);
|
|
|
|
+
|
|
|
|
+ } break;
|
|
|
|
+ case VS::MULTIMESH_CUSTOM_DATA_FLOAT: {
|
|
|
|
+ glEnableVertexAttribArray(12);
|
|
|
|
+ glVertexAttribPointer(12, 4, GL_FLOAT, GL_FALSE, stride, CAST_INT_TO_UCHAR_PTR(custom_data_ofs));
|
|
|
|
+ glVertexAttribDivisor(12, 1);
|
|
|
|
+ } break;
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ if (s->index_array_len) {
|
|
|
|
+ glDrawElementsInstanced(gl_primitive[s->primitive], s->index_array_len, (s->array_len >= (1 << 16)) ? GL_UNSIGNED_INT : GL_UNSIGNED_SHORT, 0, amount);
|
|
|
|
+ } else {
|
|
|
|
+ glDrawArraysInstanced(gl_primitive[s->primitive], 0, s->array_len, amount);
|
|
|
|
+ }
|
|
|
|
+ storage->info.render._2d_draw_call_count++;
|
|
|
|
+
|
|
|
|
+ glBindVertexArray(0);
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ state.canvas_shader.set_conditional(CanvasShaderGLES3::USE_INSTANCE_CUSTOM, false);
|
|
|
|
+ state.canvas_shader.set_conditional(CanvasShaderGLES3::USE_INSTANCING, false);
|
|
|
|
+ state.using_texture_rect = true;
|
|
|
|
+ _set_texture_rect_mode(false);
|
|
|
|
|
|
} break;
|
|
} break;
|
|
- case VS::MULTIMESH_COLOR_FLOAT: {
|
|
|
|
- glEnableVertexAttribArray(11);
|
|
|
|
- glVertexAttribPointer(11, 4, GL_FLOAT, GL_FALSE, stride, CAST_INT_TO_UCHAR_PTR(color_ofs));
|
|
|
|
- glVertexAttribDivisor(11, 1);
|
|
|
|
- custom_data_ofs += 4 * 4;
|
|
|
|
- } break;
|
|
|
|
- }
|
|
|
|
|
|
+ case Item::Command::TYPE_PARTICLES: {
|
|
|
|
+
|
|
|
|
+ Item::CommandParticles *particles_cmd = static_cast<Item::CommandParticles *>(c);
|
|
|
|
+
|
|
|
|
+ RasterizerStorageGLES3::Particles *particles = storage->particles_owner.getornull(particles_cmd->particles);
|
|
|
|
+ if (!particles)
|
|
|
|
+ break;
|
|
|
|
+
|
|
|
|
+ if (particles->inactive && !particles->emitting)
|
|
|
|
+ break;
|
|
|
|
+
|
|
|
|
+ glVertexAttrib4f(VS::ARRAY_COLOR, 1, 1, 1, 1); //not used, so keep white
|
|
|
|
+
|
|
|
|
+ VisualServerRaster::redraw_request();
|
|
|
|
+
|
|
|
|
+ storage->particles_request_process(particles_cmd->particles);
|
|
|
|
+ //enable instancing
|
|
|
|
+
|
|
|
|
+ state.canvas_shader.set_conditional(CanvasShaderGLES3::USE_INSTANCE_CUSTOM, true);
|
|
|
|
+ state.canvas_shader.set_conditional(CanvasShaderGLES3::USE_PARTICLES, true);
|
|
|
|
+ state.canvas_shader.set_conditional(CanvasShaderGLES3::USE_INSTANCING, true);
|
|
|
|
+ //reset shader and force rebind
|
|
|
|
+ state.using_texture_rect = true;
|
|
|
|
+ _set_texture_rect_mode(false);
|
|
|
|
+
|
|
|
|
+ RasterizerStorageGLES3::Texture *texture = _bind_canvas_texture(particles_cmd->texture, particles_cmd->normal_map);
|
|
|
|
+
|
|
|
|
+ if (texture) {
|
|
|
|
+ Size2 texpixel_size(1.0 / texture->width, 1.0 / texture->height);
|
|
|
|
+ state.canvas_shader.set_uniform(CanvasShaderGLES3::COLOR_TEXPIXEL_SIZE, texpixel_size);
|
|
|
|
+ } else {
|
|
|
|
+ state.canvas_shader.set_uniform(CanvasShaderGLES3::COLOR_TEXPIXEL_SIZE, Vector2(1.0, 1.0));
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ if (!particles->use_local_coords) {
|
|
|
|
+
|
|
|
|
+ Transform2D inv_xf;
|
|
|
|
+ inv_xf.set_axis(0, Vector2(particles->emission_transform.basis.get_axis(0).x, particles->emission_transform.basis.get_axis(0).y));
|
|
|
|
+ inv_xf.set_axis(1, Vector2(particles->emission_transform.basis.get_axis(1).x, particles->emission_transform.basis.get_axis(1).y));
|
|
|
|
+ inv_xf.set_origin(Vector2(particles->emission_transform.get_origin().x, particles->emission_transform.get_origin().y));
|
|
|
|
+ inv_xf.affine_invert();
|
|
|
|
+
|
|
|
|
+ state.canvas_shader.set_uniform(CanvasShaderGLES3::MODELVIEW_MATRIX, state.final_transform * inv_xf);
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ glBindVertexArray(data.particle_quad_array); //use particle quad array
|
|
|
|
+ glBindBuffer(GL_ARRAY_BUFFER, particles->particle_buffers[0]); //bind particle buffer
|
|
|
|
+
|
|
|
|
+ int stride = sizeof(float) * 4 * 6;
|
|
|
|
+
|
|
|
|
+ int amount = particles->amount;
|
|
|
|
+
|
|
|
|
+ if (particles->draw_order != VS::PARTICLES_DRAW_ORDER_LIFETIME) {
|
|
|
|
+
|
|
|
|
+ glEnableVertexAttribArray(8); //xform x
|
|
|
|
+ glVertexAttribPointer(8, 4, GL_FLOAT, GL_FALSE, stride, CAST_INT_TO_UCHAR_PTR(sizeof(float) * 4 * 3));
|
|
|
|
+ glVertexAttribDivisor(8, 1);
|
|
|
|
+ glEnableVertexAttribArray(9); //xform y
|
|
|
|
+ glVertexAttribPointer(9, 4, GL_FLOAT, GL_FALSE, stride, CAST_INT_TO_UCHAR_PTR(sizeof(float) * 4 * 4));
|
|
|
|
+ glVertexAttribDivisor(9, 1);
|
|
|
|
+ glEnableVertexAttribArray(10); //xform z
|
|
|
|
+ glVertexAttribPointer(10, 4, GL_FLOAT, GL_FALSE, stride, CAST_INT_TO_UCHAR_PTR(sizeof(float) * 4 * 5));
|
|
|
|
+ glVertexAttribDivisor(10, 1);
|
|
|
|
+ glEnableVertexAttribArray(11); //color
|
|
|
|
+ glVertexAttribPointer(11, 4, GL_FLOAT, GL_FALSE, stride, NULL);
|
|
|
|
+ glVertexAttribDivisor(11, 1);
|
|
|
|
+ glEnableVertexAttribArray(12); //custom
|
|
|
|
+ glVertexAttribPointer(12, 4, GL_FLOAT, GL_FALSE, stride, CAST_INT_TO_UCHAR_PTR(sizeof(float) * 4 * 2));
|
|
|
|
+ glVertexAttribDivisor(12, 1);
|
|
|
|
+
|
|
|
|
+ glDrawArraysInstanced(GL_TRIANGLE_FAN, 0, 4, amount);
|
|
|
|
+ storage->info.render._2d_draw_call_count++;
|
|
|
|
+ } else {
|
|
|
|
+ //split
|
|
|
|
+ int split = int(Math::ceil(particles->phase * particles->amount));
|
|
|
|
+
|
|
|
|
+ if (amount - split > 0) {
|
|
|
|
+ glEnableVertexAttribArray(8); //xform x
|
|
|
|
+ glVertexAttribPointer(8, 4, GL_FLOAT, GL_FALSE, stride, CAST_INT_TO_UCHAR_PTR(stride * split + sizeof(float) * 4 * 3));
|
|
|
|
+ glVertexAttribDivisor(8, 1);
|
|
|
|
+ glEnableVertexAttribArray(9); //xform y
|
|
|
|
+ glVertexAttribPointer(9, 4, GL_FLOAT, GL_FALSE, stride, CAST_INT_TO_UCHAR_PTR(stride * split + sizeof(float) * 4 * 4));
|
|
|
|
+ glVertexAttribDivisor(9, 1);
|
|
|
|
+ glEnableVertexAttribArray(10); //xform z
|
|
|
|
+ glVertexAttribPointer(10, 4, GL_FLOAT, GL_FALSE, stride, CAST_INT_TO_UCHAR_PTR(stride * split + sizeof(float) * 4 * 5));
|
|
|
|
+ glVertexAttribDivisor(10, 1);
|
|
|
|
+ glEnableVertexAttribArray(11); //color
|
|
|
|
+ glVertexAttribPointer(11, 4, GL_FLOAT, GL_FALSE, stride, CAST_INT_TO_UCHAR_PTR(stride * split + 0));
|
|
|
|
+ glVertexAttribDivisor(11, 1);
|
|
|
|
+ glEnableVertexAttribArray(12); //custom
|
|
|
|
+ glVertexAttribPointer(12, 4, GL_FLOAT, GL_FALSE, stride, CAST_INT_TO_UCHAR_PTR(stride * split + sizeof(float) * 4 * 2));
|
|
|
|
+ glVertexAttribDivisor(12, 1);
|
|
|
|
+
|
|
|
|
+ glDrawArraysInstanced(GL_TRIANGLE_FAN, 0, 4, amount - split);
|
|
|
|
+ storage->info.render._2d_draw_call_count++;
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ if (split > 0) {
|
|
|
|
+ glEnableVertexAttribArray(8); //xform x
|
|
|
|
+ glVertexAttribPointer(8, 4, GL_FLOAT, GL_FALSE, stride, CAST_INT_TO_UCHAR_PTR(sizeof(float) * 4 * 3));
|
|
|
|
+ glVertexAttribDivisor(8, 1);
|
|
|
|
+ glEnableVertexAttribArray(9); //xform y
|
|
|
|
+ glVertexAttribPointer(9, 4, GL_FLOAT, GL_FALSE, stride, CAST_INT_TO_UCHAR_PTR(sizeof(float) * 4 * 4));
|
|
|
|
+ glVertexAttribDivisor(9, 1);
|
|
|
|
+ glEnableVertexAttribArray(10); //xform z
|
|
|
|
+ glVertexAttribPointer(10, 4, GL_FLOAT, GL_FALSE, stride, CAST_INT_TO_UCHAR_PTR(sizeof(float) * 4 * 5));
|
|
|
|
+ glVertexAttribDivisor(10, 1);
|
|
|
|
+ glEnableVertexAttribArray(11); //color
|
|
|
|
+ glVertexAttribPointer(11, 4, GL_FLOAT, GL_FALSE, stride, NULL);
|
|
|
|
+ glVertexAttribDivisor(11, 1);
|
|
|
|
+ glEnableVertexAttribArray(12); //custom
|
|
|
|
+ glVertexAttribPointer(12, 4, GL_FLOAT, GL_FALSE, stride, CAST_INT_TO_UCHAR_PTR(sizeof(float) * 4 * 2));
|
|
|
|
+ glVertexAttribDivisor(12, 1);
|
|
|
|
+
|
|
|
|
+ glDrawArraysInstanced(GL_TRIANGLE_FAN, 0, 4, split);
|
|
|
|
+ storage->info.render._2d_draw_call_count++;
|
|
|
|
+ }
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ glBindVertexArray(0);
|
|
|
|
+
|
|
|
|
+ state.canvas_shader.set_conditional(CanvasShaderGLES3::USE_INSTANCE_CUSTOM, false);
|
|
|
|
+ state.canvas_shader.set_conditional(CanvasShaderGLES3::USE_PARTICLES, false);
|
|
|
|
+ state.canvas_shader.set_conditional(CanvasShaderGLES3::USE_INSTANCING, false);
|
|
|
|
+ state.using_texture_rect = true;
|
|
|
|
+ _set_texture_rect_mode(false);
|
|
|
|
|
|
- switch (multi_mesh->custom_data_format) {
|
|
|
|
-
|
|
|
|
- case VS::MULTIMESH_CUSTOM_DATA_MAX:
|
|
|
|
- case VS::MULTIMESH_CUSTOM_DATA_NONE: {
|
|
|
|
- glDisableVertexAttribArray(12);
|
|
|
|
- glVertexAttrib4f(12, 1, 1, 1, 1);
|
|
|
|
} break;
|
|
} break;
|
|
- case VS::MULTIMESH_CUSTOM_DATA_8BIT: {
|
|
|
|
- glEnableVertexAttribArray(12);
|
|
|
|
- glVertexAttribPointer(12, 4, GL_UNSIGNED_BYTE, GL_TRUE, stride, CAST_INT_TO_UCHAR_PTR(custom_data_ofs));
|
|
|
|
- glVertexAttribDivisor(12, 1);
|
|
|
|
|
|
+ case Item::Command::TYPE_CIRCLE: {
|
|
|
|
|
|
- } break;
|
|
|
|
- case VS::MULTIMESH_CUSTOM_DATA_FLOAT: {
|
|
|
|
- glEnableVertexAttribArray(12);
|
|
|
|
- glVertexAttribPointer(12, 4, GL_FLOAT, GL_FALSE, stride, CAST_INT_TO_UCHAR_PTR(custom_data_ofs));
|
|
|
|
- glVertexAttribDivisor(12, 1);
|
|
|
|
- } break;
|
|
|
|
- }
|
|
|
|
|
|
+ _set_texture_rect_mode(false);
|
|
|
|
|
|
- if (s->index_array_len) {
|
|
|
|
- glDrawElementsInstanced(gl_primitive[s->primitive], s->index_array_len, (s->array_len >= (1 << 16)) ? GL_UNSIGNED_INT : GL_UNSIGNED_SHORT, 0, amount);
|
|
|
|
- } else {
|
|
|
|
- glDrawArraysInstanced(gl_primitive[s->primitive], 0, s->array_len, amount);
|
|
|
|
- }
|
|
|
|
- storage->info.render._2d_draw_call_count++;
|
|
|
|
-
|
|
|
|
- glBindVertexArray(0);
|
|
|
|
- }
|
|
|
|
|
|
+ Item::CommandCircle *circle = static_cast<Item::CommandCircle *>(c);
|
|
|
|
+ static const int numpoints = 32;
|
|
|
|
+ Vector2 points[numpoints + 1];
|
|
|
|
+ points[numpoints] = circle->pos;
|
|
|
|
+ int indices[numpoints * 3];
|
|
|
|
|
|
- state.canvas_shader.set_conditional(CanvasShaderGLES3::USE_INSTANCE_CUSTOM, false);
|
|
|
|
- state.canvas_shader.set_conditional(CanvasShaderGLES3::USE_INSTANCING, false);
|
|
|
|
- state.using_texture_rect = true;
|
|
|
|
- _set_texture_rect_mode(false);
|
|
|
|
|
|
+ for (int j = 0; j < numpoints; j++) {
|
|
|
|
|
|
- } break;
|
|
|
|
- case Item::Command::TYPE_PARTICLES: {
|
|
|
|
|
|
+ points[j] = circle->pos + Vector2(Math::sin(j * Math_PI * 2.0 / numpoints), Math::cos(j * Math_PI * 2.0 / numpoints)) * circle->radius;
|
|
|
|
+ indices[j * 3 + 0] = j;
|
|
|
|
+ indices[j * 3 + 1] = (j + 1) % numpoints;
|
|
|
|
+ indices[j * 3 + 2] = numpoints;
|
|
|
|
+ }
|
|
|
|
|
|
- Item::CommandParticles *particles_cmd = static_cast<Item::CommandParticles *>(c);
|
|
|
|
|
|
+ _bind_canvas_texture(RID(), RID());
|
|
|
|
+ _draw_polygon(indices, numpoints * 3, numpoints + 1, points, NULL, &circle->color, true, NULL, NULL);
|
|
|
|
|
|
- RasterizerStorageGLES3::Particles *particles = storage->particles_owner.getornull(particles_cmd->particles);
|
|
|
|
- if (!particles)
|
|
|
|
- break;
|
|
|
|
-
|
|
|
|
- if (particles->inactive && !particles->emitting)
|
|
|
|
- break;
|
|
|
|
-
|
|
|
|
- glVertexAttrib4f(VS::ARRAY_COLOR, 1, 1, 1, 1); //not used, so keep white
|
|
|
|
|
|
+ //_draw_polygon(numpoints*3,indices,points,NULL,&circle->color,RID(),true);
|
|
|
|
+ //canvas_draw_circle(circle->indices.size(),circle->indices.ptr(),circle->points.ptr(),circle->uvs.ptr(),circle->colors.ptr(),circle->texture,circle->colors.size()==1);
|
|
|
|
+ } break;
|
|
|
|
+ case Item::Command::TYPE_TRANSFORM: {
|
|
|
|
|
|
- VisualServerRaster::redraw_request();
|
|
|
|
|
|
+ Item::CommandTransform *transform = static_cast<Item::CommandTransform *>(c);
|
|
|
|
+ state.extra_matrix = transform->xform;
|
|
|
|
+ state.canvas_shader.set_uniform(CanvasShaderGLES3::EXTRA_MATRIX, state.extra_matrix);
|
|
|
|
|
|
- storage->particles_request_process(particles_cmd->particles);
|
|
|
|
- //enable instancing
|
|
|
|
|
|
+ } break;
|
|
|
|
+ case Item::Command::TYPE_CLIP_IGNORE: {
|
|
|
|
|
|
- state.canvas_shader.set_conditional(CanvasShaderGLES3::USE_INSTANCE_CUSTOM, true);
|
|
|
|
- state.canvas_shader.set_conditional(CanvasShaderGLES3::USE_PARTICLES, true);
|
|
|
|
- state.canvas_shader.set_conditional(CanvasShaderGLES3::USE_INSTANCING, true);
|
|
|
|
- //reset shader and force rebind
|
|
|
|
- state.using_texture_rect = true;
|
|
|
|
- _set_texture_rect_mode(false);
|
|
|
|
|
|
+ Item::CommandClipIgnore *ci = static_cast<Item::CommandClipIgnore *>(c);
|
|
|
|
+ if (p_current_clip) {
|
|
|
|
|
|
- RasterizerStorageGLES3::Texture *texture = _bind_canvas_texture(particles_cmd->texture, particles_cmd->normal_map);
|
|
|
|
|
|
+ if (ci->ignore != r_reclip) {
|
|
|
|
+ if (ci->ignore) {
|
|
|
|
|
|
- if (texture) {
|
|
|
|
- Size2 texpixel_size(1.0 / texture->width, 1.0 / texture->height);
|
|
|
|
- state.canvas_shader.set_uniform(CanvasShaderGLES3::COLOR_TEXPIXEL_SIZE, texpixel_size);
|
|
|
|
- } else {
|
|
|
|
- state.canvas_shader.set_uniform(CanvasShaderGLES3::COLOR_TEXPIXEL_SIZE, Vector2(1.0, 1.0));
|
|
|
|
- }
|
|
|
|
|
|
+ glDisable(GL_SCISSOR_TEST);
|
|
|
|
+ r_reclip = true;
|
|
|
|
+ } else {
|
|
|
|
|
|
- if (!particles->use_local_coords) {
|
|
|
|
|
|
+ glEnable(GL_SCISSOR_TEST);
|
|
|
|
+ //glScissor(viewport.x+current_clip->final_clip_rect.pos.x,viewport.y+ (viewport.height-(current_clip->final_clip_rect.pos.y+current_clip->final_clip_rect.size.height)),
|
|
|
|
+ //current_clip->final_clip_rect.size.width,current_clip->final_clip_rect.size.height);
|
|
|
|
+ int y = storage->frame.current_rt->height - (p_current_clip->final_clip_rect.position.y + p_current_clip->final_clip_rect.size.y);
|
|
|
|
+ if (storage->frame.current_rt->flags[RasterizerStorage::RENDER_TARGET_VFLIP])
|
|
|
|
+ y = p_current_clip->final_clip_rect.position.y;
|
|
|
|
|
|
- Transform2D inv_xf;
|
|
|
|
- inv_xf.set_axis(0, Vector2(particles->emission_transform.basis.get_axis(0).x, particles->emission_transform.basis.get_axis(0).y));
|
|
|
|
- inv_xf.set_axis(1, Vector2(particles->emission_transform.basis.get_axis(1).x, particles->emission_transform.basis.get_axis(1).y));
|
|
|
|
- inv_xf.set_origin(Vector2(particles->emission_transform.get_origin().x, particles->emission_transform.get_origin().y));
|
|
|
|
- inv_xf.affine_invert();
|
|
|
|
|
|
+ glScissor(p_current_clip->final_clip_rect.position.x, y, p_current_clip->final_clip_rect.size.x, p_current_clip->final_clip_rect.size.y);
|
|
|
|
|
|
- state.canvas_shader.set_uniform(CanvasShaderGLES3::MODELVIEW_MATRIX, state.final_transform * inv_xf);
|
|
|
|
- }
|
|
|
|
|
|
+ r_reclip = false;
|
|
|
|
+ }
|
|
|
|
+ }
|
|
|
|
+ }
|
|
|
|
|
|
- glBindVertexArray(data.particle_quad_array); //use particle quad array
|
|
|
|
- glBindBuffer(GL_ARRAY_BUFFER, particles->particle_buffers[0]); //bind particle buffer
|
|
|
|
-
|
|
|
|
- int stride = sizeof(float) * 4 * 6;
|
|
|
|
-
|
|
|
|
- int amount = particles->amount;
|
|
|
|
-
|
|
|
|
- if (particles->draw_order != VS::PARTICLES_DRAW_ORDER_LIFETIME) {
|
|
|
|
-
|
|
|
|
- glEnableVertexAttribArray(8); //xform x
|
|
|
|
- glVertexAttribPointer(8, 4, GL_FLOAT, GL_FALSE, stride, CAST_INT_TO_UCHAR_PTR(sizeof(float) * 4 * 3));
|
|
|
|
- glVertexAttribDivisor(8, 1);
|
|
|
|
- glEnableVertexAttribArray(9); //xform y
|
|
|
|
- glVertexAttribPointer(9, 4, GL_FLOAT, GL_FALSE, stride, CAST_INT_TO_UCHAR_PTR(sizeof(float) * 4 * 4));
|
|
|
|
- glVertexAttribDivisor(9, 1);
|
|
|
|
- glEnableVertexAttribArray(10); //xform z
|
|
|
|
- glVertexAttribPointer(10, 4, GL_FLOAT, GL_FALSE, stride, CAST_INT_TO_UCHAR_PTR(sizeof(float) * 4 * 5));
|
|
|
|
- glVertexAttribDivisor(10, 1);
|
|
|
|
- glEnableVertexAttribArray(11); //color
|
|
|
|
- glVertexAttribPointer(11, 4, GL_FLOAT, GL_FALSE, stride, NULL);
|
|
|
|
- glVertexAttribDivisor(11, 1);
|
|
|
|
- glEnableVertexAttribArray(12); //custom
|
|
|
|
- glVertexAttribPointer(12, 4, GL_FLOAT, GL_FALSE, stride, CAST_INT_TO_UCHAR_PTR(sizeof(float) * 4 * 2));
|
|
|
|
- glVertexAttribDivisor(12, 1);
|
|
|
|
-
|
|
|
|
- glDrawArraysInstanced(GL_TRIANGLE_FAN, 0, 4, amount);
|
|
|
|
- storage->info.render._2d_draw_call_count++;
|
|
|
|
- } else {
|
|
|
|
- //split
|
|
|
|
- int split = int(Math::ceil(particles->phase * particles->amount));
|
|
|
|
-
|
|
|
|
- if (amount - split > 0) {
|
|
|
|
- glEnableVertexAttribArray(8); //xform x
|
|
|
|
- glVertexAttribPointer(8, 4, GL_FLOAT, GL_FALSE, stride, CAST_INT_TO_UCHAR_PTR(stride * split + sizeof(float) * 4 * 3));
|
|
|
|
- glVertexAttribDivisor(8, 1);
|
|
|
|
- glEnableVertexAttribArray(9); //xform y
|
|
|
|
- glVertexAttribPointer(9, 4, GL_FLOAT, GL_FALSE, stride, CAST_INT_TO_UCHAR_PTR(stride * split + sizeof(float) * 4 * 4));
|
|
|
|
- glVertexAttribDivisor(9, 1);
|
|
|
|
- glEnableVertexAttribArray(10); //xform z
|
|
|
|
- glVertexAttribPointer(10, 4, GL_FLOAT, GL_FALSE, stride, CAST_INT_TO_UCHAR_PTR(stride * split + sizeof(float) * 4 * 5));
|
|
|
|
- glVertexAttribDivisor(10, 1);
|
|
|
|
- glEnableVertexAttribArray(11); //color
|
|
|
|
- glVertexAttribPointer(11, 4, GL_FLOAT, GL_FALSE, stride, CAST_INT_TO_UCHAR_PTR(stride * split + 0));
|
|
|
|
- glVertexAttribDivisor(11, 1);
|
|
|
|
- glEnableVertexAttribArray(12); //custom
|
|
|
|
- glVertexAttribPointer(12, 4, GL_FLOAT, GL_FALSE, stride, CAST_INT_TO_UCHAR_PTR(stride * split + sizeof(float) * 4 * 2));
|
|
|
|
- glVertexAttribDivisor(12, 1);
|
|
|
|
-
|
|
|
|
- glDrawArraysInstanced(GL_TRIANGLE_FAN, 0, 4, amount - split);
|
|
|
|
- storage->info.render._2d_draw_call_count++;
|
|
|
|
- }
|
|
|
|
|
|
+ } break;
|
|
|
|
|
|
- if (split > 0) {
|
|
|
|
- glEnableVertexAttribArray(8); //xform x
|
|
|
|
- glVertexAttribPointer(8, 4, GL_FLOAT, GL_FALSE, stride, CAST_INT_TO_UCHAR_PTR(sizeof(float) * 4 * 3));
|
|
|
|
- glVertexAttribDivisor(8, 1);
|
|
|
|
- glEnableVertexAttribArray(9); //xform y
|
|
|
|
- glVertexAttribPointer(9, 4, GL_FLOAT, GL_FALSE, stride, CAST_INT_TO_UCHAR_PTR(sizeof(float) * 4 * 4));
|
|
|
|
- glVertexAttribDivisor(9, 1);
|
|
|
|
- glEnableVertexAttribArray(10); //xform z
|
|
|
|
- glVertexAttribPointer(10, 4, GL_FLOAT, GL_FALSE, stride, CAST_INT_TO_UCHAR_PTR(sizeof(float) * 4 * 5));
|
|
|
|
- glVertexAttribDivisor(10, 1);
|
|
|
|
- glEnableVertexAttribArray(11); //color
|
|
|
|
- glVertexAttribPointer(11, 4, GL_FLOAT, GL_FALSE, stride, NULL);
|
|
|
|
- glVertexAttribDivisor(11, 1);
|
|
|
|
- glEnableVertexAttribArray(12); //custom
|
|
|
|
- glVertexAttribPointer(12, 4, GL_FLOAT, GL_FALSE, stride, CAST_INT_TO_UCHAR_PTR(sizeof(float) * 4 * 2));
|
|
|
|
- glVertexAttribDivisor(12, 1);
|
|
|
|
-
|
|
|
|
- glDrawArraysInstanced(GL_TRIANGLE_FAN, 0, 4, split);
|
|
|
|
- storage->info.render._2d_draw_call_count++;
|
|
|
|
|
|
+ default: {
|
|
|
|
+ // FIXME: Proper error handling if relevant
|
|
|
|
+ //print_line("other");
|
|
|
|
+ } break;
|
|
}
|
|
}
|
|
}
|
|
}
|
|
|
|
|
|
- glBindVertexArray(0);
|
|
|
|
-
|
|
|
|
- state.canvas_shader.set_conditional(CanvasShaderGLES3::USE_INSTANCE_CUSTOM, false);
|
|
|
|
- state.canvas_shader.set_conditional(CanvasShaderGLES3::USE_PARTICLES, false);
|
|
|
|
- state.canvas_shader.set_conditional(CanvasShaderGLES3::USE_INSTANCING, false);
|
|
|
|
- state.using_texture_rect = true;
|
|
|
|
- _set_texture_rect_mode(false);
|
|
|
|
|
|
+ } // default
|
|
|
|
+ break;
|
|
|
|
+ }
|
|
|
|
+ }
|
|
|
|
+}
|
|
|
|
|
|
- } break;
|
|
|
|
- case Item::Command::TYPE_CIRCLE: {
|
|
|
|
|
|
+void RasterizerCanvasGLES3::render_joined_item(const BItemJoined &p_bij, RenderItemState &r_ris) {
|
|
|
|
+ storage->info.render._2d_item_count++;
|
|
|
|
|
|
- _set_texture_rect_mode(false);
|
|
|
|
|
|
+#ifdef DEBUG_ENABLED
|
|
|
|
+ if (bdata.diagnose_frame) {
|
|
|
|
+ bdata.frame_string += "\tjoined_item " + itos(p_bij.num_item_refs) + " refs\n";
|
|
|
|
+ if (p_bij.z_index != 0) {
|
|
|
|
+ bdata.frame_string += "\t\t(z " + itos(p_bij.z_index) + ")\n";
|
|
|
|
+ }
|
|
|
|
+ }
|
|
|
|
+#endif
|
|
|
|
|
|
- Item::CommandCircle *circle = static_cast<Item::CommandCircle *>(c);
|
|
|
|
- static const int numpoints = 32;
|
|
|
|
- Vector2 points[numpoints + 1];
|
|
|
|
- points[numpoints] = circle->pos;
|
|
|
|
- int indices[numpoints * 3];
|
|
|
|
|
|
+ // this must be reset for each joined item,
|
|
|
|
+ // it only exists to prevent capturing the screen more than once per item
|
|
|
|
+ state.canvas_texscreen_used = false;
|
|
|
|
|
|
- for (int j = 0; j < numpoints; j++) {
|
|
|
|
|
|
+ // all the joined items will share the same state with the first item
|
|
|
|
+ Item *p_ci = bdata.item_refs[p_bij.first_item_ref].item;
|
|
|
|
|
|
- points[j] = circle->pos + Vector2(Math::sin(j * Math_PI * 2.0 / numpoints), Math::cos(j * Math_PI * 2.0 / numpoints)) * circle->radius;
|
|
|
|
- indices[j * 3 + 0] = j;
|
|
|
|
- indices[j * 3 + 1] = (j + 1) % numpoints;
|
|
|
|
- indices[j * 3 + 2] = numpoints;
|
|
|
|
- }
|
|
|
|
|
|
+ if (r_ris.prev_distance_field != p_ci->distance_field) {
|
|
|
|
|
|
- _bind_canvas_texture(RID(), RID());
|
|
|
|
- _draw_polygon(indices, numpoints * 3, numpoints + 1, points, NULL, &circle->color, true, NULL, NULL);
|
|
|
|
|
|
+ state.canvas_shader.set_conditional(CanvasShaderGLES3::USE_DISTANCE_FIELD, p_ci->distance_field);
|
|
|
|
+ r_ris.prev_distance_field = p_ci->distance_field;
|
|
|
|
+ r_ris.rebind_shader = true;
|
|
|
|
+ }
|
|
|
|
|
|
- //_draw_polygon(numpoints*3,indices,points,NULL,&circle->color,RID(),true);
|
|
|
|
- //canvas_draw_circle(circle->indices.size(),circle->indices.ptr(),circle->points.ptr(),circle->uvs.ptr(),circle->colors.ptr(),circle->texture,circle->colors.size()==1);
|
|
|
|
- } break;
|
|
|
|
- case Item::Command::TYPE_TRANSFORM: {
|
|
|
|
|
|
+ if (r_ris.current_clip != p_ci->final_clip_owner) {
|
|
|
|
|
|
- Item::CommandTransform *transform = static_cast<Item::CommandTransform *>(c);
|
|
|
|
- state.extra_matrix = transform->xform;
|
|
|
|
- state.canvas_shader.set_uniform(CanvasShaderGLES3::EXTRA_MATRIX, state.extra_matrix);
|
|
|
|
|
|
+ r_ris.current_clip = p_ci->final_clip_owner;
|
|
|
|
|
|
- } break;
|
|
|
|
- case Item::Command::TYPE_CLIP_IGNORE: {
|
|
|
|
|
|
+ //setup clip
|
|
|
|
+ if (r_ris.current_clip) {
|
|
|
|
|
|
- Item::CommandClipIgnore *ci = static_cast<Item::CommandClipIgnore *>(c);
|
|
|
|
- if (current_clip) {
|
|
|
|
|
|
+ glEnable(GL_SCISSOR_TEST);
|
|
|
|
+ int y = storage->frame.current_rt->height - (r_ris.current_clip->final_clip_rect.position.y + r_ris.current_clip->final_clip_rect.size.y);
|
|
|
|
+ if (storage->frame.current_rt->flags[RasterizerStorage::RENDER_TARGET_VFLIP])
|
|
|
|
+ y = r_ris.current_clip->final_clip_rect.position.y;
|
|
|
|
|
|
- if (ci->ignore != reclip) {
|
|
|
|
- if (ci->ignore) {
|
|
|
|
|
|
+ glScissor(r_ris.current_clip->final_clip_rect.position.x, y, r_ris.current_clip->final_clip_rect.size.x, r_ris.current_clip->final_clip_rect.size.y);
|
|
|
|
|
|
- glDisable(GL_SCISSOR_TEST);
|
|
|
|
- reclip = true;
|
|
|
|
- } else {
|
|
|
|
|
|
+ } else {
|
|
|
|
|
|
- glEnable(GL_SCISSOR_TEST);
|
|
|
|
- //glScissor(viewport.x+current_clip->final_clip_rect.pos.x,viewport.y+ (viewport.height-(current_clip->final_clip_rect.pos.y+current_clip->final_clip_rect.size.height)),
|
|
|
|
- //current_clip->final_clip_rect.size.width,current_clip->final_clip_rect.size.height);
|
|
|
|
- int y = storage->frame.current_rt->height - (current_clip->final_clip_rect.position.y + current_clip->final_clip_rect.size.y);
|
|
|
|
- if (storage->frame.current_rt->flags[RasterizerStorage::RENDER_TARGET_VFLIP])
|
|
|
|
- y = current_clip->final_clip_rect.position.y;
|
|
|
|
|
|
+ glDisable(GL_SCISSOR_TEST);
|
|
|
|
+ }
|
|
|
|
+ }
|
|
|
|
|
|
- glScissor(current_clip->final_clip_rect.position.x, y, current_clip->final_clip_rect.size.x, current_clip->final_clip_rect.size.y);
|
|
|
|
|
|
+ if (p_ci->copy_back_buffer) {
|
|
|
|
|
|
- reclip = false;
|
|
|
|
- }
|
|
|
|
- }
|
|
|
|
- }
|
|
|
|
|
|
+ if (p_ci->copy_back_buffer->full) {
|
|
|
|
|
|
- } break;
|
|
|
|
|
|
+ _copy_texscreen(Rect2());
|
|
|
|
+ } else {
|
|
|
|
+ _copy_texscreen(p_ci->copy_back_buffer->rect);
|
|
}
|
|
}
|
|
}
|
|
}
|
|
-}
|
|
|
|
|
|
|
|
-void RasterizerCanvasGLES3::_copy_texscreen(const Rect2 &p_rect) {
|
|
|
|
|
|
+ if (!bdata.settings_use_batching || !bdata.settings_use_software_skinning) {
|
|
|
|
|
|
- ERR_FAIL_COND_MSG(storage->frame.current_rt->effects.mip_maps[0].sizes.size() == 0, "Can't use screen texture copying in a render target configured without copy buffers.");
|
|
|
|
|
|
+ RasterizerStorageGLES3::Skeleton *skeleton = NULL;
|
|
|
|
|
|
- glDisable(GL_BLEND);
|
|
|
|
|
|
+ //skeleton handling
|
|
|
|
+ if (p_ci->skeleton.is_valid() && storage->skeleton_owner.owns(p_ci->skeleton)) {
|
|
|
|
+ skeleton = storage->skeleton_owner.get(p_ci->skeleton);
|
|
|
|
+ if (!skeleton->use_2d) {
|
|
|
|
+ skeleton = NULL;
|
|
|
|
+ } else {
|
|
|
|
+ state.skeleton_transform = r_ris.item_group_base_transform * skeleton->base_transform_2d;
|
|
|
|
+ state.skeleton_transform_inverse = state.skeleton_transform.affine_inverse();
|
|
|
|
+ }
|
|
|
|
+ }
|
|
|
|
|
|
- state.canvas_texscreen_used = true;
|
|
|
|
- //blur diffuse into effect mipmaps using separatable convolution
|
|
|
|
- //storage->shaders.copy.set_conditional(CopyShaderGLES3::GAUSSIAN_HORIZONTAL,true);
|
|
|
|
|
|
+ bool use_skeleton = skeleton != NULL;
|
|
|
|
+ if (r_ris.prev_use_skeleton != use_skeleton) {
|
|
|
|
+ r_ris.rebind_shader = true;
|
|
|
|
+ state.canvas_shader.set_conditional(CanvasShaderGLES3::USE_SKELETON, use_skeleton);
|
|
|
|
+ r_ris.prev_use_skeleton = use_skeleton;
|
|
|
|
+ }
|
|
|
|
|
|
- Vector2 wh(storage->frame.current_rt->width, storage->frame.current_rt->height);
|
|
|
|
|
|
+ if (skeleton) {
|
|
|
|
+ glActiveTexture(GL_TEXTURE0 + storage->config.max_texture_image_units - 4);
|
|
|
|
+ glBindTexture(GL_TEXTURE_2D, skeleton->texture);
|
|
|
|
+ state.using_skeleton = true;
|
|
|
|
+ } else {
|
|
|
|
+ state.using_skeleton = false;
|
|
|
|
+ }
|
|
|
|
|
|
- Color blur_section(p_rect.position.x / wh.x, p_rect.position.y / wh.y, p_rect.size.x / wh.x, p_rect.size.y / wh.y);
|
|
|
|
|
|
+ } // if not using batching
|
|
|
|
|
|
- if (p_rect != Rect2()) {
|
|
|
|
|
|
+ //begin rect
|
|
|
|
+ Item *material_owner = p_ci->material_owner ? p_ci->material_owner : p_ci;
|
|
|
|
|
|
- scene_render->state.effect_blur_shader.set_conditional(EffectBlurShaderGLES3::USE_BLUR_SECTION, true);
|
|
|
|
- storage->shaders.copy.set_conditional(CopyShaderGLES3::USE_COPY_SECTION, true);
|
|
|
|
- }
|
|
|
|
|
|
+ RID material = material_owner->material;
|
|
|
|
|
|
- glBindFramebuffer(GL_FRAMEBUFFER, storage->frame.current_rt->effects.mip_maps[0].sizes[0].fbo);
|
|
|
|
- glActiveTexture(GL_TEXTURE0);
|
|
|
|
- glBindTexture(GL_TEXTURE_2D, storage->frame.current_rt->color);
|
|
|
|
|
|
+ if (material != r_ris.canvas_last_material || r_ris.rebind_shader) {
|
|
|
|
|
|
- storage->shaders.copy.bind();
|
|
|
|
- storage->shaders.copy.set_uniform(CopyShaderGLES3::COPY_SECTION, blur_section);
|
|
|
|
|
|
+ RasterizerStorageGLES3::Material *material_ptr = storage->material_owner.getornull(material);
|
|
|
|
+ RasterizerStorageGLES3::Shader *shader_ptr = NULL;
|
|
|
|
|
|
- scene_render->_copy_screen();
|
|
|
|
|
|
+ if (material_ptr) {
|
|
|
|
|
|
- for (int i = 0; i < storage->frame.current_rt->effects.mip_maps[1].sizes.size(); i++) {
|
|
|
|
|
|
+ shader_ptr = material_ptr->shader;
|
|
|
|
|
|
- int vp_w = storage->frame.current_rt->effects.mip_maps[1].sizes[i].width;
|
|
|
|
- int vp_h = storage->frame.current_rt->effects.mip_maps[1].sizes[i].height;
|
|
|
|
- glViewport(0, 0, vp_w, vp_h);
|
|
|
|
- //horizontal pass
|
|
|
|
- scene_render->state.effect_blur_shader.set_conditional(EffectBlurShaderGLES3::GAUSSIAN_HORIZONTAL, true);
|
|
|
|
- scene_render->state.effect_blur_shader.bind();
|
|
|
|
- scene_render->state.effect_blur_shader.set_uniform(EffectBlurShaderGLES3::PIXEL_SIZE, Vector2(1.0 / vp_w, 1.0 / vp_h));
|
|
|
|
- scene_render->state.effect_blur_shader.set_uniform(EffectBlurShaderGLES3::LOD, float(i));
|
|
|
|
- scene_render->state.effect_blur_shader.set_uniform(EffectBlurShaderGLES3::BLUR_SECTION, blur_section);
|
|
|
|
- glActiveTexture(GL_TEXTURE0);
|
|
|
|
- glBindTexture(GL_TEXTURE_2D, storage->frame.current_rt->effects.mip_maps[0].color); //previous level, since mipmaps[0] starts one level bigger
|
|
|
|
- glBindFramebuffer(GL_FRAMEBUFFER, storage->frame.current_rt->effects.mip_maps[1].sizes[i].fbo);
|
|
|
|
|
|
+ if (shader_ptr && shader_ptr->mode != VS::SHADER_CANVAS_ITEM) {
|
|
|
|
+ shader_ptr = NULL; //do not use non canvasitem shader
|
|
|
|
+ }
|
|
|
|
+ }
|
|
|
|
|
|
- scene_render->_copy_screen();
|
|
|
|
|
|
+ if (shader_ptr) {
|
|
|
|
|
|
- scene_render->state.effect_blur_shader.set_conditional(EffectBlurShaderGLES3::GAUSSIAN_HORIZONTAL, false);
|
|
|
|
|
|
+ if (shader_ptr->canvas_item.uses_screen_texture && !state.canvas_texscreen_used) {
|
|
|
|
+ //copy if not copied before
|
|
|
|
+ _copy_texscreen(Rect2());
|
|
|
|
|
|
- //vertical pass
|
|
|
|
- scene_render->state.effect_blur_shader.set_conditional(EffectBlurShaderGLES3::GAUSSIAN_VERTICAL, true);
|
|
|
|
- scene_render->state.effect_blur_shader.bind();
|
|
|
|
- scene_render->state.effect_blur_shader.set_uniform(EffectBlurShaderGLES3::PIXEL_SIZE, Vector2(1.0 / vp_w, 1.0 / vp_h));
|
|
|
|
- scene_render->state.effect_blur_shader.set_uniform(EffectBlurShaderGLES3::LOD, float(i));
|
|
|
|
- scene_render->state.effect_blur_shader.set_uniform(EffectBlurShaderGLES3::BLUR_SECTION, blur_section);
|
|
|
|
- glActiveTexture(GL_TEXTURE0);
|
|
|
|
- glBindTexture(GL_TEXTURE_2D, storage->frame.current_rt->effects.mip_maps[1].color);
|
|
|
|
- glBindFramebuffer(GL_FRAMEBUFFER, storage->frame.current_rt->effects.mip_maps[0].sizes[i + 1].fbo); //next level, since mipmaps[0] starts one level bigger
|
|
|
|
|
|
+ // blend mode will have been enabled so make sure we disable it again later on
|
|
|
|
+ r_ris.last_blend_mode = r_ris.last_blend_mode != RasterizerStorageGLES3::Shader::CanvasItem::BLEND_MODE_DISABLED ? r_ris.last_blend_mode : -1;
|
|
|
|
+ }
|
|
|
|
|
|
- scene_render->_copy_screen();
|
|
|
|
|
|
+ if (shader_ptr != r_ris.shader_cache || r_ris.rebind_shader) {
|
|
|
|
|
|
- scene_render->state.effect_blur_shader.set_conditional(EffectBlurShaderGLES3::GAUSSIAN_VERTICAL, false);
|
|
|
|
- }
|
|
|
|
|
|
+ if (shader_ptr->canvas_item.uses_time) {
|
|
|
|
+ VisualServerRaster::redraw_request();
|
|
|
|
+ }
|
|
|
|
|
|
- scene_render->state.effect_blur_shader.set_conditional(EffectBlurShaderGLES3::USE_BLUR_SECTION, false);
|
|
|
|
- storage->shaders.copy.set_conditional(CopyShaderGLES3::USE_COPY_SECTION, false);
|
|
|
|
|
|
+ state.canvas_shader.set_custom_shader(shader_ptr->custom_code_id);
|
|
|
|
+ state.canvas_shader.bind();
|
|
|
|
+ }
|
|
|
|
|
|
- glBindFramebuffer(GL_FRAMEBUFFER, storage->frame.current_rt->fbo); //back to front
|
|
|
|
- glViewport(0, 0, storage->frame.current_rt->width, storage->frame.current_rt->height);
|
|
|
|
|
|
+ if (material_ptr->ubo_id) {
|
|
|
|
+ glBindBufferBase(GL_UNIFORM_BUFFER, 2, material_ptr->ubo_id);
|
|
|
|
+ }
|
|
|
|
|
|
- // back to canvas, force rebind
|
|
|
|
- state.using_texture_rect = true;
|
|
|
|
- _set_texture_rect_mode(false);
|
|
|
|
|
|
+ int tc = material_ptr->textures.size();
|
|
|
|
+ RID *textures = material_ptr->textures.ptrw();
|
|
|
|
+ ShaderLanguage::ShaderNode::Uniform::Hint *texture_hints = shader_ptr->texture_hints.ptrw();
|
|
|
|
|
|
- _bind_canvas_texture(state.current_tex, state.current_normal, true);
|
|
|
|
|
|
+ for (int i = 0; i < tc; i++) {
|
|
|
|
|
|
- glEnable(GL_BLEND);
|
|
|
|
-}
|
|
|
|
|
|
+ glActiveTexture(GL_TEXTURE2 + i);
|
|
|
|
|
|
-void RasterizerCanvasGLES3::canvas_render_items(Item *p_item_list, int p_z, const Color &p_modulate, Light *p_light, const Transform2D &p_transform) {
|
|
|
|
|
|
+ RasterizerStorageGLES3::Texture *t = storage->texture_owner.getornull(textures[i]);
|
|
|
|
+ if (!t) {
|
|
|
|
|
|
- Item *current_clip = NULL;
|
|
|
|
- RasterizerStorageGLES3::Shader *shader_cache = NULL;
|
|
|
|
|
|
+ switch (texture_hints[i]) {
|
|
|
|
+ case ShaderLanguage::ShaderNode::Uniform::HINT_BLACK_ALBEDO:
|
|
|
|
+ case ShaderLanguage::ShaderNode::Uniform::HINT_BLACK: {
|
|
|
|
+ glBindTexture(GL_TEXTURE_2D, storage->resources.black_tex);
|
|
|
|
+ } break;
|
|
|
|
+ case ShaderLanguage::ShaderNode::Uniform::HINT_ANISO: {
|
|
|
|
+ glBindTexture(GL_TEXTURE_2D, storage->resources.aniso_tex);
|
|
|
|
+ } break;
|
|
|
|
+ case ShaderLanguage::ShaderNode::Uniform::HINT_NORMAL: {
|
|
|
|
+ glBindTexture(GL_TEXTURE_2D, storage->resources.normal_tex);
|
|
|
|
+ } break;
|
|
|
|
+ default: {
|
|
|
|
+ glBindTexture(GL_TEXTURE_2D, storage->resources.white_tex);
|
|
|
|
+ } break;
|
|
|
|
+ }
|
|
|
|
|
|
- bool rebind_shader = true;
|
|
|
|
|
|
+ //check hints
|
|
|
|
|
|
- glBindBuffer(GL_UNIFORM_BUFFER, state.canvas_item_ubo);
|
|
|
|
- glBufferData(GL_UNIFORM_BUFFER, sizeof(CanvasItemUBO), &state.canvas_item_ubo_data, GL_DYNAMIC_DRAW);
|
|
|
|
- glBindBuffer(GL_UNIFORM_BUFFER, 0);
|
|
|
|
|
|
+ continue;
|
|
|
|
+ }
|
|
|
|
|
|
- state.current_tex = RID();
|
|
|
|
- state.current_tex_ptr = NULL;
|
|
|
|
- state.current_normal = RID();
|
|
|
|
- glActiveTexture(GL_TEXTURE0);
|
|
|
|
- glBindTexture(GL_TEXTURE_2D, storage->resources.white_tex);
|
|
|
|
|
|
+ if (t->redraw_if_visible) { //check before proxy, because this is usually used with proxies
|
|
|
|
+ VisualServerRaster::redraw_request();
|
|
|
|
+ }
|
|
|
|
|
|
- int last_blend_mode = -1;
|
|
|
|
|
|
+ t = t->get_ptr();
|
|
|
|
|
|
- RID canvas_last_material;
|
|
|
|
|
|
+ if (storage->config.srgb_decode_supported && t->using_srgb) {
|
|
|
|
+ //no srgb in 2D
|
|
|
|
+ glTexParameteri(t->target, _TEXTURE_SRGB_DECODE_EXT, _SKIP_DECODE_EXT);
|
|
|
|
+ t->using_srgb = false;
|
|
|
|
+ }
|
|
|
|
|
|
- bool prev_distance_field = false;
|
|
|
|
- bool prev_use_skeleton = false;
|
|
|
|
|
|
+ glBindTexture(t->target, t->tex_id);
|
|
|
|
+ }
|
|
|
|
|
|
- while (p_item_list) {
|
|
|
|
|
|
+ } else {
|
|
|
|
+ state.canvas_shader.set_custom_shader(0);
|
|
|
|
+ state.canvas_shader.bind();
|
|
|
|
+ }
|
|
|
|
|
|
- Item *ci = p_item_list;
|
|
|
|
- storage->info.render._2d_item_count++;
|
|
|
|
|
|
+ r_ris.shader_cache = shader_ptr;
|
|
|
|
|
|
- if (prev_distance_field != ci->distance_field) {
|
|
|
|
|
|
+ r_ris.canvas_last_material = material;
|
|
|
|
+ r_ris.rebind_shader = false;
|
|
|
|
+ }
|
|
|
|
|
|
- state.canvas_shader.set_conditional(CanvasShaderGLES3::USE_DISTANCE_FIELD, ci->distance_field);
|
|
|
|
- prev_distance_field = ci->distance_field;
|
|
|
|
- rebind_shader = true;
|
|
|
|
|
|
+ int blend_mode = r_ris.shader_cache ? r_ris.shader_cache->canvas_item.blend_mode : RasterizerStorageGLES3::Shader::CanvasItem::BLEND_MODE_MIX;
|
|
|
|
+ if (blend_mode == RasterizerStorageGLES3::Shader::CanvasItem::BLEND_MODE_DISABLED && (!storage->frame.current_rt || !storage->frame.current_rt->flags[RasterizerStorage::RENDER_TARGET_TRANSPARENT])) {
|
|
|
|
+ blend_mode = RasterizerStorageGLES3::Shader::CanvasItem::BLEND_MODE_MIX;
|
|
|
|
+ }
|
|
|
|
+ bool unshaded = r_ris.shader_cache && (r_ris.shader_cache->canvas_item.light_mode == RasterizerStorageGLES3::Shader::CanvasItem::LIGHT_MODE_UNSHADED || (blend_mode != RasterizerStorageGLES3::Shader::CanvasItem::BLEND_MODE_MIX && blend_mode != RasterizerStorageGLES3::Shader::CanvasItem::BLEND_MODE_PMALPHA));
|
|
|
|
+ bool reclip = false;
|
|
|
|
+
|
|
|
|
+ if (r_ris.last_blend_mode != blend_mode) {
|
|
|
|
+ if (r_ris.last_blend_mode == RasterizerStorageGLES3::Shader::CanvasItem::BLEND_MODE_DISABLED) {
|
|
|
|
+ // re-enable it
|
|
|
|
+ glEnable(GL_BLEND);
|
|
|
|
+ } else if (blend_mode == RasterizerStorageGLES3::Shader::CanvasItem::BLEND_MODE_DISABLED) {
|
|
|
|
+ // disable it
|
|
|
|
+ glDisable(GL_BLEND);
|
|
}
|
|
}
|
|
|
|
|
|
- if (current_clip != ci->final_clip_owner) {
|
|
|
|
|
|
+ switch (blend_mode) {
|
|
|
|
|
|
- current_clip = ci->final_clip_owner;
|
|
|
|
|
|
+ case RasterizerStorageGLES3::Shader::CanvasItem::BLEND_MODE_DISABLED: {
|
|
|
|
|
|
- //setup clip
|
|
|
|
- if (current_clip) {
|
|
|
|
|
|
+ // nothing to do here
|
|
|
|
|
|
- glEnable(GL_SCISSOR_TEST);
|
|
|
|
- int y = storage->frame.current_rt->height - (current_clip->final_clip_rect.position.y + current_clip->final_clip_rect.size.y);
|
|
|
|
- if (storage->frame.current_rt->flags[RasterizerStorage::RENDER_TARGET_VFLIP])
|
|
|
|
- y = current_clip->final_clip_rect.position.y;
|
|
|
|
|
|
+ } break;
|
|
|
|
+ case RasterizerStorageGLES3::Shader::CanvasItem::BLEND_MODE_MIX: {
|
|
|
|
|
|
- glScissor(current_clip->final_clip_rect.position.x, y, current_clip->final_clip_rect.size.x, current_clip->final_clip_rect.size.y);
|
|
|
|
|
|
+ glBlendEquation(GL_FUNC_ADD);
|
|
|
|
+ if (storage->frame.current_rt && storage->frame.current_rt->flags[RasterizerStorage::RENDER_TARGET_TRANSPARENT]) {
|
|
|
|
+ glBlendFuncSeparate(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA, GL_ONE, GL_ONE_MINUS_SRC_ALPHA);
|
|
|
|
+ } else {
|
|
|
|
+ glBlendFuncSeparate(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA, GL_ZERO, GL_ONE);
|
|
|
|
+ }
|
|
|
|
|
|
- } else {
|
|
|
|
|
|
+ } break;
|
|
|
|
+ case RasterizerStorageGLES3::Shader::CanvasItem::BLEND_MODE_ADD: {
|
|
|
|
|
|
- glDisable(GL_SCISSOR_TEST);
|
|
|
|
- }
|
|
|
|
- }
|
|
|
|
|
|
+ glBlendEquation(GL_FUNC_ADD);
|
|
|
|
+ if (storage->frame.current_rt && storage->frame.current_rt->flags[RasterizerStorage::RENDER_TARGET_TRANSPARENT]) {
|
|
|
|
+ glBlendFuncSeparate(GL_SRC_ALPHA, GL_ONE, GL_SRC_ALPHA, GL_ONE);
|
|
|
|
+ } else {
|
|
|
|
+ glBlendFuncSeparate(GL_SRC_ALPHA, GL_ONE, GL_ZERO, GL_ONE);
|
|
|
|
+ }
|
|
|
|
|
|
- if (ci->copy_back_buffer) {
|
|
|
|
|
|
+ } break;
|
|
|
|
+ case RasterizerStorageGLES3::Shader::CanvasItem::BLEND_MODE_SUB: {
|
|
|
|
|
|
- if (ci->copy_back_buffer->full) {
|
|
|
|
|
|
+ glBlendEquation(GL_FUNC_REVERSE_SUBTRACT);
|
|
|
|
+ if (storage->frame.current_rt && storage->frame.current_rt->flags[RasterizerStorage::RENDER_TARGET_TRANSPARENT]) {
|
|
|
|
+ glBlendFuncSeparate(GL_SRC_ALPHA, GL_ONE, GL_SRC_ALPHA, GL_ONE);
|
|
|
|
+ } else {
|
|
|
|
+ glBlendFuncSeparate(GL_SRC_ALPHA, GL_ONE, GL_ZERO, GL_ONE);
|
|
|
|
+ }
|
|
|
|
+ } break;
|
|
|
|
+ case RasterizerStorageGLES3::Shader::CanvasItem::BLEND_MODE_MUL: {
|
|
|
|
+ glBlendEquation(GL_FUNC_ADD);
|
|
|
|
+ if (storage->frame.current_rt && storage->frame.current_rt->flags[RasterizerStorage::RENDER_TARGET_TRANSPARENT]) {
|
|
|
|
+ glBlendFuncSeparate(GL_DST_COLOR, GL_ZERO, GL_DST_ALPHA, GL_ZERO);
|
|
|
|
+ } else {
|
|
|
|
+ glBlendFuncSeparate(GL_DST_COLOR, GL_ZERO, GL_ZERO, GL_ONE);
|
|
|
|
+ }
|
|
|
|
|
|
- _copy_texscreen(Rect2());
|
|
|
|
- } else {
|
|
|
|
- _copy_texscreen(ci->copy_back_buffer->rect);
|
|
|
|
- }
|
|
|
|
|
|
+ } break;
|
|
|
|
+ case RasterizerStorageGLES3::Shader::CanvasItem::BLEND_MODE_PMALPHA: {
|
|
|
|
+ glBlendEquation(GL_FUNC_ADD);
|
|
|
|
+ if (storage->frame.current_rt && storage->frame.current_rt->flags[RasterizerStorage::RENDER_TARGET_TRANSPARENT]) {
|
|
|
|
+ glBlendFuncSeparate(GL_ONE, GL_ONE_MINUS_SRC_ALPHA, GL_ONE, GL_ONE_MINUS_SRC_ALPHA);
|
|
|
|
+ } else {
|
|
|
|
+ glBlendFuncSeparate(GL_ONE, GL_ONE_MINUS_SRC_ALPHA, GL_ZERO, GL_ONE);
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ } break;
|
|
}
|
|
}
|
|
|
|
|
|
- RasterizerStorageGLES3::Skeleton *skeleton = NULL;
|
|
|
|
|
|
+ r_ris.last_blend_mode = blend_mode;
|
|
|
|
+ }
|
|
|
|
|
|
- {
|
|
|
|
- //skeleton handling
|
|
|
|
- if (ci->skeleton.is_valid() && storage->skeleton_owner.owns(ci->skeleton)) {
|
|
|
|
- skeleton = storage->skeleton_owner.get(ci->skeleton);
|
|
|
|
- if (!skeleton->use_2d) {
|
|
|
|
- skeleton = NULL;
|
|
|
|
- } else {
|
|
|
|
- state.skeleton_transform = p_transform * skeleton->base_transform_2d;
|
|
|
|
- state.skeleton_transform_inverse = state.skeleton_transform.affine_inverse();
|
|
|
|
- }
|
|
|
|
- }
|
|
|
|
|
|
+ //state.canvas_item_modulate = unshaded ? p_ci->final_modulate : Color(p_ci->final_modulate.r * r_ris.item_group_modulate.r, p_ci->final_modulate.g * r_ris.item_group_modulate.g, p_ci->final_modulate.b * r_ris.item_group_modulate.b, p_ci->final_modulate.a * r_ris.item_group_modulate.a);
|
|
|
|
|
|
- bool use_skeleton = skeleton != NULL;
|
|
|
|
- if (prev_use_skeleton != use_skeleton) {
|
|
|
|
- rebind_shader = true;
|
|
|
|
- state.canvas_shader.set_conditional(CanvasShaderGLES3::USE_SKELETON, use_skeleton);
|
|
|
|
- prev_use_skeleton = use_skeleton;
|
|
|
|
- }
|
|
|
|
|
|
+ // state.final_transform = p_ci->final_transform;
|
|
|
|
+ // state.extra_matrix = Transform2D();
|
|
|
|
|
|
- if (skeleton) {
|
|
|
|
- glActiveTexture(GL_TEXTURE0 + storage->config.max_texture_image_units - 4);
|
|
|
|
- glBindTexture(GL_TEXTURE_2D, skeleton->texture);
|
|
|
|
- state.using_skeleton = true;
|
|
|
|
- } else {
|
|
|
|
- state.using_skeleton = false;
|
|
|
|
- }
|
|
|
|
- }
|
|
|
|
|
|
+ // using software transform
|
|
|
|
+ if (!p_bij.use_hardware_transform()) {
|
|
|
|
+ state.final_transform = Transform2D();
|
|
|
|
+ // final_modulate will be baked per item ref so the final_modulate can be an identity color
|
|
|
|
+ state.canvas_item_modulate = Color(1, 1, 1, 1);
|
|
|
|
+ } else {
|
|
|
|
+ state.final_transform = p_ci->final_transform;
|
|
|
|
+ // could use the stored version of final_modulate in item ref? Test which is faster NYI
|
|
|
|
+ state.canvas_item_modulate = unshaded ? p_ci->final_modulate : (p_ci->final_modulate * r_ris.item_group_modulate);
|
|
|
|
+ }
|
|
|
|
+ state.extra_matrix = Transform2D();
|
|
|
|
+
|
|
|
|
+ if (state.using_skeleton) {
|
|
|
|
+ state.canvas_shader.set_uniform(CanvasShaderGLES3::SKELETON_TRANSFORM, state.skeleton_transform);
|
|
|
|
+ state.canvas_shader.set_uniform(CanvasShaderGLES3::SKELETON_TRANSFORM_INVERSE, state.skeleton_transform_inverse);
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ state.canvas_shader.set_uniform(CanvasShaderGLES3::FINAL_MODULATE, state.canvas_item_modulate);
|
|
|
|
+ state.canvas_shader.set_uniform(CanvasShaderGLES3::MODELVIEW_MATRIX, state.final_transform);
|
|
|
|
+ state.canvas_shader.set_uniform(CanvasShaderGLES3::EXTRA_MATRIX, state.extra_matrix);
|
|
|
|
+ if (storage->frame.current_rt) {
|
|
|
|
+ state.canvas_shader.set_uniform(CanvasShaderGLES3::SCREEN_PIXEL_SIZE, Vector2(1.0 / storage->frame.current_rt->width, 1.0 / storage->frame.current_rt->height));
|
|
|
|
+ } else {
|
|
|
|
+ state.canvas_shader.set_uniform(CanvasShaderGLES3::SCREEN_PIXEL_SIZE, Vector2(1.0, 1.0));
|
|
|
|
+ }
|
|
|
|
+ if (unshaded || (state.canvas_item_modulate.a > 0.001 && (!r_ris.shader_cache || r_ris.shader_cache->canvas_item.light_mode != RasterizerStorageGLES3::Shader::CanvasItem::LIGHT_MODE_LIGHT_ONLY) && !p_ci->light_masked)) {
|
|
|
|
+ RasterizerStorageGLES3::Material *material_ptr = nullptr;
|
|
|
|
+ render_joined_item_commands(p_bij, NULL, reclip, material_ptr, false);
|
|
|
|
+ }
|
|
|
|
|
|
- //begin rect
|
|
|
|
- Item *material_owner = ci->material_owner ? ci->material_owner : ci;
|
|
|
|
|
|
+ if ((blend_mode == RasterizerStorageGLES3::Shader::CanvasItem::BLEND_MODE_MIX || blend_mode == RasterizerStorageGLES3::Shader::CanvasItem::BLEND_MODE_PMALPHA) && r_ris.item_group_light && !unshaded) {
|
|
|
|
|
|
- RID material = material_owner->material;
|
|
|
|
|
|
+ Light *light = r_ris.item_group_light;
|
|
|
|
+ bool light_used = false;
|
|
|
|
+ VS::CanvasLightMode mode = VS::CANVAS_LIGHT_MODE_ADD;
|
|
|
|
+ state.canvas_item_modulate = p_ci->final_modulate; // remove the canvas modulate
|
|
|
|
|
|
- if (material != canvas_last_material || rebind_shader) {
|
|
|
|
|
|
+ while (light) {
|
|
|
|
|
|
- RasterizerStorageGLES3::Material *material_ptr = storage->material_owner.getornull(material);
|
|
|
|
- RasterizerStorageGLES3::Shader *shader_ptr = NULL;
|
|
|
|
|
|
+ // use the bounding rect of the joined items, NOT only the bounding rect of the first item.
|
|
|
|
+ // note this is a cost of batching, the light culling will be less effective
|
|
|
|
|
|
- if (material_ptr) {
|
|
|
|
|
|
+ // note that the r_ris.item_group_z will be out of date because we are using deferred rendering till canvas_render_items_end()
|
|
|
|
+ // so we have to test z against the stored value in the joined item
|
|
|
|
+ if (p_ci->light_mask & light->item_mask && p_bij.z_index >= light->z_min && p_bij.z_index <= light->z_max && p_bij.bounding_rect.intersects_transformed(light->xform_cache, light->rect_cache)) {
|
|
|
|
|
|
- shader_ptr = material_ptr->shader;
|
|
|
|
|
|
+ //intersects this light
|
|
|
|
|
|
- if (shader_ptr && shader_ptr->mode != VS::SHADER_CANVAS_ITEM) {
|
|
|
|
- shader_ptr = NULL; //do not use non canvasitem shader
|
|
|
|
- }
|
|
|
|
- }
|
|
|
|
|
|
+ if (!light_used || mode != light->mode) {
|
|
|
|
|
|
- if (shader_ptr) {
|
|
|
|
|
|
+ mode = light->mode;
|
|
|
|
|
|
- if (shader_ptr->canvas_item.uses_screen_texture && !state.canvas_texscreen_used) {
|
|
|
|
- //copy if not copied before
|
|
|
|
- _copy_texscreen(Rect2());
|
|
|
|
|
|
+ switch (mode) {
|
|
|
|
|
|
- // blend mode will have been enabled so make sure we disable it again later on
|
|
|
|
- last_blend_mode = last_blend_mode != RasterizerStorageGLES3::Shader::CanvasItem::BLEND_MODE_DISABLED ? last_blend_mode : -1;
|
|
|
|
- }
|
|
|
|
|
|
+ case VS::CANVAS_LIGHT_MODE_ADD: {
|
|
|
|
+ glBlendEquation(GL_FUNC_ADD);
|
|
|
|
+ glBlendFunc(GL_SRC_ALPHA, GL_ONE);
|
|
|
|
|
|
- if (shader_ptr != shader_cache || rebind_shader) {
|
|
|
|
|
|
+ } break;
|
|
|
|
+ case VS::CANVAS_LIGHT_MODE_SUB: {
|
|
|
|
+ glBlendEquation(GL_FUNC_REVERSE_SUBTRACT);
|
|
|
|
+ glBlendFunc(GL_SRC_ALPHA, GL_ONE);
|
|
|
|
+ } break;
|
|
|
|
+ case VS::CANVAS_LIGHT_MODE_MIX:
|
|
|
|
+ case VS::CANVAS_LIGHT_MODE_MASK: {
|
|
|
|
+ glBlendEquation(GL_FUNC_ADD);
|
|
|
|
+ glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA);
|
|
|
|
|
|
- if (shader_ptr->canvas_item.uses_time) {
|
|
|
|
- VisualServerRaster::redraw_request();
|
|
|
|
|
|
+ } break;
|
|
}
|
|
}
|
|
-
|
|
|
|
- state.canvas_shader.set_custom_shader(shader_ptr->custom_code_id);
|
|
|
|
- state.canvas_shader.bind();
|
|
|
|
}
|
|
}
|
|
|
|
|
|
- if (material_ptr->ubo_id) {
|
|
|
|
- glBindBufferBase(GL_UNIFORM_BUFFER, 2, material_ptr->ubo_id);
|
|
|
|
- }
|
|
|
|
|
|
+ if (!light_used) {
|
|
|
|
|
|
- int tc = material_ptr->textures.size();
|
|
|
|
- RID *textures = material_ptr->textures.ptrw();
|
|
|
|
- ShaderLanguage::ShaderNode::Uniform::Hint *texture_hints = shader_ptr->texture_hints.ptrw();
|
|
|
|
-
|
|
|
|
- for (int i = 0; i < tc; i++) {
|
|
|
|
-
|
|
|
|
- glActiveTexture(GL_TEXTURE2 + i);
|
|
|
|
-
|
|
|
|
- RasterizerStorageGLES3::Texture *t = storage->texture_owner.getornull(textures[i]);
|
|
|
|
- if (!t) {
|
|
|
|
-
|
|
|
|
- switch (texture_hints[i]) {
|
|
|
|
- case ShaderLanguage::ShaderNode::Uniform::HINT_BLACK_ALBEDO:
|
|
|
|
- case ShaderLanguage::ShaderNode::Uniform::HINT_BLACK: {
|
|
|
|
- glBindTexture(GL_TEXTURE_2D, storage->resources.black_tex);
|
|
|
|
- } break;
|
|
|
|
- case ShaderLanguage::ShaderNode::Uniform::HINT_ANISO: {
|
|
|
|
- glBindTexture(GL_TEXTURE_2D, storage->resources.aniso_tex);
|
|
|
|
- } break;
|
|
|
|
- case ShaderLanguage::ShaderNode::Uniform::HINT_NORMAL: {
|
|
|
|
- glBindTexture(GL_TEXTURE_2D, storage->resources.normal_tex);
|
|
|
|
- } break;
|
|
|
|
- default: {
|
|
|
|
- glBindTexture(GL_TEXTURE_2D, storage->resources.white_tex);
|
|
|
|
- } break;
|
|
|
|
- }
|
|
|
|
|
|
+ state.canvas_shader.set_conditional(CanvasShaderGLES3::USE_LIGHTING, true);
|
|
|
|
+ light_used = true;
|
|
|
|
+ }
|
|
|
|
|
|
- //check hints
|
|
|
|
|
|
+ bool has_shadow = light->shadow_buffer.is_valid() && p_ci->light_mask & light->item_shadow_mask;
|
|
|
|
+
|
|
|
|
+ state.canvas_shader.set_conditional(CanvasShaderGLES3::USE_SHADOWS, has_shadow);
|
|
|
|
+ if (has_shadow) {
|
|
|
|
+ state.canvas_shader.set_conditional(CanvasShaderGLES3::SHADOW_USE_GRADIENT, light->shadow_gradient_length > 0);
|
|
|
|
+ state.canvas_shader.set_conditional(CanvasShaderGLES3::SHADOW_FILTER_NEAREST, light->shadow_filter == VS::CANVAS_LIGHT_FILTER_NONE);
|
|
|
|
+ state.canvas_shader.set_conditional(CanvasShaderGLES3::SHADOW_FILTER_PCF3, light->shadow_filter == VS::CANVAS_LIGHT_FILTER_PCF3);
|
|
|
|
+ state.canvas_shader.set_conditional(CanvasShaderGLES3::SHADOW_FILTER_PCF5, light->shadow_filter == VS::CANVAS_LIGHT_FILTER_PCF5);
|
|
|
|
+ state.canvas_shader.set_conditional(CanvasShaderGLES3::SHADOW_FILTER_PCF7, light->shadow_filter == VS::CANVAS_LIGHT_FILTER_PCF7);
|
|
|
|
+ state.canvas_shader.set_conditional(CanvasShaderGLES3::SHADOW_FILTER_PCF9, light->shadow_filter == VS::CANVAS_LIGHT_FILTER_PCF9);
|
|
|
|
+ state.canvas_shader.set_conditional(CanvasShaderGLES3::SHADOW_FILTER_PCF13, light->shadow_filter == VS::CANVAS_LIGHT_FILTER_PCF13);
|
|
|
|
+ }
|
|
|
|
|
|
- continue;
|
|
|
|
- }
|
|
|
|
|
|
+ bool light_rebind = state.canvas_shader.bind();
|
|
|
|
|
|
- if (t->redraw_if_visible) { //check before proxy, because this is usually used with proxies
|
|
|
|
- VisualServerRaster::redraw_request();
|
|
|
|
|
|
+ if (light_rebind) {
|
|
|
|
+ state.canvas_shader.set_uniform(CanvasShaderGLES3::FINAL_MODULATE, state.canvas_item_modulate);
|
|
|
|
+ state.canvas_shader.set_uniform(CanvasShaderGLES3::MODELVIEW_MATRIX, state.final_transform);
|
|
|
|
+ state.canvas_shader.set_uniform(CanvasShaderGLES3::EXTRA_MATRIX, Transform2D());
|
|
|
|
+ if (storage->frame.current_rt) {
|
|
|
|
+ state.canvas_shader.set_uniform(CanvasShaderGLES3::SCREEN_PIXEL_SIZE, Vector2(1.0 / storage->frame.current_rt->width, 1.0 / storage->frame.current_rt->height));
|
|
|
|
+ } else {
|
|
|
|
+ state.canvas_shader.set_uniform(CanvasShaderGLES3::SCREEN_PIXEL_SIZE, Vector2(1.0, 1.0));
|
|
}
|
|
}
|
|
-
|
|
|
|
- t = t->get_ptr();
|
|
|
|
-
|
|
|
|
- if (storage->config.srgb_decode_supported && t->using_srgb) {
|
|
|
|
- //no srgb in 2D
|
|
|
|
- glTexParameteri(t->target, _TEXTURE_SRGB_DECODE_EXT, _SKIP_DECODE_EXT);
|
|
|
|
- t->using_srgb = false;
|
|
|
|
|
|
+ if (state.using_skeleton) {
|
|
|
|
+ state.canvas_shader.set_uniform(CanvasShaderGLES3::SKELETON_TRANSFORM, state.skeleton_transform);
|
|
|
|
+ state.canvas_shader.set_uniform(CanvasShaderGLES3::SKELETON_TRANSFORM_INVERSE, state.skeleton_transform_inverse);
|
|
}
|
|
}
|
|
-
|
|
|
|
- glBindTexture(t->target, t->tex_id);
|
|
|
|
}
|
|
}
|
|
|
|
|
|
- } else {
|
|
|
|
- state.canvas_shader.set_custom_shader(0);
|
|
|
|
- state.canvas_shader.bind();
|
|
|
|
- }
|
|
|
|
-
|
|
|
|
- shader_cache = shader_ptr;
|
|
|
|
-
|
|
|
|
- canvas_last_material = material;
|
|
|
|
- rebind_shader = false;
|
|
|
|
- }
|
|
|
|
-
|
|
|
|
- int blend_mode = shader_cache ? shader_cache->canvas_item.blend_mode : RasterizerStorageGLES3::Shader::CanvasItem::BLEND_MODE_MIX;
|
|
|
|
- if (blend_mode == RasterizerStorageGLES3::Shader::CanvasItem::BLEND_MODE_DISABLED && (!storage->frame.current_rt || !storage->frame.current_rt->flags[RasterizerStorage::RENDER_TARGET_TRANSPARENT])) {
|
|
|
|
- blend_mode = RasterizerStorageGLES3::Shader::CanvasItem::BLEND_MODE_MIX;
|
|
|
|
- }
|
|
|
|
- bool unshaded = shader_cache && (shader_cache->canvas_item.light_mode == RasterizerStorageGLES3::Shader::CanvasItem::LIGHT_MODE_UNSHADED || (blend_mode != RasterizerStorageGLES3::Shader::CanvasItem::BLEND_MODE_MIX && blend_mode != RasterizerStorageGLES3::Shader::CanvasItem::BLEND_MODE_PMALPHA));
|
|
|
|
- bool reclip = false;
|
|
|
|
-
|
|
|
|
- if (last_blend_mode != blend_mode) {
|
|
|
|
- if (last_blend_mode == RasterizerStorageGLES3::Shader::CanvasItem::BLEND_MODE_DISABLED) {
|
|
|
|
- // re-enable it
|
|
|
|
- glEnable(GL_BLEND);
|
|
|
|
- } else if (blend_mode == RasterizerStorageGLES3::Shader::CanvasItem::BLEND_MODE_DISABLED) {
|
|
|
|
- // disable it
|
|
|
|
- glDisable(GL_BLEND);
|
|
|
|
- }
|
|
|
|
-
|
|
|
|
- switch (blend_mode) {
|
|
|
|
-
|
|
|
|
- case RasterizerStorageGLES3::Shader::CanvasItem::BLEND_MODE_DISABLED: {
|
|
|
|
-
|
|
|
|
- // nothing to do here
|
|
|
|
|
|
+ glBindBufferBase(GL_UNIFORM_BUFFER, 1, static_cast<LightInternal *>(light->light_internal.get_data())->ubo);
|
|
|
|
|
|
- } break;
|
|
|
|
- case RasterizerStorageGLES3::Shader::CanvasItem::BLEND_MODE_MIX: {
|
|
|
|
|
|
+ if (has_shadow) {
|
|
|
|
|
|
- glBlendEquation(GL_FUNC_ADD);
|
|
|
|
- if (storage->frame.current_rt && storage->frame.current_rt->flags[RasterizerStorage::RENDER_TARGET_TRANSPARENT]) {
|
|
|
|
- glBlendFuncSeparate(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA, GL_ONE, GL_ONE_MINUS_SRC_ALPHA);
|
|
|
|
- } else {
|
|
|
|
- glBlendFuncSeparate(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA, GL_ZERO, GL_ONE);
|
|
|
|
- }
|
|
|
|
|
|
+ RasterizerStorageGLES3::CanvasLightShadow *cls = storage->canvas_light_shadow_owner.get(light->shadow_buffer);
|
|
|
|
+ glActiveTexture(GL_TEXTURE0 + storage->config.max_texture_image_units - 2);
|
|
|
|
+ glBindTexture(GL_TEXTURE_2D, cls->distance);
|
|
|
|
|
|
- } break;
|
|
|
|
- case RasterizerStorageGLES3::Shader::CanvasItem::BLEND_MODE_ADD: {
|
|
|
|
|
|
+ /*canvas_shader.set_uniform(CanvasShaderGLES3::SHADOW_MATRIX,light->shadow_matrix_cache);
|
|
|
|
+ canvas_shader.set_uniform(CanvasShaderGLES3::SHADOW_ESM_MULTIPLIER,light->shadow_esm_mult);
|
|
|
|
+ canvas_shader.set_uniform(CanvasShaderGLES3::LIGHT_SHADOW_COLOR,light->shadow_color);*/
|
|
|
|
+ }
|
|
|
|
|
|
- glBlendEquation(GL_FUNC_ADD);
|
|
|
|
- if (storage->frame.current_rt && storage->frame.current_rt->flags[RasterizerStorage::RENDER_TARGET_TRANSPARENT]) {
|
|
|
|
- glBlendFuncSeparate(GL_SRC_ALPHA, GL_ONE, GL_SRC_ALPHA, GL_ONE);
|
|
|
|
- } else {
|
|
|
|
- glBlendFuncSeparate(GL_SRC_ALPHA, GL_ONE, GL_ZERO, GL_ONE);
|
|
|
|
- }
|
|
|
|
|
|
+ glActiveTexture(GL_TEXTURE0 + storage->config.max_texture_image_units - 1);
|
|
|
|
+ RasterizerStorageGLES3::Texture *t = storage->texture_owner.getornull(light->texture);
|
|
|
|
+ if (!t) {
|
|
|
|
+ glBindTexture(GL_TEXTURE_2D, storage->resources.white_tex);
|
|
|
|
+ } else {
|
|
|
|
+ t = t->get_ptr();
|
|
|
|
|
|
- } break;
|
|
|
|
- case RasterizerStorageGLES3::Shader::CanvasItem::BLEND_MODE_SUB: {
|
|
|
|
|
|
+ glBindTexture(t->target, t->tex_id);
|
|
|
|
+ }
|
|
|
|
|
|
- glBlendEquation(GL_FUNC_REVERSE_SUBTRACT);
|
|
|
|
- if (storage->frame.current_rt && storage->frame.current_rt->flags[RasterizerStorage::RENDER_TARGET_TRANSPARENT]) {
|
|
|
|
- glBlendFuncSeparate(GL_SRC_ALPHA, GL_ONE, GL_SRC_ALPHA, GL_ONE);
|
|
|
|
- } else {
|
|
|
|
- glBlendFuncSeparate(GL_SRC_ALPHA, GL_ONE, GL_ZERO, GL_ONE);
|
|
|
|
- }
|
|
|
|
- } break;
|
|
|
|
- case RasterizerStorageGLES3::Shader::CanvasItem::BLEND_MODE_MUL: {
|
|
|
|
- glBlendEquation(GL_FUNC_ADD);
|
|
|
|
- if (storage->frame.current_rt && storage->frame.current_rt->flags[RasterizerStorage::RENDER_TARGET_TRANSPARENT]) {
|
|
|
|
- glBlendFuncSeparate(GL_DST_COLOR, GL_ZERO, GL_DST_ALPHA, GL_ZERO);
|
|
|
|
- } else {
|
|
|
|
- glBlendFuncSeparate(GL_DST_COLOR, GL_ZERO, GL_ZERO, GL_ONE);
|
|
|
|
- }
|
|
|
|
|
|
+ glActiveTexture(GL_TEXTURE0);
|
|
|
|
|
|
- } break;
|
|
|
|
- case RasterizerStorageGLES3::Shader::CanvasItem::BLEND_MODE_PMALPHA: {
|
|
|
|
- glBlendEquation(GL_FUNC_ADD);
|
|
|
|
- if (storage->frame.current_rt && storage->frame.current_rt->flags[RasterizerStorage::RENDER_TARGET_TRANSPARENT]) {
|
|
|
|
- glBlendFuncSeparate(GL_ONE, GL_ONE_MINUS_SRC_ALPHA, GL_ONE, GL_ONE_MINUS_SRC_ALPHA);
|
|
|
|
- } else {
|
|
|
|
- glBlendFuncSeparate(GL_ONE, GL_ONE_MINUS_SRC_ALPHA, GL_ZERO, GL_ONE);
|
|
|
|
|
|
+ // redraw using light.
|
|
|
|
+ // if there is no clip item, we can consider scissoring to the intersection area between the light and the item
|
|
|
|
+ // this can greatly reduce fill rate ..
|
|
|
|
+ // at the cost of glScissor commands, so is optional
|
|
|
|
+ if (!bdata.settings_scissor_lights || r_ris.current_clip) {
|
|
|
|
+ render_joined_item_commands(p_bij, NULL, reclip, nullptr, true);
|
|
|
|
+ } else {
|
|
|
|
+ bool scissor = _light_scissor_begin(p_bij.bounding_rect, light->xform_cache, light->rect_cache);
|
|
|
|
+ render_joined_item_commands(p_bij, NULL, reclip, nullptr, true);
|
|
|
|
+ if (scissor) {
|
|
|
|
+ glDisable(GL_SCISSOR_TEST);
|
|
}
|
|
}
|
|
-
|
|
|
|
- } break;
|
|
|
|
|
|
+ }
|
|
}
|
|
}
|
|
|
|
|
|
- last_blend_mode = blend_mode;
|
|
|
|
- }
|
|
|
|
-
|
|
|
|
- state.canvas_item_modulate = unshaded ? ci->final_modulate : Color(ci->final_modulate.r * p_modulate.r, ci->final_modulate.g * p_modulate.g, ci->final_modulate.b * p_modulate.b, ci->final_modulate.a * p_modulate.a);
|
|
|
|
-
|
|
|
|
- state.final_transform = ci->final_transform;
|
|
|
|
- state.extra_matrix = Transform2D();
|
|
|
|
-
|
|
|
|
- if (state.using_skeleton) {
|
|
|
|
- state.canvas_shader.set_uniform(CanvasShaderGLES3::SKELETON_TRANSFORM, state.skeleton_transform);
|
|
|
|
- state.canvas_shader.set_uniform(CanvasShaderGLES3::SKELETON_TRANSFORM_INVERSE, state.skeleton_transform_inverse);
|
|
|
|
- }
|
|
|
|
-
|
|
|
|
- state.canvas_shader.set_uniform(CanvasShaderGLES3::FINAL_MODULATE, state.canvas_item_modulate);
|
|
|
|
- state.canvas_shader.set_uniform(CanvasShaderGLES3::MODELVIEW_MATRIX, state.final_transform);
|
|
|
|
- state.canvas_shader.set_uniform(CanvasShaderGLES3::EXTRA_MATRIX, state.extra_matrix);
|
|
|
|
- if (storage->frame.current_rt) {
|
|
|
|
- state.canvas_shader.set_uniform(CanvasShaderGLES3::SCREEN_PIXEL_SIZE, Vector2(1.0 / storage->frame.current_rt->width, 1.0 / storage->frame.current_rt->height));
|
|
|
|
- } else {
|
|
|
|
- state.canvas_shader.set_uniform(CanvasShaderGLES3::SCREEN_PIXEL_SIZE, Vector2(1.0, 1.0));
|
|
|
|
|
|
+ light = light->next_ptr;
|
|
}
|
|
}
|
|
- if (unshaded || (state.canvas_item_modulate.a > 0.001 && (!shader_cache || shader_cache->canvas_item.light_mode != RasterizerStorageGLES3::Shader::CanvasItem::LIGHT_MODE_LIGHT_ONLY) && !ci->light_masked))
|
|
|
|
- _canvas_item_render_commands(ci, current_clip, reclip);
|
|
|
|
|
|
|
|
- if ((blend_mode == RasterizerStorageGLES3::Shader::CanvasItem::BLEND_MODE_MIX || blend_mode == RasterizerStorageGLES3::Shader::CanvasItem::BLEND_MODE_PMALPHA) && p_light && !unshaded) {
|
|
|
|
|
|
+ if (light_used) {
|
|
|
|
|
|
- Light *light = p_light;
|
|
|
|
- bool light_used = false;
|
|
|
|
- VS::CanvasLightMode mode = VS::CANVAS_LIGHT_MODE_ADD;
|
|
|
|
- state.canvas_item_modulate = ci->final_modulate; // remove the canvas modulate
|
|
|
|
|
|
+ state.canvas_shader.set_conditional(CanvasShaderGLES3::USE_LIGHTING, false);
|
|
|
|
+ state.canvas_shader.set_conditional(CanvasShaderGLES3::USE_SHADOWS, false);
|
|
|
|
+ state.canvas_shader.set_conditional(CanvasShaderGLES3::SHADOW_FILTER_NEAREST, false);
|
|
|
|
+ state.canvas_shader.set_conditional(CanvasShaderGLES3::SHADOW_FILTER_PCF3, false);
|
|
|
|
+ state.canvas_shader.set_conditional(CanvasShaderGLES3::SHADOW_FILTER_PCF5, false);
|
|
|
|
+ state.canvas_shader.set_conditional(CanvasShaderGLES3::SHADOW_FILTER_PCF7, false);
|
|
|
|
+ state.canvas_shader.set_conditional(CanvasShaderGLES3::SHADOW_FILTER_PCF9, false);
|
|
|
|
+ state.canvas_shader.set_conditional(CanvasShaderGLES3::SHADOW_FILTER_PCF13, false);
|
|
|
|
|
|
- while (light) {
|
|
|
|
|
|
+ state.canvas_shader.bind();
|
|
|
|
|
|
- if (ci->light_mask & light->item_mask && p_z >= light->z_min && p_z <= light->z_max && ci->global_rect_cache.intersects_transformed(light->xform_cache, light->rect_cache)) {
|
|
|
|
|
|
+ r_ris.last_blend_mode = -1;
|
|
|
|
|
|
- //intersects this light
|
|
|
|
|
|
+ /*
|
|
|
|
+ //this is set again, so it should not be needed anyway?
|
|
|
|
+ state.canvas_item_modulate = unshaded ? ci->final_modulate : Color(
|
|
|
|
+ ci->final_modulate.r * p_modulate.r,
|
|
|
|
+ ci->final_modulate.g * p_modulate.g,
|
|
|
|
+ ci->final_modulate.b * p_modulate.b,
|
|
|
|
+ ci->final_modulate.a * p_modulate.a );
|
|
|
|
|
|
- if (!light_used || mode != light->mode) {
|
|
|
|
|
|
|
|
- mode = light->mode;
|
|
|
|
|
|
+ state.canvas_shader.set_uniform(CanvasShaderGLES3::MODELVIEW_MATRIX,state.final_transform);
|
|
|
|
+ state.canvas_shader.set_uniform(CanvasShaderGLES3::EXTRA_MATRIX,Transform2D());
|
|
|
|
+ state.canvas_shader.set_uniform(CanvasShaderGLES3::FINAL_MODULATE,state.canvas_item_modulate);
|
|
|
|
|
|
- switch (mode) {
|
|
|
|
|
|
+ glBlendEquation(GL_FUNC_ADD);
|
|
|
|
|
|
- case VS::CANVAS_LIGHT_MODE_ADD: {
|
|
|
|
- glBlendEquation(GL_FUNC_ADD);
|
|
|
|
- glBlendFunc(GL_SRC_ALPHA, GL_ONE);
|
|
|
|
|
|
+ if (storage->frame.current_rt->flags[RasterizerStorage::RENDER_TARGET_TRANSPARENT]) {
|
|
|
|
+ glBlendFuncSeparate(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA, GL_ONE, GL_ONE_MINUS_SRC_ALPHA);
|
|
|
|
+ } else {
|
|
|
|
+ glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA);
|
|
|
|
+ }
|
|
|
|
|
|
- } break;
|
|
|
|
- case VS::CANVAS_LIGHT_MODE_SUB: {
|
|
|
|
- glBlendEquation(GL_FUNC_REVERSE_SUBTRACT);
|
|
|
|
- glBlendFunc(GL_SRC_ALPHA, GL_ONE);
|
|
|
|
- } break;
|
|
|
|
- case VS::CANVAS_LIGHT_MODE_MIX:
|
|
|
|
- case VS::CANVAS_LIGHT_MODE_MASK: {
|
|
|
|
- glBlendEquation(GL_FUNC_ADD);
|
|
|
|
- glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA);
|
|
|
|
|
|
+ //@TODO RESET canvas_blend_mode
|
|
|
|
+ */
|
|
|
|
+ }
|
|
|
|
+ }
|
|
|
|
|
|
- } break;
|
|
|
|
- }
|
|
|
|
- }
|
|
|
|
|
|
+ if (reclip) {
|
|
|
|
|
|
- if (!light_used) {
|
|
|
|
|
|
+ glEnable(GL_SCISSOR_TEST);
|
|
|
|
+ int y = storage->frame.current_rt->height - (r_ris.current_clip->final_clip_rect.position.y + r_ris.current_clip->final_clip_rect.size.y);
|
|
|
|
+ if (storage->frame.current_rt->flags[RasterizerStorage::RENDER_TARGET_VFLIP])
|
|
|
|
+ y = r_ris.current_clip->final_clip_rect.position.y;
|
|
|
|
+ glScissor(r_ris.current_clip->final_clip_rect.position.x, y, r_ris.current_clip->final_clip_rect.size.width, r_ris.current_clip->final_clip_rect.size.height);
|
|
|
|
+ }
|
|
|
|
+}
|
|
|
|
|
|
- state.canvas_shader.set_conditional(CanvasShaderGLES3::USE_LIGHTING, true);
|
|
|
|
- light_used = true;
|
|
|
|
- }
|
|
|
|
|
|
+// This function is a dry run of the state changes when drawing the item.
|
|
|
|
+// It should duplicate the logic in _canvas_render_item,
|
|
|
|
+// to decide whether items are similar enough to join
|
|
|
|
+// i.e. no state differences between the 2 items.
|
|
|
|
+bool RasterizerCanvasGLES3::try_join_item(Item *p_ci, RenderItemState &r_ris, bool &r_batch_break) {
|
|
|
|
+ // if we set max join items to zero we can effectively prevent any joining, so
|
|
|
|
+ // none of the other logic needs to run. Good for testing regression bugs, and
|
|
|
|
+ // could conceivably be faster in some games.
|
|
|
|
+ if (!bdata.settings_max_join_item_commands) {
|
|
|
|
+ return false;
|
|
|
|
+ }
|
|
|
|
|
|
- bool has_shadow = light->shadow_buffer.is_valid() && ci->light_mask & light->item_shadow_mask;
|
|
|
|
|
|
+ // if there are any state changes we change join to false
|
|
|
|
+ // we also set r_batch_break to true if we don't want this item joined to the next
|
|
|
|
+ // (e.g. an item that must not be joined at all)
|
|
|
|
+ r_batch_break = false;
|
|
|
|
+ bool join = true;
|
|
|
|
|
|
- state.canvas_shader.set_conditional(CanvasShaderGLES3::USE_SHADOWS, has_shadow);
|
|
|
|
- if (has_shadow) {
|
|
|
|
- state.canvas_shader.set_conditional(CanvasShaderGLES3::SHADOW_USE_GRADIENT, light->shadow_gradient_length > 0);
|
|
|
|
- state.canvas_shader.set_conditional(CanvasShaderGLES3::SHADOW_FILTER_NEAREST, light->shadow_filter == VS::CANVAS_LIGHT_FILTER_NONE);
|
|
|
|
- state.canvas_shader.set_conditional(CanvasShaderGLES3::SHADOW_FILTER_PCF3, light->shadow_filter == VS::CANVAS_LIGHT_FILTER_PCF3);
|
|
|
|
- state.canvas_shader.set_conditional(CanvasShaderGLES3::SHADOW_FILTER_PCF5, light->shadow_filter == VS::CANVAS_LIGHT_FILTER_PCF5);
|
|
|
|
- state.canvas_shader.set_conditional(CanvasShaderGLES3::SHADOW_FILTER_PCF7, light->shadow_filter == VS::CANVAS_LIGHT_FILTER_PCF7);
|
|
|
|
- state.canvas_shader.set_conditional(CanvasShaderGLES3::SHADOW_FILTER_PCF9, light->shadow_filter == VS::CANVAS_LIGHT_FILTER_PCF9);
|
|
|
|
- state.canvas_shader.set_conditional(CanvasShaderGLES3::SHADOW_FILTER_PCF13, light->shadow_filter == VS::CANVAS_LIGHT_FILTER_PCF13);
|
|
|
|
- }
|
|
|
|
|
|
+ // light_masked may possibly need state checking here. Check for regressions!
|
|
|
|
|
|
- bool light_rebind = state.canvas_shader.bind();
|
|
|
|
|
|
+ // we will now allow joining even if final modulate is different
|
|
|
|
+ // we will instead bake the final modulate into the vertex colors
|
|
|
|
+ // if (p_ci->final_modulate != r_ris.final_modulate) {
|
|
|
|
+ // join = false;
|
|
|
|
+ // r_ris.final_modulate = p_ci->final_modulate;
|
|
|
|
+ // }
|
|
|
|
|
|
- if (light_rebind) {
|
|
|
|
- state.canvas_shader.set_uniform(CanvasShaderGLES3::FINAL_MODULATE, state.canvas_item_modulate);
|
|
|
|
- state.canvas_shader.set_uniform(CanvasShaderGLES3::MODELVIEW_MATRIX, state.final_transform);
|
|
|
|
- state.canvas_shader.set_uniform(CanvasShaderGLES3::EXTRA_MATRIX, Transform2D());
|
|
|
|
- if (storage->frame.current_rt) {
|
|
|
|
- state.canvas_shader.set_uniform(CanvasShaderGLES3::SCREEN_PIXEL_SIZE, Vector2(1.0 / storage->frame.current_rt->width, 1.0 / storage->frame.current_rt->height));
|
|
|
|
- } else {
|
|
|
|
- state.canvas_shader.set_uniform(CanvasShaderGLES3::SCREEN_PIXEL_SIZE, Vector2(1.0, 1.0));
|
|
|
|
- }
|
|
|
|
- if (state.using_skeleton) {
|
|
|
|
- state.canvas_shader.set_uniform(CanvasShaderGLES3::SKELETON_TRANSFORM, state.skeleton_transform);
|
|
|
|
- state.canvas_shader.set_uniform(CanvasShaderGLES3::SKELETON_TRANSFORM_INVERSE, state.skeleton_transform_inverse);
|
|
|
|
- }
|
|
|
|
- }
|
|
|
|
|
|
+ if (r_ris.current_clip != p_ci->final_clip_owner) {
|
|
|
|
+ r_ris.current_clip = p_ci->final_clip_owner;
|
|
|
|
+ join = false;
|
|
|
|
+ }
|
|
|
|
|
|
- glBindBufferBase(GL_UNIFORM_BUFFER, 1, static_cast<LightInternal *>(light->light_internal.get_data())->ubo);
|
|
|
|
|
|
+ // TODO: copy back buffer
|
|
|
|
|
|
- if (has_shadow) {
|
|
|
|
|
|
+ if (p_ci->copy_back_buffer) {
|
|
|
|
+ join = false;
|
|
|
|
+ }
|
|
|
|
|
|
- RasterizerStorageGLES3::CanvasLightShadow *cls = storage->canvas_light_shadow_owner.get(light->shadow_buffer);
|
|
|
|
- glActiveTexture(GL_TEXTURE0 + storage->config.max_texture_image_units - 2);
|
|
|
|
- glBindTexture(GL_TEXTURE_2D, cls->distance);
|
|
|
|
|
|
+ RasterizerStorageGLES3::Skeleton *skeleton = NULL;
|
|
|
|
|
|
- /*canvas_shader.set_uniform(CanvasShaderGLES3::SHADOW_MATRIX,light->shadow_matrix_cache);
|
|
|
|
- canvas_shader.set_uniform(CanvasShaderGLES3::SHADOW_ESM_MULTIPLIER,light->shadow_esm_mult);
|
|
|
|
- canvas_shader.set_uniform(CanvasShaderGLES3::LIGHT_SHADOW_COLOR,light->shadow_color);*/
|
|
|
|
- }
|
|
|
|
|
|
+ {
|
|
|
|
+ //skeleton handling
|
|
|
|
+ if (p_ci->skeleton.is_valid() && storage->skeleton_owner.owns(p_ci->skeleton)) {
|
|
|
|
+ skeleton = storage->skeleton_owner.get(p_ci->skeleton);
|
|
|
|
+ if (!skeleton->use_2d) {
|
|
|
|
+ skeleton = NULL;
|
|
|
|
+ }
|
|
|
|
+ }
|
|
|
|
|
|
- glActiveTexture(GL_TEXTURE0 + storage->config.max_texture_image_units - 1);
|
|
|
|
- RasterizerStorageGLES3::Texture *t = storage->texture_owner.getornull(light->texture);
|
|
|
|
- if (!t) {
|
|
|
|
- glBindTexture(GL_TEXTURE_2D, storage->resources.white_tex);
|
|
|
|
- } else {
|
|
|
|
- t = t->get_ptr();
|
|
|
|
|
|
+ bool skeleton_prevent_join = false;
|
|
|
|
|
|
- glBindTexture(t->target, t->tex_id);
|
|
|
|
- }
|
|
|
|
|
|
+ bool use_skeleton = skeleton != NULL;
|
|
|
|
+ if (r_ris.prev_use_skeleton != use_skeleton) {
|
|
|
|
|
|
- glActiveTexture(GL_TEXTURE0);
|
|
|
|
- _canvas_item_render_commands(ci, current_clip, reclip); //redraw using light
|
|
|
|
- }
|
|
|
|
|
|
+ if (!bdata.settings_use_software_skinning)
|
|
|
|
+ r_ris.rebind_shader = true;
|
|
|
|
|
|
- light = light->next_ptr;
|
|
|
|
- }
|
|
|
|
|
|
+ r_ris.prev_use_skeleton = use_skeleton;
|
|
|
|
+ // join = false;
|
|
|
|
+ skeleton_prevent_join = true;
|
|
|
|
+ }
|
|
|
|
|
|
- if (light_used) {
|
|
|
|
|
|
+ if (skeleton) {
|
|
|
|
+ // join = false;
|
|
|
|
+ skeleton_prevent_join = true;
|
|
|
|
+ state.using_skeleton = true;
|
|
|
|
+ } else {
|
|
|
|
+ state.using_skeleton = false;
|
|
|
|
+ }
|
|
|
|
|
|
- state.canvas_shader.set_conditional(CanvasShaderGLES3::USE_LIGHTING, false);
|
|
|
|
- state.canvas_shader.set_conditional(CanvasShaderGLES3::USE_SHADOWS, false);
|
|
|
|
- state.canvas_shader.set_conditional(CanvasShaderGLES3::SHADOW_FILTER_NEAREST, false);
|
|
|
|
- state.canvas_shader.set_conditional(CanvasShaderGLES3::SHADOW_FILTER_PCF3, false);
|
|
|
|
- state.canvas_shader.set_conditional(CanvasShaderGLES3::SHADOW_FILTER_PCF5, false);
|
|
|
|
- state.canvas_shader.set_conditional(CanvasShaderGLES3::SHADOW_FILTER_PCF7, false);
|
|
|
|
- state.canvas_shader.set_conditional(CanvasShaderGLES3::SHADOW_FILTER_PCF9, false);
|
|
|
|
- state.canvas_shader.set_conditional(CanvasShaderGLES3::SHADOW_FILTER_PCF13, false);
|
|
|
|
|
|
+ if (skeleton_prevent_join) {
|
|
|
|
+ if (!bdata.settings_use_software_skinning)
|
|
|
|
+ join = false;
|
|
|
|
+ }
|
|
|
|
+ }
|
|
|
|
|
|
- state.canvas_shader.bind();
|
|
|
|
|
|
+ Item *material_owner = p_ci->material_owner ? p_ci->material_owner : p_ci;
|
|
|
|
|
|
- last_blend_mode = -1;
|
|
|
|
|
|
+ RID material = material_owner->material;
|
|
|
|
+ RasterizerStorageGLES3::Material *material_ptr = storage->material_owner.getornull(material);
|
|
|
|
|
|
- /*
|
|
|
|
- //this is set again, so it should not be needed anyway?
|
|
|
|
- state.canvas_item_modulate = unshaded ? ci->final_modulate : Color(
|
|
|
|
- ci->final_modulate.r * p_modulate.r,
|
|
|
|
- ci->final_modulate.g * p_modulate.g,
|
|
|
|
- ci->final_modulate.b * p_modulate.b,
|
|
|
|
- ci->final_modulate.a * p_modulate.a );
|
|
|
|
|
|
+ if (material != r_ris.canvas_last_material || r_ris.rebind_shader) {
|
|
|
|
|
|
|
|
+ join = false;
|
|
|
|
+ RasterizerStorageGLES3::Shader *shader_ptr = NULL;
|
|
|
|
|
|
- state.canvas_shader.set_uniform(CanvasShaderGLES3::MODELVIEW_MATRIX,state.final_transform);
|
|
|
|
- state.canvas_shader.set_uniform(CanvasShaderGLES3::EXTRA_MATRIX,Transform2D());
|
|
|
|
- state.canvas_shader.set_uniform(CanvasShaderGLES3::FINAL_MODULATE,state.canvas_item_modulate);
|
|
|
|
|
|
+ if (material_ptr) {
|
|
|
|
+ shader_ptr = material_ptr->shader;
|
|
|
|
|
|
- glBlendEquation(GL_FUNC_ADD);
|
|
|
|
|
|
+ if (shader_ptr && shader_ptr->mode != VS::SHADER_CANVAS_ITEM) {
|
|
|
|
+ shader_ptr = NULL; // not a canvas item shader, don't use.
|
|
|
|
+ }
|
|
|
|
+ }
|
|
|
|
|
|
- if (storage->frame.current_rt->flags[RasterizerStorage::RENDER_TARGET_TRANSPARENT]) {
|
|
|
|
- glBlendFuncSeparate(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA, GL_ONE, GL_ONE_MINUS_SRC_ALPHA);
|
|
|
|
- } else {
|
|
|
|
- glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA);
|
|
|
|
|
|
+ if (shader_ptr) {
|
|
|
|
+ if (shader_ptr->canvas_item.uses_screen_texture) {
|
|
|
|
+ if (!state.canvas_texscreen_used) {
|
|
|
|
+ join = false;
|
|
}
|
|
}
|
|
-
|
|
|
|
- //@TODO RESET canvas_blend_mode
|
|
|
|
- */
|
|
|
|
}
|
|
}
|
|
}
|
|
}
|
|
|
|
|
|
- if (reclip) {
|
|
|
|
|
|
+ r_ris.shader_cache = shader_ptr;
|
|
|
|
|
|
- glEnable(GL_SCISSOR_TEST);
|
|
|
|
- int y = storage->frame.current_rt->height - (current_clip->final_clip_rect.position.y + current_clip->final_clip_rect.size.y);
|
|
|
|
- if (storage->frame.current_rt->flags[RasterizerStorage::RENDER_TARGET_VFLIP])
|
|
|
|
- y = current_clip->final_clip_rect.position.y;
|
|
|
|
- glScissor(current_clip->final_clip_rect.position.x, y, current_clip->final_clip_rect.size.width, current_clip->final_clip_rect.size.height);
|
|
|
|
- }
|
|
|
|
|
|
+ r_ris.canvas_last_material = material;
|
|
|
|
|
|
- p_item_list = p_item_list->next;
|
|
|
|
|
|
+ r_ris.rebind_shader = false;
|
|
}
|
|
}
|
|
|
|
|
|
- if (current_clip) {
|
|
|
|
- glDisable(GL_SCISSOR_TEST);
|
|
|
|
|
|
+ int blend_mode = r_ris.shader_cache ? r_ris.shader_cache->canvas_item.blend_mode : RasterizerStorageGLES3::Shader::CanvasItem::BLEND_MODE_MIX;
|
|
|
|
+ bool unshaded = r_ris.shader_cache && (r_ris.shader_cache->canvas_item.light_mode == RasterizerStorageGLES3::Shader::CanvasItem::LIGHT_MODE_UNSHADED || (blend_mode != RasterizerStorageGLES3::Shader::CanvasItem::BLEND_MODE_MIX && blend_mode != RasterizerStorageGLES3::Shader::CanvasItem::BLEND_MODE_PMALPHA));
|
|
|
|
+ bool reclip = false;
|
|
|
|
+
|
|
|
|
+ // we are precalculating the final_modulate ahead of time because we need this for baking of final modulate into vertex colors
|
|
|
|
+ // (only in software transform mode)
|
|
|
|
+ // This maybe inefficient storing it...
|
|
|
|
+ r_ris.final_modulate = unshaded ? p_ci->final_modulate : (p_ci->final_modulate * r_ris.item_group_modulate);
|
|
|
|
+
|
|
|
|
+ if (r_ris.last_blend_mode != blend_mode) {
|
|
|
|
+ join = false;
|
|
|
|
+ r_ris.last_blend_mode = blend_mode;
|
|
}
|
|
}
|
|
- //disable states that may have been used
|
|
|
|
- state.canvas_shader.set_conditional(CanvasShaderGLES3::USE_DISTANCE_FIELD, false);
|
|
|
|
- state.canvas_shader.set_conditional(CanvasShaderGLES3::USE_SKELETON, false);
|
|
|
|
- state.canvas_shader.set_conditional(CanvasShaderGLES3::USE_INSTANCE_CUSTOM, false);
|
|
|
|
- state.canvas_shader.set_conditional(CanvasShaderGLES3::USE_PARTICLES, false);
|
|
|
|
- state.canvas_shader.set_conditional(CanvasShaderGLES3::USE_INSTANCING, false);
|
|
|
|
- state.canvas_shader.set_conditional(CanvasShaderGLES3::USE_LIGHTING, false);
|
|
|
|
- state.canvas_shader.set_conditional(CanvasShaderGLES3::USE_SHADOWS, false);
|
|
|
|
-}
|
|
|
|
|
|
|
|
-void RasterizerCanvasGLES3::canvas_debug_viewport_shadows(Light *p_lights_with_shadow) {
|
|
|
|
|
|
+ // does the shader contain BUILTINs which should break the batching?
|
|
|
|
+ bdata.joined_item_batch_flags = 0;
|
|
|
|
+ if (r_ris.shader_cache) {
|
|
|
|
|
|
- Light *light = p_lights_with_shadow;
|
|
|
|
|
|
+ unsigned int and_flags = r_ris.shader_cache->canvas_item.batch_flags & (RasterizerStorageCommon::PREVENT_COLOR_BAKING | RasterizerStorageCommon::PREVENT_VERTEX_BAKING);
|
|
|
|
+ if (and_flags) {
|
|
|
|
|
|
- canvas_begin(); //reset
|
|
|
|
- glVertexAttrib4f(VS::ARRAY_COLOR, 1, 1, 1, 1);
|
|
|
|
- int h = 10;
|
|
|
|
- int w = storage->frame.current_rt->width;
|
|
|
|
- int ofs = h;
|
|
|
|
- glDisable(GL_BLEND);
|
|
|
|
|
|
+ bool use_larger_fvfs = true;
|
|
|
|
|
|
- while (light) {
|
|
|
|
- if (light->shadow_buffer.is_valid()) {
|
|
|
|
|
|
+ if (and_flags == RasterizerStorageCommon::PREVENT_COLOR_BAKING) {
|
|
|
|
+ // in some circumstances, if the modulate is identity, we still allow baking because reading modulate / color
|
|
|
|
+ // will still be okay to do in the shader with no ill effects
|
|
|
|
+ if (r_ris.final_modulate == Color(1, 1, 1, 1)) {
|
|
|
|
+ use_larger_fvfs = false;
|
|
|
|
+ }
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ // new .. always use large FVF
|
|
|
|
+ if (use_larger_fvfs) {
|
|
|
|
+ if (and_flags == RasterizerStorageCommon::PREVENT_COLOR_BAKING) {
|
|
|
|
+ bdata.joined_item_batch_flags |= RasterizerStorageCommon::USE_MODULATE_FVF;
|
|
|
|
+ } else {
|
|
|
|
+ // we need to save on the joined item that it should use large fvf.
|
|
|
|
+ // This info will then be used in filling and rendering
|
|
|
|
+ bdata.joined_item_batch_flags |= RasterizerStorageCommon::USE_LARGE_FVF;
|
|
|
|
+ }
|
|
|
|
|
|
- RasterizerStorageGLES3::CanvasLightShadow *sb = storage->canvas_light_shadow_owner.get(light->shadow_buffer);
|
|
|
|
- if (sb) {
|
|
|
|
- glBindTexture(GL_TEXTURE_2D, sb->distance);
|
|
|
|
- draw_generic_textured_rect(Rect2(h, ofs, w - h * 2, h), Rect2(0, 0, 1, 1));
|
|
|
|
- ofs += h * 2;
|
|
|
|
|
|
+ bdata.joined_item_batch_flags |= r_ris.shader_cache->canvas_item.batch_flags;
|
|
}
|
|
}
|
|
}
|
|
}
|
|
-
|
|
|
|
- light = light->shadows_next_ptr;
|
|
|
|
}
|
|
}
|
|
|
|
|
|
- canvas_end();
|
|
|
|
-}
|
|
|
|
-
|
|
|
|
-void RasterizerCanvasGLES3::canvas_light_shadow_buffer_update(RID p_buffer, const Transform2D &p_light_xform, int p_light_mask, float p_near, float p_far, LightOccluderInstance *p_occluders, CameraMatrix *p_xform_cache) {
|
|
|
|
|
|
+ if ((blend_mode == RasterizerStorageGLES3::Shader::CanvasItem::BLEND_MODE_MIX || blend_mode == RasterizerStorageGLES3::Shader::CanvasItem::BLEND_MODE_PMALPHA) && r_ris.item_group_light && !unshaded) {
|
|
|
|
|
|
- RasterizerStorageGLES3::CanvasLightShadow *cls = storage->canvas_light_shadow_owner.get(p_buffer);
|
|
|
|
- ERR_FAIL_COND(!cls);
|
|
|
|
|
|
+ // we cannot join lit items easily.
|
|
|
|
+ // it is possible, but not if they overlap, because
|
|
|
|
+ // a + light_blend + b + light_blend IS NOT THE SAME AS
|
|
|
|
+ // a + b + light_blend
|
|
|
|
|
|
- glDisable(GL_BLEND);
|
|
|
|
- glDisable(GL_SCISSOR_TEST);
|
|
|
|
- glDisable(GL_DITHER);
|
|
|
|
- glDisable(GL_CULL_FACE);
|
|
|
|
- glDepthFunc(GL_LEQUAL);
|
|
|
|
- glEnable(GL_DEPTH_TEST);
|
|
|
|
- glDepthMask(true);
|
|
|
|
-
|
|
|
|
- glBindFramebuffer(GL_FRAMEBUFFER, cls->fbo);
|
|
|
|
|
|
+ bool light_allow_join = true;
|
|
|
|
|
|
- state.canvas_shadow_shader.bind();
|
|
|
|
|
|
+ // this is a quick getout if we have turned off light joining
|
|
|
|
+ if ((bdata.settings_light_max_join_items == 0) || r_ris.light_region.too_many_lights) {
|
|
|
|
+ light_allow_join = false;
|
|
|
|
+ } else {
|
|
|
|
+ // do light joining...
|
|
|
|
|
|
- glViewport(0, 0, cls->size, cls->height);
|
|
|
|
- glClearDepth(1.0f);
|
|
|
|
- glClearColor(1, 1, 1, 1);
|
|
|
|
- glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
|
|
|
|
|
|
+ // first calculate the light bitfield
|
|
|
|
+ uint64_t light_bitfield = 0;
|
|
|
|
+ uint64_t shadow_bitfield = 0;
|
|
|
|
+ Light *light = r_ris.item_group_light;
|
|
|
|
|
|
- VS::CanvasOccluderPolygonCullMode cull = VS::CANVAS_OCCLUDER_POLYGON_CULL_DISABLED;
|
|
|
|
|
|
+ int light_count = -1;
|
|
|
|
+ while (light) {
|
|
|
|
+ light_count++;
|
|
|
|
+ uint64_t light_bit = 1ULL << light_count;
|
|
|
|
|
|
- for (int i = 0; i < 4; i++) {
|
|
|
|
|
|
+ // note that as a cost of batching, the light culling will be less effective
|
|
|
|
+ if (p_ci->light_mask & light->item_mask && r_ris.item_group_z >= light->z_min && r_ris.item_group_z <= light->z_max) {
|
|
|
|
|
|
- //make sure it remains orthogonal, makes easy to read angle later
|
|
|
|
|
|
+ // Note that with the above test, it is possible to also include a bound check.
|
|
|
|
+ // Tests so far have indicated better performance without it, but there may be reason to change this at a later stage,
|
|
|
|
+ // so I leave the line here for reference:
|
|
|
|
+ // && p_ci->global_rect_cache.intersects_transformed(light->xform_cache, light->rect_cache)) {
|
|
|
|
|
|
- Transform light;
|
|
|
|
- light.origin[0] = p_light_xform[2][0];
|
|
|
|
- light.origin[1] = p_light_xform[2][1];
|
|
|
|
- light.basis[0][0] = p_light_xform[0][0];
|
|
|
|
- light.basis[0][1] = p_light_xform[1][0];
|
|
|
|
- light.basis[1][0] = p_light_xform[0][1];
|
|
|
|
- light.basis[1][1] = p_light_xform[1][1];
|
|
|
|
|
|
+ light_bitfield |= light_bit;
|
|
|
|
|
|
- //light.basis.scale(Vector3(to_light.elements[0].length(),to_light.elements[1].length(),1));
|
|
|
|
|
|
+ bool has_shadow = light->shadow_buffer.is_valid() && p_ci->light_mask & light->item_shadow_mask;
|
|
|
|
|
|
- //p_near=1;
|
|
|
|
- CameraMatrix projection;
|
|
|
|
- {
|
|
|
|
- real_t fov = 90;
|
|
|
|
- real_t nearp = p_near;
|
|
|
|
- real_t farp = p_far;
|
|
|
|
- real_t aspect = 1.0;
|
|
|
|
|
|
+ if (has_shadow) {
|
|
|
|
+ shadow_bitfield |= light_bit;
|
|
|
|
+ }
|
|
|
|
+ }
|
|
|
|
|
|
- real_t ymax = nearp * Math::tan(Math::deg2rad(fov * 0.5));
|
|
|
|
- real_t ymin = -ymax;
|
|
|
|
- real_t xmin = ymin * aspect;
|
|
|
|
- real_t xmax = ymax * aspect;
|
|
|
|
|
|
+ light = light->next_ptr;
|
|
|
|
+ }
|
|
|
|
|
|
- projection.set_frustum(xmin, xmax, ymin, ymax, nearp, farp);
|
|
|
|
- }
|
|
|
|
|
|
+ // now compare to previous
|
|
|
|
+ if ((r_ris.light_region.light_bitfield != light_bitfield) || (r_ris.light_region.shadow_bitfield != shadow_bitfield)) {
|
|
|
|
+ light_allow_join = false;
|
|
|
|
|
|
- Vector3 cam_target = Basis(Vector3(0, 0, Math_PI * 2 * (i / 4.0))).xform(Vector3(0, 1, 0));
|
|
|
|
- projection = projection * CameraMatrix(Transform().looking_at(cam_target, Vector3(0, 0, -1)).affine_inverse());
|
|
|
|
|
|
+ r_ris.light_region.light_bitfield = light_bitfield;
|
|
|
|
+ r_ris.light_region.shadow_bitfield = shadow_bitfield;
|
|
|
|
+ } else {
|
|
|
|
+ // only do these checks if necessary
|
|
|
|
+ if (join && (!r_batch_break)) {
|
|
|
|
+
|
|
|
|
+ // we still can't join, even if the lights are exactly the same, if there is overlap between the previous and this item
|
|
|
|
+ if (r_ris.joined_item && light_bitfield) {
|
|
|
|
+ if ((int)r_ris.joined_item->num_item_refs <= bdata.settings_light_max_join_items) {
|
|
|
|
+ for (uint32_t r = 0; r < r_ris.joined_item->num_item_refs; r++) {
|
|
|
|
+ Item *pRefItem = bdata.item_refs[r_ris.joined_item->first_item_ref + r].item;
|
|
|
|
+ if (p_ci->global_rect_cache.intersects(pRefItem->global_rect_cache)) {
|
|
|
|
+ light_allow_join = false;
|
|
|
|
+ break;
|
|
|
|
+ }
|
|
|
|
+ }
|
|
|
|
|
|
- state.canvas_shadow_shader.set_uniform(CanvasShadowShaderGLES3::PROJECTION_MATRIX, projection);
|
|
|
|
- state.canvas_shadow_shader.set_uniform(CanvasShadowShaderGLES3::LIGHT_MATRIX, light);
|
|
|
|
- state.canvas_shadow_shader.set_uniform(CanvasShadowShaderGLES3::DISTANCE_NORM, 1.0 / p_far);
|
|
|
|
|
|
+#ifdef DEBUG_ENABLED
|
|
|
|
+ if (light_allow_join) {
|
|
|
|
+ bdata.stats_light_items_joined++;
|
|
|
|
+ }
|
|
|
|
+#endif
|
|
|
|
|
|
- if (i == 0)
|
|
|
|
- *p_xform_cache = projection;
|
|
|
|
|
|
+ } // if below max join items
|
|
|
|
+ else {
|
|
|
|
+ // just don't allow joining if above overlap check max items
|
|
|
|
+ light_allow_join = false;
|
|
|
|
+ }
|
|
|
|
+ }
|
|
|
|
|
|
- glViewport(0, (cls->height / 4) * i, cls->size, cls->height / 4);
|
|
|
|
|
|
+ } // if not batch broken already (no point in doing expensive overlap tests if not needed)
|
|
|
|
+ } // if bitfields don't match
|
|
|
|
+ } // if do light joining
|
|
|
|
|
|
- LightOccluderInstance *instance = p_occluders;
|
|
|
|
|
|
+ if (!light_allow_join) {
|
|
|
|
+ // can't join
|
|
|
|
+ join = false;
|
|
|
|
+ // we also dont want to allow joining this item with the next item, because the next item could have no lights!
|
|
|
|
+ r_batch_break = true;
|
|
|
|
+ }
|
|
|
|
|
|
- while (instance) {
|
|
|
|
|
|
+ } else {
|
|
|
|
+ // if the last item had lights, we should not join it to this one (which has no lights)
|
|
|
|
+ if (r_ris.light_region.light_bitfield || r_ris.light_region.shadow_bitfield) {
|
|
|
|
+ join = false;
|
|
|
|
+
|
|
|
|
+ // setting these to zero ensures that any following item with lights will, by definition,
|
|
|
|
+ // be affected by a different set of lights, and thus prevent a join
|
|
|
|
+ r_ris.light_region.light_bitfield = 0;
|
|
|
|
+ r_ris.light_region.shadow_bitfield = 0;
|
|
|
|
+ }
|
|
|
|
+ }
|
|
|
|
|
|
- RasterizerStorageGLES3::CanvasOccluder *cc = storage->canvas_occluder_owner.getornull(instance->polygon_buffer);
|
|
|
|
- if (!cc || cc->len == 0 || !(p_light_mask & instance->light_mask)) {
|
|
|
|
|
|
+ if (reclip) {
|
|
|
|
+ join = false;
|
|
|
|
+ }
|
|
|
|
|
|
- instance = instance->next;
|
|
|
|
- continue;
|
|
|
|
- }
|
|
|
|
|
|
+ // non rects will break the batching anyway, we don't want to record item changes, detect this
|
|
|
|
+ if (!r_batch_break && _detect_item_batch_break(r_ris, p_ci, r_batch_break)) {
|
|
|
|
+ join = false;
|
|
|
|
+ r_batch_break = true;
|
|
|
|
+ }
|
|
|
|
|
|
- state.canvas_shadow_shader.set_uniform(CanvasShadowShaderGLES3::WORLD_MATRIX, instance->xform_cache);
|
|
|
|
|
|
+ return join;
|
|
|
|
+}
|
|
|
|
|
|
- VS::CanvasOccluderPolygonCullMode transformed_cull_cache = instance->cull_cache;
|
|
|
|
|
|
+void RasterizerCanvasGLES3::canvas_render_items_implementation(Item *p_item_list, int p_z, const Color &p_modulate, Light *p_light, const Transform2D &p_base_transform) {
|
|
|
|
|
|
- if (transformed_cull_cache != VS::CANVAS_OCCLUDER_POLYGON_CULL_DISABLED &&
|
|
|
|
- (p_light_xform.basis_determinant() * instance->xform_cache.basis_determinant()) < 0) {
|
|
|
|
- transformed_cull_cache =
|
|
|
|
- transformed_cull_cache == VS::CANVAS_OCCLUDER_POLYGON_CULL_CLOCKWISE ?
|
|
|
|
- VS::CANVAS_OCCLUDER_POLYGON_CULL_COUNTER_CLOCKWISE :
|
|
|
|
- VS::CANVAS_OCCLUDER_POLYGON_CULL_CLOCKWISE;
|
|
|
|
- }
|
|
|
|
|
|
+ // parameters are easier to pass around in a structure
|
|
|
|
+ RenderItemState ris;
|
|
|
|
+ ris.item_group_z = p_z;
|
|
|
|
+ ris.item_group_modulate = p_modulate;
|
|
|
|
+ ris.item_group_light = p_light;
|
|
|
|
+ ris.item_group_base_transform = p_base_transform;
|
|
|
|
+ ris.prev_distance_field = false;
|
|
|
|
|
|
- if (cull != transformed_cull_cache) {
|
|
|
|
|
|
+ glBindBuffer(GL_UNIFORM_BUFFER, state.canvas_item_ubo);
|
|
|
|
+ glBufferData(GL_UNIFORM_BUFFER, sizeof(CanvasItemUBO), &state.canvas_item_ubo_data, GL_DYNAMIC_DRAW);
|
|
|
|
+ glBindBuffer(GL_UNIFORM_BUFFER, 0);
|
|
|
|
|
|
- cull = transformed_cull_cache;
|
|
|
|
- switch (cull) {
|
|
|
|
- case VS::CANVAS_OCCLUDER_POLYGON_CULL_DISABLED: {
|
|
|
|
|
|
+ state.current_tex = RID();
|
|
|
|
+ state.current_tex_ptr = NULL;
|
|
|
|
+ state.current_normal = RID();
|
|
|
|
+ glActiveTexture(GL_TEXTURE0);
|
|
|
|
+ glBindTexture(GL_TEXTURE_2D, storage->resources.white_tex);
|
|
|
|
|
|
- glDisable(GL_CULL_FACE);
|
|
|
|
|
|
+ // state.canvas_shader.set_conditional(CanvasShaderGLES3::USE_SKELETON, false);
|
|
|
|
+ // state.current_tex = RID();
|
|
|
|
+ // state.current_tex_ptr = NULL;
|
|
|
|
+ // state.current_normal = RID();
|
|
|
|
+ // state.canvas_texscreen_used = false;
|
|
|
|
+ // glActiveTexture(GL_TEXTURE0);
|
|
|
|
+ // glBindTexture(GL_TEXTURE_2D, storage->resources.white_tex);
|
|
|
|
+
|
|
|
|
+ if (bdata.settings_use_batching) {
|
|
|
|
+ for (int j = 0; j < bdata.items_joined.size(); j++) {
|
|
|
|
+ render_joined_item(bdata.items_joined[j], ris);
|
|
|
|
+ }
|
|
|
|
+ } else {
|
|
|
|
+ while (p_item_list) {
|
|
|
|
|
|
- } break;
|
|
|
|
- case VS::CANVAS_OCCLUDER_POLYGON_CULL_CLOCKWISE: {
|
|
|
|
|
|
+ Item *ci = p_item_list;
|
|
|
|
+ _legacy_canvas_render_item(ci, ris);
|
|
|
|
+ p_item_list = p_item_list->next;
|
|
|
|
+ }
|
|
|
|
+ }
|
|
|
|
|
|
- glEnable(GL_CULL_FACE);
|
|
|
|
- glCullFace(GL_FRONT);
|
|
|
|
- } break;
|
|
|
|
- case VS::CANVAS_OCCLUDER_POLYGON_CULL_COUNTER_CLOCKWISE: {
|
|
|
|
|
|
+ if (ris.current_clip) {
|
|
|
|
+ glDisable(GL_SCISSOR_TEST);
|
|
|
|
+ }
|
|
|
|
|
|
- glEnable(GL_CULL_FACE);
|
|
|
|
- glCullFace(GL_BACK);
|
|
|
|
|
|
+ state.canvas_shader.set_conditional(CanvasShaderGLES3::USE_SKELETON, false);
|
|
|
|
+}
|
|
|
|
|
|
- } break;
|
|
|
|
- }
|
|
|
|
- }
|
|
|
|
|
|
+void RasterizerCanvasGLES3::_batch_upload_buffers() {
|
|
|
|
|
|
- glBindVertexArray(cc->array_id);
|
|
|
|
- glDrawElements(GL_TRIANGLES, cc->len * 3, GL_UNSIGNED_SHORT, 0);
|
|
|
|
|
|
+ // noop?
|
|
|
|
+ if (!bdata.vertices.size())
|
|
|
|
+ return;
|
|
|
|
|
|
- instance = instance->next;
|
|
|
|
- }
|
|
|
|
|
|
+ glBindBuffer(GL_ARRAY_BUFFER, bdata.gl_vertex_buffer);
|
|
|
|
+
|
|
|
|
+ // orphan the old (for now)
|
|
|
|
+ //glBufferData(GL_ARRAY_BUFFER, 0, 0, GL_DYNAMIC_DRAW);
|
|
|
|
+
|
|
|
|
+ switch (bdata.fvf) {
|
|
|
|
+ case RasterizerStorageCommon::FVF_UNBATCHED: // should not happen
|
|
|
|
+ break;
|
|
|
|
+ case RasterizerStorageCommon::FVF_REGULAR: // no change
|
|
|
|
+ glBufferData(GL_ARRAY_BUFFER, sizeof(BatchVertex) * bdata.vertices.size(), bdata.vertices.get_data(), GL_DYNAMIC_DRAW);
|
|
|
|
+ break;
|
|
|
|
+ case RasterizerStorageCommon::FVF_COLOR:
|
|
|
|
+ glBufferData(GL_ARRAY_BUFFER, sizeof(BatchVertexColored) * bdata.unit_vertices.size(), bdata.unit_vertices.get_unit(0), GL_DYNAMIC_DRAW);
|
|
|
|
+ break;
|
|
|
|
+ case RasterizerStorageCommon::FVF_LIGHT_ANGLE:
|
|
|
|
+ glBufferData(GL_ARRAY_BUFFER, sizeof(BatchVertexLightAngled) * bdata.unit_vertices.size(), bdata.unit_vertices.get_unit(0), GL_DYNAMIC_DRAW);
|
|
|
|
+ break;
|
|
|
|
+ case RasterizerStorageCommon::FVF_MODULATED:
|
|
|
|
+ glBufferData(GL_ARRAY_BUFFER, sizeof(BatchVertexModulated) * bdata.unit_vertices.size(), bdata.unit_vertices.get_unit(0), GL_DYNAMIC_DRAW);
|
|
|
|
+ break;
|
|
|
|
+ case RasterizerStorageCommon::FVF_LARGE:
|
|
|
|
+ glBufferData(GL_ARRAY_BUFFER, sizeof(BatchVertexLarge) * bdata.unit_vertices.size(), bdata.unit_vertices.get_unit(0), GL_DYNAMIC_DRAW);
|
|
|
|
+ break;
|
|
}
|
|
}
|
|
|
|
|
|
- glBindVertexArray(0);
|
|
|
|
|
|
+ // might not be necessary
|
|
|
|
+ glBindBuffer(GL_ARRAY_BUFFER, 0);
|
|
}
|
|
}
|
|
-void RasterizerCanvasGLES3::reset_canvas() {
|
|
|
|
|
|
|
|
- if (storage->frame.current_rt) {
|
|
|
|
- glBindFramebuffer(GL_FRAMEBUFFER, storage->frame.current_rt->fbo);
|
|
|
|
- glColorMask(1, 1, 1, 1); //don't touch alpha
|
|
|
|
- }
|
|
|
|
|
|
+void RasterizerCanvasGLES3::_batch_render_lines(const Batch &p_batch, RasterizerStorageGLES3::Material *p_material, bool p_anti_alias) {
|
|
|
|
|
|
- glBindVertexArray(0);
|
|
|
|
- glDisable(GL_CULL_FACE);
|
|
|
|
- glDisable(GL_DEPTH_TEST);
|
|
|
|
- glDisable(GL_SCISSOR_TEST);
|
|
|
|
- glDisable(GL_DITHER);
|
|
|
|
- glEnable(GL_BLEND);
|
|
|
|
- glBlendEquation(GL_FUNC_ADD);
|
|
|
|
- if (storage->frame.current_rt && storage->frame.current_rt->flags[RasterizerStorage::RENDER_TARGET_TRANSPARENT]) {
|
|
|
|
- glBlendFuncSeparate(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA, GL_ONE, GL_ONE_MINUS_SRC_ALPHA);
|
|
|
|
- } else {
|
|
|
|
- glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA);
|
|
|
|
- }
|
|
|
|
- //glPolygonMode(GL_FRONT_AND_BACK,GL_FILL);
|
|
|
|
- //glLineWidth(1.0);
|
|
|
|
- glBindBuffer(GL_ARRAY_BUFFER, 0);
|
|
|
|
- glBindBuffer(GL_ELEMENT_ARRAY_BUFFER, 0);
|
|
|
|
|
|
+ _set_texture_rect_mode(false);
|
|
|
|
|
|
- //use for reading from screen
|
|
|
|
- if (storage->frame.current_rt && !storage->frame.current_rt->flags[RasterizerStorage::RENDER_TARGET_NO_SAMPLING]) {
|
|
|
|
- glActiveTexture(GL_TEXTURE0 + storage->config.max_texture_image_units - 3);
|
|
|
|
- glBindTexture(GL_TEXTURE_2D, storage->frame.current_rt->effects.mip_maps[0].color);
|
|
|
|
- }
|
|
|
|
|
|
+ _bind_canvas_texture(RID(), RID());
|
|
|
|
|
|
- glActiveTexture(GL_TEXTURE0);
|
|
|
|
- glBindTexture(GL_TEXTURE_2D, storage->resources.white_tex);
|
|
|
|
|
|
+ glBindVertexArray(batch_gl_data.batch_vertex_array[0]);
|
|
|
|
|
|
- glVertexAttrib4f(VS::ARRAY_COLOR, 1, 1, 1, 1);
|
|
|
|
|
|
+ glDisableVertexAttribArray(VS::ARRAY_COLOR);
|
|
|
|
+ glVertexAttrib4fv(VS::ARRAY_COLOR, (float *)&p_batch.color);
|
|
|
|
|
|
- Transform canvas_transform;
|
|
|
|
|
|
+ int64_t offset = p_batch.first_vert; // 6 inds per quad at 2 bytes each
|
|
|
|
|
|
- if (storage->frame.current_rt) {
|
|
|
|
|
|
+ int num_elements = p_batch.num_commands * 2;
|
|
|
|
|
|
- float csy = 1.0;
|
|
|
|
- if (storage->frame.current_rt && storage->frame.current_rt->flags[RasterizerStorage::RENDER_TARGET_VFLIP]) {
|
|
|
|
- csy = -1.0;
|
|
|
|
- }
|
|
|
|
- canvas_transform.translate(-(storage->frame.current_rt->width / 2.0f), -(storage->frame.current_rt->height / 2.0f), 0.0f);
|
|
|
|
- canvas_transform.scale(Vector3(2.0f / storage->frame.current_rt->width, csy * -2.0f / storage->frame.current_rt->height, 1.0f));
|
|
|
|
- } else {
|
|
|
|
- Vector2 ssize = OS::get_singleton()->get_window_size();
|
|
|
|
- canvas_transform.translate(-(ssize.width / 2.0f), -(ssize.height / 2.0f), 0.0f);
|
|
|
|
- canvas_transform.scale(Vector3(2.0f / ssize.width, -2.0f / ssize.height, 1.0f));
|
|
|
|
- }
|
|
|
|
|
|
+#ifdef GLES_OVER_GL
|
|
|
|
+ if (p_anti_alias)
|
|
|
|
+ glEnable(GL_LINE_SMOOTH);
|
|
|
|
+#endif
|
|
|
|
|
|
- state.vp = canvas_transform;
|
|
|
|
|
|
+ glDrawArrays(GL_LINES, offset, num_elements);
|
|
|
|
|
|
- store_transform(canvas_transform, state.canvas_item_ubo_data.projection_matrix);
|
|
|
|
- state.canvas_item_ubo_data.time = storage->frame.time[0];
|
|
|
|
|
|
+ storage->info.render._2d_draw_call_count++;
|
|
|
|
|
|
- glBindBuffer(GL_UNIFORM_BUFFER, state.canvas_item_ubo);
|
|
|
|
- glBufferData(GL_UNIFORM_BUFFER, sizeof(CanvasItemUBO), &state.canvas_item_ubo_data, GL_DYNAMIC_DRAW);
|
|
|
|
- glBindBuffer(GL_UNIFORM_BUFFER, 0);
|
|
|
|
|
|
+ glBindVertexArray(0);
|
|
|
|
|
|
- state.canvas_texscreen_used = false;
|
|
|
|
|
|
+#ifdef GLES_OVER_GL
|
|
|
|
+ if (p_anti_alias)
|
|
|
|
+ glDisable(GL_LINE_SMOOTH);
|
|
|
|
+#endif
|
|
}
|
|
}
|
|
|
|
|
|
-void RasterizerCanvasGLES3::draw_generic_textured_rect(const Rect2 &p_rect, const Rect2 &p_src) {
|
|
|
|
|
|
+void RasterizerCanvasGLES3::_batch_render_polys(const Batch &p_batch, RasterizerStorageGLES3::Material *p_material) {
|
|
|
|
+ ERR_FAIL_COND(p_batch.num_commands <= 0);
|
|
|
|
|
|
- state.canvas_shader.set_uniform(CanvasShaderGLES3::DST_RECT, Color(p_rect.position.x, p_rect.position.y, p_rect.size.x, p_rect.size.y));
|
|
|
|
- state.canvas_shader.set_uniform(CanvasShaderGLES3::SRC_RECT, Color(p_src.position.x, p_src.position.y, p_src.size.x, p_src.size.y));
|
|
|
|
|
|
+ _set_texture_rect_mode(false);
|
|
state.canvas_shader.set_uniform(CanvasShaderGLES3::CLIP_RECT_UV, false);
|
|
state.canvas_shader.set_uniform(CanvasShaderGLES3::CLIP_RECT_UV, false);
|
|
|
|
|
|
- glDrawArrays(GL_TRIANGLE_FAN, 0, 4);
|
|
|
|
-}
|
|
|
|
|
|
+ glBindVertexArray(batch_gl_data.batch_vertex_array[1]);
|
|
|
|
|
|
-void RasterizerCanvasGLES3::draw_lens_distortion_rect(const Rect2 &p_rect, float p_k1, float p_k2, const Vector2 &p_eye_center, float p_oversample) {
|
|
|
|
- Vector2 half_size;
|
|
|
|
- if (storage->frame.current_rt) {
|
|
|
|
- half_size = Vector2(storage->frame.current_rt->width, storage->frame.current_rt->height);
|
|
|
|
- } else {
|
|
|
|
- half_size = OS::get_singleton()->get_window_size();
|
|
|
|
- }
|
|
|
|
- half_size *= 0.5;
|
|
|
|
- Vector2 offset((p_rect.position.x - half_size.x) / half_size.x, (p_rect.position.y - half_size.y) / half_size.y);
|
|
|
|
- Vector2 scale(p_rect.size.x / half_size.x, p_rect.size.y / half_size.y);
|
|
|
|
|
|
+ // batch tex
|
|
|
|
+ const BatchTex &tex = bdata.batch_textures[p_batch.batch_texture_id];
|
|
|
|
+
|
|
|
|
+ _bind_canvas_texture(tex.RID_texture, tex.RID_normal);
|
|
|
|
|
|
- float aspect_ratio = p_rect.size.x / p_rect.size.y;
|
|
|
|
|
|
+ // may not need this disable
|
|
|
|
+ // glDisableVertexAttribArray(VS::ARRAY_COLOR);
|
|
|
|
+ // glVertexAttrib4fv(VS::ARRAY_COLOR, p_batch.color.get_data());
|
|
|
|
|
|
- // setup our lens shader
|
|
|
|
- state.lens_shader.bind();
|
|
|
|
- state.lens_shader.set_uniform(LensDistortedShaderGLES3::OFFSET, offset);
|
|
|
|
- state.lens_shader.set_uniform(LensDistortedShaderGLES3::SCALE, scale);
|
|
|
|
- state.lens_shader.set_uniform(LensDistortedShaderGLES3::K1, p_k1);
|
|
|
|
- state.lens_shader.set_uniform(LensDistortedShaderGLES3::K2, p_k2);
|
|
|
|
- state.lens_shader.set_uniform(LensDistortedShaderGLES3::EYE_CENTER, p_eye_center);
|
|
|
|
- state.lens_shader.set_uniform(LensDistortedShaderGLES3::UPSCALE, p_oversample);
|
|
|
|
- state.lens_shader.set_uniform(LensDistortedShaderGLES3::ASPECT_RATIO, aspect_ratio);
|
|
|
|
|
|
+ // we need to convert explicitly from pod Vec2 to Vector2 ...
|
|
|
|
+ // could use a cast but this might be unsafe in future
|
|
|
|
+ Vector2 tps;
|
|
|
|
+ tex.tex_pixel_size.to(tps);
|
|
|
|
+ state.canvas_shader.set_uniform(CanvasShaderGLES3::COLOR_TEXPIXEL_SIZE, tps);
|
|
|
|
|
|
- glBindBufferBase(GL_UNIFORM_BUFFER, 0, state.canvas_item_ubo);
|
|
|
|
- glBindVertexArray(data.canvas_quad_array);
|
|
|
|
|
|
+ int64_t offset = p_batch.first_vert;
|
|
|
|
|
|
- // and draw
|
|
|
|
- glDrawArrays(GL_TRIANGLE_FAN, 0, 4);
|
|
|
|
|
|
+ int num_elements = p_batch.num_commands;
|
|
|
|
+ glDrawArrays(GL_TRIANGLES, offset, num_elements);
|
|
|
|
+
|
|
|
|
+ storage->info.render._2d_draw_call_count++;
|
|
|
|
|
|
glBindVertexArray(0);
|
|
glBindVertexArray(0);
|
|
- glBindBufferBase(GL_UNIFORM_BUFFER, 0, 0);
|
|
|
|
}
|
|
}
|
|
|
|
|
|
-void RasterizerCanvasGLES3::draw_window_margins(int *black_margin, RID *black_image) {
|
|
|
|
|
|
+void RasterizerCanvasGLES3::_batch_render_rects(const Batch &p_batch, RasterizerStorageGLES3::Material *p_material) {
|
|
|
|
+ ERR_FAIL_COND(p_batch.num_commands <= 0);
|
|
|
|
|
|
- Vector2 window_size = OS::get_singleton()->get_window_size();
|
|
|
|
- int window_h = window_size.height;
|
|
|
|
- int window_w = window_size.width;
|
|
|
|
|
|
+ const bool &colored_verts = bdata.use_colored_vertices;
|
|
|
|
+ const bool &use_light_angles = bdata.use_light_angles;
|
|
|
|
+ const bool &use_modulate = bdata.use_modulate;
|
|
|
|
+ const bool &use_large_verts = bdata.use_large_verts;
|
|
|
|
|
|
- glBindFramebuffer(GL_FRAMEBUFFER, RasterizerStorageGLES3::system_fbo);
|
|
|
|
- glViewport(0, 0, window_size.width, window_size.height);
|
|
|
|
- canvas_begin();
|
|
|
|
|
|
+ _set_texture_rect_mode(false, false, use_light_angles, use_modulate, use_large_verts);
|
|
|
|
|
|
- if (black_image[MARGIN_LEFT].is_valid()) {
|
|
|
|
- _bind_canvas_texture(black_image[MARGIN_LEFT], RID(), true);
|
|
|
|
- Size2 sz(storage->texture_get_width(black_image[MARGIN_LEFT]), storage->texture_get_height(black_image[MARGIN_LEFT]));
|
|
|
|
-
|
|
|
|
- draw_generic_textured_rect(Rect2(0, 0, black_margin[MARGIN_LEFT], window_h),
|
|
|
|
- Rect2(0, 0, (float)black_margin[MARGIN_LEFT] / sz.x, (float)(window_h) / sz.y));
|
|
|
|
- } else if (black_margin[MARGIN_LEFT]) {
|
|
|
|
- glActiveTexture(GL_TEXTURE0);
|
|
|
|
- glBindTexture(GL_TEXTURE_2D, storage->resources.black_tex);
|
|
|
|
|
|
+ // state.canvas_shader.set_uniform(CanvasShaderGLES3::CLIP_RECT_UV, p_rect->flags & CANVAS_RECT_CLIP_UV);
|
|
|
|
+ state.canvas_shader.set_uniform(CanvasShaderGLES3::CLIP_RECT_UV, false);
|
|
|
|
|
|
- draw_generic_textured_rect(Rect2(0, 0, black_margin[MARGIN_LEFT], window_h), Rect2(0, 0, 1, 1));
|
|
|
|
|
|
+ switch (bdata.fvf) {
|
|
|
|
+ case RasterizerStorageCommon::FVF_UNBATCHED: // should not happen
|
|
|
|
+ return;
|
|
|
|
+ break;
|
|
|
|
+ case RasterizerStorageCommon::FVF_REGULAR: // no change
|
|
|
|
+ glBindVertexArray(batch_gl_data.batch_vertex_array[0]);
|
|
|
|
+ break;
|
|
|
|
+ case RasterizerStorageCommon::FVF_COLOR:
|
|
|
|
+ glBindVertexArray(batch_gl_data.batch_vertex_array[1]);
|
|
|
|
+ break;
|
|
|
|
+ case RasterizerStorageCommon::FVF_LIGHT_ANGLE:
|
|
|
|
+ glBindVertexArray(batch_gl_data.batch_vertex_array[2]);
|
|
|
|
+ break;
|
|
|
|
+ case RasterizerStorageCommon::FVF_MODULATED:
|
|
|
|
+ glBindVertexArray(batch_gl_data.batch_vertex_array[3]);
|
|
|
|
+ break;
|
|
|
|
+ case RasterizerStorageCommon::FVF_LARGE:
|
|
|
|
+ glBindVertexArray(batch_gl_data.batch_vertex_array[4]);
|
|
|
|
+ break;
|
|
}
|
|
}
|
|
|
|
|
|
- if (black_image[MARGIN_RIGHT].is_valid()) {
|
|
|
|
- _bind_canvas_texture(black_image[MARGIN_RIGHT], RID(), true);
|
|
|
|
- Size2 sz(storage->texture_get_width(black_image[MARGIN_RIGHT]), storage->texture_get_height(black_image[MARGIN_RIGHT]));
|
|
|
|
- draw_generic_textured_rect(Rect2(window_w - black_margin[MARGIN_RIGHT], 0, black_margin[MARGIN_RIGHT], window_h),
|
|
|
|
- Rect2(0, 0, (float)black_margin[MARGIN_RIGHT] / sz.x, (float)window_h / sz.y));
|
|
|
|
- } else if (black_margin[MARGIN_RIGHT]) {
|
|
|
|
- glActiveTexture(GL_TEXTURE0);
|
|
|
|
- glBindTexture(GL_TEXTURE_2D, storage->resources.black_tex);
|
|
|
|
-
|
|
|
|
- draw_generic_textured_rect(Rect2(window_w - black_margin[MARGIN_RIGHT], 0, black_margin[MARGIN_RIGHT], window_h), Rect2(0, 0, 1, 1));
|
|
|
|
- }
|
|
|
|
|
|
+ // if (state.canvas_shader.bind()) {
|
|
|
|
+ // _set_uniforms();
|
|
|
|
+ // state.canvas_shader.use_material((void *)p_material);
|
|
|
|
+ // }
|
|
|
|
|
|
- if (black_image[MARGIN_TOP].is_valid()) {
|
|
|
|
- _bind_canvas_texture(black_image[MARGIN_TOP], RID(), true);
|
|
|
|
|
|
+ // batch tex
|
|
|
|
+ const BatchTex &tex = bdata.batch_textures[p_batch.batch_texture_id];
|
|
|
|
|
|
- Size2 sz(storage->texture_get_width(black_image[MARGIN_TOP]), storage->texture_get_height(black_image[MARGIN_TOP]));
|
|
|
|
- draw_generic_textured_rect(Rect2(0, 0, window_w, black_margin[MARGIN_TOP]),
|
|
|
|
- Rect2(0, 0, (float)window_w / sz.x, (float)black_margin[MARGIN_TOP] / sz.y));
|
|
|
|
|
|
+ _bind_canvas_texture(tex.RID_texture, tex.RID_normal);
|
|
|
|
|
|
- } else if (black_margin[MARGIN_TOP]) {
|
|
|
|
- glActiveTexture(GL_TEXTURE0);
|
|
|
|
- glBindTexture(GL_TEXTURE_2D, storage->resources.black_tex);
|
|
|
|
|
|
+ if (!colored_verts) {
|
|
|
|
+ // may not need this disable
|
|
|
|
+ glDisableVertexAttribArray(VS::ARRAY_COLOR);
|
|
|
|
+ glVertexAttrib4fv(VS::ARRAY_COLOR, p_batch.color.get_data());
|
|
|
|
+ }
|
|
|
|
|
|
- draw_generic_textured_rect(Rect2(0, 0, window_w, black_margin[MARGIN_TOP]), Rect2(0, 0, 1, 1));
|
|
|
|
|
|
+ // We only want to set the GL wrapping mode if the texture is not already tiled (i.e. set in Import).
|
|
|
|
+ // This is an optimization left over from the legacy renderer.
|
|
|
|
+ // If we DID set tiling in the API, and reverted to clamped, then the next draw using this texture
|
|
|
|
+ // may use clamped mode incorrectly.
|
|
|
|
+ bool tex_is_already_tiled = tex.flags & VS::TEXTURE_FLAG_REPEAT;
|
|
|
|
+
|
|
|
|
+ switch (tex.tile_mode) {
|
|
|
|
+ case BatchTex::TILE_NORMAL: {
|
|
|
|
+ // if the texture is imported as tiled, no need to set GL state, as it will already be bound with repeat
|
|
|
|
+ if (!tex_is_already_tiled) {
|
|
|
|
+ glTexParameterf(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_REPEAT);
|
|
|
|
+ glTexParameterf(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_REPEAT);
|
|
|
|
+ }
|
|
|
|
+ } break;
|
|
|
|
+ default: {
|
|
|
|
+ } break;
|
|
}
|
|
}
|
|
|
|
|
|
- if (black_image[MARGIN_BOTTOM].is_valid()) {
|
|
|
|
|
|
+ // we need to convert explicitly from pod Vec2 to Vector2 ...
|
|
|
|
+ // could use a cast but this might be unsafe in future
|
|
|
|
+ Vector2 tps;
|
|
|
|
+ tex.tex_pixel_size.to(tps);
|
|
|
|
+ state.canvas_shader.set_uniform(CanvasShaderGLES3::COLOR_TEXPIXEL_SIZE, tps);
|
|
|
|
+
|
|
|
|
+ int64_t offset = p_batch.first_vert * 3; // 6 inds per quad at 2 bytes each
|
|
|
|
|
|
- _bind_canvas_texture(black_image[MARGIN_BOTTOM], RID(), true);
|
|
|
|
|
|
+ int num_elements = p_batch.num_commands * 6;
|
|
|
|
+ glDrawElements(GL_TRIANGLES, num_elements, GL_UNSIGNED_SHORT, (void *)offset);
|
|
|
|
|
|
- Size2 sz(storage->texture_get_width(black_image[MARGIN_BOTTOM]), storage->texture_get_height(black_image[MARGIN_BOTTOM]));
|
|
|
|
- draw_generic_textured_rect(Rect2(0, window_h - black_margin[MARGIN_BOTTOM], window_w, black_margin[MARGIN_BOTTOM]),
|
|
|
|
- Rect2(0, 0, (float)window_w / sz.x, (float)black_margin[MARGIN_BOTTOM] / sz.y));
|
|
|
|
|
|
+ storage->info.render._2d_draw_call_count++;
|
|
|
|
|
|
- } else if (black_margin[MARGIN_BOTTOM]) {
|
|
|
|
|
|
+ glBindVertexArray(0);
|
|
|
|
|
|
- glActiveTexture(GL_TEXTURE0);
|
|
|
|
- glBindTexture(GL_TEXTURE_2D, storage->resources.black_tex);
|
|
|
|
|
|
+ // gl_checkerror();
|
|
|
|
|
|
- draw_generic_textured_rect(Rect2(0, window_h - black_margin[MARGIN_BOTTOM], window_w, black_margin[MARGIN_BOTTOM]), Rect2(0, 0, 1, 1));
|
|
|
|
|
|
+ switch (tex.tile_mode) {
|
|
|
|
+ case BatchTex::TILE_NORMAL: {
|
|
|
|
+ // if the texture is imported as tiled, no need to revert GL state
|
|
|
|
+ if (!tex_is_already_tiled) {
|
|
|
|
+ glTexParameterf(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_CLAMP_TO_EDGE);
|
|
|
|
+ glTexParameterf(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_CLAMP_TO_EDGE);
|
|
|
|
+ }
|
|
|
|
+ } break;
|
|
|
|
+ default: {
|
|
|
|
+ } break;
|
|
}
|
|
}
|
|
|
|
+
|
|
|
|
+ /*
|
|
|
|
+ // may not be necessary .. state change optimization still TODO
|
|
|
|
+ glBindBuffer(GL_ARRAY_BUFFER, 0);
|
|
|
|
+ glBindBuffer(GL_ELEMENT_ARRAY_BUFFER, 0);
|
|
|
|
+ */
|
|
}
|
|
}
|
|
|
|
|
|
void RasterizerCanvasGLES3::initialize() {
|
|
void RasterizerCanvasGLES3::initialize() {
|
|
|
|
+ gl_checkerror();
|
|
|
|
+ RasterizerCanvasBaseGLES3::initialize();
|
|
|
|
|
|
- {
|
|
|
|
- //quad buffers
|
|
|
|
-
|
|
|
|
- glGenBuffers(1, &data.canvas_quad_vertices);
|
|
|
|
- glBindBuffer(GL_ARRAY_BUFFER, data.canvas_quad_vertices);
|
|
|
|
- {
|
|
|
|
- const float qv[8] = {
|
|
|
|
- 0, 0,
|
|
|
|
- 0, 1,
|
|
|
|
- 1, 1,
|
|
|
|
- 1, 0
|
|
|
|
- };
|
|
|
|
-
|
|
|
|
- glBufferData(GL_ARRAY_BUFFER, sizeof(float) * 8, qv, GL_STATIC_DRAW);
|
|
|
|
- }
|
|
|
|
-
|
|
|
|
- glBindBuffer(GL_ARRAY_BUFFER, 0); //unbind
|
|
|
|
-
|
|
|
|
- glGenVertexArrays(1, &data.canvas_quad_array);
|
|
|
|
- glBindVertexArray(data.canvas_quad_array);
|
|
|
|
- glBindBuffer(GL_ARRAY_BUFFER, data.canvas_quad_vertices);
|
|
|
|
- glVertexAttribPointer(0, 2, GL_FLOAT, GL_FALSE, sizeof(float) * 2, 0);
|
|
|
|
- glEnableVertexAttribArray(0);
|
|
|
|
- glBindVertexArray(0);
|
|
|
|
- glBindBuffer(GL_ARRAY_BUFFER, 0); //unbind
|
|
|
|
- }
|
|
|
|
- {
|
|
|
|
- //particle quad buffers
|
|
|
|
-
|
|
|
|
- glGenBuffers(1, &data.particle_quad_vertices);
|
|
|
|
- glBindBuffer(GL_ARRAY_BUFFER, data.particle_quad_vertices);
|
|
|
|
- {
|
|
|
|
- //quad of size 1, with pivot on the center for particles, then regular UVS. Color is general plus fetched from particle
|
|
|
|
- const float qv[16] = {
|
|
|
|
- -0.5, -0.5,
|
|
|
|
- 0.0, 0.0,
|
|
|
|
- -0.5, 0.5,
|
|
|
|
- 0.0, 1.0,
|
|
|
|
- 0.5, 0.5,
|
|
|
|
- 1.0, 1.0,
|
|
|
|
- 0.5, -0.5,
|
|
|
|
- 1.0, 0.0
|
|
|
|
- };
|
|
|
|
-
|
|
|
|
- glBufferData(GL_ARRAY_BUFFER, sizeof(float) * 16, qv, GL_STATIC_DRAW);
|
|
|
|
- }
|
|
|
|
-
|
|
|
|
- glBindBuffer(GL_ARRAY_BUFFER, 0); //unbind
|
|
|
|
|
|
+ batch_initialize();
|
|
|
|
|
|
- glGenVertexArrays(1, &data.particle_quad_array);
|
|
|
|
- glBindVertexArray(data.particle_quad_array);
|
|
|
|
- glBindBuffer(GL_ARRAY_BUFFER, data.particle_quad_vertices);
|
|
|
|
- glEnableVertexAttribArray(VS::ARRAY_VERTEX);
|
|
|
|
- glVertexAttribPointer(VS::ARRAY_VERTEX, 2, GL_FLOAT, GL_FALSE, sizeof(float) * 4, 0);
|
|
|
|
- glEnableVertexAttribArray(VS::ARRAY_TEX_UV);
|
|
|
|
- glVertexAttribPointer(VS::ARRAY_TEX_UV, 2, GL_FLOAT, GL_FALSE, sizeof(float) * 4, CAST_INT_TO_UCHAR_PTR(8));
|
|
|
|
- glBindVertexArray(0);
|
|
|
|
- glBindBuffer(GL_ARRAY_BUFFER, 0); //unbind
|
|
|
|
- }
|
|
|
|
- {
|
|
|
|
|
|
+ // just reserve some space (may not be needed as we are orphaning, but hey ho)
|
|
|
|
+ glGenBuffers(1, &bdata.gl_vertex_buffer);
|
|
|
|
|
|
- uint32_t poly_size = GLOBAL_DEF_RST("rendering/limits/buffers/canvas_polygon_buffer_size_kb", 128);
|
|
|
|
- ProjectSettings::get_singleton()->set_custom_property_info("rendering/limits/buffers/canvas_polygon_buffer_size_kb", PropertyInfo(Variant::INT, "rendering/limits/buffers/canvas_polygon_buffer_size_kb", PROPERTY_HINT_RANGE, "0,256,1,or_greater"));
|
|
|
|
- poly_size *= 1024; //kb
|
|
|
|
- poly_size = MAX(poly_size, (2 + 2 + 4 + 1) * 4 * sizeof(float));
|
|
|
|
- glGenBuffers(1, &data.polygon_buffer);
|
|
|
|
- glBindBuffer(GL_ARRAY_BUFFER, data.polygon_buffer);
|
|
|
|
- glBufferData(GL_ARRAY_BUFFER, poly_size, NULL, GL_DYNAMIC_DRAW); //allocate max size
|
|
|
|
|
|
+ if (bdata.vertex_buffer_size_bytes) {
|
|
|
|
+ glBindBuffer(GL_ARRAY_BUFFER, bdata.gl_vertex_buffer);
|
|
|
|
+ glBufferData(GL_ARRAY_BUFFER, bdata.vertex_buffer_size_bytes, NULL, GL_DYNAMIC_DRAW);
|
|
glBindBuffer(GL_ARRAY_BUFFER, 0);
|
|
glBindBuffer(GL_ARRAY_BUFFER, 0);
|
|
- data.polygon_buffer_size = poly_size;
|
|
|
|
-
|
|
|
|
- //quad arrays
|
|
|
|
- for (int i = 0; i < Data::NUM_QUAD_ARRAY_VARIATIONS; i++) {
|
|
|
|
- glGenVertexArrays(1, &data.polygon_buffer_quad_arrays[i]);
|
|
|
|
- glBindVertexArray(data.polygon_buffer_quad_arrays[i]);
|
|
|
|
- glBindBuffer(GL_ARRAY_BUFFER, data.polygon_buffer);
|
|
|
|
-
|
|
|
|
- int uv_ofs = 0;
|
|
|
|
- int color_ofs = 0;
|
|
|
|
- int light_angle_ofs = 0;
|
|
|
|
- int stride = 2 * 4;
|
|
|
|
-
|
|
|
|
- if (i & 1) { //color
|
|
|
|
- color_ofs = stride;
|
|
|
|
- stride += 4 * 4;
|
|
|
|
- }
|
|
|
|
-
|
|
|
|
- if (i & 2) { //uv
|
|
|
|
- uv_ofs = stride;
|
|
|
|
- stride += 2 * 4;
|
|
|
|
- }
|
|
|
|
-
|
|
|
|
- if (i & 4) { //light_angle
|
|
|
|
- light_angle_ofs = stride;
|
|
|
|
- stride += 1 * 4;
|
|
|
|
- }
|
|
|
|
-
|
|
|
|
- glEnableVertexAttribArray(VS::ARRAY_VERTEX);
|
|
|
|
- glVertexAttribPointer(VS::ARRAY_VERTEX, 2, GL_FLOAT, GL_FALSE, stride, NULL);
|
|
|
|
|
|
|
|
- if (i & 1) {
|
|
|
|
- glEnableVertexAttribArray(VS::ARRAY_COLOR);
|
|
|
|
- glVertexAttribPointer(VS::ARRAY_COLOR, 4, GL_FLOAT, GL_FALSE, stride, CAST_INT_TO_UCHAR_PTR(color_ofs));
|
|
|
|
- }
|
|
|
|
|
|
+ // pre fill index buffer, the indices never need to change so can be static
|
|
|
|
+ glGenBuffers(1, &bdata.gl_index_buffer);
|
|
|
|
+ glBindBuffer(GL_ELEMENT_ARRAY_BUFFER, bdata.gl_index_buffer);
|
|
|
|
|
|
- if (i & 2) {
|
|
|
|
- glEnableVertexAttribArray(VS::ARRAY_TEX_UV);
|
|
|
|
- glVertexAttribPointer(VS::ARRAY_TEX_UV, 2, GL_FLOAT, GL_FALSE, stride, CAST_INT_TO_UCHAR_PTR(uv_ofs));
|
|
|
|
- }
|
|
|
|
|
|
+ Vector<uint16_t> indices;
|
|
|
|
+ indices.resize(bdata.index_buffer_size_units);
|
|
|
|
|
|
- if (i & 4) {
|
|
|
|
- // reusing tangent for light_angle
|
|
|
|
- glEnableVertexAttribArray(VS::ARRAY_TANGENT);
|
|
|
|
- glVertexAttribPointer(VS::ARRAY_TANGENT, 1, GL_FLOAT, GL_FALSE, stride, CAST_INT_TO_UCHAR_PTR(light_angle_ofs));
|
|
|
|
- }
|
|
|
|
|
|
+ for (unsigned int q = 0; q < bdata.max_quads; q++) {
|
|
|
|
+ int i_pos = q * 6; // 6 inds per quad
|
|
|
|
+ int q_pos = q * 4; // 4 verts per quad
|
|
|
|
+ indices.set(i_pos, q_pos);
|
|
|
|
+ indices.set(i_pos + 1, q_pos + 1);
|
|
|
|
+ indices.set(i_pos + 2, q_pos + 2);
|
|
|
|
+ indices.set(i_pos + 3, q_pos);
|
|
|
|
+ indices.set(i_pos + 4, q_pos + 2);
|
|
|
|
+ indices.set(i_pos + 5, q_pos + 3);
|
|
|
|
|
|
- glBindVertexArray(0);
|
|
|
|
|
|
+ // we can only use 16 bit indices in GLES2!
|
|
|
|
+#ifdef DEBUG_ENABLED
|
|
|
|
+ CRASH_COND((q_pos + 3) > 65535);
|
|
|
|
+#endif
|
|
}
|
|
}
|
|
|
|
|
|
- glGenVertexArrays(1, &data.polygon_buffer_pointer_array);
|
|
|
|
-
|
|
|
|
- uint32_t index_size = GLOBAL_DEF_RST("rendering/limits/buffers/canvas_polygon_index_buffer_size_kb", 128);
|
|
|
|
- ProjectSettings::get_singleton()->set_custom_property_info("rendering/limits/buffers/canvas_polygon_index_buffer_size_kb", PropertyInfo(Variant::INT, "rendering/limits/buffers/canvas_polygon_index_buffer_size_kb", PROPERTY_HINT_RANGE, "0,256,1,or_greater"));
|
|
|
|
- index_size *= 1024; //kb
|
|
|
|
- glGenBuffers(1, &data.polygon_index_buffer);
|
|
|
|
- glBindBuffer(GL_ELEMENT_ARRAY_BUFFER, data.polygon_index_buffer);
|
|
|
|
- glBufferData(GL_ELEMENT_ARRAY_BUFFER, index_size, NULL, GL_DYNAMIC_DRAW); //allocate max size
|
|
|
|
|
|
+ glBufferData(GL_ELEMENT_ARRAY_BUFFER, bdata.index_buffer_size_bytes, &indices[0], GL_STATIC_DRAW);
|
|
glBindBuffer(GL_ELEMENT_ARRAY_BUFFER, 0);
|
|
glBindBuffer(GL_ELEMENT_ARRAY_BUFFER, 0);
|
|
|
|
|
|
- data.polygon_index_buffer_size = index_size;
|
|
|
|
- }
|
|
|
|
-
|
|
|
|
- store_transform(Transform(), state.canvas_item_ubo_data.projection_matrix);
|
|
|
|
-
|
|
|
|
- glGenBuffers(1, &state.canvas_item_ubo);
|
|
|
|
- glBindBuffer(GL_UNIFORM_BUFFER, state.canvas_item_ubo);
|
|
|
|
- glBufferData(GL_UNIFORM_BUFFER, sizeof(CanvasItemUBO), &state.canvas_item_ubo_data, GL_DYNAMIC_DRAW);
|
|
|
|
- glBindBuffer(GL_UNIFORM_BUFFER, 0);
|
|
|
|
-
|
|
|
|
- state.canvas_shader.init();
|
|
|
|
- state.canvas_shader.set_base_material_tex_index(2);
|
|
|
|
- state.canvas_shadow_shader.init();
|
|
|
|
- state.lens_shader.init();
|
|
|
|
-
|
|
|
|
- state.canvas_shader.set_conditional(CanvasShaderGLES3::USE_RGBA_SHADOWS, storage->config.use_rgba_2d_shadows);
|
|
|
|
- state.canvas_shadow_shader.set_conditional(CanvasShadowShaderGLES3::USE_RGBA_SHADOWS, storage->config.use_rgba_2d_shadows);
|
|
|
|
|
|
+ } // only if there is a vertex buffer (batching is on)
|
|
|
|
+
|
|
|
|
+ // vertex array objects
|
|
|
|
+ for (int vao = 0; vao < 5; vao++) {
|
|
|
|
+
|
|
|
|
+ int sizeof_vert;
|
|
|
|
+ switch (vao) {
|
|
|
|
+ case 0:
|
|
|
|
+ sizeof_vert = sizeof(BatchVertex);
|
|
|
|
+ break;
|
|
|
|
+ case 1:
|
|
|
|
+ sizeof_vert = sizeof(BatchVertexColored);
|
|
|
|
+ break;
|
|
|
|
+ case 2:
|
|
|
|
+ sizeof_vert = sizeof(BatchVertexLightAngled);
|
|
|
|
+ break;
|
|
|
|
+ case 3:
|
|
|
|
+ sizeof_vert = sizeof(BatchVertexModulated);
|
|
|
|
+ break;
|
|
|
|
+ case 4:
|
|
|
|
+ sizeof_vert = sizeof(BatchVertexLarge);
|
|
|
|
+ break;
|
|
|
|
+ }
|
|
|
|
|
|
- state.canvas_shader.set_conditional(CanvasShaderGLES3::USE_PIXEL_SNAP, GLOBAL_DEF("rendering/quality/2d/use_pixel_snap", false));
|
|
|
|
-}
|
|
|
|
|
|
+ glGenVertexArrays(1, &batch_gl_data.batch_vertex_array[vao]);
|
|
|
|
+ glBindVertexArray(batch_gl_data.batch_vertex_array[vao]);
|
|
|
|
+ glBindBuffer(GL_ARRAY_BUFFER, bdata.gl_vertex_buffer);
|
|
|
|
+ glBindBuffer(GL_ELEMENT_ARRAY_BUFFER, bdata.gl_index_buffer);
|
|
|
|
|
|
-void RasterizerCanvasGLES3::finalize() {
|
|
|
|
|
|
+ uint64_t pointer = 0;
|
|
|
|
+ glEnableVertexAttribArray(VS::ARRAY_VERTEX);
|
|
|
|
+ glVertexAttribPointer(VS::ARRAY_VERTEX, 2, GL_FLOAT, GL_FALSE, sizeof_vert, (const void *)pointer);
|
|
|
|
|
|
- glDeleteBuffers(1, &data.canvas_quad_vertices);
|
|
|
|
- glDeleteVertexArrays(1, &data.canvas_quad_array);
|
|
|
|
|
|
+ // always send UVs, even within a texture specified because a shader can still use UVs
|
|
|
|
+ glEnableVertexAttribArray(VS::ARRAY_TEX_UV);
|
|
|
|
+ glVertexAttribPointer(VS::ARRAY_TEX_UV, 2, GL_FLOAT, GL_FALSE, sizeof_vert, CAST_INT_TO_UCHAR_PTR(pointer + (2 * 4)));
|
|
|
|
+
|
|
|
|
+ // optional attributes
|
|
|
|
+ bool a_color = false;
|
|
|
|
+ bool a_light_angle = false;
|
|
|
|
+ bool a_modulate = false;
|
|
|
|
+ bool a_large = false;
|
|
|
|
+
|
|
|
|
+ switch (vao) {
|
|
|
|
+ case 0:
|
|
|
|
+ break;
|
|
|
|
+ case 1: {
|
|
|
|
+ a_color = true;
|
|
|
|
+ } break;
|
|
|
|
+ case 2: {
|
|
|
|
+ a_color = true;
|
|
|
|
+ a_light_angle = true;
|
|
|
|
+ } break;
|
|
|
|
+ case 3: {
|
|
|
|
+ a_color = true;
|
|
|
|
+ a_light_angle = true;
|
|
|
|
+ a_modulate = true;
|
|
|
|
+ } break;
|
|
|
|
+ case 4: {
|
|
|
|
+ a_color = true;
|
|
|
|
+ a_light_angle = true;
|
|
|
|
+ a_modulate = true;
|
|
|
|
+ a_large = true;
|
|
|
|
+ } break;
|
|
|
|
+ }
|
|
|
|
|
|
- glDeleteBuffers(1, &data.canvas_quad_vertices);
|
|
|
|
- glDeleteVertexArrays(1, &data.canvas_quad_array);
|
|
|
|
|
|
+ if (a_color) {
|
|
|
|
+ glEnableVertexAttribArray(VS::ARRAY_COLOR);
|
|
|
|
+ glVertexAttribPointer(VS::ARRAY_COLOR, 4, GL_FLOAT, GL_FALSE, sizeof_vert, CAST_INT_TO_UCHAR_PTR(pointer + (4 * 4)));
|
|
|
|
+ }
|
|
|
|
+ if (a_light_angle) {
|
|
|
|
+ glEnableVertexAttribArray(VS::ARRAY_TANGENT);
|
|
|
|
+ glVertexAttribPointer(VS::ARRAY_TANGENT, 1, GL_FLOAT, GL_FALSE, sizeof_vert, CAST_INT_TO_UCHAR_PTR(pointer + (8 * 4)));
|
|
|
|
+ }
|
|
|
|
+ if (a_modulate) {
|
|
|
|
+ glEnableVertexAttribArray(VS::ARRAY_TEX_UV2);
|
|
|
|
+ glVertexAttribPointer(VS::ARRAY_TEX_UV2, 4, GL_FLOAT, GL_FALSE, sizeof_vert, CAST_INT_TO_UCHAR_PTR(pointer + (9 * 4)));
|
|
|
|
+ }
|
|
|
|
+ if (a_large) {
|
|
|
|
+ glEnableVertexAttribArray(VS::ARRAY_BONES);
|
|
|
|
+ glVertexAttribPointer(VS::ARRAY_BONES, 2, GL_FLOAT, GL_FALSE, sizeof_vert, CAST_INT_TO_UCHAR_PTR(pointer + (13 * 4)));
|
|
|
|
+ glEnableVertexAttribArray(VS::ARRAY_WEIGHTS);
|
|
|
|
+ glVertexAttribPointer(VS::ARRAY_WEIGHTS, 4, GL_FLOAT, GL_FALSE, sizeof_vert, CAST_INT_TO_UCHAR_PTR(pointer + (15 * 4)));
|
|
|
|
+ }
|
|
|
|
|
|
- glDeleteVertexArrays(1, &data.polygon_buffer_pointer_array);
|
|
|
|
|
|
+ glBindVertexArray(0);
|
|
|
|
+ } // for vao
|
|
|
|
+ gl_checkerror();
|
|
}
|
|
}
|
|
|
|
|
|
RasterizerCanvasGLES3::RasterizerCanvasGLES3() {
|
|
RasterizerCanvasGLES3::RasterizerCanvasGLES3() {
|
|
- // Not needed (a priori) on GLES devices
|
|
|
|
- use_nvidia_rect_workaround = false;
|
|
|
|
|
|
|
|
-#ifdef GLES_OVER_GL
|
|
|
|
- use_nvidia_rect_workaround = GLOBAL_GET("rendering/quality/2d/use_nvidia_rect_flicker_workaround");
|
|
|
|
-#endif
|
|
|
|
|
|
+ batch_constructor();
|
|
}
|
|
}
|