Added several asserts to Video Display and stopped it from running Reset() when hidden, which could be leading to odd results.

Originally committed to SVN as r964.
This commit is contained in:
Rodrigo Braz Monteiro 2007-03-29 23:04:26 +00:00
parent 0dd4f96757
commit cc99e37e2c
1 changed files with 38 additions and 0 deletions

View File

@ -136,14 +136,19 @@ void VideoDisplay::Render() {
// Set GL context // Set GL context
VideoContext *context = VideoContext::Get(); VideoContext *context = VideoContext::Get();
wxASSERT(context);
SetCurrent(*context->GetGLContext(this)); SetCurrent(*context->GetGLContext(this));
// Get sizes // Get sizes
int w,h,sw,sh,pw,ph; int w,h,sw,sh,pw,ph;
GetClientSize(&w,&h); GetClientSize(&w,&h);
wxASSERT(w > 0);
wxASSERT(h > 0);
context->GetScriptSize(sw,sh); context->GetScriptSize(sw,sh);
pw = context->GetWidth(); pw = context->GetWidth();
ph = context->GetHeight(); ph = context->GetHeight();
wxASSERT(pw > 0);
wxASSERT(ph > 0);
// Freesized transform // Freesized transform
dx1 = 0; dx1 = 0;
@ -151,8 +156,13 @@ void VideoDisplay::Render() {
dx2 = w; dx2 = w;
dy2 = h; dy2 = h;
if (freeSize) { if (freeSize) {
// Clear frame buffer
glClearColor(0,0,0,0); glClearColor(0,0,0,0);
if (glGetError()) throw _T("Error setting glClearColor().");
glClear(GL_COLOR_BUFFER_BIT); glClear(GL_COLOR_BUFFER_BIT);
if (glGetError()) throw _T("Error calling glClear().");
// Set aspect ratio
float thisAr = float(w)/float(h); float thisAr = float(w)/float(h);
float vidAr; float vidAr;
if (context->GetAspectRatioType() == 0) vidAr = float(pw)/float(ph); if (context->GetAspectRatioType() == 0) vidAr = float(pw)/float(ph);
@ -175,6 +185,7 @@ void VideoDisplay::Render() {
// Set viewport // Set viewport
glEnable(GL_TEXTURE_2D); glEnable(GL_TEXTURE_2D);
if (glGetError()) throw _T("Error enabling texturing.");
glMatrixMode(GL_MODELVIEW); glMatrixMode(GL_MODELVIEW);
glLoadIdentity(); glLoadIdentity();
glViewport(dx1,dy1,dx2,dy2); glViewport(dx1,dy1,dx2,dy2);
@ -182,31 +193,40 @@ void VideoDisplay::Render() {
glLoadIdentity(); glLoadIdentity();
glOrtho(0.0f,sw,sh,0.0f,-1000.0f,1000.0f); glOrtho(0.0f,sw,sh,0.0f,-1000.0f,1000.0f);
glMatrixMode(GL_MODELVIEW); glMatrixMode(GL_MODELVIEW);
if (glGetError()) throw _T("Error setting up matrices (wtf?).");
// Texture mode // Texture mode
if (w != pw || h != ph) { if (w != pw || h != ph) {
glTexParameteri(GL_TEXTURE_2D,GL_TEXTURE_MIN_FILTER,GL_LINEAR); glTexParameteri(GL_TEXTURE_2D,GL_TEXTURE_MIN_FILTER,GL_LINEAR);
if (glGetError()) throw _T("Error setting texture parameter min filter.");
glTexParameteri(GL_TEXTURE_2D,GL_TEXTURE_MAG_FILTER,GL_LINEAR); glTexParameteri(GL_TEXTURE_2D,GL_TEXTURE_MAG_FILTER,GL_LINEAR);
if (glGetError()) throw _T("Error setting texture parameter mag filter.");
} }
else { else {
glTexParameteri(GL_TEXTURE_2D,GL_TEXTURE_MIN_FILTER,GL_NEAREST); glTexParameteri(GL_TEXTURE_2D,GL_TEXTURE_MIN_FILTER,GL_NEAREST);
if (glGetError()) throw _T("Error setting texture parameter min filter.");
glTexParameteri(GL_TEXTURE_2D,GL_TEXTURE_MAG_FILTER,GL_NEAREST); glTexParameteri(GL_TEXTURE_2D,GL_TEXTURE_MAG_FILTER,GL_NEAREST);
if (glGetError()) throw _T("Error setting texture parameter mag filter.");
} }
// Texture coordinates // Texture coordinates
float top = 0.0f; float top = 0.0f;
float bot = context->GetTexH(); float bot = context->GetTexH();
wxASSERT(bot != 0.0f);
if (context->IsInverted()) { if (context->IsInverted()) {
top = context->GetTexH(); top = context->GetTexH();
bot = 0.0f; bot = 0.0f;
} }
float left = 0.0; float left = 0.0;
float right = context->GetTexW(); float right = context->GetTexW();
wxASSERT(right != 0.0f);
// Draw frame // Draw frame
glDisable(GL_BLEND); glDisable(GL_BLEND);
if (glGetError()) throw _T("Error disabling blending.");
context->SetShader(true); context->SetShader(true);
glBindTexture(GL_TEXTURE_2D, VideoContext::Get()->GetFrameAsTexture(-1)); glBindTexture(GL_TEXTURE_2D, VideoContext::Get()->GetFrameAsTexture(-1));
if (glGetError()) throw _T("Error binding texture.");
glColor4f(1.0f,1.0f,1.0f,1.0f); glColor4f(1.0f,1.0f,1.0f,1.0f);
glBegin(GL_QUADS); glBegin(GL_QUADS);
// Top-left // Top-left
@ -225,10 +245,12 @@ void VideoDisplay::Render() {
context->SetShader(false); context->SetShader(false);
// Draw overlay // Draw overlay
wxASSERT(visual);
visual->DrawOverlay(); visual->DrawOverlay();
// Swap buffers // Swap buffers
glFinish(); glFinish();
if (glGetError()) throw _T("Error finishing gl operation.");
SwapBuffers(); SwapBuffers();
} }
@ -241,6 +263,7 @@ void VideoDisplay::UpdateSize() {
// Loaded? // Loaded?
VideoContext *con = VideoContext::Get(); VideoContext *con = VideoContext::Get();
wxASSERT(con);
if (!con->IsLoaded()) return; if (!con->IsLoaded()) return;
if (!IsShownOnScreen()) return; if (!IsShownOnScreen()) return;
@ -256,6 +279,8 @@ void VideoDisplay::UpdateSize() {
SetSizeHints(w,h,w,h); SetSizeHints(w,h,w,h);
SetClientSize(w,h); SetClientSize(w,h);
GetSize(&_w,&_h); GetSize(&_w,&_h);
wxASSERT(_w > 0);
wxASSERT(_h > 0);
SetSizeHints(_w,_h,_w,_h); SetSizeHints(_w,_h,_w,_h);
box->VideoSizer->Fit(box); box->VideoSizer->Fit(box);
@ -272,11 +297,17 @@ void VideoDisplay::UpdateSize() {
////////// //////////
// Resets // Resets
void VideoDisplay::Reset() { void VideoDisplay::Reset() {
// Only calculate sizes if it's visible
if (!IsShownOnScreen()) return;
int w = origSize.GetX(); int w = origSize.GetX();
int h = origSize.GetY(); int h = origSize.GetY();
wxASSERT(w > 0);
wxASSERT(h > 0);
SetClientSize(w,h); SetClientSize(w,h);
int _w,_h; int _w,_h;
GetSize(&_w,&_h); GetSize(&_w,&_h);
wxASSERT(_w > 0);
wxASSERT(_h > 0);
SetSizeHints(_w,_h,_w,_h); SetSizeHints(_w,_h,_w,_h);
} }
@ -330,6 +361,7 @@ void VideoDisplay::OnMouseEvent(wxMouseEvent& event) {
} }
// Send to visual // Send to visual
wxASSERT(visual);
visual->OnMouseEvent(event); visual->OnMouseEvent(event);
} }
@ -337,6 +369,7 @@ void VideoDisplay::OnMouseEvent(wxMouseEvent& event) {
///////////// /////////////
// Key event // Key event
void VideoDisplay::OnKey(wxKeyEvent &event) { void VideoDisplay::OnKey(wxKeyEvent &event) {
wxASSERT(visual);
visual->OnKeyEvent(event); visual->OnKeyEvent(event);
} }
@ -346,6 +379,7 @@ void VideoDisplay::OnKey(wxKeyEvent &event) {
// Mouse left display // Mouse left display
void VideoDisplay::OnMouseLeave(wxMouseEvent& event) { void VideoDisplay::OnMouseLeave(wxMouseEvent& event) {
if (VideoContext::Get()->IsPlaying()) return; if (VideoContext::Get()->IsPlaying()) return;
wxASSERT(visual);
visual->OnMouseEvent(event); visual->OnMouseEvent(event);
if (tracker) tracker->bTrackerEditing = 0; if (tracker) tracker->bTrackerEditing = 0;
} }
@ -497,6 +531,10 @@ void VideoDisplay::DrawText( wxPoint Pos, wxString text ) {
void VideoDisplay::ConvertMouseCoords(int &x,int &y) { void VideoDisplay::ConvertMouseCoords(int &x,int &y) {
int w,h; int w,h;
GetClientSize(&w,&h); GetClientSize(&w,&h);
wxASSERT(dx2 > 0);
wxASSERT(dy2 > 0);
wxASSERT(w > 0);
wxASSERT(h > 0);
x = (x-dx1)*w/dx2; x = (x-dx1)*w/dx2;
y = (y-dy1)*h/dy2; y = (y-dy1)*h/dy2;
} }