From aea38fb5fef5fa3b0ae3f0bcca7a93438afe4009 Mon Sep 17 00:00:00 2001 From: Vadim Lopatin Date: Mon, 21 Dec 2015 09:52:19 +0300 Subject: [PATCH] change OpenGLDrawable interface --- examples/example1/src/example1.d | 10 ++++++++-- src/dlangui/graphics/drawbuf.d | 2 +- src/dlangui/graphics/gldrawbuf.d | 15 +++++++-------- src/dlangui/graphics/resources.d | 4 ++-- 4 files changed, 18 insertions(+), 13 deletions(-) diff --git a/examples/example1/src/example1.d b/examples/example1/src/example1.d index 998ae83a..1635fe15 100644 --- a/examples/example1/src/example1.d +++ b/examples/example1/src/example1.d @@ -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(); } diff --git a/src/dlangui/graphics/drawbuf.d b/src/dlangui/graphics/drawbuf.d index 37273f8b..844572eb 100644 --- a/src/dlangui/graphics/drawbuf.d +++ b/src/dlangui/graphics/drawbuf.d @@ -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 { diff --git a/src/dlangui/graphics/gldrawbuf.d b/src/dlangui/graphics/gldrawbuf.d index 74de1d39..f7a7231c 100644 --- a/src/dlangui/graphics/gldrawbuf.d +++ b/src/dlangui/graphics/gldrawbuf.d @@ -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); } } } diff --git a/src/dlangui/graphics/resources.d b/src/dlangui/graphics/resources.d index b05ca84d..e9810ddf 100644 --- a/src/dlangui/graphics/resources.d +++ b/src/dlangui/graphics/resources.d @@ -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); } }