mirror of https://github.com/adamdruppe/arsd.git
more efficient opengltexture option
This commit is contained in:
parent
0f77d8f380
commit
3a433690e2
21
cgi.d
21
cgi.d
|
@ -1,6 +1,5 @@
|
|||
// FIXME: if an exception is thrown, we shouldn't necessarily cache...
|
||||
// FIXME: there's some annoying duplication of code in the various versioned mains
|
||||
// FIXME: new ConnectionThread is done a lot, no pooling implemented
|
||||
|
||||
// Note: spawn-fcgi can help with fastcgi on nginx
|
||||
|
||||
|
@ -9,6 +8,26 @@
|
|||
|
||||
// future direction: websocket as a separate process that you can sendfile to for an async passoff of those long-lived connections
|
||||
|
||||
/*
|
||||
Session manager process: it spawns a new process, passing a
|
||||
command line argument, to just be a little key/value store
|
||||
of some serializable struct. On Windows, it CreateProcess.
|
||||
On Linux, it can just fork or maybe fork/exec. The session
|
||||
key is in a cookie.
|
||||
|
||||
Server-side event process: spawns an async manager. You can
|
||||
push stuff out to channel ids and the clients listen to it.
|
||||
|
||||
websocket process: spawns an async handler. They can talk to
|
||||
each other or get info from a cgi request.
|
||||
|
||||
Tempting to put web.d 2.0 in here. It would:
|
||||
* map urls and form generation to functions
|
||||
* have data presentation magic
|
||||
* do the skeleton stuff like 1.0
|
||||
* auto-cache generated stuff in files (at least if pure?)
|
||||
*/
|
||||
|
||||
/++
|
||||
Provides a uniform server-side API for CGI, FastCGI, SCGI, and HTTP web applications.
|
||||
|
||||
|
|
4
dom.d
4
dom.d
|
@ -4819,7 +4819,7 @@ class Table : Element {
|
|||
tagName = "table";
|
||||
}
|
||||
|
||||
///.
|
||||
/// Creates an element with the given type and content.
|
||||
Element th(T)(T t) {
|
||||
Element e;
|
||||
if(parentDocument !is null)
|
||||
|
@ -4833,7 +4833,7 @@ class Table : Element {
|
|||
return e;
|
||||
}
|
||||
|
||||
///.
|
||||
/// ditto
|
||||
Element td(T)(T t) {
|
||||
Element e;
|
||||
if(parentDocument !is null)
|
||||
|
|
|
@ -226,6 +226,23 @@ final class OpenGlTexture {
|
|||
|
||||
/// Make a texture from an image.
|
||||
this(TrueColorImage from) {
|
||||
bindFrom(from);
|
||||
}
|
||||
|
||||
/// Generates from text. Requires ttf.d
|
||||
/// pass a pointer to the TtfFont as the first arg (it is template cuz of lazy importing, not because it actually works with different types)
|
||||
this(T, FONT)(FONT* font, int size, in T[] text) if(is(T == char)) {
|
||||
bindFrom(font, size, text);
|
||||
}
|
||||
|
||||
/// Creates an empty texture class for you to use with [bindFrom] later
|
||||
/// Using it when not bound is undefined behavior.
|
||||
this() {}
|
||||
|
||||
|
||||
|
||||
/// After you delete it with dispose, you may rebind it to something else with this.
|
||||
void bindFrom(TrueColorImage from) {
|
||||
assert(from.width > 0 && from.height > 0);
|
||||
|
||||
import core.stdc.stdlib;
|
||||
|
@ -295,9 +312,8 @@ final class OpenGlTexture {
|
|||
free(cast(void*) data);
|
||||
}
|
||||
|
||||
/// Generates from text. Requires ttf.d
|
||||
/// pass a pointer to the TtfFont as the first arg (it is template cuz of lazy importing, not because it actually works with different types)
|
||||
this(T, FONT)(FONT* font, int size, in T[] text) if(is(T == char)) {
|
||||
/// ditto
|
||||
void bindFrom(T, FONT)(FONT* font, int size, in T[] text) if(is(T == char)) {
|
||||
assert(font !is null);
|
||||
int width, height;
|
||||
auto data = font.renderString(text, size, width, height);
|
||||
|
@ -313,14 +329,26 @@ final class OpenGlTexture {
|
|||
}
|
||||
assert(data.length == 0);
|
||||
|
||||
this(image);
|
||||
bindFrom(image);
|
||||
}
|
||||
|
||||
/// Deletes the texture. Using it after calling this is undefined behavior
|
||||
void dispose() {
|
||||
glDeleteTextures(1, &_tex);
|
||||
_tex = 0;
|
||||
}
|
||||
|
||||
~this() {
|
||||
glDeleteTextures(1, &_tex);
|
||||
if(_tex > 0)
|
||||
dispose();
|
||||
}
|
||||
}
|
||||
|
||||
///
|
||||
void clearOpenGlScreen(SimpleWindow window) {
|
||||
glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT | GL_ACCUM_BUFFER_BIT);
|
||||
}
|
||||
|
||||
|
||||
// Some math helpers
|
||||
|
||||
|
|
26
web.d
26
web.d
|
@ -776,7 +776,7 @@ struct ReflectionInfo {
|
|||
|
||||
// these might go away.
|
||||
|
||||
string defaultOutputFormat = "html";
|
||||
string defaultOutputFormat = "default";
|
||||
int versionOfOutputFormat = 2; // change this in your constructor if you still need the (deprecated) old behavior
|
||||
// bool apiMode = false; // no longer used - if format is json, apiMode behavior is assumed. if format is html, it is not.
|
||||
// FIXME: what if you want the data formatted server side, but still in a json envelope?
|
||||
|
@ -1895,6 +1895,7 @@ Form createAutomaticForm(Document document, string action, in Parameter[] parame
|
|||
|
||||
auto fmt = Element.make("select");
|
||||
fmt.name = "format";
|
||||
fmt.addChild("option", "Automatic").setAttribute("value", "default");
|
||||
fmt.addChild("option", "html").setAttribute("value", "html");
|
||||
fmt.addChild("option", "table").setAttribute("value", "table");
|
||||
fmt.addChild("option", "json").setAttribute("value", "json");
|
||||
|
@ -2755,6 +2756,15 @@ WrapperFunction generateWrapper(alias ObjectType, string funName, alias f, R)(Re
|
|||
|
||||
// FIXME: it's awkward to call manually due to the JSONValue ref thing. Returning a string would be mega nice.
|
||||
string formatAs(T, R)(T ret, string format, R api = null, JSONValue* returnValue = null, string formatJsonToStringAs = null) if(is(R : ApiProvider)) {
|
||||
|
||||
if(format == "default") {
|
||||
static if(is(typeof(ret) : K[N][V], size_t N, K, V)) {
|
||||
format = "table";
|
||||
} else {
|
||||
format = "html";
|
||||
}
|
||||
}
|
||||
|
||||
string retstr;
|
||||
if(api !is null) {
|
||||
static if(__traits(compiles, api._customFormat(ret, format))) {
|
||||
|
@ -2817,8 +2827,18 @@ string formatAs(T, R)(T ret, string format, R api = null, JSONValue* returnValue
|
|||
goto badType;
|
||||
gotATable(table);
|
||||
break;
|
||||
}
|
||||
else
|
||||
} else static if(is(typeof(ret) : K[N][V], size_t N, K, V)) {
|
||||
auto table = cast(Table) Element.make("table");
|
||||
table.addClass("data-display");
|
||||
foreach(k, v; ret) {
|
||||
auto row = table.addChild("tr");
|
||||
foreach(cell; v)
|
||||
table.addChild("td", to!string(cell));
|
||||
}
|
||||
gotATable(table);
|
||||
break;
|
||||
|
||||
} else
|
||||
goto badType;
|
||||
default:
|
||||
badType:
|
||||
|
|
Loading…
Reference in New Issue