mirror of
https://github.com/zenorogue/hyperrogue.git
synced 2025-05-05 08:44:07 +00:00
ray:: partially works in web
This commit is contained in:
parent
052854ec74
commit
ade824e97c
4
glhr.cpp
4
glhr.cpp
@ -694,6 +694,10 @@ template<class T> void bindbuffer(T& v) {
|
|||||||
#define PTR(attrib, q, field) \
|
#define PTR(attrib, q, field) \
|
||||||
glVertexAttribPointer(attrib, q, GL_FLOAT, GL_FALSE, sizeof(v[0]), (void*) ((char*) &v[0].field - (char*) &v[0]));
|
glVertexAttribPointer(attrib, q, GL_FLOAT, GL_FALSE, sizeof(v[0]), (void*) ((char*) &v[0].field - (char*) &v[0]));
|
||||||
|
|
||||||
|
EX void bindbuffer_vertex(vector<glvertex>& v) {
|
||||||
|
bindbuffer(v);
|
||||||
|
}
|
||||||
|
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
EX void vertices(const vector<glvertex>& v, int vshift IS(0)) {
|
EX void vertices(const vector<glvertex>& v, int vshift IS(0)) {
|
||||||
|
@ -27,7 +27,11 @@ EX ld exp_start = 1;
|
|||||||
EX ld exp_decay_exp = 4;
|
EX ld exp_decay_exp = 4;
|
||||||
EX ld exp_decay_poly = 10;
|
EX ld exp_decay_poly = 10;
|
||||||
|
|
||||||
|
#if GLES_ONLY
|
||||||
|
const int gms_limit = 16; /* enough for Bringris -- need to do better */
|
||||||
|
#else
|
||||||
const int gms_limit = 110;
|
const int gms_limit = 110;
|
||||||
|
#endif
|
||||||
|
|
||||||
EX ld maxstep_sol = .05;
|
EX ld maxstep_sol = .05;
|
||||||
EX ld maxstep_nil = .1;
|
EX ld maxstep_nil = .1;
|
||||||
@ -170,6 +174,8 @@ int deg, irays;
|
|||||||
|
|
||||||
#ifdef GLES_ONLY
|
#ifdef GLES_ONLY
|
||||||
void add(string& tgt, string type, string name, int min_index, int max_index) {
|
void add(string& tgt, string type, string name, int min_index, int max_index) {
|
||||||
|
if(min_index >= max_index) ;
|
||||||
|
else
|
||||||
if(min_index + 1 == max_index)
|
if(min_index + 1 == max_index)
|
||||||
tgt += "{ return " + name + "[" + its(min_index) + "]; }";
|
tgt += "{ return " + name + "[" + its(min_index) + "]; }";
|
||||||
else {
|
else {
|
||||||
@ -193,6 +199,11 @@ string build_getter(string type, string name, int index) {
|
|||||||
#define GET(array, index) array "[" index "]"
|
#define GET(array, index) array "[" index "]"
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
|
void replace_str(string& s, string a, string b) {
|
||||||
|
while(s.find(a) != string::npos)
|
||||||
|
s.replace(s.find(a), isize(a), b);
|
||||||
|
}
|
||||||
|
|
||||||
EX hookset<void(string&, string&)> hooks_rayshader;
|
EX hookset<void(string&, string&)> hooks_rayshader;
|
||||||
EX hookset<bool(shared_ptr<raycaster>)> hooks_rayset;
|
EX hookset<bool(shared_ptr<raycaster>)> hooks_rayset;
|
||||||
|
|
||||||
@ -216,6 +227,7 @@ void enable_raycaster() {
|
|||||||
bool use_reflect = reflect_val && !nil && !levellines;
|
bool use_reflect = reflect_val && !nil && !levellines;
|
||||||
|
|
||||||
bool bi = arcm::in() || kite::in() || arb::in() || !PURE;
|
bool bi = arcm::in() || kite::in() || arb::in() || !PURE;
|
||||||
|
bi = false;
|
||||||
|
|
||||||
string vsh =
|
string vsh =
|
||||||
"attribute mediump vec4 aPosition;\n"
|
"attribute mediump vec4 aPosition;\n"
|
||||||
@ -456,7 +468,7 @@ void enable_raycaster() {
|
|||||||
|
|
||||||
fmain += "for(int i="+its(flat1)+"; i<"+(prod ? "sides-2" : WDIM == 2 ? "sides" : its(flat2))+"; i++) {\n";
|
fmain += "for(int i="+its(flat1)+"; i<"+(prod ? "sides-2" : WDIM == 2 ? "sides" : its(flat2))+"; i++) {\n";
|
||||||
|
|
||||||
fmain += "int woi = walloffset+i;\n";
|
// fmain += "int woi = walloffset+i;\n";
|
||||||
|
|
||||||
if(in_h2xe()) fmain +=
|
if(in_h2xe()) fmain +=
|
||||||
" mediump float v = ((position - uM[woi] * position)[2] / (uM[woi] * tangent - tangent)[2]);\n"
|
" mediump float v = ((position - uM[woi] * position)[2] / (uM[woi] * tangent - tangent)[2]);\n"
|
||||||
@ -498,6 +510,8 @@ void enable_raycaster() {
|
|||||||
" mediump vec4 next_position = position + d * tangent;\n"
|
" mediump vec4 next_position = position + d * tangent;\n"
|
||||||
" if(dot(next_position, tangent) < dot(uM[woi]*next_position, uM[woi]*tangent)) continue;\n";
|
" if(dot(next_position, tangent) < dot(uM[woi]*next_position, uM[woi]*tangent)) continue;\n";
|
||||||
|
|
||||||
|
replace_str(fmain, "[woi]", "[walloffset+i]");
|
||||||
|
|
||||||
fmain +=
|
fmain +=
|
||||||
" if(d < dist) { dist = d; which = i; }\n"
|
" if(d < dist) { dist = d; which = i; }\n"
|
||||||
"}\n";
|
"}\n";
|
||||||
@ -1197,12 +1211,20 @@ void bind_array(vector<array<float, 4>>& v, GLint t, GLuint& tx, int id) {
|
|||||||
if(tx == 0) glGenTextures(1, &tx);
|
if(tx == 0) glGenTextures(1, &tx);
|
||||||
|
|
||||||
glActiveTexture(GL_TEXTURE0 + id);
|
glActiveTexture(GL_TEXTURE0 + id);
|
||||||
|
GLERR("activeTexture");
|
||||||
|
|
||||||
glBindTexture(GL_TEXTURE_2D, tx);
|
glBindTexture(GL_TEXTURE_2D, tx);
|
||||||
|
GLERR("bindTexture");
|
||||||
|
|
||||||
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_NEAREST);
|
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_NEAREST);
|
||||||
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_NEAREST);
|
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_NEAREST);
|
||||||
|
GLERR("texParameteri");
|
||||||
|
|
||||||
|
#ifdef GLES_ONLY
|
||||||
|
glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA, length, isize(v)/length, 0, GL_RGBA, GL_FLOAT, &v[0]);
|
||||||
|
#else
|
||||||
glTexImage2D(GL_TEXTURE_2D, 0, 0x8814 /* GL_RGBA32F */, length, isize(v)/length, 0, GL_RGBA, GL_FLOAT, &v[0]);
|
glTexImage2D(GL_TEXTURE_2D, 0, 0x8814 /* GL_RGBA32F */, length, isize(v)/length, 0, GL_RGBA, GL_FLOAT, &v[0]);
|
||||||
|
#endif
|
||||||
GLERR("bind_array");
|
GLERR("bind_array");
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -1565,7 +1587,13 @@ EX void cast() {
|
|||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#if CAP_VERTEXBUFFER
|
||||||
|
glhr::bindbuffer_vertex(screen);
|
||||||
|
glVertexAttribPointer(hr::aPosition, 4, GL_FLOAT, GL_FALSE, sizeof(glvertex), 0);
|
||||||
|
#else
|
||||||
glVertexAttribPointer(hr::aPosition, 4, GL_FLOAT, GL_FALSE, sizeof(glvertex), &screen[0]);
|
glVertexAttribPointer(hr::aPosition, 4, GL_FLOAT, GL_FALSE, sizeof(glvertex), &screen[0]);
|
||||||
|
#endif
|
||||||
|
|
||||||
if(ray::comparison_mode)
|
if(ray::comparison_mode)
|
||||||
glhr::set_depthtest(false);
|
glhr::set_depthtest(false);
|
||||||
else {
|
else {
|
||||||
@ -1577,6 +1605,7 @@ EX void cast() {
|
|||||||
glActiveTexture(GL_TEXTURE0 + 0);
|
glActiveTexture(GL_TEXTURE0 + 0);
|
||||||
glBindTexture(GL_TEXTURE_2D, floor_textures->renderedTexture);
|
glBindTexture(GL_TEXTURE_2D, floor_textures->renderedTexture);
|
||||||
|
|
||||||
|
GLERR("bind");
|
||||||
glDrawArrays(GL_TRIANGLES, 0, 6);
|
glDrawArrays(GL_TRIANGLES, 0, 6);
|
||||||
GLERR("finish");
|
GLERR("finish");
|
||||||
}
|
}
|
||||||
|
@ -582,7 +582,7 @@ union SDL_Event;
|
|||||||
#endif
|
#endif
|
||||||
|
|
||||||
#ifndef CAP_RAY
|
#ifndef CAP_RAY
|
||||||
#define CAP_RAY (MAXMDIM >= 4 && !ISWEB && !ISMOBILE && CAP_GL)
|
#define CAP_RAY (MAXMDIM >= 4 && CAP_GL)
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
#ifndef CAP_MEMORY_RESERVE
|
#ifndef CAP_MEMORY_RESERVE
|
||||||
|
Loading…
x
Reference in New Issue
Block a user