Fix Win32 platform multiple windows OpenGL context usage; -- dlangide#151

This commit is contained in:
Vadim Lopatin 2016-04-27 11:56:56 +03:00
parent 416b519f39
commit 38899267f1
2 changed files with 18 additions and 7 deletions

View File

@ -344,7 +344,7 @@ private abstract class GLCache
if (!_texture.ID)
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);
if (!glSupport.setTextureImage(_texture, _drawbuf.width, _drawbuf.height, cast(ubyte*)pixels)) {
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) {
if (_needUpdateTexture)
updateTexture();
if (_texture.ID != 0) {
if (_texture && _texture.ID != 0) {
//rotationAngle = 0;
int rx = dstrc.middlex;
int ry = dstrc.middley;
@ -628,7 +628,7 @@ private class GLGlyphCache : GLCache
void drawItem(GLCacheItem item, Rect dstrc, Rect srcrc, uint color, Rect * clip) {
if (_needUpdateTexture)
updateTexture();
if (_texture.ID != 0) {
if (_texture && _texture.ID != 0) {
// convert coordinates to cached texture
srcrc.offset(item._rc.left, item._rc.top);
if (clip) {

View File

@ -167,8 +167,15 @@ static if (ENABLE_OPENGL) {
bool _error;
/// Init OpenGL context, if not yet initialized
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;
}
if (_error)
return false;
if (setupPixelFormat(hDC)) {
@ -203,11 +210,15 @@ static if (ENABLE_OPENGL) {
}
/// make this context current for DC
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
void unbind(HDC hDC) {
wglMakeCurrent(hDC, null);
//wglMakeCurrent(hDC, null);
wglMakeCurrent(null, null);
}
void swapBuffers(HDC hDC) {
SwapBuffers(hDC);
@ -312,7 +323,7 @@ class Win32Window : Window {
}
buf.afterDrawing();
sharedGLContext.swapBuffers(hdc);
sharedGLContext.unbind(hdc);
//sharedGLContext.unbind(hdc);
destroy(buf);
}
}