BGE Rasterizer Cleanup: Removing RAS_IRenderTools and moving the functionality to RAS_IRasterizer. RAS_OpenGLRasterizer is a bit of a mess now with references to Ketsji and other modules it shouldn't be accessing.

This commit is contained in:
2013-11-04 19:21:07 +00:00
parent f4762eb12b
commit cf9fe8f329
39 changed files with 756 additions and 1852 deletions

View File

@@ -46,7 +46,6 @@
#include "KX_BlenderCanvas.h"
#include "KX_BlenderKeyboardDevice.h"
#include "KX_BlenderMouseDevice.h"
#include "KX_BlenderRenderTools.h"
#include "KX_BlenderSystem.h"
#include "BL_Material.h"
@@ -276,7 +275,7 @@ extern "C" void StartKetsjiShell(struct bContext *C, struct ARegion *ar, rcti *c
if (animation_record) usefixed= false; /* override since you don't want to run full-speed for sim recording */
// create the canvas, rasterizer and rendertools
// create the canvas and rasterizer
RAS_ICanvas* canvas = new KX_BlenderCanvas(wm, win, area_rect, ar);
// default mouse state set on render panel
@@ -292,7 +291,6 @@ extern "C" void StartKetsjiShell(struct bContext *C, struct ARegion *ar, rcti *c
else
canvas->SetSwapInterval((startscene->gm.vsync == VSYNC_ON) ? 1 : 0);
RAS_IRenderTools* rendertools = new KX_BlenderRenderTools();
RAS_IRasterizer* rasterizer = NULL;
//Don't use displaylists with VBOs
//If auto starts using VBOs, make sure to check for that here
@@ -324,7 +322,6 @@ extern "C" void StartKetsjiShell(struct bContext *C, struct ARegion *ar, rcti *c
ketsjiengine->SetMouseDevice(mousedevice);
ketsjiengine->SetNetworkDevice(networkdevice);
ketsjiengine->SetCanvas(canvas);
ketsjiengine->SetRenderTools(rendertools);
ketsjiengine->SetRasterizer(rasterizer);
ketsjiengine->SetUseFixedTime(usefixed);
ketsjiengine->SetTimingDisplay(frameRate, profile, properties);
@@ -518,7 +515,7 @@ extern "C" void StartKetsjiShell(struct bContext *C, struct ARegion *ar, rcti *c
// convert and add scene
sceneconverter->ConvertScene(
startscene,
rendertools,
rasterizer,
canvas);
ketsjiengine->AddScene(startscene);
@@ -664,11 +661,6 @@ extern "C" void StartKetsjiShell(struct bContext *C, struct ARegion *ar, rcti *c
delete rasterizer;
rasterizer = NULL;
}
if (rendertools)
{
delete rendertools;
rendertools = NULL;
}
if (canvas)
{
canvas->SetSwapInterval(previous_vsync); // Set the swap interval back

View File

@@ -43,7 +43,6 @@ set(SRC
KX_BlenderInputDevice.cpp
KX_BlenderKeyboardDevice.cpp
KX_BlenderMouseDevice.cpp
KX_BlenderRenderTools.cpp
KX_BlenderSystem.cpp
BL_System.h
@@ -52,7 +51,6 @@ set(SRC
KX_BlenderInputDevice.h
KX_BlenderKeyboardDevice.h
KX_BlenderMouseDevice.h
KX_BlenderRenderTools.h
KX_BlenderSystem.h
)

View File

@@ -108,169 +108,6 @@ int BL_GetSwapInterval(struct wmWindow *win)
return wm_window_get_swap_interval(win);
}
static void DisableForText()
{
glPolygonMode(GL_FRONT_AND_BACK, GL_FILL); /* needed for texture fonts otherwise they render as wireframe */
glDisable(GL_BLEND);
glDisable(GL_ALPHA_TEST);
glDisable(GL_LIGHTING);
glDisable(GL_COLOR_MATERIAL);
if (GLEW_ARB_multitexture) {
for (int i=0; i<MAXTEX; i++) {
glActiveTextureARB(GL_TEXTURE0_ARB+i);
if (GLEW_ARB_texture_cube_map)
glDisable(GL_TEXTURE_CUBE_MAP_ARB);
glDisable(GL_TEXTURE_2D);
}
glActiveTextureARB(GL_TEXTURE0_ARB);
}
else {
if (GLEW_ARB_texture_cube_map)
glDisable(GL_TEXTURE_CUBE_MAP_ARB);
glDisable(GL_TEXTURE_2D);
}
}
void BL_draw_gamedebug_box(int xco, int yco, int width, int height, float percentage)
{
/* This is a rather important line :( The gl-mode hasn't been left
* behind quite as neatly as we'd have wanted to. I don't know
* what cause it, though :/ .*/
glDisable(GL_DEPTH_TEST);
glMatrixMode(GL_PROJECTION);
glPushMatrix();
glLoadIdentity();
glOrtho(0, width, 0, height, -100, 100);
glMatrixMode(GL_MODELVIEW);
glPushMatrix();
glLoadIdentity();
yco = height - yco;
int barsize = 50;
/* draw in black first*/
glColor3ub(0, 0, 0);
glBegin(GL_QUADS);
glVertex2f(xco + 1 + 1 + barsize * percentage, yco - 1 + 10);
glVertex2f(xco + 1, yco - 1 + 10);
glVertex2f(xco + 1, yco - 1);
glVertex2f(xco + 1 + 1 + barsize * percentage, yco - 1);
glEnd();
glColor3ub(255, 255, 255);
glBegin(GL_QUADS);
glVertex2f(xco + 1 + barsize * percentage, yco + 10);
glVertex2f(xco, yco + 10);
glVertex2f(xco, yco);
glVertex2f(xco + 1 + barsize * percentage, yco);
glEnd();
glMatrixMode(GL_PROJECTION);
glPopMatrix();
glMatrixMode(GL_MODELVIEW);
glPopMatrix();
glEnable(GL_DEPTH_TEST);
}
/* Print 3D text */
void BL_print_game_line(int fontid, const char *text, int size, int dpi, float *color, double *mat, float aspect)
{
/* gl prepping */
DisableForText();
/* the actual drawing */
glColor4fv(color);
/* multiply the text matrix by the object matrix */
BLF_enable(fontid, BLF_MATRIX|BLF_ASPECT);
BLF_matrix(fontid, mat);
/* aspect is the inverse scale that allows you to increase */
/* your resolution without sizing the final text size */
/* the bigger the size, the smaller the aspect */
BLF_aspect(fontid, aspect, aspect, aspect);
BLF_size(fontid, size, dpi);
BLF_position(fontid, 0, 0, 0);
BLF_draw(fontid, (char *)text, 65535);
BLF_disable(fontid, BLF_MATRIX|BLF_ASPECT);
}
void BL_print_gamedebug_line(const char *text, int xco, int yco, int width, int height)
{
/* gl prepping */
DisableForText();
glDisable(GL_DEPTH_TEST);
glMatrixMode(GL_PROJECTION);
glPushMatrix();
glLoadIdentity();
glOrtho(0, width, 0, height, -100, 100);
glMatrixMode(GL_MODELVIEW);
glPushMatrix();
glLoadIdentity();
/* the actual drawing */
glColor3ub(255, 255, 255);
BLF_size(blf_mono_font, 11, 72);
BLF_position(blf_mono_font, (float)xco, (float)(height-yco), 0.0f);
BLF_draw(blf_mono_font, (char *)text, 65535); /* XXX, use real len */
glMatrixMode(GL_PROJECTION);
glPopMatrix();
glMatrixMode(GL_MODELVIEW);
glPopMatrix();
glEnable(GL_DEPTH_TEST);
}
void BL_print_gamedebug_line_padded(const char *text, int xco, int yco, int width, int height)
{
/* This is a rather important line :( The gl-mode hasn't been left
* behind quite as neatly as we'd have wanted to. I don't know
* what cause it, though :/ .*/
DisableForText();
glDisable(GL_DEPTH_TEST);
glMatrixMode(GL_PROJECTION);
glPushMatrix();
glLoadIdentity();
glOrtho(0, width, 0, height, -100, 100);
glMatrixMode(GL_MODELVIEW);
glPushMatrix();
glLoadIdentity();
/* draw in black first*/
glColor3ub(0, 0, 0);
BLF_size(blf_mono_font, 11, 72);
BLF_position(blf_mono_font, (float)xco+1, (float)(height-yco-1), 0.0f);
BLF_draw(blf_mono_font, (char *)text, 65535);/* XXX, use real len */
glColor3ub(255, 255, 255);
BLF_position(blf_mono_font, (float)xco, (float)(height-yco), 0.0f);
BLF_draw(blf_mono_font, (char *)text, 65535);
glMatrixMode(GL_PROJECTION);
glPopMatrix();
glMatrixMode(GL_MODELVIEW);
glPopMatrix();
glEnable(GL_DEPTH_TEST);
}
void BL_HideMouse(wmWindow *win)
{
WM_cursor_set(win, CURSOR_NONE);

View File

@@ -56,11 +56,6 @@ void BL_HideMouse(struct wmWindow *win);
void BL_NormalMouse(struct wmWindow *win);
void BL_WaitMouse(struct wmWindow *win);
void BL_draw_gamedebug_box(int xco, int yco, int width, int height, float percentage);
void BL_print_game_line(int fontid, const char* text, int size, int dpi, float* color, double* mat, float aspect);
void BL_print_gamedebug_line(const char* text, int xco, int yco, int width, int height);
void BL_print_gamedebug_line_padded(const char* text, int xco, int yco, int width, int height);
#ifdef __cplusplus

View File

@@ -1,410 +0,0 @@
/*
* ***** BEGIN GPL LICENSE BLOCK *****
*
* This program is free software; you can redistribute it and/or
* modify it under the terms of the GNU General Public License
* as published by the Free Software Foundation; either version 2
* of the License, or (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software Foundation,
* Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
*
* The Original Code is Copyright (C) 2001-2002 by NaN Holding BV.
* All rights reserved.
*
* The Original Code is: all of this file.
*
* Contributor(s): none yet.
*
* ***** END GPL LICENSE BLOCK *****
*/
/** \file gameengine/BlenderRoutines/KX_BlenderRenderTools.cpp
* \ingroup blroutines
*/
#include "GL/glew.h"
#include "RAS_IRenderTools.h"
#include "RAS_IRasterizer.h"
#include "RAS_LightObject.h"
#include "RAS_ICanvas.h"
#include "RAS_GLExtensionManager.h"
#include "RAS_MeshObject.h"
#include "KX_GameObject.h"
#include "KX_PolygonMaterial.h"
#include "KX_BlenderMaterial.h"
#include "KX_RayCast.h"
#include "KX_IPhysicsController.h"
#include "KX_Light.h"
#include "PHY_IPhysicsEnvironment.h"
#include "STR_String.h"
#include "GPU_draw.h"
#include "KX_BlenderGL.h" // for text printing
#include "KX_BlenderRenderTools.h"
unsigned int KX_BlenderRenderTools::m_numgllights;
KX_BlenderRenderTools::KX_BlenderRenderTools()
{
glGetIntegerv(GL_MAX_LIGHTS, (GLint *) &m_numgllights);
if (m_numgllights < 8)
m_numgllights = 8;
}
KX_BlenderRenderTools::~KX_BlenderRenderTools()
{
}
void KX_BlenderRenderTools::BeginFrame(RAS_IRasterizer* rasty)
{
m_clientobject = NULL;
m_lastlightlayer = -1;
m_lastauxinfo = NULL;
m_lastlighting = true; /* force disable in DisableOpenGLLights() */
DisableOpenGLLights();
}
void KX_BlenderRenderTools::EndFrame(RAS_IRasterizer* rasty)
{
}
/* ProcessLighting performs lighting on objects. the layer is a bitfield that
* contains layer information. There are 20 'official' layers in blender. A
* light is applied on an object only when they are in the same layer. OpenGL
* has a maximum of 8 lights (simultaneous), so 20 * 8 lights are possible in
* a scene. */
void KX_BlenderRenderTools::ProcessLighting(RAS_IRasterizer *rasty, bool uselights, const MT_Transform& viewmat)
{
bool enable = false;
int layer= -1;
/* find the layer */
if (uselights) {
if (m_clientobject)
layer = static_cast<KX_GameObject*>(m_clientobject)->GetLayer();
}
/* avoid state switching */
if (m_lastlightlayer == layer && m_lastauxinfo == m_auxilaryClientInfo)
return;
m_lastlightlayer = layer;
m_lastauxinfo = m_auxilaryClientInfo;
/* enable/disable lights as needed */
if (layer >= 0)
enable = applyLights(layer, viewmat);
if (enable)
EnableOpenGLLights(rasty);
else
DisableOpenGLLights();
}
void KX_BlenderRenderTools::EnableOpenGLLights(RAS_IRasterizer *rasty)
{
if (m_lastlighting == true)
return;
glEnable(GL_LIGHTING);
glEnable(GL_COLOR_MATERIAL);
glColorMaterial(GL_FRONT_AND_BACK, GL_AMBIENT_AND_DIFFUSE);
glLightModeli(GL_LIGHT_MODEL_TWO_SIDE, GL_TRUE);
glLightModeli(GL_LIGHT_MODEL_LOCAL_VIEWER, (rasty->GetCameraOrtho())? GL_FALSE: GL_TRUE);
if (GLEW_EXT_separate_specular_color || GLEW_VERSION_1_2)
glLightModeli(GL_LIGHT_MODEL_COLOR_CONTROL, GL_SEPARATE_SPECULAR_COLOR);
m_lastlighting = true;
}
void KX_BlenderRenderTools::DisableOpenGLLights()
{
if (m_lastlighting == false)
return;
glDisable(GL_LIGHTING);
glDisable(GL_COLOR_MATERIAL);
m_lastlighting = false;
}
void KX_BlenderRenderTools::SetClientObject(RAS_IRasterizer *rasty, void* obj)
{
if (m_clientobject != obj)
{
bool ccw = (obj == NULL || !((KX_GameObject*)obj)->IsNegativeScaling());
rasty->SetFrontFace(ccw);
m_clientobject = obj;
}
}
bool KX_BlenderRenderTools::RayHit(KX_ClientObjectInfo *client, KX_RayCast *result, void * const data)
{
double* const oglmatrix = (double* const) data;
RAS_Polygon* poly = result->m_hitMesh->GetPolygon(result->m_hitPolygon);
if (!poly->IsVisible())
return false;
MT_Point3 resultpoint(result->m_hitPoint);
MT_Vector3 resultnormal(result->m_hitNormal);
MT_Vector3 left(oglmatrix[0],oglmatrix[1],oglmatrix[2]);
MT_Vector3 dir = -(left.cross(resultnormal)).safe_normalized();
left = (dir.cross(resultnormal)).safe_normalized();
// for the up vector, we take the 'resultnormal' returned by the physics
double maat[16] = {left[0], left[1], left[2], 0,
dir[0], dir[1], dir[2], 0,
resultnormal[0], resultnormal[1], resultnormal[2], 0,
0, 0, 0, 1};
glTranslated(resultpoint[0],resultpoint[1],resultpoint[2]);
//glMultMatrixd(oglmatrix);
glMultMatrixd(maat);
return true;
}
void KX_BlenderRenderTools::applyTransform(RAS_IRasterizer* rasty,double* oglmatrix,int objectdrawmode )
{
/* FIXME:
blender: intern/moto/include/MT_Vector3.inl:42: MT_Vector3 operator/(const
MT_Vector3&, double): Assertion `!MT_fuzzyZero(s)' failed.
Program received signal SIGABRT, Aborted.
[Switching to Thread 16384 (LWP 1519)]
0x40477571 in kill () from /lib/libc.so.6
(gdb) bt
#7 0x08334368 in MT_Vector3::normalized() const ()
#8 0x0833e6ec in KX_BlenderRenderTools::applyTransform(RAS_IRasterizer*, double*, int) ()
*/
if (objectdrawmode & RAS_IPolyMaterial::BILLBOARD_SCREENALIGNED ||
objectdrawmode & RAS_IPolyMaterial::BILLBOARD_AXISALIGNED)
{
// rotate the billboard/halo
//page 360/361 3D Game Engine Design, David Eberly for a discussion
// on screen aligned and axis aligned billboards
// assumed is that the preprocessor transformed all billboard polygons
// so that their normal points into the positive x direction (1.0, 0.0, 0.0)
// when new parenting for objects is done, this rotation
// will be moved into the object
MT_Point3 objpos (oglmatrix[12],oglmatrix[13],oglmatrix[14]);
MT_Point3 campos = rasty->GetCameraPosition();
MT_Vector3 dir = (campos - objpos).safe_normalized();
MT_Vector3 up(0,0,1.0);
KX_GameObject* gameobj = (KX_GameObject *)this->m_clientobject;
// get scaling of halo object
MT_Vector3 size = gameobj->GetSGNode()->GetWorldScaling();
bool screenaligned = (objectdrawmode & RAS_IPolyMaterial::BILLBOARD_SCREENALIGNED)!=0;//false; //either screen or axisaligned
if (screenaligned)
{
up = (up - up.dot(dir) * dir).safe_normalized();
} else
{
dir = (dir - up.dot(dir)*up).safe_normalized();
}
MT_Vector3 left = dir.normalized();
dir = (left.cross(up)).normalized();
// we have calculated the row vectors, now we keep
// local scaling into account:
left *= size[0];
dir *= size[1];
up *= size[2];
double maat[16] = {left[0], left[1], left[2], 0,
dir[0], dir[1], dir[2], 0,
up[0], up[1], up[2], 0,
0, 0, 0, 1};
glTranslated(objpos[0],objpos[1],objpos[2]);
glMultMatrixd(maat);
}
else {
if (objectdrawmode & RAS_IPolyMaterial::SHADOW)
{
// shadow must be cast to the ground, physics system needed here!
MT_Point3 frompoint(oglmatrix[12],oglmatrix[13],oglmatrix[14]);
KX_GameObject *gameobj = (KX_GameObject *)this->m_clientobject;
MT_Vector3 direction = MT_Vector3(0,0,-1);
direction.normalize();
direction *= 100000;
MT_Point3 topoint = frompoint + direction;
KX_Scene* kxscene = (KX_Scene*) m_auxilaryClientInfo;
PHY_IPhysicsEnvironment* physics_environment = kxscene->GetPhysicsEnvironment();
KX_IPhysicsController* physics_controller = gameobj->GetPhysicsController();
KX_GameObject *parent = gameobj->GetParent();
if (!physics_controller && parent)
physics_controller = parent->GetPhysicsController();
if (parent)
parent->Release();
KX_RayCast::Callback<KX_BlenderRenderTools> callback(this, physics_controller, oglmatrix);
if (!KX_RayCast::RayTest(physics_environment, frompoint, topoint, callback))
{
// couldn't find something to cast the shadow on...
glMultMatrixd(oglmatrix);
}
else
{ // we found the "ground", but the cast matrix doesn't take
// scaling in consideration, so we must apply the object scale
MT_Vector3 size = gameobj->GetSGNode()->GetLocalScale();
glScalef(size[0], size[1], size[2]);
}
} else
{
// 'normal' object
glMultMatrixd(oglmatrix);
}
}
}
void KX_BlenderRenderTools::RenderBox2D(int xco,
int yco,
int width,
int height,
float percentage)
{
BL_draw_gamedebug_box(xco, yco, width, height, percentage);
}
void KX_BlenderRenderTools::RenderText3D(int fontid,
const char* text,
int size,
int dpi,
float* color,
double* mat,
float aspect)
{
BL_print_game_line(fontid, text, size, dpi, color, mat, aspect);
}
void KX_BlenderRenderTools::RenderText2D(RAS_TEXT_RENDER_MODE mode,
const char* text,
int xco,
int yco,
int width,
int height)
{
if (mode == RAS_IRenderTools::RAS_TEXT_PADDED)
BL_print_gamedebug_line_padded(text, xco, yco, width, height);
else
BL_print_gamedebug_line(text, xco, yco, width, height);
}
/* Render Text renders text into a (series of) polygon, using a texture font,
* Each character consists of one polygon (one quad or two triangles) */
void KX_BlenderRenderTools::RenderText(
int mode,
RAS_IPolyMaterial* polymat,
float v1[3], float v2[3], float v3[3], float v4[3], int glattrib)
{
const STR_String &mytext = ((CValue *)m_clientobject)->GetPropertyText("Text");
const unsigned int flag = polymat->GetFlag();
struct MTFace* tface = 0;
unsigned int *col = 0;
if (flag & RAS_BLENDERMAT) {
KX_BlenderMaterial *bl_mat = static_cast<KX_BlenderMaterial*>(polymat);
tface = bl_mat->GetMTFace();
col = bl_mat->GetMCol();
} else {
KX_PolygonMaterial* blenderpoly = static_cast<KX_PolygonMaterial*>(polymat);
tface = blenderpoly->GetMTFace();
col = blenderpoly->GetMCol();
}
GPU_render_text(tface, mode, mytext, mytext.Length(), col, v1, v2, v3, v4, glattrib);
}
void KX_BlenderRenderTools::PushMatrix()
{
glPushMatrix();
}
void KX_BlenderRenderTools::PopMatrix()
{
glPopMatrix();
}
int KX_BlenderRenderTools::applyLights(int objectlayer, const MT_Transform& viewmat)
{
// taken from blender source, incompatibility between Blender Object / GameObject
KX_Scene* kxscene = (KX_Scene*)m_auxilaryClientInfo;
float glviewmat[16];
unsigned int count;
std::vector<struct RAS_LightObject*>::iterator lit = m_lights.begin();
for (count=0; count<m_numgllights; count++)
glDisable((GLenum)(GL_LIGHT0+count));
viewmat.getValue(glviewmat);
glPushMatrix();
glLoadMatrixf(glviewmat);
for (lit = m_lights.begin(), count = 0; !(lit==m_lights.end()) && count < m_numgllights; ++lit)
{
RAS_LightObject* lightdata = (*lit);
KX_LightObject *kxlight = (KX_LightObject*)lightdata->m_light;
if (kxlight->ApplyLight(kxscene, objectlayer, count))
count++;
}
glPopMatrix();
return count;
}
void KX_BlenderRenderTools::MotionBlur(RAS_IRasterizer* rasterizer)
{
int state = rasterizer->GetMotionBlurState();
float motionblurvalue;
if (state)
{
motionblurvalue = rasterizer->GetMotionBlurValue();
if (state==1)
{
//bugfix:load color buffer into accum buffer for the first time(state=1)
glAccum(GL_LOAD, 1.0);
rasterizer->SetMotionBlurState(2);
}
else if (motionblurvalue >= 0.0f && motionblurvalue <= 1.0f) {
glAccum(GL_MULT, motionblurvalue);
glAccum(GL_ACCUM, 1-motionblurvalue);
glAccum(GL_RETURN, 1.0);
glFlush();
}
}
}

View File

@@ -1,122 +0,0 @@
/*
* ***** BEGIN GPL LICENSE BLOCK *****
*
* This program is free software; you can redistribute it and/or
* modify it under the terms of the GNU General Public License
* as published by the Free Software Foundation; either version 2
* of the License, or (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software Foundation,
* Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
*
* The Original Code is Copyright (C) 2001-2002 by NaN Holding BV.
* All rights reserved.
*
* The Original Code is: all of this file.
*
* Contributor(s): none yet.
*
* ***** END GPL LICENSE BLOCK *****
*/
/** \file KX_BlenderRenderTools.h
* \ingroup blroutines
*/
#ifndef __KX_BLENDERRENDERTOOLS_H__
#define __KX_BLENDERRENDERTOOLS_H__
#ifdef _MSC_VER
/* don't show stl-warnings */
# pragma warning (disable:4786)
#endif
#include "RAS_IRenderTools.h"
#ifdef WITH_CXX_GUARDEDALLOC
#include "MEM_guardedalloc.h"
#endif
struct KX_ClientObjectInfo;
class KX_RayCast;
/* BlenderRenderTools are a set of tools to apply 2D/3D graphics effects, which
* are not part of the (polygon) Rasterizer. Effects like 2D text, 3D (polygon)
* text, lighting.
*
* Most of this code is duplicated in GPC_RenderTools, so this should be
* moved to some common location to avoid duplication. */
class KX_BlenderRenderTools : public RAS_IRenderTools
{
int m_lastlightlayer;
bool m_lastlighting;
void *m_lastauxinfo;
static unsigned int m_numgllights;
public:
KX_BlenderRenderTools();
virtual ~KX_BlenderRenderTools();
void EndFrame(RAS_IRasterizer* rasty);
void BeginFrame(RAS_IRasterizer* rasty);
void EnableOpenGLLights(RAS_IRasterizer *rasty);
void DisableOpenGLLights();
void ProcessLighting(RAS_IRasterizer *rasty, bool uselights, const MT_Transform& viewmat);
void RenderBox2D(int xco,
int yco,
int width,
int height,
float percentage);
void RenderText3D(int fontid,
const char* text,
int size,
int dpi,
float* color,
double* mat,
float aspect);
void RenderText2D(RAS_TEXT_RENDER_MODE mode,
const char* text,
int xco,
int yco,
int width,
int height);
void RenderText(int mode,
class RAS_IPolyMaterial* polymat,
float v1[3],
float v2[3],
float v3[3],
float v4[3],
int glattrib);
void applyTransform(RAS_IRasterizer* rasty, double* oglmatrix, int objectdrawmode);
int applyLights(int objectlayer, const MT_Transform& viewmat);
void PushMatrix();
void PopMatrix();
bool RayHit(KX_ClientObjectInfo* client, class KX_RayCast* result, void * const data);
bool NeedRayCast(KX_ClientObjectInfo*) { return true; }
virtual void MotionBlur(RAS_IRasterizer* rasterizer);
virtual void SetClientObject(RAS_IRasterizer *rasty, void* obj);
#ifdef WITH_CXX_GUARDEDALLOC
MEM_CXX_CLASS_ALLOC_FUNCS("GE:KX_BlenderRenderTools")
#endif
};
#endif /* __KX_BLENDERRENDERTOOLS_H__ */

View File

@@ -80,7 +80,6 @@
#include "RAS_Polygon.h"
#include "RAS_TexVert.h"
#include "RAS_BucketManager.h"
#include "RAS_IRenderTools.h"
#include "BL_Material.h"
#include "KX_BlenderMaterial.h"
#include "BL_Texture.h"
@@ -1874,7 +1873,7 @@ static void BL_CreatePhysicsObjectNew(KX_GameObject* gameobj,
static KX_LightObject *gamelight_from_blamp(Object *ob, Lamp *la, unsigned int layerflag, KX_Scene *kxscene, RAS_IRenderTools *rendertools, KX_BlenderSceneConverter *converter)
static KX_LightObject *gamelight_from_blamp(Object *ob, Lamp *la, unsigned int layerflag, KX_Scene *kxscene, RAS_IRasterizer *rasterizer, KX_BlenderSceneConverter *converter)
{
RAS_LightObject lightobj;
KX_LightObject *gamelight;
@@ -1913,7 +1912,7 @@ static KX_LightObject *gamelight_from_blamp(Object *ob, Lamp *la, unsigned int l
lightobj.m_type = RAS_LightObject::LIGHT_NORMAL;
}
gamelight = new KX_LightObject(kxscene, KX_Scene::m_callbacks, rendertools,
gamelight = new KX_LightObject(kxscene, KX_Scene::m_callbacks, rasterizer,
lightobj, glslmat);
return gamelight;
@@ -1934,7 +1933,7 @@ static KX_Camera *gamecamera_from_bcamera(Object *ob, KX_Scene *kxscene, KX_Blen
static KX_GameObject *gameobject_from_blenderobject(
Object *ob,
KX_Scene *kxscene,
RAS_IRenderTools *rendertools,
RAS_IRasterizer *rendertools,
KX_BlenderSceneConverter *converter,
bool libloading)
{
@@ -2359,7 +2358,7 @@ void BL_ConvertBlenderObjects(struct Main* maggie,
KX_Scene* kxscene,
KX_KetsjiEngine* ketsjiEngine,
e_PhysicsEngine physics_engine,
RAS_IRenderTools* rendertools,
RAS_IRasterizer* rendertools,
RAS_ICanvas* canvas,
KX_BlenderSceneConverter* converter,
bool alwaysUseExpandFraming,

View File

@@ -44,7 +44,7 @@ void BL_ConvertBlenderObjects(struct Main* maggie,
class KX_Scene* kxscene,
class KX_KetsjiEngine* ketsjiEngine,
e_PhysicsEngine physics_engine,
class RAS_IRenderTools* rendertools,
class RAS_IRasterizer* rendertools,
class RAS_ICanvas* canvas,
class KX_BlenderSceneConverter* sceneconverter,
bool alwaysUseExpandFraming,

View File

@@ -313,7 +313,7 @@ struct BlenderDebugDraw : public btIDebugDraw
#endif
void KX_BlenderSceneConverter::ConvertScene(class KX_Scene* destinationscene,
class RAS_IRenderTools* rendertools,
class RAS_IRasterizer* rendertools,
class RAS_ICanvas* canvas,
bool libloading)
{

View File

@@ -111,7 +111,7 @@ public:
*/
virtual void ConvertScene(
class KX_Scene* destinationscene,
class RAS_IRenderTools* rendertools,
class RAS_IRasterizer* rendertools,
class RAS_ICanvas* canvas,
bool libloading=false
);

View File

@@ -63,12 +63,10 @@ set(SRC
GPC_Canvas.cpp
GPC_KeyboardDevice.cpp
GPC_MouseDevice.cpp
GPC_RenderTools.cpp
GPC_Canvas.h
GPC_KeyboardDevice.h
GPC_MouseDevice.h
GPC_RenderTools.h
)
add_definitions(-DGLEW_STATIC)

View File

@@ -1,577 +0,0 @@
/*
* ***** BEGIN GPL LICENSE BLOCK *****
*
* This program is free software; you can redistribute it and/or
* modify it under the terms of the GNU General Public License
* as published by the Free Software Foundation; either version 2
* of the License, or (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software Foundation,
* Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
*
* The Original Code is Copyright (C) 2001-2002 by NaN Holding BV.
* All rights reserved.
*
* The Original Code is: all of this file.
*
* Contributor(s): none yet.
*
* ***** END GPL LICENSE BLOCK *****
*/
/** \file gameengine/GamePlayer/common/GPC_RenderTools.cpp
* \ingroup player
*/
#include "GL/glew.h"
#include "RAS_IRenderTools.h"
#include "RAS_IRasterizer.h"
#include "RAS_LightObject.h"
#include "RAS_ICanvas.h"
#include "RAS_GLExtensionManager.h"
#include "RAS_MeshObject.h"
#include "KX_GameObject.h"
#include "KX_PolygonMaterial.h"
#include "KX_BlenderMaterial.h"
#include "KX_RayCast.h"
#include "KX_IPhysicsController.h"
#include "KX_Light.h"
#include "PHY_IPhysicsEnvironment.h"
#include "STR_String.h"
#include "GPU_draw.h"
#include "BKE_bmfont.h" // for text printing
#include "BKE_bmfont_types.h"
#include "GPC_RenderTools.h"
extern "C" {
#include "BLF_api.h"
}
unsigned int GPC_RenderTools::m_numgllights;
GPC_RenderTools::GPC_RenderTools()
{
glGetIntegerv(GL_MAX_LIGHTS, (GLint *) &m_numgllights);
if (m_numgllights < 8)
m_numgllights = 8;
}
GPC_RenderTools::~GPC_RenderTools()
{
}
void GPC_RenderTools::BeginFrame(RAS_IRasterizer* rasty)
{
m_clientobject = NULL;
m_lastlightlayer = -1;
m_lastauxinfo = NULL;
m_lastlighting = true; /* force disable in DisableOpenGLLights() */
DisableOpenGLLights();
}
void GPC_RenderTools::EndFrame(RAS_IRasterizer* rasty)
{
}
/* ProcessLighting performs lighting on objects. the layer is a bitfield that
* contains layer information. There are 20 'official' layers in blender. A
* light is applied on an object only when they are in the same layer. OpenGL
* has a maximum of 8 lights (simultaneous), so 20 * 8 lights are possible in
* a scene. */
void GPC_RenderTools::ProcessLighting(RAS_IRasterizer *rasty, bool uselights, const MT_Transform& viewmat)
{
bool enable = false;
int layer= -1;
/* find the layer */
if (uselights) {
if (m_clientobject)
layer = static_cast<KX_GameObject*>(m_clientobject)->GetLayer();
}
/* avoid state switching */
if (m_lastlightlayer == layer && m_lastauxinfo == m_auxilaryClientInfo)
return;
m_lastlightlayer = layer;
m_lastauxinfo = m_auxilaryClientInfo;
/* enable/disable lights as needed */
if (layer >= 0)
enable = applyLights(layer, viewmat);
if (enable)
EnableOpenGLLights(rasty);
else
DisableOpenGLLights();
}
void GPC_RenderTools::EnableOpenGLLights(RAS_IRasterizer *rasty)
{
if (m_lastlighting == true)
return;
glEnable(GL_LIGHTING);
glEnable(GL_COLOR_MATERIAL);
glColorMaterial(GL_FRONT_AND_BACK, GL_AMBIENT_AND_DIFFUSE);
glLightModeli(GL_LIGHT_MODEL_TWO_SIDE, GL_TRUE);
glLightModeli(GL_LIGHT_MODEL_LOCAL_VIEWER, (rasty->GetCameraOrtho())? GL_FALSE: GL_TRUE);
if (GLEW_EXT_separate_specular_color || GLEW_VERSION_1_2)
glLightModeli(GL_LIGHT_MODEL_COLOR_CONTROL, GL_SEPARATE_SPECULAR_COLOR);
m_lastlighting = true;
}
void GPC_RenderTools::DisableOpenGLLights()
{
if (m_lastlighting == false)
return;
glDisable(GL_LIGHTING);
glDisable(GL_COLOR_MATERIAL);
m_lastlighting = false;
}
void GPC_RenderTools::SetClientObject(RAS_IRasterizer *rasty, void* obj)
{
if (m_clientobject != obj)
{
bool ccw = (obj == NULL || !((KX_GameObject*)obj)->IsNegativeScaling());
rasty->SetFrontFace(ccw);
m_clientobject = obj;
}
}
bool GPC_RenderTools::RayHit(KX_ClientObjectInfo *client, KX_RayCast *result, void * const data)
{
double* const oglmatrix = (double* const) data;
RAS_Polygon* poly = result->m_hitMesh->GetPolygon(result->m_hitPolygon);
if (!poly->IsVisible())
return false;
MT_Point3 resultpoint(result->m_hitPoint);
MT_Vector3 resultnormal(result->m_hitNormal);
MT_Vector3 left(oglmatrix[0],oglmatrix[1],oglmatrix[2]);
MT_Vector3 dir = -(left.cross(resultnormal)).safe_normalized();
left = (dir.cross(resultnormal)).safe_normalized();
// for the up vector, we take the 'resultnormal' returned by the physics
double maat[16] = {left[0], left[1], left[2], 0,
dir[0], dir[1], dir[2], 0,
resultnormal[0], resultnormal[1], resultnormal[2], 0,
0, 0, 0, 1};
glTranslated(resultpoint[0],resultpoint[1],resultpoint[2]);
//glMultMatrixd(oglmatrix);
glMultMatrixd(maat);
return true;
}
void GPC_RenderTools::applyTransform(RAS_IRasterizer* rasty,double* oglmatrix,int objectdrawmode )
{
/* FIXME:
blender: intern/moto/include/MT_Vector3.inl:42: MT_Vector3 operator/(const
MT_Vector3&, double): Assertion `!MT_fuzzyZero(s)' failed.
Program received signal SIGABRT, Aborted.
[Switching to Thread 16384 (LWP 1519)]
0x40477571 in kill () from /lib/libc.so.6
(gdb) bt
#7 0x08334368 in MT_Vector3::normalized() const ()
#8 0x0833e6ec in GPC_RenderTools::applyTransform(RAS_IRasterizer*, double*, int) ()
*/
if (objectdrawmode & RAS_IPolyMaterial::BILLBOARD_SCREENALIGNED ||
objectdrawmode & RAS_IPolyMaterial::BILLBOARD_AXISALIGNED)
{
// rotate the billboard/halo
//page 360/361 3D Game Engine Design, David Eberly for a discussion
// on screen aligned and axis aligned billboards
// assumed is that the preprocessor transformed all billboard polygons
// so that their normal points into the positive x direction (1.0, 0.0, 0.0)
// when new parenting for objects is done, this rotation
// will be moved into the object
MT_Point3 objpos (oglmatrix[12],oglmatrix[13],oglmatrix[14]);
MT_Point3 campos = rasty->GetCameraPosition();
MT_Vector3 dir = (campos - objpos).safe_normalized();
MT_Vector3 up(0,0,1.0);
KX_GameObject* gameobj = (KX_GameObject *)this->m_clientobject;
// get scaling of halo object
MT_Vector3 size = gameobj->GetSGNode()->GetWorldScaling();
bool screenaligned = (objectdrawmode & RAS_IPolyMaterial::BILLBOARD_SCREENALIGNED)!=0;//false; //either screen or axisaligned
if (screenaligned)
{
up = (up - up.dot(dir) * dir).safe_normalized();
} else
{
dir = (dir - up.dot(dir)*up).safe_normalized();
}
MT_Vector3 left = dir.normalized();
dir = (left.cross(up)).normalized();
// we have calculated the row vectors, now we keep
// local scaling into account:
left *= size[0];
dir *= size[1];
up *= size[2];
double maat[16] = {left[0], left[1], left[2], 0,
dir[0], dir[1], dir[2], 0,
up[0], up[1], up[2], 0,
0, 0, 0, 1};
glTranslated(objpos[0],objpos[1],objpos[2]);
glMultMatrixd(maat);
}
else {
if (objectdrawmode & RAS_IPolyMaterial::SHADOW)
{
// shadow must be cast to the ground, physics system needed here!
MT_Point3 frompoint(oglmatrix[12],oglmatrix[13],oglmatrix[14]);
KX_GameObject *gameobj = (KX_GameObject *)this->m_clientobject;
MT_Vector3 direction = MT_Vector3(0,0,-1);
direction.normalize();
direction *= 100000;
MT_Point3 topoint = frompoint + direction;
KX_Scene* kxscene = (KX_Scene*) m_auxilaryClientInfo;
PHY_IPhysicsEnvironment* physics_environment = kxscene->GetPhysicsEnvironment();
KX_IPhysicsController* physics_controller = gameobj->GetPhysicsController();
KX_GameObject *parent = gameobj->GetParent();
if (!physics_controller && parent)
physics_controller = parent->GetPhysicsController();
if (parent)
parent->Release();
KX_RayCast::Callback<GPC_RenderTools> callback(this, physics_controller, oglmatrix);
if (!KX_RayCast::RayTest(physics_environment, frompoint, topoint, callback))
{
// couldn't find something to cast the shadow on...
glMultMatrixd(oglmatrix);
}
else
{ // we found the "ground", but the cast matrix doesn't take
// scaling in consideration, so we must apply the object scale
MT_Vector3 size = gameobj->GetSGNode()->GetLocalScale();
glScalef(size[0], size[1], size[2]);
}
} else
{
// 'normal' object
glMultMatrixd(oglmatrix);
}
}
}
void GPC_RenderTools::RenderBox2D(int xco,
int yco,
int width,
int height,
float percentage)
{
// Save and change OpenGL settings
int texture2D;
glGetIntegerv(GL_TEXTURE_2D, (GLint*)&texture2D);
glDisable(GL_TEXTURE_2D);
int fog;
glGetIntegerv(GL_FOG, (GLint*)&fog);
glDisable(GL_FOG);
int light;
glGetIntegerv(GL_LIGHTING, (GLint*)&light);
glDisable(GL_LIGHTING);
glDisable(GL_DEPTH_TEST);
// Set up viewing settings
glMatrixMode(GL_PROJECTION);
glPushMatrix();
glLoadIdentity();
glOrtho(0, width, 0, height, -1, 1);
glMatrixMode(GL_MODELVIEW);
glPushMatrix();
glLoadIdentity();
yco = height - yco;
int barsize = 50;
// draw in black first
glColor3ub(0, 0, 0);
glBegin(GL_QUADS);
glVertex2f(xco + 1 + 1 + barsize * percentage, yco - 1 + 10);
glVertex2f(xco + 1, yco - 1 + 10);
glVertex2f(xco + 1, yco - 1);
glVertex2f(xco + 1 + 1 + barsize * percentage, yco - 1);
glEnd();
glColor3ub(255, 255, 255);
glBegin(GL_QUADS);
glVertex2f(xco + 1 + barsize * percentage, yco + 10);
glVertex2f(xco, yco + 10);
glVertex2f(xco, yco);
glVertex2f(xco + 1 + barsize * percentage, yco);
glEnd();
// Restore view settings
glMatrixMode(GL_PROJECTION);
glPopMatrix();
glMatrixMode(GL_MODELVIEW);
glPopMatrix();
// Restore OpenGL Settings
if (fog)
glEnable(GL_FOG);
else
glDisable(GL_FOG);
if (texture2D)
glEnable(GL_TEXTURE_2D);
else
glDisable(GL_TEXTURE_2D);
if (light)
glEnable(GL_LIGHTING);
else
glDisable(GL_LIGHTING);
}
void GPC_RenderTools::RenderText3D( int fontid,
const char* text,
int size,
int dpi,
float* color,
double* mat,
float aspect)
{
glPolygonMode(GL_FRONT_AND_BACK, GL_FILL); /* needed for texture fonts otherwise they render as wireframe */
if (GLEW_ARB_multitexture) {
for (int i=0; i<MAXTEX; i++) {
glActiveTextureARB(GL_TEXTURE0_ARB+i);
if (GLEW_ARB_texture_cube_map)
if (glIsEnabled(GL_TEXTURE_CUBE_MAP_ARB))
glDisable(GL_TEXTURE_CUBE_MAP_ARB);
if (glIsEnabled(GL_TEXTURE_2D))
glDisable(GL_TEXTURE_2D);
}
glActiveTextureARB(GL_TEXTURE0_ARB);
}
else {
if (GLEW_ARB_texture_cube_map)
if (glIsEnabled(GL_TEXTURE_CUBE_MAP_ARB))
glDisable(GL_TEXTURE_CUBE_MAP_ARB);
if (glIsEnabled(GL_TEXTURE_2D))
glDisable(GL_TEXTURE_2D);
}
/* the actual drawing */
glColor4fv(color);
/* multiply the text matrix by the object matrix */
BLF_enable(fontid, BLF_MATRIX|BLF_ASPECT);
BLF_matrix(fontid, mat);
/* aspect is the inverse scale that allows you to increase */
/* your resolution without sizing the final text size */
/* the bigger the size, the smaller the aspect */
BLF_aspect(fontid, aspect, aspect, aspect);
BLF_size(fontid, size, dpi);
BLF_position(fontid, 0, 0, 0);
BLF_draw(fontid, text, 65535);
BLF_disable(fontid, BLF_MATRIX|BLF_ASPECT);
glEnable(GL_DEPTH_TEST);
}
void GPC_RenderTools::RenderText2D(RAS_TEXT_RENDER_MODE mode,
const char* text,
int xco,
int yco,
int width,
int height)
{
/*
STR_String tmpstr(text);
char* s = tmpstr.Ptr(); */
// Save and change OpenGL settings
int texture2D;
glGetIntegerv(GL_TEXTURE_2D, (GLint*)&texture2D);
glDisable(GL_TEXTURE_2D);
int fog;
glGetIntegerv(GL_FOG, (GLint*)&fog);
glDisable(GL_FOG);
int light;
glGetIntegerv(GL_LIGHTING, (GLint*)&light);
glDisable(GL_LIGHTING);
glDisable(GL_DEPTH_TEST);
// Set up viewing settings
glMatrixMode(GL_PROJECTION);
glPushMatrix();
glLoadIdentity();
glOrtho(0, width, 0, height, -1, 1);
glMatrixMode(GL_MODELVIEW);
glPushMatrix();
glLoadIdentity();
// Actual drawing (draw black first if padded)
if (mode == RAS_IRenderTools::RAS_TEXT_PADDED)
{
glColor3ub(0, 0, 0);
BLF_draw_default(xco+1, height-yco-1, 0.f, text, 65536);
}
glColor3ub(255, 255, 255);
BLF_draw_default(xco, height-yco, 0.f, text, 65536);
// Restore view settings
glMatrixMode(GL_PROJECTION);
glPopMatrix();
glMatrixMode(GL_MODELVIEW);
glPopMatrix();
// Restore OpenGL Settings
if (fog)
glEnable(GL_FOG);
else
glDisable(GL_FOG);
if (texture2D)
glEnable(GL_TEXTURE_2D);
else
glDisable(GL_TEXTURE_2D);
if (light)
glEnable(GL_LIGHTING);
else
glDisable(GL_LIGHTING);
}
/* Render Text renders text into a (series of) polygon, using a texture font,
* Each character consists of one polygon (one quad or two triangles) */
void GPC_RenderTools::RenderText(
int mode,
RAS_IPolyMaterial* polymat,
float v1[3], float v2[3], float v3[3], float v4[3], int glattrib)
{
const STR_String &mytext = ((CValue *)m_clientobject)->GetPropertyText("Text");
const unsigned int flag = polymat->GetFlag();
struct MTFace* tface = 0;
unsigned int *col = 0;
if (flag & RAS_BLENDERMAT) {
KX_BlenderMaterial *bl_mat = static_cast<KX_BlenderMaterial*>(polymat);
tface = bl_mat->GetMTFace();
col = bl_mat->GetMCol();
} else {
KX_PolygonMaterial* blenderpoly = static_cast<KX_PolygonMaterial*>(polymat);
tface = blenderpoly->GetMTFace();
col = blenderpoly->GetMCol();
}
GPU_render_text(tface, mode, mytext, mytext.Length(), col, v1, v2, v3, v4, glattrib);
}
void GPC_RenderTools::PushMatrix()
{
glPushMatrix();
}
void GPC_RenderTools::PopMatrix()
{
glPopMatrix();
}
int GPC_RenderTools::applyLights(int objectlayer, const MT_Transform& viewmat)
{
// taken from blender source, incompatibility between Blender Object / GameObject
KX_Scene* kxscene = (KX_Scene*)m_auxilaryClientInfo;
float glviewmat[16];
unsigned int count;
std::vector<struct RAS_LightObject*>::iterator lit = m_lights.begin();
for (count=0; count<m_numgllights; count++)
glDisable((GLenum)(GL_LIGHT0+count));
viewmat.getValue(glviewmat);
glPushMatrix();
glLoadMatrixf(glviewmat);
for (lit = m_lights.begin(), count = 0; !(lit==m_lights.end()) && count < m_numgllights; ++lit)
{
RAS_LightObject* lightdata = (*lit);
KX_LightObject *kxlight = (KX_LightObject*)lightdata->m_light;
if (kxlight->ApplyLight(kxscene, objectlayer, count))
count++;
}
glPopMatrix();
return count;
}
void GPC_RenderTools::MotionBlur(RAS_IRasterizer* rasterizer)
{
int state = rasterizer->GetMotionBlurState();
float motionblurvalue;
if (state)
{
motionblurvalue = rasterizer->GetMotionBlurValue();
if (state==1)
{
//bugfix:load color buffer into accum buffer for the first time(state=1)
glAccum(GL_LOAD, 1.0);
rasterizer->SetMotionBlurState(2);
}
else if (motionblurvalue >= 0.0f && motionblurvalue <= 1.0f) {
glAccum(GL_MULT, motionblurvalue);
glAccum(GL_ACCUM, 1-motionblurvalue);
glAccum(GL_RETURN, 1.0);
glFlush();
}
}
}

View File

@@ -1,115 +0,0 @@
/*
* ***** BEGIN GPL LICENSE BLOCK *****
*
* This program is free software; you can redistribute it and/or
* modify it under the terms of the GNU General Public License
* as published by the Free Software Foundation; either version 2
* of the License, or (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software Foundation,
* Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
*
* The Original Code is Copyright (C) 2001-2002 by NaN Holding BV.
* All rights reserved.
*
* The Original Code is: all of this file.
*
* Contributor(s): none yet.
*
* ***** END GPL LICENSE BLOCK *****
*/
/** \file GPC_RenderTools.h
* \ingroup player
*/
#ifndef __GPC_RENDERTOOLS_H__
#define __GPC_RENDERTOOLS_H__
#ifdef WIN32
// don't show stl-warnings
#pragma warning (disable:4786)
#include <windows.h>
#endif /* WIN32 */
#include "RAS_IRenderTools.h"
struct KX_ClientObjectInfo;
class KX_RayCast;
/* BlenderRenderTools are a set of tools to apply 2D/3D graphics effects, which
* are not part of the (polygon) Rasterizer. Effects like 2D text, 3D (polygon)
* text, lighting.
*
* Most of this code is duplicated in KX_BlenderRenderTools, so this should be
* moved to some common location to avoid duplication. */
class GPC_RenderTools : public RAS_IRenderTools
{
int m_lastlightlayer;
bool m_lastlighting;
void *m_lastauxinfo;
static unsigned int m_numgllights;
// XXX BMF_Font* m_font;
public:
GPC_RenderTools();
virtual ~GPC_RenderTools();
void EndFrame(RAS_IRasterizer* rasty);
void BeginFrame(RAS_IRasterizer* rasty);
void EnableOpenGLLights(RAS_IRasterizer *rasty);
void DisableOpenGLLights();
void ProcessLighting(RAS_IRasterizer *rasty, bool uselights, const MT_Transform& viewmat);
void RenderBox2D(int xco,
int yco,
int width,
int height,
float percentage);
void RenderText3D(int fontid,
const char* text,
int size,
int dpi,
float* color,
double* mat,
float aspect);
/* \attention mode is ignored here */
void RenderText2D(RAS_TEXT_RENDER_MODE mode,
const char* text,
int xco,
int yco,
int width,
int height);
void RenderText(int mode,
class RAS_IPolyMaterial* polymat,
float v1[3],
float v2[3],
float v3[3],
float v4[3],
int glattrib);
void applyTransform(RAS_IRasterizer* rasty, double* oglmatrix, int objectdrawmode);
int applyLights(int objectlayer, const MT_Transform& viewmat);
void PushMatrix();
void PopMatrix();
bool RayHit(KX_ClientObjectInfo* client, KX_RayCast* result, void * const data);
bool NeedRayCast(KX_ClientObjectInfo* client) { return true; }
virtual void MotionBlur(RAS_IRasterizer* rasterizer);
virtual void SetClientObject(RAS_IRasterizer *rasty, void* obj);
};
#endif /* __GPC_RENDERTOOLS_H__ */

View File

@@ -86,7 +86,6 @@ extern "C"
#include "NG_LoopBackNetworkDeviceInterface.h"
#include "GPC_MouseDevice.h"
#include "GPC_RenderTools.h"
#include "GPG_Canvas.h"
#include "GPG_KeyboardDevice.h"
#include "GPG_System.h"
@@ -126,8 +125,7 @@ GPG_Application::GPG_Application(GHOST_ISystem* system)
m_kxsystem(0),
m_keyboard(0),
m_mouse(0),
m_canvas(0),
m_rendertools(0),
m_canvas(0),
m_rasterizer(0),
m_sceneconverter(0),
m_networkdevice(0),
@@ -591,10 +589,6 @@ bool GPG_Application::initEngine(GHOST_IWindow* window, const int stereoMode)
m_canvas->Init();
if (gm->flag & GAME_SHOW_MOUSE)
m_canvas->SetMouseState(RAS_ICanvas::MOUSE_NORMAL);
m_rendertools = new GPC_RenderTools();
if (!m_rendertools)
goto initFailed;
//Don't use displaylists with VBOs
//If auto starts using VBOs, make sure to check for that here
@@ -639,7 +633,6 @@ bool GPG_Application::initEngine(GHOST_IWindow* window, const int stereoMode)
m_ketsjiengine->SetMouseDevice(m_mouse);
m_ketsjiengine->SetNetworkDevice(m_networkdevice);
m_ketsjiengine->SetCanvas(m_canvas);
m_ketsjiengine->SetRenderTools(m_rendertools);
m_ketsjiengine->SetRasterizer(m_rasterizer);
KX_KetsjiEngine::SetExitKey(ConvertKeyCode(gm->exitkey));
@@ -667,10 +660,8 @@ initFailed:
delete m_mouse;
delete m_keyboard;
delete m_rasterizer;
delete m_rendertools;
delete m_canvas;
m_canvas = NULL;
m_rendertools = NULL;
m_rasterizer = NULL;
m_keyboard = NULL;
m_mouse = NULL;
@@ -752,7 +743,7 @@ bool GPG_Application::startEngine(void)
#endif
m_sceneconverter->ConvertScene(
startscene,
m_rendertools,
m_rasterizer,
m_canvas);
m_ketsjiengine->AddScene(startscene);
@@ -870,11 +861,6 @@ void GPG_Application::exitEngine()
delete m_rasterizer;
m_rasterizer = 0;
}
if (m_rendertools)
{
delete m_rendertools;
m_rendertools = 0;
}
if (m_canvas)
{
delete m_canvas;

View File

@@ -48,7 +48,6 @@ class GHOST_ISystem;
class GHOST_ITimerTask;
class GHOST_IWindow;
class GPC_MouseDevice;
class GPC_RenderTools;
class GPG_Canvas;
class GPG_KeyboardDevice;
class GPG_System;
@@ -151,8 +150,6 @@ protected:
GPC_MouseDevice* m_mouse;
/** The game engine's canvas abstraction. */
GPG_Canvas* m_canvas;
/** The game engine's platform dependent render tools. */
GPC_RenderTools* m_rendertools;
/** the rasterizer */
RAS_IRasterizer* m_rasterizer;
/** Converts Blender data files. */

View File

@@ -48,8 +48,6 @@ KX_Dome::KX_Dome (
RAS_ICanvas* canvas,
/// rasterizer
RAS_IRasterizer* rasterizer,
/// render tools
RAS_IRenderTools* rendertools,
/// engine
KX_KetsjiEngine* engine,
@@ -71,7 +69,6 @@ KX_Dome::KX_Dome (
m_tilt(tilt),
m_canvas(canvas),
m_rasterizer(rasterizer),
m_rendertools(rendertools),
m_engine(engine)
{
warp.usemesh = false;
@@ -2047,6 +2044,6 @@ void KX_Dome::RenderDomeFrame(KX_Scene* scene, KX_Camera* cam, int i)
cam->NodeUpdateGS(0.f);
scene->CalculateVisibleMeshes(m_rasterizer,cam);
scene->RenderBuckets(camtrans, m_rasterizer, m_rendertools);
scene->RenderBuckets(camtrans, m_rasterizer);
}

View File

@@ -36,7 +36,6 @@
#include "DNA_screen_types.h"
#include "RAS_ICanvas.h"
#include "RAS_IRasterizer.h"
#include "RAS_IRenderTools.h"
#include "KX_KetsjiEngine.h"
#include "GL/glew.h"
@@ -62,8 +61,6 @@ public:
KX_Dome (RAS_ICanvas* m_canvas,
/// rasterizer
RAS_IRasterizer* m_rasterizer,
/// render tools
RAS_IRenderTools* m_rendertools,
/// engine
KX_KetsjiEngine* m_engine,

View File

@@ -31,10 +31,12 @@
#include "KX_FontObject.h"
#include "DNA_curve_types.h"
#include "DNA_vfont_types.h"
#include "KX_Scene.h"
#include "KX_PythonInit.h"
#include "BLI_math.h"
#include "StringValue.h"
#include "RAS_IRasterizer.h"
/* paths needed for font load */
#include "BLI_blenlib.h"
@@ -75,14 +77,14 @@ static std::vector<STR_String> split_string(STR_String str)
KX_FontObject::KX_FontObject(void* sgReplicationInfo,
SG_Callbacks callbacks,
RAS_IRenderTools* rendertools,
RAS_IRasterizer* rasterizer,
Object *ob,
bool do_color_management):
KX_GameObject(sgReplicationInfo, callbacks),
m_object(ob),
m_dpi(72),
m_resolution(1.f),
m_rendertools(rendertools),
m_rasterizer(rasterizer),
m_do_color_management(do_color_management)
{
Curve *text = static_cast<Curve *> (ob->data);
@@ -212,7 +214,7 @@ void KX_FontObject::DrawText()
mat[13] -= spacing[1];
mat[14] -= spacing[2];
}
m_rendertools->RenderText3D(m_fontid, m_text[i], int(size), m_dpi, color, mat, aspect);
m_rasterizer->RenderText3D(m_fontid, m_text[i], int(size), m_dpi, color, mat, aspect);
}
}

View File

@@ -32,8 +32,6 @@
#ifndef __KX_FONTOBJECT_H__
#define __KX_FONTOBJECT_H__
#include "KX_GameObject.h"
#include "DNA_vfont_types.h"
#include "RAS_IRenderTools.h"
class KX_FontObject : public KX_GameObject
{
@@ -41,7 +39,7 @@ public:
Py_Header
KX_FontObject(void* sgReplicationInfo,
SG_Callbacks callbacks,
RAS_IRenderTools* rendertools,
RAS_IRasterizer* rasterizer,
Object *ob,
bool do_color_management);
@@ -68,7 +66,7 @@ protected:
float m_line_spacing;
MT_Vector3 m_offset;
class RAS_IRenderTools* m_rendertools; //needed for drawing routine
class RAS_IRasterizer* m_rasterizer; //needed for drawing routine
bool m_do_color_management;

View File

@@ -56,7 +56,7 @@ public:
*/
virtual void ConvertScene(
class KX_Scene* destinationscene,
class RAS_IRenderTools* rendertools,
class RAS_IRasterizer* rendertools,
class RAS_ICanvas* canvas,
bool libloading=false)=0;

View File

@@ -48,7 +48,6 @@
#include "RAS_BucketManager.h"
#include "RAS_Rect.h"
#include "RAS_IRasterizer.h"
#include "RAS_IRenderTools.h"
#include "RAS_ICanvas.h"
#include "MT_Vector3.h"
#include "MT_Transform.h"
@@ -121,7 +120,6 @@ KX_KetsjiEngine::KX_KetsjiEngine(KX_ISystem* system)
: m_canvas(NULL),
m_rasterizer(NULL),
m_kxsystem(system),
m_rendertools(NULL),
m_sceneconverter(NULL),
m_networkdevice(NULL),
#ifdef WITH_PYTHON
@@ -237,14 +235,6 @@ void KX_KetsjiEngine::SetCanvas(RAS_ICanvas* canvas)
void KX_KetsjiEngine::SetRenderTools(RAS_IRenderTools* rendertools)
{
MT_assert(rendertools);
m_rendertools = rendertools;
}
void KX_KetsjiEngine::SetRasterizer(RAS_IRasterizer* rasterizer)
{
MT_assert(rasterizer);
@@ -278,7 +268,7 @@ void KX_KetsjiEngine::SetSceneConverter(KX_ISceneConverter* sceneconverter)
void KX_KetsjiEngine::InitDome(short res, short mode, short angle, float resbuf, short tilt, struct Text* text)
{
m_dome = new KX_Dome(m_canvas, m_rasterizer, m_rendertools,this, res, mode, angle, resbuf, tilt, text);
m_dome = new KX_Dome(m_canvas, m_rasterizer,this, res, mode, angle, resbuf, tilt, text);
m_usedome = true;
}
@@ -319,7 +309,6 @@ void KX_KetsjiEngine::RenderDome()
scene = *sceneit;
KX_Camera* cam = scene->GetActiveCamera();
m_rendertools->BeginFrame(m_rasterizer);
// pass the scene's worldsettings to the rasterizer
SetWorldSettings(scene->GetWorldInfo());
@@ -333,7 +322,7 @@ void KX_KetsjiEngine::RenderDome()
if (scene->IsClearingZBuffer())
m_rasterizer->ClearDepthBuffer();
m_rendertools->SetAuxilaryClientInfo(scene);
m_rasterizer->SetAuxilaryClientInfo(scene);
// do the rendering
m_dome->RenderDomeFrame(scene,cam, i);
@@ -351,7 +340,7 @@ void KX_KetsjiEngine::RenderDome()
if (scene->IsClearingZBuffer())
m_rasterizer->ClearDepthBuffer();
m_rendertools->SetAuxilaryClientInfo(scene);
m_rasterizer->SetAuxilaryClientInfo(scene);
// do the rendering
m_dome->RenderDomeFrame(scene, (*it),i);
@@ -362,7 +351,7 @@ void KX_KetsjiEngine::RenderDome()
it++;
}
// Part of PostRenderScene()
m_rendertools->MotionBlur(m_rasterizer);
m_rasterizer->MotionBlur();
scene->Render2DFilters(m_canvas);
// no RunDrawingCallBacks
// no FlushDebugLines
@@ -499,7 +488,6 @@ bool KX_KetsjiEngine::BeginFrame()
ClearFrame();
m_rasterizer->BeginFrame(m_drawingmode , m_kxsystem->GetTimeInSeconds());
m_rendertools->BeginFrame(m_rasterizer);
return true;
}
@@ -510,7 +498,7 @@ bool KX_KetsjiEngine::BeginFrame()
void KX_KetsjiEngine::EndFrame()
{
m_rendertools->MotionBlur(m_rasterizer);
m_rasterizer->MotionBlur();
// Show profiling info
m_logger->StartLog(tc_overhead, m_kxsystem->GetTimeInSeconds(), true);
@@ -546,9 +534,6 @@ void KX_KetsjiEngine::EndFrame()
m_logger->StartLog(tc_latency, m_kxsystem->GetTimeInSeconds(), true);
m_rasterizer->SwapBuffers();
m_logger->StartLog(tc_rasterizer, m_kxsystem->GetTimeInSeconds(), true);
m_rendertools->EndFrame(m_rasterizer);
m_canvas->EndDraw();
}
@@ -905,7 +890,7 @@ void KX_KetsjiEngine::Render()
if (scene->IsClearingZBuffer())
m_rasterizer->ClearDepthBuffer();
m_rendertools->SetAuxilaryClientInfo(scene);
m_rasterizer->SetAuxilaryClientInfo(scene);
// do the rendering
RenderFrame(scene, cam);
@@ -921,7 +906,7 @@ void KX_KetsjiEngine::Render()
if (scene->IsClearingZBuffer())
m_rasterizer->ClearDepthBuffer();
m_rendertools->SetAuxilaryClientInfo(scene);
m_rasterizer->SetAuxilaryClientInfo(scene);
// do the rendering
RenderFrame(scene, (*it));
@@ -954,7 +939,7 @@ void KX_KetsjiEngine::Render()
m_rasterizer->ClearDepthBuffer();
//pass the scene, for picking and raycasting (shadows)
m_rendertools->SetAuxilaryClientInfo(scene);
m_rasterizer->SetAuxilaryClientInfo(scene);
// do the rendering
//RenderFrame(scene);
@@ -970,7 +955,7 @@ void KX_KetsjiEngine::Render()
if (scene->IsClearingZBuffer())
m_rasterizer->ClearDepthBuffer();
m_rendertools->SetAuxilaryClientInfo(scene);
m_rasterizer->SetAuxilaryClientInfo(scene);
// do the rendering
RenderFrame(scene, (*it));
@@ -1172,7 +1157,7 @@ void KX_KetsjiEngine::RenderShadowBuffers(KX_Scene *scene)
CListValue *lightlist = scene->GetLightList();
int i, drawmode;
m_rendertools->SetAuxilaryClientInfo(scene);
m_rasterizer->SetAuxilaryClientInfo(scene);
for (i=0; i<lightlist->GetCount(); i++) {
KX_GameObject *gameobj = (KX_GameObject*)lightlist->GetValue(i);
@@ -1202,7 +1187,7 @@ void KX_KetsjiEngine::RenderShadowBuffers(KX_Scene *scene)
/* render */
m_rasterizer->ClearDepthBuffer();
m_rasterizer->ClearColorBuffer();
scene->RenderBuckets(camtrans, m_rasterizer, m_rendertools);
scene->RenderBuckets(camtrans, m_rasterizer);
/* unbind framebuffer object, restore drawmode, free camera */
light->UnbindShadowBuffer(m_rasterizer);
@@ -1338,7 +1323,7 @@ void KX_KetsjiEngine::RenderFrame(KX_Scene* scene, KX_Camera* cam)
scene->RunDrawingCallbacks(scene->GetPreDrawCB());
#endif
scene->RenderBuckets(camtrans, m_rasterizer, m_rendertools);
scene->RenderBuckets(camtrans, m_rasterizer);
//render all the font objects for this scene
scene->RenderFonts();
@@ -1475,7 +1460,7 @@ void KX_KetsjiEngine::RenderDebugProperties()
if (m_show_framerate || m_show_profile) {
/* Title for profiling("Profile") */
m_rendertools->RenderText2D(RAS_IRenderTools::RAS_TEXT_PADDED,
m_rasterizer->RenderText2D(RAS_IRasterizer::RAS_TEXT_PADDED,
"Profile",
xcoord + const_xindent + title_xmargin, // Adds the constant x indent (0 for now) to the title x margin
ycoord,
@@ -1490,7 +1475,7 @@ void KX_KetsjiEngine::RenderDebugProperties()
/* Framerate display */
if (m_show_framerate) {
m_rendertools->RenderText2D(RAS_IRenderTools::RAS_TEXT_PADDED,
m_rasterizer->RenderText2D(RAS_IRasterizer::RAS_TEXT_PADDED,
"Frametime :",
xcoord + const_xindent,
ycoord,
@@ -1498,7 +1483,7 @@ void KX_KetsjiEngine::RenderDebugProperties()
m_canvas->GetHeight() /* RdV, TODO ?? */);
debugtxt.Format("%5.1fms (%.1ffps)", tottime * 1000.f, 1.0/tottime);
m_rendertools->RenderText2D(RAS_IRenderTools::RAS_TEXT_PADDED,
m_rasterizer->RenderText2D(RAS_IRasterizer::RAS_TEXT_PADDED,
debugtxt.ReadPtr(),
xcoord + const_xindent + profile_indent,
ycoord,
@@ -1511,7 +1496,7 @@ void KX_KetsjiEngine::RenderDebugProperties()
/* Profile display */
if (m_show_profile) {
for (int j = tc_first; j < tc_numCategories; j++) {
m_rendertools->RenderText2D(RAS_IRenderTools::RAS_TEXT_PADDED,
m_rasterizer->RenderText2D(RAS_IRasterizer::RAS_TEXT_PADDED,
m_profileLabels[j],
xcoord + const_xindent,
ycoord,
@@ -1521,13 +1506,13 @@ void KX_KetsjiEngine::RenderDebugProperties()
double time = m_logger->GetAverage((KX_TimeCategory)j);
debugtxt.Format("%5.2fms | %d%%", time*1000.f, (int)(time/tottime * 100.f));
m_rendertools->RenderText2D(RAS_IRenderTools::RAS_TEXT_PADDED,
m_rasterizer->RenderText2D(RAS_IRasterizer::RAS_TEXT_PADDED,
debugtxt.ReadPtr(),
xcoord + const_xindent + profile_indent, ycoord,
m_canvas->GetWidth(),
m_canvas->GetHeight());
m_rendertools->RenderBox2D(xcoord + (int)(2.2 * profile_indent), ycoord, m_canvas->GetWidth(), m_canvas->GetHeight(), time/tottime);
m_rasterizer->RenderBox2D(xcoord + (int)(2.2 * profile_indent), ycoord, m_canvas->GetWidth(), m_canvas->GetHeight(), time/tottime);
ycoord += const_ysize;
}
}
@@ -1538,7 +1523,7 @@ void KX_KetsjiEngine::RenderDebugProperties()
if (m_show_debug_properties) {
/* Title for debugging("Debug properties") */
m_rendertools->RenderText2D(RAS_IRenderTools::RAS_TEXT_PADDED,
m_rasterizer->RenderText2D(RAS_IRasterizer::RAS_TEXT_PADDED,
"Debug Properties",
xcoord + const_xindent + title_xmargin, // Adds the constant x indent (0 for now) to the title x margin
ycoord,
@@ -1584,7 +1569,7 @@ void KX_KetsjiEngine::RenderDebugProperties()
first = false;
}
}
m_rendertools->RenderText2D(RAS_IRenderTools::RAS_TEXT_PADDED,
m_rasterizer->RenderText2D(RAS_IRasterizer::RAS_TEXT_PADDED,
debugtxt.ReadPtr(),
xcoord + const_xindent,
ycoord,
@@ -1597,7 +1582,7 @@ void KX_KetsjiEngine::RenderDebugProperties()
if (propval) {
STR_String text = propval->GetText();
debugtxt = objname + ": '" + propname + "' = " + text;
m_rendertools->RenderText2D(RAS_IRenderTools::RAS_TEXT_PADDED,
m_rasterizer->RenderText2D(RAS_IRasterizer::RAS_TEXT_PADDED,
debugtxt.ReadPtr(),
xcoord + const_xindent,
ycoord,
@@ -1704,7 +1689,7 @@ KX_Scene* KX_KetsjiEngine::CreateScene(Scene *scene, bool libloading)
m_canvas);
m_sceneconverter->ConvertScene(tmpscene,
m_rendertools,
m_rasterizer,
m_canvas,
libloading);

View File

@@ -74,7 +74,6 @@ private:
class RAS_ICanvas* m_canvas; // 2D Canvas (2D Rendering Device Context)
class RAS_IRasterizer* m_rasterizer; // 3D Rasterizer (3D Rendering)
class KX_ISystem* m_kxsystem;
class RAS_IRenderTools* m_rendertools;
class KX_ISceneConverter* m_sceneconverter;
class NG_NetworkDeviceInterface* m_networkdevice;
#ifdef WITH_PYTHON
@@ -217,7 +216,6 @@ public:
void SetMouseDevice(SCA_IInputDevice* mousedevice);
void SetNetworkDevice(NG_NetworkDeviceInterface* networkdevice);
void SetCanvas(RAS_ICanvas* canvas);
void SetRenderTools(RAS_IRenderTools* rendertools);
void SetRasterizer(RAS_IRasterizer* rasterizer);
#ifdef WITH_PYTHON
void SetPyNamespace(PyObject *pythondictionary);
@@ -229,7 +227,6 @@ public:
RAS_IRasterizer* GetRasterizer() { return m_rasterizer; }
RAS_ICanvas* GetCanvas() { return m_canvas; }
RAS_IRenderTools* GetRenderTools() { return m_rendertools; }
SCA_IInputDevice* GetKeyboardDevice() { return m_keyboarddevice; }
SCA_IInputDevice* GetMouseDevice() { return m_mousedevice; }

View File

@@ -40,7 +40,6 @@
#include "KX_Light.h"
#include "KX_Camera.h"
#include "RAS_IRasterizer.h"
#include "RAS_IRenderTools.h"
#include "KX_PyMath.h"
@@ -53,16 +52,16 @@
#include "MEM_guardedalloc.h"
KX_LightObject::KX_LightObject(void* sgReplicationInfo,SG_Callbacks callbacks,
class RAS_IRenderTools* rendertools,
RAS_IRasterizer* rasterizer,
const RAS_LightObject& lightobj,
bool glsl)
: KX_GameObject(sgReplicationInfo,callbacks),
m_rendertools(rendertools)
m_rasterizer(rasterizer)
{
m_lightobj = lightobj;
m_lightobj.m_scene = sgReplicationInfo;
m_lightobj.m_light = this;
m_rendertools->AddLight(&m_lightobj);
m_rasterizer->AddLight(&m_lightobj);
m_glsl = glsl;
m_blenderscene = ((KX_Scene*)sgReplicationInfo)->GetBlenderScene();
m_base = NULL;
@@ -81,7 +80,7 @@ KX_LightObject::~KX_LightObject()
GPU_lamp_update_spot(lamp, la->spotsize, la->spotblend);
}
m_rendertools->RemoveLight(&m_lightobj);
m_rasterizer->RemoveLight(&m_lightobj);
if (m_base) {
BKE_scene_base_unlink(m_blenderscene, m_base);
@@ -98,7 +97,7 @@ CValue* KX_LightObject::GetReplica()
replica->ProcessReplica();
replica->m_lightobj.m_light = replica;
m_rendertools->AddLight(&replica->m_lightobj);
m_rasterizer->AddLight(&replica->m_lightobj);
return replica;
}

View File

@@ -38,9 +38,9 @@
struct GPULamp;
struct Scene;
struct Base;
struct RAS_LightObject;
class KX_Camera;
class RAS_IRasterizer;
class RAS_IRenderTools;
class MT_Transform;
class KX_LightObject : public KX_GameObject
@@ -48,13 +48,13 @@ class KX_LightObject : public KX_GameObject
Py_Header
protected:
RAS_LightObject m_lightobj;
class RAS_IRenderTools* m_rendertools; //needed for registering and replication of lightobj
class RAS_IRasterizer* m_rasterizer; //needed for registering and replication of lightobj
bool m_glsl;
Scene* m_blenderscene;
Base* m_base;
public:
KX_LightObject(void* sgReplicationInfo,SG_Callbacks callbacks,class RAS_IRenderTools* rendertools,const struct RAS_LightObject& lightobj, bool glsl);
KX_LightObject(void* sgReplicationInfo,SG_Callbacks callbacks,RAS_IRasterizer* rasterizer,const RAS_LightObject& lightobj, bool glsl);
virtual ~KX_LightObject();
virtual CValue* GetReplica();
RAS_LightObject* GetLightData() { return &m_lightobj;}
@@ -66,8 +66,8 @@ public:
struct GPULamp *GetGPULamp();
bool HasShadowBuffer();
int GetShadowLayer();
void BindShadowBuffer(class RAS_IRasterizer *ras, class RAS_ICanvas *canvas, class KX_Camera *cam, class MT_Transform& camtrans);
void UnbindShadowBuffer(class RAS_IRasterizer *ras);
void BindShadowBuffer(RAS_IRasterizer *ras, class RAS_ICanvas *canvas, class KX_Camera *cam, class MT_Transform& camtrans);
void UnbindShadowBuffer(RAS_IRasterizer *ras);
struct Image *GetTextureImage(short texslot);
void Update();

View File

@@ -1678,10 +1678,9 @@ RAS_MaterialBucket* KX_Scene::FindBucket(class RAS_IPolyMaterial* polymat, bool
void KX_Scene::RenderBuckets(const MT_Transform & cameratransform,
class RAS_IRasterizer* rasty,
class RAS_IRenderTools* rendertools)
class RAS_IRasterizer* rasty)
{
m_bucketmanager->Renderbuckets(cameratransform,rasty,rendertools);
m_bucketmanager->Renderbuckets(cameratransform,rasty);
KX_BlenderMaterial::EndFrame();
}

View File

@@ -309,8 +309,7 @@ public:
RAS_BucketManager* GetBucketManager();
RAS_MaterialBucket* FindBucket(RAS_IPolyMaterial* polymat, bool &bucketCreated);
void RenderBuckets(const MT_Transform& cameratransform,
RAS_IRasterizer* rasty,
RAS_IRenderTools* rendertools);
RAS_IRasterizer* rasty);
/**
* Update all transforms according to the scenegraph.

View File

@@ -47,7 +47,6 @@ set(SRC
RAS_BucketManager.cpp
RAS_FramingManager.cpp
RAS_IPolygonMaterial.cpp
RAS_IRenderTools.cpp
RAS_MaterialBucket.cpp
RAS_MeshObject.cpp
RAS_Polygon.cpp
@@ -62,7 +61,6 @@ set(SRC
RAS_ICanvas.h
RAS_IPolygonMaterial.h
RAS_IRasterizer.h
RAS_IRenderTools.h
RAS_LightObject.h
RAS_MaterialBucket.h
RAS_MeshObject.h

View File

@@ -38,7 +38,6 @@
#include "STR_HashedString.h"
#include "RAS_MeshObject.h"
#include "RAS_IRasterizer.h"
#include "RAS_IRenderTools.h"
#include "RAS_BucketManager.h"
@@ -139,8 +138,7 @@ void RAS_BucketManager::OrderBuckets(const MT_Transform& cameratrans, BucketList
sort(slots.begin(), slots.end(), fronttoback());
}
void RAS_BucketManager::RenderAlphaBuckets(
const MT_Transform& cameratrans, RAS_IRasterizer* rasty, RAS_IRenderTools* rendertools)
void RAS_BucketManager::RenderAlphaBuckets(const MT_Transform& cameratrans, RAS_IRasterizer* rasty)
{
vector<sortedmeshslot> slots;
vector<sortedmeshslot>::iterator sit;
@@ -154,10 +152,10 @@ void RAS_BucketManager::RenderAlphaBuckets(
OrderBuckets(cameratrans, m_AlphaBuckets, slots, true);
for (sit=slots.begin(); sit!=slots.end(); ++sit) {
rendertools->SetClientObject(rasty, sit->m_ms->m_clientObj);
rasty->SetClientObject(sit->m_ms->m_clientObj);
while (sit->m_bucket->ActivateMaterial(cameratrans, rasty, rendertools))
sit->m_bucket->RenderMeshSlot(cameratrans, rasty, rendertools, *(sit->m_ms));
while (sit->m_bucket->ActivateMaterial(cameratrans, rasty))
sit->m_bucket->RenderMeshSlot(cameratrans, rasty, *(sit->m_ms));
// make this mesh slot culled automatically for next frame
// it will be culled out by frustrum culling
@@ -167,8 +165,7 @@ void RAS_BucketManager::RenderAlphaBuckets(
rasty->SetDepthMask(RAS_IRasterizer::KX_DEPTHMASK_ENABLED);
}
void RAS_BucketManager::RenderSolidBuckets(
const MT_Transform& cameratrans, RAS_IRasterizer* rasty, RAS_IRenderTools* rendertools)
void RAS_BucketManager::RenderSolidBuckets(const MT_Transform& cameratrans, RAS_IRasterizer* rasty)
{
BucketList::iterator bit;
@@ -180,9 +177,9 @@ void RAS_BucketManager::RenderSolidBuckets(
RAS_MeshSlot* ms;
// remove the mesh slot form the list, it culls them automatically for next frame
while ((ms = bucket->GetNextActiveMeshSlot())) {
rendertools->SetClientObject(rasty, ms->m_clientObj);
while (bucket->ActivateMaterial(cameratrans, rasty, rendertools))
bucket->RenderMeshSlot(cameratrans, rasty, rendertools, *ms);
rasty->SetClientObject(ms->m_clientObj);
while (bucket->ActivateMaterial(cameratrans, rasty))
bucket->RenderMeshSlot(cameratrans, rasty, *ms);
// make this mesh slot culled automatically for next frame
// it will be culled out by frustrum culling
@@ -194,10 +191,10 @@ void RAS_BucketManager::RenderSolidBuckets(
if (mit->IsCulled())
continue;
rendertools->SetClientObject(rasty, mit->m_clientObj);
rasty->SetClientObject(rasty, mit->m_clientObj);
while ((*bit)->ActivateMaterial(cameratrans, rasty, rendertools))
(*bit)->RenderMeshSlot(cameratrans, rasty, rendertools, *mit);
while ((*bit)->ActivateMaterial(cameratrans, rasty))
(*bit)->RenderMeshSlot(cameratrans, rasty, *mit);
// make this mesh slot culled automatically for next frame
// it will be culled out by frustrum culling
@@ -218,20 +215,19 @@ void RAS_BucketManager::RenderSolidBuckets(
for (sit=slots.begin(); sit!=slots.end(); ++sit) {
rendertools->SetClientObject(rasty, sit->m_ms->m_clientObj);
while (sit->m_bucket->ActivateMaterial(cameratrans, rasty, rendertools))
sit->m_bucket->RenderMeshSlot(cameratrans, rasty, rendertools, *(sit->m_ms));
while (sit->m_bucket->ActivateMaterial(cameratrans, rasty))
sit->m_bucket->RenderMeshSlot(cameratrans, rasty, *(sit->m_ms));
}
#endif
}
void RAS_BucketManager::Renderbuckets(
const MT_Transform& cameratrans, RAS_IRasterizer* rasty, RAS_IRenderTools* rendertools)
void RAS_BucketManager::Renderbuckets(const MT_Transform& cameratrans, RAS_IRasterizer* rasty)
{
/* beginning each frame, clear (texture/material) caching information */
rasty->ClearCachingInfo();
RenderSolidBuckets(cameratrans, rasty, rendertools);
RenderAlphaBuckets(cameratrans, rasty, rendertools);
RenderSolidBuckets(cameratrans, rasty);
RenderAlphaBuckets(cameratrans, rasty);
/* All meshes should be up to date now */
/* Don't do this while processing buckets because some meshes are split between buckets */
@@ -259,7 +255,7 @@ void RAS_BucketManager::Renderbuckets(
}
rendertools->SetClientObject(rasty, NULL);
rasty->SetClientObject(NULL);
}
RAS_MaterialBucket *RAS_BucketManager::FindBucket(RAS_IPolyMaterial *material, bool &bucketCreated)

View File

@@ -51,8 +51,7 @@ public:
RAS_BucketManager();
virtual ~RAS_BucketManager();
void Renderbuckets(const MT_Transform & cameratrans,
RAS_IRasterizer* rasty, RAS_IRenderTools* rendertools);
void Renderbuckets(const MT_Transform & cameratrans, RAS_IRasterizer* rasty);
RAS_MaterialBucket* FindBucket(RAS_IPolyMaterial *material, bool &bucketCreated);
void OptimizeBuckets(MT_Scalar distance);
@@ -78,10 +77,10 @@ public:
private:
void OrderBuckets(const MT_Transform& cameratrans, BucketList& buckets, vector<sortedmeshslot>& slots, bool alpha);
void RenderSolidBuckets(const MT_Transform& cameratrans,
RAS_IRasterizer* rasty, RAS_IRenderTools* rendertools);
void RenderAlphaBuckets(const MT_Transform& cameratrans,
RAS_IRasterizer* rasty, RAS_IRenderTools* rendertools);
void RenderSolidBuckets(const MT_Transform& cameratrans,
RAS_IRasterizer* rasty);
void RenderAlphaBuckets(const MT_Transform& cameratrans,
RAS_IRasterizer* rasty);
#ifdef WITH_CXX_GUARDEDALLOC

View File

@@ -65,6 +65,13 @@ typedef vector< KX_IndexArray* > vecIndexArrays;
class RAS_IRasterizer
{
public:
enum RAS_TEXT_RENDER_MODE {
RAS_TEXT_RENDER_NODEF = 0,
RAS_TEXT_NORMAL,
RAS_TEXT_PADDED,
RAS_TEXT_MAX
};
RAS_IRasterizer(RAS_ICanvas* canv) {};
virtual ~RAS_IRasterizer() {};
@@ -247,11 +254,9 @@ public:
/**
* IndexPrimitives_3DText will render text into the polygons.
* The text to be rendered is from \param rendertools client object's text property.
*/
virtual void IndexPrimitives_3DText(class RAS_MeshSlot& ms,
class RAS_IPolyMaterial* polymat,
class RAS_IRenderTools* rendertools)=0;
class RAS_IPolyMaterial* polymat)=0;
virtual void SetProjectionMatrix(MT_CmMatrix4x4 & mat)=0;
/* This one should become our final version, methinks. */
@@ -434,6 +439,88 @@ public:
virtual void SetUsingOverrideShader(bool val)=0;
virtual bool GetUsingOverrideShader()=0;
/**
* Render Tools
*/
virtual void applyTransform(double* oglmatrix, int drawingmode)=0;
/**
* Renders 2D boxes.
* \param xco Position on the screen (origin in lower left corner).
* \param yco Position on the screen (origin in lower left corner).
* \param width Width of the canvas to draw to.
* \param height Height of the canvas to draw to.
* \param percentage Percentage of bar.
*/
virtual void RenderBox2D(int xco,
int yco,
int width,
int height,
float percentage) = 0;
/**
* Renders 3D text string using BFL.
* \param fontid The id of the font.
* \param text The string to render.
* \param size The size of the text.
* \param dpi The resolution of the text.
* \param color The color of the object.
* \param mat The Matrix of the text object.
* \param aspect A scaling factor to compensate for the size.
*/
virtual void RenderText3D(int fontid,
const char* text,
int size,
int dpi,
float* color,
double* mat,
float aspect
) = 0;
/**
* Renders 2D text string.
* \param mode The type of text
* \param text The string to render.
* \param xco Position on the screen (origin in lower left corner).
* \param yco Position on the screen (origin in lower left corner).
* \param width Width of the canvas to draw to.
* \param height Height of the canvas to draw to.
*/
virtual void RenderText2D(RAS_TEXT_RENDER_MODE mode,
const char* text,
int xco,
int yco,
int width,
int height
) = 0;
// 3d text, mapped on polygon
virtual void RenderText(int mode,
RAS_IPolyMaterial* polymat,
float v1[3],
float v2[3],
float v3[3],
float v4[3],
int glattrib
)=0;
virtual void ProcessLighting(bool uselights, const MT_Transform& trans)=0;
virtual void PushMatrix()=0;
virtual void PopMatrix()=0;
virtual void AddLight(struct RAS_LightObject* lightobject)=0;
virtual void RemoveLight(struct RAS_LightObject* lightobject)=0;
virtual void MotionBlur()=0;
virtual void SetClientObject(void* obj)=0;
virtual void SetAuxilaryClientInfo(void* inf)=0;
#ifdef WITH_CXX_GUARDEDALLOC
MEM_CXX_CLASS_ALLOC_FUNCS("GE:RAS_IRasterizer")
#endif

View File

@@ -1,59 +0,0 @@
/*
* ***** BEGIN GPL LICENSE BLOCK *****
*
* This program is free software; you can redistribute it and/or
* modify it under the terms of the GNU General Public License
* as published by the Free Software Foundation; either version 2
* of the License, or (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software Foundation,
* Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
*
* The Original Code is Copyright (C) 2001-2002 by NaN Holding BV.
* All rights reserved.
*
* The Original Code is: all of this file.
*
* Contributor(s): none yet.
*
* ***** END GPL LICENSE BLOCK *****
*/
/** \file gameengine/Rasterizer/RAS_IRenderTools.cpp
* \ingroup bgerast
*/
#include "RAS_IRenderTools.h"
void RAS_IRenderTools::SetClientObject(RAS_IRasterizer* rasty, void *obj)
{
if (m_clientobject != obj)
m_clientobject = obj;
}
void RAS_IRenderTools::SetAuxilaryClientInfo(void* inf)
{
m_auxilaryClientInfo = inf;
}
void RAS_IRenderTools::AddLight(struct RAS_LightObject* lightobject)
{
m_lights.push_back(lightobject);
}
void RAS_IRenderTools::RemoveLight(struct RAS_LightObject* lightobject)
{
std::vector<struct RAS_LightObject*>::iterator lit =
std::find(m_lights.begin(),m_lights.end(),lightobject);
if (!(lit==m_lights.end()))
m_lights.erase(lit);
}

View File

@@ -1,227 +0,0 @@
/*
* ***** BEGIN GPL LICENSE BLOCK *****
*
* This program is free software; you can redistribute it and/or
* modify it under the terms of the GNU General Public License
* as published by the Free Software Foundation; either version 2
* of the License, or (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software Foundation,
* Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
*
* The Original Code is Copyright (C) 2001-2002 by NaN Holding BV.
* All rights reserved.
*
* The Original Code is: all of this file.
*
* Contributor(s): none yet.
*
* ***** END GPL LICENSE BLOCK *****
*/
/** \file RAS_IRenderTools.h
* \ingroup bgerast
*/
#ifndef __RAS_IRENDERTOOLS_H__
#define __RAS_IRENDERTOOLS_H__
#include "MT_Transform.h"
#include "RAS_IRasterizer.h"
#include "RAS_2DFilterManager.h"
#include <vector>
#include <algorithm>
#ifdef WITH_CXX_GUARDEDALLOC
#include "MEM_guardedalloc.h"
#endif
class RAS_IPolyMaterial;
struct RAS_LightObject;
class RAS_IRenderTools
{
protected:
void* m_clientobject;
void* m_auxilaryClientInfo;
std::vector<struct RAS_LightObject*> m_lights;
RAS_2DFilterManager m_filtermanager;
public:
enum RAS_TEXT_RENDER_MODE {
RAS_TEXT_RENDER_NODEF = 0,
RAS_TEXT_NORMAL,
RAS_TEXT_PADDED,
RAS_TEXT_MAX
};
RAS_IRenderTools(
) :
m_clientobject(NULL)
{
};
virtual
~RAS_IRenderTools(
) {};
virtual
void
BeginFrame(
RAS_IRasterizer* rasty
)=0;
virtual
void
EndFrame(
RAS_IRasterizer* rasty
)=0;
// the following function was formerly called 'Render'
// by it doesn't render anymore
// It only sets the transform for the rasterizer
// so must be renamed to 'applyTransform' or something
virtual
void
applyTransform(
class RAS_IRasterizer* rasty,
double* oglmatrix,
int drawingmode
)=0;
/**
* Renders 2D boxes.
* \param xco Position on the screen (origin in lower left corner).
* \param yco Position on the screen (origin in lower left corner).
* \param width Width of the canvas to draw to.
* \param height Height of the canvas to draw to.
* \param percentage Percentage of bar.
*/
virtual
void
RenderBox2D(int xco,
int yco,
int width,
int height,
float percentage) = 0;
/**
* Renders 3D text string using BFL.
* \param fontid The id of the font.
* \param text The string to render.
* \param size The size of the text.
* \param dpi The resolution of the text.
* \param color The color of the object.
* \param mat The Matrix of the text object.
* \param aspect A scaling factor to compensate for the size.
*/
virtual
void
RenderText3D(int fontid,
const char* text,
int size,
int dpi,
float* color,
double* mat,
float aspect
) = 0;
/**
* Renders 2D text string.
* \param mode The type of text
* \param text The string to render.
* \param xco Position on the screen (origin in lower left corner).
* \param yco Position on the screen (origin in lower left corner).
* \param width Width of the canvas to draw to.
* \param height Height of the canvas to draw to.
*/
virtual
void
RenderText2D(
RAS_TEXT_RENDER_MODE mode,
const char* text,
int xco,
int yco,
int width,
int height
) = 0;
// 3d text, mapped on polygon
virtual
void
RenderText(
int mode,
RAS_IPolyMaterial* polymat,
float v1[3],
float v2[3],
float v3[3],
float v4[3],
int glattrib
)=0;
virtual
void
ProcessLighting(
RAS_IRasterizer *rasty,
bool uselights,
const MT_Transform& trans
)=0;
virtual
void
SetClientObject(
RAS_IRasterizer* rasty,
void* obj
);
void
SetAuxilaryClientInfo(
void* inf
);
virtual
void
PushMatrix(
)=0;
virtual
void
PopMatrix(
)=0;
virtual
void
AddLight(
struct RAS_LightObject* lightobject
);
virtual
void
RemoveLight(
struct RAS_LightObject* lightobject
);
virtual
void
MotionBlur(RAS_IRasterizer* rasterizer)=0;
#ifdef WITH_CXX_GUARDEDALLOC
MEM_CXX_CLASS_ALLOC_FUNCS("GE:RAS_IRenderTools")
#endif
};
#endif /* __RAS_IRENDERTOOLS_H__ */

View File

@@ -43,7 +43,6 @@
#include "RAS_Polygon.h"
#include "RAS_TexVert.h"
#include "RAS_IRasterizer.h"
#include "RAS_IRenderTools.h"
#include "RAS_MeshObject.h"
#include "RAS_Deformer.h" // __NLA
@@ -581,8 +580,7 @@ list<RAS_MeshSlot>::iterator RAS_MaterialBucket::msEnd()
return m_meshSlots.end();
}
bool RAS_MaterialBucket::ActivateMaterial(const MT_Transform& cameratrans, RAS_IRasterizer* rasty,
RAS_IRenderTools *rendertools)
bool RAS_MaterialBucket::ActivateMaterial(const MT_Transform& cameratrans, RAS_IRasterizer* rasty)
{
bool uselights;
@@ -593,13 +591,12 @@ bool RAS_MaterialBucket::ActivateMaterial(const MT_Transform& cameratrans, RAS_I
return false;
uselights= m_material->UsesLighting(rasty);
rendertools->ProcessLighting(rasty, uselights, cameratrans);
rasty->ProcessLighting(uselights, cameratrans);
return true;
}
void RAS_MaterialBucket::RenderMeshSlot(const MT_Transform& cameratrans, RAS_IRasterizer* rasty,
RAS_IRenderTools* rendertools, RAS_MeshSlot &ms)
void RAS_MaterialBucket::RenderMeshSlot(const MT_Transform& cameratrans, RAS_IRasterizer* rasty, RAS_MeshSlot &ms)
{
m_material->ActivateMeshSlot(ms, rasty);
@@ -613,10 +610,10 @@ void RAS_MaterialBucket::RenderMeshSlot(const MT_Transform& cameratrans, RAS_IRa
if (IsZSort() && rasty->GetDrawingMode() >= RAS_IRasterizer::KX_SOLID)
ms.m_mesh->SortPolygons(ms, cameratrans*MT_Transform(ms.m_OpenGLMatrix));
rendertools->PushMatrix();
rasty->PushMatrix();
if (!ms.m_pDeformer || !ms.m_pDeformer->SkipVertexTransform())
{
rendertools->applyTransform(rasty,ms.m_OpenGLMatrix,m_material->GetDrawingMode());
rasty->applyTransform(ms.m_OpenGLMatrix,m_material->GetDrawingMode());
}
if (rasty->QueryLists())
@@ -641,7 +638,7 @@ void RAS_MaterialBucket::RenderMeshSlot(const MT_Transform& cameratrans, RAS_IRa
// for text drawing using faces
if (m_material->GetDrawingMode() & RAS_IRasterizer::RAS_RENDER_3DPOLYGON_TEXT)
rasty->IndexPrimitives_3DText(ms, m_material, rendertools);
rasty->IndexPrimitives_3DText(ms, m_material);
// for multitexturing
else if ((m_material->GetFlag() & (RAS_MULTITEX|RAS_BLENDERGLSL)))
rasty->IndexPrimitivesMulti(ms);
@@ -649,7 +646,7 @@ void RAS_MaterialBucket::RenderMeshSlot(const MT_Transform& cameratrans, RAS_IRa
else
rasty->IndexPrimitives(ms);
rendertools->PopMatrix();
rasty->PopMatrix();
}
void RAS_MaterialBucket::Optimize(MT_Scalar distance)

View File

@@ -219,10 +219,8 @@ public:
bool IsZSort() const;
/* Rendering */
bool ActivateMaterial(const MT_Transform& cameratrans, RAS_IRasterizer* rasty,
RAS_IRenderTools *rendertools);
void RenderMeshSlot(const MT_Transform& cameratrans, RAS_IRasterizer* rasty,
RAS_IRenderTools* rendertools, RAS_MeshSlot &ms);
bool ActivateMaterial(const MT_Transform& cameratrans, RAS_IRasterizer* rasty);
void RenderMeshSlot(const MT_Transform& cameratrans, RAS_IRasterizer* rasty, RAS_MeshSlot &ms);
/* Mesh Slot Access */
list<RAS_MeshSlot>::iterator msBegin();

View File

@@ -25,9 +25,15 @@
set(INC
..
# XXX Remove these <<<
../../BlenderRoutines
../../Expressions
../../GameLogic
../../Ketsji
../../Physics/common
# >>>
../../SceneGraph
../../../blender/blenfont
../../../blender/blenkernel
../../../blender/blenlib
../../../blender/gpu

View File

@@ -40,8 +40,8 @@
#include "RAS_Rect.h"
#include "RAS_TexVert.h"
#include "RAS_MeshObject.h"
#include "RAS_LightObject.h"
#include "MT_CmMatrix4x4.h"
#include "RAS_IRenderTools.h" // rendering text
#include "RAS_StorageIM.h"
#include "RAS_StorageVA.h"
@@ -59,8 +59,21 @@
extern "C"{
#include "BLI_utildefines.h"
#include "BKE_DerivedMesh.h"
#include "BLF_api.h"
}
// XXX Clean these up <<<
#include "BL_Material.h" // MAXTEX
#include "Value.h"
#include "KX_BlenderMaterial.h"
#include "KX_PolygonMaterial.h"
#include "KX_Light.h"
#include "KX_Scene.h"
#include "KX_RayCast.h"
#include "KX_GameObject.h"
// >>>
#ifndef M_PI
#define M_PI 3.14159265358979323846
#endif
@@ -94,6 +107,8 @@ RAS_OpenGLRasterizer::RAS_OpenGLRasterizer(RAS_ICanvas* canvas, int storage)
m_motionblur(0),
m_motionblurvalue(-1.0),
m_usingoverrideshader(false),
m_clientobject(NULL),
m_auxilaryClientInfo(NULL),
m_texco_num(0),
m_attrib_num(0),
//m_last_alphablend(GPU_BLEND_SOLID),
@@ -131,6 +146,10 @@ RAS_OpenGLRasterizer::RAS_OpenGLRasterizer(RAS_ICanvas* canvas, int storage)
m_storage = m_failsafe_storage = new RAS_StorageIM(&m_texco_num, m_texco, &m_attrib_num, m_attrib, m_attrib_layer);
m_storage_type = RAS_IMMEDIATE;
}
glGetIntegerv(GL_MAX_LIGHTS, (GLint *) &m_numgllights);
if (m_numgllights < 8)
m_numgllights = 8;
}
@@ -350,6 +369,13 @@ bool RAS_OpenGLRasterizer::BeginFrame(int drawingmode, double time)
glEnable(GL_MULTISAMPLE_ARB);
m_2DCanvas->BeginFrame();
// Render Tools
m_clientobject = NULL;
m_lastlightlayer = -1;
m_lastauxinfo = NULL;
m_lastlighting = true; /* force disable in DisableOpenGLLights() */
DisableOpenGLLights();
return true;
}
@@ -650,8 +676,7 @@ const MT_Matrix4x4& RAS_OpenGLRasterizer::GetViewInvMatrix() const
}
void RAS_OpenGLRasterizer::IndexPrimitives_3DText(RAS_MeshSlot& ms,
class RAS_IPolyMaterial* polymat,
class RAS_IRenderTools* rendertools)
class RAS_IPolyMaterial* polymat)
{
bool obcolor = ms.m_bObjectColor;
MT_Vector4& rgba = ms.m_RGBAcolor;
@@ -708,7 +733,7 @@ void RAS_OpenGLRasterizer::IndexPrimitives_3DText(RAS_MeshSlot& ms,
if (m_attrib[unit] == RAS_TEXCO_UV)
glattrib = unit;
rendertools->RenderText(polymat->GetDrawingMode(), polymat,
RenderText(polymat->GetDrawingMode(), polymat,
v[0], v[1], v[2], (numvert == 4)? v[3]: NULL, glattrib);
ClearCachingInfo();
@@ -1107,3 +1132,476 @@ bool RAS_OpenGLRasterizer::GetUsingOverrideShader()
return m_usingoverrideshader;
}
/**
* Render Tools
*/
/* ProcessLighting performs lighting on objects. the layer is a bitfield that
* contains layer information. There are 20 'official' layers in blender. A
* light is applied on an object only when they are in the same layer. OpenGL
* has a maximum of 8 lights (simultaneous), so 20 * 8 lights are possible in
* a scene. */
void RAS_OpenGLRasterizer::ProcessLighting(bool uselights, const MT_Transform& viewmat)
{
bool enable = false;
int layer= -1;
/* find the layer */
if (uselights) {
if (m_clientobject)
layer = static_cast<KX_GameObject*>(m_clientobject)->GetLayer();
}
/* avoid state switching */
if (m_lastlightlayer == layer && m_lastauxinfo == m_auxilaryClientInfo)
return;
m_lastlightlayer = layer;
m_lastauxinfo = m_auxilaryClientInfo;
/* enable/disable lights as needed */
if (layer >= 0)
enable = ApplyLights(layer, viewmat);
if (enable)
EnableOpenGLLights();
else
DisableOpenGLLights();
}
void RAS_OpenGLRasterizer::EnableOpenGLLights()
{
if (m_lastlighting == true)
return;
glEnable(GL_LIGHTING);
glEnable(GL_COLOR_MATERIAL);
glColorMaterial(GL_FRONT_AND_BACK, GL_AMBIENT_AND_DIFFUSE);
glLightModeli(GL_LIGHT_MODEL_TWO_SIDE, GL_TRUE);
glLightModeli(GL_LIGHT_MODEL_LOCAL_VIEWER, (GetCameraOrtho())? GL_FALSE: GL_TRUE);
if (GLEW_EXT_separate_specular_color || GLEW_VERSION_1_2)
glLightModeli(GL_LIGHT_MODEL_COLOR_CONTROL, GL_SEPARATE_SPECULAR_COLOR);
m_lastlighting = true;
}
void RAS_OpenGLRasterizer::DisableOpenGLLights()
{
if (m_lastlighting == false)
return;
glDisable(GL_LIGHTING);
glDisable(GL_COLOR_MATERIAL);
m_lastlighting = false;
}
void RAS_OpenGLRasterizer::AddLight(struct RAS_LightObject* lightobject)
{
m_lights.push_back(lightobject);
}
void RAS_OpenGLRasterizer::RemoveLight(struct RAS_LightObject* lightobject)
{
std::vector<struct RAS_LightObject*>::iterator lit =
std::find(m_lights.begin(),m_lights.end(),lightobject);
if (!(lit==m_lights.end()))
m_lights.erase(lit);
}
bool RAS_OpenGLRasterizer::RayHit(class KX_ClientObjectInfo *client, KX_RayCast *result, void * const data)
{
double* const oglmatrix = (double* const) data;
RAS_Polygon* poly = result->m_hitMesh->GetPolygon(result->m_hitPolygon);
if (!poly->IsVisible())
return false;
MT_Point3 resultpoint(result->m_hitPoint);
MT_Vector3 resultnormal(result->m_hitNormal);
MT_Vector3 left(oglmatrix[0],oglmatrix[1],oglmatrix[2]);
MT_Vector3 dir = -(left.cross(resultnormal)).safe_normalized();
left = (dir.cross(resultnormal)).safe_normalized();
// for the up vector, we take the 'resultnormal' returned by the physics
double maat[16] = {left[0], left[1], left[2], 0,
dir[0], dir[1], dir[2], 0,
resultnormal[0], resultnormal[1], resultnormal[2], 0,
0, 0, 0, 1};
glTranslated(resultpoint[0],resultpoint[1],resultpoint[2]);
//glMultMatrixd(oglmatrix);
glMultMatrixd(maat);
return true;
}
void RAS_OpenGLRasterizer::applyTransform(double* oglmatrix,int objectdrawmode )
{
/* FIXME:
blender: intern/moto/include/MT_Vector3.inl:42: MT_Vector3 operator/(const
MT_Vector3&, double): Assertion `!MT_fuzzyZero(s)' failed.
Program received signal SIGABRT, Aborted.
[Switching to Thread 16384 (LWP 1519)]
0x40477571 in kill () from /lib/libc.so.6
(gdb) bt
#7 0x08334368 in MT_Vector3::normalized() const ()
#8 0x0833e6ec in RAS_OpenGLRasterizer::applyTransform(RAS_IRasterizer*, double*, int) ()
*/
if (objectdrawmode & RAS_IPolyMaterial::BILLBOARD_SCREENALIGNED ||
objectdrawmode & RAS_IPolyMaterial::BILLBOARD_AXISALIGNED)
{
// rotate the billboard/halo
//page 360/361 3D Game Engine Design, David Eberly for a discussion
// on screen aligned and axis aligned billboards
// assumed is that the preprocessor transformed all billboard polygons
// so that their normal points into the positive x direction (1.0, 0.0, 0.0)
// when new parenting for objects is done, this rotation
// will be moved into the object
MT_Point3 objpos (oglmatrix[12],oglmatrix[13],oglmatrix[14]);
MT_Point3 campos = GetCameraPosition();
MT_Vector3 dir = (campos - objpos).safe_normalized();
MT_Vector3 up(0,0,1.0);
KX_GameObject* gameobj = (KX_GameObject*)m_clientobject;
// get scaling of halo object
MT_Vector3 size = gameobj->GetSGNode()->GetWorldScaling();
bool screenaligned = (objectdrawmode & RAS_IPolyMaterial::BILLBOARD_SCREENALIGNED)!=0;//false; //either screen or axisaligned
if (screenaligned)
{
up = (up - up.dot(dir) * dir).safe_normalized();
} else
{
dir = (dir - up.dot(dir)*up).safe_normalized();
}
MT_Vector3 left = dir.normalized();
dir = (up.cross(left)).normalized();
// we have calculated the row vectors, now we keep
// local scaling into account:
left *= size[0];
dir *= size[1];
up *= size[2];
double maat[16] = {left[0], left[1], left[2], 0,
dir[0], dir[1], dir[2], 0,
up[0], up[1], up[2], 0,
0, 0, 0, 1};
glTranslated(objpos[0],objpos[1],objpos[2]);
glMultMatrixd(maat);
}
else {
if (objectdrawmode & RAS_IPolyMaterial::SHADOW)
{
// shadow must be cast to the ground, physics system needed here!
MT_Point3 frompoint(oglmatrix[12],oglmatrix[13],oglmatrix[14]);
KX_GameObject *gameobj = (KX_GameObject*)m_clientobject;
MT_Vector3 direction = MT_Vector3(0,0,-1);
direction.normalize();
direction *= 100000;
MT_Point3 topoint = frompoint + direction;
KX_Scene* kxscene = (KX_Scene*) m_auxilaryClientInfo;
PHY_IPhysicsEnvironment* physics_environment = kxscene->GetPhysicsEnvironment();
KX_IPhysicsController* physics_controller = gameobj->GetPhysicsController();
KX_GameObject *parent = gameobj->GetParent();
if (!physics_controller && parent)
physics_controller = parent->GetPhysicsController();
if (parent)
parent->Release();
KX_RayCast::Callback<RAS_OpenGLRasterizer> callback(this, physics_controller, oglmatrix);
if (!KX_RayCast::RayTest(physics_environment, frompoint, topoint, callback))
{
// couldn't find something to cast the shadow on...
glMultMatrixd(oglmatrix);
}
else
{ // we found the "ground", but the cast matrix doesn't take
// scaling in consideration, so we must apply the object scale
MT_Vector3 size = gameobj->GetSGNode()->GetLocalScale();
glScalef(size[0], size[1], size[2]);
}
} else
{
// 'normal' object
glMultMatrixd(oglmatrix);
}
}
}
static void DisableForText()
{
glPolygonMode(GL_FRONT_AND_BACK, GL_FILL); /* needed for texture fonts otherwise they render as wireframe */
glDisable(GL_BLEND);
glDisable(GL_ALPHA_TEST);
glDisable(GL_LIGHTING);
glDisable(GL_COLOR_MATERIAL);
if (GLEW_ARB_multitexture) {
for (int i=0; i<MAXTEX; i++) {
glActiveTextureARB(GL_TEXTURE0_ARB+i);
if (GLEW_ARB_texture_cube_map)
glDisable(GL_TEXTURE_CUBE_MAP_ARB);
glDisable(GL_TEXTURE_2D);
}
glActiveTextureARB(GL_TEXTURE0_ARB);
}
else {
if (GLEW_ARB_texture_cube_map)
glDisable(GL_TEXTURE_CUBE_MAP_ARB);
glDisable(GL_TEXTURE_2D);
}
}
void RAS_OpenGLRasterizer::RenderBox2D(int xco,
int yco,
int width,
int height,
float percentage)
{
/* This is a rather important line :( The gl-mode hasn't been left
* behind quite as neatly as we'd have wanted to. I don't know
* what cause it, though :/ .*/
glDisable(GL_DEPTH_TEST);
glMatrixMode(GL_PROJECTION);
glPushMatrix();
glLoadIdentity();
glOrtho(0, width, 0, height, -100, 100);
glMatrixMode(GL_MODELVIEW);
glPushMatrix();
glLoadIdentity();
yco = height - yco;
int barsize = 50;
/* draw in black first*/
glColor3ub(0, 0, 0);
glBegin(GL_QUADS);
glVertex2f(xco + 1 + 1 + barsize * percentage, yco - 1 + 10);
glVertex2f(xco + 1, yco - 1 + 10);
glVertex2f(xco + 1, yco - 1);
glVertex2f(xco + 1 + 1 + barsize * percentage, yco - 1);
glEnd();
glColor3ub(255, 255, 255);
glBegin(GL_QUADS);
glVertex2f(xco + 1 + barsize * percentage, yco + 10);
glVertex2f(xco, yco + 10);
glVertex2f(xco, yco);
glVertex2f(xco + 1 + barsize * percentage, yco);
glEnd();
glMatrixMode(GL_PROJECTION);
glPopMatrix();
glMatrixMode(GL_MODELVIEW);
glPopMatrix();
glEnable(GL_DEPTH_TEST);
}
void RAS_OpenGLRasterizer::RenderText3D(int fontid,
const char* text,
int size,
int dpi,
float* color,
double* mat,
float aspect)
{
/* gl prepping */
DisableForText();
/* the actual drawing */
glColor4fv(color);
/* multiply the text matrix by the object matrix */
BLF_enable(fontid, BLF_MATRIX|BLF_ASPECT);
BLF_matrix(fontid, mat);
/* aspect is the inverse scale that allows you to increase */
/* your resolution without sizing the final text size */
/* the bigger the size, the smaller the aspect */
BLF_aspect(fontid, aspect, aspect, aspect);
BLF_size(fontid, size, dpi);
BLF_position(fontid, 0, 0, 0);
BLF_draw(fontid, (char *)text, 65535);
BLF_disable(fontid, BLF_MATRIX|BLF_ASPECT);
}
void RAS_OpenGLRasterizer::RenderText2D(RAS_TEXT_RENDER_MODE mode,
const char* text,
int xco,
int yco,
int width,
int height)
{
/* This is a rather important line :( The gl-mode hasn't been left
* behind quite as neatly as we'd have wanted to. I don't know
* what cause it, though :/ .*/
DisableForText();
glDisable(GL_DEPTH_TEST);
glMatrixMode(GL_PROJECTION);
glPushMatrix();
glLoadIdentity();
glOrtho(0, width, 0, height, -100, 100);
glMatrixMode(GL_MODELVIEW);
glPushMatrix();
glLoadIdentity();
if (mode == RAS_TEXT_PADDED) {
/* draw in black first*/
glColor3ub(0, 0, 0);
BLF_size(blf_mono_font, 11, 72);
BLF_position(blf_mono_font, (float)xco+1, (float)(height-yco-1), 0.0f);
BLF_draw(blf_mono_font, (char *)text, 65535);/* XXX, use real len */
glColor3ub(255, 255, 255);
BLF_position(blf_mono_font, (float)xco, (float)(height-yco), 0.0f);
BLF_draw(blf_mono_font, (char *)text, 65535);
} else {
/* the actual drawing */
glColor3ub(255, 255, 255);
BLF_size(blf_mono_font, 11, 72);
BLF_position(blf_mono_font, (float)xco, (float)(height-yco), 0.0f);
BLF_draw(blf_mono_font, (char *)text, 65535); /* XXX, use real len */
}
glMatrixMode(GL_PROJECTION);
glPopMatrix();
glMatrixMode(GL_MODELVIEW);
glPopMatrix();
glEnable(GL_DEPTH_TEST);
}
/* Render Text renders text into a (series of) polygon, using a texture font,
* Each character consists of one polygon (one quad or two triangles) */
void RAS_OpenGLRasterizer::RenderText(
int mode,
RAS_IPolyMaterial* polymat,
float v1[3], float v2[3], float v3[3], float v4[3], int glattrib)
{
const STR_String& mytext = ((CValue*)m_clientobject)->GetPropertyText("Text");
const unsigned int flag = polymat->GetFlag();
struct MTFace* tface = 0;
unsigned int *col = 0;
if (flag & RAS_BLENDERMAT) {
KX_BlenderMaterial *bl_mat = static_cast<KX_BlenderMaterial*>(polymat);
tface = bl_mat->GetMTFace();
col = bl_mat->GetMCol();
} else {
KX_PolygonMaterial* blenderpoly = static_cast<KX_PolygonMaterial*>(polymat);
tface = blenderpoly->GetMTFace();
col = blenderpoly->GetMCol();
}
GPU_render_text(tface, mode, mytext, mytext.Length(), col, v1, v2, v3, v4, glattrib);
}
void RAS_OpenGLRasterizer::PushMatrix()
{
glPushMatrix();
}
void RAS_OpenGLRasterizer::PopMatrix()
{
glPopMatrix();
}
int RAS_OpenGLRasterizer::ApplyLights(int objectlayer, const MT_Transform& viewmat)
{
// taken from blender source, incompatibility between Blender Object / GameObject
KX_Scene* kxscene = (KX_Scene*)m_auxilaryClientInfo;
float glviewmat[16];
unsigned int count;
std::vector<struct RAS_LightObject*>::iterator lit = m_lights.begin();
for (count=0; count<m_numgllights; count++)
glDisable((GLenum)(GL_LIGHT0+count));
viewmat.getValue(glviewmat);
glPushMatrix();
glLoadMatrixf(glviewmat);
for (lit = m_lights.begin(), count = 0; !(lit==m_lights.end()) && count < m_numgllights; ++lit)
{
RAS_LightObject* lightdata = (*lit);
KX_LightObject *kxlight = (KX_LightObject*)lightdata->m_light;
if (kxlight->ApplyLight(kxscene, objectlayer, count))
count++;
}
glPopMatrix();
return count;
}
void RAS_OpenGLRasterizer::MotionBlur()
{
int state = GetMotionBlurState();
float motionblurvalue;
if (state)
{
motionblurvalue = GetMotionBlurValue();
if (state==1)
{
//bugfix:load color buffer into accum buffer for the first time(state=1)
glAccum(GL_LOAD, 1.0);
SetMotionBlurState(2);
}
else if (motionblurvalue >= 0.0f && motionblurvalue <= 1.0f) {
glAccum(GL_MULT, motionblurvalue);
glAccum(GL_ACCUM, 1-motionblurvalue);
glAccum(GL_RETURN, 1.0);
glFlush();
}
}
}
void RAS_OpenGLRasterizer::SetClientObject(void* obj)
{
if (m_clientobject != obj)
{
bool ccw = (obj == NULL || !((KX_GameObject*)obj)->IsNegativeScaling());
SetFrontFace(ccw);
m_clientobject = obj;
}
}
void RAS_OpenGLRasterizer::SetAuxilaryClientInfo(void* inf)
{
m_auxilaryClientInfo = inf;
}

View File

@@ -105,6 +105,15 @@ class RAS_OpenGLRasterizer : public RAS_IRasterizer
bool m_usingoverrideshader;
// Render tools
void* m_clientobject;
void* m_auxilaryClientInfo;
std::vector<struct RAS_LightObject*> m_lights;
int m_lastlightlayer;
bool m_lastlighting;
void *m_lastauxinfo;
unsigned int m_numgllights;
protected:
int m_drawingmode;
TexCoGen m_texco[RAS_MAX_TEXCO];
@@ -171,10 +180,8 @@ public:
virtual void IndexPrimitives(class RAS_MeshSlot& ms);
virtual void IndexPrimitivesMulti(class RAS_MeshSlot& ms);
virtual void IndexPrimitives_3DText(
class RAS_MeshSlot& ms,
class RAS_IPolyMaterial* polymat,
class RAS_IRenderTools* rendertools);
virtual void IndexPrimitives_3DText(class RAS_MeshSlot& ms,
class RAS_IPolyMaterial* polymat);
virtual void SetProjectionMatrix(MT_CmMatrix4x4 & mat);
virtual void SetProjectionMatrix(const MT_Matrix4x4 & mat);
@@ -330,6 +337,65 @@ public:
virtual void SetUsingOverrideShader(bool val);
virtual bool GetUsingOverrideShader();
/**
* Render Tools
*/
void EnableOpenGLLights();
void DisableOpenGLLights();
void ProcessLighting(bool uselights, const MT_Transform& viewmat);
void RenderBox2D(int xco,
int yco,
int width,
int height,
float percentage);
void RenderText3D(int fontid,
const char* text,
int size,
int dpi,
float* color,
double* mat,
float aspect);
void RenderText2D(RAS_TEXT_RENDER_MODE mode,
const char* text,
int xco,
int yco,
int width,
int height);
void RenderText(int mode,
class RAS_IPolyMaterial* polymat,
float v1[3],
float v2[3],
float v3[3],
float v4[3],
int glattrib);
void applyTransform(double* oglmatrix, int objectdrawmode);
int applyLights(int objectlayer, const MT_Transform& viewmat);
void PushMatrix();
void PopMatrix();
bool RayHit(class KX_ClientObjectInfo* client, class KX_RayCast* result, void * const data);
bool NeedRayCast(class KX_ClientObjectInfo*) { return true; }
void AddLight(struct RAS_LightObject* lightobject);
void RemoveLight(struct RAS_LightObject* lightobject);
int ApplyLights(int objectlayer, const MT_Transform& viewmat);
void MotionBlur();
void SetClientObject(void* obj);
void SetAuxilaryClientInfo(void* inf);
#ifdef WITH_CXX_GUARDEDALLOC
MEM_CXX_CLASS_ALLOC_FUNCS("GE:RAS_OpenGLRasterizer")
#endif

View File

@@ -80,7 +80,6 @@ ImageRender::ImageRender (KX_Scene *scene, KX_Camera * camera) :
m_engine = KX_GetActiveEngine();
m_rasterizer = m_engine->GetRasterizer();
m_canvas = m_engine->GetCanvas();
m_rendertools = m_engine->GetRenderTools();
}
// destructor
@@ -200,9 +199,8 @@ void ImageRender::Render()
m_canvas->ClearColor(m_background[0], m_background[1], m_background[2], m_background[3]);
m_canvas->ClearBuffer(RAS_ICanvas::COLOR_BUFFER|RAS_ICanvas::DEPTH_BUFFER);
m_rasterizer->BeginFrame(RAS_IRasterizer::KX_TEXTURED,m_engine->GetClockTime());
m_rendertools->BeginFrame(m_rasterizer);
m_engine->SetWorldSettings(m_scene->GetWorldInfo());
m_rendertools->SetAuxilaryClientInfo(m_scene);
m_rasterizer->SetAuxilaryClientInfo(m_scene);
m_rasterizer->DisplayFog();
// matrix calculation, don't apply any of the stereo mode
m_rasterizer->SetStereoMode(RAS_IRasterizer::RAS_STEREO_NOSTEREO);
@@ -275,7 +273,7 @@ void ImageRender::Render()
m_scene->CalculateVisibleMeshes(m_rasterizer,m_camera);
m_scene->RenderBuckets(camtrans, m_rasterizer, m_rendertools);
m_scene->RenderBuckets(camtrans, m_rasterizer);
m_scene->RenderFonts();
@@ -595,7 +593,6 @@ ImageRender::ImageRender (KX_Scene *scene, KX_GameObject *observer, KX_GameObjec
m_engine = KX_GetActiveEngine();
m_rasterizer = m_engine->GetRasterizer();
m_canvas = m_engine->GetCanvas();
m_rendertools = m_engine->GetRenderTools();
// locate the vertex assigned to mat and do following calculation in mesh coordinates
for (int meshIndex = 0; meshIndex < mirror->GetMeshCount(); meshIndex++)
{

View File

@@ -39,7 +39,6 @@
#include "DNA_screen_types.h"
#include "RAS_ICanvas.h"
#include "RAS_IRasterizer.h"
#include "RAS_IRenderTools.h"
#include "ImageViewport.h"
@@ -88,8 +87,6 @@ protected:
RAS_ICanvas* m_canvas;
/// rasterizer
RAS_IRasterizer* m_rasterizer;
/// render tools
RAS_IRenderTools* m_rendertools;
/// engine
KX_KetsjiEngine* m_engine;