applied Charlies patch for game engine graphics. display list support, and bumpmapping shader improvements.

This commit is contained in:
Erwin Coumans
2006-04-02 21:04:20 +00:00
parent 756bad72c4
commit 6839ec6640
32 changed files with 1485 additions and 823 deletions

View File

@@ -406,7 +406,7 @@ PFNGLGETACTIVEATTRIBARBPROC blGetActiveAttribARB;
PFNGLGETATTRIBLOCATIONARBPROC blGetAttribLocationARB;
#endif
#if 0 // TODO: GL_ARB_vertex/fragment_program support
#ifdef GL_ARB_vertex_program
PFNGLVERTEXATTRIB1FARBPROC blVertexAttrib1fARB;
PFNGLVERTEXATTRIB1FVARBPROC blVertexAttrib1fvARB;
@@ -421,6 +421,13 @@ PFNGLGETATTRIBLOCATIONARBPROC blGetAttribLocationARB;
PFNGLGETVERTEXATTRIBFVARBPROC blGetVertexAttribfvARB;
PFNGLGETVERTEXATTRIBIVARBPROC blGetVertexAttribivARB;
#endif
#endif
#ifdef GL_EXT_compiled_vertex_array
PFNGLLOCKARRAYSEXTPROC blLockArraysEXT;
PFNGLUNLOCKARRAYSEXTPROC blUnlockArraysEXT;
#endif
} // namespace bgl
@@ -605,6 +612,7 @@ static void LinkExtensions()
}
#endif
#if 0 // TODO: GL_ARB_vertex/fragment_program support
#if defined(GL_ARB_vertex_program)
if (QueryExtension("GL_ARB_vertex_program"))
{
@@ -629,6 +637,7 @@ static void LinkExtensions()
}
}
#endif
#endif
#ifdef GL_ARB_depth_texture
@@ -643,6 +652,22 @@ static void LinkExtensions()
}
#endif
#ifdef GL_EXT_compiled_vertex_array
if (QueryExtension("GL_EXT_compiled_vertex_array"))
{
blLockArraysEXT = reinterpret_cast<PFNGLLOCKARRAYSEXTPROC>(bglGetProcAddress((const GLubyte *) "glLockArraysEXT"));
blUnlockArraysEXT = reinterpret_cast<PFNGLUNLOCKARRAYSEXTPROC>(bglGetProcAddress((const GLubyte *) "glUnlockArraysEXT"));
if (blLockArraysEXT && blUnlockArraysEXT) {
EnableExtension(_GL_EXT_compiled_vertex_array);
RAS_EXT_support._EXT_compiled_vertex_array = 1;
if (doDebugMessages)
std::cout << "Enabled GL_EXT_compiled_vertex_array" << std::endl;
} else {
std::cout << "ERROR: GL_EXT_compiled_vertex_array implementation is broken!" << std::endl;
}
}
#endif
if (QueryExtension("GL_EXT_separate_specular_color"))
{
EnableExtension(_GL_EXT_separate_specular_color);

View File

@@ -403,7 +403,8 @@ typedef struct BL_EXTInfo
_ARB_fragment_shader(0),
_EXT_texture3D(0),
_ARB_vertex_program(0),
_ARB_depth_texture(0)
_ARB_depth_texture(0),
_EXT_compiled_vertex_array(0)
{
//
}
@@ -417,6 +418,7 @@ typedef struct BL_EXTInfo
bool _EXT_texture3D;
bool _ARB_vertex_program;
bool _ARB_depth_texture;
bool _EXT_compiled_vertex_array;
}BL_EXTInfo;
extern BL_EXTInfo RAS_EXT_support;
@@ -508,6 +510,7 @@ extern PFNGLGETACTIVEATTRIBARBPROC blGetActiveAttribARB;
extern PFNGLGETATTRIBLOCATIONARBPROC blGetAttribLocationARB;
#endif
#if 0 // TODO: GL_ARB_vertex/fragment_program support
#ifdef GL_ARB_vertex_program
extern PFNGLVERTEXATTRIB1FARBPROC blVertexAttrib1fARB;
extern PFNGLVERTEXATTRIB1FVARBPROC blVertexAttrib1fvARB;
@@ -522,7 +525,12 @@ extern PFNGLGETVERTEXATTRIBDVARBPROC blGetVertexAttribdvARB;
extern PFNGLGETVERTEXATTRIBFVARBPROC blGetVertexAttribfvARB;
extern PFNGLGETVERTEXATTRIBIVARBPROC blGetVertexAttribivARB;
#endif
#endif
#ifdef GL_EXT_compiled_vertex_array
extern PFNGLLOCKARRAYSEXTPROC blLockArraysEXT;
extern PFNGLUNLOCKARRAYSEXTPROC blUnlockArraysEXT;
#endif
} /* namespace bgl */

View File

@@ -0,0 +1,207 @@
//
#include <iostream>
#include "RAS_ListRasterizer.h"
#ifdef WIN32
#include <windows.h>
#endif // WIN32
#ifdef __APPLE__
#define GL_GLEXT_LEGACY 1
#include <OpenGL/gl.h>
#else
#include <GL/gl.h>
#endif
#include "RAS_TexVert.h"
#include "RAS_GLExtensionManager.h"
#include "MT_assert.h"
#ifndef NDEBUG
#define spit(x) std::cout << x << std::endl;
#else
#define spit(x)
#endif
RAS_ListSlot::RAS_ListSlot()
: KX_ListSlot(),
m_flag(LIST_MODIFY|LIST_CREATE),
m_list(0)
{
}
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)
glNewList((GLuint)m_list, GL_COMPILE_AND_EXECUTE);
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;
}
}
void RAS_ListSlot::SetModified(bool mod)
{
if(mod && !(m_flag & LIST_MODIFY)) {
spit("Modifying list (" << m_list << ")");
m_flag = m_flag &~ LIST_END;
m_flag |= LIST_MODIFY;
}
}
bool RAS_ListSlot::End()
{
return (m_flag &LIST_END)!=0;
}
RAS_ListRasterizer::RAS_ListRasterizer(RAS_ICanvas* canvas)
: RAS_OpenGLRasterizer(canvas)
{
// --
}
RAS_ListRasterizer::~RAS_ListRasterizer()
{
ReleaseAlloc();
}
RAS_ListSlot* RAS_ListRasterizer::FindOrAdd(const vecVertexArray& vertexarrays, KX_ListSlot** slot)
{
/*
Keep a copy of constant lists submitted for rendering,
this guards against (replicated)new...delete every frame,
and we can reuse lists!
:: sorted by vertex array
*/
RAS_ListSlot* localSlot = (RAS_ListSlot*)*slot;
if(!localSlot) {
RAS_Lists::iterator it = mLists.find(vertexarrays);
if(it == mLists.end()) {
localSlot = new RAS_ListSlot();
mLists.insert(std::pair<vecVertexArray, RAS_ListSlot*>(vertexarrays, localSlot));
} else {
localSlot = it->second;
}
}
MT_assert(localSlot);
return localSlot;
}
void RAS_ListRasterizer::ReleaseAlloc()
{
RAS_Lists::iterator it = mLists.begin();
while(it != mLists.end()) {
delete it->second;
it++;
}
mLists.clear();
}
void RAS_ListRasterizer::IndexPrimitives(
const vecVertexArray & vertexarrays,
const vecIndexArrays & indexarrays,
int mode,
class RAS_IPolyMaterial* polymat,
class RAS_IRenderTools* rendertools,
bool useObjectColor,
const MT_Vector4& rgbacolor,
class KX_ListSlot** slot)
{
RAS_ListSlot* localSlot =0;
// useObjectColor(are we updating every frame?)
if(!useObjectColor) {
localSlot = FindOrAdd(vertexarrays, slot);
localSlot->DrawList();
if(localSlot->End())
return;
}
RAS_OpenGLRasterizer::IndexPrimitives(
vertexarrays, indexarrays,
mode, polymat,
rendertools, useObjectColor,
rgbacolor,slot
);
if(!useObjectColor) {
localSlot->EndList();
*slot = localSlot;
}
}
void RAS_ListRasterizer::IndexPrimitivesMulti(
const vecVertexArray& vertexarrays,
const vecIndexArrays & indexarrays,
int mode,
class RAS_IPolyMaterial* polymat,
class RAS_IRenderTools* rendertools,
bool useObjectColor,
const MT_Vector4& rgbacolor,
class KX_ListSlot** slot)
{
RAS_ListSlot* localSlot =0;
// useObjectColor(are we updating every frame?)
if(!useObjectColor) {
localSlot = FindOrAdd(vertexarrays, slot);
localSlot->DrawList();
if(localSlot->End())
return;
}
RAS_OpenGLRasterizer::IndexPrimitivesMulti(
vertexarrays, indexarrays,
mode, polymat,
rendertools, useObjectColor,
rgbacolor,slot
);
if(!useObjectColor) {
localSlot->EndList();
*slot = localSlot;
}
}
// eof

View File

@@ -0,0 +1,72 @@
#ifndef __RAS_LISTRASTERIZER_H__
#define __RAS_LISTRASTERIZER_H__
#include "RAS_MaterialBucket.h"
#include "RAS_OpenGLRasterizer.h"
#include <vector>
class RAS_ListSlot : public KX_ListSlot
{
unsigned int m_list;
unsigned int m_flag;
public:
RAS_ListSlot();
virtual ~RAS_ListSlot();
virtual void SetModified(bool mod);
void RemoveList();
void DrawList();
void EndList();
bool End();
};
enum RAS_ListSlotFlags {
LIST_CREATE =1,
LIST_MODIFY =2,
LIST_STREAM =4,
LIST_NOCREATE =8,
LIST_BEGIN =16,
LIST_END =32,
LIST_REGEN =64
};
typedef std::map<const vecVertexArray, RAS_ListSlot*> RAS_Lists;
class RAS_ListRasterizer : public RAS_OpenGLRasterizer
{
RAS_Lists mLists;
RAS_ListSlot* FindOrAdd(const vecVertexArray& vertexarrays, KX_ListSlot** slot);
void ReleaseAlloc();
public:
RAS_ListRasterizer(RAS_ICanvas* canvas);
virtual ~RAS_ListRasterizer();
virtual void IndexPrimitives(
const vecVertexArray& vertexarrays,
const vecIndexArrays & indexarrays,
int mode,
class RAS_IPolyMaterial* polymat,
class RAS_IRenderTools* rendertools,
bool useObjectColor,
const MT_Vector4& rgbacolor,
class KX_ListSlot** slot
);
virtual void IndexPrimitivesMulti(
const vecVertexArray& vertexarrays,
const vecIndexArrays & indexarrays,
int mode,
class RAS_IPolyMaterial* polymat,
class RAS_IRenderTools* rendertools,
bool useObjectColor,
const MT_Vector4& rgbacolor,
class KX_ListSlot** slot
);
virtual bool QueryLists(){return true;}
};
#endif

View File

@@ -81,7 +81,6 @@ RAS_OpenGLRasterizer::RAS_OpenGLRasterizer(RAS_ICanvas* canvas)
m_focallength(0.0),
m_setfocallength(false),
m_noOfScanlines(32),
m_useTang(0),
m_materialCachingInfo(0)
{
m_viewmatrix.Identity();
@@ -619,7 +618,8 @@ void RAS_OpenGLRasterizer::IndexPrimitives(const vecVertexArray & vertexarrays,
class RAS_IPolyMaterial* polymat,
class RAS_IRenderTools* rendertools,
bool useObjectColor,
const MT_Vector4& rgbacolor
const MT_Vector4& rgbacolor,
class KX_ListSlot** slot
)
{
GLenum drawmode;
@@ -1201,12 +1201,6 @@ void RAS_OpenGLRasterizer::IndexPrimitives_3DText(const vecVertexArray & vertexa
} //for each vertexarray
}
void RAS_OpenGLRasterizer::SetAttrib(int type)
{
if(type == RAS_TEXTANGENT) m_useTang=true;
}
void RAS_OpenGLRasterizer::SetTexCoords(TexCoGen coords,int unit)
{
// this changes from material to material
@@ -1242,14 +1236,40 @@ void RAS_OpenGLRasterizer::TexCoord(const RAS_TexVert &tv, int enabled)
case RAS_TEXCO_NORM:
bgl::blMultiTexCoord3fvARB(GL_TEXTURE0_ARB+unit, tv.getNormal());
break;
case RAS_TEXTANGENT:
bgl::blMultiTexCoord4fvARB(GL_TEXTURE0_ARB+unit, tv.getTangent());
}
}
}
#endif
#ifdef GL_ARB_vertex_program
if(m_useTang && bgl::RAS_EXT_support._ARB_vertex_program)
bgl::blVertexAttrib4fvARB(1/*tangent*/, tv.getTangent());
}
void RAS_OpenGLRasterizer::Tangent( const RAS_TexVert& v1,
const RAS_TexVert& v2,
const RAS_TexVert& v3,
const MT_Vector3 &no)
{
#ifdef GL_ARB_multitexture
// TODO: set for deformer...
MT_Vector3 x1(v1.getLocalXYZ()), x2(v2.getLocalXYZ()), x3(v3.getLocalXYZ());
MT_Vector2 uv1(v1.getUV1()), uv2(v2.getUV1()), uv3(v3.getUV1());
MT_Vector3 dx1(x2 - x1), dx2(x3 - x1);
MT_Vector2 duv1(uv2 - uv1), duv2(uv3 - uv1);
MT_Scalar r = 1.0 / (duv1.x() * duv2.y() - duv2.x() * duv1.y());
duv1 *= r;
duv2 *= r;
MT_Vector3 sdir(duv2.y() * dx1 - duv1.y() * dx2);
MT_Vector3 tdir(duv1.x() * dx2 - duv2.x() * dx1);
// Gram-Schmidt orthogonalize
MT_Vector3 t(sdir - no.cross(no.cross(sdir)));
if (!MT_fuzzyZero(t))
t /= t.length();
float tangent[4];
t.getValue(tangent);
// Calculate handedness
tangent[3] = no.dot(sdir.cross(tdir)) < 0.0 ? -1.0 : 1.0;
#endif
}
@@ -1261,7 +1281,8 @@ void RAS_OpenGLRasterizer::IndexPrimitivesMulti(
class RAS_IPolyMaterial* polymat,
class RAS_IRenderTools* rendertools,
bool useObjectColor,
const MT_Vector4& rgbacolor
const MT_Vector4& rgbacolor,
class KX_ListSlot** slot
)
{
#ifdef GL_ARB_multitexture
@@ -1455,14 +1476,14 @@ void RAS_OpenGLRasterizer::IndexPrimitivesMulti(
}
void RAS_OpenGLRasterizer::IndexPrimitivesMulti_Ex(const vecVertexArray & vertexarrays,
void RAS_OpenGLRasterizer::IndexPrimitivesMulti_Ex(
const vecVertexArray & vertexarrays,
const vecIndexArrays & indexarrays,
int mode,
class RAS_IPolyMaterial* polymat,
class RAS_IRenderTools* rendertools,
bool useObjectColor,
const MT_Vector4& rgbacolor
)
const MT_Vector4& rgbacolor)
{
#ifdef GL_ARB_multitexture
bool recalc;
@@ -1492,7 +1513,6 @@ void RAS_OpenGLRasterizer::IndexPrimitivesMulti_Ex(const vecVertexArray & vertex
const KX_IndexArray & indexarray = (*indexarrays[vt]);
numindices = indexarray.size();
const unsigned int enabled = polymat->GetEnabled();
unsigned int unit;
if (!numindices)
continue;
@@ -1544,72 +1564,27 @@ void RAS_OpenGLRasterizer::IndexPrimitivesMulti_Ex(const vecVertexArray & vertex
if (!recalc)
glNormal3fv(vertexarray[(indexarray[vindex])].getNormal());
// ------------------------------
for(unit =0; unit<enabled; unit++) {
if( vertexarray[(indexarray[vindex])].getFlag() & TV_2NDUV &&
vertexarray[(indexarray[vindex])].getUnit() == unit )
{
bgl::blMultiTexCoord2fvARB(GL_TEXTURE0_ARB+unit, vertexarray[(indexarray[vindex])].getUV2());
continue;
}
bgl::blMultiTexCoord2fvARB(GL_TEXTURE0_ARB+unit, vertexarray[(indexarray[vindex])].getUV1());
}
// ------------------------------
TexCoord(vertexarray[(indexarray[vindex])],enabled );
glVertex3fv(vertexarray[(indexarray[vindex])].getLocalXYZ());
vindex++;
if (!recalc)
glNormal3fv(vertexarray[(indexarray[vindex])].getNormal());
// ------------------------------
for(unit =0; unit<enabled; unit++) {
if( vertexarray[(indexarray[vindex])].getFlag() & TV_2NDUV &&
vertexarray[(indexarray[vindex])].getUnit() == unit )
{
bgl::blMultiTexCoord2fvARB(GL_TEXTURE0_ARB+unit, vertexarray[(indexarray[vindex])].getUV2());
continue;
}
bgl::blMultiTexCoord2fvARB(GL_TEXTURE0_ARB+unit, vertexarray[(indexarray[vindex])].getUV1());
}
// ------------------------------
TexCoord(vertexarray[(indexarray[vindex])],enabled );
glVertex3fv(vertexarray[(indexarray[vindex])].getLocalXYZ());
vindex++;
if (!recalc)
glNormal3fv(vertexarray[(indexarray[vindex])].getNormal());
// ------------------------------
for(unit =0; unit<enabled; unit++) {
if( vertexarray[(indexarray[vindex])].getFlag() & TV_2NDUV &&
vertexarray[(indexarray[vindex])].getUnit() == unit )
{
bgl::blMultiTexCoord2fvARB(GL_TEXTURE0_ARB+unit, vertexarray[(indexarray[vindex])].getUV2());
continue;
}
bgl::blMultiTexCoord2fvARB(GL_TEXTURE0_ARB+unit, vertexarray[(indexarray[vindex])].getUV1());
}
// ------------------------------
TexCoord(vertexarray[(indexarray[vindex])],enabled );
glVertex3fv(vertexarray[(indexarray[vindex])].getLocalXYZ());
vindex++;
if (!recalc)
glNormal3fv(vertexarray[(indexarray[vindex])].getNormal());
// ------------------------------
for(unit =0; unit<enabled; unit++) {
if( vertexarray[(indexarray[vindex])].getFlag() & TV_2NDUV &&
vertexarray[(indexarray[vindex])].getUnit() == unit )
{
bgl::blMultiTexCoord2fvARB(GL_TEXTURE0_ARB+unit, vertexarray[(indexarray[vindex])].getUV2());
continue;
}
bgl::blMultiTexCoord2fvARB(GL_TEXTURE0_ARB+unit, vertexarray[(indexarray[vindex])].getUV1());
}
// ------------------------------
TexCoord(vertexarray[(indexarray[vindex])],enabled );
glVertex3fv(vertexarray[(indexarray[vindex])].getLocalXYZ());
vindex++;
}
@@ -1645,18 +1620,7 @@ void RAS_OpenGLRasterizer::IndexPrimitivesMulti_Ex(const vecVertexArray & vertex
if (!recalc)
glNormal3fv(vertexarray[(indexarray[vindex])].getNormal());
// ------------------------------
for(unit =0; unit<enabled; unit++) {
if( vertexarray[(indexarray[vindex])].getFlag() & TV_2NDUV &&
vertexarray[(indexarray[vindex])].getUnit() == unit )
{
bgl::blMultiTexCoord2fvARB(GL_TEXTURE0_ARB+unit, vertexarray[(indexarray[vindex])].getUV2());
continue;
}
bgl::blMultiTexCoord2fvARB(GL_TEXTURE0_ARB+unit, vertexarray[(indexarray[vindex])].getUV1());
}
// ------------------------------
TexCoord(vertexarray[(indexarray[vindex])],enabled );
glVertex3fv(vertexarray[(indexarray[vindex])].getLocalXYZ());
vindex++;
@@ -1664,18 +1628,7 @@ void RAS_OpenGLRasterizer::IndexPrimitivesMulti_Ex(const vecVertexArray & vertex
if (!recalc)
glNormal3fv(vertexarray[(indexarray[vindex])].getNormal());
// ------------------------------
for(unit =0; unit<enabled; unit++) {
if( vertexarray[(indexarray[vindex])].getFlag() & TV_2NDUV &&
vertexarray[(indexarray[vindex])].getUnit() == unit )
{
bgl::blMultiTexCoord2fvARB(GL_TEXTURE0_ARB+unit, vertexarray[(indexarray[vindex])].getUV2());
continue;
}
bgl::blMultiTexCoord2fvARB(GL_TEXTURE0_ARB+unit, vertexarray[(indexarray[vindex])].getUV1());
}
// ------------------------------
TexCoord(vertexarray[(indexarray[vindex])],enabled );
glVertex3fv(vertexarray[(indexarray[vindex])].getLocalXYZ());
vindex++;
@@ -1683,35 +1636,15 @@ void RAS_OpenGLRasterizer::IndexPrimitivesMulti_Ex(const vecVertexArray & vertex
if (!recalc)
glNormal3fv(vertexarray[(indexarray[vindex])].getNormal());
// ------------------------------
for(unit =0; unit<enabled; unit++) {
if( vertexarray[(indexarray[vindex])].getFlag() & TV_2NDUV &&
vertexarray[(indexarray[vindex])].getUnit() == unit )
{
bgl::blMultiTexCoord2fvARB(GL_TEXTURE0_ARB+unit, vertexarray[(indexarray[vindex])].getUV2());
continue;
}
bgl::blMultiTexCoord2fvARB(GL_TEXTURE0_ARB+unit, vertexarray[(indexarray[vindex])].getUV1());
}
// ------------------------------
TexCoord(vertexarray[(indexarray[vindex])],enabled );
glVertex3fv(vertexarray[(indexarray[vindex])].getLocalXYZ());
vindex++;
glColor4ubv((const GLubyte *)(vertexarray[(indexarray[vindex])].getRGBA()));
if (!recalc)
glNormal3fv(vertexarray[(indexarray[vindex])].getNormal());
// ------------------------------
for(unit =0; unit<enabled; unit++) {
if( vertexarray[(indexarray[vindex])].getFlag() & TV_2NDUV &&
vertexarray[(indexarray[vindex])].getUnit() == unit )
{
bgl::blMultiTexCoord2fvARB(GL_TEXTURE0_ARB+unit, vertexarray[(indexarray[vindex])].getUV2());
continue;
}
bgl::blMultiTexCoord2fvARB(GL_TEXTURE0_ARB+unit, vertexarray[(indexarray[vindex])].getUV1());
}
// ------------------------------
TexCoord(vertexarray[(indexarray[vindex])],enabled );
glVertex3fv(vertexarray[(indexarray[vindex])].getLocalXYZ());
vindex++;
}
@@ -1748,49 +1681,19 @@ void RAS_OpenGLRasterizer::IndexPrimitivesMulti_Ex(const vecVertexArray & vertex
if (!recalc)
glNormal3fv(vertexarray[(indexarray[vindex])].getNormal());
// ------------------------------
for(unit =0; unit<enabled; unit++) {
if( vertexarray[(indexarray[vindex])].getFlag() & TV_2NDUV &&
vertexarray[(indexarray[vindex])].getUnit() == unit )
{
bgl::blMultiTexCoord2fvARB(GL_TEXTURE0_ARB+unit, vertexarray[(indexarray[vindex])].getUV2());
continue;
}
bgl::blMultiTexCoord2fvARB(GL_TEXTURE0_ARB+unit, vertexarray[(indexarray[vindex])].getUV1());
}
// ------------------------------
TexCoord(vertexarray[(indexarray[vindex])],enabled );
glVertex3fv(vertexarray[(indexarray[vindex])].getLocalXYZ());
vindex++;
if (!recalc)
glNormal3fv(vertexarray[(indexarray[vindex])].getNormal());
// ------------------------------
for(unit =0; unit<enabled; unit++) {
if( vertexarray[(indexarray[vindex])].getFlag() & TV_2NDUV &&
vertexarray[(indexarray[vindex])].getUnit() == unit )
{
bgl::blMultiTexCoord2fvARB(GL_TEXTURE0_ARB+unit, vertexarray[(indexarray[vindex])].getUV2());
continue;
}
bgl::blMultiTexCoord2fvARB(GL_TEXTURE0_ARB+unit, vertexarray[(indexarray[vindex])].getUV1());
}
// ------------------------------
TexCoord(vertexarray[(indexarray[vindex])],enabled );
glVertex3fv(vertexarray[(indexarray[vindex])].getLocalXYZ());
vindex++;
if (!recalc)
glNormal3fv(vertexarray[(indexarray[vindex])].getNormal());
// ------------------------------
for(unit =0; unit<enabled; unit++) {
if( vertexarray[(indexarray[vindex])].getFlag() & TV_2NDUV &&
vertexarray[(indexarray[vindex])].getUnit() == unit )
{
bgl::blMultiTexCoord2fvARB(GL_TEXTURE0_ARB+unit, vertexarray[(indexarray[vindex])].getUV2());
continue;
}
bgl::blMultiTexCoord2fvARB(GL_TEXTURE0_ARB+unit, vertexarray[(indexarray[vindex])].getUV1());
}
// ------------------------------
TexCoord(vertexarray[(indexarray[vindex])],enabled );
glVertex3fv(vertexarray[(indexarray[vindex])].getLocalXYZ());
vindex++;
}
@@ -1820,51 +1723,21 @@ void RAS_OpenGLRasterizer::IndexPrimitivesMulti_Ex(const vecVertexArray & vertex
glColor4ubv((const GLubyte *)(vertexarray[(indexarray[vindex])].getRGBA()));
if (!recalc)
glNormal3fv(vertexarray[(indexarray[vindex])].getNormal());
// ------------------------------
for(unit =0; unit<enabled; unit++) {
if( vertexarray[(indexarray[vindex])].getFlag() & TV_2NDUV &&
vertexarray[(indexarray[vindex])].getUnit() == unit )
{
bgl::blMultiTexCoord2fvARB(GL_TEXTURE0_ARB+unit, vertexarray[(indexarray[vindex])].getUV2());
continue;
}
bgl::blMultiTexCoord2fvARB(GL_TEXTURE0_ARB+unit, vertexarray[(indexarray[vindex])].getUV1());
}
// ------------------------------
TexCoord(vertexarray[(indexarray[vindex])],enabled );
glVertex3fv(vertexarray[(indexarray[vindex])].getLocalXYZ());
vindex++;
glColor4ubv((const GLubyte *)(vertexarray[(indexarray[vindex])].getRGBA()));
if (!recalc)
glNormal3fv(vertexarray[(indexarray[vindex])].getNormal());
// ------------------------------
for(unit =0; unit<enabled; unit++) {
if( vertexarray[(indexarray[vindex])].getFlag() & TV_2NDUV &&
vertexarray[(indexarray[vindex])].getUnit() == unit )
{
bgl::blMultiTexCoord2fvARB(GL_TEXTURE0_ARB+unit, vertexarray[(indexarray[vindex])].getUV2());
continue;
}
bgl::blMultiTexCoord2fvARB(GL_TEXTURE0_ARB+unit, vertexarray[(indexarray[vindex])].getUV1());
}
// ------------------------------
TexCoord(vertexarray[(indexarray[vindex])],enabled );
glVertex3fv(vertexarray[(indexarray[vindex])].getLocalXYZ());
vindex++;
glColor4ubv((const GLubyte *)(vertexarray[(indexarray[vindex])].getRGBA()));
if (!recalc)
glNormal3fv(vertexarray[(indexarray[vindex])].getNormal());
// ------------------------------
for(unit =0; unit<enabled; unit++) {
if( vertexarray[(indexarray[vindex])].getFlag() & TV_2NDUV &&
vertexarray[(indexarray[vindex])].getUnit() == unit )
{
bgl::blMultiTexCoord2fvARB(GL_TEXTURE0_ARB+unit, vertexarray[(indexarray[vindex])].getUV2());
continue;
}
bgl::blMultiTexCoord2fvARB(GL_TEXTURE0_ARB+unit, vertexarray[(indexarray[vindex])].getUV1());
}
// ------------------------------
TexCoord(vertexarray[(indexarray[vindex])],enabled );
glVertex3fv(vertexarray[(indexarray[vindex])].getLocalXYZ());
vindex++;
}

View File

@@ -89,13 +89,12 @@ class RAS_OpenGLRasterizer : public RAS_IRasterizer
float m_focallength;
bool m_setfocallength;
int m_noOfScanlines;
TexCoGen m_texco[RAS_MAX];
bool m_useTang;
bool InterlacedStereo() const;
protected:
int m_drawingmode;
TexCoGen m_texco[RAS_MAX];
/** Stores the caching information for the last material activated. */
RAS_IPolyMaterial::TCachingInfo m_materialCachingInfo;
@@ -148,7 +147,8 @@ public:
class RAS_IPolyMaterial* polymat,
class RAS_IRenderTools* rendertools,
bool useObjectColor,
const MT_Vector4& rgbacolor
const MT_Vector4& rgbacolor,
class KX_ListSlot** slot
);
virtual void IndexPrimitives_Ex(
@@ -178,7 +178,8 @@ public:
class RAS_IPolyMaterial* polymat,
class RAS_IRenderTools* rendertools,
bool useObjectColor,
const MT_Vector4& rgbacolor);
const MT_Vector4& rgbacolor,
class KX_ListSlot** slot);
virtual void IndexPrimitivesMulti_Ex(
const vecVertexArray& vertexarrays,
@@ -284,9 +285,13 @@ public:
virtual void SetTexCoords(TexCoGen coords,int enabled);
void TexCoord(const RAS_TexVert &tv, int unit);
virtual void SetAttrib(int type);
virtual void GetViewMatrix(MT_Matrix4x4 &mat) const;
void Tangent(const RAS_TexVert& v1,
const RAS_TexVert& v2,
const RAS_TexVert& v3,
const MT_Vector3 &no);
};
#endif //__RAS_OPENGLRASTERIZER

View File

@@ -54,8 +54,9 @@
using namespace bgl;
RAS_VAOpenGLRasterizer::RAS_VAOpenGLRasterizer(RAS_ICanvas* canvas)
:RAS_OpenGLRasterizer(canvas)
RAS_VAOpenGLRasterizer::RAS_VAOpenGLRasterizer(RAS_ICanvas* canvas, bool lock)
: RAS_OpenGLRasterizer(canvas),
m_Lock(lock && RAS_EXT_support._EXT_compiled_vertex_array)
{
}
@@ -65,8 +66,6 @@ RAS_VAOpenGLRasterizer::~RAS_VAOpenGLRasterizer()
{
}
bool RAS_VAOpenGLRasterizer::Init(void)
{
@@ -138,7 +137,8 @@ void RAS_VAOpenGLRasterizer::IndexPrimitives( const vecVertexArray& vertexarrays
class RAS_IPolyMaterial* polymat,
class RAS_IRenderTools* rendertools,
bool useObjectColor,
const MT_Vector4& rgbacolor)
const MT_Vector4& rgbacolor,
class KX_ListSlot** slot)
{
static const GLsizei vtxstride = sizeof(RAS_TexVert);
GLenum drawmode;
@@ -181,13 +181,13 @@ void RAS_VAOpenGLRasterizer::IndexPrimitives( const vecVertexArray& vertexarrays
{
glColor3d(0,0,0);
}
// use glDrawElements to draw each vertexarray
for (vt=0;vt<vertexarrays.size();vt++)
{
vertexarray = &((*vertexarrays[vt]) [0]);
const KX_IndexArray & indexarray = (*indexarrays[vt]);
numindices = indexarray.size();
// int numverts = vertexarrays[vt]->size();
if (!numindices)
continue;
@@ -196,14 +196,142 @@ void RAS_VAOpenGLRasterizer::IndexPrimitives( const vecVertexArray& vertexarrays
glTexCoordPointer(2,GL_FLOAT,vtxstride,vertexarray->getUV1());
glColorPointer(4,GL_UNSIGNED_BYTE,vtxstride,vertexarray->getRGBA());
glNormalPointer(GL_FLOAT,vtxstride,vertexarray->getNormal());
//glLockArraysEXT(0,numverts);
//if(m_Lock)
// local->Begin(vertexarrays[vt]->size());
// here the actual drawing takes places
glDrawElements(drawmode,numindices,GL_UNSIGNED_SHORT,&(indexarray[0]));
//glUnlockArraysEXT();
//if(m_Lock)
// local->End();
}
}
void RAS_VAOpenGLRasterizer::IndexPrimitivesMulti( const vecVertexArray& vertexarrays,
const vecIndexArrays & indexarrays,
int mode,
class RAS_IPolyMaterial* polymat,
class RAS_IRenderTools* rendertools,
bool useObjectColor,
const MT_Vector4& rgbacolor,
class KX_ListSlot** slot)
{
static const GLsizei vtxstride = sizeof(RAS_TexVert);
GLenum drawmode;
switch (mode)
{
case 0:
{
drawmode = GL_TRIANGLES;
break;
}
case 2:
{
drawmode = GL_QUADS;
break;
}
case 1: //lines
{
}
default:
{
drawmode = GL_LINES;
break;
}
}
const RAS_TexVert* vertexarray;
unsigned int numindices, vt;
const unsigned int enabled = polymat->GetEnabled();
if (drawmode != GL_LINES)
{
if (useObjectColor)
{
glDisableClientState(GL_COLOR_ARRAY);
glColor4d(rgbacolor[0], rgbacolor[1], rgbacolor[2], rgbacolor[3]);
} else
{
glColor4d(0,0,0,1.0);
glEnableClientState(GL_COLOR_ARRAY);
}
}
else
{
glColor3d(0,0,0);
}
// use glDrawElements to draw each vertexarray
for (vt=0;vt<vertexarrays.size();vt++)
{
vertexarray = &((*vertexarrays[vt]) [0]);
const KX_IndexArray & indexarray = (*indexarrays[vt]);
numindices = indexarray.size();
if (!numindices)
continue;
glVertexPointer(3,GL_FLOAT,vtxstride,vertexarray->getLocalXYZ());
TexCoordPtr(vertexarray, enabled);
//glTexCoordPointer(2,GL_FLOAT,vtxstride,vertexarray->getUV1());
glColorPointer(4,GL_UNSIGNED_BYTE,vtxstride,vertexarray->getRGBA());
glNormalPointer(GL_FLOAT,vtxstride,vertexarray->getNormal());
//if(m_Lock)
// local->Begin(vertexarrays[vt]->size());
// here the actual drawing takes places
glDrawElements(drawmode,numindices,GL_UNSIGNED_SHORT,&(indexarray[0]));
//if(m_Lock)
// local->End();
}
}
void RAS_VAOpenGLRasterizer::TexCoordPtr(const RAS_TexVert *tv, int enabled)
{
#ifdef GL_ARB_multitexture
if(bgl::RAS_EXT_support._ARB_multitexture)
{
for(int unit=0; unit<enabled; unit++)
{
bgl::blClientActiveTextureARB(GL_TEXTURE0_ARB+unit);
glEnableClientState(GL_TEXTURE_COORD_ARRAY);
if( tv->getFlag() & TV_2NDUV && tv->getUnit() == unit ) {
glTexCoordPointer(2, GL_FLOAT, sizeof(RAS_TexVert), tv->getUV2());
continue;
}
switch(m_texco[unit])
{
case RAS_TEXCO_DISABLE:
case RAS_TEXCO_OBJECT:
case RAS_TEXCO_GEN:
glDisableClientState(GL_TEXTURE_COORD_ARRAY);
break;
case RAS_TEXCO_ORCO:
case RAS_TEXCO_GLOB:
glTexCoordPointer(3, GL_FLOAT, sizeof(RAS_TexVert),tv->getLocalXYZ());
break;
case RAS_TEXCO_UV1:
glTexCoordPointer(2, GL_FLOAT, sizeof(RAS_TexVert),tv->getUV1());
break;
case RAS_TEXCO_NORM:
glTexCoordPointer(3, GL_FLOAT, sizeof(RAS_TexVert),tv->getNormal());
break;
case RAS_TEXTANGENT:
glTexCoordPointer(4, GL_FLOAT, sizeof(RAS_TexVert),tv->getTangent());
}
}
}
#endif
}
void RAS_VAOpenGLRasterizer::EnableTextures(bool enable)
{
if (enable)

View File

@@ -36,8 +36,11 @@
class RAS_VAOpenGLRasterizer : public RAS_OpenGLRasterizer
{
void TexCoordPtr(const RAS_TexVert *tv, int unit);
bool m_Lock;
public:
RAS_VAOpenGLRasterizer(RAS_ICanvas* canvas);
RAS_VAOpenGLRasterizer(RAS_ICanvas* canvas, bool lock=false);
virtual ~RAS_VAOpenGLRasterizer();
virtual bool Init();
@@ -51,10 +54,23 @@ public:
class RAS_IPolyMaterial* polymat,
class RAS_IRenderTools* rendertools,
bool useObjectColor,
const MT_Vector4& rgbacolor);
const MT_Vector4& rgbacolor,
class KX_ListSlot** slot);
virtual void IndexPrimitivesMulti(
const vecVertexArray& vertexarrays,
const vecIndexArrays & indexarrays,
int mode,
class RAS_IPolyMaterial* polymat,
class RAS_IRenderTools* rendertools,
bool useObjectColor,
const MT_Vector4& rgbacolor,
class KX_ListSlot** slot);
virtual void EnableTextures(bool enable);
//virtual bool QueryArrays(){return true;}
//virtual bool QueryLists(){return m_Lock;}
};