mirror of
https://github.com/korenkonder/ReDIVA.git
synced 2026-10-05 05:07:56 +03:00
gl_rend_state massive overhaul. Created render_data_context
This commit is contained in:
+60
-15
@@ -5,13 +5,10 @@
|
||||
|
||||
#include "array_buffer.hpp"
|
||||
#include "../gl_rend_state.hpp"
|
||||
#include "../gl_state.hpp"
|
||||
|
||||
namespace GL {
|
||||
void ArrayBuffer::Bind(bool force) {
|
||||
gl_rend_state.bind_array_buffer(buffer, force);
|
||||
}
|
||||
|
||||
void ArrayBuffer::Create(size_t size) {
|
||||
void ArrayBuffer::Create(gl_state_struct& gl_st, size_t size) {
|
||||
if (buffer)
|
||||
return;
|
||||
|
||||
@@ -21,7 +18,7 @@ namespace GL {
|
||||
}
|
||||
else {
|
||||
glGenBuffers(1, &buffer);
|
||||
gl_rend_state.bind_array_buffer(buffer, true);
|
||||
gl_st.bind_array_buffer(buffer);
|
||||
if (GL_VERSION_4_4)
|
||||
glBufferStorage(GL_ARRAY_BUFFER, (GLsizeiptr)size,
|
||||
0, GL_DYNAMIC_STORAGE_BIT | GL_MAP_WRITE_BIT);
|
||||
@@ -30,7 +27,7 @@ namespace GL {
|
||||
}
|
||||
}
|
||||
|
||||
void ArrayBuffer::Create(size_t size, const void* data, bool dynamic) {
|
||||
void ArrayBuffer::Create(gl_state_struct& gl_st, size_t size, const void* data, bool dynamic) {
|
||||
if (buffer)
|
||||
return;
|
||||
|
||||
@@ -41,7 +38,7 @@ namespace GL {
|
||||
}
|
||||
else {
|
||||
glGenBuffers(1, &buffer);
|
||||
gl_rend_state.bind_array_buffer(buffer, true);
|
||||
gl_st.bind_array_buffer(buffer);
|
||||
if (GL_VERSION_4_4)
|
||||
glBufferStorage(GL_ARRAY_BUFFER, (GLsizeiptr)size, data,
|
||||
dynamic ? GL_DYNAMIC_STORAGE_BIT | GL_MAP_WRITE_BIT : 0);
|
||||
@@ -58,7 +55,7 @@ namespace GL {
|
||||
}
|
||||
}
|
||||
|
||||
void* ArrayBuffer::MapMemory() {
|
||||
void* ArrayBuffer::MapMemory(gl_state_struct& gl_st) {
|
||||
if (!buffer)
|
||||
return 0;
|
||||
|
||||
@@ -66,7 +63,7 @@ namespace GL {
|
||||
if (GL_VERSION_4_5)
|
||||
data = glMapNamedBuffer(buffer, GL_WRITE_ONLY);
|
||||
else {
|
||||
gl_rend_state.bind_array_buffer(buffer);
|
||||
gl_st.bind_array_buffer(buffer);
|
||||
data = glMapBuffer(GL_ARRAY_BUFFER, GL_WRITE_ONLY);
|
||||
}
|
||||
|
||||
@@ -77,12 +74,36 @@ namespace GL {
|
||||
glUnmapNamedBuffer(buffer);
|
||||
else {
|
||||
glUnmapBuffer(GL_ARRAY_BUFFER);
|
||||
gl_rend_state.bind_array_buffer(0);
|
||||
gl_st.bind_array_buffer(0);
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
|
||||
void ArrayBuffer::UnmapMemory() {
|
||||
void* ArrayBuffer::MapMemory(p_gl_rend_state& p_gl_rend_st) {
|
||||
if (!buffer)
|
||||
return 0;
|
||||
|
||||
void* data;
|
||||
if (GL_VERSION_4_5)
|
||||
data = glMapNamedBuffer(buffer, GL_WRITE_ONLY);
|
||||
else {
|
||||
p_gl_rend_st.bind_array_buffer(buffer);
|
||||
data = glMapBuffer(GL_ARRAY_BUFFER, GL_WRITE_ONLY);
|
||||
}
|
||||
|
||||
if (data)
|
||||
return data;
|
||||
|
||||
if (GL_VERSION_4_5)
|
||||
glUnmapNamedBuffer(buffer);
|
||||
else {
|
||||
glUnmapBuffer(GL_ARRAY_BUFFER);
|
||||
p_gl_rend_st.bind_array_buffer(0);
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
|
||||
void ArrayBuffer::UnmapMemory(gl_state_struct& gl_st) {
|
||||
if (!buffer)
|
||||
return;
|
||||
|
||||
@@ -90,18 +111,42 @@ namespace GL {
|
||||
glUnmapNamedBuffer(buffer);
|
||||
else {
|
||||
glUnmapBuffer(GL_ARRAY_BUFFER);
|
||||
gl_rend_state.bind_array_buffer(0);
|
||||
gl_st.bind_array_buffer(0);
|
||||
}
|
||||
}
|
||||
|
||||
void ArrayBuffer::WriteMemory(size_t offset, size_t size, const void* data) {
|
||||
void ArrayBuffer::UnmapMemory(p_gl_rend_state& p_gl_rend_st) {
|
||||
if (!buffer)
|
||||
return;
|
||||
|
||||
if (GL_VERSION_4_5)
|
||||
glUnmapNamedBuffer(buffer);
|
||||
else {
|
||||
glUnmapBuffer(GL_ARRAY_BUFFER);
|
||||
p_gl_rend_st.bind_array_buffer(0);
|
||||
}
|
||||
}
|
||||
|
||||
void ArrayBuffer::WriteMemory(gl_state_struct& gl_st, size_t offset, size_t size, const void* data) {
|
||||
if (!buffer || !size)
|
||||
return;
|
||||
|
||||
if (GL_VERSION_4_5)
|
||||
glNamedBufferSubData(buffer, (GLsizeiptr)offset, (GLsizeiptr)size, data);
|
||||
else {
|
||||
gl_rend_state.bind_array_buffer(buffer);
|
||||
gl_st.bind_array_buffer(buffer);
|
||||
glBufferSubData(GL_ARRAY_BUFFER, (GLsizeiptr)offset, (GLsizeiptr)size, data);
|
||||
}
|
||||
}
|
||||
|
||||
void ArrayBuffer::WriteMemory(p_gl_rend_state& p_gl_rend_st, size_t offset, size_t size, const void* data) {
|
||||
if (!buffer || !size)
|
||||
return;
|
||||
|
||||
if (GL_VERSION_4_5)
|
||||
glNamedBufferSubData(buffer, (GLsizeiptr)offset, (GLsizeiptr)size, data);
|
||||
else {
|
||||
p_gl_rend_st.bind_array_buffer(buffer);
|
||||
glBufferSubData(GL_ARRAY_BUFFER, (GLsizeiptr)offset, (GLsizeiptr)size, data);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -8,6 +8,9 @@
|
||||
#include "../../KKdLib/default.hpp"
|
||||
#include "../gl.hpp"
|
||||
|
||||
struct gl_state_struct;
|
||||
struct p_gl_rend_state;
|
||||
|
||||
namespace GL {
|
||||
struct ArrayBuffer {
|
||||
private:
|
||||
@@ -26,13 +29,15 @@ namespace GL {
|
||||
|
||||
}
|
||||
|
||||
void Bind(bool force = false);
|
||||
void Create(size_t size);
|
||||
void Create(size_t size, const void* data, bool dynamic = false);
|
||||
void Create(gl_state_struct& gl_st, size_t size);
|
||||
void Create(gl_state_struct& gl_st, size_t size, const void* data, bool dynamic = false);
|
||||
void Destroy();
|
||||
void* MapMemory();
|
||||
void UnmapMemory();
|
||||
void WriteMemory(size_t offset, size_t size, const void* data);
|
||||
void* MapMemory(gl_state_struct& gl_st);
|
||||
void* MapMemory(p_gl_rend_state& p_gl_rend_st);
|
||||
void UnmapMemory(gl_state_struct& gl_st);
|
||||
void UnmapMemory(p_gl_rend_state& p_gl_rend_st);
|
||||
void WriteMemory(gl_state_struct& gl_st, size_t offset, size_t size, const void* data);
|
||||
void WriteMemory(p_gl_rend_state& p_gl_rend_st, size_t offset, size_t size, const void* data);
|
||||
|
||||
inline bool IsNull() {
|
||||
return !buffer;
|
||||
@@ -43,8 +48,13 @@ namespace GL {
|
||||
}
|
||||
|
||||
template<typename T>
|
||||
inline void WriteMemory(T& data) {
|
||||
WriteMemory(0, sizeof(T), &data);
|
||||
inline void WriteMemory(gl_state_struct& gl_st, T& data) {
|
||||
WriteMemory(gl_st, 0, sizeof(T), &data);
|
||||
}
|
||||
|
||||
template<typename T>
|
||||
inline void WriteMemory(p_gl_rend_state& p_gl_rend_st, T& data) {
|
||||
WriteMemory(p_gl_rend_st, 0, sizeof(T), &data);
|
||||
}
|
||||
|
||||
inline operator GLuint() const {
|
||||
|
||||
@@ -5,13 +5,10 @@
|
||||
|
||||
#include "element_array_buffer.hpp"
|
||||
#include "../gl_rend_state.hpp"
|
||||
#include "../gl_state.hpp"
|
||||
|
||||
namespace GL {
|
||||
void ElementArrayBuffer::Bind(bool force) {
|
||||
gl_rend_state.bind_element_array_buffer(buffer, force);
|
||||
}
|
||||
|
||||
void ElementArrayBuffer::Create(size_t size) {
|
||||
void ElementArrayBuffer::Create(gl_state_struct& gl_st, size_t size) {
|
||||
if (buffer)
|
||||
return;
|
||||
|
||||
@@ -21,7 +18,7 @@ namespace GL {
|
||||
}
|
||||
else {
|
||||
glGenBuffers(1, &buffer);
|
||||
gl_rend_state.bind_element_array_buffer(buffer, true);
|
||||
gl_st.bind_element_array_buffer(buffer, true);
|
||||
if (GL_VERSION_4_4)
|
||||
glBufferStorage(GL_ELEMENT_ARRAY_BUFFER, (GLsizeiptr)size,
|
||||
0, GL_DYNAMIC_STORAGE_BIT | GL_MAP_WRITE_BIT);
|
||||
@@ -30,7 +27,7 @@ namespace GL {
|
||||
}
|
||||
}
|
||||
|
||||
void ElementArrayBuffer::Create(size_t size, const void* data, bool dynamic) {
|
||||
void ElementArrayBuffer::Create(gl_state_struct& gl_st, size_t size, const void* data, bool dynamic) {
|
||||
if (buffer)
|
||||
return;
|
||||
|
||||
@@ -41,7 +38,7 @@ namespace GL {
|
||||
}
|
||||
else {
|
||||
glGenBuffers(1, &buffer);
|
||||
gl_rend_state.bind_element_array_buffer(buffer, true);
|
||||
gl_st.bind_element_array_buffer(buffer, true);
|
||||
if (GL_VERSION_4_4)
|
||||
glBufferStorage(GL_ELEMENT_ARRAY_BUFFER, (GLsizeiptr)size, data,
|
||||
dynamic ? GL_DYNAMIC_STORAGE_BIT | GL_MAP_WRITE_BIT : 0);
|
||||
@@ -58,7 +55,7 @@ namespace GL {
|
||||
}
|
||||
}
|
||||
|
||||
void* ElementArrayBuffer::MapMemory() {
|
||||
void* ElementArrayBuffer::MapMemory(gl_state_struct& gl_st) {
|
||||
if (!buffer)
|
||||
return 0;
|
||||
|
||||
@@ -66,7 +63,7 @@ namespace GL {
|
||||
if (GL_VERSION_4_5)
|
||||
data = glMapNamedBuffer(buffer, GL_WRITE_ONLY);
|
||||
else {
|
||||
gl_rend_state.bind_element_array_buffer(buffer);
|
||||
gl_st.bind_element_array_buffer(buffer);
|
||||
data = glMapBuffer(GL_ELEMENT_ARRAY_BUFFER, GL_WRITE_ONLY);
|
||||
}
|
||||
|
||||
@@ -77,12 +74,36 @@ namespace GL {
|
||||
glUnmapNamedBuffer(buffer);
|
||||
else {
|
||||
glUnmapBuffer(GL_ELEMENT_ARRAY_BUFFER);
|
||||
gl_rend_state.bind_element_array_buffer(0);
|
||||
gl_st.bind_element_array_buffer(0);
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
|
||||
void ElementArrayBuffer::UnmapMemory() {
|
||||
void* ElementArrayBuffer::MapMemory(p_gl_rend_state& p_gl_rend_st) {
|
||||
if (!buffer)
|
||||
return 0;
|
||||
|
||||
void* data;
|
||||
if (GL_VERSION_4_5)
|
||||
data = glMapNamedBuffer(buffer, GL_WRITE_ONLY);
|
||||
else {
|
||||
p_gl_rend_st.bind_element_array_buffer(buffer);
|
||||
data = glMapBuffer(GL_ELEMENT_ARRAY_BUFFER, GL_WRITE_ONLY);
|
||||
}
|
||||
|
||||
if (data)
|
||||
return data;
|
||||
|
||||
if (GL_VERSION_4_5)
|
||||
glUnmapNamedBuffer(buffer);
|
||||
else {
|
||||
glUnmapBuffer(GL_ELEMENT_ARRAY_BUFFER);
|
||||
p_gl_rend_st.bind_element_array_buffer(0);
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
|
||||
void ElementArrayBuffer::UnmapMemory(gl_state_struct& gl_st) {
|
||||
if (!buffer)
|
||||
return;
|
||||
|
||||
@@ -90,18 +111,42 @@ namespace GL {
|
||||
glUnmapNamedBuffer(buffer);
|
||||
else {
|
||||
glUnmapBuffer(GL_ELEMENT_ARRAY_BUFFER);
|
||||
gl_rend_state.bind_element_array_buffer(0);
|
||||
gl_st.bind_element_array_buffer(0);
|
||||
}
|
||||
}
|
||||
|
||||
void ElementArrayBuffer::WriteMemory(size_t offset, size_t size, const void* data) {
|
||||
void ElementArrayBuffer::UnmapMemory(p_gl_rend_state& p_gl_rend_st) {
|
||||
if (!buffer)
|
||||
return;
|
||||
|
||||
if (GL_VERSION_4_5)
|
||||
glUnmapNamedBuffer(buffer);
|
||||
else {
|
||||
glUnmapBuffer(GL_ELEMENT_ARRAY_BUFFER);
|
||||
p_gl_rend_st.bind_element_array_buffer(0);
|
||||
}
|
||||
}
|
||||
|
||||
void ElementArrayBuffer::WriteMemory(gl_state_struct& gl_st, size_t offset, size_t size, const void* data) {
|
||||
if (!buffer || !size)
|
||||
return;
|
||||
|
||||
if (GL_VERSION_4_5)
|
||||
glNamedBufferSubData(buffer, (GLsizeiptr)offset, (GLsizeiptr)size, data);
|
||||
else {
|
||||
gl_rend_state.bind_element_array_buffer(buffer);
|
||||
gl_st.bind_element_array_buffer(buffer);
|
||||
glBufferSubData(GL_ELEMENT_ARRAY_BUFFER, (GLsizeiptr)offset, (GLsizeiptr)size, data);
|
||||
}
|
||||
}
|
||||
|
||||
void ElementArrayBuffer::WriteMemory(p_gl_rend_state& p_gl_rend_st, size_t offset, size_t size, const void* data) {
|
||||
if (!buffer || !size)
|
||||
return;
|
||||
|
||||
if (GL_VERSION_4_5)
|
||||
glNamedBufferSubData(buffer, (GLsizeiptr)offset, (GLsizeiptr)size, data);
|
||||
else {
|
||||
p_gl_rend_st.bind_element_array_buffer(buffer);
|
||||
glBufferSubData(GL_ELEMENT_ARRAY_BUFFER, (GLsizeiptr)offset, (GLsizeiptr)size, data);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -8,6 +8,9 @@
|
||||
#include "../../KKdLib/default.hpp"
|
||||
#include "../gl.hpp"
|
||||
|
||||
struct gl_state_struct;
|
||||
struct p_gl_rend_state;
|
||||
|
||||
namespace GL {
|
||||
struct ElementArrayBuffer {
|
||||
private:
|
||||
@@ -26,13 +29,15 @@ namespace GL {
|
||||
|
||||
}
|
||||
|
||||
void Bind(bool force = false);
|
||||
void Create(size_t size);
|
||||
void Create(size_t size, const void* data, bool dynamic = false);
|
||||
void Create(gl_state_struct& gl_st, size_t size);
|
||||
void Create(gl_state_struct& gl_st, size_t size, const void* data, bool dynamic = false);
|
||||
void Destroy();
|
||||
void* MapMemory();
|
||||
void UnmapMemory();
|
||||
void WriteMemory(size_t offset, size_t size, const void* data);
|
||||
void* MapMemory(gl_state_struct& gl_st);
|
||||
void* MapMemory(p_gl_rend_state& p_gl_rend_st);
|
||||
void UnmapMemory(gl_state_struct& gl_st);
|
||||
void UnmapMemory(p_gl_rend_state& p_gl_rend_st);
|
||||
void WriteMemory(gl_state_struct& gl_st, size_t offset, size_t size, const void* data);
|
||||
void WriteMemory(p_gl_rend_state& p_gl_rend_st, size_t offset, size_t size, const void* data);
|
||||
|
||||
inline bool IsNull() {
|
||||
return !buffer;
|
||||
@@ -43,8 +48,13 @@ namespace GL {
|
||||
}
|
||||
|
||||
template<typename T>
|
||||
inline void WriteMemory(T& data) {
|
||||
WriteMemory(0, sizeof(T), &data);
|
||||
inline void WriteMemory(gl_state_struct& gl_st, T& data) {
|
||||
WriteMemory(gl_st, 0, sizeof(T), &data);
|
||||
}
|
||||
|
||||
template<typename T>
|
||||
inline void WriteMemory(p_gl_rend_state& p_gl_rend_st, T& data) {
|
||||
WriteMemory(p_gl_rend_st, 0, sizeof(T), &data);
|
||||
}
|
||||
|
||||
inline operator GLuint() const {
|
||||
|
||||
@@ -5,13 +5,10 @@
|
||||
|
||||
#include "shader_storage_buffer.hpp"
|
||||
#include "../gl_rend_state.hpp"
|
||||
#include "../gl_state.hpp"
|
||||
|
||||
namespace GL {
|
||||
void ShaderStorageBuffer::Bind(int32_t index, bool force) {
|
||||
gl_rend_state.bind_shader_storage_buffer_base(index, buffer, force);
|
||||
}
|
||||
|
||||
void ShaderStorageBuffer::Create(size_t size) {
|
||||
void ShaderStorageBuffer::Create(gl_state_struct& gl_st, size_t size) {
|
||||
if (buffer)
|
||||
return;
|
||||
|
||||
@@ -21,7 +18,7 @@ namespace GL {
|
||||
}
|
||||
else {
|
||||
glGenBuffers(1, &buffer);
|
||||
gl_rend_state.bind_shader_storage_buffer(buffer, true);
|
||||
gl_st.bind_shader_storage_buffer(buffer, true);
|
||||
if (GL_VERSION_4_4)
|
||||
glBufferStorage(GL_SHADER_STORAGE_BUFFER, (GLsizeiptr)size,
|
||||
0, GL_DYNAMIC_STORAGE_BIT | GL_MAP_WRITE_BIT);
|
||||
@@ -30,7 +27,7 @@ namespace GL {
|
||||
}
|
||||
}
|
||||
|
||||
void ShaderStorageBuffer::Create(size_t size, const void* data, bool dynamic) {
|
||||
void ShaderStorageBuffer::Create(gl_state_struct& gl_st, size_t size, const void* data, bool dynamic) {
|
||||
if (buffer)
|
||||
return;
|
||||
|
||||
@@ -41,7 +38,7 @@ namespace GL {
|
||||
}
|
||||
else {
|
||||
glGenBuffers(1, &buffer);
|
||||
gl_rend_state.bind_shader_storage_buffer(buffer, true);
|
||||
gl_st.bind_shader_storage_buffer(buffer, true);
|
||||
if (GL_VERSION_4_4)
|
||||
glBufferStorage(GL_SHADER_STORAGE_BUFFER, (GLsizeiptr)size, data,
|
||||
dynamic ? GL_DYNAMIC_STORAGE_BIT | GL_MAP_WRITE_BIT : 0);
|
||||
@@ -58,7 +55,7 @@ namespace GL {
|
||||
}
|
||||
}
|
||||
|
||||
void* ShaderStorageBuffer::MapMemory() {
|
||||
void* ShaderStorageBuffer::MapMemory(gl_state_struct& gl_st) {
|
||||
if (!buffer)
|
||||
return 0;
|
||||
|
||||
@@ -66,7 +63,7 @@ namespace GL {
|
||||
if (GL_VERSION_4_5)
|
||||
data = glMapNamedBuffer(buffer, GL_WRITE_ONLY);
|
||||
else {
|
||||
gl_rend_state.bind_shader_storage_buffer(buffer);
|
||||
gl_st.bind_shader_storage_buffer(buffer);
|
||||
data = glMapBuffer(GL_SHADER_STORAGE_BUFFER, GL_WRITE_ONLY);
|
||||
}
|
||||
|
||||
@@ -77,12 +74,36 @@ namespace GL {
|
||||
glUnmapNamedBuffer(buffer);
|
||||
else {
|
||||
glUnmapBuffer(GL_SHADER_STORAGE_BUFFER);
|
||||
gl_rend_state.bind_shader_storage_buffer(0);
|
||||
gl_st.bind_shader_storage_buffer(0);
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
|
||||
void ShaderStorageBuffer::UnmapMemory() {
|
||||
void* ShaderStorageBuffer::MapMemory(p_gl_rend_state& p_gl_rend_st) {
|
||||
if (!buffer)
|
||||
return 0;
|
||||
|
||||
void* data;
|
||||
if (GL_VERSION_4_5)
|
||||
data = glMapNamedBuffer(buffer, GL_WRITE_ONLY);
|
||||
else {
|
||||
p_gl_rend_st.bind_shader_storage_buffer(buffer);
|
||||
data = glMapBuffer(GL_SHADER_STORAGE_BUFFER, GL_WRITE_ONLY);
|
||||
}
|
||||
|
||||
if (data)
|
||||
return data;
|
||||
|
||||
if (GL_VERSION_4_5)
|
||||
glUnmapNamedBuffer(buffer);
|
||||
else {
|
||||
glUnmapBuffer(GL_SHADER_STORAGE_BUFFER);
|
||||
p_gl_rend_st.bind_shader_storage_buffer(0);
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
|
||||
void ShaderStorageBuffer::UnmapMemory(gl_state_struct& gl_st) {
|
||||
if (!buffer)
|
||||
return;
|
||||
|
||||
@@ -90,18 +111,42 @@ namespace GL {
|
||||
glUnmapNamedBuffer(buffer);
|
||||
else {
|
||||
glUnmapBuffer(GL_SHADER_STORAGE_BUFFER);
|
||||
gl_rend_state.bind_shader_storage_buffer(0);
|
||||
gl_st.bind_shader_storage_buffer(0);
|
||||
}
|
||||
}
|
||||
|
||||
void ShaderStorageBuffer::WriteMemory(size_t offset, size_t size, const void* data) {
|
||||
void ShaderStorageBuffer::UnmapMemory(p_gl_rend_state& p_gl_rend_st) {
|
||||
if (!buffer)
|
||||
return;
|
||||
|
||||
if (GL_VERSION_4_5)
|
||||
glUnmapNamedBuffer(buffer);
|
||||
else {
|
||||
glUnmapBuffer(GL_SHADER_STORAGE_BUFFER);
|
||||
p_gl_rend_st.bind_shader_storage_buffer(0);
|
||||
}
|
||||
}
|
||||
|
||||
void ShaderStorageBuffer::WriteMemory(gl_state_struct& gl_st, size_t offset, size_t size, const void* data) {
|
||||
if (!buffer || !size)
|
||||
return;
|
||||
|
||||
if (GL_VERSION_4_5)
|
||||
glNamedBufferSubData(buffer, (GLsizeiptr)offset, (GLsizeiptr)size, data);
|
||||
else {
|
||||
gl_rend_state.bind_shader_storage_buffer(buffer);
|
||||
gl_st.bind_shader_storage_buffer(buffer);
|
||||
glBufferSubData(GL_SHADER_STORAGE_BUFFER, (GLsizeiptr)offset, (GLsizeiptr)size, data);
|
||||
}
|
||||
}
|
||||
|
||||
void ShaderStorageBuffer::WriteMemory(p_gl_rend_state& p_gl_rend_st, size_t offset, size_t size, const void* data) {
|
||||
if (!buffer || !size)
|
||||
return;
|
||||
|
||||
if (GL_VERSION_4_5)
|
||||
glNamedBufferSubData(buffer, (GLsizeiptr)offset, (GLsizeiptr)size, data);
|
||||
else {
|
||||
p_gl_rend_st.bind_shader_storage_buffer(buffer);
|
||||
glBufferSubData(GL_SHADER_STORAGE_BUFFER, (GLsizeiptr)offset, (GLsizeiptr)size, data);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -8,6 +8,9 @@
|
||||
#include "../../KKdLib/default.hpp"
|
||||
#include "../gl.hpp"
|
||||
|
||||
struct gl_state_struct;
|
||||
struct p_gl_rend_state;
|
||||
|
||||
namespace GL {
|
||||
struct ShaderStorageBuffer {
|
||||
private:
|
||||
@@ -26,13 +29,15 @@ namespace GL {
|
||||
|
||||
}
|
||||
|
||||
void Bind(int32_t index, bool force = false);
|
||||
void Create(size_t size);
|
||||
void Create(size_t size, const void* data, bool dynamic = false);
|
||||
void Create(gl_state_struct& gl_st, size_t size);
|
||||
void Create(gl_state_struct& gl_st, size_t size, const void* data, bool dynamic = false);
|
||||
void Destroy();
|
||||
void* MapMemory();
|
||||
void UnmapMemory();
|
||||
void WriteMemory(size_t offset, size_t size, const void* data);
|
||||
void* MapMemory(gl_state_struct& gl_st);
|
||||
void* MapMemory(p_gl_rend_state& p_gl_rend_st);
|
||||
void UnmapMemory(gl_state_struct& gl_st);
|
||||
void UnmapMemory(p_gl_rend_state& p_gl_rend_st);
|
||||
void WriteMemory(gl_state_struct& gl_st, size_t offset, size_t size, const void* data);
|
||||
void WriteMemory(p_gl_rend_state& p_gl_rend_st, size_t offset, size_t size, const void* data);
|
||||
|
||||
inline bool IsNull() {
|
||||
return !buffer;
|
||||
@@ -43,8 +48,13 @@ namespace GL {
|
||||
}
|
||||
|
||||
template<typename T>
|
||||
inline void WriteMemory(T& data) {
|
||||
WriteMemory(0, sizeof(T), &data);
|
||||
inline void WriteMemory(gl_state_struct& gl_st, T& data) {
|
||||
WriteMemory(gl_st, 0, sizeof(T), &data);
|
||||
}
|
||||
|
||||
template<typename T>
|
||||
inline void WriteMemory(p_gl_rend_state& p_gl_rend_st, T& data) {
|
||||
WriteMemory(p_gl_rend_st, 0, sizeof(T), &data);
|
||||
}
|
||||
|
||||
inline operator GLuint() const {
|
||||
|
||||
@@ -5,13 +5,10 @@
|
||||
|
||||
#include "uniform_buffer.hpp"
|
||||
#include "../gl_rend_state.hpp"
|
||||
#include "../gl_state.hpp"
|
||||
|
||||
namespace GL {
|
||||
void UniformBuffer::Bind(int32_t index, bool force) {
|
||||
gl_rend_state.bind_uniform_buffer_base(index, buffer, force);
|
||||
}
|
||||
|
||||
void UniformBuffer::Create(size_t size) {
|
||||
void UniformBuffer::Create(gl_state_struct& gl_st, size_t size) {
|
||||
if (buffer)
|
||||
return;
|
||||
|
||||
@@ -21,7 +18,7 @@ namespace GL {
|
||||
}
|
||||
else {
|
||||
glGenBuffers(1, &buffer);
|
||||
gl_rend_state.bind_uniform_buffer(buffer, true);
|
||||
gl_st.bind_uniform_buffer(buffer, true);
|
||||
if (GL_VERSION_4_4)
|
||||
glBufferStorage(GL_UNIFORM_BUFFER, (GLsizeiptr)size,
|
||||
0, GL_DYNAMIC_STORAGE_BIT | GL_MAP_WRITE_BIT);
|
||||
@@ -30,7 +27,7 @@ namespace GL {
|
||||
}
|
||||
}
|
||||
|
||||
void UniformBuffer::Create(size_t size, const void* data, bool dynamic) {
|
||||
void UniformBuffer::Create(gl_state_struct& gl_st, size_t size, const void* data, bool dynamic) {
|
||||
if (buffer)
|
||||
return;
|
||||
|
||||
@@ -41,7 +38,7 @@ namespace GL {
|
||||
}
|
||||
else {
|
||||
glGenBuffers(1, &buffer);
|
||||
gl_rend_state.bind_uniform_buffer(buffer, true);
|
||||
gl_st.bind_uniform_buffer(buffer, true);
|
||||
if (GL_VERSION_4_4)
|
||||
glBufferStorage(GL_UNIFORM_BUFFER, (GLsizeiptr)size, data,
|
||||
dynamic ? GL_DYNAMIC_STORAGE_BIT | GL_MAP_WRITE_BIT : 0);
|
||||
@@ -58,7 +55,7 @@ namespace GL {
|
||||
}
|
||||
}
|
||||
|
||||
void* UniformBuffer::MapMemory() {
|
||||
void* UniformBuffer::MapMemory(gl_state_struct& gl_st) {
|
||||
if (!buffer)
|
||||
return 0;
|
||||
|
||||
@@ -66,7 +63,7 @@ namespace GL {
|
||||
if (GL_VERSION_4_5)
|
||||
data = glMapNamedBuffer(buffer, GL_WRITE_ONLY);
|
||||
else {
|
||||
gl_rend_state.bind_uniform_buffer(buffer);
|
||||
gl_st.bind_uniform_buffer(buffer);
|
||||
data = glMapBuffer(GL_UNIFORM_BUFFER, GL_WRITE_ONLY);
|
||||
}
|
||||
|
||||
@@ -77,12 +74,36 @@ namespace GL {
|
||||
glUnmapNamedBuffer(buffer);
|
||||
else {
|
||||
glUnmapBuffer(GL_UNIFORM_BUFFER);
|
||||
gl_rend_state.bind_uniform_buffer(0);
|
||||
gl_st.bind_uniform_buffer(0);
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
|
||||
void UniformBuffer::UnmapMemory() {
|
||||
void* UniformBuffer::MapMemory(p_gl_rend_state& p_gl_rend_st) {
|
||||
if (!buffer)
|
||||
return 0;
|
||||
|
||||
void* data;
|
||||
if (GL_VERSION_4_5)
|
||||
data = glMapNamedBuffer(buffer, GL_WRITE_ONLY);
|
||||
else {
|
||||
p_gl_rend_st.bind_uniform_buffer(buffer);
|
||||
data = glMapBuffer(GL_UNIFORM_BUFFER, GL_WRITE_ONLY);
|
||||
}
|
||||
|
||||
if (data)
|
||||
return data;
|
||||
|
||||
if (GL_VERSION_4_5)
|
||||
glUnmapNamedBuffer(buffer);
|
||||
else {
|
||||
glUnmapBuffer(GL_UNIFORM_BUFFER);
|
||||
p_gl_rend_st.bind_uniform_buffer(0);
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
|
||||
void UniformBuffer::UnmapMemory(gl_state_struct& gl_st) {
|
||||
if (!buffer)
|
||||
return;
|
||||
|
||||
@@ -90,18 +111,42 @@ namespace GL {
|
||||
glUnmapNamedBuffer(buffer);
|
||||
else {
|
||||
glUnmapBuffer(GL_UNIFORM_BUFFER);
|
||||
gl_rend_state.bind_uniform_buffer(0);
|
||||
gl_st.bind_uniform_buffer(0);
|
||||
}
|
||||
}
|
||||
|
||||
void UniformBuffer::WriteMemory(size_t offset, size_t size, const void* data) {
|
||||
void UniformBuffer::UnmapMemory(p_gl_rend_state& p_gl_rend_st) {
|
||||
if (!buffer)
|
||||
return;
|
||||
|
||||
if (GL_VERSION_4_5)
|
||||
glUnmapNamedBuffer(buffer);
|
||||
else {
|
||||
glUnmapBuffer(GL_UNIFORM_BUFFER);
|
||||
p_gl_rend_st.bind_uniform_buffer(0);
|
||||
}
|
||||
}
|
||||
|
||||
void UniformBuffer::WriteMemory(gl_state_struct& gl_st, size_t offset, size_t size, const void* data) {
|
||||
if (!buffer || !size)
|
||||
return;
|
||||
|
||||
if (GL_VERSION_4_5)
|
||||
glNamedBufferSubData(buffer, (GLsizeiptr)offset, (GLsizeiptr)size, data);
|
||||
else {
|
||||
gl_rend_state.bind_uniform_buffer(buffer);
|
||||
gl_st.bind_uniform_buffer(buffer);
|
||||
glBufferSubData(GL_UNIFORM_BUFFER, (GLsizeiptr)offset, (GLsizeiptr)size, data);
|
||||
}
|
||||
}
|
||||
|
||||
void UniformBuffer::WriteMemory(p_gl_rend_state& p_gl_rend_st, size_t offset, size_t size, const void* data) {
|
||||
if (!buffer || !size)
|
||||
return;
|
||||
|
||||
if (GL_VERSION_4_5)
|
||||
glNamedBufferSubData(buffer, (GLsizeiptr)offset, (GLsizeiptr)size, data);
|
||||
else {
|
||||
p_gl_rend_st.bind_uniform_buffer(buffer);
|
||||
glBufferSubData(GL_UNIFORM_BUFFER, (GLsizeiptr)offset, (GLsizeiptr)size, data);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -8,6 +8,9 @@
|
||||
#include "../../KKdLib/default.hpp"
|
||||
#include "../gl.hpp"
|
||||
|
||||
struct gl_state_struct;
|
||||
struct p_gl_rend_state;
|
||||
|
||||
namespace GL {
|
||||
struct UniformBuffer {
|
||||
private:
|
||||
@@ -26,13 +29,15 @@ namespace GL {
|
||||
|
||||
}
|
||||
|
||||
void Bind(int32_t index, bool force = false);
|
||||
void Create(size_t size);
|
||||
void Create(size_t size, const void* data, bool dynamic = false);
|
||||
void Create(gl_state_struct& gl_st, size_t size);
|
||||
void Create(gl_state_struct& gl_st, size_t size, const void* data, bool dynamic = false);
|
||||
void Destroy();
|
||||
void* MapMemory();
|
||||
void UnmapMemory();
|
||||
void WriteMemory(size_t offset, size_t size, const void* data);
|
||||
void* MapMemory(gl_state_struct& gl_st);
|
||||
void* MapMemory(p_gl_rend_state& p_gl_rend_st);
|
||||
void UnmapMemory(gl_state_struct& gl_st);
|
||||
void UnmapMemory(p_gl_rend_state& p_gl_rend_st);
|
||||
void WriteMemory(gl_state_struct& gl_st, size_t offset, size_t size, const void* data);
|
||||
void WriteMemory(p_gl_rend_state& p_gl_rend_st, size_t offset, size_t size, const void* data);
|
||||
|
||||
inline bool IsNull() {
|
||||
return !buffer;
|
||||
@@ -43,8 +48,13 @@ namespace GL {
|
||||
}
|
||||
|
||||
template<typename T>
|
||||
inline void WriteMemory(T& data) {
|
||||
WriteMemory(0, sizeof(T), &data);
|
||||
inline void WriteMemory(gl_state_struct& gl_st, T& data) {
|
||||
WriteMemory(gl_st, 0, sizeof(T), &data);
|
||||
}
|
||||
|
||||
template<typename T>
|
||||
inline void WriteMemory(p_gl_rend_state& p_gl_rend_st, T& data) {
|
||||
WriteMemory(p_gl_rend_st, 0, sizeof(T), &data);
|
||||
}
|
||||
|
||||
inline operator GLuint() const {
|
||||
|
||||
@@ -204,8 +204,8 @@ namespace Glitter {
|
||||
}
|
||||
}
|
||||
|
||||
void F2EffectInst::Disp(GPM, DispType disp_type) {
|
||||
render_scene.Disp(GPM_VAL, disp_type);
|
||||
void F2EffectInst::Disp(GPM, render_data_context& rend_data_ct, DispType disp_type) {
|
||||
render_scene.Disp(GPM_VAL, rend_data_ct, disp_type);
|
||||
}
|
||||
|
||||
void F2EffectInst::DispMesh(GPM) {
|
||||
@@ -784,8 +784,8 @@ namespace Glitter {
|
||||
}
|
||||
}
|
||||
|
||||
void XEffectInst::Disp(GPM, DispType disp_type) {
|
||||
render_scene.Disp(GPM_VAL, disp_type);
|
||||
void XEffectInst::Disp(GPM, render_data_context& rend_data_ct, DispType disp_type) {
|
||||
render_scene.Disp(GPM_VAL, rend_data_ct, disp_type);
|
||||
}
|
||||
|
||||
void XEffectInst::DispMesh(GPM) {
|
||||
|
||||
@@ -10,6 +10,7 @@
|
||||
#include "../../KKdLib/farc.hpp"
|
||||
#include "../../KKdLib/msgpack.hpp"
|
||||
#include "../data.hpp"
|
||||
#include "../gl_state.hpp"
|
||||
#include "../object.hpp"
|
||||
#if SHARED_GLITTER_BUFFER
|
||||
#include "../gl_rend_state.hpp"
|
||||
@@ -119,7 +120,7 @@ namespace Glitter {
|
||||
|
||||
static const GLsizei buffer_size = sizeof(Buffer);
|
||||
|
||||
effect_group->vbo.Create(buffer_size * max_count);
|
||||
effect_group->vbo.Create(gl_state, buffer_size * max_count);
|
||||
|
||||
if (max_count_quad) {
|
||||
size_t count = max_count_quad / 4 * 5;
|
||||
@@ -132,7 +133,7 @@ namespace Glitter {
|
||||
ebo_data[i + 4] = 0xFFFFFFFF;
|
||||
}
|
||||
|
||||
effect_group->ebo.Create(sizeof(uint32_t) * count, ebo_data);
|
||||
effect_group->ebo.Create(gl_state, sizeof(uint32_t) * count, ebo_data);
|
||||
free_def(ebo_data);
|
||||
}
|
||||
else
|
||||
@@ -160,10 +161,10 @@ namespace Glitter {
|
||||
k->buffer = buffer;
|
||||
|
||||
glGenVertexArrays(1, &k->vao);
|
||||
glBindVertexArray(k->vao);
|
||||
glBindBuffer(GL_ARRAY_BUFFER, vbo);
|
||||
gl_state.bind_vertex_array(k->vao);
|
||||
gl_state.bind_array_buffer(vbo);
|
||||
if (k->data.type == PARTICLE_QUAD)
|
||||
glBindBuffer(GL_ELEMENT_ARRAY_BUFFER, ebo);
|
||||
gl_state.bind_element_array_buffer(ebo, true);
|
||||
|
||||
glEnableVertexAttribArray(0);
|
||||
glVertexAttribPointer(0, 3, GL_FLOAT, GL_FALSE, buffer_size,
|
||||
@@ -184,9 +185,9 @@ namespace Glitter {
|
||||
}
|
||||
|
||||
if (offset) {
|
||||
glBindBuffer(GL_ARRAY_BUFFER, 0);
|
||||
glBindVertexArray(0);
|
||||
glBindBuffer(GL_ELEMENT_ARRAY_BUFFER, 0);
|
||||
gl_state.bind_array_buffer(0);
|
||||
gl_state.bind_vertex_array(0);
|
||||
gl_state.bind_element_array_buffer(0);
|
||||
}
|
||||
}
|
||||
else {
|
||||
|
||||
@@ -4,7 +4,7 @@
|
||||
*/
|
||||
|
||||
#include "glitter.hpp"
|
||||
#include "../gl_rend_state.hpp"
|
||||
#include "../gl_state.hpp"
|
||||
|
||||
namespace Glitter {
|
||||
const float_t min_emission = 0.01f;
|
||||
@@ -271,12 +271,12 @@ namespace Glitter {
|
||||
buffer = force_malloc<Buffer>(max_count);
|
||||
|
||||
glGenVertexArrays(1, &vao);
|
||||
gl_rend_state.bind_vertex_array(vao, true);
|
||||
gl_state.bind_vertex_array(vao, true);
|
||||
|
||||
static const GLsizei buffer_size = sizeof(Buffer);
|
||||
|
||||
vbo.Create(buffer_size * max_count);
|
||||
vbo.Bind(true);
|
||||
gl_state.bind_array_buffer(vbo);
|
||||
|
||||
if (is_quad) {
|
||||
size_t count = max_count / 4 * 5;
|
||||
@@ -290,7 +290,7 @@ namespace Glitter {
|
||||
}
|
||||
|
||||
ebo.Create(sizeof(uint32_t) * count, ebo_data);
|
||||
ebo.Bind(true);
|
||||
gl_state.bind_element_array_buffer(ebo);
|
||||
free_def(ebo_data);
|
||||
}
|
||||
|
||||
@@ -304,10 +304,10 @@ namespace Glitter {
|
||||
glVertexAttribPointer(2, 4, GL_FLOAT, GL_FALSE, buffer_size,
|
||||
(void*)offsetof(Buffer, color));
|
||||
|
||||
gl_rend_state.bind_array_buffer(0);
|
||||
gl_rend_state.bind_vertex_array(0);
|
||||
gl_state.bind_array_buffer(0);
|
||||
gl_state.bind_vertex_array(0);
|
||||
if (is_quad)
|
||||
gl_rend_state.bind_element_array_buffer(0);
|
||||
gl_state.bind_element_array_buffer(0);
|
||||
}
|
||||
|
||||
void DeleteBuffer(Buffer*& buffer, GLuint& vao, GL::ArrayBuffer& vbo, GL::ElementArrayBuffer& ebo) {
|
||||
|
||||
@@ -29,6 +29,8 @@
|
||||
|
||||
#define SHARED_GLITTER_BUFFER (1)
|
||||
|
||||
struct render_data_context;
|
||||
|
||||
namespace Glitter {
|
||||
enum CurveFlag {
|
||||
CURVE_RANDOM_RANGE = 0x01,
|
||||
@@ -856,8 +858,8 @@ namespace Glitter {
|
||||
void CalcDispQuadNormal(GPM,
|
||||
F2RenderGroup* rend_group, mat4* model_mat, mat4* dir_mat);
|
||||
void Ctrl(GLT, float_t delta_frame);
|
||||
void Disp(GPM, DispType disp_type);
|
||||
void Disp(GPM, F2RenderGroup* rend_group);
|
||||
void Disp(GPM, render_data_context& rend_data_ct, DispType disp_type);
|
||||
void Disp(GPM, render_data_context& rend_data_ct, F2RenderGroup* rend_group);
|
||||
};
|
||||
|
||||
class XRenderScene : public RenderScene {
|
||||
@@ -878,8 +880,8 @@ namespace Glitter {
|
||||
bool CanDisp(DispType disp_type, bool a3);
|
||||
void CheckUseCamera();
|
||||
void Ctrl(float_t delta_frame, bool copy_mats);
|
||||
void Disp(GPM, DispType disp_type);
|
||||
void Disp(GPM, XRenderGroup* rend_group);
|
||||
void Disp(GPM, render_data_context& rend_data_ct, DispType disp_type);
|
||||
void Disp(GPM, render_data_context& rend_data_ct, XRenderGroup* rend_group);
|
||||
void DispMesh(GPM);
|
||||
void DispMesh(GPM, XRenderGroup* rend_group);
|
||||
};
|
||||
@@ -912,7 +914,7 @@ namespace Glitter {
|
||||
|
||||
virtual void CalcDisp(GPM) = 0;
|
||||
virtual void Copy(EffectInst* dst, float_t emission) = 0;
|
||||
virtual void Disp(GPM, DispType disp_type) = 0;
|
||||
virtual void Disp(GPM, render_data_context& rend_data_ct, DispType disp_type) = 0;
|
||||
virtual void DispMesh(GPM) = 0;
|
||||
virtual void Free(GPM, GLT, float_t emission, bool free) = 0;
|
||||
virtual size_t GetCtrlCount(ParticleType type) = 0;
|
||||
@@ -965,7 +967,7 @@ namespace Glitter {
|
||||
|
||||
virtual void CalcDisp(GPM) override;
|
||||
virtual void Copy(EffectInst* dst, float_t emission) override;
|
||||
virtual void Disp(GPM, DispType disp_type) override;
|
||||
virtual void Disp(GPM, render_data_context& rend_data_ct, DispType disp_type) override;
|
||||
virtual void DispMesh(GPM) override;
|
||||
virtual void Free(GPM, GLT, float_t emission, bool free) override;
|
||||
virtual size_t GetCtrlCount(ParticleType type) override;
|
||||
@@ -1031,7 +1033,7 @@ namespace Glitter {
|
||||
|
||||
virtual void CalcDisp(GPM) override;
|
||||
virtual void Copy(EffectInst* dst, float_t emission) override;
|
||||
virtual void Disp(GPM, DispType disp_type) override;
|
||||
virtual void Disp(GPM, render_data_context& rend_data_ct, DispType disp_type) override;
|
||||
virtual void DispMesh(GPM) override;
|
||||
virtual void Free(GPM, GLT, float_t emission, bool free) override;
|
||||
virtual size_t GetCtrlCount(ParticleType type) override;
|
||||
@@ -1623,7 +1625,7 @@ namespace Glitter {
|
||||
void CheckUpdate(float_t delta_frame);
|
||||
bool Copy(EffectInst* eff_inst, Scene* dst);
|
||||
void Ctrl(GPM, float_t delta_frame);
|
||||
void Disp(GPM, DispType disp_type);
|
||||
void Disp(GPM, render_data_context& rend_data_ct, DispType disp_type);
|
||||
void DispMesh(GPM);
|
||||
size_t GetCtrlCount(ParticleType ptcl_type);
|
||||
size_t GetDispCount(ParticleType ptcl_type);
|
||||
@@ -1687,7 +1689,7 @@ namespace Glitter {
|
||||
void CheckSceneHasLocalEffect(Scene* sc);
|
||||
void CtrlScenes();
|
||||
void DecrementInitBuffersByCount(int32_t count = 1);
|
||||
void DispScenes(DispType disp_type);
|
||||
void DispScenes(render_data_context& rend_data_ct, DispType disp_type);
|
||||
void FreeEffects();
|
||||
void FreeSceneEffect(SceneCounter scene_counter, bool force_kill = true);
|
||||
void FreeSceneEffect(uint64_t effect_group_hash, uint64_t effect_hash, bool force_kill = true);
|
||||
|
||||
@@ -272,7 +272,7 @@ namespace Glitter {
|
||||
init_buffers = max_def(init_buffers - count, 0);
|
||||
}
|
||||
|
||||
void GltParticleManager::DispScenes(DispType disp_type) {
|
||||
void GltParticleManager::DispScenes(render_data_context& rend_data_ctx, DispType disp_type) {
|
||||
if (flags & PARTICLE_MANAGER_NOT_DISP)
|
||||
return;
|
||||
|
||||
@@ -281,13 +281,13 @@ namespace Glitter {
|
||||
&& selected_effect_group != i->effect_group)
|
||||
continue;
|
||||
|
||||
i->Disp(this, disp_type);
|
||||
i->Disp(this, rend_data_ctx, disp_type);
|
||||
}
|
||||
|
||||
gl_rend_state.bind_vertex_array(0);
|
||||
gl_rend_state.disable_blend();
|
||||
gl_rend_state.enable_cull_face();
|
||||
gl_rend_state.disable_depth_test();
|
||||
rend_data_ctx.state.bind_vertex_array(0);
|
||||
rend_data_ctx.state.disable_blend();
|
||||
rend_data_ctx.state.enable_cull_face();
|
||||
rend_data_ctx.state.disable_depth_test();
|
||||
}
|
||||
|
||||
void GltParticleManager::FreeEffects() {
|
||||
|
||||
+112
-114
@@ -908,7 +908,7 @@ namespace Glitter {
|
||||
}
|
||||
}
|
||||
|
||||
void F2RenderScene::Disp(GPM, DispType disp_type) {
|
||||
void F2RenderScene::Disp(GPM, render_data_context& rend_data_ctx, DispType disp_type) {
|
||||
Effect* eff = GPM_VAL->selected_effect;
|
||||
Emitter* emit = GPM_VAL->selected_emitter;
|
||||
Particle* ptcl = GPM_VAL->selected_particle;
|
||||
@@ -922,11 +922,11 @@ namespace Glitter {
|
||||
continue;
|
||||
|
||||
if (!GPM_VAL->draw_selected || !eff) {
|
||||
Disp(GPM_VAL, rend_group);
|
||||
Disp(GPM_VAL, rend_data_ctx, rend_group);
|
||||
}
|
||||
else if ((eff && ptcl) || (eff && !emit)) {
|
||||
if (!ptcl || rend_group->particle->particle == ptcl)
|
||||
Disp(GPM_VAL, rend_group);
|
||||
Disp(GPM_VAL, rend_data_ctx, rend_group);
|
||||
}
|
||||
else if (emit)
|
||||
for (Particle*& j : emit->particles) {
|
||||
@@ -935,12 +935,12 @@ namespace Glitter {
|
||||
|
||||
Particle* particle = j;
|
||||
if (rend_group->particle->particle == particle)
|
||||
Disp(GPM_VAL, rend_group);
|
||||
Disp(GPM_VAL, rend_data_ctx, rend_group);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
void F2RenderScene::Disp(GPM, F2RenderGroup* rend_group) {
|
||||
void F2RenderScene::Disp(GPM, render_data_context& rend_data_ctx, F2RenderGroup* rend_group) {
|
||||
switch (rend_group->type) {
|
||||
case PARTICLE_QUAD:
|
||||
case PARTICLE_LINE:
|
||||
@@ -970,7 +970,7 @@ namespace Glitter {
|
||||
shader_data.g_glitter_blend_color = 1.0f;
|
||||
shader_data.g_state_material_diffuse = 0.0f;
|
||||
shader_data.g_state_material_emission = { emission, emission, emission, 1.0f };
|
||||
rctx_ptr->glitter_batch_ubo.WriteMemory(shader_data);
|
||||
rctx_ptr->glitter_batch_ubo.WriteMemory(rend_data_ctx.state, shader_data);
|
||||
|
||||
GLenum blend_src;
|
||||
GLenum blend_dst;
|
||||
@@ -995,8 +995,8 @@ namespace Glitter {
|
||||
break;
|
||||
}
|
||||
|
||||
gl_rend_state.set_blend_func(blend_src, blend_dst);
|
||||
gl_rend_state.set_blend_equation(GL_FUNC_ADD);
|
||||
rend_data_ctx.state.set_blend_func(blend_src, blend_dst);
|
||||
rend_data_ctx.state.set_blend_equation(GL_FUNC_ADD);
|
||||
|
||||
GLuint texture = rctx_ptr->empty_texture_2d->glid;
|
||||
GLuint mask_texture = rctx_ptr->empty_texture_2d->glid;
|
||||
@@ -1005,117 +1005,116 @@ namespace Glitter {
|
||||
if (rend_group->mask_texture) {
|
||||
mask_texture = rend_group->mask_texture;
|
||||
|
||||
uniform_value[U_TEXTURE_COUNT] = 2;
|
||||
rend_data_ctx.shader_flags.arr[U_TEXTURE_COUNT] = 2;
|
||||
switch (rend_group->mask_blend_mode) {
|
||||
default:
|
||||
uniform_value[U_TEXTURE_BLEND] = 0;
|
||||
rend_data_ctx.shader_flags.arr[U_TEXTURE_BLEND] = 0;
|
||||
break;
|
||||
case PARTICLE_BLEND_MULTIPLY:
|
||||
uniform_value[U_TEXTURE_BLEND] = 1;
|
||||
rend_data_ctx.shader_flags.arr[U_TEXTURE_BLEND] = 1;
|
||||
break;
|
||||
case PARTICLE_BLEND_ADD:
|
||||
uniform_value[U_TEXTURE_BLEND] = 2;
|
||||
rend_data_ctx.shader_flags.arr[U_TEXTURE_BLEND] = 2;
|
||||
break;
|
||||
}
|
||||
}
|
||||
else {
|
||||
uniform_value[U_TEXTURE_COUNT] = 1;
|
||||
uniform_value[U_TEXTURE_BLEND] = 0;
|
||||
rend_data_ctx.shader_flags.arr[U_TEXTURE_COUNT] = 1;
|
||||
rend_data_ctx.shader_flags.arr[U_TEXTURE_BLEND] = 0;
|
||||
}
|
||||
}
|
||||
else {
|
||||
uniform_value[U_TEXTURE_COUNT] = 0;
|
||||
uniform_value[U_TEXTURE_BLEND] = 0;
|
||||
rend_data_ctx.shader_flags.arr[U_TEXTURE_COUNT] = 0;
|
||||
rend_data_ctx.shader_flags.arr[U_TEXTURE_BLEND] = 0;
|
||||
}
|
||||
|
||||
gl_rend_state.active_bind_texture_2d(0, texture);
|
||||
gl_rend_state.active_bind_texture_2d(1, mask_texture);
|
||||
rend_data_ctx.state.active_bind_texture_2d(0, texture);
|
||||
rend_data_ctx.state.active_bind_texture_2d(1, mask_texture);
|
||||
|
||||
switch (rend_group->type) {
|
||||
case PARTICLE_QUAD:
|
||||
switch (rend_group->fog_type) {
|
||||
default:
|
||||
uniform_value[U_FOG_STAGE] = 0;
|
||||
rend_data_ctx.shader_flags.arr[U_FOG_STAGE] = 0;
|
||||
break;
|
||||
case Glitter::FOG_DEPTH:
|
||||
uniform_value[U_FOG_STAGE] = 1;
|
||||
rend_data_ctx.shader_flags.arr[U_FOG_STAGE] = 1;
|
||||
break;
|
||||
case Glitter::FOG_HEIGHT:
|
||||
uniform_value[U_FOG_STAGE] = 2;
|
||||
rend_data_ctx.shader_flags.arr[U_FOG_STAGE] = 2;
|
||||
break;
|
||||
}
|
||||
|
||||
gl_rend_state.enable_depth_test();
|
||||
rend_data_ctx.state.enable_depth_test();
|
||||
|
||||
if (alpha_test) {
|
||||
uniform_value[U_ALPHA_TEST] = 1;
|
||||
rctx_ptr->set_batch_alpha_threshold(0.5f);
|
||||
uniform_value[U_ALPHA_BLEND] = 1;
|
||||
gl_rend_state.set_depth_mask(GL_TRUE);
|
||||
gl_rend_state.disable_blend();
|
||||
rend_data_ctx.shader_flags.arr[U_ALPHA_TEST] = 1;
|
||||
rend_data_ctx.set_batch_alpha_threshold(0.5f);
|
||||
rend_data_ctx.shader_flags.arr[U_ALPHA_BLEND] = 1;
|
||||
rend_data_ctx.state.set_depth_mask(GL_TRUE);
|
||||
rend_data_ctx.state.disable_blend();
|
||||
}
|
||||
else if (rend_group->disp_type) {
|
||||
uniform_value[U_ALPHA_TEST] = 0;
|
||||
uniform_value[U_ALPHA_BLEND] = 2;
|
||||
gl_rend_state.set_depth_mask(GL_FALSE);
|
||||
gl_rend_state.enable_blend();
|
||||
rend_data_ctx.shader_flags.arr[U_ALPHA_TEST] = 0;
|
||||
rend_data_ctx.shader_flags.arr[U_ALPHA_BLEND] = 2;
|
||||
rend_data_ctx.state.set_depth_mask(GL_FALSE);
|
||||
rend_data_ctx.state.enable_blend();
|
||||
}
|
||||
else {
|
||||
uniform_value[U_ALPHA_TEST] = 0;
|
||||
uniform_value[U_ALPHA_BLEND] = 0;
|
||||
gl_rend_state.set_depth_mask(GL_TRUE);
|
||||
gl_rend_state.disable_blend();
|
||||
rend_data_ctx.shader_flags.arr[U_ALPHA_TEST] = 0;
|
||||
rend_data_ctx.shader_flags.arr[U_ALPHA_BLEND] = 0;
|
||||
rend_data_ctx.state.set_depth_mask(GL_TRUE);
|
||||
rend_data_ctx.state.disable_blend();
|
||||
}
|
||||
|
||||
if (rend_group->draw_type == DIRECTION_BILLBOARD) {
|
||||
gl_rend_state.enable_cull_face();
|
||||
gl_rend_state.set_cull_face_mode(GL_BACK);
|
||||
rend_data_ctx.state.enable_cull_face();
|
||||
rend_data_ctx.state.set_cull_face_mode(GL_BACK);
|
||||
}
|
||||
else
|
||||
gl_rend_state.disable_cull_face();
|
||||
rend_data_ctx.state.disable_cull_face();
|
||||
break;
|
||||
case PARTICLE_LINE:
|
||||
uniform_value[U_ALPHA_TEST] = 0;
|
||||
uniform_value[U_ALPHA_BLEND] = 2;
|
||||
uniform_value[U_FOG_STAGE] = 0;
|
||||
rend_data_ctx.shader_flags.arr[U_ALPHA_TEST] = 0;
|
||||
rend_data_ctx.shader_flags.arr[U_ALPHA_BLEND] = 2;
|
||||
rend_data_ctx.shader_flags.arr[U_FOG_STAGE] = 0;
|
||||
|
||||
gl_rend_state.enable_depth_test();
|
||||
gl_rend_state.set_depth_mask(GL_FALSE);
|
||||
gl_rend_state.enable_blend();
|
||||
gl_rend_state.enable_cull_face();
|
||||
gl_rend_state.set_cull_face_mode(GL_BACK);
|
||||
rend_data_ctx.state.enable_depth_test();
|
||||
rend_data_ctx.state.set_depth_mask(GL_FALSE);
|
||||
rend_data_ctx.state.enable_blend();
|
||||
rend_data_ctx.state.enable_cull_face();
|
||||
rend_data_ctx.state.set_cull_face_mode(GL_BACK);
|
||||
break;
|
||||
case PARTICLE_LOCUS:
|
||||
uniform_value[U_ALPHA_TEST] = 0;
|
||||
uniform_value[U_ALPHA_BLEND] = 2;
|
||||
uniform_value[U_FOG_STAGE] = 0;
|
||||
rend_data_ctx.shader_flags.arr[U_ALPHA_TEST] = 0;
|
||||
rend_data_ctx.shader_flags.arr[U_ALPHA_BLEND] = 2;
|
||||
rend_data_ctx.shader_flags.arr[U_FOG_STAGE] = 0;
|
||||
|
||||
gl_rend_state.enable_depth_test();
|
||||
gl_rend_state.set_depth_mask(GL_FALSE);
|
||||
gl_rend_state.enable_blend();
|
||||
gl_rend_state.disable_cull_face();
|
||||
rend_data_ctx.state.enable_depth_test();
|
||||
rend_data_ctx.state.set_depth_mask(GL_FALSE);
|
||||
rend_data_ctx.state.enable_blend();
|
||||
rend_data_ctx.state.disable_cull_face();
|
||||
break;
|
||||
}
|
||||
|
||||
shaders_ft.set(SHADER_FT_GLITTER_PT);
|
||||
rctx_ptr->set_glitter_render_data();
|
||||
rctx_ptr->glitter_batch_ubo.Bind(3);
|
||||
shaders_ft.set(rend_data_ctx.state, rend_data_ctx.shader_flags, SHADER_FT_GLITTER_PT);
|
||||
rend_data_ctx.set_glitter_render_data_state();
|
||||
rend_data_ctx.state.bind_uniform_buffer_base(3, rctx_ptr->glitter_batch_ubo);
|
||||
switch (rend_group->type) {
|
||||
case PARTICLE_QUAD:
|
||||
gl_rend_state.bind_vertex_array(rend_group->vao);
|
||||
shaders_ft.enable_primitive_restart();
|
||||
shaders_ft.draw_elements(GL_TRIANGLE_STRIP, (GLsizei)(5 * rend_group->disp - 1), GL_UNSIGNED_INT, 0);
|
||||
shaders_ft.disable_primitive_restart();
|
||||
rend_data_ctx.state.bind_vertex_array(rend_group->vao);
|
||||
rend_data_ctx.state.draw_elements(GL_TRIANGLE_STRIP,
|
||||
(GLsizei)(5 * rend_group->disp - 1), GL_UNSIGNED_INT, 0);
|
||||
break;
|
||||
case PARTICLE_LINE:
|
||||
gl_rend_state.bind_vertex_array(rend_group->vao);
|
||||
rend_data_ctx.state.bind_vertex_array(rend_group->vao);
|
||||
for (std::pair<GLint, GLsizei>& i : rend_group->draw_list)
|
||||
shaders_ft.draw_arrays(GL_LINE_STRIP, i.first, i.second);
|
||||
rend_data_ctx.state.draw_arrays(GL_LINE_STRIP, i.first, i.second);
|
||||
break;
|
||||
case PARTICLE_LOCUS:
|
||||
gl_rend_state.bind_vertex_array(rend_group->vao);
|
||||
rend_data_ctx.state.bind_vertex_array(rend_group->vao);
|
||||
for (std::pair<GLint, GLsizei>& i : rend_group->draw_list)
|
||||
shaders_ft.draw_arrays(GL_TRIANGLE_STRIP, i.first, i.second);
|
||||
rend_data_ctx.state.draw_arrays(GL_TRIANGLE_STRIP, i.first, i.second);
|
||||
break;
|
||||
}
|
||||
}
|
||||
@@ -1884,7 +1883,7 @@ namespace Glitter {
|
||||
}
|
||||
}
|
||||
|
||||
void XRenderScene::Disp(GPM, DispType disp_type) {
|
||||
void XRenderScene::Disp(GPM, render_data_context& rend_data_ctx, DispType disp_type) {
|
||||
Effect* eff = GPM_VAL->selected_effect;
|
||||
Emitter* emit = GPM_VAL->selected_emitter;
|
||||
Particle* ptcl = GPM_VAL->selected_particle;
|
||||
@@ -1897,11 +1896,11 @@ namespace Glitter {
|
||||
continue;
|
||||
|
||||
if (!GPM_VAL->draw_selected || !eff) {
|
||||
Disp(GPM_VAL, rend_group);
|
||||
Disp(GPM_VAL, rend_data_ctx, rend_group);
|
||||
}
|
||||
else if ((eff && ptcl) || (eff && !emit)) {
|
||||
if (!ptcl || rend_group->particle->particle == ptcl)
|
||||
Disp(GPM_VAL, rend_group);
|
||||
Disp(GPM_VAL, rend_data_ctx, rend_group);
|
||||
}
|
||||
else if (emit)
|
||||
for (Particle*& j : emit->particles) {
|
||||
@@ -1910,12 +1909,12 @@ namespace Glitter {
|
||||
|
||||
Particle* particle = j;
|
||||
if (rend_group->particle->particle == particle)
|
||||
Disp(GPM_VAL, rend_group);
|
||||
Disp(GPM_VAL, rend_data_ctx, rend_group);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
void XRenderScene::Disp(GPM, XRenderGroup* rend_group) {
|
||||
void XRenderScene::Disp(GPM, render_data_context& rend_data_ctx, XRenderGroup* rend_group) {
|
||||
switch (rend_group->type) {
|
||||
case PARTICLE_QUAD:
|
||||
case PARTICLE_LINE:
|
||||
@@ -1950,7 +1949,7 @@ namespace Glitter {
|
||||
shader_data.g_glitter_blend_color = 1.0f;
|
||||
shader_data.g_state_material_diffuse = 0.0f;
|
||||
shader_data.g_state_material_emission = { emission, emission, emission, 1.0f };
|
||||
rctx_ptr->glitter_batch_ubo.WriteMemory(shader_data);
|
||||
rctx_ptr->glitter_batch_ubo.WriteMemory(rend_data_ctx.state, shader_data);
|
||||
|
||||
GLenum blend_src;
|
||||
GLenum blend_dst;
|
||||
@@ -1975,8 +1974,8 @@ namespace Glitter {
|
||||
break;
|
||||
}
|
||||
|
||||
gl_rend_state.set_blend_func(blend_src, blend_dst);
|
||||
gl_rend_state.set_blend_equation(GL_FUNC_ADD);
|
||||
rend_data_ctx.state.set_blend_func(blend_src, blend_dst);
|
||||
rend_data_ctx.state.set_blend_equation(GL_FUNC_ADD);
|
||||
|
||||
GLuint texture = rctx_ptr->empty_texture_2d->glid;
|
||||
GLuint mask_texture = rctx_ptr->empty_texture_2d->glid;
|
||||
@@ -1985,95 +1984,94 @@ namespace Glitter {
|
||||
if (rend_group->mask_texture) {
|
||||
mask_texture = rend_group->mask_texture;
|
||||
|
||||
uniform_value[U_TEXTURE_COUNT] = 2;
|
||||
rend_data_ctx.shader_flags.arr[U_TEXTURE_COUNT] = 2;
|
||||
switch (rend_group->mask_blend_mode) {
|
||||
default:
|
||||
uniform_value[U_TEXTURE_BLEND] = 0;
|
||||
rend_data_ctx.shader_flags.arr[U_TEXTURE_BLEND] = 0;
|
||||
break;
|
||||
case PARTICLE_BLEND_MULTIPLY:
|
||||
uniform_value[U_TEXTURE_BLEND] = 1;
|
||||
rend_data_ctx.shader_flags.arr[U_TEXTURE_BLEND] = 1;
|
||||
break;
|
||||
case PARTICLE_BLEND_ADD:
|
||||
uniform_value[U_TEXTURE_BLEND] = 2;
|
||||
rend_data_ctx.shader_flags.arr[U_TEXTURE_BLEND] = 2;
|
||||
break;
|
||||
}
|
||||
}
|
||||
else {
|
||||
uniform_value[U_TEXTURE_COUNT] = 1;
|
||||
uniform_value[U_TEXTURE_BLEND] = 0;
|
||||
rend_data_ctx.shader_flags.arr[U_TEXTURE_COUNT] = 1;
|
||||
rend_data_ctx.shader_flags.arr[U_TEXTURE_BLEND] = 0;
|
||||
}
|
||||
}
|
||||
else {
|
||||
uniform_value[U_TEXTURE_COUNT] = 0;
|
||||
uniform_value[U_TEXTURE_BLEND] = 0;
|
||||
rend_data_ctx.shader_flags.arr[U_TEXTURE_COUNT] = 0;
|
||||
rend_data_ctx.shader_flags.arr[U_TEXTURE_BLEND] = 0;
|
||||
}
|
||||
|
||||
gl_rend_state.active_bind_texture_2d(0, texture);
|
||||
gl_rend_state.active_bind_texture_2d(1, mask_texture);
|
||||
rend_data_ctx.state.active_bind_texture_2d(0, texture);
|
||||
rend_data_ctx.state.active_bind_texture_2d(1, mask_texture);
|
||||
|
||||
switch (rend_group->fog_type) {
|
||||
default:
|
||||
uniform_value[U_FOG_STAGE] = 0;
|
||||
rend_data_ctx.shader_flags.arr[U_FOG_STAGE] = 0;
|
||||
break;
|
||||
case Glitter::FOG_DEPTH:
|
||||
uniform_value[U_FOG_STAGE] = 1;
|
||||
rend_data_ctx.shader_flags.arr[U_FOG_STAGE] = 1;
|
||||
break;
|
||||
case Glitter::FOG_HEIGHT:
|
||||
uniform_value[U_FOG_STAGE] = 2;
|
||||
rend_data_ctx.shader_flags.arr[U_FOG_STAGE] = 2;
|
||||
break;
|
||||
}
|
||||
|
||||
if (!(rend_group->flags & PARTICLE_DEPTH_TEST))
|
||||
gl_rend_state.enable_depth_test();
|
||||
rend_data_ctx.state.enable_depth_test();
|
||||
else
|
||||
gl_rend_state.disable_depth_test();
|
||||
rend_data_ctx.state.disable_depth_test();
|
||||
|
||||
if (alpha_test) {
|
||||
uniform_value[U_ALPHA_TEST] = 1;
|
||||
rctx_ptr->set_batch_alpha_threshold(0.5f);
|
||||
uniform_value[U_ALPHA_BLEND] = rend_group->disp_type ? 3 : 1;
|
||||
gl_rend_state.set_depth_mask(GL_TRUE);
|
||||
gl_rend_state.disable_blend();
|
||||
rend_data_ctx.shader_flags.arr[U_ALPHA_TEST] = 1;
|
||||
rend_data_ctx.set_batch_alpha_threshold(0.5f);
|
||||
rend_data_ctx.shader_flags.arr[U_ALPHA_BLEND] = rend_group->disp_type ? 3 : 1;
|
||||
rend_data_ctx.state.set_depth_mask(GL_TRUE);
|
||||
rend_data_ctx.state.disable_blend();
|
||||
}
|
||||
else if (rend_group->disp_type) {
|
||||
uniform_value[U_ALPHA_TEST] = 0;
|
||||
uniform_value[U_ALPHA_BLEND] = 2;
|
||||
gl_rend_state.set_depth_mask(GL_FALSE);
|
||||
gl_rend_state.enable_blend();
|
||||
rend_data_ctx.shader_flags.arr[U_ALPHA_TEST] = 0;
|
||||
rend_data_ctx.shader_flags.arr[U_ALPHA_BLEND] = 2;
|
||||
rend_data_ctx.state.set_depth_mask(GL_FALSE);
|
||||
rend_data_ctx.state.enable_blend();
|
||||
}
|
||||
else {
|
||||
uniform_value[U_ALPHA_TEST] = 0;
|
||||
uniform_value[U_ALPHA_BLEND] = 0;
|
||||
gl_rend_state.set_depth_mask(GL_TRUE);
|
||||
gl_rend_state.disable_blend();
|
||||
rend_data_ctx.shader_flags.arr[U_ALPHA_TEST] = 0;
|
||||
rend_data_ctx.shader_flags.arr[U_ALPHA_BLEND] = 0;
|
||||
rend_data_ctx.state.set_depth_mask(GL_TRUE);
|
||||
rend_data_ctx.state.disable_blend();
|
||||
}
|
||||
|
||||
if (rend_group->draw_type == DIRECTION_BILLBOARD && !rend_group->use_culling) {
|
||||
gl_rend_state.enable_cull_face();
|
||||
gl_rend_state.set_cull_face_mode(GL_BACK);
|
||||
rend_data_ctx.state.enable_cull_face();
|
||||
rend_data_ctx.state.set_cull_face_mode(GL_BACK);
|
||||
}
|
||||
else
|
||||
gl_rend_state.disable_cull_face();
|
||||
rend_data_ctx.state.disable_cull_face();
|
||||
|
||||
shaders_ft.set(SHADER_FT_GLITTER_PT);
|
||||
rctx_ptr->set_glitter_render_data();
|
||||
rctx_ptr->glitter_batch_ubo.Bind(3);
|
||||
shaders_ft.set(rend_data_ctx.state, rend_data_ctx.shader_flags, SHADER_FT_GLITTER_PT);
|
||||
rend_data_ctx.set_glitter_render_data_state();
|
||||
rend_data_ctx.state.bind_uniform_buffer_base(3, rctx_ptr->glitter_batch_ubo);
|
||||
switch (rend_group->type) {
|
||||
case PARTICLE_QUAD:
|
||||
gl_rend_state.bind_vertex_array(rend_group->vao);
|
||||
shaders_ft.enable_primitive_restart();
|
||||
shaders_ft.draw_elements(GL_TRIANGLE_STRIP, (GLsizei)(5 * rend_group->disp - 1), GL_UNSIGNED_INT, 0);
|
||||
shaders_ft.disable_primitive_restart();
|
||||
rend_data_ctx.state.bind_vertex_array(rend_group->vao);
|
||||
rend_data_ctx.state.draw_elements(GL_TRIANGLE_STRIP,
|
||||
(GLsizei)(5 * rend_group->disp - 1), GL_UNSIGNED_INT, 0);
|
||||
break;
|
||||
case PARTICLE_LINE:
|
||||
gl_rend_state.bind_vertex_array(rend_group->vao);
|
||||
rend_data_ctx.state.bind_vertex_array(rend_group->vao);
|
||||
for (std::pair<GLint, GLsizei>& i : rend_group->draw_list)
|
||||
shaders_ft.draw_arrays(GL_LINE_STRIP, i.first, i.second);
|
||||
rend_data_ctx.state.draw_arrays(GL_LINE_STRIP, i.first, i.second);
|
||||
break;
|
||||
case PARTICLE_LOCUS:
|
||||
gl_rend_state.bind_vertex_array(rend_group->vao);
|
||||
rend_data_ctx.state.bind_vertex_array(rend_group->vao);
|
||||
for (std::pair<GLint, GLsizei>& i : rend_group->draw_list)
|
||||
shaders_ft.draw_arrays(GL_TRIANGLE_STRIP, i.first, i.second);
|
||||
rend_data_ctx.state.draw_arrays(GL_TRIANGLE_STRIP, i.first, i.second);
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -4,6 +4,7 @@
|
||||
*/
|
||||
|
||||
#include "glitter.hpp"
|
||||
#include "../gl_state.hpp"
|
||||
|
||||
namespace Glitter {
|
||||
Scene::Scene(SceneCounter counter, uint64_t hash, EffectGroup* eff_group, bool a5) {
|
||||
@@ -78,7 +79,7 @@ namespace Glitter {
|
||||
}
|
||||
|
||||
if (disp)
|
||||
effect_group->vbo.WriteMemory(0, effect_group->max_count * sizeof(Buffer), effect_group->buffer);
|
||||
effect_group->vbo.WriteMemory(gl_state, 0, effect_group->max_count * sizeof(Buffer), effect_group->buffer);
|
||||
#endif
|
||||
}
|
||||
|
||||
@@ -163,7 +164,7 @@ namespace Glitter {
|
||||
}
|
||||
}
|
||||
|
||||
void Scene::Disp(GPM, DispType disp_type) {
|
||||
void Scene::Disp(GPM, render_data_context& rend_data_ctx, DispType disp_type) {
|
||||
if (flags & SCENE_NOT_DISP)
|
||||
return;
|
||||
|
||||
@@ -173,7 +174,7 @@ namespace Glitter {
|
||||
&& GPM_VAL->selected_effect != i.ptr->effect)
|
||||
continue;
|
||||
|
||||
i.ptr->Disp(GPM_VAL, disp_type);
|
||||
i.ptr->Disp(GPM_VAL, rend_data_ctx, disp_type);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -423,14 +423,22 @@ namespace Vulkan {
|
||||
}
|
||||
}
|
||||
|
||||
vk_fbo->render_pass[0] = Vulkan::manager_get_render_pass(
|
||||
color_formats, color_format_count, depth_format, false);
|
||||
vk_fbo->render_pass[1] = Vulkan::manager_get_render_pass(
|
||||
color_formats, color_format_count, depth_format, true);
|
||||
vk_fbo->framebuffer[0].Create(Vulkan::current_device, 0,
|
||||
*vk_fbo->render_pass[0].get(), image_view_count, image_views, width, height);
|
||||
vk_fbo->framebuffer[1].Create(Vulkan::current_device, 0,
|
||||
*vk_fbo->render_pass[1].get(), image_view_count, image_views, width, height);
|
||||
if (color_format_count || depth_format) {
|
||||
vk_fbo->render_pass[0] = Vulkan::manager_get_render_pass(
|
||||
color_formats, color_format_count, depth_format, false);
|
||||
vk_fbo->render_pass[1] = Vulkan::manager_get_render_pass(
|
||||
color_formats, color_format_count, depth_format, true);
|
||||
vk_fbo->framebuffer[0].Create(Vulkan::current_device, 0,
|
||||
*vk_fbo->render_pass[0].get(), image_view_count, image_views, width, height);
|
||||
vk_fbo->framebuffer[1].Create(Vulkan::current_device, 0,
|
||||
*vk_fbo->render_pass[1].get(), image_view_count, image_views, width, height);
|
||||
}
|
||||
else {
|
||||
vk_fbo->render_pass[0].reset();
|
||||
vk_fbo->render_pass[1].reset();
|
||||
vk_fbo->framebuffer[0].Destroy();
|
||||
vk_fbo->framebuffer[1].Destroy();
|
||||
}
|
||||
|
||||
vk_fbo->update_framebuffer = false;
|
||||
}
|
||||
|
||||
@@ -8,7 +8,6 @@
|
||||
#include "auth_2d.hpp"
|
||||
#include "../KKdLib/str_utils.hpp"
|
||||
#include "data.hpp"
|
||||
#include "file_handler.hpp"
|
||||
#include "sound.hpp"
|
||||
#include "task.hpp"
|
||||
|
||||
|
||||
@@ -11,6 +11,7 @@
|
||||
#include "../KKdLib/vec.hpp"
|
||||
#include "color.hpp"
|
||||
#include "frame_rate_control.hpp"
|
||||
#include "file_handler.hpp"
|
||||
#include "sprite.hpp"
|
||||
|
||||
enum AetFlags {
|
||||
|
||||
+114
-4
@@ -320,10 +320,10 @@ static void camera_calculate_projection(camera* c) {
|
||||
mat4_mul(&spr_3d_view, &spr_3d_proj, &c->view_projection_aet_3d);
|
||||
|
||||
extern render_context* rctx_ptr;
|
||||
rctx_ptr->render.calc_projection_matrix(&c->projection, c->fov,
|
||||
(float_t)c->aspect, c->min_distance, c->max_distance,
|
||||
c->proj_left_offset, c->proj_right_offset,
|
||||
c->proj_left_offset, c->proj_right_offset);
|
||||
vec2 persp_scale = 1.0f;
|
||||
vec2 persp_offset = rctx_ptr->render.get_taa_offset();
|
||||
mat4_persp_offset(c->fov * DEG_TO_RAD_FLOAT, (float_t)c->aspect,
|
||||
c->min_distance, c->max_distance, &persp_scale, &persp_offset, &c->projection);
|
||||
mat4_invert(&c->projection, &c->inv_projection);
|
||||
|
||||
float_t height = (float_t)res_wind_int->height * 0.5f;
|
||||
@@ -404,3 +404,113 @@ void cam_struct::set(camera* cam) {
|
||||
cam->set_up(use_up, up);
|
||||
cam->set_min_distance(min_distance);
|
||||
}
|
||||
|
||||
cam_data::cam_data() : view_point(0.0f, 0.0f, 1.0f), interest(), up(0.0f, 1.0f, 0.0f),
|
||||
fov(30.0f * DEG_TO_RAD_FLOAT), aspect(4.0f / 3.0f), min_distance(1.0f), max_distance(200.0f),
|
||||
view_mat(), proj_mat(), view_proj_mat(), persp_scale(), persp_offset() {
|
||||
|
||||
}
|
||||
|
||||
void cam_data::calc_ortho_proj_mat(float_t left, float_t right,
|
||||
float_t bottom, float_t top, const vec2& scale, const vec2& offset) {
|
||||
mat4_ortho_offset(left, right, bottom, top, min_distance, max_distance, &scale, &offset, &proj_mat);
|
||||
}
|
||||
|
||||
void cam_data::calc_persp_proj_mat() {
|
||||
mat4_persp(fov, aspect, min_distance, max_distance, &proj_mat);
|
||||
persp_scale = 1.0f;
|
||||
persp_offset = 0.0f;
|
||||
}
|
||||
|
||||
void cam_data::calc_persp_proj_mat_offset(const vec2& persp_scale, const vec2& persp_offset) {
|
||||
mat4_persp_offset(fov, aspect, min_distance, max_distance, &persp_scale, &persp_offset, &proj_mat);
|
||||
this->persp_scale = persp_scale;
|
||||
this->persp_offset = persp_offset;
|
||||
}
|
||||
|
||||
void cam_data::calc_view_mat() {
|
||||
mat4_look_at(&view_point, &interest, &up, &view_mat);
|
||||
}
|
||||
|
||||
void cam_data::calc_view_proj_mat() {
|
||||
mat4_mul(&view_mat, &proj_mat, &view_proj_mat);
|
||||
}
|
||||
|
||||
void cam_data::get(const camera* cam) {
|
||||
view_point = cam->view_point;
|
||||
interest = cam->interest;
|
||||
up = cam->up;
|
||||
fov = cam->fov * DEG_TO_RAD_FLOAT;
|
||||
aspect = (float_t)cam->aspect;
|
||||
min_distance = cam->min_distance;
|
||||
max_distance = cam->max_distance;
|
||||
view_mat = cam->view;
|
||||
proj_mat = cam->projection;
|
||||
view_proj_mat = cam->view_projection;
|
||||
persp_scale = 1.0f;
|
||||
persp_offset = 0.0f;
|
||||
}
|
||||
|
||||
float_t cam_data::get_aspect() const {
|
||||
return aspect;
|
||||
}
|
||||
|
||||
float_t cam_data::get_fov() const {
|
||||
return fov;
|
||||
}
|
||||
|
||||
const vec3& cam_data::get_interest() const {
|
||||
return interest;
|
||||
}
|
||||
|
||||
float_t cam_data::get_min_distance() const {
|
||||
return min_distance;
|
||||
}
|
||||
|
||||
float_t cam_data::get_max_distance() const {
|
||||
return max_distance;
|
||||
}
|
||||
|
||||
const mat4& cam_data::get_proj_mat() const {
|
||||
return proj_mat;
|
||||
}
|
||||
|
||||
const mat4& cam_data::get_view_mat() const {
|
||||
return view_mat;
|
||||
}
|
||||
|
||||
const vec3& cam_data::get_view_point() const {
|
||||
return view_point;
|
||||
}
|
||||
|
||||
const mat4& cam_data::get_view_proj_mat() const {
|
||||
return view_proj_mat;
|
||||
}
|
||||
|
||||
void cam_data::set_aspect(float_t value) {
|
||||
aspect = value;
|
||||
}
|
||||
|
||||
void cam_data::set_fov(float_t value) {
|
||||
fov = value;
|
||||
}
|
||||
|
||||
void cam_data::set_interest(const vec3& value) {
|
||||
interest = value;
|
||||
}
|
||||
|
||||
void cam_data::set_min_distance(float_t value) {
|
||||
min_distance = value;
|
||||
}
|
||||
|
||||
void cam_data::set_max_distance(float_t value) {
|
||||
max_distance = value;
|
||||
}
|
||||
|
||||
void cam_data::set_up(const vec3& value) {
|
||||
up = value;
|
||||
}
|
||||
|
||||
void cam_data::set_view_point(const vec3& value) {
|
||||
view_point = value;
|
||||
}
|
||||
|
||||
@@ -114,3 +114,44 @@ struct cam_struct {
|
||||
void get(camera* cam);
|
||||
void set(camera* cam);
|
||||
};
|
||||
|
||||
struct cam_data {
|
||||
vec3 view_point;
|
||||
vec3 interest;
|
||||
vec3 up;
|
||||
float_t fov;
|
||||
float_t aspect;
|
||||
float_t min_distance;
|
||||
float_t max_distance;
|
||||
mat4 view_mat;
|
||||
mat4 proj_mat;
|
||||
mat4 view_proj_mat;
|
||||
vec2 persp_scale;
|
||||
vec2 persp_offset;
|
||||
|
||||
cam_data();
|
||||
|
||||
void calc_ortho_proj_mat(float_t left, float_t right,
|
||||
float_t bottom, float_t top, const vec2& scale, const vec2& offset);
|
||||
void calc_persp_proj_mat();
|
||||
void calc_persp_proj_mat_offset(const vec2& persp_scale, const vec2& persp_offset);
|
||||
void calc_view_mat();
|
||||
void calc_view_proj_mat();
|
||||
void get(const camera* cam);
|
||||
float_t get_aspect() const;
|
||||
float_t get_fov() const;
|
||||
const vec3& get_interest() const;
|
||||
float_t get_min_distance() const;
|
||||
float_t get_max_distance() const;
|
||||
const mat4& get_proj_mat() const;
|
||||
const mat4& get_view_mat() const;
|
||||
const vec3& get_view_point() const;
|
||||
const mat4& get_view_proj_mat() const;
|
||||
void set_aspect(float_t value);
|
||||
void set_fov(float_t value);
|
||||
void set_interest(const vec3& value);
|
||||
void set_min_distance(float_t value);
|
||||
void set_max_distance(float_t value);
|
||||
void set_up(const vec3& value);
|
||||
void set_view_point(const vec3& value);
|
||||
};
|
||||
|
||||
@@ -4,7 +4,7 @@
|
||||
*/
|
||||
|
||||
#include "clear_color.hpp"
|
||||
#include "gl_rend_state.hpp"
|
||||
#include "gl.hpp"
|
||||
|
||||
color4u8 clear_color;
|
||||
bool set_clear_color;
|
||||
|
||||
+295
-283
File diff suppressed because it is too large
Load Diff
+5
-5
@@ -49,11 +49,11 @@ struct particle_event_data {
|
||||
particle_event_data();
|
||||
};
|
||||
|
||||
extern void leaf_particle_draw();
|
||||
extern void rain_particle_draw();
|
||||
extern void particle_draw();
|
||||
extern void snow_particle_draw();
|
||||
extern void star_catalog_draw();
|
||||
extern void leaf_particle_draw(struct render_data_context& rend_data_ctx, const struct cam_data& cam);
|
||||
extern void rain_particle_draw(struct render_data_context& rend_data_ctx, const struct cam_data& cam);
|
||||
extern void particle_draw(struct render_data_context& rend_data_ctx, const struct cam_data& cam);
|
||||
extern void snow_particle_draw(struct render_data_context& rend_data_ctx, const struct cam_data& cam);
|
||||
extern void star_catalog_draw(struct render_data_context& rend_data_ctx, const struct cam_data& cam);
|
||||
|
||||
extern void effect_init();
|
||||
extern void effect_free();
|
||||
|
||||
+536
-65
@@ -5,9 +5,472 @@
|
||||
|
||||
#include "gl_rend_state.hpp"
|
||||
|
||||
gl_rend_state_struct gl_rend_state;
|
||||
struct gl_rend_state {
|
||||
GLuint program;
|
||||
GLuint active_texture_index;
|
||||
GLuint texture_binding_2d[32];
|
||||
GLuint texture_binding_cube_map[32];
|
||||
GLuint sampler_binding[32];
|
||||
GLboolean blend;
|
||||
GLenum blend_src_rgb;
|
||||
GLenum blend_src_alpha;
|
||||
GLenum blend_dst_rgb;
|
||||
GLenum blend_dst_alpha;
|
||||
GLenum blend_mode_rgb;
|
||||
GLenum blend_mode_alpha;
|
||||
GLuint read_framebuffer_binding;
|
||||
GLuint draw_framebuffer_binding;
|
||||
GLuint vertex_array_binding;
|
||||
GLuint array_buffer_binding;
|
||||
GLuint element_array_buffer_binding;
|
||||
GLuint uniform_buffer_binding;
|
||||
GLuint uniform_buffer_bindings[14];
|
||||
GLintptr uniform_buffer_offsets[14];
|
||||
GLsizeiptr uniform_buffer_sizes[14];
|
||||
GLuint shader_storage_buffer_binding;
|
||||
GLuint shader_storage_buffer_bindings[14];
|
||||
GLintptr shader_storage_buffer_offsets[14];
|
||||
GLsizeiptr shader_storage_buffer_sizes[14];
|
||||
GLboolean color_mask[4];
|
||||
GLboolean cull_face;
|
||||
GLenum cull_face_mode;
|
||||
GLboolean depth_test;
|
||||
GLenum depth_func;
|
||||
GLboolean depth_mask;
|
||||
GLfloat line_width;
|
||||
GLenum polygon_mode;
|
||||
GLboolean multisample;
|
||||
GLboolean primitive_restart;
|
||||
GLuint primitive_restart_index;
|
||||
gl_rend_state_rect scissor_box;
|
||||
GLboolean scissor_test;
|
||||
GLboolean stencil_test;
|
||||
GLenum stencil_func;
|
||||
GLenum stencil_fail;
|
||||
GLenum stencil_dpfail;
|
||||
GLenum stencil_dppass;
|
||||
GLuint stencil_mask;
|
||||
GLint stencil_ref;
|
||||
GLuint stencil_value_mask;
|
||||
gl_rend_state_rect viewport;
|
||||
|
||||
void gl_rend_state_struct::active_bind_texture_2d(int32_t index, GLuint texture, bool force) {
|
||||
void active_bind_texture_2d(int32_t index, GLuint texture, bool force = false);
|
||||
void active_bind_texture_cube_map(int32_t index, GLuint texture, bool force = false);
|
||||
void active_texture(size_t index, bool force = false);
|
||||
void begin_event(const char* message, int32_t length);
|
||||
void bind_framebuffer(GLuint framebuffer, bool force = false);
|
||||
void bind_read_framebuffer(GLuint framebuffer, bool force = false);
|
||||
void bind_draw_framebuffer(GLuint framebuffer, bool force = false);
|
||||
void bind_vertex_array(GLuint array, bool force = false);
|
||||
void bind_array_buffer(GLuint buffer, bool force = false);
|
||||
void bind_element_array_buffer(GLuint buffer, bool force = false);
|
||||
void bind_uniform_buffer(GLuint buffer, bool force = false);
|
||||
void bind_uniform_buffer_base(GLuint index, GLuint buffer, bool force = false);
|
||||
void bind_uniform_buffer_range(GLuint index,
|
||||
GLuint buffer, GLintptr offset, GLsizeiptr size, bool force = false);
|
||||
void bind_shader_storage_buffer(GLuint buffer, bool force = false);
|
||||
void bind_shader_storage_buffer_base(GLuint index, GLuint buffer, bool force = false);
|
||||
void bind_shader_storage_buffer_range(GLuint index,
|
||||
GLuint buffer, GLintptr offset, GLsizeiptr size, bool force = false);
|
||||
void bind_texture_2d(GLuint texture, bool force = false);
|
||||
void bind_texture_cube_map(GLuint texture, bool force = false);
|
||||
void bind_sampler(int32_t index, GLuint sampler, bool force = false);
|
||||
bool check_uniform_buffer_binding();
|
||||
bool check_uniform_buffer_binding_base(size_t index);
|
||||
bool check_shader_storage_buffer_binding();
|
||||
bool check_shader_storage_buffer_binding_base(size_t index);
|
||||
bool check_texture_binding_2d(size_t index);
|
||||
bool check_texture_binding_cube_map(size_t index);
|
||||
bool check_sampler_binding(int32_t index, GLuint sampler);
|
||||
void disable_blend(bool force = false);
|
||||
void disable_cull_face(bool force = false);
|
||||
void disable_depth_test(bool force = false);
|
||||
void disable_multisample(bool force = false);
|
||||
void disable_primitive_restart(bool force = false);
|
||||
void disable_scissor_test(bool force = false);
|
||||
void disable_stencil_test(bool force = false);
|
||||
void enable_blend(bool force = false);
|
||||
void enable_cull_face(bool force = false);
|
||||
void enable_depth_test(bool force = false);
|
||||
void enable_multisample(bool force = false);
|
||||
void enable_primitive_restart(bool force = false);
|
||||
void enable_scissor_test(bool force = false);
|
||||
void enable_stencil_test(bool force = false);
|
||||
void end_event();
|
||||
void get();
|
||||
GLuint get_program();
|
||||
gl_rend_state_rect get_scissor();
|
||||
void get_scissor(GLint& x, GLint& y, GLsizei& width, GLsizei& height);
|
||||
gl_rend_state_rect get_viewport();
|
||||
void get_viewport(GLint& x, GLint& y, GLsizei& width, GLsizei& height);
|
||||
void set_blend_func(GLenum src, GLenum dst, bool force = false);
|
||||
void set_blend_func_separate(GLenum src_rgb, GLenum dst_rgb,
|
||||
GLenum src_alpha, GLenum dst_alpha, bool force = false);
|
||||
void set_blend_equation(GLenum mode, bool force = false);
|
||||
void set_blend_equation_separate(
|
||||
GLenum mode_rgb, GLenum mode_alpha, bool force = false);
|
||||
void set_color_mask(GLboolean red, GLboolean green,
|
||||
GLboolean blue, GLboolean alpha, bool force = false);
|
||||
void set_cull_face_mode(GLenum mode, bool force = false);
|
||||
void set_depth_func(GLenum func, bool force = false);
|
||||
void set_depth_mask(GLboolean flag, bool force = false);
|
||||
void set_line_width(GLfloat width, bool force = false);
|
||||
void set_polygon_mode(GLenum face, GLenum mode, bool force = false);
|
||||
void set_primitive_restart_index(GLuint index, bool force = false);
|
||||
void set_scissor(const gl_rend_state_rect& rect, bool force = false);
|
||||
void set_scissor(GLint x, GLint y, GLsizei width, GLsizei height, bool force = false);
|
||||
void set_stencil_func(GLenum func, GLint ref, GLuint mask, bool force = false);
|
||||
void set_stencil_mask(GLuint mask, bool force = false);
|
||||
void set_stencil_op(GLenum sfail, GLenum dpfail, GLenum dppass, bool force = false);
|
||||
void set_viewport(const gl_rend_state_rect& rect, bool force = false);
|
||||
void set_viewport(GLint x, GLint y, GLsizei width, GLsizei height, bool force = false);
|
||||
void use_program(GLuint program, bool force = false);
|
||||
};
|
||||
|
||||
gl_rend_state gl_state_data[GL_REND_STATE_COUNT];
|
||||
|
||||
p_gl_rend_state::p_gl_rend_state(int32_t index) : ptr(gl_state_data[index]) {
|
||||
|
||||
}
|
||||
|
||||
void p_gl_rend_state::active_bind_texture_2d(int32_t index, GLuint texture, bool force) {
|
||||
ptr.active_bind_texture_2d(index, texture, force);
|
||||
}
|
||||
|
||||
void p_gl_rend_state::active_bind_texture_cube_map(int32_t index, GLuint texture, bool force) {
|
||||
ptr.active_bind_texture_cube_map(index, texture, force);
|
||||
}
|
||||
|
||||
void p_gl_rend_state::active_texture(size_t index, bool force) {
|
||||
ptr.active_texture(index, force);
|
||||
}
|
||||
|
||||
void p_gl_rend_state::begin_event(const char* message, int32_t length) {
|
||||
ptr.begin_event(message, length);
|
||||
}
|
||||
|
||||
void p_gl_rend_state::bind_framebuffer(GLuint framebuffer, bool force) {
|
||||
ptr.bind_framebuffer(framebuffer, force);
|
||||
}
|
||||
|
||||
void p_gl_rend_state::bind_read_framebuffer(GLuint framebuffer, bool force) {
|
||||
ptr.bind_read_framebuffer(framebuffer, force);
|
||||
}
|
||||
|
||||
void p_gl_rend_state::bind_draw_framebuffer(GLuint framebuffer, bool force) {
|
||||
ptr.bind_draw_framebuffer(framebuffer, force);
|
||||
}
|
||||
|
||||
void p_gl_rend_state::bind_vertex_array(GLuint array, bool force) {
|
||||
ptr.bind_vertex_array(array, force);
|
||||
}
|
||||
|
||||
void p_gl_rend_state::bind_array_buffer(GLuint buffer, bool force) {
|
||||
ptr.bind_array_buffer(buffer, force);
|
||||
}
|
||||
|
||||
void p_gl_rend_state::bind_element_array_buffer(GLuint buffer, bool force) {
|
||||
ptr.bind_element_array_buffer(buffer, force);
|
||||
}
|
||||
|
||||
void p_gl_rend_state::bind_uniform_buffer(GLuint buffer, bool force) {
|
||||
ptr.bind_uniform_buffer(buffer, force);
|
||||
}
|
||||
|
||||
void p_gl_rend_state::bind_uniform_buffer_base(GLuint index, GLuint buffer, bool force) {
|
||||
ptr.bind_uniform_buffer_base(index, buffer, force);
|
||||
}
|
||||
|
||||
void p_gl_rend_state::bind_uniform_buffer_range(GLuint index,
|
||||
GLuint buffer, GLintptr offset, GLsizeiptr size, bool force) {
|
||||
ptr.bind_uniform_buffer_range(index, buffer, offset, size, force);
|
||||
}
|
||||
|
||||
void p_gl_rend_state::bind_shader_storage_buffer(GLuint buffer, bool force) {
|
||||
ptr.bind_shader_storage_buffer(buffer, force);
|
||||
}
|
||||
|
||||
void p_gl_rend_state::bind_shader_storage_buffer_base(GLuint index, GLuint buffer, bool force) {
|
||||
ptr.bind_shader_storage_buffer_base(index, buffer, force);
|
||||
}
|
||||
|
||||
void p_gl_rend_state::bind_shader_storage_buffer_range(GLuint index,
|
||||
GLuint buffer, GLintptr offset, GLsizeiptr size, bool force) {
|
||||
ptr.bind_shader_storage_buffer_range(index, buffer, offset, size, force);
|
||||
}
|
||||
|
||||
void p_gl_rend_state::bind_texture_2d(GLuint texture, bool force) {
|
||||
ptr.bind_texture_2d(texture, force);
|
||||
}
|
||||
|
||||
void p_gl_rend_state::bind_texture_cube_map(GLuint texture, bool force) {
|
||||
ptr.bind_texture_cube_map(texture, force);
|
||||
}
|
||||
|
||||
void p_gl_rend_state::bind_sampler(int32_t index, GLuint sampler, bool force) {
|
||||
ptr.bind_sampler(index, sampler, force);
|
||||
}
|
||||
|
||||
bool p_gl_rend_state::check_uniform_buffer_binding() {
|
||||
return ptr.check_uniform_buffer_binding();
|
||||
}
|
||||
|
||||
bool p_gl_rend_state::check_uniform_buffer_binding_base(size_t index) {
|
||||
return ptr.check_uniform_buffer_binding_base(index);
|
||||
}
|
||||
|
||||
bool p_gl_rend_state::check_shader_storage_buffer_binding() {
|
||||
return ptr.check_shader_storage_buffer_binding();
|
||||
}
|
||||
|
||||
bool p_gl_rend_state::check_shader_storage_buffer_binding_base(size_t index) {
|
||||
return ptr.check_shader_storage_buffer_binding_base(index);
|
||||
}
|
||||
|
||||
bool p_gl_rend_state::check_texture_binding_2d(size_t index) {
|
||||
return ptr.check_texture_binding_2d(index);
|
||||
}
|
||||
|
||||
bool p_gl_rend_state::check_texture_binding_cube_map(size_t index) {
|
||||
return ptr.check_texture_binding_cube_map(index);
|
||||
}
|
||||
|
||||
bool p_gl_rend_state::check_sampler_binding(int32_t index, GLuint sampler) {
|
||||
return ptr.check_sampler_binding(index, sampler);
|
||||
}
|
||||
|
||||
void p_gl_rend_state::disable_blend(bool force) {
|
||||
ptr.disable_blend(force);
|
||||
}
|
||||
|
||||
void p_gl_rend_state::disable_cull_face(bool force) {
|
||||
ptr.disable_cull_face(force);
|
||||
}
|
||||
|
||||
void p_gl_rend_state::disable_depth_test(bool force) {
|
||||
ptr.disable_depth_test(force);
|
||||
}
|
||||
|
||||
void p_gl_rend_state::disable_multisample(bool force) {
|
||||
ptr.disable_multisample(force);
|
||||
}
|
||||
|
||||
void p_gl_rend_state::disable_primitive_restart(bool force) {
|
||||
ptr.disable_primitive_restart(force);
|
||||
}
|
||||
|
||||
void p_gl_rend_state::disable_scissor_test(bool force) {
|
||||
ptr.disable_scissor_test(force);
|
||||
}
|
||||
|
||||
void p_gl_rend_state::disable_stencil_test(bool force) {
|
||||
ptr.disable_stencil_test(force);
|
||||
}
|
||||
|
||||
void p_gl_rend_state::draw_arrays(GLenum mode, GLint first, GLsizei count) {
|
||||
glDrawArrays(mode, first, count);
|
||||
}
|
||||
|
||||
void p_gl_rend_state::draw_elements(GLenum mode,
|
||||
GLsizei count, GLenum type, const void* indices) {
|
||||
switch (mode) {
|
||||
case GL_TRIANGLE_STRIP:
|
||||
uint32_t index;
|
||||
switch (type) {
|
||||
case GL_UNSIGNED_BYTE:
|
||||
index = 0xFF;
|
||||
break;
|
||||
case GL_UNSIGNED_SHORT:
|
||||
index = 0xFFFF;
|
||||
break;
|
||||
case GL_UNSIGNED_INT:
|
||||
default:
|
||||
index = 0xFFFFFFFF;
|
||||
break;
|
||||
}
|
||||
|
||||
enable_primitive_restart();
|
||||
set_primitive_restart_index(index);
|
||||
break;
|
||||
}
|
||||
|
||||
glDrawElements(mode, count, type, indices);
|
||||
|
||||
switch (mode) {
|
||||
case GL_TRIANGLE_STRIP:
|
||||
disable_primitive_restart();
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
void p_gl_rend_state::draw_range_elements(GLenum mode,
|
||||
GLuint start, GLuint end, GLsizei count, GLenum type, const void* indices) {
|
||||
switch (mode) {
|
||||
case GL_TRIANGLE_STRIP:
|
||||
uint32_t index;
|
||||
switch (type) {
|
||||
case GL_UNSIGNED_BYTE:
|
||||
index = 0xFF;
|
||||
break;
|
||||
case GL_UNSIGNED_SHORT:
|
||||
index = 0xFFFF;
|
||||
break;
|
||||
case GL_UNSIGNED_INT:
|
||||
default:
|
||||
index = 0xFFFFFFFF;
|
||||
break;
|
||||
}
|
||||
|
||||
enable_primitive_restart();
|
||||
set_primitive_restart_index(index);
|
||||
break;
|
||||
}
|
||||
|
||||
glDrawRangeElements(mode, start, end, count, type, indices);
|
||||
|
||||
switch (mode) {
|
||||
case GL_TRIANGLE_STRIP:
|
||||
disable_primitive_restart();
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
void p_gl_rend_state::enable_blend(bool force) {
|
||||
ptr.enable_blend(force);
|
||||
}
|
||||
|
||||
void p_gl_rend_state::enable_cull_face(bool force) {
|
||||
ptr.enable_cull_face(force);
|
||||
}
|
||||
|
||||
void p_gl_rend_state::enable_depth_test(bool force) {
|
||||
ptr.enable_depth_test(force);
|
||||
}
|
||||
|
||||
void p_gl_rend_state::enable_multisample(bool force) {
|
||||
ptr.enable_multisample(force);
|
||||
}
|
||||
|
||||
void p_gl_rend_state::enable_primitive_restart(bool force) {
|
||||
ptr.enable_primitive_restart(force);
|
||||
}
|
||||
|
||||
void p_gl_rend_state::enable_scissor_test(bool force) {
|
||||
ptr.enable_scissor_test(force);
|
||||
}
|
||||
|
||||
void p_gl_rend_state::enable_stencil_test(bool force) {
|
||||
ptr.enable_stencil_test(force);
|
||||
}
|
||||
|
||||
void p_gl_rend_state::end_event() {
|
||||
ptr.end_event();
|
||||
}
|
||||
|
||||
void p_gl_rend_state::get() {
|
||||
ptr.get();
|
||||
}
|
||||
|
||||
GLuint p_gl_rend_state::get_program() {
|
||||
return ptr.get_program();
|
||||
}
|
||||
|
||||
gl_rend_state_rect p_gl_rend_state::get_scissor() {
|
||||
return ptr.get_scissor();
|
||||
}
|
||||
|
||||
void p_gl_rend_state::get_scissor(GLint& x, GLint& y, GLsizei& width, GLsizei& height) {
|
||||
ptr.get_scissor(x, y, width, height);
|
||||
}
|
||||
|
||||
gl_rend_state_rect p_gl_rend_state::get_viewport() {
|
||||
return ptr.get_viewport();
|
||||
}
|
||||
|
||||
void p_gl_rend_state::get_viewport(GLint& x, GLint& y, GLsizei& width, GLsizei& height) {
|
||||
ptr.get_viewport(x, y, width, height);
|
||||
}
|
||||
|
||||
void p_gl_rend_state::set_blend_func(GLenum src, GLenum dst, bool force) {
|
||||
ptr.set_blend_func(src, dst, force);
|
||||
}
|
||||
|
||||
void p_gl_rend_state::set_blend_func_separate(GLenum src_rgb, GLenum dst_rgb,
|
||||
GLenum src_alpha, GLenum dst_alpha, bool force) {
|
||||
ptr.set_blend_func_separate(src_rgb, dst_rgb, src_alpha, dst_alpha, force);
|
||||
}
|
||||
|
||||
void p_gl_rend_state::set_blend_equation(GLenum mode, bool force) {
|
||||
ptr.set_blend_equation(mode, force);
|
||||
}
|
||||
|
||||
void p_gl_rend_state::set_blend_equation_separate(
|
||||
GLenum mode_rgb, GLenum mode_alpha, bool force) {
|
||||
ptr.set_blend_equation_separate(mode_rgb, mode_alpha, force);
|
||||
}
|
||||
|
||||
void p_gl_rend_state::set_color_mask(GLboolean red, GLboolean green,
|
||||
GLboolean blue, GLboolean alpha, bool force) {
|
||||
ptr.set_color_mask(red, green, blue, alpha, force);
|
||||
}
|
||||
|
||||
void p_gl_rend_state::set_cull_face_mode(GLenum mode, bool force) {
|
||||
ptr.set_cull_face_mode(mode, force);
|
||||
}
|
||||
|
||||
void p_gl_rend_state::set_depth_func(GLenum func, bool force) {
|
||||
ptr.set_depth_func(func, force);
|
||||
}
|
||||
|
||||
void p_gl_rend_state::set_depth_mask(GLboolean flag, bool force) {
|
||||
ptr.set_depth_mask(flag, force);
|
||||
}
|
||||
|
||||
void p_gl_rend_state::set_line_width(GLfloat width, bool force) {
|
||||
ptr.set_line_width(width, force);
|
||||
}
|
||||
|
||||
void p_gl_rend_state::set_polygon_mode(GLenum face, GLenum mode, bool force) {
|
||||
ptr.set_polygon_mode(face, mode, force);
|
||||
}
|
||||
|
||||
void p_gl_rend_state::set_primitive_restart_index(GLuint index, bool force) {
|
||||
ptr.set_primitive_restart_index(index, force);
|
||||
}
|
||||
|
||||
void p_gl_rend_state::set_scissor(const gl_rend_state_rect& rect, bool force) {
|
||||
ptr.set_scissor(rect, force);
|
||||
}
|
||||
|
||||
void p_gl_rend_state::set_scissor(GLint x, GLint y, GLsizei width, GLsizei height, bool force) {
|
||||
ptr.set_scissor(x, y, width, height, force);
|
||||
}
|
||||
|
||||
void p_gl_rend_state::set_stencil_func(GLenum func, GLint ref, GLuint mask, bool force) {
|
||||
ptr.set_stencil_func(func, ref, mask, force);
|
||||
}
|
||||
|
||||
void p_gl_rend_state::set_stencil_mask(GLuint mask, bool force) {
|
||||
ptr.set_stencil_mask(mask, force);
|
||||
}
|
||||
|
||||
void p_gl_rend_state::set_stencil_op(GLenum sfail, GLenum dpfail, GLenum dppass, bool force) {
|
||||
ptr.set_stencil_op(sfail, dpfail, dppass, force);
|
||||
}
|
||||
|
||||
void p_gl_rend_state::set_viewport(const gl_rend_state_rect& rect, bool force) {
|
||||
ptr.set_viewport(rect, force);
|
||||
}
|
||||
|
||||
void p_gl_rend_state::set_viewport(GLint x, GLint y, GLsizei width, GLsizei height, bool force) {
|
||||
ptr.set_viewport(x, y, width, height, force);
|
||||
}
|
||||
|
||||
void p_gl_rend_state::use_program(GLuint program, bool force) {
|
||||
ptr.use_program(program, force);
|
||||
}
|
||||
|
||||
void gl_rend_state::active_bind_texture_2d(int32_t index, GLuint texture, bool force) {
|
||||
if (force || texture_binding_2d[index] != texture) {
|
||||
if (force || active_texture_index != index) {
|
||||
glActiveTexture((GLenum)(GL_TEXTURE0 + index));
|
||||
@@ -18,7 +481,7 @@ void gl_rend_state_struct::active_bind_texture_2d(int32_t index, GLuint texture,
|
||||
}
|
||||
}
|
||||
|
||||
void gl_rend_state_struct::active_bind_texture_cube_map(int32_t index, GLuint texture, bool force) {
|
||||
void gl_rend_state::active_bind_texture_cube_map(int32_t index, GLuint texture, bool force) {
|
||||
if (force || texture_binding_cube_map[index] != texture) {
|
||||
if (force || active_texture_index != index) {
|
||||
glActiveTexture((GLenum)(GL_TEXTURE0 + index));
|
||||
@@ -29,14 +492,18 @@ void gl_rend_state_struct::active_bind_texture_cube_map(int32_t index, GLuint te
|
||||
}
|
||||
}
|
||||
|
||||
void gl_rend_state_struct::active_texture(size_t index, bool force) {
|
||||
void gl_rend_state::active_texture(size_t index, bool force) {
|
||||
if (force || active_texture_index != index) {
|
||||
glActiveTexture((GLenum)(GL_TEXTURE0 + index));
|
||||
active_texture_index = (GLuint)index;
|
||||
}
|
||||
}
|
||||
|
||||
void gl_rend_state_struct::bind_framebuffer(GLuint framebuffer, bool force) {
|
||||
void gl_rend_state::begin_event(const char* message, int32_t length) {
|
||||
glPushDebugGroup(GL_DEBUG_SOURCE_APPLICATION, 0, (GLsizei)length, message);
|
||||
}
|
||||
|
||||
void gl_rend_state::bind_framebuffer(GLuint framebuffer, bool force) {
|
||||
if (force || read_framebuffer_binding != framebuffer
|
||||
|| draw_framebuffer_binding != framebuffer) {
|
||||
glBindFramebuffer(GL_FRAMEBUFFER, framebuffer);
|
||||
@@ -45,49 +512,49 @@ void gl_rend_state_struct::bind_framebuffer(GLuint framebuffer, bool force) {
|
||||
}
|
||||
}
|
||||
|
||||
void gl_rend_state_struct::bind_read_framebuffer(GLuint framebuffer, bool force) {
|
||||
void gl_rend_state::bind_read_framebuffer(GLuint framebuffer, bool force) {
|
||||
if (force || read_framebuffer_binding != framebuffer) {
|
||||
glBindFramebuffer(GL_READ_FRAMEBUFFER, framebuffer);
|
||||
read_framebuffer_binding = framebuffer;
|
||||
}
|
||||
}
|
||||
|
||||
void gl_rend_state_struct::bind_draw_framebuffer(GLuint framebuffer, bool force) {
|
||||
void gl_rend_state::bind_draw_framebuffer(GLuint framebuffer, bool force) {
|
||||
if (force || draw_framebuffer_binding != framebuffer) {
|
||||
glBindFramebuffer(GL_DRAW_FRAMEBUFFER, framebuffer);
|
||||
draw_framebuffer_binding = framebuffer;
|
||||
}
|
||||
}
|
||||
|
||||
void gl_rend_state_struct::bind_vertex_array(GLuint array, bool force) {
|
||||
void gl_rend_state::bind_vertex_array(GLuint array, bool force) {
|
||||
if (force || vertex_array_binding != array) {
|
||||
glBindVertexArray(array);
|
||||
vertex_array_binding = array;
|
||||
}
|
||||
}
|
||||
|
||||
void gl_rend_state_struct::bind_array_buffer(GLuint buffer, bool force) {
|
||||
void gl_rend_state::bind_array_buffer(GLuint buffer, bool force) {
|
||||
if (force || array_buffer_binding != buffer) {
|
||||
glBindBuffer(GL_ARRAY_BUFFER, buffer);
|
||||
array_buffer_binding = buffer;
|
||||
}
|
||||
}
|
||||
|
||||
void gl_rend_state_struct::bind_element_array_buffer(GLuint buffer, bool force) {
|
||||
void gl_rend_state::bind_element_array_buffer(GLuint buffer, bool force) {
|
||||
if (force || element_array_buffer_binding != buffer) {
|
||||
glBindBuffer(GL_ELEMENT_ARRAY_BUFFER, buffer);
|
||||
element_array_buffer_binding = buffer;
|
||||
}
|
||||
}
|
||||
|
||||
void gl_rend_state_struct::bind_uniform_buffer(GLuint buffer, bool force) {
|
||||
void gl_rend_state::bind_uniform_buffer(GLuint buffer, bool force) {
|
||||
if (force || uniform_buffer_binding != buffer) {
|
||||
glBindBuffer(GL_UNIFORM_BUFFER, buffer);
|
||||
uniform_buffer_binding = buffer;
|
||||
}
|
||||
}
|
||||
|
||||
void gl_rend_state_struct::bind_uniform_buffer_base(GLuint index, GLuint buffer, bool force) {
|
||||
void gl_rend_state::bind_uniform_buffer_base(GLuint index, GLuint buffer, bool force) {
|
||||
if (force || uniform_buffer_bindings[index] != buffer) {
|
||||
glBindBufferBase(GL_UNIFORM_BUFFER, index, buffer);
|
||||
uniform_buffer_binding = buffer;
|
||||
@@ -97,7 +564,7 @@ void gl_rend_state_struct::bind_uniform_buffer_base(GLuint index, GLuint buffer,
|
||||
}
|
||||
}
|
||||
|
||||
void gl_rend_state_struct::bind_uniform_buffer_range(GLuint index,
|
||||
void gl_rend_state::bind_uniform_buffer_range(GLuint index,
|
||||
GLuint buffer, GLintptr offset, GLsizeiptr size, bool force) {
|
||||
if (force || uniform_buffer_bindings[index] != buffer
|
||||
|| uniform_buffer_offsets[index] != offset
|
||||
@@ -110,14 +577,14 @@ void gl_rend_state_struct::bind_uniform_buffer_range(GLuint index,
|
||||
}
|
||||
}
|
||||
|
||||
void gl_rend_state_struct::bind_shader_storage_buffer(GLuint buffer, bool force) {
|
||||
void gl_rend_state::bind_shader_storage_buffer(GLuint buffer, bool force) {
|
||||
if (force || shader_storage_buffer_binding != buffer) {
|
||||
glBindBuffer(GL_SHADER_STORAGE_BUFFER, buffer);
|
||||
shader_storage_buffer_binding = buffer;
|
||||
}
|
||||
}
|
||||
|
||||
void gl_rend_state_struct::bind_shader_storage_buffer_base(GLuint index, GLuint buffer, bool force) {
|
||||
void gl_rend_state::bind_shader_storage_buffer_base(GLuint index, GLuint buffer, bool force) {
|
||||
if (force || shader_storage_buffer_bindings[index] != buffer) {
|
||||
glBindBufferBase(GL_SHADER_STORAGE_BUFFER, index, buffer);
|
||||
shader_storage_buffer_binding = buffer;
|
||||
@@ -127,7 +594,7 @@ void gl_rend_state_struct::bind_shader_storage_buffer_base(GLuint index, GLuint
|
||||
}
|
||||
}
|
||||
|
||||
void gl_rend_state_struct::bind_shader_storage_buffer_range(GLuint index,
|
||||
void gl_rend_state::bind_shader_storage_buffer_range(GLuint index,
|
||||
GLuint buffer, GLintptr offset, GLsizeiptr size, bool force) {
|
||||
if (force || shader_storage_buffer_bindings[index] != buffer
|
||||
|| shader_storage_buffer_offsets[index] != offset
|
||||
@@ -140,154 +607,154 @@ void gl_rend_state_struct::bind_shader_storage_buffer_range(GLuint index,
|
||||
}
|
||||
}
|
||||
|
||||
void gl_rend_state_struct::bind_texture_2d(GLuint texture, bool force) {
|
||||
void gl_rend_state::bind_texture_2d(GLuint texture, bool force) {
|
||||
if (texture_binding_2d[active_texture_index] != texture) {
|
||||
glBindTexture(GL_TEXTURE_2D, texture);
|
||||
texture_binding_2d[active_texture_index] = texture;
|
||||
}
|
||||
}
|
||||
|
||||
void gl_rend_state_struct::bind_texture_cube_map(GLuint texture, bool force) {
|
||||
void gl_rend_state::bind_texture_cube_map(GLuint texture, bool force) {
|
||||
if (force || texture_binding_cube_map[active_texture_index] != texture) {
|
||||
glBindTexture(GL_TEXTURE_CUBE_MAP, texture);
|
||||
texture_binding_cube_map[active_texture_index] = texture;
|
||||
}
|
||||
}
|
||||
|
||||
void gl_rend_state_struct::bind_sampler(int32_t index, GLuint sampler, bool force) {
|
||||
void gl_rend_state::bind_sampler(int32_t index, GLuint sampler, bool force) {
|
||||
if (force || sampler_binding[index] != sampler) {
|
||||
glBindSampler(index, sampler);
|
||||
sampler_binding[index] = sampler;
|
||||
}
|
||||
}
|
||||
|
||||
bool gl_rend_state_struct::check_uniform_buffer_binding() {
|
||||
bool gl_rend_state::check_uniform_buffer_binding() {
|
||||
return uniform_buffer_binding != 0;
|
||||
}
|
||||
|
||||
bool gl_rend_state_struct::check_uniform_buffer_binding_base(size_t index) {
|
||||
bool gl_rend_state::check_uniform_buffer_binding_base(size_t index) {
|
||||
return uniform_buffer_bindings[index] != 0;
|
||||
}
|
||||
|
||||
bool gl_rend_state_struct::check_shader_storage_buffer_binding() {
|
||||
bool gl_rend_state::check_shader_storage_buffer_binding() {
|
||||
return shader_storage_buffer_binding != 0;
|
||||
}
|
||||
|
||||
bool gl_rend_state_struct::check_shader_storage_buffer_binding_base(size_t index) {
|
||||
bool gl_rend_state::check_shader_storage_buffer_binding_base(size_t index) {
|
||||
return shader_storage_buffer_bindings[index] != 0;
|
||||
}
|
||||
|
||||
bool gl_rend_state_struct::check_texture_binding_2d(size_t index) {
|
||||
bool gl_rend_state::check_texture_binding_2d(size_t index) {
|
||||
return texture_binding_2d[index] != 0;
|
||||
}
|
||||
|
||||
bool gl_rend_state_struct::check_texture_binding_cube_map(size_t index) {
|
||||
bool gl_rend_state::check_texture_binding_cube_map(size_t index) {
|
||||
return texture_binding_cube_map[index] != 0;
|
||||
}
|
||||
|
||||
bool gl_rend_state_struct::check_sampler_binding(int32_t index, GLuint sampler) {
|
||||
bool gl_rend_state::check_sampler_binding(int32_t index, GLuint sampler) {
|
||||
return sampler_binding[index] != 0;
|
||||
}
|
||||
|
||||
void gl_rend_state_struct::disable_blend(bool force) {
|
||||
void gl_rend_state::disable_blend(bool force) {
|
||||
if (force || blend) {
|
||||
glDisable(GL_BLEND);
|
||||
blend = GL_FALSE;
|
||||
}
|
||||
}
|
||||
|
||||
void gl_rend_state_struct::disable_cull_face(bool force) {
|
||||
void gl_rend_state::disable_cull_face(bool force) {
|
||||
if (force || cull_face) {
|
||||
glDisable(GL_CULL_FACE);
|
||||
cull_face = GL_FALSE;
|
||||
}
|
||||
}
|
||||
|
||||
void gl_rend_state_struct::disable_depth_test(bool force) {
|
||||
void gl_rend_state::disable_depth_test(bool force) {
|
||||
if (force || depth_test) {
|
||||
glDisable(GL_DEPTH_TEST);
|
||||
depth_test = GL_FALSE;
|
||||
}
|
||||
}
|
||||
|
||||
void gl_rend_state_struct::disable_multisample(bool force) {
|
||||
void gl_rend_state::disable_multisample(bool force) {
|
||||
if (force || multisample) {
|
||||
glDisable(GL_MULTISAMPLE);
|
||||
multisample = GL_FALSE;
|
||||
}
|
||||
}
|
||||
|
||||
void gl_rend_state_struct::disable_primitive_restart(bool force) {
|
||||
void gl_rend_state::disable_primitive_restart(bool force) {
|
||||
if (force || primitive_restart) {
|
||||
glDisable(GL_PRIMITIVE_RESTART);
|
||||
primitive_restart = GL_FALSE;
|
||||
}
|
||||
}
|
||||
|
||||
void gl_rend_state_struct::disable_scissor_test(bool force) {
|
||||
void gl_rend_state::disable_scissor_test(bool force) {
|
||||
if (force || scissor_test) {
|
||||
glDisable(GL_SCISSOR_TEST);
|
||||
scissor_test = GL_FALSE;
|
||||
}
|
||||
}
|
||||
|
||||
void gl_rend_state_struct::disable_stencil_test(bool force) {
|
||||
void gl_rend_state::disable_stencil_test(bool force) {
|
||||
if (force || stencil_test) {
|
||||
glDisable(GL_STENCIL_TEST);
|
||||
stencil_test = GL_FALSE;
|
||||
}
|
||||
}
|
||||
|
||||
void gl_rend_state_struct::enable_blend(bool force) {
|
||||
void gl_rend_state::enable_blend(bool force) {
|
||||
if (force || !blend) {
|
||||
glEnable(GL_BLEND);
|
||||
blend = GL_TRUE;
|
||||
}
|
||||
}
|
||||
|
||||
void gl_rend_state_struct::enable_cull_face(bool force) {
|
||||
void gl_rend_state::enable_cull_face(bool force) {
|
||||
if (force || !cull_face) {
|
||||
glEnable(GL_CULL_FACE);
|
||||
cull_face = GL_TRUE;
|
||||
}
|
||||
}
|
||||
|
||||
void gl_rend_state_struct::enable_depth_test(bool force) {
|
||||
void gl_rend_state::enable_depth_test(bool force) {
|
||||
if (force || !depth_test) {
|
||||
glEnable(GL_DEPTH_TEST);
|
||||
depth_test = GL_TRUE;
|
||||
}
|
||||
}
|
||||
|
||||
void gl_rend_state_struct::enable_multisample(bool force) {
|
||||
void gl_rend_state::enable_multisample(bool force) {
|
||||
if (force || !multisample) {
|
||||
glEnable(GL_MULTISAMPLE);
|
||||
multisample = GL_TRUE;
|
||||
}
|
||||
}
|
||||
|
||||
void gl_rend_state_struct::enable_primitive_restart(bool force) {
|
||||
void gl_rend_state::enable_primitive_restart(bool force) {
|
||||
if (force || !primitive_restart) {
|
||||
glEnable(GL_PRIMITIVE_RESTART);
|
||||
primitive_restart = GL_TRUE;
|
||||
}
|
||||
}
|
||||
|
||||
void gl_rend_state_struct::enable_scissor_test(bool force) {
|
||||
void gl_rend_state::enable_scissor_test(bool force) {
|
||||
if (force || !scissor_test) {
|
||||
glEnable(GL_SCISSOR_TEST);
|
||||
scissor_test = GL_TRUE;
|
||||
}
|
||||
}
|
||||
|
||||
void gl_rend_state_struct::enable_stencil_test(bool force) {
|
||||
void gl_rend_state::enable_stencil_test(bool force) {
|
||||
if (force || !stencil_test) {
|
||||
glEnable(GL_STENCIL_TEST);
|
||||
stencil_test = GL_TRUE;
|
||||
}
|
||||
}
|
||||
|
||||
void gl_rend_state_struct::get() {
|
||||
void gl_rend_state::get() {
|
||||
glGetIntegerv(GL_CURRENT_PROGRAM, (GLint*)&program);
|
||||
GLenum active_texture = GL_TEXTURE0;
|
||||
glGetIntegerv(GL_ACTIVE_TEXTURE, (GLint*)&active_texture);
|
||||
@@ -364,33 +831,37 @@ void gl_rend_state_struct::get() {
|
||||
polygon_mode = GL_FILL;
|
||||
}
|
||||
|
||||
GLuint gl_rend_state_struct::get_program() {
|
||||
void gl_rend_state::end_event() {
|
||||
glPopDebugGroup();
|
||||
}
|
||||
|
||||
GLuint gl_rend_state::get_program() {
|
||||
return program;
|
||||
}
|
||||
|
||||
gl_rend_state_rect gl_rend_state_struct::get_scissor() {
|
||||
gl_rend_state_rect gl_rend_state::get_scissor() {
|
||||
return scissor_box;
|
||||
}
|
||||
|
||||
void gl_rend_state_struct::get_scissor(GLint& x, GLint& y, GLsizei& width, GLsizei& height) {
|
||||
void gl_rend_state::get_scissor(GLint& x, GLint& y, GLsizei& width, GLsizei& height) {
|
||||
x = scissor_box.x;
|
||||
y = scissor_box.y;
|
||||
width = scissor_box.width;
|
||||
height = scissor_box.height;
|
||||
}
|
||||
|
||||
gl_rend_state_rect gl_rend_state_struct::get_viewport() {
|
||||
gl_rend_state_rect gl_rend_state::get_viewport() {
|
||||
return viewport;
|
||||
}
|
||||
|
||||
void gl_rend_state_struct::get_viewport(GLint& x, GLint& y, GLsizei& width, GLsizei& height) {
|
||||
void gl_rend_state::get_viewport(GLint& x, GLint& y, GLsizei& width, GLsizei& height) {
|
||||
x = viewport.x;
|
||||
y = viewport.y;
|
||||
width = viewport.width;
|
||||
height = viewport.height;
|
||||
}
|
||||
|
||||
void gl_rend_state_struct::set_blend_func(GLenum src, GLenum dst, bool force) {
|
||||
void gl_rend_state::set_blend_func(GLenum src, GLenum dst, bool force) {
|
||||
if (force || blend_src_rgb != src || blend_dst_rgb != dst
|
||||
|| blend_src_alpha != GL_ONE || blend_dst_alpha != GL_ONE_MINUS_SRC_ALPHA) {
|
||||
glBlendFuncSeparate(src, dst, GL_ONE, GL_ONE_MINUS_SRC_ALPHA);
|
||||
@@ -401,7 +872,7 @@ void gl_rend_state_struct::set_blend_func(GLenum src, GLenum dst, bool force) {
|
||||
}
|
||||
}
|
||||
|
||||
void gl_rend_state_struct::set_blend_func_separate(GLenum src_rgb, GLenum dst_rgb,
|
||||
void gl_rend_state::set_blend_func_separate(GLenum src_rgb, GLenum dst_rgb,
|
||||
GLenum src_alpha, GLenum dst_alpha, bool force) {
|
||||
if (force || blend_src_rgb != src_rgb || blend_dst_rgb != dst_rgb
|
||||
|| blend_src_alpha != src_alpha || blend_dst_alpha != dst_alpha) {
|
||||
@@ -413,7 +884,7 @@ void gl_rend_state_struct::set_blend_func_separate(GLenum src_rgb, GLenum dst_rg
|
||||
}
|
||||
}
|
||||
|
||||
void gl_rend_state_struct::set_blend_equation(GLenum mode, bool force) {
|
||||
void gl_rend_state::set_blend_equation(GLenum mode, bool force) {
|
||||
if (force || blend_mode_rgb != mode || blend_mode_alpha != mode) {
|
||||
glBlendEquationSeparate(mode, mode);
|
||||
blend_mode_rgb = mode;
|
||||
@@ -421,7 +892,7 @@ void gl_rend_state_struct::set_blend_equation(GLenum mode, bool force) {
|
||||
}
|
||||
}
|
||||
|
||||
void gl_rend_state_struct::set_blend_equation_separate(GLenum mode_rgb, GLenum mode_alpha, bool force) {
|
||||
void gl_rend_state::set_blend_equation_separate(GLenum mode_rgb, GLenum mode_alpha, bool force) {
|
||||
if (force || blend_mode_rgb != mode_rgb || blend_mode_alpha != mode_alpha) {
|
||||
glBlendEquationSeparate(mode_rgb, mode_alpha);
|
||||
blend_mode_rgb = mode_rgb;
|
||||
@@ -429,7 +900,7 @@ void gl_rend_state_struct::set_blend_equation_separate(GLenum mode_rgb, GLenum m
|
||||
}
|
||||
}
|
||||
|
||||
void gl_rend_state_struct::set_color_mask(GLboolean red, GLboolean green,
|
||||
void gl_rend_state::set_color_mask(GLboolean red, GLboolean green,
|
||||
GLboolean blue, GLboolean alpha, bool force) {
|
||||
if (force || color_mask[0] != red || color_mask[1] != green
|
||||
|| color_mask[2] != blue || color_mask[3] != alpha) {
|
||||
@@ -441,35 +912,35 @@ void gl_rend_state_struct::set_color_mask(GLboolean red, GLboolean green,
|
||||
}
|
||||
}
|
||||
|
||||
void gl_rend_state_struct::set_cull_face_mode(GLenum mode, bool force) {
|
||||
void gl_rend_state::set_cull_face_mode(GLenum mode, bool force) {
|
||||
if (force || cull_face_mode != mode) {
|
||||
glCullFace(mode);
|
||||
cull_face_mode = mode;
|
||||
}
|
||||
}
|
||||
|
||||
void gl_rend_state_struct::set_depth_func(GLenum func, bool force) {
|
||||
void gl_rend_state::set_depth_func(GLenum func, bool force) {
|
||||
if (force || depth_func != func) {
|
||||
glDepthFunc(func);
|
||||
depth_func = func;
|
||||
}
|
||||
}
|
||||
|
||||
void gl_rend_state_struct::set_depth_mask(GLboolean flag, bool force) {
|
||||
void gl_rend_state::set_depth_mask(GLboolean flag, bool force) {
|
||||
if (force || depth_mask != flag) {
|
||||
glDepthMask(flag);
|
||||
depth_mask = flag;
|
||||
}
|
||||
}
|
||||
|
||||
void gl_rend_state_struct::set_line_width(GLfloat width, bool force) {
|
||||
void gl_rend_state::set_line_width(GLfloat width, bool force) {
|
||||
if (force || line_width != width) {
|
||||
glLineWidth(width);
|
||||
line_width = width;
|
||||
}
|
||||
}
|
||||
|
||||
void gl_rend_state_struct::set_polygon_mode(GLenum face, GLenum mode, bool force) {
|
||||
void gl_rend_state::set_polygon_mode(GLenum face, GLenum mode, bool force) {
|
||||
switch (face) {
|
||||
case GL_FRONT:
|
||||
if (force || polygon_mode != mode) {
|
||||
@@ -492,14 +963,14 @@ void gl_rend_state_struct::set_polygon_mode(GLenum face, GLenum mode, bool force
|
||||
}
|
||||
}
|
||||
|
||||
void gl_rend_state_struct::set_primitive_restart_index(GLuint index, bool force) {
|
||||
void gl_rend_state::set_primitive_restart_index(GLuint index, bool force) {
|
||||
if (force || primitive_restart_index != index) {
|
||||
glPrimitiveRestartIndex(index);
|
||||
primitive_restart_index = index;
|
||||
}
|
||||
}
|
||||
|
||||
void gl_rend_state_struct::set_scissor(const gl_rend_state_rect& rect, bool force) {
|
||||
void gl_rend_state::set_scissor(const gl_rend_state_rect& rect, bool force) {
|
||||
if (force || scissor_box.x != rect.x || scissor_box.y != rect.y
|
||||
|| scissor_box.width != rect.width || scissor_box.height != rect.height) {
|
||||
glScissor(rect.x, rect.y, rect.width, rect.height);
|
||||
@@ -507,7 +978,7 @@ void gl_rend_state_struct::set_scissor(const gl_rend_state_rect& rect, bool forc
|
||||
}
|
||||
}
|
||||
|
||||
void gl_rend_state_struct::set_scissor(GLint x, GLint y, GLsizei width, GLsizei height, bool force) {
|
||||
void gl_rend_state::set_scissor(GLint x, GLint y, GLsizei width, GLsizei height, bool force) {
|
||||
if (force || scissor_box.x != x || scissor_box.y != y
|
||||
|| scissor_box.width != width || scissor_box.height != height) {
|
||||
glScissor(x, y, width, height);
|
||||
@@ -518,7 +989,7 @@ void gl_rend_state_struct::set_scissor(GLint x, GLint y, GLsizei width, GLsizei
|
||||
}
|
||||
}
|
||||
|
||||
void gl_rend_state_struct::set_stencil_func(GLenum func, GLint ref, GLuint mask, bool force) {
|
||||
void gl_rend_state::set_stencil_func(GLenum func, GLint ref, GLuint mask, bool force) {
|
||||
if (force || stencil_func != func || stencil_ref != ref || stencil_value_mask != mask) {
|
||||
glStencilFunc(func, ref, mask);
|
||||
stencil_func = func;
|
||||
@@ -527,14 +998,14 @@ void gl_rend_state_struct::set_stencil_func(GLenum func, GLint ref, GLuint mask,
|
||||
}
|
||||
}
|
||||
|
||||
void gl_rend_state_struct::set_stencil_mask(GLuint mask, bool force) {
|
||||
void gl_rend_state::set_stencil_mask(GLuint mask, bool force) {
|
||||
if (force || stencil_mask != mask) {
|
||||
glStencilMask(mask);
|
||||
stencil_mask = mask;
|
||||
}
|
||||
}
|
||||
|
||||
void gl_rend_state_struct::set_stencil_op(GLenum sfail, GLenum dpfail, GLenum dppass, bool force) {
|
||||
void gl_rend_state::set_stencil_op(GLenum sfail, GLenum dpfail, GLenum dppass, bool force) {
|
||||
if (force || stencil_fail != sfail || stencil_dpfail != dpfail || stencil_dppass != dppass) {
|
||||
glStencilOp(sfail, dpfail, dppass);
|
||||
stencil_fail = sfail;
|
||||
@@ -543,7 +1014,7 @@ void gl_rend_state_struct::set_stencil_op(GLenum sfail, GLenum dpfail, GLenum dp
|
||||
}
|
||||
}
|
||||
|
||||
void gl_rend_state_struct::set_viewport(const gl_rend_state_rect& rect, bool force) {
|
||||
void gl_rend_state::set_viewport(const gl_rend_state_rect& rect, bool force) {
|
||||
if (force || viewport.x != rect.x || viewport.y != rect.y
|
||||
|| viewport.width != rect.width || viewport.height != rect.height) {
|
||||
glViewport(rect.x, rect.y, rect.width, rect.height);
|
||||
@@ -551,7 +1022,7 @@ void gl_rend_state_struct::set_viewport(const gl_rend_state_rect& rect, bool for
|
||||
}
|
||||
}
|
||||
|
||||
void gl_rend_state_struct::set_viewport(GLint x, GLint y, GLsizei width, GLsizei height, bool force) {
|
||||
void gl_rend_state::set_viewport(GLint x, GLint y, GLsizei width, GLsizei height, bool force) {
|
||||
if (force || viewport.x != x || viewport.y != y
|
||||
|| viewport.width != width || viewport.height != height) {
|
||||
glViewport(x, y, width, height);
|
||||
@@ -562,7 +1033,7 @@ void gl_rend_state_struct::set_viewport(GLint x, GLint y, GLsizei width, GLsizei
|
||||
}
|
||||
}
|
||||
|
||||
void gl_rend_state_struct::use_program(GLuint program, bool force) {
|
||||
void gl_rend_state::use_program(GLuint program, bool force) {
|
||||
if (force || this->program != program) {
|
||||
glUseProgram(program);
|
||||
this->program = program;
|
||||
|
||||
+14
-55
@@ -8,6 +8,8 @@
|
||||
#include "../KKdLib/default.hpp"
|
||||
#include "gl.hpp"
|
||||
|
||||
constexpr int32_t GL_REND_STATE_COUNT = 4;
|
||||
|
||||
struct gl_rend_state_rect {
|
||||
GLint x;
|
||||
GLint y;
|
||||
@@ -15,58 +17,15 @@ struct gl_rend_state_rect {
|
||||
GLsizei height;
|
||||
};
|
||||
|
||||
struct gl_rend_state_struct {
|
||||
GLuint program;
|
||||
GLuint active_texture_index;
|
||||
GLuint texture_binding_2d[32];
|
||||
GLuint texture_binding_cube_map[32];
|
||||
GLuint sampler_binding[32];
|
||||
GLboolean blend;
|
||||
GLenum blend_src_rgb;
|
||||
GLenum blend_src_alpha;
|
||||
GLenum blend_dst_rgb;
|
||||
GLenum blend_dst_alpha;
|
||||
GLenum blend_mode_rgb;
|
||||
GLenum blend_mode_alpha;
|
||||
GLuint read_framebuffer_binding;
|
||||
GLuint draw_framebuffer_binding;
|
||||
GLuint vertex_array_binding;
|
||||
GLuint array_buffer_binding;
|
||||
GLuint element_array_buffer_binding;
|
||||
GLuint uniform_buffer_binding;
|
||||
GLuint uniform_buffer_bindings[14];
|
||||
GLintptr uniform_buffer_offsets[14];
|
||||
GLsizeiptr uniform_buffer_sizes[14];
|
||||
GLuint shader_storage_buffer_binding;
|
||||
GLuint shader_storage_buffer_bindings[14];
|
||||
GLintptr shader_storage_buffer_offsets[14];
|
||||
GLsizeiptr shader_storage_buffer_sizes[14];
|
||||
GLboolean color_mask[4];
|
||||
GLboolean cull_face;
|
||||
GLenum cull_face_mode;
|
||||
GLboolean depth_test;
|
||||
GLenum depth_func;
|
||||
GLboolean depth_mask;
|
||||
GLfloat line_width;
|
||||
GLenum polygon_mode;
|
||||
GLboolean multisample;
|
||||
GLboolean primitive_restart;
|
||||
GLuint primitive_restart_index;
|
||||
gl_rend_state_rect scissor_box;
|
||||
GLboolean scissor_test;
|
||||
GLboolean stencil_test;
|
||||
GLenum stencil_func;
|
||||
GLenum stencil_fail;
|
||||
GLenum stencil_dpfail;
|
||||
GLenum stencil_dppass;
|
||||
GLuint stencil_mask;
|
||||
GLint stencil_ref;
|
||||
GLuint stencil_value_mask;
|
||||
gl_rend_state_rect viewport;
|
||||
struct p_gl_rend_state {
|
||||
struct gl_rend_state& ptr;
|
||||
|
||||
p_gl_rend_state(int32_t index);
|
||||
|
||||
void active_bind_texture_2d(int32_t index, GLuint texture, bool force = false);
|
||||
void active_bind_texture_cube_map(int32_t index, GLuint texture, bool force = false);
|
||||
void active_texture(size_t index, bool force = false);
|
||||
void begin_event(const char* message, int32_t length);
|
||||
void bind_framebuffer(GLuint framebuffer, bool force = false);
|
||||
void bind_read_framebuffer(GLuint framebuffer, bool force = false);
|
||||
void bind_draw_framebuffer(GLuint framebuffer, bool force = false);
|
||||
@@ -98,6 +57,11 @@ struct gl_rend_state_struct {
|
||||
void disable_primitive_restart(bool force = false);
|
||||
void disable_scissor_test(bool force = false);
|
||||
void disable_stencil_test(bool force = false);
|
||||
void draw_arrays(GLenum mode, GLint first, GLsizei count);
|
||||
void draw_elements(GLenum mode,
|
||||
GLsizei count, GLenum type, const void* indices);
|
||||
void draw_range_elements(GLenum mode,
|
||||
GLuint start, GLuint end, GLsizei count, GLenum type, const void* indices);
|
||||
void enable_blend(bool force = false);
|
||||
void enable_cull_face(bool force = false);
|
||||
void enable_depth_test(bool force = false);
|
||||
@@ -105,6 +69,7 @@ struct gl_rend_state_struct {
|
||||
void enable_primitive_restart(bool force = false);
|
||||
void enable_scissor_test(bool force = false);
|
||||
void enable_stencil_test(bool force = false);
|
||||
void end_event();
|
||||
void get();
|
||||
GLuint get_program();
|
||||
gl_rend_state_rect get_scissor();
|
||||
@@ -136,12 +101,6 @@ struct gl_rend_state_struct {
|
||||
|
||||
template <size_t size>
|
||||
inline void begin_event(const char(&str)[size]) {
|
||||
glPushDebugGroup(GL_DEBUG_SOURCE_APPLICATION, 0, (GLsizei)(size - 1), str);
|
||||
}
|
||||
|
||||
inline void end_event() {
|
||||
glPopDebugGroup();
|
||||
begin_event(str, (GLsizei)(size - 1));
|
||||
}
|
||||
};
|
||||
|
||||
extern gl_rend_state_struct gl_rend_state;
|
||||
|
||||
@@ -0,0 +1,110 @@
|
||||
/*
|
||||
by korenkonder
|
||||
GitHub/GitLab: korenkonder
|
||||
*/
|
||||
|
||||
#include "gl_state.hpp"
|
||||
|
||||
gl_state_struct gl_state;
|
||||
|
||||
void gl_state_struct::bind_framebuffer(GLuint framebuffer, bool force) {
|
||||
if (force || read_framebuffer_binding != framebuffer
|
||||
|| draw_framebuffer_binding != framebuffer) {
|
||||
glBindFramebuffer(GL_FRAMEBUFFER, framebuffer);
|
||||
read_framebuffer_binding = framebuffer;
|
||||
draw_framebuffer_binding = framebuffer;
|
||||
}
|
||||
}
|
||||
|
||||
void gl_state_struct::bind_read_framebuffer(GLuint framebuffer, bool force) {
|
||||
if (force || read_framebuffer_binding != framebuffer) {
|
||||
glBindFramebuffer(GL_READ_FRAMEBUFFER, framebuffer);
|
||||
read_framebuffer_binding = framebuffer;
|
||||
}
|
||||
}
|
||||
|
||||
void gl_state_struct::bind_draw_framebuffer(GLuint framebuffer, bool force) {
|
||||
if (force || draw_framebuffer_binding != framebuffer) {
|
||||
glBindFramebuffer(GL_DRAW_FRAMEBUFFER, framebuffer);
|
||||
draw_framebuffer_binding = framebuffer;
|
||||
}
|
||||
}
|
||||
|
||||
void gl_state_struct::bind_vertex_array(GLuint array, bool force) {
|
||||
if (force || vertex_array_binding != array) {
|
||||
glBindVertexArray(array);
|
||||
vertex_array_binding = array;
|
||||
}
|
||||
}
|
||||
|
||||
void gl_state_struct::bind_array_buffer(GLuint buffer, bool force) {
|
||||
if (force || array_buffer_binding != buffer) {
|
||||
glBindBuffer(GL_ARRAY_BUFFER, buffer);
|
||||
array_buffer_binding = buffer;
|
||||
}
|
||||
}
|
||||
|
||||
void gl_state_struct::bind_element_array_buffer(GLuint buffer, bool force) {
|
||||
if (force || element_array_buffer_binding != buffer) {
|
||||
glBindBuffer(GL_ELEMENT_ARRAY_BUFFER, buffer);
|
||||
element_array_buffer_binding = buffer;
|
||||
}
|
||||
}
|
||||
|
||||
void gl_state_struct::bind_uniform_buffer(GLuint buffer, bool force) {
|
||||
if (force || uniform_buffer_binding != buffer) {
|
||||
glBindBuffer(GL_UNIFORM_BUFFER, buffer);
|
||||
uniform_buffer_binding = buffer;
|
||||
}
|
||||
}
|
||||
|
||||
void gl_state_struct::bind_shader_storage_buffer(GLuint buffer, bool force) {
|
||||
if (force || shader_storage_buffer_binding != buffer) {
|
||||
glBindBuffer(GL_SHADER_STORAGE_BUFFER, buffer);
|
||||
shader_storage_buffer_binding = buffer;
|
||||
}
|
||||
}
|
||||
|
||||
void gl_state_struct::bind_texture_2d(GLuint texture, bool force) {
|
||||
if (texture_binding_2d != texture) {
|
||||
glBindTexture(GL_TEXTURE_2D, texture);
|
||||
texture_binding_2d = texture;
|
||||
}
|
||||
}
|
||||
|
||||
void gl_state_struct::bind_texture_cube_map(GLuint texture, bool force) {
|
||||
if (force || texture_binding_cube_map != texture) {
|
||||
glBindTexture(GL_TEXTURE_CUBE_MAP, texture);
|
||||
texture_binding_cube_map = texture;
|
||||
}
|
||||
}
|
||||
|
||||
bool gl_state_struct::check_uniform_buffer_binding() {
|
||||
return uniform_buffer_binding != 0;
|
||||
}
|
||||
|
||||
bool gl_state_struct::check_shader_storage_buffer_binding() {
|
||||
return shader_storage_buffer_binding != 0;
|
||||
}
|
||||
|
||||
bool gl_state_struct::check_texture_binding_2d() {
|
||||
return texture_binding_2d != 0;
|
||||
}
|
||||
|
||||
bool gl_state_struct::check_texture_binding_cube_map() {
|
||||
return texture_binding_cube_map != 0;
|
||||
}
|
||||
|
||||
void gl_state_struct::get() {
|
||||
glGetIntegerv(GL_TEXTURE_BINDING_2D, (GLint*)&texture_binding_2d);
|
||||
glGetIntegerv(GL_TEXTURE_BINDING_CUBE_MAP, (GLint*)&texture_binding_cube_map);
|
||||
|
||||
glGetIntegerv(GL_READ_FRAMEBUFFER_BINDING, (GLint*)&read_framebuffer_binding);
|
||||
glGetIntegerv(GL_DRAW_FRAMEBUFFER_BINDING, (GLint*)&draw_framebuffer_binding);
|
||||
glGetIntegerv(GL_VERTEX_ARRAY_BINDING, (GLint*)&vertex_array_binding);
|
||||
glGetIntegerv(GL_ARRAY_BUFFER_BINDING, (GLint*)&array_buffer_binding);
|
||||
glGetIntegerv(GL_ELEMENT_ARRAY_BUFFER_BINDING, (GLint*)&element_array_buffer_binding);
|
||||
|
||||
glGetIntegerv(GL_UNIFORM_BUFFER_BINDING, (GLint*)&uniform_buffer_binding);
|
||||
glGetIntegerv(GL_SHADER_STORAGE_BUFFER_BINDING, (GLint*)&shader_storage_buffer_binding);
|
||||
}
|
||||
@@ -0,0 +1,39 @@
|
||||
/*
|
||||
by korenkonder
|
||||
GitHub/GitLab: korenkonder
|
||||
*/
|
||||
|
||||
#pragma once
|
||||
|
||||
#include "../KKdLib/default.hpp"
|
||||
#include "gl.hpp"
|
||||
|
||||
struct gl_state_struct {
|
||||
GLuint texture_binding_2d;
|
||||
GLuint texture_binding_cube_map;
|
||||
GLuint read_framebuffer_binding;
|
||||
GLuint draw_framebuffer_binding;
|
||||
GLuint vertex_array_binding;
|
||||
GLuint array_buffer_binding;
|
||||
GLuint element_array_buffer_binding;
|
||||
GLuint uniform_buffer_binding;
|
||||
GLuint shader_storage_buffer_binding;
|
||||
|
||||
void bind_framebuffer(GLuint framebuffer, bool force = false);
|
||||
void bind_read_framebuffer(GLuint framebuffer, bool force = false);
|
||||
void bind_draw_framebuffer(GLuint framebuffer, bool force = false);
|
||||
void bind_vertex_array(GLuint array, bool force = false);
|
||||
void bind_array_buffer(GLuint buffer, bool force = false);
|
||||
void bind_element_array_buffer(GLuint buffer, bool force = false);
|
||||
void bind_uniform_buffer(GLuint buffer, bool force = false);
|
||||
void bind_shader_storage_buffer(GLuint buffer, bool force = false);
|
||||
void bind_texture_2d(GLuint texture, bool force = false);
|
||||
void bind_texture_cube_map(GLuint texture, bool force = false);
|
||||
bool check_uniform_buffer_binding();
|
||||
bool check_shader_storage_buffer_binding();
|
||||
bool check_texture_binding_2d();
|
||||
bool check_texture_binding_cube_map();
|
||||
void get();
|
||||
};
|
||||
|
||||
extern gl_state_struct gl_state;
|
||||
+5
-10
@@ -7,6 +7,7 @@
|
||||
#include "../KKdLib/farc.hpp"
|
||||
#include "../KKdLib/hash.hpp"
|
||||
#include "../KKdLib/str_utils.hpp"
|
||||
#include "gl_state.hpp"
|
||||
#include "render_context.hpp"
|
||||
#include "stage_param.hpp"
|
||||
|
||||
@@ -151,14 +152,8 @@ void light_param_data_storage_data_set_default_light_param(light_param_data_stor
|
||||
light_param_data_storage_data->default_light_param.set(light_param_data_storage_data, flags);
|
||||
}
|
||||
|
||||
void light_param_data_storage_data_set_ibl() {
|
||||
static const int32_t ibl_texture_index[] = {
|
||||
9, 10, 11, 12, 13
|
||||
};
|
||||
|
||||
for (int32_t i = 0; i < 5; i++)
|
||||
gl_rend_state.active_bind_texture_cube_map(ibl_texture_index[i],
|
||||
light_param_data_storage_data->textures[i]);
|
||||
const GLuint* light_param_data_storage_data_get_ibl_textures() {
|
||||
return light_param_data_storage_data->textures;
|
||||
}
|
||||
|
||||
void light_param_data_storage_data_set_pv_id(int32_t pv_id) {
|
||||
@@ -509,7 +504,7 @@ void light_param_data::set_ibl(const light_param_ibl* ibl, const light_param_dat
|
||||
return;
|
||||
|
||||
for (int32_t i = 0, j = -1; i < 5; i++, j++) {
|
||||
glBindTexture(GL_TEXTURE_CUBE_MAP, storage->textures[i]);
|
||||
gl_state.bind_texture_cube_map(storage->textures[i]);
|
||||
glTexParameteri(GL_TEXTURE_CUBE_MAP, GL_TEXTURE_WRAP_S, GL_CLAMP_TO_EDGE);
|
||||
glTexParameteri(GL_TEXTURE_CUBE_MAP, GL_TEXTURE_WRAP_T, GL_CLAMP_TO_EDGE);
|
||||
glTexParameteri(GL_TEXTURE_CUBE_MAP, GL_TEXTURE_WRAP_R, GL_CLAMP_TO_EDGE);
|
||||
@@ -528,7 +523,7 @@ void light_param_data::set_ibl(const light_param_ibl* ibl, const light_param_dat
|
||||
light_param_data::set_ibl_specular(&ibl->specular[j]);
|
||||
}
|
||||
}
|
||||
glBindTexture(GL_TEXTURE_CUBE_MAP, 0);
|
||||
gl_state.bind_texture_cube_map(0);
|
||||
|
||||
::light_set* set = &rctx_ptr->light_set[LIGHT_SET_MAIN];
|
||||
set->set_irradiance(ibl->diff_coef[1][0], ibl->diff_coef[1][1], ibl->diff_coef[1][2]);
|
||||
|
||||
@@ -31,9 +31,6 @@ enum light_param_data_storage_flags {
|
||||
|
||||
extern void light_param_data_storage_data_init();
|
||||
extern void light_param_data_storage_data_free_file_handlers();
|
||||
#if DISPLAY_IBL
|
||||
extern GLuint light_param_data_storage_data_get_ibl_texture(int32_t index);
|
||||
#endif
|
||||
extern std::string light_param_data_storage_data_get_name();
|
||||
extern int32_t light_param_data_storage_data_get_pv_id();
|
||||
extern int32_t light_param_data_storage_data_get_stage_index();
|
||||
@@ -47,7 +44,7 @@ extern void light_param_data_storage_data_load_stages(
|
||||
extern void light_param_data_storage_data_reset();
|
||||
extern void light_param_data_storage_data_set_default_light_param(
|
||||
light_param_data_storage_flags flags = LIGHT_PARAM_DATA_STORAGE_ALL);
|
||||
extern void light_param_data_storage_data_set_ibl();
|
||||
extern const GLuint* light_param_data_storage_data_get_ibl_textures();
|
||||
extern void light_param_data_storage_data_set_pv_id(int32_t pv_id);
|
||||
extern void light_param_data_storage_data_set_pv_cut(int32_t cut_id,
|
||||
light_param_data_storage_flags flags = LIGHT_PARAM_DATA_STORAGE_ALL);
|
||||
|
||||
+10
-12
@@ -64,13 +64,11 @@ void fog::set_color(const vec4& value) {
|
||||
color = value;
|
||||
}
|
||||
|
||||
void fog::data_set(fog_id id) {
|
||||
void fog::data_set(render_data_context& rend_data_ctx, fog_id id) {
|
||||
fog_type type = get_type();
|
||||
if (type == FOG_NONE)
|
||||
return;
|
||||
|
||||
extern render_context* rctx_ptr;
|
||||
|
||||
switch (id) {
|
||||
case FOG_DEPTH: {
|
||||
float_t density = get_density();
|
||||
@@ -81,13 +79,13 @@ void fog::data_set(fog_id id) {
|
||||
vec4 color;
|
||||
get_color(color);
|
||||
|
||||
render_context::fog_params params = {};
|
||||
rctx_ptr->get_scene_fog_params(params);
|
||||
render_data_context::fog_params params = {};
|
||||
rend_data_ctx.get_scene_fog_params(params);
|
||||
params.density = density;
|
||||
params.start = start;
|
||||
params.end = end;
|
||||
params.depth_color = color;
|
||||
rctx_ptr->set_scene_fog_params(params);
|
||||
rend_data_ctx.set_scene_fog_params(params);
|
||||
} break;
|
||||
case FOG_HEIGHT: {
|
||||
float_t density = get_density();
|
||||
@@ -98,14 +96,14 @@ void fog::data_set(fog_id id) {
|
||||
vec4 color;
|
||||
get_color(color);
|
||||
|
||||
render_context::fog_params params = {};
|
||||
rctx_ptr->get_scene_fog_params(params);
|
||||
render_data_context::fog_params params = {};
|
||||
rend_data_ctx.get_scene_fog_params(params);
|
||||
params.height_params.x = density;
|
||||
params.height_params.y = start;
|
||||
params.height_params.z = end;
|
||||
params.height_params.w = 1.0f / (end - start);
|
||||
params.height_color = color;
|
||||
rctx_ptr->set_scene_fog_params(params);
|
||||
rend_data_ctx.set_scene_fog_params(params);
|
||||
} break;
|
||||
case FOG_BUMP: {
|
||||
float_t density = get_density();
|
||||
@@ -114,13 +112,13 @@ void fog::data_set(fog_id id) {
|
||||
if (start >= end)
|
||||
start = end - 0.01f;
|
||||
|
||||
render_context::fog_params params = {};
|
||||
rctx_ptr->get_scene_fog_params(params);
|
||||
render_data_context::fog_params params = {};
|
||||
rend_data_ctx.get_scene_fog_params(params);
|
||||
params.bump_params.x = density;
|
||||
params.bump_params.y = start;
|
||||
params.bump_params.z = end;
|
||||
params.bump_params.w = 1.0f / (end - start);
|
||||
rctx_ptr->set_scene_fog_params(params);
|
||||
rend_data_ctx.set_scene_fog_params(params);
|
||||
} break;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -32,5 +32,5 @@ struct fog {
|
||||
void set_index(int32_t value);
|
||||
void get_color(vec4& value) const;
|
||||
void set_color(const vec4& value);
|
||||
void data_set(fog_id id);
|
||||
void data_set(struct render_data_context& rend_data_ctx, fog_id id);
|
||||
};
|
||||
|
||||
@@ -259,7 +259,7 @@ void light_set::set_irradiance(const mat4&& r, const mat4&& g, const mat4&& b) {
|
||||
irradiance_b = b;
|
||||
}
|
||||
|
||||
void light_set::data_set(face& face, light_set_id id) {
|
||||
void light_set::data_set(render_data_context& rend_data_ctx, face& face, light_set_id id) {
|
||||
static const float_t spec_coef = (float_t)(1.0 / (1.0 - cos(18.0 * DEG_TO_RAD)));
|
||||
static const float_t luce_coef = (float_t)(1.0 / (1.0 - cos(45.0 * DEG_TO_RAD)));
|
||||
|
||||
@@ -346,7 +346,7 @@ void light_set::data_set(face& face, light_set_id id) {
|
||||
vec4 chara_f_diffuse;
|
||||
vec4 chara_tc_param;
|
||||
if (lights[LIGHT_TONE_CURVE].get_type() == LIGHT_PARALLEL) {
|
||||
uniform_value[U_TONE_CURVE] = 1;
|
||||
rend_data_ctx.shader_flags.arr[U_TONE_CURVE] = 1;
|
||||
lights[LIGHT_TONE_CURVE].get_position(chara_f_dir);
|
||||
light_get_direction_from_position(&chara_f_dir, &lights[LIGHT_TONE_CURVE]);
|
||||
lights[LIGHT_TONE_CURVE].get_ambient(chara_f_ambient);
|
||||
@@ -364,7 +364,7 @@ void light_set::data_set(face& face, light_set_id id) {
|
||||
chara_tc_param.w = 0.0f;
|
||||
}
|
||||
else {
|
||||
uniform_value[U_TONE_CURVE] = 0;
|
||||
rend_data_ctx.shader_flags.arr[U_TONE_CURVE] = 0;
|
||||
chara_f_dir = { 0.0f, 1.0f, 0.0f, 0.0f };
|
||||
chara_f_ambient = 0.0f;
|
||||
chara_f_diffuse = 0.0f;
|
||||
@@ -427,8 +427,7 @@ void light_set::data_set(face& face, light_set_id id) {
|
||||
}
|
||||
}
|
||||
|
||||
extern render_context* rctx_ptr;
|
||||
rctx_ptr->set_scene_light(irradiance_r_transforms, irradiance_g_transforms, irradiance_b_transforms,
|
||||
rend_data_ctx.set_scene_light(irradiance_r_transforms, irradiance_g_transforms, irradiance_b_transforms,
|
||||
light_env_stage_diffuse, light_env_stage_specular, light_env_chara_diffuse,
|
||||
light_env_chara_ambient, light_env_chara_specular,
|
||||
light_env_reflect_diffuse, light_env_reflect_ambient,
|
||||
@@ -439,6 +438,15 @@ void light_set::data_set(face& face, light_set_id id) {
|
||||
chara_color0, chara_color1, chara_f_dir, chara_f_ambient,
|
||||
chara_f_diffuse, chara_tc_param, normal_tangent_transforms,
|
||||
light_reflect_dir, clip_plane, npr_cloth_spec_color);
|
||||
|
||||
extern const GLuint* light_param_data_storage_data_get_ibl_textures();
|
||||
const GLuint* textures = light_param_data_storage_data_get_ibl_textures();
|
||||
static const int32_t ibl_texture_index[] = {
|
||||
9, 10, 11, 12, 13
|
||||
};
|
||||
|
||||
for (int32_t i = 0; i < 5; i++)
|
||||
rend_data_ctx.state.active_bind_texture_cube_map(ibl_texture_index[i], textures[i]);
|
||||
}
|
||||
|
||||
static void light_get_direction_from_position(vec4* pos_dir, light_data* light, bool force) {
|
||||
|
||||
@@ -85,5 +85,5 @@ struct light_set {
|
||||
void get_irradiance(mat4& r, mat4& g, mat4& b);
|
||||
void set_irradiance(const mat4& r, const mat4& g, const mat4& b);
|
||||
void set_irradiance(const mat4&& r, const mat4&& g, const mat4&& b);
|
||||
void data_set(face& face, light_set_id id);
|
||||
void data_set(struct render_data_context& rend_data_ctx, face& face, light_set_id id);
|
||||
};
|
||||
|
||||
+145
-176
@@ -7,6 +7,7 @@
|
||||
#include "../../KKdLib/database/stage.hpp"
|
||||
#include "../Glitter/glitter.hpp"
|
||||
#include "../config.hpp"
|
||||
#include "../gl_state.hpp"
|
||||
#include "../render_context.hpp"
|
||||
#include "../shader_ft.hpp"
|
||||
#include "draw_object.hpp"
|
||||
@@ -301,15 +302,15 @@ namespace mdl {
|
||||
morph_vertex_buffer = 0;
|
||||
morph_vertex_buffer_offset = 0;
|
||||
|
||||
glBindVertexArray(vertex_array);
|
||||
gl_state.bind_vertex_array(vertex_array);
|
||||
for (int32_t i = 0; i < 16; i++)
|
||||
if (vertex_attrib_array[i]) {
|
||||
glDisableVertexAttribArray(i);
|
||||
vertex_attrib_array[i] = false;
|
||||
}
|
||||
glBindBuffer(GL_ARRAY_BUFFER, 0);
|
||||
glBindBuffer(GL_ELEMENT_ARRAY_BUFFER, 0);
|
||||
glBindVertexArray(0);
|
||||
gl_state.bind_array_buffer(0);
|
||||
gl_state.bind_element_array_buffer(0);
|
||||
gl_state.bind_vertex_array(0);
|
||||
}
|
||||
|
||||
DispManager::DispManager() : obj_flags(), shadow_type(), field_8(), field_C(),
|
||||
@@ -418,7 +419,7 @@ namespace mdl {
|
||||
if (!vertex_array->vertex_array) {
|
||||
glGenVertexArrays(1, &vertex_array->vertex_array);
|
||||
|
||||
glBindVertexArray(vertex_array->vertex_array);
|
||||
gl_state.bind_vertex_array(vertex_array->vertex_array);
|
||||
glVertexAttrib4f( POSITION_INDEX, 0.0f, 0.0f, 0.0f, 1.0f);
|
||||
glVertexAttrib4f( BONE_WEIGHT_INDEX, 0.0f, 0.0f, 0.0f, 0.0f);
|
||||
glVertexAttrib4f( NORMAL_INDEX, 0.0f, 0.0f, 0.0f, 1.0f);
|
||||
@@ -452,10 +453,10 @@ namespace mdl {
|
||||
vertex_attrib_buffer_binding, sizeof(vertex_attrib_buffer_binding));
|
||||
|
||||
if (!new_vertex_array)
|
||||
glBindVertexArray(vertex_array->vertex_array);
|
||||
glBindBuffer(GL_ARRAY_BUFFER, vertex_buffer);
|
||||
gl_state.bind_vertex_array(vertex_array->vertex_array);
|
||||
gl_state.bind_array_buffer(vertex_buffer);
|
||||
if (index_buffer)
|
||||
glBindBuffer(GL_ELEMENT_ARRAY_BUFFER, index_buffer);
|
||||
gl_state.bind_element_array_buffer(index_buffer);
|
||||
|
||||
size_t offset = vertex_buffer_offset;
|
||||
if (vertex_format & OBJ_VERTEX_POSITION) {
|
||||
@@ -694,7 +695,7 @@ namespace mdl {
|
||||
}
|
||||
|
||||
if (morph_vertex_buffer) {
|
||||
glBindBuffer(GL_ARRAY_BUFFER, morph_vertex_buffer);
|
||||
gl_state.bind_array_buffer(morph_vertex_buffer);
|
||||
|
||||
size_t offset = morph_vertex_buffer_offset;
|
||||
if (vertex_format & OBJ_VERTEX_POSITION) {
|
||||
@@ -845,8 +846,6 @@ namespace mdl {
|
||||
}
|
||||
|
||||
if (vertex_format & OBJ_VERTEX_COLOR0) {
|
||||
uniform_value[U_MORPH_COLOR] = 1;
|
||||
|
||||
if (!vertex_array->vertex_attrib_array[MORPH_COLOR_INDEX]) {
|
||||
glEnableVertexAttribArray(MORPH_COLOR_INDEX);
|
||||
vertex_array->vertex_attrib_array[MORPH_COLOR_INDEX] = true;
|
||||
@@ -926,10 +925,10 @@ namespace mdl {
|
||||
}
|
||||
}
|
||||
|
||||
glBindBuffer(GL_ARRAY_BUFFER, 0);
|
||||
glBindVertexArray(0);
|
||||
gl_state.bind_array_buffer(0);
|
||||
gl_state.bind_vertex_array(0);
|
||||
if (index_buffer)
|
||||
glBindBuffer(GL_ELEMENT_ARRAY_BUFFER, 0);
|
||||
gl_state.bind_element_array_buffer(0);
|
||||
}
|
||||
|
||||
static size_t gen_grid_vertices(std::vector<std::pair<vec3, vec3>>& data,
|
||||
@@ -1694,7 +1693,7 @@ namespace mdl {
|
||||
if (!etc_vertex_array->vertex_array) {
|
||||
glGenVertexArrays(1, &etc_vertex_array->vertex_array);
|
||||
|
||||
glBindVertexArray(etc_vertex_array->vertex_array);
|
||||
gl_state.bind_vertex_array(etc_vertex_array->vertex_array);
|
||||
glVertexAttrib4f( POSITION_INDEX, 0.0f, 0.0f, 0.0f, 1.0f);
|
||||
glVertexAttrib4f( BONE_WEIGHT_INDEX, 0.0f, 0.0f, 0.0f, 0.0f);
|
||||
glVertexAttrib4f( NORMAL_INDEX, 0.0f, 0.0f, 0.0f, 1.0f);
|
||||
@@ -1834,20 +1833,20 @@ namespace mdl {
|
||||
GLsizei size_vertex = sizeof(vec3) * 2;
|
||||
|
||||
if (!new_vertex_array)
|
||||
glBindVertexArray(etc_vertex_array->vertex_array);
|
||||
gl_state.bind_vertex_array(etc_vertex_array->vertex_array);
|
||||
|
||||
if (etc_vertex_array->vertex_buffer.IsNull())
|
||||
etc_vertex_array->vertex_buffer.Create(sizeof(vec3) * 2 * vtx_data.size());
|
||||
etc_vertex_array->vertex_buffer.Create(gl_state, sizeof(vec3) * 2 * vtx_data.size());
|
||||
|
||||
glBindBuffer(GL_ARRAY_BUFFER, etc_vertex_array->vertex_buffer);
|
||||
gl_state.bind_array_buffer(etc_vertex_array->vertex_buffer);
|
||||
glBufferSubData(GL_ARRAY_BUFFER, 0, sizeof(vec3) * 2
|
||||
* vtx_data.size(), vtx_data.data());
|
||||
|
||||
if (indexed) {
|
||||
if (etc_vertex_array->index_buffer.IsNull())
|
||||
etc_vertex_array->index_buffer.Create(sizeof(uint32_t) * vtx_indices.size());
|
||||
etc_vertex_array->index_buffer.Create(gl_state, sizeof(uint32_t) * vtx_indices.size());
|
||||
|
||||
glBindBuffer(GL_ELEMENT_ARRAY_BUFFER, etc_vertex_array->index_buffer);
|
||||
gl_state.bind_element_array_buffer(etc_vertex_array->index_buffer);
|
||||
glBufferSubData(GL_ELEMENT_ARRAY_BUFFER, 0, sizeof(uint32_t)
|
||||
* vtx_indices.size(), vtx_indices.data());
|
||||
}
|
||||
@@ -1860,10 +1859,10 @@ namespace mdl {
|
||||
glVertexAttribPointer(NORMAL_INDEX,
|
||||
3, GL_FLOAT, GL_FALSE, size_vertex, (void*)sizeof(vec3));
|
||||
|
||||
glBindBuffer(GL_ARRAY_BUFFER, 0);
|
||||
glBindVertexArray(0);
|
||||
gl_state.bind_array_buffer(0);
|
||||
gl_state.bind_vertex_array(0);
|
||||
if (indexed)
|
||||
glBindBuffer(GL_ELEMENT_ARRAY_BUFFER, 0);
|
||||
gl_state.bind_element_array_buffer(0);
|
||||
}
|
||||
|
||||
void* DispManager::alloc_data(int32_t size) {
|
||||
@@ -1900,7 +1899,7 @@ namespace mdl {
|
||||
buff_offset = 0;
|
||||
}
|
||||
|
||||
void DispManager::calc_obj_radius(const mat4* view, mdl::ObjType type) {
|
||||
void DispManager::calc_obj_radius(const cam_data& cam, mdl::ObjType type) {
|
||||
std::vector<vec3> alpha_center;
|
||||
std::vector<vec3> mat_center;
|
||||
|
||||
@@ -1911,9 +1910,9 @@ namespace mdl {
|
||||
case OBJ_KIND_NORMAL: {
|
||||
mat4 mat = i->mat;
|
||||
if (i->args.sub_mesh.mesh->attrib.m.billboard)
|
||||
model_mat_face_camera_view(view, &mat, &mat);
|
||||
model_mat_face_camera_view(cam, &mat, &mat);
|
||||
else if (i->args.sub_mesh.mesh->attrib.m.billboard_y_axis)
|
||||
model_mat_face_camera_position(view, &mat, &mat);
|
||||
model_mat_face_camera_position(cam, &mat, &mat);
|
||||
|
||||
get_obj_center(mat, &i->args.sub_mesh, center);
|
||||
|
||||
@@ -1947,7 +1946,7 @@ namespace mdl {
|
||||
if (show_mat_center && type == OBJ_TYPE_TRANSLUCENT && v50)
|
||||
mat_center.push_back(center);
|
||||
|
||||
mat4_transform_point(view, ¢er, ¢er);
|
||||
mat4_transform_point(&cam.get_view_mat(), ¢er, ¢er);
|
||||
i->view_z = center.z;
|
||||
}
|
||||
|
||||
@@ -1980,7 +1979,7 @@ namespace mdl {
|
||||
}
|
||||
}
|
||||
|
||||
void DispManager::calc_obj_radius(const mat4* view, ObjTypeLocal type) {
|
||||
void DispManager::calc_obj_radius(const cam_data& cam, ObjTypeLocal type) {
|
||||
for (ObjData*& i : obj_local[type]) {
|
||||
vec3 center = 0.0f;
|
||||
bool v50 = false;
|
||||
@@ -1988,9 +1987,9 @@ namespace mdl {
|
||||
case OBJ_KIND_NORMAL: {
|
||||
mat4 mat = i->mat;
|
||||
if (i->args.sub_mesh.mesh->attrib.m.billboard)
|
||||
model_mat_face_camera_view(view, &mat, &mat);
|
||||
model_mat_face_camera_view(cam, &mat, &mat);
|
||||
else if (i->args.sub_mesh.mesh->attrib.m.billboard_y_axis)
|
||||
model_mat_face_camera_position(view, &mat, &mat);
|
||||
model_mat_face_camera_position(cam, &mat, &mat);
|
||||
|
||||
get_obj_center(mat, &i->args.sub_mesh, center);
|
||||
|
||||
@@ -2015,12 +2014,12 @@ namespace mdl {
|
||||
break;
|
||||
}
|
||||
|
||||
mat4_transform_point(view, ¢er, ¢er);
|
||||
mat4_transform_point(&cam.get_view_mat(), ¢er, ¢er);
|
||||
i->view_z = center.z;
|
||||
}
|
||||
}
|
||||
|
||||
void DispManager::calc_obj_radius(const mat4* view, ObjTypeReflect type) {
|
||||
void DispManager::calc_obj_radius(const cam_data& cam, ObjTypeReflect type) {
|
||||
for (ObjData*& i : obj_reflect[type]) {
|
||||
vec3 center = 0.0f;
|
||||
bool v50 = false;
|
||||
@@ -2028,9 +2027,9 @@ namespace mdl {
|
||||
case OBJ_KIND_NORMAL: {
|
||||
mat4 mat = i->mat;
|
||||
if (i->args.sub_mesh.mesh->attrib.m.billboard)
|
||||
model_mat_face_camera_view(view, &mat, &mat);
|
||||
model_mat_face_camera_view(cam, &mat, &mat);
|
||||
else if (i->args.sub_mesh.mesh->attrib.m.billboard_y_axis)
|
||||
model_mat_face_camera_position(view, &mat, &mat);
|
||||
model_mat_face_camera_position(cam, &mat, &mat);
|
||||
|
||||
get_obj_center(mat, &i->args.sub_mesh, center);
|
||||
|
||||
@@ -2055,7 +2054,7 @@ namespace mdl {
|
||||
break;
|
||||
}
|
||||
|
||||
mat4_transform_point(view, ¢er, ¢er);
|
||||
mat4_transform_point(&cam.get_view_mat(), ¢er, ¢er);
|
||||
i->view_z = center.z;
|
||||
}
|
||||
}
|
||||
@@ -2075,13 +2074,13 @@ namespace mdl {
|
||||
|
||||
for (DispManager::etc_vertex_array& i : etc_vertex_array_cache)
|
||||
if (i.alive_time > 0 && --i.alive_time <= 0) {
|
||||
glBindVertexArray(i.vertex_array);
|
||||
gl_state.bind_vertex_array(i.vertex_array);
|
||||
glDisableVertexAttribArray(POSITION_INDEX);
|
||||
glDisableVertexAttribArray( NORMAL_INDEX);
|
||||
glBindBuffer(GL_ARRAY_BUFFER, 0);
|
||||
gl_state.bind_array_buffer(0);
|
||||
if (i.indexed)
|
||||
glBindBuffer(GL_ELEMENT_ARRAY_BUFFER, 0);
|
||||
glBindVertexArray(0);
|
||||
gl_state.bind_element_array_buffer(0);
|
||||
gl_state.bind_vertex_array(0);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -2092,25 +2091,24 @@ namespace mdl {
|
||||
i.reset_vertex_attrib();
|
||||
}
|
||||
|
||||
void DispManager::draw(ObjType type, int32_t depth_mask, bool reflect_texture_mask, int32_t alpha) {
|
||||
void DispManager::draw(render_data_context& rend_data_ctx, ObjType type,
|
||||
const cam_data& cam, int32_t depth_mask, bool reflect_texture_mask, int32_t alpha) {
|
||||
if (type < 0 || type >= OBJ_TYPE_MAX || get_obj_count(type) < 1)
|
||||
return;
|
||||
|
||||
render_context* rctx = rctx_ptr;
|
||||
|
||||
int32_t alpha_test = 0;
|
||||
float_t min_alpha = 1.0f;
|
||||
float_t alpha_threshold = 0.0f;
|
||||
bool reflect = uniform_value[U_REFLECT] == 1;
|
||||
void(*func)(render_context * rctx, const ObjSubMeshArgs * args) = draw_sub_mesh_default;
|
||||
bool reflect = rend_data_ctx.shader_flags.arr[U_REFLECT] == 1;
|
||||
void(*func)(render_data_context & rend_data_ctx, const ObjSubMeshArgs * args,
|
||||
const cam_data & cam, const mat4* mat) = draw_sub_mesh_default;
|
||||
|
||||
for (int32_t i = 0; i < 5; i++)
|
||||
gl_rend_state.active_bind_texture_2d(i, rctx->empty_texture_2d->glid);
|
||||
gl_rend_state.active_bind_texture_cube_map(5, rctx->empty_texture_cube_map->glid);
|
||||
gl_rend_state.active_texture(0);
|
||||
gl_rend_state.set_blend_func(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA);
|
||||
uniform_value_reset();
|
||||
gl_rend_state.get();
|
||||
rend_data_ctx.state.active_bind_texture_2d(i, rctx_ptr->empty_texture_2d->glid);
|
||||
rend_data_ctx.state.active_bind_texture_cube_map(5, rctx_ptr->empty_texture_cube_map->glid);
|
||||
rend_data_ctx.state.active_texture(0);
|
||||
rend_data_ctx.state.set_blend_func(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA);
|
||||
rend_data_ctx.reset_shader_flags();
|
||||
|
||||
switch (type) {
|
||||
case OBJ_TYPE_TRANSLUCENT:
|
||||
@@ -2118,7 +2116,7 @@ namespace mdl {
|
||||
if (depth_mask)
|
||||
func = draw_sub_mesh_translucent;
|
||||
else
|
||||
gl_rend_state.set_depth_mask(GL_FALSE);
|
||||
rend_data_ctx.state.set_depth_mask(GL_FALSE);
|
||||
|
||||
alpha_test = 1;
|
||||
min_alpha = 0.0f;
|
||||
@@ -2137,42 +2135,42 @@ namespace mdl {
|
||||
break;
|
||||
case OBJ_TYPE_TYPE_6:
|
||||
func = draw_sub_mesh_translucent;
|
||||
gl_rend_state.set_color_mask(GL_FALSE, GL_FALSE, GL_FALSE, GL_FALSE);
|
||||
rctx->draw_state->shader_index = SHADER_FT_SIL;
|
||||
rend_data_ctx.state.set_color_mask(GL_FALSE, GL_FALSE, GL_FALSE, GL_FALSE);
|
||||
rctx_ptr->draw_state->rend_data[rend_data_ctx.index].shader_index = SHADER_FT_SIL;
|
||||
break;
|
||||
case OBJ_TYPE_TYPE_7:
|
||||
func = draw_sub_mesh_translucent;
|
||||
gl_rend_state.set_color_mask(GL_FALSE, GL_FALSE, GL_FALSE, GL_FALSE);
|
||||
rctx->draw_state->shader_index = SHADER_FT_SIL;
|
||||
rend_data_ctx.state.set_color_mask(GL_FALSE, GL_FALSE, GL_FALSE, GL_FALSE);
|
||||
rctx_ptr->draw_state->rend_data[rend_data_ctx.index].shader_index = SHADER_FT_SIL;
|
||||
|
||||
alpha_test = 1;
|
||||
min_alpha = 0.0f;
|
||||
alpha_threshold = 0.99999994f;
|
||||
break;
|
||||
case OBJ_TYPE_REFLECT_CHARA_OPAQUE:
|
||||
gl_rend_state.set_cull_face_mode(GL_FRONT);
|
||||
rend_data_ctx.state.set_cull_face_mode(GL_FRONT);
|
||||
|
||||
if (!reflect_draw) {
|
||||
if (reflect)
|
||||
func = draw_sub_mesh_reflect;
|
||||
else if (rctx->render_manager->reflect_type == STAGE_DATA_REFLECT_REFLECT_MAP)
|
||||
else if (rctx_ptr->render_manager->reflect_type == STAGE_DATA_REFLECT_REFLECT_MAP)
|
||||
func = draw_sub_mesh_reflect_reflect_map;
|
||||
}
|
||||
break;
|
||||
case OBJ_TYPE_REFLECT_CHARA_TRANSLUCENT:
|
||||
gl_rend_state.set_cull_face_mode(GL_FRONT);
|
||||
rend_data_ctx.state.set_cull_face_mode(GL_FRONT);
|
||||
|
||||
min_alpha = 0.0f;
|
||||
|
||||
if (!reflect_draw) {
|
||||
if (reflect)
|
||||
func = draw_sub_mesh_reflect;
|
||||
else if (rctx->render_manager->reflect_type == STAGE_DATA_REFLECT_REFLECT_MAP)
|
||||
else if (rctx_ptr->render_manager->reflect_type == STAGE_DATA_REFLECT_REFLECT_MAP)
|
||||
func = draw_sub_mesh_reflect_reflect_map;
|
||||
}
|
||||
break;
|
||||
case OBJ_TYPE_REFLECT_CHARA_TRANSPARENT:
|
||||
gl_rend_state.set_cull_face_mode(GL_FRONT);
|
||||
rend_data_ctx.state.set_cull_face_mode(GL_FRONT);
|
||||
|
||||
alpha_test = 1;
|
||||
min_alpha = 0.1f;
|
||||
@@ -2181,7 +2179,7 @@ namespace mdl {
|
||||
if (!reflect_draw) {
|
||||
if (reflect)
|
||||
func = draw_sub_mesh_reflect;
|
||||
else if (rctx->render_manager->reflect_type == STAGE_DATA_REFLECT_REFLECT_MAP)
|
||||
else if (rctx_ptr->render_manager->reflect_type == STAGE_DATA_REFLECT_REFLECT_MAP)
|
||||
func = draw_sub_mesh_reflect_reflect_map;
|
||||
}
|
||||
break;
|
||||
@@ -2190,18 +2188,18 @@ namespace mdl {
|
||||
alpha_threshold = 0.5f;
|
||||
|
||||
if (reflect_draw)
|
||||
gl_rend_state.set_cull_face_mode(GL_FRONT);
|
||||
rend_data_ctx.state.set_cull_face_mode(GL_FRONT);
|
||||
else if (!reflect_texture_mask)
|
||||
func = draw_sub_mesh_reflect_reflect_map;
|
||||
break;
|
||||
case OBJ_TYPE_REFLECT_TRANSLUCENT:
|
||||
gl_rend_state.set_depth_mask(GL_FALSE);
|
||||
rend_data_ctx.state.set_depth_mask(GL_FALSE);
|
||||
|
||||
min_alpha = 0.0f;
|
||||
alpha_threshold = 0.0f;
|
||||
|
||||
if (reflect_draw)
|
||||
gl_rend_state.set_cull_face_mode(GL_FRONT);
|
||||
rend_data_ctx.state.set_cull_face_mode(GL_FRONT);
|
||||
break;
|
||||
case OBJ_TYPE_REFLECT_TRANSPARENT:
|
||||
alpha_test = 1;
|
||||
@@ -2209,10 +2207,10 @@ namespace mdl {
|
||||
alpha_threshold = 0.5f;
|
||||
|
||||
if (reflect_draw)
|
||||
gl_rend_state.set_cull_face_mode(GL_FRONT);
|
||||
rend_data_ctx.state.set_cull_face_mode(GL_FRONT);
|
||||
break;
|
||||
case OBJ_TYPE_REFRACT_TRANSLUCENT:
|
||||
gl_rend_state.set_depth_mask(GL_FALSE);
|
||||
rend_data_ctx.state.set_depth_mask(GL_FALSE);
|
||||
|
||||
min_alpha = 0.0f;
|
||||
alpha_threshold = 0.0f;
|
||||
@@ -2226,7 +2224,7 @@ namespace mdl {
|
||||
func = draw_sub_mesh_sss;
|
||||
|
||||
if (reflect_draw)
|
||||
gl_rend_state.set_cull_face_mode(GL_FRONT);
|
||||
rend_data_ctx.state.set_cull_face_mode(GL_FRONT);
|
||||
break;
|
||||
case OBJ_TYPE_TRANSPARENT_ALPHA_ORDER_1:
|
||||
case OBJ_TYPE_TRANSPARENT_ALPHA_ORDER_2:
|
||||
@@ -2238,7 +2236,7 @@ namespace mdl {
|
||||
case OBJ_TYPE_TRANSLUCENT_ALPHA_ORDER_1:
|
||||
case OBJ_TYPE_TRANSLUCENT_ALPHA_ORDER_2:
|
||||
case OBJ_TYPE_TRANSLUCENT_ALPHA_ORDER_3:
|
||||
gl_rend_state.set_depth_mask(GL_FALSE);
|
||||
rend_data_ctx.state.set_depth_mask(GL_FALSE);
|
||||
|
||||
alpha_test = 1;
|
||||
min_alpha = 0.0f;
|
||||
@@ -2248,25 +2246,25 @@ namespace mdl {
|
||||
func = draw_sub_mesh_translucent;
|
||||
break;
|
||||
}
|
||||
rctx->set_batch_alpha_threshold(alpha_threshold);
|
||||
rctx->set_batch_min_alpha(min_alpha);
|
||||
uniform_value[U_ALPHA_TEST] = alpha_test;
|
||||
rend_data_ctx.set_batch_alpha_threshold(alpha_threshold);
|
||||
rend_data_ctx.set_batch_min_alpha(min_alpha);
|
||||
rend_data_ctx.shader_flags.arr[U_ALPHA_TEST] = alpha_test;
|
||||
|
||||
if (alpha < 0)
|
||||
for (ObjData*& i : obj[type]) {
|
||||
switch (i->kind) {
|
||||
case OBJ_KIND_NORMAL: {
|
||||
draw_sub_mesh(rctx, &i->args.sub_mesh, &i->mat, func);
|
||||
draw_sub_mesh(rend_data_ctx, &i->args.sub_mesh, &i->mat, func, cam);
|
||||
} break;
|
||||
case OBJ_KIND_ETC: {
|
||||
draw_etc_obj(rctx, &i->args.etc, &i->mat);
|
||||
draw_etc_obj(rend_data_ctx, &i->args.etc, &i->mat);
|
||||
} break;
|
||||
case OBJ_KIND_USER: {
|
||||
i->args.user.func(i->args.user.data, &i->mat);
|
||||
i->args.user.func(rend_data_ctx, i->args.user.data, cam, &i->mat);
|
||||
} break;
|
||||
case OBJ_KIND_TRANSLUCENT: {
|
||||
for (int32_t j = 0; j < i->args.translucent.count; j++)
|
||||
draw_sub_mesh(rctx, i->args.translucent.sub_mesh[j], &i->mat, func);
|
||||
draw_sub_mesh(rend_data_ctx, i->args.translucent.sub_mesh[j], &i->mat, func, cam);
|
||||
} break;
|
||||
}
|
||||
}
|
||||
@@ -2277,7 +2275,7 @@ namespace mdl {
|
||||
int32_t a = (int32_t)(i->args.sub_mesh.blend_color.w * 255.0f);
|
||||
a = clamp_def(a, 0, 255);
|
||||
if (a == alpha)
|
||||
draw_sub_mesh(rctx, &i->args.sub_mesh, &i->mat, func);
|
||||
draw_sub_mesh(rend_data_ctx, &i->args.sub_mesh, &i->mat, func, cam);
|
||||
} break;
|
||||
case OBJ_KIND_TRANSLUCENT: {
|
||||
for (int32_t j = 0; j < i->args.translucent.count; j++) {
|
||||
@@ -2285,7 +2283,7 @@ namespace mdl {
|
||||
int32_t a = (int32_t)(args->blend_color.w * 255.0f);
|
||||
a = clamp_def(a, 0, 255);
|
||||
if (a == alpha)
|
||||
draw_sub_mesh(rctx, args, &i->mat, func);
|
||||
draw_sub_mesh(rend_data_ctx, args, &i->mat, func, cam);
|
||||
}
|
||||
} break;
|
||||
}
|
||||
@@ -2295,80 +2293,79 @@ namespace mdl {
|
||||
case OBJ_TYPE_TRANSLUCENT:
|
||||
case OBJ_TYPE_TRANSLUCENT_SORT_BY_RADIUS:
|
||||
if (!depth_mask)
|
||||
gl_rend_state.set_depth_mask(GL_TRUE);
|
||||
rend_data_ctx.state.set_depth_mask(GL_TRUE);
|
||||
break;
|
||||
case OBJ_TYPE_TYPE_6:
|
||||
case OBJ_TYPE_TYPE_7:
|
||||
rctx_ptr->draw_state->shader_index = -1;
|
||||
gl_rend_state.set_color_mask(GL_TRUE, GL_TRUE, GL_TRUE, GL_TRUE);
|
||||
rctx_ptr->draw_state->rend_data[rend_data_ctx.index].shader_index = -1;
|
||||
rend_data_ctx.state.set_color_mask(GL_TRUE, GL_TRUE, GL_TRUE, GL_TRUE);
|
||||
break;
|
||||
case OBJ_TYPE_REFLECT_CHARA_OPAQUE:
|
||||
case OBJ_TYPE_REFLECT_CHARA_TRANSLUCENT:
|
||||
case OBJ_TYPE_REFLECT_CHARA_TRANSPARENT:
|
||||
gl_rend_state.set_cull_face_mode(GL_BACK);
|
||||
rend_data_ctx.state.set_cull_face_mode(GL_BACK);
|
||||
break;
|
||||
case OBJ_TYPE_REFLECT_OPAQUE:
|
||||
if (reflect_draw)
|
||||
gl_rend_state.set_cull_face_mode(GL_FRONT);
|
||||
rend_data_ctx.state.set_cull_face_mode(GL_FRONT);
|
||||
break;
|
||||
case OBJ_TYPE_REFLECT_TRANSLUCENT:
|
||||
if (reflect_draw)
|
||||
gl_rend_state.set_cull_face_mode(GL_FRONT);
|
||||
gl_rend_state.set_depth_mask(GL_TRUE);
|
||||
rend_data_ctx.state.set_cull_face_mode(GL_FRONT);
|
||||
rend_data_ctx.state.set_depth_mask(GL_TRUE);
|
||||
break;
|
||||
case OBJ_TYPE_REFLECT_TRANSPARENT:
|
||||
if (reflect_draw)
|
||||
gl_rend_state.set_cull_face_mode(GL_FRONT);
|
||||
rend_data_ctx.state.set_cull_face_mode(GL_FRONT);
|
||||
break;
|
||||
case OBJ_TYPE_REFRACT_TRANSLUCENT:
|
||||
if (reflect_draw)
|
||||
gl_rend_state.set_cull_face_mode(GL_FRONT);
|
||||
gl_rend_state.set_depth_mask(GL_TRUE);
|
||||
rend_data_ctx.state.set_cull_face_mode(GL_FRONT);
|
||||
rend_data_ctx.state.set_depth_mask(GL_TRUE);
|
||||
break;
|
||||
case OBJ_TYPE_SSS:
|
||||
if (reflect_draw)
|
||||
gl_rend_state.set_cull_face_mode(GL_BACK);
|
||||
rend_data_ctx.state.set_cull_face_mode(GL_BACK);
|
||||
break;
|
||||
case OBJ_TYPE_TRANSLUCENT_ALPHA_ORDER_1:
|
||||
case OBJ_TYPE_TRANSLUCENT_ALPHA_ORDER_2:
|
||||
case OBJ_TYPE_TRANSLUCENT_ALPHA_ORDER_3:
|
||||
gl_rend_state.set_depth_mask(GL_TRUE);
|
||||
rend_data_ctx.state.set_depth_mask(GL_TRUE);
|
||||
break;
|
||||
}
|
||||
|
||||
uniform_value_reset();
|
||||
gl_rend_state.bind_vertex_array(0);
|
||||
shader::unbind();
|
||||
gl_rend_state.set_blend_func(GL_ONE, GL_ZERO);
|
||||
rend_data_ctx.reset_shader_flags();
|
||||
rend_data_ctx.state.bind_vertex_array(0);
|
||||
shader::unbind(rend_data_ctx.state);
|
||||
rend_data_ctx.state.set_blend_func(GL_ONE, GL_ZERO);
|
||||
for (int32_t i = 0; i < 5; i++)
|
||||
gl_rend_state.bind_sampler(i, 0);
|
||||
rend_data_ctx.state.bind_sampler(i, 0);
|
||||
}
|
||||
|
||||
void DispManager::draw(mdl::ObjTypeLocal type, int32_t depth_mask, bool reflect_texture_mask) {
|
||||
void DispManager::draw(render_data_context& rend_data_ctx, mdl::ObjTypeLocal type,
|
||||
const cam_data& cam, int32_t depth_mask, bool reflect_texture_mask) {
|
||||
if (type < 0 || type >= OBJ_TYPE_LOCAL_MAX || get_obj_count(type) < 1)
|
||||
return;
|
||||
|
||||
render_context* rctx = rctx_ptr;
|
||||
|
||||
int32_t alpha_test = 0;
|
||||
float_t min_alpha = 1.0f;
|
||||
float_t alpha_threshold = 0.0f;
|
||||
void(*func)(render_context * rctx, const ObjSubMeshArgs * args) = draw_sub_mesh_default;
|
||||
void(*func)(render_data_context & rend_data_ctx, const ObjSubMeshArgs * args,
|
||||
const cam_data & cam, const mat4 * mat) = draw_sub_mesh_default;
|
||||
|
||||
for (int32_t i = 0; i < 5; i++)
|
||||
gl_rend_state.active_bind_texture_2d(i, rctx->empty_texture_2d->glid);
|
||||
gl_rend_state.active_bind_texture_cube_map(5, rctx->empty_texture_cube_map->glid);
|
||||
gl_rend_state.active_texture(0);
|
||||
gl_rend_state.set_blend_func(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA);
|
||||
uniform_value_reset();
|
||||
gl_rend_state.get();
|
||||
rend_data_ctx.state.active_bind_texture_2d(i, rctx_ptr->empty_texture_2d->glid);
|
||||
rend_data_ctx.state.active_bind_texture_cube_map(5, rctx_ptr->empty_texture_cube_map->glid);
|
||||
rend_data_ctx.state.active_texture(0);
|
||||
rend_data_ctx.state.set_blend_func(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA);
|
||||
rend_data_ctx.reset_shader_flags();
|
||||
|
||||
switch (type) {
|
||||
case OBJ_TYPE_LOCAL_TRANSLUCENT:
|
||||
if (depth_mask)
|
||||
func = draw_sub_mesh_translucent;
|
||||
else
|
||||
gl_rend_state.set_depth_mask(GL_FALSE);
|
||||
rend_data_ctx.state.set_depth_mask(GL_FALSE);
|
||||
|
||||
alpha_test = 1;
|
||||
min_alpha = 0.0f;
|
||||
@@ -2380,18 +2377,18 @@ namespace mdl {
|
||||
alpha_threshold = 0.5f;
|
||||
break;
|
||||
}
|
||||
rctx->set_batch_alpha_threshold(alpha_threshold);
|
||||
rctx->set_batch_min_alpha(min_alpha);
|
||||
uniform_value[U_ALPHA_TEST] = alpha_test;
|
||||
rend_data_ctx.set_batch_alpha_threshold(alpha_threshold);
|
||||
rend_data_ctx.set_batch_min_alpha(min_alpha);
|
||||
rend_data_ctx.shader_flags.arr[U_ALPHA_TEST] = alpha_test;
|
||||
|
||||
for (ObjData*& i : obj_local[type]) {
|
||||
switch (i->kind) {
|
||||
case OBJ_KIND_NORMAL: {
|
||||
draw_sub_mesh(rctx, &i->args.sub_mesh, &i->mat, func);
|
||||
draw_sub_mesh(rend_data_ctx, &i->args.sub_mesh, &i->mat, func, cam);
|
||||
} break;
|
||||
case OBJ_KIND_TRANSLUCENT: {
|
||||
for (int32_t j = 0; j < i->args.translucent.count; j++)
|
||||
draw_sub_mesh(rctx, i->args.translucent.sub_mesh[j], &i->mat, func);
|
||||
draw_sub_mesh(rend_data_ctx, i->args.translucent.sub_mesh[j], &i->mat, func, cam);
|
||||
} break;
|
||||
}
|
||||
}
|
||||
@@ -2399,64 +2396,63 @@ namespace mdl {
|
||||
switch (type) {
|
||||
case OBJ_TYPE_LOCAL_TRANSLUCENT:
|
||||
if (!depth_mask)
|
||||
gl_rend_state.set_depth_mask(GL_TRUE);
|
||||
rend_data_ctx.state.set_depth_mask(GL_TRUE);
|
||||
break;
|
||||
}
|
||||
|
||||
uniform_value_reset();
|
||||
gl_rend_state.bind_vertex_array(0);
|
||||
shader::unbind();
|
||||
gl_rend_state.set_blend_func(GL_ONE, GL_ZERO);
|
||||
rend_data_ctx.reset_shader_flags();
|
||||
rend_data_ctx.state.bind_vertex_array(0);
|
||||
shader::unbind(rend_data_ctx.state);
|
||||
rend_data_ctx.state.set_blend_func(GL_ONE, GL_ZERO);
|
||||
for (int32_t i = 0; i < 5; i++)
|
||||
gl_rend_state.bind_sampler(i, 0);
|
||||
rend_data_ctx.state.bind_sampler(i, 0);
|
||||
}
|
||||
|
||||
void DispManager::draw(mdl::ObjTypeReflect type, int32_t depth_mask, bool reflect_texture_mask) {
|
||||
void DispManager::draw(render_data_context& rend_data_ctx, mdl::ObjTypeReflect type,
|
||||
const cam_data& cam, int32_t depth_mask, bool reflect_texture_mask) {
|
||||
if (type < 0 || type >= OBJ_TYPE_REFLECT_MAX || get_obj_count(type) < 1)
|
||||
return;
|
||||
|
||||
render_context* rctx = rctx_ptr;
|
||||
|
||||
int32_t alpha_test = 0;
|
||||
float_t min_alpha = 1.0f;
|
||||
float_t alpha_threshold = 0.0f;
|
||||
bool reflect = uniform_value[U_REFLECT] == 1;
|
||||
void(*func)(render_context * rctx, const ObjSubMeshArgs * args) = draw_sub_mesh_default;
|
||||
bool reflect = rend_data_ctx.shader_flags.arr[U_REFLECT] == 1;
|
||||
void(*func)(render_data_context & rend_data_ctx, const ObjSubMeshArgs * args,
|
||||
const cam_data & cam, const mat4 * mat) = draw_sub_mesh_default;
|
||||
|
||||
for (int32_t i = 0; i < 5; i++)
|
||||
gl_rend_state.active_bind_texture_2d(i, rctx->empty_texture_2d->glid);
|
||||
gl_rend_state.active_bind_texture_cube_map(5, rctx->empty_texture_cube_map->glid);
|
||||
gl_rend_state.active_texture(0);
|
||||
gl_rend_state.set_blend_func(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA);
|
||||
uniform_value_reset();
|
||||
gl_rend_state.get();
|
||||
rend_data_ctx.state.active_bind_texture_2d(i, rctx_ptr->empty_texture_2d->glid);
|
||||
rend_data_ctx.state.active_bind_texture_cube_map(5, rctx_ptr->empty_texture_cube_map->glid);
|
||||
rend_data_ctx.state.active_texture(0);
|
||||
rend_data_ctx.state.set_blend_func(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA);
|
||||
rend_data_ctx.reset_shader_flags();
|
||||
|
||||
switch (type) {
|
||||
case OBJ_TYPE_REFLECT_TRANSLUCENT_SORT_BY_RADIUS:
|
||||
if (depth_mask)
|
||||
func = draw_sub_mesh_translucent;
|
||||
else
|
||||
gl_rend_state.set_depth_mask(GL_FALSE);
|
||||
rend_data_ctx.state.set_depth_mask(GL_FALSE);
|
||||
|
||||
alpha_test = 1;
|
||||
min_alpha = 0.0f;
|
||||
alpha_threshold = 0.0f;
|
||||
|
||||
gl_rend_state.set_cull_face_mode(GL_FRONT);
|
||||
rend_data_ctx.state.set_cull_face_mode(GL_FRONT);
|
||||
break;
|
||||
}
|
||||
rctx->set_batch_alpha_threshold(alpha_threshold);
|
||||
rctx->set_batch_min_alpha(min_alpha);
|
||||
uniform_value[U_ALPHA_TEST] = alpha_test;
|
||||
rend_data_ctx.set_batch_alpha_threshold(alpha_threshold);
|
||||
rend_data_ctx.set_batch_min_alpha(min_alpha);
|
||||
rend_data_ctx.shader_flags.arr[U_ALPHA_TEST] = alpha_test;
|
||||
|
||||
for (ObjData*& i : obj_reflect[type]) {
|
||||
switch (i->kind) {
|
||||
case OBJ_KIND_NORMAL: {
|
||||
draw_sub_mesh(rctx, &i->args.sub_mesh, &i->mat, func);
|
||||
draw_sub_mesh(rend_data_ctx, &i->args.sub_mesh, &i->mat, func, cam);
|
||||
} break;
|
||||
case OBJ_KIND_TRANSLUCENT: {
|
||||
for (int32_t j = 0; j < i->args.translucent.count; j++)
|
||||
draw_sub_mesh(rctx, i->args.translucent.sub_mesh[j], &i->mat, func);
|
||||
draw_sub_mesh(rend_data_ctx, i->args.translucent.sub_mesh[j], &i->mat, func, cam);
|
||||
} break;
|
||||
}
|
||||
}
|
||||
@@ -2464,48 +2460,18 @@ namespace mdl {
|
||||
switch (type) {
|
||||
case OBJ_TYPE_REFLECT_TRANSLUCENT_SORT_BY_RADIUS:
|
||||
if (!depth_mask)
|
||||
gl_rend_state.set_cull_face_mode(GL_BACK);
|
||||
rend_data_ctx.state.set_cull_face_mode(GL_BACK);
|
||||
break;
|
||||
}
|
||||
|
||||
uniform_value_reset();
|
||||
gl_rend_state.bind_vertex_array(0);
|
||||
shader::unbind();
|
||||
gl_rend_state.set_blend_func(GL_ONE, GL_ZERO);
|
||||
rend_data_ctx.reset_shader_flags();
|
||||
rend_data_ctx.state.bind_vertex_array(0);
|
||||
shader::unbind(rend_data_ctx.state);
|
||||
rend_data_ctx.state.set_blend_func(GL_ONE, GL_ZERO);
|
||||
for (int32_t i = 0; i < 5; i++)
|
||||
gl_rend_state.bind_sampler(i, 0);
|
||||
rend_data_ctx.state.bind_sampler(i, 0);
|
||||
}
|
||||
|
||||
/*void DispManager::draw_show_vector(ObjType type, int32_t show_vector) {
|
||||
if (get_obj_count(type) < 1)
|
||||
return;
|
||||
|
||||
render_context* rctx = rctx_ptr;
|
||||
|
||||
for (int32_t i = 0; i < 5; i++)
|
||||
gl_rend_state.active_bind_texture_2d(i, rctx->empty_texture_2d);
|
||||
gl_rend_state.active_bind_texture_cube_map(5, rctx->empty_texture_cube_map);
|
||||
gl_rend_state.active_texture(0);
|
||||
gl_rend_state.set_blend_func(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA);
|
||||
uniform_value_reset();
|
||||
gl_rend_state.get();
|
||||
|
||||
for (ObjData*& i : obj[type]) {
|
||||
switch (i->type) {
|
||||
case OBJ_KIND_NORMAL: {
|
||||
draw_sub_mesh_show_vector(rctx, &i->args.sub_mesh,
|
||||
&i->mat, show_vector);
|
||||
} break;
|
||||
case OBJ_KIND_TRANSLUCENT: {
|
||||
for (int32_t j = 0; j < i->args.translucent.count; j++)
|
||||
draw_sub_mesh_show_vector(rctx, i->args.translucent.sub_mesh[j],
|
||||
&i->mat, show_vector);
|
||||
} break;
|
||||
}
|
||||
}
|
||||
gl_rend_state.set_blend_func(GL_ONE, GL_ZERO);
|
||||
}*/
|
||||
|
||||
void DispManager::entry_list(ObjType type, ObjData* data) {
|
||||
obj[type].push_back(data);
|
||||
}
|
||||
@@ -3484,7 +3450,8 @@ namespace mdl {
|
||||
return wet_param;
|
||||
}
|
||||
|
||||
void DispManager::obj_sort(const mat4* view, ObjType type, int32_t compare_func, bool a3) {
|
||||
void DispManager::obj_sort(render_data_context& rend_data_ctx,
|
||||
ObjType type, int32_t compare_func, const cam_data& cam, bool a3) {
|
||||
std::list<ObjData*>& list = obj[type];
|
||||
if (list.size() < 1)
|
||||
return;
|
||||
@@ -3492,7 +3459,7 @@ namespace mdl {
|
||||
if (a3 && type == mdl::OBJ_TYPE_TRANSLUCENT)
|
||||
sub_140436760();
|
||||
|
||||
calc_obj_radius(view, type);
|
||||
calc_obj_radius(cam, type);
|
||||
|
||||
switch (compare_func) {
|
||||
case 0:
|
||||
@@ -3513,12 +3480,13 @@ namespace mdl {
|
||||
}
|
||||
}
|
||||
|
||||
void DispManager::obj_sort(const mat4* view, ObjTypeLocal type, int32_t compare_func) {
|
||||
void DispManager::obj_sort(render_data_context& rend_data_ctx,
|
||||
ObjTypeLocal type, int32_t compare_func, const cam_data& cam) {
|
||||
std::list<ObjData*>& list = obj[type];
|
||||
if (list.size() < 1)
|
||||
return;
|
||||
|
||||
calc_obj_radius(view, type);
|
||||
calc_obj_radius(cam, type);
|
||||
|
||||
switch (compare_func) {
|
||||
case 0:
|
||||
@@ -3539,12 +3507,13 @@ namespace mdl {
|
||||
}
|
||||
}
|
||||
|
||||
void DispManager::obj_sort(const mat4* view, ObjTypeReflect type, int32_t compare_func) {
|
||||
void DispManager::obj_sort(render_data_context& rend_data_ctx,
|
||||
ObjTypeReflect type, int32_t compare_func, const cam_data& cam) {
|
||||
std::list<ObjData*>& list = obj[type];
|
||||
if (list.size() < 1)
|
||||
return;
|
||||
|
||||
calc_obj_radius(view, type);
|
||||
calc_obj_radius(cam, type);
|
||||
|
||||
switch (compare_func) {
|
||||
case 0:
|
||||
|
||||
@@ -63,6 +63,9 @@ struct texture_data_struct {
|
||||
texture_data_struct();
|
||||
};
|
||||
|
||||
struct cam_data;
|
||||
struct render_data_context;
|
||||
|
||||
namespace mdl {
|
||||
struct ObjSubMeshArgs;
|
||||
|
||||
@@ -317,7 +320,7 @@ namespace mdl {
|
||||
~EtcObj();
|
||||
};
|
||||
|
||||
typedef void(*UserArgsFunc)(void* data, mat4* mat);
|
||||
typedef void(*UserArgsFunc)(render_data_context& rend_data_ctx, void* data, const cam_data& cam, mat4* mat);
|
||||
|
||||
struct UserArgs {
|
||||
UserArgsFunc func;
|
||||
@@ -458,16 +461,18 @@ namespace mdl {
|
||||
ObjData* alloc_obj_data(ObjKind kind);
|
||||
mat4* alloc_mat4_array(int32_t count);
|
||||
void buffer_reset();
|
||||
void calc_obj_radius(const mat4* view, ObjType type);
|
||||
void calc_obj_radius(const mat4* view, ObjTypeLocal type);
|
||||
void calc_obj_radius(const mat4* view, ObjTypeReflect type);
|
||||
void calc_obj_radius(const cam_data& cam, ObjType type);
|
||||
void calc_obj_radius(const cam_data& cam, ObjTypeLocal type);
|
||||
void calc_obj_radius(const cam_data& cam, ObjTypeReflect type);
|
||||
void check_index_buffer(GLuint buffer);
|
||||
void check_vertex_arrays();
|
||||
void check_vertex_buffer(GLuint buffer);
|
||||
void draw(ObjType type, int32_t depth_mask = 0, bool reflect_texture_mask = true, int32_t alpha = -1);
|
||||
void draw(ObjTypeLocal type, int32_t depth_mask = 0, bool reflect_texture_mask = true);
|
||||
void draw(ObjTypeReflect type, int32_t depth_mask = 0, bool reflect_texture_mask = true);
|
||||
/*void draw_show_vector(mdl::ObjType type, int32_t show_vector);*/
|
||||
void draw(render_data_context& rend_data_ctx, ObjType type, const cam_data& cam,
|
||||
int32_t depth_mask = 0, bool reflect_texture_mask = true, int32_t alpha = -1);
|
||||
void draw(render_data_context& rend_data_ctx, ObjTypeLocal type, const cam_data& cam,
|
||||
int32_t depth_mask = 0, bool reflect_texture_mask = true);
|
||||
void draw(render_data_context& rend_data_ctx, ObjTypeReflect type, const cam_data& cam,
|
||||
int32_t depth_mask = 0, bool reflect_texture_mask = true);
|
||||
void entry_list(ObjType type, ObjData* data);
|
||||
void entry_list(ObjTypeLocal type, ObjData* data);
|
||||
void entry_list(ObjTypeReflect type, ObjData* data);
|
||||
@@ -521,9 +526,12 @@ namespace mdl {
|
||||
void get_texture_specular_offset(vec4& value);
|
||||
void get_texture_transform(int32_t& count, texture_transform_struct*& value);
|
||||
float_t get_wet_param();
|
||||
void obj_sort(const mat4* view, ObjType type, int32_t compare_func, bool a3 = false);
|
||||
void obj_sort(const mat4* view, ObjTypeLocal type, int32_t compare_func);
|
||||
void obj_sort(const mat4* view, ObjTypeReflect type, int32_t compare_func);
|
||||
void obj_sort(render_data_context& rend_data_ctx,
|
||||
ObjType type, int32_t compare_func, const cam_data& cam, bool a3 = false);
|
||||
void obj_sort(render_data_context& rend_data_ctx,
|
||||
ObjTypeLocal type, int32_t compare_func, const cam_data& cam);
|
||||
void obj_sort(render_data_context& rend_data_ctx,
|
||||
ObjTypeReflect type, int32_t compare_func, const cam_data& cam);
|
||||
void refresh();
|
||||
void set_chara_color(bool value = false);
|
||||
void set_culling_func(bool(*func)(const obj_bounding_sphere*, const mat4*) = 0);
|
||||
|
||||
+297
-313
File diff suppressed because it is too large
Load Diff
+23
-16
@@ -12,22 +12,29 @@
|
||||
#include "../render_context.hpp"
|
||||
|
||||
namespace mdl {
|
||||
extern void draw(render_context* rctx, obj_primitive_type primitive_type, uint32_t count,
|
||||
extern void draw(
|
||||
render_data_context& rend_data_ctx, obj_primitive_type primitive_type, uint32_t count,
|
||||
uint16_t start, uint16_t end, obj_index_format index_format, size_t indices);
|
||||
extern void draw_etc_obj(render_context* rctx, const mdl::EtcObj* etc, const mat4* mat);
|
||||
extern void draw_sub_mesh(render_context* rctx, const ObjSubMeshArgs* args, const mat4* mat,
|
||||
void(*func)(render_context* rctx, const ObjSubMeshArgs* args));
|
||||
/*extern void draw_sub_mesh_show_vector(render_context* rctx,
|
||||
const ObjSubMeshArgs* args, const mat4* model, int32_t show_vector);*/
|
||||
extern void draw_sub_mesh_default(render_context* rctx, const ObjSubMeshArgs* args);
|
||||
extern void draw_sub_mesh_default_instanced(render_context* rctx,
|
||||
const ObjSubMeshArgs* args, const mat4* mat);
|
||||
extern void draw_sub_mesh_sss(render_context* rctx, const ObjSubMeshArgs* args);
|
||||
extern void draw_sub_mesh_reflect(render_context* rctx, const ObjSubMeshArgs* args);
|
||||
extern void draw_sub_mesh_reflect_reflect_map(render_context* rctx, const ObjSubMeshArgs* args);
|
||||
extern void draw_sub_mesh_shadow(render_context* rctx, const ObjSubMeshArgs* args);
|
||||
extern void draw_sub_mesh_translucent(render_context* rctx, const ObjSubMeshArgs* args);
|
||||
extern void draw_etc_obj(
|
||||
render_data_context& rend_data_ctx, const mdl::EtcObj* etc, const mat4* mat);
|
||||
extern void draw_sub_mesh(render_data_context& rend_data_ctx, const ObjSubMeshArgs* args,
|
||||
const mat4* mat, void(*func)(render_data_context& rend_data_ctx,
|
||||
const ObjSubMeshArgs* args, const cam_data& cam, const mat4* mat), const cam_data& cam);
|
||||
extern void draw_sub_mesh_default(render_data_context& rend_data_ctx,
|
||||
const ObjSubMeshArgs* args, const cam_data& cam, const mat4* mat);
|
||||
extern void draw_sub_mesh_default_instanced(render_data_context& rend_data_ctx,
|
||||
const ObjSubMeshArgs* args, const cam_data& cam, const mat4* mat);
|
||||
extern void draw_sub_mesh_sss(render_data_context& rend_data_ctx,
|
||||
const ObjSubMeshArgs* args, const cam_data& cam, const mat4* mat);
|
||||
extern void draw_sub_mesh_reflect(render_data_context& rend_data_ctx,
|
||||
const ObjSubMeshArgs* args, const cam_data& cam, const mat4* mat);
|
||||
extern void draw_sub_mesh_reflect_reflect_map(render_data_context& rend_data_ctx,
|
||||
const ObjSubMeshArgs* args, const cam_data& cam, const mat4* mat);
|
||||
extern void draw_sub_mesh_shadow(render_data_context& rend_data_ctx,
|
||||
const ObjSubMeshArgs* args, const cam_data& cam, const mat4* mat);
|
||||
extern void draw_sub_mesh_translucent(render_data_context& rend_data_ctx,
|
||||
const ObjSubMeshArgs* args, const cam_data& cam, const mat4* mat);
|
||||
};
|
||||
|
||||
extern void model_mat_face_camera_position(const mat4* view, const mat4* src, mat4* dst);
|
||||
extern void model_mat_face_camera_view(const mat4* view, const mat4* src, mat4* dst);
|
||||
extern void model_mat_face_camera_position(const cam_data& cam, const mat4* src, mat4* dst);
|
||||
extern void model_mat_face_camera_view(const cam_data& cam, const mat4* src, mat4* dst);
|
||||
|
||||
+5
-5
@@ -12,7 +12,7 @@
|
||||
#include "../KKdLib/msgpack.hpp"
|
||||
#include "../KKdLib/str_utils.hpp"
|
||||
#include "data.hpp"
|
||||
#include "gl_rend_state.hpp"
|
||||
#include "gl_state.hpp"
|
||||
#include "render_context.hpp"
|
||||
#include "shader_ft.hpp"
|
||||
#include <list>
|
||||
@@ -2407,12 +2407,12 @@ inline void objset_info_storage_free() {
|
||||
static GLuint create_index_buffer(size_t size, const void* data) {
|
||||
GLuint buffer = 0;
|
||||
glGenBuffers(1, &buffer);
|
||||
glBindBuffer(GL_ELEMENT_ARRAY_BUFFER, buffer);
|
||||
gl_state.bind_element_array_buffer(buffer);
|
||||
if (GLAD_GL_VERSION_4_4)
|
||||
glBufferStorage(GL_ELEMENT_ARRAY_BUFFER, (GLsizeiptr)size, data, 0);
|
||||
else
|
||||
glBufferData(GL_ELEMENT_ARRAY_BUFFER, (GLsizeiptr)size, data, GL_STATIC_DRAW);
|
||||
glBindBuffer(GL_ELEMENT_ARRAY_BUFFER, 0);
|
||||
gl_state.bind_element_array_buffer(0);
|
||||
|
||||
if (glGetError()) {
|
||||
glDeleteBuffers(1, &buffer);
|
||||
@@ -2424,14 +2424,14 @@ static GLuint create_index_buffer(size_t size, const void* data) {
|
||||
static GLuint create_vertex_buffer(size_t size, const void* data, bool dynamic) {
|
||||
GLuint buffer = 0;
|
||||
glGenBuffers(1, &buffer);
|
||||
glBindBuffer(GL_ARRAY_BUFFER, buffer);
|
||||
gl_state.bind_array_buffer(buffer);
|
||||
if (GLAD_GL_VERSION_4_4)
|
||||
glBufferStorage(GL_ARRAY_BUFFER, (GLsizeiptr)size, data,
|
||||
dynamic ? GL_DYNAMIC_STORAGE_BIT | GL_MAP_WRITE_BIT : 0);
|
||||
else
|
||||
glBufferData(GL_ARRAY_BUFFER, (GLsizeiptr)size, data,
|
||||
dynamic ? GL_DYNAMIC_DRAW : GL_STATIC_DRAW);
|
||||
glBindBuffer(GL_ARRAY_BUFFER, 0);
|
||||
gl_state.bind_array_buffer(0);
|
||||
|
||||
if (glGetError()) {
|
||||
glDeleteBuffers(1, &buffer);
|
||||
|
||||
+366
-369
File diff suppressed because it is too large
Load Diff
+24
-18
@@ -13,6 +13,10 @@
|
||||
#include "renderer/transparency.hpp"
|
||||
#include "camera.hpp"
|
||||
|
||||
struct cam_data;
|
||||
struct p_gl_rend_state;
|
||||
struct render_data_context;
|
||||
|
||||
namespace rndr {
|
||||
struct Render {
|
||||
enum MagFilterType {
|
||||
@@ -179,14 +183,14 @@ namespace rndr {
|
||||
Render();
|
||||
~Render();
|
||||
|
||||
void apply_post_process(camera* cam, texture* light_proj_tex, int32_t npr_param);
|
||||
void bind_render_texture(bool aet_back = false);
|
||||
void calc_exposure_chara_data(camera* cam);
|
||||
void calc_projection_matrix(mat4* mat, float_t fov, float_t aspect, float_t z_near, float_t z_far,
|
||||
float_t left_offset, float_t right_offset, float_t bottom_offset, float_t top_offset);
|
||||
void draw_quad(int32_t width, int32_t height, float_t s0, float_t t0, float_t s1, float_t t1,
|
||||
void apply_post_process(render_data_context& rend_data_ctx,
|
||||
const cam_data& cam, texture* light_proj_tex, int32_t npr_param);
|
||||
void bind_render_texture(p_gl_rend_state& p_gl_rend_st, bool aet_back = false);
|
||||
void calc_exposure_chara_data(render_data_context& rend_data_ctx, const cam_data& cam);
|
||||
void draw_quad(render_data_context& rend_data_ctx,
|
||||
int32_t width, int32_t height, float_t s0, float_t t0, float_t s1, float_t t1,
|
||||
float_t scale, float_t param_x, float_t param_y, float_t param_z, float_t param_w);
|
||||
void draw_lens_flare(camera* cam);
|
||||
void draw_lens_flare(render_data_context& rend_data_ctx, const cam_data& cam);
|
||||
bool frame_texture_cont_capture_set(bool value);
|
||||
void frame_texture_free();
|
||||
int32_t frame_texture_load(int32_t slot, FrameTextureType type, texture* tex);
|
||||
@@ -217,6 +221,7 @@ namespace rndr {
|
||||
int32_t get_scene_fade_blend_func();
|
||||
vec3 get_scene_fade_color();
|
||||
int32_t get_taa();
|
||||
vec2 get_taa_offset();
|
||||
tone_map_method get_tone_map();
|
||||
void get_tone_trans(vec3& start, vec3& end);
|
||||
void init_render_buffers(int32_t width, int32_t height,
|
||||
@@ -225,7 +230,7 @@ namespace rndr {
|
||||
int32_t movie_texture_set(texture* movie_texture);
|
||||
void movie_texture_free(texture* movie_texture);
|
||||
void post_proc();
|
||||
void pre_proc(camera* cam);
|
||||
void pre_proc(render_data_context& rend_data_ctx);
|
||||
int32_t render_texture_set(texture* render_texture, bool task_photo);
|
||||
void render_texture_free(texture* render_texture, bool task_photo);
|
||||
void reset_saturate_coeff(int32_t index, bool lock);
|
||||
@@ -256,22 +261,23 @@ namespace rndr {
|
||||
void set_taa(int32_t value);
|
||||
void set_tone_map(tone_map_method value);
|
||||
void set_tone_trans(const vec3& start, const vec3& end, int32_t index);
|
||||
void transparency_combine(float_t alpha);
|
||||
void transparency_copy();
|
||||
void transparency_combine(render_data_context& rend_data_ctx, float_t alpha);
|
||||
void transparency_copy(render_data_context& rend_data_ctx);
|
||||
void update_res(bool set, int32_t base_downsample);
|
||||
|
||||
private:
|
||||
void apply_mlaa(int32_t destination, int32_t source, int32_t ss_alpha_mask);
|
||||
void apply_tone_map(texture* light_proj_tex, int32_t npr_param);
|
||||
void calc_exposure(camera* cam);
|
||||
void calc_gaussian_blur(float_t start, float_t step,
|
||||
void apply_mlaa(render_data_context& rend_data_ctx, int32_t destination, int32_t source, int32_t ss_alpha_mask);
|
||||
void apply_tone_map(render_data_context& rend_data_ctx, texture* light_proj_tex, int32_t npr_param);
|
||||
void calc_exposure(render_data_context& rend_data_ctx, const cam_data& cam);
|
||||
void calc_gaussian_blur(render_data_context& rend_data_ctx, float_t start, float_t step,
|
||||
int32_t kernel_size, float_t radius_scale, float_t intensity_scale);
|
||||
void calc_taa_blend();
|
||||
void copy_to_frame_texture(GLuint pre_pp_tex, int32_t wight, int32_t height, GLuint post_pp_tex);
|
||||
void draw_lens_ghost();
|
||||
void downsample();
|
||||
void copy_to_frame_texture(render_data_context& rend_data_ctx,
|
||||
GLuint pre_pp_tex, int32_t wight, int32_t height, GLuint post_pp_tex);
|
||||
void draw_lens_ghost(render_data_context& rend_data_ctx);
|
||||
void downsample(render_data_context& rend_data_ctx);
|
||||
void generate_mlaa_area_texture();
|
||||
void get_blur();
|
||||
void get_blur(render_data_context& rend_data_ctx);
|
||||
void update_tone_map_lut();
|
||||
};
|
||||
}
|
||||
|
||||
+495
-412
File diff suppressed because it is too large
Load Diff
+80
-57
@@ -56,12 +56,21 @@ struct global_material_struct {
|
||||
};
|
||||
|
||||
struct draw_state {
|
||||
draw_state_stats stats;
|
||||
struct render_data {
|
||||
int32_t shader_index;
|
||||
bool self_shadow;
|
||||
bool shadow;
|
||||
bool blend;
|
||||
bool cull_front;
|
||||
int32_t field_8;
|
||||
draw_state_stats stats;
|
||||
|
||||
render_data();
|
||||
};
|
||||
|
||||
draw_state_stats stats_prev;
|
||||
bool wireframe;
|
||||
bool wireframe_overlay;
|
||||
bool shadow;
|
||||
bool self_shadow;
|
||||
bool shader_debug_flag;
|
||||
bool use_global_material;
|
||||
bool fog_height;
|
||||
@@ -72,10 +81,12 @@ struct draw_state {
|
||||
global_material_struct global_material;
|
||||
int32_t field_68;
|
||||
float_t fresnel;
|
||||
render_data rend_data[GL_REND_STATE_COUNT];
|
||||
|
||||
draw_state();
|
||||
|
||||
bool get_use_global_material();
|
||||
void stats_update();
|
||||
void set_fog_height(bool value);
|
||||
void set_use_global_material(bool value);
|
||||
};
|
||||
@@ -92,7 +103,7 @@ struct sss_data {
|
||||
|
||||
void free();
|
||||
void init();
|
||||
void set_texture(int32_t);
|
||||
void set_texture(struct p_gl_rend_state& p_gl_rend_st, int32_t texture_index);
|
||||
};
|
||||
|
||||
struct light_proj {
|
||||
@@ -105,9 +116,9 @@ struct light_proj {
|
||||
~light_proj();
|
||||
|
||||
void resize(int32_t width, int32_t height);
|
||||
bool set();
|
||||
bool set(struct render_data_context& rend_data_ctx, cam_data& cam);
|
||||
|
||||
static bool set_mat(bool set_mat);
|
||||
static bool set_mat(struct render_data_context& rend_data_ctx, cam_data& cam, bool set_mat);
|
||||
};
|
||||
|
||||
struct camera_blur_shader_data {
|
||||
@@ -206,7 +217,7 @@ struct transparency_batch_shader_data {
|
||||
vec4 g_opacity;
|
||||
};
|
||||
|
||||
struct render_context;
|
||||
struct render_data_context;
|
||||
|
||||
struct render_data {
|
||||
struct obj_shader_data {
|
||||
@@ -396,7 +407,10 @@ struct render_data {
|
||||
};
|
||||
|
||||
render_data_flags flags;
|
||||
cam_data cam;
|
||||
mat4 inv_view_mat;
|
||||
int32_t shader_index;
|
||||
uniform_value shader_flags;
|
||||
obj_shader_data buffer_shader_data;
|
||||
obj_scene_data buffer_scene_data;
|
||||
obj_batch_data buffer_batch_data;
|
||||
@@ -409,11 +423,12 @@ struct render_data {
|
||||
|
||||
void init();
|
||||
void free();
|
||||
void set(render_context* rctx);
|
||||
void set_skinning_data(struct p_gl_rend_state& p_gl_rend_st, const mat4* mats, int32_t count);
|
||||
void set_state(struct p_gl_rend_state& p_gl_rend_st);
|
||||
void set_shader(uint32_t index);
|
||||
};
|
||||
|
||||
struct render_context {
|
||||
struct render_data_context {
|
||||
struct fog_params {
|
||||
vec4 depth_color;
|
||||
vec4 height_params;
|
||||
@@ -424,6 +439,61 @@ struct render_context {
|
||||
float_t end;
|
||||
};
|
||||
|
||||
p_gl_rend_state state;
|
||||
int32_t index;
|
||||
render_data& data;
|
||||
uniform_value& shader_flags;
|
||||
|
||||
render_data_context(int32_t index);
|
||||
|
||||
void get_scene_fog_params(render_data_context::fog_params& value);
|
||||
void get_scene_light(vec4* light_env_stage_diffuse,
|
||||
vec4* light_env_stage_specular, vec4* light_chara_dir, vec4* light_chara_luce,
|
||||
vec4* light_env_chara_diffuse, vec4* light_env_chara_specular);
|
||||
void reset_shader_flags();
|
||||
void set_batch_alpha_threshold(const float_t value);
|
||||
void set_batch_blend_color_offset_color(const vec4& blend_color, const vec4& offset_color);
|
||||
void set_batch_material_color(const vec4& diffuse, const vec4& ambient,
|
||||
const vec4& emission, const float_t material_shininess, const vec4& specular,
|
||||
const vec4& fresnel_coefficients, const vec4& texture_color_coefficients,
|
||||
const vec4& texture_color_offset, const vec4& texture_specular_coefficients,
|
||||
const vec4& texture_specular_offset, const float_t shininess);
|
||||
void set_batch_material_color_emission(const vec4& emission);
|
||||
void set_batch_material_parameter(const vec4* specular, const vec4& bump_depth,
|
||||
const vec4& intensity, const float_t reflect_uv_scale, const float_t refract_uv_scale);
|
||||
void set_batch_min_alpha(const float_t value);
|
||||
void set_batch_morph_weight(const float_t value);
|
||||
void set_batch_scene_camera(const cam_data& cam);
|
||||
void set_batch_sss_param(const vec4& sss_param);
|
||||
void set_batch_texcoord_transforms(const mat4 mats[2]);
|
||||
void set_batch_worlds(const mat4& mat);
|
||||
void set_glitter_render_data_state();
|
||||
void set_render_data_state();
|
||||
void set_scene_fog_params(const render_data_context::fog_params& value);
|
||||
void set_scene_framebuffer_size(const int32_t width, const int32_t height,
|
||||
const int32_t render_width, const int32_t render_height);
|
||||
void set_scene_light(const mat4& irradiance_r_transforms, const mat4& irradiance_g_transforms,
|
||||
const mat4& irradiance_b_transforms, const vec4& light_env_stage_diffuse,
|
||||
const vec4& light_env_stage_specular, const vec4& light_env_chara_diffuse,
|
||||
const vec4& light_env_chara_ambient, const vec4& light_env_chara_specular,
|
||||
const vec4& light_env_reflect_diffuse, const vec4& light_env_reflect_ambient,
|
||||
const vec4& light_env_proj_diffuse, const vec4& light_env_proj_specular,
|
||||
const vec4& light_env_proj_position, const vec4& light_stage_dir, const vec4& light_stage_diff,
|
||||
const vec4& light_stage_spec, const vec4& light_chara_dir, const vec4& light_chara_spec,
|
||||
const vec4& light_chara_luce, const vec4& light_chara_back, const vec4& light_face_diff,
|
||||
const vec4& chara_color0, const vec4& chara_color1, const vec4& chara_f_dir, const vec4& chara_f_ambient,
|
||||
const vec4& chara_f_diffuse, const vec4& chara_tc_param, const mat4& normal_tangent_transforms,
|
||||
const vec4& light_reflect_dir, const vec4& clip_plane, const vec4& npr_cloth_spec_color);
|
||||
void set_scene_light_projection(const mat4& light_projection);
|
||||
void set_scene_shadow_params(const float_t esm_param,
|
||||
const mat4 mats[2], const vec4& shadow_ambient, const vec4& shadow_ambient1);
|
||||
void set_self_shadow(bool value);
|
||||
void set_shader(uint32_t index);
|
||||
void set_shadow(bool value);
|
||||
void set_skinning_data(p_gl_rend_state& p_gl_rend_st, const mat4* mats, int32_t count);
|
||||
};
|
||||
|
||||
struct render_context {
|
||||
struct shared_storage_buffer {
|
||||
void* data;
|
||||
size_t offset;
|
||||
@@ -469,11 +539,6 @@ struct render_context {
|
||||
bool chara_reflect;
|
||||
bool chara_refract;
|
||||
|
||||
mat4 view_mat;
|
||||
mat4 proj_mat;
|
||||
mat4 vp_mat;
|
||||
vec4 g_near_far;
|
||||
|
||||
mat4 matrix_buffer[MATRIX_BUFFER_COUNT];
|
||||
|
||||
GLuint box_vao;
|
||||
@@ -507,7 +572,7 @@ struct render_context {
|
||||
GL::UniformBuffer tone_map_ubo;
|
||||
GL::UniformBuffer transparency_batch_ubo;
|
||||
|
||||
render_data data;
|
||||
render_data data[GL_REND_STATE_COUNT];
|
||||
|
||||
texture* empty_texture_2d;
|
||||
texture* empty_texture_cube_map;
|
||||
@@ -544,50 +609,8 @@ struct render_context {
|
||||
|
||||
void add_shared_storage_uniform_buffer_data(size_t index,
|
||||
const void* data, size_t size, size_t max_size, bool storage = false);
|
||||
void get_scene_fog_params(render_context::fog_params& value);
|
||||
void get_scene_light(vec4* light_env_stage_diffuse,
|
||||
vec4* light_env_stage_specular, vec4* light_chara_dir, vec4* light_chara_luce,
|
||||
vec4* light_env_chara_diffuse, vec4* light_env_chara_specular);
|
||||
bool get_shared_storage_uniform_buffer_data(size_t index,
|
||||
GLuint& buffer, size_t& offset, size_t& size, bool storage = false);
|
||||
void post_proc();
|
||||
void pre_proc();
|
||||
void set_batch_alpha_threshold(const float_t value);
|
||||
void set_batch_blend_color_offset_color(const vec4& blend_color, const vec4& offset_color);
|
||||
void set_batch_joint(const mat4& mat);
|
||||
void set_batch_material_color(const vec4& diffuse, const vec4& ambient,
|
||||
const vec4& emission, const float_t material_shininess, const vec4& specular,
|
||||
const vec4& fresnel_coefficients, const vec4& texture_color_coefficients,
|
||||
const vec4& texture_color_offset, const vec4& texture_specular_coefficients,
|
||||
const vec4& texture_specular_offset, const float_t shininess);
|
||||
void set_batch_material_color_emission(const vec4& emission);
|
||||
void set_batch_material_parameter(const vec4* specular, const vec4& bump_depth,
|
||||
const vec4& intensity, const float_t reflect_uv_scale, const float_t refract_uv_scale);
|
||||
void set_batch_min_alpha(const float_t value);
|
||||
void set_batch_morph_weight(const float_t value);
|
||||
void set_batch_sss_param(const vec4& sss_param);
|
||||
void set_batch_texcoord_transforms(const mat4 mats[2]);
|
||||
void set_batch_worlds(const mat4& mat);
|
||||
void set_glitter_render_data();
|
||||
void set_render_data();
|
||||
void set_scene_fog_params(const render_context::fog_params& value);
|
||||
void set_scene_framebuffer_size(const int32_t width, const int32_t height,
|
||||
const int32_t render_width, const int32_t render_height);
|
||||
void set_scene_light(const mat4& irradiance_r_transforms, const mat4& irradiance_g_transforms,
|
||||
const mat4& irradiance_b_transforms, const vec4& light_env_stage_diffuse,
|
||||
const vec4& light_env_stage_specular, const vec4& light_env_chara_diffuse,
|
||||
const vec4& light_env_chara_ambient, const vec4& light_env_chara_specular,
|
||||
const vec4& light_env_reflect_diffuse, const vec4& light_env_reflect_ambient,
|
||||
const vec4& light_env_proj_diffuse, const vec4& light_env_proj_specular,
|
||||
const vec4& light_env_proj_position, const vec4& light_stage_dir, const vec4& light_stage_diff,
|
||||
const vec4& light_stage_spec, const vec4& light_chara_dir, const vec4& light_chara_spec,
|
||||
const vec4& light_chara_luce, const vec4& light_chara_back, const vec4& light_face_diff,
|
||||
const vec4& chara_color0, const vec4& chara_color1, const vec4& chara_f_dir, const vec4& chara_f_ambient,
|
||||
const vec4& chara_f_diffuse, const vec4& chara_tc_param, const mat4& normal_tangent_transforms,
|
||||
const vec4& light_reflect_dir, const vec4& clip_plane, const vec4& npr_cloth_spec_color);
|
||||
void set_scene_light_projection(const mat4& light_projection);
|
||||
void set_scene_projection_view(const mat4& view, const mat4& proj, const vec3& view_position);
|
||||
void set_scene_shadow_params(const float_t esm_param,
|
||||
const mat4 mats[2], const vec4& shadow_ambient, const vec4& shadow_ambient1);
|
||||
void set_shader(uint32_t index);
|
||||
};
|
||||
|
||||
+814
-824
File diff suppressed because it is too large
Load Diff
+22
-19
@@ -19,7 +19,8 @@ enum reflect_refract_resolution_mode {
|
||||
REFLECT_REFRACT_RESOLUTION_MAX,
|
||||
};
|
||||
|
||||
typedef void(*draw_pre_process_func)(void*);
|
||||
typedef void(*draw_pre_process_func)(struct render_data_context& rend_data_ctx,
|
||||
void* data, const struct cam_data& cam);
|
||||
|
||||
struct draw_pre_process {
|
||||
int32_t type;
|
||||
@@ -27,6 +28,8 @@ struct draw_pre_process {
|
||||
void* data;
|
||||
};
|
||||
|
||||
struct render_data_context;
|
||||
|
||||
namespace rndr {
|
||||
enum RenderPassID {
|
||||
RND_PASSID_SHADOW = 0,
|
||||
@@ -88,6 +91,7 @@ namespace rndr {
|
||||
bool field_31F;
|
||||
bool light_stage_ambient;
|
||||
bool npr;
|
||||
cam_data cam;
|
||||
|
||||
RenderManager();
|
||||
~RenderManager();
|
||||
@@ -115,33 +119,32 @@ namespace rndr {
|
||||
|
||||
void render_all();
|
||||
void rndpass_post_proc();
|
||||
void rndpass_pre_proc(struct camera* cam);
|
||||
void rndpass_pre_proc();
|
||||
|
||||
void render_single_pass(rndr::RenderPassID id);
|
||||
void render_single_pass(render_data_context& rend_data_ctx, rndr::RenderPassID id);
|
||||
|
||||
void render_pass_begin();
|
||||
void render_pass_end(rndr::RenderPassID id);
|
||||
|
||||
void pass_shadow();
|
||||
void pass_ss_sss();
|
||||
void pass_reflect();
|
||||
void pass_refract();
|
||||
void pass_pre_process();
|
||||
void pass_clear();
|
||||
void pass_pre_sprite();
|
||||
void pass_3d();
|
||||
void pass_show_vector();
|
||||
void pass_post_process();
|
||||
void pass_sprite();
|
||||
void pass_shadow(render_data_context& rend_data_ctx);
|
||||
void pass_ss_sss(render_data_context& rend_data_ctx);
|
||||
void pass_reflect(render_data_context& rend_data_ctx);
|
||||
void pass_refract(render_data_context& rend_data_ctx);
|
||||
void pass_pre_process(render_data_context& rend_data_ctx);
|
||||
void pass_clear(render_data_context& rend_data_ctx);
|
||||
void pass_pre_sprite(render_data_context& rend_data_ctx);
|
||||
void pass_3d(render_data_context& rend_data_ctx);
|
||||
void pass_show_vector(render_data_context& rend_data_ctx);
|
||||
void pass_post_process(render_data_context& rend_data_ctx);
|
||||
void pass_sprite(render_data_context& rend_data_ctx);
|
||||
|
||||
void pass_3d_contour();
|
||||
void pass_sprite_surf();
|
||||
void pass_3d_contour(render_data_context& rend_data_ctx);
|
||||
void pass_sprite_surf(render_data_context& rend_data_ctx);
|
||||
};
|
||||
}
|
||||
|
||||
extern void image_filter_scale(RenderTexture* dst, texture* src, const vec4& scale = 1.0f);
|
||||
|
||||
extern void draw_pass_set_camera();
|
||||
extern void image_filter_scale(render_data_context& rend_data_ctx,
|
||||
RenderTexture* dst, texture* src, const vec4& scale = 1.0f);
|
||||
|
||||
extern void render_manager_init_data(int32_t ssaa, int32_t hd_res, int32_t ss_alpha_mask, bool npr);
|
||||
extern void render_manager_free_data();
|
||||
|
||||
+32
-15
@@ -4,11 +4,10 @@
|
||||
*/
|
||||
|
||||
#include "render_texture.hpp"
|
||||
#include "render_context.hpp"
|
||||
#include "gl_rend_state.hpp"
|
||||
#include "gl_state.hpp"
|
||||
#include "texture.hpp"
|
||||
|
||||
extern render_context* rctx_ptr;
|
||||
|
||||
static uint32_t render_texture_counter;
|
||||
|
||||
static int32_t render_texture_init_framebuffer(RenderTexture* rt, int32_t max_level);
|
||||
@@ -24,11 +23,23 @@ RenderTexture::~RenderTexture() {
|
||||
Free();
|
||||
}
|
||||
|
||||
int32_t RenderTexture::Bind(int32_t index) {
|
||||
int32_t RenderTexture::Bind(gl_state_struct& gl_st, int32_t index) {
|
||||
if (index < 0 || index > max_level)
|
||||
return -1;
|
||||
|
||||
gl_rend_state.bind_framebuffer(fbos[index]);
|
||||
gl_st.bind_framebuffer(fbos[index]);
|
||||
if (glCheckFramebufferStatus(GL_FRAMEBUFFER) != GL_FRAMEBUFFER_COMPLETE)
|
||||
return -1;
|
||||
|
||||
gl_get_error_print();
|
||||
return 0;
|
||||
}
|
||||
|
||||
int32_t RenderTexture::Bind(p_gl_rend_state& p_gl_rend_st, int32_t index) {
|
||||
if (index < 0 || index > max_level)
|
||||
return -1;
|
||||
|
||||
p_gl_rend_st.bind_framebuffer(fbos[index]);
|
||||
if (glCheckFramebufferStatus(GL_FRAMEBUFFER) != GL_FRAMEBUFFER_COMPLETE)
|
||||
return -1;
|
||||
|
||||
@@ -85,10 +96,10 @@ int32_t RenderTexture::Init(int32_t width, int32_t height,
|
||||
render_texture_counter++;
|
||||
color_texture = GetColorTex();
|
||||
if (color_format == GL_RGBA32F) {
|
||||
glBindTexture(GL_TEXTURE_2D, color_texture);
|
||||
gl_state.bind_texture_2d(color_texture);
|
||||
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_NEAREST);
|
||||
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_NEAREST);
|
||||
glBindTexture(GL_TEXTURE_2D, 0);
|
||||
gl_state.bind_texture_2d(0);
|
||||
}
|
||||
}
|
||||
else {
|
||||
@@ -122,23 +133,25 @@ int32_t RenderTexture::Init(int32_t width, int32_t height,
|
||||
return 0;
|
||||
}
|
||||
|
||||
/*int32_t RenderTexture::InitDepthRenderbuffer(GLenum internal_format, int32_t width, int32_t height) {
|
||||
gl_rend_state.bind_framebuffer(fbos[0]);
|
||||
/*int32_t RenderTexture::InitDepthRenderbuffer(gl_state_struct& gl_st,
|
||||
GLenum internal_format, int32_t width, int32_t height) {
|
||||
gl_st.bind_framebuffer(fbos[0]);
|
||||
glGenRenderbuffers(1, &depth_rbo);
|
||||
glBindRenderbuffer(GL_RENDERBUFFER, depth_rbo);
|
||||
glRenderbufferStorage(GL_RENDERBUFFER, internal_format, width, height);
|
||||
glFramebufferRenderbuffer(GL_FRAMEBUFFER, GL_DEPTH_ATTACHMENT, GL_RENDERBUFFER, depth_rbo);
|
||||
gl_rend_state.bind_framebuffer(0);
|
||||
gl_st.bind_framebuffer(0);
|
||||
return -(glGetError() != GL_ZERO);
|
||||
}
|
||||
|
||||
int32_t RenderTexture::InitStencilRenderbuffer(GLenum internal_format, int32_t width, int32_t height) {
|
||||
gl_rend_state.bind_framebuffer(fbos[0]);
|
||||
int32_t RenderTexture::InitStencilRenderbuffer(gl_state_struct& gl_st,
|
||||
GLenum internal_format, int32_t width, int32_t height) {
|
||||
gl_st.bind_framebuffer(fbos[0]);
|
||||
glGenRenderbuffers(1, &stencil_rbo);
|
||||
glBindRenderbuffer(GL_RENDERBUFFER, stencil_rbo);
|
||||
glRenderbufferStorage(GL_RENDERBUFFER, internal_format, width, height);
|
||||
glFramebufferRenderbuffer(GL_FRAMEBUFFER, GL_STENCIL_ATTACHMENT, GL_RENDERBUFFER, stencil_rbo);
|
||||
gl_rend_state.bind_framebuffer(0);
|
||||
gl_st.bind_framebuffer(0);
|
||||
return -(glGetError() != GL_ZERO);
|
||||
}*/
|
||||
|
||||
@@ -152,6 +165,10 @@ int32_t RenderTexture::SetColorDepthTextures(GLuint color_texture,
|
||||
return error;
|
||||
}
|
||||
|
||||
void RenderTexture::SetViewport(p_gl_rend_state& p_gl_rend_st) {
|
||||
p_gl_rend_st.set_viewport(0, 0, GetWidth(), GetHeight());
|
||||
}
|
||||
|
||||
void render_texture_counter_reset() {
|
||||
render_texture_counter = 0;
|
||||
}
|
||||
@@ -167,7 +184,7 @@ static int32_t render_texture_set_framebuffer_texture(RenderTexture* rt,
|
||||
if (level < 0 || level > rt->max_level)
|
||||
return -1;
|
||||
|
||||
gl_rend_state.bind_framebuffer(rt->fbos[level]);
|
||||
gl_state.bind_framebuffer(rt->fbos[level]);
|
||||
gl_get_error_print();
|
||||
|
||||
if (color_texture) {
|
||||
@@ -200,7 +217,7 @@ static int32_t render_texture_set_framebuffer_texture(RenderTexture* rt,
|
||||
int32_t ret = 0;
|
||||
if (glCheckFramebufferStatus(GL_FRAMEBUFFER) != GL_FRAMEBUFFER_COMPLETE)
|
||||
ret = -1;
|
||||
gl_rend_state.bind_framebuffer(0);
|
||||
gl_state.bind_framebuffer(0);
|
||||
gl_get_error_print();
|
||||
return ret;
|
||||
}
|
||||
|
||||
@@ -6,7 +6,6 @@
|
||||
#pragma once
|
||||
|
||||
#include "shared.hpp"
|
||||
#include "gl_rend_state.hpp"
|
||||
#include "texture.hpp"
|
||||
|
||||
struct RenderTexture {
|
||||
@@ -21,14 +20,16 @@ struct RenderTexture {
|
||||
RenderTexture();
|
||||
virtual ~RenderTexture();
|
||||
|
||||
int32_t Bind(int32_t index = 0);
|
||||
int32_t Bind(struct gl_state_struct& gl_st, int32_t index = 0);
|
||||
int32_t Bind(struct p_gl_rend_state& p_gl_rend_st, int32_t index = 0);
|
||||
void Free();
|
||||
int32_t Init(int32_t width, int32_t height,
|
||||
int32_t max_level, GLenum color_format, GLenum depth_format);
|
||||
/*int32_t InitDepthRenderbuffer(GLenum internal_format, int32_t width, int32_t height);
|
||||
int32_t InitStencilRenderbuffer(GLenum internal_format, int32_t width, int32_t height);*/
|
||||
/*int32_t InitDepthRenderbuffer(gl_state_struct& gl_st, GLenum internal_format, int32_t width, int32_t height);
|
||||
int32_t InitStencilRenderbuffer(gl_state_struct& gl_st, GLenum internal_format, int32_t width, int32_t height);*/
|
||||
int32_t SetColorDepthTextures(GLuint color_texture,
|
||||
int32_t max_level = 0, GLuint depth_texture = 0, bool stencil = false);
|
||||
void SetViewport(struct p_gl_rend_state& p_gl_rend_st);
|
||||
|
||||
inline GLuint GetColorTex() {
|
||||
return color_texture->glid;
|
||||
@@ -45,10 +46,6 @@ struct RenderTexture {
|
||||
inline int32_t GetWidth() {
|
||||
return color_texture->width;
|
||||
};
|
||||
|
||||
inline void SetViewport() {
|
||||
gl_rend_state.set_viewport(0, 0, GetWidth(), GetHeight());
|
||||
};
|
||||
};
|
||||
|
||||
extern void render_texture_counter_reset();
|
||||
|
||||
+123
-117
@@ -6,6 +6,7 @@
|
||||
#include "dof.hpp"
|
||||
#include "../rob/rob.hpp"
|
||||
#include "../gl_rend_state.hpp"
|
||||
#include "../gl_state.hpp"
|
||||
#include "../shader_ft.hpp"
|
||||
|
||||
struct dof_common_shader_data {
|
||||
@@ -60,7 +61,7 @@ namespace renderer {
|
||||
|
||||
}
|
||||
|
||||
void DOF3::apply(RenderTexture* rt, RenderTexture* buf_rt) {
|
||||
void DOF3::apply(render_data_context& rend_data_ctx, RenderTexture* rt, RenderTexture* buf_rt) {
|
||||
camera* cam = rctx_ptr->camera;
|
||||
bool use_dof_f2 = false;
|
||||
if (dof_debug_data.flags & DOF_DEBUG_USE_UI_PARAMS) {
|
||||
@@ -89,13 +90,13 @@ namespace renderer {
|
||||
}
|
||||
|
||||
focus = max_def(focus, (float_t)cam->min_distance);
|
||||
apply_physical(rt, buf_rt, rt->GetColorTex(), rt->GetDepthTex(),
|
||||
apply_physical(rend_data_ctx, rt, buf_rt, rt->GetColorTex(), rt->GetDepthTex(),
|
||||
cam->min_distance, cam->max_distance, focus,
|
||||
dof_debug_data.focal_length, cam->fov * DEG_TO_RAD_FLOAT, dof_debug_data.f_number);
|
||||
}
|
||||
else {
|
||||
float_t fuzzing_range = max_def(dof_debug_data.f2.fuzzing_range, 0.01f);
|
||||
apply_f2(rt, buf_rt, rt->GetColorTex(), rt->GetDepthTex(),
|
||||
apply_f2(rend_data_ctx, rt, buf_rt, rt->GetColorTex(), rt->GetDepthTex(),
|
||||
cam->min_distance, cam->max_distance, cam->fov * DEG_TO_RAD_FLOAT,
|
||||
dof_debug_data.f2.focus, dof_debug_data.f2.focus_range,
|
||||
fuzzing_range, dof_debug_data.f2.ratio);
|
||||
@@ -105,7 +106,7 @@ namespace renderer {
|
||||
}
|
||||
else if (dof_pv_data.enable && dof_pv_data.f2.ratio > 0.0f) {
|
||||
float_t fuzzing_range = max_def(dof_pv_data.f2.fuzzing_range, 0.01f);
|
||||
apply_f2(rt, buf_rt, rt->GetColorTex(), rt->GetDepthTex(),
|
||||
apply_f2(rend_data_ctx, rt, buf_rt, rt->GetColorTex(), rt->GetDepthTex(),
|
||||
cam->min_distance, cam->max_distance, cam->fov * DEG_TO_RAD_FLOAT,
|
||||
dof_pv_data.f2.focus, dof_pv_data.f2.focus_range,
|
||||
fuzzing_range, dof_pv_data.f2.ratio);
|
||||
@@ -164,149 +165,153 @@ namespace renderer {
|
||||
glSamplerParameteri(samplers[1], GL_TEXTURE_WRAP_S, GL_CLAMP_TO_EDGE);
|
||||
glSamplerParameteri(samplers[1], GL_TEXTURE_WRAP_T, GL_CLAMP_TO_EDGE);
|
||||
|
||||
common_ubo.Create(sizeof(dof_common_shader_data));
|
||||
common_ubo.Create(gl_state, sizeof(dof_common_shader_data));
|
||||
|
||||
vec2 data[50] = {};
|
||||
renderer::DOF3::calculate_texcoords(data, 3.0f);
|
||||
texcoords_ubo.Create(sizeof(data), data);
|
||||
texcoords_ubo.Create(gl_state, sizeof(data), data);
|
||||
|
||||
glGenVertexArrays(1, &vao);
|
||||
}
|
||||
|
||||
void DOF3::apply_f2(RenderTexture* rt, RenderTexture* buf_rt, GLuint color_texture,
|
||||
void DOF3::apply_f2(render_data_context& rend_data_ctx,
|
||||
RenderTexture* rt, RenderTexture* buf_rt, GLuint color_texture,
|
||||
GLuint depth_texture, float_t min_distance, float_t max_distance, float_t fov,
|
||||
float_t focus, float_t focus_range, float_t fuzzing_range, float_t ratio) {
|
||||
gl_rend_state.begin_event("renderer::DOF3::apply_f2");
|
||||
gl_rend_state.disable_blend();
|
||||
gl_rend_state.set_depth_mask(GL_FALSE);
|
||||
gl_rend_state.set_depth_func(GL_ALWAYS);
|
||||
update_data(min_distance, max_distance,
|
||||
rend_data_ctx.state.begin_event("renderer::DOF3::apply_f2");
|
||||
rend_data_ctx.state.disable_blend();
|
||||
rend_data_ctx.state.set_depth_mask(GL_FALSE);
|
||||
rend_data_ctx.state.set_depth_func(GL_ALWAYS);
|
||||
update_data(rend_data_ctx, min_distance, max_distance,
|
||||
fov, focus, 0.0f, 1.0f, focus_range, fuzzing_range, ratio);
|
||||
|
||||
uniform_value[U_DOF] = 1;
|
||||
rend_data_ctx.shader_flags.arr[U_DOF] = 1;
|
||||
|
||||
gl_rend_state.bind_vertex_array(vao);
|
||||
render_tiles(depth_texture, true);
|
||||
downsample(color_texture, depth_texture, true);
|
||||
apply_main_filter(true);
|
||||
upsample(rt, buf_rt, color_texture, depth_texture, true);
|
||||
rend_data_ctx.state.bind_vertex_array(vao);
|
||||
render_tiles(rend_data_ctx, depth_texture, true);
|
||||
downsample(rend_data_ctx, color_texture, depth_texture, true);
|
||||
apply_main_filter(rend_data_ctx, true);
|
||||
upsample(rend_data_ctx, rt, buf_rt, color_texture, depth_texture, true);
|
||||
|
||||
shader::unbind();
|
||||
shader::unbind(rend_data_ctx.state);
|
||||
for (int32_t i = 0; i < 8; i++) {
|
||||
gl_rend_state.bind_sampler(i, 0);
|
||||
gl_rend_state.active_bind_texture_2d(i, 0);
|
||||
rend_data_ctx.state.bind_sampler(i, 0);
|
||||
rend_data_ctx.state.active_bind_texture_2d(i, 0);
|
||||
}
|
||||
gl_rend_state.bind_vertex_array(0);
|
||||
gl_rend_state.end_event();
|
||||
rend_data_ctx.state.bind_vertex_array(0);
|
||||
rend_data_ctx.state.end_event();
|
||||
}
|
||||
|
||||
void DOF3::apply_physical(RenderTexture* rt, RenderTexture* buf_rt, GLuint color_texture,
|
||||
void DOF3::apply_physical(render_data_context& rend_data_ctx,
|
||||
RenderTexture* rt, RenderTexture* buf_rt, GLuint color_texture,
|
||||
GLuint depth_texture, float_t min_distance, float_t max_distance,
|
||||
float_t focus, float_t focal_length, float_t fov, float_t f_number) {
|
||||
gl_rend_state.begin_event("renderer::DOF3::apply_physical");
|
||||
gl_rend_state.disable_blend();
|
||||
gl_rend_state.set_depth_mask(GL_FALSE);
|
||||
gl_rend_state.set_depth_func(GL_ALWAYS);
|
||||
update_data(min_distance, max_distance,
|
||||
rend_data_ctx.state.begin_event("renderer::DOF3::apply_physical");
|
||||
rend_data_ctx.state.disable_blend();
|
||||
rend_data_ctx.state.set_depth_mask(GL_FALSE);
|
||||
rend_data_ctx.state.set_depth_func(GL_ALWAYS);
|
||||
update_data(rend_data_ctx, min_distance, max_distance,
|
||||
fov, focus, focal_length, f_number, 0.0f, 0.1f, 0.0f);
|
||||
|
||||
uniform_value[U_DOF] = 0;
|
||||
rend_data_ctx.shader_flags.arr[U_DOF] = 0;
|
||||
|
||||
gl_rend_state.bind_vertex_array(vao);
|
||||
render_tiles(depth_texture, false);
|
||||
downsample(color_texture, depth_texture, false);
|
||||
apply_main_filter(false);
|
||||
upsample(rt, buf_rt, color_texture, depth_texture, false);
|
||||
rend_data_ctx.state.bind_vertex_array(vao);
|
||||
render_tiles(rend_data_ctx, depth_texture, false);
|
||||
downsample(rend_data_ctx, color_texture, depth_texture, false);
|
||||
apply_main_filter(rend_data_ctx, false);
|
||||
upsample(rend_data_ctx, rt, buf_rt, color_texture, depth_texture, false);
|
||||
|
||||
shader::unbind();
|
||||
shader::unbind(rend_data_ctx.state);
|
||||
for (int32_t i = 0; i < 8; i++) {
|
||||
gl_rend_state.bind_sampler(i, 0);
|
||||
gl_rend_state.active_bind_texture_2d(i, 0);
|
||||
rend_data_ctx.state.bind_sampler(i, 0);
|
||||
rend_data_ctx.state.active_bind_texture_2d(i, 0);
|
||||
}
|
||||
gl_rend_state.bind_vertex_array(0);
|
||||
gl_rend_state.end_event();
|
||||
rend_data_ctx.state.bind_vertex_array(0);
|
||||
rend_data_ctx.state.end_event();
|
||||
}
|
||||
|
||||
void DOF3::render_tiles(GLuint depth_texture, bool f2) {
|
||||
gl_rend_state.begin_event("renderer::DOF3::render_tiles");
|
||||
fbo[0].bind_buffer();
|
||||
gl_rend_state.set_viewport(0, 0, fbo[0].width, fbo[0].height);
|
||||
uniform_value[U_DOF_STAGE] = 0;
|
||||
shaders_ft.set(SHADER_FT_DOF);
|
||||
common_ubo.Bind(0);
|
||||
gl_rend_state.active_bind_texture_2d(0, depth_texture);
|
||||
gl_rend_state.bind_sampler(0, samplers[1]);
|
||||
shaders_ft.draw_arrays(GL_TRIANGLE_STRIP, 0, 4);
|
||||
void DOF3::render_tiles(render_data_context& rend_data_ctx,
|
||||
GLuint depth_texture, bool f2) {
|
||||
rend_data_ctx.state.begin_event("renderer::DOF3::render_tiles");
|
||||
rend_data_ctx.state.bind_framebuffer(fbo[0].buffer);
|
||||
rend_data_ctx.state.set_viewport(0, 0, fbo[0].width, fbo[0].height);
|
||||
rend_data_ctx.shader_flags.arr[U_DOF_STAGE] = 0;
|
||||
shaders_ft.set(rend_data_ctx.state, rend_data_ctx.shader_flags, SHADER_FT_DOF);
|
||||
rend_data_ctx.state.bind_uniform_buffer_base(0, common_ubo);
|
||||
rend_data_ctx.state.active_bind_texture_2d(0, depth_texture);
|
||||
rend_data_ctx.state.bind_sampler(0, samplers[1]);
|
||||
rend_data_ctx.state.draw_arrays(GL_TRIANGLE_STRIP, 0, 4);
|
||||
|
||||
fbo[1].bind_buffer();
|
||||
gl_rend_state.set_viewport(0, 0, fbo[1].width, fbo[1].height);
|
||||
uniform_value[U_DOF_STAGE] = 1;
|
||||
shaders_ft.set(SHADER_FT_DOF);
|
||||
gl_rend_state.active_bind_texture_2d(0, textures[0]);
|
||||
gl_rend_state.bind_sampler(0, samplers[1]);
|
||||
shaders_ft.draw_arrays(GL_TRIANGLE_STRIP, 0, 4);
|
||||
gl_rend_state.end_event();
|
||||
rend_data_ctx.state.bind_framebuffer(fbo[1].buffer);
|
||||
rend_data_ctx.state.set_viewport(0, 0, fbo[1].width, fbo[1].height);
|
||||
rend_data_ctx.shader_flags.arr[U_DOF_STAGE] = 1;
|
||||
shaders_ft.set(rend_data_ctx.state, rend_data_ctx.shader_flags, SHADER_FT_DOF);
|
||||
rend_data_ctx.state.active_bind_texture_2d(0, textures[0]);
|
||||
rend_data_ctx.state.bind_sampler(0, samplers[1]);
|
||||
rend_data_ctx.state.draw_arrays(GL_TRIANGLE_STRIP, 0, 4);
|
||||
rend_data_ctx.state.end_event();
|
||||
}
|
||||
|
||||
void DOF3::downsample(GLuint color_texture, GLuint depth_texture, bool f2) {
|
||||
gl_rend_state.begin_event("renderer::DOF3::downsample");
|
||||
fbo[2].bind_buffer();
|
||||
gl_rend_state.set_viewport(0, 0, fbo[2].width, fbo[2].height);
|
||||
uniform_value[U_DOF_STAGE] = 2;
|
||||
shaders_ft.set(SHADER_FT_DOF);
|
||||
common_ubo.Bind(0);
|
||||
gl_rend_state.active_bind_texture_2d(0, depth_texture);
|
||||
gl_rend_state.bind_sampler(0, samplers[1]);
|
||||
gl_rend_state.active_bind_texture_2d(1, color_texture);
|
||||
gl_rend_state.bind_sampler(1, samplers[0]);
|
||||
gl_rend_state.active_bind_texture_2d(2, textures[1]);
|
||||
gl_rend_state.bind_sampler(2, samplers[1]);
|
||||
shaders_ft.draw_arrays(GL_TRIANGLE_STRIP, 0, 4);
|
||||
gl_rend_state.end_event();
|
||||
void DOF3::downsample(render_data_context& rend_data_ctx, GLuint color_texture, GLuint depth_texture, bool f2) {
|
||||
rend_data_ctx.state.begin_event("renderer::DOF3::downsample");
|
||||
rend_data_ctx.state.bind_framebuffer(fbo[2].buffer);
|
||||
rend_data_ctx.state.set_viewport(0, 0, fbo[2].width, fbo[2].height);
|
||||
rend_data_ctx.shader_flags.arr[U_DOF_STAGE] = 2;
|
||||
shaders_ft.set(rend_data_ctx.state, rend_data_ctx.shader_flags, SHADER_FT_DOF);
|
||||
rend_data_ctx.state.bind_uniform_buffer_base(0, common_ubo);
|
||||
rend_data_ctx.state.active_bind_texture_2d(0, depth_texture);
|
||||
rend_data_ctx.state.bind_sampler(0, samplers[1]);
|
||||
rend_data_ctx.state.active_bind_texture_2d(1, color_texture);
|
||||
rend_data_ctx.state.bind_sampler(1, samplers[0]);
|
||||
rend_data_ctx.state.active_bind_texture_2d(2, textures[1]);
|
||||
rend_data_ctx.state.bind_sampler(2, samplers[1]);
|
||||
rend_data_ctx.state.draw_arrays(GL_TRIANGLE_STRIP, 0, 4);
|
||||
rend_data_ctx.state.end_event();
|
||||
}
|
||||
|
||||
void DOF3::apply_main_filter(bool f2) {
|
||||
gl_rend_state.begin_event("renderer::DOF3::apply_main_filter");
|
||||
fbo[3].bind_buffer();
|
||||
gl_rend_state.set_viewport(0, 0, fbo[3].width, fbo[3].height);
|
||||
uniform_value[U_DOF_STAGE] = 3;
|
||||
shaders_ft.set(SHADER_FT_DOF);
|
||||
common_ubo.Bind(0);
|
||||
texcoords_ubo.Bind(1);
|
||||
gl_rend_state.active_bind_texture_2d(0, textures[3]);
|
||||
gl_rend_state.bind_sampler(0, samplers[1]);
|
||||
gl_rend_state.active_bind_texture_2d(1, textures[2]);
|
||||
gl_rend_state.bind_sampler(1, samplers[1]);
|
||||
gl_rend_state.active_bind_texture_2d(2, textures[1]);
|
||||
gl_rend_state.bind_sampler(2, samplers[1]);
|
||||
shaders_ft.draw_arrays(GL_TRIANGLE_STRIP, 0, 4);
|
||||
gl_rend_state.end_event();
|
||||
void DOF3::apply_main_filter(render_data_context& rend_data_ctx, bool f2) {
|
||||
rend_data_ctx.state.begin_event("renderer::DOF3::apply_main_filter");
|
||||
rend_data_ctx.state.bind_framebuffer(fbo[3].buffer);
|
||||
rend_data_ctx.state.set_viewport(0, 0, fbo[3].width, fbo[3].height);
|
||||
rend_data_ctx.shader_flags.arr[U_DOF_STAGE] = 3;
|
||||
shaders_ft.set(rend_data_ctx.state, rend_data_ctx.shader_flags, SHADER_FT_DOF);
|
||||
rend_data_ctx.state.bind_uniform_buffer_base(0, common_ubo);
|
||||
rend_data_ctx.state.bind_uniform_buffer_base(1, texcoords_ubo);
|
||||
rend_data_ctx.state.active_bind_texture_2d(0, textures[3]);
|
||||
rend_data_ctx.state.bind_sampler(0, samplers[1]);
|
||||
rend_data_ctx.state.active_bind_texture_2d(1, textures[2]);
|
||||
rend_data_ctx.state.bind_sampler(1, samplers[1]);
|
||||
rend_data_ctx.state.active_bind_texture_2d(2, textures[1]);
|
||||
rend_data_ctx.state.bind_sampler(2, samplers[1]);
|
||||
rend_data_ctx.state.draw_arrays(GL_TRIANGLE_STRIP, 0, 4);
|
||||
rend_data_ctx.state.end_event();
|
||||
}
|
||||
|
||||
void DOF3::upsample(RenderTexture* rt, RenderTexture* buf_rt,
|
||||
void DOF3::upsample(render_data_context& rend_data_ctx,
|
||||
RenderTexture* rt, RenderTexture* buf_rt,
|
||||
GLuint color_texture, GLuint depth_texture, bool f2) {
|
||||
gl_rend_state.begin_event("renderer::DOF3::upsample");
|
||||
buf_rt->Bind();
|
||||
gl_rend_state.set_viewport(0, 0, width, height);
|
||||
uniform_value[U_DOF_STAGE] = 4;
|
||||
shaders_ft.set(SHADER_FT_DOF);
|
||||
common_ubo.Bind(0);
|
||||
gl_rend_state.active_bind_texture_2d(0, textures[4]);
|
||||
gl_rend_state.bind_sampler(0, samplers[1]);
|
||||
gl_rend_state.active_bind_texture_2d(1, textures[5]);
|
||||
gl_rend_state.bind_sampler(1, samplers[1]);
|
||||
gl_rend_state.active_bind_texture_2d(2, textures[1]);
|
||||
gl_rend_state.bind_sampler(2, samplers[1]);
|
||||
gl_rend_state.active_bind_texture_2d(3, color_texture);
|
||||
gl_rend_state.bind_sampler(3, samplers[1]);
|
||||
gl_rend_state.active_bind_texture_2d(4, depth_texture);
|
||||
gl_rend_state.bind_sampler(4, samplers[1]);
|
||||
shaders_ft.draw_arrays(GL_TRIANGLE_STRIP, 0, 4);
|
||||
rend_data_ctx.state.begin_event("renderer::DOF3::upsample");
|
||||
buf_rt->Bind(rend_data_ctx.state);
|
||||
rend_data_ctx.state.set_viewport(0, 0, width, height);
|
||||
rend_data_ctx.shader_flags.arr[U_DOF_STAGE] = 4;
|
||||
shaders_ft.set(rend_data_ctx.state, rend_data_ctx.shader_flags, SHADER_FT_DOF);
|
||||
rend_data_ctx.state.bind_uniform_buffer_base(0, common_ubo);
|
||||
rend_data_ctx.state.active_bind_texture_2d(0, textures[4]);
|
||||
rend_data_ctx.state.bind_sampler(0, samplers[1]);
|
||||
rend_data_ctx.state.active_bind_texture_2d(1, textures[5]);
|
||||
rend_data_ctx.state.bind_sampler(1, samplers[1]);
|
||||
rend_data_ctx.state.active_bind_texture_2d(2, textures[1]);
|
||||
rend_data_ctx.state.bind_sampler(2, samplers[1]);
|
||||
rend_data_ctx.state.active_bind_texture_2d(3, color_texture);
|
||||
rend_data_ctx.state.bind_sampler(3, samplers[1]);
|
||||
rend_data_ctx.state.active_bind_texture_2d(4, depth_texture);
|
||||
rend_data_ctx.state.bind_sampler(4, samplers[1]);
|
||||
rend_data_ctx.state.draw_arrays(GL_TRIANGLE_STRIP, 0, 4);
|
||||
|
||||
glCopyImageSubData(
|
||||
buf_rt->GetColorTex(), GL_TEXTURE_2D, 0, 0, 0, 0,
|
||||
rt->GetColorTex(), GL_TEXTURE_2D, 0, 0, 0, 0, width, height, 1);
|
||||
gl_rend_state.end_event();
|
||||
rend_data_ctx.state.end_event();
|
||||
}
|
||||
|
||||
void DOF3::init_textures(int32_t width, int32_t height) {
|
||||
@@ -316,30 +321,31 @@ namespace renderer {
|
||||
int32_t h2 = max_def(height / 2, 1);
|
||||
|
||||
glGenTextures(6, textures);
|
||||
glBindTexture(GL_TEXTURE_2D, textures[0]);
|
||||
gl_state.bind_texture_2d(textures[0]);
|
||||
glTexImage2D(GL_TEXTURE_2D, 0, GL_RG16F, w20, h20, 0, GL_RG, GL_HALF_FLOAT, 0);
|
||||
fbo[0].init(w20, h20, &textures[0], 1, 0);
|
||||
|
||||
glBindTexture(GL_TEXTURE_2D, textures[1]);
|
||||
gl_state.bind_texture_2d(textures[1]);
|
||||
glTexImage2D(GL_TEXTURE_2D, 0, GL_RG16F, w20, h20, 0, GL_RG, GL_HALF_FLOAT, 0);
|
||||
fbo[1].init(w20, h20, &textures[1], 1, 0);
|
||||
|
||||
glBindTexture(GL_TEXTURE_2D, textures[2]);
|
||||
gl_state.bind_texture_2d(textures[2]);
|
||||
glTexImage2D(GL_TEXTURE_2D, 0, GL_R11F_G11F_B10F, w2, h2, 0, GL_RGB, GL_UNSIGNED_INT_10F_11F_11F_REV, 0);
|
||||
glBindTexture(GL_TEXTURE_2D, textures[3]);
|
||||
gl_state.bind_texture_2d(textures[3]);
|
||||
glTexImage2D(GL_TEXTURE_2D, 0, GL_R11F_G11F_B10F, w2, h2, 0, GL_RGB, GL_UNSIGNED_INT_10F_11F_11F_REV, 0);
|
||||
fbo[2].init(w2, h2, &textures[2], 2, 0);
|
||||
|
||||
glBindTexture(GL_TEXTURE_2D, textures[4]);
|
||||
gl_state.bind_texture_2d(textures[4]);
|
||||
glTexImage2D(GL_TEXTURE_2D, 0, GL_R11F_G11F_B10F, w2, h2, 0, GL_RGB, GL_UNSIGNED_INT_10F_11F_11F_REV, 0);
|
||||
glBindTexture(GL_TEXTURE_2D, textures[5]);
|
||||
gl_state.bind_texture_2d(textures[5]);
|
||||
glTexImage2D(GL_TEXTURE_2D, 0, GL_R8, w2, h2, 0, GL_RED, GL_UNSIGNED_BYTE, 0);
|
||||
fbo[3].init(w2, h2, &textures[4], 2, 0);
|
||||
|
||||
glBindTexture(GL_TEXTURE_2D, 0);
|
||||
gl_state.bind_texture_2d(0);
|
||||
}
|
||||
|
||||
void DOF3::update_data(float_t min_dist, float_t max_dist, float_t fov, float_t dist, float_t focal_length,
|
||||
void DOF3::update_data(render_data_context& rend_data_ctx,
|
||||
float_t min_dist, float_t max_dist, float_t fov, float_t dist, float_t focal_length,
|
||||
float_t f_number, float_t focus_range, float_t fuzzing_range, float_t ratio) {
|
||||
float_t fl = focal_length;
|
||||
if (dist <= focal_length)
|
||||
@@ -359,7 +365,7 @@ namespace renderer {
|
||||
shader_data.g_depth_params2.y = focus_range;
|
||||
shader_data.g_depth_params2.z = -4.5f / (fuzzing_range * fuzzing_range);
|
||||
shader_data.g_depth_params2.w = ratio * 8.0f;
|
||||
common_ubo.WriteMemory(shader_data);
|
||||
common_ubo.WriteMemory(rend_data_ctx.state, shader_data);
|
||||
}
|
||||
|
||||
void DOF3::calculate_texcoords(vec2* data, float_t size) {
|
||||
|
||||
@@ -38,6 +38,8 @@ struct dof_pv {
|
||||
dof_f2 f2;
|
||||
};
|
||||
|
||||
struct render_data_context;
|
||||
|
||||
namespace renderer {
|
||||
struct DOF3 {
|
||||
private:
|
||||
@@ -54,28 +56,32 @@ namespace renderer {
|
||||
DOF3(int32_t width, int32_t height);
|
||||
~DOF3();
|
||||
|
||||
void apply(RenderTexture* rt, RenderTexture* buf_rt);
|
||||
void apply(render_data_context& rend_data_ctx, RenderTexture* rt, RenderTexture* buf_rt);
|
||||
void resize(int32_t width, int32_t height);
|
||||
|
||||
private:
|
||||
void free();
|
||||
void init(int32_t width, int32_t height);
|
||||
|
||||
void apply_f2(RenderTexture* rt, RenderTexture* buf_rt, GLuint color_texture,
|
||||
void apply_f2(render_data_context& rend_data_ctx,
|
||||
RenderTexture* rt, RenderTexture* buf_rt, GLuint color_texture,
|
||||
GLuint depth_texture, float_t min_distance, float_t max_distance, float_t fov,
|
||||
float_t focus, float_t focus_range, float_t fuzzing_range, float_t ratio);
|
||||
void apply_physical(RenderTexture* rt, RenderTexture* buf_rt, GLuint color_texture,
|
||||
void apply_physical(render_data_context& rend_data_ctx,
|
||||
RenderTexture* rt, RenderTexture* buf_rt, GLuint color_texture,
|
||||
GLuint depth_texture, float_t min_distance, float_t max_distance,
|
||||
float_t focus, float_t focal_length, float_t fov, float_t f_number);
|
||||
|
||||
void render_tiles(GLuint depth_texture, bool f2);
|
||||
void downsample(GLuint color_texture, GLuint depth_texture, bool f2);
|
||||
void apply_main_filter(bool f2);
|
||||
void upsample(RenderTexture* rt, RenderTexture* buf_rt,
|
||||
void render_tiles(render_data_context& rend_data_ctx, GLuint depth_texture, bool f2);
|
||||
void downsample(render_data_context& rend_data_ctx, GLuint color_texture, GLuint depth_texture, bool f2);
|
||||
void apply_main_filter(render_data_context& rend_data_ctx, bool f2);
|
||||
void upsample(render_data_context& rend_data_ctx,
|
||||
RenderTexture* rt, RenderTexture* buf_rt,
|
||||
GLuint color_texture, GLuint depth_texture, bool f2);
|
||||
|
||||
void init_textures(int32_t width, int32_t height);
|
||||
void update_data(float_t min_dist, float_t max_dist, float_t fov, float_t dist, float_t focal_length,
|
||||
void update_data(render_data_context& rend_data_ctx,
|
||||
float_t min_dist, float_t max_dist, float_t fov, float_t dist, float_t focal_length,
|
||||
float_t f_number, float_t focus_range, float_t fuzzing_range, float_t ratio);
|
||||
|
||||
static void calculate_texcoords(vec2* data, float_t size);
|
||||
|
||||
@@ -4,7 +4,7 @@
|
||||
*/
|
||||
|
||||
#include "fbo.hpp"
|
||||
#include "../gl_rend_state.hpp"
|
||||
#include "../gl_state.hpp"
|
||||
|
||||
namespace renderer {
|
||||
FBO::FBO() : flags(), width(), height(), buffer(), count(), textures() {
|
||||
@@ -41,7 +41,7 @@ namespace renderer {
|
||||
textures[count] = depth_texture;
|
||||
|
||||
glGenFramebuffers(1, &buffer);
|
||||
gl_rend_state.bind_framebuffer(buffer, true);
|
||||
gl_state.bind_framebuffer(buffer, true);
|
||||
for (int32_t i = 0; i < count; i++)
|
||||
glFramebufferTexture(GL_FRAMEBUFFER, GL_COLOR_ATTACHMENT0 + i, textures[i], 0);
|
||||
|
||||
@@ -53,7 +53,7 @@ namespace renderer {
|
||||
color_attachments[i] = GL_COLOR_ATTACHMENT0 + i;
|
||||
glDrawBuffers(count, color_attachments);
|
||||
glCheckFramebufferStatus(GL_FRAMEBUFFER);
|
||||
gl_rend_state.bind_framebuffer(0);
|
||||
gl_state.bind_framebuffer(0);
|
||||
}
|
||||
#pragma warning(pop)
|
||||
|
||||
|
||||
@@ -27,9 +27,5 @@ namespace renderer {
|
||||
void init(int32_t width, int32_t height,
|
||||
GLuint* color_textures, int32_t count, GLuint depth_texture);
|
||||
void free();
|
||||
|
||||
inline void bind_buffer() {
|
||||
gl_rend_state.bind_framebuffer(buffer);
|
||||
}
|
||||
};
|
||||
}
|
||||
|
||||
@@ -39,31 +39,31 @@ namespace renderer {
|
||||
}
|
||||
}
|
||||
|
||||
void Transparency::combine(RenderTexture* rt, float_t alpha) {
|
||||
void Transparency::combine(render_data_context& rend_data_ctx, RenderTexture* rt, float_t alpha) {
|
||||
transparency_batch_shader_data shader_data = {};
|
||||
shader_data.g_opacity = { alpha, 0.0f, 0.0f, 0.0f };
|
||||
rctx_ptr->transparency_batch_ubo.WriteMemory(shader_data);
|
||||
rctx_ptr->transparency_batch_ubo.WriteMemory(rend_data_ctx.state, shader_data);
|
||||
|
||||
gl_rend_state.disable_blend();
|
||||
gl_rend_state.disable_depth_test();
|
||||
rctx_ptr->render_buffer.Bind();
|
||||
shaders_ft.set(SHADER_FT_TRANSPARENCY);
|
||||
rctx_ptr->transparency_batch_ubo.Bind(0);
|
||||
gl_rend_state.active_bind_texture_2d(0, fbo.textures[0]);
|
||||
gl_rend_state.active_bind_texture_2d(1, rt->GetColorTex());
|
||||
gl_rend_state.bind_vertex_array(vao);
|
||||
shaders_ft.draw_arrays(GL_TRIANGLE_STRIP, 0, 4);
|
||||
gl_rend_state.enable_depth_test();
|
||||
rend_data_ctx.state.disable_blend();
|
||||
rend_data_ctx.state.disable_depth_test();
|
||||
rctx_ptr->render_buffer.Bind(rend_data_ctx.state);
|
||||
shaders_ft.set(rend_data_ctx.state, rend_data_ctx.shader_flags, SHADER_FT_TRANSPARENCY);
|
||||
rend_data_ctx.state.bind_uniform_buffer_base(0, rctx_ptr->transparency_batch_ubo);
|
||||
rend_data_ctx.state.active_bind_texture_2d(0, fbo.textures[0]);
|
||||
rend_data_ctx.state.active_bind_texture_2d(1, rt->GetColorTex());
|
||||
rend_data_ctx.state.bind_vertex_array(vao);
|
||||
rend_data_ctx.state.draw_arrays(GL_TRIANGLE_STRIP, 0, 4);
|
||||
rend_data_ctx.state.enable_depth_test();
|
||||
|
||||
glCopyImageSubData(rctx_ptr->render_buffer.GetColorTex(), GL_TEXTURE_2D, 0, 0, 0, 0,
|
||||
rt->GetColorTex(), GL_TEXTURE_2D, 0, 0, 0, 0, fbo.width, fbo.height, 1);
|
||||
}
|
||||
|
||||
void Transparency::copy(GLuint texture) {
|
||||
void Transparency::copy(render_data_context& rend_data_ctx, GLuint texture) {
|
||||
glCopyImageSubData(texture, GL_TEXTURE_2D, 0, 0, 0, 0,
|
||||
fbo.textures[0], GL_TEXTURE_2D, 0, 0, 0, 0, fbo.width, fbo.height, 1);
|
||||
fbo.bind_buffer();
|
||||
gl_rend_state.set_viewport(0, 0, fbo.width, fbo.height);
|
||||
rend_data_ctx.state.bind_framebuffer(fbo.buffer);
|
||||
rend_data_ctx.state.set_viewport(0, 0, fbo.width, fbo.height);
|
||||
}
|
||||
|
||||
void Transparency::resize(GLuint color_texture, GLuint depth_texture, int32_t width, int32_t height) {
|
||||
|
||||
@@ -10,6 +10,8 @@
|
||||
#include "../render_texture.hpp"
|
||||
#include "fbo.hpp"
|
||||
|
||||
struct render_data_context;
|
||||
|
||||
namespace renderer {
|
||||
struct Transparency {
|
||||
private:
|
||||
@@ -21,8 +23,8 @@ namespace renderer {
|
||||
Transparency(GLuint color_texture, GLuint depth_texture, int32_t width, int32_t height);
|
||||
~Transparency();
|
||||
|
||||
void combine(RenderTexture* rt, float_t alpha);
|
||||
void copy(GLuint texture);
|
||||
void combine(render_data_context& rend_data_ctx, RenderTexture* rt, float_t alpha);
|
||||
void copy(render_data_context& rend_data_ctx, GLuint texture);
|
||||
|
||||
void resize(GLuint color_texture, GLuint depth_texture, int32_t width, int32_t height);
|
||||
};
|
||||
|
||||
@@ -8,6 +8,7 @@
|
||||
#include "../../KKdLib/str_utils.hpp"
|
||||
#include "../app_system_detail.hpp"
|
||||
#include "../data.hpp"
|
||||
#include "../gl_state.hpp"
|
||||
#include "skin_param.hpp"
|
||||
|
||||
struct exp_func_op1 {
|
||||
@@ -1957,7 +1958,7 @@ void RobCloth::UpdateVertexBuffer(obj_mesh* mesh, obj_mesh_vertex_buffer* vertex
|
||||
|
||||
vertex_buffer->cycle_index();
|
||||
GL::ArrayBuffer buffer = vertex_buffer->get_buffer();
|
||||
size_t data = (size_t)buffer.MapMemory();
|
||||
size_t data = (size_t)buffer.MapMemory(gl_state);
|
||||
if (!data)
|
||||
return;
|
||||
|
||||
@@ -2093,7 +2094,7 @@ void RobCloth::UpdateVertexBuffer(obj_mesh* mesh, obj_mesh_vertex_buffer* vertex
|
||||
break;
|
||||
}
|
||||
|
||||
buffer.UnmapMemory();
|
||||
buffer.UnmapMemory(gl_state);
|
||||
}
|
||||
|
||||
ExClothBlock::ExClothBlock() {
|
||||
|
||||
+3
-2
@@ -16,6 +16,7 @@
|
||||
#include "../module_table.hpp"
|
||||
#include "../data.hpp"
|
||||
#include "../effect.hpp"
|
||||
#include "../gl_state.hpp"
|
||||
#include "../hand_item.hpp"
|
||||
#include "../mdata_manager.hpp"
|
||||
#include "../pv_db.hpp"
|
||||
@@ -18129,7 +18130,7 @@ void rob_chara_age_age_object::disp(render_context* rctx, size_t chara_index,
|
||||
obj_vert_buf.cycle_index();
|
||||
|
||||
GL::ArrayBuffer buffer = obj_vert_buf.get_buffer();
|
||||
size_t vtx_data = (size_t)buffer.MapMemory();
|
||||
size_t vtx_data = (size_t)buffer.MapMemory(gl_state);
|
||||
if (!vtx_data)
|
||||
return;
|
||||
|
||||
@@ -18138,7 +18139,7 @@ void rob_chara_age_age_object::disp(render_context* rctx, size_t chara_index,
|
||||
memmove((void*)(vtx_data + vertex_array_size * i),
|
||||
(void*)((size_t)vertex_data + vertex_array_size * v44[i].second), vertex_array_size);
|
||||
|
||||
buffer.UnmapMemory();
|
||||
buffer.UnmapMemory(gl_state);
|
||||
|
||||
mesh.num_vertex = disp_count * num_vertex;
|
||||
sub_mesh.num_index = disp_count * num_index;
|
||||
|
||||
+17
-117
@@ -14,6 +14,7 @@
|
||||
#include "Vulkan/Manager.hpp"
|
||||
#include "Vulkan/ShaderModule.hpp"
|
||||
#include "gl_rend_state.hpp"
|
||||
#include "render_context.hpp"
|
||||
#include "shared.hpp"
|
||||
#include <shlobj_core.h>
|
||||
|
||||
@@ -38,11 +39,9 @@ static GLuint shader_compile_binary(const char* vert, const char* frag, const ch
|
||||
#endif
|
||||
static bool shader_load_binary_shader(program_binary* bin, GLuint* program, const char* vp, const char* fp);
|
||||
static prj::shared_ptr<Vulkan::ShaderModule> shader_load_spv_shader(program_spv* spv, const char* shader);
|
||||
static bool shader_update_data(shader_set_data* set);
|
||||
|
||||
int32_t shader::bind(shader_set_data* set, uint32_t sub_index) {
|
||||
set->curr_program = 0;
|
||||
|
||||
int32_t shader::bind(p_gl_rend_state& p_gl_rend_st,
|
||||
const uniform_value& shader_flags, shader_set_data* set, uint32_t sub_index) {
|
||||
if (num_sub < 1)
|
||||
return -1;
|
||||
|
||||
@@ -60,7 +59,7 @@ int32_t shader::bind(shader_set_data* set, uint32_t sub_index) {
|
||||
const int32_t* fp_unival_max = sub_shader->fp_unival_max;
|
||||
|
||||
for (int32_t i = 0; i < num_uniform; i++) {
|
||||
const int32_t unival = uniform_value[use_uniform[i]];
|
||||
const int32_t unival = shader_flags.arr[use_uniform[i]];
|
||||
const int32_t unival_max = max_def(vp_unival_max[i], fp_unival_max[i]);
|
||||
unival_shad += unival_shad_curr * min_def(unival, unival_max);
|
||||
unival_shad_curr *= unival_max + 1;
|
||||
@@ -68,9 +67,7 @@ int32_t shader::bind(shader_set_data* set, uint32_t sub_index) {
|
||||
}
|
||||
|
||||
GLuint program = sub_shader->programs[unival_shad];
|
||||
set->curr_program = program;
|
||||
|
||||
gl_rend_state.use_program(program);
|
||||
p_gl_rend_st.use_program(program);
|
||||
return 0;
|
||||
}
|
||||
|
||||
@@ -489,98 +486,15 @@ char* shader::parse_include(char* data, farc* f) {
|
||||
return temp_data;
|
||||
}
|
||||
|
||||
void shader::unbind() {
|
||||
gl_rend_state.use_program(0);
|
||||
void shader::unbind(p_gl_rend_state& p_gl_rend_st) {
|
||||
p_gl_rend_st.use_program(0);
|
||||
}
|
||||
|
||||
shader_set_data::shader_set_data() : size(), shaders(), curr_program(), primitive_restart(),
|
||||
primitive_restart_index(), get_index_by_name_func(), get_name_by_index_func() {
|
||||
shader_set_data::shader_set_data() : size(), shaders(),
|
||||
get_index_by_name_func(), get_name_by_index_func() {
|
||||
|
||||
}
|
||||
|
||||
void shader_set_data::disable_primitive_restart() {
|
||||
primitive_restart = false;
|
||||
}
|
||||
|
||||
void shader_set_data::draw_arrays(GLenum mode, GLint first, GLsizei count) {
|
||||
if (shader_update_data(this))
|
||||
glDrawArrays(mode, first, count);
|
||||
}
|
||||
|
||||
void shader_set_data::draw_elements(GLenum mode,
|
||||
GLsizei count, GLenum type, const void* indices) {
|
||||
switch (mode) {
|
||||
case GL_TRIANGLE_STRIP:
|
||||
uint32_t index;
|
||||
switch (type) {
|
||||
case GL_UNSIGNED_BYTE:
|
||||
index = 0xFF;
|
||||
break;
|
||||
case GL_UNSIGNED_SHORT:
|
||||
index = 0xFFFF;
|
||||
break;
|
||||
case GL_UNSIGNED_INT:
|
||||
default:
|
||||
index = 0xFFFFFFFF;
|
||||
break;
|
||||
}
|
||||
|
||||
enable_primitive_restart();
|
||||
|
||||
if (primitive_restart_index != index)
|
||||
primitive_restart_index = index;
|
||||
break;
|
||||
}
|
||||
|
||||
if (shader_update_data(this))
|
||||
glDrawElements(mode, count, type, indices);
|
||||
|
||||
switch (mode) {
|
||||
case GL_TRIANGLE_STRIP:
|
||||
disable_primitive_restart();
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
void shader_set_data::draw_range_elements(GLenum mode,
|
||||
GLuint start, GLuint end, GLsizei count, GLenum type, const void* indices) {
|
||||
switch (mode) {
|
||||
case GL_TRIANGLE_STRIP:
|
||||
uint32_t index;
|
||||
switch (type) {
|
||||
case GL_UNSIGNED_BYTE:
|
||||
index = 0xFF;
|
||||
break;
|
||||
case GL_UNSIGNED_SHORT:
|
||||
index = 0xFFFF;
|
||||
break;
|
||||
case GL_UNSIGNED_INT:
|
||||
default:
|
||||
index = 0xFFFFFFFF;
|
||||
break;
|
||||
}
|
||||
|
||||
enable_primitive_restart();
|
||||
|
||||
if (primitive_restart_index != index)
|
||||
primitive_restart_index = index;
|
||||
break;
|
||||
}
|
||||
|
||||
if (shader_update_data(this))
|
||||
glDrawRangeElements(mode, start, end, count, type, indices);
|
||||
|
||||
switch (mode) {
|
||||
case GL_TRIANGLE_STRIP:
|
||||
disable_primitive_restart();
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
void shader_set_data::enable_primitive_restart() {
|
||||
primitive_restart = true;
|
||||
}
|
||||
|
||||
int32_t shader_set_data::get_index_by_name(const char* name) {
|
||||
if (get_index_by_name_func) {
|
||||
int32_t index = get_index_by_name_func(name);
|
||||
@@ -1120,13 +1034,13 @@ void shader_set_data::load(farc* f, bool ignore_cache,
|
||||
if (programs[k] && samplers.size()) {
|
||||
GLuint program = programs[k];
|
||||
|
||||
gl_rend_state.use_program(program);
|
||||
glUseProgram(program);
|
||||
for (auto& i : samplers) {
|
||||
GLint loc = glGetUniformLocation(program, i.second.c_str());
|
||||
if (loc != -1)
|
||||
glUniform1i(loc, i.first);
|
||||
}
|
||||
gl_rend_state.use_program(0);
|
||||
glUseProgram(0);
|
||||
}
|
||||
|
||||
if (programs[k] && uniforms.size()) {
|
||||
@@ -1185,13 +1099,13 @@ void shader_set_data::load(farc* f, bool ignore_cache,
|
||||
if (programs[0] && samplers.size()) {
|
||||
GLuint program = programs[0];
|
||||
|
||||
gl_rend_state.use_program(program);
|
||||
glUseProgram(program);
|
||||
for (auto& i : samplers) {
|
||||
GLint loc = glGetUniformLocation(program, i.second.c_str());
|
||||
if (loc != -1)
|
||||
glUniform1i(loc, i.first);
|
||||
}
|
||||
gl_rend_state.use_program(0);
|
||||
glUseProgram(0);
|
||||
}
|
||||
|
||||
if (programs[0] && uniforms.size()) {
|
||||
@@ -1271,16 +1185,16 @@ void shader_set_data::load(farc* f, bool ignore_cache,
|
||||
this->get_name_by_index_func = get_name_by_index;
|
||||
}
|
||||
|
||||
void shader_set_data::set(uint32_t index) {
|
||||
void shader_set_data::set(p_gl_rend_state& p_gl_rend_st, uniform_value& shader_flags, uint32_t index) {
|
||||
if (this && index && index != -1) {
|
||||
shader* shader = &shaders[index];
|
||||
if (shader->bind_func)
|
||||
shader->bind_func(this, shader);
|
||||
shader->bind_func(p_gl_rend_st, shader_flags, this, shader);
|
||||
else
|
||||
shader->bind(this, shader->sub[0].sub_index);
|
||||
shader->bind(p_gl_rend_st, shader_flags, this, shader->sub[0].sub_index);
|
||||
}
|
||||
else
|
||||
shader::unbind();
|
||||
shader::unbind(p_gl_rend_st);
|
||||
}
|
||||
|
||||
void shader_set_data::unload() {
|
||||
@@ -1574,17 +1488,3 @@ static prj::shared_ptr<Vulkan::ShaderModule> shader_load_spv_shader(program_spv*
|
||||
return prj::shared_ptr<Vulkan::ShaderModule>(new Vulkan::ShaderModule(
|
||||
Vulkan::current_device, (const void*)((size_t)spv + spv->spv), spv->size));
|
||||
}
|
||||
|
||||
static bool shader_update_data(shader_set_data* set) {
|
||||
if (!set || !set->curr_program)
|
||||
return false;
|
||||
|
||||
if (set->primitive_restart) {
|
||||
gl_rend_state.enable_primitive_restart();
|
||||
gl_rend_state.set_primitive_restart_index(set->primitive_restart_index);
|
||||
}
|
||||
else
|
||||
gl_rend_state.disable_primitive_restart();
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
+6
-14
@@ -56,7 +56,8 @@ struct shader_set_data;
|
||||
typedef int32_t (*PFNSHADERGETINDEXFUNCPROC)(const char* name);
|
||||
typedef const char* (*PFNSHADERGETNAMEFUNCPROC)(int32_t index);
|
||||
|
||||
typedef void (*PFNSHADERBINDFUNCPROC)(shader_set_data* set, shader* shad);
|
||||
typedef void (*PFNSHADERBINDFUNCPROC)(struct p_gl_rend_state& p_gl_rend_st,
|
||||
struct uniform_value& shader_flags, shader_set_data* set, shader* shad);
|
||||
|
||||
struct shader_bind_func {
|
||||
uint32_t name_index;
|
||||
@@ -81,40 +82,31 @@ struct shader {
|
||||
const uniform_name* use_uniform;
|
||||
PFNSHADERBINDFUNCPROC bind_func;
|
||||
|
||||
int32_t bind(shader_set_data* set, uint32_t sub_index);
|
||||
int32_t bind(struct p_gl_rend_state& p_gl_rend_st,
|
||||
const struct uniform_value& shader_flags, shader_set_data* set, uint32_t sub_index);
|
||||
|
||||
static bool parse_define(const char* data, std::string& temp, bool vulkan = false);
|
||||
static bool parse_define(const char* data, int32_t num_uniform,
|
||||
int32_t* uniform_value, std::string& temp, bool vulkan = false);
|
||||
static char* parse_include(char* data, farc* f);
|
||||
static void unbind();
|
||||
static void unbind(struct p_gl_rend_state& p_gl_rend_st);
|
||||
};
|
||||
|
||||
struct shader_set_data {
|
||||
size_t size;
|
||||
shader* shaders;
|
||||
GLuint curr_program;
|
||||
GLboolean primitive_restart;
|
||||
GLuint primitive_restart_index;
|
||||
|
||||
PFNSHADERGETINDEXFUNCPROC get_index_by_name_func;
|
||||
PFNSHADERGETNAMEFUNCPROC get_name_by_index_func;
|
||||
|
||||
shader_set_data();
|
||||
|
||||
void disable_primitive_restart();
|
||||
void draw_arrays(GLenum mode, GLint first, GLsizei count);
|
||||
void draw_elements(GLenum mode,
|
||||
GLsizei count, GLenum type, const void* indices);
|
||||
void draw_range_elements(GLenum mode,
|
||||
GLuint start, GLuint end, GLsizei count, GLenum type, const void* indices);
|
||||
void enable_primitive_restart();
|
||||
int32_t get_index_by_name(const char* name);
|
||||
const char* get_name_by_index(int32_t index);
|
||||
void load(farc* f, bool ignore_cache, const char* name,
|
||||
const shader_table* shaders_table, const size_t size,
|
||||
const shader_bind_func* bind_func_table, const size_t bind_func_table_size,
|
||||
PFNSHADERGETINDEXFUNCPROC get_index_by_name, PFNSHADERGETNAMEFUNCPROC get_name_by_index);
|
||||
void set(uint32_t index);
|
||||
void set(struct p_gl_rend_state& p_gl_rend_st, struct uniform_value& shader_flags, uint32_t index);
|
||||
void unload();
|
||||
};
|
||||
|
||||
+131
-99
@@ -2573,23 +2573,39 @@ const size_t shader_ft_table_size =
|
||||
sizeof(shader_ft_table) / sizeof(shader_table);
|
||||
|
||||
static void glass_eye_calc(glass_eye_struct* glass_eye);
|
||||
static void glass_eye_set(glass_eye_struct* glass_eye);
|
||||
static void shader_bind_blinn(shader_set_data* set, shader* shad);
|
||||
static void shader_bind_cloth(shader_set_data* set, shader* shad);
|
||||
static void shader_bind_hair(shader_set_data* set, shader* shad);
|
||||
static void shader_bind_glass_eye(shader_set_data* set, shader* shad);
|
||||
static void shader_bind_tone_map(shader_set_data* set, shader* shad);
|
||||
static void shader_bind_sss_filter(shader_set_data* set, shader* shad);
|
||||
static void shader_bind_esm_filter(shader_set_data* set, shader* shad);
|
||||
static void shader_bind_reduce_tex(shader_set_data* set, shader* shad);
|
||||
static void shader_bind_magnify(shader_set_data* set, shader* shad);
|
||||
static void shader_bind_mlaa(shader_set_data* set, shader* shad);
|
||||
static void shader_bind_exposure(shader_set_data* set, shader* shad);
|
||||
static void shader_bind_gauss(shader_set_data* set, shader* shad);
|
||||
static void shader_bind_snow_particle(shader_set_data* set, shader* shad);
|
||||
static void shader_bind_star(shader_set_data* set, shader* shad);
|
||||
static void shader_bind_imgfilter(shader_set_data* set, shader* shad);
|
||||
static void shader_bind_dof(shader_set_data* set, shader* shad);
|
||||
static void glass_eye_set(p_gl_rend_state& p_gl_rend_st, glass_eye_struct* glass_eye);
|
||||
static void shader_bind_blinn(p_gl_rend_state& p_gl_rend_st,
|
||||
uniform_value& shader_flags, shader_set_data* set, shader* shad);
|
||||
static void shader_bind_cloth(p_gl_rend_state& p_gl_rend_st,
|
||||
uniform_value& shader_flags, shader_set_data* set, shader* shad);
|
||||
static void shader_bind_hair(p_gl_rend_state& p_gl_rend_st,
|
||||
uniform_value& shader_flags, shader_set_data* set, shader* shad);
|
||||
static void shader_bind_glass_eye(p_gl_rend_state& p_gl_rend_st,
|
||||
uniform_value& shader_flags, shader_set_data* set, shader* shad);
|
||||
static void shader_bind_tone_map(p_gl_rend_state& p_gl_rend_st,
|
||||
uniform_value& shader_flags, shader_set_data* set, shader* shad);
|
||||
static void shader_bind_sss_filter(p_gl_rend_state& p_gl_rend_st,
|
||||
uniform_value& shader_flags, shader_set_data* set, shader* shad);
|
||||
static void shader_bind_esm_filter(p_gl_rend_state& p_gl_rend_st,
|
||||
uniform_value& shader_flags, shader_set_data* set, shader* shad);
|
||||
static void shader_bind_reduce_tex(p_gl_rend_state& p_gl_rend_st,
|
||||
uniform_value& shader_flags, shader_set_data* set, shader* shad);
|
||||
static void shader_bind_magnify(p_gl_rend_state& p_gl_rend_st,
|
||||
uniform_value& shader_flags, shader_set_data* set, shader* shad);
|
||||
static void shader_bind_mlaa(p_gl_rend_state& p_gl_rend_st,
|
||||
uniform_value& shader_flags, shader_set_data* set, shader* shad);
|
||||
static void shader_bind_exposure(p_gl_rend_state& p_gl_rend_st,
|
||||
uniform_value& shader_flags, shader_set_data* set, shader* shad);
|
||||
static void shader_bind_gauss(p_gl_rend_state& p_gl_rend_st,
|
||||
uniform_value& shader_flags, shader_set_data* set, shader* shad);
|
||||
static void shader_bind_snow_particle(p_gl_rend_state& p_gl_rend_st,
|
||||
uniform_value& shader_flags, shader_set_data* set, shader* shad);
|
||||
static void shader_bind_star(p_gl_rend_state& p_gl_rend_st,
|
||||
uniform_value& shader_flags, shader_set_data* set, shader* shad);
|
||||
static void shader_bind_imgfilter(p_gl_rend_state& p_gl_rend_st,
|
||||
uniform_value& shader_flags, shader_set_data* set, shader* shad);
|
||||
static void shader_bind_dof(p_gl_rend_state& p_gl_rend_st,
|
||||
uniform_value& shader_flags, shader_set_data* set, shader* shad);
|
||||
|
||||
const shader_bind_func shader_ft_bind_func_table[] = {
|
||||
{
|
||||
@@ -2729,7 +2745,7 @@ static void glass_eye_calc(glass_eye_struct* glass_eye) {
|
||||
glass_eye->tex_offset.w = 0.0f;
|
||||
}
|
||||
|
||||
static void glass_eye_set(glass_eye_struct* glass_eye) {
|
||||
static void glass_eye_set(p_gl_rend_state& p_gl_rend_st, glass_eye_struct* glass_eye) {
|
||||
glass_eye_batch_shader_data glass_eye_batch = {};
|
||||
|
||||
vec3 ellipsoid_radius = glass_eye->cornea_radius * glass_eye->cornea_radius;
|
||||
@@ -2776,228 +2792,244 @@ static void glass_eye_set(glass_eye_struct* glass_eye) {
|
||||
glass_eye_batch.g_tex_scale.w = glass_eye->lens_depth;
|
||||
|
||||
extern render_context* rctx_ptr;
|
||||
rctx_ptr->glass_eye_batch_ubo.WriteMemory(glass_eye_batch);
|
||||
rctx_ptr->glass_eye_batch_ubo.Bind(3);
|
||||
rctx_ptr->glass_eye_batch_ubo.WriteMemory(p_gl_rend_st, glass_eye_batch);
|
||||
p_gl_rend_st.bind_uniform_buffer_base(3, rctx_ptr->glass_eye_batch_ubo);
|
||||
}
|
||||
|
||||
static void shader_bind_blinn(shader_set_data* set, shader* shad) {
|
||||
shad->bind(set, uniform_value[U_NORMAL]
|
||||
static void shader_bind_blinn(p_gl_rend_state& p_gl_rend_st,
|
||||
uniform_value& shader_flags, shader_set_data* set, shader* shad) {
|
||||
shad->bind(p_gl_rend_st, shader_flags, set, shader_flags.arr[U_NORMAL]
|
||||
? SHADER_FT_SUB_BLINN_FRAG : SHADER_FT_SUB_BLINN_VERT);
|
||||
}
|
||||
|
||||
static void shader_bind_cloth(shader_set_data* set, shader* shad) {
|
||||
shad->bind(set, uniform_value[U_NPR] ? SHADER_FT_SUB_CLOTH_NPR1
|
||||
: (uniform_value[U_ANISO] ? SHADER_FT_SUB_CLOTH_ANISO : SHADER_FT_SUB_CLOTH_DEFAULT));
|
||||
static void shader_bind_cloth(p_gl_rend_state& p_gl_rend_st,
|
||||
uniform_value& shader_flags, shader_set_data* set, shader* shad) {
|
||||
shad->bind(p_gl_rend_st, shader_flags, set, shader_flags.arr[U_NPR] ? SHADER_FT_SUB_CLOTH_NPR1
|
||||
: (shader_flags.arr[U_ANISO] ? SHADER_FT_SUB_CLOTH_ANISO : SHADER_FT_SUB_CLOTH_DEFAULT));
|
||||
}
|
||||
|
||||
static void shader_bind_hair(shader_set_data* set, shader* shad) {
|
||||
shad->bind(set, uniform_value[U_NPR] ? SHADER_FT_SUB_HAIR_NPR1 : SHADER_FT_SUB_HAIR_DEFAULT);
|
||||
static void shader_bind_hair(p_gl_rend_state& p_gl_rend_st,
|
||||
uniform_value& shader_flags, shader_set_data* set, shader* shad) {
|
||||
shad->bind(p_gl_rend_st, shader_flags, set, shader_flags.arr[U_NPR] ? SHADER_FT_SUB_HAIR_NPR1 : SHADER_FT_SUB_HAIR_DEFAULT);
|
||||
}
|
||||
|
||||
static void shader_bind_glass_eye(shader_set_data* set, shader* shad) {
|
||||
uniform_value[U_EYE_LENS] = 0;
|
||||
if (set->shaders[SHADER_FT_GLASEYE].bind(set, SHADER_FT_SUB_GLASS_EYE) >= 0) {
|
||||
static void shader_bind_glass_eye(p_gl_rend_state& p_gl_rend_st,
|
||||
uniform_value& shader_flags, shader_set_data* set, shader* shad) {
|
||||
shader_flags.arr[U_EYE_LENS] = 0;
|
||||
if (set->shaders[SHADER_FT_GLASEYE].bind(p_gl_rend_st, shader_flags, set, SHADER_FT_SUB_GLASS_EYE) >= 0) {
|
||||
glass_eye_calc(&glass_eye);
|
||||
glass_eye_set(&glass_eye);
|
||||
glass_eye_set(p_gl_rend_st, &glass_eye);
|
||||
}
|
||||
}
|
||||
|
||||
static void shader_bind_tone_map(shader_set_data* set, shader* shad) {
|
||||
shad->bind(set, uniform_value[U_NPR] == 1
|
||||
static void shader_bind_tone_map(p_gl_rend_state& p_gl_rend_st,
|
||||
uniform_value& shader_flags, shader_set_data* set, shader* shad) {
|
||||
shad->bind(p_gl_rend_st, shader_flags, set, shader_flags.arr[U_NPR] == 1
|
||||
? SHADER_FT_SUB_TONEMAP_NPR1 : SHADER_FT_SUB_TONEMAP);
|
||||
}
|
||||
|
||||
static void shader_bind_sss_filter(shader_set_data* set, shader* shad) {
|
||||
switch (uniform_value[U_SSS_FILTER]) {
|
||||
static void shader_bind_sss_filter(p_gl_rend_state& p_gl_rend_st,
|
||||
uniform_value& shader_flags, shader_set_data* set, shader* shad) {
|
||||
switch (shader_flags.arr[U_SSS_FILTER]) {
|
||||
case 0:
|
||||
shad->bind(set, uniform_value[U_NPR]
|
||||
shad->bind(p_gl_rend_st, shader_flags, set, shader_flags.arr[U_NPR]
|
||||
? SHADER_FT_SUB_SSS_FILTER_MIN_NPR : SHADER_FT_SUB_SSS_FILTER_MIN);
|
||||
break;
|
||||
case 3:
|
||||
shad->bind(set, SHADER_FT_SUB_SSS_FILTER_GAUSS_2D);
|
||||
shad->bind(p_gl_rend_st, shader_flags, set, SHADER_FT_SUB_SSS_FILTER_GAUSS_2D);
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
static void shader_bind_esm_filter(shader_set_data* set, shader* shad) {
|
||||
switch (uniform_value[U_ESM_FILTER]) {
|
||||
static void shader_bind_esm_filter(p_gl_rend_state& p_gl_rend_st,
|
||||
uniform_value& shader_flags, shader_set_data* set, shader* shad) {
|
||||
switch (shader_flags.arr[U_ESM_FILTER]) {
|
||||
case 0:
|
||||
shad->bind(set, SHADER_FT_SUB_ESM_FILTER_MIN);
|
||||
shad->bind(p_gl_rend_st, shader_flags, set, SHADER_FT_SUB_ESM_FILTER_MIN);
|
||||
break;
|
||||
case 1:
|
||||
shad->bind(set, SHADER_FT_SUB_ESM_FILTER_EROSION);
|
||||
shad->bind(p_gl_rend_st, shader_flags, set, SHADER_FT_SUB_ESM_FILTER_EROSION);
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
static void shader_bind_reduce_tex(shader_set_data* set, shader* shad) {
|
||||
switch (uniform_value[U_REDUCE]) {
|
||||
static void shader_bind_reduce_tex(p_gl_rend_state& p_gl_rend_st,
|
||||
uniform_value& shader_flags, shader_set_data* set, shader* shad) {
|
||||
switch (shader_flags.arr[U_REDUCE]) {
|
||||
case 0:
|
||||
switch (uniform_value[U_ALPHA_MASK]) {
|
||||
switch (shader_flags.arr[U_ALPHA_MASK]) {
|
||||
case 0:
|
||||
shad->bind(set, SHADER_FT_SUB_REDUCE_TEX_REDUCE_2);
|
||||
shad->bind(p_gl_rend_st, shader_flags, set, SHADER_FT_SUB_REDUCE_TEX_REDUCE_2);
|
||||
break;
|
||||
default:
|
||||
shad->bind(set, SHADER_FT_SUB_REDUCE_TEX_REDUCE_2_ALPHAMASK);
|
||||
shad->bind(p_gl_rend_st, shader_flags, set, SHADER_FT_SUB_REDUCE_TEX_REDUCE_2_ALPHAMASK);
|
||||
break;
|
||||
}
|
||||
break;
|
||||
case 1:
|
||||
switch (uniform_value[U_ALPHA_MASK]) {
|
||||
switch (shader_flags.arr[U_ALPHA_MASK]) {
|
||||
case 0:
|
||||
shad->bind(set, SHADER_FT_SUB_REDUCE_TEX_REDUCE_4);
|
||||
shad->bind(p_gl_rend_st, shader_flags, set, SHADER_FT_SUB_REDUCE_TEX_REDUCE_4);
|
||||
break;
|
||||
}
|
||||
break;
|
||||
case 3:
|
||||
switch (uniform_value[U_ALPHA_MASK]) {
|
||||
switch (shader_flags.arr[U_ALPHA_MASK]) {
|
||||
case 0:
|
||||
shad->bind(set, SHADER_FT_SUB_REDUCE_TEX_REDUCE_4_EXTRACT);
|
||||
shad->bind(p_gl_rend_st, shader_flags, set, SHADER_FT_SUB_REDUCE_TEX_REDUCE_4_EXTRACT);
|
||||
break;
|
||||
}
|
||||
break;
|
||||
case 4:
|
||||
switch (uniform_value[U_ALPHA_MASK]) {
|
||||
switch (shader_flags.arr[U_ALPHA_MASK]) {
|
||||
case 0:
|
||||
shad->bind(set, SHADER_FT_SUB_GHOST);
|
||||
shad->bind(p_gl_rend_st, shader_flags, set, SHADER_FT_SUB_GHOST);
|
||||
break;
|
||||
}
|
||||
break;
|
||||
case 5:
|
||||
switch (uniform_value[U_ALPHA_MASK]) {
|
||||
switch (shader_flags.arr[U_ALPHA_MASK]) {
|
||||
case 0:
|
||||
shad->bind(set, SHADER_FT_SUB_REDUCE_TEX_REDUCE_COMPOSITE_2);
|
||||
shad->bind(p_gl_rend_st, shader_flags, set, SHADER_FT_SUB_REDUCE_TEX_REDUCE_COMPOSITE_2);
|
||||
break;
|
||||
}
|
||||
break;
|
||||
case 6:
|
||||
switch (uniform_value[U_ALPHA_MASK]) {
|
||||
switch (shader_flags.arr[U_ALPHA_MASK]) {
|
||||
case 0:
|
||||
shad->bind(set, SHADER_FT_SUB_REDUCE_TEX_REDUCE_COMPOSITE_BLUR);
|
||||
shad->bind(p_gl_rend_st, shader_flags, set, SHADER_FT_SUB_REDUCE_TEX_REDUCE_COMPOSITE_BLUR);
|
||||
break;
|
||||
}
|
||||
break;
|
||||
case 7:
|
||||
switch (uniform_value[U_ALPHA_MASK]) {
|
||||
switch (shader_flags.arr[U_ALPHA_MASK]) {
|
||||
case 0:
|
||||
shad->bind(set, SHADER_FT_SUB_REDUCE_TEX_REDUCE_COMPOSITE_4);
|
||||
shad->bind(p_gl_rend_st, shader_flags, set, SHADER_FT_SUB_REDUCE_TEX_REDUCE_COMPOSITE_4);
|
||||
break;
|
||||
}
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
static void shader_bind_magnify(shader_set_data* set, shader* shad) {
|
||||
switch (uniform_value[U_MAGNIFY]) {
|
||||
static void shader_bind_magnify(p_gl_rend_state& p_gl_rend_st,
|
||||
uniform_value& shader_flags, shader_set_data* set, shader* shad) {
|
||||
switch (shader_flags.arr[U_MAGNIFY]) {
|
||||
case 0:
|
||||
shad->bind(set, SHADER_FT_SUB_MAGNIFY_LINEAR);
|
||||
shad->bind(p_gl_rend_st, shader_flags, set, SHADER_FT_SUB_MAGNIFY_LINEAR);
|
||||
break;
|
||||
case 2:
|
||||
shad->bind(set, SHADER_FT_SUB_MAGNIFY_DIFF);
|
||||
shad->bind(p_gl_rend_st, shader_flags, set, SHADER_FT_SUB_MAGNIFY_DIFF);
|
||||
break;
|
||||
case 3:
|
||||
shad->bind(set, SHADER_FT_SUB_MAGNIFY_DIFF2);
|
||||
shad->bind(p_gl_rend_st, shader_flags, set, SHADER_FT_SUB_MAGNIFY_DIFF2);
|
||||
break;
|
||||
case 4:
|
||||
shad->bind(set, SHADER_FT_SUB_MAGNIFY_CONE);
|
||||
shad->bind(p_gl_rend_st, shader_flags, set, SHADER_FT_SUB_MAGNIFY_CONE);
|
||||
break;
|
||||
case 5:
|
||||
shad->bind(set, SHADER_FT_SUB_MAGNIFY_CONE2);
|
||||
shad->bind(p_gl_rend_st, shader_flags, set, SHADER_FT_SUB_MAGNIFY_CONE2);
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
static void shader_bind_mlaa(shader_set_data* set, shader* shad) {
|
||||
switch (uniform_value[U_MLAA]) {
|
||||
static void shader_bind_mlaa(p_gl_rend_state& p_gl_rend_st,
|
||||
uniform_value& shader_flags, shader_set_data* set, shader* shad) {
|
||||
switch (shader_flags.arr[U_MLAA]) {
|
||||
case 0:
|
||||
shad->bind(set, SHADER_FT_SUB_MLAA_EDGE);
|
||||
shad->bind(p_gl_rend_st, shader_flags, set, SHADER_FT_SUB_MLAA_EDGE);
|
||||
break;
|
||||
case 1:
|
||||
shad->bind(set, SHADER_FT_SUB_MLAA_AREA);
|
||||
shad->bind(p_gl_rend_st, shader_flags, set, SHADER_FT_SUB_MLAA_AREA);
|
||||
break;
|
||||
case 2:
|
||||
shad->bind(set, SHADER_FT_SUB_MLAA_BLEND);
|
||||
shad->bind(p_gl_rend_st, shader_flags, set, SHADER_FT_SUB_MLAA_BLEND);
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
static void shader_bind_exposure(shader_set_data* set, shader* shad) {
|
||||
switch (uniform_value[U_EXPOSURE]) {
|
||||
static void shader_bind_exposure(p_gl_rend_state& p_gl_rend_st,
|
||||
uniform_value& shader_flags, shader_set_data* set, shader* shad) {
|
||||
switch (shader_flags.arr[U_EXPOSURE]) {
|
||||
case 0:
|
||||
shad->bind(set, SHADER_FT_SUB_EXPOSURE_MINIFY);
|
||||
shad->bind(p_gl_rend_st, shader_flags, set, SHADER_FT_SUB_EXPOSURE_MINIFY);
|
||||
break;
|
||||
case 1:
|
||||
shad->bind(set, SHADER_FT_SUB_EXPOSURE_MEASURE);
|
||||
shad->bind(p_gl_rend_st, shader_flags, set, SHADER_FT_SUB_EXPOSURE_MEASURE);
|
||||
break;
|
||||
case 2:
|
||||
shad->bind(set, SHADER_FT_SUB_EXPOSURE_AVERAGE);
|
||||
shad->bind(p_gl_rend_st, shader_flags, set, SHADER_FT_SUB_EXPOSURE_AVERAGE);
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
static void shader_bind_gauss(shader_set_data* set, shader* shad) {
|
||||
switch (uniform_value[U_GAUSS]) {
|
||||
static void shader_bind_gauss(p_gl_rend_state& p_gl_rend_st,
|
||||
uniform_value& shader_flags, shader_set_data* set, shader* shad) {
|
||||
switch (shader_flags.arr[U_GAUSS]) {
|
||||
case 0:
|
||||
shad->bind(set, SHADER_FT_SUB_PP_GAUSS_USUAL);
|
||||
shad->bind(p_gl_rend_st, shader_flags, set, SHADER_FT_SUB_PP_GAUSS_USUAL);
|
||||
break;
|
||||
case 1:
|
||||
shad->bind(set, SHADER_FT_SUB_PP_GAUSS_CONE);
|
||||
shad->bind(p_gl_rend_st, shader_flags, set, SHADER_FT_SUB_PP_GAUSS_CONE);
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
static void shader_bind_snow_particle(shader_set_data* set, shader* shad) {
|
||||
switch (uniform_value[U_SNOW_PARTICLE]) {
|
||||
static void shader_bind_snow_particle(p_gl_rend_state& p_gl_rend_st,
|
||||
uniform_value& shader_flags, shader_set_data* set, shader* shad) {
|
||||
switch (shader_flags.arr[U_SNOW_PARTICLE]) {
|
||||
case 0:
|
||||
shad->bind(set, SHADER_FT_SUB_SNOW_PARTICLE_CPU);
|
||||
shad->bind(p_gl_rend_st, shader_flags, set, SHADER_FT_SUB_SNOW_PARTICLE_CPU);
|
||||
break;
|
||||
case 1:
|
||||
shad->bind(set, SHADER_FT_SUB_SNOW_PARTICLE);
|
||||
shad->bind(p_gl_rend_st, shader_flags, set, SHADER_FT_SUB_SNOW_PARTICLE);
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
static void shader_bind_star(shader_set_data* set, shader* shad) {
|
||||
switch (uniform_value[U_STAR]) {
|
||||
static void shader_bind_star(p_gl_rend_state& p_gl_rend_st,
|
||||
uniform_value& shader_flags, shader_set_data* set, shader* shad) {
|
||||
switch (shader_flags.arr[U_STAR]) {
|
||||
case 0:
|
||||
shad->bind(set, SHADER_FT_SUB_STAR);
|
||||
shad->bind(p_gl_rend_st, shader_flags, set, SHADER_FT_SUB_STAR);
|
||||
break;
|
||||
case 1:
|
||||
shad->bind(set, SHADER_FT_SUB_STAR_MILKY_WAY);
|
||||
shad->bind(p_gl_rend_st, shader_flags, set, SHADER_FT_SUB_STAR_MILKY_WAY);
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
static void shader_bind_imgfilter(shader_set_data* set, shader* shad) {
|
||||
switch (uniform_value[U_IMAGE_FILTER]) {
|
||||
static void shader_bind_imgfilter(p_gl_rend_state& p_gl_rend_st,
|
||||
uniform_value& shader_flags, shader_set_data* set, shader* shad) {
|
||||
switch (shader_flags.arr[U_IMAGE_FILTER]) {
|
||||
case 0:
|
||||
shad->bind(set, SHADER_FT_SUB_BOX4);
|
||||
shad->bind(p_gl_rend_st, shader_flags, set, SHADER_FT_SUB_BOX4);
|
||||
break;
|
||||
case 1:
|
||||
shad->bind(set, SHADER_FT_SUB_BOX8);
|
||||
shad->bind(p_gl_rend_st, shader_flags, set, SHADER_FT_SUB_BOX8);
|
||||
break;
|
||||
case 5:
|
||||
shad->bind(set, SHADER_FT_SUB_COPY);
|
||||
shad->bind(p_gl_rend_st, shader_flags, set, SHADER_FT_SUB_COPY);
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
static void shader_bind_dof(shader_set_data* set, shader* shad) {
|
||||
switch (uniform_value[U_DOF_STAGE]) {
|
||||
static void shader_bind_dof(p_gl_rend_state& p_gl_rend_st,
|
||||
uniform_value& shader_flags, shader_set_data* set, shader* shad) {
|
||||
switch (shader_flags.arr[U_DOF_STAGE]) {
|
||||
case 0:
|
||||
shad->bind(set, SHADER_FT_SUB_DOF_RENDER_TILE);
|
||||
shad->bind(p_gl_rend_st, shader_flags, set, SHADER_FT_SUB_DOF_RENDER_TILE);
|
||||
break;
|
||||
case 1:
|
||||
shad->bind(set, SHADER_FT_SUB_DOF_GATHER_TILE);
|
||||
shad->bind(p_gl_rend_st, shader_flags, set, SHADER_FT_SUB_DOF_GATHER_TILE);
|
||||
break;
|
||||
case 2:
|
||||
shad->bind(set, SHADER_FT_SUB_DOF_DOWNSAMPLE);
|
||||
shad->bind(p_gl_rend_st, shader_flags, set, SHADER_FT_SUB_DOF_DOWNSAMPLE);
|
||||
break;
|
||||
case 3:
|
||||
shad->bind(set, SHADER_FT_SUB_DOF_MAIN_FILTER);
|
||||
shad->bind(p_gl_rend_st, shader_flags, set, SHADER_FT_SUB_DOF_MAIN_FILTER);
|
||||
break;
|
||||
case 4:
|
||||
shad->bind(set, SHADER_FT_SUB_DOF_UPSAMPLE);
|
||||
shad->bind(p_gl_rend_st, shader_flags, set, SHADER_FT_SUB_DOF_UPSAMPLE);
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
+31
-6
@@ -4,6 +4,7 @@
|
||||
*/
|
||||
|
||||
#include "shadow.hpp"
|
||||
#include "gl_state.hpp"
|
||||
#include "render_context.hpp"
|
||||
|
||||
Shadow* shadow_ptr;
|
||||
@@ -30,14 +31,38 @@ Shadow::~Shadow() {
|
||||
free();
|
||||
}
|
||||
|
||||
void Shadow::clear_textures() {
|
||||
void Shadow::calc_proj_view_mat(cam_data& cam, const vec3& view_point,
|
||||
const vec3& interest, float_t range, float_t offset, float_t scale) {
|
||||
cam.set_view_point(view_point);
|
||||
cam.set_interest(interest);
|
||||
|
||||
vec3 up = { 0.0f, 1.0f, 0.0f };
|
||||
const vec3 dir = interest - view_point;
|
||||
if (vec3::length_squared(dir) <= 0.000001f) {
|
||||
up.x = 0.0f;
|
||||
up.y = 0.0f;
|
||||
if (dir.z < 0.0f)
|
||||
up.z = 1.0f;
|
||||
else
|
||||
up.z = -1.0f;
|
||||
}
|
||||
cam.set_up(up);
|
||||
|
||||
cam.calc_view_mat();
|
||||
cam.set_min_distance(z_near);
|
||||
cam.set_max_distance(z_far);
|
||||
cam.calc_ortho_proj_mat(-range, range, -range, range, scale, { offset, 0.0f });
|
||||
cam.calc_view_proj_mat();
|
||||
}
|
||||
|
||||
void Shadow::clear_textures(p_gl_rend_state& p_gl_rend_st) {
|
||||
for (int32_t i = 1; i < 3; i++)
|
||||
for (int32_t j = 0; j < 4; j++) {
|
||||
curr_render_textures[i]->Bind(j);
|
||||
curr_render_textures[i]->Bind(p_gl_rend_st, j);
|
||||
glClearColor(1.0f, 1.0f, 1.0f, 1.0f);
|
||||
glClear(GL_COLOR_BUFFER_BIT);
|
||||
}
|
||||
gl_rend_state.bind_framebuffer(0);
|
||||
p_gl_rend_st.bind_framebuffer(0);
|
||||
}
|
||||
|
||||
void Shadow::ctrl() {
|
||||
@@ -101,7 +126,7 @@ int32_t Shadow::init() {
|
||||
return -1;
|
||||
|
||||
for (int32_t i = 0; i < 3; i++) {
|
||||
glBindTexture(GL_TEXTURE_2D, render_textures[i].GetColorTex());
|
||||
gl_state.bind_texture_2d(render_textures[i].GetColorTex());
|
||||
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_CLAMP_TO_BORDER);
|
||||
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_CLAMP_TO_BORDER);
|
||||
glTexParameterf(GL_TEXTURE_2D, GL_TEXTURE_MAX_ANISOTROPY_EXT, 16.0f);
|
||||
@@ -109,10 +134,10 @@ int32_t Shadow::init() {
|
||||
glTexParameterfv(GL_TEXTURE_2D, GL_TEXTURE_BORDER_COLOR, (GLfloat*)&border_color);
|
||||
}
|
||||
|
||||
glBindTexture(GL_TEXTURE_2D, render_textures[0].GetDepthTex());
|
||||
gl_state.bind_texture_2d(render_textures[0].GetDepthTex());
|
||||
GLint swizzle[] = { GL_RED, GL_RED, GL_RED, GL_ONE };
|
||||
glTexParameteriv(GL_TEXTURE_2D, GL_TEXTURE_SWIZZLE_RGBA, swizzle);
|
||||
glBindTexture(GL_TEXTURE_2D, 0);
|
||||
gl_state.bind_texture_2d(0);
|
||||
gl_get_error_print();
|
||||
return 0;
|
||||
}
|
||||
|
||||
+3
-1
@@ -59,7 +59,9 @@ struct Shadow {
|
||||
Shadow();
|
||||
virtual ~Shadow();
|
||||
|
||||
void clear_textures();
|
||||
void calc_proj_view_mat(struct cam_data& cam, const vec3& view_point,
|
||||
const vec3& interest, float_t range, float_t offset, float_t scale);
|
||||
void clear_textures(struct p_gl_rend_state& p_gl_rend_st);
|
||||
void ctrl();
|
||||
void free();
|
||||
float_t get_shadow_range();
|
||||
|
||||
+3
-3
@@ -6,11 +6,11 @@
|
||||
#include "shared.hpp"
|
||||
#include "gl_rend_state.hpp"
|
||||
|
||||
void fbo_blit(GLuint src_fbo, GLuint dst_fbo,
|
||||
void fbo_blit(p_gl_rend_state& p_gl_rend_st, GLuint src_fbo, GLuint dst_fbo,
|
||||
GLint src_x, GLint src_y, GLint src_width, GLint src_height,
|
||||
GLint dst_x, GLint dst_y, GLint dst_width, GLint dst_height, GLbitfield mask, GLenum filter) {
|
||||
gl_rend_state.bind_read_framebuffer(src_fbo);
|
||||
gl_rend_state.bind_draw_framebuffer(dst_fbo);
|
||||
p_gl_rend_st.bind_read_framebuffer(src_fbo);
|
||||
p_gl_rend_st.bind_draw_framebuffer(dst_fbo);
|
||||
glBlitFramebuffer(src_x, src_y, src_x + src_width, src_y + src_height,
|
||||
dst_x, dst_y, dst_x + dst_width, dst_y + dst_height, mask, filter);
|
||||
}
|
||||
|
||||
+1
-1
@@ -18,7 +18,7 @@ enum blur_filter_mode {
|
||||
BLUR_FILTER_MAX = 0x04,
|
||||
};
|
||||
|
||||
extern void fbo_blit(GLuint src_fbo, GLuint dst_fbo,
|
||||
extern void fbo_blit(struct p_gl_rend_state& p_gl_rend_st, GLuint src_fbo, GLuint dst_fbo,
|
||||
GLint src_x, GLint src_y, GLint src_width, GLint src_height,
|
||||
GLint dst_x, GLint dst_y, GLint dst_width, GLint dst_height, GLbitfield mask, GLenum filter);
|
||||
|
||||
|
||||
+91
-81
@@ -12,6 +12,8 @@
|
||||
#include "data.hpp"
|
||||
#include "file_handler.hpp"
|
||||
#include "gl.hpp"
|
||||
#include "gl_state.hpp"
|
||||
#include "render_context.hpp"
|
||||
#include "shader_ft.hpp"
|
||||
#include "texture.hpp"
|
||||
|
||||
@@ -158,7 +160,8 @@ namespace spr {
|
||||
uint32_t AddSetModern();
|
||||
void AddSprSets(const sprite_database* spr_db);
|
||||
void Clear();
|
||||
void Draw(int32_t index, bool font, texture* overlay_tex, const mat4& vp);
|
||||
void Draw(render_data_context& rend_data_ctx,
|
||||
int32_t index, bool font, texture* overlay_tex, const mat4& vp);
|
||||
SprSet* GetSet(uint32_t index);
|
||||
bool GetSetReady(uint32_t index);
|
||||
uint32_t GetSetSpriteNum(uint32_t index);
|
||||
@@ -187,12 +190,14 @@ namespace spr {
|
||||
static void add_draw_sprite(spr::SprArgs** args_array, int32_t count, bool font,
|
||||
spr::SprArgsInner& args_inner, std::vector<sprite_draw_param>& draw_param_buffer,
|
||||
std::vector<sprite_draw_vertex>& vertex_buffer, std::vector<uint32_t>& index_buffer);
|
||||
static void draw_sprite(spr::SpriteManager* sprite_manager, render_context* rctx, const SprArgs& args,
|
||||
static void draw_sprite(render_data_context& rend_data_ctx,
|
||||
spr::SpriteManager* sprite_manager, const SprArgs& args,
|
||||
const mat4& mat, int32_t x_min, int32_t y_min, int32_t x_max, int32_t y_max, texture* overlay_tex);
|
||||
static void draw_sprite_begin(render_context* rctx);
|
||||
static void draw_sprite_copy_overlay_texture(render_context* rctx, const SprArgs& args, const mat4& mat,
|
||||
const vec3* vtx, int32_t overlay_x_min, int32_t overlay_y_min, int32_t overlay_x_max, int32_t overlay_y_max);
|
||||
static void draw_sprite_end();
|
||||
static void draw_sprite_begin(render_data_context& rend_data_ctx);
|
||||
static void draw_sprite_copy_overlay_texture(
|
||||
render_data_context& rend_data_ctx, const SprArgs& args, const mat4& mat, const vec3* vtx,
|
||||
int32_t overlay_x_min, int32_t overlay_y_min, int32_t overlay_x_max, int32_t overlay_y_max);
|
||||
static void draw_sprite_end(render_data_context& rend_data_ctx);
|
||||
static void draw_sprite_scale(spr::SprArgs* args);
|
||||
}
|
||||
|
||||
@@ -476,8 +481,9 @@ void sprite_manager_clear() {
|
||||
sprite_manager->Clear();
|
||||
}
|
||||
|
||||
void sprite_manager_draw(int32_t index, bool font, texture* overlay_tex, const mat4& vp) {
|
||||
sprite_manager->Draw(index, font, overlay_tex, vp);
|
||||
void sprite_manager_draw(render_data_context& rend_data_ctx,
|
||||
int32_t index, bool font, texture* overlay_tex, const mat4& vp) {
|
||||
sprite_manager->Draw(rend_data_ctx, index, font, overlay_tex, vp);
|
||||
}
|
||||
|
||||
int32_t sprite_manager_get_index() {
|
||||
@@ -607,14 +613,14 @@ void sprite_manager_free() {
|
||||
namespace spr {
|
||||
SpriteManager::RenderData::RenderData() : vao() {
|
||||
glGenVertexArrays(1, &vao);
|
||||
glBindVertexArray(vao);
|
||||
gl_state.bind_vertex_array(vao);
|
||||
|
||||
vbo_vertex_count = 4096;
|
||||
|
||||
static const GLsizei buffer_size = sizeof(sprite_draw_vertex);
|
||||
|
||||
vbo.Create(buffer_size * vbo_vertex_count);
|
||||
glBindBuffer(GL_ARRAY_BUFFER, vbo);
|
||||
vbo.Create(gl_state, buffer_size * vbo_vertex_count);
|
||||
gl_state.bind_array_buffer(vbo);
|
||||
|
||||
glEnableVertexAttribArray(0);
|
||||
glVertexAttribPointer(0, 3, GL_FLOAT, GL_FALSE, buffer_size,
|
||||
@@ -628,12 +634,12 @@ namespace spr {
|
||||
|
||||
ebo_index_count = 4096;
|
||||
|
||||
ebo.Create(sizeof(uint32_t) * ebo_index_count);
|
||||
glBindBuffer(GL_ELEMENT_ARRAY_BUFFER, ebo);
|
||||
ebo.Create(gl_state, sizeof(uint32_t) * ebo_index_count);
|
||||
gl_state.bind_element_array_buffer(ebo);
|
||||
|
||||
glBindBuffer(GL_ARRAY_BUFFER, 0);
|
||||
glBindVertexArray(0);
|
||||
glBindBuffer(GL_ELEMENT_ARRAY_BUFFER, 0);
|
||||
gl_state.bind_array_buffer(0);
|
||||
gl_state.bind_vertex_array(0);
|
||||
gl_state.bind_element_array_buffer(0);
|
||||
}
|
||||
|
||||
SpriteManager::RenderData::~RenderData() {
|
||||
@@ -661,10 +667,10 @@ namespace spr {
|
||||
|
||||
vbo.Destroy();
|
||||
|
||||
glBindVertexArray(vao);
|
||||
gl_state.bind_vertex_array(vao);
|
||||
|
||||
vbo.Create(buffer_size * vbo_vertex_count);
|
||||
glBindBuffer(GL_ARRAY_BUFFER, vbo);
|
||||
vbo.Create(gl_state, buffer_size * vbo_vertex_count);
|
||||
gl_state.bind_array_buffer(vbo);
|
||||
|
||||
glBufferSubData(GL_ARRAY_BUFFER, 0, (GLsizeiptr)(buffer_size
|
||||
* vertex_buffer.size()), vertex_buffer.data());
|
||||
@@ -679,11 +685,11 @@ namespace spr {
|
||||
glVertexAttribPointer(2, 4, GL_FLOAT, GL_FALSE, buffer_size,
|
||||
(void*)offsetof(sprite_draw_vertex, uv));
|
||||
|
||||
glBindBuffer(GL_ARRAY_BUFFER, 0);
|
||||
glBindVertexArray(0);
|
||||
gl_state.bind_array_buffer(0);
|
||||
gl_state.bind_vertex_array(0);
|
||||
}
|
||||
else
|
||||
vbo.WriteMemory(0, buffer_size * vertex_buffer.size(), vertex_buffer.data());
|
||||
vbo.WriteMemory(gl_state, 0, buffer_size * vertex_buffer.size(), vertex_buffer.data());
|
||||
|
||||
if (ebo_index_count < index_buffer.size()) {
|
||||
while (ebo_index_count < index_buffer.size())
|
||||
@@ -691,19 +697,19 @@ namespace spr {
|
||||
|
||||
ebo.Destroy();
|
||||
|
||||
glBindVertexArray(vao);
|
||||
gl_state.bind_vertex_array(vao);
|
||||
|
||||
ebo.Create(sizeof(uint32_t) * ebo_index_count);
|
||||
glBindBuffer(GL_ELEMENT_ARRAY_BUFFER, ebo);
|
||||
ebo.Create(gl_state, sizeof(uint32_t) * ebo_index_count);
|
||||
gl_state.bind_element_array_buffer(ebo);
|
||||
|
||||
glBufferSubData(GL_ELEMENT_ARRAY_BUFFER, 0, (GLsizeiptr)(sizeof(uint32_t)
|
||||
* index_buffer.size()), index_buffer.data());
|
||||
|
||||
glBindVertexArray(0);
|
||||
glBindBuffer(GL_ELEMENT_ARRAY_BUFFER, 0);
|
||||
gl_state.bind_vertex_array(0);
|
||||
gl_state.bind_element_array_buffer(0);
|
||||
}
|
||||
else
|
||||
ebo.WriteMemory(0, sizeof(uint32_t) * index_buffer.size(), index_buffer.data());
|
||||
ebo.WriteMemory(gl_state, 0, sizeof(uint32_t) * index_buffer.size(), index_buffer.data());
|
||||
}
|
||||
|
||||
SpriteManager::SpriteManager() : aspect(), index(), set_counter() {
|
||||
@@ -777,15 +783,16 @@ namespace spr {
|
||||
render_data.Clear();
|
||||
}
|
||||
|
||||
void SpriteManager::Draw(int32_t index, bool font, texture* overlay_tex, const mat4& vp) {
|
||||
void SpriteManager::Draw(render_data_context& rend_data_ctx,
|
||||
int32_t index, bool font, texture* overlay_tex, const mat4& vp) {
|
||||
render_context* rctx = rctx_ptr;
|
||||
draw_sprite_begin(rctx);
|
||||
draw_sprite_begin(rend_data_ctx);
|
||||
|
||||
::resolution_mode mode = res_window_get()->resolution_mode;
|
||||
if (index == 2 && resolution_mode != RESOLUTION_MODE_MAX)
|
||||
res_window_get()->resolution_mode = resolution_mode;
|
||||
|
||||
gl_rend_state_rect viewport_rect = gl_rend_state.get_viewport();
|
||||
gl_rend_state_rect viewport_rect = rend_data_ctx.state.get_viewport();
|
||||
|
||||
for (int32_t i = 0; i < 2; i++) {
|
||||
auto reqlist = this->reqlist[index][i];
|
||||
@@ -826,7 +833,7 @@ namespace spr {
|
||||
y_min = (int32_t)min.y;
|
||||
x_max = (int32_t)(max.x - min.x);
|
||||
y_max = (int32_t)(max.y - min.y);
|
||||
gl_rend_state.set_viewport(x_min, y_min, x_max, y_max);
|
||||
rend_data_ctx.state.set_viewport(x_min, y_min, x_max, y_max);
|
||||
}
|
||||
else {
|
||||
view_projection = vp;
|
||||
@@ -858,21 +865,21 @@ namespace spr {
|
||||
1.0f / (float_t)overlay_tex->height, 0.0f, 0.0f
|
||||
};
|
||||
mat4_transpose(&view_projection, &shader_data.g_transform);
|
||||
rctx->sprite_scene_ubo.WriteMemory(shader_data);
|
||||
rctx->sprite_scene_ubo.Bind(0);
|
||||
rctx->sprite_scene_ubo.WriteMemory(rend_data_ctx.state, shader_data);
|
||||
rend_data_ctx.state.bind_uniform_buffer_base(0, rctx->sprite_scene_ubo);
|
||||
|
||||
gl_rend_state.bind_vertex_array(render_data.vao);
|
||||
rend_data_ctx.state.bind_vertex_array(render_data.vao);
|
||||
for (uint32_t j = SPR_PRIO_MAX; j; j--, reqlist++)
|
||||
for (SprArgs& k : *reqlist)
|
||||
if (k.sprite_draw_param_index >= 0)
|
||||
draw_sprite(this, rctx, k, mat, x_min, y_min, x_max, y_max, overlay_tex);
|
||||
gl_rend_state.bind_vertex_array(0);
|
||||
draw_sprite(rend_data_ctx, this, k, mat, x_min, y_min, x_max, y_max, overlay_tex);
|
||||
rend_data_ctx.state.bind_vertex_array(0);
|
||||
}
|
||||
|
||||
if (index == 2 && resolution_mode != RESOLUTION_MODE_MAX)
|
||||
res_window_get()->resolution_mode = mode;
|
||||
|
||||
draw_sprite_end();
|
||||
draw_sprite_end(rend_data_ctx);
|
||||
}
|
||||
|
||||
SprSet* SpriteManager::GetSet(uint32_t index) {
|
||||
@@ -1788,7 +1795,8 @@ namespace spr {
|
||||
args_array[i]->sprite_draw_param_index = -1;
|
||||
}
|
||||
|
||||
static void draw_sprite(spr::SpriteManager* sprite_manager, render_context* rctx, const SprArgs& args,
|
||||
static void draw_sprite(render_data_context& rend_data_ctx,
|
||||
spr::SpriteManager* sprite_manager, const SprArgs& args,
|
||||
const mat4& mat, int32_t x_min, int32_t y_min, int32_t x_max, int32_t y_max, texture* overlay_tex) {
|
||||
sprite_draw_param& draw_param
|
||||
= sprite_manager->render_data.draw_param_buffer.data()[args.sprite_draw_param_index];
|
||||
@@ -1796,8 +1804,9 @@ namespace spr {
|
||||
int32_t combiner = 0;
|
||||
if (draw_param.attrib.m.enable_blend) {
|
||||
if (draw_param.attrib.m.blend == 5) {
|
||||
gl_rend_state.active_bind_texture_2d(7, overlay_tex->glid);
|
||||
draw_sprite_copy_overlay_texture(rctx, args, mat, draw_param.vtx, x_min, y_min, x_max, y_max);
|
||||
rend_data_ctx.state.active_bind_texture_2d(7, overlay_tex->glid);
|
||||
draw_sprite_copy_overlay_texture(rend_data_ctx,
|
||||
args, mat, draw_param.vtx, x_min, y_min, x_max, y_max);
|
||||
combiner = 2;
|
||||
}
|
||||
else
|
||||
@@ -1805,11 +1814,11 @@ namespace spr {
|
||||
|
||||
const GLenum* blend = spr_blend_param[draw_param.attrib.m.blend];
|
||||
|
||||
gl_rend_state.enable_blend();
|
||||
gl_rend_state.set_blend_func_separate(blend[0], blend[1], blend[2], blend[3]);
|
||||
rend_data_ctx.state.enable_blend();
|
||||
rend_data_ctx.state.set_blend_func_separate(blend[0], blend[1], blend[2], blend[3]);
|
||||
}
|
||||
else
|
||||
gl_rend_state.disable_blend();
|
||||
rend_data_ctx.state.disable_blend();
|
||||
|
||||
if (draw_param.shader == SHADER_FT_SPRITE) {
|
||||
int32_t tex_0_type = 0;
|
||||
@@ -1832,49 +1841,50 @@ namespace spr {
|
||||
}
|
||||
}
|
||||
|
||||
uniform_value[U_TEX_0_TYPE] = tex_0_type;
|
||||
uniform_value[U_TEX_1_TYPE] = tex_1_type;
|
||||
uniform_value[U_COMBINER] = combiner;
|
||||
rend_data_ctx.shader_flags.arr[U_TEX_0_TYPE] = tex_0_type;
|
||||
rend_data_ctx.shader_flags.arr[U_TEX_1_TYPE] = tex_1_type;
|
||||
rend_data_ctx.shader_flags.arr[U_COMBINER] = combiner;
|
||||
}
|
||||
|
||||
if (draw_param.textures[0]) {
|
||||
gl_rend_state.active_bind_texture_2d(0, draw_param.textures[0]->glid);
|
||||
gl_rend_state.bind_sampler(0, rctx->sprite_samplers[draw_param.attrib.m.sampler]);
|
||||
rend_data_ctx.state.active_bind_texture_2d(0, draw_param.textures[0]->glid);
|
||||
rend_data_ctx.state.bind_sampler(0, rctx_ptr->sprite_samplers[draw_param.attrib.m.sampler]);
|
||||
|
||||
if (draw_param.textures[1]) {
|
||||
gl_rend_state.active_bind_texture_2d(1, draw_param.textures[1]->glid);
|
||||
gl_rend_state.bind_sampler(1, rctx->sprite_samplers[draw_param.attrib.m.sampler]);
|
||||
rend_data_ctx.state.active_bind_texture_2d(1, draw_param.textures[1]->glid);
|
||||
rend_data_ctx.state.bind_sampler(1, rctx_ptr->sprite_samplers[draw_param.attrib.m.sampler]);
|
||||
}
|
||||
else if (!gl_rend_state.texture_binding_2d[1])
|
||||
gl_rend_state.active_bind_texture_2d(1, rctx->empty_texture_2d->glid);
|
||||
else
|
||||
rend_data_ctx.state.active_bind_texture_2d(1, rctx_ptr->empty_texture_2d->glid);
|
||||
}
|
||||
else {
|
||||
if (!gl_rend_state.texture_binding_2d[0])
|
||||
gl_rend_state.active_bind_texture_2d(0, rctx->empty_texture_2d->glid);
|
||||
if (!gl_rend_state.texture_binding_2d[1])
|
||||
gl_rend_state.active_bind_texture_2d(1, rctx->empty_texture_2d->glid);
|
||||
rend_data_ctx.state.active_bind_texture_2d(0, rctx_ptr->empty_texture_2d->glid);
|
||||
rend_data_ctx.state.active_bind_texture_2d(1, rctx_ptr->empty_texture_2d->glid);
|
||||
}
|
||||
|
||||
shaders_ft.set(draw_param.shader);
|
||||
shaders_ft.set(rend_data_ctx.state, rend_data_ctx.shader_flags, draw_param.shader);
|
||||
if (draw_param.attrib.m.primitive != GL_TRIANGLES)
|
||||
shaders_ft.draw_arrays(draw_param.attrib.m.primitive, draw_param.first, draw_param.count);
|
||||
rend_data_ctx.state.draw_arrays(
|
||||
draw_param.attrib.m.primitive, draw_param.first, draw_param.count);
|
||||
else
|
||||
shaders_ft.draw_range_elements(draw_param.attrib.m.primitive, draw_param.start, draw_param.end,
|
||||
rend_data_ctx.state.draw_range_elements(
|
||||
draw_param.attrib.m.primitive, draw_param.start, draw_param.end,
|
||||
draw_param.count, GL_UNSIGNED_INT, (void*)draw_param.offset);
|
||||
}
|
||||
|
||||
static void draw_sprite_begin(render_context* rctx) {
|
||||
gl_rend_state.disable_blend();
|
||||
gl_rend_state.active_bind_texture_2d(0, rctx->empty_texture_2d->glid);
|
||||
gl_rend_state.bind_sampler(0, 0);
|
||||
gl_rend_state.active_bind_texture_2d(1, rctx->empty_texture_2d->glid);
|
||||
gl_rend_state.bind_sampler(1, 0);
|
||||
gl_rend_state.bind_sampler(7, 0);
|
||||
gl_rend_state.set_blend_func_separate(GL_ONE, GL_ZERO, GL_ONE, GL_ZERO);
|
||||
static void draw_sprite_begin(render_data_context& rend_data_ctx) {
|
||||
rend_data_ctx.state.disable_blend();
|
||||
rend_data_ctx.state.active_bind_texture_2d(0, rctx_ptr->empty_texture_2d->glid);
|
||||
rend_data_ctx.state.bind_sampler(0, 0);
|
||||
rend_data_ctx.state.active_bind_texture_2d(1, rctx_ptr->empty_texture_2d->glid);
|
||||
rend_data_ctx.state.bind_sampler(1, 0);
|
||||
rend_data_ctx.state.bind_sampler(7, 0);
|
||||
rend_data_ctx.state.set_blend_func_separate(GL_ONE, GL_ZERO, GL_ONE, GL_ZERO);
|
||||
}
|
||||
|
||||
static void draw_sprite_copy_overlay_texture(render_context* rctx, const SprArgs& args, const mat4& mat,
|
||||
const vec3* vtx, int32_t overlay_x_min, int32_t overlay_y_min, int32_t overlay_x_max, int32_t overlay_y_max) {
|
||||
static void draw_sprite_copy_overlay_texture(
|
||||
render_data_context& rend_data_ctx, const SprArgs& args, const mat4& mat, const vec3* vtx,
|
||||
int32_t overlay_x_min, int32_t overlay_y_min, int32_t overlay_x_max, int32_t overlay_y_max) {
|
||||
if (args.num_vertex || args.kind != SPR_KIND_NORMAL)
|
||||
return;
|
||||
|
||||
@@ -1929,21 +1939,21 @@ namespace spr {
|
||||
const int32_t width = x_max - x_min + 1;
|
||||
const int32_t height = y_max - y_min + 1;
|
||||
if (width * height > 0) {
|
||||
gl_rend_state.active_texture(7);
|
||||
rend_data_ctx.state.active_texture(7);
|
||||
glCopyTexSubImage2D(GL_TEXTURE_2D, 0, x_min, y_min, x_min, y_min, width, height);
|
||||
}
|
||||
}
|
||||
|
||||
static void draw_sprite_end() {
|
||||
gl_rend_state.disable_blend();
|
||||
gl_rend_state.active_bind_texture_2d(0, 0);
|
||||
gl_rend_state.bind_sampler(0, 0);
|
||||
gl_rend_state.active_bind_texture_2d(1, 0);
|
||||
gl_rend_state.bind_sampler(1, 0);
|
||||
gl_rend_state.active_bind_texture_2d(7, 0);
|
||||
gl_rend_state.bind_sampler(7, 0);
|
||||
gl_rend_state.set_blend_func_separate(GL_ONE, GL_ZERO, GL_ONE, GL_ZERO);
|
||||
shader::unbind();
|
||||
static void draw_sprite_end(render_data_context& rend_data_ctx) {
|
||||
rend_data_ctx.state.disable_blend();
|
||||
rend_data_ctx.state.active_bind_texture_2d(0, 0);
|
||||
rend_data_ctx.state.bind_sampler(0, 0);
|
||||
rend_data_ctx.state.active_bind_texture_2d(1, 0);
|
||||
rend_data_ctx.state.bind_sampler(1, 0);
|
||||
rend_data_ctx.state.active_bind_texture_2d(7, 0);
|
||||
rend_data_ctx.state.bind_sampler(7, 0);
|
||||
rend_data_ctx.state.set_blend_func_separate(GL_ONE, GL_ZERO, GL_ONE, GL_ZERO);
|
||||
shader::unbind(rend_data_ctx.state);
|
||||
}
|
||||
|
||||
static void draw_sprite_scale(spr::SprArgs* args) {
|
||||
|
||||
+2
-2
@@ -14,7 +14,6 @@
|
||||
#include "../KKdLib/spr.hpp"
|
||||
#include "../KKdLib/vec.hpp"
|
||||
#include "color.hpp"
|
||||
#include "render_context.hpp"
|
||||
#include "resolution_mode.hpp"
|
||||
#include "texture.hpp"
|
||||
#include "gl_rend_state.hpp"
|
||||
@@ -211,7 +210,8 @@ namespace spr {
|
||||
extern void sprite_manager_init();
|
||||
extern void sprite_manager_add_spr_sets(const sprite_database* spr_db);
|
||||
extern void sprite_manager_clear();
|
||||
extern void sprite_manager_draw(int32_t index, bool font, texture* overlay_tex, const mat4& vp);
|
||||
extern void sprite_manager_draw(struct render_data_context& rend_data_ctx,
|
||||
int32_t index, bool font, texture* overlay_tex, const mat4& vp);
|
||||
extern int32_t sprite_manager_get_index();
|
||||
extern size_t sprite_manager_get_reqlist_count(int32_t index);
|
||||
extern ::spr_set* sprite_manager_get_set(uint32_t set_id, const sprite_database* spr_db);
|
||||
|
||||
+1
-22
@@ -18,9 +18,7 @@ int32_t sv_anisotropy = 1;
|
||||
|
||||
bool sv_better_reflect = false;
|
||||
|
||||
bool sv_shared_storage_uniform_buffer = true;
|
||||
|
||||
int32_t uniform_value[U_MAX];
|
||||
bool sv_shared_storage_uniform_buffer = false;
|
||||
|
||||
const vec3 sv_rgb_to_luma = {
|
||||
0.2126f, 0.7152f, 0.0722f
|
||||
@@ -44,22 +42,3 @@ void sv_anisotropy_set(int32_t value) {
|
||||
sv_anisotropy_changed = true;
|
||||
sv_old_anisotropy = sv_anisotropy;
|
||||
}
|
||||
|
||||
void uniform_value_reset() {
|
||||
uniform_value[U_ANISO] = 0;
|
||||
uniform_value[U0B] = 0;
|
||||
uniform_value[U_TEXTURE_BLEND] = 0;
|
||||
uniform_value[U_FOG_STAGE] = 0;
|
||||
uniform_value[U_FOG_CHARA] = 0;
|
||||
uniform_value[U_SPECULAR_IBL] = 0;
|
||||
uniform_value[U_TEX_0_TYPE] = 0;
|
||||
uniform_value[U_TEX_1_TYPE] = 0;
|
||||
uniform_value[U_TEXTURE_COUNT] = 0;
|
||||
uniform_value[U_ENV_MAP] = 0;
|
||||
uniform_value[U_TRANSLUCENCY] = 0;
|
||||
uniform_value[U_NORMAL] = 0;
|
||||
uniform_value[U_TRANSPARENCY] = 0;
|
||||
uniform_value[U_STAGE_SHADOW] = 0;
|
||||
uniform_value[U_SPECULAR] = 0;
|
||||
uniform_value[U45] = 0;
|
||||
}
|
||||
|
||||
@@ -97,6 +97,10 @@ enum uniform_name {
|
||||
U_DOF_STAGE = U_TEX_1_TYPE,
|
||||
};
|
||||
|
||||
struct uniform_value {
|
||||
int32_t arr[U_MAX];
|
||||
};
|
||||
|
||||
extern int32_t sv_max_texture_size;
|
||||
extern int32_t sv_max_texture_max_anisotropy;
|
||||
extern int32_t sv_max_uniform_buffer_size;
|
||||
@@ -111,11 +115,8 @@ extern bool sv_better_reflect;
|
||||
|
||||
extern bool sv_shared_storage_uniform_buffer;
|
||||
|
||||
extern int32_t uniform_value[U_MAX];
|
||||
|
||||
extern const vec3 sv_rgb_to_luma;
|
||||
extern const mat3 sv_rgb_to_ypbpr;
|
||||
extern const mat3 sv_ypbpr_to_rgb;
|
||||
|
||||
extern void sv_anisotropy_set(int32_t value);
|
||||
extern void uniform_value_reset();
|
||||
|
||||
+9
-2
@@ -4,7 +4,7 @@
|
||||
*/
|
||||
|
||||
#include "texture.hpp"
|
||||
#include "gl_rend_state.hpp"
|
||||
#include "gl_state.hpp"
|
||||
#include "shared.hpp"
|
||||
#include "static_var.hpp"
|
||||
|
||||
@@ -582,7 +582,14 @@ inline void texture_manager_free() {
|
||||
}
|
||||
|
||||
inline static void texture_bind(GLenum target, GLuint texture) {
|
||||
glBindTexture(target, texture);
|
||||
switch (target) {
|
||||
case GL_TEXTURE_2D:
|
||||
gl_state.bind_texture_2d(texture);
|
||||
break;
|
||||
case GL_TEXTURE_CUBE_MAP:
|
||||
gl_state.bind_texture_cube_map(texture);
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
inline static GLuint texture_get_working_internal_format(GLuint internal_format) {
|
||||
|
||||
@@ -1956,6 +1956,19 @@ inline void mat4_ortho(float_t left, float_t right,
|
||||
out_m->row3.w = 1.0f;
|
||||
}
|
||||
|
||||
inline void mat4_ortho_offset(float_t left, float_t right,
|
||||
float_t bottom, float_t top, float_t z_near, float_t z_far,
|
||||
const vec2* scale, const vec2* offset, mat4* out_m) {
|
||||
*out_m = mat4_null;
|
||||
out_m->row0.x = 2.0f / (right - left) * scale->x;
|
||||
out_m->row1.y = 2.0f / (top - bottom) * scale->y;
|
||||
out_m->row2.z = -2.0f / (z_far - z_near);
|
||||
out_m->row3.x = -((right + left) / (right - left)) * scale->x + offset->x;
|
||||
out_m->row3.y = -((top + bottom) / (top - bottom)) * scale->y + offset->y;
|
||||
out_m->row3.z = -((z_far + z_near) / (z_far - z_near));
|
||||
out_m->row3.w = 1.0f;
|
||||
}
|
||||
|
||||
inline void mat4_persp(float_t fov_y, float_t aspect, float_t z_near, float_t z_far, mat4* out_m) {
|
||||
float_t tan_fov = tanf(fov_y * 0.5f);
|
||||
|
||||
@@ -1967,6 +1980,15 @@ inline void mat4_persp(float_t fov_y, float_t aspect, float_t z_near, float_t z_
|
||||
out_m->row3.z = -((2.0f * z_far * z_near) / (z_far - z_near));
|
||||
}
|
||||
|
||||
inline void mat4_persp_offset(float_t fov_y, float_t aspect, float_t z_near, float_t z_far,
|
||||
const vec2* scale, const vec2* offset, mat4* out_m) {
|
||||
mat4_persp(fov_y, aspect, z_near, z_far, out_m);
|
||||
*(vec2*)&out_m->row0.x = *(vec2*)&out_m->row0.x * *scale + out_m->row0.w * *offset;
|
||||
*(vec2*)&out_m->row1.x = *(vec2*)&out_m->row1.x * *scale + out_m->row1.w * *offset;
|
||||
*(vec2*)&out_m->row2.x = *(vec2*)&out_m->row2.x * *scale + out_m->row2.w * *offset;
|
||||
*(vec2*)&out_m->row3.x = *(vec2*)&out_m->row3.x * *scale + out_m->row3.w * *offset;
|
||||
}
|
||||
|
||||
inline void mat4_look_at(const vec3* eye, const vec3* target, const vec3* up, mat4* out_m) {
|
||||
vec3 x_axis, y_axis, z_axis;
|
||||
vec3 xyz;
|
||||
|
||||
@@ -218,7 +218,12 @@ extern void mat4_frustrum(float_t left, float_t right,
|
||||
float_t bottom, float_t top, float_t z_near, float_t z_far, mat4* out_m);
|
||||
extern void mat4_ortho(float_t left, float_t right,
|
||||
float_t bottom, float_t top, float_t z_near, float_t z_far, mat4* out_m);
|
||||
extern void mat4_ortho_offset(float_t left, float_t right,
|
||||
float_t bottom, float_t top, float_t z_near, float_t z_far,
|
||||
const vec2* scale, const vec2* offset, mat4* out_m);
|
||||
extern void mat4_persp(float_t fov_y, float_t aspect, float_t z_near, float_t z_far, mat4* out_m);
|
||||
extern void mat4_persp_offset(float_t fov_y, float_t aspect, float_t z_near, float_t z_far,
|
||||
const vec2* scale, const vec2* offset, mat4* out_m);
|
||||
extern void mat4_look_at(const vec3* eye, const vec3* target, const vec3* up, mat4* out_m);
|
||||
extern void mat4_look_at(const vec3* eye, const vec3* target, mat4* out_m);
|
||||
|
||||
|
||||
+61
-57
@@ -27,6 +27,7 @@
|
||||
#include "../CRE/file_handler.hpp"
|
||||
#include "../CRE/font.hpp"
|
||||
#include "../CRE/gl_rend_state.hpp"
|
||||
#include "../CRE/gl_state.hpp"
|
||||
#include "../CRE/hand_item.hpp"
|
||||
#include "../CRE/light_param.hpp"
|
||||
#include "../CRE/mdata_manager.hpp"
|
||||
@@ -450,12 +451,29 @@ int32_t app_main(const app_init_struct& ais) {
|
||||
#if !(BAKE_PNG || BAKE_VIDEO)
|
||||
glfwGetFramebufferSize(window, &width, &height);
|
||||
#endif
|
||||
gl_rend_state.set_viewport(0, 0, width, height);
|
||||
gl_rend_state.disable_blend();
|
||||
gl_rend_state.disable_depth_test();
|
||||
gl_rend_state.set_depth_mask(GL_FALSE);
|
||||
gl_rend_state.disable_cull_face();
|
||||
gl_rend_state.disable_stencil_test();
|
||||
|
||||
if (Vulkan::use) {
|
||||
Vulkan::CommandBuffer cb;
|
||||
cb.Create(vulkan_device, vulkan_command_pool);
|
||||
cb.BeginOneTimeSubmit();
|
||||
Vulkan::current_command_buffer = cb;
|
||||
}
|
||||
|
||||
render_data_context rend_data_ctx(0);
|
||||
rend_data_ctx.state.set_viewport(0, 0, width, height);
|
||||
rend_data_ctx.state.disable_blend();
|
||||
rend_data_ctx.state.disable_depth_test();
|
||||
rend_data_ctx.state.set_depth_mask(GL_FALSE);
|
||||
rend_data_ctx.state.disable_cull_face();
|
||||
rend_data_ctx.state.disable_stencil_test();
|
||||
|
||||
if (Vulkan::use) {
|
||||
Vulkan::CommandBuffer cb(vulkan_device,
|
||||
vulkan_command_pool, Vulkan::current_command_buffer);
|
||||
Vulkan::current_command_buffer = 0;
|
||||
cb.Sumbit(vulkan_graphics_queue);
|
||||
cb.Destroy();
|
||||
}
|
||||
|
||||
glfwSwapInterval(0);
|
||||
|
||||
@@ -528,9 +546,6 @@ bool app_render_data::load() {
|
||||
d3d_gl_handle = wglDXOpenDeviceNV(d3d_device);
|
||||
#endif
|
||||
|
||||
gl_get_error_print();
|
||||
gl_rend_state.set_viewport(0, 0, width, height);
|
||||
|
||||
#if DISPLAY_IBL
|
||||
const float_t box_vertices[] = {
|
||||
-1.0f, 1.0f, -1.0f,
|
||||
@@ -577,16 +592,16 @@ bool app_render_data::load() {
|
||||
};
|
||||
|
||||
glGenVertexArrays(1, &ibl_vao);
|
||||
gl_rend_state.bind_vertex_array(ibl_vao, true);
|
||||
gl_state.bind_vertex_array(ibl_vao, true);
|
||||
|
||||
ibl_vbo.Create(sizeof(box_vertices), box_vertices);
|
||||
ibl_vbo.Bind(true);
|
||||
gl_state.bind_array_buffer(ibl_vbo.Bind);
|
||||
|
||||
glEnableVertexAttribArray(0);
|
||||
glVertexAttribPointer(0, 3, GL_FLOAT, GL_FALSE, sizeof(float_t) * 3, (void*)0);
|
||||
|
||||
gl_rend_state.bind_array_buffer(0);
|
||||
gl_rend_state.bind_vertex_array(0);
|
||||
gl_state.bind_array_buffer(0);
|
||||
gl_state.bind_vertex_array(0);
|
||||
|
||||
cubemap_display_ubo.Create(sizeof(cubemap_display_batch_shader_data));
|
||||
#endif
|
||||
@@ -749,7 +764,9 @@ static render_context* render_context_load() {
|
||||
render_context* rctx = new render_context;
|
||||
rctx_ptr = rctx;
|
||||
|
||||
gl_rend_state.get();
|
||||
gl_state.get();
|
||||
render_data_context rend_data_ctx(0);
|
||||
rend_data_ctx.state.get();
|
||||
|
||||
data_struct* aft_data = &data_list[DATA_AFT];
|
||||
aet_database* aft_aet_db = &aft_data->data_ft.aet_db;
|
||||
@@ -1276,7 +1293,7 @@ static render_context* render_context_load() {
|
||||
cam->set_view_point({ 0.0f, 1.4f, 1.0f });
|
||||
cam->set_interest({ 0.0f, 1.4f, 0.0f });
|
||||
|
||||
uniform_value[U16] = 1;
|
||||
rend_data_ctx.shader_flags.arr[U16] = 1;
|
||||
|
||||
imgui_context = ImGui::CreateContext();
|
||||
ImGui::SetCurrentContext(imgui_context);
|
||||
@@ -1386,14 +1403,7 @@ static void render_context_ctrl(render_context* rctx) {
|
||||
|
||||
camera* cam = rctx->camera;
|
||||
|
||||
for (int32_t i = 0; i < 32; i++) {
|
||||
if (!gl_rend_state.check_texture_binding_2d(i) && !gl_rend_state.check_texture_binding_cube_map(i))
|
||||
continue;
|
||||
|
||||
gl_rend_state.active_bind_texture_2d(i, 0);
|
||||
gl_rend_state.active_bind_texture_cube_map(i, 0);
|
||||
gl_rend_state.bind_sampler(i, 0);
|
||||
}
|
||||
gl_state.get();
|
||||
|
||||
global_context_menu = true;
|
||||
ImGui::SetCurrentContext(imgui_context);
|
||||
@@ -1536,30 +1546,24 @@ static void render_context_disp(render_context* rctx) {
|
||||
static const GLfloat depth_clear = 1.0f;
|
||||
static const GLint stencil_clear = 0;
|
||||
|
||||
for (int32_t i = 0; i < 32; i++) {
|
||||
if (!gl_rend_state.check_texture_binding_2d(i) && !gl_rend_state.check_texture_binding_cube_map(i))
|
||||
continue;
|
||||
|
||||
gl_rend_state.active_bind_texture_2d(i, 0);
|
||||
gl_rend_state.active_bind_texture_cube_map(i, 0);
|
||||
gl_rend_state.bind_sampler(i, 0);
|
||||
}
|
||||
|
||||
gl_rend_state.bind_framebuffer(0);
|
||||
gl_rend_state.set_depth_mask(GL_TRUE);
|
||||
gl_rend_state.set_stencil_mask(0xFF);
|
||||
render_data_context pre_rend_data_ctx(0);
|
||||
pre_rend_data_ctx.state.get();
|
||||
pre_rend_data_ctx.state.set_depth_mask(GL_TRUE);
|
||||
pre_rend_data_ctx.state.set_stencil_mask(0xFF);
|
||||
glClearBufferfv(GL_COLOR, 0, (float_t*)&color_clear);
|
||||
glClearDepthf(depth_clear);
|
||||
gl_rend_state.set_stencil_mask(0x00);
|
||||
gl_rend_state.set_depth_mask(GL_FALSE);
|
||||
pre_rend_data_ctx.state.set_stencil_mask(0x00);
|
||||
pre_rend_data_ctx.state.set_depth_mask(GL_FALSE);
|
||||
|
||||
gl_rend_state.set_viewport(0, 0, internal_3d_res.x, internal_3d_res.y);
|
||||
pre_rend_data_ctx.state.set_viewport(0, 0, internal_3d_res.x, internal_3d_res.y);
|
||||
|
||||
rctx->disp();
|
||||
|
||||
render_data_context post_rend_data_ctx(3);
|
||||
|
||||
#if DISPLAY_IBL
|
||||
if (display_ibl) {
|
||||
rctx->screen_buffer.Bind();
|
||||
rctx->screen_buffer.Bind(post_rend_data_ctx.state);
|
||||
|
||||
mat4 mat;
|
||||
mat4_translate_y(1.4f, &mat);
|
||||
@@ -1576,15 +1580,15 @@ static void render_context_disp(render_context* rctx) {
|
||||
shader_data.g_vp[3] = mat.row3;
|
||||
shader_data.g_texture_lod.x = ibl_index == 1 ? 1.0f : 0.0f;
|
||||
shader_data.g_texture_lod.y = 1.0f / (float_t)ibl_scale;
|
||||
rctx_ptr->glitter_batch_ubo.WriteMemory(shader_data);
|
||||
rctx_ptr->glitter_batch_ubo.WriteMemory(post_rend_data_ctx.state, shader_data);
|
||||
|
||||
rctx_ptr->glitter_batch_ubo.Bind(3);
|
||||
shaders_dev.set(SHADER_DEV_CUBEMAP_DISPLAY);
|
||||
gl_rend_state.bind_vertex_array(ibl_vao);
|
||||
gl_rend_state.active_bind_texture_cube_map(0,
|
||||
light_param_data_storage_data_get_ibl_texture(max_def(ibl_index - 1, 0)));
|
||||
shaders_dev.draw_arrays(GL_TRIANGLES, 0, 36);
|
||||
gl_rend_state.bind_vertex_array(0);
|
||||
post_rend_data_ctx.state.bind_uniform_buffer_base(3, rctx_ptr->glitter_batch_ubo);
|
||||
shaders_dev.set(post_rend_data_ctx.state, post_rend_data_ctx.shader_flags, SHADER_DEV_CUBEMAP_DISPLAY);
|
||||
post_rend_data_ctx.state.bind_vertex_array(ibl_vao);
|
||||
post_rend_data_ctx.state.active_bind_texture_cube_map(0,
|
||||
light_param_data_storage_data_get_ibl_textures()[max_def(ibl_index - 1, 0)]);
|
||||
post_rend_data_ctx.state.draw_arrays(GL_TRIANGLES, 0, 36);
|
||||
post_rend_data_ctx.state.bind_vertex_array(0);
|
||||
}
|
||||
#endif
|
||||
|
||||
@@ -1592,28 +1596,28 @@ static void render_context_disp(render_context* rctx) {
|
||||
Vulkan::end_render_pass(Vulkan::current_command_buffer);
|
||||
|
||||
#if BAKE_PNG || BAKE_VIDEO
|
||||
gl_rend_state.set_viewport(0, 0, rctx->screen_width, rctx->screen_height);
|
||||
post_rend_data_ctx.state.set_viewport(0, 0, rctx->screen_width, rctx->screen_height);
|
||||
#else
|
||||
gl_rend_state.set_viewport(rctx->screen_x_offset, rctx->screen_y_offset,
|
||||
post_rend_data_ctx.state.set_viewport(rctx->screen_x_offset, rctx->screen_y_offset,
|
||||
rctx->sprite_width, rctx->sprite_height);
|
||||
#endif
|
||||
|
||||
gl_rend_state.bind_framebuffer(0);
|
||||
gl_rend_state.active_bind_texture_2d(0, rctx->screen_buffer.GetColorTex());
|
||||
uniform_value[U_ALPHA_MASK] = 0;
|
||||
uniform_value[U_REDUCE] = 0;
|
||||
shaders_ft.set(SHADER_FT_REDUCE);
|
||||
rctx->render.draw_quad(rctx->sprite_width, rctx->sprite_height,
|
||||
post_rend_data_ctx.state.bind_framebuffer(0);
|
||||
post_rend_data_ctx.state.active_bind_texture_2d(0, rctx->screen_buffer.GetColorTex());
|
||||
post_rend_data_ctx.shader_flags.arr[U_ALPHA_MASK] = 0;
|
||||
post_rend_data_ctx.shader_flags.arr[U_REDUCE] = 0;
|
||||
shaders_ft.set(post_rend_data_ctx.state, post_rend_data_ctx.shader_flags, SHADER_FT_REDUCE);
|
||||
rctx->render.draw_quad(post_rend_data_ctx, rctx->sprite_width, rctx->sprite_height,
|
||||
1.0f, 0.0f, 0.0f, 1.0f, 1.0f, 1.0f, 1.0f, 1.0f, 1.0f);
|
||||
}
|
||||
#ifdef USE_OPENGL
|
||||
else {
|
||||
#if BAKE_PNG || BAKE_VIDEO
|
||||
fbo_blit(rctx->screen_buffer.fbos[0], 0,
|
||||
fbo_blit(post_rend_data_ctx.state, rctx->screen_buffer.fbos[0], 0,
|
||||
0, 0, rctx->sprite_width, rctx->sprite_height,
|
||||
0, 0, rctx->screen_width, rctx->screen_height, GL_COLOR_BUFFER_BIT, GL_LINEAR);
|
||||
#else
|
||||
fbo_blit(rctx->screen_buffer.fbos[0], 0,
|
||||
fbo_blit(post_rend_data_ctx.state, rctx->screen_buffer.fbos[0], 0,
|
||||
0, 0, rctx->sprite_width, rctx->sprite_height,
|
||||
rctx->screen_x_offset, rctx->screen_y_offset,
|
||||
rctx->sprite_width, rctx->sprite_height, GL_COLOR_BUFFER_BIT, GL_LINEAR);
|
||||
|
||||
@@ -217,6 +217,7 @@ void ShadowDw::ShowTextureCallback(dw::Widget* data) {
|
||||
dw::Button* button = dynamic_cast<dw::Button*>(data);
|
||||
if (button) {
|
||||
shadow_dw->shadow_ptr->show_texture = button->value;
|
||||
shadow_dw->shadow_ptr->clear_textures();
|
||||
render_data_context rend_data_ctx(0);
|
||||
shadow_dw->shadow_ptr->clear_textures(rend_data_ctx.state);
|
||||
}
|
||||
}
|
||||
|
||||
+38
-38
@@ -12,6 +12,7 @@
|
||||
#include "../CRE/app_system_detail.hpp"
|
||||
#include "../CRE/data.hpp"
|
||||
#include "../CRE/effect.hpp"
|
||||
#include "../CRE/gl_state.hpp"
|
||||
#include "../CRE/item_table.hpp"
|
||||
#include "../CRE/object.hpp"
|
||||
#include "../CRE/pv_expression.hpp"
|
||||
@@ -6336,11 +6337,11 @@ struct d3d_gl_fbo_tex_struct {
|
||||
handle = wglDXRegisterObjectNV(d3d_gl_handle, d3d_tex,
|
||||
gl_tex, GL_TEXTURE_2D, WGL_ACCESS_READ_WRITE_NV);
|
||||
else {
|
||||
gl_rend_state.bind_texture_2d(gl_tex);
|
||||
gl_state.bind_texture_2d(gl_tex);
|
||||
::texture* tex = rctx_ptr->screen_buffer.color_texture;
|
||||
glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA8,
|
||||
tex->width, tex->height, 0, GL_RGBA, GL_UNSIGNED_BYTE, 0);
|
||||
gl_rend_state.bind_texture_2d(0);
|
||||
gl_state.bind_texture_2d(0);
|
||||
}
|
||||
|
||||
glGenFramebuffers(1, &gl_fbo);
|
||||
@@ -6348,9 +6349,9 @@ struct d3d_gl_fbo_tex_struct {
|
||||
return;
|
||||
|
||||
lock();
|
||||
gl_rend_state.bind_framebuffer(gl_fbo);
|
||||
gl_state.bind_framebuffer(gl_fbo);
|
||||
glFramebufferTexture(GL_FRAMEBUFFER, GL_COLOR_ATTACHMENT0, gl_tex, 0);
|
||||
gl_rend_state.bind_framebuffer(0);
|
||||
gl_state.bind_framebuffer(0);
|
||||
unlock();
|
||||
}
|
||||
|
||||
@@ -6390,7 +6391,6 @@ struct d3d_gl_fbo_tex_struct {
|
||||
static d3d_gl_fbo_tex_struct d3d_gl_fbo_tex;
|
||||
|
||||
#if BAKE_VIDEO_ALPHA
|
||||
static ID3D11Texture2D* d3d_alpha_texture;
|
||||
static d3d_gl_fbo_tex_struct d3d_gl_alpha_fbo_tex;
|
||||
#endif
|
||||
|
||||
@@ -6468,9 +6468,9 @@ bool x_pv_game::ctrl() {
|
||||
D3D11_MAPPED_SUBRESOURCE mapped_res = {};
|
||||
if (SUCCEEDED(d3d_device_context->Map(d3d_gl_fbo_tex.d3d_tex,
|
||||
0, D3D11_MAP_WRITE_DISCARD, 0, &mapped_res))) {
|
||||
gl_rend_state.bind_texture_2d(d3d_gl_fbo_tex.gl_tex);
|
||||
gl_state.bind_texture_2d(d3d_gl_fbo_tex.gl_tex);
|
||||
glGetTexImage(GL_TEXTURE_2D, 0, GL_RGBA, GL_UNSIGNED_BYTE, nvenc_temp_pixels.data());
|
||||
gl_rend_state.bind_texture_2d(0);
|
||||
gl_state.bind_texture_2d(0);
|
||||
|
||||
uint8_t* src = (uint8_t*)nvenc_temp_pixels.data();
|
||||
uint8_t* dst = (uint8_t*)mapped_res.pData;
|
||||
@@ -6491,9 +6491,9 @@ bool x_pv_game::ctrl() {
|
||||
D3D11_MAPPED_SUBRESOURCE mapped_alpha_res = {};
|
||||
if (SUCCEEDED(d3d_device_context->Map(d3d_gl_alpha_fbo_tex.d3d_tex,
|
||||
0, D3D11_MAP_WRITE_DISCARD, 0, &mapped_alpha_res))) {
|
||||
gl_rend_state.bind_texture_2d(d3d_gl_alpha_fbo_tex.gl_tex);
|
||||
gl_state.bind_texture_2d(d3d_gl_alpha_fbo_tex.gl_tex);
|
||||
glGetTexImage(GL_TEXTURE_2D, 0, GL_RGBA, GL_UNSIGNED_BYTE, nvenc_temp_pixels.data());
|
||||
gl_rend_state.bind_texture_2d(0);
|
||||
gl_state.bind_texture_2d(0);
|
||||
|
||||
uint8_t* src = (uint8_t*)nvenc_temp_pixels.data();
|
||||
uint8_t* dst = (uint8_t*)mapped_alpha_res.pData;
|
||||
@@ -6524,9 +6524,9 @@ bool x_pv_game::ctrl() {
|
||||
#elif BAKE_PNG
|
||||
std::vector<uint8_t> temp_pixels;
|
||||
temp_pixels.resize((size_t)width * (size_t)height * 4 * sizeof(uint8_t));
|
||||
gl_rend_state.bind_texture_2d(tex->glid);
|
||||
gl_state.bind_texture_2d(tex->glid);
|
||||
glGetTexImage(GL_TEXTURE_2D, 0, GL_RGBA, GL_UNSIGNED_BYTE, temp_pixels.data());
|
||||
gl_rend_state.bind_texture_2d(0);
|
||||
gl_state.bind_texture_2d(0);
|
||||
|
||||
std::vector<uint8_t> pixels;
|
||||
pixels.resize((size_t)width * (size_t)height * 4 * sizeof(uint8_t));
|
||||
@@ -8000,11 +8000,6 @@ bool x_pv_game::ctrl() {
|
||||
#endif
|
||||
d3d_gl_fbo_tex.free();
|
||||
|
||||
#if BAKE_VIDEO_ALPHA
|
||||
d3d_alpha_texture->Release();
|
||||
d3d_alpha_texture = 0;
|
||||
#endif
|
||||
|
||||
if (!GLAD_WGL_NV_DX_interop2) {
|
||||
nvenc_temp_pixels.clear();
|
||||
nvenc_temp_pixels.shrink_to_fit();
|
||||
@@ -8183,20 +8178,23 @@ void x_pv_game::basic() {
|
||||
#if BAKE_VIDEO
|
||||
d3d_gl_fbo_tex.lock();
|
||||
|
||||
gl_rend_state.bind_framebuffer(d3d_gl_fbo_tex.gl_fbo);
|
||||
gl_rend_state.active_bind_texture_2d(0, tex->glid);
|
||||
gl_rend_state.bind_sampler(0, rctx_ptr->render_samplers[1]);
|
||||
render_data_context rend_data_ctx(3);
|
||||
rend_data_ctx.state.bind_framebuffer(d3d_gl_fbo_tex.gl_fbo);
|
||||
rend_data_ctx.state.active_bind_texture_2d(0, tex->glid);
|
||||
rend_data_ctx.state.bind_sampler(0, rctx_ptr->render_samplers[1]);
|
||||
|
||||
#if BAKE_VIDEO_ALPHA
|
||||
GLint swizzle_rgb1[] = { GL_RED, GL_GREEN, GL_BLUE, GL_ONE };
|
||||
glTexParameteriv(GL_TEXTURE_2D, GL_TEXTURE_SWIZZLE_RGBA, swizzle_rgb1);
|
||||
#endif
|
||||
|
||||
gl_rend_state.set_viewport(0, 0, width, height);
|
||||
rend_data_ctx.state.set_viewport(0, 0, width, height);
|
||||
if (nvenc_rgb)
|
||||
shaders_dev.set(SHADER_DEV_CONVERT_RGB);
|
||||
shaders_dev.set(rend_data_ctx.state,
|
||||
rend_data_ctx.shader_flags, SHADER_DEV_CONVERT_RGB);
|
||||
else
|
||||
shaders_dev.set(SHADER_DEV_CONVERT_YCBCR_BT709);
|
||||
shaders_dev.set(rend_data_ctx.state,
|
||||
rend_data_ctx.shader_flags, SHADER_DEV_CONVERT_YCBCR_BT709);
|
||||
|
||||
float_t s0 = 1.0f;
|
||||
float_t t0 = 0.0f;
|
||||
@@ -8214,48 +8212,50 @@ void x_pv_game::basic() {
|
||||
quad.g_color = 1.0f;
|
||||
quad.g_texture_lod = 0.0f;
|
||||
|
||||
rctx_ptr->quad_ubo.WriteMemory(quad);
|
||||
rctx_ptr->quad_ubo.Bind(0);
|
||||
gl_rend_state.bind_vertex_array(rctx_ptr->common_vao);
|
||||
shaders_dev.draw_arrays(GL_TRIANGLE_STRIP, 0, 4);
|
||||
rctx_ptr->quad_ubo.WriteMemory(rend_data_ctx.state, quad);
|
||||
rend_data_ctx.state.bind_uniform_buffer_base(0, rctx_ptr->quad_ubo);
|
||||
rend_data_ctx.state.bind_vertex_array(rctx_ptr->common_vao);
|
||||
rend_data_ctx.state.draw_arrays(GL_TRIANGLE_STRIP, 0, 4);
|
||||
|
||||
#if BAKE_VIDEO_ALPHA
|
||||
GLint swizzle_rgba[] = { GL_RED, GL_GREEN, GL_BLUE, GL_ALPHA };
|
||||
glTexParameteriv(GL_TEXTURE_2D, GL_TEXTURE_SWIZZLE_RGBA, swizzle_rgba);
|
||||
#endif
|
||||
|
||||
gl_rend_state.bind_sampler(0, 0);
|
||||
gl_rend_state.bind_texture_2d(0);
|
||||
gl_rend_state.bind_framebuffer(0);
|
||||
rend_data_ctx.state.bind_sampler(0, 0);
|
||||
rend_data_ctx.state.bind_texture_2d(0);
|
||||
rend_data_ctx.state.bind_framebuffer(0);
|
||||
|
||||
d3d_gl_fbo_tex.unlock();
|
||||
|
||||
#if BAKE_VIDEO_ALPHA
|
||||
d3d_gl_alpha_fbo_tex.lock();
|
||||
|
||||
gl_rend_state.bind_framebuffer(d3d_gl_alpha_fbo_tex.gl_fbo);
|
||||
gl_rend_state.active_bind_texture_2d(0, tex->glid);
|
||||
rend_data_ctx.state.bind_framebuffer(d3d_gl_alpha_fbo_tex.gl_fbo);
|
||||
rend_data_ctx.state.active_bind_texture_2d(0, tex->glid);
|
||||
|
||||
if (nvenc_rgb) {
|
||||
GLint swizzle_aaa1[] = { GL_ALPHA, GL_ALPHA, GL_ALPHA, GL_ONE };
|
||||
glTexParameteriv(GL_TEXTURE_2D, GL_TEXTURE_SWIZZLE_RGBA, swizzle_aaa1);
|
||||
}
|
||||
|
||||
gl_rend_state.set_viewport(0, 0, width, height);
|
||||
rend_data_ctx.state.set_viewport(0, 0, width, height);
|
||||
if (nvenc_rgb) {
|
||||
uniform_value[U_REDUCE] = 0;
|
||||
shaders_ft.set(SHADER_FT_REDUCE);
|
||||
rend_data_ctx.shader_flags.arr[U_REDUCE] = 0;
|
||||
shaders_dev.set(rend_data_ctx.state,
|
||||
rend_data_ctx.shader_flags, SHADER_FT_REDUCE);
|
||||
}
|
||||
else
|
||||
shaders_dev.set(SHADER_DEV_CONVERT_ALPHA);
|
||||
rctx_ptr->render.draw_quad(width, height,
|
||||
shaders_dev.set(rend_data_ctx.state,
|
||||
rend_data_ctx.shader_flags, SHADER_DEV_CONVERT_ALPHA);
|
||||
rctx_ptr->render.draw_quad(rend_data_ctx, width, height,
|
||||
1.0f, 0.0f, 0.0f, 1.0f, 1.0f, 1.0f, 1.0f, 1.0f, 1.0f);
|
||||
|
||||
if (nvenc_rgb)
|
||||
glTexParameteriv(GL_TEXTURE_2D, GL_TEXTURE_SWIZZLE_RGBA, swizzle_rgba);
|
||||
|
||||
gl_rend_state.bind_texture_2d(0);
|
||||
gl_rend_state.bind_framebuffer(0);
|
||||
rend_data_ctx.state.bind_texture_2d(0);
|
||||
rend_data_ctx.state.bind_framebuffer(0);
|
||||
|
||||
d3d_gl_alpha_fbo_tex.unlock();
|
||||
#endif
|
||||
|
||||
Reference in New Issue
Block a user