|
|
@@ -4393,7 +4393,7 @@ end_frame(Thread *current_thread) {
|
|
|
bool CLP(GraphicsStateGuardian)::
|
|
|
begin_draw_primitives(const GeomPipelineReader *geom_reader,
|
|
|
const GeomVertexDataPipelineReader *data_reader,
|
|
|
- bool force) {
|
|
|
+ size_t num_instances, bool force) {
|
|
|
#ifndef NDEBUG
|
|
|
if (GLCAT.is_spam()) {
|
|
|
GLCAT.spam() << "begin_draw_primitives: " << *(data_reader->get_object()) << "\n";
|
|
|
@@ -4410,11 +4410,13 @@ begin_draw_primitives(const GeomPipelineReader *geom_reader,
|
|
|
}
|
|
|
#endif
|
|
|
|
|
|
- if (!GraphicsStateGuardian::begin_draw_primitives(geom_reader, data_reader, force)) {
|
|
|
+ if (!GraphicsStateGuardian::begin_draw_primitives(geom_reader, data_reader, num_instances, force)) {
|
|
|
return false;
|
|
|
}
|
|
|
nassertr(_data_reader != nullptr, false);
|
|
|
|
|
|
+ _instance_count = _supports_geometry_instancing ? num_instances : 1;
|
|
|
+
|
|
|
_geom_display_list = 0;
|
|
|
|
|
|
if (_auto_antialias_mode) {
|
|
|
@@ -4955,7 +4957,7 @@ draw_triangles(const GeomPrimitivePipelineReader *reader, bool force) {
|
|
|
}
|
|
|
|
|
|
#ifndef OPENGLES_1
|
|
|
- if (_supports_geometry_instancing && _instance_count > 0) {
|
|
|
+ if (_instance_count != 1) {
|
|
|
_glDrawElementsInstanced(GL_TRIANGLES, num_vertices,
|
|
|
get_numeric_type(reader->get_index_type()),
|
|
|
client_pointer, _instance_count);
|
|
|
@@ -4971,7 +4973,7 @@ draw_triangles(const GeomPrimitivePipelineReader *reader, bool force) {
|
|
|
}
|
|
|
} else {
|
|
|
#ifndef OPENGLES_1
|
|
|
- if (_supports_geometry_instancing && _instance_count > 0) {
|
|
|
+ if (_instance_count != 1) {
|
|
|
_glDrawArraysInstanced(GL_TRIANGLES,
|
|
|
reader->get_first_vertex(),
|
|
|
num_vertices, _instance_count);
|
|
|
@@ -5021,7 +5023,7 @@ draw_triangles_adj(const GeomPrimitivePipelineReader *reader, bool force) {
|
|
|
return false;
|
|
|
}
|
|
|
|
|
|
- if (_supports_geometry_instancing && _instance_count > 0) {
|
|
|
+ if (_instance_count != 1) {
|
|
|
_glDrawElementsInstanced(GL_TRIANGLES_ADJACENCY, num_vertices,
|
|
|
get_numeric_type(reader->get_index_type()),
|
|
|
client_pointer, _instance_count);
|
|
|
@@ -5034,7 +5036,7 @@ draw_triangles_adj(const GeomPrimitivePipelineReader *reader, bool force) {
|
|
|
client_pointer);
|
|
|
}
|
|
|
} else {
|
|
|
- if (_supports_geometry_instancing && _instance_count > 0) {
|
|
|
+ if (_instance_count != 1) {
|
|
|
_glDrawArraysInstanced(GL_TRIANGLES_ADJACENCY,
|
|
|
reader->get_first_vertex(),
|
|
|
num_vertices, _instance_count);
|
|
|
@@ -5086,7 +5088,7 @@ draw_tristrips(const GeomPrimitivePipelineReader *reader, bool force) {
|
|
|
return false;
|
|
|
}
|
|
|
#ifndef OPENGLES_1
|
|
|
- if (_supports_geometry_instancing && _instance_count > 0) {
|
|
|
+ if (_instance_count != 1) {
|
|
|
_glDrawElementsInstanced(GL_TRIANGLE_STRIP, num_vertices,
|
|
|
get_numeric_type(reader->get_index_type()),
|
|
|
client_pointer, _instance_count);
|
|
|
@@ -5102,7 +5104,7 @@ draw_tristrips(const GeomPrimitivePipelineReader *reader, bool force) {
|
|
|
}
|
|
|
} else {
|
|
|
#ifndef OPENGLES_1
|
|
|
- if (_supports_geometry_instancing && _instance_count > 0) {
|
|
|
+ if (_instance_count != 1) {
|
|
|
_glDrawArraysInstanced(GL_TRIANGLE_STRIP,
|
|
|
reader->get_first_vertex(),
|
|
|
num_vertices, _instance_count);
|
|
|
@@ -5136,7 +5138,7 @@ draw_tristrips(const GeomPrimitivePipelineReader *reader, bool force) {
|
|
|
for (size_t i = 0; i < ends.size(); i++) {
|
|
|
_vertices_tristrip_pcollector.add_level(ends[i] - start);
|
|
|
#ifndef OPENGLES_1
|
|
|
- if (_supports_geometry_instancing && _instance_count > 0) {
|
|
|
+ if (_instance_count != 1) {
|
|
|
_glDrawElementsInstanced(GL_TRIANGLE_STRIP, ends[i] - start,
|
|
|
get_numeric_type(reader->get_index_type()),
|
|
|
client_pointer + start * index_stride,
|
|
|
@@ -5158,7 +5160,7 @@ draw_tristrips(const GeomPrimitivePipelineReader *reader, bool force) {
|
|
|
for (size_t i = 0; i < ends.size(); i++) {
|
|
|
_vertices_tristrip_pcollector.add_level(ends[i] - start);
|
|
|
#ifndef OPENGLES_1
|
|
|
- if (_supports_geometry_instancing && _instance_count > 0) {
|
|
|
+ if (_instance_count != 1) {
|
|
|
_glDrawArraysInstanced(GL_TRIANGLE_STRIP, first_vertex + start,
|
|
|
ends[i] - start, _instance_count);
|
|
|
} else
|
|
|
@@ -5216,7 +5218,7 @@ draw_tristrips_adj(const GeomPrimitivePipelineReader *reader, bool force) {
|
|
|
if (!setup_primitive(client_pointer, reader, force)) {
|
|
|
return false;
|
|
|
}
|
|
|
- if (_supports_geometry_instancing && _instance_count > 0) {
|
|
|
+ if (_instance_count != 1) {
|
|
|
_glDrawElementsInstanced(GL_TRIANGLE_STRIP_ADJACENCY, num_vertices,
|
|
|
get_numeric_type(reader->get_index_type()),
|
|
|
client_pointer, _instance_count);
|
|
|
@@ -5229,7 +5231,7 @@ draw_tristrips_adj(const GeomPrimitivePipelineReader *reader, bool force) {
|
|
|
client_pointer);
|
|
|
}
|
|
|
} else {
|
|
|
- if (_supports_geometry_instancing && _instance_count > 0) {
|
|
|
+ if (_instance_count != 1) {
|
|
|
_glDrawArraysInstanced(GL_TRIANGLE_STRIP_ADJACENCY,
|
|
|
reader->get_first_vertex(),
|
|
|
num_vertices, _instance_count);
|
|
|
@@ -5262,7 +5264,7 @@ draw_tristrips_adj(const GeomPrimitivePipelineReader *reader, bool force) {
|
|
|
unsigned int start = 0;
|
|
|
for (size_t i = 0; i < ends.size(); i++) {
|
|
|
_vertices_tristrip_pcollector.add_level(ends[i] - start);
|
|
|
- if (_supports_geometry_instancing && _instance_count > 0) {
|
|
|
+ if (_instance_count != 1) {
|
|
|
_glDrawElementsInstanced(GL_TRIANGLE_STRIP_ADJACENCY, ends[i] - start,
|
|
|
get_numeric_type(reader->get_index_type()),
|
|
|
client_pointer + start * index_stride,
|
|
|
@@ -5281,7 +5283,7 @@ draw_tristrips_adj(const GeomPrimitivePipelineReader *reader, bool force) {
|
|
|
int first_vertex = reader->get_first_vertex();
|
|
|
for (size_t i = 0; i < ends.size(); i++) {
|
|
|
_vertices_tristrip_pcollector.add_level(ends[i] - start);
|
|
|
- if (_supports_geometry_instancing && _instance_count > 0) {
|
|
|
+ if (_instance_count != 1) {
|
|
|
_glDrawArraysInstanced(GL_TRIANGLE_STRIP_ADJACENCY, first_vertex + start,
|
|
|
ends[i] - start, _instance_count);
|
|
|
} else {
|
|
|
@@ -5339,7 +5341,7 @@ draw_trifans(const GeomPrimitivePipelineReader *reader, bool force) {
|
|
|
for (size_t i = 0; i < ends.size(); i++) {
|
|
|
_vertices_trifan_pcollector.add_level(ends[i] - start);
|
|
|
#ifndef OPENGLES_1
|
|
|
- if (_supports_geometry_instancing && _instance_count > 0) {
|
|
|
+ if (_instance_count != 1) {
|
|
|
_glDrawElementsInstanced(GL_TRIANGLE_FAN, ends[i] - start,
|
|
|
get_numeric_type(reader->get_index_type()),
|
|
|
client_pointer + start * index_stride,
|
|
|
@@ -5360,7 +5362,7 @@ draw_trifans(const GeomPrimitivePipelineReader *reader, bool force) {
|
|
|
for (size_t i = 0; i < ends.size(); i++) {
|
|
|
_vertices_trifan_pcollector.add_level(ends[i] - start);
|
|
|
#ifndef OPENGLES_1
|
|
|
- if (_supports_geometry_instancing && _instance_count > 0) {
|
|
|
+ if (_instance_count != 1) {
|
|
|
_glDrawArraysInstanced(GL_TRIANGLE_FAN, first_vertex + start,
|
|
|
ends[i] - start, _instance_count);
|
|
|
} else
|
|
|
@@ -5418,7 +5420,7 @@ draw_patches(const GeomPrimitivePipelineReader *reader, bool force) {
|
|
|
}
|
|
|
|
|
|
#ifndef OPENGLES_1
|
|
|
- if (_supports_geometry_instancing && _instance_count > 0) {
|
|
|
+ if (_instance_count != 1) {
|
|
|
_glDrawElementsInstanced(GL_PATCHES, num_vertices,
|
|
|
get_numeric_type(reader->get_index_type()),
|
|
|
client_pointer, _instance_count);
|
|
|
@@ -5434,7 +5436,7 @@ draw_patches(const GeomPrimitivePipelineReader *reader, bool force) {
|
|
|
}
|
|
|
} else {
|
|
|
#ifndef OPENGLES_1
|
|
|
- if (_supports_geometry_instancing && _instance_count > 0) {
|
|
|
+ if (_instance_count != 1) {
|
|
|
_glDrawArraysInstanced(GL_PATCHES,
|
|
|
reader->get_first_vertex(),
|
|
|
num_vertices, _instance_count);
|
|
|
@@ -5484,7 +5486,7 @@ draw_lines(const GeomPrimitivePipelineReader *reader, bool force) {
|
|
|
return false;
|
|
|
}
|
|
|
#ifndef OPENGLES_1
|
|
|
- if (_supports_geometry_instancing && _instance_count > 0) {
|
|
|
+ if (_instance_count != 1) {
|
|
|
_glDrawElementsInstanced(GL_LINES, num_vertices,
|
|
|
get_numeric_type(reader->get_index_type()),
|
|
|
client_pointer, _instance_count);
|
|
|
@@ -5500,7 +5502,7 @@ draw_lines(const GeomPrimitivePipelineReader *reader, bool force) {
|
|
|
}
|
|
|
} else {
|
|
|
#ifndef OPENGLES_1
|
|
|
- if (_supports_geometry_instancing && _instance_count > 0) {
|
|
|
+ if (_instance_count != 1) {
|
|
|
_glDrawArraysInstanced(GL_LINES,
|
|
|
reader->get_first_vertex(),
|
|
|
num_vertices, _instance_count);
|
|
|
@@ -5548,7 +5550,7 @@ draw_lines_adj(const GeomPrimitivePipelineReader *reader, bool force) {
|
|
|
if (!setup_primitive(client_pointer, reader, force)) {
|
|
|
return false;
|
|
|
}
|
|
|
- if (_supports_geometry_instancing && _instance_count > 0) {
|
|
|
+ if (_instance_count != 1) {
|
|
|
_glDrawElementsInstanced(GL_LINES_ADJACENCY, num_vertices,
|
|
|
get_numeric_type(reader->get_index_type()),
|
|
|
client_pointer, _instance_count);
|
|
|
@@ -5561,7 +5563,7 @@ draw_lines_adj(const GeomPrimitivePipelineReader *reader, bool force) {
|
|
|
client_pointer);
|
|
|
}
|
|
|
} else {
|
|
|
- if (_supports_geometry_instancing && _instance_count > 0) {
|
|
|
+ if (_instance_count != 1) {
|
|
|
_glDrawArraysInstanced(GL_LINES_ADJACENCY,
|
|
|
reader->get_first_vertex(),
|
|
|
num_vertices, _instance_count);
|
|
|
@@ -5620,7 +5622,7 @@ draw_linestrips(const GeomPrimitivePipelineReader *reader, bool force) {
|
|
|
return false;
|
|
|
}
|
|
|
#ifndef OPENGLES_1
|
|
|
- if (_supports_geometry_instancing && _instance_count > 0) {
|
|
|
+ if (_instance_count != 1) {
|
|
|
_glDrawElementsInstanced(GL_LINE_STRIP, num_vertices,
|
|
|
get_numeric_type(reader->get_index_type()),
|
|
|
client_pointer, _instance_count);
|
|
|
@@ -5660,7 +5662,7 @@ draw_linestrips(const GeomPrimitivePipelineReader *reader, bool force) {
|
|
|
for (size_t i = 0; i < ends.size(); i++) {
|
|
|
_vertices_other_pcollector.add_level(ends[i] - start);
|
|
|
#ifndef OPENGLES_1
|
|
|
- if (_supports_geometry_instancing && _instance_count > 0) {
|
|
|
+ if (_instance_count != 1) {
|
|
|
_glDrawElementsInstanced(GL_LINE_STRIP, ends[i] - start,
|
|
|
get_numeric_type(reader->get_index_type()),
|
|
|
client_pointer + start * index_stride,
|
|
|
@@ -5682,7 +5684,7 @@ draw_linestrips(const GeomPrimitivePipelineReader *reader, bool force) {
|
|
|
for (size_t i = 0; i < ends.size(); i++) {
|
|
|
_vertices_other_pcollector.add_level(ends[i] - start);
|
|
|
#ifndef OPENGLES_1
|
|
|
- if (_supports_geometry_instancing && _instance_count > 0) {
|
|
|
+ if (_instance_count != 1) {
|
|
|
_glDrawArraysInstanced(GL_LINE_STRIP, first_vertex + start,
|
|
|
ends[i] - start, _instance_count);
|
|
|
} else
|
|
|
@@ -5740,7 +5742,7 @@ draw_linestrips_adj(const GeomPrimitivePipelineReader *reader, bool force) {
|
|
|
if (!setup_primitive(client_pointer, reader, force)) {
|
|
|
return false;
|
|
|
}
|
|
|
- if (_supports_geometry_instancing && _instance_count > 0) {
|
|
|
+ if (_instance_count != 1) {
|
|
|
_glDrawElementsInstanced(GL_LINE_STRIP_ADJACENCY, num_vertices,
|
|
|
get_numeric_type(reader->get_index_type()),
|
|
|
client_pointer, _instance_count);
|
|
|
@@ -5775,7 +5777,7 @@ draw_linestrips_adj(const GeomPrimitivePipelineReader *reader, bool force) {
|
|
|
unsigned int start = 0;
|
|
|
for (size_t i = 0; i < ends.size(); i++) {
|
|
|
_vertices_other_pcollector.add_level(ends[i] - start);
|
|
|
- if (_supports_geometry_instancing && _instance_count > 0) {
|
|
|
+ if (_instance_count != 1) {
|
|
|
_glDrawElementsInstanced(GL_LINE_STRIP_ADJACENCY, ends[i] - start,
|
|
|
get_numeric_type(reader->get_index_type()),
|
|
|
client_pointer + start * index_stride,
|
|
|
@@ -5794,7 +5796,7 @@ draw_linestrips_adj(const GeomPrimitivePipelineReader *reader, bool force) {
|
|
|
int first_vertex = reader->get_first_vertex();
|
|
|
for (size_t i = 0; i < ends.size(); i++) {
|
|
|
_vertices_other_pcollector.add_level(ends[i] - start);
|
|
|
- if (_supports_geometry_instancing && _instance_count > 0) {
|
|
|
+ if (_instance_count != 1) {
|
|
|
_glDrawArraysInstanced(GL_LINE_STRIP_ADJACENCY, first_vertex + start,
|
|
|
ends[i] - start, _instance_count);
|
|
|
} else {
|
|
|
@@ -5841,7 +5843,7 @@ draw_points(const GeomPrimitivePipelineReader *reader, bool force) {
|
|
|
return false;
|
|
|
}
|
|
|
#ifndef OPENGLES_1
|
|
|
- if (_supports_geometry_instancing && _instance_count > 0) {
|
|
|
+ if (_instance_count != 1) {
|
|
|
_glDrawElementsInstanced(GL_POINTS, num_vertices,
|
|
|
get_numeric_type(reader->get_index_type()),
|
|
|
client_pointer, _instance_count);
|
|
|
@@ -5857,7 +5859,7 @@ draw_points(const GeomPrimitivePipelineReader *reader, bool force) {
|
|
|
}
|
|
|
} else {
|
|
|
#ifndef OPENGLES_1
|
|
|
- if (_supports_geometry_instancing && _instance_count > 0) {
|
|
|
+ if (_instance_count != 1) {
|
|
|
_glDrawArraysInstanced(GL_POINTS,
|
|
|
reader->get_first_vertex(),
|
|
|
num_vertices, _instance_count);
|
|
|
@@ -9824,15 +9826,22 @@ get_external_image_format(Texture *tex) const {
|
|
|
|
|
|
case Texture::F_rgba:
|
|
|
case Texture::F_rgbm:
|
|
|
- case Texture::F_rgba4:
|
|
|
- case Texture::F_rgba5:
|
|
|
case Texture::F_rgba8:
|
|
|
case Texture::F_rgba12:
|
|
|
+ return _supports_bgr ? GL_BGRA : GL_RGBA;
|
|
|
+
|
|
|
+ case Texture::F_rgba4:
|
|
|
+ case Texture::F_rgba5:
|
|
|
case Texture::F_rgba16:
|
|
|
case Texture::F_rgba32:
|
|
|
case Texture::F_srgb_alpha:
|
|
|
case Texture::F_rgb10_a2:
|
|
|
+#ifdef OPENGLES
|
|
|
+ // OpenGL ES doesn't have sized BGRA formats.
|
|
|
+ return GL_RGBA;
|
|
|
+#else
|
|
|
return _supports_bgr ? GL_BGRA : GL_RGBA;
|
|
|
+#endif
|
|
|
|
|
|
case Texture::F_luminance:
|
|
|
#ifdef OPENGLES
|
|
|
@@ -10353,9 +10362,9 @@ get_internal_image_format(Texture *tex, bool force_sized) const {
|
|
|
|
|
|
#ifdef OPENGLES
|
|
|
case Texture::F_rgba8:
|
|
|
- return GL_RGBA8_OES;
|
|
|
+ return _supports_bgr ? GL_BGRA : GL_RGBA8_OES;
|
|
|
case Texture::F_rgba12:
|
|
|
- return force_sized ? GL_RGBA8 : GL_RGBA;
|
|
|
+ return _supports_bgr ? GL_BGRA : (force_sized ? GL_RGBA8 : GL_RGBA);
|
|
|
#else
|
|
|
case Texture::F_rgba8:
|
|
|
if (Texture::is_unsigned(tex->get_component_type())) {
|
|
|
@@ -11497,7 +11506,7 @@ set_state_and_transform(const RenderState *target,
|
|
|
|
|
|
#ifndef OPENGLES_1
|
|
|
determine_target_shader();
|
|
|
- _instance_count = _target_shader->get_instance_count();
|
|
|
+ _sattr_instance_count = _target_shader->get_instance_count();
|
|
|
|
|
|
if (_target_shader != _state_shader) {
|
|
|
do_issue_shader();
|
|
|
@@ -13832,7 +13841,11 @@ upload_simple_texture(CLP(TextureContext) *gtc) {
|
|
|
Texture *tex = gtc->get_texture();
|
|
|
nassertr(tex != nullptr, false);
|
|
|
|
|
|
+#ifdef OPENGLES
|
|
|
+ GLenum internal_format = GL_BGRA;
|
|
|
+#else
|
|
|
GLenum internal_format = GL_RGBA;
|
|
|
+#endif
|
|
|
GLenum external_format = GL_BGRA;
|
|
|
|
|
|
const unsigned char *image_ptr = tex->get_simple_ram_image();
|
|
|
@@ -13846,6 +13859,9 @@ upload_simple_texture(CLP(TextureContext) *gtc) {
|
|
|
// If the GL doesn't claim to support BGR, we may have to reverse the
|
|
|
// component ordering of the image.
|
|
|
external_format = GL_RGBA;
|
|
|
+#ifdef OPENGLES
|
|
|
+ internal_format = GL_RGBA;
|
|
|
+#endif
|
|
|
image_ptr = fix_component_ordering(bgr_image, image_ptr, image_size,
|
|
|
external_format, tex);
|
|
|
}
|