Re: [Interest] [QT3D] How Do I render multiple QEntities in different QViewports in C++?

2016-04-30 Thread Pierre Chicoine
Thank you Sean. Very descriptive.   Since I have such a large system, I
will create an example and pass it to you.

By the way a large percentage of your examples on 5.7 beta don't work. But
I'm sure you're aware of that.

Thank you again.

On Apr 30, 2016 10:55 AM, "Sean Harmer"  wrote:
>
> Hi,
>
> There's two things you need to consider:
>
> 1) The scene graph - the Entities that you wish to draw.
> 2) The framegraph - specifies the algorithm used to draw the scene graph
>
> I assume from your screenshot that you are more or less happy with
defining
> QEntity's to construct your scene graph. If you wish some entities to be
drawn
> in one part of the window (viewport) and the others in another viewport
then
> we need some way of saying "select this set of entities but not that set".
>
> One way of doing this is by using a QLayer component attached to your
entities
> that says which layer that entity is part of. This is just like layers
> photoshop, gimp, blender etc. Create a QLayer, give it a name, and
aggregate
> it onto your QEntity as you do the other components (mesh, transform and
> material).
>
> Doing this doesn't change anything in the rendering on it's own. To
affect the
> change we also need to modify the framegraph. To do this, make sure the
> concept of the framegraph is clear in your mind. Have a read of:
>
> https://www.kdab.com/qt3d-2-0-framegraph/
>
> Each leaf node, corresponds to a portion of your overall scene. To keep
things
> simple, lets only consider the viewports and layer filters you will need.
You
> will need other things in the framegraph too (rendersurfaceselector (if
using
> 5.7), camera selector, technique selector etc). The parts of the
framegraph
> concerned with viewports and layers will look something like this:
>
> Root (e.g. TechniqueSelector)
> |- Viewport [left half of window]
> |- LayerFilter [names="layer1"] (*)
> |- Viewport [right half of window]
> |- LayerFilter [names="layer2"] (**)
>
> Where:
>
> (*) <-- draws entities on "layer1" in left viewport
> (**) <-- draws entities on "layer2" in right viewport
>
> If you then want to use different cameras in the different viewports then
you
> can include a QCameraSelector node in each sub-tree.
>
> Root (e.g. TechniqueSelector)
> |- Viewport [left half of window]
> |- CameraSelector [camera1]
> |- LayerFilter [names="layer1"] (*)
> |- Viewport [right half of window]
> |- CameraSelector [camera2]
> |- LayerFilter [names="layer2"] (**)
>
> Where:
>
> (*) <-- draws entities on "layer1" in left viewport using "camera1"
> (**) <-- draws entities on "layer2" in right viewport using "camera2"
>
> Hopefully that makes sense. In the future, I hope we can provide tooling
and
> perhaps higher level ways of building custom framegraphs. The framegraph
is
> hugely powerful as it totally allows changing the rendering algorithm at
> runtime without having to touch low level C++ graphics code. However, it
is a
> bit tricky to get to grips with at first.
>
> Cheers,
>
> Sean
>
> On Thursday 28 April 2016 13:34:58 Pierre Chicoine wrote:
> > Dear Sirs
> >
> > First: Thank you for Qt3d. The KDAB people are heroes in my book.
> >
> > I have two problems in C++ Qt3D.
> >
> > 1. I am having a difficult time figuring out how to render QEntities
into
> > separate QViewports. All my 3d objects draw to the first QViewport, the
> > rest are black. I have read all your articles and comments everywhere on
> > the Internet that I can find and I am basically confused.
> >
> > Is there a c++ example that would show multiple viewports with distinct
> > separate QEntities? I can't seem to duplicate The QML example
multiviewport
> > in my code. What classes would get me there?
> >
> > 2. Also I'm also confused about QNodes and QEntitys and their
> > relationships. Maybe it's the use of Qt3d version 1 that is messing me
up .
> > I use to have a scene node and all the entities would hang off of one
scene
> > node for each scene. But that doesn't seem to work in version 2. Or do I
> > use the  addComponent on a QFrameGraph instead of a node? Or do I hang
> > Entities off of a viewport?
> >
> > Attached is a pic of my progress which draws all the objects into the
same
> > viewport. The window tiles 2 windows properly but I only draw to one
> > viewport, the second or third stay black. The code here is what I
repeat in
> > each scene class. It's a bit of a mess thrown together to test Qt3D
classes
> > because I don't understand the relationships between all the Qt3D
classes
> > used to place objects in a viewport.
> >
> >
> >  Qt3DCore::QCamera *cameraEntity = new Qt3DCore::QCamera( pParentNode);
> >
> >  cameraEntity->setObjectName(QStringLiteral("cameraEntity"));
> >
> >
cameraEntity->setProjectionType(Qt3DCore::QCameraLens::PerspectiveProjectio
> > n);
> >
> >  cameraEntity->setAspectRatio(1024 / 768);
> >
> >  cameraEntity->setUpVector(QVector3D(0.0f, 1.0f, 0.0f));
> >
> >  

Re: [Interest] Clean way to define and categorize constants in QML

2016-04-30 Thread Sina Dogru
2016-04-29 21:34 GMT+03:00 Jérôme Godbout :

>
> QmlObject
> {
>   readonly property alias myCategory: myCategory_
>
>   QmlObject
>   {
>  id: myCategory_
>  readonly property color red: "#FF0"
>   }
> }
>

Hello Jérôme,

Can you please explain what would be different to use QtObject instead of
QmlObject,

QtObject {
readonly property alias myCategory: myCategory_

QtObject {
id: myCategory_
readonly property color red: "#FF"
}
}
___
Interest mailing list
Interest@qt-project.org
http://lists.qt-project.org/mailman/listinfo/interest


Re: [Interest] [QT3D] How Do I render multiple QEntities in different QViewports in C++?

2016-04-30 Thread Sean Harmer
On Thursday 28 April 2016 14:50:22 charleyb123 . wrote:
> Pierre spaketh:
> > Dear Sirs
> > 
> > First: Thank you for Qt3d. The KDAB people are heroes in my book.
> > 
> 
> +1
> 
> A very big "Thank You!" to what KDAB does in Qt3D.
> 
> They probably don't hear it often enough for all their
> work-and-contributions, but Qt3D is truly technology that pushes the entire
> industry.

Thanks Charley! That's very nice to hear (especially when battling an 
uncooperative CI on a Bank Holiday weekend)!

Sean
--
Dr Sean Harmer | sean.har...@kdab.com | Managing Director UK
Klarälvdalens Datakonsult AB, a KDAB Group company
Tel. UK +44 (0)1625 809908, Sweden (HQ) +46-563-540090
KDAB - Qt Experts - Platform-independent software solutions
___
Interest mailing list
Interest@qt-project.org
http://lists.qt-project.org/mailman/listinfo/interest


Re: [Interest] [QT3D] How Do I render multiple QEntities in different QViewports in C++?

2016-04-30 Thread Sean Harmer
Hi,

There's two things you need to consider:

1) The scene graph - the Entities that you wish to draw.
2) The framegraph - specifies the algorithm used to draw the scene graph

I assume from your screenshot that you are more or less happy with defining 
QEntity's to construct your scene graph. If you wish some entities to be drawn 
in one part of the window (viewport) and the others in another viewport then 
we need some way of saying "select this set of entities but not that set".

One way of doing this is by using a QLayer component attached to your entities 
that says which layer that entity is part of. This is just like layers 
photoshop, gimp, blender etc. Create a QLayer, give it a name, and aggregate 
it onto your QEntity as you do the other components (mesh, transform and 
material).

Doing this doesn't change anything in the rendering on it's own. To affect the 
change we also need to modify the framegraph. To do this, make sure the 
concept of the framegraph is clear in your mind. Have a read of:

https://www.kdab.com/qt3d-2-0-framegraph/

Each leaf node, corresponds to a portion of your overall scene. To keep things 
simple, lets only consider the viewports and layer filters you will need. You 
will need other things in the framegraph too (rendersurfaceselector (if using 
5.7), camera selector, technique selector etc). The parts of the framegraph 
concerned with viewports and layers will look something like this:

Root (e.g. TechniqueSelector)
|- Viewport [left half of window]
|- LayerFilter [names="layer1"] (*)
|- Viewport [right half of window]
|- LayerFilter [names="layer2"] (**)

Where:

(*) <-- draws entities on "layer1" in left viewport
(**) <-- draws entities on "layer2" in right viewport

If you then want to use different cameras in the different viewports then you 
can include a QCameraSelector node in each sub-tree.

Root (e.g. TechniqueSelector)
|- Viewport [left half of window]
|- CameraSelector [camera1]
|- LayerFilter [names="layer1"] (*)
|- Viewport [right half of window]
|- CameraSelector [camera2]
|- LayerFilter [names="layer2"] (**)

Where:

(*) <-- draws entities on "layer1" in left viewport using "camera1"
(**) <-- draws entities on "layer2" in right viewport using "camera2"

Hopefully that makes sense. In the future, I hope we can provide tooling and 
perhaps higher level ways of building custom framegraphs. The framegraph is 
hugely powerful as it totally allows changing the rendering algorithm at 
runtime without having to touch low level C++ graphics code. However, it is a 
bit tricky to get to grips with at first.

Cheers,

Sean

On Thursday 28 April 2016 13:34:58 Pierre Chicoine wrote:
> Dear Sirs
> 
> First: Thank you for Qt3d. The KDAB people are heroes in my book.
> 
> I have two problems in C++ Qt3D.
> 
> 1. I am having a difficult time figuring out how to render QEntities into
> separate QViewports. All my 3d objects draw to the first QViewport, the
> rest are black. I have read all your articles and comments everywhere on
> the Internet that I can find and I am basically confused.
> 
> Is there a c++ example that would show multiple viewports with distinct
> separate QEntities? I can't seem to duplicate The QML example multiviewport
> in my code. What classes would get me there?
> 
> 2. Also I'm also confused about QNodes and QEntitys and their
> relationships. Maybe it's the use of Qt3d version 1 that is messing me up .
> I use to have a scene node and all the entities would hang off of one scene
> node for each scene. But that doesn't seem to work in version 2. Or do I
> use the  addComponent on a QFrameGraph instead of a node? Or do I hang
> Entities off of a viewport?
> 
> Attached is a pic of my progress which draws all the objects into the same
> viewport. The window tiles 2 windows properly but I only draw to one
> viewport, the second or third stay black. The code here is what I repeat in
> each scene class. It's a bit of a mess thrown together to test Qt3D classes
> because I don't understand the relationships between all the Qt3D classes
> used to place objects in a viewport.
> 
> 
>  Qt3DCore::QCamera *cameraEntity = new Qt3DCore::QCamera( pParentNode);
> 
>  cameraEntity->setObjectName(QStringLiteral("cameraEntity"));
> 
>  cameraEntity->setProjectionType(Qt3DCore::QCameraLens::PerspectiveProjectio
> n);
> 
>  cameraEntity->setAspectRatio(1024 / 768);
> 
>  cameraEntity->setUpVector(QVector3D(0.0f, 1.0f, 0.0f));
> 
>  cameraEntity->setViewCenter(QVector3D(0.0f, 3.5f, 0.0f));
> 
>  //cameraEntity->lens()->setPerspectiveProjection(60.0f, 16.0f/9.0f,
> 0.1f, 1000.0f);
> 
> 
>  if(pScenesSet) // if it's a scene then we want to set it where they want it
> 
>   cameraEntity->setPosition(QVector3D(pScenesSet->CamXPos - 20,
> pScenesSet->CamYPos + 80, pScenesSet->CamZPos));
> 
>  else // so it's a schematic
> 
>   cameraEntity->setPosition(QVector3D(-20, 65, 180));
> 
> 
>  theApp->input->setCamera(cameraEntity); // not sure 

Re: [Interest] Example for: QTreeView + QAbstractItemModel + external data

2016-04-30 Thread Andy
On Sat, Apr 30, 2016 at 4:08 AM, anton  wrote:

> Thanks Björn,
>
> I'll try it (actually i did the job in the rowCount() function..)
> I would have preferred that the documentation be clear about this,
> I mean with a detailed example :-)
>

Slight aside:

Since you're working with QAbstractItemModel I would highly recommend using
Model Test in your debug build:

  https://wiki.qt.io/Model_Test

I've written many QAbstractItemModel-derived classes, and I still find them
hard to get right. Model Test has helped catch a lot of edge cases.


> Thanks
>
> Anton
>
> Björn Schäpers wrote:
>
> > Am 26.04.2016 um 19:05 schrieb anton:
> >> Hi,
> >>
> >> I have subclassed QAbstractItemModel,
> >> and I want to load additionally data in the model
> >> as soon as somebody clicks on the [+]
> >> in the treeview to load the children of this
> >> item form an external data ( web- app which gives me json data back).
> >>
> >> Now:
> >>   I reimplemented hasChildren() in the model
> >> but i am not sure about the moment to load the data.
> >>
> >> I suppose that the rowCount() method of the model is called
> >> when somebody expands an item in the view?
> >> If not what is the moment when my model should ask for additional Data?
> >>
> >> Does there exist a small example which demonstrates how to
> >> handle this in an optimal way.
> >> Not sure about beginInsertRows() or layoutChanged() ..
> >> I am experimenting but i get also some crashes so an
> >> example project would be nice.
> >>
> >> Thanks
> >>
> >> Anton
> > I think you are looking for QAbstractItemModel::canFetchMore() and
> > fetchMore(). See also the last paragraph in
> > http://doc.qt.io/qt-5/qabstractitemmodel.html
> >
> > To create models that populate incrementally, you can reimplement
> > fetchMore() and canFetchMore(). If the reimplementation of fetchMore()
> > adds rows to the model, beginInsertRows() and endInsertRows() must be
> > called.
>
>
> ___
> Interest mailing list
> Interest@qt-project.org
> http://lists.qt-project.org/mailman/listinfo/interest
>

---
Andy Maloney  //  https://asmaloney.com
twitter ~ @asmaloney 
___
Interest mailing list
Interest@qt-project.org
http://lists.qt-project.org/mailman/listinfo/interest


Re: [Interest] armv7a-hard-float in Qt android apps

2016-04-30 Thread Elvis Stansvik
2016-04-30 11:51 GMT+02:00 Ola Røer Thorsen :
>
> 2016-04-30 10:46 GMT+02:00 Jean-Michaël Celerier
> :
>>
>> https://godbolt.org/g/DqBlFG
>>
>> With gcc -O1
>>
>> float f(float x)
>> {
>>   return 2. * x;
>> }
>>
>> becomes
>>
>> f(float):
>> addss   %xmm0, %xmm0
>> ret
>>
>>
>> and
>>
>> float g (float x)
>> {
>>   return 2.f * x;
>> }
>>
>> becomes
>>
>> g(float):
>> addss   %xmm0, %xmm0
>> ret
>>
>
> This is on x86. I was talking about ARM with single-precision FPUs and the
> general advice not to use double precision constants if possible there.

Also, Jean-Michaël's example is a little unfortunate since the
compiler is smart enough to convert the multiplication by 2 to an
addss instruction. Changing the constant to 2.1 is more interesting
(https://godbolt.org/g/Cgw2cR):

f(float):
cvtss2sd%xmm0, %xmm0
mulsd   .LC0(%rip), %xmm0
cvtsd2ss%xmm0, %xmm0
ret
g(float):
mulss   .LC1(%rip), %xmm0
ret
.LC0:
.long   3435973837
.long   1073794252
.LC1:
.long   1074161254

So conversion to double-precision and then back to single-precision in
the code for f.

For reference, here's the result with ARM GCC 4.5.3:
https://godbolt.org/g/r7Kf1H

Elvis

>
> This is what GCC itself says in the documentation for -Wdouble-promotion:
>
> -Wdouble-promotion (C, C++, Objective-C and Objective-C++ only)Give a
> warning when a value of type float is implicitly promoted to double. CPUs
> with a 32-bit “single-precision” floating-point unit implement float in
> hardware, but emulate double in software. On such a machine, doing
> computations using double values is much more expensive because of the
> overhead required for software emulation.
>
> It is easy to accidentally do computations with double because
> floating-point literals are implicitly of type double. For example, in:
>
>   float area(float radius)
>   {
>  return 3.14159 * radius * radius;
>   }
>
> the compiler performs the entire computation with double because the
> floating-point literal is a double.
>
>
>
> ___
> Interest mailing list
> Interest@qt-project.org
> http://lists.qt-project.org/mailman/listinfo/interest
>
___
Interest mailing list
Interest@qt-project.org
http://lists.qt-project.org/mailman/listinfo/interest


[Interest] [Qt 3D] What is AspectCreateFunction? (or how to expose a custom aspect to QML)

2016-04-30 Thread Adrián Chaves Fernández
The Qt input system does not work for me. The Qt key event system, with its
special handling of modifier keys, is designed for (desktop) applications,
not for games. For example, as far as I can see, there is no reliable way
for me to use modifier keys, such as Shift or Ctrl, as regular keys. So I
plan to create a custom input aspect that uses SDL for input.

I’ve had a look at the QInputAspect code, and now I am trying to create the
most basic aspect, so that I can verify that the aspect barebones are in
place before I start implementing my custom input handling into this new
aspect. So right now I have a QAbstractAspect subclass that implements a
constructor and overrides jobsToExecute(), onInitialize() and onCleanup().

Now I am trying to figure out how to define the ‘name’ of my custom input
aspect, the keyword that I must pass to the ‘aspects’ property of the
‘Scene3D’ QML element so that it instantiates my custom aspect.

At the end of ‘qinputaspect.cpp’ I found QT3D_REGISTER_NAMESPACED_ASPECT(),
which receives the "input" string as a parameter. I assume that this is the
code that determines that passing "input" to the ‘aspects’ property of the
‘Scene3D’ QML element adds an instance of the QInputAspect aspect to the
simulation. So I am trying to do that in my code as well.

Since my custom aspect (InputAspect) does not have a namespace, I cannot
just use the QT3D_REGISTER_NAMESPACED_ASPECT() macro, so instead I tried to
replicate its code. This is the result:

void qt3d_QAspectFactory_addDefaultFactory(const QString &, const
QMetaObject *, AspectCreateFunction);

*(*AspectCreateFunction)(QObject *)
*qt3d_InputAspect_createFunction(QObject *parent)
{
return new InputAspect(parent);
}

void qt3d_InputAspect_registerFunction()
{

qt3d_QAspectFactory_addDefaultFactory(QStringLiteral("chopshop_input"),
::staticMetaObject, qt3d_InputAspect_createFunction);
}

Q_CONSTRUCTOR_FUNCTION(qt3d_InputAspect_registerFunction)

But this code fails to compile:

…/inputaspect.cpp:46:82: error: ‘AspectCreateFunction’ has not been
declared
void qt3d_QAspectFactory_addDefaultFactory(const QString &, const
QMetaObject *, AspectCreateFunction);

^
I’ve grepped the sources of Qt 3D 5.6 for such a name, but the only
appearances seem to be those 2 in the QT3D_REGISTER_NAMESPACED_ASPECT()
macro definition:

[gallaecio@afonso qt3d]$ grep AspectCreateFunction * -FIR
src/core/aspects/qabstractaspect.h:typedef QAbstractAspect
*(*AspectCreateFunction)(QObject *); \
src/core/aspects/qabstractaspect.h:QT3DCORESHARED_EXPORT void
qt3d_QAspectFactory_addDefaultFactory(const QString &, const QMetaObject *,
AspectCreateFunction); \

I don’t know what to do now.
___
Interest mailing list
Interest@qt-project.org
http://lists.qt-project.org/mailman/listinfo/interest


Re: [Interest] armv7a-hard-float in Qt android apps

2016-04-30 Thread Ola Røer Thorsen
2016-04-30 10:46 GMT+02:00 Jean-Michaël Celerier <
jeanmichael.celer...@gmail.com>:

> https://godbolt.org/g/DqBlFG
>
> With gcc -O1
>
> float f(float x)
> {
>   return 2. * x;
> }
>
> becomes
>
> f(float):
> addss   %xmm0, %xmm0
> ret
>
>
> and
>
> float g (float x)
> {
>   return 2.f * x;
> }
>
> becomes
>
> g(float):
> addss   %xmm0, %xmm0
> ret
>
>
This is on x86. I was talking about ARM with single-precision FPUs and the
general advice not to use double precision constants if possible there.

This is what GCC itself says in the documentation for -Wdouble-promotion:

-Wdouble-promotion (C, C++, Objective-C and Objective-C++ only)Give a
warning when a value of type float is implicitly promoted to double. CPUs
with a 32-bit “single-precision” floating-point unit implement float in
hardware, but emulate double in software. On such a machine, doing
computations using double values is much more expensive because of the
overhead required for software emulation.

It is easy to accidentally do computations with double because
floating-point literals are implicitly of type double. For example, in:

  float area(float radius)
  {
 return 3.14159 * radius * radius;
  }

the compiler performs the entire computation with double because the
floating-point literal is a double.
___
Interest mailing list
Interest@qt-project.org
http://lists.qt-project.org/mailman/listinfo/interest


Re: [Interest] armv7a-hard-float in Qt android apps

2016-04-30 Thread Jean-Michaël Celerier
https://godbolt.org/g/DqBlFG

With gcc -O1

float f(float x)
{
  return 2. * x;
}

becomes

f(float):
addss   %xmm0, %xmm0
ret


and

float g (float x)
{
  return 2.f * x;
}

becomes

g(float):
addss   %xmm0, %xmm0
ret


On Fri, Apr 29, 2016 at 6:30 PM, Ola Røer Thorsen 
wrote:

>
>
> 2016-04-29 16:36 GMT+02:00 Jean-Michaël Celerier <
> jeanmichael.celer...@gmail.com>:
>
>>
>> On Fri, Apr 29, 2016 at 1:55 PM, Ola Røer Thorsen 
>> wrote:
>>
>>>
>>> float a = 1.0f;
>>> float b = 2.0*a; // BAD!
>>> float b = 2.0f*a; // Good!
>>>
>>
>> Pretty sure that this would be a non-problem starting at -O1 optimization
>> level.
>>
>
> Well you're wrong. If you multiply with a double precision constant value
> (2.0), the multiplication is done in double precision and the result is
> then converted to single precision, regardless of the optimize level. This
> makes a big difference on hardware that only support single-precision in
> hardware (I know this from experience, not assumptions).
>
>
>
> ___
> Interest mailing list
> Interest@qt-project.org
> http://lists.qt-project.org/mailman/listinfo/interest
>
>
___
Interest mailing list
Interest@qt-project.org
http://lists.qt-project.org/mailman/listinfo/interest


Re: [Interest] Example for: QTreeView + QAbstractItemModel + external data

2016-04-30 Thread anton
Thanks Björn,

I'll try it (actually i did the job in the rowCount() function..)
I would have preferred that the documentation be clear about this,
I mean with a detailed example :-)

Thanks

Anton

Björn Schäpers wrote:

> Am 26.04.2016 um 19:05 schrieb anton:
>> Hi,
>>
>> I have subclassed QAbstractItemModel,
>> and I want to load additionally data in the model
>> as soon as somebody clicks on the [+]
>> in the treeview to load the children of this
>> item form an external data ( web- app which gives me json data back).
>>
>> Now:
>>   I reimplemented hasChildren() in the model
>> but i am not sure about the moment to load the data.
>>
>> I suppose that the rowCount() method of the model is called
>> when somebody expands an item in the view?
>> If not what is the moment when my model should ask for additional Data?
>>
>> Does there exist a small example which demonstrates how to
>> handle this in an optimal way.
>> Not sure about beginInsertRows() or layoutChanged() ..
>> I am experimenting but i get also some crashes so an
>> example project would be nice.
>>
>> Thanks
>>
>> Anton
> I think you are looking for QAbstractItemModel::canFetchMore() and
> fetchMore(). See also the last paragraph in
> http://doc.qt.io/qt-5/qabstractitemmodel.html
> 
> To create models that populate incrementally, you can reimplement
> fetchMore() and canFetchMore(). If the reimplementation of fetchMore()
> adds rows to the model, beginInsertRows() and endInsertRows() must be
> called.


___
Interest mailing list
Interest@qt-project.org
http://lists.qt-project.org/mailman/listinfo/interest