mirror of
https://github.com/ultimatepp/ultimatepp.git
synced 2026-09-05 17:44:55 -06:00
GLDraw: new features
git-svn-id: svn://ultimatepp.org/upp/trunk@12729 f0d560ea-af0d-0410-9eb7-867de7ffcac7
This commit is contained in:
parent
ebbc917bba
commit
7179a03ca4
7 changed files with 58 additions and 16 deletions
|
|
@ -7,36 +7,55 @@ GLCode::GLCode(const char *vertex_shader, const char *pixel_shader)
|
|||
Compile(vertex_shader, pixel_shader);
|
||||
Vector<Tuple2<int, const char *>> ins;
|
||||
CParser p(vertex_shader);
|
||||
int ii = 0;
|
||||
int ti = 0;
|
||||
auto readID = [&] {
|
||||
auto readID = [&](int& n) {
|
||||
String id;
|
||||
while(!p.IsEof() && !p.Char(';'))
|
||||
if(p.IsId())
|
||||
n = 0;
|
||||
while(!p.IsEof() && !p.IsChar(';'))
|
||||
if(p.IsId()) {
|
||||
id = p.ReadId();
|
||||
else
|
||||
if(p.Char('[') && p.IsInt()) {
|
||||
n = p.ReadInt();
|
||||
p.Char(']');
|
||||
}
|
||||
}
|
||||
else {
|
||||
p.SkipTerm();
|
||||
n = 0;
|
||||
}
|
||||
return id;
|
||||
};
|
||||
int ii = 0;
|
||||
while(!p.IsEof() && !p.Char('{'))
|
||||
if(p.Id("attribute") || p.Id("in")) {
|
||||
String id = readID();
|
||||
int n;
|
||||
String id = readID(n);
|
||||
if(id.GetCount())
|
||||
glBindAttribLocation(program, ii++, id);
|
||||
}
|
||||
else
|
||||
p.SkipTerm();
|
||||
|
||||
Link();
|
||||
Use();
|
||||
|
||||
p.Set(pixel_shader);
|
||||
int ti = 0;
|
||||
while(!p.IsEof() && !p.Char('{'))
|
||||
if(p.Id("sampler2D") || p.Id("sampler3D")) {
|
||||
String id = readID();
|
||||
int n;
|
||||
String id = readID(n);
|
||||
if(id.GetCount())
|
||||
glUniform1i(GetUniform(id), ti++);
|
||||
if(n) {
|
||||
for(int i = 0; i < n; i++) {
|
||||
ASSERT(GetUniform(id + '[' + AsString(i) + ']') >= 0);
|
||||
glUniform1i(GetUniform(id + '[' + AsString(i) + ']'), ti++);
|
||||
}
|
||||
}
|
||||
else
|
||||
glUniform1i(GetUniform(id), ti++);
|
||||
}
|
||||
else
|
||||
p.SkipTerm();
|
||||
Link();
|
||||
}
|
||||
|
||||
GLCode& GLCode::Uniform(int i, double a)
|
||||
|
|
|
|||
|
|
@ -78,7 +78,7 @@ public:
|
|||
void Clear();
|
||||
void Set(const Image& img, dword flags = TEXTURE_LINEAR|TEXTURE_MIPMAP);
|
||||
|
||||
void Bind() const;
|
||||
void Bind(int ii = 0) const;
|
||||
int GetID() const { return data ? data->textureid : 0; }
|
||||
operator GLuint() const { return GetID(); }
|
||||
Size GetSize() const { return data ? data->sz : Size(0, 0); }
|
||||
|
|
@ -92,6 +92,7 @@ public:
|
|||
GLTexture& operator=(const GLTexture& src);
|
||||
};
|
||||
|
||||
void GLBind(int ii, const Image& img, dword style = TEXTURE_LINEAR|TEXTURE_MIPMAP);
|
||||
void GLBind(const Image& img, dword style = TEXTURE_LINEAR|TEXTURE_MIPMAP);
|
||||
|
||||
void GLDrawTexture(const GLContext2D& dd, const Rectf& rect, int textureid, Size tsz, const Rect& src);
|
||||
|
|
@ -120,8 +121,10 @@ public:
|
|||
GLVertexData& Add(const void *data, int type, int ntuple, int count);
|
||||
GLVertexData& Add(const float *data, int ntuple, int count) { return Add(data, GL_FLOAT, ntuple, count); }
|
||||
GLVertexData& Add(const byte *data, int ntuple, int count) { return Add(data, GL_UNSIGNED_BYTE, ntuple, count); }
|
||||
GLVertexData& Add(const dword *data, int ntuple, int count) { return Add(data, GL_UNSIGNED_INT, ntuple, count); }
|
||||
GLVertexData& Add(const Vector<float>& data, int ntuple) { return Add(data, ntuple, data.GetCount() / ntuple); }
|
||||
GLVertexData& Add(const Vector<byte>& data, int ntuple) { return Add(data, ntuple, data.GetCount() / ntuple); }
|
||||
GLVertexData& Add(const Vector<dword>& data, int ntuple) { return Add(data, ntuple, data.GetCount() / ntuple); }
|
||||
GLVertexData& Add(const Vector<Pointf>& pt);
|
||||
GLVertexData& Index(const int *indices, int count);
|
||||
GLVertexData& Index(const Vector<int>& indices) { return Index(indices, indices.GetCount()); }
|
||||
|
|
@ -306,6 +309,7 @@ int GLElementCounter();
|
|||
int GLTextureCounter();
|
||||
int GLProgramCounter();
|
||||
int GLDrawCounter();
|
||||
int GLTesselateCounter();
|
||||
|
||||
};
|
||||
|
||||
|
|
|
|||
|
|
@ -27,9 +27,10 @@ void GLTexture::Set(const Image& img, dword flags)
|
|||
|
||||
extern int sTextureCounter;
|
||||
|
||||
void GLTexture::Bind() const
|
||||
void GLTexture::Bind(int ii) const
|
||||
{
|
||||
if(data) {
|
||||
glActiveTexture(GL_TEXTURE0 + ii);
|
||||
glBindTexture(GL_TEXTURE_2D, data->textureid);
|
||||
sTextureCounter++;
|
||||
}
|
||||
|
|
@ -51,13 +52,19 @@ GLTexture& GLTexture::operator=(const GLTexture& src)
|
|||
return *this;
|
||||
}
|
||||
|
||||
void GLBind(const Image& img, dword style)
|
||||
void GLBind(int ii, const Image& img, dword style)
|
||||
{
|
||||
extern int sTextureCounter;
|
||||
glActiveTexture(GL_TEXTURE0 + ii);
|
||||
glBindTexture(GL_TEXTURE_2D, GetTextureForImage(style, img));
|
||||
sTextureCounter++;
|
||||
}
|
||||
|
||||
void GLBind(const Image& img, dword style)
|
||||
{
|
||||
GLBind(0, img, style);
|
||||
}
|
||||
|
||||
const GLVertexData& GLRectMesh()
|
||||
{
|
||||
static GLVertexData mesh;
|
||||
|
|
|
|||
|
|
@ -6,10 +6,11 @@ int sDrawCounter;
|
|||
int sElementCounter;
|
||||
int sTextureCounter;
|
||||
int sProgramCounter;
|
||||
int sTesselateCounter;
|
||||
|
||||
void GLClearCounters()
|
||||
{
|
||||
sElementCounter = sTextureCounter = sProgramCounter = sDrawCounter = 0;
|
||||
sElementCounter = sTextureCounter = sProgramCounter = sDrawCounter = sTesselateCounter = 0;
|
||||
}
|
||||
|
||||
int GLElementCounter()
|
||||
|
|
@ -32,4 +33,9 @@ int GLDrawCounter()
|
|||
return sDrawCounter;
|
||||
}
|
||||
|
||||
int GLTesselateCounter()
|
||||
{
|
||||
return sTesselateCounter;
|
||||
}
|
||||
|
||||
};
|
||||
|
|
@ -251,6 +251,8 @@ void DrawGL::DrawPolyPolylineOp(const Point *vertices, int vertex_count, const i
|
|||
DoDrawPolylines(poly, width, color);
|
||||
}
|
||||
|
||||
extern int sTesselateCounter;
|
||||
|
||||
void DrawGL::DoDrawPolygons(const Vector<Vector<Pointf>>& path, Color color)
|
||||
{
|
||||
const int TESS_LIMIT = 200;
|
||||
|
|
@ -268,6 +270,7 @@ void DrawGL::DoDrawPolygons(const Vector<Vector<Pointf>>& path, Color color)
|
|||
}
|
||||
Vector<Pointf> vertex;
|
||||
Vector<Tuple<int, int, int>> triangle;
|
||||
sTesselateCounter++;
|
||||
RTIMING("Tesselate");
|
||||
Tesselate(path, vertex, triangle, false);
|
||||
int ii0;
|
||||
|
|
|
|||
|
|
@ -10,7 +10,7 @@ void GLTriangles::Draw(const GLContext2D& dd)
|
|||
static GLCode program(R"(
|
||||
#version 130
|
||||
attribute vec3 p;
|
||||
attribute vec3 c;
|
||||
attribute uvec3 c;
|
||||
uniform vec2 offset;
|
||||
uniform vec2 scale;
|
||||
varying vec4 v_color;
|
||||
|
|
|
|||
|
|
@ -57,7 +57,10 @@ GLVertexData& GLVertexData::Add(const void *values, int type, int ntuple, int co
|
|||
GL_UNSIGNED_INT, sizeof(uint32),
|
||||
sizeof(double));
|
||||
glBufferData(GL_ARRAY_BUFFER, sz * ntuple * count, values, GL_STATIC_DRAW);
|
||||
glVertexAttribPointer(ii, ntuple, type, GL_FALSE, ntuple * sz, (void*)0);
|
||||
if(type == GL_FLOAT)
|
||||
glVertexAttribPointer(ii, ntuple, type, GL_FALSE, ntuple * sz, (void*)0);
|
||||
else
|
||||
glVertexAttribIPointer(ii, ntuple, type, ntuple * sz, (void*)0);
|
||||
glEnableVertexAttribArray(ii);
|
||||
glBindBuffer(GL_ARRAY_BUFFER, 0);
|
||||
glBindVertexArray(0);
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue