/* * nextpnr -- Next Generation Place and Route * * Copyright (C) 2018 Serge Bazanski * * Permission to use, copy, modify, and/or distribute this software for any * purpose with or without fee is hereby granted, provided that the above * copyright notice and this permission notice appear in all copies. * * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. * */ #ifndef LINESHADER_H #define LINESHADER_H #include #include #include #include #include #include "nextpnr.h" NEXTPNR_NAMESPACE_BEGIN // Vertex2DPOD is a structure of X, Y coordinates that can be passed to OpenGL // directly. NPNR_PACKED_STRUCT(struct Vertex2DPOD { GLfloat x; GLfloat y; Vertex2DPOD(GLfloat X, GLfloat Y) : x(X), y(Y) {} }); // LineShaderData is a built set of vertices that can be rendered by the // LineShader. // Each LineShaderData can have its' own color and thickness. struct LineShaderData { std::vector vertices; std::vector normals; std::vector miters; std::vector indices; LineShaderData(void) {} void clear(void) { vertices.clear(); normals.clear(); miters.clear(); indices.clear(); } }; // PolyLine is a set of segments defined by points, that can be built to a // ShaderLine for GPU rendering. class PolyLine { private: std::vector points_; bool closed_; void buildPoint(LineShaderData *building, const QVector2D *prev, const QVector2D *cur, const QVector2D *next) const; public: // Create an empty PolyLine. PolyLine(bool closed = false) : closed_(closed) {} // Create a non-closed polyline consisting of one segment. PolyLine(float x0, float y0, float x1, float y1) : closed_(false) { point(x0, y0); point(x1, y1); } // Add a point to the PolyLine. void point(float x, float y) { points_.push_back(QVector2D(x, y)); } // Built PolyLine to shader data. void build(LineShaderData &target) const; // Set whether line is closed (ie. a loop). void setClosed(bool closed) { closed_ = closed; } }; // LineShader is an OpenGL shader program that renders LineShaderData on the // GPU. // The LineShader expects two vertices per line point. It will push those // vertices along the given normal * miter. This is used to 'stretch' the line // to be as wide as the given thickness. The normal and miter are calculated // by the PolyLine build method in order to construct a constant thickness line // with miter edge joints. // // +------+------+ // // | // PolyLine.build() // | // V // // ^ ^ ^ // | | | <--- normal vectors (x2, pointing in the same // +/+----+/+----+/+ direction) // // | // vertex shader // | // V // // +------+------+ ^ by normal * miter * thickness/2 // | | | // +------+------+ V by normal * miter * thickness/2 // // (miter is flipped for every second vertex generated) class LineShader { private: QObject *parent_; QOpenGLShaderProgram *program_; // GL attribute locations. struct { // original position of line vertex GLuint position; // normal by which vertex should be translated GLuint normal; // scalar defining: // - how stretched the normal vector should be to // compensate for bends // - which way the normal should be applied (+1 for one vertex, -1 // for the other) GLuint miter; } attributes_; // GL buffers struct { QOpenGLBuffer position; QOpenGLBuffer normal; QOpenGLBuffer miter; QOpenGLBuffer index; } buffers_; // GL uniform locations. struct { // combines m/v/p matrix to apply GLuint projection; // desired thickness of line GLuint thickness; // color of line GLuint color; } uniforms_; QOpenGLVertexArrayObject vao_; public: LineShader(QObject *parent) : parent_(parent), program_(nullptr) { buffers_.position = QOpenGLBuffer(QOpenGLBuffer::VertexBuffer); buffers_.position.setUsagePattern(QOpenGLBuffer::StaticDraw); buffers_.normal = QOpenGLBuffer(QOpenGLBuffer::VertexBuffer); buffers_.normal.setUsagePattern(QOpenGLBuffer::StaticDraw); buffers_.miter = QOpenGLBuffer(QOpenGLBuffer::VertexBuffer); buffers_.miter.setUsagePattern(QOpenGLBuffer::StaticDraw); buffers_.index = QOpenGLBuffer(QOpenGLBuffer::IndexBuffer); buffers_.index.setUsagePattern(QOpenGLBuffer::StaticDraw); } static constexpr const char *vertexShaderSource_ = "#version 110\n" "attribute highp vec2 position;\n" "attribute highp vec2 normal;\n" "attribute highp float miter;\n" "uniform highp float thickness;\n" "uniform highp mat4 projection;\n" "void main() {\n" " vec2 p = position.xy + vec2(normal * thickness/2.0 / miter);\n" " gl_Position = projection * vec4(p, 0.0, 1.0);\n" "}\n"; static constexpr const char *fragmentShaderSource_ = "#version 110\n" "uniform lowp vec4 color;\n" "void main() {\n" " gl_FragColor = color;\n" "}\n"; // Must be called on initialization. bool compile(void); // Render a LineShaderData with a given M/V/P transformation. void draw(const LineShaderData &data, const QColor &color, float thickness, const QMatrix4x4 &projection); }; NEXTPNR_NAMESPACE_END #endif href='#n91'>91 92 93
/*
             LUFA Library
     Copyright (C) Dean Camera, 2017.

  dean [at] fourwalledcubicle [dot] com
           www.lufa-lib.org
*/

/*
  Copyright 2017  Dean Camera (dean [at] fourwalledcubicle [dot] com)

  Permission to use, copy, modify, distribute, and sell this
  software and its documentation for any purpose is hereby granted
  without fee, provided that the above copyright notice appear in
  all copies and that both that the copyright notice and this
  permission notice and warranty disclaimer appear in supporting
  documentation, and that the name of the author not be used in
  advertising or publicity pertaining to distribution of the
  software without specific, written prior permission.

  The author disclaims all warranties with regard to this
  software, including all implied warranties of merchantability
  and fitness.  In no event shall the author be liable for any
  special, indirect or consequential damages or any damages
  whatsoever resulting from loss of use, data or profits, whether
  in an action of contract, negligence or other tortious action,
  arising out of or in connection with the use or performance of
  this software.
*/

/** \file
 *  \brief LUFA Library Configuration Header File
 *
 *  This header file is used to configure LUFA's compile time options,
 *  as an alternative to the compile time constants supplied through
 *  a makefile.
 *
 *  For information on what each token does, refer to the LUFA
 *  manual section "Summary of Compile Tokens".
 */

#ifndef _LUFA_CONFIG_H_
#define _LUFA_CONFIG_H_

	#if (ARCH == ARCH_AVR8)

		/* Non-USB Related Configuration Tokens: */
//		#define DISABLE_TERMINAL_CODES

		/* USB Class Driver Related Tokens: */
//		#define HID_HOST_BOOT_PROTOCOL_ONLY
//		#define HID_STATETABLE_STACK_DEPTH       {Insert Value Here}
//		#define HID_USAGE_STACK_DEPTH            {Insert Value Here}
//		#define HID_MAX_COLLECTIONS              {Insert Value Here}
//		#define HID_MAX_REPORTITEMS              {Insert Value Here}
//		#define HID_MAX_REPORT_IDS               {Insert Value Here}
//		#define NO_CLASS_DRIVER_AUTOFLUSH

		/* General USB Driver Related Tokens: */
		#define ORDERED_EP_CONFIG
		#define USE_STATIC_OPTIONS               (USB_DEVICE_OPT_FULLSPEED | USB_OPT_REG_ENABLED | USB_OPT_AUTO_PLL)
		#define USB_DEVICE_ONLY
//		#define USB_HOST_ONLY
//		#define USB_STREAM_TIMEOUT_MS            {Insert Value Here}
//		#define NO_LIMITED_CONTROLLER_CONNECT
//		#define NO_SOF_EVENTS

		/* USB Device Mode Driver Related Tokens: */
//		#define USE_RAM_DESCRIPTORS
		#define USE_FLASH_DESCRIPTORS
//		#define USE_EEPROM_DESCRIPTORS
//		#define NO_INTERNAL_SERIAL
		#define FIXED_CONTROL_ENDPOINT_SIZE      8
		#define DEVICE_STATE_AS_GPIOR            0
		#define FIXED_NUM_CONFIGURATIONS         1
//		#define CONTROL_ONLY_DEVICE
		#define INTERRUPT_CONTROL_ENDPOINT
//		#define NO_DEVICE_REMOTE_WAKEUP
//		#define NO_DEVICE_SELF_POWER

		/* USB Host Mode Driver Related Tokens: */
//		#define HOST_STATE_AS_GPIOR              {Insert Value Here}
//		#define USB_HOST_TIMEOUT_MS              {Insert Value Here}
//		#define HOST_DEVICE_SETTLE_DELAY_MS	     {Insert Value Here}
//		#define NO_AUTO_VBUS_MANAGEMENT
//		#define INVERTED_VBUS_ENABLE_LINE

	#else

		#error Unsupported architecture for this LUFA configuration file.

	#endif
#endif