a bunch of cleanups
parent
967b12960d
commit
956d26a6ba
|
@ -237,10 +237,13 @@ public:
|
|||
static Device *create(Session *session);
|
||||
|
||||
/// Return the dimension of the device
|
||||
inline Vector2i getDimension() const { return m_dimension; }
|
||||
inline Vector2i getSize() const { return m_size; }
|
||||
|
||||
/// Set the dimension of the device
|
||||
void setDimension(const Vector2i &dimension);
|
||||
void setSize(const Vector2i &dimension);
|
||||
|
||||
/// Return the aspect ratio of the device
|
||||
inline Float getAspect() const { return (Float) m_size.x / (Float) m_size.y; }
|
||||
|
||||
/// Return the position of the device
|
||||
inline Point2i getPosition() const { return m_position; }
|
||||
|
@ -380,7 +383,7 @@ protected:
|
|||
protected:
|
||||
ref<Session> m_session;
|
||||
ref<Timer> m_timer;
|
||||
Vector2i m_dimension;
|
||||
Vector2i m_size;
|
||||
Point2i m_position;
|
||||
int m_fsaa;
|
||||
int m_redBits;
|
||||
|
|
|
@ -44,6 +44,9 @@ public:
|
|||
|
||||
/// Set the source code of this program
|
||||
inline void setSource(EType type, const std::string &source) { m_source[type] = source; }
|
||||
|
||||
/// Set the source code of this program by filename
|
||||
void setSourceFile(EType type, const fs::path &path);
|
||||
|
||||
/// Get the source code of this program
|
||||
inline const std::string &getSource(EType type) const { return m_source[type]; }
|
||||
|
|
|
@ -35,10 +35,11 @@
|
|||
#include <limits>
|
||||
|
||||
/// Current release of Mitsuba
|
||||
#define MTS_VERSION "0.2.0"
|
||||
#define MTS_VERSION "0.2.1"
|
||||
#define MTS_VERSION_CODE 000201
|
||||
|
||||
/// Year of this release
|
||||
#define MTS_YEAR "2010"
|
||||
#define MTS_YEAR "2011"
|
||||
|
||||
/// Default port of <tt>mtssrv</tt>
|
||||
#define MTS_DEFAULT_PORT 7554
|
||||
|
|
|
@ -112,7 +112,7 @@ public:
|
|||
m_accumBuffer->setMipMapped(false);
|
||||
|
||||
m_session->init();
|
||||
m_device->setDimension(film->getSize());
|
||||
m_device->setSize(film->getSize());
|
||||
m_device->init();
|
||||
m_device->setVisible(false);
|
||||
m_renderer->init(m_device);
|
||||
|
|
|
@ -371,7 +371,7 @@ std::string Stream::readLine() {
|
|||
|
||||
do {
|
||||
try {
|
||||
data = readChar();
|
||||
read(&data, sizeof(char));
|
||||
} catch (std::exception &e) {
|
||||
if (getPos() == getSize()) {
|
||||
if (retval.size() != 0) {
|
||||
|
@ -391,9 +391,9 @@ std::string Stream::readLine() {
|
|||
std::string Stream::readString() {
|
||||
std::string retval;
|
||||
char data;
|
||||
|
||||
|
||||
do {
|
||||
data = readChar();
|
||||
read(&data, sizeof(char));
|
||||
if (data != 0)
|
||||
retval += data;
|
||||
} while (data != 0);
|
||||
|
|
|
@ -37,7 +37,7 @@ Device::Device(Session *name) {
|
|||
m_doubleBuffer = true;
|
||||
m_fullscreen = false;
|
||||
m_fsaa = 1;
|
||||
m_dimension = Vector2i(640, 480);
|
||||
m_size = Vector2i(640, 480);
|
||||
m_position = Point2i(0, 0);
|
||||
m_center = true;
|
||||
m_session = name;
|
||||
|
@ -69,9 +69,9 @@ void Device::setTitle(const std::string &title) {
|
|||
m_title = title;
|
||||
}
|
||||
|
||||
void Device::setDimension(const Vector2i &dimension) {
|
||||
void Device::setSize(const Vector2i &dimension) {
|
||||
Assert(!m_initialized);
|
||||
m_dimension = dimension;
|
||||
m_size = dimension;
|
||||
}
|
||||
|
||||
void Device::setRedBits(int redBits) {
|
||||
|
|
|
@ -26,6 +26,22 @@ GPUProgram::GPUProgram(const std::string &name)
|
|||
|
||||
GPUProgram::~GPUProgram() {
|
||||
}
|
||||
|
||||
void GPUProgram::setSourceFile(EType type, const fs::path &path) {
|
||||
fs::ifstream ifs(path);
|
||||
if (ifs.fail() || ifs.bad())
|
||||
Log(EError, "Unable to load GPU program \"%s\"",
|
||||
path.file_string().c_str());
|
||||
std::string code, line;
|
||||
|
||||
while (getline(ifs, line)) {
|
||||
code += line;
|
||||
code += "\n";
|
||||
}
|
||||
|
||||
ifs.close();
|
||||
setSource(type, code);
|
||||
}
|
||||
|
||||
std::string GPUProgram::toString() const {
|
||||
std::ostringstream oss;
|
||||
|
|
|
@ -24,7 +24,7 @@ Viewer::Viewer() {
|
|||
m_session = Session::create();
|
||||
m_device = Device::create(m_session);
|
||||
m_renderer = Renderer::create(m_session);
|
||||
m_device->setDimension(Vector2i(768, 576));
|
||||
m_device->setSize(Vector2i(768, 576));
|
||||
}
|
||||
|
||||
int Viewer::run(int argc, char **argv) {
|
||||
|
|
|
@ -66,7 +66,7 @@ LONG WINAPI WGLDevice::WndProc(HWND hWnd, UINT uMsg, WPARAM wParam, LPARAM lPara
|
|||
device->initPixelFormat(hWnd);
|
||||
break;
|
||||
case WM_SIZE:
|
||||
device->m_dimension = Vector2i(LOWORD(lParam), HIWORD(lParam));
|
||||
device->m_size = Vector2i(LOWORD(lParam), HIWORD(lParam));
|
||||
break;
|
||||
case WM_PAINT:
|
||||
BeginPaint(hWnd, &ps);
|
||||
|
@ -280,7 +280,7 @@ void WGLDevice::init(Device *other) {
|
|||
m_fullscreen ? WS_POPUP : (WS_OVERLAPPED | WS_CAPTION | WS_SYSMENU | WS_MINIMIZEBOX),
|
||||
CW_USEDEFAULT,
|
||||
CW_USEDEFAULT,
|
||||
getDimension().x, getDimension().y,
|
||||
getSize().x, getSize().y,
|
||||
NULL, NULL,
|
||||
session->m_hinstance,
|
||||
NULL);
|
||||
|
@ -299,8 +299,8 @@ void WGLDevice::init(Device *other) {
|
|||
ZeroMemory(&dm, sizeof(dm));
|
||||
dm.dmSize = sizeof(dm);
|
||||
dm.dmBitsPerPel = GetDeviceCaps(m_hdc, BITSPIXEL);
|
||||
dm.dmPelsWidth = m_dimension.x;
|
||||
dm.dmPelsHeight = m_dimension.y;
|
||||
dm.dmPelsWidth = m_size.x;
|
||||
dm.dmPelsHeight = m_size.y;
|
||||
|
||||
dm.dmFields = DM_PELSWIDTH | DM_PELSHEIGHT | DM_BITSPERPEL;
|
||||
if (!ChangeDisplaySettings(&dm, CDS_FULLSCREEN) == DISP_CHANGE_SUCCESSFUL)
|
||||
|
@ -308,11 +308,11 @@ void WGLDevice::init(Device *other) {
|
|||
}
|
||||
|
||||
if (m_fullscreen || m_center) {
|
||||
m_position.x = (GetSystemMetrics(SM_CXSCREEN) - m_dimension.x) / 2;
|
||||
m_position.y = (GetSystemMetrics(SM_CYSCREEN) - m_dimension.y) / 2;
|
||||
m_position.x = (GetSystemMetrics(SM_CXSCREEN) - m_size.x) / 2;
|
||||
m_position.y = (GetSystemMetrics(SM_CYSCREEN) - m_size.y) / 2;
|
||||
}
|
||||
|
||||
SetWindowPos(m_hwnd, HWND_TOP, m_position.x, m_position.y, m_dimension.x, m_dimension.y, SWP_NOCOPYBITS);
|
||||
SetWindowPos(m_hwnd, HWND_TOP, m_position.x, m_position.y, m_size.x, m_size.y, SWP_NOCOPYBITS);
|
||||
UpdateWindow(m_hwnd);
|
||||
|
||||
m_mouse = Point2i(-1, -1);
|
||||
|
@ -434,8 +434,8 @@ bool WGLDevice::translateMouse(UINT uMsg, WPARAM wParam, DeviceEvent &event) {
|
|||
event.setType(EMouseMotionEvent);
|
||||
event.setMouseButton(ENoButton);
|
||||
if (m_grab)
|
||||
warpMouse(Point2i(getDimension().x / 2,
|
||||
getDimension().y/2));
|
||||
warpMouse(Point2i(getSize().x / 2,
|
||||
getSize().y/2));
|
||||
break;
|
||||
case WM_LBUTTONDOWN:
|
||||
event.setType(EMouseButtonDownEvent);
|
||||
|
|
|
@ -168,8 +168,8 @@ void X11Device::init(Device *other) {
|
|||
|
||||
/* Find the best matching screen resolution */
|
||||
for (int i=0; i<modeCount; ++i) {
|
||||
if (modes[i]->hdisplay == m_dimension.x &&
|
||||
modes[i]->vdisplay == m_dimension.y)
|
||||
if (modes[i]->hdisplay == m_size.x &&
|
||||
modes[i]->vdisplay == m_size.y)
|
||||
modeList.push_back(modes[i]);
|
||||
}
|
||||
/* Release the memory held by the resolution list */
|
||||
|
@ -201,7 +201,7 @@ void X11Device::init(Device *other) {
|
|||
|
||||
m_window = XCreateWindow(session->m_display, session->m_root,
|
||||
0, 0, /* x,y position*/
|
||||
m_dimension.x, m_dimension.y,
|
||||
m_size.x, m_size.y,
|
||||
0, m_visinfo->depth, /* border width, color depth */
|
||||
InputOutput, m_visinfo->visual,
|
||||
CWBackPixel | CWBorderPixel | CWColormap |
|
||||
|
@ -221,14 +221,14 @@ void X11Device::init(Device *other) {
|
|||
} else {
|
||||
/* Center the window if needed */
|
||||
if (m_center) {
|
||||
m_position.x = (DisplayWidth(session->m_display, session->m_screen) - m_dimension.x) / 2;
|
||||
m_position.y = (DisplayHeight(session->m_display, session->m_screen) - m_dimension.y) / 2;
|
||||
m_position.x = (DisplayWidth(session->m_display, session->m_screen) - m_size.x) / 2;
|
||||
m_position.y = (DisplayHeight(session->m_display, session->m_screen) - m_size.y) / 2;
|
||||
}
|
||||
|
||||
/* Create the X window */
|
||||
unsigned long mask = CWBackPixel | CWBorderPixel | CWColormap;
|
||||
m_window = XCreateWindow(session->m_display, session->m_root,
|
||||
m_position.x, m_position.y, m_dimension.x, m_dimension.y, 0, m_visinfo->depth,
|
||||
m_position.x, m_position.y, m_size.x, m_size.y, 0, m_visinfo->depth,
|
||||
InputOutput, m_visinfo->visual, mask, &x11attr);
|
||||
|
||||
if (!m_window)
|
||||
|
@ -236,8 +236,8 @@ void X11Device::init(Device *other) {
|
|||
|
||||
/* Make the window non-resizable */
|
||||
XSizeHints *hints = XAllocSizeHints();
|
||||
hints->min_width = hints->max_width = hints->width = m_dimension.x;
|
||||
hints->min_height = hints->max_height = hints->height = m_dimension.y;
|
||||
hints->min_width = hints->max_width = hints->width = m_size.x;
|
||||
hints->min_height = hints->max_height = hints->height = m_size.y;
|
||||
hints->x = m_position.x; hints->y = m_position.y;
|
||||
hints->flags = PMaxSize | PMinSize | USSize | USPosition;
|
||||
XSetNormalHints(session->m_display, m_window, hints);
|
||||
|
@ -426,10 +426,10 @@ void X11Device::processEvent(const XEvent &event) {
|
|||
translateMouse(event, deviceEvent);
|
||||
deviceEvent.setMouseButton(m_buttonState);
|
||||
if (m_grab)
|
||||
warpMouse(Point2i(getDimension().x / 2, getDimension().y/2));
|
||||
warpMouse(Point2i(getSize().x / 2, getSize().y/2));
|
||||
int xpos = deviceEvent.getMousePosition().x;
|
||||
int ypos = deviceEvent.getMousePosition().y;
|
||||
if (xpos > m_dimension.x || xpos < 0 || ypos > m_dimension.y || ypos < 0)
|
||||
if (xpos > m_size.x || xpos < 0 || ypos > m_size.y || ypos < 0)
|
||||
return;
|
||||
}
|
||||
break;
|
||||
|
|
|
@ -1054,5 +1054,5 @@ void GLWidget::onUpdateView() {
|
|||
|
||||
void GLWidget::resizeGL(int width, int height) {
|
||||
glViewport(0, 0, (GLint) width, (GLint) height);
|
||||
m_device->setDimension(Vector2i(width, height));
|
||||
m_device->setSize(Vector2i(width, height));
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue