size and texture logic to the vertex shader.master
@@ -16,7 +16,7 @@ | |||||
# include "config.h" | # include "config.h" | ||||
#endif | #endif | ||||
#if !defined _WIN32 | |||||
#if !defined _WIN32 && defined HAVE_GLOB_H | |||||
#include <errno.h> | #include <errno.h> | ||||
#include <fcntl.h> | #include <fcntl.h> | ||||
@@ -21,6 +21,7 @@ | |||||
#include <stdlib.h> | #include <stdlib.h> | ||||
#include <string.h> | #include <string.h> | ||||
#include <time.h> | #include <time.h> | ||||
#include <endian.h> | |||||
#include <sys/wait.h> | #include <sys/wait.h> | ||||
#include <sys/types.h> | #include <sys/types.h> | ||||
#include <caca.h> | #include <caca.h> | ||||
@@ -14,7 +14,7 @@ | |||||
# include "config.h" | # include "config.h" | ||||
#endif | #endif | ||||
#if !defined _WIN32 | |||||
#if !defined _WIN32 && defined HAVE_GLOB_H | |||||
#define _XOPEN_SOURCE 500 /* getsid() */ | #define _XOPEN_SOURCE 500 /* getsid() */ | ||||
@@ -14,7 +14,7 @@ | |||||
# include "config.h" | # include "config.h" | ||||
#endif | #endif | ||||
#if defined HAVE_PTY_H || defined HAVE_UTIL_H || defined HAVE_LIBUTIL_H | |||||
#if defined HAVE_FORKPTY | |||||
# define _XOPEN_SOURCE | # define _XOPEN_SOURCE | ||||
# include <stdlib.h> | # include <stdlib.h> | ||||
# include <stdio.h> | # include <stdio.h> | ||||
@@ -53,7 +53,7 @@ Pty::Pty() | |||||
Pty::~Pty() | Pty::~Pty() | ||||
{ | { | ||||
#if defined HAVE_PTY_H || defined HAVE_UTIL_H || defined HAVE_LIBUTIL_H | |||||
#if defined HAVE_FORKPTY | |||||
delete[] m_unread_data; | delete[] m_unread_data; | ||||
if (m_fd >= 0) | if (m_fd >= 0) | ||||
@@ -65,7 +65,7 @@ Pty::~Pty() | |||||
void Pty::Run(char const *command, ivec2 size) | void Pty::Run(char const *command, ivec2 size) | ||||
{ | { | ||||
#if defined HAVE_PTY_H || defined HAVE_UTIL_H || defined HAVE_LIBUTIL_H | |||||
#if defined HAVE_FORKPTY | |||||
int fd; | int fd; | ||||
pid_t pid; | pid_t pid; | ||||
@@ -112,7 +112,7 @@ bool Pty::IsEof() const | |||||
size_t Pty::ReadData(char *data, size_t maxlen) | size_t Pty::ReadData(char *data, size_t maxlen) | ||||
{ | { | ||||
#if defined HAVE_PTY_H || defined HAVE_UTIL_H || defined HAVE_LIBUTIL_H | |||||
#if defined HAVE_FORKPTY | |||||
/* Do we have data from previous call? */ | /* Do we have data from previous call? */ | ||||
if (m_unread_len) | if (m_unread_len) | ||||
{ | { | ||||
@@ -172,7 +172,7 @@ size_t Pty::ReadData(char *data, size_t maxlen) | |||||
void Pty::UnreadData(char *data, size_t len) | void Pty::UnreadData(char *data, size_t len) | ||||
{ | { | ||||
#if defined HAVE_PTY_H || defined HAVE_UTIL_H || defined HAVE_LIBUTIL_H | |||||
#if defined HAVE_FORKPTY | |||||
char *new_data; | char *new_data; | ||||
if (m_unread_data) | if (m_unread_data) | ||||
@@ -193,7 +193,7 @@ void Pty::UnreadData(char *data, size_t len) | |||||
size_t Pty::WriteData(char const *data, size_t len) | size_t Pty::WriteData(char const *data, size_t len) | ||||
{ | { | ||||
#if defined HAVE_PTY_H || defined HAVE_UTIL_H || defined HAVE_LIBUTIL_H | |||||
#if defined HAVE_FORKPTY | |||||
/* FIXME: can we be more naive than that? */ | /* FIXME: can we be more naive than that? */ | ||||
return write((int)m_fd, data, len); | return write((int)m_fd, data, len); | ||||
#endif | #endif | ||||
@@ -203,7 +203,7 @@ size_t Pty::WriteData(char const *data, size_t len) | |||||
void Pty::SetWindowSize(ivec2 size, int64_t fd /* = -1 */) | void Pty::SetWindowSize(ivec2 size, int64_t fd /* = -1 */) | ||||
{ | { | ||||
#if defined HAVE_PTY_H || defined HAVE_UTIL_H || defined HAVE_LIBUTIL_H | |||||
#if defined HAVE_FORKPTY | |||||
if (m_size == size) | if (m_size == size) | ||||
return; | return; | ||||
@@ -50,8 +50,9 @@ void TextRender::Init() | |||||
VertexUsage::Color, 0); | VertexUsage::Color, 0); | ||||
m_char = m_shader->GetAttribLocation("in_Char", | m_char = m_shader->GetAttribLocation("in_Char", | ||||
VertexUsage::Color, 1); | VertexUsage::Color, 1); | ||||
m_texture = m_shader->GetUniformLocation("in_Texture"); | |||||
m_transform = m_shader->GetUniformLocation("in_Transform"); | |||||
m_texture = m_shader->GetUniformLocation("u_Texture"); | |||||
m_transform = m_shader->GetUniformLocation("u_Transform"); | |||||
m_pointsize = m_shader->GetUniformLocation("u_PointSize"); | |||||
m_vdecl | m_vdecl | ||||
= new VertexDeclaration(VertexStream<vec2>(VertexUsage::Position), | = new VertexDeclaration(VertexStream<vec2>(VertexUsage::Position), | ||||
VertexStream<uint32_t>(VertexUsage::Color), | VertexStream<uint32_t>(VertexUsage::Color), | ||||
@@ -128,14 +129,18 @@ void TextRender::Render() | |||||
m_fbo->Bind(); | m_fbo->Bind(); | ||||
glViewport(0, 0, m_fbo_size.x, m_fbo_size.y); | glViewport(0, 0, m_fbo_size.x, m_fbo_size.y); | ||||
glDisable(GL_DEPTH_TEST); | glDisable(GL_DEPTH_TEST); | ||||
#if !defined HAVE_GLES_2X | |||||
glEnable(GL_POINT_SPRITE); | glEnable(GL_POINT_SPRITE); | ||||
//glEnable(GL_VERTEX_PROGRAM_POINT_SIZE); | //glEnable(GL_VERTEX_PROGRAM_POINT_SIZE); | ||||
glDisable(GL_POINT_SMOOTH); | glDisable(GL_POINT_SMOOTH); | ||||
glPointSize((float)max(m_font_size.x, m_font_size.y)); | |||||
#endif | |||||
glEnable(GL_VERTEX_PROGRAM_POINT_SIZE); | |||||
glTexEnvi(GL_POINT_SPRITE, GL_COORD_REPLACE, GL_TRUE); | |||||
m_shader->Bind(); | m_shader->Bind(); | ||||
m_font->Bind(); | m_font->Bind(); | ||||
m_shader->SetUniform(m_texture, 0); | m_shader->SetUniform(m_texture, 0); | ||||
m_shader->SetUniform(m_transform, xform); | m_shader->SetUniform(m_transform, xform); | ||||
m_shader->SetUniform(m_pointsize, (float)max(m_font_size.x, m_font_size.y)); | |||||
m_vdecl->SetStream(m_vbo1, m_coord); | m_vdecl->SetStream(m_vbo1, m_coord); | ||||
m_vdecl->SetStream(m_vbo2, m_color); | m_vdecl->SetStream(m_vbo2, m_color); | ||||
m_vdecl->SetStream(m_vbo3, m_char); | m_vdecl->SetStream(m_vbo3, m_char); | ||||
@@ -144,7 +149,9 @@ void TextRender::Render() | |||||
m_vdecl->Unbind(); | m_vdecl->Unbind(); | ||||
m_font->Unbind(); | m_font->Unbind(); | ||||
m_shader->Unbind(); | m_shader->Unbind(); | ||||
#if !defined HAVE_GLES_2X | |||||
glDisable(GL_POINT_SPRITE); | glDisable(GL_POINT_SPRITE); | ||||
#endif | |||||
m_fbo->Unbind(); | m_fbo->Unbind(); | ||||
} | } | ||||
@@ -20,11 +20,13 @@ private: | |||||
int m_cells; | int m_cells; | ||||
TileSet *m_font; | TileSet *m_font; | ||||
Shader *m_shader; | Shader *m_shader; | ||||
ShaderAttrib m_coord, m_color, m_char; | ShaderAttrib m_coord, m_color, m_char; | ||||
ShaderUniform m_texture, m_transform; | |||||
ShaderUniform m_texture, m_transform, m_pointsize; | |||||
VertexDeclaration *m_vdecl; | VertexDeclaration *m_vdecl; | ||||
VertexBuffer *m_vbo1, *m_vbo2, *m_vbo3; | VertexBuffer *m_vbo1, *m_vbo2, *m_vbo3; | ||||
FrameBuffer *m_fbo; | FrameBuffer *m_fbo; | ||||
}; | }; | ||||
@@ -15,7 +15,8 @@ varying vec4 pass_Foreground; | |||||
varying vec4 pass_Background; | varying vec4 pass_Background; | ||||
varying vec2 pass_UV; | varying vec2 pass_UV; | ||||
uniform mat4 in_Transform; | |||||
uniform float u_PointSize; | |||||
uniform mat4 u_Transform; | |||||
void main() | void main() | ||||
{ | { | ||||
@@ -56,9 +57,9 @@ void main() | |||||
if (F + G + H < 0.01) E = 1.0; | if (F + G + H < 0.01) E = 1.0; | ||||
// This only works with glEnable(GL_VERTEX_PROGRAM_POINT_SIZE); | // This only works with glEnable(GL_VERTEX_PROGRAM_POINT_SIZE); | ||||
//gl_PointSize = 40; | |||||
gl_PointSize = u_PointSize; | |||||
gl_Position = in_Transform * vec4(in_Position, 0.0, 1.0); | |||||
gl_Position = u_Transform * vec4(in_Position, 0.0, 1.0); | |||||
} | } | ||||
[frag.glsl] | [frag.glsl] | ||||
@@ -69,11 +70,11 @@ varying vec4 pass_Foreground; | |||||
varying vec4 pass_Background; | varying vec4 pass_Background; | ||||
varying vec2 pass_UV; | varying vec2 pass_UV; | ||||
uniform sampler2D in_Texture; | |||||
uniform sampler2D u_Texture; | |||||
void main(void) | void main(void) | ||||
{ | { | ||||
vec2 c = gl_PointCoord * (1.0 / 32.0) + pass_UV; | vec2 c = gl_PointCoord * (1.0 / 32.0) + pass_UV; | ||||
float t = texture2D(in_Texture, c).x; | |||||
float t = texture2D(u_Texture, c).x; | |||||
gl_FragColor = mix(pass_Background, pass_Foreground, t); | gl_FragColor = mix(pass_Background, pass_Foreground, t); | ||||
} | } |