Works online now!

This commit is contained in:
Zeno Rogue 2018-02-11 19:08:17 +01:00
parent d01d772669
commit cab8a0a38f
11 changed files with 386 additions and 277 deletions

View File

@ -263,8 +263,8 @@ void setGLProjection(int col) {
GLERR("setGLProjection #1");
#ifndef GLES_ONLY
glEnable(GL_BLEND);
#ifndef GLES_ONLY
if(vid.antialias & AA_LINES) {
glEnable(GL_LINE_SMOOTH);
glHint(GL_LINE_SMOOTH_HINT, GL_NICEST);
@ -443,8 +443,6 @@ void init_glfont(int size) {
GLERR("initfont");
}
GLfloat tver[24];
int gl_width(int size, const char *s) {
int gsiz = size;
if(size > vid.fsize || size > 72) gsiz = 72;
@ -467,8 +465,27 @@ int gl_width(int size, const char *s) {
return x;
}
bool gl_print(int x, int y, int shift, int size, const char *s, int color, int align) {
namespace glhr { void texture_vertices(GLfloat *f, int qty, int stride = 2) {
#if CAP_SHADER
glVertexAttribPointer(aTexture, stride, GL_FLOAT, GL_FALSE, stride * sizeof(GLfloat), f);
#else
glTexCoordPointer(stride, GL_FLOAT, 0, f);
#endif
}
void oldvertices(GLfloat *f, int qty) {
#if CAP_SHADER
glVertexAttribPointer(aPosition, 3, GL_FLOAT, GL_FALSE, 3 * sizeof(GLfloat), f);
#else
glVertexPointer(3, GL_FLOAT, 0, f);
#endif
// #endif
}
}
GLfloat otver[24];
vector<glhr::textured_vertex> tver(4);
bool gl_print(int x, int y, int shift, int size, const char *s, int color, int align) {
int gsiz = size;
if(size > vid.fsize || size > 72) gsiz = 72;
@ -512,12 +529,16 @@ bool gl_print(int x, int y, int shift, int size, const char *s, int color, int a
stereo::set_mask(ed);
glBindTexture(GL_TEXTURE_2D, f.textures[tabid]);
tver[1] = tver[10] = -hi;
tver[6] = tver[9] = wi;
tver[12+3] = tver[12+5] = fy;
tver[12+4] = tver[12+6] = fx;
glhr::vertices(tver, 4);
glhr::texture_vertices(tver+12, 4);
tver[0].coords[1] = -hi;
tver[3].coords[1] = -hi;
tver[2].coords[0] = wi;
tver[3].coords[0] = wi;
tver[1].texture[1] = fy;
tver[2].texture[1] = fy;
tver[2].texture[0] = fx;
tver[3].texture[0] = fx;
glhr::prepare(tver);
glDrawArrays(GL_TRIANGLE_FAN, 0, 4);
}
@ -530,6 +551,7 @@ bool gl_print(int x, int y, int shift, int size, const char *s, int color, int a
return clicked;
}
#endif
purehookset hooks_resetGL;
@ -872,7 +894,7 @@ void drawCircle(int x, int y, int size, int color) {
if(vid.usingGL) {
glhr::be_nontextured();
glhr::set_modelview(glhr::id());
qglcoords = 0;
glcoords.clear();
glhr::color2(color);
x -= vid.xcenter; y -= vid.ycenter;
int pts = size * 4;
@ -880,13 +902,9 @@ void drawCircle(int x, int y, int size, int color) {
if(ISMOBILE && pts > 72) pts = 72;
for(int r=0; r<pts; r++) {
float rr = (M_PI * 2 * r) / pts;
glcoords[r][0] = x + size * sin(rr);
glcoords[r][1] = y + size * cos(rr);
glcoords[r][2] = stereo::scrdist;
glcoords.push_back(make_array<GLfloat>(x + size * sin(rr), y + size * cos(rr), stereo::scrdist));
}
qglcoords = pts;
activateGlcoords();
glhr::vertices(glcoords);
glDrawArrays(GL_LINE_LOOP, 0, pts);
return;
}
@ -1057,12 +1075,12 @@ void setvideomode() {
if(vid.usingGL) {
flags = SDL_OPENGL | SDL_HWSURFACE | SDL_GL_DOUBLEBUFFER;
SDL_GL_SetAttribute(SDL_GL_STENCIL_SIZE, 1);
#if !ISWEB
if(vid.antialias & AA_MULTI) {
SDL_GL_SetAttribute(SDL_GL_MULTISAMPLEBUFFERS, 1);
SDL_GL_SetAttribute(SDL_GL_MULTISAMPLESAMPLES, (vid.antialias & AA_MULTI16) ? 16 : 4);
}
#endif
}
#endif
@ -1088,10 +1106,12 @@ void setvideomode() {
#if CAP_GL
if(vid.usingGL) {
#if !ISWEB
if(vid.antialias & AA_MULTI)
glEnable(GL_MULTISAMPLE);
else
glDisable(GL_MULTISAMPLE);
#endif
glViewport(0, 0, vid.xres, vid.yres);
glhr::init();

View File

@ -2206,8 +2206,8 @@ void sumaura(int v) {
}
aurac[AURA][v] = aurac[0][v];
}
float coltab[4][4];
vector<glhr::colored_vertex> auravertices;
void drawaura() {
if(!haveaura()) return;
@ -2270,13 +2270,8 @@ void drawaura() {
#endif
#if CAP_GL
glhr::switch_mode(glhr::gmVarColored);
glhr::set_modelview(glhr::id());
setcameraangle(true);
glhr::color_vertices(coltab[0], 4);
activateGlcoords();
float cx[AURA+1][11][5];
double facs[11] = {1, 1.01, 1.02, 1.04, 1.08, 1.70, 1.95, 1.5, 2, 6, 10};
@ -2301,22 +2296,21 @@ void drawaura() {
cx[r][z][u+2] = bak[u] + (aurac[rm][u] / (aurac[rm][3]+.1) - bak[u]) * cmul[z];
}
for(int u=0; u<4; u++) glcoords[u][2] = stereo::scrdist;
for(int u=0; u<4; u++) coltab[u][3] = 1;
auravertices.clear();
for(int r=0; r<AURA; r++) for(int z=0;z<10;z++) {
for(int c=0; c<4; c++) {
int br = (c == 1 || c == 2) ? r+1 : r;
int bz = (c == 3 || c == 2) ? z+1 : z;
glcoords[c][0] = cx[br][bz][0];
glcoords[c][1] = cx[br][bz][1];
coltab[c][0] = min<float>(cx[br][bz][2], 1);
coltab[c][1] = min<float>(cx[br][bz][3], 1);
coltab[c][2] = min<float>(cx[br][bz][4], 1);
for(int c=0; c<6; c++) {
int br = (c == 1 || c == 3 || c == 5) ? r+1 : r;
int bz = (c == 2 || c == 4 || c == 5) ? z+1 : z;
auravertices.emplace_back(
cx[br][bz][0], cx[br][bz][1], cx[br][bz][2], cx[br][bz][3], cx[br][bz][4]
);
}
glDrawArrays(GL_TRIANGLE_FAN, 0, 4);
}
glhr::switch_mode(glhr::gmVarColored);
glhr::set_modelview(glhr::id());
glhr::prepare(auravertices);
glDrawArrays(GL_TRIANGLES, 0, size(auravertices));
setcameraangle(false);
#endif
@ -3118,7 +3112,7 @@ void warpfloor(cell *c, const transmatrix& V, int col, int prio, bool warp) {
if(shmup::on || nonbitrunc) warp = false;
#if CAP_TEXTURE
if(qfi.tinf) {
queuetable(V*qfi.spin, &qfi.tinf->vertices[0], size(qfi.tinf->vertices) / 3, 0, texture::recolor(col), prio);
queuetable(V*qfi.spin, qfi.tinf->vertices, size(qfi.tinf->vertices), 0, texture::recolor(col), prio);
lastptd().u.poly.tinf = qfi.tinf;
}
else

16
hyper.h
View File

@ -2020,12 +2020,16 @@ void drawqueue();
typedef float GLfloat;
#endif
typedef array<GLfloat, 3> glvec3;
typedef array<GLfloat, 4> glvec4;
typedef glvec3 glvertex;
struct textureinfo {
transmatrix M;
int texture_id;
vector<array<hyperpoint, 3>> triangles;
vector<GLfloat> vertices;
vector<GLfloat> tvertices;
vector<glvertex> vertices;
vector<glvertex> tvertices;
cell *c;
vector<transmatrix> matrices;
@ -2035,9 +2039,8 @@ struct textureinfo {
struct qpoly {
transmatrix V;
GLfloat *tab;
int curveindex;
int cnt;
const vector<glvertex> *tab;
int offset, cnt;
int outline;
double minwidth;
int flags;
@ -2668,3 +2671,6 @@ string helptitle(string s, int col);
pair<int, int> cell_to_pair(cell *c);
extern bool nohud, nofps;
template<class T> array<T, 3> make_array(T a, T b, T c) { array<T,3> x; x[0] = a; x[1] = b; x[2] = c; return x; }
template<class T> array<T, 2> make_array(T a, T b) { array<T,2> x; x[0] = a; x[1] = b; return x; }

View File

@ -11,6 +11,7 @@
#define CAP_SDLTTF 0
#define CAP_SHMUP 0
#define CAP_RUG 1
#define GLES_ONLY
#ifdef FAKEWEB
void mainloopiter();
@ -62,7 +63,7 @@ void showDemo() {
dialog::addItem(XLAT("play"), 'f');
dialog::addItem(XLAT("tutorial"), 'T');
dialog::addItem(XLAT("help"), 'h'); dialog::lastItem().keycaption += " / F1";
dialog::addItem(XLAT("toggle high detail"), 'a');
// dialog::addItem(XLAT("toggle high detail"), 'a');
dialog::addBreak(100);
dialog::addTitle("highlights", 0xC00000, 120);
@ -110,7 +111,8 @@ void showDemo() {
}
void initweb() {
toggleanim(false);
// pushScreen(showDemo);
rug::renderonce = true;
// toggleanim(false);
pushScreen(showDemo);
}

View File

@ -315,12 +315,12 @@ typedef unsigned int Uint32;
#endif
#if ISWEB
inline Uint8 *SDL_GetKeyState(void *v) { static Uint8 tab[1024]; return tab; }
extern "C" {
Uint8 *SDL_GetKeyState(void*);
}
// inline Uint8 *SDL_GetKeyState(void *v) { static Uint8 tab[1024]; return tab; }
#endif
/* extern "C" {
Uint8 *SDL_GetKeyState(void*);
} */
#ifndef CAP_GLEW
#define CAP_GLEW (CAP_GL && !ISMOBILE && !ISMAC && !ISLINUX && !ISWEB)
@ -645,8 +645,6 @@ int getticks();
void shareScore(MOBPAR_FORMAL);
#endif
int mobile_xres, mobile_yres;
void mobile_draw(MOBPAR_FORMAL) {
optimizeview();

View File

@ -1128,7 +1128,7 @@ namespace mapeditor {
dsCur->rots = 1;
for(auto& v: symmetriesAt)
if(p.tab == &ourshape[v[0]*3]) {
if(v[0] == p.offset) {
dsCur->rots = v[1];
dsCur->sym = v[2] == 2;
}
@ -1136,7 +1136,7 @@ namespace mapeditor {
int d = dsCur->rots * (dsCur->sym ? 2 : 1);
for(int i=0; i < cnt/d; i++)
dsCur->list.push_back(p.V * hpxyz(p.tab[3*i], p.tab[3*i+1], p.tab[3*i+2]));
dsCur->list.push_back(p.V * glhr::gltopoint((*p.tab)[i+p.offset]));
layer++;
if(layer == USERLAYERS) break;

View File

@ -108,45 +108,16 @@ SDL_Surface *aux;
vector<polytodraw*> ptds2;
#define POLYMAX 60000
GLfloat glcoords[POLYMAX][3];
int qglcoords;
GLfloat *ourshape = NULL;
vector<array<GLfloat, 3>> glcoords, ourshape;
void initPolyForGL() {
ourshape.clear();
if(ourshape) delete[] ourshape;
ourshape = new GLfloat[3 * qhpc];
for(int i=0; i<qhpc; i++)
ourshape.push_back(make_array<GLfloat>(hpc[i][0], hpc[i][1], hpc[i][2]));
// GLfloat ourshape[3*qhpc];
int id = 0;
for(int i=0; i<qhpc; i++) {
ourshape[id++] = hpc[i][0];
ourshape[id++] = hpc[i][1];
ourshape[id++] = hpc[i][2];
}
#if CAP_GL
glhr::currentvertices = NULL;
#endif
}
#endif
#if CAP_GL
GLuint shapebuffer;
extern GLfloat *ourshape;
void activateShapes() {
if(glhr::currentvertices != ourshape) {
glhr::vertices(ourshape, qhpc);
}
}
void activateGlcoords() {
glhr::vertices(glcoords[0], qglcoords);
glhr::store_in_buffer(ourshape);
}
#endif
@ -157,21 +128,13 @@ int polyx[POLYMAX], polyxr[POLYMAX], polyy[POLYMAX];
int poly_flags;
hyperpoint gltopoint(GLfloat t[3]) {
hyperpoint h;
h[0] = t[0]; h[1] = t[1]; h[2] = t[2];
return h;
}
void add1(const hyperpoint& H) {
for(int i=0; i<3; i++) glcoords[qglcoords][i] = H[i];
glcoords.push_back(make_array<GLfloat>(H[0], H[1], H[2]));
}
int spherespecial, spherephase;
void addpoint(const hyperpoint& H) {
if(qglcoords >= POLYMAX) return;
if(true) {
hyperpoint Hscr;
applymodel(H, Hscr);
@ -201,11 +164,10 @@ void addpoint(const hyperpoint& H) {
glcoords[qglcoords][2] += vid.alpha;
// glcoords[qglcoords][2] = 1; // EUCSCALE;
} */
qglcoords++;
}
void coords_to_poly() {
polyi = qglcoords;
polyi = size(glcoords);
for(int i=0; i<polyi; i++) {
// printf("%lf %lf\n", double(glcoords[i][0]), double(glcoords[i][1]));
@ -215,11 +177,9 @@ void coords_to_poly() {
}
}
void addpoly(const transmatrix& V, GLfloat *tab, int cnt) {
while(cnt--) {
addpoint(V*gltopoint(tab));
tab += 3;
}
void addpoly(const transmatrix& V, const vector<glvertex> &tab, int ofs, int cnt) {
for(int i=ofs; i<ofs+cnt; i++)
addpoint(V*glhr::gltopoint(tab[i]));
}
#if CAP_SDLGFX
@ -241,9 +201,9 @@ void filledPolygonColorI(SDL_Surface *s, int* px, int *py, int polyi, int col) {
#endif
#if CAP_TEXTURE
void drawTexturedTriangle(SDL_Surface *s, int *px, int *py, GLfloat *tv, int col) {
void drawTexturedTriangle(SDL_Surface *s, int *px, int *py, glvertex *tv, int col) {
transmatrix source = {{{ld(px[0]),ld(px[1]),ld(px[2])}, {ld(py[0]),ld(py[1]),ld(py[2])}, {1,1,1}}};
transmatrix target = {{{tv[0],tv[3],tv[6]}, {tv[1],tv[4],tv[7]}, {1,1,1}}};
transmatrix target = {{{tv[0][0],tv[1][0],tv[2][0]}, {tv[0][1],tv[1][1],tv[2][1]}, {1,1,1}}};
transmatrix isource = inverse(source);
int minx = px[0], maxx = px[0];
int miny = py[0], maxy = py[0];
@ -299,36 +259,41 @@ void glapplymatrix(const transmatrix& V) {
glhr::set_modelview(glhr::as_glmatrix(mat));
}
int tinfshift;
void gldraw(int useV, const transmatrix& V, int ps, int pq, int col, int outline, int flags, textureinfo *tinf) {
void setmatrix(int useV, const transmatrix& V) {
if(useV == 1) {
glapplymatrix(V);
}
else if(useV == 3) {
GLfloat mat[16] = {
1, 0, 0, 0,
0, 1, 0, 0,
0, 0, 0, 0,
0, 0, stereo::scrdist, 1
};
glhr::set_modelview(glhr::as_glmatrix(mat));
}
else
glhr::set_modelview(glhr::id());
}
void gldraw(int useV, const transmatrix& V, const vector<glvertex>& v, int ps, int pq, int col, int outline, int flags, textureinfo *tinf) {
if(tinf) {
#if CAP_TEXTURE
glhr::be_textured();
glBindTexture(GL_TEXTURE_2D, tinf->texture_id);
glhr::texture_vertices(&tinf->tvertices[tinfshift], 0, 3);
glhr::vertices_texture(v, tinf->tvertices);
#endif
}
else {
glhr::vertices(v);
glhr::be_nontextured();
}
else glhr::be_nontextured();
for(int ed = stereo::active() ? -1 : 0; ed<2; ed+=2) {
if(ed) stereo::set_projection(ed), stereo::set_viewport(ed);
bool draw = col;
again:
if(useV == 1) {
glapplymatrix(V);
}
else if(useV == 3) {
GLfloat mat[16] = {
1, 0, 0, 0,
0, 1, 0, 0,
0, 0, 0, 0,
0, 0, stereo::scrdist, 1
};
glhr::set_modelview(glhr::as_glmatrix(mat));
}
else
glhr::set_modelview(glhr::id());
setmatrix(useV, V);
if(draw) {
glEnable(GL_STENCIL_TEST);
@ -346,16 +311,17 @@ void gldraw(int useV, const transmatrix& V, int ps, int pq, int col, int outline
glStencilFunc( GL_NOTEQUAL, 1, 1);
GLfloat xx = vid.xres;
GLfloat yy = vid.yres;
GLfloat scr[12] = {
-xx, -yy, stereo::scrdist, +xx, -yy, stereo::scrdist,
+xx, +yy, stereo::scrdist, -xx, +yy, stereo::scrdist
vector<glvertex> scr = {
make_array<GLfloat>(-xx, -yy, stereo::scrdist),
make_array<GLfloat>(+xx, -yy, stereo::scrdist),
make_array<GLfloat>(+xx, +yy, stereo::scrdist),
make_array<GLfloat>(-xx, +yy, stereo::scrdist)
};
GLfloat *cur = glhr::currentvertices;
glhr::vertices(scr, 4);
glhr::vertices(scr);
glhr::set_modelview(glhr::id());
glDrawArrays(tinf ? GL_TRIANGLES : GL_TRIANGLE_FAN, 0, 4);
glhr::vertices(cur, 0);
draw = false; goto again;
glhr::vertices(v);
setmatrix(useV, V);
}
else {
stereo::set_mask(ed);
@ -408,7 +374,7 @@ void fixMercator(bool tinf) {
if(mercator_coord)
swap(cmin, dmin), swap(cmax, dmax);
for(int i = 0; i<qglcoords; i++) {
for(int i = 0; i<size(glcoords); i++) {
while(glcoords[0][mercator_coord] < hperiod) glcoords[0][mercator_coord] += period;
while(glcoords[0][mercator_coord] > hperiod) glcoords[0][mercator_coord] -= period;
}
@ -418,7 +384,7 @@ void fixMercator(bool tinf) {
ld mincoord = first, maxcoord = first;
for(int i = 0; i<qglcoords; i++) {
for(int i = 0; i<size(glcoords); i++) {
while(glcoords[i][mercator_coord] < next - hperiod)
glcoords[i][mercator_coord] += period;
while(glcoords[i][mercator_coord] > next + hperiod)
@ -449,33 +415,27 @@ void fixMercator(bool tinf) {
mercator_loop_max--; return;
}
if(last < first) {
reverse(glcoords, glcoords+qglcoords);
reverse(glcoords.begin(), glcoords.end());
swap(first, last);
}
while(maxcoord > cmin) {
for(int i=0; i<qglcoords; i++) glcoords[i][mercator_coord] -= period;
for(int i=0; i<size(glcoords); i++) glcoords[i][mercator_coord] -= period;
first -= period; last -= period;
mincoord -= period; maxcoord -= period;
}
int base = qglcoords;
int base = size(glcoords);
int minto = mincoord;
while(minto < cmax) {
for(int i=0; i<base; i++) {
for(int c=0; c<3; c++)
glcoords[qglcoords][c] = glcoords[qglcoords-base][c];
glcoords[qglcoords][mercator_coord] += period;
qglcoords++;
glcoords.push_back(glcoords[size(glcoords)-base]);
glcoords.back()[mercator_coord] += period;
}
minto += period;
}
for(int r=0; r<3; r++)
glcoords[qglcoords][r] = glcoords[qglcoords-1][r];
qglcoords++;
for(int r=0; r<3; r++)
glcoords[qglcoords][r] = glcoords[0][r];
qglcoords++;
glcoords.push_back(glcoords.back());
glcoords.push_back(glcoords[0]);
for(int u=1; u<=2; u++) {
auto& v = glcoords[qglcoords-u][1-mercator_coord];
auto& v = glcoords[size(glcoords)-u][1-mercator_coord];
v = v < 0 ? dmin : dmax;
}
/* printf("cycling %d -> %d\n", base, qglcoords);
@ -495,13 +455,11 @@ void drawpolyline(polytodraw& p) {
int i = pp.cnt;
pp.cnt = 3;
for(int j=0; j<i; j+=3) {
pp.offset = j;
drawpolyline(p);
pp.tab += 9;
tinfshift += 9;
}
pp.tab -= 3*i;
tinfshift = 0;
pp.cnt = i;
pp.offset = 0;
return;
}
@ -514,17 +472,13 @@ void drawpolyline(polytodraw& p) {
#if CAP_GL
if(vid.usingGL && pmodel == mdDisk && !spherespecial) {
const int pq = pp.cnt;
if(glhr::currentvertices != pp.tab)
glhr::vertices(pp.tab, pq);
const int ps=0;
glLineWidth(linewidthat(tC0(pp.V), pp.minwidth));
gldraw(1, pp.V, ps, pq, p.col, pp.outline, 0, pp.tinf);
gldraw(1, pp.V, *pp.tab, pp.offset, pp.cnt, p.col, pp.outline, 0, pp.tinf);
return;
}
#endif
qglcoords = 0;
glcoords.clear();
poly_flags = pp.flags;
double d = 0, curradius = 0;
@ -536,7 +490,7 @@ void drawpolyline(polytodraw& p) {
/* pp.outline = 0x80808080;
p.col = 0; */
addpoly(pp.V, pp.tab, pp.cnt);
addpoly(pp.V, *pp.tab, pp.offset, pp.cnt);
mercator_loop_min = mercator_loop_max = 0;
if(sphere && pmodel == mdBand)
@ -546,16 +500,16 @@ void drawpolyline(polytodraw& p) {
if(poly_flags & POLY_BEHIND) return;
if(0) for(int i=0; i<qglcoords; i++) {
if(abs(glcoords[i][0]) > poly_limit || abs(glcoords[i][1]) > poly_limit)
if(0) for(auto& p: glcoords) {
if(abs(p[0]) > poly_limit || abs(p[1]) > poly_limit)
return; // too large!
}
if((spherespecial > 0 || (sphere && mdEqui())) && !(poly_flags & POLY_ISSIDE)) {
double rarea = 0;
for(int i=0; i<qglcoords-1; i++)
for(int i=0; i<size(glcoords)-1; i++)
rarea += glcoords[i][0] * glcoords[i+1][1] - glcoords[i][1] * glcoords[i+1][0];
rarea += glcoords[qglcoords-1][0] * glcoords[0][1] - glcoords[qglcoords-1][1] * glcoords[0][0];
rarea += glcoords.back()[0] * glcoords[0][1] - glcoords.back()[1] * glcoords[0][0];
if(d < 0) poly_flags ^= POLY_INVERSE;
@ -577,7 +531,7 @@ void drawpolyline(polytodraw& p) {
for(int l=mercator_loop_min; l <= mercator_loop_max; l++) {
if(l || lastl) {
for(int i=0; i<qglcoords; i++)
for(int i=0; i<size(glcoords); i++)
glcoords[i][mercator_coord] += vid.radius * 4 * (l - lastl);
lastl = l;
}
@ -586,10 +540,7 @@ void drawpolyline(polytodraw& p) {
ld h = atan2(glcoords[0][0], glcoords[0][1]);
for(int i=0; i<=360; i++) {
ld a = i * M_PI / 180 + h;
glcoords[qglcoords][0] = vid.radius * sin(a);
glcoords[qglcoords][1] = vid.radius * cos(a);
glcoords[qglcoords][2] = stereo::scrdist;
qglcoords++;
glcoords.push_back(make_array<GLfloat>(vid.radius * sin(a), vid.radius * cos(a), stereo::scrdist));
}
poly_flags ^= POLY_INVERSE;
}
@ -600,8 +551,7 @@ void drawpolyline(polytodraw& p) {
if(pp.tinf && (poly_flags & POLY_INVERSE)) {
return;
}
activateGlcoords();
gldraw(3, Id, 0, qglcoords, p.col, pp.outline, poly_flags, pp.tinf);
gldraw(3, Id, glcoords, 0, size(glcoords), p.col, pp.outline, poly_flags, pp.tinf);
continue;
}
#endif
@ -627,7 +577,7 @@ void drawpolyline(polytodraw& p) {
#if CAP_TEXTURE
if(!(poly_flags & POLY_INVERSE))
for(int i=0; i<polyi; i += 3)
drawTexturedTriangle(s, polyx+i, polyy+i, &pp.tinf->tvertices[tinfshift + i*3], p.col);
drawTexturedTriangle(s, polyx+i, polyy+i, &pp.tinf->tvertices[pp.offset + i], p.col);
#endif
}
else if(poly_flags & POLY_INVERSE) {
@ -665,10 +615,10 @@ void drawpolyline(polytodraw& p) {
}
}
vector<float> prettylinepoints;
vector<glvertex> prettylinepoints;
void prettypoint(const hyperpoint& h) {
for(int i=0; i<3; i++) prettylinepoints.push_back(h[i]);
prettylinepoints.push_back(glhr::pointtogl(h));
}
void prettylinesub(const hyperpoint& h1, const hyperpoint& h2, int lev) {
@ -687,7 +637,8 @@ void prettyline(hyperpoint h1, hyperpoint h2, int col, int lev) {
polytodraw p;
auto& pp = p.u.poly;
pp.V = Id;
pp.tab = &prettylinepoints[0];
pp.tab = &prettylinepoints;
pp.offset = 0;
pp.cnt = size(prettylinepoints)/3;
pp.minwidth = minwidth_global;
p.col = 0;
@ -705,7 +656,8 @@ void prettypoly(const vector<hyperpoint>& t, int fillcol, int linecol, int lev)
polytodraw p;
auto& pp = p.u.poly;
pp.V = Id;
pp.tab = &prettylinepoints[0];
pp.tab = &prettylinepoints;
pp.offset = 0;
pp.cnt = size(prettylinepoints)/3;
pp.minwidth = minwidth_global;
p.col = fillcol;
@ -715,7 +667,7 @@ void prettypoly(const vector<hyperpoint>& t, int fillcol, int linecol, int lev)
drawpolyline(p);
}
vector<GLfloat> curvedata;
vector<glvertex> curvedata;
int curvestart = 0;
bool keep_curvedata = false;
@ -738,8 +690,6 @@ void drawqueueitem(polytodraw& ptd) {
break;
case pkPoly:
if(ptd.u.poly.curveindex >= 0)
ptd.u.poly.tab = &curvedata[ptd.u.poly.curveindex];
drawpolyline(ptd);
break;
@ -2300,9 +2250,9 @@ void queuepolyat(const transmatrix& V, const hpcshape& h, int col, int prio) {
polytodraw& ptd = nextptd();
ptd.kind = pkPoly;
ptd.u.poly.V = V;
ptd.u.poly.offset = h.s;
ptd.u.poly.cnt = h.e-h.s;
ptd.u.poly.tab = &ourshape[3*h.s];
ptd.u.poly.curveindex = -1;
ptd.u.poly.tab = &ourshape;
if(cblind) {
// protanopia
/* int r = (56 * part(col,3) + 43 * part(col,2)) / 100;
@ -2336,13 +2286,13 @@ void queuereset(eModel md, int prio) {
ptd.prio = prio << PSHIFT;
}
void queuetable(const transmatrix& V, GLfloat *f, int cnt, int linecol, int fillcol, int prio) {
void queuetable(const transmatrix& V, const vector<glvertex>& f, int cnt, int linecol, int fillcol, int prio) {
polytodraw& ptd = nextptd();
ptd.kind = pkPoly;
ptd.u.poly.V = V;
ptd.u.poly.tab = &f;
ptd.u.poly.offset = 0;
ptd.u.poly.cnt = cnt;
ptd.u.poly.tab = f;
ptd.u.poly.curveindex = -1;
ptd.col = fillcol;
ptd.prio = prio << PSHIFT;
ptd.u.poly.outline = linecol;
@ -2419,14 +2369,12 @@ void qfloor(cell *c, const transmatrix& V, const transmatrix& Vspin, const hpcsh
}
void curvepoint(const hyperpoint& H1) {
curvedata.push_back(H1[0]);
curvedata.push_back(H1[1]);
curvedata.push_back(H1[2]);
curvedata.push_back(glhr::pointtogl(H1));
}
void queuecurve(int linecol, int fillcol, int prio) {
queuetable(Id, &curvedata[curvestart], (size(curvedata)-curvestart)/3, linecol, fillcol, prio);
lastptd().u.poly.curveindex = curvestart;
queuetable(Id, curvedata, size(curvedata)-curvestart, linecol, fillcol, prio);
lastptd().u.poly.offset = curvestart;
curvestart = size(curvedata);
}

View File

@ -75,8 +75,15 @@ renderbuffer::renderbuffer(int x, int y, bool gl) : x(x), y(y) {
glBindRenderbuffer(GL_RENDERBUFFER, depth_stencil_rb);
GLERR("BindRenderbuffer");
glRenderbufferStorage(GL_RENDERBUFFER, GL_DEPTH24_STENCIL8, tx, ty);
bool has_depth = true;
if(glGetError() != GL_NO_ERROR) {
printf("Could not create: GL_DEPTH24_STENCIL8");
glRenderbufferStorage(GL_RENDERBUFFER, GL_STENCIL_INDEX8, tx, ty);
has_depth = false;
}
GLERR("RbS");
glFramebufferRenderbuffer(GL_FRAMEBUFFER, GL_DEPTH_ATTACHMENT, GL_RENDERBUFFER, depth_stencil_rb);
if(has_depth)
glFramebufferRenderbuffer(GL_FRAMEBUFFER, GL_DEPTH_ATTACHMENT, GL_RENDERBUFFER, depth_stencil_rb);
glFramebufferRenderbuffer(GL_FRAMEBUFFER, GL_STENCIL_ATTACHMENT, GL_RENDERBUFFER, depth_stencil_rb);
GLERR("FrRb");

48
rug.cpp
View File

@ -995,7 +995,7 @@ bool project_ods(hyperpoint azeq, hyperpoint& h1, hyperpoint& h2, bool eye) {
}
#endif
vector<GLfloat> vertex_array, tvertex_array, color_array;
vector<glhr::ct_vertex> ct_array;
void drawTriangle(triangle& t) {
using namespace hyperpoint_vec;
@ -1070,21 +1070,8 @@ void drawTriangle(triangle& t) {
ld col = (2 + hc[0]/hch) / 3;
#if !CAP_SHADER
glNormal3f(hc[0]/hch,hc[1]/hch,hc[2]/hch);
#endif
for(int i: {0,1,2}) {
tvertex_array.push_back(t.m[i]->x1);
tvertex_array.push_back(t.m[i]->y1);
for(int j: {0,1,2})
vertex_array.push_back(h[i][j]);
#if CAP_SHADER
for(int a=0; a<3; a++) color_array.push_back(col);
color_array.push_back(1);
#endif
}
for(int i: {0,1,2})
ct_array.emplace_back(h[i], t.m[i]->x1, t.m[i]->y1, col);
}
renderbuffer *glbuf;
@ -1143,9 +1130,7 @@ void drawRugScene() {
for(int ed=stereo::active() && stereo::mode != stereo::sODS ? -1 : 0; ed < 2; ed += 2) {
use_precompute = false;
vertex_array.clear();
tvertex_array.clear();
color_array.clear();
ct_array.clear();
stereo::set_mask(ed), stereo::set_viewport(ed);
if(ed == 1 && stereo::mode == stereo::sAnaglyph)
glClear(GL_DEPTH_BUFFER_BIT);
@ -1190,18 +1175,13 @@ void drawRugScene() {
gwhere == gElliptic && rug_perspective ? 4 :
100
);
glhr::set_modelview(glhr::id());
for(int t=0; t<size(triangles); t++)
drawTriangle(triangles[t]);
glhr::vertices(&vertex_array[0], 0);
glhr::texture_vertices(&tvertex_array[0], 0);
#if CAP_SHADER
glhr::color_vertices(&color_array[0], 0);
#endif
glDrawArrays(GL_TRIANGLES, 0, size(vertex_array)/3);
glhr::set_modelview(glhr::id());
glhr::prepare(ct_array);
glDrawArrays(GL_TRIANGLES, 0, size(ct_array));
stereo::set_mask(0);
}
@ -1293,6 +1273,8 @@ void move_forward(ld distance) {
else model_distance /= exp(distance);
}
#define CAP_HOLDKEYS CAP_SDL // && !ISWEB)
bool handlekeys(int sym, int uni) {
if(uni == '4') {
#if CAP_ODS
@ -1321,7 +1303,7 @@ bool handlekeys(int sym, int uni) {
apply_rotation(rotmatrix(M_PI/2, 0, 2));
return true;
}
#if !CAP_SDL
#if !CAP_HOLDKEYS
else if(uni == SDLK_PAGEUP || uni == '[') {
move_forward(.1);
return true;
@ -1330,6 +1312,12 @@ bool handlekeys(int sym, int uni) {
move_forward(-.1);
return true;
}
else if(uni == SDLK_HOME) { apply_rotation(rotmatrix(.1, 0, 1)); return true; }
else if(uni == SDLK_END) { apply_rotation(rotmatrix(.1, 1, 0)); return true; }
else if(uni == SDLK_DOWN) { apply_rotation(rotmatrix(.1, 2, 1)); return true; }
else if(uni == SDLK_UP) { apply_rotation(rotmatrix(.1, 1, 2)); return true; }
else if(uni == SDLK_LEFT) { apply_rotation(rotmatrix(.1, 2, 0)); return true; }
else if(uni == SDLK_RIGHT) { apply_rotation(rotmatrix(.1, 0, 2)); return true; }
#endif
else return false;
}
@ -1362,7 +1350,7 @@ void actDraw() {
}
#endif
#if CAP_SDL
#if CAP_HOLDKEYS
Uint8 *keystate = SDL_GetKeyState(NULL);
int qm = 0;
double alpha = (ticks - lastticks) / 1000.0;

View File

@ -13,10 +13,18 @@ void glError(const char* GLcall, const char* file, const int line) {
}
}
#define CAP_VERTEXBUFFER (!ISWEB)
namespace glhr {
bool glew = false;
typedef const void *constvoidptr;
constvoidptr current_vertices, buffered_vertices;
GLuint buf_current, buf_buffered;
enum eMode { gmColored, gmTextured, gmVarColored, gmLightFog, gmMAX};
static const flagtype GF_TEXTURE = 1;
@ -294,34 +302,6 @@ void set_modelview(const glmatrix& modelview) {
#endif
GLfloat *currentvertices;
void vertices(GLfloat *f, int qty) {
currentvertices = f;
#if CAP_SHADER
glVertexAttribPointer(aPosition, 3, GL_FLOAT, GL_FALSE, 3 * sizeof(GLfloat), f);
#else
glVertexPointer(3, GL_FLOAT, 0, f);
#endif
// #endif
}
void texture_vertices(GLfloat *f, int qty, int stride = 2) {
#if CAP_SHADER
glVertexAttribPointer(aTexture, stride, GL_FLOAT, GL_FALSE, stride * sizeof(GLfloat), f);
#else
glTexCoordPointer(stride, GL_FLOAT, 0, f);
#endif
}
void color_vertices(GLfloat *f, int qty) {
#if CAP_SHADER
glVertexAttribPointer(aColor, 4, GL_FLOAT, GL_FALSE, 4 * sizeof(GLfloat), f);
#else
glColorPointer(4, GL_FLOAT, 0, f);
#endif
}
void color2(int color, ld part = 1) {
unsigned char *c = (unsigned char*) (&color);
GLfloat cols[4];
@ -421,6 +401,7 @@ void switch_mode(eMode m) {
}
mode = m;
GLERR("after_switch_mode");
current_vertices = NULL;
}
void fog_max(ld fogmax) {
@ -503,6 +484,179 @@ void init() {
glEnableClientState(GL_VERTEX_ARRAY);
#endif
// #endif
#if CAP_VERTEXBUFFER
glGenBuffers(1, &buf_current);
glGenBuffers(1, &buf_buffered);
current_vertices = NULL;
buffered_vertices = (void*) &buffered_vertices; // point to nothing
glBindBuffer(GL_ARRAY_BUFFER, buf_current);
#endif
}
hyperpoint gltopoint(const glvertex& t) {
hyperpoint h;
h[0] = t[0]; h[1] = t[1]; h[2] = t[2];
return h;
}
glvertex pointtogl(const hyperpoint& t) {
glvertex h;
h[0] = t[0]; h[1] = t[1]; h[2] = t[2];
return h;
}
struct colored_vertex {
glvec3 coords;
glvec4 color;
colored_vertex(GLfloat x, GLfloat y, GLfloat r, GLfloat g, GLfloat b) {
coords[0] = x;
coords[1] = y;
coords[2] = stereo::scrdist;
color[0] = r;
color[1] = g;
color[2] = b;
color[3] = 1;
}
};
struct textured_vertex {
glvec3 coords;
glvec3 texture;
};
struct ct_vertex {
glvec3 coords;
glvec4 color;
glvec3 texture;
ct_vertex(const hyperpoint& h, ld x1, ld y1, ld col) {
coords = pointtogl(h);
texture[0] = x1;
texture[1] = y1;
color[0] = color[1] = color[2] = col;
color[3] = 1;
}
};
#if CAP_VERTEXBUFFER
template<class T> void bindbuffer(T& v) {
if(current_vertices == buffered_vertices) {
glBindBuffer(GL_ARRAY_BUFFER, buf_current);
}
current_vertices = &v[0];
glBufferData(GL_ARRAY_BUFFER, size(v) * sizeof(v[0]), &v[0], GL_DYNAMIC_DRAW);
}
#define PTR(attrib, q, field) \
glVertexAttribPointer(attrib, q, GL_FLOAT, GL_FALSE, sizeof(v[0]), (void*) ((char*) &v[0].field - (char*) &v[0]));
#endif
void vertices(const vector<glvertex>& v) {
#if CAP_VERTEXBUFFER
if(&v[0] == buffered_vertices) {
if(&v[0] == current_vertices) return;
current_vertices = buffered_vertices;
glBindBuffer(GL_ARRAY_BUFFER, buf_buffered);
glBufferData(GL_ARRAY_BUFFER, size(v) * sizeof(v[0]), &v[0], GL_STATIC_DRAW);
glVertexAttribPointer(glhr::aPosition, 3, GL_FLOAT, GL_FALSE, sizeof(glvertex), 0);
return;
}
bindbuffer(v);
glVertexAttribPointer(glhr::aPosition, 3, GL_FLOAT, GL_FALSE, sizeof(glvertex), 0);
#else
if(current_vertices == &v[0]) return;
current_vertices = &v[0];
#if CAP_SHADER
glVertexAttribPointer(aPosition, 3, GL_FLOAT, GL_FALSE, sizeof(glvertex), &v[0]);
#else
glVertexPointer(3, GL_FLOAT, sizeof(glvertex), &v[0]);
#endif
#endif
}
void vertices_texture(const vector<glvertex>& v, const vector<glvertex>& t) {
#if CAP_TEXTURE
vertices(v);
#if CAP_SHADER
glVertexAttribPointer(aTexture, 3, GL_FLOAT, GL_FALSE, sizeof(glvertex), &t[0]);
#else
glTexCoordPointer(stride, GL_FLOAT, 0, &v[0]);
#endif
#endif
}
void prepare(vector<colored_vertex>& v) {
#if CAP_VERTEXBUFFER
bindbuffer(v);
PTR(glhr::aPosition, 3, coords);
PTR(glhr::aColor, 4, color);
#else
if(current_vertices == &v[0]) return;
current_vertices = &v[0];
#if CAP_SHADER
glVertexAttribPointer(aPosition, 3, GL_FLOAT, GL_FALSE, sizeof(colored_vertex), &v[0].coords);
glVertexAttribPointer(aColor, 4, GL_FLOAT, GL_FALSE, sizeof(colored_vertex), &v[0].color);
#else
glVertexPointer(3, GL_FLOAT, sizeof(colored_vertex), &v[0].coords);
glVertexPointer(3, GL_FLOAT, sizeof(colored_vertex), &v[0].color);
#endif
#endif
}
void prepare(vector<textured_vertex>& v) {
#if CAP_VERTEXBUFFER
bindbuffer(v);
PTR(glhr::aPosition, 3, coords);
PTR(glhr::aTexture, 2, texture);
#else
if(current_vertices == &v[0]) return;
current_vertices = &v[0];
#if CAP_SHADER
glVertexAttribPointer(aPosition, 3, GL_FLOAT, GL_FALSE, sizeof(textured_vertex), &v[0].coords);
glVertexAttribPointer(aTexture, 3, GL_FLOAT, GL_FALSE, sizeof(textured_vertex), &v[0].texture);
#else
glVertexPointer(3, GL_FLOAT, sizeof(textured_vertex), &v[0].coords);
glVertexPointer(3, GL_FLOAT, sizeof(textured_vertex), &v[0].texture);
#endif
#endif
// color2(col);
}
void prepare(vector<ct_vertex>& v) {
#if CAP_VERTEXBUFFER
bindbuffer(v);
PTR(glhr::aPosition, 3, coords);
PTR(glhr::aColor, 4, color);
PTR(glhr::aTexture, 2, texture);
#else
if(current_vertices == &v[0]) return;
current_vertices = &v[0];
#if CAP_SHADER
glVertexAttribPointer(aPosition, 3, GL_FLOAT, GL_FALSE, sizeof(ct_vertex), &v[0].coords);
glVertexAttribPointer(aColor, 4, GL_FLOAT, GL_FALSE, sizeof(ct_vertex), &v[0].color);
glVertexAttribPointer(aTexture, 3, GL_FLOAT, GL_FALSE, sizeof(ct_vertex), &v[0].texture);
#else
glVertexPointer(3, GL_FLOAT, sizeof(ct_vertex), &v[0].coords);
glVertexPointer(3, GL_FLOAT, sizeof(ct_vertex), &v[0].texture);
glVertexPointer(3, GL_FLOAT, sizeof(ct_vertex), &v[0].color);
#endif
#endif
}
void store_in_buffer(vector<glvertex>& v) {
#if CAP_VERTEXBUFFER
if(!buf_buffered) {
printf("no buffer yet\n");
return;
}
printf("storing %d in buffer: %p\n", size(v), &v[0]);
current_vertices = buffered_vertices = &v[0];
glBindBuffer(GL_ARRAY_BUFFER, buf_buffered);
glVertexAttribPointer(glhr::aPosition, 3, GL_FLOAT, GL_FALSE, sizeof(glvertex), 0);
glBufferData(GL_ARRAY_BUFFER, size(v) * sizeof(glvertex), &v[0], GL_STATIC_DRAW);
printf("Stored.\n");
#endif
}
}

View File

@ -243,9 +243,6 @@ int color_alpha = 128;
int gsplits = 1;
template<class T> array<T, 3> make_array(T a, T b, T c) { array<T,3> x; x[0] = a; x[1] = b; x[2] = c; return x; }
template<class T> array<T, 2> make_array(T a, T b) { array<T,2> x; x[0] = a; x[1] = b; return x; }
void mapTextureTriangle(textureinfo &mi, array<hyperpoint, 3> v, int splits = gsplits) {
if(splits) {
@ -258,16 +255,13 @@ void mapTextureTriangle(textureinfo &mi, array<hyperpoint, 3> v, int splits = gs
}
for(int i=0; i<3; i++) {
for(int j=0; j<3; j++)
mi.vertices.push_back(v[i][j]);
mi.vertices.push_back(glhr::pointtogl(v[i]));
hyperpoint inmodel;
applymodel(mi.M * v[i], inmodel);
inmodel = itt * inmodel;
inmodel[0] *= vid.radius * 1. / vid.scrsize;
inmodel[1] *= vid.radius * 1. / vid.scrsize;
mi.tvertices.push_back((inmodel[0]+1)/2);
mi.tvertices.push_back((inmodel[1]+1)/2);
mi.tvertices.push_back(0);
mi.tvertices.push_back(make_array<GLfloat>((inmodel[0]+1)/2, (inmodel[1]+1)/2, 0));
}
}
@ -325,7 +319,7 @@ bool apply(cell *c, const transmatrix &V, int col) {
qfi.spin = applyPatterndir(c, si);
int n = mi.vertices.size() / 3;
int n = mi.vertices.size();
qfi.special = false;
qfi.shape = &shFullFloor[ctof(c)];
@ -334,10 +328,10 @@ bool apply(cell *c, const transmatrix &V, int col) {
if(chasmg == 2) return false;
else if(chasmg && wmspatial) {
if(detaillevel == 0) return false;
queuetable(V * qfi.spin, &mi.vertices[0], n, mesh_color, recolor(c->land == laCocytus ? 0x080808FF : 0x101010FF), PPR_LAKEBOTTOM);
queuetable(V * qfi.spin, mi.vertices, n, mesh_color, recolor(c->land == laCocytus ? 0x080808FF : 0x101010FF), PPR_LAKEBOTTOM);
}
else {
queuetable(V * qfi.spin, &mi.vertices[0], n, mesh_color, recolor(col), PPR_FLOOR);
queuetable(V * qfi.spin, mi.vertices, n, mesh_color, recolor(col), PPR_FLOOR);
}
lastptd().u.poly.tinf = &mi;
@ -348,7 +342,7 @@ bool apply(cell *c, const transmatrix &V, int col) {
if(texture::saving) {
// create a nicer aura for saved texture
for(int i=0; i<size(mi.tvertices); i += 9) {
for(int i=0; i<size(mi.tvertices); i += 3) {
ld p[3];
while(true) {
p[0] = hrandf();
@ -358,12 +352,12 @@ bool apply(cell *c, const transmatrix &V, int col) {
}
ld v[2] = {0,0};
for(int j=0; j<2; j++) for(int k=0; k<3; k++)
v[j] += mi.tvertices[3*k+j] * p[k];
v[j] += mi.tvertices[i+k][j] * p[k];
int vi[2] = {int(v[0] * twidth), int(v[1] * twidth)};
col = get_texture_pixel(vi[0], vi[1]);
hyperpoint h = hpxyz(mi.vertices[i], mi.vertices[i+1], mi.vertices[i+2]);
hyperpoint h = glhr::gltopoint(mi.vertices[i]);
addaura(V*h, col, 0);
}
}
@ -464,12 +458,12 @@ void saveFullTexture() {
bool newmove = false;
vector<glhr::textured_vertex> rtver(4);
void drawRawTexture() {
glhr::be_textured();
glhr::color2(0xFFFFFF20);
glhr::set_modelview(glhr::translate(0, 0, stereo::scrdist));
glBindTexture(GL_TEXTURE_2D, textureid);
vector<GLfloat> tver, sver;
for(int i=0; i<4; i++) {
int cx[4] = {2, -2, -2, 2};
int cy[4] = {2, 2, -2, -2};
@ -477,15 +471,13 @@ void drawRawTexture() {
int y = cy[i];
hyperpoint inmodel = hpxyz(x, y, 1);
inmodel = itt * inmodel;
tver.push_back((inmodel[0]+1)/2);
tver.push_back((inmodel[1]+1)/2);
tver.push_back(0);
sver.push_back(x * vid.scrsize);
sver.push_back(y * vid.scrsize);
sver.push_back(0);
rtver[i].texture[0] = (inmodel[0]+1)/2;
rtver[i].texture[1] = (inmodel[1]+1)/2;
rtver[i].coords[0] = x * vid.scrsize;
rtver[i].coords[1] = y * vid.scrsize;
}
glhr::vertices(&sver[0], 4);
glhr::texture_vertices(&tver[0], 4, 3);
glhr::set_modelview(glhr::translate(0, 0, stereo::scrdist));
glhr::prepare(rtver);
glDrawArrays(GL_TRIANGLE_FAN, 0, 4);
}
@ -1263,7 +1255,7 @@ void remap(eTextureState old_tstate, eTextureState old_tstate_max) {
auto& mi = texture_map_orig.at(oldid);
int ncurr = size(mi.tvertices);
int ntarget = ncurr * c->type / mi.current_type;
vector<GLfloat> new_tvertices = mi.tvertices;
vector<glvertex> new_tvertices = mi.tvertices;
new_tvertices.resize(ntarget);
for(int i=ncurr; i<ntarget; i++) {
new_tvertices[i] = new_tvertices[i - ncurr];