School is soooooo boooorrrrriiiiiinnnngggf

This commit is contained in:
DepressedTWM 2026-05-18 09:50:04 +04:00
parent e1ced21b34
commit d5bb0f501a
16 changed files with 145 additions and 302 deletions

View file

@ -219,8 +219,6 @@ void graphicsBindingInit(){
INIT_GRA_PROP_BIND( Brightness, "brightness" ); INIT_GRA_PROP_BIND( Brightness, "brightness" );
_rb_define_module_function(module, "play_movie", graphicsPlayMovie);
INIT_GRA_PROP_BIND( Fullscreen, "fullscreen" ); INIT_GRA_PROP_BIND( Fullscreen, "fullscreen" );
INIT_GRA_PROP_BIND( ShowCursor, "show_cursor" ); INIT_GRA_PROP_BIND( ShowCursor, "show_cursor" );
INIT_GRA_PROP_BIND( Smooth, "smooth" ); INIT_GRA_PROP_BIND( Smooth, "smooth" );

View file

@ -29,14 +29,12 @@
#include <SDL3/SDL_pixels.h> #include <SDL3/SDL_pixels.h>
Color::Color(double red, double green, double blue, double alpha) Color::Color(double red, double green, double blue, double alpha)
: red(red), green(green), blue(blue), alpha(alpha) : red(red), green(green), blue(blue), alpha(alpha){
{
updateInternal(); updateInternal();
} }
Color::Color(const Vec4 &norm) Color::Color(const Vec4 &norm)
: norm(norm) : norm(norm){
{
updateExternal(); updateExternal();
} }
@ -45,16 +43,14 @@ Color::Color(const Color &o)
norm(o.norm) norm(o.norm)
{} {}
bool Color::operator==(const Color &o) const bool Color::operator==(const Color &o) const{
{
return red == o.red && return red == o.red &&
green == o.green && green == o.green &&
blue == o.blue && blue == o.blue &&
alpha == o.alpha; alpha == o.alpha;
} }
const Color &Color::operator=(const Color &o) const Color &Color::operator=(const Color &o){
{
red = o.red; red = o.red;
green = o.green; green = o.green;
blue = o.blue; blue = o.blue;
@ -64,8 +60,7 @@ const Color &Color::operator=(const Color &o)
return o; return o;
} }
void Color::set(double red, double green, double blue, double alpha) void Color::set(double red, double green, double blue, double alpha){
{
this->red = red; this->red = red;
this->green = green; this->green = green;
this->blue = blue; this->blue = blue;
@ -74,46 +69,39 @@ void Color::set(double red, double green, double blue, double alpha)
updateInternal(); updateInternal();
} }
void Color::setRed(double value) void Color::setRed(double value){
{
red = value; red = value;
norm.x = clamp<double>(value, 0, 255) / 255; norm.x = clamp<double>(value, 0, 255) / 255;
} }
void Color::setGreen(double value) void Color::setGreen(double value){
{
green = value; green = value;
norm.y = clamp<double>(value, 0, 255) / 255; norm.y = clamp<double>(value, 0, 255) / 255;
} }
void Color::setBlue(double value) void Color::setBlue(double value){
{
blue = value; blue = value;
norm.z = clamp<double>(value, 0, 255) / 255; norm.z = clamp<double>(value, 0, 255) / 255;
} }
void Color::setAlpha(double value) void Color::setAlpha(double value){
{
alpha = value; alpha = value;
norm.w = clamp<double>(value, 0, 255) / 255; norm.w = clamp<double>(value, 0, 255) / 255;
} }
/* Serializable */ /* Serializable */
int Color::serialSize() const int Color::serialSize() const{
{
return 4 * 8; return 4 * 8;
} }
void Color::serialize(char *buffer) const void Color::serialize(char *buffer) const{
{
writeDouble(&buffer, red); writeDouble(&buffer, red);
writeDouble(&buffer, green); writeDouble(&buffer, green);
writeDouble(&buffer, blue); writeDouble(&buffer, blue);
writeDouble(&buffer, alpha); writeDouble(&buffer, alpha);
} }
Color *Color::deserialize(const char *data, int len) Color *Color::deserialize(const char *data, int len){
{
if (len != 32) if (len != 32)
throw Exception(Exception::ArgumentError, "Color: Serialized data invalid"); throw Exception(Exception::ArgumentError, "Color: Serialized data invalid");
@ -128,24 +116,21 @@ Color *Color::deserialize(const char *data, int len)
return c; return c;
} }
void Color::updateInternal() void Color::updateInternal(){
{
norm.x = red / 255; norm.x = red / 255;
norm.y = green / 255; norm.y = green / 255;
norm.z = blue / 255; norm.z = blue / 255;
norm.w = alpha / 255; norm.w = alpha / 255;
} }
void Color::updateExternal() void Color::updateExternal(){
{
red = norm.x * 255; red = norm.x * 255;
green = norm.y * 255; green = norm.y * 255;
blue = norm.z * 255; blue = norm.z * 255;
alpha = norm.w * 255; alpha = norm.w * 255;
} }
SDL_Color Color::toSDLColor() const SDL_Color Color::toSDLColor() const{
{
SDL_Color c; SDL_Color c;
c.r = clamp<double>(red, 0, 255); c.r = clamp<double>(red, 0, 255);
c.g = clamp<double>(green, 0, 255); c.g = clamp<double>(green, 0, 255);
@ -157,8 +142,7 @@ SDL_Color Color::toSDLColor() const
Tone::Tone(double red, double green, double blue, double gray) Tone::Tone(double red, double green, double blue, double gray)
: red(red), green(green), blue(blue), gray(gray) : red(red), green(green), blue(blue), gray(gray){
{
updateInternal(); updateInternal();
} }
@ -167,16 +151,14 @@ Tone::Tone(const Tone &o)
norm(o.norm) norm(o.norm)
{} {}
bool Tone::operator==(const Tone &o) const bool Tone::operator==(const Tone &o) const{
{
return red == o.red && return red == o.red &&
green == o.green && green == o.green &&
blue == o.blue && blue == o.blue &&
gray == o.gray; gray == o.gray;
} }
void Tone::set(double red, double green, double blue, double gray) void Tone::set(double red, double green, double blue, double gray){
{
this->red = red; this->red = red;
this->green = green; this->green = green;
this->blue = blue; this->blue = blue;
@ -186,8 +168,7 @@ void Tone::set(double red, double green, double blue, double gray)
valueChanged(); valueChanged();
} }
const Tone& Tone::operator=(const Tone &o) const Tone& Tone::operator=(const Tone &o){
{
red = o.red; red = o.red;
green = o.green; green = o.green;
blue = o.blue; blue = o.blue;
@ -199,32 +180,28 @@ const Tone& Tone::operator=(const Tone &o)
return o; return o;
} }
void Tone::setRed(double value) void Tone::setRed(double value){
{
red = value; red = value;
norm.x = (float) clamp<double>(value, -255, 255) / 255; norm.x = (float) clamp<double>(value, -255, 255) / 255;
valueChanged(); valueChanged();
} }
void Tone::setGreen(double value) void Tone::setGreen(double value){
{
green = value; green = value;
norm.y = (float) clamp<double>(value, -255, 255) / 255; norm.y = (float) clamp<double>(value, -255, 255) / 255;
valueChanged(); valueChanged();
} }
void Tone::setBlue(double value) void Tone::setBlue(double value){
{
blue = value; blue = value;
norm.z = (float) clamp<double>(value, -255, 255) / 255; norm.z = (float) clamp<double>(value, -255, 255) / 255;
valueChanged(); valueChanged();
} }
void Tone::setGray(double value) void Tone::setGray(double value){
{
gray = value; gray = value;
norm.w = (float) clamp<double>(value, 0, 255) / 255; norm.w = (float) clamp<double>(value, 0, 255) / 255;
@ -232,21 +209,18 @@ void Tone::setGray(double value)
} }
/* Serializable */ /* Serializable */
int Tone::serialSize() const int Tone::serialSize() const{
{
return 4 * 8; return 4 * 8;
} }
void Tone::serialize(char *buffer) const void Tone::serialize(char *buffer) const{
{
writeDouble(&buffer, red); writeDouble(&buffer, red);
writeDouble(&buffer, green); writeDouble(&buffer, green);
writeDouble(&buffer, blue); writeDouble(&buffer, blue);
writeDouble(&buffer, gray); writeDouble(&buffer, gray);
} }
Tone *Tone::deserialize(const char *data, int len) Tone *Tone::deserialize(const char *data, int len){
{
if (len != 32) if (len != 32)
throw Exception(Exception::ArgumentError, "Tone: Serialized data invalid"); throw Exception(Exception::ArgumentError, "Tone: Serialized data invalid");
@ -261,8 +235,7 @@ Tone *Tone::deserialize(const char *data, int len)
return t; return t;
} }
void Tone::updateInternal() void Tone::updateInternal(){
{
norm.x = (float) clamp<double>(red, -255, 255) / 255; norm.x = (float) clamp<double>(red, -255, 255) / 255;
norm.y = (float) clamp<double>(green, -255, 255) / 255; norm.y = (float) clamp<double>(green, -255, 255) / 255;
norm.z = (float) clamp<double>(blue, -255, 255) / 255; norm.z = (float) clamp<double>(blue, -255, 255) / 255;
@ -283,29 +256,25 @@ Rect::Rect(const IntRect &r)
: x(r.x), y(r.y), width(r.w), height(r.h) : x(r.x), y(r.y), width(r.w), height(r.h)
{} {}
bool Rect::operator==(const Rect &o) const bool Rect::operator==(const Rect &o) const{
{
return x == o.x && return x == o.x &&
y == o.y && y == o.y &&
width == o.width && width == o.width &&
height == o.height; height == o.height;
} }
void Rect::operator=(const IntRect &rect) void Rect::operator=(const IntRect &rect){
{
x = rect.x; x = rect.x;
y = rect.y; y = rect.y;
width = rect.w; width = rect.w;
height = rect.h; height = rect.h;
} }
void Rect::set(int x, int y, int w, int h) void Rect::set(int x, int y, int w, int h){
{
if (this->x == x && if (this->x == x &&
this->y == y && this->y == y &&
width == w && width == w &&
height == h) height == h){
{
return; return;
} }
@ -316,8 +285,7 @@ void Rect::set(int x, int y, int w, int h)
valueChanged(); valueChanged();
} }
const Rect &Rect::operator=(const Rect &o) const Rect &Rect::operator=(const Rect &o){
{
x = o.x; x = o.x;
y = o.y; y = o.y;
width = o.width; width = o.width;
@ -328,8 +296,7 @@ const Rect &Rect::operator=(const Rect &o)
return o; return o;
} }
void Rect::empty() void Rect::empty(){
{
if (!(x || y || width || height)) if (!(x || y || width || height))
return; return;
@ -337,13 +304,11 @@ void Rect::empty()
valueChanged(); valueChanged();
} }
bool Rect::isEmpty() const bool Rect::isEmpty() const{
{
return !(width && height); return !(width && height);
} }
void Rect::setX(int value) void Rect::setX(int value){
{
if (x == value) if (x == value)
return; return;
@ -351,8 +316,7 @@ void Rect::setX(int value)
valueChanged(); valueChanged();
} }
void Rect::setY(int value) void Rect::setY(int value){
{
if (y == value) if (y == value)
return; return;
@ -360,8 +324,7 @@ void Rect::setY(int value)
valueChanged(); valueChanged();
} }
void Rect::setWidth(int value) void Rect::setWidth(int value){
{
if (width == value) if (width == value)
return; return;
@ -369,8 +332,7 @@ void Rect::setWidth(int value)
valueChanged(); valueChanged();
} }
void Rect::setHeight(int value) void Rect::setHeight(int value){
{
if (height == value) if (height == value)
return; return;
@ -378,21 +340,18 @@ void Rect::setHeight(int value)
valueChanged(); valueChanged();
} }
int Rect::serialSize() const int Rect::serialSize() const{
{
return 4 * 4; return 4 * 4;
} }
void Rect::serialize(char *buffer) const void Rect::serialize(char *buffer) const{
{
writeInt32(&buffer, x); writeInt32(&buffer, x);
writeInt32(&buffer, y); writeInt32(&buffer, y);
writeInt32(&buffer, width); writeInt32(&buffer, width);
writeInt32(&buffer, height); writeInt32(&buffer, height);
} }
Rect *Rect::deserialize(const char *data, int len) Rect *Rect::deserialize(const char *data, int len){
{
if (len != 16) if (len != 16)
throw Exception(Exception::ArgumentError, "Rect: Serialized data invalid"); throw Exception(Exception::ArgumentError, "Rect: Serialized data invalid");

View file

@ -44,8 +44,7 @@
#include <iconv.h> #include <iconv.h>
#endif #endif
struct SDLRWIoContext struct SDLRWIoContext{
{
SDL_IOStream *ops; SDL_IOStream *ops;
std::string filename; std::string filename;
@ -58,8 +57,7 @@ struct SDLRWIoContext
"Failed to open file: %s", SDL_GetError()); "Failed to open file: %s", SDL_GetError());
} }
~SDLRWIoContext() ~SDLRWIoContext(){
{
SDL_CloseIO(ops); SDL_CloseIO(ops);
} }
}; };
@ -233,10 +231,7 @@ static int SDL_RWopsCloseFree(void *userdata)
* or the full string if srcN == -1. Never writes more * or the full string if srcN == -1. Never writes more
* than dstMax, and guarantees dst to be null terminated. * than dstMax, and guarantees dst to be null terminated.
* Returns copied bytes (minus terminating null) */ * Returns copied bytes (minus terminating null) */
static size_t static size_t strcpySafe(char *dst, const char *src, size_t dstMax, int srcN){
strcpySafe(char *dst, const char *src,
size_t dstMax, int srcN)
{
if (srcN < 0) if (srcN < 0)
srcN = strlen(src); srcN = strlen(src);
@ -265,11 +260,7 @@ static const char *findExt(const char *filename){
return 0; return 0;
} }
static void static void initReadOps(PHYSFS_File *handle, SDL_IOStream* &ops){
initReadOps(PHYSFS_File *handle,
SDL_IOStream* &ops)
//bool freeOnClose)
{
SDL_IOStreamInterface iface; SDL_IOStreamInterface iface;
SDL_INIT_INTERFACE(&iface); SDL_INIT_INTERFACE(&iface);
@ -309,8 +300,7 @@ struct FileSystemPrivate{
bool havePathCache; bool havePathCache;
}; };
FileSystem::FileSystem(bool allowSymlinks) FileSystem::FileSystem(bool allowSymlinks){
{
p = new FileSystemPrivate; p = new FileSystemPrivate;
p->havePathCache = false; p->havePathCache = false;
@ -331,8 +321,7 @@ FileSystem::~FileSystem(){
void FileSystem::addPath(const char *path){ void FileSystem::addPath(const char *path){
/* Try the normal mount first */ /* Try the normal mount first */
if (!PHYSFS_mount(path, 0, 1)) if (!PHYSFS_mount(path, 0, 1)){
{
/* If it didn't work, try mounting via a wrapped /* If it didn't work, try mounting via a wrapped
* SDL_IOStream */ * SDL_IOStream */
PHYSFS_Io *io = createSDLRWIo(path); PHYSFS_Io *io = createSDLRWIo(path);
@ -359,8 +348,7 @@ struct CacheEnumData{
#endif #endif
} }
~CacheEnumData() ~CacheEnumData(){
{
#ifdef OS_OSX #ifdef OS_OSX
iconv_close(nfd2nfc); iconv_close(nfd2nfc);
#endif #endif
@ -622,10 +610,7 @@ void FileSystem::openRead(OpenHandler &handler, const char *filename){
throw Exception(Exception::NoFileError, "%s", filename); throw Exception(Exception::NoFileError, "%s", filename);
} }
void FileSystem::openReadRaw(SDL_IOStream* &stream, void FileSystem::openReadRaw(SDL_IOStream* &stream, const char *filename){
const char *filename)
//bool freeOnClose)
{
PHYSFS_File *handle = PHYSFS_openRead(filename); PHYSFS_File *handle = PHYSFS_openRead(filename);
if (!handle) if (!handle)
throw Exception(Exception::NoFileError, "%s", filename); throw Exception(Exception::NoFileError, "%s", filename);

View file

@ -26,28 +26,23 @@
#include "gl-fun.h" #include "gl-fun.h"
struct GLDebugLoggerPrivate struct GLDebugLoggerPrivate{
{
std::ostream *stream; std::ostream *stream;
time_t timestamp; time_t timestamp;
GLDebugLoggerPrivate(const char *logFilename) GLDebugLoggerPrivate(const char *logFilename){
{
(void) logFilename; (void) logFilename;
stream = &std::clog; stream = &std::clog;
} }
~GLDebugLoggerPrivate() ~GLDebugLoggerPrivate(){}
{
}
void writeTimestamp(){ void writeTimestamp(){
time(&timestamp); time(&timestamp);
*stream << "[GLDEBUG " << ctime(&timestamp) << "]"; *stream << "[GLDEBUG " << ctime(&timestamp) << "]";
} }
void writeLine(const char *line) void writeLine(const char *line){
{
*stream << line << "\n"; *stream << line << "\n";
stream->flush(); stream->flush();
} }
@ -76,8 +71,7 @@ static void APIENTRY arbDebugFunc(GLenum source,
p->writeLine(message); p->writeLine(message);
} }
GLDebugLogger::GLDebugLogger(const char *filename) GLDebugLogger::GLDebugLogger(const char *filename){
{
p = new GLDebugLoggerPrivate(filename); p = new GLDebugLoggerPrivate(filename);
if (gl.DebugMessageCallback) if (gl.DebugMessageCallback)
@ -86,7 +80,6 @@ GLDebugLogger::GLDebugLogger(const char *filename)
Debug() << "DebugLogger: no debug extensions found"; Debug() << "DebugLogger: no debug extensions found";
} }
GLDebugLogger::~GLDebugLogger() GLDebugLogger::~GLDebugLogger(){
{
delete p; delete p;
} }

View file

@ -29,8 +29,7 @@
struct GLDebugLoggerPrivate; struct GLDebugLoggerPrivate;
class GLDebugLogger class GLDebugLogger{
{
public: public:
GLDebugLogger(const char *filename = 0); GLDebugLogger(const char *filename = 0);
~GLDebugLogger(); ~GLDebugLogger();

View file

@ -31,8 +31,7 @@ GLFunctions gl;
typedef const GLubyte* (APIENTRYP _PFNGLGETSTRINGIPROC) (GLenum, GLuint); typedef const GLubyte* (APIENTRYP _PFNGLGETSTRINGIPROC) (GLenum, GLuint);
static void parseExtensionsCore(_PFNGLGETINTEGERVPROC GetIntegerv, BoostSet<std::string> &out) static void parseExtensionsCore(_PFNGLGETINTEGERVPROC GetIntegerv, BoostSet<std::string> &out){
{
_PFNGLGETSTRINGIPROC GetStringi = _PFNGLGETSTRINGIPROC GetStringi =
(_PFNGLGETSTRINGIPROC) SDL_GL_GetProcAddress("glGetStringi"); (_PFNGLGETSTRINGIPROC) SDL_GL_GetProcAddress("glGetStringi");
@ -43,8 +42,7 @@ static void parseExtensionsCore(_PFNGLGETINTEGERVPROC GetIntegerv, BoostSet<std:
out.insert((const char*) GetStringi(GL_EXTENSIONS, i)); out.insert((const char*) GetStringi(GL_EXTENSIONS, i));
} }
static void parseExtensionsCompat(_PFNGLGETSTRINGPROC GetString, BoostSet<std::string> &out) static void parseExtensionsCompat(_PFNGLGETSTRINGPROC GetString, BoostSet<std::string> &out){
{
const char *ext = (const char*) GetString(GL_EXTENSIONS); const char *ext = (const char*) GetString(GL_EXTENSIONS);
if (!ext) if (!ext)
@ -53,8 +51,7 @@ static void parseExtensionsCompat(_PFNGLGETSTRINGPROC GetString, BoostSet<std::s
char buffer[0x100]; char buffer[0x100];
size_t bufferI; size_t bufferI;
while (*ext) while (*ext){
{
bufferI = 0; bufferI = 0;
while (*ext && *ext != ' ') while (*ext && *ext != ' ')
buffer[bufferI++] = *ext++; buffer[bufferI++] = *ext++;
@ -74,8 +71,7 @@ static void parseExtensionsCompat(_PFNGLGETSTRINGPROC GetString, BoostSet<std::s
#define EXC(msg) \ #define EXC(msg) \
Exception(Exception::MKXPError, "%s", msg) Exception(Exception::MKXPError, "%s", msg)
void initGLFunctions() void initGLFunctions(){
{
#define EXT_SUFFIX "" #define EXT_SUFFIX ""
GL_20_FUN; GL_20_FUN;
@ -87,8 +83,7 @@ void initGLFunctions()
bool gles = false; bool gles = false;
if (!strncmp(ver, glesPrefix, glesPrefixN)) if (!strncmp(ver, glesPrefix, glesPrefixN)){
{
gles = true; gles = true;
gl.glsles = true; gl.glsles = true;
@ -101,8 +96,7 @@ void initGLFunctions()
if (glMajor < 2) if (glMajor < 2)
throw EXC("At least OpenGL (ES) 2.0 is required"); throw EXC("At least OpenGL (ES) 2.0 is required");
if (gles) if (gles){
{
GL_ES_FUN; GL_ES_FUN;
} }
@ -116,69 +110,58 @@ void initGLFunctions()
#define HAVE_EXT(_ext) ext.contains("GL_" #_ext) #define HAVE_EXT(_ext) ext.contains("GL_" #_ext)
/* FBO entrypoints */ /* FBO entrypoints */
if (glMajor >= 3 || HAVE_EXT(ARB_framebuffer_object)) if (glMajor >= 3 || HAVE_EXT(ARB_framebuffer_object)){
{
#undef EXT_SUFFIX #undef EXT_SUFFIX
#define EXT_SUFFIX "" #define EXT_SUFFIX ""
GL_FBO_FUN; GL_FBO_FUN;
GL_FBO_BLIT_FUN; GL_FBO_BLIT_FUN;
} }
else if (gles && glMajor == 2) else if (gles && glMajor == 2){
{
GL_FBO_FUN; GL_FBO_FUN;
} }
else if (HAVE_EXT(EXT_framebuffer_object)) else if (HAVE_EXT(EXT_framebuffer_object)){
{
#undef EXT_SUFFIX #undef EXT_SUFFIX
#define EXT_SUFFIX "EXT" #define EXT_SUFFIX "EXT"
GL_FBO_FUN; GL_FBO_FUN;
if (HAVE_EXT(EXT_framebuffer_blit)) if (HAVE_EXT(EXT_framebuffer_blit)){
{
GL_FBO_BLIT_FUN; GL_FBO_BLIT_FUN;
} }
} }
else else{
{
throw EXC("No FBO support available"); throw EXC("No FBO support available");
} }
/* VAO entrypoints */ /* VAO entrypoints */
if (HAVE_EXT(ARB_vertex_array_object) || glMajor >= 3) if (HAVE_EXT(ARB_vertex_array_object) || glMajor >= 3){
{
#undef EXT_SUFFIX #undef EXT_SUFFIX
#define EXT_SUFFIX "" #define EXT_SUFFIX ""
GL_VAO_FUN; GL_VAO_FUN;
} }
else if (HAVE_EXT(APPLE_vertex_array_object)) else if (HAVE_EXT(APPLE_vertex_array_object)){
{
#undef EXT_SUFFIX #undef EXT_SUFFIX
#define EXT_SUFFIX "APPLE" #define EXT_SUFFIX "APPLE"
GL_VAO_FUN; GL_VAO_FUN;
} }
else if (HAVE_EXT(OES_vertex_array_object)) else if (HAVE_EXT(OES_vertex_array_object)){
{
#undef EXT_SUFFIX #undef EXT_SUFFIX
#define EXT_SUFFIX "OES" #define EXT_SUFFIX "OES"
GL_VAO_FUN; GL_VAO_FUN;
} }
/* Debug callback entrypoints */ /* Debug callback entrypoints */
if (HAVE_EXT(KHR_debug)) if (HAVE_EXT(KHR_debug)){
{
#undef EXT_SUFFIX #undef EXT_SUFFIX
#define EXT_SUFFIX "" #define EXT_SUFFIX ""
GL_DEBUG_KHR_FUN; GL_DEBUG_KHR_FUN;
} }
else if (HAVE_EXT(ARB_debug_output)) else if (HAVE_EXT(ARB_debug_output)){
{
#undef EXT_SUFFIX #undef EXT_SUFFIX
#define EXT_SUFFIX "ARB" #define EXT_SUFFIX "ARB"
GL_DEBUG_KHR_FUN; GL_DEBUG_KHR_FUN;
} }
if (HAVE_EXT(GREMEDY_string_marker)) if (HAVE_EXT(GREMEDY_string_marker)){
{
#undef EXT_SUFFIX #undef EXT_SUFFIX
#define EXT_SUFFIX "GREMEDY" #define EXT_SUFFIX "GREMEDY"
GL_GREMEMDY_FUN; GL_GREMEMDY_FUN;

View file

@ -207,8 +207,7 @@ typedef void (APIENTRYP _PFNGLRELEASESHADERCOMPILERPROC) (void);
GL_FUN(StringMarker, _PFNGLSTRINGMARKERPROC) GL_FUN(StringMarker, _PFNGLSTRINGMARKERPROC)
struct GLFunctions struct GLFunctions{
{
#define GL_FUN(name, type) type name; #define GL_FUN(name, type) type name;
GL_20_FUN GL_20_FUN

View file

@ -73,3 +73,4 @@ void blitEnd();
} }
#endif // GLMETA_H #endif // GLMETA_H

View file

@ -49,140 +49,115 @@ struct ID \
}; };
/* 2D Texture */ /* 2D Texture */
namespace TEX namespace TEX{
{
DEF_GL_ID DEF_GL_ID
inline ID gen() inline ID gen(){
{
ID id; ID id;
gl.GenTextures(1, &id.gl); gl.GenTextures(1, &id.gl);
return id; return id;
} }
static inline void del(ID id) static inline void del(ID id){
{
gl.DeleteTextures(1, &id.gl); gl.DeleteTextures(1, &id.gl);
} }
static inline void bind(ID id) static inline void bind(ID id){
{
gl.BindTexture(GL_TEXTURE_2D, id.gl); gl.BindTexture(GL_TEXTURE_2D, id.gl);
} }
static inline void unbind() static inline void unbind(){
{
bind(ID(0)); bind(ID(0));
} }
static inline void uploadImage(GLsizei width, GLsizei height, const void *data, GLenum format) static inline void uploadImage(GLsizei width, GLsizei height, const void *data, GLenum format){
{
gl.TexImage2D(GL_TEXTURE_2D, 0, GL_RGBA, width, height, 0, format, GL_UNSIGNED_BYTE, data); gl.TexImage2D(GL_TEXTURE_2D, 0, GL_RGBA, width, height, 0, format, GL_UNSIGNED_BYTE, data);
} }
static inline void uploadSubImage(GLint x, GLint y, GLsizei width, GLsizei height, const void *data, GLenum format) static inline void uploadSubImage(GLint x, GLint y, GLsizei width, GLsizei height, const void *data, GLenum format){
{
gl.TexSubImage2D(GL_TEXTURE_2D, 0, x, y, width, height, format, GL_UNSIGNED_BYTE, data); gl.TexSubImage2D(GL_TEXTURE_2D, 0, x, y, width, height, format, GL_UNSIGNED_BYTE, data);
} }
static inline void allocEmpty(GLsizei width, GLsizei height) static inline void allocEmpty(GLsizei width, GLsizei height){
{
gl.TexImage2D(GL_TEXTURE_2D, 0, GL_RGBA, width, height, 0, GL_RGBA, GL_UNSIGNED_BYTE, 0); gl.TexImage2D(GL_TEXTURE_2D, 0, GL_RGBA, width, height, 0, GL_RGBA, GL_UNSIGNED_BYTE, 0);
} }
static inline void setRepeat(bool mode) static inline void setRepeat(bool mode){
{
gl.TexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, mode ? GL_REPEAT : GL_CLAMP_TO_EDGE); gl.TexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, mode ? GL_REPEAT : GL_CLAMP_TO_EDGE);
gl.TexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, mode ? GL_REPEAT : GL_CLAMP_TO_EDGE); gl.TexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, mode ? GL_REPEAT : GL_CLAMP_TO_EDGE);
} }
static inline void setSmooth(bool mode) static inline void setSmooth(bool mode){
{
gl.TexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, mode ? GL_LINEAR : GL_NEAREST); gl.TexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, mode ? GL_LINEAR : GL_NEAREST);
gl.TexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, mode ? GL_LINEAR : GL_NEAREST); gl.TexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, mode ? GL_LINEAR : GL_NEAREST);
} }
} }
/* Framebuffer Object */ /* Framebuffer Object */
namespace FBO namespace FBO{
{
DEF_GL_ID DEF_GL_ID
inline ID gen() inline ID gen(){
{
ID id; ID id;
gl.GenFramebuffers(1, &id.gl); gl.GenFramebuffers(1, &id.gl);
return id; return id;
} }
static inline void del(ID id) static inline void del(ID id){
{
gl.DeleteFramebuffers(1, &id.gl); gl.DeleteFramebuffers(1, &id.gl);
} }
static inline void bind(ID id) static inline void bind(ID id){
{
gl.BindFramebuffer(GL_FRAMEBUFFER, id.gl); gl.BindFramebuffer(GL_FRAMEBUFFER, id.gl);
} }
static inline void unbind() static inline void unbind(){
{
bind(ID(0)); bind(ID(0));
} }
static inline void setTarget(TEX::ID target, unsigned colorAttach = 0) static inline void setTarget(TEX::ID target, unsigned colorAttach = 0){
{
gl.FramebufferTexture2D(GL_FRAMEBUFFER, GL_COLOR_ATTACHMENT0 + colorAttach, GL_TEXTURE_2D, target.gl, 0); gl.FramebufferTexture2D(GL_FRAMEBUFFER, GL_COLOR_ATTACHMENT0 + colorAttach, GL_TEXTURE_2D, target.gl, 0);
} }
static inline void clear() static inline void clear(){
{
gl.Clear(GL_COLOR_BUFFER_BIT); gl.Clear(GL_COLOR_BUFFER_BIT);
} }
} }
template<GLenum target> template<GLenum target>
struct GenericBO struct GenericBO{
{
DEF_GL_ID DEF_GL_ID
static inline ID gen() static inline ID gen(){
{
ID id; ID id;
gl.GenBuffers(1, &id.gl); gl.GenBuffers(1, &id.gl);
return id; return id;
} }
static inline void del(ID id) static inline void del(ID id){
{
gl.DeleteBuffers(1, &id.gl); gl.DeleteBuffers(1, &id.gl);
} }
static inline void bind(ID id) static inline void bind(ID id){
{
gl.BindBuffer(target, id.gl); gl.BindBuffer(target, id.gl);
} }
static inline void unbind() static inline void unbind(){
{
bind(ID(0)); bind(ID(0));
} }
static inline void uploadData(GLsizeiptr size, const GLvoid *data, GLenum usage = GL_STATIC_DRAW) static inline void uploadData(GLsizeiptr size, const GLvoid *data, GLenum usage = GL_STATIC_DRAW){
{
gl.BufferData(target, size, data, usage); gl.BufferData(target, size, data, usage);
} }
static inline void uploadSubData(GLintptr offset, GLsizeiptr size, const GLvoid *data) static inline void uploadSubData(GLintptr offset, GLsizeiptr size, const GLvoid *data){
{
gl.BufferSubData(target, offset, size, data); gl.BufferSubData(target, offset, size, data);
} }
static inline void allocEmpty(GLsizeiptr size, GLenum usage = GL_STATIC_DRAW) static inline void allocEmpty(GLsizeiptr size, GLenum usage = GL_STATIC_DRAW){
{
uploadData(size, 0, usage); uploadData(size, 0, usage);
} }
}; };
@ -197,8 +172,7 @@ typedef struct GenericBO<GL_ELEMENT_ARRAY_BUFFER> IBO;
/* Convenience struct wrapping a framebuffer /* Convenience struct wrapping a framebuffer
* and a 2D texture as its target */ * and a 2D texture as its target */
struct TEXFBO struct TEXFBO{
{
TEX::ID tex; TEX::ID tex;
FBO::ID fbo; FBO::ID fbo;
int width, height; int width, height;
@ -207,13 +181,11 @@ struct TEXFBO
: tex(0), fbo(0), width(0), height(0) : tex(0), fbo(0), width(0), height(0)
{} {}
bool operator==(const TEXFBO &other) const bool operator==(const TEXFBO &other) const{
{
return (tex == other.tex) && (fbo == other.fbo); return (tex == other.tex) && (fbo == other.fbo);
} }
static inline void init(TEXFBO &obj) static inline void init(TEXFBO &obj){
{
obj.tex = TEX::gen(); obj.tex = TEX::gen();
obj.fbo = FBO::gen(); obj.fbo = FBO::gen();
TEX::bind(obj.tex); TEX::bind(obj.tex);
@ -221,28 +193,24 @@ struct TEXFBO
TEX::setSmooth(false); TEX::setSmooth(false);
} }
static inline void allocEmpty(TEXFBO &obj, int width, int height) static inline void allocEmpty(TEXFBO &obj, int width, int height){
{
TEX::bind(obj.tex); TEX::bind(obj.tex);
TEX::allocEmpty(width, height); TEX::allocEmpty(width, height);
obj.width = width; obj.width = width;
obj.height = height; obj.height = height;
} }
static inline void linkFBO(TEXFBO &obj) static inline void linkFBO(TEXFBO &obj){
{
FBO::bind(obj.fbo); FBO::bind(obj.fbo);
FBO::setTarget(obj.tex); FBO::setTarget(obj.tex);
} }
static inline void fini(TEXFBO &obj) static inline void fini(TEXFBO &obj){
{
FBO::del(obj.fbo); FBO::del(obj.fbo);
TEX::del(obj.tex); TEX::del(obj.tex);
} }
static inline void clear(TEXFBO &obj) static inline void clear(TEXFBO &obj){
{
obj.tex = TEX::ID(0); obj.tex = TEX::ID(0);
obj.fbo = FBO::ID(0); obj.fbo = FBO::ID(0);
obj.width = obj.height = 0; obj.width = obj.height = 0;

View file

@ -30,15 +30,12 @@
struct Config; struct Config;
template<typename T> template<typename T>
struct GLProperty struct GLProperty{
{ ~GLProperty(){
~GLProperty()
{
assert(stack.size() == 0); assert(stack.size() == 0);
} }
void init(const T &value) void init(const T &value){
{
current = value; current = value;
apply(value); apply(value);
} }
@ -46,22 +43,19 @@ struct GLProperty
void push() { stack.push(current); } void push() { stack.push(current); }
void pop() { if (!stack.empty()) { set(stack.top()); stack.pop(); } } void pop() { if (!stack.empty()) { set(stack.top()); stack.pop(); } }
const T &get() { return current; } const T &get() { return current; }
void set(const T &value) void set(const T &value){
{
if (value == current) if (value == current)
return; return;
init(value); init(value);
} }
void pushSet(const T &value) void pushSet(const T &value){
{
push(); push();
set(value); set(value);
} }
void refresh() void refresh(){
{
apply(current); apply(current);
} }
private: private:
@ -72,13 +66,11 @@ private:
}; };
class GLClearColor : public GLProperty<Vec4> class GLClearColor : public GLProperty<Vec4>{
{
void apply(const Vec4 &); void apply(const Vec4 &);
}; };
class GLScissorBox : public GLProperty<IntRect> class GLScissorBox : public GLProperty<IntRect>{
{
public: public:
/* Sets the intersection of the current box with value */ /* Sets the intersection of the current box with value */
void setIntersect(const IntRect &value); void setIntersect(const IntRect &value);
@ -87,13 +79,11 @@ private:
void apply(const IntRect &value); void apply(const IntRect &value);
}; };
class GLScissorTest : public GLProperty<bool> class GLScissorTest : public GLProperty<bool>{
{
void apply(const bool &value); void apply(const bool &value);
}; };
class GLBlendMode : public GLProperty<BlendType> class GLBlendMode : public GLProperty<BlendType>{
{
void apply(const BlendType &value); void apply(const BlendType &value);
}; };
@ -102,19 +92,16 @@ class GLBlend : public GLProperty<bool>
void apply(const bool &value); void apply(const bool &value);
}; };
class GLViewport : public GLProperty<IntRect> class GLViewport : public GLProperty<IntRect>{
{
void apply(const IntRect &value); void apply(const IntRect &value);
}; };
class GLProgram : public GLProperty<unsigned int> /* GLuint */ class GLProgram : public GLProperty<unsigned int> /* GLuint */{
{
void apply(const unsigned int &value); void apply(const unsigned int &value);
}; };
class GLState class GLState{
{
public: public:
GLClearColor clearColor; GLClearColor clearColor;
GLScissorBox scissorBox; GLScissorBox scissorBox;
@ -124,8 +111,7 @@ public:
GLViewport viewport; GLViewport viewport;
GLProgram program; GLProgram program;
struct Caps struct Caps{
{
int maxTexSize; int maxTexSize;
Caps(); Caps();

View file

@ -894,10 +894,6 @@ void Graphics::resizeScreen(int width, int height){
shState->eThread().requestWindowResize(width, height); shState->eThread().requestWindowResize(width, height);
} }
void Graphics::playMovie(const char *filename){
Debug() << "[playMovie] Graphics.playMovie(" << filename << ") not implemented";
}
DEF_ATTR_RD_SIMPLE(Graphics, Brightness, int, p->brightness) DEF_ATTR_RD_SIMPLE(Graphics, Brightness, int, p->brightness)
void Graphics::setBrightness(int value){ void Graphics::setBrightness(int value){

View file

@ -54,7 +54,6 @@ public:
int width() const; int width() const;
int height() const; int height() const;
void resizeScreen(int width, int height); void resizeScreen(int width, int height);
void playMovie(const char *filename);
void reset(); void reset();

View file

@ -21,13 +21,11 @@
#include "tileatlas.h" #include "tileatlas.h"
namespace TileAtlas namespace TileAtlas{
{
/* A Column represents a Rect /* A Column represents a Rect
* with undefined width */ * with undefined width */
struct Column struct Column{
{
int x, y, h; int x, y, h;
Column(int x, int y, int h) Column(int x, int y, int h)

View file

@ -39,28 +39,24 @@
#include <sigc++/connection.h> #include <sigc++/connection.h>
static inline int static inline int wrap(int value, int range){
wrap(int value, int range){
int res = value % range; int res = value % range;
return res < 0 ? res + range : res; return res < 0 ? res + range : res;
} }
static inline Vec2i static inline Vec2i wrap(const Vec2i &value, int range){
wrap(const Vec2i &value, int range){
return Vec2i(wrap(value.x, range), return Vec2i(wrap(value.x, range),
wrap(value.y, range)); wrap(value.y, range));
} }
static inline int16_t static inline int16_t tableGetWrapped(const Table &t, int x, int y, int z = 0){
tableGetWrapped(const Table &t, int x, int y, int z = 0){
return t.get(wrap(x, t.xSize()), return t.get(wrap(x, t.xSize()),
wrap(y, t.ySize()), wrap(y, t.ySize()),
z); z);
} }
/* Calculate the tile x/y on which this pixel x/y lies */ /* Calculate the tile x/y on which this pixel x/y lies */
static inline Vec2i static inline Vec2i getTilePos(const Vec2i &pixelPos){
getTilePos(const Vec2i &pixelPos){
/* Round the pixel position down to the nearest top left /* Round the pixel position down to the nearest top left
* tile boundary, by masking off the lower 5 bits (2^5 = 32). * tile boundary, by masking off the lower 5 bits (2^5 = 32).
* Then divide by 32 to convert into tile units. */ * Then divide by 32 to convert into tile units. */
@ -209,8 +205,7 @@ private:
return; return;
for (int x = 0; x < viewp.w; ++x) for (int x = 0; x < viewp.w; ++x)
for (int y = 0; y < viewp.h; ++y) for (int y = 0; y < viewp.h; ++y){
{
Vec4 color; Vec4 color;
if (!sampleFlashColor(color, x+viewp.x, y+viewp.y)) if (!sampleFlashColor(color, x+viewp.x, y+viewp.y))

View file

@ -1171,3 +1171,4 @@ void Tilemap::releaseResources(){
delete p; delete p;
atProxy.p = 0; atProxy.p = 0;
} }

View file

@ -323,14 +323,12 @@ struct WindowPrivate {
backgroundVert.vert = &vert[i]; backgroundVert.vert = &vert[i];
/* Background */ /* Background */
if (bgStretch) if (bgStretch){
{
Quad::setTexRect(&vert[i*4], backgroundSrc); Quad::setTexRect(&vert[i*4], backgroundSrc);
Quad::setPosRect(&vert[i*4], bgRect); Quad::setPosRect(&vert[i*4], bgRect);
i += 1; i += 1;
} }
else else{
{
i += TileQuads::build(backgroundSrc, bgRect, &vert[i*4]); i += TileQuads::build(backgroundSrc, bgRect, &vert[i*4]);
} }
@ -372,13 +370,11 @@ struct WindowPrivate {
int newH = baseTex.height; int newH = baseTex.height;
bool resizeNeeded = false; bool resizeNeeded = false;
if (size.x > baseTex.width) if (size.x > baseTex.width){
{
newW = findNextPow2(size.x); newW = findNextPow2(size.x);
resizeNeeded = true; resizeNeeded = true;
} }
if (size.y > baseTex.height) if (size.y > baseTex.height){
{
newH = findNextPow2(size.y); newH = findNextPow2(size.y);
resizeNeeded = true; resizeNeeded = true;
} }
@ -438,8 +434,7 @@ struct WindowPrivate {
Vertex *vert = controlsQuadArray.vertices.data(); Vertex *vert = controlsQuadArray.vertices.data();
/* Cursor */ /* Cursor */
if (!cursorRect->isEmpty()) if (!cursorRect->isEmpty()){
{
/* Effective cursor rect has 16 xy offset to window */ /* Effective cursor rect has 16 xy offset to window */
IntRect effectRect(cursorRect->x+16, cursorRect->y+16, IntRect effectRect(cursorRect->x+16, cursorRect->y+16,
cursorRect->width, cursorRect->height); cursorRect->width, cursorRect->height);
@ -458,8 +453,7 @@ struct WindowPrivate {
scrollArrows.t = IntRect(scroll.x, 4, 16, 8); scrollArrows.t = IntRect(scroll.x, 4, 16, 8);
scrollArrows.b = IntRect(scroll.x, size.y - 12, 16, 8); scrollArrows.b = IntRect(scroll.x, size.y - 12, 16, 8);
if (contents) if (contents){
{
if (contentsOffset.x > 0) if (contentsOffset.x > 0)
i += Quad::setTexPosRect(&vert[i*4], scrollArrowSrc.l, scrollArrows.l); i += Quad::setTexPosRect(&vert[i*4], scrollArrowSrc.l, scrollArrows.l);
@ -474,8 +468,7 @@ struct WindowPrivate {
} }
/* Pause animation */ /* Pause animation */
if (pause) if (pause){
{
pauseAniVert.vert = &vert[i*4]; pauseAniVert.vert = &vert[i*4];
i += Quad::setTexPosRect(&vert[i*4], pauseAniSrc[pauseAniQuad[pauseAniQuadIdx]], i += Quad::setTexPosRect(&vert[i*4], pauseAniSrc[pauseAniQuad[pauseAniQuadIdx]],
FloatRect((size.x - 16) / 2, size.y - 16, 16, 16)); FloatRect((size.x - 16) / 2, size.y - 16, 16, 16));
@ -491,15 +484,13 @@ struct WindowPrivate {
bool updateBaseQuadArray = false; bool updateBaseQuadArray = false;
if (baseVertDirty) if (baseVertDirty){
{
buildBaseVert(); buildBaseVert();
baseVertDirty = false; baseVertDirty = false;
updateBaseQuadArray = true; updateBaseQuadArray = true;
} }
if (opacityDirty) if (opacityDirty){
{
updateBaseAlpha(); updateBaseAlpha();
opacityDirty = false; opacityDirty = false;
updateBaseQuadArray = true; updateBaseQuadArray = true;
@ -512,12 +503,10 @@ struct WindowPrivate {
* and then draw this texture instead of the quad array */ * and then draw this texture instead of the quad array */
useBaseTex = opacity < 255; useBaseTex = opacity < 255;
if (useBaseTex) if (useBaseTex){
{
ensureBaseTexReady(); ensureBaseTexReady();
if (baseTexDirty) if (baseTexDirty){
{
redrawBaseTex(); redrawBaseTex();
baseTexDirty = false; baseTexDirty = false;
} }
@ -536,15 +525,12 @@ struct WindowPrivate {
shader.applyViewportProj(); shader.applyViewportProj();
shader.setTranslation(position + sceneOffset); shader.setTranslation(position + sceneOffset);
if (useBaseTex) if (useBaseTex){
{
shader.setTexSize(Vec2i(baseTex.width, baseTex.height)); shader.setTexSize(Vec2i(baseTex.width, baseTex.height));
TEX::bind(baseTex.tex); TEX::bind(baseTex.tex);
baseTexQuad.draw(); baseTexQuad.draw();
} }else{
else
{
windowskin->bindTex(shader); windowskin->bindTex(shader);
TEX::setSmooth(true); TEX::setSmooth(true);
@ -561,8 +547,7 @@ struct WindowPrivate {
if (size == Vec2i(0, 0)) if (size == Vec2i(0, 0))
return; return;
if (controlsVertDirty) if (controlsVertDirty){
{
buildControlsVert(); buildControlsVert();
updateControls(); updateControls();
controlsVertDirty = false; controlsVertDirty = false;
@ -582,8 +567,7 @@ struct WindowPrivate {
shader.bind(); shader.bind();
shader.applyViewportProj(); shader.applyViewportProj();
if (!nullOrDisposed(windowskin)) if (!nullOrDisposed(windowskin)){
{
shader.setTranslation(efPos); shader.setTranslation(efPos);
/* Draw arrows / cursors */ /* Draw arrows / cursors */
@ -595,8 +579,7 @@ struct WindowPrivate {
TEX::setSmooth(false); TEX::setSmooth(false);
} }
if (!nullOrDisposed(contents)) if (!nullOrDisposed(contents)){
{
/* Draw contents bitmap */ /* Draw contents bitmap */
glState.scissorBox.setIntersect(contentsRect); glState.scissorBox.setIntersect(contentsRect);