Performance optimization
Some checks failed
Run ReCI Build Test / Explore-Gitea-Actions (push) Has been cancelled
Some checks failed
Run ReCI Build Test / Explore-Gitea-Actions (push) Has been cancelled
This commit is contained in:
@@ -88,7 +88,6 @@ void Default() {
|
||||
}
|
||||
|
||||
void main() {
|
||||
|
||||
/* If you want behavior per JGL draw function, Or for specific ones. The order here matters because some JGL functions call others.
|
||||
if (JGL_RENDERING_ROUTINE == J2D_DrawRenderTarget)
|
||||
Default();
|
||||
|
@@ -41,9 +41,9 @@ public:
|
||||
Shader(const std::string& vertex_code, const std::string& fragment_code);
|
||||
|
||||
/// @return True if the shader program successfully loaded and compiled.
|
||||
bool Loaded() const;
|
||||
[[nodiscard]] bool Loaded() const;
|
||||
/// @return The integer handle that OpenGL links to this shader program.
|
||||
unsigned int Handle() const;
|
||||
[[nodiscard]] unsigned int Handle() const;
|
||||
/// Enable this shader. All rendering performed thereafter will be affected by this shader code.
|
||||
/// @see UseDefault.
|
||||
|
||||
@@ -58,7 +58,7 @@ public:
|
||||
|
||||
/// @return The Attribute variable linked to the specified name.
|
||||
/// Attributes differ from Uniforms in that their value is different for each instance of the shader-program as it is running.
|
||||
GLint Attribute(const std::string& name) const;
|
||||
[[nodiscard]] GLint Attribute(const std::string& name) const;
|
||||
|
||||
/// Sets a `uniform bool name = value` in the shader program.
|
||||
void SetBool (const std::string& name, bool value) const;
|
||||
@@ -116,5 +116,6 @@ private:
|
||||
std::string vertexSource;
|
||||
std::string fragmentSource;
|
||||
std::string fragmentPath;
|
||||
mutable std::unordered_map<std::string, GLint> uniform_location_cache;
|
||||
static void checkCompileErrors(GLuint shader, const std::string& type);
|
||||
};
|
@@ -236,6 +236,7 @@ void JGL::J3D::BatchWireframeRevoSphere(const Color4& color, const Sphere* spher
|
||||
glLineWidth(thickness);
|
||||
glColor4ubv(color.ptr());
|
||||
|
||||
// TODO allocate once.
|
||||
VRamList vertex_data(vertices.data(), vertices.size());
|
||||
glBindBuffer(GL_ARRAY_BUFFER, vertex_data.GetHandle());
|
||||
glVertexPointer(3, GL_FLOAT, sizeof(Vector3), nullptr);
|
||||
|
@@ -144,7 +144,13 @@ namespace JGL {
|
||||
}
|
||||
|
||||
GLint Shader::Uniform(const std::string &name) const {
|
||||
return glGetUniformLocation(id, name.c_str());
|
||||
auto it = uniform_location_cache.find(name);
|
||||
if (it == uniform_location_cache.end()) {
|
||||
auto location = glGetUniformLocation(id, name.c_str());
|
||||
uniform_location_cache[name] = location;
|
||||
return location;
|
||||
}
|
||||
return it->second;
|
||||
}
|
||||
|
||||
GLint Shader::Attribute(const std::string &name) const {
|
||||
@@ -155,8 +161,6 @@ namespace JGL {
|
||||
vertexSource = vertex_code;
|
||||
fragmentSource = fragment_code;
|
||||
|
||||
|
||||
|
||||
const char* vShaderCode = vertex_code.c_str();
|
||||
const char* fShaderCode = fragment_code.c_str();
|
||||
|
||||
|
Reference in New Issue
Block a user