2015-12-08 07:31:57 +00:00
|
|
|
/*
|
|
|
|
* This program source code file is part of KiCad, a free EDA CAD application.
|
|
|
|
*
|
2016-07-19 17:35:25 +00:00
|
|
|
* Copyright (C) 2015-2016 Mario Luzeiro <mrluzeiro@ua.pt>
|
2021-01-02 21:05:29 +00:00
|
|
|
* Copyright (C) 1992-2020 KiCad Developers, see AUTHORS.txt for contributors.
|
2015-12-08 07:31:57 +00:00
|
|
|
*
|
|
|
|
* 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 2
|
|
|
|
* 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, you may find one here:
|
|
|
|
* http://www.gnu.org/licenses/old-licenses/gpl-2.0.html
|
|
|
|
* or you may search the http://www.gnu.org website for the version 2 license,
|
|
|
|
* or you may write to the Free Software Foundation, Inc.,
|
|
|
|
* 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA
|
|
|
|
*/
|
|
|
|
|
|
|
|
/**
|
2021-01-03 22:23:00 +00:00
|
|
|
* @file layer_triangles.h
|
2015-12-08 07:31:57 +00:00
|
|
|
*/
|
|
|
|
|
2021-01-02 21:05:29 +00:00
|
|
|
#ifndef TRIANGLE_DISPLAY_LIST_H_
|
|
|
|
#define TRIANGLE_DISPLAY_LIST_H_
|
2015-12-08 07:31:57 +00:00
|
|
|
|
2016-07-19 17:35:25 +00:00
|
|
|
#include "../../common_ogl/openGL_includes.h"
|
|
|
|
#include <plugins/3dapi/xv3d_types.h>
|
|
|
|
#include <geometry/shape_line_chain.h>
|
|
|
|
#include <geometry/shape_poly_set.h>
|
2021-01-03 22:23:00 +00:00
|
|
|
#include <3d_render_raytracing/accelerators/container_2d.h>
|
2015-12-08 07:31:57 +00:00
|
|
|
#include <vector>
|
2018-09-21 04:23:15 +00:00
|
|
|
#include <mutex>
|
2015-12-08 07:31:57 +00:00
|
|
|
|
|
|
|
|
|
|
|
typedef std::vector< SFVEC3F > SFVEC3F_VECTOR;
|
|
|
|
|
|
|
|
|
|
|
|
/**
|
2021-01-03 22:23:00 +00:00
|
|
|
* Container to manage a vector of triangles.
|
2015-12-08 07:31:57 +00:00
|
|
|
*/
|
2021-01-02 21:05:29 +00:00
|
|
|
class TRIANGLE_LIST
|
2015-12-08 07:31:57 +00:00
|
|
|
{
|
|
|
|
public:
|
|
|
|
|
|
|
|
/**
|
2021-01-02 21:05:29 +00:00
|
|
|
* @param aNrReservedTriangles is number of triangles expected to be used.
|
|
|
|
* @param aReserveNormals if you use normals, set it to bool to reserve space.
|
2015-12-08 07:31:57 +00:00
|
|
|
*/
|
2021-01-02 21:05:29 +00:00
|
|
|
TRIANGLE_LIST( unsigned int aNrReservedTriangles, bool aReserveNormals );
|
2015-12-08 07:31:57 +00:00
|
|
|
|
2016-07-19 17:35:25 +00:00
|
|
|
/**
|
2021-01-02 21:05:29 +00:00
|
|
|
* Reserve more triangles.
|
2016-07-19 17:35:25 +00:00
|
|
|
*/
|
|
|
|
void Reserve_More( unsigned int aNrReservedTriangles, bool aReserveNormals );
|
|
|
|
|
2021-01-02 21:05:29 +00:00
|
|
|
void AddTriangle( const SFVEC3F& aV1, const SFVEC3F& aV2, const SFVEC3F& aV3 );
|
2015-12-08 07:31:57 +00:00
|
|
|
|
2021-01-02 21:05:29 +00:00
|
|
|
void AddQuad( const SFVEC3F& aV1, const SFVEC3F& aV2, const SFVEC3F& aV3, const SFVEC3F& aV4 );
|
2015-12-08 07:31:57 +00:00
|
|
|
|
2021-01-02 21:05:29 +00:00
|
|
|
void AddNormal( const SFVEC3F& aN1, const SFVEC3F& aN2, const SFVEC3F& aN3 );
|
2015-12-08 07:31:57 +00:00
|
|
|
|
2021-01-02 21:05:29 +00:00
|
|
|
void AddNormal( const SFVEC3F& aN1, const SFVEC3F& aN2, const SFVEC3F& aN3,
|
|
|
|
const SFVEC3F& aN4 );
|
2015-12-08 07:31:57 +00:00
|
|
|
|
|
|
|
/**
|
2021-06-09 19:32:58 +00:00
|
|
|
* Get the array of vertices.
|
2021-01-02 21:05:29 +00:00
|
|
|
*
|
|
|
|
* @return a pointer to the start of array vertex.
|
2015-12-08 07:31:57 +00:00
|
|
|
*/
|
2021-01-02 21:05:29 +00:00
|
|
|
const float* GetVertexPointer() const { return (const float *)&m_vertexs[0].x; }
|
2015-12-08 07:31:57 +00:00
|
|
|
|
|
|
|
/**
|
2021-01-02 21:05:29 +00:00
|
|
|
* Get the array of normals.
|
|
|
|
*
|
|
|
|
* @return a pointer to start of array of normals.
|
2015-12-08 07:31:57 +00:00
|
|
|
*/
|
2021-01-02 21:05:29 +00:00
|
|
|
const float* GetNormalsPointer() const { return (const float*) &m_normals[0].x; }
|
2015-12-08 07:31:57 +00:00
|
|
|
|
2021-01-02 21:05:29 +00:00
|
|
|
unsigned int GetVertexSize() const { return (unsigned int) m_vertexs.size(); }
|
2015-12-08 07:31:57 +00:00
|
|
|
|
2021-01-02 21:05:29 +00:00
|
|
|
unsigned int GetNormalsSize() const { return (unsigned int) m_normals.size(); }
|
2015-12-08 07:31:57 +00:00
|
|
|
|
|
|
|
private:
|
2016-07-19 17:35:25 +00:00
|
|
|
SFVEC3F_VECTOR m_vertexs; ///< vertex array
|
|
|
|
SFVEC3F_VECTOR m_normals; ///< normals array
|
2015-12-08 07:31:57 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
|
|
|
|
/**
|
2021-01-02 21:05:29 +00:00
|
|
|
* Store arrays of triangles to be used to create display lists.
|
2015-12-08 07:31:57 +00:00
|
|
|
*/
|
2021-01-02 21:05:29 +00:00
|
|
|
class TRIANGLE_DISPLAY_LIST
|
2015-12-08 07:31:57 +00:00
|
|
|
{
|
|
|
|
public:
|
|
|
|
/**
|
2021-01-02 21:05:29 +00:00
|
|
|
* Initialize arrays with reserved triangles.
|
|
|
|
*
|
|
|
|
* @param aNrReservedTriangles is the number of triangles to reserve.
|
2015-12-08 07:31:57 +00:00
|
|
|
*/
|
2021-01-02 21:05:29 +00:00
|
|
|
explicit TRIANGLE_DISPLAY_LIST( unsigned int aNrReservedTriangles );
|
2015-12-08 07:31:57 +00:00
|
|
|
|
2021-01-02 21:05:29 +00:00
|
|
|
~TRIANGLE_DISPLAY_LIST();
|
2015-12-08 07:31:57 +00:00
|
|
|
|
|
|
|
/**
|
2021-01-02 21:05:29 +00:00
|
|
|
* Check if the vertex arrays of the layers are as expected.
|
|
|
|
*
|
|
|
|
* @return true if layers are correctly setup.
|
2015-12-08 07:31:57 +00:00
|
|
|
*/
|
|
|
|
bool IsLayersSizeValid();
|
|
|
|
|
2016-07-19 17:35:25 +00:00
|
|
|
|
2021-01-02 21:05:29 +00:00
|
|
|
void AddToMiddleContourns( const SHAPE_LINE_CHAIN& outlinePath, float zBot, float zTop,
|
|
|
|
double aBiuTo3Du, bool aInvertFaceDirection,
|
|
|
|
const BVH_CONTAINER_2D* aThroughHoles = nullptr );
|
2016-07-19 17:35:25 +00:00
|
|
|
|
2021-01-02 21:05:29 +00:00
|
|
|
void AddToMiddleContourns( const SHAPE_POLY_SET& aPolySet, float zBot, float zTop,
|
|
|
|
double aBiuTo3Du, bool aInvertFaceDirection,
|
|
|
|
const BVH_CONTAINER_2D* aThroughHoles = nullptr );
|
2016-07-19 17:35:25 +00:00
|
|
|
|
2021-01-02 21:05:29 +00:00
|
|
|
void AddToMiddleContourns( const std::vector< SFVEC2F >& aContournPoints, float zBot,
|
|
|
|
float zTop, bool aInvertFaceDirection,
|
|
|
|
const BVH_CONTAINER_2D* aThroughHoles = nullptr );
|
2016-07-19 17:35:25 +00:00
|
|
|
|
2018-09-21 04:23:15 +00:00
|
|
|
std::mutex m_middle_layer_lock;
|
|
|
|
|
2021-01-02 21:05:29 +00:00
|
|
|
TRIANGLE_LIST* m_layer_top_segment_ends;
|
|
|
|
TRIANGLE_LIST* m_layer_top_triangles;
|
|
|
|
TRIANGLE_LIST* m_layer_middle_contourns_quads;
|
|
|
|
TRIANGLE_LIST* m_layer_bot_triangles;
|
|
|
|
TRIANGLE_LIST* m_layer_bot_segment_ends;
|
2015-12-08 07:31:57 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
|
|
|
|
/**
|
2021-01-02 21:05:29 +00:00
|
|
|
* Store the OpenGL display lists to related with a layer.
|
2015-12-08 07:31:57 +00:00
|
|
|
*/
|
2021-01-02 21:05:29 +00:00
|
|
|
class OPENGL_RENDER_LIST
|
2015-12-08 07:31:57 +00:00
|
|
|
{
|
|
|
|
public:
|
|
|
|
/**
|
2021-01-02 21:05:29 +00:00
|
|
|
* Create the display lists for a layer.
|
|
|
|
*
|
|
|
|
* @param aLayerTriangles contains the layers array of vertex to render to display lists.
|
|
|
|
* @param aTextureIndexForSegEnds is the texture index to be used by segment ends.
|
|
|
|
* It is a black and white squared texture
|
|
|
|
* with a center circle diameter of the size
|
|
|
|
* of the texture.
|
2015-12-08 07:31:57 +00:00
|
|
|
*/
|
2021-01-02 21:05:29 +00:00
|
|
|
OPENGL_RENDER_LIST( const TRIANGLE_DISPLAY_LIST& aLayerTriangles,
|
|
|
|
GLuint aTextureIndexForSegEnds, float aZBot, float aZTop );
|
2015-12-08 07:31:57 +00:00
|
|
|
|
|
|
|
/**
|
2021-01-02 21:05:29 +00:00
|
|
|
* Destroy this class while free the display lists from GPU memory.
|
2015-12-08 07:31:57 +00:00
|
|
|
*/
|
2021-01-02 21:05:29 +00:00
|
|
|
~OPENGL_RENDER_LIST();
|
2015-12-08 07:31:57 +00:00
|
|
|
|
|
|
|
/**
|
2021-01-02 21:05:29 +00:00
|
|
|
* Call the display lists for the top elements and middle contours.
|
2015-12-08 07:31:57 +00:00
|
|
|
*/
|
|
|
|
void DrawTopAndMiddle() const;
|
|
|
|
|
|
|
|
/**
|
2021-01-02 21:05:29 +00:00
|
|
|
* Call the display lists for the bottom elements and middle contours.
|
2015-12-08 07:31:57 +00:00
|
|
|
*/
|
|
|
|
void DrawBotAndMiddle() const;
|
|
|
|
|
|
|
|
/**
|
2021-01-02 21:05:29 +00:00
|
|
|
* Call the display lists for the top elements.
|
2015-12-08 07:31:57 +00:00
|
|
|
*/
|
|
|
|
void DrawTop() const;
|
|
|
|
|
|
|
|
/**
|
2021-01-02 21:05:29 +00:00
|
|
|
* Call the display lists for the bottom elements.
|
2015-12-08 07:31:57 +00:00
|
|
|
*/
|
|
|
|
void DrawBot() const;
|
|
|
|
|
|
|
|
/**
|
2021-01-02 21:05:29 +00:00
|
|
|
* Call the display lists for the middle elements.
|
2015-12-08 07:31:57 +00:00
|
|
|
*/
|
|
|
|
void DrawMiddle() const;
|
|
|
|
|
|
|
|
/**
|
2021-01-02 21:05:29 +00:00
|
|
|
* Call to draw all the display lists.
|
2015-12-08 07:31:57 +00:00
|
|
|
*/
|
2016-07-19 17:35:25 +00:00
|
|
|
void DrawAll( bool aDrawMiddle = true ) const;
|
|
|
|
|
|
|
|
/**
|
2021-01-02 21:05:29 +00:00
|
|
|
* Draw all layers if they are visible by the camera if camera position is above the layer.
|
|
|
|
*
|
|
|
|
* This only works because the board is centered and the planes are always perpendicular to
|
|
|
|
* the Z axis.
|
|
|
|
*
|
|
|
|
* @param zCameraPos is the camera z axis position.
|
2016-07-19 17:35:25 +00:00
|
|
|
*/
|
|
|
|
void DrawAllCameraCulled( float zCameraPos, bool aDrawMiddle = true ) const;
|
|
|
|
|
2020-10-01 15:49:36 +00:00
|
|
|
void DrawAllCameraCulledSubtractLayer( bool aDrawMiddle,
|
2021-01-02 21:05:29 +00:00
|
|
|
const OPENGL_RENDER_LIST* aLayerToSubtractA = nullptr,
|
|
|
|
const OPENGL_RENDER_LIST* aLayerToSubtractB = nullptr,
|
|
|
|
const OPENGL_RENDER_LIST* aLayerToSubtractC = nullptr,
|
|
|
|
const OPENGL_RENDER_LIST* aLayerToSubtractD = nullptr ) const;
|
2016-07-19 17:35:25 +00:00
|
|
|
|
|
|
|
void ApplyScalePosition( float aZposition, float aZscale );
|
|
|
|
|
|
|
|
void ClearScalePosition() { m_haveTransformation = false; }
|
|
|
|
|
|
|
|
void SetItIsTransparent( bool aSetTransparent );
|
|
|
|
|
|
|
|
float GetZBot() const { return m_zBot; }
|
|
|
|
float GetZTop() const { return m_zTop; }
|
2015-12-08 07:31:57 +00:00
|
|
|
|
|
|
|
private:
|
2021-01-02 21:05:29 +00:00
|
|
|
GLuint generate_top_or_bot_seg_ends( const TRIANGLE_LIST* aTriangleContainer,
|
|
|
|
bool aIsNormalUp, GLuint aTextureId ) const;
|
2016-07-19 17:35:25 +00:00
|
|
|
|
2021-01-02 21:05:29 +00:00
|
|
|
GLuint generate_top_or_bot_triangles( const TRIANGLE_LIST* aTriangleContainer,
|
2016-07-19 17:35:25 +00:00
|
|
|
bool aIsNormalUp ) const;
|
|
|
|
|
2021-01-02 21:05:29 +00:00
|
|
|
GLuint generate_middle_triangles( const TRIANGLE_LIST* aTriangleContainer ) const;
|
2016-07-19 17:35:25 +00:00
|
|
|
|
|
|
|
void beginTransformation() const;
|
|
|
|
void endTransformation() const;
|
|
|
|
|
|
|
|
void setBlendfunction() const;
|
2015-12-08 07:31:57 +00:00
|
|
|
|
|
|
|
private:
|
2016-07-19 17:35:25 +00:00
|
|
|
float m_zBot;
|
|
|
|
float m_zTop;
|
|
|
|
GLuint m_layer_top_segment_ends;
|
|
|
|
GLuint m_layer_top_triangles;
|
|
|
|
GLuint m_layer_middle_contourns_quads;
|
|
|
|
GLuint m_layer_bot_triangles;
|
|
|
|
GLuint m_layer_bot_segment_ends;
|
|
|
|
|
|
|
|
bool m_haveTransformation;
|
|
|
|
float m_zPositionTransformation;
|
|
|
|
float m_zScaleTransformation;
|
|
|
|
|
|
|
|
bool m_draw_it_transparent;
|
2015-12-08 07:31:57 +00:00
|
|
|
};
|
|
|
|
|
2021-01-02 21:05:29 +00:00
|
|
|
#endif // TRIANGLE_DISPLAY_LIST_H_
|