mirror of
https://github.com/enduro2d/enduro2d.git
synced 2025-12-15 00:11:55 +07:00
added opengl4 support (for debugging with RenderDoc)
This commit is contained in:
@@ -871,7 +871,8 @@ namespace e2d
|
||||
unknown,
|
||||
opengles2,
|
||||
opengles3,
|
||||
opengl_compat
|
||||
opengl2_compat,
|
||||
opengl4_compat
|
||||
};
|
||||
|
||||
struct device_caps {
|
||||
|
||||
@@ -25,13 +25,20 @@ namespace
|
||||
precision highp int;
|
||||
precision highp float;
|
||||
)glsl";
|
||||
case e2d::render::api_profile::opengl_compat:
|
||||
case e2d::render::api_profile::opengl2_compat:
|
||||
return R"glsl(
|
||||
#version 120
|
||||
#define highp
|
||||
#define mediump
|
||||
#define lowp
|
||||
)glsl";
|
||||
case e2d::render::api_profile::opengl4_compat:
|
||||
return R"glsl(
|
||||
#version 410 core
|
||||
#define texture2D texture
|
||||
#define varying out
|
||||
#define attribute in
|
||||
)glsl";
|
||||
default:
|
||||
E2D_ASSERT_MSG(false, "unexpected render API profile");
|
||||
return "";
|
||||
@@ -48,13 +55,20 @@ namespace
|
||||
precision mediump int;
|
||||
precision mediump float;
|
||||
)glsl";
|
||||
case e2d::render::api_profile::opengl_compat:
|
||||
case e2d::render::api_profile::opengl2_compat:
|
||||
return R"glsl(
|
||||
#version 120
|
||||
#define highp
|
||||
#define mediump
|
||||
#define lowp
|
||||
)glsl";
|
||||
case e2d::render::api_profile::opengl4_compat:
|
||||
return R"glsl(
|
||||
#version 410 core
|
||||
#define texture2D texture
|
||||
#define varying in
|
||||
layout(location=0) out vec4 gl_FragColor;
|
||||
)glsl";
|
||||
default:
|
||||
E2D_ASSERT_MSG(false, "unexpected render API profile");
|
||||
return "";
|
||||
|
||||
@@ -127,6 +127,7 @@ namespace
|
||||
|
||||
gl_210 = 210 | gl_bit_,
|
||||
gl_300 = 300 | gl_bit_,
|
||||
gl_410 = 410 | gl_bit_,
|
||||
gles_200 = 200 | gles_bit_,
|
||||
gles_300 = 300 | gles_bit_
|
||||
};
|
||||
@@ -1367,7 +1368,8 @@ namespace e2d::opengl
|
||||
caps.profile =
|
||||
version >= gl_version::gles_300 ? render::api_profile::opengles3 :
|
||||
version >= gl_version::gles_200 ? render::api_profile::opengles2 :
|
||||
render::api_profile::opengl_compat;
|
||||
version >= gl_version::gl_410 ? render::api_profile::opengl4_compat :
|
||||
render::api_profile::opengl2_compat;
|
||||
|
||||
caps.npot_texture_supported =
|
||||
version >= gl_version::gl_210 ||
|
||||
@@ -1431,6 +1433,10 @@ namespace e2d::opengl
|
||||
"GL_IMG_texture_compression_pvrtc2");
|
||||
}
|
||||
|
||||
bool gl_has_extension(debug& debug, str_view name) noexcept {
|
||||
return gl_has_any_extension(debug, name);
|
||||
}
|
||||
|
||||
gl_shader_id gl_compile_shader(
|
||||
debug& debug,
|
||||
str_view header,
|
||||
|
||||
@@ -295,6 +295,7 @@ namespace e2d::opengl
|
||||
void gl_trace_info(debug& debug) noexcept;
|
||||
void gl_trace_limits(debug& debug) noexcept;
|
||||
void gl_fill_device_caps(debug& debug, render::device_caps& caps) noexcept;
|
||||
bool gl_has_extension(debug& debug, str_view name) noexcept;
|
||||
|
||||
gl_shader_id gl_compile_shader(
|
||||
debug& debug,
|
||||
|
||||
@@ -219,6 +219,7 @@ namespace e2d
|
||||
GL_CHECK_CODE(debug_, glPixelStorei(GL_PACK_ALIGNMENT, 1));
|
||||
GL_CHECK_CODE(debug_, glPixelStorei(GL_UNPACK_ALIGNMENT, 1));
|
||||
|
||||
create_debug_output_();
|
||||
reset_states();
|
||||
reset_shader_program();
|
||||
reset_render_target();
|
||||
@@ -395,6 +396,78 @@ namespace e2d
|
||||
GL_CHECK_CODE(debug_, enable_or_disable(GL_DEPTH_TEST, cs.depth_test()));
|
||||
GL_CHECK_CODE(debug_, enable_or_disable(GL_STENCIL_TEST, cs.stencil_test()));
|
||||
}
|
||||
|
||||
void render::internal_state::create_debug_output_() noexcept {
|
||||
if ( !gl_has_extension(debug_, "GL_ARB_debug_output") ) {
|
||||
return;
|
||||
}
|
||||
|
||||
GL_CHECK_CODE(debug_, glDebugMessageCallbackARB(debug_output_callback_, this));
|
||||
|
||||
// disable notifications
|
||||
GL_CHECK_CODE(debug_, glDebugMessageControlARB(
|
||||
GL_DONT_CARE,
|
||||
GL_DONT_CARE,
|
||||
GL_DEBUG_SEVERITY_NOTIFICATION,
|
||||
0,
|
||||
nullptr,
|
||||
GL_FALSE));
|
||||
}
|
||||
|
||||
void render::internal_state::debug_output_callback_(
|
||||
GLenum source,
|
||||
GLenum type,
|
||||
GLuint id,
|
||||
GLenum severity,
|
||||
GLsizei length,
|
||||
const GLchar* message,
|
||||
const void* userParam)
|
||||
{
|
||||
if ( !userParam ) {
|
||||
return;
|
||||
}
|
||||
|
||||
str msg;
|
||||
switch ( severity ) {
|
||||
case GL_DEBUG_SEVERITY_HIGH : msg += "[High]"; break;
|
||||
case GL_DEBUG_SEVERITY_MEDIUM : msg += "[Medium]"; break;
|
||||
case GL_DEBUG_SEVERITY_LOW : msg += "[Low]"; break;
|
||||
case GL_DEBUG_SEVERITY_NOTIFICATION : msg += "[Notification]"; break;
|
||||
}
|
||||
|
||||
msg += " src: ";
|
||||
switch ( source ) {
|
||||
case GL_DEBUG_SOURCE_API : msg += "OpenGL"; break;
|
||||
case GL_DEBUG_SOURCE_WINDOW_SYSTEM : msg += "OS"; break;
|
||||
case GL_DEBUG_SOURCE_SHADER_COMPILER : msg += "GL_Compiler"; break;
|
||||
case GL_DEBUG_SOURCE_THIRD_PARTY : msg += "Third_Party"; break;
|
||||
case GL_DEBUG_SOURCE_APPLICATION : msg += "Application"; break;
|
||||
case GL_DEBUG_SOURCE_OTHER :
|
||||
default : msg += "Other"; break;
|
||||
}
|
||||
|
||||
msg += ", type: ";
|
||||
switch ( type ) {
|
||||
case GL_DEBUG_TYPE_ERROR : msg += "Error"; break;
|
||||
case GL_DEBUG_TYPE_DEPRECATED_BEHAVIOR : msg += "Deprecated"; break;
|
||||
case GL_DEBUG_TYPE_UNDEFINED_BEHAVIOR : msg += "Undefined_Behavior"; break;
|
||||
case GL_DEBUG_TYPE_PORTABILITY : msg += "Portability"; break;
|
||||
case GL_DEBUG_TYPE_PERFORMANCE : msg += "Performance"; break;
|
||||
case GL_DEBUG_TYPE_MARKER : msg += "Marker"; break;
|
||||
case GL_DEBUG_TYPE_PUSH_GROUP : msg += "Push_Group"; break;
|
||||
case GL_DEBUG_TYPE_POP_GROUP : msg += "Pop_Group"; break;
|
||||
case GL_DEBUG_TYPE_OTHER :
|
||||
default : msg += "Other"; break;
|
||||
}
|
||||
|
||||
msg += "\n";
|
||||
|
||||
if ( message && length ) {
|
||||
msg += str_view(message, length);
|
||||
}
|
||||
|
||||
static_cast<const internal_state*>(userParam)->debug_.trace(msg);
|
||||
}
|
||||
}
|
||||
|
||||
#endif
|
||||
|
||||
@@ -190,6 +190,15 @@ namespace e2d
|
||||
void set_culling_state_(const culling_state& cs) noexcept;
|
||||
void set_blending_state_(const blending_state& bs) noexcept;
|
||||
void set_capabilities_state_(const capabilities_state& cs) noexcept;
|
||||
void create_debug_output_() noexcept;
|
||||
static void GLAPIENTRY debug_output_callback_(
|
||||
GLenum source,
|
||||
GLenum type,
|
||||
GLuint id,
|
||||
GLenum severity,
|
||||
GLsizei length,
|
||||
const GLchar* message,
|
||||
const void* userParam);
|
||||
private:
|
||||
debug& debug_;
|
||||
window& window_;
|
||||
|
||||
Reference in New Issue
Block a user