mirror of https://github.com/buggins/dlangui.git
change OpenGLDrawable interface
This commit is contained in:
parent
57aba53bf5
commit
aea38fb5fe
|
@ -974,7 +974,8 @@ static if (ENABLE_OPENGL) {
|
|||
|
||||
bool _oldApi;
|
||||
|
||||
private void doDraw(DrawBuf buf, Rect rc) {
|
||||
/// this is OpenGLDrawableDelegate implementation
|
||||
private void doDraw(Rect windowRect, Rect rc) {
|
||||
Log.v("GlGears: MyOpenglWidget.doDraw() draw gears");
|
||||
if (!openglEnabled) {
|
||||
Log.v("GlGears: OpenGL is disabled");
|
||||
|
@ -988,6 +989,7 @@ static if (ENABLE_OPENGL) {
|
|||
}
|
||||
}
|
||||
|
||||
/// Legacy API example (glBegin/glEnd)
|
||||
void drawUsingOldAPI(Rect rc) {
|
||||
static bool _initCalled;
|
||||
if (!_initCalled) {
|
||||
|
@ -1006,17 +1008,21 @@ static if (ENABLE_OPENGL) {
|
|||
glDisable(GL_LIGHT0);
|
||||
glDisable(GL_DEPTH_TEST);
|
||||
}
|
||||
|
||||
/// New API example (OpenGL3+, shaders)
|
||||
void drawUsingNewAPI(Rect rc) {
|
||||
// TODO: put some sample code here
|
||||
}
|
||||
/// returns true is widget is being animated - need to call animate() and redraw
|
||||
@property override bool animating() { return true; }
|
||||
/// animates window; interval is time left from previous draw, in hnsecs (1/10000000 of second)
|
||||
override void animate(long interval) {
|
||||
if (_oldApi) {
|
||||
// animate legacy API example
|
||||
// rotate gears
|
||||
angle += interval * 0.000002f;
|
||||
} else {
|
||||
// animate new API example
|
||||
// TODO: animate new API example
|
||||
}
|
||||
invalidate();
|
||||
}
|
||||
|
|
|
@ -40,7 +40,7 @@ static if (ENABLE_OPENGL) {
|
|||
}
|
||||
|
||||
/// Custom draw delegate for OpenGL direct drawing
|
||||
alias OpenGLDrawableDelegate = void delegate(DrawBuf buf, Rect rc);
|
||||
alias OpenGLDrawableDelegate = void delegate(Rect windowRect, Rect rc);
|
||||
|
||||
/// drawing buffer - image container which allows to perform some drawing operations
|
||||
class DrawBuf : RefCountedObject {
|
||||
|
|
|
@ -91,7 +91,7 @@ class GLDrawBuf : DrawBuf, GLConfigCallback {
|
|||
|
||||
/// draw custom OpenGL scene
|
||||
override void drawCustomOpenGLScene(Rect rc, OpenGLDrawableDelegate handler) {
|
||||
_scene.add(new CustomDrawnSceneItem(this, rc, handler));
|
||||
_scene.add(new CustomDrawnSceneItem(Rect(0, 0, width, height), rc, handler));
|
||||
}
|
||||
|
||||
/// fill the whole buffer with solid color (no clipping applied)
|
||||
|
@ -911,13 +911,13 @@ public:
|
|||
|
||||
private class CustomDrawnSceneItem : SceneItem {
|
||||
private:
|
||||
DrawBuf _buf;
|
||||
Rect _windowRect;
|
||||
Rect _rc;
|
||||
OpenGLDrawableDelegate _handler;
|
||||
|
||||
public:
|
||||
this(DrawBuf buf, Rect rc, OpenGLDrawableDelegate handler) {
|
||||
_buf = buf;
|
||||
this(Rect windowRect, Rect rc, OpenGLDrawableDelegate handler) {
|
||||
_windowRect = windowRect;
|
||||
_rc = rc;
|
||||
_handler = handler;
|
||||
}
|
||||
|
@ -925,10 +925,9 @@ public:
|
|||
if (_handler) {
|
||||
|
||||
import derelict.opengl3.gl3 : glViewport;
|
||||
glViewport(_rc.left, _buf.height - _rc.bottom, _rc.width, _rc.height);
|
||||
_handler(_buf, _rc);
|
||||
glSupport.setOrthoProjection(Rect(0, 0, _buf.width, _buf.height));
|
||||
|
||||
glViewport(_rc.left, _windowRect.height - _rc.bottom, _rc.width, _rc.height);
|
||||
_handler(_windowRect, _rc);
|
||||
glSupport.setOrthoProjection(_windowRect);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -252,10 +252,10 @@ class OpenGLDrawable : Drawable {
|
|||
_drawHandler = drawHandler;
|
||||
}
|
||||
|
||||
void onDraw(DrawBuf buf, Rect rc) {
|
||||
void onDraw(Rect windowRect, Rect rc) {
|
||||
// either override this method or assign draw handler
|
||||
if (_drawHandler) {
|
||||
_drawHandler(buf, rc);
|
||||
_drawHandler(windowRect, rc);
|
||||
}
|
||||
}
|
||||
|
||||
|
|
Loading…
Reference in New Issue