Direct3D vs. OpenGL: A Comparison

本文对比了SGI的OpenGL与Microsoft的Direct3D两大3D图形API。从系统机制、建模、渲染等方面详细比较了两者的特性及差异。
 

Direct3D vs. OpenGL: A Comparison

Summary

This page is an informal attempt to summarize the main differences between SGI's OpenGL and Microsoft's Direct3D. First, each API is summarized in an attempt to bring a balanced presentation of the two APIs. Then a feature comparison is made between the capabilities of OpenGL and Direct3D.

Unless otherwise noted, "OpenGL" refers to the OpenGL 1.2 core with no extensions and "Direct3D" refers to Direct3D8, the Direct3D interface in DirectX 8. When a difference between Direct3D7 and Direct3D8 is noteworthy, version numbers are given.

Intended Audience

This document assumes that the reader is familiar with the architecture of a traditional 3D graphics pipeline as commonly used with scanline rendering techniques. For more information on such architectures, the reader is encouraged to consult a 3D graphics text such as "3D Computer Graphics" by Alan Watt and Mark Watt. This is only one book of many 3D graphics books, the interested reader is encouraged to browse a good technical bookstore and find one that speaks to them most effectively.

SGI's OpenGL

SGI's OpenGL is a procedural 3D graphics API, the successor to Iris GL which originated in the unix workstation market. Iris GL is the graphics API used on a succession of 3D graphics workstations designed and built by Silicon Graphics, Inc.

"OpenGL" is a trademark of the OpenGL Architectural Review Board (ARB). The ARB controls the definition of OpenGL through control of the specification by which an implementation may call itself "OpenGL". The specification is an English prose document with associated mathematics that define the semantics of the API. The ARB also governs a suite of conformance tests that serve as a validation suite for an implementation.

The ARB was formed in 1992 and functions under a set of bylaws to revise and oversee the specification of the API.

OpenGL defines a state machine that controls the rendering pipeline. State machine attributes are modified through procedure calls and vertices defining graphic primitives are specified to the pipeline through procedure calls.

Only the OpenGL 1.2 core is considered in this document, not extensions.

Microsoft's Direct3D

Microsoft's Direct3D is a COM based 3D graphics API originating in a third-party 3D graphics API for x86 architectures. Microsoft acquired the technology in 1996 and has been offering the API as a component of its DirectX technology. Direct3D contains an immediate-mode interface and a strctured hierarchical scene graph interface called retained mode. Only the immediate-mode interface is considered in this document.

Microsoft defines the Direct3D API through its COM interfaces, and the semantics are defined by the the help files and sample code accompanying the software development kit provided by Microsoft.

Direct3D first appeared in DirectX 3 with execute buffers as its display paradigm. All subsequent releases, beginning with DirectX 5 (there was no DirectX 4), replaced execute buffers with a more traditional graphics primitive display paradigm.

Feature Comparison

OpenGL and Direct3D both expose a traditional graphics rendering pipeline. This basic pipeline design has been present since the earliest days of computer graphics and has been enhanced and extended over the years as hardware has become more capable, but the fundamental paradigm has not changed.

Vertices are described to the pipeline as a bundle of data consisting of coordinates in space defining the vertex's location and associated per-vertex data. A graphics primitive is described to the pipeline as an ordered set of vertices. How vertices are combined into various primitives -- generally points, lines and triangles -- is defined by the particular API.

Rather than provide an exhaustive list of features where both OpenGL and Direct3D provide the same feature, I will list the differences.

FeatureOpenGL 1.2 CoreDirect3D 7Direct3D 8
System Mechanics
Operating System SupportWindows (9x, NT, 2000), MacOS, BeOS, *nix, othersWindows (9x, 2000, CE) [12]Windows (9x, 2000) [12]
API Definition ControlOpenGL ARBMicrosoftMicrosoft
API SpecificationOpenGL Specification [10]SDK/DDK Documentation and DDK ReferenceSDK Documentation
API Mechanismincludes and librariesCOMCOM
Software Emulation of Unaccelerated Features [4]YesNoNo [11]
Extension Mechanism [5]YesNoYes
Source Implementation Available [6]YesYesNo
Modeling
Fixed-Function Vertex BlendingNoYesYes
Programmable Vertex BlendingNoNoYes
Parametric Curve PrimitivesYesNoYes
Parametric Surface PrimitivesYesNoYes
Hierarchical Display ListsYesNo [8]No [8]
Rendering
Two-sided LightingYesNo [1]No [1]
Point Size Rendering Attributes [9]YesNoYes
Line Width Rendering Attributes [9]YesNoNo
Programmable Pixel ShadingNo [14]NoYes
Triadic Texture Blending OperationsNoNoYes
Cube Environment MappingNoYesYes
Volume TexturesYesNoYes
Multitexture CascadeNo [13]YesYes
Texture Temporary Result RegisterNoNoYes
Mirror Texture AddressingNoYesYes
Texture "Wrapping"NoYesYes
Range-Based FogNoYesYes
Bump MappingNoYesYes
Modulate 2X Texture BlendNoYesYes
Modulate 4X Texture BlendNoYesYes
Add Signed Texture BlendNoYesYes
Frame Buffer
Hardware Independent Z Buffer AccessYesNo [2]No [2]
Full-Screen AntialiasingYesYesYes
Motion BlurYesNoYes
Depth of FieldYesNoYes
Accumulation BuffersYesNoNo [7]
Miscellaneous
Picking SupportYesNo [3]No [3]
Multiple Monitor SupportNoYesYes
Stereo RenderingYesYesNo

Notes:

  1. Two-sided lighting can be emulated by an application that desires two-sided polygon surfaces. First, the application sets the pipeline to cull back facing polygons and draws the front side of all two-sided polygons. Next, the pipeline is set to cull front facing polygons and the application draws the back side of all two-sided polygons.
  2. Access to the Z buffer is provided, but the values stored in the Z buffer are hardware dependent.
  3. Picking can be done entirely in the application by traversing its own data structures.
  4. OpenGL provides software emulation when hardware cannot accomodate the requested feature to guarantee that a rendering feature will exist. Direct3D exposes extensive information about hardware capabilities and lets the application determine how to obtain the requested feature.
  5. OpenGL provides an extension mechanism for an implementation to expose additional features not yet adopted by the ARB. Direct3D7 has one implementation with no extension mechanism. Direct3D8 has one implementation and provides support for pluggable software devices.
  6. An open source sample implementation of OpenGL is available. Microsoft's Windows 2000 DDK (driver development kit) contains the reference rasterizer for Direct3D 7.
  7. Multisampling is provided Direct3D8, but not as an accumulation buffer. This allows Direct3D8 to perform full-screen antialiasing, depth of field and motion blur effects without providing an accumulation buffer.
  8. Hierarchical display lists are not provided by Direct3D, but Direct3D does provide storage for polygon vertices and vertex indices to avoid data copying. These are flat array-like storages consisting only of geometry data and no state changes. State changes may be aggregated into state blocks for efficient transmission to the device. Neither state blocks, nor index buffers nor vertex buffers are hierarchical.
  9. Point and line width attributes can be emulated by drawing textured triangles (for points) or quadrilaterals (for lines) when the size of the point or line is significant. This also provides the application with more control over the exact rendering of these large points and thick lines. This additional control over rendering may be important for OpenGL applications even though OpenGL provides point and line rendering attributes.
  10. OpenGL's specification, while still being an English prose specification, is more rigorously defined than Direct3D.
  11. Direct3D8 provides software emulation for vertex processing (blending, vertex shaders, fixed-function vertex processing, etc.), but not for pixel processing (pixel shaders, multitexturing, etc.).
  12. Windows NT 4 only supports DirectX 3.
  13. Multitexture cascade is provided in OpenGL 1.2 through an ARB extension. While still an extension and not part of the official 1.2 core, it is expected to be widely implemented as it is a "standard" extension and not a vendor extension.
  14. Programmable pixel shading is provided by some vendors in OGL through the register combiner vendor extension.

In several aspects, a comparison between OpenGL and Direct3D is similar to a comparison between OpenGL and PEX. Many of the same differences exist for Direct3D.

 
### 问题分析 `java.lang.IllegalArgumentException: invalid comparison: java.time.LocalDateTime and java.lang.String` 异常的根本原因是,在 MyBatis 的映射文件中,尝试将 `java.time.LocalDateTime` 类型与 `java.lang.String` 类型进行比较。这种跨类型的比较在 Java 和 MyBatis 中均不受支持。 以下是可能导致该问题的具体场景及其解决方案: --- ### 数据库字段类型与实体类属性类型一致性验证 确保数据库中的字段类型(如 `DATETIME` 或 `TIMESTAMP`)与其对应的实体类属性类型一致。例如,如果数据库字段是 `DATETIME` 类型,则实体类中的对应属性应为 `LocalDateTime` 而非 `String`[^2]。 #### 示例代码 ```java @Entity public class User { @Column(name = "create_time", columnDefinition = "DATETIME") private LocalDateTime createTime; } ``` --- ### 检查 MyBatis 映射文件中的条件表达式 在 MyBatis 的 XML 文件中,避免对 `LocalDateTime` 类型的参数执行非法比较操作。常见的错误是在 `<if>` 标签中使用类似于 `createTime != ''` 的逻辑。由于 `createTime` 是 `LocalDateTime` 类型,而 `''` 是字符串类型,因此会产生异常。 #### 错误写法 ```xml <if test="createTime != null and createTime != ''"> AND create_time = #{createTime} </if> ``` #### 正确写法 仅检查 `createTime` 是否为 `null` 即可: ```xml <if test="createTime != null"> AND create_time = #{createTime} </if> ``` --- ### 参数传递的一致性 当调用 MyBatis 方法时,确保传入的参数类型与预期类型完全匹配。如果方法签名期望接收 `LocalDateTime` 类型的参数,则不应传递 `String` 类型的数据[^3]。 #### 示例代码 ```java // 错误示例:传递 String 类型 userMapper.findByCreateTime("2023-10-01T12:00:00"); // 正确示例:传递 LocalDateTime 类型 userMapper.findByCreateTime(LocalDateTime.of(2023, 10, 1, 12, 0)); ``` --- ### 使用正确的类型转换机制 如果确实需要基于字符串形式的时间值构建查询条件,可以在应用程序层面完成类型转换后再将其作为参数传递给 MyBatis。推荐使用 `DateTimeFormatter` 来解析字符串并生成 `LocalDateTime` 实例[^4]。 #### 示例代码 ```java import java.time.LocalDateTime; import java.time.format.DateTimeFormatter; public class TimeUtil { public static LocalDateTime parse(String timeStr) { DateTimeFormatter formatter = DateTimeFormatter.ofPattern("yyyy-MM-dd'T'HH:mm:ss"); return LocalDateTime.parse(timeStr, formatter); } } // 调用示例 LocalDateTime dateTime = TimeUtil.parse("2023-10-01T12:00:00"); userMapper.findByCreateTime(dateTime); ``` --- ### 版本兼容性注意事项 某些版本的 MyBatis 可能存在针对时间类型处理的 Bug。建议升级到最新稳定版以获得更好的支持和修复[^5]。当前推荐使用的版本为 **MyBatis 3.5.x** 或更高版本。 #### Maven 配置示例 ```xml <dependency> <groupId>org.mybatis</groupId> <artifactId>mybatis</artifactId> <version>3.5.9</version> </dependency> ``` --- ### 总结 通过以上措施可以有效解决 `java.lang.IllegalArgumentException: invalid comparison: java.time.LocalDateTime and java.lang.String` 异常问题。核心在于保持数据类型的一致性和避免非法的跨类型比较。 ---
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值