refactor setOrthoProjection, implement setPerspectiveProjection

This commit is contained in:
Vadim Lopatin 2015-12-21 10:18:49 +03:00
parent aea38fb5fe
commit 0556ad5781
2 changed files with 15 additions and 12 deletions

View File

@ -60,7 +60,7 @@ class GLDrawBuf : DrawBuf, GLConfigCallback {
override void saveConfiguration() { override void saveConfiguration() {
} }
override void restoreConfiguration() { override void restoreConfiguration() {
glSupport.setOrthoProjection(Rect(0, 0, _dx, _dy)); glSupport.setOrthoProjection(Rect(0, 0, _dx, _dy), Rect(0, 0, _dx, _dy));
} }
/// reserved for hardware-accelerated drawing - begins drawing batch /// reserved for hardware-accelerated drawing - begins drawing batch
@ -75,7 +75,7 @@ class GLDrawBuf : DrawBuf, GLConfigCallback {
/// reserved for hardware-accelerated drawing - ends drawing batch /// reserved for hardware-accelerated drawing - ends drawing batch
override void afterDrawing() { override void afterDrawing() {
glSupport.setOrthoProjection(Rect(0, 0, _dx, _dy)); glSupport.setOrthoProjection(Rect(0, 0, _dx, _dy), Rect(0, 0, _dx, _dy));
_scene.draw(); _scene.draw();
glSupport.flushGL(); glSupport.flushGL();
destroy(_scene); destroy(_scene);
@ -923,11 +923,9 @@ public:
} }
override void draw() { override void draw() {
if (_handler) { if (_handler) {
glSupport.setOrthoProjection(_windowRect, _rc);
import derelict.opengl3.gl3 : glViewport;
glViewport(_rc.left, _windowRect.height - _rc.bottom, _rc.width, _rc.height);
_handler(_windowRect, _rc); _handler(_windowRect, _rc);
glSupport.setOrthoProjection(_windowRect); glSupport.setOrthoProjection(_windowRect, _windowRect);
} }
} }
} }

View File

@ -979,9 +979,9 @@ class GLSupport {
qtmatrix[y * 4 + x] = m[y][x]; qtmatrix[y * 4 + x] = m[y][x];
} }
void setOrthoProjection(Rect view) { void setOrthoProjection(Rect windowRect, Rect view) {
bufferDx = view.width; bufferDx = windowRect.width;
bufferDy = view.height; bufferDy = windowRect.height;
QMatrix4x4_ortho(view.left, view.right, view.top, view.bottom, 0.5f, 50.0f); QMatrix4x4_ortho(view.left, view.right, view.top, view.bottom, 0.5f, 50.0f);
//myGlOrtho(0, dx, 0, dy, 0.1f, 5.0f); //myGlOrtho(0, dx, 0, dy, 0.1f, 5.0f);
@ -995,11 +995,16 @@ class GLSupport {
//checkgl!glPushMatrix(); //checkgl!glPushMatrix();
glLoadIdentity(); glLoadIdentity();
} }
checkgl!glViewport(view.left, view.top, view.right, view.bottom); checkgl!glViewport(view.left, windowRect.height - view.bottom, view.width, view.height);
} }
void setPerspectiveProjection(float fieldOfView, float aspectRatio, float nearPlane, float farPlane) { void setPerspectiveProjection(Rect windowRect, Rect view, float fieldOfView, float nearPlane, float farPlane) {
// TODO
bufferDx = windowRect.width;
bufferDy = windowRect.height;
float aspectRatio = cast(float)view.width / cast(float)view.height;
QMatrix4x4_perspective(fieldOfView, aspectRatio, nearPlane, farPlane);
checkgl!glViewport(view.left, windowRect.height - view.bottom, view.width, view.height);
} }
} }