avdl_shaders.h 2.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869
  1. #ifndef AVDL_SHADERS_H
  2. #define AVDL_SHADERS_H
  3. #include <dd_opengl.h>
  4. struct avdl_program {
  5. char *sdrVertexSrc;
  6. char *sdrFragmentSrc;
  7. int openglContext;
  8. int program;
  9. void (*clean)(struct avdl_program *);
  10. void (*setVertexShader)(struct avdl_program *, char *source);
  11. void (*setFragmentShader)(struct avdl_program *, char *source);
  12. void (*useProgram)(struct avdl_program *);
  13. };
  14. void avdl_program_create(struct avdl_program *);
  15. void avdl_program_clean(struct avdl_program *);
  16. void avdl_program_setVertexShader(struct avdl_program *, char *source);
  17. void avdl_program_setFragmentShader(struct avdl_program *, char *source);
  18. void avdl_program_useProgram(struct avdl_program *);
  19. /*
  20. * function to change the current program
  21. */
  22. void avdl_useProgram(struct avdl_program *o);
  23. /*
  24. * get/edit uniforms
  25. */
  26. int avdl_getUniformLocation(struct avdl_program *o, char *varname);
  27. #define avdl_setUniformMatrix4f(uniform, matrix) glUniformMatrix4fv(unfirom, 1, GL_FALSE, matrix)
  28. #define avdl_setUniform1f(uniform, f1) glUniform1f(uniform, f1)
  29. #define avdl_setUniform2f(uniform, f1, f2) glUniform2f(uniform, f1, f2)
  30. #define avdl_setUniform3f(uniform, f1, f2, f3) glUniform3f(uniform, f1, f2, f3)
  31. #define avdl_setUniform4f(uniform, f1, f2, f3, f4) glUniform4f(uniform, f1, f2, f3, f4)
  32. #define avdl_setUniform1i(uniform, i1) glUniform1i(uniform, i1)
  33. #define avdl_setUniform2i(uniform, i1, i2) glUniform2i(uniform, i1, i2)
  34. #define avdl_setUniform3i(uniform, i1, i2, i3) glUniform3i(uniform, i1, i2, i3)
  35. #define avdl_setUniform4i(uniform, i1, i2, i3, i4) glUniform4i(uniform, i1, i2, i3, i4)
  36. #define avdl_setUniform1ui(uniform, ui1) glUniform1ui(uniform, ui1)
  37. #define avdl_setUniform2ui(uniform, ui1, ui2) glUniform2ui(uniform, ui1, ui2)
  38. #define avdl_setUniform3ui(uniform, ui1, ui2, ui3) glUniform3ui(uniform, ui1, ui2, ui3)
  39. #define avdl_setUniform4ui(uniform, ui1, ui2, ui3, ui4) glUniform4ui(uniform, ui1, ui2, ui3, ui4)
  40. /*
  41. * takes a string for the vertex and one for the fragment shader as parameters,
  42. * returns the number of the created program, or `0` if an error occured.
  43. */
  44. unsigned int avdl_loadProgram(const char *vfname, const char *ffname);
  45. /*
  46. * the default shader, draws vertex colors and textures only
  47. */
  48. extern const char *avdl_shaderDefault_vertex;
  49. extern const char *avdl_shaderDefault_fragment;
  50. /*
  51. * the font shader, used only for text
  52. */
  53. extern const char *avdl_shaderFont_vertex;
  54. extern const char *avdl_shaderFont_fragment;
  55. #endif