src/shader.c

changeset 153
4116e2bd501b
parent 152
c3ae2b2e8ff6
equal deleted inserted replaced
152:c3ae2b2e8ff6 153:4116e2bd501b
55 55
56 // some drivers don't like NULL strings, even when length is zero 56 // some drivers don't like NULL strings, even when length is zero
57 if (code_pp == NULL) code_pp = ""; 57 if (code_pp == NULL) code_pp = "";
58 58
59 GLint success; 59 GLint success;
60 const char *code_array[4]; 60 const char *code_array[4] = {
61 "#version 400 core\n",
62 code_pp,
63 "\n#line 1\n",
64 code
65 };
61 GLint length_array[4]; 66 GLint length_array[4];
62 #define store_str(i, s) do {cxstring cxs = cx_str(s); code_array[i] = cxs.ptr; length_array[i] = (GLint) cxs.length;} while(0) 67 for (unsigned int i = 0; i < cx_nmemb(length_array); i++) {
63 store_str(0, "#version 400 core\n"); 68 length_array[i] = (GLint) strlen(code_array[i]);
64 store_str(1, code_pp); 69 }
65 store_str(2, "\n#line 1\n");
66 store_str(3, code);
67 #undef store_str
68 70
69 // compile 71 // compile
70 glShaderSource(id, cx_nmemb(length_array), code_array, length_array); 72 glShaderSource(id, cx_nmemb(length_array), code_array, length_array);
71 glCompileShader(id); 73 glCompileShader(id);
72 glGetShaderiv(id, GL_COMPILE_STATUS, &success); 74 glGetShaderiv(id, GL_COMPILE_STATUS, &success);

mercurial