Logo ROOT  
Reference Guide
 
Loading...
Searching...
No Matches
REveRenderData.cxx
Go to the documentation of this file.
1// @(#)root/eve7:$Id$
2// Authors: Matevz Tadel & Alja Mrak-Tadel: 2006, 2007, 2018
3
4/*************************************************************************
5 * Copyright (C) 1995-2019, Rene Brun and Fons Rademakers. *
6 * All rights reserved. *
7 * *
8 * For the licensing terms see $ROOTSYS/LICENSE. *
9 * For the list of contributors see $ROOTSYS/README/CREDITS. *
10 *************************************************************************/
11
13#include <ROOT/REveUtil.hxx>
14
15#include <cstdio>
16#include <cstring>
17
18using namespace ROOT::Experimental;
19
20/////////////////////////////////////////////////////////////////////////////////////////
21/// Constructor
22
23REveRenderData::REveRenderData(const std::string &func, int size_vert, int size_norm, int size_idx) :
24 fRnrFunc(func)
25{
26 Reserve(size_vert, size_norm, size_idx);
27}
28
29/////////////////////////////////////////////////////////////////////////////////////////
30/// Reserve place for render data
31
32void REveRenderData::Reserve(int size_vert, int size_norm, int size_idx)
33{
34 if (size_vert > 0)
35 fVertexBuffer.reserve(size_vert);
36 if (size_norm > 0)
37 fNormalBuffer.reserve(size_norm);
38 if (size_idx > 0)
39 fIndexBuffer.reserve(size_idx);
40}
41
42/////////////////////////////////////////////////////////////////////////////////////////
43/// Write render data to binary buffer
44
45int REveRenderData::Write(char *msg, int maxlen)
46{
47 static const REveException eh("REveRenderData::Write ");
48
49 int off{0};
50
51 auto append = [&](void *buf, int len) {
52 if (off + len > maxlen)
53 throw eh + "output buffer does not have enough memory";
54 memcpy(msg + off, buf, len);
55 off += len;
56 };
57
58 if (!fVertexBuffer.empty())
59 append(&fVertexBuffer[0], fVertexBuffer.size() * sizeof(float));
60
61 if (!fNormalBuffer.empty())
62 append(&fNormalBuffer[0], fNormalBuffer.size() * sizeof(float));
63
64 if (!fIndexBuffer.empty())
65 append(&fIndexBuffer[0], fIndexBuffer.size() * sizeof(int));
66
67 return off;
68}
69
70/////////////////////////////////////////////////////////////////////////////////////////
71/// Calculate texture dimensions to hold nel elements with given alignment on x axis.
72/// Static function.
73///
74/// Implementation could be improved -- now it simply goes for near-square-root(size)
75/// dimensions that satisfy the alignment requirement.
76
77void REveRenderData::CalcTextureSize(int nel, int align, int &sx, int &sy)
78{
79 if (nel <= 0) { sx = sy = 0; return; }
80
81 sx = (int) std::ceil(std::sqrt(nel));
82 int rx = sx % align;
83 if (rx > 0) sx += align - rx;
84 sy = nel / sx;
85 if (nel % sx > 0) sy += 1;
86}
Option_t Option_t TPoint TPoint const char GetTextMagnitude GetFillStyle GetLineColor GetLineWidth GetMarkerStyle GetTextAlign GetTextColor GetTextSize void char Point_t Rectangle_t WindowAttributes_t Float_t Float_t Float_t Int_t Int_t UInt_t UInt_t Rectangle_t Int_t Int_t Window_t TString Int_t GCValues_t GetPrimarySelectionOwner GetDisplay GetScreen GetColormap GetNativeEvent const char const char dpyName wid window const char font_name cursor keysym reg const char only_if_exist regb h Point_t winding char text const char depth char const char Int_t count const char ColorStruct_t color const char Pixmap_t Pixmap_t PictureAttributes_t attr const char char ret_data h unsigned char height h Atom_t Int_t ULong_t ULong_t unsigned char prop_list Atom_t Atom_t Atom_t Time_t UChar_t len
REveException Exception-type thrown by Eve classes.
Definition REveTypes.hxx:42
void Reserve(int size_vert=0, int size_norm=0, int size_idx=0)
Reserve place for render data.
int Write(char *msg, int maxlen)
Write render data to binary buffer.
static void CalcTextureSize(int nel, int align, int &sx, int &sy)
Calculate texture dimensions to hold nel elements with given alignment on x axis.
Namespace for ROOT features in testing.
Definition TROOT.h:100