In WebGL before we call the drawArrays() function we call this function called enableVertexAttribArray() passing the reference to a variable in my compiled glsl program which stores the vertex positions of the object we are going to draw. Can someone explain to me what it does and why we have to call that function.
The attributes in a vertex shader are disabled by default. To use one, you have to first enable it with this function.
You still need to bound a buffer to an enabled attribute, the specification says this:
If a vertex attribute is enabled as an array via enableVertexAttribArray but no buffer is bound to that attribute via bindBuffer and vertexAttribPointer, then calls to drawArrays or drawElements will generate an INVALID_OPERATION error.
Related
I am trying to check whether two rects overlap, one of which comes from getBoundingClientRect, the other I am trying to construct from a mouse position.
I've already discovered that ClientRect is deprecated. Haxe now has a class called DOMRect, but when I try to instantiate it, I get a "cannot be called" warning. I am using haxe 3.2
In the haxe source it seems that the constructor for this class returns void, which doesn't make a lot of sense. The name is also pretty dumb, because I might be making rects which have no relation to the DOM.
Is it not possible to instantiate this thing? If so, what is the point of it?
Do I have to make an anonymous 'rect' or use a map of floats instead?
In Win CE 6.0, class TankObject is defined in a static library, C++ compiler is VS2008; target is ARM4 (/QRarch4).
An instance of class TankObject is constructed by a call of the form
*TankObject myTankObject = new TankObject(parm1, parm2 ...);
Last attribute declared in TankObject definition is an object pointer, and when an assignment is made to same, memory corruption of another dynamically allocated object occurs.
Step into constructor reveals that operator new is called with a size of 0x500. sizeof(TankObject) reveals two different values, depending on the context:
In instantiating context (the application), sizeof(TankObject) and sizeof(*myTankObject) is 0x500.
In context of the object itself (the constructor, or object methods), sizeof(TankObject) and sizeof(*this) is 0x508. The address of last declared attribute is 0x500, relative to object.
The call to new requests and receives 0x500 bytes. The object itself expects and uses 0x508 bytes, which can cause assignments to last attribute to step on other dynamically allocated objects.
Work around is to declare another unused attribute at the end of the object definition, to pad the request to new.
Both contexts include the same .h file, to debug I changed include statement to an explicit path name. I also went through compiler switches, made them identical. So I am puzzled, if any one can shed light, I'm glad, I would like to know a proper solution.
I'm looking at some VTK code which may not be working correctly. Here's a snippet:
vtkSmartPointer<vtkCamera> cam = vtkSmartPointer<vtkCamera>::New();
cam->SetFocalPoint(0, 0, 0);
cam->SetViewUp(perp[0], perp[1], perp[2]);
cam->SetPosition(first_cam_pos);
cam->SetViewAngle(20);
cam->Modified();
It seems to me that the call to Modified() shouldn't be necessary, that calling the four Set functions should automatically signal that the camera has been modified.
Indeed, the Kitware VTK camera example doesn't use Modified() for the camera.
vtkSmartPointer<vtkCamera> camera = vtkSmartPointer<vtkCamera>::New();
camera->SetPosition(0, 0, 20);
camera->SetFocalPoint(0, 0, 0);
// Create a renderer, render window, and interactor
vtkSmartPointer<vtkRenderer> renderer = vtkSmartPointer<vtkRenderer>::New();
renderer->SetActiveCamera(camera);
In other cases, the potentially not-working VTK code I'm looking at uses Update() to manually update — not for the camera object, but elsewhere. Again, I think this is probably not necessary; but clearly Update() and Modified() are there for some reason.
Is there some rule for determining when Modified() and Update() need to be called and when they don't? Are there certain types of objects that need them and certain types that don't? Or is it related to the types of functions that are called on them?
I'm using VTK 6.1, but I'd love to get a general answer if there's some historical context here.
Update() is required when you want to use an object before the pipeline updates it for you. An example is:
vtkSmartPointer<vtkXMLPolyDataReader> reader = \
vtkSmartPointer<vtkPolyDataReader>::New();
reader->SetFileName("myfile.vtp");
// At this point, the reader hasn't yet read the file, so the
// following line with result in polydata being null (or
// something like that)
vtkPolyData* badPolydata = reader->GetOutput();
// However, once you tell the reader "update right now, don't wait
// for the pipeline to update you" with:
reader->Update();
// you can now get access to the data it has read:
vtkPolyData* goodPolydata = reader->GetOutput();
If, on the other hand, you are going to take the reader, attach it to a mapper, attach the mapper to an actor, and display the actor in the renderwindow, then at the time when the renderer says "Ok, now I need the data that drives this whole chain", the pipeline will go back and call Update() on the reader. This is the whole reason for/benefit of the pipeline execution model.
Modified() is required when you want to inform the pipeline "on the next pass, you need to re-process this object". This is done internally by most of the Set* functions, so I guess you just have to look at the implementation to see if Modified() is getting called or not by whatever function you've called that you expect to take effect the next pass through the pipeline.
I am working with the classes in the System.Windows.Documents namespace, trying to write some generic code that will conditionally set the value of certain dependency properties, depending on whether these properties exist on a given class.
For example, the following method assigns an arbitrary value to the Padding property of the passed FrameworkContentElement:
void SetElementPadding(FrameworkContentElement element)
{
element.SetValue(Block.PaddingProperty, new Thickness(155d));
}
However, not all concrete implementations of FrameworkContentElement have a Padding property (Paragraph does but Span does not) so I would expect the property assignment to succeed for types that implement this property and to be silently ignored for types that do not.
But it seems that the above property assignment succeeds for instances of all derivatives of FrameworkContentElement, regardless of whether they implement the Padding property. I make this assumption because I have always been able to read back the assigned value.
I assume there is some flaw in the way I am assigning property values. What should I do to ensure that a given dependency property assignment is ignored by classes that do not implement that property?
Many thanks for your advice.
Tim
All classes that derive from Block have the Padding property. You may use the following modification:
void SetElementPadding(FrameworkContentElement element)
{
var block = element as Block;
if (block == null) return;
block.Padding = new Thickness(155d);
}
Even without this modification everything would still work for you because all you want is for Padding to be ignored by classes that do not support it. This is exactly what would happen. The fact that you can read out the value of a Padding dependency property on an instance that does not support it is probably by design but you shouldn't care. Block and derivatives would honor the value and all others would ignore it.
ATL provides a bunch of macros for creating so-called COM maps - chains of rules of how the QueryInterface() call behaves on a given object. The map begins with BEGIN_COM_MAP and ends with END_COM_MAP. In between the the following can be used (among others):
COM_INTERFACE_ENTRY, COM_INTERFACE_ENTRY2 - to ask C++ to simply cast this class to the corresponding COM interface
COM_INTERFACE_ENTRY_FUNC - to ask C++ to call a function that will retrieve the interface
Now the problem is I want to use COM_INTERFACE_ENTRY_FUNC for every interface I expose so that I can log all the calls - I believe it will help me debugging my component when it is deployed in the field. The implementation of CComObjectRootBase::InternalQueryInterface contains an ATLASSERT:
ATLASSERT(pEntries->pFunc == _ATL_SIMPLEMAPENTRY);
which implies that the following is allright:
BEGIN_COM_MAP
COM_INTERFACE_ENTRY( IMyInterface1 )
COM_INTERFACE_ENTRY_FUNC( __uuidof(IMyInterface2), 0, OnQueryMyInterface2 )
END_COM_MAP
since here the first entry results in _ATL_SIMPLEMAPENTRY type entry but the following is not:
BEGIN_COM_MAP
COM_INTERFACE_ENTRY_FUNC( __uuidof(IMyInterface1), 0, OnQueryMyInterface1 )
COM_INTERFACE_ENTRY_FUNC( __uuidof(IMyInterface2), 0, OnQueryMyInterface2 )
END_COM_MAP
since here the entry type will not be _ATL_SIMPLEMAPENTRY.
This makes no sense at all. Why am I enforced into having a "please, C++, do the static_cast" entry as the first entry of the COM map?
Upd: Resolved after many more hour of debugging, answer added.
Inside ATL there's AtlInternalQueryInterface() that actually does scan the COM map. Inside it there's this code:
if (InlineIsEqualUnknown(iid)) // use first interface
{
IUnknown* pUnk = (IUnknown*)((INT_PTR)pThis+pEntries->dw);
// call AddRef on pUnk, copy it to ppvObject, return S_OK
}
this code actually relies on the first entry of the table being of _ATL_SIMPLEMAPENTRY type since it expects that _ATL_INTMAP_ENTRY::dw stores an offset from the current object this pointer to the necessary interface. In the use cited in the question if the first entry is this one:
COM_INTERFACE_ENTRY_FUNC( __uuidof(IMyInterface1), 0, OnQueryMyInterface1 )
the entry will be of wrong type, but the _ATL_INTMAP_ENTRY::dw will be zero (second parameter to the macro) and the code will happily work each time returning this pointer as IUnknown*. But if the second macro parameter which corresponds to a pass this value into the function specified as the third parameter variable is not zero the program will use that value as the offset and could run into undefined behaviour.