full support of ObjectBase:: isReceiveShadows, isCastShadows, isAcceptLight and isAcceptFog
This commit is contained in:
@@ -32,12 +32,11 @@ const char qgl_vertex_head[] = "layout(location = 1 ) in vec3 qgl_Vertex
|
||||
"layout(location = 3 ) in vec3 qgl_Tangent ;\n"
|
||||
"layout(location = 4 ) in vec3 qgl_Bitangent ;\n"
|
||||
"layout(location = 5 ) in vec2 qgl_Texture ;\n"
|
||||
"layout(location = 6 ) in uint qgl_Material ;\n"
|
||||
"layout(location = 6 ) in uvec4 qgl_ObjectIntegers;\n"
|
||||
"layout(location = 7 ) in uint qgl_ObjectSelected;\n"
|
||||
"layout(location = 8 ) in uint qgl_ObjectID ;\n"
|
||||
"layout(location = 9 ) in vec4 qgl_ObjectColor ;\n"
|
||||
"layout(location = 10) in mat4 qgl_ModelMatrix ;\n"
|
||||
"layout(location = 14) in mat2x3 qgl_TextureMatrix ;\n"
|
||||
"layout(location = 8 ) in vec4 qgl_ObjectColor ;\n"
|
||||
"layout(location = 9 ) in mat4 qgl_ModelMatrix ;\n"
|
||||
"layout(location = 13) in mat2x3 qgl_TextureMatrix ;\n"
|
||||
"out vec2 qgl_FragTexture;\n"
|
||||
"flat out uint qgl_MaterialIndex;\n"
|
||||
"uniform mat4 qgl_ViewMatrix;\n"
|
||||
@@ -46,6 +45,9 @@ const char qgl_vertex_head[] = "layout(location = 1 ) in vec3 qgl_Vertex
|
||||
"mat3 qgl_getTangentMatrix() {return mat3(qgl_ViewMatrix * qgl_ModelMatrix);}\n"
|
||||
"vec2 qgl_getFragTexture() {return (vec3(qgl_Texture, 1.f) * qgl_TextureMatrix).xy;}\n"
|
||||
"vec4 qgl_ftransform() {return qgl_ViewProjMatrix * (qgl_ModelMatrix * vec4(qgl_Vertex, 1.f));}\n"
|
||||
"#define qgl_Material qgl_ObjectIntegers[0]\n"
|
||||
"#define qgl_ObjectID qgl_ObjectIntegers[1]\n"
|
||||
"#define qgl_ObjectFlags qgl_ObjectIntegers[2]\n"
|
||||
"";
|
||||
|
||||
const char qgl_fragment_head[] =
|
||||
|
||||
@@ -61,8 +61,7 @@ void QGLEngineShaders::prepareDrawGeom(QOpenGLExtraFunctions * f) {
|
||||
void QGLEngineShaders::prepareDrawObj(QOpenGLExtraFunctions * f) {
|
||||
// qDebug() << "prepareDrawObj";
|
||||
|
||||
f->glEnableVertexAttribArray(material_loc);
|
||||
f->glEnableVertexAttribArray(object_id_loc);
|
||||
f->glEnableVertexAttribArray(integers_loc);
|
||||
f->glEnableVertexAttribArray(color_loc);
|
||||
for (int i = 0; i < 4; ++i)
|
||||
f->glEnableVertexAttribArray(modelmatrix_loc + i);
|
||||
@@ -70,8 +69,7 @@ void QGLEngineShaders::prepareDrawObj(QOpenGLExtraFunctions * f) {
|
||||
f->glEnableVertexAttribArray(texturematrix_loc + i);
|
||||
|
||||
GLsizei size = sizeof(Object);
|
||||
f->glVertexAttribIPointer(material_loc, 1, GL_UNSIGNED_INT, size, (const void *)material_offset);
|
||||
f->glVertexAttribIPointer(object_id_loc, 1, GL_UNSIGNED_INT, size, (const void *)object_id_offset);
|
||||
f->glVertexAttribIPointer(integers_loc, 4, GL_UNSIGNED_INT, size, (const void *)integers_offset);
|
||||
f->glVertexAttribPointer(color_loc, 4, GL_FLOAT, GL_FALSE, size, (const void *)color_offset);
|
||||
for (int i = 0; i < 4; ++i) {
|
||||
f->glVertexAttribPointer(modelmatrix_loc + i,
|
||||
@@ -90,8 +88,7 @@ void QGLEngineShaders::prepareDrawObj(QOpenGLExtraFunctions * f) {
|
||||
(const void *)(texturematrix_offset + sizeof(QVector3D) * i));
|
||||
}
|
||||
|
||||
f->glVertexAttribDivisor(material_loc, 1);
|
||||
f->glVertexAttribDivisor(object_id_loc, 1);
|
||||
f->glVertexAttribDivisor(integers_loc, 1);
|
||||
f->glVertexAttribDivisor(color_loc, 1);
|
||||
for (int i = 0; i < 4; ++i)
|
||||
f->glVertexAttribDivisor(modelmatrix_loc + i, 1);
|
||||
|
||||
@@ -34,9 +34,8 @@ const GLsizei bitangent_offset = sizeof(QVector3D) + tangent_offset;
|
||||
const GLsizei tex_offset = sizeof(QVector3D) + bitangent_offset;
|
||||
|
||||
// object
|
||||
const GLsizei material_offset = 0;
|
||||
const GLsizei object_id_offset = sizeof(GLuint) + material_offset;
|
||||
const GLsizei color_offset = sizeof(GLuint) + object_id_offset;
|
||||
const GLsizei integers_offset = 0;
|
||||
const GLsizei color_offset = sizeof(GLuint) * 4 + integers_offset;
|
||||
const GLsizei modelmatrix_offset = sizeof(QVector4D) + color_offset;
|
||||
const GLsizei texturematrix_offset = sizeof(QVector4D) * 4 + modelmatrix_offset;
|
||||
|
||||
@@ -48,11 +47,10 @@ const GLuint tangent_loc = 3; // qgl_Tangent
|
||||
const GLuint bitangent_loc = 4; // qgl_Bitangent
|
||||
const GLuint tex_loc = 5; // qgl_Texture
|
||||
|
||||
const GLuint material_loc = 6; // qgl_Material
|
||||
const GLuint object_id_loc = 8; // qgl_ObjectID
|
||||
const GLuint color_loc = 9; // qgl_ObjectColor
|
||||
const GLuint modelmatrix_loc = 10; // qgl_ModelViewProjectionMatrix
|
||||
const GLuint texturematrix_loc = 14; // qgl_TextureMatrix
|
||||
const GLuint integers_loc = 6; // qgl_ObjectIntegers
|
||||
const GLuint color_loc = 8; // qgl_ObjectColor
|
||||
const GLuint modelmatrix_loc = 9; // qgl_ModelViewProjectionMatrix
|
||||
const GLuint texturematrix_loc = 13; // qgl_TextureMatrix
|
||||
|
||||
const GLuint is_selected_loc = 7; // qgl_ObjectSelected
|
||||
|
||||
@@ -66,13 +64,23 @@ struct Vertex {
|
||||
};
|
||||
struct Object {
|
||||
Object() {
|
||||
material = object_id = 0;
|
||||
color = QVector4D(1, 1, 1, 1);
|
||||
material = object_id = flags = 0;
|
||||
color = QVector4D(1, 1, 1, 1);
|
||||
QMatrix4x4().copyDataTo(modelmatrix);
|
||||
QMatrix2x3().transposed().copyDataTo(texturematrix);
|
||||
}
|
||||
GLuint material;
|
||||
GLuint object_id;
|
||||
union {
|
||||
GLuint flags;
|
||||
struct {
|
||||
GLuint f_accept_light : 1;
|
||||
GLuint f_accept_fog : 1;
|
||||
GLuint f_accept_cast_shadow: 1;
|
||||
GLuint f_accept_rec_shadow : 1;
|
||||
};
|
||||
};
|
||||
GLuint _reserve;
|
||||
QVector4D color;
|
||||
GLfloat modelmatrix[16];
|
||||
GLfloat texturematrix[6];
|
||||
|
||||
@@ -241,7 +241,12 @@ void Renderer::fillObjectsBuffer(const ObjectBaseList & ol, RenderPass pass) {
|
||||
so.material = 0;
|
||||
so.color = QColor2QVector(o->color());
|
||||
}
|
||||
so.object_id = o->id();
|
||||
so.object_id = o->id();
|
||||
so.flags = 0;
|
||||
so.f_accept_light = o->isAcceptLight();
|
||||
so.f_accept_fog = o->isAcceptFog();
|
||||
so.f_accept_cast_shadow = o->isCastShadows();
|
||||
so.f_accept_rec_shadow = o->isReceiveShadows();
|
||||
o->worldTransform().transposed().copyDataTo(so.modelmatrix);
|
||||
o->textureGLMatrix().copyDataTo(so.texturematrix);
|
||||
// qDebug() << "load obj" << o->name() << o->textureMatrix() << tmat;
|
||||
|
||||
@@ -110,7 +110,6 @@ public:
|
||||
|
||||
protected:
|
||||
void fillObjectsBuffer(const ObjectBaseList & ol, RenderPass pass);
|
||||
void reloadObjects();
|
||||
void renderObjects(Scene & scene, RenderPass pass);
|
||||
void renderLight(int first_wr_buff, bool clear_only);
|
||||
void renderShadow(int index, Light * light);
|
||||
|
||||
@@ -225,7 +225,10 @@ void ObjectBase::setVisible(bool v) {
|
||||
|
||||
void ObjectBase::setCastShadows(bool on) {
|
||||
cast_shadow = on;
|
||||
if (type_ == glLight) ((Light *)this)->apply();
|
||||
if (type_ == glLight)
|
||||
((Light *)this)->apply();
|
||||
else
|
||||
setObjectsChanged();
|
||||
}
|
||||
|
||||
|
||||
|
||||
@@ -84,7 +84,10 @@ public:
|
||||
|
||||
bool isReceiveShadows() const { return rec_shadow; }
|
||||
bool isCastShadows() const { return cast_shadow; }
|
||||
void setReceiveShadows(bool on) { rec_shadow = on; }
|
||||
void setReceiveShadows(bool on) {
|
||||
rec_shadow = on;
|
||||
setObjectsChanged();
|
||||
}
|
||||
void setCastShadows(bool on);
|
||||
|
||||
void move(const QVector3D & dv) {
|
||||
@@ -271,10 +274,16 @@ public:
|
||||
QGenericMatrix<3, 2, float> textureGLMatrix() const;
|
||||
|
||||
bool isAcceptLight() const { return accept_light; }
|
||||
void setAcceptLight(bool yes) { accept_light = yes; }
|
||||
void setAcceptLight(bool yes) {
|
||||
accept_light = yes;
|
||||
setObjectsChanged();
|
||||
}
|
||||
|
||||
bool isAcceptFog() const { return accept_fog; }
|
||||
void setAcceptFog(bool yes) { accept_fog = yes; }
|
||||
void setAcceptFog(bool yes) {
|
||||
accept_fog = yes;
|
||||
setObjectsChanged();
|
||||
}
|
||||
|
||||
bool isSelected(bool check_parents = false) const;
|
||||
void setSelected(bool yes);
|
||||
|
||||
Reference in New Issue
Block a user