Skip to content
This repository was archived by the owner on Aug 27, 2025. It is now read-only.
Open
Show file tree
Hide file tree
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
55 changes: 54 additions & 1 deletion host_applications/linux/apps/raspicam/RaspiTexUtil.c
Original file line number Diff line number Diff line change
Expand Up @@ -582,7 +582,25 @@ int raspitexutil_build_shader_program(RASPITEXUTIL_SHADER_PROGRAM_T *p)
}
}

return 0;
/// Automatically find uniform variables
glGetProgramiv( p->program, GL_ACTIVE_UNIFORM_MAX_LENGTH, &p->max_length);
glGetProgramiv( p->program, GL_ACTIVE_UNIFORMS, &p->uniform_count);
printf("found %d uniform variable(s) : \n",p->uniform_count);

raspitexutil_create_param_array(p);

GLchar *name= (GLchar*) malloc(sizeof(GLchar)*p->max_length);
GLsizei length=0;
RASPITEXUTIL_SHADER_PARAMETER_T *array = p->uniform_array;
for(i=0;i<p->uniform_count;i++){
glGetActiveUniform(p->program, i, p->max_length, &length, &array[i].size, &array[i].type, name);
array[i].loc = glGetUniformLocation( p->program, name );
strncpy(array[i].name,name,length+1);
printf("\t%s\n",name);
}
free(name);

return 0;

fail:
vcos_log_error("%s: Failed to build shader program", VCOS_FUNCTION);
Expand All @@ -595,3 +613,38 @@ int raspitexutil_build_shader_program(RASPITEXUTIL_SHADER_PROGRAM_T *p)
return -1;
}

void raspitexutil_create_param_array(RASPITEXUTIL_SHADER_PROGRAM_T *p)
{

int i;

p->uniform_array = (RASPITEXUTIL_SHADER_PARAMETER_T*) malloc(sizeof (RASPITEXUTIL_SHADER_PARAMETER_T) * p->uniform_count);
p->attribute_array = (RASPITEXUTIL_SHADER_PARAMETER_T*) malloc(sizeof (RASPITEXUTIL_SHADER_PARAMETER_T) * p->attribute_count);

RASPITEXUTIL_SHADER_PARAMETER_T* array = p->uniform_array;
// allocate maximum size for a param, which is a 4x4 matrix of floats
// in the future, only allocate for specific type
// also, technically we should handle arrays of matrices, too...sheesh!
for (i = 0; i < p->uniform_count; i++) {
int j=0;
array[i].size = 0;
array[i].type = 0;
array[i].loc = 0;
// uniform_array[i].param = (float*) malloc(sizeof(float)*16);
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

remove commented out code

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

done

array[i].name = (GLchar*) malloc(sizeof(GLchar)* p->max_length+1);;
array[i].flag = 0;
for(j=0; j<16; j++)array[i].param[j]=0;
}

array = p->attribute_array;
for (i = 0; i < p->attribute_count; i++) {
int j=0;
array[i].size = 0;
array[i].type = 0;
array[i].loc = 0;
// attribute_array[i].param = (float*) malloc(sizeof(float)*16);
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

remove commented out code

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

done

array[i].name = (GLchar*) malloc(sizeof(GLchar)* p->max_length+1);
array[i].flag = 0;
for(j=0; j<16; j++)array[i].param[j]=0;
}
}
23 changes: 23 additions & 0 deletions host_applications/linux/apps/raspicam/RaspiTexUtil.h
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,19 @@ extern VCOS_LOG_CAT_T raspitex_log_category;

#define SHADER_MAX_ATTRIBUTES 16
#define SHADER_MAX_UNIFORMS 16

typedef struct RASPITEXUTIL_SHADER_PARAMETER_T
{
// Variables for the, uh, variables
// stolen from puredata/gem glsl_program.h, thanks guys ;-)
GLint size;
GLenum type;
GLint loc;
GLchar *name;
GLfloat param[16];
int flag;
} RASPITEXUTIL_SHADER_PARAMETER_T;

/**
* Container for a simple shader program. The uniform and attribute locations
* are automatically setup by raspitex_build_shader_program.
Expand All @@ -51,7 +64,16 @@ typedef struct RASPITEXUTIL_SHADER_PROGRAM_T
{
const char *vertex_source; /// Pointer to vertex shader source
const char *fragment_source; /// Pointer to fragment shader source

GLint max_length; /// Maximum length of parameter name;
GLint uniform_count, attribute_count; /// Number of parameters


char* fragment_shader_filename;
char* vertex_shader_filename;
/// Array of shader paramaters (uniform and attributes)
RASPITEXUTIL_SHADER_PARAMETER_T *uniform_array, *attribute_array;

/// Array of uniform names for raspitex_build_shader_program to process
const char *uniform_names[SHADER_MAX_UNIFORMS];
/// Array of attribute names for raspitex_build_shader_program to process
Expand Down Expand Up @@ -112,5 +134,6 @@ void raspitexutil_close(RASPITEX_STATE* raspitex_state);
/* Utility functions */
int raspitexutil_build_shader_program(RASPITEXUTIL_SHADER_PROGRAM_T *p);
void raspitexutil_brga_to_rgba(uint8_t *buffer, size_t size);
void raspitexutil_create_param_array(RASPITEXUTIL_SHADER_PROGRAM_T *p);

#endif /* RASPITEX_UTIL_H_ */