Mercurial > repos > blastem
comparison render_sdl.c @ 742:2e1b3b258523
Make Windows port a little less half-assed
author | Michael Pavone <pavone@retrodev.com> |
---|---|
date | Tue, 01 Apr 2014 21:12:00 -0700 |
parents | b7b7a1cab44a |
children | fc68992cf18d |
comparison
equal
deleted
inserted
replaced
741:80a67be1770b | 742:2e1b3b258523 |
---|---|
111 | 111 |
112 const GLushort element_data[] = {0, 1, 2, 3}; | 112 const GLushort element_data[] = {0, 1, 2, 3}; |
113 | 113 |
114 GLuint load_shader(char * fname, GLenum shader_type) | 114 GLuint load_shader(char * fname, GLenum shader_type) |
115 { | 115 { |
116 char * parts[] = {getenv("HOME"), "/.config/blastem/shaders/", fname}; | 116 char * parts[] = {get_home_dir(), "/.config/blastem/shaders/", fname}; |
117 char * shader_path = alloc_concat_m(3, parts); | 117 char * shader_path = alloc_concat_m(3, parts); |
118 printf("Trying to find shader at %s\n", shader_path); | |
118 FILE * f = fopen(shader_path, "r"); | 119 FILE * f = fopen(shader_path, "r"); |
119 free(shader_path); | 120 free(shader_path); |
120 if (!f) { | 121 if (!f) { |
122 #ifdef _WIN32 | |
123 parts[0] = "shaders/"; | |
124 parts[1] = fname; | |
125 shader_path = alloc_concat_m(2, parts); | |
126 #else | |
121 parts[0] = get_exe_dir(); | 127 parts[0] = get_exe_dir(); |
122 parts[1] = "/shaders/"; | 128 parts[1] = "/shaders/"; |
123 shader_path = alloc_concat_m(3, parts); | 129 shader_path = alloc_concat_m(3, parts); |
130 #endif | |
131 printf("Trying to find shader at %s\n", shader_path); | |
124 f = fopen(shader_path, "r"); | 132 f = fopen(shader_path, "r"); |
125 free(shader_path); | 133 free(shader_path); |
126 if (!f) { | 134 if (!f) { |
127 fprintf(stderr, "Failed to open shader file %s for reading\n", fname); | 135 fprintf(stderr, "Failed to open shader file %s for reading\n", fname); |
128 return 0; | 136 return 0; |
129 } | 137 } |
130 } | 138 } |
139 puts("reading shader"); | |
131 long fsize = file_size(f); | 140 long fsize = file_size(f); |
132 GLchar * text = malloc(fsize); | 141 GLchar * text = malloc(fsize); |
133 if (fread(text, 1, fsize, f) != fsize) { | 142 if (fread(text, 1, fsize, f) != fsize) { |
134 fprintf(stderr, "Error reading from shader file %s\n", fname); | 143 fprintf(stderr, "Error reading from shader file %s\n", fname); |
135 free(text); | 144 free(text); |
136 return 0; | 145 return 0; |
137 } | 146 } |
138 GLuint ret = glCreateShader(shader_type); | 147 GLuint ret = glCreateShader(shader_type); |
139 glShaderSource(ret, 1, (const GLchar **)&text, (const GLint *)&fsize); | 148 glShaderSource(ret, 1, (const GLchar **)&text, (const GLint *)&fsize); |
140 free(text); | 149 free(text); |
150 puts("compiling shader"); | |
141 glCompileShader(ret); | 151 glCompileShader(ret); |
142 GLint compile_status, loglen; | 152 GLint compile_status, loglen; |
143 glGetShaderiv(ret, GL_COMPILE_STATUS, &compile_status); | 153 glGetShaderiv(ret, GL_COMPILE_STATUS, &compile_status); |
144 if (!compile_status) { | 154 if (!compile_status) { |
145 fprintf(stderr, "Shader %s failed to compile\n", fname); | 155 fprintf(stderr, "Shader %s failed to compile\n", fname); |
160 #ifndef DISABLE_OPENGL | 170 #ifndef DISABLE_OPENGL |
161 if (render_gl) { | 171 if (render_gl) { |
162 context->oddbuf = context->framebuf = malloc(512 * 256 * 4 * 2); | 172 context->oddbuf = context->framebuf = malloc(512 * 256 * 4 * 2); |
163 memset(context->oddbuf, 0, 512 * 256 * 4 * 2); | 173 memset(context->oddbuf, 0, 512 * 256 * 4 * 2); |
164 context->evenbuf = ((char *)context->oddbuf) + 512 * 256 * 4; | 174 context->evenbuf = ((char *)context->oddbuf) + 512 * 256 * 4; |
175 puts("generating textures"); | |
165 glGenTextures(3, textures); | 176 glGenTextures(3, textures); |
166 for (int i = 0; i < 3; i++) | 177 for (int i = 0; i < 3; i++) |
167 { | 178 { |
168 glBindTexture(GL_TEXTURE_2D, textures[i]); | 179 glBindTexture(GL_TEXTURE_2D, textures[i]); |
169 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR); | 180 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR); |
180 glGenBuffers(2, buffers); | 191 glGenBuffers(2, buffers); |
181 glBindBuffer(GL_ARRAY_BUFFER, buffers[0]); | 192 glBindBuffer(GL_ARRAY_BUFFER, buffers[0]); |
182 glBufferData(GL_ARRAY_BUFFER, sizeof(vertex_data), vertex_data, GL_STATIC_DRAW); | 193 glBufferData(GL_ARRAY_BUFFER, sizeof(vertex_data), vertex_data, GL_STATIC_DRAW); |
183 glBindBuffer(GL_ELEMENT_ARRAY_BUFFER, buffers[1]); | 194 glBindBuffer(GL_ELEMENT_ARRAY_BUFFER, buffers[1]); |
184 glBufferData(GL_ELEMENT_ARRAY_BUFFER, sizeof(element_data), element_data, GL_STATIC_DRAW); | 195 glBufferData(GL_ELEMENT_ARRAY_BUFFER, sizeof(element_data), element_data, GL_STATIC_DRAW); |
196 puts("Loading vertex shader"); | |
185 vshader = load_shader(tern_find_ptr_default(config, "videovertex_shader", "default.v.glsl"), GL_VERTEX_SHADER); | 197 vshader = load_shader(tern_find_ptr_default(config, "videovertex_shader", "default.v.glsl"), GL_VERTEX_SHADER); |
198 puts("loading fragment shader"); | |
186 fshader = load_shader(tern_find_ptr_default(config, "videofragment_shader", "default.f.glsl"), GL_FRAGMENT_SHADER); | 199 fshader = load_shader(tern_find_ptr_default(config, "videofragment_shader", "default.f.glsl"), GL_FRAGMENT_SHADER); |
200 puts("creating program"); | |
187 program = glCreateProgram(); | 201 program = glCreateProgram(); |
188 glAttachShader(program, vshader); | 202 glAttachShader(program, vshader); |
189 glAttachShader(program, fshader); | 203 glAttachShader(program, fshader); |
204 puts("linking program"); | |
190 glLinkProgram(program); | 205 glLinkProgram(program); |
191 GLint link_status; | 206 GLint link_status; |
192 glGetProgramiv(program, GL_LINK_STATUS, &link_status); | 207 glGetProgramiv(program, GL_LINK_STATUS, &link_status); |
193 if (!link_status) { | 208 if (!link_status) { |
194 fputs("Failed to link shader program\n", stderr); | 209 fputs("Failed to link shader program\n", stderr); |
203 context->oddbuf = context->framebuf = malloc(320 * 240 * screen->format->BytesPerPixel * 2); | 218 context->oddbuf = context->framebuf = malloc(320 * 240 * screen->format->BytesPerPixel * 2); |
204 context->evenbuf = ((char *)context->oddbuf) + 320 * 240 * screen->format->BytesPerPixel; | 219 context->evenbuf = ((char *)context->oddbuf) + 320 * 240 * screen->format->BytesPerPixel; |
205 #ifndef DISABLE_OPENGL | 220 #ifndef DISABLE_OPENGL |
206 } | 221 } |
207 #endif | 222 #endif |
223 puts("alloc surfaces done"); | |
208 } | 224 } |
209 | 225 |
210 uint8_t render_depth() | 226 uint8_t render_depth() |
211 { | 227 { |
212 return screen->format->BytesPerPixel * 8; | 228 return screen->format->BytesPerPixel * 8; |