210 |
|
const char * src = |
211 |
|
"uniform sampler2D screen;" |
212 |
|
"uniform sampler1D palette;" |
213 |
< |
"uniform float texSize;" |
213 |
> |
"const float texSize = 512.0;" // texture size |
214 |
> |
"const float texel = 1.0 / texSize;" |
215 |
|
"void main()" |
216 |
|
"{" |
217 |
|
#if 0 |
223 |
|
// (setting the GL_TEXTURE_MAG_FILTER to GL_LINEAR would interpolate |
224 |
|
// the color indices which is not what we want; we need to manually |
225 |
|
// interpolate the palette values instead) |
225 |
– |
" const float texel = 1.0 / texSize;" |
226 |
|
" vec2 st = gl_TexCoord[0].st - vec2(texel * 0.5, texel * 0.5);" |
227 |
|
" vec4 idx00 = texture2D(screen, st);" |
228 |
|
" vec4 idx01 = texture2D(screen, st + vec2(0, texel));" |
229 |
|
" vec4 idx10 = texture2D(screen, st + vec2(texel, 0));" |
230 |
|
" vec4 idx11 = texture2D(screen, st + vec2(texel, texel));" |
231 |
< |
" float s1 = fract(st.s * texSize);" |
232 |
< |
" float s0 = 1.0 - s1;" |
233 |
< |
" float t1 = fract(st.t * texSize);" |
234 |
< |
" float t0 = 1.0 - t1;" |
235 |
< |
" vec4 color00 = texture1D(palette, idx00.r) * s0 * t0;" |
236 |
< |
" vec4 color01 = texture1D(palette, idx01.r) * s0 * t1;" |
237 |
< |
" vec4 color10 = texture1D(palette, idx10.r) * s1 * t0;" |
238 |
< |
" vec4 color11 = texture1D(palette, idx11.r) * s1 * t1;" |
239 |
< |
" gl_FragColor = color00 + color01 + color10 + color11;" |
231 |
> |
" vec2 f = fract(st * texSize);" |
232 |
> |
" vec4 color0 = mix(texture1D(palette, idx00.r), texture1D(palette, idx01.r), f.y);" |
233 |
> |
" vec4 color1 = mix(texture1D(palette, idx10.r), texture1D(palette, idx11.r), f.y);" |
234 |
> |
" gl_FragColor = mix(color0, color1, f.x);" |
235 |
|
#endif |
236 |
|
"}"; |
237 |
|
glShaderSource(shader, 1, &src, NULL); |
256 |
|
glLinkProgram(program); |
257 |
|
glUseProgram(program); |
258 |
|
|
264 |
– |
glUniform1f(glGetUniformLocation(program, "texSize"), float(TEXTURE_SIZE)); |
265 |
– |
|
259 |
|
// Create VIC display texture (8-bit color index in the red channel) |
260 |
|
uint8 *tmp = (uint8 *)malloc(TEXTURE_SIZE * TEXTURE_SIZE); |
261 |
|
memset(tmp, 0, TEXTURE_SIZE * TEXTURE_SIZE); |