Java源码示例:com.jme3.renderer.RenderManager
示例1
/**
* For internal use only
* specific render for the ragdoll(if debugging)
* @param rm
* @param vp
*/
public void render(RenderManager rm, ViewPort vp) {
if (enabled && space != null && space.getDebugManager() != null) {
if (!debug) {
attachDebugShape(space.getDebugManager());
}
for (Iterator<PhysicsBoneLink> it = boneLinks.values().iterator(); it.hasNext();) {
PhysicsBoneLink physicsBoneLink = it.next();
Spatial debugShape = physicsBoneLink.rigidBody.debugShape();
if (debugShape != null) {
debugShape.setLocalTranslation(physicsBoneLink.rigidBody.getMotionState().getWorldLocation());
debugShape.setLocalRotation(physicsBoneLink.rigidBody.getMotionState().getWorldRotationQuat());
debugShape.updateGeometricState();
rm.renderScene(debugShape, vp);
}
}
}
}
示例2
/**
* Creates the camera to use for rendering. Default values are perspective
* projection with 45° field of view, with near and far values 1 and 1000
* units respectively.
*/
private void initCamera(){
cam = new Camera(settings.getWidth(), settings.getHeight());
cam.setFrustumPerspective(45f, (float)cam.getWidth() / cam.getHeight(), 1f, 1000f);
cam.setLocation(new Vector3f(0f, 0f, 10f));
cam.lookAt(new Vector3f(0f, 0f, 0f), Vector3f.UNIT_Y);
renderManager = new RenderManager(renderer);
//Remy - 09/14/2010 setted the timer in the renderManager
renderManager.setTimer(timer);
if (prof != null) {
renderManager.setAppProfiler(prof);
}
viewPort = renderManager.createMainView("Default", cam);
viewPort.setClearFlags(true, true, true);
// Create a new cam for the gui
Camera guiCam = new Camera(settings.getWidth(), settings.getHeight());
guiViewPort = renderManager.createPostView("Gui Default", guiCam);
guiViewPort.setClearFlags(false, false, false);
}
示例3
public void renderQueue(Bucket bucket, RenderManager rm, Camera cam, boolean clear) {
switch (bucket) {
case Gui:
renderGeometryList(guiList, rm, cam, clear);
break;
case Opaque:
renderGeometryList(opaqueList, rm, cam, clear);
break;
case Sky:
renderGeometryList(skyList, rm, cam, clear);
break;
case Transparent:
renderGeometryList(transparentList, rm, cam, clear);
break;
case Translucent:
renderGeometryList(translucentList, rm, cam, clear);
break;
default:
throw new UnsupportedOperationException("Unsupported bucket type: " + bucket);
}
}
示例4
/**
* Callback from Control.render(), do not use.
*
* @param rm
* @param vp
*/
private void renderFromControl(RenderManager rm, ViewPort vp) {
Camera cam = vp.getCamera();
if (meshType == ParticleMesh.Type.Point) {
float C = cam.getProjectionMatrix().m00;
C *= cam.getWidth() * 0.5f;
// send attenuation params
this.getMaterial().setFloat("Quadratic", C);
}
Matrix3f inverseRotation = Matrix3f.IDENTITY;
TempVars vars = null;
if (!worldSpace) {
vars = TempVars.get();
inverseRotation = this.getWorldRotation().toRotationMatrix(vars.tempMat3).invertLocal();
}
particleMesh.updateParticleData(particles, cam, inverseRotation);
if (!worldSpace) {
vars.release();
}
}
示例5
/**
* Creates the camera to use for rendering. Default values are perspective
* projection with 45° field of view, with near and far values 1 and 1000
* units respectively.
*/
private void initCamera(){
cam = new Camera(settings.getWidth(), settings.getHeight());
cam.setFrustumPerspective(45f, (float)cam.getWidth() / cam.getHeight(), 1f, 1000f);
cam.setLocation(new Vector3f(0f, 0f, 10f));
cam.lookAt(new Vector3f(0f, 0f, 0f), Vector3f.UNIT_Y);
renderManager = new RenderManager(renderer);
//Remy - 09/14/2010 setted the timer in the renderManager
renderManager.setTimer(timer);
viewPort = renderManager.createMainView("Default", cam);
viewPort.setClearFlags(true, true, true);
// Create a new cam for the gui
Camera guiCam = new Camera(settings.getWidth(), settings.getHeight());
guiViewPort = renderManager.createPostView("Gui Default", guiCam);
guiViewPort.setClearFlags(false, false, false);
}
示例6
private void renderGeometryList(GeometryList list, RenderManager rm, Camera cam, boolean clear) {
list.setCamera(cam); // select camera for sorting
list.sort();
for (int i = 0; i < list.size(); i++) {
Spatial obj = list.get(i);
assert obj != null;
if (obj instanceof Geometry) {
Geometry g = (Geometry) obj;
rm.renderGeometry(g);
// make sure to reset queue distance
}
if (obj != null) {
obj.queueDistance = Float.NEGATIVE_INFINITY;
}
}
if (clear) {
list.clear();
}
}
示例7
private boolean testHardwareSupported(RenderManager rm) {
for (Material m : materials) {
// Some of the animated mesh(es) do not support hardware skinning,
// so it is not supported by the model.
if (m.getMaterialDef().getMaterialParam("NumberOfBones") == null) {
Logger.getLogger(SkeletonControl.class.getName()).log(Level.WARNING,
"Not using hardware skinning for {0}, " +
"because material {1} doesn''t support it.",
new Object[]{spatial, m.getMaterialDef().getName()});
return false;
}
}
switchToHardware();
try {
rm.preloadScene(spatial);
return true;
} catch (RendererException e) {
Logger.getLogger(SkeletonControl.class.getName()).log(Level.WARNING, "Could not enable HW skinning due to shader compile error:", e);
return false;
}
}
示例8
/**
* Preloads this material for the given render manager.
* <p>
* Preloading the material can ensure that when the material is first
* used for rendering, there won't be any delay since the material has
* been already been setup for rendering.
*
* @param renderManager The render manager to preload for
*/
public void preload(RenderManager renderManager, Geometry geometry) {
if (technique == null) {
selectTechnique(TechniqueDef.DEFAULT_TECHNIQUE_NAME, renderManager);
}
TechniqueDef techniqueDef = technique.getDef();
Renderer renderer = renderManager.getRenderer();
EnumSet<Caps> rendererCaps = renderer.getCaps();
if (techniqueDef.isNoRender()) {
return;
}
// Get world overrides
SafeArrayList<MatParamOverride> overrides = geometry.getWorldMatParamOverrides();
Shader shader = technique.makeCurrent(renderManager, overrides, null, null, rendererCaps);
updateShaderMaterialParameters(renderer, shader, overrides, null);
renderManager.getRenderer().setShader(shader);
}
示例9
@Override
protected void initFilter(AssetManager manager, RenderManager rm, ViewPort vp, int w, int h) {
this.renderManager = rm;
this.viewPort = vp;
material = new Material(manager, "Common/MatDefs/Post/Overlay.j3md");
material.setColor("Color", ColorRGBA.White);
Texture2D tex = processor.getFilterTexture();
material.setTexture("Texture", tex);
if (tex.getImage().getMultiSamples() > 1) {
material.setInt("NumSamples", tex.getImage().getMultiSamples());
} else {
material.clearParam("NumSamples");
}
renderManager.setHandleTranslucentBucket(false);
if (enabledSoftParticles && depthTexture != null) {
initSoftParticles(vp, true);
}
}
示例10
public void renderQueue(Bucket bucket, RenderManager rm, Camera cam, boolean clear) {
switch (bucket) {
case Gui:
renderGeometryList(guiList, rm, cam, clear);
break;
case Opaque:
renderGeometryList(opaqueList, rm, cam, clear);
break;
case Sky:
renderGeometryList(skyList, rm, cam, clear);
break;
case Transparent:
renderGeometryList(transparentList, rm, cam, clear);
break;
case Translucent:
renderGeometryList(translucentList, rm, cam, clear);
break;
default:
throw new UnsupportedOperationException("Unsupported bucket type: " + bucket);
}
}
示例11
/**
* Get pre-normals from the given rendering.
* @param renderManager the render manager.
* @param normalPass the normal pass.
* @param viewPort the viewport.
*/
public static void getPreNormals(RenderManager renderManager, Pass normalPass, ViewPort viewPort) {
curCount++;
// do we already have a valid cache to set the framebuffer to?
Renderer r = renderManager.getRenderer();
if( cachedPreNormals != null ) {
r.copyFrameBuffer(cachedPreNormals, normalPass.getRenderFrameBuffer(), false);
} else {
// lets make the prenormals
r.setFrameBuffer(normalPass.getRenderFrameBuffer());
renderManager.getRenderer().clearBuffers(true, true, true);
if( renderManager.getRenderer().getCaps().contains(Caps.GLSL150) ) {
renderManager.setForcedTechnique("PreNormalPass15");
} else {
renderManager.setForcedTechnique("PreNormalPass");
}
renderManager.renderViewPortQueues(viewPort, false);
renderManager.setForcedTechnique(null);
// if we should cache this, do it now
if( lastNormalPassesCount > 1 ) {
cachedPreNormals = normalPass.getRenderFrameBuffer();
}
}
renderManager.getRenderer().setFrameBuffer(viewPort.getOutputFrameBuffer());
}
示例12
@Override
public void initialize(RenderManager rm, ViewPort vp) {
renderManager = rm;
viewPort = vp;
reshape(vp, vp.getCamera().getWidth(), vp.getCamera().getHeight());
}
示例13
private void updateRenderState(RenderManager renderManager, Renderer renderer, TechniqueDef techniqueDef) {
if (renderManager.getForcedRenderState() != null) {
renderer.applyRenderState(renderManager.getForcedRenderState());
} else {
if (techniqueDef.getRenderState() != null) {
renderer.applyRenderState(techniqueDef.getRenderState().copyMergedTo(additionalState, mergedRenderState));
} else {
renderer.applyRenderState(RenderState.DEFAULT.copyMergedTo(additionalState, mergedRenderState));
}
}
}
示例14
@Override
protected void controlRender(RenderManager rm, ViewPort vp) {
if (!wasMeshUpdated) {
updateTargetsAndMaterials(spatial);
// Prevent illegal cases. These should never happen.
assert hwSkinningTested || (!hwSkinningTested && !hwSkinningSupported && !hwSkinningEnabled);
assert !hwSkinningEnabled || (hwSkinningEnabled && hwSkinningTested && hwSkinningSupported);
if (hwSkinningDesired && !hwSkinningTested) {
hwSkinningTested = true;
hwSkinningSupported = testHardwareSupported(rm);
if (hwSkinningSupported) {
hwSkinningEnabled = true;
Logger.getLogger(SkeletonControl.class.getName()).log(Level.INFO, "Hardware skinning engaged for " + spatial);
} else {
switchToSoftware();
}
} else if (hwSkinningDesired && hwSkinningSupported && !hwSkinningEnabled) {
switchToHardware();
hwSkinningEnabled = true;
} else if (!hwSkinningDesired && hwSkinningEnabled) {
switchToSoftware();
hwSkinningEnabled = false;
}
if (hwSkinningEnabled) {
controlRenderHardware();
} else {
controlRenderSoftware();
}
wasMeshUpdated = true;
}
}
示例15
@Override
protected void controlRender(RenderManager rm, ViewPort vp) {
BoundingVolume bv = spatial.getWorldBound();
Camera cam = vp.getCamera();
float atanNH = FastMath.atan(cam.getFrustumNear() * cam.getFrustumTop());
float ratio = (FastMath.PI / (8f * atanNH));
float newDistance = bv.distanceTo(vp.getCamera().getLocation()) / ratio;
int level;
if (Math.abs(newDistance - lastDistance) <= distTolerance) {
level = lastLevel; // we haven't moved relative to the model, send the old measurement back.
} else if (lastDistance > newDistance && lastLevel == 0) {
level = lastLevel; // we're already at the lowest setting and we just got closer to the model, no need to keep trying.
} else if (lastDistance < newDistance && lastLevel == numLevels - 1) {
level = lastLevel; // we're already at the highest setting and we just got further from the model, no need to keep trying.
} else {
lastDistance = newDistance;
// estimate area of polygon via bounding volume
float area = AreaUtils.calcScreenArea(bv, lastDistance, cam.getWidth());
float trisToDraw = area * trisPerPixel;
level = numLevels - 1;
for (int i = numLevels; --i >= 0;) {
if (trisToDraw - numTris[i] < 0) {
break;
}
level = i;
}
lastLevel = level;
}
spatial.setLodLevel(level);
}
示例16
@Override
protected void initFilter(AssetManager manager, RenderManager renderManager, ViewPort vp, int w, int h) {
this.renderManager = renderManager;
this.viewPort = vp;
normalPass = new Pass();
normalPass.init(renderManager.getRenderer(), w, h, Format.RGBA8, Format.Depth);
material = new Material(manager, "Common/MatDefs/Post/CartoonEdge.j3md");
material.setFloat("EdgeWidth", edgeWidth);
material.setFloat("EdgeIntensity", edgeIntensity);
material.setFloat("NormalThreshold", normalThreshold);
material.setFloat("DepthThreshold", depthThreshold);
material.setFloat("NormalSensitivity", normalSensitivity);
material.setFloat("DepthSensitivity", depthSensitivity);
material.setColor("EdgeColor", edgeColor);
}
示例17
private void autoSelectTechnique(RenderManager rm) {
if (technique == null) {
// NOTE: Not really needed anymore since we have technique
// selection by caps. Rename all "FixedFunc" techniques to "Default"
// and remove this hack.
if (!rm.getRenderer().getCaps().contains(Caps.GLSL100)) {
selectTechnique("FixedFunc", rm);
} else {
selectTechnique("Default", rm);
}
} else if (technique.isNeedReload()) {
technique.makeCurrent(def.getAssetManager(), paramValues);
}
}
示例18
@Override
public Shader makeCurrent(AssetManager assetManager, RenderManager renderManager,
EnumSet<Caps> rendererCaps, LightList lights, DefineList defines) {
// TODO: if it ever changes that render isn't called
// right away with the same geometry after makeCurrent, it would be
// a problem.
// Do a radix sort.
tempDirLights.clear();
tempPointLights.clear();
tempSpotLights.clear();
for (Light light : lights) {
switch (light.getType()) {
case Directional:
tempDirLights.add((DirectionalLight) light);
break;
case Point:
tempPointLights.add((PointLight) light);
break;
case Spot:
tempSpotLights.add((SpotLight) light);
break;
}
}
defines.set(numDirLightsDefineId, tempDirLights.size());
defines.set(numPointLightsDefineId, tempPointLights.size());
defines.set(numSpotLightsDefineId, tempSpotLights.size());
return techniqueDef.getShader(assetManager, rendererCaps, defines);
}
示例19
@Override
public void initialize(RenderManager rm, ViewPort viewPort) {
this.camera = viewPort.getCamera();
this.width = camera.getWidth();
this.height = camera.getHeight();
this.renderManager = rm;
this.isInitilized = true;
if (freeItems == null) {
freeItems = new LinkedBlockingQueue<WorkItem>();
for (int i = 0; i < numCpus; i++) {
freeItems.add(new WorkItem(width, height));
}
}
}
示例20
public void initialize(RenderManager rm, ViewPort vp) {
if (this.rm == null){
// First time called in OGL thread
this.rm = rm;
reshapeInThread(1, 1);
}
}
示例21
/**
* Bind this processor.
*
* @param destination the destination.
* @param application the application.
*/
public void bind(Component destination, Application application) {
final RenderManager renderManager = application.getRenderManager();
if (renderManager == null) {
throw new RuntimeException("No render manager available from the application.");
}
List<ViewPort> postViews = renderManager.getPostViews();
if (postViews.isEmpty()) {
throw new RuntimeException("the list of a post view is empty.");
}
bind(destination, application, postViews.get(postViews.size() - 1), true);
}
示例22
public void render(RenderManager rm) {
if (!active) {
return;
}
if (threadingType == ThreadingType.PARALLEL) {
physicsFuture = executor.submit(parallelPhysicsUpdate);
} else if (threadingType == ThreadingType.SEQUENTIAL) {
pSpace.update(active ? tpf * speed : 0);
} else {
}
}
示例23
@Override
protected void initFilter(AssetManager manager, RenderManager renderManager, ViewPort vp, int w, int h) {
this.renderManager = renderManager;
this.viewPort = vp;
normalPass = new Pass();
normalPass.init(renderManager.getRenderer(), w, h, Format.RGBA8, Format.Depth);
material = new Material(manager, "Common/MatDefs/Post/CartoonEdge.j3md");
material.setFloat("EdgeWidth", edgeWidth);
material.setFloat("EdgeIntensity", edgeIntensity);
material.setFloat("NormalThreshold", normalThreshold);
material.setFloat("DepthThreshold", depthThreshold);
material.setFloat("NormalSensitivity", normalSensitivity);
material.setFloat("DepthSensitivity", depthSensitivity);
material.setColor("EdgeColor", edgeColor);
}
示例24
@Override
protected void initFilter(AssetManager manager,
RenderManager renderManager, ViewPort vp, int w, int h) {
material = new Material(manager, "Common/MatDefs/Post/FXAA.j3md");
material.setFloat("SubPixelShift", subPixelShift);
material.setFloat("VxOffset", vxOffset);
material.setFloat("SpanMax", spanMax);
material.setFloat("ReduceMul", reduceMul);
}
示例25
/**
* Calls render for all attached and initialized states, do not call directly.
* @param rm The RenderManager
*/
public void render(RenderManager rm){
AppState[] array = getStates();
for (AppState state : array){
if (state.isEnabled()) {
state.render(rm);
}
}
}
示例26
/**
* Initialize this shadow renderer prior to its first update.
*
* @param rm the render manager
* @param vp the viewport
*/
@Override
public void initialize(RenderManager rm, ViewPort vp) {
renderManager = rm;
viewPort = vp;
postTechniqueName = "PostShadow";
if(zFarOverride>0 && frustumCam == null){
initFrustumCam();
}
}
示例27
/**
* Render this state. Should be invoked only by a subclass or by the
* AppStateManager. Invoked once per frame, provided the state is attached
* and enabled.
*
* @param rm the render manager (not null)
*/
@Override
public void render(RenderManager rm) {
super.render(rm);
if (viewPort != null) {
rm.renderScene(physicsDebugRootNode, viewPort);
}
}
示例28
public void render(RenderManager rm, ViewPort vp) {
if (enabled && space != null && space.getDebugManager() != null) {
if (debugShape == null) {
attachDebugShape(space.getDebugManager());
}
debugShape.setLocalTranslation(spatial.getWorldTranslation());
debugShape.setLocalRotation(spatial.getWorldRotation());
debugShape.updateLogicalState(0);
debugShape.updateGeometricState();
rm.renderScene(debugShape, vp);
}
}
示例29
/**
* Render this state. Should be invoked only by a subclass or by the
* AppStateManager. Invoked once per frame, provided the state is attached
* and enabled.
*
* @param rm the render manager (not null)
*/
@Override
public void render(RenderManager rm) {
super.render(rm);
if (!active) {
return;
}
if (threadingType == ThreadingType.PARALLEL) {
physicsFuture = executor.submit(parallelPhysicsUpdate);
} else if (threadingType == ThreadingType.SEQUENTIAL) {
pSpace.update(active ? tpf * speed : 0);
} else {
}
}
示例30
@Override
public void initialize(RenderManager rm, ViewPort viewPort) {
logger.log(Level.INFO, "initialize in VideoProcessor");
this.camera = viewPort.getCamera();
this.width = camera.getWidth();
this.height = camera.getHeight();
this.renderManager = rm;
this.isInitilized = true;
if (freeItems == null) {
freeItems = new LinkedBlockingQueue<WorkItem>();
for (int i = 0; i < numCpus; i++) {
freeItems.add(new WorkItem(width, height));
}
}
}