src/gl/compiler.h

Sun, 19 Jan 2020 14:25:43 +0200

author
Teemu Piippo <teemu@hecknology.net>
date
Sun, 19 Jan 2020 14:25:43 +0200
changeset 24
1a0faaaceb84
parent 22
6da867fa5429
child 26
3a9e761e4faa
permissions
-rw-r--r--

added license

/*
 *  LDForge: LDraw parts authoring CAD
 *  Copyright (C) 2013 - 2018 Teemu Piippo
 *
 *  This program is free software: you can redistribute it and/or modify
 *  it under the terms of the GNU General Public License as published by
 *  the Free Software Foundation, either version 3 of the License, or
 *  (at your option) any later version.
 *
 *  This program is distributed in the hope that it will be useful,
 *  but WITHOUT ANY WARRANTY; without even the implied warranty of
 *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 *  GNU General Public License for more details.
 *
 *  You should have received a copy of the GNU General Public License
 *  along with this program.  If not, see <http://www.gnu.org/licenses/>.
 */

#pragma once
#include "main.h"
#include "gl/common.h"
#include "types/boundingbox.h"
#include <QMap>
#include <QSet>

class Model;
class DocumentManager;

namespace gl
{
	class Compiler;
	class Renderer;
	struct VboAddress
	{
		VboClass vboClass;
		VboSubclass vboSubclass;
	};
	int vboIndex(const VboAddress vboAddress);
}

class gl::Compiler : public QObject, protected QOpenGLFunctions
{
	Q_OBJECT
public:
	Compiler(QObject* parent);
	~Compiler();
	void build(Model* model, DocumentManager* context);
	void buildPolygon(Polygon polygon, std::vector<GLfloat>* vboData);
	void upload(const int vboIndex, const std::vector<GLfloat>& data);
	GLuint vbo(const VboAddress vboAddress) const;
	std::size_t vboSize(const VboAddress vboAddress) const;
	QColor getColorForPolygon(const gl::Polygon& polygon, VboSubclass subclass);
	void writeColor(std::vector<GLfloat>* data, const gl::Polygon& polygon, VboSubclass subclass);
	Point3D modelCenter() const;
	double modelDistance() const;
private:
	void initializeVbo();
	GLuint storedVbo[gl::numVbos];
	bool m_vboChanged[gl::numVbos] = {true};
	std::size_t storedVboSizes[gl::numVbos] = {0_z};
	bool initialized = false;
	BoundingBox boundingBox;
};

#define CHECK_GL_ERROR() { checkGLError(__FILE__, __LINE__); }
void checkGLError (QString file, int line);

mercurial