KLN89: Change to more meaningful function names, and always clear the buffer after drawing.
This commit is contained in:
parent
cd420dadf7
commit
dbd3e7077d
3 changed files with 45 additions and 45 deletions
|
@ -232,7 +232,7 @@ DCLGPS::~DCLGPS() {
|
||||||
}
|
}
|
||||||
|
|
||||||
void DCLGPS::draw(osg::State& state) {
|
void DCLGPS::draw(osg::State& state) {
|
||||||
_instrument->draw(state);
|
_instrument->Draw(state);
|
||||||
}
|
}
|
||||||
|
|
||||||
void DCLGPS::init() {
|
void DCLGPS::init() {
|
||||||
|
|
|
@ -57,7 +57,7 @@ RenderArea2D::RenderArea2D(int logx, int logy, int sizex, int sizey, int posx, i
|
||||||
_ra2d_debug = false;
|
_ra2d_debug = false;
|
||||||
}
|
}
|
||||||
|
|
||||||
void RenderArea2D::draw(osg::State& state) {
|
void RenderArea2D::Draw(osg::State& state) {
|
||||||
|
|
||||||
static osg::ref_ptr<osg::StateSet> renderArea2DStateSet;
|
static osg::ref_ptr<osg::StateSet> renderArea2DStateSet;
|
||||||
if(!renderArea2DStateSet.valid()) {
|
if(!renderArea2DStateSet.valid()) {
|
||||||
|
@ -82,27 +82,29 @@ void RenderArea2D::draw(osg::State& state) {
|
||||||
glDisable(GL_CLIP_PLANE2);
|
glDisable(GL_CLIP_PLANE2);
|
||||||
glDisable(GL_CLIP_PLANE3);
|
glDisable(GL_CLIP_PLANE3);
|
||||||
|
|
||||||
oldDrawBackground();
|
DoDrawBackground();
|
||||||
|
|
||||||
for(unsigned int i = 0; i < drawing_list.size(); ++i) {
|
for(unsigned int i = 0; i < drawing_list.size(); ++i) {
|
||||||
RA2DPrimitive prim = drawing_list[i];
|
RA2DPrimitive prim = drawing_list[i];
|
||||||
switch(prim.type) {
|
switch(prim.type) {
|
||||||
case RA2D_LINE:
|
case RA2D_LINE:
|
||||||
oldDrawLine(prim.x1, prim.y1, prim.x2, prim.y2);
|
DoDrawLine(prim.x1, prim.y1, prim.x2, prim.y2);
|
||||||
break;
|
break;
|
||||||
case RA2D_QUAD:
|
case RA2D_QUAD:
|
||||||
if(prim.debug) {
|
if(prim.debug) {
|
||||||
//cout << "Clipping = " << _clipx1 << ", " << _clipy1 << " to " << _clipx2 << ", " << _clipy2 << '\n';
|
//cout << "Clipping = " << _clipx1 << ", " << _clipy1 << " to " << _clipx2 << ", " << _clipy2 << '\n';
|
||||||
//cout << "Drawing quad " << prim.x1 << ", " << prim.y1 << " to " << prim.x2 << ", " << prim.y2 << '\n';
|
//cout << "Drawing quad " << prim.x1 << ", " << prim.y1 << " to " << prim.x2 << ", " << prim.y2 << '\n';
|
||||||
}
|
}
|
||||||
oldDrawQuad(prim.x1, prim.y1, prim.x2, prim.y2, prim.invert);
|
DoDrawQuad(prim.x1, prim.y1, prim.x2, prim.y2, prim.invert);
|
||||||
break;
|
break;
|
||||||
case RA2D_PIXEL:
|
case RA2D_PIXEL:
|
||||||
oldDrawPixel(prim.x1, prim.y1, prim.invert);
|
DoDrawPixel(prim.x1, prim.y1, prim.invert);
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
drawing_list.clear();
|
||||||
|
|
||||||
glPopAttrib();
|
glPopAttrib();
|
||||||
|
|
||||||
state.popStateSet();
|
state.popStateSet();
|
||||||
|
@ -111,6 +113,10 @@ void RenderArea2D::draw(osg::State& state) {
|
||||||
state.setClientActiveTextureUnit(0);
|
state.setClientActiveTextureUnit(0);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void RenderArea2D::Flush() {
|
||||||
|
drawing_list.clear();
|
||||||
|
}
|
||||||
|
|
||||||
// Set clipping region in logical units
|
// Set clipping region in logical units
|
||||||
void RenderArea2D::SetClipRegion(int x1, int y1, int x2, int y2) {
|
void RenderArea2D::SetClipRegion(int x1, int y1, int x2, int y2) {
|
||||||
_clipx1 = x1;
|
_clipx1 = x1;
|
||||||
|
@ -158,7 +164,7 @@ void RenderArea2D::DrawPixel(int x, int y, bool invert) {
|
||||||
drawing_list.push_back(prim);
|
drawing_list.push_back(prim);
|
||||||
}
|
}
|
||||||
|
|
||||||
void RenderArea2D::oldDrawPixel(int x, int y, bool invert) {
|
void RenderArea2D::DoDrawPixel(int x, int y, bool invert) {
|
||||||
// Clip. In theory this shouldn't be necessary, since all input is clipped before adding
|
// Clip. In theory this shouldn't be necessary, since all input is clipped before adding
|
||||||
// to the drawing list, but it ensures that any errors in clipping lines etc will only
|
// to the drawing list, but it ensures that any errors in clipping lines etc will only
|
||||||
// spill over the clip area within the instrument, and still be clipped from straying
|
// spill over the clip area within the instrument, and still be clipped from straying
|
||||||
|
@ -182,14 +188,14 @@ void RenderArea2D::oldDrawPixel(int x, int y, bool invert) {
|
||||||
|
|
||||||
//cout << "DP: " << fx1 << ", " << fy1 << " ... " << fx2 << ", " << fy2 << '\n';
|
//cout << "DP: " << fx1 << ", " << fy1 << " ... " << fx2 << ", " << fy2 << '\n';
|
||||||
|
|
||||||
doSetColor(invert ? _backgroundColor : _pixelColor);
|
SetRenderColor(invert ? _backgroundColor : _pixelColor);
|
||||||
SGVec2f corners[4] = {
|
SGVec2f corners[4] = {
|
||||||
SGVec2f(fx1, fy1),
|
SGVec2f(fx1, fy1),
|
||||||
SGVec2f(fx2, fy1),
|
SGVec2f(fx2, fy1),
|
||||||
SGVec2f(fx2, fy2),
|
SGVec2f(fx2, fy2),
|
||||||
SGVec2f(fx1, fy2)
|
SGVec2f(fx1, fy2)
|
||||||
};
|
};
|
||||||
doDrawQuad(corners);
|
RenderQuad(corners);
|
||||||
}
|
}
|
||||||
|
|
||||||
void RenderArea2D::DrawLine(int x1, int y1, int x2, int y2) {
|
void RenderArea2D::DrawLine(int x1, int y1, int x2, int y2) {
|
||||||
|
@ -243,7 +249,7 @@ void RenderArea2D::DrawLine(int x1, int y1, int x2, int y2) {
|
||||||
drawing_list.push_back(prim);
|
drawing_list.push_back(prim);
|
||||||
}
|
}
|
||||||
|
|
||||||
void RenderArea2D::oldDrawLine(int x1, int y1, int x2, int y2) {
|
void RenderArea2D::DoDrawLine(int x1, int y1, int x2, int y2) {
|
||||||
// Crude implementation of Bresenham line drawing algorithm.
|
// Crude implementation of Bresenham line drawing algorithm.
|
||||||
|
|
||||||
// Our lines are non directional, so first order the points x-direction-wise to leave only 4 octants to consider.
|
// Our lines are non directional, so first order the points x-direction-wise to leave only 4 octants to consider.
|
||||||
|
@ -264,7 +270,7 @@ void RenderArea2D::oldDrawLine(int x1, int y1, int x2, int y2) {
|
||||||
int y = y1;
|
int y = y1;
|
||||||
int yn = dx/2;
|
int yn = dx/2;
|
||||||
for(int x=x1; x<=x2; ++x) {
|
for(int x=x1; x<=x2; ++x) {
|
||||||
oldDrawPixel(x, y);
|
DoDrawPixel(x, y);
|
||||||
yn += dy;
|
yn += dy;
|
||||||
if(yn >= dx) {
|
if(yn >= dx) {
|
||||||
yn -= dx;
|
yn -= dx;
|
||||||
|
@ -278,7 +284,7 @@ void RenderArea2D::oldDrawLine(int x1, int y1, int x2, int y2) {
|
||||||
// Must be a more elegant way to roll the next two cases into one!
|
// Must be a more elegant way to roll the next two cases into one!
|
||||||
if(flip_y) {
|
if(flip_y) {
|
||||||
for(int y=y1; y>=y2; --y) {
|
for(int y=y1; y>=y2; --y) {
|
||||||
oldDrawPixel(x, y);
|
DoDrawPixel(x, y);
|
||||||
xn += dx;
|
xn += dx;
|
||||||
if(xn >= dy) {
|
if(xn >= dy) {
|
||||||
xn -= dy;
|
xn -= dy;
|
||||||
|
@ -287,7 +293,7 @@ void RenderArea2D::oldDrawLine(int x1, int y1, int x2, int y2) {
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
for(int y=y1; y<=y2; ++y) {
|
for(int y=y1; y<=y2; ++y) {
|
||||||
oldDrawPixel(x, y);
|
DoDrawPixel(x, y);
|
||||||
xn += dx;
|
xn += dx;
|
||||||
if(xn >= dy) {
|
if(xn >= dy) {
|
||||||
xn -= dy;
|
xn -= dy;
|
||||||
|
@ -332,7 +338,7 @@ void RenderArea2D::DrawQuad(int x1, int y1, int x2, int y2, bool invert) {
|
||||||
drawing_list.push_back(prim);
|
drawing_list.push_back(prim);
|
||||||
}
|
}
|
||||||
|
|
||||||
void RenderArea2D::oldDrawQuad(int x1, int y1, int x2, int y2, bool invert) {
|
void RenderArea2D::DoDrawQuad(int x1, int y1, int x2, int y2, bool invert) {
|
||||||
// Scale to position within background
|
// Scale to position within background
|
||||||
float fx1 = (float)x1, fy1 = (float)y1;
|
float fx1 = (float)x1, fy1 = (float)y1;
|
||||||
float fx2 = (float)x2, fy2 = (float)y2;
|
float fx2 = (float)x2, fy2 = (float)y2;
|
||||||
|
@ -354,22 +360,22 @@ void RenderArea2D::oldDrawQuad(int x1, int y1, int x2, int y2, bool invert) {
|
||||||
|
|
||||||
//cout << "DP: " << fx1 << ", " << fy1 << " ... " << fx2 << ", " << fy2 << '\n';
|
//cout << "DP: " << fx1 << ", " << fy1 << " ... " << fx2 << ", " << fy2 << '\n';
|
||||||
|
|
||||||
doSetColor(invert ? _backgroundColor : _pixelColor);
|
SetRenderColor(invert ? _backgroundColor : _pixelColor);
|
||||||
SGVec2f corners[4] = {
|
SGVec2f corners[4] = {
|
||||||
SGVec2f(fx1, fy1),
|
SGVec2f(fx1, fy1),
|
||||||
SGVec2f(fx2, fy1),
|
SGVec2f(fx2, fy1),
|
||||||
SGVec2f(fx2, fy2),
|
SGVec2f(fx2, fy2),
|
||||||
SGVec2f(fx1, fy2)
|
SGVec2f(fx1, fy2)
|
||||||
};
|
};
|
||||||
doDrawQuad(corners);
|
RenderQuad(corners);
|
||||||
}
|
}
|
||||||
|
|
||||||
void RenderArea2D::DrawBackground() {
|
void RenderArea2D::DrawBackground() {
|
||||||
// TODO
|
// Currently a NO-OP
|
||||||
}
|
}
|
||||||
|
|
||||||
void RenderArea2D::oldDrawBackground() {
|
void RenderArea2D::DoDrawBackground() {
|
||||||
doSetColor(_backgroundColor);
|
SetRenderColor(_backgroundColor);
|
||||||
SGVec2f corners[4] = {
|
SGVec2f corners[4] = {
|
||||||
SGVec2f(_posx, _posy),
|
SGVec2f(_posx, _posy),
|
||||||
SGVec2f(_posx + _sizex, _posy),
|
SGVec2f(_posx + _sizex, _posy),
|
||||||
|
@ -377,11 +383,7 @@ void RenderArea2D::oldDrawBackground() {
|
||||||
SGVec2f(_posx, _posy + _sizey)
|
SGVec2f(_posx, _posy + _sizey)
|
||||||
};
|
};
|
||||||
|
|
||||||
doDrawQuad(corners);
|
RenderQuad(corners);
|
||||||
}
|
|
||||||
|
|
||||||
void RenderArea2D::Flush() {
|
|
||||||
drawing_list.clear();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// -----------------------------------------
|
// -----------------------------------------
|
||||||
|
@ -390,12 +392,12 @@ void RenderArea2D::Flush() {
|
||||||
//
|
//
|
||||||
// -----------------------------------------
|
// -----------------------------------------
|
||||||
|
|
||||||
void RenderArea2D::doSetColor( const float *rgba ) {
|
void RenderArea2D::SetRenderColor( const float *rgba ) {
|
||||||
glMaterialfv(GL_FRONT_AND_BACK, GL_AMBIENT_AND_DIFFUSE, rgba);
|
glMaterialfv(GL_FRONT_AND_BACK, GL_AMBIENT_AND_DIFFUSE, rgba);
|
||||||
glColor4fv( rgba );
|
glColor4fv( rgba );
|
||||||
}
|
}
|
||||||
|
|
||||||
void RenderArea2D::doDrawQuad( const SGVec2f *p) {
|
void RenderArea2D::RenderQuad( const SGVec2f *p) {
|
||||||
glBegin(GL_QUADS);
|
glBegin(GL_QUADS);
|
||||||
glNormal3f(0.0f, 0.0f, 0.0f);
|
glNormal3f(0.0f, 0.0f, 0.0f);
|
||||||
glVertex2fv( p[0].data() );
|
glVertex2fv( p[0].data() );
|
||||||
|
@ -405,7 +407,7 @@ void RenderArea2D::doDrawQuad( const SGVec2f *p) {
|
||||||
glEnd();
|
glEnd();
|
||||||
}
|
}
|
||||||
|
|
||||||
void RenderArea2D::doDrawQuad( const SGVec2f *p, const SGVec4f *color ) {
|
void RenderArea2D::RenderQuad( const SGVec2f *p, const SGVec4f *color ) {
|
||||||
glBegin(GL_QUADS);
|
glBegin(GL_QUADS);
|
||||||
glNormal3f(0.0f, 0.0f, 0.0f);
|
glNormal3f(0.0f, 0.0f, 0.0f);
|
||||||
glColor4fv( color[0].data() ); glVertex2fv( p[0].data() );
|
glColor4fv( color[0].data() ); glVertex2fv( p[0].data() );
|
||||||
|
|
|
@ -60,8 +60,6 @@ public:
|
||||||
RenderArea2D(int logx, int logy, int sizex, int sizey, int posx, int posy);
|
RenderArea2D(int logx, int logy, int sizex, int sizey, int posx, int posy);
|
||||||
~RenderArea2D();
|
~RenderArea2D();
|
||||||
|
|
||||||
void draw(osg::State& state);
|
|
||||||
|
|
||||||
void SetPixelColor(const float* rgba);
|
void SetPixelColor(const float* rgba);
|
||||||
void SetBackgroundColor(const float* rgba);
|
void SetBackgroundColor(const float* rgba);
|
||||||
void SetPosition(int posx, int posy);
|
void SetPosition(int posx, int posy);
|
||||||
|
@ -73,23 +71,17 @@ public:
|
||||||
// Set clip region to be the same as the rendered area (default)
|
// Set clip region to be the same as the rendered area (default)
|
||||||
void ResetClipRegion();
|
void ResetClipRegion();
|
||||||
|
|
||||||
// Drawing specified in logical units
|
// The DrawXXX functions place the shapes in the buffer, specified
|
||||||
|
// in logical units, and clipped to the current clip region.
|
||||||
|
void DrawPixel(int x, int y, bool invert = false);
|
||||||
void DrawLine(int x1, int y1, int x2, int y2);
|
void DrawLine(int x1, int y1, int x2, int y2);
|
||||||
void DrawQuad(int x1, int y1, int x2, int y2, bool invert = false);
|
void DrawQuad(int x1, int y1, int x2, int y2, bool invert = false);
|
||||||
void DrawBackground();
|
void DrawBackground();
|
||||||
// Draw a pixel specified by *logical* position
|
|
||||||
void DrawPixel(int x, int y, bool invert = false);
|
|
||||||
|
|
||||||
// The old drawing functions have been renamed in order to buffer the drawing for FG
|
// Call Draw to have the buffer contents drawn and then cleared.
|
||||||
//
|
void Draw(osg::State& state);
|
||||||
// Drawing specified in logical units
|
|
||||||
void oldDrawLine(int x1, int y1, int x2, int y2);
|
|
||||||
void oldDrawQuad(int x1, int y1, int x2, int y2, bool invert = false);
|
|
||||||
void oldDrawBackground();
|
|
||||||
// Draw a pixel specified by *logical* position
|
|
||||||
void oldDrawPixel(int x, int y, bool invert = false);
|
|
||||||
|
|
||||||
// Flush the buffer pipeline
|
// Clear the buffer contents
|
||||||
void Flush();
|
void Flush();
|
||||||
|
|
||||||
// Turn debugging on or off.
|
// Turn debugging on or off.
|
||||||
|
@ -104,10 +96,16 @@ private:
|
||||||
float _backgroundColor[4];
|
float _backgroundColor[4];
|
||||||
float _pixelColor[4];
|
float _pixelColor[4];
|
||||||
|
|
||||||
// Actual drawing routines copied from Atlas
|
// Drawing specified in logical units
|
||||||
void doSetColor( const float *rgb );
|
void DoDrawPixel(int x, int y, bool invert = false);
|
||||||
void doDrawQuad( const SGVec2f *p);
|
void DoDrawLine(int x1, int y1, int x2, int y2);
|
||||||
void doDrawQuad( const SGVec2f *p, const SGVec4f *color );
|
void DoDrawQuad(int x1, int y1, int x2, int y2, bool invert = false);
|
||||||
|
void DoDrawBackground();
|
||||||
|
|
||||||
|
// Actual rendering routines copied from Atlas
|
||||||
|
void SetRenderColor( const float *rgb );
|
||||||
|
void RenderQuad( const SGVec2f *p);
|
||||||
|
void RenderQuad( const SGVec2f *p, const SGVec4f *color );
|
||||||
|
|
||||||
vector<RA2DPrimitive> drawing_list;
|
vector<RA2DPrimitive> drawing_list;
|
||||||
|
|
||||||
|
|
Loading…
Add table
Reference in a new issue