Patch for OpenGL 1280 errors

This commit is contained in:
Charles J. Cliffe 2015-01-20 22:26:34 -05:00
parent 3657ce38bc
commit e9b99be18c
3 changed files with 81 additions and 52 deletions

View File

@ -141,7 +141,7 @@ void PrimaryGLContext::DrawDemodInfo(DemodulatorInstance *demod, float r, float
glVertex3f(uxPos + ofs, hPos + labelHeight, 0.0); glVertex3f(uxPos + ofs, hPos + labelHeight, 0.0);
glEnd(); glEnd();
glBlendFunc(GL_SRC_ALPHA, GL_DST_COLOR); glBlendFunc(GL_SRC_ALPHA, GL_ONE);
glColor4f(r, g, b, 0.2); glColor4f(r, g, b, 0.2);
glBegin(GL_QUADS); glBegin(GL_QUADS);
@ -189,11 +189,10 @@ void PrimaryGLContext::DrawDemod(DemodulatorInstance *demod, float r, float g, f
float uxPos = (float) (demod->getFrequency() - (center_freq - srate / 2)) / (float) srate; float uxPos = (float) (demod->getFrequency() - (center_freq - srate / 2)) / (float) srate;
glDisable(GL_DEPTH_TEST);
glDisable(GL_TEXTURE_2D); glDisable(GL_TEXTURE_2D);
glEnable(GL_BLEND); glEnable(GL_BLEND);
glBlendFunc(GL_SRC_ALPHA, GL_DST_COLOR); glBlendFunc(GL_SRC_ALPHA, GL_ONE);
glColor4f(r, g, b, 0.6); glColor4f(r, g, b, 0.6);
glBegin(GL_LINES); glBegin(GL_LINES);
@ -210,7 +209,7 @@ void PrimaryGLContext::DrawDemod(DemodulatorInstance *demod, float r, float g, f
glEnd(); glEnd();
glBlendFunc(GL_SRC_ALPHA, GL_DST_COLOR); glBlendFunc(GL_SRC_ALPHA, GL_ONE);
glColor4f(r, g, b, 0.2); glColor4f(r, g, b, 0.2);
glBegin(GL_QUADS); glBegin(GL_QUADS);
glVertex3f((uxPos - 0.5) * 2.0 - ofs, 1.0, 0.0); glVertex3f((uxPos - 0.5) * 2.0 - ofs, 1.0, 0.0);
@ -267,7 +266,6 @@ void PrimaryGLContext::DrawDemod(DemodulatorInstance *demod, float r, float g, f
getFont(PrimaryGLContext::GLFONT_SIZE16).drawString(demodStr, 2.0 * (uxPos - 0.5), -1.0 + hPos, 16, demodAlign, GLFont::GLFONT_ALIGN_CENTER); getFont(PrimaryGLContext::GLFONT_SIZE16).drawString(demodStr, 2.0 * (uxPos - 0.5), -1.0 + hPos, 16, demodAlign, GLFont::GLFONT_ALIGN_CENTER);
glDisable(GL_BLEND); glDisable(GL_BLEND);
glEnable(GL_DEPTH_TEST);
} }
@ -286,11 +284,10 @@ void PrimaryGLContext::DrawFreqSelector(float uxPos, float r, float g, float b,
srate = wxGetApp().getSampleRate(); srate = wxGetApp().getSampleRate();
} }
glDisable(GL_DEPTH_TEST);
glDisable(GL_TEXTURE_2D); glDisable(GL_TEXTURE_2D);
glEnable(GL_BLEND); glEnable(GL_BLEND);
glBlendFunc(GL_SRC_ALPHA, GL_DST_COLOR); glBlendFunc(GL_SRC_ALPHA, GL_ONE);
glColor4f(r, g, b, 0.6); glColor4f(r, g, b, 0.6);
glBegin(GL_LINES); glBegin(GL_LINES);
@ -313,7 +310,6 @@ void PrimaryGLContext::DrawFreqSelector(float uxPos, float r, float g, float b,
glEnd(); glEnd();
glDisable(GL_BLEND); glDisable(GL_BLEND);
glEnable(GL_DEPTH_TEST);
} }

View File

@ -3,91 +3,124 @@
#include "CubicSDR.h" #include "CubicSDR.h"
WaterfallContext::WaterfallContext(WaterfallCanvas *canvas, wxGLContext *sharedContext) : WaterfallContext::WaterfallContext(WaterfallCanvas *canvas, wxGLContext *sharedContext) :
PrimaryGLContext(canvas, sharedContext), waterfall(0), waterfall_tex(NULL), waterfall_lines(0), fft_size(0), activeTheme(NULL) { PrimaryGLContext(canvas, sharedContext), waterfall_lines(0), fft_size(0), activeTheme(NULL) {
for (int i = 0; i < 2; i++) {
waterfall[i] = 0;
waterfall_tex[i] = 0;
}
} }
void WaterfallContext::Setup(int fft_size_in, int num_waterfall_lines_in) { void WaterfallContext::Setup(int fft_size_in, int num_waterfall_lines_in) {
if (waterfall) {
glDeleteTextures(1, &waterfall);
waterfall = 0;
}
if (waterfall_tex) {
delete waterfall_tex;
}
waterfall_lines = num_waterfall_lines_in; waterfall_lines = num_waterfall_lines_in;
fft_size = fft_size_in; fft_size = fft_size_in;
waterfall_tex = new unsigned char[fft_size * waterfall_lines]; int half_fft_size = fft_size / 2;
memset(waterfall_tex, 0, fft_size * waterfall_lines);
for (int i = 0; i < 2; i++) {
if (waterfall[i]) {
glDeleteTextures(1, &waterfall[i]);
waterfall[i] = 0;
}
if (waterfall_tex[i]) {
delete waterfall_tex[i];
}
waterfall_tex[i] = new unsigned char[half_fft_size * waterfall_lines];
memset(waterfall_tex[i], 0, half_fft_size * waterfall_lines);
}
} }
void WaterfallContext::refreshTheme() { void WaterfallContext::refreshTheme() {
glEnable(GL_TEXTURE_2D); glEnable(GL_TEXTURE_2D);
glBindTexture(GL_TEXTURE_2D, waterfall);
glPixelTransferi(GL_MAP_COLOR, GL_TRUE); for (int i = 0; i < 2; i++) {
glPixelMapfv(GL_PIXEL_MAP_I_TO_R, 256, &(ThemeMgr::mgr.currentTheme->waterfallGradient.getRed())[0]); glBindTexture(GL_TEXTURE_2D, waterfall[i]);
glPixelMapfv(GL_PIXEL_MAP_I_TO_G, 256, &(ThemeMgr::mgr.currentTheme->waterfallGradient.getGreen())[0]);
glPixelMapfv(GL_PIXEL_MAP_I_TO_B, 256, &(ThemeMgr::mgr.currentTheme->waterfallGradient.getBlue())[0]); glPixelTransferi(GL_MAP_COLOR, GL_TRUE);
glPixelMapfv(GL_PIXEL_MAP_I_TO_R, 256, &(ThemeMgr::mgr.currentTheme->waterfallGradient.getRed())[0]);
glPixelMapfv(GL_PIXEL_MAP_I_TO_G, 256, &(ThemeMgr::mgr.currentTheme->waterfallGradient.getGreen())[0]);
glPixelMapfv(GL_PIXEL_MAP_I_TO_B, 256, &(ThemeMgr::mgr.currentTheme->waterfallGradient.getBlue())[0]);
}
} }
void WaterfallContext::Draw(std::vector<float> &points) { void WaterfallContext::Draw(std::vector<float> &points) {
if (!waterfall) { glEnable(GL_TEXTURE_2D);
glGenTextures(1, &waterfall); glTexEnvf(GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_DECAL);
glEnable(GL_TEXTURE_2D); if (!waterfall[0]) {
glBindTexture(GL_TEXTURE_2D, waterfall); glGenTextures(2, waterfall);
glPixelStorei(GL_UNPACK_ALIGNMENT, 1);
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_CLAMP); for (int i = 0; i < 2; i++) {
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_CLAMP); glBindTexture(GL_TEXTURE_2D, waterfall[i]);
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR); glPixelStorei(GL_UNPACK_ALIGNMENT, 1);
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR);
} glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_CLAMP);
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_CLAMP);
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR);
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR);
}
}
if (activeTheme != ThemeMgr::mgr.currentTheme) { if (activeTheme != ThemeMgr::mgr.currentTheme) {
refreshTheme(); refreshTheme();
activeTheme = ThemeMgr::mgr.currentTheme; activeTheme = ThemeMgr::mgr.currentTheme;
} }
glTexEnvf(GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_DECAL); int half_fft_size = fft_size / 2;
if (points.size()) { if (points.size()) {
memmove(waterfall_tex + fft_size, waterfall_tex, (waterfall_lines - 1) * fft_size); for (int j = 0; j < 2; j++) {
memmove(waterfall_tex[j] + half_fft_size, waterfall_tex[j], (waterfall_lines - 1) * half_fft_size);
for (int i = 0, iMax = fft_size; i < iMax; i++) { for (int i = 0, iMax = half_fft_size; i < iMax; i++) {
float v = points[i * 2 + 1]; float v = points[(j * half_fft_size + i) * 2 + 1];
float wv = v; float wv = v;
if (wv < 0.0) if (wv < 0.0)
wv = 0.0; wv = 0.0;
if (wv > 0.99) if (wv > 0.99)
wv = 0.99; wv = 0.99;
waterfall_tex[i] = (unsigned char) floor(wv * 255.0); waterfall_tex[j][i] = (unsigned char) floor(wv * 255.0);
}
} }
} }
glEnable(GL_TEXTURE_2D); for (int i = 0; i < 2; i++) {
glBindTexture(GL_TEXTURE_2D, waterfall[i]);
glBindTexture(GL_TEXTURE_2D, waterfall); glTexImage2D(GL_TEXTURE_2D, 0, GL_RGB, half_fft_size, waterfall_lines, 0, GL_COLOR_INDEX, GL_UNSIGNED_BYTE, (GLvoid *) waterfall_tex[i]);
glTexImage2D(GL_TEXTURE_2D, 0, GL_RGB, fft_size, waterfall_lines, 0, GL_COLOR_INDEX, GL_UNSIGNED_BYTE, (GLvoid *) waterfall_tex); }
glColor3f(1.0, 1.0, 1.0); glColor3f(1.0, 1.0, 1.0);
glBindTexture(GL_TEXTURE_2D, waterfall); glBindTexture(GL_TEXTURE_2D, waterfall[0]);
glBegin(GL_QUADS); glBegin(GL_QUADS);
glTexCoord2f(0.0, 1.0); glTexCoord2f(0.0, 1.0);
glVertex3f(-1.0, -1.0, 0.0); glVertex3f(-1.0, -1.0, 0.0);
glTexCoord2f(1.0, 1.0); glTexCoord2f(1.0, 1.0);
glVertex3f(0.0, -1.0, 0.0);
glTexCoord2f(1.0, 0.0);
glVertex3f(0.0, 1.0, 0.0);
glTexCoord2f(0.0, 0.0);
glVertex3f(-1.0, 1.0, 0.0);
glEnd();
glBindTexture(GL_TEXTURE_2D, waterfall[1]);
glBegin(GL_QUADS);
glTexCoord2f(0.0, 1.0);
glVertex3f(0.0, -1.0, 0.0);
glTexCoord2f(1.0, 1.0);
glVertex3f(1.0, -1.0, 0.0); glVertex3f(1.0, -1.0, 0.0);
glTexCoord2f(1.0, 0.0); glTexCoord2f(1.0, 0.0);
glVertex3f(1.0, 1.0, 0.0); glVertex3f(1.0, 1.0, 0.0);
glTexCoord2f(0.0, 0.0); glTexCoord2f(0.0, 0.0);
glVertex3f(-1.0, 1.0, 0.0); glVertex3f(0.0, 1.0, 0.0);
glEnd(); glEnd();
glBindTexture(GL_TEXTURE_2D, 0);
glTexEnvf(GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_MODULATE); glTexEnvf(GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_MODULATE);
glDisable(GL_TEXTURE_2D);
} }

View File

@ -15,8 +15,8 @@ public:
void refreshTheme(); void refreshTheme();
private: private:
GLuint waterfall; GLuint waterfall[2];
unsigned char *waterfall_tex; unsigned char *waterfall_tex[2];
int fft_size; int fft_size;
int waterfall_lines; int waterfall_lines;