basic GLES working again

This commit is contained in:
milek7
2021-01-20 19:29:50 +01:00
parent 97d6547824
commit f0b364bafe
10 changed files with 398 additions and 23974 deletions

View File

@@ -231,6 +231,7 @@ gl::shader::shader(const std::string &filename)
str += "precision highp float;\n";
str += "precision highp int;\n";
str += "precision highp sampler2DShadow;\n";
str += "precision highp sampler2DArrayShadow;\n";
}
str += "vec4 FBOUT(vec4 x) { return " + (Global.gfx_shadergamma ? std::string("vec4(pow(x.rgb, vec3(1.0 / 2.2)), x.a)") : std::string("x")) + "; }\n";

View File

@@ -29,6 +29,8 @@ void gl::vao::setup_attrib(gl::buffer &buffer, int attrib, int size, int type, i
glEnableVertexAttribArray(attrib);
}
else {
if (attrib == 0)
params.clear();
params.push_back({buffer, attrib, size, type, stride, offset});
active = nullptr;
}

View File

@@ -122,20 +122,14 @@
#endif
#endif
// Desktop GL has glDrawElementsBaseVertex() which GL ES and WebGL don't have.
#if defined(IMGUI_IMPL_OPENGL_ES2) || defined(IMGUI_IMPL_OPENGL_ES3)
#define IMGUI_IMPL_OPENGL_HAS_DRAW_WITH_BASE_VERTEX 0
#else
#define IMGUI_IMPL_OPENGL_HAS_DRAW_WITH_BASE_VERTEX 1
#endif
// OpenGL Data
static char g_GlslVersionString[32] = "";
static char g_GlslVersionString[128] = "";
static GLuint g_FontTexture = 0;
static GLuint g_ShaderHandle = 0, g_VertHandle = 0, g_FragHandle = 0;
static int g_AttribLocationTex = 0, g_AttribLocationProjMtx = 0; // Uniforms location
static int g_AttribLocationVtxPos = 0, g_AttribLocationVtxUV = 0, g_AttribLocationVtxColor = 0; // Vertex attributes location
static unsigned int g_VboHandle = 0, g_ElementsHandle = 0;
static int IMGUI_IMPL_OPENGL_HAS_DRAW_WITH_BASE_VERTEX = 0;
// Functions
bool ImGui_ImplOpenGL3_Init(const char* glsl_version)
@@ -143,6 +137,10 @@ bool ImGui_ImplOpenGL3_Init(const char* glsl_version)
// Setup back-end capabilities flags
ImGuiIO& io = ImGui::GetIO();
io.BackendRendererName = "imgui_impl_opengl3";
if (GLAD_GL_VERSION_3_3 || GLAD_GL_ES_VERSION_3_2)
IMGUI_IMPL_OPENGL_HAS_DRAW_WITH_BASE_VERTEX = 1;
#if IMGUI_IMPL_OPENGL_HAS_DRAW_WITH_BASE_VERTEX
io.BackendFlags |= ImGuiBackendFlags_RendererHasVtxOffset; // We can honor the ImDrawCmd::VtxOffset field, allowing for large meshes.
#endif
@@ -191,9 +189,6 @@ static void ImGui_ImplOpenGL3_SetupRenderState(ImDrawData* draw_data, int fb_wid
glDisable(GL_CULL_FACE);
glDisable(GL_DEPTH_TEST);
glEnable(GL_SCISSOR_TEST);
#ifdef GL_POLYGON_MODE
glPolygonMode(GL_FRONT_AND_BACK, GL_FILL);
#endif
// Setup viewport, orthographic projection matrix
// Our visible imgui space lies from draw_data->DisplayPos (top left) to draw_data->DisplayPos+data_data->DisplaySize (bottom right). DisplayPos is (0,0) for single viewport apps.
@@ -254,16 +249,10 @@ void ImGui_ImplOpenGL3_RenderDrawData(ImDrawData* draw_data)
GLint last_array_buffer; glGetIntegerv(GL_ARRAY_BUFFER_BINDING, &last_array_buffer);
#ifndef IMGUI_IMPL_OPENGL_ES2
GLint last_vertex_array_object; glGetIntegerv(GL_VERTEX_ARRAY_BINDING, &last_vertex_array_object);
#endif
#ifdef GL_POLYGON_MODE
GLint last_polygon_mode[2];
#endif
GLboolean last_enable_srgb;
if (!Global.gfx_usegles)
{
glGetIntegerv(GL_POLYGON_MODE, last_polygon_mode);
glPolygonMode(GL_FRONT_AND_BACK, GL_FILL);
if (!Global.gfx_shadergamma)
{
last_enable_srgb = glIsEnabled(GL_FRAMEBUFFER_SRGB);
@@ -380,9 +369,6 @@ void ImGui_ImplOpenGL3_RenderDrawData(ImDrawData* draw_data)
if (!Global.gfx_usegles)
{
#ifdef GL_POLYGON_MODE
glPolygonMode(GL_FRONT_AND_BACK, (GLenum)last_polygon_mode[0]);
#endif
if (!Global.gfx_shadergamma)
{
if (last_enable_srgb)

View File

@@ -94,11 +94,18 @@ void opengl33_vaogeometrybank::setup_buffer()
ErrorLog( "openGL error: out of memory; failed to create a geometry buffer" );
throw std::bad_alloc();
}
m_vao->setup_attrib( *m_vertexbuffer, 0, 3, GL_FLOAT, sizeof( basic_vertex ), 0 * sizeof( float ) );
setup_attrib();
}
void
opengl33_vaogeometrybank::setup_attrib(size_t offset)
{
m_vao->setup_attrib( *m_vertexbuffer, 0, 3, GL_FLOAT, sizeof( basic_vertex ), 0 * sizeof( float ) + offset * sizeof( basic_vertex ) );
// NOTE: normal and color streams share the data
m_vao->setup_attrib( *m_vertexbuffer, 1, 3, GL_FLOAT, sizeof( basic_vertex ), 3 * sizeof( float ) );
m_vao->setup_attrib( *m_vertexbuffer, 2, 2, GL_FLOAT, sizeof( basic_vertex ), 6 * sizeof( float ) );
m_vao->setup_attrib( *m_vertexbuffer, 3, 4, GL_FLOAT, sizeof( basic_vertex ), 8 * sizeof( float ) );
m_vao->setup_attrib( *m_vertexbuffer, 1, 3, GL_FLOAT, sizeof( basic_vertex ), 3 * sizeof( float ) + offset * sizeof( basic_vertex ) );
m_vao->setup_attrib( *m_vertexbuffer, 2, 2, GL_FLOAT, sizeof( basic_vertex ), 6 * sizeof( float ) + offset * sizeof( basic_vertex ) );
m_vao->setup_attrib( *m_vertexbuffer, 3, 4, GL_FLOAT, sizeof( basic_vertex ), 8 * sizeof( float ) + offset * sizeof( basic_vertex ) );
}
// draw() subclass details
@@ -114,10 +121,9 @@ opengl33_vaogeometrybank::draw_( gfx::geometry_handle const &Geometry, gfx::stre
if( chunkrecord.vertex_count == 0 )
return 0;
m_vao->bind();
auto const &chunk = gfx::geometry_bank::chunk( Geometry );
if( false == chunkrecord.is_good ) {
m_vao->bind();
// we may potentially need to upload new buffer data before we can draw it
if( chunkrecord.index_count > 0 ) {
m_indexbuffer->upload( gl::buffer::ELEMENT_ARRAY_BUFFER, chunk.indices.data(), chunkrecord.index_offset * sizeof( gfx::basic_index ), chunkrecord.index_count * sizeof( gfx::basic_index ) );
@@ -133,13 +139,25 @@ opengl33_vaogeometrybank::draw_( gfx::geometry_handle const &Geometry, gfx::stre
chunkrecord.index_count, GL_UNSIGNED_INT, reinterpret_cast<void const *>( chunkrecord.index_offset * sizeof( gfx::basic_index ) ),
chunkrecord.vertex_offset );
*/
::glDrawRangeElementsBaseVertex(
chunk.type,
0, chunkrecord.vertex_count,
chunkrecord.index_count, GL_UNSIGNED_INT, reinterpret_cast<void const *>( chunkrecord.index_offset * sizeof( gfx::basic_index ) ),
chunkrecord.vertex_offset );
if (GLAD_GL_VERSION_3_3 || GLAD_GL_ES_VERSION_3_2) {
m_vao->bind();
::glDrawRangeElementsBaseVertex(
chunk.type,
0, chunkrecord.vertex_count,
chunkrecord.index_count, GL_UNSIGNED_INT, reinterpret_cast<void const *>( chunkrecord.index_offset * sizeof( gfx::basic_index ) ),
chunkrecord.vertex_offset );
}
else {
setup_attrib(chunkrecord.vertex_offset);
m_vao->bind();
::glDrawRangeElements(
chunk.type,
0, chunkrecord.vertex_count,
chunkrecord.index_count, GL_UNSIGNED_INT, reinterpret_cast<void const *>( chunkrecord.index_offset * sizeof( gfx::basic_index ) ) );
}
}
else {
m_vao->bind();
::glDrawArrays( chunk.type, chunkrecord.vertex_offset, chunkrecord.vertex_count );
}
/*

View File

@@ -57,6 +57,8 @@ private:
release_() override;
void
setup_buffer();
void
setup_attrib(size_t offset = 0);
void
delete_buffer();

View File

@@ -119,7 +119,7 @@
* This follows the return type of the function and precedes the function
* name in the function prototype.
*/
#if defined(_WIN32) && !defined(_WIN32_WCE) && !defined(KHRONOS_STATIC)
#if defined(_WIN32) && !defined(_WIN32_WCE) && !defined(__SCITECH_SNAP__)
/* Win32 but not WinCE */
# define KHRONOS_APIENTRY __stdcall
#else

File diff suppressed because one or more lines are too long

File diff suppressed because one or more lines are too long

View File

@@ -32,7 +32,7 @@ float calc_shadow()
//basic
// shadow = texture(shadowmap, coords.xyz + vec3(0.0, 0.0, bias));
//PCF
float bias = 0.00005f * (cascade + 1U);
float bias = 0.00005f * float(cascade + 1U);
vec2 texel = vec2(1.0) / vec2(textureSize(shadowmap, 0));
float radius = 1.0;
for (float y = -1.5; y <= 1.5; y += 1.0)

View File

@@ -245,7 +245,7 @@ bool ui_layer::init(GLFWwindow *Window)
ImGui_ImplOpenGL2_Init();
#else
if (Global.gfx_usegles)
ImGui_ImplOpenGL3_Init("#version 300 es\nprecision highp float;");
ImGui_ImplOpenGL3_Init("#version 310 es\nprecision highp float;");
else
ImGui_ImplOpenGL3_Init("#version 330 core");
#endif