|
@@ -220,197 +220,6 @@ static int profilerFrame() {
|
|
|
return retval;
|
|
|
}
|
|
|
|
|
|
-#if 0
|
|
|
-static const float fsquad_vertices[] = {
|
|
|
- -1.f, 1.f, -1.f, -1.f, 1.f, 1.f, 1.f, -1.f
|
|
|
-};
|
|
|
-
|
|
|
-static const char fsquad_vertex_src[] =
|
|
|
- "attribute vec2 av2_pos;\n"
|
|
|
- "varying vec2 vv2_pos;\n"
|
|
|
- "void main() {\n"
|
|
|
- "vv2_pos = av2_pos;\n"
|
|
|
- "gl_Position = vec4(vv2_pos, 0., 1.);\n"
|
|
|
- "}\n";
|
|
|
-
|
|
|
-static const char fsquad_fragment_src[] =
|
|
|
- "uniform sampler2D us2_tex;\n"
|
|
|
- "varying vec2 vv2_pos;\n"
|
|
|
- "void main() {\n"
|
|
|
- "gl_FragColor = texture2D(us2_tex, vv2_pos * .5 + .5);\n"
|
|
|
- "}\n";
|
|
|
-
|
|
|
-static struct {
|
|
|
- AGLDrawSource source;
|
|
|
- AGLDrawMerge merge;
|
|
|
- AGLProgramUniform uniforms[2];
|
|
|
- AGLAttribute attrib_pos;
|
|
|
-} fsquad;
|
|
|
-
|
|
|
-static void fsquadInit() {
|
|
|
- fsquad.merge.depth.mode = AGLDM_Disabled;
|
|
|
- fsquad.merge.blend.enable = 0;
|
|
|
-
|
|
|
- fsquad.source.program = aGLProgramCreateSimple(fsquad_vertex_src, fsquad_fragment_src);
|
|
|
- if (fsquad.source.program < 1) {
|
|
|
- aAppDebugPrintf("Shader compilation error: %s", a_gl_error);
|
|
|
- aAppTerminate(-1);
|
|
|
- }
|
|
|
-
|
|
|
- fsquad.source.primitive.mode = GL_TRIANGLE_STRIP;
|
|
|
- fsquad.source.primitive.cull_mode = AGLCM_Disable;
|
|
|
- fsquad.source.primitive.front_face = AGLFF_CounterClockwise;
|
|
|
- fsquad.source.primitive.first = 0;
|
|
|
- fsquad.source.primitive.index.buffer = 0;
|
|
|
- fsquad.source.primitive.index.type = 0;
|
|
|
- fsquad.source.primitive.index.data.ptr = 0;
|
|
|
- fsquad.source.primitive.count = 4;
|
|
|
-
|
|
|
- fsquad.source.uniforms.p = fsquad.uniforms;
|
|
|
- fsquad.source.uniforms.n = COUNTOF(fsquad.uniforms);
|
|
|
- fsquad.source.attribs.p = &fsquad.attrib_pos;
|
|
|
- fsquad.source.attribs.n = 1;
|
|
|
-
|
|
|
- fsquad.attrib_pos.name = "av2_pos";
|
|
|
- fsquad.attrib_pos.size = 2;
|
|
|
- fsquad.attrib_pos.type = GL_FLOAT;
|
|
|
- fsquad.attrib_pos.normalized = GL_FALSE;
|
|
|
- fsquad.attrib_pos.stride = 2 * sizeof(float);
|
|
|
- fsquad.attrib_pos.ptr = fsquad_vertices;
|
|
|
- fsquad.attrib_pos.buffer = 0;
|
|
|
-
|
|
|
- fsquad.uniforms[0].name = "uf_aspect";
|
|
|
- fsquad.uniforms[0].type = AGLAT_Float;
|
|
|
- fsquad.uniforms[0].count = 1;
|
|
|
-
|
|
|
- fsquad.uniforms[1].name = "us2_tex";
|
|
|
- fsquad.uniforms[1].type = AGLAT_Texture;
|
|
|
- fsquad.uniforms[1].count = 1;
|
|
|
-}
|
|
|
-
|
|
|
-static void fsquadDraw(float aspect, const AGLTexture *tex, const AGLDrawTarget *target) {
|
|
|
- fsquad.uniforms[0].value.pf = &aspect;
|
|
|
- fsquad.uniforms[1].value.texture = tex;
|
|
|
- aGLDraw(&fsquad.source, &fsquad.merge, target);
|
|
|
-}
|
|
|
-
|
|
|
-static const float aabb_draw_vertices[] = {
|
|
|
- 0.f, 0.f, 0.f,
|
|
|
- 0.f, 0.f, 1.f,
|
|
|
- 0.f, 1.f, 1.f,
|
|
|
- 0.f, 1.f, 0.f,
|
|
|
- 1.f, 0.f, 0.f,
|
|
|
- 1.f, 0.f, 1.f,
|
|
|
- 1.f, 1.f, 1.f,
|
|
|
- 1.f, 1.f, 0.f
|
|
|
-};
|
|
|
-
|
|
|
-static const uint16_t aabb_draw_indices[] = {
|
|
|
- 0, 1, 1, 2, 2, 3, 3, 0,
|
|
|
- 4, 5, 5, 6, 6, 7, 7, 4,
|
|
|
- 0, 4, 1, 5, 2, 6, 3, 7
|
|
|
-};
|
|
|
-
|
|
|
-static const char aabb_draw_vertex_src[] =
|
|
|
- "attribute vec3 av3_pos;\n"
|
|
|
- "uniform mat4 um4_MVP;\n"
|
|
|
- "uniform vec3 uv3_mul, uv3_add;\n"
|
|
|
- "varying vec3 vv3_pos;\n"
|
|
|
- "void main() {\n"
|
|
|
- "vv3_pos = av3_pos;\n"
|
|
|
- "gl_Position = um4_MVP * vec4(av3_pos * uv3_mul + uv3_add, 1.);\n"
|
|
|
- "}\n";
|
|
|
-
|
|
|
-static const char aabb_draw_fragment_src[] =
|
|
|
- "uniform vec3 uv3_color;\n"
|
|
|
- "varying vec3 vv3_pos;\n"
|
|
|
- "void main() {\n"
|
|
|
- "gl_FragColor = vec4(vv3_pos * uv3_color, 1.);\n"
|
|
|
- "}\n";
|
|
|
-
|
|
|
-enum { AABBDUniformMVP, AABBDUniformMul, AABBDUniformAdd, AABBDUniformColor, AABBDUniform_COUNT };
|
|
|
-
|
|
|
-struct AABBDraw {
|
|
|
- struct AVec3f min, max, color;
|
|
|
- const struct AMat4f *mvp;
|
|
|
- const AGLDrawTarget *target;
|
|
|
-};
|
|
|
-
|
|
|
-static struct {
|
|
|
- AGLProgram program;
|
|
|
-} aabb_draw;
|
|
|
-
|
|
|
-static void aabbDraw(const struct AABBDraw *draw) {
|
|
|
- AGLDrawSource source;
|
|
|
- AGLDrawMerge merge;
|
|
|
- AGLProgramUniform uniforms[AABBDUniform_COUNT];
|
|
|
- AGLAttribute attrib_pos;
|
|
|
- const struct AVec3f mul = aVec3fSub(draw->max, draw->min);
|
|
|
-
|
|
|
- merge.depth.mode = AGLDM_Disabled;
|
|
|
- merge.blend.enable = 0;
|
|
|
-
|
|
|
- if (aabb_draw.program < 1) {
|
|
|
- aabb_draw.program = aGLProgramCreateSimple(aabb_draw_vertex_src, aabb_draw_fragment_src);
|
|
|
- if (aabb_draw.program < 1) {
|
|
|
- aAppDebugPrintf("Shader compilation error: %s", a_gl_error);
|
|
|
- aAppTerminate(-1);
|
|
|
- }
|
|
|
- }
|
|
|
- source.program = aabb_draw.program;
|
|
|
-
|
|
|
- source.primitive.mode = GL_LINES;
|
|
|
- source.primitive.cull_mode = AGLCM_Back;//AGLCM_Disable;
|
|
|
- source.primitive.front_face = AGLFF_CounterClockwise;
|
|
|
- source.primitive.first = 0;
|
|
|
- source.primitive.index.buffer = 0;
|
|
|
-#if 1
|
|
|
- source.primitive.index.type = GL_UNSIGNED_SHORT;
|
|
|
- source.primitive.index.data.ptr = aabb_draw_indices;
|
|
|
- source.primitive.count = COUNTOF(aabb_draw_indices);
|
|
|
-#else
|
|
|
- source.primitive.index.type = 0;//GL_UNSIGNED_SHORT;
|
|
|
- source.primitive.index.data.ptr = 0;//aabb_draw_indices;
|
|
|
- source.primitive.count = 8;(void)(aabb_draw_indices);//COUNTOF(aabb_draw_indices);
|
|
|
-#endif
|
|
|
-
|
|
|
- source.uniforms.p = uniforms;
|
|
|
- source.uniforms.n = AABBDUniform_COUNT;
|
|
|
- source.attribs.p = &attrib_pos;
|
|
|
- source.attribs.n = 1;
|
|
|
-
|
|
|
- attrib_pos.name = "av3_pos";
|
|
|
- attrib_pos.size = 3;
|
|
|
- attrib_pos.type = GL_FLOAT;
|
|
|
- attrib_pos.normalized = GL_FALSE;
|
|
|
- attrib_pos.stride = 3 * sizeof(float);
|
|
|
- attrib_pos.ptr = aabb_draw_vertices;
|
|
|
- attrib_pos.buffer = 0;
|
|
|
-
|
|
|
- uniforms[AABBDUniformMVP].name = "um4_MVP";
|
|
|
- uniforms[AABBDUniformMVP].type = AGLAT_Mat4;
|
|
|
- uniforms[AABBDUniformMVP].count = 1;
|
|
|
- uniforms[AABBDUniformMVP].value.pf = &draw->mvp->X.x;
|
|
|
-
|
|
|
- uniforms[AABBDUniformMul].name = "uv3_mul";
|
|
|
- uniforms[AABBDUniformMul].type = AGLAT_Vec3;
|
|
|
- uniforms[AABBDUniformMul].count = 1;
|
|
|
- uniforms[AABBDUniformMul].value.pf = &mul.x;
|
|
|
-
|
|
|
- uniforms[AABBDUniformAdd].name = "uv3_add";
|
|
|
- uniforms[AABBDUniformAdd].type = AGLAT_Vec3;
|
|
|
- uniforms[AABBDUniformAdd].count = 1;
|
|
|
- uniforms[AABBDUniformAdd].value.pf = &draw->min.x;
|
|
|
-
|
|
|
- uniforms[AABBDUniformColor].name = "uv3_color";
|
|
|
- uniforms[AABBDUniformColor].type = AGLAT_Vec3;
|
|
|
- uniforms[AABBDUniformColor].count = 1;
|
|
|
- uniforms[AABBDUniformColor].value.pf = &draw->color.x;
|
|
|
-
|
|
|
- aGLDraw(&source, &merge, draw->target);
|
|
|
-}
|
|
|
-#endif
|
|
|
-
|
|
|
static struct {
|
|
|
struct SimpleCamera camera;
|
|
|
int forward, right, run;
|
|
@@ -418,13 +227,6 @@ static struct {
|
|
|
float R;
|
|
|
float lmn;
|
|
|
|
|
|
-#if 0
|
|
|
- AGLDrawTarget screen;
|
|
|
- AGLDrawSource source;
|
|
|
- AGLDrawMerge merge;
|
|
|
- AGLAttribute attribs[Attrib_COUNT];
|
|
|
- AGLProgramUniform uniforms[Uniform_COUNT];
|
|
|
-#endif
|
|
|
struct BSPModel worldspawn;
|
|
|
struct AMat4f model;
|
|
|
} g;
|
|
@@ -437,32 +239,6 @@ static void opensrcInit(struct ICollection *collection, const char *map) {
|
|
|
aAppTerminate(-1);
|
|
|
}
|
|
|
|
|
|
-
|
|
|
-#if 0
|
|
|
- g.source.program = aGLProgramCreateSimple(vertex_src, fragment_src);
|
|
|
- if (g.source.program < 1) {
|
|
|
- aAppDebugPrintf("Shader compilation error: %s", a_gl_error);
|
|
|
- aAppTerminate(-1);
|
|
|
- }
|
|
|
- fsquadInit();
|
|
|
-
|
|
|
- {
|
|
|
- Texture tex_placeholder;
|
|
|
- const uint16_t pixels[] = {
|
|
|
- 0xf81f, 0x07e0, 0x07e0, 0xf81f
|
|
|
- };
|
|
|
- tex_placeholder.gltex = aGLTextureCreate();
|
|
|
- AGLTextureUploadData up = {
|
|
|
- .width = 2,
|
|
|
- .height = 2,
|
|
|
- .format = AGLTF_U565_RGB,
|
|
|
- .pixels = pixels
|
|
|
- };
|
|
|
- aGLTextureUpload(&tex_placeholder.gltex, &up);
|
|
|
- cachePutTexture("opensource/placeholder", &tex_placeholder);
|
|
|
- }
|
|
|
-#endif
|
|
|
-
|
|
|
struct BSPLoadModelContext loadctx = {
|
|
|
.collection = collection,
|
|
|
.persistent = &stack_persistent,
|
|
@@ -491,155 +267,14 @@ static void opensrcInit(struct ICollection *collection, const char *map) {
|
|
|
|
|
|
g.model = aMat4fIdentity();
|
|
|
|
|
|
-#if 0
|
|
|
- g.source.primitive.mode = GL_TRIANGLES;
|
|
|
- g.source.primitive.first = 0;
|
|
|
- g.source.primitive.cull_mode = AGLCM_Back;
|
|
|
- g.source.primitive.front_face = AGLFF_CounterClockwise;
|
|
|
- g.source.primitive.index.type = GL_UNSIGNED_SHORT;
|
|
|
-
|
|
|
- g.source.uniforms.p = g.uniforms;
|
|
|
- g.source.uniforms.n = Uniform_COUNT;
|
|
|
- g.source.attribs.p = g.attribs;
|
|
|
- g.source.attribs.n = Attrib_COUNT;
|
|
|
-
|
|
|
- g.attribs[AttribPos].name = "av3_pos";
|
|
|
- g.attribs[AttribPos].size = 3;
|
|
|
- g.attribs[AttribPos].type = GL_FLOAT;
|
|
|
- g.attribs[AttribPos].normalized = GL_FALSE;
|
|
|
- g.attribs[AttribPos].stride = sizeof(struct BSPModelVertex);
|
|
|
- g.attribs[AttribPos].ptr = 0;
|
|
|
-
|
|
|
- g.attribs[AttribNormal].name = "av3_normal";
|
|
|
- g.attribs[AttribNormal].size = 3;
|
|
|
- g.attribs[AttribNormal].type = GL_FLOAT;
|
|
|
- g.attribs[AttribNormal].normalized = GL_FALSE;
|
|
|
- g.attribs[AttribNormal].stride = sizeof(struct BSPModelVertex);
|
|
|
- g.attribs[AttribNormal].ptr = (void*)offsetof(struct BSPModelVertex, normal);
|
|
|
-
|
|
|
- g.attribs[AttribLightmapUV].name = "av2_lightmap";
|
|
|
- g.attribs[AttribLightmapUV].size = 2;
|
|
|
- g.attribs[AttribLightmapUV].type = GL_FLOAT;
|
|
|
- g.attribs[AttribLightmapUV].normalized = GL_FALSE;
|
|
|
- g.attribs[AttribLightmapUV].stride = sizeof(struct BSPModelVertex);
|
|
|
- g.attribs[AttribLightmapUV].ptr = (void*)offsetof(struct BSPModelVertex, lightmap_uv);
|
|
|
-
|
|
|
- g.attribs[AttribTextureUV].name = "av2_base0_uv";
|
|
|
- g.attribs[AttribTextureUV].size = 2;
|
|
|
- g.attribs[AttribTextureUV].type = GL_FLOAT;
|
|
|
- g.attribs[AttribTextureUV].normalized = GL_FALSE;
|
|
|
- g.attribs[AttribTextureUV].stride = sizeof(struct BSPModelVertex);
|
|
|
- g.attribs[AttribTextureUV].ptr = (void*)offsetof(struct BSPModelVertex, base0_uv);
|
|
|
-
|
|
|
- g.uniforms[UniformM].name = "um4_M";
|
|
|
- g.uniforms[UniformM].type = AGLAT_Mat4;
|
|
|
- g.uniforms[UniformM].count = 1;
|
|
|
- g.uniforms[UniformM].value.pf = &g.model.X.x;
|
|
|
-
|
|
|
- g.uniforms[UniformVP].name = "um4_VP";
|
|
|
- g.uniforms[UniformVP].type = AGLAT_Mat4;
|
|
|
- g.uniforms[UniformVP].count = 1;
|
|
|
- g.uniforms[UniformVP].value.pf = &g.camera.view_projection.X.x;
|
|
|
-
|
|
|
- g.uniforms[UniformLightmap].name = "us2_lightmap";
|
|
|
- g.uniforms[UniformLightmap].type = AGLAT_Texture;
|
|
|
- g.uniforms[UniformLightmap].count = 1;
|
|
|
-
|
|
|
- g.uniforms[UniformLightmapSize].name = "uv2_lightmap_size";
|
|
|
- g.uniforms[UniformLightmapSize].type = AGLAT_Vec2;
|
|
|
- g.uniforms[UniformLightmapSize].count = 1;
|
|
|
-
|
|
|
- g.uniforms[UniformTextureBase0].name = "tex_base0";
|
|
|
- g.uniforms[UniformTextureBase0].type = AGLAT_Texture;
|
|
|
- g.uniforms[UniformTextureBase0].count = 1;
|
|
|
-
|
|
|
- g.uniforms[UniformTextureBase0Size].name = "tex_base0_size";
|
|
|
- g.uniforms[UniformTextureBase0Size].type = AGLAT_Vec2;
|
|
|
- g.uniforms[UniformTextureBase0Size].count = 1;
|
|
|
-
|
|
|
- g.uniforms[UniformTextureBase1].name = "tex_base1";
|
|
|
- g.uniforms[UniformTextureBase1].type = AGLAT_Texture;
|
|
|
- g.uniforms[UniformTextureBase1].count = 1;
|
|
|
-
|
|
|
- g.uniforms[UniformTextureBase1Size].name = "tex_base1_size";
|
|
|
- g.uniforms[UniformTextureBase1Size].type = AGLAT_Vec2;
|
|
|
- g.uniforms[UniformTextureBase1Size].count = 1;
|
|
|
-
|
|
|
- g.uniforms[UniformLMN].name = "uf_lmn";
|
|
|
- g.uniforms[UniformLMN].type = AGLAT_Float;
|
|
|
- g.uniforms[UniformLMN].count = 1;
|
|
|
- g.uniforms[UniformLMN].value.pf = &g.lmn;
|
|
|
-
|
|
|
- aGLUniformLocate(g.source.program, g.uniforms, Uniform_COUNT);
|
|
|
- aGLAttributeLocate(g.source.program, g.attribs, Attrib_COUNT);
|
|
|
-
|
|
|
- g.merge.blend.enable = 0;
|
|
|
- g.merge.depth.mode = AGLDM_TestAndWrite;
|
|
|
- g.merge.depth.func = AGLDF_Less;
|
|
|
-
|
|
|
- g.screen.framebuffer = 0;
|
|
|
-
|
|
|
- g.lmn = 0;
|
|
|
-#endif
|
|
|
-
|
|
|
const float t = 0;
|
|
|
simplecamLookAt(&g.camera,
|
|
|
aVec3fAdd(g.center, aVec3fMulf(aVec3f(cosf(t*.5), sinf(t*.5), .25f), g.R*.5f)),
|
|
|
g.center, aVec3f(0.f, 0.f, 1.f));
|
|
|
}
|
|
|
|
|
|
-#if 0
|
|
|
-static void drawBSPDraw(const struct BSPDraw *draw) {
|
|
|
- const ATimeUs start = aAppTime();
|
|
|
- g.source.primitive.index.data.offset = sizeof(uint16_t) * draw->start;
|
|
|
- g.source.primitive.count = draw->count;
|
|
|
- g.attribs[AttribPos].buffer =
|
|
|
- g.attribs[AttribNormal].buffer =
|
|
|
- g.attribs[AttribTextureUV].buffer =
|
|
|
- g.attribs[AttribLightmapUV].buffer = &draw->vbo;
|
|
|
-
|
|
|
- struct AVec2f tex0_size = aVec2f(1.f, 1.f);
|
|
|
- struct AVec2f tex1_size = aVec2f(1.f, 1.f);
|
|
|
-
|
|
|
- const struct Texture *texture = draw->material->base_texture[0];
|
|
|
- if (!texture)
|
|
|
- texture = cacheGetTexture("opensource/placeholder");
|
|
|
-
|
|
|
- g.uniforms[UniformTextureBase0Size].value.pf = &tex0_size.x;
|
|
|
- tex0_size = aVec2f(texture->gltex.width, texture->gltex.height);
|
|
|
- g.uniforms[UniformTextureBase0].value.texture = &texture->gltex;
|
|
|
-
|
|
|
- texture = draw->material->base_texture[1];
|
|
|
- if (!texture)
|
|
|
- texture = cacheGetTexture("opensource/placeholder");
|
|
|
- tex1_size = aVec2f(texture->gltex.width, texture->gltex.height);
|
|
|
- g.uniforms[UniformTextureBase1Size].value.pf = &tex1_size.x;
|
|
|
- g.uniforms[UniformTextureBase1].value.texture = &texture->gltex;
|
|
|
-
|
|
|
- aGLDraw(&g.source, &g.merge, &g.screen);
|
|
|
- profileEvent("drawBSDDraw", aAppTime() - start);
|
|
|
-}
|
|
|
-
|
|
|
-static void drawModel(const struct BSPModel *model) {
|
|
|
- const ATimeUs start = aAppTime();
|
|
|
- const struct AVec2f lm_size = aVec2f(model->lightmap.width, model->lightmap.height);
|
|
|
- g.uniforms[UniformLightmap].value.texture = &model->lightmap;
|
|
|
- g.uniforms[UniformLightmapSize].value.pf = &lm_size.x;
|
|
|
- g.source.primitive.index.buffer = &model->ibo;
|
|
|
-
|
|
|
- for (int i = 0; i < model->draws_count /*&& i < 200*/; ++i)
|
|
|
- drawBSPDraw(model->draws + i);
|
|
|
- profileEvent("drawModel", aAppTime() - start);
|
|
|
-}
|
|
|
-#endif
|
|
|
-
|
|
|
static void opensrcResize(ATimeUs timestamp, unsigned int old_w, unsigned int old_h) {
|
|
|
(void)(timestamp); (void)(old_w); (void)(old_h);
|
|
|
-#if 0
|
|
|
- g.screen.viewport.x = g.screen.viewport.y = 0;
|
|
|
- g.screen.viewport.w = a_app_state->width;
|
|
|
- g.screen.viewport.h = a_app_state->height;
|
|
|
-#endif
|
|
|
glViewport(0, 0, a_app_state->width, a_app_state->height);
|
|
|
|
|
|
simplecamProjection(&g.camera, 1.f, g.R * 10.f, 3.1415926f/2.f, (float)a_app_state->width / (float)a_app_state->height);
|
|
@@ -660,30 +295,6 @@ static void opensrcPaint(ATimeUs timestamp, float dt) {
|
|
|
simplecamRecalc(&g.camera);
|
|
|
}
|
|
|
|
|
|
-#if 0
|
|
|
- AGLClearParams clear;
|
|
|
- clear.r = clear.g = clear.b = 0;
|
|
|
- clear.depth = 1.f;
|
|
|
- clear.bits = AGLCB_ColorAndDepth;
|
|
|
- aGLClear(&clear, &g.screen);
|
|
|
-
|
|
|
- if (0)
|
|
|
- fsquadDraw(1., &g.worldspawn.lightmap, &g.screen);
|
|
|
-
|
|
|
- drawModel(&g.worldspawn);
|
|
|
-
|
|
|
- if (0) {
|
|
|
- const struct AABBDraw aabb = {
|
|
|
- .min = g.worldspawn.aabb.min,
|
|
|
- .max = g.worldspawn.aabb.max,
|
|
|
- .color = aVec3ff(1),
|
|
|
- .mvp = &g.camera.view_projection,
|
|
|
- .target = &g.screen
|
|
|
- };
|
|
|
- aabbDraw(&aabb);
|
|
|
- }
|
|
|
-#endif
|
|
|
-
|
|
|
renderClear();
|
|
|
|
|
|
renderModelDraw(&g.camera.view_projection, g.lmn, &g.worldspawn);
|