1
0
mirror of https://github.com/XProger/OpenLara.git synced 2025-08-15 01:24:35 +02:00

#11 detail quality checks; #23 CPU-host memory for dynamic geometry buffers

This commit is contained in:
XProger
2018-03-03 14:06:44 +03:00
parent ee538b85ea
commit 9388002bf4
4 changed files with 77 additions and 41 deletions

View File

@@ -1507,7 +1507,7 @@ namespace Core {
#endif #endif
} }
void DIP(int iStart, int iCount) { void DIP(int iStart, int iCount, void *iBuffer) {
validateRenderState(); validateRenderState();
#ifdef FFP #ifdef FFP
@@ -1526,7 +1526,7 @@ namespace Core {
#ifdef _PSP #ifdef _PSP
sceGumDrawArray(GU_TRIANGLES, GU_TEXTURE_16BIT | GU_COLOR_8888 | GU_NORMAL_16BIT | GU_VERTEX_16BIT | GU_INDEX_16BIT | GU_TRANSFORM_3D, iCount, active.iBuffer + iStart, active.vBuffer); sceGumDrawArray(GU_TRIANGLES, GU_TEXTURE_16BIT | GU_COLOR_8888 | GU_NORMAL_16BIT | GU_VERTEX_16BIT | GU_INDEX_16BIT | GU_TRANSFORM_3D, iCount, active.iBuffer + iStart, active.vBuffer);
#else #else
glDrawElements(GL_TRIANGLES, iCount, GL_UNSIGNED_SHORT, (Index*)NULL + iStart); glDrawElements(GL_TRIANGLES, iCount, GL_UNSIGNED_SHORT, (Index*)iBuffer + iStart);
#endif #endif
stats.dips++; stats.dips++;

View File

@@ -40,6 +40,18 @@ struct OptionItem {
*(uint8*)(intptr_t(settings) + offset) = value; *(uint8*)(intptr_t(settings) + offset) = value;
} }
bool checkValue(uint8 value) const {
if (value >= maxValue) return false;
Core::Settings stg;
switch (title) {
case STR_OPT_DETAIL_FILTER : stg.detail.setFilter((Core::Settings::Quality)value); return stg.detail.filter == value;
case STR_OPT_DETAIL_LIGHTING : stg.detail.setLighting((Core::Settings::Quality)value); return stg.detail.lighting == value;
case STR_OPT_DETAIL_SHADOWS : stg.detail.setShadows((Core::Settings::Quality)value); return stg.detail.shadows == value;
case STR_OPT_DETAIL_WATER : stg.detail.setWater((Core::Settings::Quality)value); return stg.detail.water == value;
default : return true;
}
}
float drawParam(float x, float y, float w, StringID oStr, bool active, uint8 value) const { float drawParam(float x, float y, float w, StringID oStr, bool active, uint8 value) const {
if (oStr != STR_NOT_IMPLEMENTED) { if (oStr != STR_NOT_IMPLEMENTED) {
UI::textOut(vec2(x + 32.0f, y), oStr); UI::textOut(vec2(x + 32.0f, y), oStr);
@@ -63,8 +75,8 @@ struct OptionItem {
float maxWidth = UI::getTextSize(STR[color + value]).x; float maxWidth = UI::getTextSize(STR[color + value]).x;
maxWidth = maxWidth * 0.5f + 8.0f; maxWidth = maxWidth * 0.5f + 8.0f;
x += w * 0.5f; x += w * 0.5f;
if (value > 0) UI::specOut(vec2(x - maxWidth - 16.0f, y), 108); if (checkValue(value - 1)) UI::specOut(vec2(x - maxWidth - 16.0f, y), 108);
if (value < maxValue) UI::specOut(vec2(x + maxWidth, y), 109); if (checkValue(value + 1)) UI::specOut(vec2(x + maxWidth, y), 109);
} }
return y + LINE_HEIGHT; return y + LINE_HEIGHT;
} }
@@ -91,10 +103,10 @@ struct OptionItem {
UI::textOut(vec2(x, y), title, UI::aCenter, w, 255, UI::SHADE_GRAY); UI::textOut(vec2(x, y), title, UI::aCenter, w, 255, UI::SHADE_GRAY);
case TYPE_EMPTY : break; case TYPE_EMPTY : break;
case TYPE_BUTTON : { case TYPE_BUTTON : {
const char *caption = offset ? (char*)offset : STR[title]; const char *caption = offset ? (char*)offset : STR[title];
UI::textOut(vec2(x, y), caption, UI::aCenter, w); UI::textOut(vec2(x, y), caption, UI::aCenter, w);
break; break;
} }
case TYPE_PARAM : case TYPE_PARAM :
case TYPE_KEY : case TYPE_KEY :
return bar ? drawBar(x, y, w, active, value) : drawParam(x, y, w, title, active, value); return bar ? drawBar(x, y, w, active, value) : drawParam(x, y, w, title, active, value);
@@ -358,14 +370,14 @@ struct Inventory {
case cUp : nextSlot(slot, -1); break; case cUp : nextSlot(slot, -1); break;
case cDown : nextSlot(slot, +1); break; case cDown : nextSlot(slot, +1); break;
case cLeft : case cLeft :
if (opt->type == OptionItem::TYPE_PARAM && value > 0) { if (opt->type == OptionItem::TYPE_PARAM && opt->checkValue(value - 1)) {
value--; value--;
timer = 0.2f; timer = 0.2f;
return opt; return opt;
} }
break; break;
case cRight : case cRight :
if (opt->type == OptionItem::TYPE_PARAM && value < opt->maxValue) { if (opt->type == OptionItem::TYPE_PARAM && opt->checkValue(value + 1)) {
value++; value++;
timer = 0.2f; timer = 0.2f;
return opt; return opt;

View File

@@ -35,14 +35,14 @@ struct MeshRange {
void bind(uint32 *VAO) const {} void bind(uint32 *VAO) const {}
#else #else
void setup() const { void setup(void *vBuffer) const {
glEnableVertexAttribArray(aCoord); glEnableVertexAttribArray(aCoord);
glEnableVertexAttribArray(aNormal); glEnableVertexAttribArray(aNormal);
glEnableVertexAttribArray(aTexCoord); glEnableVertexAttribArray(aTexCoord);
glEnableVertexAttribArray(aColor); glEnableVertexAttribArray(aColor);
glEnableVertexAttribArray(aLight); glEnableVertexAttribArray(aLight);
VertexGPU *v = (VertexGPU*)NULL + vStart; VertexGPU *v = (VertexGPU*)vBuffer + vStart;
glVertexAttribPointer(aCoord, 4, GL_SHORT, false, sizeof(*v), &v->coord); glVertexAttribPointer(aCoord, 4, GL_SHORT, false, sizeof(*v), &v->coord);
glVertexAttribPointer(aNormal, 4, GL_SHORT, true, sizeof(*v), &v->normal); glVertexAttribPointer(aNormal, 4, GL_SHORT, true, sizeof(*v), &v->normal);
glVertexAttribPointer(aTexCoord, 4, GL_SHORT, true, sizeof(*v), &v->texCoord); glVertexAttribPointer(aTexCoord, 4, GL_SHORT, true, sizeof(*v), &v->texCoord);
@@ -66,10 +66,9 @@ struct MeshRange {
#define MAX_ROOM_DYN_FACES 256 #define MAX_ROOM_DYN_FACES 256
struct Mesh { struct Mesh {
#ifdef _PSP Index *iBuffer;
Index *iBuffer; VertexGPU *vBuffer;
VertexGPU *vBuffer; #ifndef _PSP
#else
GLuint ID[2]; GLuint ID[2];
GLuint *VAO; GLuint *VAO;
#endif #endif
@@ -80,12 +79,12 @@ struct Mesh {
int aIndex; int aIndex;
bool cmdBufAlloc; bool cmdBufAlloc;
Mesh(int iCount, int vCount) : iCount(iCount), vCount(vCount), aCount(0), aIndex(-1), cmdBufAlloc(true) { #ifdef _PSP
#ifdef _PSP Mesh(int iCount, int vCount, bool dynamic) : iCount(iCount), vCount(vCount), aCount(0), aIndex(-1), cmdBufAlloc(true) {
iBuffer = (Index*)sceGuGetMemory(iCount * sizeof(Index)); iBuffer = (Index*)sceGuGetMemory(iCount * sizeof(Index));
vBuffer = (VertexGPU*)sceGuGetMemory(vCount * sizeof(VertexGPU)); vBuffer = (VertexGPU*)sceGuGetMemory(vCount * sizeof(VertexGPU));
#endif
} }
#endif
Mesh(Index *indices, int iCount, Vertex *vertices, int vCount, int aCount) : iCount(iCount), vCount(vCount), aCount(aCount), aIndex(0), cmdBufAlloc(false) { Mesh(Index *indices, int iCount, Vertex *vertices, int vCount, int aCount) : iCount(iCount), vCount(vCount), aCount(aCount), aIndex(0), cmdBufAlloc(false) {
#ifdef _PSP #ifdef _PSP
@@ -103,14 +102,22 @@ struct Mesh {
if (Core::support.VAO) if (Core::support.VAO)
glBindVertexArray(Core::active.VAO = 0); glBindVertexArray(Core::active.VAO = 0);
glGenBuffers(2, ID); if (vertices || indices) {
bind(true); glGenBuffers(2, ID);
glBufferData(GL_ELEMENT_ARRAY_BUFFER, iCount * sizeof(Index), indices, GL_STATIC_DRAW); bind(true);
glBufferData(GL_ARRAY_BUFFER, vCount * sizeof(Vertex), vertices, GL_STATIC_DRAW); glBufferData(GL_ELEMENT_ARRAY_BUFFER, iCount * sizeof(Index), indices, GL_STATIC_DRAW);
glBufferData(GL_ARRAY_BUFFER, vCount * sizeof(VertexGPU), vertices, GL_STATIC_DRAW);
if (Core::support.VAO && aCount) {
VAO = new GLuint[aCount]; if (Core::support.VAO && aCount) {
glGenVertexArrays(aCount, VAO); VAO = new GLuint[aCount];
glGenVertexArrays(aCount, VAO);
}
iBuffer = NULL;
vBuffer = NULL;
} else {
ID[0] = ID[1] = 0;
iBuffer = new Index[iCount];
vBuffer = new VertexGPU[vCount];
} }
#endif #endif
} }
@@ -135,16 +142,27 @@ struct Mesh {
} }
} }
#else #else
// !!! typeof vertices[0] == Vertex == VertexGPU
ASSERT(sizeof(VertexGPU) == sizeof(Vertex));
if (Core::support.VAO) if (Core::support.VAO)
glBindVertexArray(Core::active.VAO = 0); glBindVertexArray(Core::active.VAO = 0);
if (indices && iCount) { if (indices && iCount) {
glBindBuffer(GL_ELEMENT_ARRAY_BUFFER, Core::active.iBuffer = ID[0]); if (iBuffer) {
glBufferSubData(GL_ELEMENT_ARRAY_BUFFER, 0, iCount * sizeof(Index), indices); memcpy(iBuffer, indices, iCount * sizeof(Index));
} else {
glBindBuffer(GL_ELEMENT_ARRAY_BUFFER, Core::active.iBuffer = ID[0]);
glBufferSubData(GL_ELEMENT_ARRAY_BUFFER, 0, iCount * sizeof(Index), indices);
}
} }
if (vertices && vCount) { if (vertices && vCount) {
glBindBuffer(GL_ARRAY_BUFFER, Core::active.vBuffer = ID[1]); if (vBuffer) {
glBufferSubData(GL_ARRAY_BUFFER, 0, vCount * sizeof(Vertex), vertices); memcpy(vBuffer, vertices, vCount * sizeof(VertexGPU));
} else {
glBindBuffer(GL_ARRAY_BUFFER, Core::active.vBuffer = ID[1]);
glBufferSubData(GL_ARRAY_BUFFER, 0, vCount * sizeof(VertexGPU), vertices);
}
} }
#endif #endif
} }
@@ -158,11 +176,16 @@ struct Mesh {
} }
#endif #endif
#else #else
if (VAO) { if (iBuffer || vBuffer) {
glDeleteVertexArrays(aCount, VAO); delete[] iBuffer;
delete[] VAO; delete[] vBuffer;
} else {
if (VAO) {
glDeleteVertexArrays(aCount, VAO);
delete[] VAO;
}
glDeleteBuffers(2, ID);
} }
glDeleteBuffers(2, ID);
#endif #endif
} }
@@ -173,7 +196,7 @@ struct Mesh {
range.aIndex = aIndex++; range.aIndex = aIndex++;
range.bind(VAO); range.bind(VAO);
bind(true); bind(true);
range.setup(); range.setup(vBuffer);
} else } else
#endif #endif
range.aIndex = -1; range.aIndex = -1;
@@ -198,10 +221,10 @@ struct Mesh {
if (range.aIndex == -1) { if (range.aIndex == -1) {
bind(); bind();
range.setup(); range.setup(vBuffer);
}; };
Core::DIP(range.iStart, range.iCount); Core::DIP(range.iStart, range.iCount, iBuffer);
} }
}; };
@@ -1410,4 +1433,4 @@ struct MeshBuilder {
} }
}; };
#endif #endif

View File

@@ -161,13 +161,14 @@ uniform sampler2D sNormal;
return v; return v;
} }
#ifdef WATER_CAUSTICS
vec4 caustics() { vec4 caustics() {
float rOldArea = length(dFdx(vOldPos.xyz)) * length(dFdy(vOldPos.xyz)); float rOldArea = length(dFdx(vOldPos.xyz)) * length(dFdy(vOldPos.xyz));
float rNewArea = length(dFdx(vNewPos.xyz)) * length(dFdy(vNewPos.xyz)); float rNewArea = length(dFdx(vNewPos.xyz)) * length(dFdy(vNewPos.xyz));
float value = clamp(rOldArea / rNewArea * 0.2, 0.0, 1.0) * vOldPos.w; float value = clamp(rOldArea / rNewArea * 0.2, 0.0, 1.0) * vOldPos.w;
return vec4(value, 0.0, 0.0, 0.0); return vec4(value, 0.0, 0.0, 0.0);
} }
#endif
vec4 mask() { vec4 mask() {
return vec4(0.0); return vec4(0.0);
@@ -232,4 +233,4 @@ uniform sampler2D sNormal;
gl_FragColor = pass(); gl_FragColor = pass();
} }
#endif #endif
)====" )===="