Permalink
Browse files

Disallow the choice whether openGL should be used or not: OpenGL is a…

…lways used.

Texture, ShaderProgram: lowercase ID -> id
  • Loading branch information...
Dgame committed May 30, 2015
1 parent 7e5c27e commit f1a8d1c460e1a00d044bed9dc1ab4a143211c952
@@ -104,7 +104,7 @@ public:
*/
@nogc
@property
uint ID() const pure nothrow {
uint id() const pure nothrow {
return _shader;
}
@@ -98,7 +98,7 @@ public:
// Attach the shaders
foreach (ref const Shader shader; shaders) {
glAttachShader(_program, shader.ID);
glAttachShader(_program, shader.id);
}
//Link our program
@@ -124,7 +124,7 @@ public:
// Always detach shaders after a successful link.
foreach (ref const Shader shader; shaders) {
glDetachShader(_program, shader.ID);
glDetachShader(_program, shader.id);
}
return true;
@@ -134,15 +134,15 @@ public:
* Bind and use the current program
*/
@nogc
void use() const nothrow {
void bind() const nothrow {
glUseProgram(_program);
}
/**
* Unbind the current program. It is no longer used.
*/
@nogc
void disuse() const nothrow {
void unbind() const nothrow {
glUseProgram(0);
}
@@ -157,7 +157,7 @@ public:
return false;
}
this.use();
this.bind();
switch (values.length) {
case 1:
@@ -215,7 +215,7 @@ public:
return false;
}
this.use();
this.bind();
glUniformMatrix4fv(loc, 1, GL_FALSE, mat.getValues().ptr);
@@ -129,7 +129,7 @@ public:
*/
@property
@nogc
uint ID() const pure nothrow {
uint id() const pure nothrow {
return _texId;
}
@@ -126,7 +126,7 @@ void _initSDL() {
}
@nogc
void _initGLAttr(ref GLSettings gl) {
void _initGLAttr(GLSettings gl) {
version (OSX) {
if (gl.majorVersion == 0) {
gl.majorVersion = 2;
@@ -81,22 +81,20 @@ struct Window {
* The specific window styles
*/
enum Style {
Default = Shown, /// Default is Shown
Fullscreen = SDL_WINDOW_FULLSCREEN, /// Window is fullscreened
Desktop = SDL_WINDOW_FULLSCREEN_DESKTOP, /// Window has Desktop Fullscreen
OpenGL = SDL_WINDOW_OPENGL, /// OpenGL support
Shown = SDL_WINDOW_SHOWN, /// Show the Window immediately
Borderless = SDL_WINDOW_BORDERLESS, /// Hide the Window immediately
Hidden = SDL_WINDOW_HIDDEN, /// Hide the Window immediately
Borderless = SDL_WINDOW_BORDERLESS, /// The Window has no border
Resizeable = SDL_WINDOW_RESIZABLE, /// Window is resizeable
Maximized = SDL_WINDOW_MAXIMIZED, /// Maximize the Window immediately
Minimized = SDL_WINDOW_MINIMIZED, /// Minimize the Window immediately
InputGrabbed = SDL_WINDOW_INPUT_GRABBED, /// Grab the input inside the window
InputFocus = SDL_WINDOW_INPUT_FOCUS, /// The Window has input (keyboard) focus
MouseFocus = SDL_WINDOW_MOUSE_FOCUS, /// The Window has mouse focus
MouseCapture = SDL_WINDOW_MOUSE_CAPTURE, /// window has mouse captured (unrelated to InputGrabbed)
HighDPI = SDL_WINDOW_ALLOW_HIGHDPI, /// Window should be created in high-DPI mode if supported
Foreign = SDL_WINDOW_FOREIGN, /// The window was created by some other framework.
Default = Shown | OpenGL | HighDPI /// Default mode is Shown | OpenGL | HighDPI
AllowHighDPI = SDL_WINDOW_ALLOW_HIGHDPI, /// Window should be created in high-DPI mode if supported
}
private:
@@ -142,35 +140,31 @@ public:
if (_count == 0)
_initSDL();
if (style & Style.OpenGL)
_initGLAttr(gl);
_initGLAttr(gl);
_window = SDL_CreateWindow(
toStringz(title),
view.x, view.y,
view.width, view.height,
style
style | SDL_WINDOW_OPENGL
);
assert(_window, "SDL_Window could not be created.");
if (style & Style.OpenGL) {
_glContext = SDL_GL_CreateContext(_window);
assert(_glContext, "SDL_GLContext could not be created.");
assert(SDL_GL_MakeCurrent(_window, _glContext) == 0);
if (_count == 0)
_initGL();
_glContext = SDL_GL_CreateContext(_window);
assert(_glContext, "SDL_GLContext could not be created.");
assert(SDL_GL_MakeCurrent(_window, _glContext) == 0);
_initGL();
const Rect rect = Rect(0, 0, view.width, view.height);
const Rect rect = Rect(0, 0, view.width, view.height);
this.projection.ortho(rect);
this.loadProjection();
this.projection.ortho(rect);
this.loadProjection();
glViewport(rect.x, rect.y, rect.width, rect.height);
glViewport(rect.x, rect.y, rect.width, rect.height);
this.setClearColor(Color4b.White);
this.setVerticalSync(VerticalSync.Disable);
}
this.setClearColor(Color4b.White);
this.setVerticalSync(VerticalSync.Disable);
_count++;
}
@@ -259,38 +253,34 @@ public:
*/
@nogc
Surface capture(Texture.Format fmt = Texture.Format.BGRA) nothrow {
if (this.getStyle() & Style.OpenGL) {
const Size size = this.getSize();
Surface my_capture = Surface(size.width, size.height, 32, Masks.Zero);
const Size size = this.getSize();
Surface my_capture = Surface(size.width, size.height, 32, Masks.Zero);
glReadBuffer(GL_FRONT);
glReadPixels(0, 0, size.width, size.height, fmt, GL_UNSIGNED_BYTE, my_capture.pixels);
immutable uint lineWidth = size.width * 4;
immutable uint hlw = size.height * lineWidth;
void[] tmpLine = make!(void[])(lineWidth);
scope(exit) unmake(tmpLine);
glReadBuffer(GL_FRONT);
glReadPixels(0, 0, size.width, size.height, fmt, GL_UNSIGNED_BYTE, my_capture.pixels);
// Flip it
for (uint i = 0; i < size.height / 2; ++i) {
immutable uint tmpIdx1 = i * lineWidth;
immutable uint tmpIdx2 = (i + 1) * lineWidth;
immutable uint lineWidth = size.width * 4;
immutable uint hlw = size.height * lineWidth;
void[] tmpLine = make!(void[])(lineWidth);
scope(exit) unmake(tmpLine);
// Flip it
for (uint i = 0; i < size.height / 2; ++i) {
immutable uint tmpIdx1 = i * lineWidth;
immutable uint tmpIdx2 = (i + 1) * lineWidth;
immutable uint switchIdx1 = hlw - tmpIdx2;
immutable uint switchIdx2 = hlw - tmpIdx1;
tmpLine[0 .. lineWidth] = my_capture.pixels[tmpIdx1 .. tmpIdx2];
void[] switchLine = my_capture.pixels[switchIdx1 .. switchIdx2];
my_capture.pixels[tmpIdx1 .. tmpIdx2] = switchLine[];
my_capture.pixels[switchIdx1 .. switchIdx2] = tmpLine[0 .. lineWidth];
}
immutable uint switchIdx1 = hlw - tmpIdx2;
immutable uint switchIdx2 = hlw - tmpIdx1;
tmpLine[0 .. lineWidth] = my_capture.pixels[tmpIdx1 .. tmpIdx2];
void[] switchLine = my_capture.pixels[switchIdx1 .. switchIdx2];
return my_capture;
my_capture.pixels[tmpIdx1 .. tmpIdx2] = switchLine[];
my_capture.pixels[switchIdx1 .. switchIdx2] = tmpLine[0 .. lineWidth];
}
return Surface(SDL_GetWindowSurface(_window));
return my_capture;
}
/**
@@ -547,23 +537,18 @@ public:
*/
@nogc
void draw(Drawable d) const nothrow {
assert(d, "Drawable is null");
d.draw(this);
if (d)
d.draw(this);
}
/**
* Make all changes visible on screen
*/
@nogc
void display() nothrow {
immutable uint style = this.getStyle();
if (style & Style.OpenGL) {
if (_count > 1)
SDL_GL_MakeCurrent(_window, _glContext);
SDL_GL_SwapWindow(_window);
} else
SDL_UpdateWindowSurface(_window);
if (_count > 1)
SDL_GL_MakeCurrent(_window, _glContext);
SDL_GL_SwapWindow(_window);
}
/**
@@ -36,9 +36,9 @@ <h1>Dgame.Graphic.Shader</h1>
<dd>CTor<br><br>
</dd>
<dt><big><a name="Shader.ID"></a>const pure nothrow @nogc @property uint <u>ID</u>();
<dt><big><a name="Shader.id"></a>const pure nothrow @nogc @property uint <u>id</u>();
</big></dt>
<dd>Returns the internal Shader <u>ID</u><br><br>
<dd>Returns the internal Shader ID<br><br>
</dd>
<dt><big><a name="Shader.loadFromFile"></a>const nothrow @nogc void <u>loadFromFile</u>(string <i>filename</i>);
@@ -35,12 +35,12 @@ <h1>Dgame.Graphic.ShaderProgram</h1>
The <i>shaders</i> must be already compiled.<br><br>
</dd>
<dt><big><a name="ShaderProgram.use"></a>const nothrow @nogc void <u>use</u>();
<dt><big><a name="ShaderProgram.bind"></a>const nothrow @nogc void <u>bind</u>();
</big></dt>
<dd>Bind and <u>use</u> the current program<br><br>
<dd>Bind and use the current program<br><br>
</dd>
<dt><big><a name="ShaderProgram.disuse"></a>const nothrow @nogc void <u>disuse</u>();
<dt><big><a name="ShaderProgram.unbind"></a>const nothrow @nogc void <u>unbind</u>();
</big></dt>
<dd>Unbind the current program. It is no longer used.<br><br>
@@ -82,7 +82,7 @@ <h1>Dgame.Graphic.Texture</h1>
<dd>Returns the currently bound texture id.<br><br>
</dd>
<dt><big><a name="Texture.ID"></a>const pure nothrow @nogc @property uint <u>ID</u>();
<dt><big><a name="Texture.id"></a>const pure nothrow @nogc @property uint <u>id</u>();
</big></dt>
<dd>Returns the Texture Id.<br><br>
@@ -39,25 +39,29 @@ <h1>Dgame.Window.Window</h1>
</big></dt>
<dd>The specific window styles<br><br>
<dl><dt><big><a name="Window.Style.Fullscreen"></a><u>Fullscreen</u></big></dt>
<dl><dt><big><a name="Window.Style.Default"></a><u>Default</u></big></dt>
<dd><u>Default</u> is Shown<br><br>
</dd>
<dt><big><a name="Window.Style.Fullscreen"></a><u>Fullscreen</u></big></dt>
<dd>Window is fullscreened<br><br>
</dd>
<dt><big><a name="Window.Style.Desktop"></a><u>Desktop</u></big></dt>
<dd>Window has <u>Desktop</u> Fullscreen<br><br>
</dd>
<dt><big><a name="Window.Style.OpenGL"></a><u>OpenGL</u></big></dt>
<dd><u>OpenGL</u> support<br><br>
</dd>
<dt><big><a name="Window.Style.Shown"></a><u>Shown</u></big></dt>
<dd>Show the Window immediately<br><br>
</dd>
<dt><big><a name="Window.Style.Borderless"></a><u>Borderless</u></big></dt>
<dt><big><a name="Window.Style.Hidden"></a><u>Hidden</u></big></dt>
<dd>Hide the Window immediately<br><br>
</dd>
<dt><big><a name="Window.Style.Borderless"></a><u>Borderless</u></big></dt>
<dd>The Window has no border<br><br>
</dd>
<dt><big><a name="Window.Style.Resizeable"></a><u>Resizeable</u></big></dt>
<dd>Window is resizeable<br><br>
@@ -87,17 +91,9 @@ <h1>Dgame.Window.Window</h1>
<dd>window has mouse captured (unrelated to InputGrabbed)<br><br>
</dd>
<dt><big><a name="Window.Style.HighDPI"></a><u>HighDPI</u></big></dt>
<dt><big><a name="Window.Style.AllowHighDPI"></a><u>AllowHighDPI</u></big></dt>
<dd>Window should be created in high-DPI mode if supported<br><br>
</dd>
<dt><big><a name="Window.Style.Foreign"></a><u>Foreign</u></big></dt>
<dd>The window was created by some other framework.<br><br>
</dd>
<dt><big><a name="Window.Style.Default"></a><u>Default</u></big></dt>
<dd><u>Default</u> mode is Shown | OpenGL | HighDPI<br><br>
</dd>
</dl>
</dd>
View
@@ -16,10 +16,11 @@ debug {
pragma(msg, Vector2i.sizeof);
pragma(msg, Vector2f.sizeof);
pragma(msg, Vertex.sizeof);
pragma(msg, GLSettings.sizeof);
}
void main() {
Window wnd = Window(480, 640, "Dgame App - Test", Window.Style.Default, GLSettings(0, 0, 0));
Window wnd = Window(480, 640, "Dgame App - Test", Window.Style.Default, GLSettings(0, 0, 2));
//wnd.setVerticalSync(Window.VerticalSync.Enable);
/*
immutable int display_count = DisplayMode.getNumOfDisplays();
@@ -114,7 +115,7 @@ void main() {
Texture wiki_tex = Texture(wiki_srfc);
wiki_tex.setSmooth(true);
writeln(wiki_tex.ID, ':', wiki_tex.width, ':', wiki_tex.height, ':', wiki_tex.format);
writeln(wiki_tex.id, ':', wiki_tex.width, ':', wiki_tex.height, ':', wiki_tex.format);
Joystick controller;
// Check for joysticks

0 comments on commit f1a8d1c

Please sign in to comment.