mirror of https://github.com/buggins/dlangui.git
Fix Win32 platform multiple windows OpenGL context usage; -- dlangide#151
This commit is contained in:
parent
416b519f39
commit
38899267f1
|
|
@ -344,7 +344,7 @@ private abstract class GLCache
|
||||||
if (!_texture.ID)
|
if (!_texture.ID)
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
Log.d("updateTexture for cache page - setting image ", _drawbuf.width, "x", _drawbuf.height, " tx=", _texture.ID);
|
Log.d("updateTexture for cache page - setting image ", _drawbuf.width, "x", _drawbuf.height, " tx=", _texture ? _texture.ID : 0);
|
||||||
uint * pixels = _drawbuf.scanLine(0);
|
uint * pixels = _drawbuf.scanLine(0);
|
||||||
if (!glSupport.setTextureImage(_texture, _drawbuf.width, _drawbuf.height, cast(ubyte*)pixels)) {
|
if (!glSupport.setTextureImage(_texture, _drawbuf.width, _drawbuf.height, cast(ubyte*)pixels)) {
|
||||||
destroy(_texture);
|
destroy(_texture);
|
||||||
|
|
@ -527,7 +527,7 @@ private class GLImageCache : GLCache
|
||||||
void drawItem(GLCacheItem item, Rect dstrc, Rect srcrc, uint color, uint options, Rect * clip, int rotationAngle) {
|
void drawItem(GLCacheItem item, Rect dstrc, Rect srcrc, uint color, uint options, Rect * clip, int rotationAngle) {
|
||||||
if (_needUpdateTexture)
|
if (_needUpdateTexture)
|
||||||
updateTexture();
|
updateTexture();
|
||||||
if (_texture.ID != 0) {
|
if (_texture && _texture.ID != 0) {
|
||||||
//rotationAngle = 0;
|
//rotationAngle = 0;
|
||||||
int rx = dstrc.middlex;
|
int rx = dstrc.middlex;
|
||||||
int ry = dstrc.middley;
|
int ry = dstrc.middley;
|
||||||
|
|
@ -628,7 +628,7 @@ private class GLGlyphCache : GLCache
|
||||||
void drawItem(GLCacheItem item, Rect dstrc, Rect srcrc, uint color, Rect * clip) {
|
void drawItem(GLCacheItem item, Rect dstrc, Rect srcrc, uint color, Rect * clip) {
|
||||||
if (_needUpdateTexture)
|
if (_needUpdateTexture)
|
||||||
updateTexture();
|
updateTexture();
|
||||||
if (_texture.ID != 0) {
|
if (_texture && _texture.ID != 0) {
|
||||||
// convert coordinates to cached texture
|
// convert coordinates to cached texture
|
||||||
srcrc.offset(item._rc.left, item._rc.top);
|
srcrc.offset(item._rc.left, item._rc.top);
|
||||||
if (clip) {
|
if (clip) {
|
||||||
|
|
|
||||||
|
|
@ -167,8 +167,15 @@ static if (ENABLE_OPENGL) {
|
||||||
bool _error;
|
bool _error;
|
||||||
/// Init OpenGL context, if not yet initialized
|
/// Init OpenGL context, if not yet initialized
|
||||||
bool init(HDC hDC) {
|
bool init(HDC hDC) {
|
||||||
if (_hGLRC)
|
if (_hGLRC) {
|
||||||
|
// just setup pixel format
|
||||||
|
if (setupPixelFormat(hDC)) {
|
||||||
|
Log.i("OpenGL context already exists. Setting pixel format.");
|
||||||
|
} else {
|
||||||
|
Log.e("Cannot setup pixel format");
|
||||||
|
}
|
||||||
return true;
|
return true;
|
||||||
|
}
|
||||||
if (_error)
|
if (_error)
|
||||||
return false;
|
return false;
|
||||||
if (setupPixelFormat(hDC)) {
|
if (setupPixelFormat(hDC)) {
|
||||||
|
|
@ -203,11 +210,15 @@ static if (ENABLE_OPENGL) {
|
||||||
}
|
}
|
||||||
/// make this context current for DC
|
/// make this context current for DC
|
||||||
void bind(HDC hDC) {
|
void bind(HDC hDC) {
|
||||||
wglMakeCurrent(hDC, _hGLRC);
|
if (!wglMakeCurrent(hDC, _hGLRC)) {
|
||||||
|
import std.string : format;
|
||||||
|
Log.e("wglMakeCurrent is failed. GetLastError=%x".format(GetLastError()));
|
||||||
|
}
|
||||||
}
|
}
|
||||||
/// make null context current for DC
|
/// make null context current for DC
|
||||||
void unbind(HDC hDC) {
|
void unbind(HDC hDC) {
|
||||||
wglMakeCurrent(hDC, null);
|
//wglMakeCurrent(hDC, null);
|
||||||
|
wglMakeCurrent(null, null);
|
||||||
}
|
}
|
||||||
void swapBuffers(HDC hDC) {
|
void swapBuffers(HDC hDC) {
|
||||||
SwapBuffers(hDC);
|
SwapBuffers(hDC);
|
||||||
|
|
@ -312,7 +323,7 @@ class Win32Window : Window {
|
||||||
}
|
}
|
||||||
buf.afterDrawing();
|
buf.afterDrawing();
|
||||||
sharedGLContext.swapBuffers(hdc);
|
sharedGLContext.swapBuffers(hdc);
|
||||||
sharedGLContext.unbind(hdc);
|
//sharedGLContext.unbind(hdc);
|
||||||
destroy(buf);
|
destroy(buf);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue