Witam,
tak jak w temacie. Mimo że na scenie jest tylko 1536 wierzchołków w trybie pełnoekranowym jest jedynie 5-10 fps-ów
Mój kod wygląda mniej więcej jak ten z tego przykładu:
http://qt-project.org/doc/qt-5.0/qtgui/openglwindow.html
Zmieniłem jedynie funkcje renderującą i inicjalizującą:
void TriangleWindow::initialize()
{
glEnable(GL_DEPTH_TEST);
glEnable(GL_CULL_FACE);
program = new QOpenGLShaderProgram(this);
QFile vsFile(":/shaders/VS.vert");
QFile fsFile(":/shaders/FS.fsh");
vsFile.open(QIODevice::ReadOnly);
fsFile.open(QIODevice::ReadOnly);
program->addShaderFromSourceCode(QOpenGLShader::Vertex, vsFile.readAll());
program->addShaderFromSourceCode(QOpenGLShader::Fragment, fsFile.readAll());
program->link();
texture = QGLContext::fromOpenGLContext(m_context)->bindTexture(QPixmap(":/textures/tx.jpg"));
const qreal retinaScale = devicePixelRatio();
glViewport(0, 0, width() * retinaScale, height() * retinaScale);
program->bind();
}
int frame =0;
void TriangleWindow::render()
{
glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
glClearColor(0,0.5,1,255);
QMatrix4x4 matrix;
matrix.perspective(60, width()/height() , 0.01, 100.0);
matrix.translate(0, -2, -7);
matrix.rotate(++frame, 0, 1, 0);
program->setUniformValue("mvp_matrix", matrix);
program->setUniformValue("normal_matrix", matrix.normalMatrix());
program->setUniformValue("ec_light_dir",QVector3D(-1,0,-1));
program->setUniformValue("i_ambient",QVector4D(0.1,0.1,0.1,1));
program->setAttributeArray("a_vertex", reader->vertices.constData());
program->setAttributeArray("a_normal",reader->normals.constData());
program->setAttributeArray("a_texcoord",reader->texCoords.constData());
program->enableAttributeArray("a_vertex");
program->enableAttributeArray("a_normal");
program->enableAttributeArray("a_texcoord");
glDrawArrays(GL_TRIANGLES, 0, reader->vertices.size());
program->enableAttributeArray("a_texcoord");
program->enableAttributeArray("a_normal");
program->enableAttributeArray("a_vertex;");
frames++;
}
kod shader wygląda tak(nie mój):
uniform mat4 mvp_matrix; // model-view-projection matrix
uniform mat3 normal_matrix; // normal matrix
uniform vec3 ec_light_dir; // light direction in eye coords
attribute vec4 a_vertex; // vertex position
attribute vec3 a_normal; // vertex normal
attribute vec2 a_texcoord; // texture coordinates
varying float v_diffuse;
varying vec2 v_texcoord;
void main(void)
{
// put vertex normal into eye coords
vec3 ec_normal = normalize(normal_matrix * a_normal);
// emit diffuse scale factor, texcoord, and position
v_diffuse = max(dot(ec_light_dir, ec_normal), 0.0);
v_texcoord = a_texcoord;
gl_Position = mvp_matrix * a_vertex;
}
precision mediump float;
uniform sampler2D t_reflectance;
uniform vec4 i_ambient;
varying float v_diffuse;
varying vec2 v_texcoord;
void main (void)
{
vec4 color = texture2D(t_reflectance, v_texcoord);
gl_FragColor = color * (vec4(v_diffuse) + i_ambient);
}
Gry w opengl działają dośc płynni, więc to raczej nie wina sprzętu.
W jaki sposób mogę to naprawić?