Skip to content

Commit

Permalink
Use unsigned int for shaderCount all through shaders, correct createP…
Browse files Browse the repository at this point in the history
…rogram() declaration
  • Loading branch information
stuarthayhurst committed Oct 3, 2024
1 parent 41ec7ab commit 1025d7e
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 9 deletions.
5 changes: 4 additions & 1 deletion src/ammonite/graphics/internal/internalShaders.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -6,10 +6,13 @@
- Allow loading shaders by path or directory
*/

#include <string>

namespace ammonite {
namespace shaders {
namespace internal {
int createProgram(const char* shaderPaths[], const int shaderCount, bool* externalSuccess);
int createProgram(std::string* shaderPaths, unsigned int shaderCount,
bool* externalSuccess);
int loadDirectory(const char* directoryPath, bool* externalSuccess);
void updateCacheSupport();
}
Expand Down
16 changes: 8 additions & 8 deletions src/ammonite/graphics/shaders.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ namespace ammonite {

//Data required by cache worker
struct CacheWorkerData {
int shaderCount;
unsigned int shaderCount;
std::string* shaderPaths;
std::string cacheFilePath;
int binaryLength;
Expand Down Expand Up @@ -203,7 +203,7 @@ namespace ammonite {
}

//Take multiple shader objects and create a program
static int createProgramObject(GLuint* shaderIds, const int shaderCount,
static int createProgramObject(GLuint* shaderIds, int shaderCount,
bool* externalSuccess) {
//Create the program
GLuint programId = glCreateProgram();
Expand Down Expand Up @@ -232,11 +232,11 @@ namespace ammonite {

//Create a program from shader source with loadShader() and createProgramObject()
static int createProgramUncached(std::string* shaderPaths, GLenum* shaderTypes,
int shaderCount, bool* externalSuccess) {
unsigned int shaderCount, bool* externalSuccess) {
//Since cache wasn't available, generate fresh shaders
GLuint* shaderIds = new GLuint[shaderCount];
bool hasCreatedShaders = true;
for (int i = 0; i < shaderCount; i++) {
for (unsigned int i = 0; i < shaderCount; i++) {
bool passed = true;
shaderIds[i] = loadShader(shaderPaths[i], shaderTypes[i], &passed);
if (!passed) {
Expand All @@ -256,7 +256,7 @@ namespace ammonite {
//Clean up
if (!hasCreatedProgram || !hasCreatedShaders) {
*externalSuccess = false;
for (int i = 0; i < shaderCount; i++) {
for (unsigned int i = 0; i < shaderCount; i++) {
if (shaderIds[i] != unsigned(-1)) {
glDeleteShader(shaderIds[i]);
}
Expand All @@ -271,7 +271,7 @@ namespace ammonite {

//Attempt to use a cached program or hand off to createProgramUncached()
static int createProgramCached(std::string* shaderPaths, GLenum* shaderTypes,
int shaderCount, bool* externalSuccess) {
unsigned int shaderCount, bool* externalSuccess) {
//Check for OpenGL and engine cache support
bool isCacheSupported = ammonite::utils::files::getCacheEnabled();
isCacheSupported = isCacheSupported && isBinaryCacheSupported;
Expand Down Expand Up @@ -361,12 +361,12 @@ namespace ammonite {
- If possible, load and store a cache
- Writes 'false' to externalSuccess on failure and returns -1
*/
int createProgram(std::string* inputShaderPaths, int inputShaderCount,
int createProgram(std::string* inputShaderPaths, unsigned int inputShaderCount,
bool* externalSuccess) {
//Find all shaders
std::vector<std::string> shaderPaths(0);
std::vector<GLenum> shaderTypes(0);
for (int i = 0; i < inputShaderCount; i++) {
for (unsigned int i = 0; i < inputShaderCount; i++) {
std::filesystem::path filePath{inputShaderPaths[i]};
std::string extension = filePath.extension();

Expand Down

0 comments on commit 1025d7e

Please sign in to comment.