KiCad PCB EDA Suite
Loading...
Searching...
No Matches
rhi_instance.h
Go to the documentation of this file.
1/*
2 * This program source code file is part of KiCad, a free EDA CAD application.
3 *
4 * Copyright The KiCad Developers, see AUTHORS.txt for contributors.
5 *
6 * This program is free software: you can redistribute it and/or modify it
7 * under the terms of the GNU General Public License as published by the
8 * Free Software Foundation, either version 3 of the License, or (at your
9 * option) any later version.
10 *
11 * This program is distributed in the hope that it will be useful, but
12 * WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
14 * General Public License for more details.
15 *
16 * You should have received a copy of the GNU General Public License along
17 * with this program. If not, see <http://www.gnu.org/licenses/>.
18 */
19
20#ifndef RHI_INSTANCE_H
21#define RHI_INSTANCE_H
22
23#include <rhi/rhi_vertex.h>
24
25#include <cstdint>
26
27
45
46
54{
55 float x = 0.0f;
56 float y = 0.0f;
57 uint16_t rotation = 0;
58 uint16_t scaleX = glm::packHalf1x16( 1.0f );
59 uint16_t scaleY = glm::packHalf1x16( 1.0f );
60 uint16_t depth = 0;
61 float params[4] = { 0.0f, 0.0f, 0.0f, 0.0f };
62 uint8_t r = 255;
63 uint8_t g = 255;
64 uint8_t b = 255;
65 uint8_t a = 255;
66 uint16_t flags = 0;
67 uint16_t pixelPad = 0;
68
69 void SetPosition( float aX, float aY ) { x = aX; y = aY; }
70
71 void SetRotation( float aRadians ) { rotation = glm::packHalf1x16( aRadians ); }
72
73 void SetDepth( float aNormalized )
74 {
75 depth = glm::packHalf1x16( aNormalized );
76 }
77
78 void SetColor( uint8_t aR, uint8_t aG, uint8_t aB, uint8_t aA = 255 )
79 {
80 r = aR; g = aG; b = aB; a = aA;
81 }
82
83 void SetParam( int aIndex, float aValue )
84 {
85 if( aIndex >= 0 && aIndex < 4 )
86 params[aIndex] = aValue;
87 }
88
89 void SetFlag( RHI_INSTANCE_FLAG aFlag ) { flags |= aFlag; }
90 void ClearFlag( RHI_INSTANCE_FLAG aFlag ) { flags &= static_cast<uint16_t>( ~aFlag ); }
91 bool HasFlag( RHI_INSTANCE_FLAG aFlag ) const { return ( flags & aFlag ) != 0; }
92};
93
94static_assert( sizeof( RHI_INSTANCE ) == 40, "RHI_INSTANCE must be exactly 40 bytes" );
95static_assert( alignof( RHI_INSTANCE ) <= 4, "RHI_INSTANCE must not require more than 4-byte alignment" );
96
97
102{
104 layout.stride = sizeof( RHI_INSTANCE );
106 layout.attributes = {
112 };
113 return layout;
114}
115
116
117#endif // RHI_INSTANCE_H
RHI_INSTANCE_FLAG
Instance flags controlling how the shaders draw an element.
@ RHI_INSTANCE_FADE_SMALL
text stroke that fades as its glyph height (param 2) shrinks
@ RHI_INSTANCE_BITMAP_GLYPH
a track that draws the bitmap font glyph named by param 2
@ RHI_INSTANCE_OVERLAY_ALPHA
premultiplied with alpha squared, as the OpenGL overlay leaves it
@ RHI_INSTANCE_LENGTH_PAD
a track longer at each end by param 2 pixels
@ RHI_INSTANCE_NEGATIVE
@ RHI_INSTANCE_PIXEL_CIRCLE
a circle on whole pixels, as the OpenGL canvas draws it
@ RHI_INSTANCE_UNDIMMED
keeps its colour when its layer is dimmed
@ RHI_INSTANCE_GROW_OUTWARD
a PIXEL_CIRCLE stroke grows outward from its inner edge
@ RHI_INSTANCE_SCREEN_SPACE
@ RHI_INSTANCE_SCALE_LOD
a track shown only while the view scale is above param 3
@ RHI_INSTANCE_HARD_EDGE
no antialiased edge, for layers that take a pixel once
RHI_VERTEX_BUFFER_LAYOUT_DESC RhiInstanceLayout()
Per-instance vertex layout of RHI_INSTANCE, starting at location 3 after the RHI_VERTEX attributes.
Per-instance data for instanced 2D rendering, packed into 40 bytes.
uint16_t depth
void SetDepth(float aNormalized)
void SetFlag(RHI_INSTANCE_FLAG aFlag)
uint16_t rotation
bool HasFlag(RHI_INSTANCE_FLAG aFlag) const
uint16_t scaleX
uint16_t pixelPad
extra stroke width in sixteenths of a pixel
uint16_t flags
float params[4]
uint16_t scaleY
void SetColor(uint8_t aR, uint8_t aG, uint8_t aB, uint8_t aA=255)
void SetParam(int aIndex, float aValue)
void ClearFlag(RHI_INSTANCE_FLAG aFlag)
void SetRotation(float aRadians)
void SetPosition(float aX, float aY)
RHI_VERTEX_STEP_MODE stepMode
std::vector< RHI_VERTEX_ATTRIBUTE_DESC > attributes