diff --git a/3rdparty/X11/Xlib.d b/3rdparty/X11/Xlib.d
index d83c0330..f96b5db2 100644
--- a/3rdparty/X11/Xlib.d
+++ b/3rdparty/X11/Xlib.d
@@ -18,7 +18,7 @@ const int XlibSpecificationRelease=6;
version = X_HAVE_UTF8_STRING;
alias XPointer = void*;
-typedef int Status ;
+alias Status = int;
enum Bool:int{False,True}; //xlib boolean is int type, D bool is only byte
enum QueueMode{QueuedAlready,QueuedAfterReading,QueuedAfterFlush};
@@ -143,7 +143,7 @@ struct XGCValues
byte dashes;
};
-typedef void* GC;
+alias GC = void*;
/*
* Visual structure; contains information about colormapping possible.
@@ -462,7 +462,7 @@ struct Display
/* there is more to this structure, but it is private to Xlib */
}
-typedef Display *_XPrivDisplay;
+alias _XPrivDisplay = Display *;
struct XrmHashBucketRec{};
@@ -485,8 +485,8 @@ struct XKeyEvent
uint keycode; /* detail */
Bool same_screen; /* same screen flag */
};
-typedef XKeyEvent XKeyPressedEvent;
-typedef XKeyEvent XKeyReleasedEvent;
+alias XKeyPressedEvent = XKeyEvent;
+alias XKeyReleasedEvent = XKeyEvent;
struct XButtonEvent
{
@@ -504,8 +504,8 @@ struct XButtonEvent
uint button; /* detail */
Bool same_screen; /* same screen flag */
};
-typedef XButtonEvent XButtonPressedEvent;
-typedef XButtonEvent XButtonReleasedEvent;
+alias XButtonPressedEvent = XButtonEvent;
+alias XButtonReleasedEvent = XButtonEvent;
struct XMotionEvent{
int type; /* of event */
@@ -522,7 +522,7 @@ struct XMotionEvent{
byte is_hint; /* detail */
Bool same_screen; /* same screen flag */
};
-typedef XMotionEvent XPointerMovedEvent;
+alias XPointerMovedEvent = XMotionEvent;
struct XCrossingEvent{
int type; /* of event */
@@ -545,8 +545,8 @@ struct XCrossingEvent{
Bool focus; /* Boolean focus */
KeyOrButtonMask state; /* key or button mask */
};
-typedef XCrossingEvent XEnterWindowEvent;
-typedef XCrossingEvent XLeaveWindowEvent;
+alias XEnterWindowEvent = XCrossingEvent ;
+alias XLeaveWindowEvent = XCrossingEvent ;
struct XFocusChangeEvent{
int type; /* FocusIn or FocusOut */
@@ -563,8 +563,8 @@ struct XFocusChangeEvent{
* NotifyPointerRoot, NotifyDetailNone
*/
};
-typedef XFocusChangeEvent XFocusInEvent;
-typedef XFocusChangeEvent XFocusOutEvent;
+alias XFocusInEvent = XFocusChangeEvent;
+alias XFocusOutEvent = XFocusChangeEvent;
/* generated on EnterWindow and FocusIn when KeyMapState selected */
struct XKeymapEvent
@@ -1008,9 +1008,9 @@ typedef void (*XOMProc)();
struct _XOM{}
struct _XOC{}
-typedef _XOM *XOM;
-typedef _XOC *XOC;
-typedef _XOC *XFontSet;
+alias XOM = _XOM *;
+alias XOC = _XOC *;
+alias XFontSet = _XOC *;
struct XmbTextItem{
byte *chars;
int nchars;
@@ -1066,27 +1066,27 @@ struct XOMFontInfo{
struct _XIM{}
struct _XIC{}
-typedef _XIM *XIM;
-typedef _XIC *XIC;
+alias XIM = _XIM *;
+alias XIC = _XIC *;
-typedef void function(
+alias XIMProc = void function(
XIM,
XPointer,
XPointer
-) XIMProc;
+) ;
-typedef Bool function(
+alias XICProc = Bool function(
XIC,
XPointer,
XPointer
-)XICProc;
+);
-typedef void function(
+alias XIDProc = void function(
Display*,
XPointer,
XPointer
-)XIDProc;
+);
enum XIMStyle:ulong
{
@@ -1157,7 +1157,7 @@ const int XLookupKeySym= 3;
const int XLookupBoth = 4;
-typedef void *XVaNestedList;
+alias XVaNestedList = void *;
struct XIMCallback{
XPointer client_data;
@@ -1232,7 +1232,7 @@ struct XIMStringConversionText {
};
};
-typedef ushort XIMStringConversionPosition;
+alias XIMStringConversionPosition = ushort ;
enum XIMStringConversionType:ushort
{
@@ -1753,19 +1753,19 @@ extern int XScreenNumberOfScreen(
Screen* /* screen */
);
-typedef int function ( /* WARNING, this type not in Xlib spec */
+alias XErrorHandler = int function ( /* WARNING, this type not in Xlib spec */
Display* /* display */,
XErrorEvent* /* error_event */
-) XErrorHandler;
+);
extern XErrorHandler XSetErrorHandler (
XErrorHandler /* handler */
);
-typedef int function ( /* WARNING, this type not in Xlib spec */
+alias XIOErrorHandler = int function ( /* WARNING, this type not in Xlib spec */
Display* /* display */
-) XIOErrorHandler;
+);
extern XIOErrorHandler XSetIOErrorHandler (
XIOErrorHandler /* handler */
@@ -3876,13 +3876,13 @@ extern Bool XUnregisterIMInstantiateCallback(
XPointer /* client_data */
);
-typedef void function(
+alias XConnectionWatchProc = void function(
Display* /* dpy */,
XPointer /* client_data */,
int /* fd */,
Bool /* opening */, /* open or close flag */
XPointer* /* watch_data */ /* open sets, close uses */
-)XConnectionWatchProc;
+);
extern Status XInternalConnectionNumbers(
diff --git a/dlanguilib.dproj b/dlanguilib.dproj
index 8e382708..07988f92 100644
--- a/dlanguilib.dproj
+++ b/dlanguilib.dproj
@@ -28,6 +28,8 @@
obj/Debug
true
StaticLibrary
+ -version=USE_OPENGL
+
bin\Release
@@ -171,6 +173,8 @@
3rdparty\DerelictFI\types.d
+
+
diff --git a/examples/example1/main.d b/examples/example1/main.d
index 81837325..29763117 100644
--- a/examples/example1/main.d
+++ b/examples/example1/main.d
@@ -8,6 +8,7 @@ version (linux) {
pragma(lib, "xcb");
pragma(lib, "xcb-shm");
pragma(lib, "xcb-image");
+ pragma(lib, "X11-xcb");
pragma(lib, "X11");
pragma(lib, "dl");
}
diff --git a/src/dlangui/graphics/glsupport.d b/src/dlangui/graphics/glsupport.d
index 0fc259e3..5db06bf2 100644
--- a/src/dlangui/graphics/glsupport.d
+++ b/src/dlangui/graphics/glsupport.d
@@ -1,664 +1,664 @@
-module dlangui.graphics.glsupport;
-
-version(USE_OPENGL) {
-
-import dlangui.core.logger;
-private import derelict.opengl3.gl3;
-//private import gl3n.linalg;
-private import dlangui.core.types;
-private import std.conv;
-
-// utility function to fill 4-float array of vertex colors with converted CR 32bit color
-private void LVGLFillColor(uint color, float * buf, int count) {
- float r = ((color >> 16) & 255) / 255.0f;
- float g = ((color >> 8) & 255) / 255.0f;
- float b = ((color >> 0) & 255) / 255.0f;
- float a = (((color >> 24) & 255) ^ 255) / 255.0f;
- for (int i=0; i 1)
- {
- GLchar[] msg = new GLchar[blen + 1];
- GLchar * pmsg = &msg[0];
- glGetShaderInfoLog(shader, blen, &slen, pmsg);
- Log.d("Shader compilation error: ", fromStringz(pmsg));
- }
- return 0;
- }
- }
- bool compile() {
- glslversion = fromStringz(glGetString(GL_SHADING_LANGUAGE_VERSION));
- vertexShader = compileShader(vertexSource, GL_VERTEX_SHADER);
- fragmentShader = compileShader(fragmentSource, GL_FRAGMENT_SHADER);
- if (!vertexShader || !fragmentShader) {
- error = true;
- return false;
- }
- program = glCreateProgram();
- glAttachShader(program, vertexShader);
- glAttachShader(program, fragmentShader);
- glLinkProgram(program);
- GLint isLinked = 0;
- glGetProgramiv(program, GL_LINK_STATUS, &isLinked);
- if (!isLinked) {
- GLint maxLength = 0;
- glGetProgramiv(program, GL_INFO_LOG_LENGTH, &maxLength);
- GLchar[] msg = new GLchar[maxLength + 1];
- GLchar * pmsg = &msg[0];
- glGetProgramInfoLog(program, maxLength, &maxLength, pmsg);
- Log.e("Error while linking program: ", fromStringz(pmsg));
- error = true;
- return false;
- }
- Log.d("Program compiled successfully");
- //glDetachShader(program, vertexShader);
- //glDetachShader(program, fragmentShader);
- glUseProgram(program);
- checkError("glUseProgram " ~ to!string(program));
- if (!initLocations()) {
- Log.e("some of locations were not found");
- error = true;
- }
- initialized = true;
- return true;
- }
- bool initLocations() {
- return true;
- }
- bool bind() {
- if (!initialized)
- return false;
- if (!glIsProgram(program))
- Log.e("!glIsProgram(program)");
- glUseProgram(program);
- checkError("glUseProgram " ~ to!string(program));
- return true;
- }
- void release() {
- glUseProgram(0);
- checkError("glUseProgram(0)");
- }
- ~this() {
- clear();
- }
- void clear() {
- // TODO: cleanup
- if (program)
- glDeleteProgram(program);
- if (vertexShader)
- glDeleteShader(vertexShader);
- if (fragmentShader)
- glDeleteShader(fragmentShader);
- program = vertexShader = fragmentShader = 0;
- initialized = false;
- }
-}
-
-immutable string HIGHP = "";
-immutable string LOWP = "";
-immutable string MEDIUMP = "";
-
-class SolidFillProgram : GLProgram {
- @property override string vertexSource() {
- return
- "attribute " ~ HIGHP ~ " vec4 vertex;\n"
- "attribute " ~ LOWP ~ " vec4 colAttr;\n"
- "varying " ~ LOWP ~ " vec4 col;\n"
- "uniform " ~ MEDIUMP ~ " mat4 matrix;\n"
- "void main(void)\n"
- "{\n"
- " gl_Position = matrix * vertex;\n"
- " col = colAttr;\n"
- "}\n";
-
- }
- @property override string fragmentSource() {
- return
- "varying " ~ LOWP ~ " vec4 col;\n"
- "void main(void)\n"
- "{\n"
- " gl_FragColor = col;\n"
- "}\n";
- }
-
- void beforeExecute() {
- glEnable(GL_BLEND);
- glDisable(GL_CULL_FACE);
- checkError("glDisable(GL_CULL_FACE)");
- glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA);
- //glTexEnvi(GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_MODULATE);
- checkError("glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA)");
- bind();
- //glUniformMatrix4fv(matrixLocation, 1, false, m.value_ptr);
- //glUniformMatrix4fv(matrixLocation, 1, false, matrix.ptr);
- glUniformMatrix4fv(matrixLocation, 1, false, qtmatrix.ptr);
- checkError("glUniformMatrix4fv");
- }
-
- void afterExecute() {
- release();
- }
-
- protected GLint matrixLocation;
- protected GLint vertexLocation;
- protected GLint colAttrLocation;
- protected GLuint vertexBuffer;
- protected GLuint colAttrBuffer;
- override bool initLocations() {
- bool res = super.initLocations();
-
- //glGenBuffers(1, &vertexBuffer);
- //glBindBuffer(GL_ARRAY_BUFFER, vertexBuffer);
- //glBufferData(GL_ARRAY_BUFFER, float.sizeof * 3 * 6, null, GL_DYNAMIC_DRAW);
- //glGenBuffers(1, &colAttrBuffer);
- //glBindBuffer(GL_ARRAY_BUFFER, colAttrBuffer);
- //glBufferData(GL_ARRAY_BUFFER, float.sizeof * 4 * 6, null, GL_DYNAMIC_DRAW);
-
- matrixLocation = glGetUniformLocation(program, "matrix");
- checkError("glGetUniformLocation matrix");
- vertexLocation = glGetAttribLocation(program, "vertex");
- checkError("glGetAttribLocation vertex");
- colAttrLocation = glGetAttribLocation(program, "colAttr");
- checkError("glGetAttribLocation colAttr");
- return res && matrixLocation >= 0 && vertexLocation >= 0 && colAttrLocation >= 0;
- }
-
- bool execute(float[] vertices, float[] colors) {
- if (error)
- return false;
- if (!initialized)
- if (!compile())
- return false;
- beforeExecute();
-
- glEnableVertexAttribArray(vertexLocation);
- checkError("glEnableVertexAttribArray");
- glVertexAttribPointer(vertexLocation, 3, GL_FLOAT, GL_FALSE, float.sizeof * 3, vertices.ptr);
- checkError("glVertexAttribPointer");
-
- glEnableVertexAttribArray(colAttrLocation);
- checkError("glEnableVertexAttribArray");
- glVertexAttribPointer(colAttrLocation, 4, GL_FLOAT, GL_FALSE, float.sizeof * 4, colors.ptr);
- checkError("glVertexAttribPointer");
-
- glDrawArrays(GL_TRIANGLES, 0, 6);
- checkError("glDrawArrays");
-
- glDisableVertexAttribArray(vertexLocation);
- checkError("glDisableVertexAttribArray");
- glDisableVertexAttribArray(colAttrLocation);
- checkError("glDisableVertexAttribArray");
-
- afterExecute();
- return true;
- }
-}
-
-class TextureProgram : SolidFillProgram {
- @property override string vertexSource() {
- return
- "attribute " ~ HIGHP ~ " vec4 vertex;\n"
- "attribute " ~ LOWP ~ " vec4 colAttr;\n"
- "attribute " ~ MEDIUMP ~ " vec4 texCoord;\n"
- "varying " ~ LOWP ~ " vec4 col;\n"
- "varying " ~ MEDIUMP ~ " vec4 texc;\n"
- "uniform " ~ MEDIUMP ~ " mat4 matrix;\n"
- "void main(void)\n"
- "{\n"
- " gl_Position = matrix * vertex;\n"
- " col = colAttr;\n"
- " texc = texCoord;\n"
- "}\n";
-
- }
- @property override string fragmentSource() {
- return
- "uniform sampler2D texture;\n"
- "varying " ~ LOWP ~ " vec4 col;\n"
- "varying " ~ MEDIUMP ~ " vec4 texc;\n"
- "void main(void)\n"
- "{\n"
- " gl_FragColor = texture2D(texture, texc.st) * col;\n"
- "}\n";
- }
-
- GLint texCoordLocation;
- override bool initLocations() {
- bool res = super.initLocations();
- texCoordLocation = glGetAttribLocation(program, "texCoord");
- return res && texCoordLocation >= 0;
- }
-
- bool execute(float[] vertices, float[] texcoords, float[] colors, uint textureId, bool linear) {
- if (error)
- return false;
- if (!initialized)
- if (!compile())
- return false;
- beforeExecute();
- glActiveTexture(GL_TEXTURE0);
- checkError("glActiveTexture GL_TEXTURE0");
- glBindTexture(GL_TEXTURE_2D, textureId);
- checkError("glBindTexture");
- glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, linear ? GL_LINEAR : GL_NEAREST);
- checkError("drawColorAndTextureRect - glTexParameteri");
- glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, linear ? GL_LINEAR : GL_NEAREST);
- checkError("drawColorAndTextureRect - glTexParameteri");
-
- glEnableVertexAttribArray(vertexLocation);
- glEnableVertexAttribArray(colAttrLocation);
- glEnableVertexAttribArray(texCoordLocation);
-
- glVertexAttribPointer(vertexLocation, 3, GL_FLOAT, GL_FALSE, 0, vertices.ptr);
- glVertexAttribPointer(colAttrLocation, 4, GL_FLOAT, GL_FALSE, 0, colors.ptr);
- glVertexAttribPointer(texCoordLocation, 2, GL_FLOAT, GL_FALSE, 0, texcoords.ptr);
-
- glDrawArrays(GL_TRIANGLES, 0, 6);
- checkError("glDrawArrays");
-
- glDisableVertexAttribArray(vertexLocation);
- glDisableVertexAttribArray(colAttrLocation);
- glDisableVertexAttribArray(texCoordLocation);
-
- afterExecute();
- glBindTexture(GL_TEXTURE_2D, 0);
- checkError("glBindTexture");
- return true;
- }
-}
-
-__gshared TextureProgram _textureProgram;
-__gshared SolidFillProgram _solidFillProgram;
-
-bool initShaders() {
- if (_textureProgram is null) {
- _textureProgram = new TextureProgram();
- if (!_textureProgram.compile())
- return false;
- }
- if (_solidFillProgram is null) {
- _solidFillProgram = new SolidFillProgram();
- if (!_solidFillProgram.compile())
- return false;
- }
- Log.d("Shaders compiled successfully");
- return true;
-}
-
-bool uninitShaders() {
- Log.d("Uniniting shaders");
- if (_textureProgram !is null) {
- destroy(_textureProgram);
- _textureProgram = null;
- }
- if (_solidFillProgram !is null) {
- destroy(_solidFillProgram);
- _solidFillProgram = null;
- }
- return true;
-}
-
-bool isTexture(uint textureId) {
- return glIsTexture(textureId) == GL_TRUE;
-}
-
-void setRotation(int x, int y, int rotationAngle) {
- /*
- this->rotationAngle = rotationAngle;
- rotationX = x;
- rotationY = y;
- if (!currentFramebufferId) {
- rotationY = bufferDy - rotationY;
- }
-
- QMatrix4x4 matrix2;
- matrix2.ortho(0, bufferDx, 0, bufferDy, 0.5f, 5.0f);
- if (rotationAngle) {
- matrix2.translate(rotationX, rotationY, 0);
- matrix2.rotate(rotationAngle, 0, 0, 1);
- matrix2.translate(-rotationX, -rotationY, 0);
- }
- matrix2.copyDataTo(m);
- */
-}
-
-
-}
+module dlangui.graphics.glsupport;
+
+version(USE_OPENGL) {
+
+import dlangui.core.logger;
+private import derelict.opengl3.gl3;
+//private import gl3n.linalg;
+private import dlangui.core.types;
+private import std.conv;
+
+// utility function to fill 4-float array of vertex colors with converted CR 32bit color
+private void LVGLFillColor(uint color, float * buf, int count) {
+ float r = ((color >> 16) & 255) / 255.0f;
+ float g = ((color >> 8) & 255) / 255.0f;
+ float b = ((color >> 0) & 255) / 255.0f;
+ float a = (((color >> 24) & 255) ^ 255) / 255.0f;
+ for (int i=0; i 1)
+ {
+ GLchar[] msg = new GLchar[blen + 1];
+ GLchar * pmsg = &msg[0];
+ glGetShaderInfoLog(shader, blen, &slen, pmsg);
+ Log.d("Shader compilation error: ", fromStringz(pmsg));
+ }
+ return 0;
+ }
+ }
+ bool compile() {
+ glslversion = fromStringz(glGetString(GL_SHADING_LANGUAGE_VERSION));
+ vertexShader = compileShader(vertexSource, GL_VERTEX_SHADER);
+ fragmentShader = compileShader(fragmentSource, GL_FRAGMENT_SHADER);
+ if (!vertexShader || !fragmentShader) {
+ error = true;
+ return false;
+ }
+ program = glCreateProgram();
+ glAttachShader(program, vertexShader);
+ glAttachShader(program, fragmentShader);
+ glLinkProgram(program);
+ GLint isLinked = 0;
+ glGetProgramiv(program, GL_LINK_STATUS, &isLinked);
+ if (!isLinked) {
+ GLint maxLength = 0;
+ glGetProgramiv(program, GL_INFO_LOG_LENGTH, &maxLength);
+ GLchar[] msg = new GLchar[maxLength + 1];
+ GLchar * pmsg = &msg[0];
+ glGetProgramInfoLog(program, maxLength, &maxLength, pmsg);
+ Log.e("Error while linking program: ", fromStringz(pmsg));
+ error = true;
+ return false;
+ }
+ Log.d("Program compiled successfully");
+ //glDetachShader(program, vertexShader);
+ //glDetachShader(program, fragmentShader);
+ glUseProgram(program);
+ checkError("glUseProgram " ~ to!string(program));
+ if (!initLocations()) {
+ Log.e("some of locations were not found");
+ error = true;
+ }
+ initialized = true;
+ return true;
+ }
+ bool initLocations() {
+ return true;
+ }
+ bool bind() {
+ if (!initialized)
+ return false;
+ if (!glIsProgram(program))
+ Log.e("!glIsProgram(program)");
+ glUseProgram(program);
+ checkError("glUseProgram " ~ to!string(program));
+ return true;
+ }
+ void release() {
+ glUseProgram(0);
+ checkError("glUseProgram(0)");
+ }
+ ~this() {
+ clear();
+ }
+ void clear() {
+ // TODO: cleanup
+ if (program)
+ glDeleteProgram(program);
+ if (vertexShader)
+ glDeleteShader(vertexShader);
+ if (fragmentShader)
+ glDeleteShader(fragmentShader);
+ program = vertexShader = fragmentShader = 0;
+ initialized = false;
+ }
+}
+
+immutable string HIGHP = "";
+immutable string LOWP = "";
+immutable string MEDIUMP = "";
+
+class SolidFillProgram : GLProgram {
+ @property override string vertexSource() {
+ return
+ "attribute " ~ HIGHP ~ " vec4 vertex;\n"
+ "attribute " ~ LOWP ~ " vec4 colAttr;\n"
+ "varying " ~ LOWP ~ " vec4 col;\n"
+ "uniform " ~ MEDIUMP ~ " mat4 matrix;\n"
+ "void main(void)\n"
+ "{\n"
+ " gl_Position = matrix * vertex;\n"
+ " col = colAttr;\n"
+ "}\n";
+
+ }
+ @property override string fragmentSource() {
+ return
+ "varying " ~ LOWP ~ " vec4 col;\n"
+ "void main(void)\n"
+ "{\n"
+ " gl_FragColor = col;\n"
+ "}\n";
+ }
+
+ void beforeExecute() {
+ glEnable(GL_BLEND);
+ glDisable(GL_CULL_FACE);
+ checkError("glDisable(GL_CULL_FACE)");
+ glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA);
+ //glTexEnvi(GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_MODULATE);
+ checkError("glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA)");
+ bind();
+ //glUniformMatrix4fv(matrixLocation, 1, false, m.value_ptr);
+ //glUniformMatrix4fv(matrixLocation, 1, false, matrix.ptr);
+ glUniformMatrix4fv(matrixLocation, 1, false, qtmatrix.ptr);
+ checkError("glUniformMatrix4fv");
+ }
+
+ void afterExecute() {
+ release();
+ }
+
+ protected GLint matrixLocation;
+ protected GLint vertexLocation;
+ protected GLint colAttrLocation;
+ protected GLuint vertexBuffer;
+ protected GLuint colAttrBuffer;
+ override bool initLocations() {
+ bool res = super.initLocations();
+
+ //glGenBuffers(1, &vertexBuffer);
+ //glBindBuffer(GL_ARRAY_BUFFER, vertexBuffer);
+ //glBufferData(GL_ARRAY_BUFFER, float.sizeof * 3 * 6, null, GL_DYNAMIC_DRAW);
+ //glGenBuffers(1, &colAttrBuffer);
+ //glBindBuffer(GL_ARRAY_BUFFER, colAttrBuffer);
+ //glBufferData(GL_ARRAY_BUFFER, float.sizeof * 4 * 6, null, GL_DYNAMIC_DRAW);
+
+ matrixLocation = glGetUniformLocation(program, "matrix");
+ checkError("glGetUniformLocation matrix");
+ vertexLocation = glGetAttribLocation(program, "vertex");
+ checkError("glGetAttribLocation vertex");
+ colAttrLocation = glGetAttribLocation(program, "colAttr");
+ checkError("glGetAttribLocation colAttr");
+ return res && matrixLocation >= 0 && vertexLocation >= 0 && colAttrLocation >= 0;
+ }
+
+ bool execute(float[] vertices, float[] colors) {
+ if (error)
+ return false;
+ if (!initialized)
+ if (!compile())
+ return false;
+ beforeExecute();
+
+ glEnableVertexAttribArray(vertexLocation);
+ checkError("glEnableVertexAttribArray");
+ glVertexAttribPointer(vertexLocation, 3, GL_FLOAT, GL_FALSE, float.sizeof * 3, vertices.ptr);
+ checkError("glVertexAttribPointer");
+
+ glEnableVertexAttribArray(colAttrLocation);
+ checkError("glEnableVertexAttribArray");
+ glVertexAttribPointer(colAttrLocation, 4, GL_FLOAT, GL_FALSE, float.sizeof * 4, colors.ptr);
+ checkError("glVertexAttribPointer");
+
+ glDrawArrays(GL_TRIANGLES, 0, 6);
+ checkError("glDrawArrays");
+
+ glDisableVertexAttribArray(vertexLocation);
+ checkError("glDisableVertexAttribArray");
+ glDisableVertexAttribArray(colAttrLocation);
+ checkError("glDisableVertexAttribArray");
+
+ afterExecute();
+ return true;
+ }
+}
+
+class TextureProgram : SolidFillProgram {
+ @property override string vertexSource() {
+ return
+ "attribute " ~ HIGHP ~ " vec4 vertex;\n"
+ "attribute " ~ LOWP ~ " vec4 colAttr;\n"
+ "attribute " ~ MEDIUMP ~ " vec4 texCoord;\n"
+ "varying " ~ LOWP ~ " vec4 col;\n"
+ "varying " ~ MEDIUMP ~ " vec4 texc;\n"
+ "uniform " ~ MEDIUMP ~ " mat4 matrix;\n"
+ "void main(void)\n"
+ "{\n"
+ " gl_Position = matrix * vertex;\n"
+ " col = colAttr;\n"
+ " texc = texCoord;\n"
+ "}\n";
+
+ }
+ @property override string fragmentSource() {
+ return
+ "uniform sampler2D texture;\n"
+ "varying " ~ LOWP ~ " vec4 col;\n"
+ "varying " ~ MEDIUMP ~ " vec4 texc;\n"
+ "void main(void)\n"
+ "{\n"
+ " gl_FragColor = texture2D(texture, texc.st) * col;\n"
+ "}\n";
+ }
+
+ GLint texCoordLocation;
+ override bool initLocations() {
+ bool res = super.initLocations();
+ texCoordLocation = glGetAttribLocation(program, "texCoord");
+ return res && texCoordLocation >= 0;
+ }
+
+ bool execute(float[] vertices, float[] texcoords, float[] colors, uint textureId, bool linear) {
+ if (error)
+ return false;
+ if (!initialized)
+ if (!compile())
+ return false;
+ beforeExecute();
+ glActiveTexture(GL_TEXTURE0);
+ checkError("glActiveTexture GL_TEXTURE0");
+ glBindTexture(GL_TEXTURE_2D, textureId);
+ checkError("glBindTexture");
+ glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, linear ? GL_LINEAR : GL_NEAREST);
+ checkError("drawColorAndTextureRect - glTexParameteri");
+ glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, linear ? GL_LINEAR : GL_NEAREST);
+ checkError("drawColorAndTextureRect - glTexParameteri");
+
+ glEnableVertexAttribArray(vertexLocation);
+ glEnableVertexAttribArray(colAttrLocation);
+ glEnableVertexAttribArray(texCoordLocation);
+
+ glVertexAttribPointer(vertexLocation, 3, GL_FLOAT, GL_FALSE, 0, vertices.ptr);
+ glVertexAttribPointer(colAttrLocation, 4, GL_FLOAT, GL_FALSE, 0, colors.ptr);
+ glVertexAttribPointer(texCoordLocation, 2, GL_FLOAT, GL_FALSE, 0, texcoords.ptr);
+
+ glDrawArrays(GL_TRIANGLES, 0, 6);
+ checkError("glDrawArrays");
+
+ glDisableVertexAttribArray(vertexLocation);
+ glDisableVertexAttribArray(colAttrLocation);
+ glDisableVertexAttribArray(texCoordLocation);
+
+ afterExecute();
+ glBindTexture(GL_TEXTURE_2D, 0);
+ checkError("glBindTexture");
+ return true;
+ }
+}
+
+__gshared TextureProgram _textureProgram;
+__gshared SolidFillProgram _solidFillProgram;
+
+bool initShaders() {
+ if (_textureProgram is null) {
+ _textureProgram = new TextureProgram();
+ if (!_textureProgram.compile())
+ return false;
+ }
+ if (_solidFillProgram is null) {
+ _solidFillProgram = new SolidFillProgram();
+ if (!_solidFillProgram.compile())
+ return false;
+ }
+ Log.d("Shaders compiled successfully");
+ return true;
+}
+
+bool uninitShaders() {
+ Log.d("Uniniting shaders");
+ if (_textureProgram !is null) {
+ destroy(_textureProgram);
+ _textureProgram = null;
+ }
+ if (_solidFillProgram !is null) {
+ destroy(_solidFillProgram);
+ _solidFillProgram = null;
+ }
+ return true;
+}
+
+bool isTexture(uint textureId) {
+ return glIsTexture(textureId) == GL_TRUE;
+}
+
+void setRotation(int x, int y, int rotationAngle) {
+ /*
+ this->rotationAngle = rotationAngle;
+ rotationX = x;
+ rotationY = y;
+ if (!currentFramebufferId) {
+ rotationY = bufferDy - rotationY;
+ }
+
+ QMatrix4x4 matrix2;
+ matrix2.ortho(0, bufferDx, 0, bufferDy, 0.5f, 5.0f);
+ if (rotationAngle) {
+ matrix2.translate(rotationX, rotationY, 0);
+ matrix2.rotate(rotationAngle, 0, 0, 1);
+ matrix2.translate(-rotationX, -rotationY, 0);
+ }
+ matrix2.copyDataTo(m);
+ */
+}
+
+
+}
diff --git a/src/dlangui/platforms/x11/x11app.d b/src/dlangui/platforms/x11/x11app.d
index 13d869ea..41f2f83c 100644
--- a/src/dlangui/platforms/x11/x11app.d
+++ b/src/dlangui/platforms/x11/x11app.d
@@ -20,7 +20,20 @@ version(linux) {
import dlangui.graphics.images;
import dlangui.widgets.styles;
import dlangui.platforms.common.platform;
-
+
+ version (USE_OPENGL) {
+ import dlangui.graphics.glsupport;
+ }
+
+ import derelict.opengl3.gl3;
+ import derelict.opengl3.glx;
+
+ extern (System)
+ xcb_connection_t *XGetXCBConnection(std.c.linux.X11.Xlib.Display *dpy);
+ enum XEventQueueOwner { XlibOwnsEventQueue = 0, XCBOwnsEventQueue };
+ extern (System)
+ void XSetEventQueueOwner(std.c.linux.X11.Xlib.Display *dpy, XEventQueueOwner owner);
+
class XCBWindow : Window {
xcb_window_t _w;
xcb_gcontext_t _g;
@@ -298,9 +311,12 @@ version(linux) {
private __gshared xcb_connection_t * _xcbconnection;
private __gshared xcb_screen_t * _xcbscreen;
private __gshared ubyte _xcbscreendepth;
+ private __gshared bool _enableOpengl;
+ private __gshared std.c.linux.X11.Xlib.Display * _display;
class XCBPlatform : Platform {
this() {
+
}
~this() {
foreach(ref XCBWindow wnd; _windowMap) {
@@ -311,15 +327,62 @@ version(linux) {
disconnect();
}
void disconnect() {
- if (_xcbconnection) {
+ /* Cleanup */
+ if (_display) {
+ Log.d("Closing X display");
+ std.c.linux.X11.Xlib.XCloseDisplay(_display);
+ _display = null;
+ } else if (_xcbconnection) {
+ Log.d("Closing XCB connection");
/* close connection to server */
xcb_disconnect(_xcbconnection);
+ _xcbconnection = null;
}
}
bool connect() {
- Log.d("Opening connection");
- /* open connection with the server */
- _xcbconnection = xcb_connect(null,null);
+
+ try {
+ DerelictGL3.load();
+ _enableOpengl = true;
+ } catch (Exception e) {
+ Log.e("Cannot load opengl library", e);
+ }
+ // X
+ import std.c.linux.X11.Xlib;
+ int default_screen;
+
+ if (_enableOpengl) {
+ Log.d("Opening display via XLib");
+ /* Open Xlib Display */
+ _display = XOpenDisplay(null);
+ if (!_display)
+ {
+ Log.e("Failed to open display using Xlib");
+ _enableOpengl = false;
+ } else {
+ // display is opened
+ default_screen = DefaultScreen(_display);
+ Log.d("Opened display =");
+ /* Get the XCB connection from the display */
+ _xcbconnection = XGetXCBConnection(_display);
+ if (!_xcbconnection)
+ {
+ XCloseDisplay(_display);
+ _display = null;
+ Log.e("Failed to get XCB connection from Xlib display");
+ _enableOpengl = false;
+ } else {
+ /* Acquire event queue ownership */
+ XSetEventQueueOwner(_display, XEventQueueOwner.XCBOwnsEventQueue);
+ }
+ }
+ }
+
+ if (_xcbconnection is null) {
+ Log.d("Opening XCB connection");
+ /* open connection with the server */
+ _xcbconnection = xcb_connect(null,null);
+ }
if (xcb_connection_has_error(_xcbconnection)) {
Log.e("Cannot open display");
_xcbconnection = null;
@@ -328,9 +391,21 @@ version(linux) {
//XSetEventQueueOwner(display, XCBOwnsEventQueue);
Log.d("Getting first screen");
/* get the first screen */
- _xcbscreen = xcb_setup_roots_iterator( xcb_get_setup(_xcbconnection) ).data;
- _xcbscreendepth = xcb_aux_get_depth(_xcbconnection, _xcbscreen);
-
+
+ if (_enableOpengl) {
+ /* Find XCB screen */
+ //xcb_screen_t *screen = null;
+ xcb_screen_iterator_t screen_iter =
+ xcb_setup_roots_iterator(xcb_get_setup(_xcbconnection));
+ for(int screen_num = default_screen;
+ screen_iter.rem && screen_num > 0;
+ --screen_num, xcb_screen_next(&screen_iter)) {
+ }
+ _xcbscreen = screen_iter.data;
+ } else {
+ _xcbscreen = xcb_setup_roots_iterator( xcb_get_setup(_xcbconnection) ).data;
+ }
+ _xcbscreendepth = xcb_aux_get_depth(_xcbconnection, _xcbscreen);
return true;
}
XCBWindow getWindow(xcb_window_t w) {