add java client source
This commit is contained in:
commit
c7a15fdc7d
98 files changed
+80145
No files matched your search
@@ -0,0 +1,71 @@
|
||||
#include "gl_state.h"
|
||||
#include <cstdlib>
|
||||
#include <iostream>
|
||||
|
||||
namespace {
|
||||
void check(bool pass,const char* message) {
|
||||
if (pass) return;
|
||||
std::cerr << message << '\n';
|
||||
std::exit(1);
|
||||
}
|
||||
GLint integer(GLenum key) { GLint result{}; glGetIntegerv(key,&result); return result; }
|
||||
}
|
||||
|
||||
int main() {
|
||||
auto window=CreateWindowExW(0,L"STATIC",L"Amnesia GL state test",WS_POPUP,0,0,32,32,nullptr,nullptr,nullptr,nullptr);
|
||||
check(window!=nullptr,"could not create a test window");
|
||||
auto dc=GetDC(window);
|
||||
PIXELFORMATDESCRIPTOR descriptor{sizeof(descriptor),1,PFD_DRAW_TO_WINDOW|PFD_SUPPORT_OPENGL|PFD_DOUBLEBUFFER,
|
||||
PFD_TYPE_RGBA,32};
|
||||
auto format=ChoosePixelFormat(dc,&descriptor);
|
||||
check(format!=0 && SetPixelFormat(dc,format,&descriptor),"could not select a pixel format");
|
||||
auto gl=wglCreateContext(dc);
|
||||
check(gl && wglMakeCurrent(dc,gl),"could not create an OpenGL context");
|
||||
constexpr GLenum unpackBuffer=0x88EC, unpackBinding=0x88EF, drawFramebuffer=0x8CA9, drawBinding=0x8CA6;
|
||||
using Bind=void (APIENTRY*)(GLenum,GLuint);
|
||||
using Generate=void (APIENTRY*)(GLsizei,GLuint*);
|
||||
const auto genBuffer=reinterpret_cast<Generate>(wglGetProcAddress("glGenBuffers"));
|
||||
const auto bindBuffer=reinterpret_cast<Bind>(wglGetProcAddress("glBindBuffer"));
|
||||
const auto genFrame=reinterpret_cast<Generate>(wglGetProcAddress("glGenFramebuffers"));
|
||||
const auto bindFrame=reinterpret_cast<Bind>(wglGetProcAddress("glBindFramebuffer"));
|
||||
check(genBuffer && bindBuffer && genFrame && bindFrame,"driver has no modern buffer functions");
|
||||
GLuint buffer{}, frame{};
|
||||
genBuffer(1,&buffer);
|
||||
genFrame(1,&frame);
|
||||
bindBuffer(unpackBuffer,buffer);
|
||||
bindFrame(drawFramebuffer,frame);
|
||||
glPixelStorei(GL_UNPACK_ALIGNMENT,8);
|
||||
glPixelStorei(GL_UNPACK_ROW_LENGTH,120);
|
||||
glPixelStorei(GL_UNPACK_SKIP_ROWS,20);
|
||||
glPixelStorei(GL_UNPACK_SKIP_PIXELS,35);
|
||||
glPixelStorei(0x806E,50);
|
||||
glPixelStorei(0x806D,4);
|
||||
glPixelStorei(GL_UNPACK_SWAP_BYTES,1);
|
||||
glPixelStorei(GL_UNPACK_LSB_FIRST,1);
|
||||
glColorMask(0,1,0,0);
|
||||
{
|
||||
java::overlay::GlState guard;
|
||||
check(!integer(unpackBinding) && !integer(drawBinding),"buffer and framebuffer must be released");
|
||||
check(integer(GL_UNPACK_ALIGNMENT)==1 && !integer(GL_UNPACK_ROW_LENGTH) && !integer(GL_UNPACK_SKIP_ROWS) &&
|
||||
!integer(GL_UNPACK_SKIP_PIXELS) && !integer(0x806E) && !integer(0x806D) &&
|
||||
!integer(GL_UNPACK_SWAP_BYTES) && !integer(GL_UNPACK_LSB_FIRST),"all unpack offsets must be reset");
|
||||
GLuint texture{};
|
||||
glGenTextures(1,&texture);
|
||||
glBindTexture(GL_TEXTURE_2D,texture);
|
||||
const unsigned color=0xff80ff40;
|
||||
glTexImage2D(GL_TEXTURE_2D,0,GL_RGBA,1,1,0,GL_RGBA,GL_UNSIGNED_BYTE,&color);
|
||||
check(glGetError()==GL_NO_ERROR,"CPU texture upload must succeed");
|
||||
glDeleteTextures(1,&texture);
|
||||
}
|
||||
check(integer(unpackBinding)==GLint(buffer) && integer(drawBinding)==GLint(frame),"buffer bindings must be restored");
|
||||
check(integer(GL_UNPACK_ALIGNMENT)==8 && integer(GL_UNPACK_ROW_LENGTH)==120 && integer(GL_UNPACK_SKIP_ROWS)==20 &&
|
||||
integer(GL_UNPACK_SKIP_PIXELS)==35 && integer(0x806E)==50 && integer(0x806D)==4 &&
|
||||
integer(GL_UNPACK_SWAP_BYTES)==1 && integer(GL_UNPACK_LSB_FIRST)==1,"all unpack state must be restored");
|
||||
GLboolean mask[4]{};
|
||||
glGetBooleanv(GL_COLOR_WRITEMASK,mask);
|
||||
check(!mask[0] && mask[1] && !mask[2] && !mask[3],"color mask must be restored");
|
||||
wglMakeCurrent(nullptr,nullptr);
|
||||
wglDeleteContext(gl);
|
||||
ReleaseDC(window,dc);
|
||||
DestroyWindow(window);
|
||||
}
|
||||
Reference in new issue
Block a user