From d8ef25c9ce0d67ec89b28d63a8a4458dc3fcb81c Mon Sep 17 00:00:00 2001 From: Sam Hocevar Date: Mon, 19 Nov 2012 00:45:41 +0000 Subject: [PATCH] neercs: added a better check for forkpty(), and moved the GL_POINTS size and texture logic to the vertex shader. --- neercs/old/attach.c | 2 +- neercs/old/effects.c | 1 + neercs/old/grab.c | 2 +- neercs/term/pty.cpp | 14 +++++++------- neercs/video/text-render.cpp | 13 ++++++++++--- neercs/video/text-render.h | 4 +++- neercs/video/text.lolfx | 11 ++++++----- 7 files changed, 29 insertions(+), 18 deletions(-) diff --git a/neercs/old/attach.c b/neercs/old/attach.c index 0ac1593..bca63ea 100644 --- a/neercs/old/attach.c +++ b/neercs/old/attach.c @@ -16,7 +16,7 @@ # include "config.h" #endif -#if !defined _WIN32 +#if !defined _WIN32 && defined HAVE_GLOB_H #include #include diff --git a/neercs/old/effects.c b/neercs/old/effects.c index 4b824bc..fc54cc5 100644 --- a/neercs/old/effects.c +++ b/neercs/old/effects.c @@ -21,6 +21,7 @@ #include #include #include +#include #include #include #include diff --git a/neercs/old/grab.c b/neercs/old/grab.c index 4f71c70..029557f 100644 --- a/neercs/old/grab.c +++ b/neercs/old/grab.c @@ -14,7 +14,7 @@ # include "config.h" #endif -#if !defined _WIN32 +#if !defined _WIN32 && defined HAVE_GLOB_H #define _XOPEN_SOURCE 500 /* getsid() */ diff --git a/neercs/term/pty.cpp b/neercs/term/pty.cpp index 530e942..90cf843 100644 --- a/neercs/term/pty.cpp +++ b/neercs/term/pty.cpp @@ -14,7 +14,7 @@ # include "config.h" #endif -#if defined HAVE_PTY_H || defined HAVE_UTIL_H || defined HAVE_LIBUTIL_H +#if defined HAVE_FORKPTY # define _XOPEN_SOURCE # include # include @@ -53,7 +53,7 @@ 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; if (m_fd >= 0) @@ -65,7 +65,7 @@ Pty::~Pty() 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; pid_t pid; @@ -112,7 +112,7 @@ bool Pty::IsEof() const 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? */ 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) { -#if defined HAVE_PTY_H || defined HAVE_UTIL_H || defined HAVE_LIBUTIL_H +#if defined HAVE_FORKPTY char *new_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) { -#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? */ return write((int)m_fd, data, len); #endif @@ -203,7 +203,7 @@ size_t Pty::WriteData(char const *data, size_t len) 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) return; diff --git a/neercs/video/text-render.cpp b/neercs/video/text-render.cpp index 14583a2..3e4e046 100644 --- a/neercs/video/text-render.cpp +++ b/neercs/video/text-render.cpp @@ -50,8 +50,9 @@ void TextRender::Init() VertexUsage::Color, 0); m_char = m_shader->GetAttribLocation("in_Char", 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 = new VertexDeclaration(VertexStream(VertexUsage::Position), VertexStream(VertexUsage::Color), @@ -128,14 +129,18 @@ void TextRender::Render() m_fbo->Bind(); glViewport(0, 0, m_fbo_size.x, m_fbo_size.y); glDisable(GL_DEPTH_TEST); +#if !defined HAVE_GLES_2X glEnable(GL_POINT_SPRITE); //glEnable(GL_VERTEX_PROGRAM_POINT_SIZE); 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_font->Bind(); m_shader->SetUniform(m_texture, 0); 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_vbo2, m_color); m_vdecl->SetStream(m_vbo3, m_char); @@ -144,7 +149,9 @@ void TextRender::Render() m_vdecl->Unbind(); m_font->Unbind(); m_shader->Unbind(); +#if !defined HAVE_GLES_2X glDisable(GL_POINT_SPRITE); +#endif m_fbo->Unbind(); } diff --git a/neercs/video/text-render.h b/neercs/video/text-render.h index 101af5e..e9bc45c 100644 --- a/neercs/video/text-render.h +++ b/neercs/video/text-render.h @@ -20,11 +20,13 @@ private: int m_cells; TileSet *m_font; + Shader *m_shader; ShaderAttrib m_coord, m_color, m_char; - ShaderUniform m_texture, m_transform; + ShaderUniform m_texture, m_transform, m_pointsize; VertexDeclaration *m_vdecl; VertexBuffer *m_vbo1, *m_vbo2, *m_vbo3; + FrameBuffer *m_fbo; }; diff --git a/neercs/video/text.lolfx b/neercs/video/text.lolfx index acc08da..fa22246 100644 --- a/neercs/video/text.lolfx +++ b/neercs/video/text.lolfx @@ -15,7 +15,8 @@ varying vec4 pass_Foreground; varying vec4 pass_Background; varying vec2 pass_UV; -uniform mat4 in_Transform; +uniform float u_PointSize; +uniform mat4 u_Transform; void main() { @@ -56,9 +57,9 @@ void main() if (F + G + H < 0.01) E = 1.0; // 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] @@ -69,11 +70,11 @@ varying vec4 pass_Foreground; varying vec4 pass_Background; varying vec2 pass_UV; -uniform sampler2D in_Texture; +uniform sampler2D u_Texture; void main(void) { 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); }