Fixed printing.

This commit is contained in:
Leonardo Zide 2017-02-11 09:46:21 -08:00
parent cfdfe30b40
commit 0f2e808477
9 changed files with 133 additions and 270 deletions

View file

@ -964,7 +964,7 @@ void lcCamera::SetViewpoint(lcViewpoint Viewpoint)
void lcCamera::StartTiledRendering(int tw, int th, int iw, int ih, float AspectRatio)
{
m_pTR = new TiledRender();
m_pTR->TileSize(tw, th, 0);
m_pTR->TileSize(tw, th);
m_pTR->ImageSize(iw, ih);
if (IsOrtho())
@ -982,10 +982,10 @@ void lcCamera::GetTileInfo(int* row, int* col, int* width, int* height)
{
if (m_pTR != NULL)
{
*row = m_pTR->m_Rows - m_pTR->m_CurrentRow - 1;
*col = m_pTR->m_CurrentColumn;
*width = m_pTR->m_CurrentTileWidth;
*height = m_pTR->m_CurrentTileHeight;
*row = m_pTR->mRows - m_pTR->mCurrentRow - 1;
*col = m_pTR->mCurrentColumn;
*width = m_pTR->mCurrentTileWidth;
*height = m_pTR->mCurrentTileHeight;
}
}

View file

@ -337,6 +337,17 @@ void lcContext::SetLineWidth(float LineWidth)
mLineWidth = LineWidth;
}
void lcContext::SetTextureMode(lcTextureMode TextureMode)
{
#ifndef LC_OPENGLES
if (!gSupportsShaderObjects)
{
const GLenum ModeTable[] = { GL_DECAL, GL_REPLACE, GL_MODULATE };
glTexEnvi(GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, ModeTable[TextureMode]);
}
#endif
}
void lcContext::SetColor(float Red, float Green, float Blue, float Alpha)
{
SetColor(lcVector4(Red, Green, Blue, Alpha));
@ -938,7 +949,7 @@ void lcContext::DrawMeshSection(lcMesh* Mesh, lcMeshSection* Section)
if (!mTexture)
{
glTexEnvi(GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_DECAL);
SetTextureMode(LC_TEXTURE_DECAL);
glEnable(GL_TEXTURE_2D);
}

View file

@ -82,6 +82,13 @@ struct lcProgram
GLint ColorLocation;
};
enum lcTextureMode
{
LC_TEXTURE_DECAL,
LC_TEXTURE_REPLACE,
LC_TEXTURE_MODULATE
};
class lcContext
{
public:
@ -116,6 +123,7 @@ public:
void SetProgram(lcProgramType ProgramType);
void SetViewport(int x, int y, int Width, int Height);
void SetLineWidth(float LineWidth);
void SetTextureMode(lcTextureMode TextureMode);
void SetColor(const lcVector4& Color)
{

View file

@ -8,11 +8,15 @@
#include <QtGui>
#include <QPrinter>
#if !defined(EGL_VERSION_1_0) && !defined(GL_ES_VERSION_2_0) && !defined(GL_ES_VERSION_3_0)
#undef GL_LINES_ADJACENCY_EXT
#undef GL_LINE_STRIP_ADJACENCY_EXT
#undef GL_TRIANGLES_ADJACENCY_EXT
#undef GL_TRIANGLE_STRIP_ADJACENCY_EXT
#include "lc_glext.h"
#else
#define LC_OPENGLES 1
#endif
// Old defines and declarations.
#define LC_MAXPATH 1024

View file

@ -904,16 +904,8 @@ inline lcMatrix44 lcMatrix44LookAt(const lcVector3& Eye, const lcVector3& Target
return m;
}
inline lcMatrix44 lcMatrix44Perspective(float FoVy, float Aspect, float Near, float Far)
inline lcMatrix44 lcMatrix44Frustum(float Left, float Right, float Bottom, float Top, float Near, float Far)
{
float Left, Right, Bottom, Top;
Top = Near * (float)tan(FoVy * LC_PI / 360.0f);
Bottom = -Top;
Left = Bottom * Aspect;
Right = Top * Aspect;
if ((Near <= 0.0f) || (Far <= 0.0f) || (Near == Far) || (Left == Right) || (Top == Bottom))
return lcMatrix44Identity();
@ -936,6 +928,19 @@ inline lcMatrix44 lcMatrix44Perspective(float FoVy, float Aspect, float Near, fl
return m;
}
inline lcMatrix44 lcMatrix44Perspective(float FoVy, float Aspect, float Near, float Far)
{
float Left, Right, Bottom, Top;
Top = Near * (float)tan(FoVy * LC_PI / 360.0f);
Bottom = -Top;
Left = Bottom * Aspect;
Right = Top * Aspect;
return lcMatrix44Frustum(Left, Right, Bottom, Top, Near, Far);
}
inline lcMatrix44 lcMatrix44Ortho(float Left, float Right, float Bottom, float Top, float Near, float Far)
{
lcMatrix44 m;

View file

@ -1155,7 +1155,7 @@ void lcModel::DrawBackground(lcGLWidget* Widget)
{
glEnable(GL_TEXTURE_2D);
glTexEnvi(GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_REPLACE);
Context->SetTextureMode(LC_TEXTURE_REPLACE);
glBindTexture(GL_TEXTURE_2D, mBackgroundTexture->mTexture);
float TileWidth = 1.0f, TileHeight = 1.0f;

View file

@ -1,133 +1,59 @@
// TR.cpp: implementation of the TiledRender class.
//
//////////////////////////////////////////////////////////////////////
#include "lc_global.h"
#include <math.h>
#include "tr.h"
//////////////////////////////////////////////////////////////////////
// Construction/Destruction
//////////////////////////////////////////////////////////////////////
#include "lc_math.h"
TiledRender::TiledRender()
{
m_TileWidth = 256;
m_TileHeight = 256;
m_TileBorder = 0;
m_RowOrder = TR_BOTTOM_TO_TOP;
m_CurrentTile = -1;
m_ImageBuffer = 0;
m_TileBuffer = 0;
mTileWidth = 256;
mTileHeight = 256;
mCurrentTile = -1;
}
TiledRender::~TiledRender()
{
}
void TiledRender::TileSize(int width, int height, int border)
void TiledRender::TileSize(int width, int height)
{
m_TileBorder = border;
m_TileWidth = width;
m_TileHeight = height;
m_TileWidthNB = width - 2 * border;
m_TileHeightNB = height - 2 * border;
}
void TiledRender::TileBuffer(TRenum format, TRenum type, void *image)
{
m_TileFormat = format;
m_TileType = type;
m_TileBuffer = image;
mTileWidth = width;
mTileHeight = height;
}
void TiledRender::ImageSize(int width, int height)
{
m_ImageWidth = width;
m_ImageHeight = height;
}
void TiledRender::ImageBuffer(TRenum format, TRenum type, void *image)
{
m_ImageFormat = format;
m_ImageType = type;
m_ImageBuffer = image;
}
void TiledRender::RowOrder(TRenum order)
{
if (order == TR_TOP_TO_BOTTOM || order == TR_BOTTOM_TO_TOP)
m_RowOrder = order;
}
int TiledRender::Get(TRenum param)
{
switch (param)
{
case TR_TILE_WIDTH:
return m_TileWidth;
case TR_TILE_HEIGHT:
return m_TileHeight;
case TR_TILE_BORDER:
return m_TileBorder;
case TR_IMAGE_WIDTH:
return m_ImageWidth;
case TR_IMAGE_HEIGHT:
return m_ImageHeight;
case TR_ROWS:
return m_Rows;
case TR_COLUMNS:
return m_Columns;
case TR_CURRENT_ROW:
if (m_CurrentTile < 0)
return -1;
else
return m_CurrentRow;
case TR_CURRENT_COLUMN:
if (m_CurrentTile < 0)
return -1;
else
return m_CurrentColumn;
case TR_CURRENT_TILE_WIDTH:
return m_CurrentTileWidth;
case TR_CURRENT_TILE_HEIGHT:
return m_CurrentTileHeight;
case TR_ROW_ORDER:
return (int) m_RowOrder;
default:
return 0;
}
mImageWidth = width;
mImageHeight = height;
}
void TiledRender::Ortho(double left, double right, double bottom, double top, double zNear, double zFar)
{
if (m_CurrentTile < 0)
if (mCurrentTile < 0)
{
m_Perspective = false;
m_Left = left;
m_Right = right;
m_Bottom = bottom;
m_Top = top;
m_Near = zNear;
m_Far = zFar;
mPerspective = false;
mLeft = left;
mRight = right;
mBottom = bottom;
mTop = top;
mNear = zNear;
mFar = zFar;
}
}
void TiledRender::Frustum(double left, double right, double bottom, double top, double zNear, double zFar)
{
if (m_CurrentTile < 0)
if (mCurrentTile < 0)
{
m_Perspective = true;
m_Left = left;
m_Right = right;
m_Bottom = bottom;
m_Top = top;
m_Near = zNear;
m_Far = zFar;
mPerspective = true;
mLeft = left;
mRight = right;
mBottom = bottom;
mTop = top;
mNear = zNear;
mFar = zFar;
}
}
void TiledRender::Perspective(double fovy, double aspect, double zNear, double zFar )
void TiledRender::Perspective(double fovy, double aspect, double zNear, double zFar)
{
double xmin, xmax, ymin, ymax;
ymax = zNear * tan(fovy * 3.14159265 / 360.0);
@ -137,129 +63,66 @@ void TiledRender::Perspective(double fovy, double aspect, double zNear, double z
Frustum(xmin, xmax, ymin, ymax, zNear, zFar);
}
void TiledRender::BeginTile()
lcMatrix44 TiledRender::BeginTile()
{
GLint matrixMode;
int tileWidth, tileHeight, border;
int tileWidth, tileHeight;
double left, right, bottom, top;
if (m_CurrentTile <= 0)
if (mCurrentTile <= 0)
{
m_Columns = (m_ImageWidth + m_TileWidthNB - 1) / m_TileWidthNB;
m_Rows = (m_ImageHeight + m_TileHeightNB - 1) / m_TileHeightNB;
m_CurrentTile = 0;
mColumns = (mImageWidth + mTileWidth - 1) / mTileWidth;
mRows = (mImageHeight + mTileHeight - 1) / mTileHeight;
mCurrentTile = 0;
// Save user's viewport, will be restored after last tile rendered
glGetIntegerv(GL_VIEWPORT, m_ViewportSave);
glGetIntegerv(GL_VIEWPORT, mViewportSave);
}
// which tile (by row and column) we're about to render
if (m_RowOrder == TR_BOTTOM_TO_TOP)
{
m_CurrentRow = m_CurrentTile / m_Columns;
m_CurrentColumn = m_CurrentTile % m_Columns;
}
else if (m_RowOrder==TR_TOP_TO_BOTTOM)
{
m_CurrentRow = m_Rows - (m_CurrentTile / m_Columns) - 1;
m_CurrentColumn = m_CurrentTile % m_Columns;
}
border = m_TileBorder;
mCurrentRow = mCurrentTile / mColumns;
mCurrentColumn = mCurrentTile % mColumns;
// Compute actual size of this tile with border
if (m_CurrentRow < m_Rows-1)
tileHeight = m_TileHeight;
if (mCurrentRow < mRows - 1)
tileHeight = mTileHeight;
else
tileHeight = m_ImageHeight - (m_Rows-1) * (m_TileHeightNB) + 2 * border;
tileHeight = mImageHeight - (mRows - 1) * (mTileHeight);
if (m_CurrentColumn < m_Columns-1)
tileWidth = m_TileWidth;
if (mCurrentColumn < mColumns - 1)
tileWidth = mTileWidth;
else
tileWidth = m_ImageWidth - (m_Columns-1) * (m_TileWidthNB) + 2 * border;
tileWidth = mImageWidth - (mColumns - 1) * (mTileWidth);
// Save tile size, with border
m_CurrentTileWidth = tileWidth;
m_CurrentTileHeight = tileHeight;
mCurrentTileWidth = tileWidth;
mCurrentTileHeight = tileHeight;
glViewport(0, 0, tileWidth, tileHeight); // tile size including border
// save current matrix mode
glGetIntegerv(GL_MATRIX_MODE, &matrixMode);
glMatrixMode(GL_PROJECTION);
glLoadIdentity();
// compute projection parameters
left = m_Left + (m_Right - m_Left)
* (m_CurrentColumn * m_TileWidthNB - border) / m_ImageWidth;
right = left + (m_Right - m_Left) * tileWidth / m_ImageWidth;
bottom = m_Bottom + (m_Top - m_Bottom)
* (m_CurrentRow * m_TileHeightNB - border) / m_ImageHeight;
top = bottom + (m_Top - m_Bottom) * tileHeight / m_ImageHeight;
left = mLeft + (mRight - mLeft) * (mCurrentColumn * mTileWidth) / mImageWidth;
right = left + (mRight - mLeft) * tileWidth / mImageWidth;
bottom = mBottom + (mTop - mBottom) * (mCurrentRow * mTileHeight) / mImageHeight;
top = bottom + (mTop - mBottom) * tileHeight / mImageHeight;
if (m_Perspective)
glFrustum(left, right, bottom, top, m_Near, m_Far);
if (mPerspective)
return lcMatrix44Frustum(left, right, bottom, top, mNear, mFar);
else
glOrtho(left, right, bottom, top, m_Near, m_Far);
// restore user's matrix mode
glMatrixMode((GLenum)matrixMode);
return lcMatrix44Ortho(left, right, bottom, top, mNear, mFar);
}
int TiledRender::EndTile()
{
GLint prevRowLength, prevSkipRows, prevSkipPixels;
// be sure OpenGL rendering is finished
glFlush();
// save current glPixelStore values
glGetIntegerv(GL_PACK_ROW_LENGTH, &prevRowLength);
glGetIntegerv(GL_PACK_SKIP_ROWS, &prevSkipRows);
glGetIntegerv(GL_PACK_SKIP_PIXELS, &prevSkipPixels);
if (m_TileBuffer)
{
int srcX = m_TileBorder;
int srcY = m_TileBorder;
int srcWidth = m_TileWidthNB;
int srcHeight = m_TileHeightNB;
glReadPixels(srcX, srcY, srcWidth, srcHeight,
(GLenum)m_TileFormat, (GLenum)m_TileType, m_TileBuffer);
}
if (m_ImageBuffer)
{
int srcX = m_TileBorder;
int srcY = m_TileBorder;
int srcWidth = m_CurrentTileWidth - 2 * m_TileBorder;
int srcHeight = m_CurrentTileHeight - 2 * m_TileBorder;
int destX = m_TileWidthNB * m_CurrentColumn;
int destY = m_TileHeightNB * m_CurrentRow;
// setup pixel store for glReadPixels
glPixelStorei(GL_PACK_ROW_LENGTH, m_ImageWidth);
glPixelStorei(GL_PACK_SKIP_ROWS, destY);
glPixelStorei(GL_PACK_SKIP_PIXELS, destX);
// read the tile into the final image
glReadPixels(srcX, srcY, srcWidth, srcHeight,
(GLenum)m_ImageFormat, (GLenum)m_ImageType, m_ImageBuffer);
}
// restore previous glPixelStore values
glPixelStorei(GL_PACK_ROW_LENGTH, prevRowLength);
glPixelStorei(GL_PACK_SKIP_ROWS, prevSkipRows);
glPixelStorei(GL_PACK_SKIP_PIXELS, prevSkipPixels);
// increment tile counter, return 1 if more tiles left to render
m_CurrentTile++;
if (m_CurrentTile >= m_Rows * m_Columns)
mCurrentTile++;
if (mCurrentTile >= mRows * mColumns)
{
// restore user's viewport
glViewport(m_ViewportSave[0], m_ViewportSave[1],
m_ViewportSave[2], m_ViewportSave[3]);
m_CurrentTile = -1; // all done
glViewport(mViewportSave[0], mViewportSave[1], mViewportSave[2], mViewportSave[3]);
mCurrentTile = -1; // all done
return 0;
}
else

View file

@ -5,70 +5,42 @@
#ifndef _TR_H_
#define _TR_H_
typedef enum {
TR_TILE_WIDTH = 100,
TR_TILE_HEIGHT,
TR_TILE_BORDER,
TR_IMAGE_WIDTH,
TR_IMAGE_HEIGHT,
TR_ROWS,
TR_COLUMNS,
TR_CURRENT_ROW,
TR_CURRENT_COLUMN,
TR_CURRENT_TILE_WIDTH,
TR_CURRENT_TILE_HEIGHT,
TR_ROW_ORDER,
TR_TOP_TO_BOTTOM,
TR_BOTTOM_TO_TOP
} TRenum;
class TiledRender
{
public:
TiledRender();
virtual ~TiledRender();
~TiledRender();
void TileSize(int width, int height, int border);
void TileBuffer(TRenum format, TRenum type, void *image);
void TileSize(int width, int height);
void ImageSize(int width, int height);
void ImageBuffer(TRenum format, TRenum type, void *image);
void RowOrder(TRenum order);
void Ortho(double left, double right, double bottom, double top, double zNear, double zFar);
void Frustum(double left, double right, double bottom, double top, double zNear, double zFar);
void Perspective(double fovy, double aspect, double zNear, double zFar );
int Get(TRenum param);
int EndTile();
void BeginTile();
lcMatrix44 BeginTile();
// Final image parameters
int m_ImageWidth, m_ImageHeight;
TRenum m_ImageFormat, m_ImageType;
void *m_ImageBuffer;
int mImageWidth, mImageHeight;
// Tile parameters
int m_TileWidth, m_TileHeight;
int m_TileWidthNB, m_TileHeightNB;
int m_TileBorder;
TRenum m_TileFormat, m_TileType;
void *m_TileBuffer;
int mTileWidth, mTileHeight;
// Projection parameters
bool m_Perspective;
double m_Left;
double m_Right;
double m_Bottom;
double m_Top;
double m_Near;
double m_Far;
bool mPerspective;
double mLeft;
double mRight;
double mBottom;
double mTop;
double mNear;
double mFar;
// Misc
TRenum m_RowOrder;
int m_Rows, m_Columns;
int m_CurrentTile;
int m_CurrentTileWidth, m_CurrentTileHeight;
int m_CurrentRow, m_CurrentColumn;
int mRows, mColumns;
int mCurrentTile;
int mCurrentTileWidth, mCurrentTileHeight;
int mCurrentRow, mCurrentColumn;
GLint m_ViewportSave[4];
GLint mViewportSave[4];
};
#endif // _TR_H_

View file

@ -277,7 +277,7 @@ lcMatrix44 View::GetProjectionMatrix() const
float AspectRatio = (float)mWidth / (float)mHeight;
if (mCamera->m_pTR)
mCamera->m_pTR->BeginTile();
return mCamera->m_pTR->BeginTile();
if (mCamera->IsOrtho())
{
@ -1120,7 +1120,7 @@ void View::DrawRotateOverlay()
mContext->SetViewMatrix(lcMatrix44Translation(lcVector3(0.375, 0.375, 0.0)));
mContext->SetProjectionMatrix(lcMatrix44Ortho(0.0f, mWidth, 0.0f, mHeight, -1.0f, 1.0f));
glTexEnvi(GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_MODULATE);
mContext->SetTextureMode(LC_TEXTURE_MODULATE);
gTexFont.MakeCurrent();
glEnable(GL_TEXTURE_2D);
glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA);
@ -1439,7 +1439,7 @@ void View::DrawGrid()
if (Preferences.mDrawGridStuds)
{
glTexEnvi(GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_MODULATE);
mContext->SetTextureMode(LC_TEXTURE_MODULATE);
glBindTexture(GL_TEXTURE_2D, gGridTexture->mTexture);
glEnable(GL_TEXTURE_2D);
glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA);
@ -1520,7 +1520,7 @@ void View::DrawAxes()
mContext->SetProgram(LC_PROGRAM_TEXTURE);
mContext->SetViewMatrix(TranslationMatrix);
glTexEnvi(GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_MODULATE);
mContext->SetTextureMode(LC_TEXTURE_MODULATE);
gTexFont.MakeCurrent();
glEnable(GL_TEXTURE_2D);
glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA);
@ -1577,7 +1577,7 @@ void View::DrawViewport()
mContext->SetColor(0.0f, 0.0f, 0.0f, 1.0f);
glEnable(GL_TEXTURE_2D);
glTexEnvi(GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_MODULATE);
mContext->SetTextureMode(LC_TEXTURE_MODULATE);
gTexFont.MakeCurrent();
glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA);
glEnable(GL_BLEND);