mirror of
https://github.com/love2d/love.git
synced 2026-08-17 19:23:38 +02:00
Added stack type enums to love.graphics.push (resolves issue #906.) Current enums are "transform" and "all". "transform" is the default (for compatibility.) When love.graphics.push("all") is used, love.graphics.pop() will restore all love.graphics module state to what it was when push was called.
Updated the graphics code to use a custom matrix stack rather than OpenGL1's APIs.
This commit is contained in:
@@ -26,9 +26,11 @@
|
||||
// LOVE
|
||||
#include "graphics/Color.h"
|
||||
#include "graphics/Texture.h"
|
||||
#include "common/Matrix.h"
|
||||
|
||||
// C++
|
||||
#include <vector>
|
||||
#include <stack>
|
||||
|
||||
// The last argument to AttribPointer takes a buffer offset casted to a pointer.
|
||||
#define BUFFER_OFFSET(i) ((char *) NULL + (i))
|
||||
@@ -101,6 +103,36 @@ public:
|
||||
GLenum func;
|
||||
};
|
||||
|
||||
struct
|
||||
{
|
||||
std::vector<Matrix> transform;
|
||||
std::vector<Matrix> projection;
|
||||
} matrices;
|
||||
|
||||
class TempTransform
|
||||
{
|
||||
public:
|
||||
|
||||
TempTransform(OpenGL &gl)
|
||||
: gl(gl)
|
||||
{
|
||||
gl.pushTransform();
|
||||
}
|
||||
|
||||
~TempTransform()
|
||||
{
|
||||
gl.popTransform();
|
||||
}
|
||||
|
||||
Matrix &get()
|
||||
{
|
||||
return gl.getTransform();
|
||||
}
|
||||
|
||||
private:
|
||||
OpenGL ≷
|
||||
};
|
||||
|
||||
OpenGL();
|
||||
|
||||
/**
|
||||
@@ -116,6 +148,10 @@ public:
|
||||
**/
|
||||
void deInitContext();
|
||||
|
||||
void pushTransform();
|
||||
void popTransform();
|
||||
Matrix &getTransform();
|
||||
|
||||
/**
|
||||
* Set up necessary state (LOVE-provided shader uniforms, etc.) for drawing.
|
||||
* This *MUST* be called directly before OpenGL drawing functions.
|
||||
@@ -258,6 +294,7 @@ private:
|
||||
void initVendor();
|
||||
void initOpenGLFunctions();
|
||||
void initMaxValues();
|
||||
void initMatrices();
|
||||
void createDefaultTexture();
|
||||
|
||||
bool contextInitialized;
|
||||
@@ -290,6 +327,9 @@ private:
|
||||
// The last ID value used for pseudo-instancing.
|
||||
int lastPseudoInstanceID;
|
||||
|
||||
Matrix lastProjectionMatrix;
|
||||
Matrix lastTransformMatrix;
|
||||
|
||||
} state;
|
||||
|
||||
}; // OpenGL
|
||||
|
||||
Reference in New Issue
Block a user