// See method declaration for details.
	void DrawPrimitivesTaskList::ExtractVertexData(VertexQueue& textured_vertex_queue, VertexQueue& colored_vertex_queue)
	{
		for(auto i = draw_primitives_tasks.begin(); i != draw_primitives_tasks.end(); ++i)
		{
			if(i->IsTextured() == true)
			{
				ASSERT(textured_vertex_queue.size() % 5 == 0);
				i->SetBaseVertex(textured_vertex_queue.size() / 5);
				i->GetVertexData(textured_vertex_queue);
			}
			else
			{
				ASSERT(colored_vertex_queue.size() % 4 == 0);
				i->SetBaseVertex(textured_vertex_queue.size() / 4);
				i->GetVertexData(colored_vertex_queue);
			}
		}
	}
Example #2
0
void GSkybox::Init(const char *pos_x, const char *neg_x, const char *pos_y, const char *neg_y, const char *pos_z, const char *neg_z, QImage::Format img_format)
{
    _is_inited = true;
    //QImage::Format::Format_RGB888
    _cube_tex_obj.Load(pos_x,neg_x,pos_y,neg_y,pos_z,neg_z,img_format);

    const char vs[] =
            "#version 410\n"
            "layout (location = 0) in vec3 vi_position;\n"
            "layout (location = 1) in vec3 vi_color;\n"
            "uniform vec3   move;\n"
            "uniform float  scale;\n"
            "uniform vec4   color;\n"
            "uniform mat4x4 view_matrix;\n"
            "uniform mat4x4 projection_matrix;\n"
            "out vec3 vo_tex_pos;\n"
            "out vec4 vo_color;\n"
            "void main(void)\n"
            "{\n"
            "    mat4 scale_mat = mat4(scale);"
            "    scale_mat[3].w = 1.0f;"
            "    //gl_Position = scale_mat*vec4(vi_position+move,1.0);\n"
            "    //gl_Position = view_matrix*scale_mat*vec4(vi_position+move,1.0);\n"
            "    //gl_Position = projection_matrix*scale_mat*vec4(vi_position+move,1.0);\n"
            "    gl_Position = projection_matrix*view_matrix*scale_mat*vec4(vi_position+move,1.0);\n"
            "    gl_Position = gl_Position.xyww;\n"
            "    //vo_color = color;\n"
            "    vo_color = vec4(vi_color,1.0);\n"
            "    vo_tex_pos = vi_position;\n"
            "}\n";
    const char fs[] =
            "#version 410\n"
            "in vec3 vo_tex_pos;\n"
            "in vec4 vo_color;\n"
            "out vec4 fo_color;\n"
            "uniform samplerCube cube_tex;\n"
            "void main(void)\n"
            "{\n"
            "    //fo_color = vo_color;\n"
            "    fo_color = texture(cube_tex,vo_tex_pos);\n"
            "}\n";
    _program = GLHelper::CreateShaderProgram(vs,fs);
    glUseProgram(_program);
    {
        glGenVertexArrays(1,&_vertex_arr_obj);
        glBindVertexArray(_vertex_arr_obj);

        GLfloat* vertex_data = NULL;
        GLint    vertex_data_size;
        GLfloat* vertex_color_data = NULL;
        GLint    vertex_color_data_size;
        GLuint*  vertex_index_data = NULL;
        GLint    vertex_index_data_size;
        GLint    vertex_pos_comp_count;
        GLint    vertex_color_comp_count;

        GetVertexData(vertex_data,vertex_index_data,vertex_color_data,
                      vertex_data_size,vertex_index_data_size,vertex_color_data_size,
                      vertex_pos_comp_count,vertex_color_comp_count);

        glGenBuffers(1,&_vertex_buffer);
        glBindBuffer(GL_ARRAY_BUFFER,_vertex_buffer);
        glBufferData(GL_ARRAY_BUFFER,vertex_data_size+vertex_color_data_size,NULL,GL_STATIC_DRAW);
        glBufferSubData(GL_ARRAY_BUFFER,0,vertex_data_size,vertex_data);
        glBufferSubData(GL_ARRAY_BUFFER,vertex_data_size,vertex_color_data_size,vertex_color_data);

        glGenBuffers(1,&_vertex_index_buffer);
        glBindBuffer(GL_ELEMENT_ARRAY_BUFFER,_vertex_index_buffer);
        glBufferData(GL_ELEMENT_ARRAY_BUFFER,vertex_index_data_size,vertex_index_data,GL_STATIC_DRAW);

        _scaleUniformLocal = GLHelper::GetUniformLocal(_program,"scale");
        _colorUniformLocal = GLHelper::GetUniformLocal(_program,"color");
        _moveUniformLocal  = GLHelper::GetUniformLocal(_program,"move");
        _cubeSamplerVarUniformLocal = GLHelper::GetUniformLocal(_program,"cube_tex");

        _viewMatrixUniformLocal = GLHelper::GetUniformLocal(_program,"view_matrix");
        _projectionMatrixUniformLocal = GLHelper::GetUniformLocal(_program,"projection_matrix");

        glVertexAttribPointer(_kPosAttribLocal,vertex_pos_comp_count,GL_FLOAT,GL_FALSE,
                              0,BUFF_OFFSET(0));
        glEnableVertexAttribArray(_kPosAttribLocal);
        glVertexAttribPointer(_kColorAttribLocal,vertex_color_comp_count,GL_FLOAT,GL_FALSE,
                              0,BUFF_OFFSET(vertex_data_size));
        glEnableVertexAttribArray(_kColorAttribLocal);

        glUniform1i(_cubeSamplerVarUniformLocal,0);

        glBindVertexArray(0);
        glBindBuffer(GL_ARRAY_BUFFER,0);
        glBindBuffer(GL_ELEMENT_ARRAY_BUFFER,0);
    }
    glUseProgram(0);
}
Example #3
0
void GCube::Init()
{
    _is_inited = true;

    const char vs[] =
            "#version 410\n"
            "layout (location = 0) in vec3 vi_position;\n"
            "layout (location = 1) in vec3 vi_color;\n"
            "uniform vec3   move;\n"
            "uniform float  scale;\n"
            "uniform vec4   color;\n"
            "uniform mat4x4 view_matrix;\n"
            "uniform mat4x4 projection_matrix;\n"
            "out vec4 vo_color;\n"
            "void main(void)\n"
            "{\n"
            "    mat4 scale_mat = mat4(scale);\n"
            "    scale_mat[3].w = 1.0f;\n"
            "    vec4 temp_pos = scale_mat*vec4(vi_position,1.0);\n"
            "    temp_pos = temp_pos+vec4(move,0.0);\n"
            "    gl_Position = projection_matrix*view_matrix*temp_pos;\n"
            "    //vo_color = color;\n"
            "    vo_color = vec4(vi_color,1.0);\n"
            "}\n";
    const char fs[] =
            "#version 410\n"
            "in vec4 vo_color;\n"
            "out vec4 fo_color;\n"
            "void main(void)\n"
            "{\n"
            "    fo_color = vo_color;\n"
            "}\n";
    _program = GLHelper::CreateShaderProgram(vs,fs);
    glUseProgram(_program);
    {
        glGenVertexArrays(1,&_vertex_arr_obj);
        glBindVertexArray(_vertex_arr_obj);

        GLfloat* vertex_data = NULL;
        GLint    vertex_data_size;
        GLfloat* vertex_color_data = NULL;
        GLint    vertex_color_data_size;
        GLuint*  vertex_index_data = NULL;
        GLint    vertex_index_data_size;
        GLint    vertex_pos_comp_count;
        GLint    vertex_color_comp_count;

        GetVertexData(vertex_data,vertex_index_data,vertex_color_data,
                      vertex_data_size,vertex_index_data_size,vertex_color_data_size,
                      vertex_pos_comp_count,vertex_color_comp_count);

        glGenBuffers(1,&_vertex_buffer);
        glBindBuffer(GL_ARRAY_BUFFER,_vertex_buffer);
        glBufferData(GL_ARRAY_BUFFER,vertex_data_size+vertex_color_data_size,NULL,GL_STATIC_DRAW);
        glBufferSubData(GL_ARRAY_BUFFER,0,vertex_data_size,vertex_data);
        glBufferSubData(GL_ARRAY_BUFFER,vertex_data_size,vertex_color_data_size,vertex_color_data);

        glGenBuffers(1,&_vertex_index_buffer);
        glBindBuffer(GL_ELEMENT_ARRAY_BUFFER,_vertex_index_buffer);
        glBufferData(GL_ELEMENT_ARRAY_BUFFER,vertex_index_data_size,vertex_index_data,GL_STATIC_DRAW);

        _scaleUniformLocal = GLHelper::GetUniformLocal(_program,"scale");
        _colorUniformLocal = GLHelper::GetUniformLocal(_program,"color");
        _moveUniformLocal  = GLHelper::GetUniformLocal(_program,"move");
        _viewMatrixUniformLocal = GLHelper::GetUniformLocal(_program,"view_matrix");
        _projectionMatrixUniformLocal = GLHelper::GetUniformLocal(_program,"projection_matrix");

        glVertexAttribPointer(_kPosAttribLocal,vertex_pos_comp_count,GL_FLOAT,GL_FALSE,
                              0,BUFF_OFFSET(0));
        glEnableVertexAttribArray(_kPosAttribLocal);
        glVertexAttribPointer(_kColorAttribLocal,vertex_color_comp_count,GL_FLOAT,GL_FALSE,
                              0,BUFF_OFFSET(vertex_data_size));
        glEnableVertexAttribArray(_kColorAttribLocal);

        glBindVertexArray(0);
        glBindBuffer(GL_ARRAY_BUFFER,0);
        glBindBuffer(GL_ELEMENT_ARRAY_BUFFER,0);
    }
    glUseProgram(0);
}