⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 lwjglrenderer.java

📁 java 3d game jme 工程开发源代码
💻 JAVA
📖 第 1 页 / 共 5 页
字号:
        Vector3f point;
        float limit = (1 + (1.0f / curve.getSteps()));
        for (float t = 0; t <= limit; t += 1.0f / curve.getSteps()) {

            if (t >= colorInterval && color != null) {

                colorInterval += colorModifier;
                matRecord.setCurrentColor(color.get(), color.get(),
                        color.get(), color.get());
            }

            point = curve.getPoint(t, tempVa);
            GL11.glVertex3f(point.x, point.y, point.z);
        }

        if (Debug.stats) {
            StatCollector.addStat(StatType.STAT_VERTEX_COUNT, limit);
        }

        GL11.glEnd();
        undoTransforms(curve);
    }

    /**
     * <code>draw</code> renders a <code>Line</code> object including it's
     * normals, colors, textures and vertices.
     * 
     * @see Renderer#draw(Line)
     * @param lines
     *            the lines to render.
     */
    public void draw(Line lines) {
        if (!lines.predraw(this))
            return;

        if (Debug.stats) {
            StatCollector.addStat(StatType.STAT_LINE_COUNT, 1);
            StatCollector.addStat(StatType.STAT_VERTEX_COUNT, lines.getVertexCount());
            StatCollector.addStat(StatType.STAT_GEOM_COUNT, 1);
        }

        if (lines.getDisplayListID() != -1) {
            renderDisplayList(lines);
            return;
        }

        if (!generatingDisplayList)
            applyStates(lines.states, lines);
        if (Debug.stats) {
            StatCollector.startStat(StatType.STAT_RENDER_TIMER);
        }
        boolean transformed = doTransforms(lines);
        int mode = GL11.GL_LINES;
        switch (lines.getMode()) {
            case Segments:
                mode = GL11.GL_LINES;
                break;
            case Connected:
                mode = GL11.GL_LINE_STRIP;
                break;
            case Loop:
                mode = GL11.GL_LINE_LOOP;
                break;
        }

        LineRecord lineRecord = (LineRecord) DisplaySystem.getDisplaySystem()
                .getCurrentContext().getLineRecord();
        lineRecord.applyLineWidth(lines.getLineWidth());
        lineRecord.applyLineStipple(lines.getStippleFactor(), lines
                .getStipplePattern());
        lineRecord.applyLineSmooth(lines.isAntialiased());
        if (!lineRecord.isValid())
            lineRecord.validate();

        if (!predrawGeometry(lines)) {
            // make sure only the necessary indices are sent through on old
            // cards.
            IntBuffer indices = lines.getIndexBuffer();
            indices.rewind();
            indices.limit(lines.getVertexCount());

            GL11.glDrawElements(mode, indices);

            indices.clear();
        } else {
            GL11.glDrawElements(mode, lines.getIndexBuffer().limit(),
                    GL11.GL_UNSIGNED_INT, 0);
        }

        postdrawGeometry(lines);
        if (transformed) undoTransforms(lines);

        if (Debug.stats) {
            StatCollector.endStat(StatType.STAT_RENDER_TIMER);
        }
        lines.postdraw(this);
    }

    /**
     * <code>draw</code> renders a <code>Point</code> object including it's
     * normals, colors, textures and vertices.
     * 
     * @see Renderer#draw(Point)
     * @param points
     *            the points to render.
     */
    public void draw(Point points) {
        if (!points.predraw(this))
            return;

        if (Debug.stats) {
            StatCollector.addStat(StatType.STAT_POINT_COUNT, 1);
            StatCollector.addStat(StatType.STAT_VERTEX_COUNT, points.getVertexCount());
            StatCollector.addStat(StatType.STAT_GEOM_COUNT, 1);
        }

        if (points.getDisplayListID() != -1) {
            renderDisplayList(points);
            return;
        }

        if (!generatingDisplayList)
            applyStates(points.states, points);
        if (Debug.stats) {
            StatCollector.startStat(StatType.STAT_RENDER_TIMER);
        }
        boolean transformed = doTransforms(points);

        GL11.glPointSize(points.getPointSize());
        if (points.isAntialiased()) {
            GL11.glEnable(GL11.GL_POINT_SMOOTH);
            GL11.glHint(GL11.GL_POINT_SMOOTH_HINT, GL11.GL_NICEST);
        }

        if (!predrawGeometry(points)) {
            // make sure only the necessary indices are sent through on old
            // cards.
            IntBuffer indices = points.getIndexBuffer();
            indices.rewind();
            indices.limit(points.getVertexCount());

            GL11.glDrawElements(GL11.GL_POINTS, indices);

            indices.clear();
        } else {
            GL11.glDrawElements(GL11.GL_POINTS,
                    points.getIndexBuffer().limit(), GL11.GL_UNSIGNED_INT, 0);
        }

        if (points.isAntialiased()) {
            GL11.glDisable(GL11.GL_POINT_SMOOTH);
        }

        postdrawGeometry(points);
        if (transformed) undoTransforms(points);

        if (Debug.stats) {
            StatCollector.endStat(StatType.STAT_RENDER_TIMER);
        }
        points.postdraw(this);
    }

    /**
     * <code>draw</code> renders a <code>QuadMesh</code> object including
     * it's normals, colors, textures and vertices.
     * 
     * @see Renderer#draw(QuadMesh)
     * @param quads
     *            the mesh to render.
     */
    public void draw(QuadMesh quads) {
        if (!quads.predraw(this))
            return;

        if (Debug.stats) {
            StatCollector.addStat(StatType.STAT_QUAD_COUNT, quads.getQuadCount());
            StatCollector.addStat(StatType.STAT_VERTEX_COUNT, quads.getVertexCount());
            StatCollector.addStat(StatType.STAT_GEOM_COUNT, 1);
        }

        if (quads.getDisplayListID() != -1) {
            renderDisplayList(quads);
            return;
        }

        if (!generatingDisplayList)
            applyStates(quads.states, quads);
        if (Debug.stats) {
            StatCollector.startStat(StatType.STAT_RENDER_TIMER);
        }
        boolean transformed = doTransforms(quads);
        int glMode = GL11.GL_QUADS;
        switch (quads.getMode()) {
            case Quads:
                glMode = GL11.GL_QUADS;
                break;
            case Strip:
                glMode = GL11.GL_QUAD_STRIP;
                break;
        }

        if (!predrawGeometry(quads)) {
            // make sure only the necessary indices are sent through on old
            // cards.
            IntBuffer indices = quads.getIndexBuffer();
            indices.rewind();
            indices.limit(quads.getMaxIndex());

            GL11.glDrawElements(glMode, indices);

            indices.clear();
        } else {

            GL11.glDrawElements(glMode, quads.getIndexBuffer().limit(),
                    GL11.GL_UNSIGNED_INT, 0);

        }

        postdrawGeometry(quads);
        if (transformed) undoTransforms(quads);

        if (Debug.stats) {
            StatCollector.endStat(StatType.STAT_RENDER_TIMER);
        }
        quads.postdraw(this);
    }

    /**
     * <code>draw</code> renders a <code>TriMesh</code> object including
     * it's normals, colors, textures and vertices.
     * 
     * @see Renderer#draw(TriMesh)
     * @param tris
     *            the mesh to render.
     */
    public void draw(TriMesh tris) {
        if (!tris.predraw(this))
            return;
        if (Debug.stats) {
            StatCollector.addStat(StatType.STAT_TRIANGLE_COUNT, tris.getTriangleCount());
            StatCollector.addStat(StatType.STAT_VERTEX_COUNT, tris.getVertexCount());
            StatCollector.addStat(StatType.STAT_GEOM_COUNT, 1);
        }

        if (tris.getDisplayListID() != -1) {
            renderDisplayList(tris);
            return;
        }

        if (!generatingDisplayList) {
            applyStates(tris.states, tris);
        }
        if (Debug.stats) {
            StatCollector.startStat(StatType.STAT_RENDER_TIMER);
        }
        boolean transformed = doTransforms(tris);

        int glMode = GL11.GL_TRIANGLES;
        switch (tris.getMode()) {
            case Triangles:
                glMode = GL11.GL_TRIANGLES;
                break;
            case Strip:
                glMode = GL11.GL_TRIANGLE_STRIP;
                break;
            case Fan:
                glMode = GL11.GL_TRIANGLE_FAN;
                break;
        }

        if (!predrawGeometry(tris)) {
            // make sure only the necessary indices are sent through on old
            // cards.
            IntBuffer indices = tris.getIndexBuffer();
            if (indices == null) {
                logger.severe("missing indices on geometry object: "
                        + tris.toString());
            } else {
                indices.rewind();
                indices.limit(tris.getMaxIndex());

                GL11.glDrawElements(glMode, indices);

                indices.clear();
            }
        } else {
            GL11.glDrawElements(glMode, tris.getIndexBuffer().limit(),
                    GL11.GL_UNSIGNED_INT, 0);
        }

        postdrawGeometry(tris);
        if (transformed) undoTransforms(tris);

        if (Debug.stats) {
            StatCollector.endStat(StatType.STAT_RENDER_TIMER);
        }
        tris.postdraw(this);
    }

    private synchronized void renderDisplayList(Geometry geom) {
        applyStates(geom.states, geom);
        
        if (Debug.stats) {
            StatCollector.startStat(StatType.STAT_RENDER_TIMER);
        }
        if ((geom.getLocks() & Spatial.LOCKED_TRANSFORMS) == 0) {
            boolean transformed = doTransforms(geom);
            GL11.glCallList(geom.getDisplayListID());
            if (transformed) undoTransforms(geom);
        } else {
            GL11.glCallList(geom.getDisplayListID());
        }
        // invalidate line record as we do not know the line state anymore
        ((LineRecord) DisplaySystem.getDisplaySystem().getCurrentContext()
                .getLineRecord()).invalidate();
        // invalidate "current arrays"
        reset();
        if (Debug.stats) {
            StatCollector.endStat(StatType.STAT_RENDER_TIMER);
        }
    }

    /**
     * <code>prepVBO</code> binds the geometry data to a vbo buffer and sends
     * it to the GPU if necessary. The vbo id is stored in the geometry's
     * VBOInfo class. If a new vbo id is created, the VBO is also stored in a
     * cache. Before creating a new VBO this cache will be checked to see if a
     * VBO is already created for that Buffer.
     * 
     * @param g
     *            the geometry to initialize VBO for.
     */
    protected void prepVBO(Geometry g) {
        if (!supportsVBO())
            return;
        RendererRecord rendRecord = (RendererRecord) DisplaySystem
                .getDisplaySystem().getCurrentContext().getRendererRecord();

        VBOInfo vbo = g.getVBOInfo();

        if (vbo.isVBOVertexEnabled() && vbo.getVBOVertexID() <= 0) {
            if (g.getVertexBuffer() != null) {

                Object vboid;
                if ((vboid = vboMap.get(g.getVertexBuffer())) != null) {
                    vbo.setVBOVertexID(((Integer) vboid).intValue());
                } else {
                    g.getVertexBuffer().rewind();
                    int vboID = rendRecord.makeVBOId();
                    vbo.setVBOVertexID(vboID);
                    vboMap.put(g.getVertexBuffer(), vboID);

                    // ensure no VBO is bound
                    rendRecord.invalidateVBO(); // make sure we set it...
                    rendRecord.setBoundVBO(vbo.getVBOVertexID());

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -