2011-02-25 13:38:24 +00:00
|
|
|
/** \file gameengine/Rasterizer/RAS_OpenGLRasterizer/RAS_ListRasterizer.cpp
|
|
|
|
* \ingroup bgerastogl
|
|
|
|
*/
|
2006-04-02 21:04:20 +00:00
|
|
|
//
|
|
|
|
#include <iostream>
|
|
|
|
|
|
|
|
#include "RAS_ListRasterizer.h"
|
|
|
|
|
|
|
|
#ifdef WIN32
|
|
|
|
#include <windows.h>
|
|
|
|
#endif // WIN32
|
Merge of apricot branch game engine changes into trunk, excluding GLSL.
GLEW
====
Added the GLEW opengl extension library into extern/, always compiled
into Blender now. This is much nicer than doing this kind of extension
management manually, and will be used in the game engine, for GLSL, and
other opengl extensions.
* According to the GLEW website it works on Windows, Linux, Mac OS X,
FreeBSD, Irix, and Solaris. There might still be platform specific
issues due to this commit, so let me know and I'll look into it.
* This means also that all extensions will now always be compiled in,
regardless of the glext.h on the platform where compilation happens.
Game Engine
===========
Refactoring of the use of opengl extensions and other drawing code
in the game engine, and cleaning up some hacks related to GLSL
integration. These changes will be merged into trunk too after this.
The game engine graphics demos & apricot level survived my tests,
but this could use some good testing of course.
For users: please test with the options "Generate Display Lists" and
"Vertex Arrays" enabled, these should be the fastest and are supposed
to be "unreliable", but if that's the case that's probably due to bugs
that can be fixed.
* The game engine now also uses GLEW for extensions, replacing the
custom opengl extensions code that was there. Removes a lot of
#ifdef's, but the runtime checks stay of course.
* Removed the WITHOUT_GLEXT environment variable. This was added to
work around a specific bug and only disabled multitexturing anyway.
It might also have caused a slowdown since it was retrieving the
environment variable for every vertex in immediate mode (bug #13680).
* Refactored the code to allow drawing skinned meshes with vertex
arrays too, removing some specific immediate mode drawing functions
for this that only did extra normal calculation. Now it always splits
vertices of flat faces instead.
* Refactored normal recalculation with some minor optimizations,
required for the above change.
* Removed some outdated code behind the __NLA_OLDDEFORM #ifdef.
* Fixed various bugs in setting of multitexture coordinates and vertex
attributes for vertex arrays. These were not being enabled/disabled
correct according to the opengl spec, leading to crashes. Also tangent
attributes used an immediate mode call for vertex arrays, which can't
work.
* Fixed use of uninitialized variable in RAS_TexVert.
* Exporting skinned meshes was doing O(n^2) lookups for vertices and
deform weights, now uses same trick as regular meshes.
2008-06-17 10:27:34 +00:00
|
|
|
|
|
|
|
#include "GL/glew.h"
|
2006-04-02 21:04:20 +00:00
|
|
|
|
Merge of first part of changes from the apricot branch, especially
the features that are needed to run the game. Compile tested with
scons, make, but not cmake, that seems to have an issue not related
to these changes. The changes include:
* GLSL support in the viewport and game engine, enable in the game
menu in textured draw mode.
* Synced and merged part of the duplicated blender and gameengine/
gameplayer drawing code.
* Further refactoring of game engine drawing code, especially mesh
storage changed a lot.
* Optimizations in game engine armatures to avoid recomputations.
* A python function to get the framerate estimate in game.
* An option take object color into account in materials.
* An option to restrict shadow casters to a lamp's layers.
* Increase from 10 to 18 texture slots for materials, lamps, word.
An extra texture slot shows up once the last slot is used.
* Memory limit for undo, not enabled by default yet because it
needs the .B.blend to be changed.
* Multiple undo for image painting.
* An offset for dupligroups, so not all objects in a group have to
be at the origin.
2008-09-04 20:51:28 +00:00
|
|
|
#include "RAS_MaterialBucket.h"
|
2006-04-02 21:04:20 +00:00
|
|
|
#include "RAS_TexVert.h"
|
|
|
|
#include "MT_assert.h"
|
|
|
|
|
2010-10-18 06:52:10 +00:00
|
|
|
//#if defined(DEBUG)
|
2006-04-05 02:01:34 +00:00
|
|
|
//#ifdef WIN32
|
|
|
|
//#define spit(x) std::cout << x << std::endl;
|
|
|
|
//#endif //WIN32
|
|
|
|
//#else
|
2006-04-02 21:04:20 +00:00
|
|
|
#define spit(x)
|
2006-04-05 02:01:34 +00:00
|
|
|
//#endif
|
2006-04-02 21:04:20 +00:00
|
|
|
|
2008-03-09 22:02:32 +00:00
|
|
|
RAS_ListSlot::RAS_ListSlot(RAS_ListRasterizer* rasty)
|
2006-04-02 21:04:20 +00:00
|
|
|
: KX_ListSlot(),
|
2008-03-09 22:02:32 +00:00
|
|
|
m_list(0),
|
Merge of apricot branch game engine changes into trunk, excluding GLSL.
GLEW
====
Added the GLEW opengl extension library into extern/, always compiled
into Blender now. This is much nicer than doing this kind of extension
management manually, and will be used in the game engine, for GLSL, and
other opengl extensions.
* According to the GLEW website it works on Windows, Linux, Mac OS X,
FreeBSD, Irix, and Solaris. There might still be platform specific
issues due to this commit, so let me know and I'll look into it.
* This means also that all extensions will now always be compiled in,
regardless of the glext.h on the platform where compilation happens.
Game Engine
===========
Refactoring of the use of opengl extensions and other drawing code
in the game engine, and cleaning up some hacks related to GLSL
integration. These changes will be merged into trunk too after this.
The game engine graphics demos & apricot level survived my tests,
but this could use some good testing of course.
For users: please test with the options "Generate Display Lists" and
"Vertex Arrays" enabled, these should be the fastest and are supposed
to be "unreliable", but if that's the case that's probably due to bugs
that can be fixed.
* The game engine now also uses GLEW for extensions, replacing the
custom opengl extensions code that was there. Removes a lot of
#ifdef's, but the runtime checks stay of course.
* Removed the WITHOUT_GLEXT environment variable. This was added to
work around a specific bug and only disabled multitexturing anyway.
It might also have caused a slowdown since it was retrieving the
environment variable for every vertex in immediate mode (bug #13680).
* Refactored the code to allow drawing skinned meshes with vertex
arrays too, removing some specific immediate mode drawing functions
for this that only did extra normal calculation. Now it always splits
vertices of flat faces instead.
* Refactored normal recalculation with some minor optimizations,
required for the above change.
* Removed some outdated code behind the __NLA_OLDDEFORM #ifdef.
* Fixed various bugs in setting of multitexture coordinates and vertex
attributes for vertex arrays. These were not being enabled/disabled
correct according to the opengl spec, leading to crashes. Also tangent
attributes used an immediate mode call for vertex arrays, which can't
work.
* Fixed use of uninitialized variable in RAS_TexVert.
* Exporting skinned meshes was doing O(n^2) lookups for vertices and
deform weights, now uses same trick as regular meshes.
2008-06-17 10:27:34 +00:00
|
|
|
m_flag(LIST_MODIFY|LIST_CREATE),
|
2010-03-25 08:48:31 +00:00
|
|
|
m_matnr(0),
|
|
|
|
m_rasty(rasty)
|
2006-04-02 21:04:20 +00:00
|
|
|
{
|
|
|
|
}
|
|
|
|
|
2008-03-09 22:02:32 +00:00
|
|
|
int RAS_ListSlot::Release()
|
|
|
|
{
|
|
|
|
if (--m_refcount > 0)
|
|
|
|
return m_refcount;
|
|
|
|
m_rasty->RemoveListSlot(this);
|
|
|
|
delete this;
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2006-04-02 21:04:20 +00:00
|
|
|
RAS_ListSlot::~RAS_ListSlot()
|
|
|
|
{
|
|
|
|
RemoveList();
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
void RAS_ListSlot::RemoveList()
|
|
|
|
{
|
|
|
|
if(m_list != 0) {
|
|
|
|
spit("Releasing display list (" << m_list << ")");
|
|
|
|
glDeleteLists((GLuint)m_list, 1);
|
|
|
|
m_list =0;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
void RAS_ListSlot::DrawList()
|
|
|
|
{
|
|
|
|
if(m_flag &LIST_STREAM || m_flag& LIST_NOCREATE) {
|
|
|
|
RemoveList();
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
if(m_flag &LIST_MODIFY) {
|
|
|
|
if(m_flag &LIST_CREATE) {
|
|
|
|
if(m_list == 0) {
|
|
|
|
m_list = (unsigned int)glGenLists(1);
|
|
|
|
m_flag = m_flag &~ LIST_CREATE;
|
|
|
|
spit("Created display list (" << m_list << ")");
|
|
|
|
}
|
|
|
|
}
|
|
|
|
if(m_list != 0)
|
2007-11-04 05:31:20 +00:00
|
|
|
glNewList((GLuint)m_list, GL_COMPILE);
|
2006-04-02 21:04:20 +00:00
|
|
|
|
|
|
|
m_flag |= LIST_BEGIN;
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
glCallList(m_list);
|
|
|
|
}
|
|
|
|
|
|
|
|
void RAS_ListSlot::EndList()
|
|
|
|
{
|
|
|
|
if(m_flag & LIST_BEGIN) {
|
|
|
|
glEndList();
|
|
|
|
m_flag = m_flag &~(LIST_BEGIN|LIST_MODIFY);
|
|
|
|
m_flag |= LIST_END;
|
2007-11-04 05:31:20 +00:00
|
|
|
glCallList(m_list);
|
2006-04-02 21:04:20 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
void RAS_ListSlot::SetModified(bool mod)
|
|
|
|
{
|
|
|
|
if(mod && !(m_flag & LIST_MODIFY)) {
|
|
|
|
spit("Modifying list (" << m_list << ")");
|
|
|
|
m_flag = m_flag &~ LIST_END;
|
2006-04-13 05:11:34 +00:00
|
|
|
m_flag |= LIST_STREAM;
|
2006-04-02 21:04:20 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
bool RAS_ListSlot::End()
|
|
|
|
{
|
|
|
|
return (m_flag &LIST_END)!=0;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
2007-11-06 18:39:16 +00:00
|
|
|
RAS_ListRasterizer::RAS_ListRasterizer(RAS_ICanvas* canvas, bool useVertexArrays, bool lock)
|
|
|
|
: RAS_VAOpenGLRasterizer(canvas, lock),
|
2009-05-07 19:36:12 +00:00
|
|
|
mUseVertexArrays(useVertexArrays),
|
|
|
|
mATI(false)
|
2006-04-02 21:04:20 +00:00
|
|
|
{
|
2009-05-07 19:36:12 +00:00
|
|
|
if (!strcmp((const char*)glGetString(GL_VENDOR), "ATI Technologies Inc."))
|
|
|
|
mATI = true;
|
2006-04-02 21:04:20 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
RAS_ListRasterizer::~RAS_ListRasterizer()
|
|
|
|
{
|
|
|
|
ReleaseAlloc();
|
|
|
|
}
|
|
|
|
|
2008-03-09 22:02:32 +00:00
|
|
|
void RAS_ListRasterizer::RemoveListSlot(RAS_ListSlot* list)
|
|
|
|
{
|
2009-05-14 13:47:08 +00:00
|
|
|
if (list->m_flag & LIST_DERIVEDMESH) {
|
|
|
|
RAS_DerivedMeshLists::iterator it = mDerivedMeshLists.begin();
|
|
|
|
while(it != mDerivedMeshLists.end()) {
|
2010-03-24 22:55:45 +00:00
|
|
|
RAS_ListSlots *slots = it->second;
|
|
|
|
if (slots->size() > list->m_matnr && slots->at(list->m_matnr) == list) {
|
|
|
|
(*slots)[list->m_matnr] = NULL;
|
|
|
|
// check if all slots are NULL and if yes, delete the entry
|
|
|
|
int i;
|
|
|
|
for (i=slots->size(); i-- > 0; ) {
|
|
|
|
if (slots->at(i) != NULL)
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
if (i < 0) {
|
|
|
|
slots->clear();
|
|
|
|
delete slots;
|
|
|
|
mDerivedMeshLists.erase(it);
|
|
|
|
}
|
2009-05-14 13:47:08 +00:00
|
|
|
break;
|
|
|
|
}
|
2010-03-24 22:55:45 +00:00
|
|
|
++it;
|
2009-05-14 13:47:08 +00:00
|
|
|
}
|
|
|
|
} else {
|
|
|
|
RAS_ArrayLists::iterator it = mArrayLists.begin();
|
|
|
|
while(it != mArrayLists.end()) {
|
|
|
|
if (it->second == list) {
|
|
|
|
mArrayLists.erase(it);
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
it++;
|
2008-03-09 22:02:32 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
Merge of first part of changes from the apricot branch, especially
the features that are needed to run the game. Compile tested with
scons, make, but not cmake, that seems to have an issue not related
to these changes. The changes include:
* GLSL support in the viewport and game engine, enable in the game
menu in textured draw mode.
* Synced and merged part of the duplicated blender and gameengine/
gameplayer drawing code.
* Further refactoring of game engine drawing code, especially mesh
storage changed a lot.
* Optimizations in game engine armatures to avoid recomputations.
* A python function to get the framerate estimate in game.
* An option take object color into account in materials.
* An option to restrict shadow casters to a lamp's layers.
* Increase from 10 to 18 texture slots for materials, lamps, word.
An extra texture slot shows up once the last slot is used.
* Memory limit for undo, not enabled by default yet because it
needs the .B.blend to be changed.
* Multiple undo for image painting.
* An offset for dupligroups, so not all objects in a group have to
be at the origin.
2008-09-04 20:51:28 +00:00
|
|
|
RAS_ListSlot* RAS_ListRasterizer::FindOrAdd(RAS_MeshSlot& ms)
|
2006-04-02 21:04:20 +00:00
|
|
|
{
|
|
|
|
/*
|
|
|
|
Keep a copy of constant lists submitted for rendering,
|
|
|
|
this guards against (replicated)new...delete every frame,
|
|
|
|
and we can reuse lists!
|
Merge of first part of changes from the apricot branch, especially
the features that are needed to run the game. Compile tested with
scons, make, but not cmake, that seems to have an issue not related
to these changes. The changes include:
* GLSL support in the viewport and game engine, enable in the game
menu in textured draw mode.
* Synced and merged part of the duplicated blender and gameengine/
gameplayer drawing code.
* Further refactoring of game engine drawing code, especially mesh
storage changed a lot.
* Optimizations in game engine armatures to avoid recomputations.
* A python function to get the framerate estimate in game.
* An option take object color into account in materials.
* An option to restrict shadow casters to a lamp's layers.
* Increase from 10 to 18 texture slots for materials, lamps, word.
An extra texture slot shows up once the last slot is used.
* Memory limit for undo, not enabled by default yet because it
needs the .B.blend to be changed.
* Multiple undo for image painting.
* An offset for dupligroups, so not all objects in a group have to
be at the origin.
2008-09-04 20:51:28 +00:00
|
|
|
:: sorted by mesh slot
|
2006-04-02 21:04:20 +00:00
|
|
|
*/
|
Merge of first part of changes from the apricot branch, especially
the features that are needed to run the game. Compile tested with
scons, make, but not cmake, that seems to have an issue not related
to these changes. The changes include:
* GLSL support in the viewport and game engine, enable in the game
menu in textured draw mode.
* Synced and merged part of the duplicated blender and gameengine/
gameplayer drawing code.
* Further refactoring of game engine drawing code, especially mesh
storage changed a lot.
* Optimizations in game engine armatures to avoid recomputations.
* A python function to get the framerate estimate in game.
* An option take object color into account in materials.
* An option to restrict shadow casters to a lamp's layers.
* Increase from 10 to 18 texture slots for materials, lamps, word.
An extra texture slot shows up once the last slot is used.
* Memory limit for undo, not enabled by default yet because it
needs the .B.blend to be changed.
* Multiple undo for image painting.
* An offset for dupligroups, so not all objects in a group have to
be at the origin.
2008-09-04 20:51:28 +00:00
|
|
|
RAS_ListSlot* localSlot = (RAS_ListSlot*)ms.m_DisplayList;
|
2006-04-02 21:04:20 +00:00
|
|
|
if(!localSlot) {
|
BGE: Support mesh modifiers in the game engine.
Realtime modifiers applied on mesh objects will be supported in
the game engine with the following limitations:
- Only real time modifiers are supported (basically all of them!)
- Virtual modifiers resulting from parenting are not supported:
armature, curve, lattice. You can still use these modifiers
(armature is really not recommended) but in non parent mode.
The BGE has it's own parenting capability for armature.
- Modifiers are computed on the host (using blender modifier
stack).
- Modifiers are statically evaluated: any possible time dependency
in the modifiers is not supported (don't know enough about
modifiers to be more specific).
- Modifiers are reevaluated if the underlying mesh is deformed
due to shape action or armature action. Beware that this is
very CPU intensive; modifiers should really be used for static
objects only.
- Physics is still based on the original mesh: if you have a
mirror modifier, the physic shape will be limited to one half
of the resulting object. Therefore, the modifiers should
preferably be used on graphic objects.
- Scripts have no access to the modified mesh.
- Modifiers that are based on objects interaction (boolean,..)
will not be dependent on the objects position in the GE.
What you see in the 3D view is what you get in the GE regardless
on the object position, velocity, etc.
Besides that, the feature is compatible with all the BGE features
that affect meshes: armature action, shape action, relace mesh,
VideoTexture, add object, dupligroup.
Known problems:
- This feature is a bit hacky: the BGE uses the derived mesh draw
functions to display the object. This drawing method is a
bit slow and is not 100% compatible with the BGE. There may
be some problems in multi-texture mode: the multi-texture
coordinates are not sent to the GPU.
Texface and GLSL on the other hand should be fully supported.
- Culling is still based on the extend of the original mesh.
If you have a modifer that extends the size of the mesh,
the object may disappear while still in the view frustrum.
- Derived mesh is not shared between replicas.
The derived mesh is allocated and computed for each object
with modifiers, regardless if they are static replicas.
- Display list are not created on objects with modifiers.
I should be able to fix the above problems before release.
However, the feature is already useful for game development.
Once you are ready to release the game, you can apply the modifiers
to get back display list support and mesh sharing capability.
MSVC, scons, Cmake, makefile updated.
Enjoy
/benoit
2009-04-21 11:01:09 +00:00
|
|
|
if (ms.m_pDerivedMesh) {
|
|
|
|
// that means that we draw based on derived mesh, a display list is possible
|
2009-05-14 13:47:08 +00:00
|
|
|
// Note that we come here only for static derived mesh
|
2010-03-24 22:55:45 +00:00
|
|
|
int matnr = ms.m_bucket->GetPolyMaterial()->GetMaterialIndex();
|
2010-03-25 08:48:31 +00:00
|
|
|
RAS_ListSlot* nullSlot = NULL;
|
2010-03-24 22:55:45 +00:00
|
|
|
RAS_ListSlots *listVector;
|
2009-05-14 13:47:08 +00:00
|
|
|
RAS_DerivedMeshLists::iterator it = mDerivedMeshLists.find(ms.m_pDerivedMesh);
|
|
|
|
if(it == mDerivedMeshLists.end()) {
|
2010-03-25 08:48:31 +00:00
|
|
|
listVector = new RAS_ListSlots(matnr+4, nullSlot);
|
2009-05-14 13:47:08 +00:00
|
|
|
localSlot = new RAS_ListSlot(this);
|
|
|
|
localSlot->m_flag |= LIST_DERIVEDMESH;
|
2010-03-24 22:55:45 +00:00
|
|
|
localSlot->m_matnr = matnr;
|
2010-03-25 08:48:31 +00:00
|
|
|
listVector->at(matnr) = localSlot;
|
2010-03-24 22:55:45 +00:00
|
|
|
mDerivedMeshLists.insert(std::pair<DerivedMesh*, RAS_ListSlots*>(ms.m_pDerivedMesh, listVector));
|
2009-05-14 13:47:08 +00:00
|
|
|
} else {
|
2010-03-24 22:55:45 +00:00
|
|
|
listVector = it->second;
|
|
|
|
if (listVector->size() <= matnr)
|
2010-03-25 08:48:31 +00:00
|
|
|
listVector->resize(matnr+4, nullSlot);
|
2010-03-24 22:55:45 +00:00
|
|
|
if ((localSlot = listVector->at(matnr)) == NULL) {
|
|
|
|
localSlot = new RAS_ListSlot(this);
|
|
|
|
localSlot->m_flag |= LIST_DERIVEDMESH;
|
|
|
|
localSlot->m_matnr = matnr;
|
2010-03-25 08:48:31 +00:00
|
|
|
listVector->at(matnr) = localSlot;
|
2010-03-24 22:55:45 +00:00
|
|
|
} else {
|
|
|
|
localSlot->AddRef();
|
|
|
|
}
|
2009-05-14 13:47:08 +00:00
|
|
|
}
|
2006-04-02 21:04:20 +00:00
|
|
|
} else {
|
BGE: Support mesh modifiers in the game engine.
Realtime modifiers applied on mesh objects will be supported in
the game engine with the following limitations:
- Only real time modifiers are supported (basically all of them!)
- Virtual modifiers resulting from parenting are not supported:
armature, curve, lattice. You can still use these modifiers
(armature is really not recommended) but in non parent mode.
The BGE has it's own parenting capability for armature.
- Modifiers are computed on the host (using blender modifier
stack).
- Modifiers are statically evaluated: any possible time dependency
in the modifiers is not supported (don't know enough about
modifiers to be more specific).
- Modifiers are reevaluated if the underlying mesh is deformed
due to shape action or armature action. Beware that this is
very CPU intensive; modifiers should really be used for static
objects only.
- Physics is still based on the original mesh: if you have a
mirror modifier, the physic shape will be limited to one half
of the resulting object. Therefore, the modifiers should
preferably be used on graphic objects.
- Scripts have no access to the modified mesh.
- Modifiers that are based on objects interaction (boolean,..)
will not be dependent on the objects position in the GE.
What you see in the 3D view is what you get in the GE regardless
on the object position, velocity, etc.
Besides that, the feature is compatible with all the BGE features
that affect meshes: armature action, shape action, relace mesh,
VideoTexture, add object, dupligroup.
Known problems:
- This feature is a bit hacky: the BGE uses the derived mesh draw
functions to display the object. This drawing method is a
bit slow and is not 100% compatible with the BGE. There may
be some problems in multi-texture mode: the multi-texture
coordinates are not sent to the GPU.
Texface and GLSL on the other hand should be fully supported.
- Culling is still based on the extend of the original mesh.
If you have a modifer that extends the size of the mesh,
the object may disappear while still in the view frustrum.
- Derived mesh is not shared between replicas.
The derived mesh is allocated and computed for each object
with modifiers, regardless if they are static replicas.
- Display list are not created on objects with modifiers.
I should be able to fix the above problems before release.
However, the feature is already useful for game development.
Once you are ready to release the game, you can apply the modifiers
to get back display list support and mesh sharing capability.
MSVC, scons, Cmake, makefile updated.
Enjoy
/benoit
2009-04-21 11:01:09 +00:00
|
|
|
RAS_ArrayLists::iterator it = mArrayLists.find(ms.m_displayArrays);
|
|
|
|
if(it == mArrayLists.end()) {
|
|
|
|
localSlot = new RAS_ListSlot(this);
|
|
|
|
mArrayLists.insert(std::pair<RAS_DisplayArrayList, RAS_ListSlot*>(ms.m_displayArrays, localSlot));
|
|
|
|
} else {
|
|
|
|
localSlot = static_cast<RAS_ListSlot*>(it->second->AddRef());
|
|
|
|
}
|
2006-04-02 21:04:20 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
MT_assert(localSlot);
|
|
|
|
return localSlot;
|
|
|
|
}
|
|
|
|
|
|
|
|
void RAS_ListRasterizer::ReleaseAlloc()
|
|
|
|
{
|
2009-05-14 13:47:08 +00:00
|
|
|
for(RAS_ArrayLists::iterator it = mArrayLists.begin();it != mArrayLists.end();++it)
|
2006-04-02 21:04:20 +00:00
|
|
|
delete it->second;
|
BGE: Support mesh modifiers in the game engine.
Realtime modifiers applied on mesh objects will be supported in
the game engine with the following limitations:
- Only real time modifiers are supported (basically all of them!)
- Virtual modifiers resulting from parenting are not supported:
armature, curve, lattice. You can still use these modifiers
(armature is really not recommended) but in non parent mode.
The BGE has it's own parenting capability for armature.
- Modifiers are computed on the host (using blender modifier
stack).
- Modifiers are statically evaluated: any possible time dependency
in the modifiers is not supported (don't know enough about
modifiers to be more specific).
- Modifiers are reevaluated if the underlying mesh is deformed
due to shape action or armature action. Beware that this is
very CPU intensive; modifiers should really be used for static
objects only.
- Physics is still based on the original mesh: if you have a
mirror modifier, the physic shape will be limited to one half
of the resulting object. Therefore, the modifiers should
preferably be used on graphic objects.
- Scripts have no access to the modified mesh.
- Modifiers that are based on objects interaction (boolean,..)
will not be dependent on the objects position in the GE.
What you see in the 3D view is what you get in the GE regardless
on the object position, velocity, etc.
Besides that, the feature is compatible with all the BGE features
that affect meshes: armature action, shape action, relace mesh,
VideoTexture, add object, dupligroup.
Known problems:
- This feature is a bit hacky: the BGE uses the derived mesh draw
functions to display the object. This drawing method is a
bit slow and is not 100% compatible with the BGE. There may
be some problems in multi-texture mode: the multi-texture
coordinates are not sent to the GPU.
Texface and GLSL on the other hand should be fully supported.
- Culling is still based on the extend of the original mesh.
If you have a modifer that extends the size of the mesh,
the object may disappear while still in the view frustrum.
- Derived mesh is not shared between replicas.
The derived mesh is allocated and computed for each object
with modifiers, regardless if they are static replicas.
- Display list are not created on objects with modifiers.
I should be able to fix the above problems before release.
However, the feature is already useful for game development.
Once you are ready to release the game, you can apply the modifiers
to get back display list support and mesh sharing capability.
MSVC, scons, Cmake, makefile updated.
Enjoy
/benoit
2009-04-21 11:01:09 +00:00
|
|
|
mArrayLists.clear();
|
2010-03-24 22:55:45 +00:00
|
|
|
for (RAS_DerivedMeshLists::iterator it = mDerivedMeshLists.begin();it != mDerivedMeshLists.end();++it) {
|
|
|
|
RAS_ListSlots* slots = it->second;
|
|
|
|
for (int i=slots->size(); i-- > 0; ) {
|
|
|
|
RAS_ListSlot* slot = slots->at(i);
|
|
|
|
if (slot)
|
|
|
|
delete slot;
|
|
|
|
}
|
|
|
|
slots->clear();
|
|
|
|
delete slots;
|
|
|
|
}
|
2009-05-14 13:47:08 +00:00
|
|
|
mDerivedMeshLists.clear();
|
2006-04-02 21:04:20 +00:00
|
|
|
}
|
|
|
|
|
Merge of first part of changes from the apricot branch, especially
the features that are needed to run the game. Compile tested with
scons, make, but not cmake, that seems to have an issue not related
to these changes. The changes include:
* GLSL support in the viewport and game engine, enable in the game
menu in textured draw mode.
* Synced and merged part of the duplicated blender and gameengine/
gameplayer drawing code.
* Further refactoring of game engine drawing code, especially mesh
storage changed a lot.
* Optimizations in game engine armatures to avoid recomputations.
* A python function to get the framerate estimate in game.
* An option take object color into account in materials.
* An option to restrict shadow casters to a lamp's layers.
* Increase from 10 to 18 texture slots for materials, lamps, word.
An extra texture slot shows up once the last slot is used.
* Memory limit for undo, not enabled by default yet because it
needs the .B.blend to be changed.
* Multiple undo for image painting.
* An offset for dupligroups, so not all objects in a group have to
be at the origin.
2008-09-04 20:51:28 +00:00
|
|
|
void RAS_ListRasterizer::IndexPrimitives(RAS_MeshSlot& ms)
|
2006-04-02 21:04:20 +00:00
|
|
|
{
|
|
|
|
RAS_ListSlot* localSlot =0;
|
|
|
|
|
Merge of first part of changes from the apricot branch, especially
the features that are needed to run the game. Compile tested with
scons, make, but not cmake, that seems to have an issue not related
to these changes. The changes include:
* GLSL support in the viewport and game engine, enable in the game
menu in textured draw mode.
* Synced and merged part of the duplicated blender and gameengine/
gameplayer drawing code.
* Further refactoring of game engine drawing code, especially mesh
storage changed a lot.
* Optimizations in game engine armatures to avoid recomputations.
* A python function to get the framerate estimate in game.
* An option take object color into account in materials.
* An option to restrict shadow casters to a lamp's layers.
* Increase from 10 to 18 texture slots for materials, lamps, word.
An extra texture slot shows up once the last slot is used.
* Memory limit for undo, not enabled by default yet because it
needs the .B.blend to be changed.
* Multiple undo for image painting.
* An offset for dupligroups, so not all objects in a group have to
be at the origin.
2008-09-04 20:51:28 +00:00
|
|
|
if(ms.m_bDisplayList) {
|
|
|
|
localSlot = FindOrAdd(ms);
|
2006-04-02 21:04:20 +00:00
|
|
|
localSlot->DrawList();
|
2008-03-09 22:02:32 +00:00
|
|
|
if(localSlot->End()) {
|
|
|
|
// save slot here too, needed for replicas and object using same mesh
|
|
|
|
// => they have the same vertexarray but different mesh slot
|
Merge of first part of changes from the apricot branch, especially
the features that are needed to run the game. Compile tested with
scons, make, but not cmake, that seems to have an issue not related
to these changes. The changes include:
* GLSL support in the viewport and game engine, enable in the game
menu in textured draw mode.
* Synced and merged part of the duplicated blender and gameengine/
gameplayer drawing code.
* Further refactoring of game engine drawing code, especially mesh
storage changed a lot.
* Optimizations in game engine armatures to avoid recomputations.
* A python function to get the framerate estimate in game.
* An option take object color into account in materials.
* An option to restrict shadow casters to a lamp's layers.
* Increase from 10 to 18 texture slots for materials, lamps, word.
An extra texture slot shows up once the last slot is used.
* Memory limit for undo, not enabled by default yet because it
needs the .B.blend to be changed.
* Multiple undo for image painting.
* An offset for dupligroups, so not all objects in a group have to
be at the origin.
2008-09-04 20:51:28 +00:00
|
|
|
ms.m_DisplayList = localSlot;
|
2006-04-02 21:04:20 +00:00
|
|
|
return;
|
2008-03-09 22:02:32 +00:00
|
|
|
}
|
2006-04-02 21:04:20 +00:00
|
|
|
}
|
BGE: Support mesh modifiers in the game engine.
Realtime modifiers applied on mesh objects will be supported in
the game engine with the following limitations:
- Only real time modifiers are supported (basically all of them!)
- Virtual modifiers resulting from parenting are not supported:
armature, curve, lattice. You can still use these modifiers
(armature is really not recommended) but in non parent mode.
The BGE has it's own parenting capability for armature.
- Modifiers are computed on the host (using blender modifier
stack).
- Modifiers are statically evaluated: any possible time dependency
in the modifiers is not supported (don't know enough about
modifiers to be more specific).
- Modifiers are reevaluated if the underlying mesh is deformed
due to shape action or armature action. Beware that this is
very CPU intensive; modifiers should really be used for static
objects only.
- Physics is still based on the original mesh: if you have a
mirror modifier, the physic shape will be limited to one half
of the resulting object. Therefore, the modifiers should
preferably be used on graphic objects.
- Scripts have no access to the modified mesh.
- Modifiers that are based on objects interaction (boolean,..)
will not be dependent on the objects position in the GE.
What you see in the 3D view is what you get in the GE regardless
on the object position, velocity, etc.
Besides that, the feature is compatible with all the BGE features
that affect meshes: armature action, shape action, relace mesh,
VideoTexture, add object, dupligroup.
Known problems:
- This feature is a bit hacky: the BGE uses the derived mesh draw
functions to display the object. This drawing method is a
bit slow and is not 100% compatible with the BGE. There may
be some problems in multi-texture mode: the multi-texture
coordinates are not sent to the GPU.
Texface and GLSL on the other hand should be fully supported.
- Culling is still based on the extend of the original mesh.
If you have a modifer that extends the size of the mesh,
the object may disappear while still in the view frustrum.
- Derived mesh is not shared between replicas.
The derived mesh is allocated and computed for each object
with modifiers, regardless if they are static replicas.
- Display list are not created on objects with modifiers.
I should be able to fix the above problems before release.
However, the feature is already useful for game development.
Once you are ready to release the game, you can apply the modifiers
to get back display list support and mesh sharing capability.
MSVC, scons, Cmake, makefile updated.
Enjoy
/benoit
2009-04-21 11:01:09 +00:00
|
|
|
// derived mesh cannot use vertex array
|
|
|
|
if (mUseVertexArrays && !ms.m_pDerivedMesh)
|
Merge of first part of changes from the apricot branch, especially
the features that are needed to run the game. Compile tested with
scons, make, but not cmake, that seems to have an issue not related
to these changes. The changes include:
* GLSL support in the viewport and game engine, enable in the game
menu in textured draw mode.
* Synced and merged part of the duplicated blender and gameengine/
gameplayer drawing code.
* Further refactoring of game engine drawing code, especially mesh
storage changed a lot.
* Optimizations in game engine armatures to avoid recomputations.
* A python function to get the framerate estimate in game.
* An option take object color into account in materials.
* An option to restrict shadow casters to a lamp's layers.
* Increase from 10 to 18 texture slots for materials, lamps, word.
An extra texture slot shows up once the last slot is used.
* Memory limit for undo, not enabled by default yet because it
needs the .B.blend to be changed.
* Multiple undo for image painting.
* An offset for dupligroups, so not all objects in a group have to
be at the origin.
2008-09-04 20:51:28 +00:00
|
|
|
RAS_VAOpenGLRasterizer::IndexPrimitives(ms);
|
|
|
|
else
|
|
|
|
RAS_OpenGLRasterizer::IndexPrimitives(ms);
|
2006-04-02 21:04:20 +00:00
|
|
|
|
Merge of first part of changes from the apricot branch, especially
the features that are needed to run the game. Compile tested with
scons, make, but not cmake, that seems to have an issue not related
to these changes. The changes include:
* GLSL support in the viewport and game engine, enable in the game
menu in textured draw mode.
* Synced and merged part of the duplicated blender and gameengine/
gameplayer drawing code.
* Further refactoring of game engine drawing code, especially mesh
storage changed a lot.
* Optimizations in game engine armatures to avoid recomputations.
* A python function to get the framerate estimate in game.
* An option take object color into account in materials.
* An option to restrict shadow casters to a lamp's layers.
* Increase from 10 to 18 texture slots for materials, lamps, word.
An extra texture slot shows up once the last slot is used.
* Memory limit for undo, not enabled by default yet because it
needs the .B.blend to be changed.
* Multiple undo for image painting.
* An offset for dupligroups, so not all objects in a group have to
be at the origin.
2008-09-04 20:51:28 +00:00
|
|
|
if(ms.m_bDisplayList) {
|
2006-04-02 21:04:20 +00:00
|
|
|
localSlot->EndList();
|
Merge of first part of changes from the apricot branch, especially
the features that are needed to run the game. Compile tested with
scons, make, but not cmake, that seems to have an issue not related
to these changes. The changes include:
* GLSL support in the viewport and game engine, enable in the game
menu in textured draw mode.
* Synced and merged part of the duplicated blender and gameengine/
gameplayer drawing code.
* Further refactoring of game engine drawing code, especially mesh
storage changed a lot.
* Optimizations in game engine armatures to avoid recomputations.
* A python function to get the framerate estimate in game.
* An option take object color into account in materials.
* An option to restrict shadow casters to a lamp's layers.
* Increase from 10 to 18 texture slots for materials, lamps, word.
An extra texture slot shows up once the last slot is used.
* Memory limit for undo, not enabled by default yet because it
needs the .B.blend to be changed.
* Multiple undo for image painting.
* An offset for dupligroups, so not all objects in a group have to
be at the origin.
2008-09-04 20:51:28 +00:00
|
|
|
ms.m_DisplayList = localSlot;
|
2006-04-02 21:04:20 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
Merge of first part of changes from the apricot branch, especially
the features that are needed to run the game. Compile tested with
scons, make, but not cmake, that seems to have an issue not related
to these changes. The changes include:
* GLSL support in the viewport and game engine, enable in the game
menu in textured draw mode.
* Synced and merged part of the duplicated blender and gameengine/
gameplayer drawing code.
* Further refactoring of game engine drawing code, especially mesh
storage changed a lot.
* Optimizations in game engine armatures to avoid recomputations.
* A python function to get the framerate estimate in game.
* An option take object color into account in materials.
* An option to restrict shadow casters to a lamp's layers.
* Increase from 10 to 18 texture slots for materials, lamps, word.
An extra texture slot shows up once the last slot is used.
* Memory limit for undo, not enabled by default yet because it
needs the .B.blend to be changed.
* Multiple undo for image painting.
* An offset for dupligroups, so not all objects in a group have to
be at the origin.
2008-09-04 20:51:28 +00:00
|
|
|
void RAS_ListRasterizer::IndexPrimitivesMulti(RAS_MeshSlot& ms)
|
2006-04-02 21:04:20 +00:00
|
|
|
{
|
|
|
|
RAS_ListSlot* localSlot =0;
|
|
|
|
|
Merge of first part of changes from the apricot branch, especially
the features that are needed to run the game. Compile tested with
scons, make, but not cmake, that seems to have an issue not related
to these changes. The changes include:
* GLSL support in the viewport and game engine, enable in the game
menu in textured draw mode.
* Synced and merged part of the duplicated blender and gameengine/
gameplayer drawing code.
* Further refactoring of game engine drawing code, especially mesh
storage changed a lot.
* Optimizations in game engine armatures to avoid recomputations.
* A python function to get the framerate estimate in game.
* An option take object color into account in materials.
* An option to restrict shadow casters to a lamp's layers.
* Increase from 10 to 18 texture slots for materials, lamps, word.
An extra texture slot shows up once the last slot is used.
* Memory limit for undo, not enabled by default yet because it
needs the .B.blend to be changed.
* Multiple undo for image painting.
* An offset for dupligroups, so not all objects in a group have to
be at the origin.
2008-09-04 20:51:28 +00:00
|
|
|
if(ms.m_bDisplayList) {
|
|
|
|
localSlot = FindOrAdd(ms);
|
2006-04-02 21:04:20 +00:00
|
|
|
localSlot->DrawList();
|
|
|
|
|
2008-03-09 22:02:32 +00:00
|
|
|
if(localSlot->End()) {
|
|
|
|
// save slot here too, needed for replicas and object using same mesh
|
|
|
|
// => they have the same vertexarray but different mesh slot
|
Merge of first part of changes from the apricot branch, especially
the features that are needed to run the game. Compile tested with
scons, make, but not cmake, that seems to have an issue not related
to these changes. The changes include:
* GLSL support in the viewport and game engine, enable in the game
menu in textured draw mode.
* Synced and merged part of the duplicated blender and gameengine/
gameplayer drawing code.
* Further refactoring of game engine drawing code, especially mesh
storage changed a lot.
* Optimizations in game engine armatures to avoid recomputations.
* A python function to get the framerate estimate in game.
* An option take object color into account in materials.
* An option to restrict shadow casters to a lamp's layers.
* Increase from 10 to 18 texture slots for materials, lamps, word.
An extra texture slot shows up once the last slot is used.
* Memory limit for undo, not enabled by default yet because it
needs the .B.blend to be changed.
* Multiple undo for image painting.
* An offset for dupligroups, so not all objects in a group have to
be at the origin.
2008-09-04 20:51:28 +00:00
|
|
|
ms.m_DisplayList = localSlot;
|
2006-04-02 21:04:20 +00:00
|
|
|
return;
|
2008-03-09 22:02:32 +00:00
|
|
|
}
|
2006-04-02 21:04:20 +00:00
|
|
|
}
|
|
|
|
|
2008-07-10 12:47:20 +00:00
|
|
|
// workaround: note how we do not use vertex arrays for making display
|
|
|
|
// lists, since glVertexAttribPointerARB doesn't seem to work correct
|
|
|
|
// in display lists on ATI? either a bug in the driver or in Blender ..
|
2009-05-07 19:36:12 +00:00
|
|
|
if (mUseVertexArrays && !mATI && !ms.m_pDerivedMesh)
|
Merge of first part of changes from the apricot branch, especially
the features that are needed to run the game. Compile tested with
scons, make, but not cmake, that seems to have an issue not related
to these changes. The changes include:
* GLSL support in the viewport and game engine, enable in the game
menu in textured draw mode.
* Synced and merged part of the duplicated blender and gameengine/
gameplayer drawing code.
* Further refactoring of game engine drawing code, especially mesh
storage changed a lot.
* Optimizations in game engine armatures to avoid recomputations.
* A python function to get the framerate estimate in game.
* An option take object color into account in materials.
* An option to restrict shadow casters to a lamp's layers.
* Increase from 10 to 18 texture slots for materials, lamps, word.
An extra texture slot shows up once the last slot is used.
* Memory limit for undo, not enabled by default yet because it
needs the .B.blend to be changed.
* Multiple undo for image painting.
* An offset for dupligroups, so not all objects in a group have to
be at the origin.
2008-09-04 20:51:28 +00:00
|
|
|
RAS_VAOpenGLRasterizer::IndexPrimitivesMulti(ms);
|
|
|
|
else
|
|
|
|
RAS_OpenGLRasterizer::IndexPrimitivesMulti(ms);
|
2007-11-06 18:39:16 +00:00
|
|
|
|
Merge of first part of changes from the apricot branch, especially
the features that are needed to run the game. Compile tested with
scons, make, but not cmake, that seems to have an issue not related
to these changes. The changes include:
* GLSL support in the viewport and game engine, enable in the game
menu in textured draw mode.
* Synced and merged part of the duplicated blender and gameengine/
gameplayer drawing code.
* Further refactoring of game engine drawing code, especially mesh
storage changed a lot.
* Optimizations in game engine armatures to avoid recomputations.
* A python function to get the framerate estimate in game.
* An option take object color into account in materials.
* An option to restrict shadow casters to a lamp's layers.
* Increase from 10 to 18 texture slots for materials, lamps, word.
An extra texture slot shows up once the last slot is used.
* Memory limit for undo, not enabled by default yet because it
needs the .B.blend to be changed.
* Multiple undo for image painting.
* An offset for dupligroups, so not all objects in a group have to
be at the origin.
2008-09-04 20:51:28 +00:00
|
|
|
if(ms.m_bDisplayList) {
|
2006-04-02 21:04:20 +00:00
|
|
|
localSlot->EndList();
|
Merge of first part of changes from the apricot branch, especially
the features that are needed to run the game. Compile tested with
scons, make, but not cmake, that seems to have an issue not related
to these changes. The changes include:
* GLSL support in the viewport and game engine, enable in the game
menu in textured draw mode.
* Synced and merged part of the duplicated blender and gameengine/
gameplayer drawing code.
* Further refactoring of game engine drawing code, especially mesh
storage changed a lot.
* Optimizations in game engine armatures to avoid recomputations.
* A python function to get the framerate estimate in game.
* An option take object color into account in materials.
* An option to restrict shadow casters to a lamp's layers.
* Increase from 10 to 18 texture slots for materials, lamps, word.
An extra texture slot shows up once the last slot is used.
* Memory limit for undo, not enabled by default yet because it
needs the .B.blend to be changed.
* Multiple undo for image painting.
* An offset for dupligroups, so not all objects in a group have to
be at the origin.
2008-09-04 20:51:28 +00:00
|
|
|
ms.m_DisplayList = localSlot;
|
2006-04-02 21:04:20 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2007-11-06 18:39:16 +00:00
|
|
|
bool RAS_ListRasterizer::Init(void)
|
|
|
|
{
|
|
|
|
if (mUseVertexArrays) {
|
|
|
|
return RAS_VAOpenGLRasterizer::Init();
|
|
|
|
} else {
|
|
|
|
return RAS_OpenGLRasterizer::Init();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
void RAS_ListRasterizer::SetDrawingMode(int drawingmode)
|
|
|
|
{
|
|
|
|
if (mUseVertexArrays) {
|
|
|
|
RAS_VAOpenGLRasterizer::SetDrawingMode(drawingmode);
|
|
|
|
} else {
|
|
|
|
RAS_OpenGLRasterizer::SetDrawingMode(drawingmode);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
void RAS_ListRasterizer::Exit()
|
|
|
|
{
|
|
|
|
if (mUseVertexArrays) {
|
|
|
|
RAS_VAOpenGLRasterizer::Exit();
|
|
|
|
} else {
|
|
|
|
RAS_OpenGLRasterizer::Exit();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2006-04-02 21:04:20 +00:00
|
|
|
// eof
|