Skip to content

Instantly share code, notes, and snippets.

@sgithens
Created January 9, 2025 02:28
Show Gist options
  • Select an option

  • Save sgithens/03e94462cb2dc5420cae2373ea1269d3 to your computer and use it in GitHub Desktop.

Select an option

Save sgithens/03e94462cb2dc5420cae2373ea1269d3 to your computer and use it in GitHub Desktop.
Passing lisp strings in to c functions
(defvar vertexSource "attribute vec4 position;
varying vec3 color;
void main()
{
gl_Position = vec4(position.xyz, 1.0);
color = gl_Position.xyz + vec3(0.5);
}")
(gl:shader-source vertex-shader vertexSource)
const GLchar* vertexSource =
"attribute vec4 position; \n"
"varying vec3 color; \n"
"void main() \n"
"{ \n"
" gl_Position = vec4(position.xyz, 1.0); \n"
" color = gl_Position.xyz + vec3(0.5); \n"
"} \n";
// In c/c++ this call would have been:
// glShaderSource(vertexShader, 1, &vertexSource, NULL);
// I'm not sure if the ecl_string already has a pointer inside it somewhere with the string
// allocated, or if that needs to be done still, it doens't seem ready to be coerced, as this
// doesn't work.
// (const char *const *) ecl_foreign_data_pointer_safe(ecl_null_terminated_base_string(source))
//
cl_object lisp_gl_shader_source(cl_object shader, cl_object source) {
glShaderSource(ecl_fixnum(shader), 1, ??source??, NULL);
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment